public override IAstNode VisitFunctionDefinition(FunctionDefinitionContext context) { BeginFunctionDefinition( ); var sig = ( Prototype )context.Signature.Accept(this); foreach (var param in sig.Parameters) { Push(param); } var body = ( IExpression )context.BodyExpression.Accept(this); var retVal = new FunctionDefinition(context.GetSourceSpan( ) , sig , body , LocalVariables.ToImmutableArray( ) ); // only add valid definitions to the runtime state. var errors = retVal.CollectErrors( ); if (errors.Count == 0) { RuntimeState.FunctionDefinitions.AddOrReplaceItem(retVal); } else { // remove the prototype implicitly added for this definition // as the definition has errors RuntimeState.FunctionDeclarations.Remove(sig); } return(retVal); }
public override ASTNode VisitFunctionDefinition([NotNull] FunctionDefinitionContext ctx) { DeclSpecsNode declSpecs = this.Visit(ctx.declarationSpecifiers()).As <DeclSpecsNode>(); ASTNode decl = this.Visit(ctx.declarator()); if (decl is IdNode fname) { decl = new FuncDeclNode(fname.Line, fname); } FuncDeclNode fdecl = decl.As <FuncDeclNode>(); BlockStatNode body = this.Visit(ctx.compoundStatement()).As <BlockStatNode>(); return(new FuncDefNode(ctx.Start.Line, declSpecs, fdecl, body)); }
public override IAstNode VisitFunctionDefinition([NotNull] FunctionDefinitionContext context) { BeginFunctionDefinition( ); var sig = ( Prototype )context.Signature.Accept(this); foreach (var param in sig.Parameters) { Push(param); } var body = ( IExpression )context.BodyExpression.Accept(this); var retVal = new FunctionDefinition(context.GetSourceSpan( ) , sig , body , LocalVariables.ToImmutableArray( ) ); RuntimeState.FunctionDefinitions.AddOrReplaceItem(retVal); return(retVal); }
public override Value VisitFunctionDefinition([NotNull] FunctionDefinitionContext context) { return(DefineFunction(( Function )context.Signature.Accept(this) , context.BodyExpression ).Function); }