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

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

Issue 1271343003: Reuse constructor closures (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/ast_transformer.h" 9 #include "vm/ast_transformer.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 12847 matching lines...) Expand 10 before | Expand all | Expand 10 after
12858 } 12858 }
12859 const Instance& instance = Instance::Cast(result); 12859 const Instance& instance = Instance::Cast(result);
12860 return new(Z) LiteralNode(symbol_pos, 12860 return new(Z) LiteralNode(symbol_pos,
12861 Instance::ZoneHandle(Z, instance.raw())); 12861 Instance::ZoneHandle(Z, instance.raw()));
12862 } 12862 }
12863 12863
12864 12864
12865 RawFunction* Parser::BuildConstructorClosureFunction(const Function& ctr, 12865 RawFunction* Parser::BuildConstructorClosureFunction(const Function& ctr,
12866 intptr_t token_pos) { 12866 intptr_t token_pos) {
12867 ASSERT(ctr.kind() == RawFunction::kConstructor); 12867 ASSERT(ctr.kind() == RawFunction::kConstructor);
12868 Function& closure = Function::Handle(Z);
12869 closure = current_class().LookupClosureFunction(token_pos);
12870 if (!closure.IsNull()) {
12871 ASSERT(closure.IsConstructorClosureFunction());
12872 return closure.raw();
12873 }
12874
12868 String& closure_name = String::Handle(Z, ctr.name()); 12875 String& closure_name = String::Handle(Z, ctr.name());
12869 closure_name = Symbols::FromConcat(Symbols::ConstructorClosurePrefix(), 12876 closure_name = Symbols::FromConcat(Symbols::ConstructorClosurePrefix(),
12870 closure_name); 12877 closure_name);
12878
12871 ParamList params; 12879 ParamList params;
12872 params.AddFinalParameter(token_pos, 12880 params.AddFinalParameter(token_pos,
12873 &Symbols::ClosureParameter(), 12881 &Symbols::ClosureParameter(),
12874 &Type::ZoneHandle(Z, Type::DynamicType())); 12882 &Type::ZoneHandle(Z, Type::DynamicType()));
12875 12883
12876 ParseFormalParameters(ctr, &params); 12884 ParseFormalParameters(ctr, &params);
12877 // Per language spec, the type of the closure parameters is dynamic. 12885 // Per language spec, the type of the closure parameters is dynamic.
12878 // Replace the types parsed from the constructor. 12886 // Replace the types parsed from the constructor.
12879 params.EraseParameterTypes(); 12887 params.EraseParameterTypes();
12880 12888
12881 Function& closure = Function::Handle(Z);
12882 closure = Function::NewClosureFunction(closure_name, 12889 closure = Function::NewClosureFunction(closure_name,
12883 innermost_function(), 12890 innermost_function(),
12884 token_pos); 12891 token_pos);
12885 closure.set_is_generated_body(true); 12892 closure.set_is_generated_body(true);
12893 closure.set_is_debuggable(false);
12886 closure.set_result_type(AbstractType::Handle(Type::DynamicType())); 12894 closure.set_result_type(AbstractType::Handle(Type::DynamicType()));
12887 AddFormalParamsToFunction(&params, closure); 12895 AddFormalParamsToFunction(&params, closure);
12888 12896
12889 // Create and set the signature class of the closure. 12897 // Create and set the signature class of the closure.
12890 const String& sig = String::Handle(Z, closure.Signature()); 12898 const String& sig = String::Handle(Z, closure.Signature());
12891 Class& sig_cls = Class::Handle(Z, library_.LookupLocalClass(sig)); 12899 Class& sig_cls = Class::Handle(Z, library_.LookupLocalClass(sig));
12892 if (sig_cls.IsNull()) { 12900 if (sig_cls.IsNull()) {
12893 sig_cls = Class::NewSignatureClass(sig, closure, script_, token_pos); 12901 sig_cls = Class::NewSignatureClass(sig, closure, script_, token_pos);
12894 library_.AddClass(sig_cls); 12902 library_.AddClass(sig_cls);
12895 } 12903 }
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after
14060 void Parser::SkipQualIdent() { 14068 void Parser::SkipQualIdent() {
14061 ASSERT(IsIdentifier()); 14069 ASSERT(IsIdentifier());
14062 ConsumeToken(); 14070 ConsumeToken();
14063 if (CurrentToken() == Token::kPERIOD) { 14071 if (CurrentToken() == Token::kPERIOD) {
14064 ConsumeToken(); // Consume the kPERIOD token. 14072 ConsumeToken(); // Consume the kPERIOD token.
14065 ExpectIdentifier("identifier expected after '.'"); 14073 ExpectIdentifier("identifier expected after '.'");
14066 } 14074 }
14067 } 14075 }
14068 14076
14069 } // namespace dart 14077 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698