Exemplo n.º 1
0
        void VisitDeclContext(DeclarationContext ctx, AST.DeclarationContext _ctx)
        {
            for (uint i = 0; i < ctx.NamespacesCount; ++i)
            {
                var decl  = ctx.getNamespaces(i);
                var _decl = Visit(decl) as AST.Namespace;
                _ctx.Namespaces.Add(_decl);
            }

            for (uint i = 0; i < ctx.EnumsCount; ++i)
            {
                var decl  = ctx.getEnums(i);
                var _decl = Visit(decl) as AST.Enumeration;
                _ctx.Enums.Add(_decl);
            }

            for (uint i = 0; i < ctx.FunctionsCount; ++i)
            {
                var decl  = ctx.getFunctions(i);
                var _decl = Visit(decl) as AST.Function;
                _ctx.Functions.Add(_decl);
            }

            for (uint i = 0; i < ctx.ClassesCount; ++i)
            {
                var decl  = ctx.getClasses(i);
                var _decl = Visit(decl) as AST.Class;
                _ctx.Classes.Add(_decl);
            }

            for (uint i = 0; i < ctx.TemplatesCount; ++i)
            {
                var decl  = ctx.getTemplates(i);
                var _decl = Visit(decl) as AST.Template;
                _ctx.Templates.Add(_decl);
            }

            for (uint i = 0; i < ctx.TypedefsCount; ++i)
            {
                var decl  = ctx.getTypedefs(i);
                var _decl = Visit(decl) as AST.TypedefDecl;
                _ctx.Typedefs.Add(_decl);
            }

            for (uint i = 0; i < ctx.VariablesCount; ++i)
            {
                var decl  = ctx.getVariables(i);
                var _decl = Visit(decl) as AST.Variable;
                _ctx.Variables.Add(_decl);
            }

            // Anonymous types
        }
Exemplo n.º 2
0
        public static IEnumerable <Declaration> GatherNamespaces(DeclarationContext @namespace)
        {
            var namespaces = new Stack <Declaration>();

            var currentNamespace = @namespace;

            while (currentNamespace != null)
            {
                namespaces.Push(currentNamespace);
                currentNamespace = currentNamespace.Namespace;
            }

            return(namespaces);
        }
Exemplo n.º 3
0
        public static List <Declaration> GatherNamespaces(DeclarationContext @namespace)
        {
            var namespaces = new List <Declaration>();

            var currentNamespace = @namespace;

            while (currentNamespace != null)
            {
                namespaces.Add(currentNamespace);
                currentNamespace = currentNamespace.Namespace;
            }

            return(namespaces);
        }
Exemplo n.º 4
0
 protected DeclarationContext(DeclarationContext dc)
     : base(dc)
 {
     Namespaces     = new List <Namespace>(dc.Namespaces);
     Enums          = new List <Enumeration>(dc.Enums);
     Functions      = new List <Function>(dc.Functions);
     Classes        = new List <Class>(dc.Classes);
     Templates      = new List <Template>(dc.Templates);
     Typedefs       = new List <TypedefDecl>(dc.Typedefs);
     Variables      = new List <Variable>(dc.Variables);
     Events         = new List <Event>(dc.Events);
     TypeReferences = new List <TypeReference>(dc.TypeReferences);
     Anonymous      = new Dictionary <ulong, Declaration>(dc.Anonymous);
     IsAnonymous    = dc.IsAnonymous;
 }
Exemplo n.º 5
0
        public static IEnumerable <Declaration> GatherNamespaces(DeclarationContext @namespace)
        {
            var namespaces = new Stack <Declaration>();

            var currentNamespace = @namespace;

            while (currentNamespace != null)
            {
                var isInlineNamespace = currentNamespace is Namespace &&
                                        ((Namespace)currentNamespace).IsInline;
                if (!isInlineNamespace)
                {
                    namespaces.Push(currentNamespace);
                }
                currentNamespace = currentNamespace.Namespace;
            }

            return(namespaces);
        }
