• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/base/macros.h"
9 #include "src/base/optional.h"
10 #include "src/zone/zone-type-traits.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 class AstValueFactory;
16 class Isolate;
17 class ParseInfo;
18 class Parser;
19 class DeclarationScope;
20 class Scope;
21 class Statement;
22 class VariableProxy;
23 
24 class Rewriter {
25  public:
26   // Rewrite top-level code (ECMA 262 "programs") so as to conservatively
27   // include an assignment of the value of the last statement in the code to
28   // a compiler-generated temporary variable wherever needed.
29   //
30   // Assumes code has been parsed and scopes have been analyzed.  Mutates the
31   // AST, so the AST should not continue to be used in the case of failure.
32   V8_EXPORT_PRIVATE static bool Rewrite(ParseInfo* info);
33 
34   // Helper that does the actual re-writing. Extracted so REPL scripts can
35   // rewrite the body but then use the ".result" VariableProxy to resolve
36   // the async promise that is the result of running a REPL script.
37   // Returns base::nullopt in case something went wrong.
38   static base::Optional<VariableProxy*> RewriteBody(
39       ParseInfo* info, Scope* scope, ZonePtrList<Statement>* body);
40 };
41 
42 
43 }  // namespace internal
44 }  // namespace v8
45 
46 #endif  // V8_PARSING_REWRITER_H_
47