void Imperative_functiondecl(out ProtoCore.AST.ImperativeAST.ImperativeNode node, List<ProtoCore.AST.ImperativeAST.ImperativeNode> attrs = null) { ProtoCore.AST.ImperativeAST.FunctionDefinitionNode funcDecl = new ProtoCore.AST.ImperativeAST.FunctionDefinitionNode(); ProtoCore.Type rtype = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Var, Constants.kArbitraryRank); Expect(27); NodeUtils.SetNodeStartLocation(funcDecl, t); funcDecl.Attributes = attrs; Expect(1); funcDecl.Name = t.val; NodeUtils.SetNodeEndLocation(funcDecl, t); if (IsKeyWord(t.val, true)) { errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val)); } if (la.kind == 47) { Get(); Imperative_ReturnType(out rtype); } funcDecl.ReturnType = rtype; ProtoCore.AST.ImperativeAST.ArgumentSignatureNode args = null; Imperative_ArgumentSignatureDefinition(out args); funcDecl.Signature = args; isGlobalScope = false; funcDecl.FunctionBody = new ProtoCore.AST.ImperativeAST.CodeBlockNode(); NodeUtils.SetNodeStartLocation(funcDecl.FunctionBody, la); List<ProtoCore.AST.ImperativeAST.ImperativeNode> body = new List<ProtoCore.AST.ImperativeAST.ImperativeNode>(); if (la.kind == 51) { Get(); Imperative_functionalMethodBodySingleStatement(out body); } else if (la.kind == 45) { Get(); Imperative_stmtlist(out body); Expect(46); } else SynErr(103); funcDecl.LocalVariableCount = localVarCount; NodeUtils.SetNodeEndLocation(funcDecl.FunctionBody, t); funcDecl.FunctionBody.Body = body; node = funcDecl; isGlobalScope = true; localVarCount= 0; }
void Imperative_functiondecl(out ProtoCore.AST.ImperativeAST.ImperativeNode node, List<ProtoCore.AST.ImperativeAST.ImperativeNode> attrs = null) { ProtoCore.AST.ImperativeAST.FunctionDefinitionNode funcDecl = new ProtoCore.AST.ImperativeAST.FunctionDefinitionNode(); ProtoCore.Type rtype = new ProtoCore.Type(); rtype.Name = "var"; rtype.UID = 0; rtype.rank = DSASM.Constants.kArbitraryRank; rtype.IsIndexable = true; Expect(25); NodeUtils.SetNodeStartLocation(funcDecl, t); funcDecl.Attributes = attrs; Expect(1); funcDecl.Name = t.val; NodeUtils.SetNodeEndLocation(funcDecl, t); if (IsKeyWord(t.val, true)) { errors.SemErr(t.line, t.col, String.Format("\"{0}\" is a keyword, identifier expected", t.val)); } if (la.kind == 48) { Get(); Imperative_ReturnType(out rtype); } funcDecl.ReturnType = rtype; ProtoCore.AST.ImperativeAST.ArgumentSignatureNode args = null; Imperative_ArgumentSignatureDefinition(out args); funcDecl.Signature = args; isGlobalScope = false; funcDecl.FunctionBody = new ProtoCore.AST.ImperativeAST.CodeBlockNode(); NodeUtils.SetNodeStartLocation(funcDecl.FunctionBody, la); List<ProtoCore.AST.ImperativeAST.ImperativeNode> body = new List<ProtoCore.AST.ImperativeAST.ImperativeNode>(); if (la.kind == 47) { Get(); Imperative_functionalMethodBodySingleStatement(out body); } else if (la.kind == 44) { Get(); Imperative_stmtlist(out body); Expect(45); } else SynErr(104); funcDecl.localVars = localVarCount; NodeUtils.SetNodeEndLocation(funcDecl.FunctionBody, t); funcDecl.FunctionBody.Body = body; node = funcDecl; isGlobalScope = true; localVarCount= 0; }