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

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

Issue 8509031: Revert r1380 that is breaking frog. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object_test.cc ('k') | runtime/vm/parser_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 tokens_(TokenStream::Handle(script.tokens())), 167 tokens_(TokenStream::Handle(script.tokens())),
168 token_index_(0), 168 token_index_(0),
169 current_block_(NULL), 169 current_block_(NULL),
170 is_top_level_(false), 170 is_top_level_(false),
171 current_member_(NULL), 171 current_member_(NULL),
172 allow_function_literals_(true), 172 allow_function_literals_(true),
173 current_function_(Function::Handle()), 173 current_function_(Function::Handle()),
174 current_class_(Class::Handle()), 174 current_class_(Class::Handle()),
175 library_(library), 175 library_(library),
176 try_blocks_list_(NULL) { 176 try_blocks_list_(NULL) {
177 ASSERT(!tokens_.IsNull());
178 ASSERT(!library.IsNull());
179 SetPosition(0); 177 SetPosition(0);
180 } 178 }
181 179
182 180
183 Parser::Parser(const Script& script, 181 Parser::Parser(const Script& script,
184 const Function& function, 182 const Function& function,
185 intptr_t token_index) 183 intptr_t token_index)
186 : script_(script), 184 : script_(script),
187 tokens_(TokenStream::Handle(script.tokens())), 185 tokens_(TokenStream::Handle(script.tokens())),
188 token_index_(0), 186 token_index_(0),
189 current_block_(NULL), 187 current_block_(NULL),
190 is_top_level_(false), 188 is_top_level_(false),
191 current_member_(NULL), 189 current_member_(NULL),
192 allow_function_literals_(true), 190 allow_function_literals_(true),
193 current_function_(function), 191 current_function_(function),
194 current_class_(Class::Handle(current_function_.owner())), 192 current_class_(Class::Handle(current_function_.owner())),
195 library_(Library::Handle(current_class_.library())), 193 library_(Library::Handle(current_class_.library())),
196 try_blocks_list_(NULL) { 194 try_blocks_list_(NULL) {
197 ASSERT(!tokens_.IsNull());
198 ASSERT(!function.IsNull());
199 SetPosition(token_index); 195 SetPosition(token_index);
200 } 196 }
201 197
202 198
203 bool Parser::SetAllowFunctionLiterals(bool value) { 199 bool Parser::SetAllowFunctionLiterals(bool value) {
204 bool current_value = allow_function_literals_; 200 bool current_value = allow_function_literals_;
205 allow_function_literals_ = value; 201 allow_function_literals_ = value;
206 return current_value; 202 return current_value;
207 } 203 }
208 204
(...skipping 2400 matching lines...) Expand 10 before | Expand all | Expand 10 after
2609 if (CurrentToken() != Token::kIDENT) { 2605 if (CurrentToken() != Token::kIDENT) {
2610 ErrorMsg("function alias name expected"); 2606 ErrorMsg("function alias name expected");
2611 } 2607 }
2612 const intptr_t alias_name_pos = token_index_; 2608 const intptr_t alias_name_pos = token_index_;
2613 const String* alias_name = CurrentLiteral(); 2609 const String* alias_name = CurrentLiteral();
2614 ConsumeToken(); 2610 ConsumeToken();
2615 2611
2616 // Allocate an interface to hold the type parameters and their 'extends' 2612 // Allocate an interface to hold the type parameters and their 'extends'
2617 // constraints. Make it the owner of the function type descriptor. 2613 // constraints. Make it the owner of the function type descriptor.
2618 const Class& alias_owner = Class::Handle( 2614 const Class& alias_owner = Class::Handle(
2619 Class::New(String::Handle(String::NewSymbol(":alias_owner")), 2615 Class::New(String::Handle(String::NewSymbol("")), Script::Handle()));
2620 Script::Handle()));
2621 alias_owner.set_is_interface(); 2616 alias_owner.set_is_interface();
2622 set_current_class(alias_owner); 2617 set_current_class(alias_owner);
2623 ParseTypeParameters(alias_owner); 2618 ParseTypeParameters(alias_owner);
2624 if (CurrentToken() != Token::kLPAREN) { 2619 if (CurrentToken() != Token::kLPAREN) {
2625 ErrorMsg("formal parameter list expected"); 2620 ErrorMsg("formal parameter list expected");
2626 } 2621 }
2627 2622
2628 // At this point, the type parameters have been parsed, so we can resolve the 2623 // At this point, the type parameters have been parsed, so we can resolve the
2629 // result type. 2624 // result type.
2630 if (!result_type.IsNull() && !result_type.IsResolved()) { 2625 if (!result_type.IsNull() && !result_type.IsResolved()) {
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
3205 3200
3206 void Parser::ParseTopLevel() { 3201 void Parser::ParseTopLevel() {
3207 // Collect the classes found at the top level in this growable array. 3202 // Collect the classes found at the top level in this growable array.
3208 // They need to be registered with class finalization after parsing 3203 // They need to be registered with class finalization after parsing
3209 // has been completed. 3204 // has been completed.
3210 GrowableArray<const Class*> classes; 3205 GrowableArray<const Class*> classes;
3211 SetPosition(0); 3206 SetPosition(0);
3212 is_top_level_ = true; 3207 is_top_level_ = true;
3213 TopLevel top_level; 3208 TopLevel top_level;
3214 Class& toplevel_class = Class::ZoneHandle( 3209 Class& toplevel_class = Class::ZoneHandle(
3215 Class::New(String::ZoneHandle(String::NewSymbol("::")), script_)); 3210 Class::New(String::ZoneHandle(String::NewSymbol("")), script_));
3216 toplevel_class.set_library(library_); 3211 toplevel_class.set_library(library_);
3217 3212
3218 // We notify the class finalizer to expect classes to finalize.
3219 // This allows signature classes generated at runtime to be properly
3220 // finalized, without finalizing them prematurely at compile time.
3221 ClassFinalizer::ExpectClassesToFinalize();
3222
3223 if (is_library_source()) { 3213 if (is_library_source()) {
3224 ParseLibraryDefinition(); 3214 ParseLibraryDefinition();
3225 } 3215 }
3226 3216
3227 while (true) { 3217 while (true) {
3228 set_current_class(Class::Handle()); // No current class. 3218 set_current_class(Class::Handle()); // No current class.
3229 if (CurrentToken() == Token::kCLASS) { 3219 if (CurrentToken() == Token::kCLASS) {
3230 ParseClassDefinition(&classes); 3220 ParseClassDefinition(&classes);
3231 } else if (CurrentToken() == Token::kTYPEDEF) { 3221 } else if (CurrentToken() == Token::kTYPEDEF) {
3232 ParseFunctionTypeAlias(&classes); 3222 ParseFunctionTypeAlias(&classes);
(...skipping 15 matching lines...) Expand all
3248 } 3238 }
3249 } 3239 }
3250 if ((top_level.fields.length() > 0) || (top_level.functions.length() > 0)) { 3240 if ((top_level.fields.length() > 0) || (top_level.functions.length() > 0)) {
3251 toplevel_class.SetFields( 3241 toplevel_class.SetFields(
3252 Array::Handle(NewArray<Field>(top_level.fields))); 3242 Array::Handle(NewArray<Field>(top_level.fields)));
3253 toplevel_class.SetFunctions( 3243 toplevel_class.SetFunctions(
3254 Array::Handle(NewArray<Function>(top_level.functions))); 3244 Array::Handle(NewArray<Function>(top_level.functions)));
3255 library_.AddAnonymousClass(toplevel_class); 3245 library_.AddAnonymousClass(toplevel_class);
3256 classes.Add(&toplevel_class); 3246 classes.Add(&toplevel_class);
3257 } 3247 }
3258 ClassFinalizer::AddClassesToFinalize(classes); 3248 ClassFinalizer::AddPendingClasses(classes);
3259 } 3249 }
3260 3250
3261 3251
3262 void Parser::ChainNewBlock(LocalScope* outer_scope) { 3252 void Parser::ChainNewBlock(LocalScope* outer_scope) {
3263 Block* block = new Block(current_block_, 3253 Block* block = new Block(current_block_,
3264 outer_scope, 3254 outer_scope,
3265 new SequenceNode(token_index_, outer_scope)); 3255 new SequenceNode(token_index_, outer_scope));
3266 current_block_ = block; 3256 current_block_ = block;
3267 } 3257 }
3268 3258
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
3682 3672
3683 // Since the signature type is cached by the signature class, it may have 3673 // Since the signature type is cached by the signature class, it may have
3684 // been finalized already. 3674 // been finalized already.
3685 if (!signature_type.IsFinalized()) { 3675 if (!signature_type.IsFinalized()) {
3686 String& errmsg = String::Handle(); 3676 String& errmsg = String::Handle();
3687 signature_type = 3677 signature_type =
3688 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); 3678 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg);
3689 if (!errmsg.IsNull()) { 3679 if (!errmsg.IsNull()) {
3690 ErrorMsg(errmsg.ToCString()); 3680 ErrorMsg(errmsg.ToCString());
3691 } 3681 }
3692 // The call to ClassFinalizer::FinalizeAndCanonicalizeType may have 3682 // The call to ClassFinalizer::FinalizeTypeWhileParsing may have extended
3693 // extended the vector of type arguments. 3683 // the vector of type arguments.
3694 ASSERT(signature_type_arguments.IsNull() || 3684 ASSERT(signature_type_arguments.IsNull() ||
3695 (signature_type_arguments.Length() == 3685 (signature_type_arguments.Length() ==
3696 signature_class.NumTypeArguments())); 3686 signature_class.NumTypeArguments()));
3697 // The signature_class should not have changed. 3687 // The signature_class should not have changed.
3698 ASSERT(signature_type.type_class() == signature_class.raw()); 3688 ASSERT(signature_type.type_class() == signature_class.raw());
3699 } 3689 }
3700 3690
3701 // Now patch the function type of the variable. 3691 // Now patch the function type of the variable.
3702 function_type.set_type_class(signature_class); 3692 function_type.set_type_class(signature_class);
3703 function_type.set_arguments(signature_type_arguments); 3693 function_type.set_arguments(signature_type_arguments);
(...skipping 3572 matching lines...) Expand 10 before | Expand all | Expand 10 after
7276 } 7266 }
7277 7267
7278 7268
7279 void Parser::SkipNestedExpr() { 7269 void Parser::SkipNestedExpr() {
7280 const bool saved_mode = SetAllowFunctionLiterals(true); 7270 const bool saved_mode = SetAllowFunctionLiterals(true);
7281 SkipExpr(); 7271 SkipExpr();
7282 SetAllowFunctionLiterals(saved_mode); 7272 SetAllowFunctionLiterals(saved_mode);
7283 } 7273 }
7284 7274
7285 } // namespace dart 7275 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object_test.cc ('k') | runtime/vm/parser_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698