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

Side by Side Diff: vm/parser.cc

Issue 11667012: Convert all symbols accessor to return read only handles so that it is not necessary to create a ne… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 years, 12 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
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 stack_trace ^= Object::Clone(stack_trace, Heap::kOld); 108 stack_trace ^= Object::Clone(stack_trace, Heap::kOld);
109 } 109 }
110 return new ThrowNode(token_pos, 110 return new ThrowNode(token_pos,
111 new LiteralNode(token_pos, exception), 111 new LiteralNode(token_pos, exception),
112 new LiteralNode(token_pos, stack_trace)); 112 new LiteralNode(token_pos, stack_trace));
113 } 113 }
114 114
115 115
116 LocalVariable* ParsedFunction::CreateExpressionTempVar(intptr_t token_pos) { 116 LocalVariable* ParsedFunction::CreateExpressionTempVar(intptr_t token_pos) {
117 return new LocalVariable(token_pos, 117 return new LocalVariable(token_pos,
118 String::ZoneHandle(Symbols::ExprTemp()), 118 Symbols::ExprTemp(),
119 Type::ZoneHandle(Type::DynamicType())); 119 Type::ZoneHandle(Type::DynamicType()));
120 } 120 }
121 121
122 122
123 void ParsedFunction::SetNodeSequence(SequenceNode* node_sequence) { 123 void ParsedFunction::SetNodeSequence(SequenceNode* node_sequence) {
124 ASSERT(node_sequence_ == NULL); 124 ASSERT(node_sequence_ == NULL);
125 ASSERT(node_sequence != NULL); 125 ASSERT(node_sequence != NULL);
126 node_sequence_ = node_sequence; 126 node_sequence_ = node_sequence;
127 } 127 }
128 128
129 129
130 LocalVariable* ParsedFunction::GetSavedArgumentsDescriptorVar() const { 130 LocalVariable* ParsedFunction::GetSavedArgumentsDescriptorVar() const {
131 const int num_parameters = function().NumParameters(); 131 const int num_parameters = function().NumParameters();
132 LocalScope* scope = node_sequence()->scope(); 132 LocalScope* scope = node_sequence()->scope();
133 if (scope->num_variables() > num_parameters) { 133 if (scope->num_variables() > num_parameters) {
134 LocalVariable* saved_args_desc_var = scope->VariableAt(num_parameters); 134 LocalVariable* saved_args_desc_var = scope->VariableAt(num_parameters);
135 ASSERT(saved_args_desc_var != NULL); 135 ASSERT(saved_args_desc_var != NULL);
136 // The scope of the formal parameters may also contain at this position 136 // The scope of the formal parameters may also contain at this position
137 // an alias for the saved arguments descriptor variable of the enclosing 137 // an alias for the saved arguments descriptor variable of the enclosing
138 // function (check its scope owner) or an internal variable such as the 138 // function (check its scope owner) or an internal variable such as the
139 // expression temp variable or the saved entry context variable (check its 139 // expression temp variable or the saved entry context variable (check its
140 // name). 140 // name).
141 if ((saved_args_desc_var->owner() == scope) && 141 if ((saved_args_desc_var->owner() == scope) &&
142 saved_args_desc_var->name().StartsWith( 142 saved_args_desc_var->name().StartsWith(
143 String::Handle(Symbols::SavedArgDescVarPrefix()))) { 143 Symbols::SavedArgDescVarPrefix())) {
144 return saved_args_desc_var; 144 return saved_args_desc_var;
145 } 145 }
146 } 146 }
147 return NULL; 147 return NULL;
148 } 148 }
149 149
150 150
151 void ParsedFunction::AllocateVariables() { 151 void ParsedFunction::AllocateVariables() {
152 LocalScope* scope = node_sequence()->scope(); 152 LocalScope* scope = node_sequence()->scope();
153 const intptr_t num_fixed_params = function().num_fixed_parameters(); 153 const intptr_t num_fixed_params = function().num_fixed_parameters();
(...skipping 29 matching lines...) Expand all
183 scope->AllocateVariables(first_parameter_index_, 183 scope->AllocateVariables(first_parameter_index_,
184 num_params, 184 num_params,
185 first_stack_local_index_, 185 first_stack_local_index_,
186 scope, 186 scope,
187 &context_owner); 187 &context_owner);
188 188
189 // If this function is not a closure function and if it contains captured 189 // If this function is not a closure function and if it contains captured
190 // variables, the context needs to be saved on entry and restored on exit. 190 // variables, the context needs to be saved on entry and restored on exit.
191 // Add and allocate a local variable to this purpose. 191 // Add and allocate a local variable to this purpose.
192 if ((context_owner != NULL) && !function().IsClosureFunction()) { 192 if ((context_owner != NULL) && !function().IsClosureFunction()) {
193 const String& context_var_name =
194 String::ZoneHandle(Symbols::SavedEntryContextVar());
195 LocalVariable* context_var = 193 LocalVariable* context_var =
196 new LocalVariable(function().token_pos(), 194 new LocalVariable(function().token_pos(),
197 context_var_name, 195 Symbols::SavedEntryContextVar(),
198 Type::ZoneHandle(Type::DynamicType())); 196 Type::ZoneHandle(Type::DynamicType()));
199 context_var->set_index(next_free_frame_index--); 197 context_var->set_index(next_free_frame_index--);
200 scope->AddVariable(context_var); 198 scope->AddVariable(context_var);
201 set_saved_context_var(context_var); 199 set_saved_context_var(context_var);
202 } 200 }
203 201
204 // Frame indices are relative to the frame pointer and are decreasing. 202 // Frame indices are relative to the frame pointer and are decreasing.
205 ASSERT(next_free_frame_index <= first_stack_local_index_); 203 ASSERT(next_free_frame_index <= first_stack_local_index_);
206 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index; 204 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index;
207 } 205 }
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 param.name_pos = name_pos; 440 param.name_pos = name_pos;
443 param.name = name; 441 param.name = name;
444 param.is_final = true; 442 param.is_final = true;
445 param.type = type; 443 param.type = type;
446 this->parameters->Add(param); 444 this->parameters->Add(param);
447 } 445 }
448 446
449 void AddReceiver(const Type* receiver_type) { 447 void AddReceiver(const Type* receiver_type) {
450 ASSERT(this->parameters->is_empty()); 448 ASSERT(this->parameters->is_empty());
451 AddFinalParameter(receiver_type->token_pos(), 449 AddFinalParameter(receiver_type->token_pos(),
452 &Symbols::ThisHandle(), 450 &Symbols::This(),
453 receiver_type); 451 receiver_type);
454 } 452 }
455 453
456 void SetImplicitlyFinal() { 454 void SetImplicitlyFinal() {
457 implicitly_final = true; 455 implicitly_final = true;
458 } 456 }
459 457
460 int num_fixed_parameters; 458 int num_fixed_parameters;
461 int num_optional_parameters; 459 int num_optional_parameters;
462 bool has_optional_positional_parameters; 460 bool has_optional_positional_parameters;
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 const String& field_name = *CurrentLiteral(); 948 const String& field_name = *CurrentLiteral();
951 const Class& field_class = Class::ZoneHandle(func.Owner()); 949 const Class& field_class = Class::ZoneHandle(func.Owner());
952 const Field& field = 950 const Field& field =
953 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); 951 Field::ZoneHandle(field_class.LookupInstanceField(field_name));
954 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); 952 const AbstractType& field_type = AbstractType::ZoneHandle(field.type());
955 953
956 ParamList params; 954 ParamList params;
957 ASSERT(current_class().raw() == func.Owner()); 955 ASSERT(current_class().raw() == func.Owner());
958 params.AddReceiver(ReceiverType(TokenPos())); 956 params.AddReceiver(ReceiverType(TokenPos()));
959 params.AddFinalParameter(TokenPos(), 957 params.AddFinalParameter(TokenPos(),
960 &String::ZoneHandle(Symbols::Value()), 958 &Symbols::Value(),
961 &field_type); 959 &field_type);
962 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. 960 ASSERT(func.num_fixed_parameters() == 2); // receiver, value.
963 ASSERT(!func.HasOptionalParameters()); 961 ASSERT(!func.HasOptionalParameters());
964 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType()); 962 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType());
965 963
966 // Build local scope for function and populate with the formal parameters. 964 // Build local scope for function and populate with the formal parameters.
967 OpenFunctionBlock(func); 965 OpenFunctionBlock(func);
968 AddFormalParamsToScope(&params, current_block_->scope); 966 AddFormalParamsToScope(&params, current_block_->scope);
969 967
970 LoadLocalNode* receiver = 968 LoadLocalNode* receiver =
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 // The parsed parameter type is actually the function result type. 1113 // The parsed parameter type is actually the function result type.
1116 const AbstractType& result_type = 1114 const AbstractType& result_type =
1117 AbstractType::Handle(parameter.type->raw()); 1115 AbstractType::Handle(parameter.type->raw());
1118 1116
1119 // Finish parsing the function type parameter. 1117 // Finish parsing the function type parameter.
1120 ParamList func_params; 1118 ParamList func_params;
1121 1119
1122 // Add implicit closure object parameter. 1120 // Add implicit closure object parameter.
1123 func_params.AddFinalParameter( 1121 func_params.AddFinalParameter(
1124 TokenPos(), 1122 TokenPos(),
1125 &String::ZoneHandle(Symbols::ClosureParameter()), 1123 &Symbols::ClosureParameter(),
1126 &Type::ZoneHandle(Type::DynamicType())); 1124 &Type::ZoneHandle(Type::DynamicType()));
1127 1125
1128 const bool no_explicit_default_values = false; 1126 const bool no_explicit_default_values = false;
1129 ParseFormalParameterList(no_explicit_default_values, &func_params); 1127 ParseFormalParameterList(no_explicit_default_values, &func_params);
1130 1128
1131 // The field 'is_static' has no meaning for signature functions. 1129 // The field 'is_static' has no meaning for signature functions.
1132 const Function& signature_function = Function::Handle( 1130 const Function& signature_function = Function::Handle(
1133 Function::New(*parameter.name, 1131 Function::New(*parameter.name,
1134 RawFunction::kSignatureFunction, 1132 RawFunction::kSignatureFunction,
1135 /* is_static = */ false, 1133 /* is_static = */ false,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 } 1290 }
1293 Function& super_func = 1291 Function& super_func =
1294 Function::Handle(Resolver::ResolveDynamicAnyArgs(super_class, name)); 1292 Function::Handle(Resolver::ResolveDynamicAnyArgs(super_class, name));
1295 if (super_func.IsNull() && resolve_getter) { 1293 if (super_func.IsNull() && resolve_getter) {
1296 const String& getter_name = String::ZoneHandle(Field::GetterName(name)); 1294 const String& getter_name = String::ZoneHandle(Field::GetterName(name));
1297 super_func = Resolver::ResolveDynamicAnyArgs(super_class, getter_name); 1295 super_func = Resolver::ResolveDynamicAnyArgs(super_class, getter_name);
1298 ASSERT(super_func.IsNull() || 1296 ASSERT(super_func.IsNull() ||
1299 (super_func.kind() != RawFunction::kConstImplicitGetter)); 1297 (super_func.kind() != RawFunction::kConstImplicitGetter));
1300 } 1298 }
1301 if (super_func.IsNull()) { 1299 if (super_func.IsNull()) {
1302 const String& no_such_method_name = String::Handle(Symbols::NoSuchMethod());
1303 super_func = 1300 super_func =
1304 Resolver::ResolveDynamicAnyArgs(super_class, no_such_method_name); 1301 Resolver::ResolveDynamicAnyArgs(super_class, Symbols::NoSuchMethod());
1305 ASSERT(!super_func.IsNull()); 1302 ASSERT(!super_func.IsNull());
1306 *is_no_such_method = true; 1303 *is_no_such_method = true;
1307 } else { 1304 } else {
1308 *is_no_such_method = false; 1305 *is_no_such_method = false;
1309 } 1306 }
1310 return super_func.raw(); 1307 return super_func.raw();
1311 } 1308 }
1312 1309
1313 1310
1314 // Lookup class in the core lib which also contains various VM 1311 // Lookup class in the core lib which also contains various VM
(...skipping 27 matching lines...) Expand all
1342 arguments->Add(new LiteralNode(args_pos, args_descriptor)); 1339 arguments->Add(new LiteralNode(args_pos, args_descriptor));
1343 // The third argument is an array containing the original function arguments, 1340 // The third argument is an array containing the original function arguments,
1344 // including the receiver. 1341 // including the receiver.
1345 ArrayNode* args_array = new ArrayNode( 1342 ArrayNode* args_array = new ArrayNode(
1346 args_pos, Type::ZoneHandle(Type::ArrayType())); 1343 args_pos, Type::ZoneHandle(Type::ArrayType()));
1347 for (intptr_t i = 0; i < function_args.length(); i++) { 1344 for (intptr_t i = 0; i < function_args.length(); i++) {
1348 args_array->AddElement(function_args.NodeAt(i)); 1345 args_array->AddElement(function_args.NodeAt(i));
1349 } 1346 }
1350 arguments->Add(args_array); 1347 arguments->Add(args_array);
1351 // Lookup the static InvocationMirror._allocateInvocationMirror method. 1348 // Lookup the static InvocationMirror._allocateInvocationMirror method.
1352 const Class& mirror_class = Class::Handle( 1349 const Class& mirror_class =
1353 LookupCoreClass(String::Handle(Symbols::InvocationMirror()))); 1350 Class::Handle(LookupCoreClass(Symbols::InvocationMirror()));
1354 ASSERT(!mirror_class.IsNull()); 1351 ASSERT(!mirror_class.IsNull());
1355 const String& allocation_function_name =
1356 String::Handle(Symbols::AllocateInvocationMirror());
1357 const Function& allocation_function = Function::ZoneHandle( 1352 const Function& allocation_function = Function::ZoneHandle(
1358 mirror_class.LookupStaticFunction(allocation_function_name)); 1353 mirror_class.LookupStaticFunction(Symbols::AllocateInvocationMirror()));
1359 ASSERT(!allocation_function.IsNull()); 1354 ASSERT(!allocation_function.IsNull());
1360 return new StaticCallNode(call_pos, allocation_function, arguments); 1355 return new StaticCallNode(call_pos, allocation_function, arguments);
1361 } 1356 }
1362 1357
1363 1358
1364 ArgumentListNode* Parser::BuildNoSuchMethodArguments( 1359 ArgumentListNode* Parser::BuildNoSuchMethodArguments(
1365 intptr_t call_pos, 1360 intptr_t call_pos,
1366 const String& function_name, 1361 const String& function_name,
1367 const ArgumentListNode& function_args) { 1362 const ArgumentListNode& function_args) {
1368 ASSERT(function_args.length() >= 1); // The receiver is the first argument. 1363 ASSERT(function_args.length() >= 1); // The receiver is the first argument.
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 const Class& super_class = Class::Handle(cls.SuperClass()); 1580 const Class& super_class = Class::Handle(cls.SuperClass());
1586 // Omit the implicit super() if there is no super class (i.e. 1581 // Omit the implicit super() if there is no super class (i.e.
1587 // we're not compiling class Object), or if the super class is an 1582 // we're not compiling class Object), or if the super class is an
1588 // artificially generated "wrapper class" that has no constructor. 1583 // artificially generated "wrapper class" that has no constructor.
1589 if (super_class.IsNull() || 1584 if (super_class.IsNull() ||
1590 (super_class.num_native_fields() > 0 && 1585 (super_class.num_native_fields() > 0 &&
1591 Class::Handle(super_class.SuperClass()).IsObjectClass())) { 1586 Class::Handle(super_class.SuperClass()).IsObjectClass())) {
1592 return; 1587 return;
1593 } 1588 }
1594 String& ctor_name = String::Handle(super_class.Name()); 1589 String& ctor_name = String::Handle(super_class.Name());
1595 ctor_name = String::Concat(ctor_name, Symbols::DotHandle()); 1590 ctor_name = String::Concat(ctor_name, Symbols::Dot());
1596 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); 1591 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos);
1597 // Implicit 'this' parameter is the first argument. 1592 // Implicit 'this' parameter is the first argument.
1598 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver); 1593 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver);
1599 arguments->Add(implicit_argument); 1594 arguments->Add(implicit_argument);
1600 // Implicit construction phase parameter is second argument. 1595 // Implicit construction phase parameter is second argument.
1601 AstNode* phase_parameter = 1596 AstNode* phase_parameter =
1602 new LiteralNode(supercall_pos, 1597 new LiteralNode(supercall_pos,
1603 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); 1598 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll)));
1604 arguments->Add(phase_parameter); 1599 arguments->Add(phase_parameter);
1605 const Function& super_ctor = Function::ZoneHandle( 1600 const Function& super_ctor = Function::ZoneHandle(
(...skipping 19 matching lines...) Expand all
1625 1620
1626 AstNode* Parser::ParseSuperInitializer(const Class& cls, 1621 AstNode* Parser::ParseSuperInitializer(const Class& cls,
1627 LocalVariable* receiver) { 1622 LocalVariable* receiver) {
1628 TRACE_PARSER("ParseSuperInitializer"); 1623 TRACE_PARSER("ParseSuperInitializer");
1629 ASSERT(CurrentToken() == Token::kSUPER); 1624 ASSERT(CurrentToken() == Token::kSUPER);
1630 const intptr_t supercall_pos = TokenPos(); 1625 const intptr_t supercall_pos = TokenPos();
1631 ConsumeToken(); 1626 ConsumeToken();
1632 const Class& super_class = Class::Handle(cls.SuperClass()); 1627 const Class& super_class = Class::Handle(cls.SuperClass());
1633 ASSERT(!super_class.IsNull()); 1628 ASSERT(!super_class.IsNull());
1634 String& ctor_name = String::Handle(super_class.Name()); 1629 String& ctor_name = String::Handle(super_class.Name());
1635 ctor_name = String::Concat(ctor_name, Symbols::DotHandle()); 1630 ctor_name = String::Concat(ctor_name, Symbols::Dot());
1636 if (CurrentToken() == Token::kPERIOD) { 1631 if (CurrentToken() == Token::kPERIOD) {
1637 ConsumeToken(); 1632 ConsumeToken();
1638 ctor_name = String::Concat(ctor_name, 1633 ctor_name = String::Concat(ctor_name,
1639 *ExpectIdentifier("constructor name expected")); 1634 *ExpectIdentifier("constructor name expected"));
1640 } 1635 }
1641 if (CurrentToken() != Token::kLPAREN) { 1636 if (CurrentToken() != Token::kLPAREN) {
1642 ErrorMsg("parameter list expected"); 1637 ErrorMsg("parameter list expected");
1643 } 1638 }
1644 1639
1645 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); 1640 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 1839
1845 1840
1846 void Parser::ParseConstructorRedirection(const Class& cls, 1841 void Parser::ParseConstructorRedirection(const Class& cls,
1847 LocalVariable* receiver) { 1842 LocalVariable* receiver) {
1848 TRACE_PARSER("ParseConstructorRedirection"); 1843 TRACE_PARSER("ParseConstructorRedirection");
1849 ASSERT(CurrentToken() == Token::kTHIS); 1844 ASSERT(CurrentToken() == Token::kTHIS);
1850 const intptr_t call_pos = TokenPos(); 1845 const intptr_t call_pos = TokenPos();
1851 ConsumeToken(); 1846 ConsumeToken();
1852 String& ctor_name = String::Handle(cls.Name()); 1847 String& ctor_name = String::Handle(cls.Name());
1853 1848
1854 ctor_name = String::Concat(ctor_name, Symbols::DotHandle()); 1849 ctor_name = String::Concat(ctor_name, Symbols::Dot());
1855 if (CurrentToken() == Token::kPERIOD) { 1850 if (CurrentToken() == Token::kPERIOD) {
1856 ConsumeToken(); 1851 ConsumeToken();
1857 ctor_name = String::Concat(ctor_name, 1852 ctor_name = String::Concat(ctor_name,
1858 *ExpectIdentifier("constructor name expected")); 1853 *ExpectIdentifier("constructor name expected"));
1859 } 1854 }
1860 if (CurrentToken() != Token::kLPAREN) { 1855 if (CurrentToken() != Token::kLPAREN) {
1861 ErrorMsg("parameter list expected"); 1856 ErrorMsg("parameter list expected");
1862 } 1857 }
1863 1858
1864 ArgumentListNode* arguments = new ArgumentListNode(call_pos); 1859 ArgumentListNode* arguments = new ArgumentListNode(call_pos);
(...skipping 28 matching lines...) Expand all
1893 } 1888 }
1894 1889
1895 1890
1896 SequenceNode* Parser::MakeImplicitConstructor(const Function& func) { 1891 SequenceNode* Parser::MakeImplicitConstructor(const Function& func) {
1897 ASSERT(func.IsConstructor()); 1892 ASSERT(func.IsConstructor());
1898 const intptr_t ctor_pos = TokenPos(); 1893 const intptr_t ctor_pos = TokenPos();
1899 OpenFunctionBlock(func); 1894 OpenFunctionBlock(func);
1900 const Class& cls = Class::Handle(func.Owner()); 1895 const Class& cls = Class::Handle(func.Owner());
1901 LocalVariable* receiver = new LocalVariable( 1896 LocalVariable* receiver = new LocalVariable(
1902 ctor_pos, 1897 ctor_pos,
1903 Symbols::ThisHandle(), 1898 Symbols::This(),
1904 Type::ZoneHandle(Type::DynamicType())); 1899 Type::ZoneHandle(Type::DynamicType()));
1905 current_block_->scope->AddVariable(receiver); 1900 current_block_->scope->AddVariable(receiver);
1906 1901
1907 LocalVariable* phase_parameter = new LocalVariable( 1902 LocalVariable* phase_parameter = new LocalVariable(
1908 ctor_pos, 1903 ctor_pos,
1909 String::ZoneHandle(Symbols::PhaseParameter()), 1904 Symbols::PhaseParameter(),
1910 Type::ZoneHandle(Type::SmiType())); 1905 Type::ZoneHandle(Type::SmiType()));
1911 current_block_->scope->AddVariable(phase_parameter); 1906 current_block_->scope->AddVariable(phase_parameter);
1912 1907
1913 // Parse expressions of instance fields that have an explicit 1908 // Parse expressions of instance fields that have an explicit
1914 // initializer expression. 1909 // initializer expression.
1915 // The receiver must not be visible to field initializer expressions. 1910 // The receiver must not be visible to field initializer expressions.
1916 receiver->set_invisible(true); 1911 receiver->set_invisible(true);
1917 GrowableArray<Field*> initialized_fields; 1912 GrowableArray<Field*> initialized_fields;
1918 ParseInitializedInstanceFields(cls, receiver, &initialized_fields); 1913 ParseInitializedInstanceFields(cls, receiver, &initialized_fields);
1919 receiver->set_invisible(false); 1914 receiver->set_invisible(false);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 ASSERT(CurrentToken() == Token::kLPAREN); 1962 ASSERT(CurrentToken() == Token::kLPAREN);
1968 1963
1969 // Add implicit receiver parameter which is passed the allocated 1964 // Add implicit receiver parameter which is passed the allocated
1970 // but uninitialized instance to construct. 1965 // but uninitialized instance to construct.
1971 ASSERT(current_class().raw() == func.Owner()); 1966 ASSERT(current_class().raw() == func.Owner());
1972 params.AddReceiver(ReceiverType(TokenPos())); 1967 params.AddReceiver(ReceiverType(TokenPos()));
1973 1968
1974 // Add implicit parameter for construction phase. 1969 // Add implicit parameter for construction phase.
1975 params.AddFinalParameter( 1970 params.AddFinalParameter(
1976 TokenPos(), 1971 TokenPos(),
1977 &String::ZoneHandle(Symbols::PhaseParameter()), 1972 &Symbols::PhaseParameter(),
1978 &Type::ZoneHandle(Type::SmiType())); 1973 &Type::ZoneHandle(Type::SmiType()));
1979 1974
1980 if (func.is_const()) { 1975 if (func.is_const()) {
1981 params.SetImplicitlyFinal(); 1976 params.SetImplicitlyFinal();
1982 } 1977 }
1983 ParseFormalParameterList(allow_explicit_default_values, &params); 1978 ParseFormalParameterList(allow_explicit_default_values, &params);
1984 1979
1985 SetupDefaultsForOptionalParams(&params, default_parameter_values); 1980 SetupDefaultsForOptionalParams(&params, default_parameter_values);
1986 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); 1981 ASSERT(AbstractType::Handle(func.result_type()).IsResolved());
1987 ASSERT(func.NumParameters() == params.parameters->length()); 1982 ASSERT(func.NumParameters() == params.parameters->length());
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
2215 OpenFunctionBlock(func); // Build local scope for function. 2210 OpenFunctionBlock(func); // Build local scope for function.
2216 2211
2217 ParamList params; 2212 ParamList params;
2218 // An instance closure function may capture and access the receiver, but via 2213 // An instance closure function may capture and access the receiver, but via
2219 // the context and not via the first formal parameter. 2214 // the context and not via the first formal parameter.
2220 if (func.IsClosureFunction()) { 2215 if (func.IsClosureFunction()) {
2221 // The first parameter of a closure function is the closure object. 2216 // The first parameter of a closure function is the closure object.
2222 ASSERT(!func.is_const()); // Closure functions cannot be const. 2217 ASSERT(!func.is_const()); // Closure functions cannot be const.
2223 params.AddFinalParameter( 2218 params.AddFinalParameter(
2224 TokenPos(), 2219 TokenPos(),
2225 &String::ZoneHandle(Symbols::ClosureParameter()), 2220 &Symbols::ClosureParameter(),
2226 &Type::ZoneHandle(Type::DynamicType())); 2221 &Type::ZoneHandle(Type::DynamicType()));
2227 } else if (!func.is_static()) { 2222 } else if (!func.is_static()) {
2228 // Static functions do not have a receiver. 2223 // Static functions do not have a receiver.
2229 ASSERT(current_class().raw() == func.Owner()); 2224 ASSERT(current_class().raw() == func.Owner());
2230 params.AddReceiver(ReceiverType(TokenPos())); 2225 params.AddReceiver(ReceiverType(TokenPos()));
2231 } else if (func.IsFactory()) { 2226 } else if (func.IsFactory()) {
2232 // The first parameter of a factory is the AbstractTypeArguments vector of 2227 // The first parameter of a factory is the AbstractTypeArguments vector of
2233 // the type of the instance to be allocated. 2228 // the type of the instance to be allocated.
2234 params.AddFinalParameter( 2229 params.AddFinalParameter(
2235 TokenPos(), 2230 TokenPos(),
2236 &String::ZoneHandle(Symbols::TypeArgumentsParameter()), 2231 &Symbols::TypeArgumentsParameter(),
2237 &Type::ZoneHandle(Type::DynamicType())); 2232 &Type::ZoneHandle(Type::DynamicType()));
2238 } 2233 }
2239 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction()); 2234 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction());
2240 const bool allow_explicit_default_values = true; 2235 const bool allow_explicit_default_values = true;
2241 if (!func.IsGetterFunction()) { 2236 if (!func.IsGetterFunction()) {
2242 ParseFormalParameterList(allow_explicit_default_values, &params); 2237 ParseFormalParameterList(allow_explicit_default_values, &params);
2243 } else { 2238 } else {
2244 // TODO(hausner): Remove this once we no longer support the old 2239 // TODO(hausner): Remove this once we no longer support the old
2245 // getter syntax with explicit empty parameter list. 2240 // getter syntax with explicit empty parameter list.
2246 if (CurrentToken() == Token::kLPAREN) { 2241 if (CurrentToken() == Token::kLPAREN) {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
2433 const intptr_t formal_param_pos = TokenPos(); 2428 const intptr_t formal_param_pos = TokenPos();
2434 method->params.Clear(); 2429 method->params.Clear();
2435 // Static functions do not have a receiver. 2430 // Static functions do not have a receiver.
2436 // The first parameter of a factory is the AbstractTypeArguments vector of 2431 // The first parameter of a factory is the AbstractTypeArguments vector of
2437 // the type of the instance to be allocated. 2432 // the type of the instance to be allocated.
2438 if (!method->has_static || method->IsConstructor()) { 2433 if (!method->has_static || method->IsConstructor()) {
2439 method->params.AddReceiver(ReceiverType(formal_param_pos)); 2434 method->params.AddReceiver(ReceiverType(formal_param_pos));
2440 } else if (method->IsFactory()) { 2435 } else if (method->IsFactory()) {
2441 method->params.AddFinalParameter( 2436 method->params.AddFinalParameter(
2442 formal_param_pos, 2437 formal_param_pos,
2443 &String::ZoneHandle(Symbols::TypeArgumentsParameter()), 2438 &Symbols::TypeArgumentsParameter(),
2444 &Type::ZoneHandle(Type::DynamicType())); 2439 &Type::ZoneHandle(Type::DynamicType()));
2445 } 2440 }
2446 // Constructors have an implicit parameter for the construction phase. 2441 // Constructors have an implicit parameter for the construction phase.
2447 if (method->IsConstructor()) { 2442 if (method->IsConstructor()) {
2448 method->params.AddFinalParameter( 2443 method->params.AddFinalParameter(
2449 TokenPos(), 2444 TokenPos(),
2450 &String::ZoneHandle(Symbols::PhaseParameter()), 2445 &Symbols::PhaseParameter(),
2451 &Type::ZoneHandle(Type::SmiType())); 2446 &Type::ZoneHandle(Type::SmiType()));
2452 } 2447 }
2453 if (are_implicitly_final) { 2448 if (are_implicitly_final) {
2454 method->params.SetImplicitlyFinal(); 2449 method->params.SetImplicitlyFinal();
2455 } 2450 }
2456 if (!method->IsGetter()) { 2451 if (!method->IsGetter()) {
2457 ParseFormalParameterList(allow_explicit_default_values, &method->params); 2452 ParseFormalParameterList(allow_explicit_default_values, &method->params);
2458 } 2453 }
2459 2454
2460 // Now that we know the parameter list, we can distinguish between the 2455 // Now that we know the parameter list, we can distinguish between the
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2534 // Redirected constructor: either this(...) or this.xxx(...). 2529 // Redirected constructor: either this(...) or this.xxx(...).
2535 if (method->params.has_field_initializer) { 2530 if (method->params.has_field_initializer) {
2536 // Constructors that redirect to another constructor must not 2531 // Constructors that redirect to another constructor must not
2537 // initialize any fields using field initializer parameters. 2532 // initialize any fields using field initializer parameters.
2538 ErrorMsg(formal_param_pos, "Redirecting constructor " 2533 ErrorMsg(formal_param_pos, "Redirecting constructor "
2539 "may not use field initializer parameters"); 2534 "may not use field initializer parameters");
2540 } 2535 }
2541 ConsumeToken(); // Colon. 2536 ConsumeToken(); // Colon.
2542 ExpectToken(Token::kTHIS); 2537 ExpectToken(Token::kTHIS);
2543 String& redir_name = String::ZoneHandle( 2538 String& redir_name = String::ZoneHandle(
2544 String::Concat(members->class_name(), Symbols::DotHandle())); 2539 String::Concat(members->class_name(), Symbols::Dot()));
2545 if (CurrentToken() == Token::kPERIOD) { 2540 if (CurrentToken() == Token::kPERIOD) {
2546 ConsumeToken(); 2541 ConsumeToken();
2547 redir_name = String::Concat(redir_name, 2542 redir_name = String::Concat(redir_name,
2548 *ExpectIdentifier("constructor name expected")); 2543 *ExpectIdentifier("constructor name expected"));
2549 } 2544 }
2550 method->redirect_name = &redir_name; 2545 method->redirect_name = &redir_name;
2551 if (CurrentToken() != Token::kLPAREN) { 2546 if (CurrentToken() != Token::kLPAREN) {
2552 ErrorMsg("'(' expected"); 2547 ErrorMsg("'(' expected");
2553 } 2548 }
2554 SkipToMatchingParenthesis(); 2549 SkipToMatchingParenthesis();
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
2792 field->has_static, 2787 field->has_static,
2793 field->has_final, 2788 field->has_final,
2794 /* is_abstract = */ false, 2789 /* is_abstract = */ false,
2795 /* is_external = */ false, 2790 /* is_external = */ false,
2796 current_class(), 2791 current_class(),
2797 field->name_pos); 2792 field->name_pos);
2798 ParamList params; 2793 ParamList params;
2799 ASSERT(current_class().raw() == setter.Owner()); 2794 ASSERT(current_class().raw() == setter.Owner());
2800 params.AddReceiver(ReceiverType(TokenPos())); 2795 params.AddReceiver(ReceiverType(TokenPos()));
2801 params.AddFinalParameter(TokenPos(), 2796 params.AddFinalParameter(TokenPos(),
2802 &String::ZoneHandle(Symbols::Value()), 2797 &Symbols::Value(),
2803 field->type); 2798 field->type);
2804 setter.set_result_type(Type::Handle(Type::VoidType())); 2799 setter.set_result_type(Type::Handle(Type::VoidType()));
2805 AddFormalParamsToFunction(&params, setter); 2800 AddFormalParamsToFunction(&params, setter);
2806 members->AddFunction(setter); 2801 members->AddFunction(setter);
2807 } 2802 }
2808 } 2803 }
2809 2804
2810 if (CurrentToken() != Token::kCOMMA) { 2805 if (CurrentToken() != Token::kCOMMA) {
2811 break; 2806 break;
2812 } 2807 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2940 member.name_pos)); 2935 member.name_pos));
2941 // The type arguments of the result type are set during finalization. 2936 // The type arguments of the result type are set during finalization.
2942 member.type = &Type::ZoneHandle(Type::New(result_type_class, 2937 member.type = &Type::ZoneHandle(Type::New(result_type_class,
2943 TypeArguments::Handle(), 2938 TypeArguments::Handle(),
2944 member.name_pos)); 2939 member.name_pos));
2945 } else if (member.has_static) { 2940 } else if (member.has_static) {
2946 ErrorMsg(member.name_pos, "constructor cannot be static"); 2941 ErrorMsg(member.name_pos, "constructor cannot be static");
2947 } 2942 }
2948 // We must be dealing with a constructor or named constructor. 2943 // We must be dealing with a constructor or named constructor.
2949 member.kind = RawFunction::kConstructor; 2944 member.kind = RawFunction::kConstructor;
2950 *member.name = String::Concat(*member.name, Symbols::DotHandle()); 2945 *member.name = String::Concat(*member.name, Symbols::Dot());
2951 if (CurrentToken() == Token::kPERIOD) { 2946 if (CurrentToken() == Token::kPERIOD) {
2952 // Named constructor. 2947 // Named constructor.
2953 ConsumeToken(); 2948 ConsumeToken();
2954 member.constructor_name = ExpectIdentifier("identifier expected"); 2949 member.constructor_name = ExpectIdentifier("identifier expected");
2955 *member.name = String::Concat(*member.name, *member.constructor_name); 2950 *member.name = String::Concat(*member.name, *member.constructor_name);
2956 } 2951 }
2957 // Ensure that names are symbols. 2952 // Ensure that names are symbols.
2958 *member.name = Symbols::New(*member.name); 2953 *member.name = Symbols::New(*member.name);
2959 if (member.type == NULL) { 2954 if (member.type == NULL) {
2960 ASSERT(!member.has_factory); 2955 ASSERT(!member.has_factory);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3087 } 3082 }
3088 cls = Class::New(class_name, script_, classname_pos); 3083 cls = Class::New(class_name, script_, classname_pos);
3089 library_.AddClass(cls); 3084 library_.AddClass(cls);
3090 } else { 3085 } else {
3091 if (!obj.IsClass()) { 3086 if (!obj.IsClass()) {
3092 ErrorMsg(classname_pos, "'%s' is already defined", 3087 ErrorMsg(classname_pos, "'%s' is already defined",
3093 class_name.ToCString()); 3088 class_name.ToCString());
3094 } 3089 }
3095 cls ^= obj.raw(); 3090 cls ^= obj.raw();
3096 if (is_patch) { 3091 if (is_patch) {
3097 String& patch = String::Handle(Symbols::New("patch ")); 3092 String& patch = String::Handle(
3098 patch = String::Concat(patch, class_name); 3093 String::Concat(Symbols::PatchSpace(), class_name));
3099 patch = Symbols::New(patch); 3094 patch = Symbols::New(patch);
3100 cls = Class::New(patch, script_, classname_pos); 3095 cls = Class::New(patch, script_, classname_pos);
3101 cls.set_library(library_); 3096 cls.set_library(library_);
3102 } else { 3097 } else {
3103 // Not patching a class, but it has been found. This must be one of the 3098 // Not patching a class, but it has been found. This must be one of the
3104 // pre-registered classes from object.cc or a duplicate definition. 3099 // pre-registered classes from object.cc or a duplicate definition.
3105 if (cls.functions() != Object::empty_array().raw()) { 3100 if (cls.functions() != Object::empty_array().raw()) {
3106 ErrorMsg(classname_pos, "class '%s' is already defined", 3101 ErrorMsg(classname_pos, "class '%s' is already defined",
3107 class_name.ToCString()); 3102 class_name.ToCString());
3108 } 3103 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
3179 } 3174 }
3180 } 3175 }
3181 } 3176 }
3182 3177
3183 3178
3184 // Add an implicit constructor if no explicit constructor is present. 3179 // Add an implicit constructor if no explicit constructor is present.
3185 void Parser::AddImplicitConstructor(ClassDesc* class_desc) { 3180 void Parser::AddImplicitConstructor(ClassDesc* class_desc) {
3186 // The implicit constructor is unnamed, has no explicit parameter, 3181 // The implicit constructor is unnamed, has no explicit parameter,
3187 // and contains a supercall in the initializer list. 3182 // and contains a supercall in the initializer list.
3188 String& ctor_name = String::ZoneHandle( 3183 String& ctor_name = String::ZoneHandle(
3189 String::Concat(class_desc->class_name(), Symbols::DotHandle())); 3184 String::Concat(class_desc->class_name(), Symbols::Dot()));
3190 ctor_name = Symbols::New(ctor_name); 3185 ctor_name = Symbols::New(ctor_name);
3191 // The token position for the implicit constructor is the 'class' 3186 // The token position for the implicit constructor is the 'class'
3192 // keyword of the constructor's class. 3187 // keyword of the constructor's class.
3193 Function& ctor = Function::Handle( 3188 Function& ctor = Function::Handle(
3194 Function::New(ctor_name, 3189 Function::New(ctor_name,
3195 RawFunction::kConstructor, 3190 RawFunction::kConstructor,
3196 /* is_static = */ false, 3191 /* is_static = */ false,
3197 /* is_const = */ false, 3192 /* is_const = */ false,
3198 /* is_abstract = */ false, 3193 /* is_abstract = */ false,
3199 /* is_external = */ false, 3194 /* is_external = */ false,
3200 current_class(), 3195 current_class(),
3201 class_desc->token_pos())); 3196 class_desc->token_pos()));
3202 ParamList params; 3197 ParamList params;
3203 // Add implicit 'this' parameter. 3198 // Add implicit 'this' parameter.
3204 ASSERT(current_class().raw() == ctor.Owner()); 3199 ASSERT(current_class().raw() == ctor.Owner());
3205 params.AddReceiver(ReceiverType(TokenPos())); 3200 params.AddReceiver(ReceiverType(TokenPos()));
3206 // Add implicit parameter for construction phase. 3201 // Add implicit parameter for construction phase.
3207 params.AddFinalParameter(TokenPos(), 3202 params.AddFinalParameter(TokenPos(),
3208 &String::ZoneHandle(Symbols::PhaseParameter()), 3203 &Symbols::PhaseParameter(),
3209 &Type::ZoneHandle(Type::SmiType())); 3204 &Type::ZoneHandle(Type::SmiType()));
3210 3205
3211 AddFormalParamsToFunction(&params, ctor); 3206 AddFormalParamsToFunction(&params, ctor);
3212 // The body of the constructor cannot modify the type of the constructed 3207 // The body of the constructor cannot modify the type of the constructed
3213 // instance, which is passed in as the receiver. 3208 // instance, which is passed in as the receiver.
3214 ctor.set_result_type(*((*params.parameters)[0].type)); 3209 ctor.set_result_type(*((*params.parameters)[0].type));
3215 class_desc->AddFunction(ctor); 3210 class_desc->AddFunction(ctor);
3216 } 3211 }
3217 3212
3218 3213
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3279 3274
3280 3275
3281 void Parser::ParseFunctionTypeAlias( 3276 void Parser::ParseFunctionTypeAlias(
3282 const GrowableObjectArray& pending_classes) { 3277 const GrowableObjectArray& pending_classes) {
3283 TRACE_PARSER("ParseFunctionTypeAlias"); 3278 TRACE_PARSER("ParseFunctionTypeAlias");
3284 ExpectToken(Token::kTYPEDEF); 3279 ExpectToken(Token::kTYPEDEF);
3285 3280
3286 // Allocate an abstract class to hold the type parameters and their bounds. 3281 // Allocate an abstract class to hold the type parameters and their bounds.
3287 // Make it the owner of the function type descriptor. 3282 // Make it the owner of the function type descriptor.
3288 const Class& alias_owner = Class::Handle( 3283 const Class& alias_owner = Class::Handle(
3289 Class::New(String::Handle(Symbols::New(":alias_owner")), 3284 Class::New(Symbols::AliasOwner(), Script::Handle(), TokenPos()));
3290 Script::Handle(),
3291 TokenPos()));
3292 3285
3293 alias_owner.set_is_abstract(); 3286 alias_owner.set_is_abstract();
3294 alias_owner.set_library(library_); 3287 alias_owner.set_library(library_);
3295 set_current_class(alias_owner); 3288 set_current_class(alias_owner);
3296 3289
3297 // Parse the result type of the function type. 3290 // Parse the result type of the function type.
3298 AbstractType& result_type = Type::Handle(Type::DynamicType()); 3291 AbstractType& result_type = Type::Handle(Type::DynamicType());
3299 if (CurrentToken() == Token::kVOID) { 3292 if (CurrentToken() == Token::kVOID) {
3300 ConsumeToken(); 3293 ConsumeToken();
3301 result_type = Type::VoidType(); 3294 result_type = Type::VoidType();
(...skipping 18 matching lines...) Expand all
3320 } 3313 }
3321 // Parse the formal parameters of the function type. 3314 // Parse the formal parameters of the function type.
3322 if (CurrentToken() != Token::kLPAREN) { 3315 if (CurrentToken() != Token::kLPAREN) {
3323 ErrorMsg("formal parameter list expected"); 3316 ErrorMsg("formal parameter list expected");
3324 } 3317 }
3325 ParamList func_params; 3318 ParamList func_params;
3326 3319
3327 // Add implicit closure object parameter. 3320 // Add implicit closure object parameter.
3328 func_params.AddFinalParameter( 3321 func_params.AddFinalParameter(
3329 TokenPos(), 3322 TokenPos(),
3330 &String::ZoneHandle(Symbols::ClosureParameter()), 3323 &Symbols::ClosureParameter(),
3331 &Type::ZoneHandle(Type::DynamicType())); 3324 &Type::ZoneHandle(Type::DynamicType()));
3332 3325
3333 const bool no_explicit_default_values = false; 3326 const bool no_explicit_default_values = false;
3334 ParseFormalParameterList(no_explicit_default_values, &func_params); 3327 ParseFormalParameterList(no_explicit_default_values, &func_params);
3335 // The field 'is_static' has no meaning for signature functions. 3328 // The field 'is_static' has no meaning for signature functions.
3336 Function& signature_function = Function::Handle( 3329 Function& signature_function = Function::Handle(
3337 Function::New(*alias_name, 3330 Function::New(*alias_name,
3338 RawFunction::kSignatureFunction, 3331 RawFunction::kSignatureFunction,
3339 /* is_static = */ false, 3332 /* is_static = */ false,
3340 /* is_const = */ false, 3333 /* is_const = */ false,
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
4061 } 4054 }
4062 4055
4063 4056
4064 void Parser::ParseLibraryName() { 4057 void Parser::ParseLibraryName() {
4065 ASSERT(CurrentToken() == Token::kLIBRARY); 4058 ASSERT(CurrentToken() == Token::kLIBRARY);
4066 ConsumeToken(); 4059 ConsumeToken();
4067 String& lib_name = *ExpectIdentifier("library name expected"); 4060 String& lib_name = *ExpectIdentifier("library name expected");
4068 if (CurrentToken() == Token::kPERIOD) { 4061 if (CurrentToken() == Token::kPERIOD) {
4069 while (CurrentToken() == Token::kPERIOD) { 4062 while (CurrentToken() == Token::kPERIOD) {
4070 ConsumeToken(); 4063 ConsumeToken();
4071 lib_name = String::Concat(lib_name, Symbols::DotHandle()); 4064 lib_name = String::Concat(lib_name, Symbols::Dot());
4072 lib_name = String::Concat(lib_name, 4065 lib_name = String::Concat(lib_name,
4073 *ExpectIdentifier("malformed library name")); 4066 *ExpectIdentifier("malformed library name"));
4074 } 4067 }
4075 lib_name = Symbols::New(lib_name); 4068 lib_name = Symbols::New(lib_name);
4076 } 4069 }
4077 library_.SetName(lib_name); 4070 library_.SetName(lib_name);
4078 ExpectSemicolon(); 4071 ExpectSemicolon();
4079 } 4072 }
4080 4073
4081 4074
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
4300 // They need to be registered with class finalization after parsing 4293 // They need to be registered with class finalization after parsing
4301 // has been completed. 4294 // has been completed.
4302 Isolate* isolate = Isolate::Current(); 4295 Isolate* isolate = Isolate::Current();
4303 ObjectStore* object_store = isolate->object_store(); 4296 ObjectStore* object_store = isolate->object_store();
4304 const GrowableObjectArray& pending_classes = 4297 const GrowableObjectArray& pending_classes =
4305 GrowableObjectArray::Handle(isolate, object_store->pending_classes()); 4298 GrowableObjectArray::Handle(isolate, object_store->pending_classes());
4306 SetPosition(0); 4299 SetPosition(0);
4307 is_top_level_ = true; 4300 is_top_level_ = true;
4308 TopLevel top_level; 4301 TopLevel top_level;
4309 Class& toplevel_class = Class::Handle( 4302 Class& toplevel_class = Class::Handle(
4310 Class::New(String::Handle(Symbols::TopLevel()), script_, TokenPos())); 4303 Class::New(Symbols::TopLevel(), script_, TokenPos()));
4311 toplevel_class.set_library(library_); 4304 toplevel_class.set_library(library_);
4312 4305
4313 if (is_library_source()) { 4306 if (is_library_source()) {
4314 ParseLibraryDefinition(); 4307 ParseLibraryDefinition();
4315 } else if (is_part_source()) { 4308 } else if (is_part_source()) {
4316 ParsePartHeader(); 4309 ParsePartHeader();
4317 } 4310 }
4318 4311
4319 while (true) { 4312 while (true) {
4320 set_current_class(Class::Handle()); // No current class. 4313 set_current_class(Class::Handle()); // No current class.
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
4521 new ReturnNode(TokenPos(), 4514 new ReturnNode(TokenPos(),
4522 new NativeBodyNode(TokenPos(), 4515 new NativeBodyNode(TokenPos(),
4523 Function::ZoneHandle(func.raw()), 4516 Function::ZoneHandle(func.raw()),
4524 native_name, 4517 native_name,
4525 native_function))); 4518 native_function)));
4526 } 4519 }
4527 4520
4528 4521
4529 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { 4522 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) {
4530 ASSERT(!current_function().is_static()); 4523 ASSERT(!current_function().is_static());
4531 return from_scope->LookupVariable(Symbols::ThisHandle(), test_only); 4524 return from_scope->LookupVariable(Symbols::This(), test_only);
4532 } 4525 }
4533 4526
4534 4527
4535 LocalVariable* Parser::LookupTypeArgumentsParameter(LocalScope* from_scope, 4528 LocalVariable* Parser::LookupTypeArgumentsParameter(LocalScope* from_scope,
4536 bool test_only) { 4529 bool test_only) {
4537 ASSERT(current_function().IsInFactoryScope()); 4530 ASSERT(current_function().IsInFactoryScope());
4538 const String& param_name = String::Handle(Symbols::TypeArgumentsParameter()); 4531 return from_scope->LookupVariable(Symbols::TypeArgumentsParameter(),
4539 return from_scope->LookupVariable(param_name, test_only); 4532 test_only);
4540 } 4533 }
4541 LocalVariable* Parser::LookupPhaseParameter() { 4534 LocalVariable* Parser::LookupPhaseParameter() {
4542 const String& phase_name =
4543 String::Handle(Symbols::PhaseParameter());
4544 const bool kTestOnly = false; 4535 const bool kTestOnly = false;
4545 return current_block_->scope->LookupVariable(phase_name, kTestOnly); 4536 return current_block_->scope->LookupVariable(Symbols::PhaseParameter(),
4537 kTestOnly);
4546 } 4538 }
4547 4539
4548 4540
4549 void Parser::CaptureInstantiator() { 4541 void Parser::CaptureInstantiator() {
4550 ASSERT(current_block_->scope->function_level() > 0); 4542 ASSERT(current_block_->scope->function_level() > 0);
4551 const bool kTestOnly = false; 4543 const bool kTestOnly = false;
4552 // Side effect of lookup captures the instantiator variable. 4544 // Side effect of lookup captures the instantiator variable.
4553 LocalVariable* instantiator = NULL; 4545 LocalVariable* instantiator = NULL;
4554 if (current_function().IsInFactoryScope()) { 4546 if (current_function().IsInFactoryScope()) {
4555 instantiator = LookupTypeArgumentsParameter(current_block_->scope, 4547 instantiator = LookupTypeArgumentsParameter(current_block_->scope,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
4713 AbstractType& result_type = AbstractType::Handle(); 4705 AbstractType& result_type = AbstractType::Handle();
4714 const String* variable_name = NULL; 4706 const String* variable_name = NULL;
4715 const String* function_name = NULL; 4707 const String* function_name = NULL;
4716 4708
4717 result_type = Type::DynamicType(); 4709 result_type = Type::DynamicType();
4718 4710
4719 intptr_t ident_pos = TokenPos(); 4711 intptr_t ident_pos = TokenPos();
4720 if (FLAG_strict_function_literals) { 4712 if (FLAG_strict_function_literals) {
4721 if (is_literal) { 4713 if (is_literal) {
4722 ASSERT(CurrentToken() == Token::kLPAREN); 4714 ASSERT(CurrentToken() == Token::kLPAREN);
4723 function_name = &String::ZoneHandle(Symbols::AnonymousClosure()); 4715 function_name = &Symbols::AnonymousClosure();
4724 } else { 4716 } else {
4725 if (CurrentToken() == Token::kVOID) { 4717 if (CurrentToken() == Token::kVOID) {
4726 ConsumeToken(); 4718 ConsumeToken();
4727 result_type = Type::VoidType(); 4719 result_type = Type::VoidType();
4728 } else if ((CurrentToken() == Token::kIDENT) && 4720 } else if ((CurrentToken() == Token::kIDENT) &&
4729 (LookaheadToken(1) != Token::kLPAREN)) { 4721 (LookaheadToken(1) != Token::kLPAREN)) {
4730 result_type = ParseType(ClassFinalizer::kCanonicalize); 4722 result_type = ParseType(ClassFinalizer::kCanonicalize);
4731 } 4723 }
4732 ident_pos = TokenPos(); 4724 ident_pos = TokenPos();
4733 variable_name = ExpectIdentifier("function name expected"); 4725 variable_name = ExpectIdentifier("function name expected");
(...skipping 11 matching lines...) Expand all
4745 } 4737 }
4746 ident_pos = TokenPos(); 4738 ident_pos = TokenPos();
4747 if (IsIdentifier()) { 4739 if (IsIdentifier()) {
4748 variable_name = CurrentLiteral(); 4740 variable_name = CurrentLiteral();
4749 function_name = variable_name; 4741 function_name = variable_name;
4750 ConsumeToken(); 4742 ConsumeToken();
4751 } else { 4743 } else {
4752 if (!is_literal) { 4744 if (!is_literal) {
4753 ErrorMsg("function name expected"); 4745 ErrorMsg("function name expected");
4754 } 4746 }
4755 function_name = &String::ZoneHandle(Symbols::AnonymousClosure()); 4747 function_name = &Symbols::AnonymousClosure();
4756 } 4748 }
4757 } 4749 }
4758 4750
4759 if (CurrentToken() != Token::kLPAREN) { 4751 if (CurrentToken() != Token::kLPAREN) {
4760 ErrorMsg("'(' expected"); 4752 ErrorMsg("'(' expected");
4761 } 4753 }
4762 intptr_t function_pos = TokenPos(); 4754 intptr_t function_pos = TokenPos();
4763 4755
4764 // Check whether we have parsed this closure function before, in a previous 4756 // Check whether we have parsed this closure function before, in a previous
4765 // compilation. If so, reuse the function object, else create a new one 4757 // compilation. If so, reuse the function object, else create a new one
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
5386 // End of switch statement. 5378 // End of switch statement.
5387 break; 5379 break;
5388 } 5380 }
5389 if ((next_token == Token::kCASE) || (next_token == Token::kDEFAULT)) { 5381 if ((next_token == Token::kCASE) || (next_token == Token::kDEFAULT)) {
5390 // End of this case clause. If there is a possible fall-through to 5382 // End of this case clause. If there is a possible fall-through to
5391 // the next case clause, throw an implicit FallThroughError. 5383 // the next case clause, throw an implicit FallThroughError.
5392 if (!abrupt_completing_seen) { 5384 if (!abrupt_completing_seen) {
5393 ArgumentListNode* arguments = new ArgumentListNode(TokenPos()); 5385 ArgumentListNode* arguments = new ArgumentListNode(TokenPos());
5394 arguments->Add(new LiteralNode( 5386 arguments->Add(new LiteralNode(
5395 TokenPos(), Integer::ZoneHandle(Integer::New(TokenPos())))); 5387 TokenPos(), Integer::ZoneHandle(Integer::New(TokenPos()))));
5396 const String& cls_name = String::Handle(Symbols::FallThroughError());
5397 const String& func_name = String::Handle(Symbols::ThrowNew());
5398 current_block_->statements->Add( 5388 current_block_->statements->Add(
5399 MakeStaticCall(cls_name, func_name, arguments)); 5389 MakeStaticCall(Symbols::FallThroughError(),
5390 Symbols::ThrowNew(),
5391 arguments));
5400 } 5392 }
5401 break; 5393 break;
5402 } 5394 }
5403 // The next statement still belongs to this case. 5395 // The next statement still belongs to this case.
5404 AstNode* statement = ParseStatement(); 5396 AstNode* statement = ParseStatement();
5405 if (statement != NULL) { 5397 if (statement != NULL) {
5406 current_block_->statements->Add(statement); 5398 current_block_->statements->Add(statement);
5407 abrupt_completing_seen |= IsAbruptCompleting(statement); 5399 abrupt_completing_seen |= IsAbruptCompleting(statement);
5408 } 5400 }
5409 } 5401 }
(...skipping 23 matching lines...) Expand all
5433 if (paren_found) { 5425 if (paren_found) {
5434 ExpectToken(Token::kRPAREN); 5426 ExpectToken(Token::kRPAREN);
5435 } 5427 }
5436 ExpectToken(Token::kLBRACE); 5428 ExpectToken(Token::kLBRACE);
5437 OpenBlock(); 5429 OpenBlock();
5438 current_block_->scope->AddLabel(label); 5430 current_block_->scope->AddLabel(label);
5439 5431
5440 // Store switch expression in temporary local variable. 5432 // Store switch expression in temporary local variable.
5441 LocalVariable* temp_variable = 5433 LocalVariable* temp_variable =
5442 new LocalVariable(expr_pos, 5434 new LocalVariable(expr_pos,
5443 String::ZoneHandle(Symbols::New(":switch_expr")), 5435 Symbols::SwitchExpr(),
5444 Type::ZoneHandle(Type::DynamicType())); 5436 Type::ZoneHandle(Type::DynamicType()));
5445 current_block_->scope->AddVariable(temp_variable); 5437 current_block_->scope->AddVariable(temp_variable);
5446 AstNode* save_switch_expr = 5438 AstNode* save_switch_expr =
5447 new StoreLocalNode(expr_pos, temp_variable, switch_expr); 5439 new StoreLocalNode(expr_pos, temp_variable, switch_expr);
5448 current_block_->statements->Add(save_switch_expr); 5440 current_block_->statements->Add(save_switch_expr);
5449 5441
5450 // Parse case clauses 5442 // Parse case clauses
5451 bool default_seen = false; 5443 bool default_seen = false;
5452 while (true) { 5444 while (true) {
5453 // Check for statement label 5445 // Check for statement label
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
5564 } 5556 }
5565 } 5557 }
5566 ExpectToken(Token::kIN); 5558 ExpectToken(Token::kIN);
5567 const intptr_t collection_pos = TokenPos(); 5559 const intptr_t collection_pos = TokenPos();
5568 AstNode* collection_expr = ParseExpr(kAllowConst, kConsumeCascades); 5560 AstNode* collection_expr = ParseExpr(kAllowConst, kConsumeCascades);
5569 ExpectToken(Token::kRPAREN); 5561 ExpectToken(Token::kRPAREN);
5570 5562
5571 OpenBlock(); // Implicit block around while loop. 5563 OpenBlock(); // Implicit block around while loop.
5572 5564
5573 // Generate implicit iterator variable and add to scope. 5565 // Generate implicit iterator variable and add to scope.
5574 const String& iterator_name = String::ZoneHandle(Symbols::ForInIter());
5575 // We could set the type of the implicit iterator variable to Iterator<T> 5566 // We could set the type of the implicit iterator variable to Iterator<T>
5576 // where T is the type of the for loop variable. However, the type error 5567 // where T is the type of the for loop variable. However, the type error
5577 // would refer to the compiler generated iterator and could confuse the user. 5568 // would refer to the compiler generated iterator and could confuse the user.
5578 // It is better to leave the iterator untyped and postpone the type error 5569 // It is better to leave the iterator untyped and postpone the type error
5579 // until the loop variable is assigned to. 5570 // until the loop variable is assigned to.
5580 const AbstractType& iterator_type = Type::ZoneHandle(Type::DynamicType()); 5571 const AbstractType& iterator_type = Type::ZoneHandle(Type::DynamicType());
5581 LocalVariable* iterator_var = 5572 LocalVariable* iterator_var =
5582 new LocalVariable(collection_pos, iterator_name, iterator_type); 5573 new LocalVariable(collection_pos, Symbols::ForInIter(), iterator_type);
5583 current_block_->scope->AddVariable(iterator_var); 5574 current_block_->scope->AddVariable(iterator_var);
5584 5575
5585 // Generate initialization of iterator variable. 5576 // Generate initialization of iterator variable.
5586 const String& iterator_method_name =
5587 String::ZoneHandle(Symbols::GetIterator());
5588 ArgumentListNode* no_args = new ArgumentListNode(collection_pos); 5577 ArgumentListNode* no_args = new ArgumentListNode(collection_pos);
5589 AstNode* get_iterator = new InstanceCallNode( 5578 AstNode* get_iterator = new InstanceCallNode(
5590 collection_pos, collection_expr, iterator_method_name, no_args); 5579 collection_pos, collection_expr, Symbols::GetIterator(), no_args);
5591 AstNode* iterator_init = 5580 AstNode* iterator_init =
5592 new StoreLocalNode(collection_pos, iterator_var, get_iterator); 5581 new StoreLocalNode(collection_pos, iterator_var, get_iterator);
5593 current_block_->statements->Add(iterator_init); 5582 current_block_->statements->Add(iterator_init);
5594 5583
5595 // Generate while loop condition. 5584 // Generate while loop condition.
5596 AstNode* iterator_has_next = new InstanceGetterNode( 5585 AstNode* iterator_has_next = new InstanceGetterNode(
5597 collection_pos, 5586 collection_pos,
5598 new LoadLocalNode(collection_pos, iterator_var), 5587 new LoadLocalNode(collection_pos, iterator_var),
5599 String::ZoneHandle(Symbols::HasNext())); 5588 Symbols::HasNext());
5600 5589
5601 // Parse the for loop body. Ideally, we would use ParseNestedStatement() 5590 // Parse the for loop body. Ideally, we would use ParseNestedStatement()
5602 // here, but that does not work well because we have to insert an implicit 5591 // here, but that does not work well because we have to insert an implicit
5603 // variable assignment and potentially a variable declaration in the 5592 // variable assignment and potentially a variable declaration in the
5604 // loop body. 5593 // loop body.
5605 OpenLoopBlock(); 5594 OpenLoopBlock();
5606 current_block_->scope->AddLabel(label); 5595 current_block_->scope->AddLabel(label);
5607 5596
5608 AstNode* iterator_next = new InstanceCallNode( 5597 AstNode* iterator_next = new InstanceCallNode(
5609 collection_pos, 5598 collection_pos,
5610 new LoadLocalNode(collection_pos, iterator_var), 5599 new LoadLocalNode(collection_pos, iterator_var),
5611 String::ZoneHandle(Symbols::Next()), 5600 Symbols::Next(),
5612 no_args); 5601 no_args);
5613 5602
5614 // Generate assignment of next iterator value to loop variable. 5603 // Generate assignment of next iterator value to loop variable.
5615 AstNode* loop_var_assignment = NULL; 5604 AstNode* loop_var_assignment = NULL;
5616 if (loop_var != NULL) { 5605 if (loop_var != NULL) {
5617 // The for loop declares a new variable. Add it to the loop body scope. 5606 // The for loop declares a new variable. Add it to the loop body scope.
5618 current_block_->scope->AddVariable(loop_var); 5607 current_block_->scope->AddVariable(loop_var);
5619 loop_var_assignment = 5608 loop_var_assignment =
5620 new StoreLocalNode(loop_var_pos, loop_var, iterator_next); 5609 new StoreLocalNode(loop_var_pos, loop_var, iterator_next);
5621 } else { 5610 } else {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
5734 return new StaticCallNode(arguments->token_pos(), func, arguments); 5723 return new StaticCallNode(arguments->token_pos(), func, arguments);
5735 } 5724 }
5736 5725
5737 5726
5738 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) { 5727 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) {
5739 ArgumentListNode* arguments = new ArgumentListNode(begin); 5728 ArgumentListNode* arguments = new ArgumentListNode(begin);
5740 arguments->Add(new LiteralNode(begin, 5729 arguments->Add(new LiteralNode(begin,
5741 Integer::ZoneHandle(Integer::New(begin)))); 5730 Integer::ZoneHandle(Integer::New(begin))));
5742 arguments->Add(new LiteralNode(end, 5731 arguments->Add(new LiteralNode(end,
5743 Integer::ZoneHandle(Integer::New(end)))); 5732 Integer::ZoneHandle(Integer::New(end))));
5744 const String& cls_name = String::Handle(Symbols::AssertionError()); 5733 return MakeStaticCall(Symbols::AssertionError(),
5745 const String& func_name = String::Handle(Symbols::ThrowNew()); 5734 Symbols::ThrowNew(),
5746 return MakeStaticCall(cls_name, func_name, arguments); 5735 arguments);
5747 } 5736 }
5748 5737
5749 5738
5750 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) { 5739 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) {
5751 if (condition->IsClosureNode() || 5740 if (condition->IsClosureNode() ||
5752 (condition->IsStoreLocalNode() && 5741 (condition->IsStoreLocalNode() &&
5753 condition->AsStoreLocalNode()->value()->IsClosureNode())) { 5742 condition->AsStoreLocalNode()->value()->IsClosureNode())) {
5754 EnsureExpressionTemp(); 5743 EnsureExpressionTemp();
5755 // Function literal in assert implies a call. 5744 // Function literal in assert implies a call.
5756 const intptr_t pos = condition->token_pos(); 5745 const intptr_t pos = condition->token_pos();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
5894 // block. The context register is restored from this 5883 // block. The context register is restored from this
5895 // slot before processing the catch block handler. 5884 // slot before processing the catch block handler.
5896 // ':exception_var' - Used to save the current exception object that was 5885 // ':exception_var' - Used to save the current exception object that was
5897 // thrown. 5886 // thrown.
5898 // ':stacktrace_var' - Used to save the current stack trace object into which 5887 // ':stacktrace_var' - Used to save the current stack trace object into which
5899 // the stack trace was copied into when an exception was 5888 // the stack trace was copied into when an exception was
5900 // thrown. 5889 // thrown.
5901 // :exception_var and :stacktrace_var get set with the exception object 5890 // :exception_var and :stacktrace_var get set with the exception object
5902 // and the stacktrace object when an exception is thrown. 5891 // and the stacktrace object when an exception is thrown.
5903 // These three implicit variables can never be captured variables. 5892 // These three implicit variables can never be captured variables.
5904 const String& context_var_name =
5905 String::ZoneHandle(Symbols::SavedContextVar());
5906 LocalVariable* context_var = 5893 LocalVariable* context_var =
5907 current_block_->scope->LocalLookupVariable(context_var_name); 5894 current_block_->scope->LocalLookupVariable(Symbols::SavedContextVar());
5908 if (context_var == NULL) { 5895 if (context_var == NULL) {
5909 context_var = new LocalVariable(TokenPos(), 5896 context_var = new LocalVariable(TokenPos(),
5910 context_var_name, 5897 Symbols::SavedContextVar(),
5911 Type::ZoneHandle(Type::DynamicType())); 5898 Type::ZoneHandle(Type::DynamicType()));
5912 current_block_->scope->AddVariable(context_var); 5899 current_block_->scope->AddVariable(context_var);
5913 } 5900 }
5914 const String& catch_excp_var_name =
5915 String::ZoneHandle(Symbols::ExceptionVar());
5916 LocalVariable* catch_excp_var = 5901 LocalVariable* catch_excp_var =
5917 current_block_->scope->LocalLookupVariable(catch_excp_var_name); 5902 current_block_->scope->LocalLookupVariable(Symbols::ExceptionVar());
5918 if (catch_excp_var == NULL) { 5903 if (catch_excp_var == NULL) {
5919 catch_excp_var = new LocalVariable(TokenPos(), 5904 catch_excp_var = new LocalVariable(TokenPos(),
5920 catch_excp_var_name, 5905 Symbols::ExceptionVar(),
5921 Type::ZoneHandle(Type::DynamicType())); 5906 Type::ZoneHandle(Type::DynamicType()));
5922 current_block_->scope->AddVariable(catch_excp_var); 5907 current_block_->scope->AddVariable(catch_excp_var);
5923 } 5908 }
5924 const String& catch_trace_var_name =
5925 String::ZoneHandle(Symbols::StacktraceVar());
5926 LocalVariable* catch_trace_var = 5909 LocalVariable* catch_trace_var =
5927 current_block_->scope->LocalLookupVariable(catch_trace_var_name); 5910 current_block_->scope->LocalLookupVariable(Symbols::StacktraceVar());
5928 if (catch_trace_var == NULL) { 5911 if (catch_trace_var == NULL) {
5929 catch_trace_var = new LocalVariable(TokenPos(), 5912 catch_trace_var = new LocalVariable(TokenPos(),
5930 catch_trace_var_name, 5913 Symbols::StacktraceVar(),
5931 Type::ZoneHandle(Type::DynamicType())); 5914 Type::ZoneHandle(Type::DynamicType()));
5932 current_block_->scope->AddVariable(catch_trace_var); 5915 current_block_->scope->AddVariable(catch_trace_var);
5933 } 5916 }
5934 5917
5935 const intptr_t try_pos = TokenPos(); 5918 const intptr_t try_pos = TokenPos();
5936 ConsumeToken(); // Consume the 'try'. 5919 ConsumeToken(); // Consume the 'try'.
5937 5920
5938 SourceLabel* try_label = NULL; 5921 SourceLabel* try_label = NULL;
5939 if (label_name != NULL) { 5922 if (label_name != NULL) {
5940 try_label = SourceLabel::New(try_pos, label_name, SourceLabel::kStatement); 5923 try_label = SourceLabel::New(try_pos, label_name, SourceLabel::kStatement);
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
6285 ExpectSemicolon(); 6268 ExpectSemicolon();
6286 // Check if it is ok to do a rethrow. 6269 // Check if it is ok to do a rethrow.
6287 SourceLabel* label = current_block_->scope->LookupInnermostCatchLabel(); 6270 SourceLabel* label = current_block_->scope->LookupInnermostCatchLabel();
6288 if (label == NULL || 6271 if (label == NULL ||
6289 label->FunctionLevel() != current_block_->scope->function_level()) { 6272 label->FunctionLevel() != current_block_->scope->function_level()) {
6290 ErrorMsg(statement_pos, "rethrow of an exception is not valid here"); 6273 ErrorMsg(statement_pos, "rethrow of an exception is not valid here");
6291 } 6274 }
6292 ASSERT(label->owner() != NULL); 6275 ASSERT(label->owner() != NULL);
6293 LocalScope* scope = label->owner()->parent(); 6276 LocalScope* scope = label->owner()->parent();
6294 ASSERT(scope != NULL); 6277 ASSERT(scope != NULL);
6295 LocalVariable* excp_var = scope->LocalLookupVariable( 6278 LocalVariable* excp_var =
6296 String::ZoneHandle(Symbols::ExceptionVar())); 6279 scope->LocalLookupVariable(Symbols::ExceptionVar());
6297 ASSERT(excp_var != NULL); 6280 ASSERT(excp_var != NULL);
6298 LocalVariable* trace_var = scope->LocalLookupVariable( 6281 LocalVariable* trace_var =
6299 String::ZoneHandle(Symbols::StacktraceVar())); 6282 scope->LocalLookupVariable(Symbols::StacktraceVar());
6300 ASSERT(trace_var != NULL); 6283 ASSERT(trace_var != NULL);
6301 statement = new ThrowNode(statement_pos, 6284 statement = new ThrowNode(statement_pos,
6302 new LoadLocalNode(statement_pos, excp_var), 6285 new LoadLocalNode(statement_pos, excp_var),
6303 new LoadLocalNode(statement_pos, trace_var)); 6286 new LoadLocalNode(statement_pos, trace_var));
6304 } else { 6287 } else {
6305 statement = ParseExpr(kAllowConst, kConsumeCascades); 6288 statement = ParseExpr(kAllowConst, kConsumeCascades);
6306 ExpectSemicolon(); 6289 ExpectSemicolon();
6307 } 6290 }
6308 return statement; 6291 return statement;
6309 } 6292 }
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
6562 6545
6563 AstNode* Parser::ThrowTypeError(intptr_t type_pos, const AbstractType& type) { 6546 AstNode* Parser::ThrowTypeError(intptr_t type_pos, const AbstractType& type) {
6564 ASSERT(type.IsMalformed()); 6547 ASSERT(type.IsMalformed());
6565 ArgumentListNode* arguments = new ArgumentListNode(type_pos); 6548 ArgumentListNode* arguments = new ArgumentListNode(type_pos);
6566 // Location argument. 6549 // Location argument.
6567 arguments->Add(new LiteralNode( 6550 arguments->Add(new LiteralNode(
6568 type_pos, Integer::ZoneHandle(Integer::New(type_pos)))); 6551 type_pos, Integer::ZoneHandle(Integer::New(type_pos))));
6569 // Src value argument. 6552 // Src value argument.
6570 arguments->Add(new LiteralNode(type_pos, Instance::ZoneHandle())); 6553 arguments->Add(new LiteralNode(type_pos, Instance::ZoneHandle()));
6571 // Dst type name argument. 6554 // Dst type name argument.
6572 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( 6555 arguments->Add(new LiteralNode(type_pos, Symbols::Malformed()));
6573 Symbols::New("malformed"))));
6574 // Dst name argument. 6556 // Dst name argument.
6575 arguments->Add(new LiteralNode(type_pos, 6557 arguments->Add(new LiteralNode(type_pos, Symbols::Empty()));
6576 String::ZoneHandle(Symbols::Empty())));
6577 // Malformed type error. 6558 // Malformed type error.
6578 const Error& error = Error::Handle(type.malformed_error()); 6559 const Error& error = Error::Handle(type.malformed_error());
6579 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( 6560 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle(
6580 Symbols::New(error.ToErrorCString())))); 6561 Symbols::New(error.ToErrorCString()))));
6581 const String& cls_name = String::Handle(Symbols::TypeError()); 6562 return MakeStaticCall(Symbols::TypeError(), Symbols::ThrowNew(), arguments);
6582 const String& func_name = String::Handle(Symbols::ThrowNew());
6583 return MakeStaticCall(cls_name, func_name, arguments);
6584 } 6563 }
6585 6564
6586 6565
6587 AstNode* Parser::ThrowNoSuchMethodError(intptr_t call_pos, const String& name) { 6566 AstNode* Parser::ThrowNoSuchMethodError(intptr_t call_pos, const String& name) {
6588 ArgumentListNode* arguments = new ArgumentListNode(call_pos); 6567 ArgumentListNode* arguments = new ArgumentListNode(call_pos);
6589 // Location argument. 6568 // Location argument.
6590 arguments->Add(new LiteralNode( 6569 arguments->Add(new LiteralNode(
6591 call_pos, Integer::ZoneHandle(Integer::New(call_pos)))); 6570 call_pos, Integer::ZoneHandle(Integer::New(call_pos))));
6592 // Function name argument. 6571 // Function name argument.
6593 arguments->Add(new LiteralNode( 6572 arguments->Add(new LiteralNode(
6594 call_pos, String::ZoneHandle(Symbols::New(name)))); 6573 call_pos, String::ZoneHandle(Symbols::New(name))));
6595 const String& cls_name = String::Handle(Symbols::NoSuchMethodError()); 6574 return MakeStaticCall(Symbols::NoSuchMethodErrorImpl(),
6596 const String& func_name = String::Handle(Symbols::ThrowNew()); 6575 Symbols::ThrowNew(),
6597 return MakeStaticCall(cls_name, func_name, arguments); 6576 arguments);
6598 } 6577 }
6599 6578
6600 6579
6601 AstNode* Parser::ParseBinaryExpr(int min_preced) { 6580 AstNode* Parser::ParseBinaryExpr(int min_preced) {
6602 TRACE_PARSER("ParseBinaryExpr"); 6581 TRACE_PARSER("ParseBinaryExpr");
6603 ASSERT(min_preced >= 4); 6582 ASSERT(min_preced >= 4);
6604 AstNode* left_operand = ParseUnaryExpr(); 6583 AstNode* left_operand = ParseUnaryExpr();
6605 if (left_operand->IsPrimaryNode() && 6584 if (left_operand->IsPrimaryNode() &&
6606 (left_operand->AsPrimaryNode()->IsSuper())) { 6585 (left_operand->AsPrimaryNode()->IsSuper())) {
6607 ErrorMsg(left_operand->token_pos(), "illegal use of 'super'"); 6586 ErrorMsg(left_operand->token_pos(), "illegal use of 'super'");
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
7137 // Check if there is a static field of the same name, it could be a closure 7116 // Check if there is a static field of the same name, it could be a closure
7138 // and so we try and invoke the closure. 7117 // and so we try and invoke the closure.
7139 AstNode* closure = NULL; 7118 AstNode* closure = NULL;
7140 const Field& field = Field::ZoneHandle(cls.LookupStaticField(func_name)); 7119 const Field& field = Field::ZoneHandle(cls.LookupStaticField(func_name));
7141 Function& func = Function::ZoneHandle(); 7120 Function& func = Function::ZoneHandle();
7142 if (field.IsNull()) { 7121 if (field.IsNull()) {
7143 // No field, check if we have an explicit getter function. 7122 // No field, check if we have an explicit getter function.
7144 const String& getter_name = 7123 const String& getter_name =
7145 String::ZoneHandle(Field::GetterName(func_name)); 7124 String::ZoneHandle(Field::GetterName(func_name));
7146 const int kNumArguments = 0; // no arguments. 7125 const int kNumArguments = 0; // no arguments.
7147 const Array& kNoArgumentNames = Array::Handle();
7148 func = Resolver::ResolveStatic(cls, 7126 func = Resolver::ResolveStatic(cls,
7149 getter_name, 7127 getter_name,
7150 kNumArguments, 7128 kNumArguments,
7151 kNoArgumentNames, 7129 Object::empty_array(),
7152 Resolver::kIsQualified); 7130 Resolver::kIsQualified);
7153 if (!func.IsNull()) { 7131 if (!func.IsNull()) {
7154 ASSERT(func.kind() != RawFunction::kConstImplicitGetter); 7132 ASSERT(func.kind() != RawFunction::kConstImplicitGetter);
7155 EnsureExpressionTemp(); 7133 EnsureExpressionTemp();
7156 closure = new StaticGetterNode(call_pos, 7134 closure = new StaticGetterNode(call_pos,
7157 NULL, 7135 NULL,
7158 false, 7136 false,
7159 Class::ZoneHandle(cls.raw()), 7137 Class::ZoneHandle(cls.raw()),
7160 func_name); 7138 func_name);
7161 return new ClosureCallNode(call_pos, closure, arguments); 7139 return new ClosureCallNode(call_pos, closure, arguments);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
7223 const intptr_t call_pos = TokenPos(); 7201 const intptr_t call_pos = TokenPos();
7224 const Field& field = Field::ZoneHandle(cls.LookupStaticField(field_name)); 7202 const Field& field = Field::ZoneHandle(cls.LookupStaticField(field_name));
7225 Function& func = Function::ZoneHandle(); 7203 Function& func = Function::ZoneHandle();
7226 if (Token::IsAssignmentOperator(CurrentToken())) { 7204 if (Token::IsAssignmentOperator(CurrentToken())) {
7227 // Make sure an assignment is legal. 7205 // Make sure an assignment is legal.
7228 if (field.IsNull()) { 7206 if (field.IsNull()) {
7229 // No field, check if we have an explicit setter function. 7207 // No field, check if we have an explicit setter function.
7230 const String& setter_name = 7208 const String& setter_name =
7231 String::ZoneHandle(Field::SetterName(field_name)); 7209 String::ZoneHandle(Field::SetterName(field_name));
7232 const int kNumArguments = 1; // value. 7210 const int kNumArguments = 1; // value.
7233 const Array& kNoArgumentNames = Array::Handle();
7234 func = Resolver::ResolveStatic(cls, 7211 func = Resolver::ResolveStatic(cls,
7235 setter_name, 7212 setter_name,
7236 kNumArguments, 7213 kNumArguments,
7237 kNoArgumentNames, 7214 Object::empty_array(),
7238 Resolver::kIsQualified); 7215 Resolver::kIsQualified);
7239 if (func.IsNull()) { 7216 if (func.IsNull()) {
7240 // No field or explicit setter function, throw a NoSuchMethodError. 7217 // No field or explicit setter function, throw a NoSuchMethodError.
7241 return ThrowNoSuchMethodError(ident_pos, field_name); 7218 return ThrowNoSuchMethodError(ident_pos, field_name);
7242 } 7219 }
7243 7220
7244 // Explicit setter function for the field found, field does not exist. 7221 // Explicit setter function for the field found, field does not exist.
7245 // Create a getter node first in case it is needed. If getter node 7222 // Create a getter node first in case it is needed. If getter node
7246 // is used as part of, e.g., "+=", and the explicit getter does not 7223 // is used as part of, e.g., "+=", and the explicit getter does not
7247 // exist, and error will be reported by the code generator. 7224 // exist, and error will be reported by the code generator.
(...skipping 12 matching lines...) Expand all
7260 field_name.ToCString()); 7237 field_name.ToCString());
7261 } 7238 }
7262 access = GenerateStaticFieldLookup(field, TokenPos()); 7239 access = GenerateStaticFieldLookup(field, TokenPos());
7263 } 7240 }
7264 } else { // Not Token::IsAssignmentOperator(CurrentToken()). 7241 } else { // Not Token::IsAssignmentOperator(CurrentToken()).
7265 if (field.IsNull()) { 7242 if (field.IsNull()) {
7266 // No field, check if we have an explicit getter function. 7243 // No field, check if we have an explicit getter function.
7267 const String& getter_name = 7244 const String& getter_name =
7268 String::ZoneHandle(Field::GetterName(field_name)); 7245 String::ZoneHandle(Field::GetterName(field_name));
7269 const int kNumArguments = 0; // no arguments. 7246 const int kNumArguments = 0; // no arguments.
7270 const Array& kNoArgumentNames = Array::Handle();
7271 func = Resolver::ResolveStatic(cls, 7247 func = Resolver::ResolveStatic(cls,
7272 getter_name, 7248 getter_name,
7273 kNumArguments, 7249 kNumArguments,
7274 kNoArgumentNames, 7250 Object::empty_array(),
7275 Resolver::kIsQualified); 7251 Resolver::kIsQualified);
7276 if (func.IsNull()) { 7252 if (func.IsNull()) {
7277 // We might be referring to an implicit closure, check to see if 7253 // We might be referring to an implicit closure, check to see if
7278 // there is a function of the same name. 7254 // there is a function of the same name.
7279 func = cls.LookupStaticFunction(field_name); 7255 func = cls.LookupStaticFunction(field_name);
7280 if (func.IsNull()) { 7256 if (func.IsNull()) {
7281 // No field or explicit getter function, throw a NoSuchMethodError. 7257 // No field or explicit getter function, throw a NoSuchMethodError.
7282 return ThrowNoSuchMethodError(ident_pos, field_name); 7258 return ThrowNoSuchMethodError(ident_pos, field_name);
7283 } 7259 }
7284 access = CreateImplicitClosureNode(func, call_pos, NULL); 7260 access = CreateImplicitClosureNode(func, call_pos, NULL);
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
7679 // Returns true if ident resolves to a formal parameter of the current function 7655 // Returns true if ident resolves to a formal parameter of the current function
7680 // or of one of its enclosing functions. 7656 // or of one of its enclosing functions.
7681 // Make sure not to capture the formal parameter, since it is not accessed. 7657 // Make sure not to capture the formal parameter, since it is not accessed.
7682 bool Parser::IsFormalParameter(const String& ident, 7658 bool Parser::IsFormalParameter(const String& ident,
7683 Function* owner_function, 7659 Function* owner_function,
7684 LocalScope** owner_scope, 7660 LocalScope** owner_scope,
7685 intptr_t* local_index) { 7661 intptr_t* local_index) {
7686 if (current_block_ == NULL) { 7662 if (current_block_ == NULL) {
7687 return false; 7663 return false;
7688 } 7664 }
7689 if (ident.Equals(Symbols::ThisHandle())) { 7665 if (ident.Equals(Symbols::This())) {
7690 // 'this' is not a formal parameter. 7666 // 'this' is not a formal parameter.
7691 return false; 7667 return false;
7692 } 7668 }
7693 // Since an argument definition test does not use the value of the formal 7669 // Since an argument definition test does not use the value of the formal
7694 // parameter, there is no reason to capture it. 7670 // parameter, there is no reason to capture it.
7695 const bool kTestOnly = true; // No capturing. 7671 const bool kTestOnly = true; // No capturing.
7696 LocalVariable* local = 7672 LocalVariable* local =
7697 current_block_->scope->LookupVariable(ident, kTestOnly); 7673 current_block_->scope->LookupVariable(ident, kTestOnly);
7698 if (local == NULL) { 7674 if (local == NULL) {
7699 if (!current_function().IsLocalFunction()) { 7675 if (!current_function().IsLocalFunction()) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
7835 // This field has not been referenced yet and thus the value has 7811 // This field has not been referenced yet and thus the value has
7836 // not been evaluated. If the field is const, call the static getter method 7812 // not been evaluated. If the field is const, call the static getter method
7837 // to evaluate the expression and canonicalize the value. 7813 // to evaluate the expression and canonicalize the value.
7838 if (field.is_const()) { 7814 if (field.is_const()) {
7839 field.set_value(Object::transition_sentinel()); 7815 field.set_value(Object::transition_sentinel());
7840 const String& field_name = String::Handle(field.name()); 7816 const String& field_name = String::Handle(field.name());
7841 const String& getter_name = 7817 const String& getter_name =
7842 String::Handle(Field::GetterName(field_name)); 7818 String::Handle(Field::GetterName(field_name));
7843 const Class& cls = Class::Handle(field.owner()); 7819 const Class& cls = Class::Handle(field.owner());
7844 const int kNumArguments = 0; // no arguments. 7820 const int kNumArguments = 0; // no arguments.
7845 const Array& kNoArgumentNames = Array::Handle();
7846 const Function& func = 7821 const Function& func =
7847 Function::Handle(Resolver::ResolveStatic(cls, 7822 Function::Handle(Resolver::ResolveStatic(cls,
7848 getter_name, 7823 getter_name,
7849 kNumArguments, 7824 kNumArguments,
7850 kNoArgumentNames, 7825 Object::empty_array(),
7851 Resolver::kIsQualified)); 7826 Resolver::kIsQualified));
7852 ASSERT(!func.IsNull()); 7827 ASSERT(!func.IsNull());
7853 ASSERT(func.kind() == RawFunction::kConstImplicitGetter); 7828 ASSERT(func.kind() == RawFunction::kConstImplicitGetter);
7854 Object& const_value = Object::Handle( 7829 Object& const_value = Object::Handle(
7855 DartEntry::InvokeStatic(func, Object::empty_array())); 7830 DartEntry::InvokeStatic(func, Object::empty_array()));
7856 if (const_value.IsError()) { 7831 if (const_value.IsError()) {
7857 const Error& error = Error::Cast(const_value); 7832 const Error& error = Error::Cast(const_value);
7858 if (error.IsUnhandledException()) { 7833 if (error.IsUnhandledException()) {
7859 field.set_value(Instance::Handle()); 7834 field.set_value(Instance::Handle());
7860 // It is a compile-time error if evaluation of a compile-time constant 7835 // It is a compile-time error if evaluation of a compile-time constant
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
8491 Type& type = Type::ZoneHandle( 8466 Type& type = Type::ZoneHandle(
8492 Type::New(array_class, type_arguments, type_pos)); 8467 Type::New(array_class, type_arguments, type_pos));
8493 type ^= ClassFinalizer::FinalizeType( 8468 type ^= ClassFinalizer::FinalizeType(
8494 current_class(), type, ClassFinalizer::kCanonicalize); 8469 current_class(), type, ClassFinalizer::kCanonicalize);
8495 ArrayNode* list = new ArrayNode(TokenPos(), type); 8470 ArrayNode* list = new ArrayNode(TokenPos(), type);
8496 8471
8497 // Parse the list elements. Note: there may be an optional extra 8472 // Parse the list elements. Note: there may be an optional extra
8498 // comma after the last element. 8473 // comma after the last element.
8499 if (!is_empty_literal) { 8474 if (!is_empty_literal) {
8500 const bool saved_mode = SetAllowFunctionLiterals(true); 8475 const bool saved_mode = SetAllowFunctionLiterals(true);
8501 const String& dst_name = String::ZoneHandle(Symbols::ListLiteralElement());
8502 while (CurrentToken() != Token::kRBRACK) { 8476 while (CurrentToken() != Token::kRBRACK) {
8503 const intptr_t element_pos = TokenPos(); 8477 const intptr_t element_pos = TokenPos();
8504 AstNode* element = ParseExpr(is_const, kConsumeCascades); 8478 AstNode* element = ParseExpr(is_const, kConsumeCascades);
8505 if (FLAG_enable_type_checks && 8479 if (FLAG_enable_type_checks &&
8506 !is_const && 8480 !is_const &&
8507 !element_type.IsDynamicType()) { 8481 !element_type.IsDynamicType()) {
8508 element = new AssignableNode(element_pos, 8482 element = new AssignableNode(element_pos,
8509 element, 8483 element,
8510 element_type, 8484 element_type,
8511 dst_name); 8485 Symbols::ListLiteralElement());
8512 } 8486 }
8513 list->AddElement(element); 8487 list->AddElement(element);
8514 if (CurrentToken() == Token::kCOMMA) { 8488 if (CurrentToken() == Token::kCOMMA) {
8515 ConsumeToken(); 8489 ConsumeToken();
8516 } else if (CurrentToken() != Token::kRBRACK) { 8490 } else if (CurrentToken() != Token::kRBRACK) {
8517 ErrorMsg("comma or ']' expected"); 8491 ErrorMsg("comma or ']' expected");
8518 } 8492 }
8519 } 8493 }
8520 ExpectToken(Token::kRBRACK); 8494 ExpectToken(Token::kRBRACK);
8521 SetAllowFunctionLiterals(saved_mode); 8495 SetAllowFunctionLiterals(saved_mode);
(...skipping 26 matching lines...) Expand all
8548 String::Handle(element_type.UserVisibleName()).ToCString()); 8522 String::Handle(element_type.UserVisibleName()).ToCString());
8549 } 8523 }
8550 } 8524 }
8551 const_list.SetAt(i, elem->AsLiteralNode()->literal()); 8525 const_list.SetAt(i, elem->AsLiteralNode()->literal());
8552 } 8526 }
8553 const_list ^= const_list.Canonicalize(); 8527 const_list ^= const_list.Canonicalize();
8554 const_list.MakeImmutable(); 8528 const_list.MakeImmutable();
8555 return new LiteralNode(literal_pos, const_list); 8529 return new LiteralNode(literal_pos, const_list);
8556 } else { 8530 } else {
8557 // Factory call at runtime. 8531 // Factory call at runtime.
8558 String& factory_class_name = String::Handle(Symbols::List());
8559 const Class& factory_class = 8532 const Class& factory_class =
8560 Class::Handle(LookupCoreClass(factory_class_name)); 8533 Class::Handle(LookupCoreClass(Symbols::List()));
8561 ASSERT(!factory_class.IsNull()); 8534 ASSERT(!factory_class.IsNull());
8562 const String& factory_method_name =
8563 String::Handle(Symbols::ListLiteralFactory());
8564 const Function& factory_method = Function::ZoneHandle( 8535 const Function& factory_method = Function::ZoneHandle(
8565 factory_class.LookupFactory(factory_method_name)); 8536 factory_class.LookupFactory(Symbols::ListLiteralFactory()));
8566 ASSERT(!factory_method.IsNull()); 8537 ASSERT(!factory_method.IsNull());
8567 if (!type_arguments.IsNull() && 8538 if (!type_arguments.IsNull() &&
8568 !type_arguments.IsInstantiated() && 8539 !type_arguments.IsInstantiated() &&
8569 (current_block_->scope->function_level() > 0)) { 8540 (current_block_->scope->function_level() > 0)) {
8570 // Make sure that the instantiator is captured. 8541 // Make sure that the instantiator is captured.
8571 CaptureInstantiator(); 8542 CaptureInstantiator();
8572 } 8543 }
8573 AbstractTypeArguments& factory_type_args = 8544 AbstractTypeArguments& factory_type_args =
8574 AbstractTypeArguments::ZoneHandle(type_arguments.raw()); 8545 AbstractTypeArguments::ZoneHandle(type_arguments.raw());
8575 // If the factory class extends other parameterized classes, adjust the 8546 // If the factory class extends other parameterized classes, adjust the
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
8687 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); 8658 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2));
8688 map_type_arguments ^= map_type_arguments.Canonicalize(); 8659 map_type_arguments ^= map_type_arguments.Canonicalize();
8689 8660
8690 // The kv_pair array is temporary and of element type dynamic. It is passed 8661 // The kv_pair array is temporary and of element type dynamic. It is passed
8691 // to the factory to initialize a properly typed map. 8662 // to the factory to initialize a properly typed map.
8692 ArrayNode* kv_pairs = new ArrayNode( 8663 ArrayNode* kv_pairs = new ArrayNode(
8693 TokenPos(), Type::ZoneHandle(Type::ArrayType())); 8664 TokenPos(), Type::ZoneHandle(Type::ArrayType()));
8694 8665
8695 // Parse the map entries. Note: there may be an optional extra 8666 // Parse the map entries. Note: there may be an optional extra
8696 // comma after the last entry. 8667 // comma after the last entry.
8697 const String& dst_name = String::ZoneHandle(Symbols::ListLiteralElement());
8698 while (CurrentToken() != Token::kRBRACE) { 8668 while (CurrentToken() != Token::kRBRACE) {
8699 AstNode* key = NULL; 8669 AstNode* key = NULL;
8700 if (CurrentToken() == Token::kSTRING) { 8670 if (CurrentToken() == Token::kSTRING) {
8701 key = ParseStringLiteral(); 8671 key = ParseStringLiteral();
8702 } 8672 }
8703 if (key == NULL) { 8673 if (key == NULL) {
8704 ErrorMsg("map entry key must be string literal"); 8674 ErrorMsg("map entry key must be string literal");
8705 } else if (is_const && !key->IsLiteralNode()) { 8675 } else if (is_const && !key->IsLiteralNode()) {
8706 ErrorMsg("map entry key must be compile-time constant string"); 8676 ErrorMsg("map entry key must be compile-time constant string");
8707 } 8677 }
8708 ExpectToken(Token::kCOLON); 8678 ExpectToken(Token::kCOLON);
8709 const bool saved_mode = SetAllowFunctionLiterals(true); 8679 const bool saved_mode = SetAllowFunctionLiterals(true);
8710 const intptr_t value_pos = TokenPos(); 8680 const intptr_t value_pos = TokenPos();
8711 AstNode* value = ParseExpr(is_const, kConsumeCascades); 8681 AstNode* value = ParseExpr(is_const, kConsumeCascades);
8712 SetAllowFunctionLiterals(saved_mode); 8682 SetAllowFunctionLiterals(saved_mode);
8713 if (FLAG_enable_type_checks && 8683 if (FLAG_enable_type_checks &&
8714 !is_const && 8684 !is_const &&
8715 !value_type.IsDynamicType()) { 8685 !value_type.IsDynamicType()) {
8716 value = new AssignableNode(value_pos, 8686 value = new AssignableNode(value_pos,
8717 value, 8687 value,
8718 value_type, 8688 value_type,
8719 dst_name); 8689 Symbols::ListLiteralElement());
8720 } 8690 }
8721 AddKeyValuePair(kv_pairs, is_const, key, value); 8691 AddKeyValuePair(kv_pairs, is_const, key, value);
8722 8692
8723 if (CurrentToken() == Token::kCOMMA) { 8693 if (CurrentToken() == Token::kCOMMA) {
8724 ConsumeToken(); 8694 ConsumeToken();
8725 } else if (CurrentToken() != Token::kRBRACE) { 8695 } else if (CurrentToken() != Token::kRBRACE) {
8726 ErrorMsg("comma or '}' expected"); 8696 ErrorMsg("comma or '}' expected");
8727 } 8697 }
8728 } 8698 }
8729 ASSERT(kv_pairs->length() % 2 == 0); 8699 ASSERT(kv_pairs->length() % 2 == 0);
(...skipping 28 matching lines...) Expand all
8758 i >> 1, 8728 i >> 1,
8759 String::Handle(value_type.UserVisibleName()).ToCString()); 8729 String::Handle(value_type.UserVisibleName()).ToCString());
8760 } 8730 }
8761 } 8731 }
8762 key_value_array.SetAt(i, arg->AsLiteralNode()->literal()); 8732 key_value_array.SetAt(i, arg->AsLiteralNode()->literal());
8763 } 8733 }
8764 key_value_array ^= key_value_array.Canonicalize(); 8734 key_value_array ^= key_value_array.Canonicalize();
8765 key_value_array.MakeImmutable(); 8735 key_value_array.MakeImmutable();
8766 8736
8767 // Construct the map object. 8737 // Construct the map object.
8768 const String& immutable_map_class_name =
8769 String::Handle(Symbols::ImmutableMap());
8770 const Class& immutable_map_class = 8738 const Class& immutable_map_class =
8771 Class::Handle(LookupCoreClass(immutable_map_class_name)); 8739 Class::Handle(LookupCoreClass(Symbols::ImmutableMap()));
8772 ASSERT(!immutable_map_class.IsNull()); 8740 ASSERT(!immutable_map_class.IsNull());
8773 // If the immutable map class extends other parameterized classes, we need 8741 // If the immutable map class extends other parameterized classes, we need
8774 // to adjust the type argument vector. This is currently not the case. 8742 // to adjust the type argument vector. This is currently not the case.
8775 ASSERT(immutable_map_class.NumTypeArguments() == 2); 8743 ASSERT(immutable_map_class.NumTypeArguments() == 2);
8776 ArgumentListNode* constr_args = new ArgumentListNode(TokenPos()); 8744 ArgumentListNode* constr_args = new ArgumentListNode(TokenPos());
8777 constr_args->Add(new LiteralNode(literal_pos, key_value_array)); 8745 constr_args->Add(new LiteralNode(literal_pos, key_value_array));
8778 const String& constr_name = 8746 const Function& map_constr =
8779 String::Handle(Symbols::ImmutableMapConstructor()); 8747 Function::ZoneHandle(immutable_map_class.LookupConstructor(
8780 const Function& map_constr = Function::ZoneHandle( 8748 Symbols::ImmutableMapConstructor()));
8781 immutable_map_class.LookupConstructor(constr_name));
8782 ASSERT(!map_constr.IsNull()); 8749 ASSERT(!map_constr.IsNull());
8783 const Object& constructor_result = Object::Handle( 8750 const Object& constructor_result = Object::Handle(
8784 EvaluateConstConstructorCall(immutable_map_class, 8751 EvaluateConstConstructorCall(immutable_map_class,
8785 map_type_arguments, 8752 map_type_arguments,
8786 map_constr, 8753 map_constr,
8787 constr_args)); 8754 constr_args));
8788 if (constructor_result.IsUnhandledException()) { 8755 if (constructor_result.IsUnhandledException()) {
8789 return GenerateRethrow(literal_pos, constructor_result); 8756 return GenerateRethrow(literal_pos, constructor_result);
8790 } else { 8757 } else {
8791 const Instance& const_instance = Instance::Cast(constructor_result); 8758 const Instance& const_instance = Instance::Cast(constructor_result);
8792 return new LiteralNode(literal_pos, 8759 return new LiteralNode(literal_pos,
8793 Instance::ZoneHandle(const_instance.raw())); 8760 Instance::ZoneHandle(const_instance.raw()));
8794 } 8761 }
8795 } else { 8762 } else {
8796 // Factory call at runtime. 8763 // Factory call at runtime.
8797 String& factory_class_name = String::Handle(Symbols::Map());
8798 const Class& factory_class = 8764 const Class& factory_class =
8799 Class::Handle(LookupCoreClass(factory_class_name)); 8765 Class::Handle(LookupCoreClass(Symbols::Map()));
8800 ASSERT(!factory_class.IsNull()); 8766 ASSERT(!factory_class.IsNull());
8801 const String& factory_method_name =
8802 String::Handle(Symbols::MapLiteralFactory());
8803 const Function& factory_method = Function::ZoneHandle( 8767 const Function& factory_method = Function::ZoneHandle(
8804 factory_class.LookupFactory(factory_method_name)); 8768 factory_class.LookupFactory(Symbols::MapLiteralFactory()));
8805 ASSERT(!factory_method.IsNull()); 8769 ASSERT(!factory_method.IsNull());
8806 if (!map_type_arguments.IsNull() && 8770 if (!map_type_arguments.IsNull() &&
8807 !map_type_arguments.IsInstantiated() && 8771 !map_type_arguments.IsInstantiated() &&
8808 (current_block_->scope->function_level() > 0)) { 8772 (current_block_->scope->function_level() > 0)) {
8809 // Make sure that the instantiator is captured. 8773 // Make sure that the instantiator is captured.
8810 CaptureInstantiator(); 8774 CaptureInstantiator();
8811 } 8775 }
8812 AbstractTypeArguments& factory_type_args = 8776 AbstractTypeArguments& factory_type_args =
8813 AbstractTypeArguments::ZoneHandle(map_type_arguments.raw()); 8777 AbstractTypeArguments::ZoneHandle(map_type_arguments.raw());
8814 // If the factory class extends other parameterized classes, adjust the 8778 // If the factory class extends other parameterized classes, adjust the
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
8863 } 8827 }
8864 8828
8865 8829
8866 static const String& BuildConstructorName(const String& type_class_name, 8830 static const String& BuildConstructorName(const String& type_class_name,
8867 const String* named_constructor) { 8831 const String* named_constructor) {
8868 // By convention, the static function implementing a named constructor 'C' 8832 // By convention, the static function implementing a named constructor 'C'
8869 // for class 'A' is labeled 'A.C', and the static function implementing the 8833 // for class 'A' is labeled 'A.C', and the static function implementing the
8870 // unnamed constructor for class 'A' is labeled 'A.'. 8834 // unnamed constructor for class 'A' is labeled 'A.'.
8871 // This convention prevents users from explicitly calling constructors. 8835 // This convention prevents users from explicitly calling constructors.
8872 String& constructor_name = 8836 String& constructor_name =
8873 String::Handle(String::Concat(type_class_name, Symbols::DotHandle())); 8837 String::Handle(String::Concat(type_class_name, Symbols::Dot()));
8874 if (named_constructor != NULL) { 8838 if (named_constructor != NULL) {
8875 constructor_name = String::Concat(constructor_name, *named_constructor); 8839 constructor_name = String::Concat(constructor_name, *named_constructor);
8876 } 8840 }
8877 return constructor_name; 8841 return constructor_name;
8878 } 8842 }
8879 8843
8880 8844
8881 AstNode* Parser::ParseNewOperator() { 8845 AstNode* Parser::ParseNewOperator() {
8882 TRACE_PARSER("ParseNewOperator"); 8846 TRACE_PARSER("ParseNewOperator");
8883 const intptr_t new_pos = TokenPos(); 8847 const intptr_t new_pos = TokenPos();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
9004 8968
9005 // It is ok to call a factory method of an abstract class, but it is 8969 // It is ok to call a factory method of an abstract class, but it is
9006 // a dynamic error to instantiate an abstract class. 8970 // a dynamic error to instantiate an abstract class.
9007 ASSERT(!constructor.IsNull()); 8971 ASSERT(!constructor.IsNull());
9008 if (type_class.is_abstract() && !constructor.IsFactory()) { 8972 if (type_class.is_abstract() && !constructor.IsFactory()) {
9009 ArgumentListNode* arguments = new ArgumentListNode(type_pos); 8973 ArgumentListNode* arguments = new ArgumentListNode(type_pos);
9010 arguments->Add(new LiteralNode( 8974 arguments->Add(new LiteralNode(
9011 TokenPos(), Integer::ZoneHandle(Integer::New(type_pos)))); 8975 TokenPos(), Integer::ZoneHandle(Integer::New(type_pos))));
9012 arguments->Add(new LiteralNode( 8976 arguments->Add(new LiteralNode(
9013 TokenPos(), String::ZoneHandle(type_class_name.raw()))); 8977 TokenPos(), String::ZoneHandle(type_class_name.raw())));
9014 const String& cls_name = 8978 return MakeStaticCall(Symbols::AbstractClassInstantiationError(),
9015 String::Handle(Symbols::AbstractClassInstantiationError()); 8979 Symbols::ThrowNew(),
9016 const String& func_name = String::Handle(Symbols::ThrowNew()); 8980 arguments);
9017 return MakeStaticCall(cls_name, func_name, arguments);
9018 } 8981 }
9019 String& error_message = String::Handle(); 8982 String& error_message = String::Handle();
9020 if (!constructor.AreValidArguments(arguments_length, 8983 if (!constructor.AreValidArguments(arguments_length,
9021 arguments->names(), 8984 arguments->names(),
9022 &error_message)) { 8985 &error_message)) {
9023 const String& external_constructor_name = 8986 const String& external_constructor_name =
9024 (named_constructor ? constructor_name : type_class_name); 8987 (named_constructor ? constructor_name : type_class_name);
9025 if (is_const) { 8988 if (is_const) {
9026 ErrorMsg(call_pos, 8989 ErrorMsg(call_pos,
9027 "invalid arguments passed to constructor '%s' " 8990 "invalid arguments passed to constructor '%s' "
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
9086 (current_block_->scope->function_level() > 0)) { 9049 (current_block_->scope->function_level() > 0)) {
9087 // Make sure that the instantiator is captured. 9050 // Make sure that the instantiator is captured.
9088 CaptureInstantiator(); 9051 CaptureInstantiator();
9089 } 9052 }
9090 // If the type argument vector is not instantiated, we verify in checked 9053 // If the type argument vector is not instantiated, we verify in checked
9091 // mode at runtime that it is within its declared bounds. 9054 // mode at runtime that it is within its declared bounds.
9092 new_object = CreateConstructorCallNode( 9055 new_object = CreateConstructorCallNode(
9093 new_pos, type_arguments, constructor, arguments); 9056 new_pos, type_arguments, constructor, arguments);
9094 } 9057 }
9095 if (!type_bound.IsNull()) { 9058 if (!type_bound.IsNull()) {
9096 const String& dst_name = String::ZoneHandle(Symbols::FactoryResult()); 9059 new_object = new AssignableNode(new_pos,
9097 new_object = new AssignableNode(new_pos, new_object, type_bound, dst_name); 9060 new_object,
9061 type_bound,
9062 Symbols::FactoryResult());
9098 } 9063 }
9099 return new_object; 9064 return new_object;
9100 } 9065 }
9101 9066
9102 9067
9103 String& Parser::Interpolate(ArrayNode* values) { 9068 String& Parser::Interpolate(ArrayNode* values) {
9104 const String& class_name = String::Handle(Symbols::StringBase()); 9069 const Class& cls = Class::Handle(LookupCoreClass(Symbols::StringBase()));
9105 const Class& cls = Class::Handle(LookupCoreClass(class_name));
9106 ASSERT(!cls.IsNull()); 9070 ASSERT(!cls.IsNull());
9107 const String& func_name = String::Handle(Symbols::Interpolate());
9108 const Function& func = 9071 const Function& func =
9109 Function::Handle(cls.LookupStaticFunction(func_name)); 9072 Function::Handle(cls.LookupStaticFunction(Symbols::Interpolate()));
9110 ASSERT(!func.IsNull()); 9073 ASSERT(!func.IsNull());
9111 9074
9112 // Build the array of literal values to interpolate. 9075 // Build the array of literal values to interpolate.
9113 const Array& value_arr = Array::Handle(Array::New(values->length())); 9076 const Array& value_arr = Array::Handle(Array::New(values->length()));
9114 for (int i = 0; i < values->length(); i++) { 9077 for (int i = 0; i < values->length(); i++) {
9115 ASSERT(values->ElementAt(i)->IsLiteralNode()); 9078 ASSERT(values->ElementAt(i)->IsLiteralNode());
9116 value_arr.SetAt(i, values->ElementAt(i)->AsLiteralNode()->literal()); 9079 value_arr.SetAt(i, values->ElementAt(i)->AsLiteralNode()->literal());
9117 } 9080 }
9118 9081
9119 // Build argument array to pass to the interpolation function. 9082 // Build argument array to pass to the interpolation function.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
9190 } 9153 }
9191 values->AddElement(expr); 9154 values->AddElement(expr);
9192 } 9155 }
9193 } 9156 }
9194 if (is_compiletime_const) { 9157 if (is_compiletime_const) {
9195 primary = new LiteralNode(literal_start, Interpolate(values)); 9158 primary = new LiteralNode(literal_start, Interpolate(values));
9196 } else { 9159 } else {
9197 ArgumentListNode* interpolate_arg = 9160 ArgumentListNode* interpolate_arg =
9198 new ArgumentListNode(values->token_pos()); 9161 new ArgumentListNode(values->token_pos());
9199 interpolate_arg->Add(values); 9162 interpolate_arg->Add(values);
9200 const String& cls_name = String::Handle(Symbols::StringBase()); 9163 primary = MakeStaticCall(Symbols::StringBase(),
9201 const String& func_name = String::Handle(Symbols::Interpolate()); 9164 Symbols::Interpolate(),
9202 primary = MakeStaticCall(cls_name, func_name, interpolate_arg); 9165 interpolate_arg);
9203 } 9166 }
9204 return primary; 9167 return primary;
9205 } 9168 }
9206 9169
9207 9170
9208 AstNode* Parser::ParseArgumentDefinitionTest() { 9171 AstNode* Parser::ParseArgumentDefinitionTest() {
9209 const intptr_t test_pos = TokenPos(); 9172 const intptr_t test_pos = TokenPos();
9210 ConsumeToken(); 9173 ConsumeToken();
9211 const intptr_t ident_pos = TokenPos(); 9174 const intptr_t ident_pos = TokenPos();
9212 String* ident = ExpectIdentifier("parameter name expected"); 9175 String* ident = ExpectIdentifier("parameter name expected");
9213 Function& owner_function = Function::Handle(); 9176 Function& owner_function = Function::Handle();
9214 LocalScope* owner_scope; 9177 LocalScope* owner_scope;
9215 intptr_t param_index; 9178 intptr_t param_index;
9216 if (!IsFormalParameter(*ident, &owner_function, &owner_scope, &param_index)) { 9179 if (!IsFormalParameter(*ident, &owner_function, &owner_scope, &param_index)) {
9217 ErrorMsg(ident_pos, "formal parameter name expected"); 9180 ErrorMsg(ident_pos, "formal parameter name expected");
9218 } 9181 }
9219 if (param_index < owner_function.num_fixed_parameters()) { 9182 if (param_index < owner_function.num_fixed_parameters()) {
9220 // The formal parameter is not optional, therefore the corresponding 9183 // The formal parameter is not optional, therefore the corresponding
9221 // argument is always passed and defined. 9184 // argument is always passed and defined.
9222 return new LiteralNode(test_pos, Bool::ZoneHandle(Bool::True())); 9185 return new LiteralNode(test_pos, Bool::ZoneHandle(Bool::True()));
9223 } 9186 }
9224 char name[64]; 9187 char name[64];
9225 OS::SNPrint(name, 64, "%s_%"Pd"", 9188 OS::SNPrint(name, 64, "%s_%"Pd"",
9226 Symbols::Name(Symbols::kSavedArgDescVarPrefix), 9189 Symbols::Name(Symbols::kSavedArgDescVarPrefixId),
9227 owner_function.token_pos()); 9190 owner_function.token_pos());
9228 const String& saved_args_desc_name = String::ZoneHandle(Symbols::New(name)); 9191 const String& saved_args_desc_name = String::ZoneHandle(Symbols::New(name));
9229 LocalVariable* saved_args_desc_var = LookupLocalScope(saved_args_desc_name); 9192 LocalVariable* saved_args_desc_var = LookupLocalScope(saved_args_desc_name);
9230 if (saved_args_desc_var == NULL) { 9193 if (saved_args_desc_var == NULL) {
9231 ASSERT(owner_scope != NULL); 9194 ASSERT(owner_scope != NULL);
9232 saved_args_desc_var = 9195 saved_args_desc_var =
9233 new LocalVariable(owner_function.token_pos(), 9196 new LocalVariable(owner_function.token_pos(),
9234 saved_args_desc_name, 9197 saved_args_desc_name,
9235 Type::ZoneHandle(Type::ArrayType())); 9198 Type::ZoneHandle(Type::ArrayType()));
9236 saved_args_desc_var->set_is_final(); 9199 saved_args_desc_var->set_is_final();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
9295 } else { 9258 } else {
9296 // This is a qualified identifier with a library prefix so resolve 9259 // This is a qualified identifier with a library prefix so resolve
9297 // the identifier locally in that library (we do not include the 9260 // the identifier locally in that library (we do not include the
9298 // libraries imported by that library). 9261 // libraries imported by that library).
9299 primary = ResolveIdentInPrefixScope(qual_ident.ident_pos, 9262 primary = ResolveIdentInPrefixScope(qual_ident.ident_pos,
9300 *qual_ident.lib_prefix, 9263 *qual_ident.lib_prefix,
9301 *qual_ident.ident); 9264 *qual_ident.ident);
9302 } 9265 }
9303 ASSERT(primary != NULL); 9266 ASSERT(primary != NULL);
9304 } else if (CurrentToken() == Token::kTHIS) { 9267 } else if (CurrentToken() == Token::kTHIS) {
9305 LocalVariable* local = LookupLocalScope(Symbols::ThisHandle()); 9268 LocalVariable* local = LookupLocalScope(Symbols::This());
9306 if (local == NULL) { 9269 if (local == NULL) {
9307 ErrorMsg("receiver 'this' is not in scope"); 9270 ErrorMsg("receiver 'this' is not in scope");
9308 } 9271 }
9309 primary = new LoadLocalNode(TokenPos(), local); 9272 primary = new LoadLocalNode(TokenPos(), local);
9310 ConsumeToken(); 9273 ConsumeToken();
9311 } else if (CurrentToken() == Token::kINTEGER) { 9274 } else if (CurrentToken() == Token::kINTEGER) {
9312 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); 9275 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral());
9313 primary = new LiteralNode(TokenPos(), literal); 9276 primary = new LiteralNode(TokenPos(), literal);
9314 ConsumeToken(); 9277 ConsumeToken();
9315 } else if (CurrentToken() == Token::kTRUE) { 9278 } else if (CurrentToken() == Token::kTRUE) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
9367 if (CurrentToken() == Token::kLPAREN) { 9330 if (CurrentToken() == Token::kLPAREN) {
9368 primary = ParseSuperCall(ident); 9331 primary = ParseSuperCall(ident);
9369 } else { 9332 } else {
9370 primary = ParseSuperFieldAccess(ident); 9333 primary = ParseSuperFieldAccess(ident);
9371 } 9334 }
9372 } else if ((CurrentToken() == Token::kLBRACK) || 9335 } else if ((CurrentToken() == Token::kLBRACK) ||
9373 Token::CanBeOverloaded(CurrentToken()) || 9336 Token::CanBeOverloaded(CurrentToken()) ||
9374 (CurrentToken() == Token::kNE)) { 9337 (CurrentToken() == Token::kNE)) {
9375 primary = ParseSuperOperator(); 9338 primary = ParseSuperOperator();
9376 } else { 9339 } else {
9377 primary = new PrimaryNode(TokenPos(), 9340 primary = new PrimaryNode(TokenPos(), Symbols::Super());
9378 String::ZoneHandle(Symbols::Super()));
9379 } 9341 }
9380 } else if (CurrentToken() == Token::kCONDITIONAL) { 9342 } else if (CurrentToken() == Token::kCONDITIONAL) {
9381 primary = ParseArgumentDefinitionTest(); 9343 primary = ParseArgumentDefinitionTest();
9382 } else { 9344 } else {
9383 UnexpectedToken(); 9345 UnexpectedToken();
9384 } 9346 }
9385 return primary; 9347 return primary;
9386 } 9348 }
9387 9349
9388 9350
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
9694 void Parser::SkipQualIdent() { 9656 void Parser::SkipQualIdent() {
9695 ASSERT(IsIdentifier()); 9657 ASSERT(IsIdentifier());
9696 ConsumeToken(); 9658 ConsumeToken();
9697 if (CurrentToken() == Token::kPERIOD) { 9659 if (CurrentToken() == Token::kPERIOD) {
9698 ConsumeToken(); // Consume the kPERIOD token. 9660 ConsumeToken(); // Consume the kPERIOD token.
9699 ExpectIdentifier("identifier expected after '.'"); 9661 ExpectIdentifier("identifier expected after '.'");
9700 } 9662 }
9701 } 9663 }
9702 9664
9703 } // namespace dart 9665 } // namespace dart
OLDNEW
« vm/intermediate_language_x64.cc ('K') | « vm/object_test.cc ('k') | vm/resolver_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698