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 "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 6418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6429 // Calling VM-internal helpers, uses implementation core library. | 6429 // Calling VM-internal helpers, uses implementation core library. |
6430 AstNode* Parser::MakeStaticCall(const String& cls_name, | 6430 AstNode* Parser::MakeStaticCall(const String& cls_name, |
6431 const String& func_name, | 6431 const String& func_name, |
6432 ArgumentListNode* arguments) { | 6432 ArgumentListNode* arguments) { |
6433 const Class& cls = Class::Handle(Library::LookupCoreClass(cls_name)); | 6433 const Class& cls = Class::Handle(Library::LookupCoreClass(cls_name)); |
6434 ASSERT(!cls.IsNull()); | 6434 ASSERT(!cls.IsNull()); |
6435 const Function& func = Function::ZoneHandle( | 6435 const Function& func = Function::ZoneHandle( |
6436 Resolver::ResolveStatic(cls, | 6436 Resolver::ResolveStatic(cls, |
6437 func_name, | 6437 func_name, |
6438 arguments->length(), | 6438 arguments->length(), |
6439 arguments->names(), | 6439 arguments->names())); |
6440 Resolver::kIsQualified)); | |
6441 ASSERT(!func.IsNull()); | 6440 ASSERT(!func.IsNull()); |
6442 return new StaticCallNode(arguments->token_pos(), func, arguments); | 6441 return new StaticCallNode(arguments->token_pos(), func, arguments); |
6443 } | 6442 } |
6444 | 6443 |
6445 | 6444 |
6446 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) { | 6445 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) { |
6447 ArgumentListNode* arguments = new ArgumentListNode(begin); | 6446 ArgumentListNode* arguments = new ArgumentListNode(begin); |
6448 arguments->Add(new LiteralNode(begin, | 6447 arguments->Add(new LiteralNode(begin, |
6449 Integer::ZoneHandle(Integer::New(begin)))); | 6448 Integer::ZoneHandle(Integer::New(begin)))); |
6450 arguments->Add(new LiteralNode(end, | 6449 arguments->Add(new LiteralNode(end, |
(...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7952 intptr_t ident_pos) { | 7951 intptr_t ident_pos) { |
7953 TRACE_PARSER("ParseStaticCall"); | 7952 TRACE_PARSER("ParseStaticCall"); |
7954 const intptr_t call_pos = TokenPos(); | 7953 const intptr_t call_pos = TokenPos(); |
7955 ASSERT(CurrentToken() == Token::kLPAREN); | 7954 ASSERT(CurrentToken() == Token::kLPAREN); |
7956 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); | 7955 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); |
7957 const int num_arguments = arguments->length(); | 7956 const int num_arguments = arguments->length(); |
7958 const Function& func = Function::ZoneHandle( | 7957 const Function& func = Function::ZoneHandle( |
7959 Resolver::ResolveStatic(cls, | 7958 Resolver::ResolveStatic(cls, |
7960 func_name, | 7959 func_name, |
7961 num_arguments, | 7960 num_arguments, |
7962 arguments->names(), | 7961 arguments->names())); |
7963 Resolver::kIsQualified)); | |
7964 if (func.IsNull()) { | 7962 if (func.IsNull()) { |
7965 // Check if there is a static field of the same name, it could be a closure | 7963 // Check if there is a static field of the same name, it could be a closure |
7966 // and so we try and invoke the closure. | 7964 // and so we try and invoke the closure. |
7967 AstNode* closure = NULL; | 7965 AstNode* closure = NULL; |
7968 const Field& field = Field::ZoneHandle(cls.LookupStaticField(func_name)); | 7966 const Field& field = Field::ZoneHandle(cls.LookupStaticField(func_name)); |
7969 Function& func = Function::ZoneHandle(); | 7967 Function& func = Function::ZoneHandle(); |
7970 if (field.IsNull()) { | 7968 if (field.IsNull()) { |
7971 // No field, check if we have an explicit getter function. | 7969 // No field, check if we have an explicit getter function. |
7972 const String& getter_name = | 7970 const String& getter_name = |
7973 String::ZoneHandle(Field::GetterName(func_name)); | 7971 String::ZoneHandle(Field::GetterName(func_name)); |
7974 const int kNumArguments = 0; // no arguments. | 7972 const int kNumArguments = 0; // no arguments. |
7975 func = Resolver::ResolveStatic(cls, | 7973 func = Resolver::ResolveStatic(cls, |
7976 getter_name, | 7974 getter_name, |
7977 kNumArguments, | 7975 kNumArguments, |
7978 Object::empty_array(), | 7976 Object::empty_array()); |
7979 Resolver::kIsQualified); | |
7980 if (!func.IsNull()) { | 7977 if (!func.IsNull()) { |
7981 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter); | 7978 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter); |
7982 EnsureSavedCurrentContext(); | 7979 EnsureSavedCurrentContext(); |
7983 closure = new StaticGetterNode(call_pos, | 7980 closure = new StaticGetterNode(call_pos, |
7984 NULL, | 7981 NULL, |
7985 false, | 7982 false, |
7986 Class::ZoneHandle(cls.raw()), | 7983 Class::ZoneHandle(cls.raw()), |
7987 func_name); | 7984 func_name); |
7988 return new ClosureCallNode(call_pos, closure, arguments); | 7985 return new ClosureCallNode(call_pos, closure, arguments); |
7989 } | 7986 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8077 const Field& field = Field::ZoneHandle(cls.LookupStaticField(field_name)); | 8074 const Field& field = Field::ZoneHandle(cls.LookupStaticField(field_name)); |
8078 Function& func = Function::ZoneHandle(); | 8075 Function& func = Function::ZoneHandle(); |
8079 if (field.IsNull()) { | 8076 if (field.IsNull()) { |
8080 // No field, check if we have an explicit getter function. | 8077 // No field, check if we have an explicit getter function. |
8081 const String& getter_name = | 8078 const String& getter_name = |
8082 String::ZoneHandle(Field::GetterName(field_name)); | 8079 String::ZoneHandle(Field::GetterName(field_name)); |
8083 const int kNumArguments = 0; // no arguments. | 8080 const int kNumArguments = 0; // no arguments. |
8084 func = Resolver::ResolveStatic(cls, | 8081 func = Resolver::ResolveStatic(cls, |
8085 getter_name, | 8082 getter_name, |
8086 kNumArguments, | 8083 kNumArguments, |
8087 Object::empty_array(), | 8084 Object::empty_array()); |
8088 Resolver::kIsQualified); | |
8089 if (func.IsNull()) { | 8085 if (func.IsNull()) { |
8090 // We might be referring to an implicit closure, check to see if | 8086 // We might be referring to an implicit closure, check to see if |
8091 // there is a function of the same name. | 8087 // there is a function of the same name. |
8092 func = cls.LookupStaticFunction(field_name); | 8088 func = cls.LookupStaticFunction(field_name); |
8093 if (!func.IsNull()) { | 8089 if (!func.IsNull()) { |
8094 access = CreateImplicitClosureNode(func, call_pos, NULL); | 8090 access = CreateImplicitClosureNode(func, call_pos, NULL); |
8095 } else { | 8091 } else { |
8096 // No function to closurize found found. | 8092 // No function to closurize found found. |
8097 // This field access may turn out to be a call to the setter. | 8093 // This field access may turn out to be a call to the setter. |
8098 // Create a getter call, which may later be turned into | 8094 // Create a getter call, which may later be turned into |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8648 // This field has not been referenced yet and thus the value has | 8644 // This field has not been referenced yet and thus the value has |
8649 // not been evaluated. If the field is const, call the static getter method | 8645 // not been evaluated. If the field is const, call the static getter method |
8650 // to evaluate the expression and canonicalize the value. | 8646 // to evaluate the expression and canonicalize the value. |
8651 if (field.is_const()) { | 8647 if (field.is_const()) { |
8652 field.set_value(Object::transition_sentinel()); | 8648 field.set_value(Object::transition_sentinel()); |
8653 const int kNumArguments = 0; // no arguments. | 8649 const int kNumArguments = 0; // no arguments. |
8654 const Function& func = | 8650 const Function& func = |
8655 Function::Handle(Resolver::ResolveStatic(field_owner, | 8651 Function::Handle(Resolver::ResolveStatic(field_owner, |
8656 getter_name, | 8652 getter_name, |
8657 kNumArguments, | 8653 kNumArguments, |
8658 Object::empty_array(), | 8654 Object::empty_array())); |
8659 Resolver::kIsQualified)); | |
8660 ASSERT(!func.IsNull()); | 8655 ASSERT(!func.IsNull()); |
8661 ASSERT(func.kind() == RawFunction::kImplicitStaticFinalGetter); | 8656 ASSERT(func.kind() == RawFunction::kImplicitStaticFinalGetter); |
8662 Object& const_value = Object::Handle( | 8657 Object& const_value = Object::Handle( |
8663 DartEntry::InvokeFunction(func, Object::empty_array())); | 8658 DartEntry::InvokeFunction(func, Object::empty_array())); |
8664 if (const_value.IsError()) { | 8659 if (const_value.IsError()) { |
8665 const Error& error = Error::Cast(const_value); | 8660 const Error& error = Error::Cast(const_value); |
8666 if (error.IsUnhandledException()) { | 8661 if (error.IsUnhandledException()) { |
8667 // An exception may not occur in every parse attempt, i.e., the | 8662 // An exception may not occur in every parse attempt, i.e., the |
8668 // generated AST is not deterministic. Therefore mark the function as | 8663 // generated AST is not deterministic. Therefore mark the function as |
8669 // not optimizable. | 8664 // not optimizable. |
(...skipping 1918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10588 void Parser::SkipQualIdent() { | 10583 void Parser::SkipQualIdent() { |
10589 ASSERT(IsIdentifier()); | 10584 ASSERT(IsIdentifier()); |
10590 ConsumeToken(); | 10585 ConsumeToken(); |
10591 if (CurrentToken() == Token::kPERIOD) { | 10586 if (CurrentToken() == Token::kPERIOD) { |
10592 ConsumeToken(); // Consume the kPERIOD token. | 10587 ConsumeToken(); // Consume the kPERIOD token. |
10593 ExpectIdentifier("identifier expected after '.'"); | 10588 ExpectIdentifier("identifier expected after '.'"); |
10594 } | 10589 } |
10595 } | 10590 } |
10596 | 10591 |
10597 } // namespace dart | 10592 } // namespace dart |
OLD | NEW |