xref: /third_party/node/deps/v8/src/parsing/rewriter.h (revision 1cb0ef41)
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
12namespace v8 {
13namespace internal {
14
15class AstValueFactory;
16class Isolate;
17class ParseInfo;
18class Parser;
19class DeclarationScope;
20class Scope;
21class Statement;
22class VariableProxy;
23
24class 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