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

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

Issue 24240010: Implement symbol literals in the VM compiler (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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/parser.h ('k') | runtime/vm/scanner.cc » ('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 "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 9560 matching lines...) Expand 10 before | Expand all | Expand 10 after
9571 primary = ParseListLiteral(type_pos, is_const, type_arguments); 9571 primary = ParseListLiteral(type_pos, is_const, type_arguments);
9572 } else if (CurrentToken() == Token::kLBRACE) { 9572 } else if (CurrentToken() == Token::kLBRACE) {
9573 primary = ParseMapLiteral(type_pos, is_const, type_arguments); 9573 primary = ParseMapLiteral(type_pos, is_const, type_arguments);
9574 } else { 9574 } else {
9575 ErrorMsg("unexpected token %s", Token::Str(CurrentToken())); 9575 ErrorMsg("unexpected token %s", Token::Str(CurrentToken()));
9576 } 9576 }
9577 return primary; 9577 return primary;
9578 } 9578 }
9579 9579
9580 9580
9581 AstNode* Parser::ParseSymbolLiteral() {
9582 ASSERT(CurrentToken() == Token::kHASH);
9583 ConsumeToken();
9584 intptr_t symbol_pos = TokenPos();
9585 String& symbol = String::Handle();
9586 if (IsIdentifier()) {
9587 symbol = CurrentLiteral()->raw();
9588 ConsumeToken();
9589 while (CurrentToken() == Token::kPERIOD) {
9590 symbol = String::Concat(symbol, Symbols::Dot());
9591 ConsumeToken();
9592 symbol = String::Concat(symbol,
9593 *ExpectIdentifier("identifier expected"));
9594 }
9595 } else if (Token::CanBeOverloaded(CurrentToken())) {
9596 symbol = String::New(Token::Str(CurrentToken()));
9597 ConsumeToken();
9598 } else {
9599 ErrorMsg("illegal symbol literal");
9600 }
9601 // Lookup class Symbol from collection_dev library and call the
9602 // constructor to create a symbol instance.
9603 const Library& lib = Library::Handle(Library::CollectionDevLibrary());
9604 const Class& symbol_class = Class::Handle(lib.LookupClass(Symbols::Symbol()));
9605 ASSERT(!symbol_class.IsNull());
9606 ArgumentListNode* constr_args = new ArgumentListNode(symbol_pos);
9607 constr_args->Add(new LiteralNode(
9608 symbol_pos, String::ZoneHandle(Symbols::New(symbol))));
9609 const Function& constr = Function::ZoneHandle(
9610 symbol_class.LookupConstructor(Symbols::SymbolCtor()));
9611 ASSERT(!constr.IsNull());
9612 const Object& result = Object::Handle(
9613 EvaluateConstConstructorCall(symbol_class,
9614 TypeArguments::Handle(),
9615 constr,
9616 constr_args));
9617 if (result.IsUnhandledException()) {
9618 return GenerateRethrow(symbol_pos, result);
9619 }
9620 const Instance& instance = Instance::Cast(result);
9621 return new LiteralNode(symbol_pos, Instance::ZoneHandle(instance.raw()));
9622 }
9623
9624
9581 static const String& BuildConstructorName(const String& type_class_name, 9625 static const String& BuildConstructorName(const String& type_class_name,
9582 const String* named_constructor) { 9626 const String* named_constructor) {
9583 // By convention, the static function implementing a named constructor 'C' 9627 // By convention, the static function implementing a named constructor 'C'
9584 // for class 'A' is labeled 'A.C', and the static function implementing the 9628 // for class 'A' is labeled 'A.C', and the static function implementing the
9585 // unnamed constructor for class 'A' is labeled 'A.'. 9629 // unnamed constructor for class 'A' is labeled 'A.'.
9586 // This convention prevents users from explicitly calling constructors. 9630 // This convention prevents users from explicitly calling constructors.
9587 String& constructor_name = 9631 String& constructor_name =
9588 String::Handle(String::Concat(type_class_name, Symbols::Dot())); 9632 String::Handle(String::Concat(type_class_name, Symbols::Dot()));
9589 if (named_constructor != NULL) { 9633 if (named_constructor != NULL) {
9590 constructor_name = String::Concat(constructor_name, *named_constructor); 9634 constructor_name = String::Concat(constructor_name, *named_constructor);
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
10061 primary = ParseCompoundLiteral(); 10105 primary = ParseCompoundLiteral();
10062 } else { 10106 } else {
10063 ConsumeToken(); 10107 ConsumeToken();
10064 primary = ParseNewOperator(Token::kCONST); 10108 primary = ParseNewOperator(Token::kCONST);
10065 } 10109 }
10066 } else if (CurrentToken() == Token::kLT || 10110 } else if (CurrentToken() == Token::kLT ||
10067 CurrentToken() == Token::kLBRACK || 10111 CurrentToken() == Token::kLBRACK ||
10068 CurrentToken() == Token::kINDEX || 10112 CurrentToken() == Token::kINDEX ||
10069 CurrentToken() == Token::kLBRACE) { 10113 CurrentToken() == Token::kLBRACE) {
10070 primary = ParseCompoundLiteral(); 10114 primary = ParseCompoundLiteral();
10115 } else if (CurrentToken() == Token::kHASH) {
10116 primary = ParseSymbolLiteral();
10071 } else if (CurrentToken() == Token::kSUPER) { 10117 } else if (CurrentToken() == Token::kSUPER) {
10072 if (current_function().is_static()) { 10118 if (current_function().is_static()) {
10073 ErrorMsg("cannot access superclass from static method"); 10119 ErrorMsg("cannot access superclass from static method");
10074 } 10120 }
10075 if (current_class().SuperClass() == Class::null()) { 10121 if (current_class().SuperClass() == Class::null()) {
10076 ErrorMsg("class '%s' does not have a superclass", 10122 ErrorMsg("class '%s' does not have a superclass",
10077 String::Handle(current_class().Name()).ToCString()); 10123 String::Handle(current_class().Name()).ToCString());
10078 } 10124 }
10079 if (current_class().IsMixinApplication()) { 10125 if (current_class().IsMixinApplication()) {
10080 const Type& mixin_type = Type::Handle(current_class().mixin()); 10126 const Type& mixin_type = Type::Handle(current_class().mixin());
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
10442 void Parser::SkipQualIdent() { 10488 void Parser::SkipQualIdent() {
10443 ASSERT(IsIdentifier()); 10489 ASSERT(IsIdentifier());
10444 ConsumeToken(); 10490 ConsumeToken();
10445 if (CurrentToken() == Token::kPERIOD) { 10491 if (CurrentToken() == Token::kPERIOD) {
10446 ConsumeToken(); // Consume the kPERIOD token. 10492 ConsumeToken(); // Consume the kPERIOD token.
10447 ExpectIdentifier("identifier expected after '.'"); 10493 ExpectIdentifier("identifier expected after '.'");
10448 } 10494 }
10449 } 10495 }
10450 10496
10451 } // namespace dart 10497 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/scanner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698