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

Unified Diff: runtime/vm/parser.cc

Issue 10928169: Revert change 12289 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
« no previous file with comments | « runtime/vm/ast.h ('k') | tests/co19/co19-runtime.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 12289)
+++ runtime/vm/parser.cc (working copy)
@@ -766,6 +766,8 @@
}
+// TODO(regis): Implement support for non-const final static fields (currently
+// supported "final" fields are actually const fields).
// TODO(regis): Since a const variable is implicitly final,
// rename ParseStaticConstGetter to ParseStaticFinalGetter and
// rename kConstImplicitGetter to kImplicitFinalGetter.
@@ -795,11 +797,12 @@
// leave the evaluation to the getter function.
const intptr_t expr_pos = TokenPos();
AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades);
-
- if (field.is_const()) {
+ // TODO(hausner): Remove is_final check below once we support
+ // non-const finals.
+ if (field.is_const() || field.is_final()) {
// This getter will only be called once at compile time.
if (expr->EvalConstExpr() == NULL) {
- ErrorMsg(expr_pos, "initializer must be a compile-time constant");
+ ErrorMsg(expr_pos, "initializer must be a compile time constant");
}
ReturnNode* return_node = new ReturnNode(TokenPos(), expr);
current_block_->statements->Add(return_node);
@@ -816,6 +819,11 @@
// }
// return field.value; // Type check is executed here in checked mode.
+ // TODO(regis): Remove this check once we support proper const fields.
+ if (expr->EvalConstExpr() == NULL) {
+ ErrorMsg(expr_pos, "initializer must be a compile time constant");
+ }
+
// Generate code checking for circular dependency in field initialization.
AstNode* compare_circular = new ComparisonNode(
TokenPos(),
@@ -858,10 +866,6 @@
new LiteralNode(
TokenPos(),
Instance::ZoneHandle(Object::transition_sentinel()))));
- // TODO(hausner): If evaluation of the field value throws an exception,
- // we leave the field value as 'transition_sentinel', which is wrong.
- // A second reference to the field later throws a circular dependency
- // exception. The field should instead be set to null after an exception.
initialize_field->Add(new StoreStaticFieldNode(TokenPos(), field, expr));
AstNode* uninitialized_check =
new IfNode(TokenPos(), compare_uninitialized, initialize_field, NULL);
@@ -2668,10 +2672,12 @@
}
// Create the field object.
+ // TODO(hausner): For now, all static final fields are constant. Remove
+ // this when lazy init of static variables is implemented.
class_field = Field::New(*field->name,
field->has_static,
field->has_final,
- field->has_const,
+ field->has_const || field->has_final,
current_class(),
field->name_pos);
class_field.set_type(*field->type);
@@ -2687,7 +2693,7 @@
getter = Function::New(getter_name,
RawFunction::kConstImplicitGetter,
field->has_static,
- field->has_const,
+ field->has_final,
/* is_abstract = */ false,
/* is_external = */ false,
current_class(),
@@ -3729,9 +3735,8 @@
void Parser::ParseTopLevelVariable(TopLevel* top_level) {
TRACE_PARSER("ParseTopLevelVariable");
+ const bool is_final = (CurrentToken() == Token::kFINAL);
const bool is_const = (CurrentToken() == Token::kCONST);
- // Const fields are implicitly final.
- const bool is_final = is_const || (CurrentToken() == Token::kFINAL);
const bool is_static = true;
const AbstractType& type =
AbstractType::ZoneHandle(ParseConstFinalVarOrType(
@@ -3757,8 +3762,13 @@
var_name.ToCString());
}
- field = Field::New(var_name, is_static, is_final, is_const,
- current_class(), name_pos);
+ // TODO(hausner): const and final are equivalent at the moment.
+ field = Field::New(var_name,
+ is_static,
+ is_final || is_const, // Const fields are also final.
+ is_const || is_final,
+ current_class(),
+ name_pos);
field.set_type(type);
field.set_value(Instance::Handle(Instance::null()));
top_level->fields.Add(field);
@@ -3767,7 +3777,7 @@
ConsumeToken();
Instance& field_value = Instance::Handle(Object::sentinel());
bool has_simple_literal = false;
- if (is_final && (LookaheadToken(1) == Token::kSEMICOLON)) {
+ if ((is_final || is_const) && (LookaheadToken(1) == Token::kSEMICOLON)) {
has_simple_literal = IsSimpleLiteral(type, &field_value);
}
SkipExpr();
@@ -3778,7 +3788,7 @@
getter = Function::New(getter_name,
RawFunction::kConstImplicitGetter,
is_static,
- is_const,
+ is_final,
/* is_abstract = */ false,
/* is_external = */ false,
current_class(),
@@ -3786,7 +3796,8 @@
getter.set_result_type(type);
top_level->functions.Add(getter);
}
- } else if (is_final) {
+
+ } else if (is_final || is_const) {
ErrorMsg(name_pos, "missing initializer for final or const variable");
}
@@ -6776,7 +6787,7 @@
return expr;
}
if (expr->EvalConstExpr() == NULL) {
- ErrorMsg(expr_pos, "expression must be a compile-time constant");
+ ErrorMsg(expr_pos, "expression must be a compile time constant");
}
return new LiteralNode(expr_pos, EvaluateConstExpr(expr));
}
@@ -6931,7 +6942,7 @@
ConsumeToken();
const intptr_t right_expr_pos = TokenPos();
if (require_compiletime_const && (assignment_op != Token::kASSIGN)) {
- ErrorMsg(right_expr_pos, "expression must be a compile-time constant");
+ ErrorMsg(right_expr_pos, "expression must be a compile time constant");
}
AstNode* right_expr = ParseExpr(require_compiletime_const, consume_cascades);
AstNode* left_expr = expr;
@@ -7170,7 +7181,9 @@
return initializing_getter;
}
// The field is initialized.
- if (field.is_const()) {
+ // TODO(hausner): Remove the is_final check when we support non-const
+ // final static variables.
+ if (field.is_const() || field.is_final()) {
ASSERT(field.value() != Object::sentinel());
ASSERT(field.value() != Object::transition_sentinel());
return new LiteralNode(ident_pos, Instance::ZoneHandle(field.value()));
@@ -7739,7 +7752,9 @@
ASSERT(field.is_static());
const Instance& value = Instance::Handle(field.value());
if (value.raw() == Object::transition_sentinel()) {
- if (field.is_const()) {
+ // TODO(hausner): Remove the check for is_final() once we support
+ // non-const final fields.
+ if (field.is_const() || field.is_final()) {
ErrorMsg("circular dependency while initializing static field '%s'",
String::Handle(field.name()).ToCString());
} else {
@@ -7754,7 +7769,9 @@
// This field has not been referenced yet and thus the value has
// not been evaluated. If the field is const, call the static getter method
// to evaluate the expression and canonicalize the value.
- if (field.is_const()) {
+ // TODO(hausner): Remove the check for is_final() once we support
+ // non-const final fields.
+ if (field.is_const() || field.is_final()) {
field.set_value(Instance::Handle(Object::transition_sentinel()));
const String& field_name = String::Handle(field.name());
const String& getter_name =
@@ -7780,7 +7797,7 @@
// It is a compile-time error if evaluation of a compile-time constant
// would raise an exception.
AppendErrorMsg(error, TokenPos(),
- "error initializing const field '%s'",
+ "error initializing final field '%s'",
String::Handle(field.name()).ToCString());
} else {
Isolate::Current()->long_jump_base()->Jump(1, error);
@@ -8550,7 +8567,7 @@
if (key == NULL) {
ErrorMsg("map entry key must be string literal");
} else if (is_const && !key->IsLiteralNode()) {
- ErrorMsg("map entry key must be compile-time constant string");
+ ErrorMsg("map entry key must be compile time constant string");
}
ExpectToken(Token::kCOLON);
const bool saved_mode = SetAllowFunctionLiterals(true);
« no previous file with comments | « runtime/vm/ast.h ('k') | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698