/// <summary> /// func-decl -> DEF ID LP type-list RP optional-return-spec brace-block /// </summary> /// <param name="n"></param> private void funcdeclNodeCode(TreeNode n, bool justPutFunctionNameInSymtable) { var fname = n.Children[1].Token.Lexeme; VarType retType; optionalreturnspecNodeCode(n.Children[5], out retType); List <VarType> argTypes; List <string> argNames; optionaltypelistNodeCode(n.Children[3], out argNames, out argTypes); VarType funcType = new FuncVarType(argTypes, retType); if (justPutFunctionNameInSymtable) { if (symtable.ContainsInCurrentScope(fname)) { throw new Exception("Error!! duplicate function decleration in scope!! DupFuncName: " + fname); } symtable[fname] = new VarInfo(funcType, label()); } else { symtable.AddScope(); addParametersToSymbolTable(argNames, argTypes); emit("{0}: ;{1}", symtable[fname].Label, fname); prologueCode(); emit("; braceblock for {0}", fname); braceblockNodeCode(n.Children[6], 0); emit("; final epilogue for {0}", fname); epilogueCode(); symtable.DeleteScope(); } }
public override bool Equals(object obj) { FuncVarType v2 = (obj as FuncVarType); if (v2 == null) { return(false); } if (!base.Equals(v2)) { return(false); } if (RetType != v2.RetType) { return(false); } return(ArgTypes.SequenceEqual(v2.ArgTypes)); }
static void funcdeclNodeCode(TreeNode n, bool justPutFunctionNamesInSymtable) { var fname = n.Children[1].Lexeme; VarType retType; optionalreturnspecNodeCode(n.Children[5], out retType); List <VarType> argTypes; List <string> argNames; optionaltypelistNodeCode(n.Children[3], out argNames, out argTypes); for (int i = 0; i < argTypes.Count; ++i) { if (argTypes[i] as ArrayVarType != null) { argTypes[i] = new PointerVarType(argTypes[i]); } } var funcType = new FuncVarType(argTypes, retType); if (justPutFunctionNamesInSymtable) { if (symtable.ContainsInCurrentScope(fname)) { throw new Exception("Variable already exists."); } symtable[fname] = new VarInfo(funcType, label(), false); } else { symtable.AddScope(); addParametersToSymbolTable(argNames, argTypes); emit("{0}:", symtable[fname].Label); prologueCode(); braceblockNodeCode(n.Children[6], 0); epilogueCode(); symtable.DeleteScope(); } }