1 // Copyright 2014 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.
5 #include "src/ast-this-access-visitor.h"
6 #include "src/parser.h"
11 typedef class AstThisAccessVisitor ATAV; // for code shortitude.
13 ATAV::AstThisAccessVisitor(Zone* zone) : uses_this_(false) {
14 InitializeAstVisitor(zone);
18 void ATAV::VisitVariableProxy(VariableProxy* proxy) {
19 if (proxy->is_this()) {
25 void ATAV::VisitSuperReference(SuperReference* leaf) {
26 // disallow super.method() and super(...).
31 void ATAV::VisitCallNew(CallNew* e) {
32 // new super(..) does not use 'this'.
33 if (!e->expression()->IsSuperReference()) {
34 Visit(e->expression());
36 VisitExpressions(e->arguments());
40 // ---------------------------------------------------------------------------
41 // -- Leaf nodes -------------------------------------------------------------
42 // ---------------------------------------------------------------------------
44 void ATAV::VisitVariableDeclaration(VariableDeclaration* leaf) {}
45 void ATAV::VisitFunctionDeclaration(FunctionDeclaration* leaf) {}
46 void ATAV::VisitModuleDeclaration(ModuleDeclaration* leaf) {}
47 void ATAV::VisitImportDeclaration(ImportDeclaration* leaf) {}
48 void ATAV::VisitExportDeclaration(ExportDeclaration* leaf) {}
49 void ATAV::VisitModuleVariable(ModuleVariable* leaf) {}
50 void ATAV::VisitModulePath(ModulePath* leaf) {}
51 void ATAV::VisitModuleUrl(ModuleUrl* leaf) {}
52 void ATAV::VisitEmptyStatement(EmptyStatement* leaf) {}
53 void ATAV::VisitContinueStatement(ContinueStatement* leaf) {}
54 void ATAV::VisitBreakStatement(BreakStatement* leaf) {}
55 void ATAV::VisitDebuggerStatement(DebuggerStatement* leaf) {}
56 void ATAV::VisitFunctionLiteral(FunctionLiteral* leaf) {}
57 void ATAV::VisitNativeFunctionLiteral(NativeFunctionLiteral* leaf) {}
58 void ATAV::VisitLiteral(Literal* leaf) {}
59 void ATAV::VisitRegExpLiteral(RegExpLiteral* leaf) {}
60 void ATAV::VisitThisFunction(ThisFunction* leaf) {}
62 // ---------------------------------------------------------------------------
63 // -- Pass-through nodes------------------------------------------------------
64 // ---------------------------------------------------------------------------
65 void ATAV::VisitModuleLiteral(ModuleLiteral* e) { Visit(e->body()); }
68 void ATAV::VisitBlock(Block* stmt) { VisitStatements(stmt->statements()); }
71 void ATAV::VisitExpressionStatement(ExpressionStatement* stmt) {
72 Visit(stmt->expression());
76 void ATAV::VisitIfStatement(IfStatement* stmt) {
77 Visit(stmt->condition());
78 Visit(stmt->then_statement());
79 Visit(stmt->else_statement());
83 void ATAV::VisitReturnStatement(ReturnStatement* stmt) {
84 Visit(stmt->expression());
88 void ATAV::VisitWithStatement(WithStatement* stmt) {
89 Visit(stmt->expression());
90 Visit(stmt->statement());
94 void ATAV::VisitSwitchStatement(SwitchStatement* stmt) {
96 ZoneList<CaseClause*>* clauses = stmt->cases();
97 for (int i = 0; i < clauses->length(); i++) {
98 Visit(clauses->at(i));
103 void ATAV::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
104 Visit(stmt->try_block());
105 Visit(stmt->finally_block());
109 void ATAV::VisitClassLiteral(ClassLiteral* e) {
110 VisitIfNotNull(e->extends());
111 Visit(e->constructor());
112 ZoneList<ObjectLiteralProperty*>* properties = e->properties();
113 for (int i = 0; i < properties->length(); i++) {
114 Visit(properties->at(i)->value());
119 void ATAV::VisitConditional(Conditional* e) {
120 Visit(e->condition());
121 Visit(e->then_expression());
122 Visit(e->else_expression());
126 void ATAV::VisitObjectLiteral(ObjectLiteral* e) {
127 ZoneList<ObjectLiteralProperty*>* properties = e->properties();
128 for (int i = 0; i < properties->length(); i++) {
129 Visit(properties->at(i)->value());
134 void ATAV::VisitArrayLiteral(ArrayLiteral* e) { VisitExpressions(e->values()); }
137 void ATAV::VisitYield(Yield* stmt) {
138 Visit(stmt->generator_object());
139 Visit(stmt->expression());
143 void ATAV::VisitThrow(Throw* stmt) { Visit(stmt->exception()); }
146 void ATAV::VisitProperty(Property* e) {
152 void ATAV::VisitCall(Call* e) {
153 Visit(e->expression());
154 VisitExpressions(e->arguments());
158 void ATAV::VisitCallRuntime(CallRuntime* e) {
159 VisitExpressions(e->arguments());
163 void ATAV::VisitUnaryOperation(UnaryOperation* e) { Visit(e->expression()); }
166 void ATAV::VisitBinaryOperation(BinaryOperation* e) {
172 void ATAV::VisitCompareOperation(CompareOperation* e) {
178 void ATAV::VisitCaseClause(CaseClause* cc) {
179 if (!cc->is_default()) Visit(cc->label());
180 VisitStatements(cc->statements());
184 void ATAV::VisitModuleStatement(ModuleStatement* stmt) { Visit(stmt->body()); }
187 void ATAV::VisitTryCatchStatement(TryCatchStatement* stmt) {
188 Visit(stmt->try_block());
189 Visit(stmt->catch_block());
193 void ATAV::VisitDoWhileStatement(DoWhileStatement* loop) {
199 void ATAV::VisitWhileStatement(WhileStatement* loop) {
205 void ATAV::VisitForStatement(ForStatement* loop) {
206 VisitIfNotNull(loop->init());
207 VisitIfNotNull(loop->cond());
209 VisitIfNotNull(loop->next());
213 void ATAV::VisitForInStatement(ForInStatement* loop) {
215 Visit(loop->subject());
220 void ATAV::VisitForOfStatement(ForOfStatement* loop) {
222 Visit(loop->subject());
227 void ATAV::VisitAssignment(Assignment* stmt) {
228 Expression* l = stmt->target();
230 Visit(stmt->value());
234 void ATAV::VisitCountOperation(CountOperation* e) {
235 Expression* l = e->expression();
239 } // namespace v8::internal