/// <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;
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); }
public Stat DeclStat(Decl decl) { return(new DeclStat { Declaration = decl }); }