public virtual Expression ResolveVariable(string name, VariableExpression original) { return(original); }
void AddDeclaration(object a, Block block) { if (a is CParser.MultiDeclaration) { var d = (CParser.MultiDeclaration)a; foreach (var idecl in d.InitDeclarators) { if ((d.Specifiers.StorageClassSpecifier & StorageClassSpecifier.Typedef) != 0) { if (idecl.Declarator != null) { var name = idecl.Declarator.DeclaredIdentifier; //Typedefs[name] = decl; } } else { var ctype = MakeCType(d.Specifiers, idecl.Declarator); var name = idecl.Declarator.DeclaredIdentifier; if (ctype is CFunctionType && !HasStronglyBoundPointer(idecl.Declarator)) { var ftype = (CFunctionType)ctype; var f = new FunctionDeclaration(name, ftype); for (var i = 0; i < ftype.Parameters.Count; i++) { f.ParameterInfos[i].Name = ftype.Parameters[i].Name; } block.AddFunction(f); } else { if ((ctype is CArrayType) && (((CArrayType)ctype).LengthExpression == null) && (idecl.Initializer != null)) { if (idecl.Initializer is StructuredInitializer) { var atype = (CArrayType)ctype; var len = 0; foreach (var i in ((StructuredInitializer)idecl.Initializer).Initializers) { if (i.Designation == null) { len++; } else { foreach (var de in i.Designation.Designators) { // TODO: Pay attention to designators len++; } } } atype.LengthExpression = new ConstantExpression(len); } else { //Report.Error(); } } //var init = GetInitExpression(idecl.Initializer); var vdecl = new VariableDeclaration(name, ctype); block.AddVariable(vdecl); } if (idecl.Initializer != null) { var varExpr = new VariableExpression(name); var initExpr = GetInitializerExpression(idecl.Initializer); block.AddStatement(new ExpressionStatement(new AssignExpression(varExpr, initExpr))); } } } } else if (a is FunctionDefinition) { var fdef = (FunctionDefinition)a; var ftype = (CFunctionType)MakeCType(fdef.Specifiers, fdef.Declarator); var name = fdef.Declarator.DeclaredIdentifier; var f = new FunctionDeclaration(name, ftype); for (var i = 0; i < ftype.Parameters.Count; i++) { f.ParameterInfos[i].Name = ftype.Parameters[i].Name; } f.Body = fdef.Body; block.AddFunction(f); } }