| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 #include "vm/flags.h" | 6 #include "vm/flags.h" |
| 7 | 7 |
| 8 #ifndef DART_PRECOMPILED_RUNTIME | 8 #ifndef DART_PRECOMPILED_RUNTIME |
| 9 | 9 |
| 10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 DEFINE_FLAG(bool, conditional_directives, false, | 52 DEFINE_FLAG(bool, conditional_directives, false, |
| 53 "Enable conditional directives"); | 53 "Enable conditional directives"); |
| 54 DEFINE_FLAG(bool, warn_super, false, | 54 DEFINE_FLAG(bool, warn_super, false, |
| 55 "Warning if super initializer not last in initializer list."); | 55 "Warning if super initializer not last in initializer list."); |
| 56 DEFINE_FLAG(bool, await_is_keyword, false, | 56 DEFINE_FLAG(bool, await_is_keyword, false, |
| 57 "await and yield are treated as proper keywords in synchronous code."); | 57 "await and yield are treated as proper keywords in synchronous code."); |
| 58 | 58 |
| 59 DECLARE_FLAG(bool, lazy_dispatchers); | 59 DECLARE_FLAG(bool, lazy_dispatchers); |
| 60 DECLARE_FLAG(bool, load_deferred_eagerly); | 60 DECLARE_FLAG(bool, load_deferred_eagerly); |
| 61 DECLARE_FLAG(bool, profile_vm); | 61 DECLARE_FLAG(bool, profile_vm); |
| 62 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); | |
| 63 DECLARE_FLAG(bool, warn_on_javascript_compatibility); | |
| 64 | 62 |
| 65 // Quick access to the current thread, isolate and zone. | 63 // Quick access to the current thread, isolate and zone. |
| 66 #define T (thread()) | 64 #define T (thread()) |
| 67 #define I (isolate()) | 65 #define I (isolate()) |
| 68 #define Z (zone()) | 66 #define Z (zone()) |
| 69 | 67 |
| 70 // Quick synthetic token position. | 68 // Quick synthetic token position. |
| 71 #define ST(token_pos) ((token_pos).ToSynthetic()) | 69 #define ST(token_pos) ((token_pos).ToSynthetic()) |
| 72 | 70 |
| 73 #if defined(DEBUG) | 71 #if defined(DEBUG) |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 literal_token_ ^= tokens_iterator_.CurrentToken(); | 529 literal_token_ ^= tokens_iterator_.CurrentToken(); |
| 532 ASSERT(literal_token_.kind() == Token::kDOUBLE); | 530 ASSERT(literal_token_.kind() == Token::kDOUBLE); |
| 533 return Double::RawCast(literal_token_.value()); | 531 return Double::RawCast(literal_token_.value()); |
| 534 } | 532 } |
| 535 | 533 |
| 536 | 534 |
| 537 RawInteger* Parser::CurrentIntegerLiteral() const { | 535 RawInteger* Parser::CurrentIntegerLiteral() const { |
| 538 literal_token_ ^= tokens_iterator_.CurrentToken(); | 536 literal_token_ ^= tokens_iterator_.CurrentToken(); |
| 539 ASSERT(literal_token_.kind() == Token::kINTEGER); | 537 ASSERT(literal_token_.kind() == Token::kINTEGER); |
| 540 RawInteger* ri = Integer::RawCast(literal_token_.value()); | 538 RawInteger* ri = Integer::RawCast(literal_token_.value()); |
| 541 if (FLAG_throw_on_javascript_int_overflow) { | |
| 542 const Integer& i = Integer::Handle(Z, ri); | |
| 543 if (i.CheckJavascriptIntegerOverflow()) { | |
| 544 ReportError(TokenPos(), | |
| 545 "Integer literal does not fit in a Javascript integer: %s.", | |
| 546 i.ToCString()); | |
| 547 } | |
| 548 } | |
| 549 return ri; | 539 return ri; |
| 550 } | 540 } |
| 551 | 541 |
| 552 | 542 |
| 553 struct ParamDesc { | 543 struct ParamDesc { |
| 554 ParamDesc() | 544 ParamDesc() |
| 555 : type(NULL), | 545 : type(NULL), |
| 556 name_pos(TokenPosition::kNoSource), | 546 name_pos(TokenPosition::kNoSource), |
| 557 name(NULL), | 547 name(NULL), |
| 558 default_value(NULL), | 548 default_value(NULL), |
| (...skipping 10550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11109 cls, | 11099 cls, |
| 11110 func_name, | 11100 func_name, |
| 11111 arguments, | 11101 arguments, |
| 11112 InvocationMirror::kStatic, | 11102 InvocationMirror::kStatic, |
| 11113 InvocationMirror::kMethod, | 11103 InvocationMirror::kMethod, |
| 11114 NULL); // No existing function. | 11104 NULL); // No existing function. |
| 11115 } else if (cls.IsTopLevel() && | 11105 } else if (cls.IsTopLevel() && |
| 11116 (cls.library() == Library::CoreLibrary()) && | 11106 (cls.library() == Library::CoreLibrary()) && |
| 11117 (func.name() == Symbols::Identical().raw())) { | 11107 (func.name() == Symbols::Identical().raw())) { |
| 11118 // This is the predefined toplevel function identical(a,b). | 11108 // This is the predefined toplevel function identical(a,b). |
| 11119 // Create a comparison node instead of a static call to the function, unless | 11109 // Create a comparison node instead of a static call to the function. |
| 11120 // javascript warnings are desired and identical is not invoked from a patch | 11110 ASSERT(num_arguments == 2); |
| 11121 // source. | |
| 11122 if (!FLAG_warn_on_javascript_compatibility || is_patch_source()) { | |
| 11123 ASSERT(num_arguments == 2); | |
| 11124 | 11111 |
| 11125 // If both arguments are constant expressions of type string, | 11112 // If both arguments are constant expressions of type string, |
| 11126 // evaluate and canonicalize them. | 11113 // evaluate and canonicalize them. |
| 11127 // This guarantees that identical("ab", "a"+"b") is true. | 11114 // This guarantees that identical("ab", "a"+"b") is true. |
| 11128 // An alternative way to guarantee this would be to introduce | 11115 // An alternative way to guarantee this would be to introduce |
| 11129 // an AST node that canonicalizes a value. | 11116 // an AST node that canonicalizes a value. |
| 11130 AstNode* arg0 = arguments->NodeAt(0); | 11117 AstNode* arg0 = arguments->NodeAt(0); |
| 11131 const Instance* val0 = arg0->EvalConstExpr(); | 11118 const Instance* val0 = arg0->EvalConstExpr(); |
| 11132 if ((val0 != NULL) && (val0->IsString())) { | 11119 if ((val0 != NULL) && (val0->IsString())) { |
| 11133 AstNode* arg1 = arguments->NodeAt(1); | 11120 AstNode* arg1 = arguments->NodeAt(1); |
| 11134 const Instance* val1 = arg1->EvalConstExpr(); | 11121 const Instance* val1 = arg1->EvalConstExpr(); |
| 11135 if ((val1 != NULL) && (val1->IsString())) { | 11122 if ((val1 != NULL) && (val1->IsString())) { |
| 11136 arguments->SetNodeAt(0, | 11123 arguments->SetNodeAt(0, |
| 11137 new(Z) LiteralNode(arg0->token_pos(), | 11124 new(Z) LiteralNode(arg0->token_pos(), |
| 11138 EvaluateConstExpr(arg0->token_pos(), arg0))); | 11125 EvaluateConstExpr(arg0->token_pos(), arg0))); |
| 11139 arguments->SetNodeAt(1, | 11126 arguments->SetNodeAt(1, |
| 11140 new(Z) LiteralNode(arg1->token_pos(), | 11127 new(Z) LiteralNode(arg1->token_pos(), |
| 11141 EvaluateConstExpr(arg1->token_pos(), arg1))); | 11128 EvaluateConstExpr(arg1->token_pos(), arg1))); |
| 11142 } | |
| 11143 } | 11129 } |
| 11144 return new(Z) ComparisonNode(ident_pos, | |
| 11145 Token::kEQ_STRICT, | |
| 11146 arguments->NodeAt(0), | |
| 11147 arguments->NodeAt(1)); | |
| 11148 } | 11130 } |
| 11131 return new(Z) ComparisonNode(ident_pos, |
| 11132 Token::kEQ_STRICT, |
| 11133 arguments->NodeAt(0), |
| 11134 arguments->NodeAt(1)); |
| 11149 } | 11135 } |
| 11150 return new(Z) StaticCallNode(ident_pos, func, arguments); | 11136 return new(Z) StaticCallNode(ident_pos, func, arguments); |
| 11151 } | 11137 } |
| 11152 | 11138 |
| 11153 | 11139 |
| 11154 AstNode* Parser::ParseInstanceCall(AstNode* receiver, | 11140 AstNode* Parser::ParseInstanceCall(AstNode* receiver, |
| 11155 const String& func_name, | 11141 const String& func_name, |
| 11156 TokenPosition ident_pos, | 11142 TokenPosition ident_pos, |
| 11157 bool is_conditional) { | 11143 bool is_conditional) { |
| 11158 TRACE_PARSER("ParseInstanceCall"); | 11144 TRACE_PARSER("ParseInstanceCall"); |
| (...skipping 3262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14421 const ArgumentListNode& function_args, | 14407 const ArgumentListNode& function_args, |
| 14422 const LocalVariable* temp_for_last_arg, | 14408 const LocalVariable* temp_for_last_arg, |
| 14423 bool is_super_invocation) { | 14409 bool is_super_invocation) { |
| 14424 UNREACHABLE(); | 14410 UNREACHABLE(); |
| 14425 return NULL; | 14411 return NULL; |
| 14426 } | 14412 } |
| 14427 | 14413 |
| 14428 } // namespace dart | 14414 } // namespace dart |
| 14429 | 14415 |
| 14430 #endif // DART_PRECOMPILED_RUNTIME | 14416 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |