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

Side by Side Diff: src/scopes.h

Issue 943543002: [strong] Declaration-after-use errors. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: computed prop names comment fix Created 5 years, 10 months 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/preparser.h ('k') | src/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_SCOPES_H_ 5 #ifndef V8_SCOPES_H_
6 #define V8_SCOPES_H_ 6 #define V8_SCOPES_H_
7 7
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/pending-compilation-error-handler.h"
9 #include "src/zone.h" 10 #include "src/zone.h"
10 11
11 namespace v8 { 12 namespace v8 {
12 namespace internal { 13 namespace internal {
13 14
14 class CompilationInfo; 15 class CompilationInfo;
15 16
16 17
17 // A hash map to support fast variable declaration and lookup. 18 // A hash map to support fast variable declaration and lookup.
18 class VariableMap: public ZoneHashMap { 19 class VariableMap: public ZoneHashMap {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 124
124 // Declare a parameter in this scope. When there are duplicated 125 // Declare a parameter in this scope. When there are duplicated
125 // parameters the rightmost one 'wins'. However, the implementation 126 // parameters the rightmost one 'wins'. However, the implementation
126 // expects all parameters to be declared and from left to right. 127 // expects all parameters to be declared and from left to right.
127 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, 128 Variable* DeclareParameter(const AstRawString* name, VariableMode mode,
128 bool is_rest = false); 129 bool is_rest = false);
129 130
130 // Declare a local variable in this scope. If the variable has been 131 // Declare a local variable in this scope. If the variable has been
131 // declared before, the previously declared variable is returned. 132 // declared before, the previously declared variable is returned.
132 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, 133 Variable* DeclareLocal(const AstRawString* name, VariableMode mode,
133 InitializationFlag init_flag, 134 InitializationFlag init_flag, Variable::Kind kind,
134 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); 135 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned);
135 136
136 // Declare an implicit global variable in this scope which must be a 137 // Declare an implicit global variable in this scope which must be a
137 // script scope. The variable was introduced (possibly from an inner 138 // script scope. The variable was introduced (possibly from an inner
138 // scope) by a reference to an unresolved variable with no intervening 139 // scope) by a reference to an unresolved variable with no intervening
139 // with statements or eval calls. 140 // with statements or eval calls.
140 Variable* DeclareDynamicGlobal(const AstRawString* name); 141 Variable* DeclareDynamicGlobal(const AstRawString* name);
141 142
142 // Create a new unresolved variable. 143 // Create a new unresolved variable.
143 VariableProxy* NewUnresolved(AstNodeFactory* factory, 144 VariableProxy* NewUnresolved(AstNodeFactory* factory,
144 const AstRawString* name, 145 const AstRawString* name,
145 int position = RelocInfo::kNoPosition) { 146 int start_position = RelocInfo::kNoPosition,
147 int end_position = RelocInfo::kNoPosition) {
146 // Note that we must not share the unresolved variables with 148 // Note that we must not share the unresolved variables with
147 // the same name because they may be removed selectively via 149 // the same name because they may be removed selectively via
148 // RemoveUnresolved(). 150 // RemoveUnresolved().
149 DCHECK(!already_resolved()); 151 DCHECK(!already_resolved());
150 VariableProxy* proxy = factory->NewVariableProxy(name, false, position); 152 VariableProxy* proxy =
153 factory->NewVariableProxy(name, false, start_position, end_position);
151 unresolved_.Add(proxy, zone_); 154 unresolved_.Add(proxy, zone_);
152 return proxy; 155 return proxy;
153 } 156 }
154 157
155 // Remove a unresolved variable. During parsing, an unresolved variable 158 // Remove a unresolved variable. During parsing, an unresolved variable
156 // may have been added optimistically, but then only the variable name 159 // may have been added optimistically, but then only the variable name
157 // was used (typically for labels). If the variable was not declared, the 160 // was used (typically for labels). If the variable was not declared, the
158 // addition introduced a new unresolved variable which may end up being 161 // addition introduced a new unresolved variable which may end up being
159 // allocated globally as a "ghost" variable. RemoveUnresolved removes 162 // allocated globally as a "ghost" variable. RemoveUnresolved removes
160 // such a variable again if it was added; otherwise this is a no-op. 163 // such a variable again if it was added; otherwise this is a no-op.
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 bool uses_super_property() const { return scope_uses_super_property_; } 313 bool uses_super_property() const { return scope_uses_super_property_; }
311 // Does any inner scope access "super" property. 314 // Does any inner scope access "super" property.
312 bool inner_uses_super_property() const { 315 bool inner_uses_super_property() const {
313 return inner_scope_uses_super_property_; 316 return inner_scope_uses_super_property_;
314 } 317 }
315 // Does this scope access "this". 318 // Does this scope access "this".
316 bool uses_this() const { return scope_uses_this_; } 319 bool uses_this() const { return scope_uses_this_; }
317 // Does any inner scope access "this". 320 // Does any inner scope access "this".
318 bool inner_uses_this() const { return inner_scope_uses_this_; } 321 bool inner_uses_this() const { return inner_scope_uses_this_; }
319 322
323 const Scope* NearestOuterEvalScope() const {
324 if (is_eval_scope()) return this;
325 if (outer_scope() == nullptr) return nullptr;
326 return outer_scope()->NearestOuterEvalScope();
327 }
328
320 // --------------------------------------------------------------------------- 329 // ---------------------------------------------------------------------------
321 // Accessors. 330 // Accessors.
322 331
323 // The type of this scope. 332 // The type of this scope.
324 ScopeType scope_type() const { return scope_type_; } 333 ScopeType scope_type() const { return scope_type_; }
325 334
326 // The language mode of this scope. 335 // The language mode of this scope.
327 LanguageMode language_mode() const { return language_mode_; } 336 LanguageMode language_mode() const { return language_mode_; }
328 337
329 // The variable corresponding to the 'this' value. 338 // The variable corresponding to the 'this' value.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 return variables_.Lookup(name) != NULL; 472 return variables_.Lookup(name) != NULL;
464 } 473 }
465 474
466 bool IsDeclaredParameter(const AstRawString* name) { 475 bool IsDeclaredParameter(const AstRawString* name) {
467 // If IsSimpleParameterList is false, duplicate parameters are not allowed, 476 // If IsSimpleParameterList is false, duplicate parameters are not allowed,
468 // however `arguments` may be allowed if function is not strict code. Thus, 477 // however `arguments` may be allowed if function is not strict code. Thus,
469 // the assumptions explained above do not hold. 478 // the assumptions explained above do not hold.
470 return params_.Contains(variables_.Lookup(name)); 479 return params_.Contains(variables_.Lookup(name));
471 } 480 }
472 481
482 // Error handling.
483 void ReportMessage(int start_position, int end_position, const char* message,
484 const AstRawString* arg);
485
473 // --------------------------------------------------------------------------- 486 // ---------------------------------------------------------------------------
474 // Debugging. 487 // Debugging.
475 488
476 #ifdef DEBUG 489 #ifdef DEBUG
477 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively 490 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively
478 #endif 491 #endif
479 492
480 // --------------------------------------------------------------------------- 493 // ---------------------------------------------------------------------------
481 // Implementation. 494 // Implementation.
482 protected: 495 protected:
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 inner_scope->outer_scope_ = this; 702 inner_scope->outer_scope_ = this;
690 } 703 }
691 } 704 }
692 705
693 void SetDefaults(ScopeType type, 706 void SetDefaults(ScopeType type,
694 Scope* outer_scope, 707 Scope* outer_scope,
695 Handle<ScopeInfo> scope_info); 708 Handle<ScopeInfo> scope_info);
696 709
697 AstValueFactory* ast_value_factory_; 710 AstValueFactory* ast_value_factory_;
698 Zone* zone_; 711 Zone* zone_;
712
713 PendingCompilationErrorHandler pending_error_handler_;
699 }; 714 };
700 715
701 } } // namespace v8::internal 716 } } // namespace v8::internal
702 717
703 #endif // V8_SCOPES_H_ 718 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698