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

Unified Diff: dart/runtime/vm/scopes.cc

Issue 59073003: Version 0.8.10.4 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/runtime/vm/scopes.h ('k') | dart/runtime/vm/snapshot.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/runtime/vm/scopes.cc
===================================================================
--- dart/runtime/vm/scopes.cc (revision 29808)
+++ dart/runtime/vm/scopes.cc (working copy)
@@ -30,7 +30,8 @@
begin_token_pos_(0),
end_token_pos_(0),
variables_(),
- labels_() {
+ labels_(),
+ referenced_() {
// Hook this node into the children of the parent, unless the parent has a
// different function_level, since the local scope of a nested function can
// be discarded after it has been parsed.
@@ -82,6 +83,48 @@
}
+NameReference* LocalScope::FindReference(const String& name) const {
+ intptr_t num_references = referenced_.length();
+ for (intptr_t i = 0; i < num_references; i++) {
+ if (name.Equals(referenced_[i]->name())) {
+ return referenced_[i];
+ }
+ }
+ return NULL;
+}
+
+
+void LocalScope::AddReferencedName(intptr_t token_pos,
+ const String& name) {
+ if (LocalLookupVariable(name) != NULL) {
+ return;
+ }
+ NameReference* ref = FindReference(name);
+ if (ref != NULL) {
+ ref->set_token_pos(token_pos);
+ return;
+ }
+ ref = new NameReference(token_pos, name);
+ referenced_.Add(ref);
+ // Add name reference in innermost enclosing scopes that do not
+ // define a local variable with this name.
+ LocalScope* scope = this->parent();
+ while (scope != NULL && (scope->LocalLookupVariable(name) == NULL)) {
+ scope->referenced_.Add(ref);
+ scope = scope->parent();
+ }
+}
+
+
+intptr_t LocalScope::PreviousReferencePos(const String& name) const {
+ NameReference* ref = FindReference(name);
+ if (ref != NULL) {
+ return ref->token_pos();
+ }
+ return -1;
+}
+
+
void LocalScope::AllocateContextVariable(LocalVariable* variable,
LocalScope** context_owner) {
ASSERT(variable->is_captured());
« no previous file with comments | « dart/runtime/vm/scopes.h ('k') | dart/runtime/vm/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698