Exemplo n.º 6
0
        public Namespace FindNamespace(IEnumerable <string> namespaces)
        {
            DeclarationContext currentNamespace = this;

            foreach (var @namespace in namespaces)
            {
                var childNamespace = currentNamespace.Namespaces.Find(
                    e => e.Name.Equals(@namespace));

                if (childNamespace == null)
                {
                    return(null);
                }

                currentNamespace = childNamespace;
            }

            return(currentNamespace as Namespace);
        }
Exemplo n.º 7
0
        public DeclarationContext FindDeclaration(IEnumerable <string> declarations)
        {
            DeclarationContext currentDeclaration = this;

            foreach (var declaration in declarations)
            {
                var subDeclaration = currentDeclaration.Namespaces
                                     .Concat <DeclarationContext>(currentDeclaration.Classes)
                                     .FirstOrDefault(e => e.Name.Equals(declaration));

                if (subDeclaration == null)
                {
                    return(null);
                }

                currentDeclaration = subDeclaration;
            }

            return(currentDeclaration as DeclarationContext);
        }
Exemplo n.º 8
0
        public Class FindClass(string name,
                               StringComparison stringComparison = StringComparison.Ordinal)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            var entries = name.Split(new[] { "::" },
                                     StringSplitOptions.RemoveEmptyEntries).ToList();

            if (entries.Count <= 1)
            {
                var @class = Classes.Find(c => c.Name.Equals(name, stringComparison)) ??
                             Namespaces.Select(n => n.FindClass(name, stringComparison)).FirstOrDefault(c => c != null);
                if (@class != null)
                {
                    return(@class.CompleteDeclaration == null ?
                           @class : (Class)@class.CompleteDeclaration);
                }
                return(null);
            }

            var className  = entries[entries.Count - 1];
            var namespaces = entries.Take(entries.Count - 1);

            DeclarationContext declContext = FindDeclaration(namespaces);

            if (declContext == null)
            {
                declContext = FindClass(entries[0]);
                if (declContext == null)
                {
                    return(null);
                }
            }

            return(declContext.FindClass(className));
        }
Exemplo n.º 9
0
 protected Declaration(Declaration declaration)
     : this()
 {
     Namespace         = declaration.Namespace;
     OriginalNamespace = declaration.OriginalNamespace;
     OriginalName      = declaration.OriginalName;
     name                = declaration.Name;
     Comment             = declaration.Comment;
     generationKind      = declaration.generationKind;
     Access              = declaration.Access;
     DebugText           = declaration.DebugText;
     IsIncomplete        = declaration.IsIncomplete;
     IsDependent         = declaration.IsDependent;
     CompleteDeclaration = declaration.CompleteDeclaration;
     DefinitionOrder     = declaration.DefinitionOrder;
     ExcludeFromPasses   = new HashSet <System.Type>(
         declaration.ExcludeFromPasses);
     PreprocessedEntities = new List <PreprocessedEntity>(
         declaration.PreprocessedEntities);
     OriginalPtr     = declaration.OriginalPtr;
     LineNumberStart = declaration.LineNumberStart;
     LineNumberEnd   = declaration.LineNumberEnd;
 }
Exemplo n.º 10
0
        public virtual bool VisitDeclarationContext(DeclarationContext context)
        {
            if (!VisitDeclaration(context))
            {
                return(false);
            }

            foreach (var decl in context.Classes)
            {
                decl.Visit(this);
            }

            foreach (var decl in context.Functions)
            {
                decl.Visit(this);
            }

            if (Options.VisitNamespaceEnums)
            {
                foreach (var decl in context.Enums)
                {
                    decl.Visit(this);
                }
            }

            if (Options.VisitNamespaceTemplates)
            {
                foreach (var decl in context.Templates)
                {
                    decl.Visit(this);
                }
            }

            if (Options.VisitNamespaceTypedefs)
            {
                foreach (var decl in context.Typedefs)
                {
                    decl.Visit(this);
                }
            }

            if (Options.VisitNamespaceVariables)
            {
                foreach (var decl in context.Variables)
                {
                    decl.Visit(this);
                }
            }

            if (Options.VisitNamespaceEvents)
            {
                foreach (var decl in context.Events)
                {
                    decl.Visit(this);
                }
            }

            foreach (var decl in context.Namespaces)
            {
                decl.Visit(this);
            }

            return(true);
        }