Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: runtime/vm/parser.cc

Issue 294943008: - Landing https://codereview.chromium.org/293963008/ (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/tags.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 tokens_iterator_.SetCurrentPosition(position); 374 tokens_iterator_.SetCurrentPosition(position);
375 token_kind_ = Token::kILLEGAL; 375 token_kind_ = Token::kILLEGAL;
376 } 376 }
377 377
378 378
379 void Parser::ParseCompilationUnit(const Library& library, 379 void Parser::ParseCompilationUnit(const Library& library,
380 const Script& script) { 380 const Script& script) {
381 Isolate* isolate = Isolate::Current(); 381 Isolate* isolate = Isolate::Current();
382 ASSERT(isolate->long_jump_base()->IsSafeToJump()); 382 ASSERT(isolate->long_jump_base()->IsSafeToJump());
383 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer); 383 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer);
384 VMTagScope tagScope(isolate, VMTag::kCompileTagId); 384 VMTagScope tagScope(isolate, VMTag::kCompileTopLevelTagId);
385 Parser parser(script, library, 0); 385 Parser parser(script, library, 0);
386 parser.ParseTopLevel(); 386 parser.ParseTopLevel();
387 } 387 }
388 388
389 389
390 Token::Kind Parser::CurrentToken() { 390 Token::Kind Parser::CurrentToken() {
391 if (token_kind_ == Token::kILLEGAL) { 391 if (token_kind_ == Token::kILLEGAL) {
392 token_kind_ = tokens_iterator_.CurrentTokenKind(); 392 token_kind_ = tokens_iterator_.CurrentTokenKind();
393 if (token_kind_ == Token::kERROR) { 393 if (token_kind_ == Token::kERROR) {
394 ErrorMsg(TokenPos(), "%s", CurrentLiteral()->ToCString()); 394 ErrorMsg(TokenPos(), "%s", CurrentLiteral()->ToCString());
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 return HasReturnNode(seq->NodeAt(seq->length() - 1)->AsSequenceNode()); 723 return HasReturnNode(seq->NodeAt(seq->length() - 1)->AsSequenceNode());
724 } else { 724 } else {
725 return seq->NodeAt(seq->length() - 1)->IsReturnNode(); 725 return seq->NodeAt(seq->length() - 1)->IsReturnNode();
726 } 726 }
727 } 727 }
728 728
729 729
730 void Parser::ParseClass(const Class& cls) { 730 void Parser::ParseClass(const Class& cls) {
731 if (!cls.is_synthesized_class()) { 731 if (!cls.is_synthesized_class()) {
732 Isolate* isolate = Isolate::Current(); 732 Isolate* isolate = Isolate::Current();
733 VMTagScope tagScope(isolate, VMTag::kCompileTagId);
734 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer); 733 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer);
735 ASSERT(isolate->long_jump_base()->IsSafeToJump()); 734 ASSERT(isolate->long_jump_base()->IsSafeToJump());
736 const Script& script = Script::Handle(isolate, cls.script()); 735 const Script& script = Script::Handle(isolate, cls.script());
737 const Library& lib = Library::Handle(isolate, cls.library()); 736 const Library& lib = Library::Handle(isolate, cls.library());
738 Parser parser(script, lib, cls.token_pos()); 737 Parser parser(script, lib, cls.token_pos());
739 parser.ParseClassDefinition(cls); 738 parser.ParseClassDefinition(cls);
740 } 739 }
741 } 740 }
742 741
743 742
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 isolate->object_store()->clear_sticky_error(); 781 isolate->object_store()->clear_sticky_error();
783 return error.raw(); 782 return error.raw();
784 } 783 }
785 UNREACHABLE(); 784 UNREACHABLE();
786 return Object::null(); 785 return Object::null();
787 } 786 }
788 787
789 788
790 void Parser::ParseFunction(ParsedFunction* parsed_function) { 789 void Parser::ParseFunction(ParsedFunction* parsed_function) {
791 Isolate* isolate = Isolate::Current(); 790 Isolate* isolate = Isolate::Current();
792 VMTagScope tagScope(isolate, VMTag::kCompileTagId);
793 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer); 791 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer);
794 CompilerStats::num_functions_compiled++; 792 CompilerStats::num_functions_compiled++;
795 ASSERT(isolate->long_jump_base()->IsSafeToJump()); 793 ASSERT(isolate->long_jump_base()->IsSafeToJump());
796 ASSERT(parsed_function != NULL); 794 ASSERT(parsed_function != NULL);
797 const Function& func = parsed_function->function(); 795 const Function& func = parsed_function->function();
798 const Script& script = Script::Handle(isolate, func.script()); 796 const Script& script = Script::Handle(isolate, func.script());
799 Parser parser(script, parsed_function, func.token_pos()); 797 Parser parser(script, parsed_function, func.token_pos());
800 SequenceNode* node_sequence = NULL; 798 SequenceNode* node_sequence = NULL;
801 Array& default_parameter_values = Array::ZoneHandle(isolate, Array::null()); 799 Array& default_parameter_values = Array::ZoneHandle(isolate, Array::null());
802 switch (func.kind()) { 800 switch (func.kind()) {
(...skipping 7967 matching lines...) Expand 10 before | Expand all | Expand 10 after
8770 ClassFinalizer::FinalizationKind finalization, 8768 ClassFinalizer::FinalizationKind finalization,
8771 AbstractType* type) { 8769 AbstractType* type) {
8772 ASSERT(finalization >= ClassFinalizer::kResolveTypeParameters); 8770 ASSERT(finalization >= ClassFinalizer::kResolveTypeParameters);
8773 ASSERT(type != NULL); 8771 ASSERT(type != NULL);
8774 if (type->IsResolved()) { 8772 if (type->IsResolved()) {
8775 return; 8773 return;
8776 } 8774 }
8777 // Resolve class. 8775 // Resolve class.
8778 if (!type->HasResolvedTypeClass()) { 8776 if (!type->HasResolvedTypeClass()) {
8779 const UnresolvedClass& unresolved_class = 8777 const UnresolvedClass& unresolved_class =
8780 UnresolvedClass::Handle(type->unresolved_class()); 8778 UnresolvedClass::Handle(isolate(), type->unresolved_class());
8781 const String& unresolved_class_name = 8779 const String& unresolved_class_name =
8782 String::Handle(unresolved_class.ident()); 8780 String::Handle(isolate(), unresolved_class.ident());
8783 Class& resolved_type_class = Class::Handle(); 8781 Class& resolved_type_class = Class::Handle(isolate());
8784 if (unresolved_class.library_prefix() == LibraryPrefix::null()) { 8782 if (unresolved_class.library_prefix() == LibraryPrefix::null()) {
8785 if (!scope_class.IsNull()) { 8783 if (!scope_class.IsNull()) {
8786 // First check if the type is a type parameter of the given scope class. 8784 // First check if the type is a type parameter of the given scope class.
8787 const TypeParameter& type_parameter = TypeParameter::Handle( 8785 const TypeParameter& type_parameter = TypeParameter::Handle(
8786 isolate(),
8788 scope_class.LookupTypeParameter(unresolved_class_name)); 8787 scope_class.LookupTypeParameter(unresolved_class_name));
8789 if (!type_parameter.IsNull()) { 8788 if (!type_parameter.IsNull()) {
8790 // A type parameter is considered to be a malformed type when 8789 // A type parameter is considered to be a malformed type when
8791 // referenced by a static member. 8790 // referenced by a static member.
8792 if (ParsingStaticMember()) { 8791 if (ParsingStaticMember()) {
8793 ASSERT(scope_class.raw() == current_class().raw()); 8792 ASSERT(scope_class.raw() == current_class().raw());
8794 *type = ClassFinalizer::NewFinalizedMalformedType( 8793 *type = ClassFinalizer::NewFinalizedMalformedType(
8795 Error::Handle(), // No previous error. 8794 Error::Handle(isolate()), // No previous error.
8796 script_, 8795 script_,
8797 type->token_pos(), 8796 type->token_pos(),
8798 "type parameter '%s' cannot be referenced " 8797 "type parameter '%s' cannot be referenced "
8799 "from static member", 8798 "from static member",
8800 String::Handle(type_parameter.name()).ToCString()); 8799 String::Handle(isolate(), type_parameter.name()).ToCString());
8801 return; 8800 return;
8802 } 8801 }
8803 // A type parameter cannot be parameterized, so make the type 8802 // A type parameter cannot be parameterized, so make the type
8804 // malformed if type arguments have previously been parsed. 8803 // malformed if type arguments have previously been parsed.
8805 if (!TypeArguments::Handle(type->arguments()).IsNull()) { 8804 if (!TypeArguments::Handle(isolate(), type->arguments()).IsNull()) {
8806 *type = ClassFinalizer::NewFinalizedMalformedType( 8805 *type = ClassFinalizer::NewFinalizedMalformedType(
8807 Error::Handle(), // No previous error. 8806 Error::Handle(isolate()), // No previous error.
8808 script_, 8807 script_,
8809 type_parameter.token_pos(), 8808 type_parameter.token_pos(),
8810 "type parameter '%s' cannot be parameterized", 8809 "type parameter '%s' cannot be parameterized",
8811 String::Handle(type_parameter.name()).ToCString()); 8810 String::Handle(isolate(), type_parameter.name()).ToCString());
8812 return; 8811 return;
8813 } 8812 }
8814 *type = type_parameter.raw(); 8813 *type = type_parameter.raw();
8815 return; 8814 return;
8816 } 8815 }
8817 } 8816 }
8818 // The referenced class may not have been parsed yet. It would be wrong 8817 // The referenced class may not have been parsed yet. It would be wrong
8819 // to resolve it too early to an imported class of the same name. 8818 // to resolve it too early to an imported class of the same name.
8820 if (finalization > ClassFinalizer::kResolveTypeParameters) { 8819 if (finalization > ClassFinalizer::kResolveTypeParameters) {
8821 // Resolve classname in the scope of the current library. 8820 // Resolve classname in the scope of the current library.
8822 resolved_type_class = ResolveClassInCurrentLibraryScope( 8821 resolved_type_class = ResolveClassInCurrentLibraryScope(
8823 unresolved_class_name); 8822 unresolved_class_name);
8824 } 8823 }
8825 } else { 8824 } else {
8826 LibraryPrefix& lib_prefix = 8825 LibraryPrefix& lib_prefix =
8827 LibraryPrefix::Handle(unresolved_class.library_prefix()); 8826 LibraryPrefix::Handle(isolate(), unresolved_class.library_prefix());
8828 // Resolve class name in the scope of the library prefix. 8827 // Resolve class name in the scope of the library prefix.
8829 resolved_type_class = 8828 resolved_type_class =
8830 ResolveClassInPrefixScope(lib_prefix, unresolved_class_name); 8829 ResolveClassInPrefixScope(lib_prefix, unresolved_class_name);
8831 } 8830 }
8832 // At this point, we can only have a parameterized_type. 8831 // At this point, we can only have a parameterized_type.
8833 const Type& parameterized_type = Type::Cast(*type); 8832 const Type& parameterized_type = Type::Cast(*type);
8834 if (!resolved_type_class.IsNull()) { 8833 if (!resolved_type_class.IsNull()) {
8835 // Replace unresolved class with resolved type class. 8834 // Replace unresolved class with resolved type class.
8836 parameterized_type.set_type_class(resolved_type_class); 8835 parameterized_type.set_type_class(resolved_type_class);
8837 } else if (finalization >= ClassFinalizer::kCanonicalize) { 8836 } else if (finalization >= ClassFinalizer::kCanonicalize) {
8838 ClassFinalizer::FinalizeMalformedType( 8837 ClassFinalizer::FinalizeMalformedType(
8839 Error::Handle(), // No previous error. 8838 Error::Handle(isolate()), // No previous error.
8840 script_, 8839 script_,
8841 parameterized_type, 8840 parameterized_type,
8842 "type '%s' is not loaded", 8841 "type '%s' is not loaded",
8843 String::Handle(parameterized_type.UserVisibleName()).ToCString()); 8842 String::Handle(isolate(),
8843 parameterized_type.UserVisibleName()).ToCString());
8844 return; 8844 return;
8845 } 8845 }
8846 } 8846 }
8847 // Resolve type arguments, if any. 8847 // Resolve type arguments, if any.
8848 const TypeArguments& arguments = TypeArguments::Handle(type->arguments()); 8848 const TypeArguments& arguments = TypeArguments::Handle(isolate(),
8849 TypeArguments::Handle(type->arguments()); 8849 type->arguments());
8850 TypeArguments::Handle(isolate(), type->arguments());
8850 if (!arguments.IsNull()) { 8851 if (!arguments.IsNull()) {
8851 const intptr_t num_arguments = arguments.Length(); 8852 const intptr_t num_arguments = arguments.Length();
8852 for (intptr_t i = 0; i < num_arguments; i++) { 8853 for (intptr_t i = 0; i < num_arguments; i++) {
8853 AbstractType& type_argument = AbstractType::Handle(arguments.TypeAt(i)); 8854 AbstractType& type_argument = AbstractType::Handle(isolate(),
8855 arguments.TypeAt(i));
8854 ResolveTypeFromClass(scope_class, finalization, &type_argument); 8856 ResolveTypeFromClass(scope_class, finalization, &type_argument);
8855 arguments.SetTypeAt(i, type_argument); 8857 arguments.SetTypeAt(i, type_argument);
8856 } 8858 }
8857 } 8859 }
8858 } 8860 }
8859 8861
8860 8862
8861 LocalVariable* Parser::LookupLocalScope(const String& ident) { 8863 LocalVariable* Parser::LookupLocalScope(const String& ident) {
8862 if (current_block_ == NULL) { 8864 if (current_block_ == NULL) {
8863 return NULL; 8865 return NULL;
(...skipping 2085 matching lines...) Expand 10 before | Expand all | Expand 10 after
10949 void Parser::SkipQualIdent() { 10951 void Parser::SkipQualIdent() {
10950 ASSERT(IsIdentifier()); 10952 ASSERT(IsIdentifier());
10951 ConsumeToken(); 10953 ConsumeToken();
10952 if (CurrentToken() == Token::kPERIOD) { 10954 if (CurrentToken() == Token::kPERIOD) {
10953 ConsumeToken(); // Consume the kPERIOD token. 10955 ConsumeToken(); // Consume the kPERIOD token.
10954 ExpectIdentifier("identifier expected after '.'"); 10956 ExpectIdentifier("identifier expected after '.'");
10955 } 10957 }
10956 } 10958 }
10957 10959
10958 } // namespace dart 10960 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/tags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698