| 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 | 6 |
| 7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 return error.raw(); | 1043 return error.raw(); |
| 1044 } | 1044 } |
| 1045 UNREACHABLE(); | 1045 UNREACHABLE(); |
| 1046 return Object::null(); | 1046 return Object::null(); |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 | 1049 |
| 1050 RawArray* Parser::EvaluateMetadata() { | 1050 RawArray* Parser::EvaluateMetadata() { |
| 1051 CheckToken(Token::kAT, "Metadata character '@' expected"); | 1051 CheckToken(Token::kAT, "Metadata character '@' expected"); |
| 1052 GrowableObjectArray& meta_values = | 1052 GrowableObjectArray& meta_values = |
| 1053 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); | 1053 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); |
| 1054 while (CurrentToken() == Token::kAT) { | 1054 while (CurrentToken() == Token::kAT) { |
| 1055 ConsumeToken(); | 1055 ConsumeToken(); |
| 1056 intptr_t expr_pos = TokenPos(); | 1056 intptr_t expr_pos = TokenPos(); |
| 1057 if (!IsIdentifier()) { | 1057 if (!IsIdentifier()) { |
| 1058 ExpectIdentifier("identifier expected"); | 1058 ExpectIdentifier("identifier expected"); |
| 1059 } | 1059 } |
| 1060 // Reject expressions with deferred library prefix eagerly. | 1060 // Reject expressions with deferred library prefix eagerly. |
| 1061 Object& obj = | 1061 Object& obj = |
| 1062 Object::Handle(Z, library_.LookupLocalObject(*CurrentLiteral())); | 1062 Object::Handle(Z, library_.LookupLocalObject(*CurrentLiteral())); |
| 1063 if (!obj.IsNull() && obj.IsLibraryPrefix()) { | 1063 if (!obj.IsNull() && obj.IsLibraryPrefix()) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 ident->ToCString(), | 1112 ident->ToCString(), |
| 1113 cls.ToCString()); | 1113 cls.ToCString()); |
| 1114 } | 1114 } |
| 1115 expr = GenerateStaticFieldLookup(field, ident_pos); | 1115 expr = GenerateStaticFieldLookup(field, ident_pos); |
| 1116 } | 1116 } |
| 1117 } | 1117 } |
| 1118 if (expr->EvalConstExpr() == NULL) { | 1118 if (expr->EvalConstExpr() == NULL) { |
| 1119 ReportError(expr_pos, "expression must be a compile-time constant"); | 1119 ReportError(expr_pos, "expression must be a compile-time constant"); |
| 1120 } | 1120 } |
| 1121 const Instance& val = EvaluateConstExpr(expr_pos, expr); | 1121 const Instance& val = EvaluateConstExpr(expr_pos, expr); |
| 1122 meta_values.Add(val); | 1122 meta_values.Add(val, Heap::kOld); |
| 1123 } | 1123 } |
| 1124 return Array::MakeArray(meta_values); | 1124 return Array::MakeArray(meta_values); |
| 1125 } | 1125 } |
| 1126 | 1126 |
| 1127 | 1127 |
| 1128 SequenceNode* Parser::ParseStaticInitializer() { | 1128 SequenceNode* Parser::ParseStaticInitializer() { |
| 1129 ExpectIdentifier("field name expected"); | 1129 ExpectIdentifier("field name expected"); |
| 1130 CheckToken(Token::kASSIGN, "field initialier expected"); | 1130 CheckToken(Token::kASSIGN, "field initialier expected"); |
| 1131 ConsumeToken(); | 1131 ConsumeToken(); |
| 1132 OpenFunctionBlock(parsed_function()->function()); | 1132 OpenFunctionBlock(parsed_function()->function()); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1534 | 1534 |
| 1535 // Receiver is local 0. | 1535 // Receiver is local 0. |
| 1536 LocalScope* scope = current_block_->scope; | 1536 LocalScope* scope = current_block_->scope; |
| 1537 ArgumentListNode* func_args = new ArgumentListNode(token_pos); | 1537 ArgumentListNode* func_args = new ArgumentListNode(token_pos); |
| 1538 for (intptr_t i = 0; i < desc.Count(); ++i) { | 1538 for (intptr_t i = 0; i < desc.Count(); ++i) { |
| 1539 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); | 1539 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); |
| 1540 } | 1540 } |
| 1541 | 1541 |
| 1542 if (desc.NamedCount() > 0) { | 1542 if (desc.NamedCount() > 0) { |
| 1543 const Array& arg_names = | 1543 const Array& arg_names = |
| 1544 Array::ZoneHandle(Z, Array::New(desc.NamedCount())); | 1544 Array::ZoneHandle(Z, Array::New(desc.NamedCount(), Heap::kOld)); |
| 1545 for (intptr_t i = 0; i < arg_names.Length(); ++i) { | 1545 for (intptr_t i = 0; i < arg_names.Length(); ++i) { |
| 1546 arg_names.SetAt(i, String::Handle(Z, desc.NameAt(i))); | 1546 arg_names.SetAt(i, String::Handle(Z, desc.NameAt(i))); |
| 1547 } | 1547 } |
| 1548 func_args->set_names(arg_names); | 1548 func_args->set_names(arg_names); |
| 1549 } | 1549 } |
| 1550 | 1550 |
| 1551 const String& func_name = String::ZoneHandle(Z, func.name()); | 1551 const String& func_name = String::ZoneHandle(Z, func.name()); |
| 1552 ArgumentListNode* arguments = BuildNoSuchMethodArguments( | 1552 ArgumentListNode* arguments = BuildNoSuchMethodArguments( |
| 1553 token_pos, func_name, *func_args, NULL, false); | 1553 token_pos, func_name, *func_args, NULL, false); |
| 1554 const intptr_t kNumArguments = 2; // Receiver, InvocationMirror. | 1554 const intptr_t kNumArguments = 2; // Receiver, InvocationMirror. |
| (...skipping 4235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5790 } | 5790 } |
| 5791 return Api::UnwrapHandle(result); | 5791 return Api::UnwrapHandle(result); |
| 5792 } | 5792 } |
| 5793 | 5793 |
| 5794 | 5794 |
| 5795 void Parser::ParseLibraryName() { | 5795 void Parser::ParseLibraryName() { |
| 5796 ASSERT(CurrentToken() == Token::kLIBRARY); | 5796 ASSERT(CurrentToken() == Token::kLIBRARY); |
| 5797 ConsumeToken(); | 5797 ConsumeToken(); |
| 5798 String& lib_name = *ExpectIdentifier("library name expected"); | 5798 String& lib_name = *ExpectIdentifier("library name expected"); |
| 5799 if (CurrentToken() == Token::kPERIOD) { | 5799 if (CurrentToken() == Token::kPERIOD) { |
| 5800 GrowableHandlePtrArray<const String> pieces(Z, 3); |
| 5801 pieces.Add(lib_name); |
| 5800 while (CurrentToken() == Token::kPERIOD) { | 5802 while (CurrentToken() == Token::kPERIOD) { |
| 5801 ConsumeToken(); | 5803 ConsumeToken(); |
| 5802 lib_name = String::Concat(lib_name, Symbols::Dot()); | 5804 pieces.Add(Symbols::Dot()); |
| 5803 lib_name = String::Concat(lib_name, | 5805 pieces.Add(*ExpectIdentifier("malformed library name")); |
| 5804 *ExpectIdentifier("malformed library name")); | |
| 5805 } | 5806 } |
| 5806 lib_name = Symbols::New(lib_name); | 5807 lib_name = Symbols::FromConcatAll(pieces); |
| 5807 } | 5808 } |
| 5808 library_.SetName(lib_name); | 5809 library_.SetName(lib_name); |
| 5809 ExpectSemicolon(); | 5810 ExpectSemicolon(); |
| 5810 } | 5811 } |
| 5811 | 5812 |
| 5812 | 5813 |
| 5813 void Parser::ParseIdentList(GrowableObjectArray* names) { | 5814 void Parser::ParseIdentList(GrowableObjectArray* names) { |
| 5814 if (!IsIdentifier()) { | 5815 if (!IsIdentifier()) { |
| 5815 ReportError("identifier expected"); | 5816 ReportError("identifier expected"); |
| 5816 } | 5817 } |
| (...skipping 5825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11642 extractor_name, | 11643 extractor_name, |
| 11643 NULL, // No arguments. | 11644 NULL, // No arguments. |
| 11644 InvocationMirror::kStatic, | 11645 InvocationMirror::kStatic, |
| 11645 is_setter_name | 11646 is_setter_name |
| 11646 ? InvocationMirror::kSetter | 11647 ? InvocationMirror::kSetter |
| 11647 : InvocationMirror::kMethod, | 11648 : InvocationMirror::kMethod, |
| 11648 NULL); // No existing function. | 11649 NULL); // No existing function. |
| 11649 } | 11650 } |
| 11650 | 11651 |
| 11651 // Closurization of instance getter, setter, method or operator. | 11652 // Closurization of instance getter, setter, method or operator. |
| 11653 GrowableHandlePtrArray<const String> pieces(Z, 3); |
| 11654 pieces.Add(Symbols::HashMark()); |
| 11652 if (is_setter_name) { | 11655 if (is_setter_name) { |
| 11653 extractor_name = String::Concat(Symbols::SetterPrefix(), extractor_name); | 11656 pieces.Add(Symbols::SetterPrefix()); |
| 11654 } | 11657 } |
| 11655 extractor_name = Symbols::FromConcat(Symbols::HashMark(), extractor_name); | 11658 pieces.Add(extractor_name); |
| 11659 extractor_name = Symbols::FromConcatAll(pieces); |
| 11656 return new(Z) InstanceGetterNode(property_pos, primary, extractor_name); | 11660 return new(Z) InstanceGetterNode(property_pos, primary, extractor_name); |
| 11657 } | 11661 } |
| 11658 | 11662 |
| 11659 | 11663 |
| 11660 AstNode* Parser::ParsePostfixExpr() { | 11664 AstNode* Parser::ParsePostfixExpr() { |
| 11661 TRACE_PARSER("ParsePostfixExpr"); | 11665 TRACE_PARSER("ParsePostfixExpr"); |
| 11662 String* expr_ident = | 11666 String* expr_ident = |
| 11663 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL; | 11667 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL; |
| 11664 const intptr_t expr_pos = TokenPos(); | 11668 const intptr_t expr_pos = TokenPos(); |
| 11665 AstNode* expr = ParsePrimary(); | 11669 AstNode* expr = ParsePrimary(); |
| (...skipping 1869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13535 | 13539 |
| 13536 String& Parser::Interpolate(const GrowableArray<AstNode*>& values) { | 13540 String& Parser::Interpolate(const GrowableArray<AstNode*>& values) { |
| 13537 const Class& cls = Class::Handle( | 13541 const Class& cls = Class::Handle( |
| 13538 Z, Library::LookupCoreClass(Symbols::StringBase())); | 13542 Z, Library::LookupCoreClass(Symbols::StringBase())); |
| 13539 ASSERT(!cls.IsNull()); | 13543 ASSERT(!cls.IsNull()); |
| 13540 const Function& func = Function::Handle(Z, cls.LookupStaticFunction( | 13544 const Function& func = Function::Handle(Z, cls.LookupStaticFunction( |
| 13541 Library::PrivateCoreLibName(Symbols::Interpolate()))); | 13545 Library::PrivateCoreLibName(Symbols::Interpolate()))); |
| 13542 ASSERT(!func.IsNull()); | 13546 ASSERT(!func.IsNull()); |
| 13543 | 13547 |
| 13544 // Build the array of literal values to interpolate. | 13548 // Build the array of literal values to interpolate. |
| 13545 const Array& value_arr = Array::Handle(Z, Array::New(values.length())); | 13549 const Array& value_arr = Array::Handle(Z, |
| 13550 Array::New(values.length(), Heap::kOld)); |
| 13546 for (int i = 0; i < values.length(); i++) { | 13551 for (int i = 0; i < values.length(); i++) { |
| 13547 ASSERT(values[i]->IsLiteralNode()); | 13552 ASSERT(values[i]->IsLiteralNode()); |
| 13548 value_arr.SetAt(i, values[i]->AsLiteralNode()->literal()); | 13553 value_arr.SetAt(i, values[i]->AsLiteralNode()->literal()); |
| 13549 } | 13554 } |
| 13550 | 13555 |
| 13551 // Build argument array to pass to the interpolation function. | 13556 // Build argument array to pass to the interpolation function. |
| 13552 const Array& interpolate_arg = Array::Handle(Z, Array::New(1)); | 13557 const Array& interpolate_arg = Array::Handle(Z, Array::New(1, Heap::kOld)); |
| 13553 interpolate_arg.SetAt(0, value_arr); | 13558 interpolate_arg.SetAt(0, value_arr); |
| 13554 | 13559 |
| 13555 // Call interpolation function. | 13560 // Call interpolation function. |
| 13556 Object& result = Object::Handle(Z); | 13561 Object& result = Object::Handle(Z); |
| 13557 { | 13562 { |
| 13558 PAUSETIMERSCOPE(T, time_compilation); | 13563 PAUSETIMERSCOPE(T, time_compilation); |
| 13559 result = DartEntry::InvokeFunction(func, interpolate_arg); | 13564 result = DartEntry::InvokeFunction(func, interpolate_arg); |
| 13560 } | 13565 } |
| 13561 if (result.IsUnhandledException()) { | 13566 if (result.IsUnhandledException()) { |
| 13562 ReportError("%s", Error::Cast(result).ToErrorCString()); | 13567 ReportError("%s", Error::Cast(result).ToErrorCString()); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13739 // TODO(hausner): Ideally we should generate the NoSuchMethodError | 13744 // TODO(hausner): Ideally we should generate the NoSuchMethodError |
| 13740 // later, when we know more about how the unresolved name is used. | 13745 // later, when we know more about how the unresolved name is used. |
| 13741 // For example, we don't know yet whether the unresolved name | 13746 // For example, we don't know yet whether the unresolved name |
| 13742 // refers to a getter or a setter. However, it is more awkward | 13747 // refers to a getter or a setter. However, it is more awkward |
| 13743 // to distinuish four NoSuchMethodError cases all over the place | 13748 // to distinuish four NoSuchMethodError cases all over the place |
| 13744 // in the parser. The four cases are: prefixed vs non-prefixed | 13749 // in the parser. The four cases are: prefixed vs non-prefixed |
| 13745 // name, static vs dynamic context in which the unresolved name | 13750 // name, static vs dynamic context in which the unresolved name |
| 13746 // is used. We cheat a little here by looking at the next token | 13751 // is used. We cheat a little here by looking at the next token |
| 13747 // to determine whether we have an unresolved method call or | 13752 // to determine whether we have an unresolved method call or |
| 13748 // field access. | 13753 // field access. |
| 13749 String& qualified_name = String::ZoneHandle(Z, prefix.name()); | 13754 GrowableHandlePtrArray<const String> pieces(Z, 3); |
| 13750 qualified_name = String::Concat(qualified_name, Symbols::Dot()); | 13755 pieces.Add(String::Handle(Z, prefix.name())); |
| 13751 qualified_name = Symbols::FromConcat(qualified_name, ident); | 13756 pieces.Add(Symbols::Dot()); |
| 13757 pieces.Add(ident); |
| 13758 const String& qualified_name = String::ZoneHandle(Z, |
| 13759 Symbols::FromConcatAll(pieces)); |
| 13752 InvocationMirror::Type call_type = | 13760 InvocationMirror::Type call_type = |
| 13753 CurrentToken() == Token::kLPAREN ? | 13761 CurrentToken() == Token::kLPAREN ? |
| 13754 InvocationMirror::kMethod : InvocationMirror::kGetter; | 13762 InvocationMirror::kMethod : InvocationMirror::kGetter; |
| 13755 primary = ThrowNoSuchMethodError(qual_ident_pos, | 13763 primary = ThrowNoSuchMethodError(qual_ident_pos, |
| 13756 current_class(), | 13764 current_class(), |
| 13757 qualified_name, | 13765 qualified_name, |
| 13758 NULL, // No arguments. | 13766 NULL, // No arguments. |
| 13759 InvocationMirror::kTopLevel, | 13767 InvocationMirror::kTopLevel, |
| 13760 call_type, | 13768 call_type, |
| 13761 NULL); // No existing function. | 13769 NULL); // No existing function. |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14274 void Parser::SkipQualIdent() { | 14282 void Parser::SkipQualIdent() { |
| 14275 ASSERT(IsIdentifier()); | 14283 ASSERT(IsIdentifier()); |
| 14276 ConsumeToken(); | 14284 ConsumeToken(); |
| 14277 if (CurrentToken() == Token::kPERIOD) { | 14285 if (CurrentToken() == Token::kPERIOD) { |
| 14278 ConsumeToken(); // Consume the kPERIOD token. | 14286 ConsumeToken(); // Consume the kPERIOD token. |
| 14279 ExpectIdentifier("identifier expected after '.'"); | 14287 ExpectIdentifier("identifier expected after '.'"); |
| 14280 } | 14288 } |
| 14281 } | 14289 } |
| 14282 | 14290 |
| 14283 } // namespace dart | 14291 } // namespace dart |
| OLD | NEW |