public void Visit(FunctionDeclarationStatement expression) { Builder.Append("function ") .Append(expression.Name) .Append("("); bool first = true; foreach (var parameter in expression.Parameters) { if (first == false) Builder.Append(", "); first = false; Builder.Append(parameter); } Builder.Append(") {"); indent++; Indent(); expression.Statement.Accept(this); indent--; Indent(); Builder.AppendLine("}"); }
public void Visit(FunctionDeclarationStatement statement) { JsFunction f = CreateFunction(statement); CurrentScope.DefineOwnProperty(statement.Name, f); }
public void Visit(FunctionDeclarationStatement statement) { JsFunction f = CreateFunction(statement); // Closures ? if (CurrentScope.Class == JsFunction.TYPEOF) { ((JsFunction)CurrentScope).Scope[statement.Name] = f; } else { //if (Scopes.Count == 2) GlobalScope[statement.Name] = f; //else // CurrentScope[statement.Name] = f; } }
// $ANTLR start "functionDeclaration" // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1788:1: functionDeclaration returns [Statement value] : FUNCTION name= Identifier parameters= formalParameterList body= functionBody ; public ES3Parser.functionDeclaration_return functionDeclaration() // throws RecognitionException [1] { ES3Parser.functionDeclaration_return retval = new ES3Parser.functionDeclaration_return(); retval.Start = input.LT(1); object root_0 = null; IToken name = null; IToken FUNCTION176 = null; ES3Parser.formalParameterList_return parameters = null; ES3Parser.functionBody_return body = null; object name_tree=null; object FUNCTION176_tree=null; FunctionDeclarationStatement statement = new FunctionDeclarationStatement(); retval.value = statement; try { // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1793:2: ( FUNCTION name= Identifier parameters= formalParameterList body= functionBody ) // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1793:4: FUNCTION name= Identifier parameters= formalParameterList body= functionBody { root_0 = (object)adaptor.GetNilNode(); FUNCTION176=(IToken)Match(input,FUNCTION,FOLLOW_FUNCTION_in_functionDeclaration6571); FUNCTION176_tree = (object)adaptor.Create(FUNCTION176); adaptor.AddChild(root_0, FUNCTION176_tree); name=(IToken)Match(input,Identifier,FOLLOW_Identifier_in_functionDeclaration6576); name_tree = (object)adaptor.Create(name); adaptor.AddChild(root_0, name_tree); statement.Name = name.Text; PushFollow(FOLLOW_formalParameterList_in_functionDeclaration6586); parameters = formalParameterList(); state.followingStackPointer--; adaptor.AddChild(root_0, parameters.Tree); statement.Parameters.AddRange(parameters.value); PushFollow(FOLLOW_functionBody_in_functionDeclaration6595); body = functionBody(); state.followingStackPointer--; adaptor.AddChild(root_0, body.Tree); statement.Statement = body.value; } retval.Stop = input.LT(-1); retval.Tree = (object)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop); } catch (RecognitionException re) { ReportError(re); Recover(input,re); // Conversion of the second argument necessary, but harmless retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re); } finally { } return retval; }
void Analyze(FunctionDeclarationStatement Stmt) { SetCurrentLineAndCharNos(Stmt); if (Stmt.Name != null) { int StatusIndex = AddToJintStack(Stmt.Source, JintState.MethodName); JintStack[StatusIndex].Value = Stmt.Name; //Analyzer.CheckIdentifier(Stmt.Name); } if (Stmt.Parameters != null) { for (int i=0; i< Stmt.Parameters.Count; i++) { if (Stmt.Parameters[i] != null) { AddToJintStack(Stmt.Source, JintState.MethodArgumentIdentifier); } } } if (Stmt.Statement != null) { //function body is declared here. Variable scoping etc must be handled. Analyze(Stmt.Statement); } }
public void Visit(FunctionDeclarationStatement statement) { JsFunction f = CreateFunction(statement); CurrentScope[statement.Name] = f; }