blob: 916842ab20ee69462e1a76f2b76c63bea3e1a267 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 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_AST_AST_EXPRESSION_REWRITER_H_
6#define V8_AST_AST_EXPRESSION_REWRITER_H_
7
8#include "src/allocation.h"
9#include "src/ast/ast.h"
10#include "src/ast/scopes.h"
11#include "src/effects.h"
12#include "src/type-info.h"
13#include "src/types.h"
14#include "src/zone.h"
15
16namespace v8 {
17namespace internal {
18
19// A rewriting Visitor over a CompilationInfo's AST that invokes
20// VisitExpression on each expression node.
21
22class AstExpressionRewriter : public AstVisitor {
23 public:
24 explicit AstExpressionRewriter(Isolate* isolate) : AstVisitor() {
25 InitializeAstRewriter(isolate);
26 }
27 explicit AstExpressionRewriter(uintptr_t stack_limit) : AstVisitor() {
28 InitializeAstRewriter(stack_limit);
29 }
30 ~AstExpressionRewriter() override {}
31
32 void VisitDeclarations(ZoneList<Declaration*>* declarations) override;
33 void VisitStatements(ZoneList<Statement*>* statements) override;
34 void VisitExpressions(ZoneList<Expression*>* expressions) override;
35
36 virtual void VisitObjectLiteralProperty(ObjectLiteralProperty* property);
37
38 protected:
39 virtual bool RewriteExpression(Expression* expr) = 0;
40
41 private:
42 DEFINE_AST_REWRITER_SUBCLASS_MEMBERS();
43
44#define DECLARE_VISIT(type) void Visit##type(type* node) override;
45 AST_NODE_LIST(DECLARE_VISIT)
46#undef DECLARE_VISIT
47
48 DISALLOW_COPY_AND_ASSIGN(AstExpressionRewriter);
49};
50
51} // namespace internal
52} // namespace v8
53
54#endif // V8_AST_AST_EXPRESSION_REWRITER_H_