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

Side by Side Diff: vm/parser.cc

Issue 11469036: - Create frame work for adding read only handles for symbols in the VM isolate (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years 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 | « vm/handles.h ('k') | vm/symbols.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 "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/compiler_stats.h" 10 #include "vm/compiler_stats.h"
(...skipping 1571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 const Class& super_class = Class::Handle(cls.SuperClass()); 1582 const Class& super_class = Class::Handle(cls.SuperClass());
1583 // Omit the implicit super() if there is no super class (i.e. 1583 // Omit the implicit super() if there is no super class (i.e.
1584 // we're not compiling class Object), or if the super class is an 1584 // we're not compiling class Object), or if the super class is an
1585 // artificially generated "wrapper class" that has no constructor. 1585 // artificially generated "wrapper class" that has no constructor.
1586 if (super_class.IsNull() || 1586 if (super_class.IsNull() ||
1587 (super_class.num_native_fields() > 0 && 1587 (super_class.num_native_fields() > 0 &&
1588 Class::Handle(super_class.SuperClass()).IsObjectClass())) { 1588 Class::Handle(super_class.SuperClass()).IsObjectClass())) {
1589 return; 1589 return;
1590 } 1590 }
1591 String& ctor_name = String::Handle(super_class.Name()); 1591 String& ctor_name = String::Handle(super_class.Name());
1592 String& ctor_suffix = String::Handle(Symbols::Dot()); 1592 ctor_name = String::Concat(ctor_name, Symbols::DotHandle());
1593 ctor_name = String::Concat(ctor_name, ctor_suffix);
1594 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); 1593 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos);
1595 // Implicit 'this' parameter is the first argument. 1594 // Implicit 'this' parameter is the first argument.
1596 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver); 1595 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver);
1597 arguments->Add(implicit_argument); 1596 arguments->Add(implicit_argument);
1598 // Implicit construction phase parameter is second argument. 1597 // Implicit construction phase parameter is second argument.
1599 AstNode* phase_parameter = 1598 AstNode* phase_parameter =
1600 new LiteralNode(supercall_pos, 1599 new LiteralNode(supercall_pos,
1601 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); 1600 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll)));
1602 arguments->Add(phase_parameter); 1601 arguments->Add(phase_parameter);
1603 const Function& super_ctor = Function::ZoneHandle( 1602 const Function& super_ctor = Function::ZoneHandle(
(...skipping 19 matching lines...) Expand all
1623 1622
1624 AstNode* Parser::ParseSuperInitializer(const Class& cls, 1623 AstNode* Parser::ParseSuperInitializer(const Class& cls,
1625 LocalVariable* receiver) { 1624 LocalVariable* receiver) {
1626 TRACE_PARSER("ParseSuperInitializer"); 1625 TRACE_PARSER("ParseSuperInitializer");
1627 ASSERT(CurrentToken() == Token::kSUPER); 1626 ASSERT(CurrentToken() == Token::kSUPER);
1628 const intptr_t supercall_pos = TokenPos(); 1627 const intptr_t supercall_pos = TokenPos();
1629 ConsumeToken(); 1628 ConsumeToken();
1630 const Class& super_class = Class::Handle(cls.SuperClass()); 1629 const Class& super_class = Class::Handle(cls.SuperClass());
1631 ASSERT(!super_class.IsNull()); 1630 ASSERT(!super_class.IsNull());
1632 String& ctor_name = String::Handle(super_class.Name()); 1631 String& ctor_name = String::Handle(super_class.Name());
1633 String& ctor_suffix = String::Handle(Symbols::Dot()); 1632 ctor_name = String::Concat(ctor_name, Symbols::DotHandle());
1634 if (CurrentToken() == Token::kPERIOD) { 1633 if (CurrentToken() == Token::kPERIOD) {
1635 ConsumeToken(); 1634 ConsumeToken();
1636 ctor_suffix = String::Concat( 1635 ctor_name = String::Concat(ctor_name,
1637 ctor_suffix, *ExpectIdentifier("constructor name expected")); 1636 *ExpectIdentifier("constructor name expected"));
1638 } 1637 }
1639 ctor_name = String::Concat(ctor_name, ctor_suffix);
1640 if (CurrentToken() != Token::kLPAREN) { 1638 if (CurrentToken() != Token::kLPAREN) {
1641 ErrorMsg("parameter list expected"); 1639 ErrorMsg("parameter list expected");
1642 } 1640 }
1643 1641
1644 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); 1642 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos);
1645 // 'this' parameter is the first argument to super class constructor. 1643 // 'this' parameter is the first argument to super class constructor.
1646 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver); 1644 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver);
1647 arguments->Add(implicit_argument); 1645 arguments->Add(implicit_argument);
1648 // Second implicit parameter is the construction phase. We optimistically 1646 // Second implicit parameter is the construction phase. We optimistically
1649 // assume that we can execute both the super initializer and the super 1647 // assume that we can execute both the super initializer and the super
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 } 1840 }
1843 1841
1844 1842
1845 void Parser::ParseConstructorRedirection(const Class& cls, 1843 void Parser::ParseConstructorRedirection(const Class& cls,
1846 LocalVariable* receiver) { 1844 LocalVariable* receiver) {
1847 TRACE_PARSER("ParseConstructorRedirection"); 1845 TRACE_PARSER("ParseConstructorRedirection");
1848 ASSERT(CurrentToken() == Token::kTHIS); 1846 ASSERT(CurrentToken() == Token::kTHIS);
1849 const intptr_t call_pos = TokenPos(); 1847 const intptr_t call_pos = TokenPos();
1850 ConsumeToken(); 1848 ConsumeToken();
1851 String& ctor_name = String::Handle(cls.Name()); 1849 String& ctor_name = String::Handle(cls.Name());
1852 String& ctor_suffix = String::Handle(Symbols::Dot());
1853 1850
1851 ctor_name = String::Concat(ctor_name, Symbols::DotHandle());
1854 if (CurrentToken() == Token::kPERIOD) { 1852 if (CurrentToken() == Token::kPERIOD) {
1855 ConsumeToken(); 1853 ConsumeToken();
1856 ctor_suffix = String::Concat( 1854 ctor_name = String::Concat(ctor_name,
1857 ctor_suffix, *ExpectIdentifier("constructor name expected")); 1855 *ExpectIdentifier("constructor name expected"));
1858 } 1856 }
1859 ctor_name = String::Concat(ctor_name, ctor_suffix);
1860 if (CurrentToken() != Token::kLPAREN) { 1857 if (CurrentToken() != Token::kLPAREN) {
1861 ErrorMsg("parameter list expected"); 1858 ErrorMsg("parameter list expected");
1862 } 1859 }
1863 1860
1864 ArgumentListNode* arguments = new ArgumentListNode(call_pos); 1861 ArgumentListNode* arguments = new ArgumentListNode(call_pos);
1865 // 'this' parameter is the first argument to constructor. 1862 // 'this' parameter is the first argument to constructor.
1866 AstNode* implicit_argument = new LoadLocalNode(call_pos, receiver); 1863 AstNode* implicit_argument = new LoadLocalNode(call_pos, receiver);
1867 arguments->Add(implicit_argument); 1864 arguments->Add(implicit_argument);
1868 // Construction phase parameter is second argument. 1865 // Construction phase parameter is second argument.
1869 LocalVariable* phase_param = LookupPhaseParameter(); 1866 LocalVariable* phase_param = LookupPhaseParameter();
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
2534 // Redirected constructor: either this(...) or this.xxx(...). 2531 // Redirected constructor: either this(...) or this.xxx(...).
2535 if (method->params.has_field_initializer) { 2532 if (method->params.has_field_initializer) {
2536 // Constructors that redirect to another constructor must not 2533 // Constructors that redirect to another constructor must not
2537 // initialize any fields using field initializer parameters. 2534 // initialize any fields using field initializer parameters.
2538 ErrorMsg(formal_param_pos, "Redirecting constructor " 2535 ErrorMsg(formal_param_pos, "Redirecting constructor "
2539 "may not use field initializer parameters"); 2536 "may not use field initializer parameters");
2540 } 2537 }
2541 ConsumeToken(); // Colon. 2538 ConsumeToken(); // Colon.
2542 ExpectToken(Token::kTHIS); 2539 ExpectToken(Token::kTHIS);
2543 String& redir_name = String::ZoneHandle( 2540 String& redir_name = String::ZoneHandle(
2544 String::Concat(members->class_name(), 2541 String::Concat(members->class_name(), Symbols::DotHandle()));
2545 String::Handle(Symbols::Dot())));
2546 if (CurrentToken() == Token::kPERIOD) { 2542 if (CurrentToken() == Token::kPERIOD) {
2547 ConsumeToken(); 2543 ConsumeToken();
2548 redir_name = String::Concat(redir_name, 2544 redir_name = String::Concat(redir_name,
2549 *ExpectIdentifier("constructor name expected")); 2545 *ExpectIdentifier("constructor name expected"));
2550 } 2546 }
2551 method->redirect_name = &redir_name; 2547 method->redirect_name = &redir_name;
2552 if (CurrentToken() != Token::kLPAREN) { 2548 if (CurrentToken() != Token::kLPAREN) {
2553 ErrorMsg("'(' expected"); 2549 ErrorMsg("'(' expected");
2554 } 2550 }
2555 SkipToMatchingParenthesis(); 2551 SkipToMatchingParenthesis();
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
2941 member.name_pos)); 2937 member.name_pos));
2942 // The type arguments of the result type are set during finalization. 2938 // The type arguments of the result type are set during finalization.
2943 member.type = &Type::ZoneHandle(Type::New(result_type_class, 2939 member.type = &Type::ZoneHandle(Type::New(result_type_class,
2944 TypeArguments::Handle(), 2940 TypeArguments::Handle(),
2945 member.name_pos)); 2941 member.name_pos));
2946 } else if (member.has_static) { 2942 } else if (member.has_static) {
2947 ErrorMsg(member.name_pos, "constructor cannot be static"); 2943 ErrorMsg(member.name_pos, "constructor cannot be static");
2948 } 2944 }
2949 // We must be dealing with a constructor or named constructor. 2945 // We must be dealing with a constructor or named constructor.
2950 member.kind = RawFunction::kConstructor; 2946 member.kind = RawFunction::kConstructor;
2951 String& ctor_suffix = String::ZoneHandle(Symbols::Dot()); 2947 *member.name = String::Concat(*member.name, Symbols::DotHandle());
2952 if (CurrentToken() == Token::kPERIOD) { 2948 if (CurrentToken() == Token::kPERIOD) {
2953 // Named constructor. 2949 // Named constructor.
2954 ConsumeToken(); 2950 ConsumeToken();
2955 member.constructor_name = ExpectIdentifier("identifier expected"); 2951 member.constructor_name = ExpectIdentifier("identifier expected");
2956 ctor_suffix = String::Concat(ctor_suffix, *member.constructor_name); 2952 *member.name = String::Concat(*member.name, *member.constructor_name);
2957 } 2953 }
2958 *member.name = String::Concat(*member.name, ctor_suffix);
2959 // Ensure that names are symbols. 2954 // Ensure that names are symbols.
2960 *member.name = Symbols::New(*member.name); 2955 *member.name = Symbols::New(*member.name);
2961 if (member.type == NULL) { 2956 if (member.type == NULL) {
2962 ASSERT(!member.has_factory); 2957 ASSERT(!member.has_factory);
2963 // The body of the constructor cannot modify the type arguments of the 2958 // The body of the constructor cannot modify the type arguments of the
2964 // constructed instance, which is passed in as a hidden parameter. 2959 // constructed instance, which is passed in as a hidden parameter.
2965 // Therefore, there is no need to set the result type to be checked. 2960 // Therefore, there is no need to set the result type to be checked.
2966 member.type = &Type::ZoneHandle(Type::DynamicType()); 2961 member.type = &Type::ZoneHandle(Type::DynamicType());
2967 } else { 2962 } else {
2968 // The type can only be already set in the factory case. 2963 // The type can only be already set in the factory case.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
3181 } 3176 }
3182 } 3177 }
3183 } 3178 }
3184 3179
3185 3180
3186 // Add an implicit constructor if no explicit constructor is present. 3181 // Add an implicit constructor if no explicit constructor is present.
3187 void Parser::AddImplicitConstructor(ClassDesc* class_desc) { 3182 void Parser::AddImplicitConstructor(ClassDesc* class_desc) {
3188 // The implicit constructor is unnamed, has no explicit parameter, 3183 // The implicit constructor is unnamed, has no explicit parameter,
3189 // and contains a supercall in the initializer list. 3184 // and contains a supercall in the initializer list.
3190 String& ctor_name = String::ZoneHandle( 3185 String& ctor_name = String::ZoneHandle(
3191 String::Concat(class_desc->class_name(), String::Handle(Symbols::Dot()))); 3186 String::Concat(class_desc->class_name(), Symbols::DotHandle()));
3192 ctor_name = Symbols::New(ctor_name); 3187 ctor_name = Symbols::New(ctor_name);
3193 // The token position for the implicit constructor is the 'class' 3188 // The token position for the implicit constructor is the 'class'
3194 // keyword of the constructor's class. 3189 // keyword of the constructor's class.
3195 Function& ctor = Function::Handle( 3190 Function& ctor = Function::Handle(
3196 Function::New(ctor_name, 3191 Function::New(ctor_name,
3197 RawFunction::kConstructor, 3192 RawFunction::kConstructor,
3198 /* is_static = */ false, 3193 /* is_static = */ false,
3199 /* is_const = */ false, 3194 /* is_const = */ false,
3200 /* is_abstract = */ false, 3195 /* is_abstract = */ false,
3201 /* is_external = */ false, 3196 /* is_external = */ false,
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
4068 CallLibraryTagHandler(kSourceTag, source_pos, canon_url); 4063 CallLibraryTagHandler(kSourceTag, source_pos, canon_url);
4069 } 4064 }
4070 } 4065 }
4071 4066
4072 4067
4073 void Parser::ParseLibraryName() { 4068 void Parser::ParseLibraryName() {
4074 ASSERT(CurrentToken() == Token::kLIBRARY); 4069 ASSERT(CurrentToken() == Token::kLIBRARY);
4075 ConsumeToken(); 4070 ConsumeToken();
4076 String& lib_name = *ExpectIdentifier("library name expected"); 4071 String& lib_name = *ExpectIdentifier("library name expected");
4077 if (CurrentToken() == Token::kPERIOD) { 4072 if (CurrentToken() == Token::kPERIOD) {
4078 const String& dot = String::Handle(Symbols::Dot());
4079 while (CurrentToken() == Token::kPERIOD) { 4073 while (CurrentToken() == Token::kPERIOD) {
4080 ConsumeToken(); 4074 ConsumeToken();
4081 lib_name = String::Concat(lib_name, dot); 4075 lib_name = String::Concat(lib_name, Symbols::DotHandle());
4082 lib_name = String::Concat(lib_name, 4076 lib_name = String::Concat(lib_name,
4083 *ExpectIdentifier("malformed library name")); 4077 *ExpectIdentifier("malformed library name"));
4084 } 4078 }
4085 lib_name = Symbols::New(lib_name); 4079 lib_name = Symbols::New(lib_name);
4086 } 4080 }
4087 library_.SetName(lib_name); 4081 library_.SetName(lib_name);
4088 ExpectSemicolon(); 4082 ExpectSemicolon();
4089 } 4083 }
4090 4084
4091 4085
(...skipping 4777 matching lines...) Expand 10 before | Expand all | Expand 10 after
8869 return primary; 8863 return primary;
8870 } 8864 }
8871 8865
8872 8866
8873 static const String& BuildConstructorName(const String& type_class_name, 8867 static const String& BuildConstructorName(const String& type_class_name,
8874 const String* named_constructor) { 8868 const String* named_constructor) {
8875 // By convention, the static function implementing a named constructor 'C' 8869 // By convention, the static function implementing a named constructor 'C'
8876 // for class 'A' is labeled 'A.C', and the static function implementing the 8870 // for class 'A' is labeled 'A.C', and the static function implementing the
8877 // unnamed constructor for class 'A' is labeled 'A.'. 8871 // unnamed constructor for class 'A' is labeled 'A.'.
8878 // This convention prevents users from explicitly calling constructors. 8872 // This convention prevents users from explicitly calling constructors.
8879 const String& period = String::Handle(Symbols::Dot());
8880 String& constructor_name = 8873 String& constructor_name =
8881 String::Handle(String::Concat(type_class_name, period)); 8874 String::Handle(String::Concat(type_class_name, Symbols::DotHandle()));
8882 if (named_constructor != NULL) { 8875 if (named_constructor != NULL) {
8883 constructor_name = String::Concat(constructor_name, *named_constructor); 8876 constructor_name = String::Concat(constructor_name, *named_constructor);
8884 } 8877 }
8885 return constructor_name; 8878 return constructor_name;
8886 } 8879 }
8887 8880
8888 8881
8889 AstNode* Parser::ParseNewOperator() { 8882 AstNode* Parser::ParseNewOperator() {
8890 TRACE_PARSER("ParseNewOperator"); 8883 TRACE_PARSER("ParseNewOperator");
8891 const intptr_t new_pos = TokenPos(); 8884 const intptr_t new_pos = TokenPos();
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
9706 void Parser::SkipQualIdent() { 9699 void Parser::SkipQualIdent() {
9707 ASSERT(IsIdentifier()); 9700 ASSERT(IsIdentifier());
9708 ConsumeToken(); 9701 ConsumeToken();
9709 if (CurrentToken() == Token::kPERIOD) { 9702 if (CurrentToken() == Token::kPERIOD) {
9710 ConsumeToken(); // Consume the kPERIOD token. 9703 ConsumeToken(); // Consume the kPERIOD token.
9711 ExpectIdentifier("identifier expected after '.'"); 9704 ExpectIdentifier("identifier expected after '.'");
9712 } 9705 }
9713 } 9706 }
9714 9707
9715 } // namespace dart 9708 } // namespace dart
OLDNEW
« no previous file with comments | « vm/handles.h ('k') | vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698