Esempio n. 1
0
        private static string[] GetNonTypeMemberNames(Syntax.InternalSyntax.SyntaxList <Syntax.InternalSyntax.MemberDeclarationSyntax> members, ref SingleTypeDeclaration.TypeDeclarationFlags declFlags)
        {
            bool anyMethodHadExtensionSyntax = false;
            bool anyMemberHasAttributes      = false;
            bool anyNonTypeMembers           = false;

            var set = PooledHashSet <string> .GetInstance();

            foreach (var member in members)
            {
                AddNonTypeMemberNames(member, set, ref anyNonTypeMembers);

                // Check to see if any method contains a 'this' modifier on its first parameter.
                // This data is used to determine if a type needs to have its members materialized
                // as part of extension method lookup.
                if (!anyMethodHadExtensionSyntax && CheckMethodMemberForExtensionSyntax(member))
                {
                    anyMethodHadExtensionSyntax = true;
                }

                if (!anyMemberHasAttributes && CheckMemberForAttributes(member))
                {
                    anyMemberHasAttributes = true;
                }
            }

            if (anyMethodHadExtensionSyntax)
            {
                declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.AnyMemberHasExtensionMethodSyntax;
            }

            if (anyMemberHasAttributes)
            {
                declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.AnyMemberHasAttributes;
            }

            if (anyNonTypeMembers)
            {
                declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers;
            }

            // PERF: The member names collection tends to be long-lived. Use a string array since
            // that uses less memory than a HashSet<string>.
            string[] result;
            if (set.Count == 0)
            {
                result = SpecializedCollections.EmptyArray <string>();
            }
            else
            {
                result = new string[set.Count];
                set.CopyTo(result);
            }

            set.Free();
            return(result);
        }
Esempio n. 2
0
        private ImmutableArray <SingleNamespaceOrTypeDeclaration> VisitNamespaceChildren(
            CSharpSyntaxNode node,
            SyntaxList <MemberDeclarationSyntax> members,
            Syntax.InternalSyntax.SyntaxList <Syntax.InternalSyntax.MemberDeclarationSyntax> internalMembers)
        {
            Debug.Assert(node.Kind == SyntaxKind.NamespaceDeclaration || (node.Kind == SyntaxKind.CompilationUnit && syntaxTree.Options.Kind == SourceCodeKind.Regular));

            if (members.Count == 0)
            {
                return(ImmutableArray <SingleNamespaceOrTypeDeclaration> .Empty);
            }

            // We look for members that are not allowed in a namespace.
            // If there are any we create an implicit class to wrap them.
            bool hasGlobalMembers = false;

            var childrenBuilder = ArrayBuilder <SingleNamespaceOrTypeDeclaration> .GetInstance();

            foreach (var member in members)
            {
                SingleNamespaceOrTypeDeclaration namespaceOrType = Visit(member);
                if (namespaceOrType != null)
                {
                    childrenBuilder.Add(namespaceOrType);
                }
                else
                {
                    hasGlobalMembers = hasGlobalMembers || member.Kind != SyntaxKind.IncompleteMember;
                }
            }

            // wrap all members that are defined in a namespace or compilation unit into an implicit type:
            if (hasGlobalMembers)
            {
                //The implicit class is not static and has no extensions
                SingleTypeDeclaration.TypeDeclarationFlags declFlags = SingleTypeDeclaration.TypeDeclarationFlags.None;
                var memberNames = GetNonTypeMemberNames(internalMembers, false, ref declFlags);
                var container   = syntaxTree.GetReference(node);

                childrenBuilder.Add(CreateImplicitClass(memberNames, container, declFlags));
            }

            return(childrenBuilder.ToImmutableAndFree());
        }
Esempio n. 3
0
 public static SeparatedSyntaxList <TNode> SeparatedList <TNode>(TNode node1, SyntaxToken token, TNode node2) where TNode : CSharpSyntaxNode
 {
     return(new SeparatedSyntaxList <TNode>(new SyntaxList <CSharpSyntaxNode>(SyntaxList.List(node1, token, node2))));
 }
Esempio n. 4
0
 internal static CSharpSyntaxNode ListNode(params ArrayElement <CSharpSyntaxNode>[] nodes)
 {
     return(SyntaxList.List(nodes));
 }
Esempio n. 5
0
 internal static CSharpSyntaxNode ListNode(CSharpSyntaxNode node0, CSharpSyntaxNode node1, CSharpSyntaxNode node2)
 {
     return(SyntaxList.List(node0, node1, node2));
 }
Esempio n. 6
0
 public static SyntaxList <TNode> List <TNode>(TNode node0, TNode node1, TNode node2) where TNode : CSharpSyntaxNode
 {
     return(new SyntaxList <TNode>(SyntaxList.List(node0, node1, node2)));
 }