rewriter.h 1.42 KB
Newer Older
1
// Copyright 2011 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_PARSING_REWRITER_H_
#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 13
namespace v8 {
namespace internal {
14

15
class AstValueFactory;
16
class Isolate;
17
class ParseInfo;
18
class Parser;
19
class DeclarationScope;
20
class Scope;
21 22
class Statement;
class VariableProxy;
23 24 25

class Rewriter {
 public:
26 27 28 29 30 31
  // Rewrite top-level code (ECMA 262 "programs") so as to conservatively
  // include an assignment of the value of the last statement in the code to
  // a compiler-generated temporary variable wherever needed.
  //
  // Assumes code has been parsed and scopes have been analyzed.  Mutates the
  // 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 35 36 37 38 39

  // Helper that does the actual re-writing. Extracted so REPL scripts can
  // rewrite the body but then use the ".result" VariableProxy to resolve
  // the async promise that is the result of running a REPL script.
  // Returns base::nullopt in case something went wrong.
  static base::Optional<VariableProxy*> RewriteBody(
      ParseInfo* info, Scope* scope, ZonePtrList<Statement>* body);
40 41 42
};


43 44
}  // namespace internal
}  // namespace v8
45

46
#endif  // V8_PARSING_REWRITER_H_