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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/container_builder.dart

Issue 1198293002: dart2js: Use an abstract Name class for names in the generated JavaScript ast. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix new emitter. Created 5 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 /// This class should morph into something that makes it easy to build 7 /// This class should morph into something that makes it easy to build
8 /// JavaScript representations of libraries, class-sides, and instance-sides. 8 /// JavaScript representations of libraries, class-sides, and instance-sides.
9 /// Initially, it is just a placeholder for code that is moved from 9 /// Initially, it is just a placeholder for code that is moved from
10 /// [CodeEmitterTask]. 10 /// [CodeEmitterTask].
11 class ContainerBuilder extends CodeEmitterHelper { 11 class ContainerBuilder extends CodeEmitterHelper {
12 12
13 void addMemberMethod(DartMethod method, ClassBuilder builder) { 13 void addMemberMethod(DartMethod method, ClassBuilder builder) {
14 MethodElement member = method.element; 14 MethodElement member = method.element;
15 String name = method.name; 15 jsAst.Name name = method.name;
16 FunctionSignature parameters = member.functionSignature; 16 FunctionSignature parameters = member.functionSignature;
17 jsAst.Expression code = method.code; 17 jsAst.Expression code = method.code;
18 bool needsStubs = method.parameterStubs.isNotEmpty; 18 bool needsStubs = method.parameterStubs.isNotEmpty;
19 bool canBeApplied = method.canBeApplied; 19 bool canBeApplied = method.canBeApplied;
20 bool canBeReflected = method.canBeReflected; 20 bool canBeReflected = method.canBeReflected;
21 bool canTearOff = method.needsTearOff; 21 bool canTearOff = method.needsTearOff;
22 String tearOffName = method.tearOffName; 22 jsAst.Name tearOffName = method.tearOffName;
23 bool isClosure = method is InstanceMethod && method.isClosure; 23 bool isClosure = method is InstanceMethod && method.isClosure;
24 String superAlias = method is InstanceMethod ? method.aliasName : null; 24 jsAst.Name superAlias = method is InstanceMethod ? method.aliasName : null;
25 bool hasSuperAlias = superAlias != null; 25 bool hasSuperAlias = superAlias != null;
26 jsAst.Expression memberTypeExpression = method.functionType; 26 jsAst.Expression memberTypeExpression = method.functionType;
27 27
28 bool needStructuredInfo = 28 bool needStructuredInfo =
29 canTearOff || canBeReflected || canBeApplied || hasSuperAlias; 29 canTearOff || canBeReflected || canBeApplied || hasSuperAlias;
30 30
31 emitter.interceptorEmitter.recordMangledNameOfMemberMethod(member, name); 31 emitter.interceptorEmitter.recordMangledNameOfMemberMethod(member, name);
32 32
33 if (!needStructuredInfo) { 33 if (!needStructuredInfo) {
34 compiler.dumpInfoTask.registerElementAst(member, 34 compiler.dumpInfoTask.registerElementAst(member,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // P. Unmangled name (if reflectable). 70 // P. Unmangled name (if reflectable).
71 // P+1. First metadata (if reflectable). 71 // P+1. First metadata (if reflectable).
72 // ... 72 // ...
73 // TODO(ahe): Consider one of the parameter counts can be replaced by the 73 // TODO(ahe): Consider one of the parameter counts can be replaced by the
74 // length property of the JavaScript function object. 74 // length property of the JavaScript function object.
75 75
76 List<jsAst.Expression> expressions = <jsAst.Expression>[]; 76 List<jsAst.Expression> expressions = <jsAst.Expression>[];
77 77
78 // Create the optional aliasing entry if this method is called via super. 78 // Create the optional aliasing entry if this method is called via super.
79 if (hasSuperAlias) { 79 if (hasSuperAlias) {
80 expressions.add(new jsAst.LiteralString('"${superAlias}"')); 80 expressions.add(js.quoteName(superAlias));
81 } 81 }
82 82
83 expressions.add(code); 83 expressions.add(code);
84 84
85 bool onlyNeedsSuperAlias = 85 bool onlyNeedsSuperAlias =
86 !(canTearOff || canBeReflected || canBeApplied || needsStubs); 86 !(canTearOff || canBeReflected || canBeApplied || needsStubs);
87 87
88 if (onlyNeedsSuperAlias) { 88 if (onlyNeedsSuperAlias) {
89 jsAst.ArrayInitializer arrayInit = 89 jsAst.ArrayInitializer arrayInit =
90 new jsAst.ArrayInitializer(expressions); 90 new jsAst.ArrayInitializer(expressions);
91 compiler.dumpInfoTask.registerElementAst(member, 91 compiler.dumpInfoTask.registerElementAst(member,
92 builder.addProperty(name, arrayInit)); 92 builder.addProperty(name, arrayInit));
93 return; 93 return;
94 } 94 }
95 95
96 String callSelectorString = 'null'; 96 jsAst.LiteralString callSelectorString;
97 if (method.callName != null) { 97 if (method.callName == null) {
98 callSelectorString = '"${method.callName}"'; 98 callSelectorString = new jsAst.LiteralString('null');
99 } else {
100 callSelectorString = js.quoteName(method.callName);
99 } 101 }
100 102
101 // On [requiredParameterCount], the lower bit is set if this method can be 103 // On [requiredParameterCount], the lower bit is set if this method can be
102 // called reflectively. 104 // called reflectively.
103 int requiredParameterCount = parameters.requiredParameterCount << 1; 105 int requiredParameterCount = parameters.requiredParameterCount << 1;
104 if (member.isAccessor) requiredParameterCount++; 106 if (member.isAccessor) requiredParameterCount++;
105 107
106 int optionalParameterCount = parameters.optionalParameterCount << 1; 108 int optionalParameterCount = parameters.optionalParameterCount << 1;
107 if (parameters.optionalParametersAreNamed) optionalParameterCount++; 109 if (parameters.optionalParametersAreNamed) optionalParameterCount++;
108 110
109 // TODO(sra): Don't use LiteralString for non-strings. 111 // TODO(sra): Don't use LiteralString for non-strings.
floitsch 2015/06/22 17:43:44 does this comment still apply?
herhut 2015/06/23 13:26:31 It did but to get rid of the TODO I have now repla
110 List tearOffInfo = [new jsAst.LiteralString(callSelectorString)]; 112 List tearOffInfo = [callSelectorString];
111 113
112 for (ParameterStubMethod stub in method.parameterStubs) { 114 for (ParameterStubMethod stub in method.parameterStubs) {
113 String invocationName = stub.name; 115 jsAst.Name invocationName = stub.name;
114 emitter.interceptorEmitter 116 emitter.interceptorEmitter
115 .recordMangledNameOfMemberMethod(member, invocationName); 117 .recordMangledNameOfMemberMethod(member, invocationName);
116 118
117 expressions.add(stub.code); 119 expressions.add(stub.code);
118 if (member.isInstanceMember) { 120 if (member.isInstanceMember) {
119 expressions.add(js.string(invocationName)); 121 expressions.add(js.quoteName(invocationName));
120 } 122 }
121 String callName = stub.callName; 123 jsAst.Name callName = stub.callName;
122 String callSelectorString = (callName == null) ? 'null' : '"$callName"'; 124 jsAst.Literal callSelectorString =
123 tearOffInfo.add(new jsAst.LiteralString(callSelectorString)); 125 (callName == null) ? new jsAst.LiteralNull() : js.quoteName(callName);
126 tearOffInfo.add(callSelectorString);
124 } 127 }
125 128
126 expressions 129 expressions
127 ..addAll(tearOffInfo) 130 ..addAll(tearOffInfo)
128 ..add((tearOffName == null || member.isAccessor) 131 ..add((tearOffName == null || member.isAccessor)
129 ? js("null") : js.string(tearOffName)) 132 ? js("null") : js.quoteName(tearOffName))
130 ..add(js.number(requiredParameterCount)) 133 ..add(js.number(requiredParameterCount))
131 ..add(js.number(optionalParameterCount)) 134 ..add(js.number(optionalParameterCount))
132 ..add(memberTypeExpression == null ? js("null") : memberTypeExpression) 135 ..add(memberTypeExpression == null ? js("null") : memberTypeExpression)
133 ..addAll(task.metadataCollector.reifyDefaultArguments(member)); 136 ..addAll(task.metadataCollector.reifyDefaultArguments(member));
134 137
135 if (canBeReflected || canBeApplied) { 138 if (canBeReflected || canBeApplied) {
136 parameters.forEachParameter((Element parameter) { 139 parameters.forEachParameter((Element parameter) {
137 expressions.add(task.metadataCollector.reifyName(parameter.name)); 140 expressions.add(task.metadataCollector.reifyName(parameter.name));
138 if (backend.mustRetainMetadata) { 141 if (backend.mustRetainMetadata) {
139 Iterable<jsAst.Expression> metadataIndices = 142 Iterable<jsAst.Expression> metadataIndices =
(...skipping 30 matching lines...) Expand all
170 jsAst.ArrayInitializer arrayInit = 173 jsAst.ArrayInitializer arrayInit =
171 new jsAst.ArrayInitializer(expressions.toList()); 174 new jsAst.ArrayInitializer(expressions.toList());
172 compiler.dumpInfoTask.registerElementAst(member, 175 compiler.dumpInfoTask.registerElementAst(member,
173 builder.addProperty(name, arrayInit)); 176 builder.addProperty(name, arrayInit));
174 } 177 }
175 178
176 void addMemberField(Field field, ClassBuilder builder) { 179 void addMemberField(Field field, ClassBuilder builder) {
177 // For now, do nothing. 180 // For now, do nothing.
178 } 181 }
179 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698