Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/parameter-initializer-rewriter.cc

Issue 1481613002: Create ast/ and parsing/ subdirectories and move appropriate files (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parameter-initializer-rewriter.h ('k') | src/parser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // 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 #include "src/parameter-initializer-rewriter.h"
6
7 #include "src/ast.h"
8 #include "src/ast-expression-visitor.h"
9 #include "src/scopes.h"
10
11 namespace v8 {
12 namespace internal {
13
14 namespace {
15
16
17 class Rewriter final : public AstExpressionVisitor {
18 public:
19 Rewriter(uintptr_t stack_limit, Expression* initializer, Scope* old_scope,
20 Scope* new_scope)
21 : AstExpressionVisitor(stack_limit, initializer),
22 old_scope_(old_scope),
23 new_scope_(new_scope) {}
24
25 private:
26 void VisitExpression(Expression* expr) override {}
27
28 void VisitFunctionLiteral(FunctionLiteral* expr) override;
29 void VisitClassLiteral(ClassLiteral* expr) override;
30 void VisitVariableProxy(VariableProxy* expr) override;
31
32 Scope* old_scope_;
33 Scope* new_scope_;
34 };
35
36
37 void Rewriter::VisitFunctionLiteral(FunctionLiteral* function_literal) {
38 function_literal->scope()->ReplaceOuterScope(new_scope_);
39 }
40
41
42 void Rewriter::VisitClassLiteral(ClassLiteral* class_literal) {
43 class_literal->scope()->ReplaceOuterScope(new_scope_);
44 if (class_literal->extends() != nullptr) {
45 Visit(class_literal->extends());
46 }
47 // No need to visit the constructor since it will have the class
48 // scope on its scope chain.
49 ZoneList<ObjectLiteralProperty*>* props = class_literal->properties();
50 for (int i = 0; i < props->length(); ++i) {
51 ObjectLiteralProperty* prop = props->at(i);
52 if (!prop->key()->IsLiteral()) {
53 Visit(prop->key());
54 }
55 // No need to visit the values, since all values are functions with
56 // the class scope on their scope chain.
57 DCHECK(prop->value()->IsFunctionLiteral());
58 }
59 }
60
61
62 void Rewriter::VisitVariableProxy(VariableProxy* proxy) {
63 DCHECK(!proxy->is_resolved());
64 if (old_scope_->RemoveUnresolved(proxy)) {
65 new_scope_->AddUnresolved(proxy);
66 }
67 }
68
69
70 } // anonymous namespace
71
72
73 void RewriteParameterInitializerScope(uintptr_t stack_limit,
74 Expression* initializer, Scope* old_scope,
75 Scope* new_scope) {
76 Rewriter rewriter(stack_limit, initializer, old_scope, new_scope);
77 rewriter.Run();
78 }
79
80
81 } // namespace internal
82 } // namespace v8
OLDNEW
« no previous file with comments | « src/parameter-initializer-rewriter.h ('k') | src/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698