1 // Copyright 2011 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_PARSING_REWRITER_H_ 6 #define V8_PARSING_REWRITER_H_ 7 8 namespace v8 { 9 namespace internal { 10 11 class AstValueFactory; 12 class DoExpression; 13 class Isolate; 14 class ParseInfo; 15 class Parser; 16 class DeclarationScope; 17 class Scope; 18 19 class Rewriter { 20 public: 21 // Rewrite top-level code (ECMA 262 "programs") so as to conservatively 22 // include an assignment of the value of the last statement in the code to 23 // a compiler-generated temporary variable wherever needed. 24 // 25 // Assumes code has been parsed and scopes have been analyzed. Mutates the 26 // AST, so the AST should not continue to be used in the case of failure. 27 static bool Rewrite(ParseInfo* info); 28 29 // Rewrite a list of statements, using the same rules as a top-level program, 30 // to ensure identical behaviour of completion result. The temporary is added 31 // to the closure scope of the do-expression, which matches the closure scope 32 // of the outer scope (the do-expression itself runs in a block scope, not a 33 // closure scope). This closure scope needs to be passed in since the 34 // do-expression could have dropped its own block scope. 35 static bool Rewrite(Parser* parser, DeclarationScope* closure_scope, 36 DoExpression* expr, AstValueFactory* factory); 37 }; 38 39 40 } // namespace internal 41 } // namespace v8 42 43 #endif // V8_PARSING_REWRITER_H_ 44