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

Unified Diff: runtime/vm/scopes.h

Issue 51533003: Compile time error if name is used before variable is declared (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/scopes.h
===================================================================
--- runtime/vm/scopes.h (revision 29679)
+++ runtime/vm/scopes.h (working copy)
@@ -117,6 +117,21 @@
};
+class NameReference : public ZoneAllocated {
+ public:
+ NameReference(intptr_t token_pos, const String& name)
+ : token_pos_(token_pos),
+ name_(name) {
+ }
+ const String& name() const { return name_; }
+ intptr_t token_pos() const { return token_pos_; }
+ void set_token_pos(intptr_t value) { token_pos_ = value; }
+ private:
+ intptr_t token_pos_;
+ const String& name_;
+};
+
+
class SourceLabel : public ZoneAllocated {
public:
enum Kind {
@@ -306,6 +321,12 @@
// this local scope.
int NumCapturedVariables() const;
+ // Add a reference to the given name into this scope and the enclosing
+ // scopes that do not have a local variable declaration for this name
+ // already.
+ void AddReferencedName(intptr_t token_pos, const String& name);
+ intptr_t PreviousReferencePos(const String& name) const;
+
// Allocate both captured and non-captured variables declared in this scope
// and in its children scopes of the same function level. Allocating means
// assigning a frame slot index or a context slot index.
@@ -354,6 +375,8 @@
void CollectLocalVariables(GrowableArray<VarDesc>* vars, int16_t* scope_id);
+ NameReference* FindReference(const String& name) const;
+
static const int kUnitializedContextLevel = INT_MIN;
LocalScope* parent_;
LocalScope* child_;
@@ -367,6 +390,10 @@
GrowableArray<LocalVariable*> variables_;
GrowableArray<SourceLabel*> labels_;
+ // List of names referenced in this scope and its children that
+ // are not resolved to local variables.
+ GrowableArray<NameReference*> referenced_;
+
DISALLOW_COPY_AND_ASSIGN(LocalScope);
};

Powered by Google App Engine
This is Rietveld 408576698