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

Unified Diff: runtime/vm/scopes.cc

Issue 8992020: First part of inspecting local variables (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 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 side-by-side diff with in-line comments
Download patch
« runtime/vm/scopes.h ('K') | « runtime/vm/scopes.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/scopes.cc
===================================================================
--- runtime/vm/scopes.cc (revision 2646)
+++ runtime/vm/scopes.cc (working copy)
@@ -26,6 +26,7 @@
loop_level_(loop_level),
context_level_(LocalScope::kUnitializedContextLevel_),
num_context_variables_(0),
+ end_token_index_(0),
variables_(),
labels_() {
// Hook this node into the children of the parent, unless the parent has a
@@ -172,6 +173,45 @@
}
+static int CompareVariableRanges(
+ LocalVariable* const* a, LocalVariable* const* b) {
+ if ((*a)->token_index() < (*b)->token_index()) return -1;
+ if ((*a)->token_index() > (*b)->token_index()) return 1;
+ return 0;
+}
+
+
+RawLocalVarDescriptors* LocalScope::GetVarDescriptors() {
+ GrowableArray<LocalVariable*> vars(8);
+ CollectLocalVariables(&vars);
+ vars.Sort(&CompareVariableRanges);
+ const LocalVarDescriptors& var_desc =
+ LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length()));
+ for (int i = 0; i < vars.length(); i++) {
+ LocalVariable* var = vars[i];
+ var_desc.SetVar(i, var->name(), var->index(),
+ var->token_index(), var->owner()->end_token_index());
+ }
+ return var_desc.raw();
+}
+
+
+void LocalScope::CollectLocalVariables(GrowableArray<LocalVariable*>* vars) {
+ for (int i = 0; i < this->variables_.length(); i++) {
+ LocalVariable* var = variables_[i];
+ if ((var->owner() == this) && Scanner::IsIdent(var->name())) {
+ vars->Add(this->variables_[i]);
+ }
+ }
+ if (child() != NULL) {
+ child()->CollectLocalVariables(vars);
+ }
+ if (sibling() != NULL) {
+ sibling()->CollectLocalVariables(vars);
+ }
+}
+
+
SourceLabel* LocalScope::LocalLookupLabel(const String& name) const {
for (intptr_t i = 0; i < labels_.length(); i++) {
SourceLabel* label = labels_[i];
« runtime/vm/scopes.h ('K') | « runtime/vm/scopes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698