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

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, 11 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(ident_pos)); 956 params.AddReceiver(ReceiverType(ident_pos));
959 params.AddFinalParameter(ident_pos, 957 params.AddFinalParameter(ident_pos,
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 arguments->names(), 1296 arguments->names(),
1299 NULL)) { 1297 NULL)) {
1300 super_func = Function::null(); 1298 super_func = Function::null();
1301 } else if (super_func.IsNull() && resolve_getter) { 1299 } else if (super_func.IsNull() && resolve_getter) {
1302 const String& getter_name = String::ZoneHandle(Field::GetterName(name)); 1300 const String& getter_name = String::ZoneHandle(Field::GetterName(name));
1303 super_func = Resolver::ResolveDynamicAnyArgs(super_class, getter_name); 1301 super_func = Resolver::ResolveDynamicAnyArgs(super_class, getter_name);
1304 ASSERT(super_func.IsNull() || 1302 ASSERT(super_func.IsNull() ||
1305 (super_func.kind() != RawFunction::kConstImplicitGetter)); 1303 (super_func.kind() != RawFunction::kConstImplicitGetter));
1306 } 1304 }
1307 if (super_func.IsNull()) { 1305 if (super_func.IsNull()) {
1308 const String& no_such_method_name = String::Handle(Symbols::NoSuchMethod());
1309 super_func = 1306 super_func =
1310 Resolver::ResolveDynamicAnyArgs(super_class, no_such_method_name); 1307 Resolver::ResolveDynamicAnyArgs(super_class, Symbols::NoSuchMethod());
1311 ASSERT(!super_func.IsNull()); 1308 ASSERT(!super_func.IsNull());
1312 *is_no_such_method = true; 1309 *is_no_such_method = true;
1313 } else { 1310 } else {
1314 *is_no_such_method = false; 1311 *is_no_such_method = false;
1315 } 1312 }
1316 return super_func.raw(); 1313 return super_func.raw();
1317 } 1314 }
1318 1315
1319 1316
1320 // Lookup class in the core lib which also contains various VM 1317 // Lookup class in the core lib which also contains various VM
(...skipping 27 matching lines...) Expand all
1348 arguments->Add(new LiteralNode(args_pos, args_descriptor)); 1345 arguments->Add(new LiteralNode(args_pos, args_descriptor));
1349 // The third argument is an array containing the original function arguments, 1346 // The third argument is an array containing the original function arguments,
1350 // including the receiver. 1347 // including the receiver.
1351 ArrayNode* args_array = new ArrayNode( 1348 ArrayNode* args_array = new ArrayNode(
1352 args_pos, Type::ZoneHandle(Type::ArrayType())); 1349 args_pos, Type::ZoneHandle(Type::ArrayType()));
1353 for (intptr_t i = 0; i < function_args.length(); i++) { 1350 for (intptr_t i = 0; i < function_args.length(); i++) {
1354 args_array->AddElement(function_args.NodeAt(i)); 1351 args_array->AddElement(function_args.NodeAt(i));
1355 } 1352 }
1356 arguments->Add(args_array); 1353 arguments->Add(args_array);
1357 // Lookup the static InvocationMirror._allocateInvocationMirror method. 1354 // Lookup the static InvocationMirror._allocateInvocationMirror method.
1358 const Class& mirror_class = Class::Handle( 1355 const Class& mirror_class =
1359 LookupCoreClass(String::Handle(Symbols::InvocationMirror()))); 1356 Class::Handle(LookupCoreClass(Symbols::InvocationMirror()));
1360 ASSERT(!mirror_class.IsNull()); 1357 ASSERT(!mirror_class.IsNull());
1361 const String& allocation_function_name =
1362 String::Handle(Symbols::AllocateInvocationMirror());
1363 const Function& allocation_function = Function::ZoneHandle( 1358 const Function& allocation_function = Function::ZoneHandle(
1364 mirror_class.LookupStaticFunction(allocation_function_name)); 1359 mirror_class.LookupStaticFunction(Symbols::AllocateInvocationMirror()));
1365 ASSERT(!allocation_function.IsNull()); 1360 ASSERT(!allocation_function.IsNull());
1366 return new StaticCallNode(call_pos, allocation_function, arguments); 1361 return new StaticCallNode(call_pos, allocation_function, arguments);
1367 } 1362 }
1368 1363
1369 1364
1370 ArgumentListNode* Parser::BuildNoSuchMethodArguments( 1365 ArgumentListNode* Parser::BuildNoSuchMethodArguments(
1371 intptr_t call_pos, 1366 intptr_t call_pos,
1372 const String& function_name, 1367 const String& function_name,
1373 const ArgumentListNode& function_args) { 1368 const ArgumentListNode& function_args) {
1374 ASSERT(function_args.length() >= 1); // The receiver is the first argument. 1369 ASSERT(function_args.length() >= 1); // The receiver is the first argument.
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 const Class& super_class = Class::Handle(cls.SuperClass()); 1594 const Class& super_class = Class::Handle(cls.SuperClass());
1600 // Omit the implicit super() if there is no super class (i.e. 1595 // Omit the implicit super() if there is no super class (i.e.
1601 // we're not compiling class Object), or if the super class is an 1596 // we're not compiling class Object), or if the super class is an
1602 // artificially generated "wrapper class" that has no constructor. 1597 // artificially generated "wrapper class" that has no constructor.
1603 if (super_class.IsNull() || 1598 if (super_class.IsNull() ||
1604 (super_class.num_native_fields() > 0 && 1599 (super_class.num_native_fields() > 0 &&
1605 Class::Handle(super_class.SuperClass()).IsObjectClass())) { 1600 Class::Handle(super_class.SuperClass()).IsObjectClass())) {
1606 return; 1601 return;
1607 } 1602 }
1608 String& ctor_name = String::Handle(super_class.Name()); 1603 String& ctor_name = String::Handle(super_class.Name());
1609 ctor_name = String::Concat(ctor_name, Symbols::DotHandle()); 1604 ctor_name = String::Concat(ctor_name, Symbols::Dot());
1610 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); 1605 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos);
1611 // Implicit 'this' parameter is the first argument. 1606 // Implicit 'this' parameter is the first argument.
1612 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver); 1607 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver);
1613 arguments->Add(implicit_argument); 1608 arguments->Add(implicit_argument);
1614 // Implicit construction phase parameter is second argument. 1609 // Implicit construction phase parameter is second argument.
1615 AstNode* phase_parameter = 1610 AstNode* phase_parameter =
1616 new LiteralNode(supercall_pos, 1611 new LiteralNode(supercall_pos,
1617 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); 1612 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll)));
1618 arguments->Add(phase_parameter); 1613 arguments->Add(phase_parameter);
1619 const Function& super_ctor = Function::ZoneHandle( 1614 const Function& super_ctor = Function::ZoneHandle(
(...skipping 19 matching lines...) Expand all
1639 1634
1640 AstNode* Parser::ParseSuperInitializer(const Class& cls, 1635 AstNode* Parser::ParseSuperInitializer(const Class& cls,
1641 LocalVariable* receiver) { 1636 LocalVariable* receiver) {
1642 TRACE_PARSER("ParseSuperInitializer"); 1637 TRACE_PARSER("ParseSuperInitializer");
1643 ASSERT(CurrentToken() == Token::kSUPER); 1638 ASSERT(CurrentToken() == Token::kSUPER);
1644 const intptr_t supercall_pos = TokenPos(); 1639 const intptr_t supercall_pos = TokenPos();
1645 ConsumeToken(); 1640 ConsumeToken();
1646 const Class& super_class = Class::Handle(cls.SuperClass()); 1641 const Class& super_class = Class::Handle(cls.SuperClass());
1647 ASSERT(!super_class.IsNull()); 1642 ASSERT(!super_class.IsNull());
1648 String& ctor_name = String::Handle(super_class.Name()); 1643 String& ctor_name = String::Handle(super_class.Name());
1649 ctor_name = String::Concat(ctor_name, Symbols::DotHandle()); 1644 ctor_name = String::Concat(ctor_name, Symbols::Dot());
1650 if (CurrentToken() == Token::kPERIOD) { 1645 if (CurrentToken() == Token::kPERIOD) {
1651 ConsumeToken(); 1646 ConsumeToken();
1652 ctor_name = String::Concat(ctor_name, 1647 ctor_name = String::Concat(ctor_name,
1653 *ExpectIdentifier("constructor name expected")); 1648 *ExpectIdentifier("constructor name expected"));
1654 } 1649 }
1655 if (CurrentToken() != Token::kLPAREN) { 1650 if (CurrentToken() != Token::kLPAREN) {
1656 ErrorMsg("parameter list expected"); 1651 ErrorMsg("parameter list expected");
1657 } 1652 }
1658 1653
1659 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); 1654 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 1853
1859 1854
1860 void Parser::ParseConstructorRedirection(const Class& cls, 1855 void Parser::ParseConstructorRedirection(const Class& cls,
1861 LocalVariable* receiver) { 1856 LocalVariable* receiver) {
1862 TRACE_PARSER("ParseConstructorRedirection"); 1857 TRACE_PARSER("ParseConstructorRedirection");
1863 ASSERT(CurrentToken() == Token::kTHIS); 1858 ASSERT(CurrentToken() == Token::kTHIS);
1864 const intptr_t call_pos = TokenPos(); 1859 const intptr_t call_pos = TokenPos();
1865 ConsumeToken(); 1860 ConsumeToken();
1866 String& ctor_name = String::Handle(cls.Name()); 1861 String& ctor_name = String::Handle(cls.Name());
1867 1862
1868 ctor_name = String::Concat(ctor_name, Symbols::DotHandle()); 1863 ctor_name = String::Concat(ctor_name, Symbols::Dot());
1869 if (CurrentToken() == Token::kPERIOD) { 1864 if (CurrentToken() == Token::kPERIOD) {
1870 ConsumeToken(); 1865 ConsumeToken();
1871 ctor_name = String::Concat(ctor_name, 1866 ctor_name = String::Concat(ctor_name,
1872 *ExpectIdentifier("constructor name expected")); 1867 *ExpectIdentifier("constructor name expected"));
1873 } 1868 }
1874 if (CurrentToken() != Token::kLPAREN) { 1869 if (CurrentToken() != Token::kLPAREN) {
1875 ErrorMsg("parameter list expected"); 1870 ErrorMsg("parameter list expected");
1876 } 1871 }
1877 1872
1878 ArgumentListNode* arguments = new ArgumentListNode(call_pos); 1873 ArgumentListNode* arguments = new ArgumentListNode(call_pos);
(...skipping 28 matching lines...) Expand all
1907 } 1902 }
1908 1903
1909 1904
1910 SequenceNode* Parser::MakeImplicitConstructor(const Function& func) { 1905 SequenceNode* Parser::MakeImplicitConstructor(const Function& func) {
1911 ASSERT(func.IsConstructor()); 1906 ASSERT(func.IsConstructor());
1912 const intptr_t ctor_pos = TokenPos(); 1907 const intptr_t ctor_pos = TokenPos();
1913 OpenFunctionBlock(func); 1908 OpenFunctionBlock(func);
1914 const Class& cls = Class::Handle(func.Owner()); 1909 const Class& cls = Class::Handle(func.Owner());
1915 LocalVariable* receiver = new LocalVariable( 1910 LocalVariable* receiver = new LocalVariable(
1916 ctor_pos, 1911 ctor_pos,
1917 Symbols::ThisHandle(), 1912 Symbols::This(),
1918 Type::ZoneHandle(Type::DynamicType())); 1913 Type::ZoneHandle(Type::DynamicType()));
1919 current_block_->scope->AddVariable(receiver); 1914 current_block_->scope->AddVariable(receiver);
1920 1915
1921 LocalVariable* phase_parameter = new LocalVariable( 1916 LocalVariable* phase_parameter = new LocalVariable(
1922 ctor_pos, 1917 ctor_pos,
1923 String::ZoneHandle(Symbols::PhaseParameter()), 1918 Symbols::PhaseParameter(),
1924 Type::ZoneHandle(Type::SmiType())); 1919 Type::ZoneHandle(Type::SmiType()));
1925 current_block_->scope->AddVariable(phase_parameter); 1920 current_block_->scope->AddVariable(phase_parameter);
1926 1921
1927 // Parse expressions of instance fields that have an explicit 1922 // Parse expressions of instance fields that have an explicit
1928 // initializer expression. 1923 // initializer expression.
1929 // The receiver must not be visible to field initializer expressions. 1924 // The receiver must not be visible to field initializer expressions.
1930 receiver->set_invisible(true); 1925 receiver->set_invisible(true);
1931 GrowableArray<Field*> initialized_fields; 1926 GrowableArray<Field*> initialized_fields;
1932 ParseInitializedInstanceFields(cls, receiver, &initialized_fields); 1927 ParseInitializedInstanceFields(cls, receiver, &initialized_fields);
1933 receiver->set_invisible(false); 1928 receiver->set_invisible(false);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 ASSERT(CurrentToken() == Token::kLPAREN); 1976 ASSERT(CurrentToken() == Token::kLPAREN);
1982 1977
1983 // Add implicit receiver parameter which is passed the allocated 1978 // Add implicit receiver parameter which is passed the allocated
1984 // but uninitialized instance to construct. 1979 // but uninitialized instance to construct.
1985 ASSERT(current_class().raw() == func.Owner()); 1980 ASSERT(current_class().raw() == func.Owner());
1986 params.AddReceiver(ReceiverType(TokenPos())); 1981 params.AddReceiver(ReceiverType(TokenPos()));
1987 1982
1988 // Add implicit parameter for construction phase. 1983 // Add implicit parameter for construction phase.
1989 params.AddFinalParameter( 1984 params.AddFinalParameter(
1990 TokenPos(), 1985 TokenPos(),
1991 &String::ZoneHandle(Symbols::PhaseParameter()), 1986 &Symbols::PhaseParameter(),
1992 &Type::ZoneHandle(Type::SmiType())); 1987 &Type::ZoneHandle(Type::SmiType()));
1993 1988
1994 if (func.is_const()) { 1989 if (func.is_const()) {
1995 params.SetImplicitlyFinal(); 1990 params.SetImplicitlyFinal();
1996 } 1991 }
1997 ParseFormalParameterList(allow_explicit_default_values, &params); 1992 ParseFormalParameterList(allow_explicit_default_values, &params);
1998 1993
1999 SetupDefaultsForOptionalParams(&params, default_parameter_values); 1994 SetupDefaultsForOptionalParams(&params, default_parameter_values);
2000 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); 1995 ASSERT(AbstractType::Handle(func.result_type()).IsResolved());
2001 ASSERT(func.NumParameters() == params.parameters->length()); 1996 ASSERT(func.NumParameters() == params.parameters->length());
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
2229 OpenFunctionBlock(func); // Build local scope for function. 2224 OpenFunctionBlock(func); // Build local scope for function.
2230 2225
2231 ParamList params; 2226 ParamList params;
2232 // An instance closure function may capture and access the receiver, but via 2227 // An instance closure function may capture and access the receiver, but via
2233 // the context and not via the first formal parameter. 2228 // the context and not via the first formal parameter.
2234 if (func.IsClosureFunction()) { 2229 if (func.IsClosureFunction()) {
2235 // The first parameter of a closure function is the closure object. 2230 // The first parameter of a closure function is the closure object.
2236 ASSERT(!func.is_const()); // Closure functions cannot be const. 2231 ASSERT(!func.is_const()); // Closure functions cannot be const.
2237 params.AddFinalParameter( 2232 params.AddFinalParameter(
2238 TokenPos(), 2233 TokenPos(),
2239 &String::ZoneHandle(Symbols::ClosureParameter()), 2234 &Symbols::ClosureParameter(),
2240 &Type::ZoneHandle(Type::DynamicType())); 2235 &Type::ZoneHandle(Type::DynamicType()));
2241 } else if (!func.is_static()) { 2236 } else if (!func.is_static()) {
2242 // Static functions do not have a receiver. 2237 // Static functions do not have a receiver.
2243 ASSERT(current_class().raw() == func.Owner()); 2238 ASSERT(current_class().raw() == func.Owner());
2244 params.AddReceiver(ReceiverType(TokenPos())); 2239 params.AddReceiver(ReceiverType(TokenPos()));
2245 } else if (func.IsFactory()) { 2240 } else if (func.IsFactory()) {
2246 // The first parameter of a factory is the AbstractTypeArguments vector of 2241 // The first parameter of a factory is the AbstractTypeArguments vector of
2247 // the type of the instance to be allocated. 2242 // the type of the instance to be allocated.
2248 params.AddFinalParameter( 2243 params.AddFinalParameter(
2249 TokenPos(), 2244 TokenPos(),
2250 &String::ZoneHandle(Symbols::TypeArgumentsParameter()), 2245 &Symbols::TypeArgumentsParameter(),
2251 &Type::ZoneHandle(Type::DynamicType())); 2246 &Type::ZoneHandle(Type::DynamicType()));
2252 } 2247 }
2253 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction()); 2248 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction());
2254 const bool allow_explicit_default_values = true; 2249 const bool allow_explicit_default_values = true;
2255 if (!func.IsGetterFunction()) { 2250 if (!func.IsGetterFunction()) {
2256 ParseFormalParameterList(allow_explicit_default_values, &params); 2251 ParseFormalParameterList(allow_explicit_default_values, &params);
2257 } else { 2252 } else {
2258 // TODO(hausner): Remove this once we no longer support the old 2253 // TODO(hausner): Remove this once we no longer support the old
2259 // getter syntax with explicit empty parameter list. 2254 // getter syntax with explicit empty parameter list.
2260 if (CurrentToken() == Token::kLPAREN) { 2255 if (CurrentToken() == Token::kLPAREN) {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
2449 const intptr_t formal_param_pos = TokenPos(); 2444 const intptr_t formal_param_pos = TokenPos();
2450 method->params.Clear(); 2445 method->params.Clear();
2451 // Static functions do not have a receiver. 2446 // Static functions do not have a receiver.
2452 // The first parameter of a factory is the AbstractTypeArguments vector of 2447 // The first parameter of a factory is the AbstractTypeArguments vector of
2453 // the type of the instance to be allocated. 2448 // the type of the instance to be allocated.
2454 if (!method->has_static || method->IsConstructor()) { 2449 if (!method->has_static || method->IsConstructor()) {
2455 method->params.AddReceiver(ReceiverType(formal_param_pos)); 2450 method->params.AddReceiver(ReceiverType(formal_param_pos));
2456 } else if (method->IsFactory()) { 2451 } else if (method->IsFactory()) {
2457 method->params.AddFinalParameter( 2452 method->params.AddFinalParameter(
2458 formal_param_pos, 2453 formal_param_pos,
2459 &String::ZoneHandle(Symbols::TypeArgumentsParameter()), 2454 &Symbols::TypeArgumentsParameter(),
2460 &Type::ZoneHandle(Type::DynamicType())); 2455 &Type::ZoneHandle(Type::DynamicType()));
2461 } 2456 }
2462 // Constructors have an implicit parameter for the construction phase. 2457 // Constructors have an implicit parameter for the construction phase.
2463 if (method->IsConstructor()) { 2458 if (method->IsConstructor()) {
2464 method->params.AddFinalParameter( 2459 method->params.AddFinalParameter(
2465 TokenPos(), 2460 TokenPos(),
2466 &String::ZoneHandle(Symbols::PhaseParameter()), 2461 &Symbols::PhaseParameter(),
2467 &Type::ZoneHandle(Type::SmiType())); 2462 &Type::ZoneHandle(Type::SmiType()));
2468 } 2463 }
2469 if (are_implicitly_final) { 2464 if (are_implicitly_final) {
2470 method->params.SetImplicitlyFinal(); 2465 method->params.SetImplicitlyFinal();
2471 } 2466 }
2472 if (!method->IsGetter()) { 2467 if (!method->IsGetter()) {
2473 ParseFormalParameterList(allow_explicit_default_values, &method->params); 2468 ParseFormalParameterList(allow_explicit_default_values, &method->params);
2474 } 2469 }
2475 2470
2476 // Now that we know the parameter list, we can distinguish between the 2471 // Now that we know the parameter list, we can distinguish between the
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 // Redirected constructor: either this(...) or this.xxx(...). 2545 // Redirected constructor: either this(...) or this.xxx(...).
2551 if (method->params.has_field_initializer) { 2546 if (method->params.has_field_initializer) {
2552 // Constructors that redirect to another constructor must not 2547 // Constructors that redirect to another constructor must not
2553 // initialize any fields using field initializer parameters. 2548 // initialize any fields using field initializer parameters.
2554 ErrorMsg(formal_param_pos, "Redirecting constructor " 2549 ErrorMsg(formal_param_pos, "Redirecting constructor "
2555 "may not use field initializer parameters"); 2550 "may not use field initializer parameters");
2556 } 2551 }
2557 ConsumeToken(); // Colon. 2552 ConsumeToken(); // Colon.
2558 ExpectToken(Token::kTHIS); 2553 ExpectToken(Token::kTHIS);
2559 String& redir_name = String::ZoneHandle( 2554 String& redir_name = String::ZoneHandle(
2560 String::Concat(members->class_name(), Symbols::DotHandle())); 2555 String::Concat(members->class_name(), Symbols::Dot()));
2561 if (CurrentToken() == Token::kPERIOD) { 2556 if (CurrentToken() == Token::kPERIOD) {
2562 ConsumeToken(); 2557 ConsumeToken();
2563 redir_name = String::Concat(redir_name, 2558 redir_name = String::Concat(redir_name,
2564 *ExpectIdentifier("constructor name expected")); 2559 *ExpectIdentifier("constructor name expected"));
2565 } 2560 }
2566 method->redirect_name = &redir_name; 2561 method->redirect_name = &redir_name;
2567 if (CurrentToken() != Token::kLPAREN) { 2562 if (CurrentToken() != Token::kLPAREN) {
2568 ErrorMsg("'(' expected"); 2563 ErrorMsg("'(' expected");
2569 } 2564 }
2570 SkipToMatchingParenthesis(); 2565 SkipToMatchingParenthesis();
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
2808 field->has_static, 2803 field->has_static,
2809 field->has_final, 2804 field->has_final,
2810 /* is_abstract = */ false, 2805 /* is_abstract = */ false,
2811 /* is_external = */ false, 2806 /* is_external = */ false,
2812 current_class(), 2807 current_class(),
2813 field->name_pos); 2808 field->name_pos);
2814 ParamList params; 2809 ParamList params;
2815 ASSERT(current_class().raw() == setter.Owner()); 2810 ASSERT(current_class().raw() == setter.Owner());
2816 params.AddReceiver(ReceiverType(TokenPos())); 2811 params.AddReceiver(ReceiverType(TokenPos()));
2817 params.AddFinalParameter(TokenPos(), 2812 params.AddFinalParameter(TokenPos(),
2818 &String::ZoneHandle(Symbols::Value()), 2813 &Symbols::Value(),
2819 field->type); 2814 field->type);
2820 setter.set_result_type(Type::Handle(Type::VoidType())); 2815 setter.set_result_type(Type::Handle(Type::VoidType()));
2821 AddFormalParamsToFunction(&params, setter); 2816 AddFormalParamsToFunction(&params, setter);
2822 members->AddFunction(setter); 2817 members->AddFunction(setter);
2823 } 2818 }
2824 } 2819 }
2825 2820
2826 if (CurrentToken() != Token::kCOMMA) { 2821 if (CurrentToken() != Token::kCOMMA) {
2827 break; 2822 break;
2828 } 2823 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2956 member.name_pos)); 2951 member.name_pos));
2957 // The type arguments of the result type are set during finalization. 2952 // The type arguments of the result type are set during finalization.
2958 member.type = &Type::ZoneHandle(Type::New(result_type_class, 2953 member.type = &Type::ZoneHandle(Type::New(result_type_class,
2959 TypeArguments::Handle(), 2954 TypeArguments::Handle(),
2960 member.name_pos)); 2955 member.name_pos));
2961 } else if (member.has_static) { 2956 } else if (member.has_static) {
2962 ErrorMsg(member.name_pos, "constructor cannot be static"); 2957 ErrorMsg(member.name_pos, "constructor cannot be static");
2963 } 2958 }
2964 // We must be dealing with a constructor or named constructor. 2959 // We must be dealing with a constructor or named constructor.
2965 member.kind = RawFunction::kConstructor; 2960 member.kind = RawFunction::kConstructor;
2966 *member.name = String::Concat(*member.name, Symbols::DotHandle()); 2961 *member.name = String::Concat(*member.name, Symbols::Dot());
2967 if (CurrentToken() == Token::kPERIOD) { 2962 if (CurrentToken() == Token::kPERIOD) {
2968 // Named constructor. 2963 // Named constructor.
2969 ConsumeToken(); 2964 ConsumeToken();
2970 member.constructor_name = ExpectIdentifier("identifier expected"); 2965 member.constructor_name = ExpectIdentifier("identifier expected");
2971 *member.name = String::Concat(*member.name, *member.constructor_name); 2966 *member.name = String::Concat(*member.name, *member.constructor_name);
2972 } 2967 }
2973 // Ensure that names are symbols. 2968 // Ensure that names are symbols.
2974 *member.name = Symbols::New(*member.name); 2969 *member.name = Symbols::New(*member.name);
2975 if (member.type == NULL) { 2970 if (member.type == NULL) {
2976 ASSERT(!member.has_factory); 2971 ASSERT(!member.has_factory);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3103 } 3098 }
3104 cls = Class::New(class_name, script_, classname_pos); 3099 cls = Class::New(class_name, script_, classname_pos);
3105 library_.AddClass(cls); 3100 library_.AddClass(cls);
3106 } else { 3101 } else {
3107 if (!obj.IsClass()) { 3102 if (!obj.IsClass()) {
3108 ErrorMsg(classname_pos, "'%s' is already defined", 3103 ErrorMsg(classname_pos, "'%s' is already defined",
3109 class_name.ToCString()); 3104 class_name.ToCString());
3110 } 3105 }
3111 cls ^= obj.raw(); 3106 cls ^= obj.raw();
3112 if (is_patch) { 3107 if (is_patch) {
3113 String& patch = String::Handle(Symbols::New("patch ")); 3108 String& patch = String::Handle(
3114 patch = String::Concat(patch, class_name); 3109 String::Concat(Symbols::PatchSpace(), class_name));
3115 patch = Symbols::New(patch); 3110 patch = Symbols::New(patch);
3116 cls = Class::New(patch, script_, classname_pos); 3111 cls = Class::New(patch, script_, classname_pos);
3117 cls.set_library(library_); 3112 cls.set_library(library_);
3118 } else { 3113 } else {
3119 // Not patching a class, but it has been found. This must be one of the 3114 // Not patching a class, but it has been found. This must be one of the
3120 // pre-registered classes from object.cc or a duplicate definition. 3115 // pre-registered classes from object.cc or a duplicate definition.
3121 if (cls.functions() != Object::empty_array().raw()) { 3116 if (cls.functions() != Object::empty_array().raw()) {
3122 ErrorMsg(classname_pos, "class '%s' is already defined", 3117 ErrorMsg(classname_pos, "class '%s' is already defined",
3123 class_name.ToCString()); 3118 class_name.ToCString());
3124 } 3119 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
3195 } 3190 }
3196 } 3191 }
3197 } 3192 }
3198 3193
3199 3194
3200 // Add an implicit constructor if no explicit constructor is present. 3195 // Add an implicit constructor if no explicit constructor is present.
3201 void Parser::AddImplicitConstructor(ClassDesc* class_desc) { 3196 void Parser::AddImplicitConstructor(ClassDesc* class_desc) {
3202 // The implicit constructor is unnamed, has no explicit parameter, 3197 // The implicit constructor is unnamed, has no explicit parameter,
3203 // and contains a supercall in the initializer list. 3198 // and contains a supercall in the initializer list.
3204 String& ctor_name = String::ZoneHandle( 3199 String& ctor_name = String::ZoneHandle(
3205 String::Concat(class_desc->class_name(), Symbols::DotHandle())); 3200 String::Concat(class_desc->class_name(), Symbols::Dot()));
3206 ctor_name = Symbols::New(ctor_name); 3201 ctor_name = Symbols::New(ctor_name);
3207 // The token position for the implicit constructor is the 'class' 3202 // The token position for the implicit constructor is the 'class'
3208 // keyword of the constructor's class. 3203 // keyword of the constructor's class.
3209 Function& ctor = Function::Handle( 3204 Function& ctor = Function::Handle(
3210 Function::New(ctor_name, 3205 Function::New(ctor_name,
3211 RawFunction::kConstructor, 3206 RawFunction::kConstructor,
3212 /* is_static = */ false, 3207 /* is_static = */ false,
3213 /* is_const = */ false, 3208 /* is_const = */ false,
3214 /* is_abstract = */ false, 3209 /* is_abstract = */ false,
3215 /* is_external = */ false, 3210 /* is_external = */ false,
3216 current_class(), 3211 current_class(),
3217 class_desc->token_pos())); 3212 class_desc->token_pos()));
3218 ParamList params; 3213 ParamList params;
3219 // Add implicit 'this' parameter. 3214 // Add implicit 'this' parameter.
3220 ASSERT(current_class().raw() == ctor.Owner()); 3215 ASSERT(current_class().raw() == ctor.Owner());
3221 params.AddReceiver(ReceiverType(TokenPos())); 3216 params.AddReceiver(ReceiverType(TokenPos()));
3222 // Add implicit parameter for construction phase. 3217 // Add implicit parameter for construction phase.
3223 params.AddFinalParameter(TokenPos(), 3218 params.AddFinalParameter(TokenPos(),
3224 &String::ZoneHandle(Symbols::PhaseParameter()), 3219 &Symbols::PhaseParameter(),
3225 &Type::ZoneHandle(Type::SmiType())); 3220 &Type::ZoneHandle(Type::SmiType()));
3226 3221
3227 AddFormalParamsToFunction(&params, ctor); 3222 AddFormalParamsToFunction(&params, ctor);
3228 // The body of the constructor cannot modify the type of the constructed 3223 // The body of the constructor cannot modify the type of the constructed
3229 // instance, which is passed in as the receiver. 3224 // instance, which is passed in as the receiver.
3230 ctor.set_result_type(*((*params.parameters)[0].type)); 3225 ctor.set_result_type(*((*params.parameters)[0].type));
3231 class_desc->AddFunction(ctor); 3226 class_desc->AddFunction(ctor);
3232 } 3227 }
3233 3228
3234 3229
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3295 3290
3296 3291
3297 void Parser::ParseFunctionTypeAlias( 3292 void Parser::ParseFunctionTypeAlias(
3298 const GrowableObjectArray& pending_classes) { 3293 const GrowableObjectArray& pending_classes) {
3299 TRACE_PARSER("ParseFunctionTypeAlias"); 3294 TRACE_PARSER("ParseFunctionTypeAlias");
3300 ExpectToken(Token::kTYPEDEF); 3295 ExpectToken(Token::kTYPEDEF);
3301 3296
3302 // Allocate an abstract class to hold the type parameters and their bounds. 3297 // Allocate an abstract class to hold the type parameters and their bounds.
3303 // Make it the owner of the function type descriptor. 3298 // Make it the owner of the function type descriptor.
3304 const Class& alias_owner = Class::Handle( 3299 const Class& alias_owner = Class::Handle(
3305 Class::New(String::Handle(Symbols::New(":alias_owner")), 3300 Class::New(Symbols::AliasOwner(), Script::Handle(), TokenPos()));
3306 Script::Handle(),
3307 TokenPos()));
3308 3301
3309 alias_owner.set_is_abstract(); 3302 alias_owner.set_is_abstract();
3310 alias_owner.set_library(library_); 3303 alias_owner.set_library(library_);
3311 set_current_class(alias_owner); 3304 set_current_class(alias_owner);
3312 3305
3313 // Parse the result type of the function type. 3306 // Parse the result type of the function type.
3314 AbstractType& result_type = Type::Handle(Type::DynamicType()); 3307 AbstractType& result_type = Type::Handle(Type::DynamicType());
3315 if (CurrentToken() == Token::kVOID) { 3308 if (CurrentToken() == Token::kVOID) {
3316 ConsumeToken(); 3309 ConsumeToken();
3317 result_type = Type::VoidType(); 3310 result_type = Type::VoidType();
(...skipping 18 matching lines...) Expand all
3336 } 3329 }
3337 // Parse the formal parameters of the function type. 3330 // Parse the formal parameters of the function type.
3338 if (CurrentToken() != Token::kLPAREN) { 3331 if (CurrentToken() != Token::kLPAREN) {
3339 ErrorMsg("formal parameter list expected"); 3332 ErrorMsg("formal parameter list expected");
3340 } 3333 }
3341 ParamList func_params; 3334 ParamList func_params;
3342 3335
3343 // Add implicit closure object parameter. 3336 // Add implicit closure object parameter.
3344 func_params.AddFinalParameter( 3337 func_params.AddFinalParameter(
3345 TokenPos(), 3338 TokenPos(),
3346 &String::ZoneHandle(Symbols::ClosureParameter()), 3339 &Symbols::ClosureParameter(),
3347 &Type::ZoneHandle(Type::DynamicType())); 3340 &Type::ZoneHandle(Type::DynamicType()));
3348 3341
3349 const bool no_explicit_default_values = false; 3342 const bool no_explicit_default_values = false;
3350 ParseFormalParameterList(no_explicit_default_values, &func_params); 3343 ParseFormalParameterList(no_explicit_default_values, &func_params);
3351 // The field 'is_static' has no meaning for signature functions. 3344 // The field 'is_static' has no meaning for signature functions.
3352 Function& signature_function = Function::Handle( 3345 Function& signature_function = Function::Handle(
3353 Function::New(*alias_name, 3346 Function::New(*alias_name,
3354 RawFunction::kSignatureFunction, 3347 RawFunction::kSignatureFunction,
3355 /* is_static = */ false, 3348 /* is_static = */ false,
3356 /* is_const = */ false, 3349 /* is_const = */ false,
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
4077 } 4070 }
4078 4071
4079 4072
4080 void Parser::ParseLibraryName() { 4073 void Parser::ParseLibraryName() {
4081 ASSERT(CurrentToken() == Token::kLIBRARY); 4074 ASSERT(CurrentToken() == Token::kLIBRARY);
4082 ConsumeToken(); 4075 ConsumeToken();
4083 String& lib_name = *ExpectIdentifier("library name expected"); 4076 String& lib_name = *ExpectIdentifier("library name expected");
4084 if (CurrentToken() == Token::kPERIOD) { 4077 if (CurrentToken() == Token::kPERIOD) {
4085 while (CurrentToken() == Token::kPERIOD) { 4078 while (CurrentToken() == Token::kPERIOD) {
4086 ConsumeToken(); 4079 ConsumeToken();
4087 lib_name = String::Concat(lib_name, Symbols::DotHandle()); 4080 lib_name = String::Concat(lib_name, Symbols::Dot());
4088 lib_name = String::Concat(lib_name, 4081 lib_name = String::Concat(lib_name,
4089 *ExpectIdentifier("malformed library name")); 4082 *ExpectIdentifier("malformed library name"));
4090 } 4083 }
4091 lib_name = Symbols::New(lib_name); 4084 lib_name = Symbols::New(lib_name);
4092 } 4085 }
4093 library_.SetName(lib_name); 4086 library_.SetName(lib_name);
4094 ExpectSemicolon(); 4087 ExpectSemicolon();
4095 } 4088 }
4096 4089
4097 4090
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
4316 // They need to be registered with class finalization after parsing 4309 // They need to be registered with class finalization after parsing
4317 // has been completed. 4310 // has been completed.
4318 Isolate* isolate = Isolate::Current(); 4311 Isolate* isolate = Isolate::Current();
4319 ObjectStore* object_store = isolate->object_store(); 4312 ObjectStore* object_store = isolate->object_store();
4320 const GrowableObjectArray& pending_classes = 4313 const GrowableObjectArray& pending_classes =
4321 GrowableObjectArray::Handle(isolate, object_store->pending_classes()); 4314 GrowableObjectArray::Handle(isolate, object_store->pending_classes());
4322 SetPosition(0); 4315 SetPosition(0);
4323 is_top_level_ = true; 4316 is_top_level_ = true;
4324 TopLevel top_level; 4317 TopLevel top_level;
4325 Class& toplevel_class = Class::Handle( 4318 Class& toplevel_class = Class::Handle(
4326 Class::New(String::Handle(Symbols::TopLevel()), script_, TokenPos())); 4319 Class::New(Symbols::TopLevel(), script_, TokenPos()));
4327 toplevel_class.set_library(library_); 4320 toplevel_class.set_library(library_);
4328 4321
4329 if (is_library_source()) { 4322 if (is_library_source()) {
4330 ParseLibraryDefinition(); 4323 ParseLibraryDefinition();
4331 } else if (is_part_source()) { 4324 } else if (is_part_source()) {
4332 ParsePartHeader(); 4325 ParsePartHeader();
4333 } 4326 }
4334 4327
4335 while (true) { 4328 while (true) {
4336 set_current_class(Class::Handle()); // No current class. 4329 set_current_class(Class::Handle()); // No current class.
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
4537 new ReturnNode(TokenPos(), 4530 new ReturnNode(TokenPos(),
4538 new NativeBodyNode(TokenPos(), 4531 new NativeBodyNode(TokenPos(),
4539 Function::ZoneHandle(func.raw()), 4532 Function::ZoneHandle(func.raw()),
4540 native_name, 4533 native_name,
4541 native_function))); 4534 native_function)));
4542 } 4535 }
4543 4536
4544 4537
4545 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { 4538 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) {
4546 ASSERT(!current_function().is_static()); 4539 ASSERT(!current_function().is_static());
4547 return from_scope->LookupVariable(Symbols::ThisHandle(), test_only); 4540 return from_scope->LookupVariable(Symbols::This(), test_only);
4548 } 4541 }
4549 4542
4550 4543
4551 LocalVariable* Parser::LookupTypeArgumentsParameter(LocalScope* from_scope, 4544 LocalVariable* Parser::LookupTypeArgumentsParameter(LocalScope* from_scope,
4552 bool test_only) { 4545 bool test_only) {
4553 ASSERT(current_function().IsInFactoryScope()); 4546 ASSERT(current_function().IsInFactoryScope());
4554 const String& param_name = String::Handle(Symbols::TypeArgumentsParameter()); 4547 return from_scope->LookupVariable(Symbols::TypeArgumentsParameter(),
4555 return from_scope->LookupVariable(param_name, test_only); 4548 test_only);
4556 } 4549 }
4557 LocalVariable* Parser::LookupPhaseParameter() { 4550 LocalVariable* Parser::LookupPhaseParameter() {
4558 const String& phase_name =
4559 String::Handle(Symbols::PhaseParameter());
4560 const bool kTestOnly = false; 4551 const bool kTestOnly = false;
4561 return current_block_->scope->LookupVariable(phase_name, kTestOnly); 4552 return current_block_->scope->LookupVariable(Symbols::PhaseParameter(),
4553 kTestOnly);
4562 } 4554 }
4563 4555
4564 4556
4565 void Parser::CaptureInstantiator() { 4557 void Parser::CaptureInstantiator() {
4566 ASSERT(current_block_->scope->function_level() > 0); 4558 ASSERT(current_block_->scope->function_level() > 0);
4567 const bool kTestOnly = false; 4559 const bool kTestOnly = false;
4568 // Side effect of lookup captures the instantiator variable. 4560 // Side effect of lookup captures the instantiator variable.
4569 LocalVariable* instantiator = NULL; 4561 LocalVariable* instantiator = NULL;
4570 if (current_function().IsInFactoryScope()) { 4562 if (current_function().IsInFactoryScope()) {
4571 instantiator = LookupTypeArgumentsParameter(current_block_->scope, 4563 instantiator = LookupTypeArgumentsParameter(current_block_->scope,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
4729 AbstractType& result_type = AbstractType::Handle(); 4721 AbstractType& result_type = AbstractType::Handle();
4730 const String* variable_name = NULL; 4722 const String* variable_name = NULL;
4731 const String* function_name = NULL; 4723 const String* function_name = NULL;
4732 4724
4733 result_type = Type::DynamicType(); 4725 result_type = Type::DynamicType();
4734 4726
4735 intptr_t ident_pos = TokenPos(); 4727 intptr_t ident_pos = TokenPos();
4736 if (FLAG_strict_function_literals) { 4728 if (FLAG_strict_function_literals) {
4737 if (is_literal) { 4729 if (is_literal) {
4738 ASSERT(CurrentToken() == Token::kLPAREN); 4730 ASSERT(CurrentToken() == Token::kLPAREN);
4739 function_name = &String::ZoneHandle(Symbols::AnonymousClosure()); 4731 function_name = &Symbols::AnonymousClosure();
4740 } else { 4732 } else {
4741 if (CurrentToken() == Token::kVOID) { 4733 if (CurrentToken() == Token::kVOID) {
4742 ConsumeToken(); 4734 ConsumeToken();
4743 result_type = Type::VoidType(); 4735 result_type = Type::VoidType();
4744 } else if ((CurrentToken() == Token::kIDENT) && 4736 } else if ((CurrentToken() == Token::kIDENT) &&
4745 (LookaheadToken(1) != Token::kLPAREN)) { 4737 (LookaheadToken(1) != Token::kLPAREN)) {
4746 result_type = ParseType(ClassFinalizer::kCanonicalize); 4738 result_type = ParseType(ClassFinalizer::kCanonicalize);
4747 } 4739 }
4748 ident_pos = TokenPos(); 4740 ident_pos = TokenPos();
4749 variable_name = ExpectIdentifier("function name expected"); 4741 variable_name = ExpectIdentifier("function name expected");
(...skipping 11 matching lines...) Expand all
4761 } 4753 }
4762 ident_pos = TokenPos(); 4754 ident_pos = TokenPos();
4763 if (IsIdentifier()) { 4755 if (IsIdentifier()) {
4764 variable_name = CurrentLiteral(); 4756 variable_name = CurrentLiteral();
4765 function_name = variable_name; 4757 function_name = variable_name;
4766 ConsumeToken(); 4758 ConsumeToken();
4767 } else { 4759 } else {
4768 if (!is_literal) { 4760 if (!is_literal) {
4769 ErrorMsg("function name expected"); 4761 ErrorMsg("function name expected");
4770 } 4762 }
4771 function_name = &String::ZoneHandle(Symbols::AnonymousClosure()); 4763 function_name = &Symbols::AnonymousClosure();
4772 } 4764 }
4773 } 4765 }
4774 4766
4775 if (CurrentToken() != Token::kLPAREN) { 4767 if (CurrentToken() != Token::kLPAREN) {
4776 ErrorMsg("'(' expected"); 4768 ErrorMsg("'(' expected");
4777 } 4769 }
4778 intptr_t function_pos = TokenPos(); 4770 intptr_t function_pos = TokenPos();
4779 4771
4780 // Check whether we have parsed this closure function before, in a previous 4772 // Check whether we have parsed this closure function before, in a previous
4781 // compilation. If so, reuse the function object, else create a new one 4773 // compilation. If so, reuse the function object, else create a new one
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
5402 // End of switch statement. 5394 // End of switch statement.
5403 break; 5395 break;
5404 } 5396 }
5405 if ((next_token == Token::kCASE) || (next_token == Token::kDEFAULT)) { 5397 if ((next_token == Token::kCASE) || (next_token == Token::kDEFAULT)) {
5406 // End of this case clause. If there is a possible fall-through to 5398 // End of this case clause. If there is a possible fall-through to
5407 // the next case clause, throw an implicit FallThroughError. 5399 // the next case clause, throw an implicit FallThroughError.
5408 if (!abrupt_completing_seen) { 5400 if (!abrupt_completing_seen) {
5409 ArgumentListNode* arguments = new ArgumentListNode(TokenPos()); 5401 ArgumentListNode* arguments = new ArgumentListNode(TokenPos());
5410 arguments->Add(new LiteralNode( 5402 arguments->Add(new LiteralNode(
5411 TokenPos(), Integer::ZoneHandle(Integer::New(TokenPos())))); 5403 TokenPos(), Integer::ZoneHandle(Integer::New(TokenPos()))));
5412 const String& cls_name = String::Handle(Symbols::FallThroughError());
5413 const String& func_name = String::Handle(Symbols::ThrowNew());
5414 current_block_->statements->Add( 5404 current_block_->statements->Add(
5415 MakeStaticCall(cls_name, func_name, arguments)); 5405 MakeStaticCall(Symbols::FallThroughError(),
5406 Symbols::ThrowNew(),
5407 arguments));
5416 } 5408 }
5417 break; 5409 break;
5418 } 5410 }
5419 // The next statement still belongs to this case. 5411 // The next statement still belongs to this case.
5420 AstNode* statement = ParseStatement(); 5412 AstNode* statement = ParseStatement();
5421 if (statement != NULL) { 5413 if (statement != NULL) {
5422 current_block_->statements->Add(statement); 5414 current_block_->statements->Add(statement);
5423 abrupt_completing_seen |= IsAbruptCompleting(statement); 5415 abrupt_completing_seen |= IsAbruptCompleting(statement);
5424 } 5416 }
5425 } 5417 }
(...skipping 23 matching lines...) Expand all
5449 if (paren_found) { 5441 if (paren_found) {
5450 ExpectToken(Token::kRPAREN); 5442 ExpectToken(Token::kRPAREN);
5451 } 5443 }
5452 ExpectToken(Token::kLBRACE); 5444 ExpectToken(Token::kLBRACE);
5453 OpenBlock(); 5445 OpenBlock();
5454 current_block_->scope->AddLabel(label); 5446 current_block_->scope->AddLabel(label);
5455 5447
5456 // Store switch expression in temporary local variable. 5448 // Store switch expression in temporary local variable.
5457 LocalVariable* temp_variable = 5449 LocalVariable* temp_variable =
5458 new LocalVariable(expr_pos, 5450 new LocalVariable(expr_pos,
5459 String::ZoneHandle(Symbols::New(":switch_expr")), 5451 Symbols::SwitchExpr(),
5460 Type::ZoneHandle(Type::DynamicType())); 5452 Type::ZoneHandle(Type::DynamicType()));
5461 current_block_->scope->AddVariable(temp_variable); 5453 current_block_->scope->AddVariable(temp_variable);
5462 AstNode* save_switch_expr = 5454 AstNode* save_switch_expr =
5463 new StoreLocalNode(expr_pos, temp_variable, switch_expr); 5455 new StoreLocalNode(expr_pos, temp_variable, switch_expr);
5464 current_block_->statements->Add(save_switch_expr); 5456 current_block_->statements->Add(save_switch_expr);
5465 5457
5466 // Parse case clauses 5458 // Parse case clauses
5467 bool default_seen = false; 5459 bool default_seen = false;
5468 while (true) { 5460 while (true) {
5469 // Check for statement label 5461 // Check for statement label
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
5580 } 5572 }
5581 } 5573 }
5582 ExpectToken(Token::kIN); 5574 ExpectToken(Token::kIN);
5583 const intptr_t collection_pos = TokenPos(); 5575 const intptr_t collection_pos = TokenPos();
5584 AstNode* collection_expr = ParseExpr(kAllowConst, kConsumeCascades); 5576 AstNode* collection_expr = ParseExpr(kAllowConst, kConsumeCascades);
5585 ExpectToken(Token::kRPAREN); 5577 ExpectToken(Token::kRPAREN);
5586 5578
5587 OpenBlock(); // Implicit block around while loop. 5579 OpenBlock(); // Implicit block around while loop.
5588 5580
5589 // Generate implicit iterator variable and add to scope. 5581 // Generate implicit iterator variable and add to scope.
5590 const String& iterator_name = String::ZoneHandle(Symbols::ForInIter());
5591 // We could set the type of the implicit iterator variable to Iterator<T> 5582 // We could set the type of the implicit iterator variable to Iterator<T>
5592 // where T is the type of the for loop variable. However, the type error 5583 // where T is the type of the for loop variable. However, the type error
5593 // would refer to the compiler generated iterator and could confuse the user. 5584 // would refer to the compiler generated iterator and could confuse the user.
5594 // It is better to leave the iterator untyped and postpone the type error 5585 // It is better to leave the iterator untyped and postpone the type error
5595 // until the loop variable is assigned to. 5586 // until the loop variable is assigned to.
5596 const AbstractType& iterator_type = Type::ZoneHandle(Type::DynamicType()); 5587 const AbstractType& iterator_type = Type::ZoneHandle(Type::DynamicType());
5597 LocalVariable* iterator_var = 5588 LocalVariable* iterator_var =
5598 new LocalVariable(collection_pos, iterator_name, iterator_type); 5589 new LocalVariable(collection_pos, Symbols::ForInIter(), iterator_type);
5599 current_block_->scope->AddVariable(iterator_var); 5590 current_block_->scope->AddVariable(iterator_var);
5600 5591
5601 // Generate initialization of iterator variable. 5592 // Generate initialization of iterator variable.
5602 const String& iterator_method_name =
5603 String::ZoneHandle(Symbols::GetIterator());
5604 ArgumentListNode* no_args = new ArgumentListNode(collection_pos); 5593 ArgumentListNode* no_args = new ArgumentListNode(collection_pos);
5605 AstNode* get_iterator = new InstanceCallNode( 5594 AstNode* get_iterator = new InstanceCallNode(
5606 collection_pos, collection_expr, iterator_method_name, no_args); 5595 collection_pos, collection_expr, Symbols::GetIterator(), no_args);
5607 AstNode* iterator_init = 5596 AstNode* iterator_init =
5608 new StoreLocalNode(collection_pos, iterator_var, get_iterator); 5597 new StoreLocalNode(collection_pos, iterator_var, get_iterator);
5609 current_block_->statements->Add(iterator_init); 5598 current_block_->statements->Add(iterator_init);
5610 5599
5611 // Generate while loop condition. 5600 // Generate while loop condition.
5612 AstNode* iterator_has_next = new InstanceGetterNode( 5601 AstNode* iterator_has_next = new InstanceGetterNode(
5613 collection_pos, 5602 collection_pos,
5614 new LoadLocalNode(collection_pos, iterator_var), 5603 new LoadLocalNode(collection_pos, iterator_var),
5615 String::ZoneHandle(Symbols::HasNext())); 5604 Symbols::HasNext());
5616 5605
5617 // Parse the for loop body. Ideally, we would use ParseNestedStatement() 5606 // Parse the for loop body. Ideally, we would use ParseNestedStatement()
5618 // here, but that does not work well because we have to insert an implicit 5607 // here, but that does not work well because we have to insert an implicit
5619 // variable assignment and potentially a variable declaration in the 5608 // variable assignment and potentially a variable declaration in the
5620 // loop body. 5609 // loop body.
5621 OpenLoopBlock(); 5610 OpenLoopBlock();
5622 current_block_->scope->AddLabel(label); 5611 current_block_->scope->AddLabel(label);
5623 5612
5624 AstNode* iterator_next = new InstanceCallNode( 5613 AstNode* iterator_next = new InstanceCallNode(
5625 collection_pos, 5614 collection_pos,
5626 new LoadLocalNode(collection_pos, iterator_var), 5615 new LoadLocalNode(collection_pos, iterator_var),
5627 String::ZoneHandle(Symbols::Next()), 5616 Symbols::Next(),
5628 no_args); 5617 no_args);
5629 5618
5630 // Generate assignment of next iterator value to loop variable. 5619 // Generate assignment of next iterator value to loop variable.
5631 AstNode* loop_var_assignment = NULL; 5620 AstNode* loop_var_assignment = NULL;
5632 if (loop_var != NULL) { 5621 if (loop_var != NULL) {
5633 // The for loop declares a new variable. Add it to the loop body scope. 5622 // The for loop declares a new variable. Add it to the loop body scope.
5634 current_block_->scope->AddVariable(loop_var); 5623 current_block_->scope->AddVariable(loop_var);
5635 loop_var_assignment = 5624 loop_var_assignment =
5636 new StoreLocalNode(loop_var_pos, loop_var, iterator_next); 5625 new StoreLocalNode(loop_var_pos, loop_var, iterator_next);
5637 } else { 5626 } else {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
5750 return new StaticCallNode(arguments->token_pos(), func, arguments); 5739 return new StaticCallNode(arguments->token_pos(), func, arguments);
5751 } 5740 }
5752 5741
5753 5742
5754 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) { 5743 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) {
5755 ArgumentListNode* arguments = new ArgumentListNode(begin); 5744 ArgumentListNode* arguments = new ArgumentListNode(begin);
5756 arguments->Add(new LiteralNode(begin, 5745 arguments->Add(new LiteralNode(begin,
5757 Integer::ZoneHandle(Integer::New(begin)))); 5746 Integer::ZoneHandle(Integer::New(begin))));
5758 arguments->Add(new LiteralNode(end, 5747 arguments->Add(new LiteralNode(end,
5759 Integer::ZoneHandle(Integer::New(end)))); 5748 Integer::ZoneHandle(Integer::New(end))));
5760 const String& cls_name = String::Handle(Symbols::AssertionError()); 5749 return MakeStaticCall(Symbols::AssertionError(),
5761 const String& func_name = String::Handle(Symbols::ThrowNew()); 5750 Symbols::ThrowNew(),
5762 return MakeStaticCall(cls_name, func_name, arguments); 5751 arguments);
5763 } 5752 }
5764 5753
5765 5754
5766 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) { 5755 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) {
5767 if (condition->IsClosureNode() || 5756 if (condition->IsClosureNode() ||
5768 (condition->IsStoreLocalNode() && 5757 (condition->IsStoreLocalNode() &&
5769 condition->AsStoreLocalNode()->value()->IsClosureNode())) { 5758 condition->AsStoreLocalNode()->value()->IsClosureNode())) {
5770 EnsureExpressionTemp(); 5759 EnsureExpressionTemp();
5771 // Function literal in assert implies a call. 5760 // Function literal in assert implies a call.
5772 const intptr_t pos = condition->token_pos(); 5761 const intptr_t pos = condition->token_pos();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
5910 // block. The context register is restored from this 5899 // block. The context register is restored from this
5911 // slot before processing the catch block handler. 5900 // slot before processing the catch block handler.
5912 // ':exception_var' - Used to save the current exception object that was 5901 // ':exception_var' - Used to save the current exception object that was
5913 // thrown. 5902 // thrown.
5914 // ':stacktrace_var' - Used to save the current stack trace object into which 5903 // ':stacktrace_var' - Used to save the current stack trace object into which
5915 // the stack trace was copied into when an exception was 5904 // the stack trace was copied into when an exception was
5916 // thrown. 5905 // thrown.
5917 // :exception_var and :stacktrace_var get set with the exception object 5906 // :exception_var and :stacktrace_var get set with the exception object
5918 // and the stacktrace object when an exception is thrown. 5907 // and the stacktrace object when an exception is thrown.
5919 // These three implicit variables can never be captured variables. 5908 // These three implicit variables can never be captured variables.
5920 const String& context_var_name =
5921 String::ZoneHandle(Symbols::SavedContextVar());
5922 LocalVariable* context_var = 5909 LocalVariable* context_var =
5923 current_block_->scope->LocalLookupVariable(context_var_name); 5910 current_block_->scope->LocalLookupVariable(Symbols::SavedContextVar());
5924 if (context_var == NULL) { 5911 if (context_var == NULL) {
5925 context_var = new LocalVariable(TokenPos(), 5912 context_var = new LocalVariable(TokenPos(),
5926 context_var_name, 5913 Symbols::SavedContextVar(),
5927 Type::ZoneHandle(Type::DynamicType())); 5914 Type::ZoneHandle(Type::DynamicType()));
5928 current_block_->scope->AddVariable(context_var); 5915 current_block_->scope->AddVariable(context_var);
5929 } 5916 }
5930 const String& catch_excp_var_name =
5931 String::ZoneHandle(Symbols::ExceptionVar());
5932 LocalVariable* catch_excp_var = 5917 LocalVariable* catch_excp_var =
5933 current_block_->scope->LocalLookupVariable(catch_excp_var_name); 5918 current_block_->scope->LocalLookupVariable(Symbols::ExceptionVar());
5934 if (catch_excp_var == NULL) { 5919 if (catch_excp_var == NULL) {
5935 catch_excp_var = new LocalVariable(TokenPos(), 5920 catch_excp_var = new LocalVariable(TokenPos(),
5936 catch_excp_var_name, 5921 Symbols::ExceptionVar(),
5937 Type::ZoneHandle(Type::DynamicType())); 5922 Type::ZoneHandle(Type::DynamicType()));
5938 current_block_->scope->AddVariable(catch_excp_var); 5923 current_block_->scope->AddVariable(catch_excp_var);
5939 } 5924 }
5940 const String& catch_trace_var_name =
5941 String::ZoneHandle(Symbols::StacktraceVar());
5942 LocalVariable* catch_trace_var = 5925 LocalVariable* catch_trace_var =
5943 current_block_->scope->LocalLookupVariable(catch_trace_var_name); 5926 current_block_->scope->LocalLookupVariable(Symbols::StacktraceVar());
5944 if (catch_trace_var == NULL) { 5927 if (catch_trace_var == NULL) {
5945 catch_trace_var = new LocalVariable(TokenPos(), 5928 catch_trace_var = new LocalVariable(TokenPos(),
5946 catch_trace_var_name, 5929 Symbols::StacktraceVar(),
5947 Type::ZoneHandle(Type::DynamicType())); 5930 Type::ZoneHandle(Type::DynamicType()));
5948 current_block_->scope->AddVariable(catch_trace_var); 5931 current_block_->scope->AddVariable(catch_trace_var);
5949 } 5932 }
5950 5933
5951 const intptr_t try_pos = TokenPos(); 5934 const intptr_t try_pos = TokenPos();
5952 ConsumeToken(); // Consume the 'try'. 5935 ConsumeToken(); // Consume the 'try'.
5953 5936
5954 SourceLabel* try_label = NULL; 5937 SourceLabel* try_label = NULL;
5955 if (label_name != NULL) { 5938 if (label_name != NULL) {
5956 try_label = SourceLabel::New(try_pos, label_name, SourceLabel::kStatement); 5939 try_label = SourceLabel::New(try_pos, label_name, SourceLabel::kStatement);
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
6301 ExpectSemicolon(); 6284 ExpectSemicolon();
6302 // Check if it is ok to do a rethrow. 6285 // Check if it is ok to do a rethrow.
6303 SourceLabel* label = current_block_->scope->LookupInnermostCatchLabel(); 6286 SourceLabel* label = current_block_->scope->LookupInnermostCatchLabel();
6304 if (label == NULL || 6287 if (label == NULL ||
6305 label->FunctionLevel() != current_block_->scope->function_level()) { 6288 label->FunctionLevel() != current_block_->scope->function_level()) {
6306 ErrorMsg(statement_pos, "rethrow of an exception is not valid here"); 6289 ErrorMsg(statement_pos, "rethrow of an exception is not valid here");
6307 } 6290 }
6308 ASSERT(label->owner() != NULL); 6291 ASSERT(label->owner() != NULL);
6309 LocalScope* scope = label->owner()->parent(); 6292 LocalScope* scope = label->owner()->parent();
6310 ASSERT(scope != NULL); 6293 ASSERT(scope != NULL);
6311 LocalVariable* excp_var = scope->LocalLookupVariable( 6294 LocalVariable* excp_var =
6312 String::ZoneHandle(Symbols::ExceptionVar())); 6295 scope->LocalLookupVariable(Symbols::ExceptionVar());
6313 ASSERT(excp_var != NULL); 6296 ASSERT(excp_var != NULL);
6314 LocalVariable* trace_var = scope->LocalLookupVariable( 6297 LocalVariable* trace_var =
6315 String::ZoneHandle(Symbols::StacktraceVar())); 6298 scope->LocalLookupVariable(Symbols::StacktraceVar());
6316 ASSERT(trace_var != NULL); 6299 ASSERT(trace_var != NULL);
6317 statement = new ThrowNode(statement_pos, 6300 statement = new ThrowNode(statement_pos,
6318 new LoadLocalNode(statement_pos, excp_var), 6301 new LoadLocalNode(statement_pos, excp_var),
6319 new LoadLocalNode(statement_pos, trace_var)); 6302 new LoadLocalNode(statement_pos, trace_var));
6320 } else { 6303 } else {
6321 statement = ParseExpr(kAllowConst, kConsumeCascades); 6304 statement = ParseExpr(kAllowConst, kConsumeCascades);
6322 ExpectSemicolon(); 6305 ExpectSemicolon();
6323 } 6306 }
6324 return statement; 6307 return statement;
6325 } 6308 }
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
6578 6561
6579 AstNode* Parser::ThrowTypeError(intptr_t type_pos, const AbstractType& type) { 6562 AstNode* Parser::ThrowTypeError(intptr_t type_pos, const AbstractType& type) {
6580 ASSERT(type.IsMalformed()); 6563 ASSERT(type.IsMalformed());
6581 ArgumentListNode* arguments = new ArgumentListNode(type_pos); 6564 ArgumentListNode* arguments = new ArgumentListNode(type_pos);
6582 // Location argument. 6565 // Location argument.
6583 arguments->Add(new LiteralNode( 6566 arguments->Add(new LiteralNode(
6584 type_pos, Integer::ZoneHandle(Integer::New(type_pos)))); 6567 type_pos, Integer::ZoneHandle(Integer::New(type_pos))));
6585 // Src value argument. 6568 // Src value argument.
6586 arguments->Add(new LiteralNode(type_pos, Instance::ZoneHandle())); 6569 arguments->Add(new LiteralNode(type_pos, Instance::ZoneHandle()));
6587 // Dst type name argument. 6570 // Dst type name argument.
6588 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( 6571 arguments->Add(new LiteralNode(type_pos, Symbols::Malformed()));
6589 Symbols::New("malformed"))));
6590 // Dst name argument. 6572 // Dst name argument.
6591 arguments->Add(new LiteralNode(type_pos, 6573 arguments->Add(new LiteralNode(type_pos, Symbols::Empty()));
6592 String::ZoneHandle(Symbols::Empty())));
6593 // Malformed type error. 6574 // Malformed type error.
6594 const Error& error = Error::Handle(type.malformed_error()); 6575 const Error& error = Error::Handle(type.malformed_error());
6595 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( 6576 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle(
6596 Symbols::New(error.ToErrorCString())))); 6577 Symbols::New(error.ToErrorCString()))));
6597 const String& cls_name = String::Handle(Symbols::TypeError()); 6578 return MakeStaticCall(Symbols::TypeError(), Symbols::ThrowNew(), arguments);
6598 const String& func_name = String::Handle(Symbols::ThrowNew());
6599 return MakeStaticCall(cls_name, func_name, arguments);
6600 } 6579 }
6601 6580
6602 6581
6603 // TODO(regis): Providing the argument values is not always feasible, since 6582 // TODO(regis): Providing the argument values is not always feasible, since
6604 // evaluating them could throw an error. 6583 // evaluating them could throw an error.
6605 // Should NoSuchMethodError reflect the argument count and names instead of 6584 // Should NoSuchMethodError reflect the argument count and names instead of
6606 // argument values? Or should the spec specify a different evaluation order? 6585 // argument values? Or should the spec specify a different evaluation order?
6607 AstNode* Parser::ThrowNoSuchMethodError(intptr_t call_pos, 6586 AstNode* Parser::ThrowNoSuchMethodError(intptr_t call_pos,
6608 const Class& cls, 6587 const Class& cls,
6609 const String& function_name) { 6588 const String& function_name) {
6610 ArgumentListNode* arguments = new ArgumentListNode(call_pos); 6589 ArgumentListNode* arguments = new ArgumentListNode(call_pos);
6611 // Object receiver. 6590 // Object receiver.
6612 // TODO(regis): For now, we pass a class literal of the unresolved 6591 // TODO(regis): For now, we pass a class literal of the unresolved
6613 // method's owner, but this is not specified and will probably change. 6592 // method's owner, but this is not specified and will probably change.
6614 Type& type = Type::ZoneHandle( 6593 Type& type = Type::ZoneHandle(
6615 Type::New(cls, TypeArguments::Handle(), call_pos, Heap::kOld)); 6594 Type::New(cls, TypeArguments::Handle(), call_pos, Heap::kOld));
6616 type ^= ClassFinalizer::FinalizeType( 6595 type ^= ClassFinalizer::FinalizeType(
6617 current_class(), type, ClassFinalizer::kCanonicalize); 6596 current_class(), type, ClassFinalizer::kCanonicalize);
6618 arguments->Add(new LiteralNode(call_pos, type)); 6597 arguments->Add(new LiteralNode(call_pos, type));
6619 // String memberName. 6598 // String memberName.
6620 arguments->Add(new LiteralNode( 6599 arguments->Add(new LiteralNode(
6621 call_pos, String::ZoneHandle(Symbols::New(function_name)))); 6600 call_pos, String::ZoneHandle(Symbols::New(function_name))));
6622 // List arguments. 6601 // List arguments.
6623 arguments->Add(new LiteralNode(call_pos, Array::ZoneHandle())); 6602 arguments->Add(new LiteralNode(call_pos, Array::ZoneHandle()));
6624 // List argumentNames. 6603 // List argumentNames.
6625 arguments->Add(new LiteralNode(call_pos, Array::ZoneHandle())); 6604 arguments->Add(new LiteralNode(call_pos, Array::ZoneHandle()));
6626 // List existingArgumentNames. 6605 // List existingArgumentNames.
6627 arguments->Add(new LiteralNode(call_pos, Array::ZoneHandle())); 6606 arguments->Add(new LiteralNode(call_pos, Array::ZoneHandle()));
6628 const String& cls_name = String::Handle(Symbols::NoSuchMethodError()); 6607 return MakeStaticCall(Symbols::NoSuchMethodError(),
6629 const String& func_name = String::Handle(Symbols::ThrowNew()); 6608 Symbols::ThrowNew(),
6630 return MakeStaticCall(cls_name, func_name, arguments); 6609 arguments);
6631 } 6610 }
6632 6611
6633 6612
6634 AstNode* Parser::ParseBinaryExpr(int min_preced) { 6613 AstNode* Parser::ParseBinaryExpr(int min_preced) {
6635 TRACE_PARSER("ParseBinaryExpr"); 6614 TRACE_PARSER("ParseBinaryExpr");
6636 ASSERT(min_preced >= 4); 6615 ASSERT(min_preced >= 4);
6637 AstNode* left_operand = ParseUnaryExpr(); 6616 AstNode* left_operand = ParseUnaryExpr();
6638 if (left_operand->IsPrimaryNode() && 6617 if (left_operand->IsPrimaryNode() &&
6639 (left_operand->AsPrimaryNode()->IsSuper())) { 6618 (left_operand->AsPrimaryNode()->IsSuper())) {
6640 ErrorMsg(left_operand->token_pos(), "illegal use of 'super'"); 6619 ErrorMsg(left_operand->token_pos(), "illegal use of 'super'");
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
7170 // Check if there is a static field of the same name, it could be a closure 7149 // Check if there is a static field of the same name, it could be a closure
7171 // and so we try and invoke the closure. 7150 // and so we try and invoke the closure.
7172 AstNode* closure = NULL; 7151 AstNode* closure = NULL;
7173 const Field& field = Field::ZoneHandle(cls.LookupStaticField(func_name)); 7152 const Field& field = Field::ZoneHandle(cls.LookupStaticField(func_name));
7174 Function& func = Function::ZoneHandle(); 7153 Function& func = Function::ZoneHandle();
7175 if (field.IsNull()) { 7154 if (field.IsNull()) {
7176 // No field, check if we have an explicit getter function. 7155 // No field, check if we have an explicit getter function.
7177 const String& getter_name = 7156 const String& getter_name =
7178 String::ZoneHandle(Field::GetterName(func_name)); 7157 String::ZoneHandle(Field::GetterName(func_name));
7179 const int kNumArguments = 0; // no arguments. 7158 const int kNumArguments = 0; // no arguments.
7180 const Array& kNoArgumentNames = Array::Handle();
7181 func = Resolver::ResolveStatic(cls, 7159 func = Resolver::ResolveStatic(cls,
7182 getter_name, 7160 getter_name,
7183 kNumArguments, 7161 kNumArguments,
7184 kNoArgumentNames, 7162 Object::empty_array(),
7185 Resolver::kIsQualified); 7163 Resolver::kIsQualified);
7186 if (!func.IsNull()) { 7164 if (!func.IsNull()) {
7187 ASSERT(func.kind() != RawFunction::kConstImplicitGetter); 7165 ASSERT(func.kind() != RawFunction::kConstImplicitGetter);
7188 EnsureExpressionTemp(); 7166 EnsureExpressionTemp();
7189 closure = new StaticGetterNode(call_pos, 7167 closure = new StaticGetterNode(call_pos,
7190 NULL, 7168 NULL,
7191 false, 7169 false,
7192 Class::ZoneHandle(cls.raw()), 7170 Class::ZoneHandle(cls.raw()),
7193 func_name); 7171 func_name);
7194 return new ClosureCallNode(call_pos, closure, arguments); 7172 return new ClosureCallNode(call_pos, closure, arguments);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
7256 const intptr_t call_pos = TokenPos(); 7234 const intptr_t call_pos = TokenPos();
7257 const Field& field = Field::ZoneHandle(cls.LookupStaticField(field_name)); 7235 const Field& field = Field::ZoneHandle(cls.LookupStaticField(field_name));
7258 Function& func = Function::ZoneHandle(); 7236 Function& func = Function::ZoneHandle();
7259 if (Token::IsAssignmentOperator(CurrentToken())) { 7237 if (Token::IsAssignmentOperator(CurrentToken())) {
7260 // Make sure an assignment is legal. 7238 // Make sure an assignment is legal.
7261 if (field.IsNull()) { 7239 if (field.IsNull()) {
7262 // No field, check if we have an explicit setter function. 7240 // No field, check if we have an explicit setter function.
7263 const String& setter_name = 7241 const String& setter_name =
7264 String::ZoneHandle(Field::SetterName(field_name)); 7242 String::ZoneHandle(Field::SetterName(field_name));
7265 const int kNumArguments = 1; // value. 7243 const int kNumArguments = 1; // value.
7266 const Array& kNoArgumentNames = Array::Handle();
7267 func = Resolver::ResolveStatic(cls, 7244 func = Resolver::ResolveStatic(cls,
7268 setter_name, 7245 setter_name,
7269 kNumArguments, 7246 kNumArguments,
7270 kNoArgumentNames, 7247 Object::empty_array(),
7271 Resolver::kIsQualified); 7248 Resolver::kIsQualified);
7272 if (func.IsNull()) { 7249 if (func.IsNull()) {
7273 // No field or explicit setter function, throw a NoSuchMethodError. 7250 // No field or explicit setter function, throw a NoSuchMethodError.
7274 return ThrowNoSuchMethodError(ident_pos, cls, field_name); 7251 return ThrowNoSuchMethodError(ident_pos, cls, field_name);
7275 } 7252 }
7276 7253
7277 // Explicit setter function for the field found, field does not exist. 7254 // Explicit setter function for the field found, field does not exist.
7278 // Create a getter node first in case it is needed. If getter node 7255 // Create a getter node first in case it is needed. If getter node
7279 // is used as part of, e.g., "+=", and the explicit getter does not 7256 // is used as part of, e.g., "+=", and the explicit getter does not
7280 // exist, and error will be reported by the code generator. 7257 // exist, and error will be reported by the code generator.
(...skipping 12 matching lines...) Expand all
7293 field_name.ToCString()); 7270 field_name.ToCString());
7294 } 7271 }
7295 access = GenerateStaticFieldLookup(field, TokenPos()); 7272 access = GenerateStaticFieldLookup(field, TokenPos());
7296 } 7273 }
7297 } else { // Not Token::IsAssignmentOperator(CurrentToken()). 7274 } else { // Not Token::IsAssignmentOperator(CurrentToken()).
7298 if (field.IsNull()) { 7275 if (field.IsNull()) {
7299 // No field, check if we have an explicit getter function. 7276 // No field, check if we have an explicit getter function.
7300 const String& getter_name = 7277 const String& getter_name =
7301 String::ZoneHandle(Field::GetterName(field_name)); 7278 String::ZoneHandle(Field::GetterName(field_name));
7302 const int kNumArguments = 0; // no arguments. 7279 const int kNumArguments = 0; // no arguments.
7303 const Array& kNoArgumentNames = Array::Handle();
7304 func = Resolver::ResolveStatic(cls, 7280 func = Resolver::ResolveStatic(cls,
7305 getter_name, 7281 getter_name,
7306 kNumArguments, 7282 kNumArguments,
7307 kNoArgumentNames, 7283 Object::empty_array(),
7308 Resolver::kIsQualified); 7284 Resolver::kIsQualified);
7309 if (func.IsNull()) { 7285 if (func.IsNull()) {
7310 // We might be referring to an implicit closure, check to see if 7286 // We might be referring to an implicit closure, check to see if
7311 // there is a function of the same name. 7287 // there is a function of the same name.
7312 func = cls.LookupStaticFunction(field_name); 7288 func = cls.LookupStaticFunction(field_name);
7313 if (func.IsNull()) { 7289 if (func.IsNull()) {
7314 // No field or explicit getter function, throw a NoSuchMethodError. 7290 // No field or explicit getter function, throw a NoSuchMethodError.
7315 return ThrowNoSuchMethodError(ident_pos, cls, field_name); 7291 return ThrowNoSuchMethodError(ident_pos, cls, field_name);
7316 } 7292 }
7317 access = CreateImplicitClosureNode(func, call_pos, NULL); 7293 access = CreateImplicitClosureNode(func, call_pos, NULL);
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
7717 // Returns true if ident resolves to a formal parameter of the current function 7693 // Returns true if ident resolves to a formal parameter of the current function
7718 // or of one of its enclosing functions. 7694 // or of one of its enclosing functions.
7719 // Make sure not to capture the formal parameter, since it is not accessed. 7695 // Make sure not to capture the formal parameter, since it is not accessed.
7720 bool Parser::IsFormalParameter(const String& ident, 7696 bool Parser::IsFormalParameter(const String& ident,
7721 Function* owner_function, 7697 Function* owner_function,
7722 LocalScope** owner_scope, 7698 LocalScope** owner_scope,
7723 intptr_t* local_index) { 7699 intptr_t* local_index) {
7724 if (current_block_ == NULL) { 7700 if (current_block_ == NULL) {
7725 return false; 7701 return false;
7726 } 7702 }
7727 if (ident.Equals(Symbols::ThisHandle())) { 7703 if (ident.Equals(Symbols::This())) {
7728 // 'this' is not a formal parameter. 7704 // 'this' is not a formal parameter.
7729 return false; 7705 return false;
7730 } 7706 }
7731 // Since an argument definition test does not use the value of the formal 7707 // Since an argument definition test does not use the value of the formal
7732 // parameter, there is no reason to capture it. 7708 // parameter, there is no reason to capture it.
7733 const bool kTestOnly = true; // No capturing. 7709 const bool kTestOnly = true; // No capturing.
7734 LocalVariable* local = 7710 LocalVariable* local =
7735 current_block_->scope->LookupVariable(ident, kTestOnly); 7711 current_block_->scope->LookupVariable(ident, kTestOnly);
7736 if (local == NULL) { 7712 if (local == NULL) {
7737 if (!current_function().IsLocalFunction()) { 7713 if (!current_function().IsLocalFunction()) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
7873 // This field has not been referenced yet and thus the value has 7849 // This field has not been referenced yet and thus the value has
7874 // not been evaluated. If the field is const, call the static getter method 7850 // not been evaluated. If the field is const, call the static getter method
7875 // to evaluate the expression and canonicalize the value. 7851 // to evaluate the expression and canonicalize the value.
7876 if (field.is_const()) { 7852 if (field.is_const()) {
7877 field.set_value(Object::transition_sentinel()); 7853 field.set_value(Object::transition_sentinel());
7878 const String& field_name = String::Handle(field.name()); 7854 const String& field_name = String::Handle(field.name());
7879 const String& getter_name = 7855 const String& getter_name =
7880 String::Handle(Field::GetterName(field_name)); 7856 String::Handle(Field::GetterName(field_name));
7881 const Class& cls = Class::Handle(field.owner()); 7857 const Class& cls = Class::Handle(field.owner());
7882 const int kNumArguments = 0; // no arguments. 7858 const int kNumArguments = 0; // no arguments.
7883 const Array& kNoArgumentNames = Array::Handle();
7884 const Function& func = 7859 const Function& func =
7885 Function::Handle(Resolver::ResolveStatic(cls, 7860 Function::Handle(Resolver::ResolveStatic(cls,
7886 getter_name, 7861 getter_name,
7887 kNumArguments, 7862 kNumArguments,
7888 kNoArgumentNames, 7863 Object::empty_array(),
7889 Resolver::kIsQualified)); 7864 Resolver::kIsQualified));
7890 ASSERT(!func.IsNull()); 7865 ASSERT(!func.IsNull());
7891 ASSERT(func.kind() == RawFunction::kConstImplicitGetter); 7866 ASSERT(func.kind() == RawFunction::kConstImplicitGetter);
7892 Object& const_value = Object::Handle( 7867 Object& const_value = Object::Handle(
7893 DartEntry::InvokeStatic(func, Object::empty_array())); 7868 DartEntry::InvokeStatic(func, Object::empty_array()));
7894 if (const_value.IsError()) { 7869 if (const_value.IsError()) {
7895 const Error& error = Error::Cast(const_value); 7870 const Error& error = Error::Cast(const_value);
7896 if (error.IsUnhandledException()) { 7871 if (error.IsUnhandledException()) {
7897 field.set_value(Instance::Handle()); 7872 field.set_value(Instance::Handle());
7898 // It is a compile-time error if evaluation of a compile-time constant 7873 // 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
8529 Type& type = Type::ZoneHandle( 8504 Type& type = Type::ZoneHandle(
8530 Type::New(array_class, type_arguments, type_pos)); 8505 Type::New(array_class, type_arguments, type_pos));
8531 type ^= ClassFinalizer::FinalizeType( 8506 type ^= ClassFinalizer::FinalizeType(
8532 current_class(), type, ClassFinalizer::kCanonicalize); 8507 current_class(), type, ClassFinalizer::kCanonicalize);
8533 ArrayNode* list = new ArrayNode(TokenPos(), type); 8508 ArrayNode* list = new ArrayNode(TokenPos(), type);
8534 8509
8535 // Parse the list elements. Note: there may be an optional extra 8510 // Parse the list elements. Note: there may be an optional extra
8536 // comma after the last element. 8511 // comma after the last element.
8537 if (!is_empty_literal) { 8512 if (!is_empty_literal) {
8538 const bool saved_mode = SetAllowFunctionLiterals(true); 8513 const bool saved_mode = SetAllowFunctionLiterals(true);
8539 const String& dst_name = String::ZoneHandle(Symbols::ListLiteralElement());
8540 while (CurrentToken() != Token::kRBRACK) { 8514 while (CurrentToken() != Token::kRBRACK) {
8541 const intptr_t element_pos = TokenPos(); 8515 const intptr_t element_pos = TokenPos();
8542 AstNode* element = ParseExpr(is_const, kConsumeCascades); 8516 AstNode* element = ParseExpr(is_const, kConsumeCascades);
8543 if (FLAG_enable_type_checks && 8517 if (FLAG_enable_type_checks &&
8544 !is_const && 8518 !is_const &&
8545 !element_type.IsDynamicType()) { 8519 !element_type.IsDynamicType()) {
8546 element = new AssignableNode(element_pos, 8520 element = new AssignableNode(element_pos,
8547 element, 8521 element,
8548 element_type, 8522 element_type,
8549 dst_name); 8523 Symbols::ListLiteralElement());
8550 } 8524 }
8551 list->AddElement(element); 8525 list->AddElement(element);
8552 if (CurrentToken() == Token::kCOMMA) { 8526 if (CurrentToken() == Token::kCOMMA) {
8553 ConsumeToken(); 8527 ConsumeToken();
8554 } else if (CurrentToken() != Token::kRBRACK) { 8528 } else if (CurrentToken() != Token::kRBRACK) {
8555 ErrorMsg("comma or ']' expected"); 8529 ErrorMsg("comma or ']' expected");
8556 } 8530 }
8557 } 8531 }
8558 ExpectToken(Token::kRBRACK); 8532 ExpectToken(Token::kRBRACK);
8559 SetAllowFunctionLiterals(saved_mode); 8533 SetAllowFunctionLiterals(saved_mode);
(...skipping 26 matching lines...) Expand all
8586 String::Handle(element_type.UserVisibleName()).ToCString()); 8560 String::Handle(element_type.UserVisibleName()).ToCString());
8587 } 8561 }
8588 } 8562 }
8589 const_list.SetAt(i, elem->AsLiteralNode()->literal()); 8563 const_list.SetAt(i, elem->AsLiteralNode()->literal());
8590 } 8564 }
8591 const_list ^= const_list.Canonicalize(); 8565 const_list ^= const_list.Canonicalize();
8592 const_list.MakeImmutable(); 8566 const_list.MakeImmutable();
8593 return new LiteralNode(literal_pos, const_list); 8567 return new LiteralNode(literal_pos, const_list);
8594 } else { 8568 } else {
8595 // Factory call at runtime. 8569 // Factory call at runtime.
8596 String& factory_class_name = String::Handle(Symbols::List());
8597 const Class& factory_class = 8570 const Class& factory_class =
8598 Class::Handle(LookupCoreClass(factory_class_name)); 8571 Class::Handle(LookupCoreClass(Symbols::List()));
8599 ASSERT(!factory_class.IsNull()); 8572 ASSERT(!factory_class.IsNull());
8600 const String& factory_method_name =
8601 String::Handle(Symbols::ListLiteralFactory());
8602 const Function& factory_method = Function::ZoneHandle( 8573 const Function& factory_method = Function::ZoneHandle(
8603 factory_class.LookupFactory(factory_method_name)); 8574 factory_class.LookupFactory(Symbols::ListLiteralFactory()));
8604 ASSERT(!factory_method.IsNull()); 8575 ASSERT(!factory_method.IsNull());
8605 if (!type_arguments.IsNull() && 8576 if (!type_arguments.IsNull() &&
8606 !type_arguments.IsInstantiated() && 8577 !type_arguments.IsInstantiated() &&
8607 (current_block_->scope->function_level() > 0)) { 8578 (current_block_->scope->function_level() > 0)) {
8608 // Make sure that the instantiator is captured. 8579 // Make sure that the instantiator is captured.
8609 CaptureInstantiator(); 8580 CaptureInstantiator();
8610 } 8581 }
8611 AbstractTypeArguments& factory_type_args = 8582 AbstractTypeArguments& factory_type_args =
8612 AbstractTypeArguments::ZoneHandle(type_arguments.raw()); 8583 AbstractTypeArguments::ZoneHandle(type_arguments.raw());
8613 // If the factory class extends other parameterized classes, adjust the 8584 // If the factory class extends other parameterized classes, adjust the
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
8725 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); 8696 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2));
8726 map_type_arguments ^= map_type_arguments.Canonicalize(); 8697 map_type_arguments ^= map_type_arguments.Canonicalize();
8727 8698
8728 // The kv_pair array is temporary and of element type dynamic. It is passed 8699 // The kv_pair array is temporary and of element type dynamic. It is passed
8729 // to the factory to initialize a properly typed map. 8700 // to the factory to initialize a properly typed map.
8730 ArrayNode* kv_pairs = new ArrayNode( 8701 ArrayNode* kv_pairs = new ArrayNode(
8731 TokenPos(), Type::ZoneHandle(Type::ArrayType())); 8702 TokenPos(), Type::ZoneHandle(Type::ArrayType()));
8732 8703
8733 // Parse the map entries. Note: there may be an optional extra 8704 // Parse the map entries. Note: there may be an optional extra
8734 // comma after the last entry. 8705 // comma after the last entry.
8735 const String& dst_name = String::ZoneHandle(Symbols::ListLiteralElement());
8736 while (CurrentToken() != Token::kRBRACE) { 8706 while (CurrentToken() != Token::kRBRACE) {
8737 AstNode* key = NULL; 8707 AstNode* key = NULL;
8738 if (CurrentToken() == Token::kSTRING) { 8708 if (CurrentToken() == Token::kSTRING) {
8739 key = ParseStringLiteral(); 8709 key = ParseStringLiteral();
8740 } 8710 }
8741 if (key == NULL) { 8711 if (key == NULL) {
8742 ErrorMsg("map entry key must be string literal"); 8712 ErrorMsg("map entry key must be string literal");
8743 } else if (is_const && !key->IsLiteralNode()) { 8713 } else if (is_const && !key->IsLiteralNode()) {
8744 ErrorMsg("map entry key must be compile-time constant string"); 8714 ErrorMsg("map entry key must be compile-time constant string");
8745 } 8715 }
8746 ExpectToken(Token::kCOLON); 8716 ExpectToken(Token::kCOLON);
8747 const bool saved_mode = SetAllowFunctionLiterals(true); 8717 const bool saved_mode = SetAllowFunctionLiterals(true);
8748 const intptr_t value_pos = TokenPos(); 8718 const intptr_t value_pos = TokenPos();
8749 AstNode* value = ParseExpr(is_const, kConsumeCascades); 8719 AstNode* value = ParseExpr(is_const, kConsumeCascades);
8750 SetAllowFunctionLiterals(saved_mode); 8720 SetAllowFunctionLiterals(saved_mode);
8751 if (FLAG_enable_type_checks && 8721 if (FLAG_enable_type_checks &&
8752 !is_const && 8722 !is_const &&
8753 !value_type.IsDynamicType()) { 8723 !value_type.IsDynamicType()) {
8754 value = new AssignableNode(value_pos, 8724 value = new AssignableNode(value_pos,
8755 value, 8725 value,
8756 value_type, 8726 value_type,
8757 dst_name); 8727 Symbols::ListLiteralElement());
8758 } 8728 }
8759 AddKeyValuePair(kv_pairs, is_const, key, value); 8729 AddKeyValuePair(kv_pairs, is_const, key, value);
8760 8730
8761 if (CurrentToken() == Token::kCOMMA) { 8731 if (CurrentToken() == Token::kCOMMA) {
8762 ConsumeToken(); 8732 ConsumeToken();
8763 } else if (CurrentToken() != Token::kRBRACE) { 8733 } else if (CurrentToken() != Token::kRBRACE) {
8764 ErrorMsg("comma or '}' expected"); 8734 ErrorMsg("comma or '}' expected");
8765 } 8735 }
8766 } 8736 }
8767 ASSERT(kv_pairs->length() % 2 == 0); 8737 ASSERT(kv_pairs->length() % 2 == 0);
(...skipping 28 matching lines...) Expand all
8796 i >> 1, 8766 i >> 1,
8797 String::Handle(value_type.UserVisibleName()).ToCString()); 8767 String::Handle(value_type.UserVisibleName()).ToCString());
8798 } 8768 }
8799 } 8769 }
8800 key_value_array.SetAt(i, arg->AsLiteralNode()->literal()); 8770 key_value_array.SetAt(i, arg->AsLiteralNode()->literal());
8801 } 8771 }
8802 key_value_array ^= key_value_array.Canonicalize(); 8772 key_value_array ^= key_value_array.Canonicalize();
8803 key_value_array.MakeImmutable(); 8773 key_value_array.MakeImmutable();
8804 8774
8805 // Construct the map object. 8775 // Construct the map object.
8806 const String& immutable_map_class_name =
8807 String::Handle(Symbols::ImmutableMap());
8808 const Class& immutable_map_class = 8776 const Class& immutable_map_class =
8809 Class::Handle(LookupCoreClass(immutable_map_class_name)); 8777 Class::Handle(LookupCoreClass(Symbols::ImmutableMap()));
8810 ASSERT(!immutable_map_class.IsNull()); 8778 ASSERT(!immutable_map_class.IsNull());
8811 // If the immutable map class extends other parameterized classes, we need 8779 // If the immutable map class extends other parameterized classes, we need
8812 // to adjust the type argument vector. This is currently not the case. 8780 // to adjust the type argument vector. This is currently not the case.
8813 ASSERT(immutable_map_class.NumTypeArguments() == 2); 8781 ASSERT(immutable_map_class.NumTypeArguments() == 2);
8814 ArgumentListNode* constr_args = new ArgumentListNode(TokenPos()); 8782 ArgumentListNode* constr_args = new ArgumentListNode(TokenPos());
8815 constr_args->Add(new LiteralNode(literal_pos, key_value_array)); 8783 constr_args->Add(new LiteralNode(literal_pos, key_value_array));
8816 const String& constr_name = 8784 const Function& map_constr =
8817 String::Handle(Symbols::ImmutableMapConstructor()); 8785 Function::ZoneHandle(immutable_map_class.LookupConstructor(
8818 const Function& map_constr = Function::ZoneHandle( 8786 Symbols::ImmutableMapConstructor()));
8819 immutable_map_class.LookupConstructor(constr_name));
8820 ASSERT(!map_constr.IsNull()); 8787 ASSERT(!map_constr.IsNull());
8821 const Object& constructor_result = Object::Handle( 8788 const Object& constructor_result = Object::Handle(
8822 EvaluateConstConstructorCall(immutable_map_class, 8789 EvaluateConstConstructorCall(immutable_map_class,
8823 map_type_arguments, 8790 map_type_arguments,
8824 map_constr, 8791 map_constr,
8825 constr_args)); 8792 constr_args));
8826 if (constructor_result.IsUnhandledException()) { 8793 if (constructor_result.IsUnhandledException()) {
8827 return GenerateRethrow(literal_pos, constructor_result); 8794 return GenerateRethrow(literal_pos, constructor_result);
8828 } else { 8795 } else {
8829 const Instance& const_instance = Instance::Cast(constructor_result); 8796 const Instance& const_instance = Instance::Cast(constructor_result);
8830 return new LiteralNode(literal_pos, 8797 return new LiteralNode(literal_pos,
8831 Instance::ZoneHandle(const_instance.raw())); 8798 Instance::ZoneHandle(const_instance.raw()));
8832 } 8799 }
8833 } else { 8800 } else {
8834 // Factory call at runtime. 8801 // Factory call at runtime.
8835 String& factory_class_name = String::Handle(Symbols::Map());
8836 const Class& factory_class = 8802 const Class& factory_class =
8837 Class::Handle(LookupCoreClass(factory_class_name)); 8803 Class::Handle(LookupCoreClass(Symbols::Map()));
8838 ASSERT(!factory_class.IsNull()); 8804 ASSERT(!factory_class.IsNull());
8839 const String& factory_method_name =
8840 String::Handle(Symbols::MapLiteralFactory());
8841 const Function& factory_method = Function::ZoneHandle( 8805 const Function& factory_method = Function::ZoneHandle(
8842 factory_class.LookupFactory(factory_method_name)); 8806 factory_class.LookupFactory(Symbols::MapLiteralFactory()));
8843 ASSERT(!factory_method.IsNull()); 8807 ASSERT(!factory_method.IsNull());
8844 if (!map_type_arguments.IsNull() && 8808 if (!map_type_arguments.IsNull() &&
8845 !map_type_arguments.IsInstantiated() && 8809 !map_type_arguments.IsInstantiated() &&
8846 (current_block_->scope->function_level() > 0)) { 8810 (current_block_->scope->function_level() > 0)) {
8847 // Make sure that the instantiator is captured. 8811 // Make sure that the instantiator is captured.
8848 CaptureInstantiator(); 8812 CaptureInstantiator();
8849 } 8813 }
8850 AbstractTypeArguments& factory_type_args = 8814 AbstractTypeArguments& factory_type_args =
8851 AbstractTypeArguments::ZoneHandle(map_type_arguments.raw()); 8815 AbstractTypeArguments::ZoneHandle(map_type_arguments.raw());
8852 // If the factory class extends other parameterized classes, adjust the 8816 // If the factory class extends other parameterized classes, adjust the
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
8901 } 8865 }
8902 8866
8903 8867
8904 static const String& BuildConstructorName(const String& type_class_name, 8868 static const String& BuildConstructorName(const String& type_class_name,
8905 const String* named_constructor) { 8869 const String* named_constructor) {
8906 // By convention, the static function implementing a named constructor 'C' 8870 // By convention, the static function implementing a named constructor 'C'
8907 // for class 'A' is labeled 'A.C', and the static function implementing the 8871 // for class 'A' is labeled 'A.C', and the static function implementing the
8908 // unnamed constructor for class 'A' is labeled 'A.'. 8872 // unnamed constructor for class 'A' is labeled 'A.'.
8909 // This convention prevents users from explicitly calling constructors. 8873 // This convention prevents users from explicitly calling constructors.
8910 String& constructor_name = 8874 String& constructor_name =
8911 String::Handle(String::Concat(type_class_name, Symbols::DotHandle())); 8875 String::Handle(String::Concat(type_class_name, Symbols::Dot()));
8912 if (named_constructor != NULL) { 8876 if (named_constructor != NULL) {
8913 constructor_name = String::Concat(constructor_name, *named_constructor); 8877 constructor_name = String::Concat(constructor_name, *named_constructor);
8914 } 8878 }
8915 return constructor_name; 8879 return constructor_name;
8916 } 8880 }
8917 8881
8918 8882
8919 AstNode* Parser::ParseNewOperator() { 8883 AstNode* Parser::ParseNewOperator() {
8920 TRACE_PARSER("ParseNewOperator"); 8884 TRACE_PARSER("ParseNewOperator");
8921 const intptr_t new_pos = TokenPos(); 8885 const intptr_t new_pos = TokenPos();
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
9044 9008
9045 // It is ok to call a factory method of an abstract class, but it is 9009 // It is ok to call a factory method of an abstract class, but it is
9046 // a dynamic error to instantiate an abstract class. 9010 // a dynamic error to instantiate an abstract class.
9047 ASSERT(!constructor.IsNull()); 9011 ASSERT(!constructor.IsNull());
9048 if (type_class.is_abstract() && !constructor.IsFactory()) { 9012 if (type_class.is_abstract() && !constructor.IsFactory()) {
9049 ArgumentListNode* arguments = new ArgumentListNode(type_pos); 9013 ArgumentListNode* arguments = new ArgumentListNode(type_pos);
9050 arguments->Add(new LiteralNode( 9014 arguments->Add(new LiteralNode(
9051 TokenPos(), Integer::ZoneHandle(Integer::New(type_pos)))); 9015 TokenPos(), Integer::ZoneHandle(Integer::New(type_pos))));
9052 arguments->Add(new LiteralNode( 9016 arguments->Add(new LiteralNode(
9053 TokenPos(), String::ZoneHandle(type_class_name.raw()))); 9017 TokenPos(), String::ZoneHandle(type_class_name.raw())));
9054 const String& cls_name = 9018 return MakeStaticCall(Symbols::AbstractClassInstantiationError(),
9055 String::Handle(Symbols::AbstractClassInstantiationError()); 9019 Symbols::ThrowNew(),
9056 const String& func_name = String::Handle(Symbols::ThrowNew()); 9020 arguments);
9057 return MakeStaticCall(cls_name, func_name, arguments);
9058 } 9021 }
9059 String& error_message = String::Handle(); 9022 String& error_message = String::Handle();
9060 if (!constructor.AreValidArguments(arguments_length, 9023 if (!constructor.AreValidArguments(arguments_length,
9061 arguments->names(), 9024 arguments->names(),
9062 &error_message)) { 9025 &error_message)) {
9063 const String& external_constructor_name = 9026 const String& external_constructor_name =
9064 (named_constructor ? constructor_name : type_class_name); 9027 (named_constructor ? constructor_name : type_class_name);
9065 if (is_const) { 9028 if (is_const) {
9066 ErrorMsg(call_pos, 9029 ErrorMsg(call_pos,
9067 "invalid arguments passed to constructor '%s' " 9030 "invalid arguments passed to constructor '%s' "
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
9128 (current_block_->scope->function_level() > 0)) { 9091 (current_block_->scope->function_level() > 0)) {
9129 // Make sure that the instantiator is captured. 9092 // Make sure that the instantiator is captured.
9130 CaptureInstantiator(); 9093 CaptureInstantiator();
9131 } 9094 }
9132 // If the type argument vector is not instantiated, we verify in checked 9095 // If the type argument vector is not instantiated, we verify in checked
9133 // mode at runtime that it is within its declared bounds. 9096 // mode at runtime that it is within its declared bounds.
9134 new_object = CreateConstructorCallNode( 9097 new_object = CreateConstructorCallNode(
9135 new_pos, type_arguments, constructor, arguments); 9098 new_pos, type_arguments, constructor, arguments);
9136 } 9099 }
9137 if (!type_bound.IsNull()) { 9100 if (!type_bound.IsNull()) {
9138 const String& dst_name = String::ZoneHandle(Symbols::FactoryResult()); 9101 new_object = new AssignableNode(new_pos,
9139 new_object = new AssignableNode(new_pos, new_object, type_bound, dst_name); 9102 new_object,
9103 type_bound,
9104 Symbols::FactoryResult());
9140 } 9105 }
9141 return new_object; 9106 return new_object;
9142 } 9107 }
9143 9108
9144 9109
9145 String& Parser::Interpolate(ArrayNode* values) { 9110 String& Parser::Interpolate(ArrayNode* values) {
9146 const String& class_name = String::Handle(Symbols::StringBase()); 9111 const Class& cls = Class::Handle(LookupCoreClass(Symbols::StringBase()));
9147 const Class& cls = Class::Handle(LookupCoreClass(class_name));
9148 ASSERT(!cls.IsNull()); 9112 ASSERT(!cls.IsNull());
9149 const String& func_name = String::Handle(Symbols::Interpolate());
9150 const Function& func = 9113 const Function& func =
9151 Function::Handle(cls.LookupStaticFunction(func_name)); 9114 Function::Handle(cls.LookupStaticFunction(Symbols::Interpolate()));
9152 ASSERT(!func.IsNull()); 9115 ASSERT(!func.IsNull());
9153 9116
9154 // Build the array of literal values to interpolate. 9117 // Build the array of literal values to interpolate.
9155 const Array& value_arr = Array::Handle(Array::New(values->length())); 9118 const Array& value_arr = Array::Handle(Array::New(values->length()));
9156 for (int i = 0; i < values->length(); i++) { 9119 for (int i = 0; i < values->length(); i++) {
9157 ASSERT(values->ElementAt(i)->IsLiteralNode()); 9120 ASSERT(values->ElementAt(i)->IsLiteralNode());
9158 value_arr.SetAt(i, values->ElementAt(i)->AsLiteralNode()->literal()); 9121 value_arr.SetAt(i, values->ElementAt(i)->AsLiteralNode()->literal());
9159 } 9122 }
9160 9123
9161 // Build argument array to pass to the interpolation function. 9124 // Build argument array to pass to the interpolation function.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
9232 } 9195 }
9233 values->AddElement(expr); 9196 values->AddElement(expr);
9234 } 9197 }
9235 } 9198 }
9236 if (is_compiletime_const) { 9199 if (is_compiletime_const) {
9237 primary = new LiteralNode(literal_start, Interpolate(values)); 9200 primary = new LiteralNode(literal_start, Interpolate(values));
9238 } else { 9201 } else {
9239 ArgumentListNode* interpolate_arg = 9202 ArgumentListNode* interpolate_arg =
9240 new ArgumentListNode(values->token_pos()); 9203 new ArgumentListNode(values->token_pos());
9241 interpolate_arg->Add(values); 9204 interpolate_arg->Add(values);
9242 const String& cls_name = String::Handle(Symbols::StringBase()); 9205 primary = MakeStaticCall(Symbols::StringBase(),
9243 const String& func_name = String::Handle(Symbols::Interpolate()); 9206 Symbols::Interpolate(),
9244 primary = MakeStaticCall(cls_name, func_name, interpolate_arg); 9207 interpolate_arg);
9245 } 9208 }
9246 return primary; 9209 return primary;
9247 } 9210 }
9248 9211
9249 9212
9250 AstNode* Parser::ParseArgumentDefinitionTest() { 9213 AstNode* Parser::ParseArgumentDefinitionTest() {
9251 const intptr_t test_pos = TokenPos(); 9214 const intptr_t test_pos = TokenPos();
9252 ConsumeToken(); 9215 ConsumeToken();
9253 const intptr_t ident_pos = TokenPos(); 9216 const intptr_t ident_pos = TokenPos();
9254 String* ident = ExpectIdentifier("parameter name expected"); 9217 String* ident = ExpectIdentifier("parameter name expected");
9255 Function& owner_function = Function::Handle(); 9218 Function& owner_function = Function::Handle();
9256 LocalScope* owner_scope; 9219 LocalScope* owner_scope;
9257 intptr_t param_index; 9220 intptr_t param_index;
9258 if (!IsFormalParameter(*ident, &owner_function, &owner_scope, &param_index)) { 9221 if (!IsFormalParameter(*ident, &owner_function, &owner_scope, &param_index)) {
9259 ErrorMsg(ident_pos, "formal parameter name expected"); 9222 ErrorMsg(ident_pos, "formal parameter name expected");
9260 } 9223 }
9261 if (param_index < owner_function.num_fixed_parameters()) { 9224 if (param_index < owner_function.num_fixed_parameters()) {
9262 // The formal parameter is not optional, therefore the corresponding 9225 // The formal parameter is not optional, therefore the corresponding
9263 // argument is always passed and defined. 9226 // argument is always passed and defined.
9264 return new LiteralNode(test_pos, Bool::ZoneHandle(Bool::True())); 9227 return new LiteralNode(test_pos, Bool::ZoneHandle(Bool::True()));
9265 } 9228 }
9266 char name[64]; 9229 char name[64];
9267 OS::SNPrint(name, 64, "%s_%"Pd"", 9230 OS::SNPrint(name, 64, "%s_%"Pd"",
9268 Symbols::Name(Symbols::kSavedArgDescVarPrefix), 9231 Symbols::Name(Symbols::kSavedArgDescVarPrefixId),
9269 owner_function.token_pos()); 9232 owner_function.token_pos());
9270 const String& saved_args_desc_name = String::ZoneHandle(Symbols::New(name)); 9233 const String& saved_args_desc_name = String::ZoneHandle(Symbols::New(name));
9271 LocalVariable* saved_args_desc_var = LookupLocalScope(saved_args_desc_name); 9234 LocalVariable* saved_args_desc_var = LookupLocalScope(saved_args_desc_name);
9272 if (saved_args_desc_var == NULL) { 9235 if (saved_args_desc_var == NULL) {
9273 ASSERT(owner_scope != NULL); 9236 ASSERT(owner_scope != NULL);
9274 saved_args_desc_var = 9237 saved_args_desc_var =
9275 new LocalVariable(owner_function.token_pos(), 9238 new LocalVariable(owner_function.token_pos(),
9276 saved_args_desc_name, 9239 saved_args_desc_name,
9277 Type::ZoneHandle(Type::ArrayType())); 9240 Type::ZoneHandle(Type::ArrayType()));
9278 saved_args_desc_var->set_is_final(); 9241 saved_args_desc_var->set_is_final();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
9337 } else { 9300 } else {
9338 // This is a qualified identifier with a library prefix so resolve 9301 // This is a qualified identifier with a library prefix so resolve
9339 // the identifier locally in that library (we do not include the 9302 // the identifier locally in that library (we do not include the
9340 // libraries imported by that library). 9303 // libraries imported by that library).
9341 primary = ResolveIdentInPrefixScope(qual_ident.ident_pos, 9304 primary = ResolveIdentInPrefixScope(qual_ident.ident_pos,
9342 *qual_ident.lib_prefix, 9305 *qual_ident.lib_prefix,
9343 *qual_ident.ident); 9306 *qual_ident.ident);
9344 } 9307 }
9345 ASSERT(primary != NULL); 9308 ASSERT(primary != NULL);
9346 } else if (CurrentToken() == Token::kTHIS) { 9309 } else if (CurrentToken() == Token::kTHIS) {
9347 LocalVariable* local = LookupLocalScope(Symbols::ThisHandle()); 9310 LocalVariable* local = LookupLocalScope(Symbols::This());
9348 if (local == NULL) { 9311 if (local == NULL) {
9349 ErrorMsg("receiver 'this' is not in scope"); 9312 ErrorMsg("receiver 'this' is not in scope");
9350 } 9313 }
9351 primary = new LoadLocalNode(TokenPos(), local); 9314 primary = new LoadLocalNode(TokenPos(), local);
9352 ConsumeToken(); 9315 ConsumeToken();
9353 } else if (CurrentToken() == Token::kINTEGER) { 9316 } else if (CurrentToken() == Token::kINTEGER) {
9354 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); 9317 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral());
9355 primary = new LiteralNode(TokenPos(), literal); 9318 primary = new LiteralNode(TokenPos(), literal);
9356 ConsumeToken(); 9319 ConsumeToken();
9357 } else if (CurrentToken() == Token::kTRUE) { 9320 } else if (CurrentToken() == Token::kTRUE) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
9409 if (CurrentToken() == Token::kLPAREN) { 9372 if (CurrentToken() == Token::kLPAREN) {
9410 primary = ParseSuperCall(ident); 9373 primary = ParseSuperCall(ident);
9411 } else { 9374 } else {
9412 primary = ParseSuperFieldAccess(ident); 9375 primary = ParseSuperFieldAccess(ident);
9413 } 9376 }
9414 } else if ((CurrentToken() == Token::kLBRACK) || 9377 } else if ((CurrentToken() == Token::kLBRACK) ||
9415 Token::CanBeOverloaded(CurrentToken()) || 9378 Token::CanBeOverloaded(CurrentToken()) ||
9416 (CurrentToken() == Token::kNE)) { 9379 (CurrentToken() == Token::kNE)) {
9417 primary = ParseSuperOperator(); 9380 primary = ParseSuperOperator();
9418 } else { 9381 } else {
9419 primary = new PrimaryNode(TokenPos(), 9382 primary = new PrimaryNode(TokenPos(), Symbols::Super());
9420 String::ZoneHandle(Symbols::Super()));
9421 } 9383 }
9422 } else if (CurrentToken() == Token::kCONDITIONAL) { 9384 } else if (CurrentToken() == Token::kCONDITIONAL) {
9423 primary = ParseArgumentDefinitionTest(); 9385 primary = ParseArgumentDefinitionTest();
9424 } else { 9386 } else {
9425 UnexpectedToken(); 9387 UnexpectedToken();
9426 } 9388 }
9427 return primary; 9389 return primary;
9428 } 9390 }
9429 9391
9430 9392
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
9736 void Parser::SkipQualIdent() { 9698 void Parser::SkipQualIdent() {
9737 ASSERT(IsIdentifier()); 9699 ASSERT(IsIdentifier());
9738 ConsumeToken(); 9700 ConsumeToken();
9739 if (CurrentToken() == Token::kPERIOD) { 9701 if (CurrentToken() == Token::kPERIOD) {
9740 ConsumeToken(); // Consume the kPERIOD token. 9702 ConsumeToken(); // Consume the kPERIOD token.
9741 ExpectIdentifier("identifier expected after '.'"); 9703 ExpectIdentifier("identifier expected after '.'");
9742 } 9704 }
9743 } 9705 }
9744 9706
9745 } // namespace dart 9707 } // namespace dart
OLDNEW
« no previous file with comments | « vm/object_test.cc ('k') | vm/resolver_test.cc » ('j') | vm/symbols.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698