| Index: runtime/vm/parser.cc
|
| ===================================================================
|
| --- runtime/vm/parser.cc (revision 43426)
|
| +++ runtime/vm/parser.cc (working copy)
|
| @@ -66,6 +66,21 @@
|
| #define Z (zone())
|
|
|
|
|
| +static bool TypeChecksEnabled(Isolate* isolate) {
|
| + return FLAG_enable_type_checks || isolate->checked_mode();
|
| +}
|
| +
|
| +
|
| +static bool AssertsEnabled(Isolate* isolate) {
|
| + return FLAG_enable_asserts || isolate->checked_mode();
|
| +}
|
| +
|
| +
|
| +static bool ErrorOnBadTypeEnabled(Isolate* isolate) {
|
| + return FLAG_error_on_bad_type || isolate->checked_mode();
|
| +}
|
| +
|
| +
|
| #if defined(DEBUG)
|
| class TraceParser : public ValueObject {
|
| public:
|
| @@ -3125,7 +3140,7 @@
|
| // Populate function scope with the formal parameters.
|
| AddFormalParamsToScope(¶ms, current_block_->scope);
|
|
|
| - if (FLAG_enable_type_checks &&
|
| + if (TypeChecksEnabled(I) &&
|
| (current_block_->scope->function_level() > 0)) {
|
| // We are parsing, but not compiling, a local function.
|
| // The instantiator may be required at run time for generic type checks.
|
| @@ -6561,7 +6576,7 @@
|
| bool is_final = (CurrentToken() == Token::kFINAL);
|
| bool is_const = (CurrentToken() == Token::kCONST);
|
| const AbstractType& type = AbstractType::ZoneHandle(Z,
|
| - ParseConstFinalVarOrType(FLAG_enable_type_checks ?
|
| + ParseConstFinalVarOrType(TypeChecksEnabled(I) ?
|
| ClassFinalizer::kCanonicalize : ClassFinalizer::kIgnore));
|
| if (!IsIdentifier()) {
|
| ReportError("identifier expected");
|
| @@ -7549,7 +7564,7 @@
|
| // position, which is inside the loop body.
|
| new_loop_var = true;
|
| loop_var_type = ParseConstFinalVarOrType(
|
| - FLAG_enable_type_checks ? ClassFinalizer::kCanonicalize :
|
| + TypeChecksEnabled(I) ? ClassFinalizer::kCanonicalize :
|
| ClassFinalizer::kIgnore);
|
| }
|
| intptr_t loop_var_pos = TokenPos();
|
| @@ -7692,7 +7707,7 @@
|
| // position, which is inside the loop body.
|
| new_loop_var = true;
|
| loop_var_type = ParseConstFinalVarOrType(
|
| - FLAG_enable_type_checks ? ClassFinalizer::kCanonicalize :
|
| + TypeChecksEnabled(I) ? ClassFinalizer::kCanonicalize :
|
| ClassFinalizer::kIgnore);
|
| loop_var_name = ExpectIdentifier("variable name expected");
|
| }
|
| @@ -7911,7 +7926,7 @@
|
| ConsumeToken(); // Consume assert keyword.
|
| ExpectToken(Token::kLPAREN);
|
| const intptr_t condition_pos = TokenPos();
|
| - if (!FLAG_enable_asserts && !FLAG_enable_type_checks) {
|
| + if (!AssertsEnabled(I) && !TypeChecksEnabled(I)) {
|
| SkipExpr();
|
| ExpectToken(Token::kRPAREN);
|
| return NULL;
|
| @@ -10821,7 +10836,7 @@
|
| "include a type variable");
|
| }
|
| } else {
|
| - if (FLAG_error_on_bad_type) {
|
| + if (ErrorOnBadTypeEnabled(I)) {
|
| ReportError(type_pos,
|
| "a list literal takes one type argument specifying "
|
| "the element type");
|
| @@ -10844,7 +10859,7 @@
|
| while (CurrentToken() != Token::kRBRACK) {
|
| const intptr_t element_pos = TokenPos();
|
| AstNode* element = ParseExpr(is_const, kConsumeCascades);
|
| - if (FLAG_enable_type_checks &&
|
| + if (TypeChecksEnabled(I) &&
|
| !is_const &&
|
| !element_type.IsDynamicType()) {
|
| element = new(Z) AssignableNode(element_pos,
|
| @@ -10875,7 +10890,7 @@
|
| // Arguments have been evaluated to a literal value already.
|
| ASSERT(elem->IsLiteralNode());
|
| ASSERT(!is_top_level_); // We cannot check unresolved types.
|
| - if (FLAG_enable_type_checks &&
|
| + if (TypeChecksEnabled(I) &&
|
| !element_type.IsDynamicType() &&
|
| (!elem->AsLiteralNode()->literal().IsNull() &&
|
| !elem->AsLiteralNode()->literal().IsInstanceOf(
|
| @@ -11018,7 +11033,7 @@
|
| "include a type variable");
|
| }
|
| } else {
|
| - if (FLAG_error_on_bad_type) {
|
| + if (ErrorOnBadTypeEnabled(I)) {
|
| ReportError(type_pos,
|
| "a map literal takes two type arguments specifying "
|
| "the key type and the value type");
|
| @@ -11037,7 +11052,7 @@
|
| const bool saved_mode = SetAllowFunctionLiterals(true);
|
| const intptr_t key_pos = TokenPos();
|
| AstNode* key = ParseExpr(is_const, kConsumeCascades);
|
| - if (FLAG_enable_type_checks &&
|
| + if (TypeChecksEnabled(I) &&
|
| !is_const &&
|
| !key_type.IsDynamicType()) {
|
| key = new(Z) AssignableNode(
|
| @@ -11060,7 +11075,7 @@
|
| const intptr_t value_pos = TokenPos();
|
| AstNode* value = ParseExpr(is_const, kConsumeCascades);
|
| SetAllowFunctionLiterals(saved_mode);
|
| - if (FLAG_enable_type_checks &&
|
| + if (TypeChecksEnabled(I) &&
|
| !is_const &&
|
| !value_type.IsDynamicType()) {
|
| value = new(Z) AssignableNode(
|
| @@ -11092,7 +11107,7 @@
|
| // Arguments have been evaluated to a literal value already.
|
| ASSERT(arg->IsLiteralNode());
|
| ASSERT(!is_top_level_); // We cannot check unresolved types.
|
| - if (FLAG_enable_type_checks) {
|
| + if (TypeChecksEnabled(I)) {
|
| if ((i % 2) == 0) {
|
| // Check key type.
|
| arg_type = key_type.raw();
|
| @@ -11417,7 +11432,7 @@
|
| }
|
| return ThrowTypeError(redirect_type.token_pos(), redirect_type);
|
| }
|
| - if (FLAG_enable_type_checks && !redirect_type.IsSubtypeOf(type, NULL)) {
|
| + if (TypeChecksEnabled(I) && !redirect_type.IsSubtypeOf(type, NULL)) {
|
| // Additional type checking of the result is necessary.
|
| type_bound = type.raw();
|
| }
|
|
|