Beispiel #1
0
        private static Structure GetStructureType(CLanguageParser.StructDeclarationListContext context)
        {
            var declarations = context
                               .GetLeafDescendants <CLanguageParser.StructDeclarationContext>()
                               .Select(x => (CLanguageParser.StructDeclarationContext)x);
            var specifierContext = context.GetAncestor <CLanguageParser.StructOrUnionSpecifierContext>();
            var structure        = new Structure(specifierContext.GetChild(1).GetText())
            {
                Context = specifierContext
            };

            foreach (var declaration in declarations)
            {
                string text         = declaration.GetContextText();
                int    index        = text.InvariantLastIndexOf(SEPARATOR_TOKEN);
                string type         = text.Substring(0, index).Trim(SEPARATOR_TOKEN);
                string name         = text.Substring(index + 1).TrimEnd(SEMICOLUMN_TOKEN).Trim(SEPARATOR_TOKEN);
                int    pointerIndex = name.InvariantLastIndexOf(POINTER_TOKEN);

                if (pointerIndex >= 0)
                {
                    type += name.Substring(0, pointerIndex + 1);
                    name  = name.TrimStart(POINTER_TOKEN);
                }

                var field = new Field(type, name);

                structure.Fields.Add(field);
            }

            return(structure);
        }
Beispiel #2
0
        public override object VisitStructDeclarationList(CLanguageParser.StructDeclarationListContext context)
        {
            DataStructure.AddStructure(GetStructureType(context));

            return(base.VisitStructDeclarationList(context));
        }