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

Unified Diff: runtime/vm/scopes.cc

Issue 11265047: Implement const expressions for local variables (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | « runtime/vm/scopes.h ('k') | tests/language/const_locals_test.dart » ('j') | 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 14713)
+++ runtime/vm/scopes.cc (working copy)
@@ -460,7 +460,12 @@
context_scope.SetTokenIndexAt(captured_idx, variable->token_pos());
context_scope.SetNameAt(captured_idx, variable->name());
context_scope.SetIsFinalAt(captured_idx, variable->is_final());
- context_scope.SetTypeAt(captured_idx, variable->type());
+ context_scope.SetIsConstAt(captured_idx, variable->IsConst());
+ if (variable->IsConst()) {
+ context_scope.SetConstValueAt(captured_idx, *variable->ConstValue());
+ } else {
+ context_scope.SetTypeAt(captured_idx, variable->type());
+ }
context_scope.SetContextIndexAt(captured_idx, variable->index());
// Adjust the context level relative to the current context level,
// since the context of the current scope will be at level 0 when
@@ -482,10 +487,18 @@
LocalScope* outer_scope = new LocalScope(NULL, -1, 0);
// Add all variables as aliases to the outer scope.
for (int i = 0; i < context_scope.num_variables(); i++) {
- LocalVariable* variable =
- new LocalVariable(context_scope.TokenIndexAt(i),
- String::ZoneHandle(context_scope.NameAt(i)),
- AbstractType::ZoneHandle(context_scope.TypeAt(i)));
+ LocalVariable* variable;
+ if (context_scope.IsConstAt(i)) {
+ variable = new LocalVariable(context_scope.TokenIndexAt(i),
+ String::ZoneHandle(context_scope.NameAt(i)),
+ AbstractType::ZoneHandle(Type::DynamicType()));
+ variable->SetConstValue(
+ Instance::ZoneHandle(context_scope.ConstValueAt(i)));
+ } else {
+ variable = new LocalVariable(context_scope.TokenIndexAt(i),
+ String::ZoneHandle(context_scope.NameAt(i)),
+ AbstractType::ZoneHandle(context_scope.TypeAt(i)));
+ }
variable->set_is_captured();
variable->set_index(context_scope.ContextIndexAt(i));
if (context_scope.IsFinalAt(i)) {
@@ -516,6 +529,7 @@
context_scope.SetTokenIndexAt(0, func.token_pos());
context_scope.SetNameAt(0, name);
context_scope.SetIsFinalAt(0, true);
+ context_scope.SetIsConstAt(0, false);
const AbstractType& type = AbstractType::Handle(func.ParameterTypeAt(0));
context_scope.SetTypeAt(0, type);
context_scope.SetContextIndexAt(0, 0);
« no previous file with comments | « runtime/vm/scopes.h ('k') | tests/language/const_locals_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698