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

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

Issue 2949803002: New growth strategy for growable arrays (Closed)
Patch Set: Branch-free grow size computation. Renamed function names to be clearer. Created 3 years, 6 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
« no previous file with comments | « runtime/vm/pages.cc ('k') | runtime/vm/precompiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 #include "vm/flags.h" 6 #include "vm/flags.h"
7 7
8 #ifndef DART_PRECOMPILED_RUNTIME 8 #ifndef DART_PRECOMPILED_RUNTIME
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 } 1329 }
1330 expr = GenerateStaticFieldLookup(field, ident_pos); 1330 expr = GenerateStaticFieldLookup(field, ident_pos);
1331 } 1331 }
1332 } 1332 }
1333 if (expr->EvalConstExpr() == NULL) { 1333 if (expr->EvalConstExpr() == NULL) {
1334 ReportError(expr_pos, "expression must be a compile-time constant"); 1334 ReportError(expr_pos, "expression must be a compile-time constant");
1335 } 1335 }
1336 const Instance& val = EvaluateConstExpr(expr_pos, expr); 1336 const Instance& val = EvaluateConstExpr(expr_pos, expr);
1337 meta_values.Add(val, Heap::kOld); 1337 meta_values.Add(val, Heap::kOld);
1338 } 1338 }
1339 return Array::MakeArray(meta_values); 1339 return Array::MakeFixedLength(meta_values);
1340 } 1340 }
1341 1341
1342 1342
1343 SequenceNode* Parser::ParseStaticInitializer() { 1343 SequenceNode* Parser::ParseStaticInitializer() {
1344 ExpectIdentifier("field name expected"); 1344 ExpectIdentifier("field name expected");
1345 CheckToken(Token::kASSIGN, "field initialier expected"); 1345 CheckToken(Token::kASSIGN, "field initialier expected");
1346 ConsumeToken(); 1346 ConsumeToken();
1347 OpenFunctionBlock(parsed_function()->function()); 1347 OpenFunctionBlock(parsed_function()->function());
1348 TokenPosition expr_pos = TokenPos(); 1348 TokenPosition expr_pos = TokenPos();
1349 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); 1349 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades);
(...skipping 3617 matching lines...) Expand 10 before | Expand all | Expand 10 after
4967 ParseClassMemberDefinition(&members, metadata_pos); 4967 ParseClassMemberDefinition(&members, metadata_pos);
4968 } 4968 }
4969 ExpectToken(Token::kRBRACE); 4969 ExpectToken(Token::kRBRACE);
4970 4970
4971 if (cls.LookupTypeParameter(class_name) != TypeParameter::null()) { 4971 if (cls.LookupTypeParameter(class_name) != TypeParameter::null()) {
4972 ReportError(class_pos, "class name conflicts with type parameter '%s'", 4972 ReportError(class_pos, "class name conflicts with type parameter '%s'",
4973 class_name.ToCString()); 4973 class_name.ToCString());
4974 } 4974 }
4975 CheckConstructors(&members); 4975 CheckConstructors(&members);
4976 4976
4977 // Need to compute this here since MakeArray() will clear the 4977 // Need to compute this here since MakeFixedLength() will clear the
4978 // functions array in members. 4978 // functions array in members.
4979 const bool need_implicit_constructor = 4979 const bool need_implicit_constructor =
4980 !members.has_constructor() && !cls.is_patch(); 4980 !members.has_constructor() && !cls.is_patch();
4981 4981
4982 cls.AddFields(members.fields()); 4982 cls.AddFields(members.fields());
4983 4983
4984 // Creating a new array for functions marks the class as parsed. 4984 // Creating a new array for functions marks the class as parsed.
4985 Array& array = Array::Handle(Z, members.MakeFunctionsArray()); 4985 Array& array = Array::Handle(Z, members.MakeFunctionsArray());
4986 cls.SetFunctions(array); 4986 cls.SetFunctions(array);
4987 4987
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
5723 ConsumeToken(); 5723 ConsumeToken();
5724 TokenPosition interface_pos = TokenPos(); 5724 TokenPosition interface_pos = TokenPos();
5725 interface = ParseType(ClassFinalizer::kResolveTypeParameters); 5725 interface = ParseType(ClassFinalizer::kResolveTypeParameters);
5726 if (interface.IsTypeParameter()) { 5726 if (interface.IsTypeParameter()) {
5727 ReportError(interface_pos, 5727 ReportError(interface_pos,
5728 "type parameter '%s' may not be used in interface list", 5728 "type parameter '%s' may not be used in interface list",
5729 String::Handle(Z, interface.UserVisibleName()).ToCString()); 5729 String::Handle(Z, interface.UserVisibleName()).ToCString());
5730 } 5730 }
5731 all_interfaces.Add(interface, Heap::kOld); 5731 all_interfaces.Add(interface, Heap::kOld);
5732 } while (CurrentToken() == Token::kCOMMA); 5732 } while (CurrentToken() == Token::kCOMMA);
5733 cls_interfaces = Array::MakeArray(all_interfaces); 5733 cls_interfaces = Array::MakeFixedLength(all_interfaces);
5734 cls.set_interfaces(cls_interfaces); 5734 cls.set_interfaces(cls_interfaces);
5735 } 5735 }
5736 5736
5737 5737
5738 RawAbstractType* Parser::ParseMixins(const AbstractType& super_type) { 5738 RawAbstractType* Parser::ParseMixins(const AbstractType& super_type) {
5739 TRACE_PARSER("ParseMixins"); 5739 TRACE_PARSER("ParseMixins");
5740 ASSERT(CurrentToken() == Token::kWITH); 5740 ASSERT(CurrentToken() == Token::kWITH);
5741 const GrowableObjectArray& mixin_types = 5741 const GrowableObjectArray& mixin_types =
5742 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); 5742 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld));
5743 AbstractType& mixin_type = AbstractType::Handle(Z); 5743 AbstractType& mixin_type = AbstractType::Handle(Z);
5744 do { 5744 do {
5745 ConsumeToken(); 5745 ConsumeToken();
5746 mixin_type = ParseType(ClassFinalizer::kResolveTypeParameters); 5746 mixin_type = ParseType(ClassFinalizer::kResolveTypeParameters);
5747 if (mixin_type.IsDynamicType()) { 5747 if (mixin_type.IsDynamicType()) {
5748 // The string 'dynamic' is not resolved yet at this point, but a malformed 5748 // The string 'dynamic' is not resolved yet at this point, but a malformed
5749 // type mapped to dynamic can be encountered here. 5749 // type mapped to dynamic can be encountered here.
5750 ReportError(mixin_type.token_pos(), "illegal mixin of a malformed type"); 5750 ReportError(mixin_type.token_pos(), "illegal mixin of a malformed type");
5751 } 5751 }
5752 if (mixin_type.IsTypeParameter()) { 5752 if (mixin_type.IsTypeParameter()) {
5753 ReportError(mixin_type.token_pos(), 5753 ReportError(mixin_type.token_pos(),
5754 "mixin type '%s' may not be a type parameter", 5754 "mixin type '%s' may not be a type parameter",
5755 String::Handle(Z, mixin_type.UserVisibleName()).ToCString()); 5755 String::Handle(Z, mixin_type.UserVisibleName()).ToCString());
5756 } 5756 }
5757 mixin_types.Add(mixin_type, Heap::kOld); 5757 mixin_types.Add(mixin_type, Heap::kOld);
5758 } while (CurrentToken() == Token::kCOMMA); 5758 } while (CurrentToken() == Token::kCOMMA);
5759 return MixinAppType::New(super_type, 5759 return MixinAppType::New(
5760 Array::Handle(Z, Array::MakeArray(mixin_types))); 5760 super_type, Array::Handle(Z, Array::MakeFixedLength(mixin_types)));
5761 } 5761 }
5762 5762
5763 5763
5764 void Parser::ParseTopLevelVariable(TopLevel* top_level, 5764 void Parser::ParseTopLevelVariable(TopLevel* top_level,
5765 const Object& owner, 5765 const Object& owner,
5766 TokenPosition metadata_pos) { 5766 TokenPosition metadata_pos) {
5767 TRACE_PARSER("ParseTopLevelVariable"); 5767 TRACE_PARSER("ParseTopLevelVariable");
5768 const bool is_const = (CurrentToken() == Token::kCONST); 5768 const bool is_const = (CurrentToken() == Token::kCONST);
5769 // Const fields are implicitly final. 5769 // Const fields are implicitly final.
5770 const bool is_final = is_const || (CurrentToken() == Token::kFINAL); 5770 const bool is_final = is_const || (CurrentToken() == Token::kFINAL);
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
6279 CheckToken(Token::kSTRING, "library url expected"); 6279 CheckToken(Token::kSTRING, "library url expected");
6280 AstNode* conditional_url_literal = ParseStringLiteral(false); 6280 AstNode* conditional_url_literal = ParseStringLiteral(false);
6281 6281
6282 // If there was already a condition that triggered, don't try to match 6282 // If there was already a condition that triggered, don't try to match
6283 // again. 6283 // again.
6284 if (condition_triggered) { 6284 if (condition_triggered) {
6285 continue; 6285 continue;
6286 } 6286 }
6287 // Check if this conditional line overrides the default import. 6287 // Check if this conditional line overrides the default import.
6288 const String& key = String::Handle(String::ConcatAll( 6288 const String& key = String::Handle(String::ConcatAll(
6289 Array::Handle(Array::MakeArray(pieces)), allocation_space_)); 6289 Array::Handle(Array::MakeFixedLength(pieces)), allocation_space_));
6290 const String& value = 6290 const String& value =
6291 (valueNode == NULL) 6291 (valueNode == NULL)
6292 ? Symbols::True() 6292 ? Symbols::True()
6293 : String::Cast(valueNode->AsLiteralNode()->literal()); 6293 : String::Cast(valueNode->AsLiteralNode()->literal());
6294 // Call the embedder to supply us with the environment. 6294 // Call the embedder to supply us with the environment.
6295 const String& env_value = 6295 const String& env_value =
6296 String::Handle(Api::GetEnvironmentValue(T, key)); 6296 String::Handle(Api::GetEnvironmentValue(T, key));
6297 if (!env_value.IsNull() && env_value.Equals(value)) { 6297 if (!env_value.IsNull() && env_value.Equals(value)) {
6298 condition_triggered = true; 6298 condition_triggered = true;
6299 url_literal = conditional_url_literal; 6299 url_literal = conditional_url_literal;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
6338 ConsumeToken(); 6338 ConsumeToken();
6339 ParseIdentList(&show_list); 6339 ParseIdentList(&show_list);
6340 } else if (IsSymbol(Symbols::Hide())) { 6340 } else if (IsSymbol(Symbols::Hide())) {
6341 ConsumeToken(); 6341 ConsumeToken();
6342 ParseIdentList(&hide_list); 6342 ParseIdentList(&hide_list);
6343 } else { 6343 } else {
6344 break; 6344 break;
6345 } 6345 }
6346 } 6346 }
6347 if (show_list.Length() > 0) { 6347 if (show_list.Length() > 0) {
6348 show_names = Array::MakeArray(show_list); 6348 show_names = Array::MakeFixedLength(show_list);
6349 } 6349 }
6350 if (hide_list.Length() > 0) { 6350 if (hide_list.Length() > 0) {
6351 hide_names = Array::MakeArray(hide_list); 6351 hide_names = Array::MakeFixedLength(hide_list);
6352 } 6352 }
6353 } 6353 }
6354 ExpectSemicolon(); 6354 ExpectSemicolon();
6355 6355
6356 // Canonicalize library URL. 6356 // Canonicalize library URL.
6357 const String& canon_url = String::CheckedHandle( 6357 const String& canon_url = String::CheckedHandle(
6358 CallLibraryTagHandler(Dart_kCanonicalizeUrl, import_pos, url)); 6358 CallLibraryTagHandler(Dart_kCanonicalizeUrl, import_pos, url));
6359 6359
6360 // Create a new library if it does not exist yet. 6360 // Create a new library if it does not exist yet.
6361 Library& library = Library::Handle(Z, Library::LookupLibrary(T, canon_url)); 6361 Library& library = Library::Handle(Z, Library::LookupLibrary(T, canon_url));
(...skipping 4012 matching lines...) Expand 10 before | Expand all | Expand 10 after
10374 tokens_iterator_.SetCurrentPosition(finally_pos); 10374 tokens_iterator_.SetCurrentPosition(finally_pos);
10375 rethrow_clause = EnsureFinallyClause( 10375 rethrow_clause = EnsureFinallyClause(
10376 parse, is_async, exception_var, stack_trace_var, 10376 parse, is_async, exception_var, stack_trace_var,
10377 is_async ? saved_exception_var : exception_var, 10377 is_async ? saved_exception_var : exception_var,
10378 is_async ? saved_stack_trace_var : stack_trace_var); 10378 is_async ? saved_stack_trace_var : stack_trace_var);
10379 } 10379 }
10380 } 10380 }
10381 10381
10382 CatchClauseNode* catch_clause = new (Z) CatchClauseNode( 10382 CatchClauseNode* catch_clause = new (Z) CatchClauseNode(
10383 handler_pos, catch_handler_list, 10383 handler_pos, catch_handler_list,
10384 Array::ZoneHandle(Z, Array::MakeArray(handler_types)), context_var, 10384 Array::ZoneHandle(Z, Array::MakeFixedLength(handler_types)), context_var,
10385 exception_var, stack_trace_var, 10385 exception_var, stack_trace_var,
10386 is_async ? saved_exception_var : exception_var, 10386 is_async ? saved_exception_var : exception_var,
10387 is_async ? saved_stack_trace_var : stack_trace_var, 10387 is_async ? saved_stack_trace_var : stack_trace_var,
10388 (finally_clause != NULL) ? AllocateTryIndex() 10388 (finally_clause != NULL) ? AllocateTryIndex()
10389 : CatchClauseNode::kInvalidTryIndex, 10389 : CatchClauseNode::kInvalidTryIndex,
10390 needs_stack_trace); 10390 needs_stack_trace);
10391 10391
10392 // Now create the try/catch ast node and return it. If there is a label 10392 // Now create the try/catch ast node and return it. If there is a label
10393 // on the try/catch, close the block that's embedding the try statement 10393 // on the try/catch, close the block that's embedding the try statement
10394 // and attach the label to it. 10394 // and attach the label to it.
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after
11735 ReportError("named argument expected"); 11735 ReportError("named argument expected");
11736 } 11736 }
11737 arguments->Add(ParseExpr(require_const, kConsumeCascades)); 11737 arguments->Add(ParseExpr(require_const, kConsumeCascades));
11738 } while (CurrentToken() == Token::kCOMMA); 11738 } while (CurrentToken() == Token::kCOMMA);
11739 } else { 11739 } else {
11740 ConsumeToken(); 11740 ConsumeToken();
11741 } 11741 }
11742 ExpectToken(Token::kRPAREN); 11742 ExpectToken(Token::kRPAREN);
11743 SetAllowFunctionLiterals(saved_mode); 11743 SetAllowFunctionLiterals(saved_mode);
11744 if (named_argument_seen) { 11744 if (named_argument_seen) {
11745 arguments->set_names(Array::Handle(Z, Array::MakeArray(names))); 11745 arguments->set_names(Array::Handle(Z, Array::MakeFixedLength(names)));
11746 } 11746 }
11747 return arguments; 11747 return arguments;
11748 } 11748 }
11749 11749
11750 11750
11751 AstNode* Parser::ParseStaticCall(const Class& cls, 11751 AstNode* Parser::ParseStaticCall(const Class& cls,
11752 const String& func_name, 11752 const String& func_name,
11753 TokenPosition ident_pos, 11753 TokenPosition ident_pos,
11754 const TypeArguments& func_type_args, 11754 const TypeArguments& func_type_args,
11755 const LibraryPrefix* prefix) { 11755 const LibraryPrefix* prefix) {
(...skipping 3557 matching lines...) Expand 10 before | Expand all | Expand 10 after
15313 TokenPosition* start, 15313 TokenPosition* start,
15314 TokenPosition* end) { 15314 TokenPosition* end) {
15315 UNREACHABLE(); 15315 UNREACHABLE();
15316 return false; 15316 return false;
15317 } 15317 }
15318 15318
15319 15319
15320 } // namespace dart 15320 } // namespace dart
15321 15321
15322 #endif // DART_PRECOMPILED_RUNTIME 15322 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW
« no previous file with comments | « runtime/vm/pages.cc ('k') | runtime/vm/precompiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698