Chromium Code Reviews| Index: runtime/vm/parser.cc |
| =================================================================== |
| --- runtime/vm/parser.cc (revision 29176) |
| +++ runtime/vm/parser.cc (working copy) |
| @@ -97,22 +97,6 @@ |
| } |
| -static ThrowNode* GenerateRethrow(intptr_t token_pos, const Object& obj) { |
| - const UnhandledException& excp = UnhandledException::Cast(obj); |
| - Instance& exception = Instance::ZoneHandle(excp.exception()); |
| - if (exception.IsNew()) { |
| - exception ^= Object::Clone(exception, Heap::kOld); |
| - } |
| - Instance& stack_trace = Instance::ZoneHandle(excp.stacktrace()); |
| - if (stack_trace.IsNew()) { |
| - stack_trace ^= Object::Clone(stack_trace, Heap::kOld); |
|
srdjan
2013/10/24 17:03:32
Why not Canonicalize instead of Clone?
hausner
2013/10/24 17:09:32
This code goes away, but I don't think canonicaliz
|
| - } |
| - return new ThrowNode(token_pos, |
| - new LiteralNode(token_pos, exception), |
| - new LiteralNode(token_pos, stack_trace)); |
| -} |
| - |
| - |
| LocalVariable* ParsedFunction::EnsureExpressionTemp() { |
| if (!has_expression_temp_var()) { |
| LocalVariable* temp = |
| @@ -897,7 +881,7 @@ |
| if (expr->EvalConstExpr() == NULL) { |
| ErrorMsg(expr_pos, "expression must be a compile-time constant"); |
| } |
| - const Instance& val = EvaluateConstExpr(expr); |
| + const Instance& val = EvaluateConstExpr(expr_pos, expr); |
| meta_values.Add(val); |
| } |
| return Array::MakeArray(meta_values); |
| @@ -2128,13 +2112,15 @@ |
| ConsumeToken(); |
| ExpectToken(Token::kASSIGN); |
| AstNode* init_expr = NULL; |
| + intptr_t expr_pos = TokenPos(); |
| if (field.is_const()) { |
| init_expr = ParseConstExpr(); |
| } else { |
| init_expr = ParseExpr(kAllowConst, kConsumeCascades); |
| if (init_expr->EvalConstExpr() != NULL) { |
| init_expr = |
| - new LiteralNode(field.token_pos(), EvaluateConstExpr(init_expr)); |
| + new LiteralNode(field.token_pos(), |
| + EvaluateConstExpr(expr_pos, init_expr)); |
| } |
| } |
| set_current_class(saved_class); |
| @@ -2173,10 +2159,11 @@ |
| if (field.is_const()) { |
| init_expr = ParseConstExpr(); |
| } else { |
| + intptr_t expr_pos = TokenPos(); |
| init_expr = ParseExpr(kAllowConst, kConsumeCascades); |
| if (init_expr->EvalConstExpr() != NULL) { |
| init_expr = new LiteralNode(field.token_pos(), |
| - EvaluateConstExpr(init_expr)); |
| + EvaluateConstExpr(expr_pos, init_expr)); |
| } |
| } |
| } |
| @@ -7649,7 +7636,7 @@ |
| if (expr->EvalConstExpr() == NULL) { |
| ErrorMsg(expr_pos, "expression is not a valid compile-time constant"); |
| } |
| - return new LiteralNode(expr_pos, EvaluateConstExpr(expr)); |
| + return new LiteralNode(expr_pos, EvaluateConstExpr(expr_pos, expr)); |
| } |
| @@ -9572,7 +9559,9 @@ |
| map_constr, |
| constr_args)); |
| if (constructor_result.IsUnhandledException()) { |
| - return GenerateRethrow(literal_pos, constructor_result); |
| + AppendErrorMsg(Error::Cast(constructor_result), |
| + literal_pos, |
| + "error executing const Map constructor"); |
| } else { |
| const Instance& const_instance = Instance::Cast(constructor_result); |
| return new LiteralNode(literal_pos, |
| @@ -9620,6 +9609,8 @@ |
| factory_method, |
| factory_param); |
| } |
| + UNREACHABLE(); |
| + return NULL; |
| } |
| @@ -9685,7 +9676,9 @@ |
| constr, |
| constr_args)); |
| if (result.IsUnhandledException()) { |
| - return GenerateRethrow(symbol_pos, result); |
| + AppendErrorMsg(Error::Cast(result), |
| + symbol_pos, |
| + "error executing const Symbol constructor"); |
| } |
| const Instance& instance = Instance::Cast(result); |
| return new LiteralNode(symbol_pos, Instance::ZoneHandle(instance.raw())); |
| @@ -9923,7 +9916,11 @@ |
| constructor, |
| arguments)); |
| if (constructor_result.IsUnhandledException()) { |
| - new_object = GenerateRethrow(new_pos, constructor_result); |
| + // It's a compile-time error if invocation of a const constructor |
| + // call fails. |
| + AppendErrorMsg(Error::Cast(constructor_result), |
| + new_pos, |
| + "error while evaluating const constructor"); |
| } else { |
| const Instance& const_instance = Instance::Cast(constructor_result); |
| new_object = new LiteralNode(new_pos, |
| @@ -10060,7 +10057,7 @@ |
| const_expr->IsBool() || |
| const_expr->IsNull())) { |
| // Change expr into a literal. |
| - expr = new LiteralNode(expr_pos, EvaluateConstExpr(expr)); |
| + expr = new LiteralNode(expr_pos, EvaluateConstExpr(expr_pos, expr)); |
| } else { |
| is_compiletime_const = false; |
| } |
| @@ -10258,7 +10255,7 @@ |
| // Evaluate expression in expr and return the value. The expression must |
| // be a compile time constant. |
| -const Instance& Parser::EvaluateConstExpr(AstNode* expr) { |
| +const Instance& Parser::EvaluateConstExpr(intptr_t expr_pos, AstNode* expr) { |
| if (expr->IsLiteralNode()) { |
| return expr->AsLiteralNode()->literal(); |
| } else if (expr->IsLoadLocalNode() && |
| @@ -10275,9 +10272,9 @@ |
| Object& result = Object::Handle(Compiler::ExecuteOnce(seq)); |
| if (result.IsError()) { |
| - // Propagate the compilation error. |
| - isolate()->long_jump_base()->Jump(1, Error::Cast(result)); |
| - UNREACHABLE(); |
| + AppendErrorMsg(Error::Cast(result), |
| + expr_pos, |
| + "error evaluating constant expression"); |
| } |
| ASSERT(result.IsInstance()); |
| Instance& value = Instance::ZoneHandle(); |