コード例 #1
0
ファイル: TypeSizer.cs プロジェクト: feelworld/reko
 public int VisitTypedef(SerializedTypedef typedef)
 {
     throw new NotImplementedException();
     //int size = typedef.DataType.Accept(this);
     //namedTypeSizes[typedef.Name] = size;
     //return size;
 }
コード例 #2
0
        public DataType VisitTypedef(SerializedTypedef typedef)
        {
            var dt = typedef.DataType.Accept(this);

            types[typedef.Name] = dt;       //$BUGBUG: check for type equality if already exists.
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Given a C declaration, adds it to the symbol table
        /// as a function or a type declaration.
        /// </summary>
        /// <param name="decl"></param>
        public List <SerializedType> AddDeclaration(Decl decl)
        {
            var types = new List <SerializedType>();

            if (decl is FunctionDecl fndec)
            {
                return(types);
            }

            IEnumerable <DeclSpec> declspecs = decl.decl_specs;
            var isTypedef = false;

            if (decl.decl_specs[0] is StorageClassSpec scspec &&
                scspec.Type == CTokenType.Typedef)
            {
                declspecs = decl.decl_specs.Skip(1);
                isTypedef = true;
            }

            var ntde = new NamedDataTypeExtractor(platform, declspecs, this, pointerSize);

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

                if (nt.DataType is SerializedSignature sSig)
                {
                    sSig.Convention ??= GetCallingConventionFromAttributes(decl.attribute_list);
                    if (sSig.ReturnValue != null)
                    {
                        sSig.ReturnValue.Kind = ntde.GetArgumentKindFromAttributes(
                            "returns", decl.attribute_list);
                    }
                    var sProc = MakeProcedure(nt.Name !, sSig, decl.attribute_list);
                    Procedures.Add(sProc);
                    types.Add(sSig);
                }
                else if (!isTypedef)
                {
                    var variable = new GlobalDataItem_v2
                    {
                        Name     = nt.Name,
                        DataType = serType,
                    };
                    Variables.Add(variable);
                    types.Add(serType);
                }
                if (isTypedef)
                {
                    //$REVIEW: should make sure that if the typedef already exists,
                    // then the types match but a real compiler would have validated that.
                    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;
コード例 #4
0
        public List <SerializedType> AddDeclaration(Decl decl)
        {
            var types = new List <SerializedType>();
            var fndec = decl as FunctionDecl;

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

            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)
                {
                    if (sSig.ReturnValue != null)
                    {
                        sSig.ReturnValue.Kind = ntde.GetArgumentKindFromAttributes(decl.attribute_list);
                    }
                    Procedures.Add(new Procedure_v1
                    {
                        Name      = nt.Name,
                        Signature = sSig,
                    });
                    types.Add(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.
                    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;
                    types.Add(serType);
                }
            }
            return(types);
        }
コード例 #5
0
ファイル: TypeImporter.cs プロジェクト: ermshiperete/reko
        public SerializedType VisitTypeDeclaration(TypeDeclaration td)
        {
            var dt      = td.Type.Accept(this);
            var typedef = new SerializedTypedef {
                Name = td.Name, DataType = dt
            };

            return(typedef);
        }
コード例 #6
0
        public int VisitTypedef(SerializedTypedef typedef)
        {
            //int size = typedef.DataType.Accept(this);
            //namedTypeSizes[typedef.Name] = size;
            //return size;

            int size = typedef.DataType !.Accept(this);

            return(size);
        }
コード例 #7
0
        public DataType VisitTypedef(SerializedTypedef typedef)
        {
            var dt = typedef.DataType !.Accept(this);

            //$BUGBUG: check for type equality if already exists.
            if (types.TryGetValue(typedef.Name !, out var dtOld) &&
                dtOld is TypeReference tr)
            {
                tr.Referent = dt;
            }
コード例 #8
0
 public StringBuilder VisitTypedef(SerializedTypedef typedef)
 {
     throw new NotImplementedException();
 }
コード例 #9
0
 public DataType VisitTypedef(SerializedTypedef typedef)
 {
     throw new NotImplementedException();
 }
コード例 #10
0
ファイル: SymbolTable.cs プロジェクト: feelworld/reko
        public List<SerializedType> AddDeclaration(Decl decl)
        {
            var types = new List<SerializedType>();
            var fndec = decl as FunctionDecl;
            if (fndec != null)
            {
                return types;
            }

            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)
                {
                    if (sSig.ReturnValue != null)
                    {
                        sSig.ReturnValue.Kind = ntde.GetArgumentKindFromAttributes(decl.attribute_list);
                    }
                    Procedures.Add(new Procedure_v1
                    {
                        Name = nt.Name,
                        Signature = sSig,
                    });
                    types.Add(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.
                    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;
                    types.Add(serType);
                }
            }
            return types;
        }