Exemple #1
0
        public int VisitDeclaration(Decl decl)
        {
            var fndec = decl as FunctionDecl;

            if (fndec != null)
            {
                return(0);
            }

            IEnumerable <DeclSpec> declspecs = decl.decl_specs;
            var isTypedef = false;
            var scspec    = decl.decl_specs[0] as StorageClassSpec;

            if (scspec != null && scspec.Type == CTokenType.Typedef)
            {
                declspecs = decl.decl_specs.Skip(1);
                isTypedef = true;
            }


            var ntde = new NamedDataTypeExtractor(declspecs, this);

            foreach (var declarator in decl.init_declarator_list)
            {
                var nt      = ntde.GetNameAndType(declarator.Declarator);
                var serType = nt.DataType;

                var sSig = nt.DataType as SerializedSignature;
                if (sSig != null)
                {
                    procs.Add(new Procedure_v1
                    {
                        Name      = nt.Name,
                        Signature = sSig,
                    });
                }
                if (isTypedef)
                {
                    //$REVIEW: should make sure that if the typedef already exists,
                    // then the types match but a real compiler would have validated that.
                    parserState.Typedefs.Add(nt.Name);
                    var typedef = new SerializedTypedef
                    {
                        Name     = nt.Name,
                        DataType = serType
                    };
                    Types.Add(typedef);
                    //$REVIEW: do we really need to check for consistence?
                    NamedTypes[typedef.Name] = serType;
                }
            }
            return(0);
        }
Exemple #2
0
 public Stat DeclStat(Decl decl)
 {
     return(new DeclStat {
         Declaration = decl
     });
 }