OLD | NEW |
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 /** | 5 /** |
6 * A function element that represents a closure call. The signature is copied | 6 * A function element that represents a closure call. The signature is copied |
7 * from the given element. | 7 * from the given element. |
8 */ | 8 */ |
9 class ClosureInvocationElement extends FunctionElement { | 9 class ClosureInvocationElement extends FunctionElement { |
10 ClosureInvocationElement(SourceString name, | 10 ClosureInvocationElement(SourceString name, |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 if (member.modifiers.isAbstract()) return; | 603 if (member.modifiers.isAbstract()) return; |
604 CodeBuffer codeBuffer = compiler.codegenWorld.generatedCode[member]; | 604 CodeBuffer codeBuffer = compiler.codegenWorld.generatedCode[member]; |
605 if (codeBuffer == null) return; | 605 if (codeBuffer == null) return; |
606 defineInstanceMember(namer.getName(member), codeBuffer); | 606 defineInstanceMember(namer.getName(member), codeBuffer); |
607 codeBuffer = compiler.codegenWorld.generatedBailoutCode[member]; | 607 codeBuffer = compiler.codegenWorld.generatedBailoutCode[member]; |
608 if (codeBuffer != null) { | 608 if (codeBuffer != null) { |
609 defineInstanceMember(namer.getBailoutName(member), codeBuffer); | 609 defineInstanceMember(namer.getBailoutName(member), codeBuffer); |
610 } | 610 } |
611 FunctionElement function = member; | 611 FunctionElement function = member; |
612 FunctionSignature parameters = function.computeSignature(compiler); | 612 FunctionSignature parameters = function.computeSignature(compiler); |
613 if (!parameters.optionalParameters.isEmpty()) { | 613 if (!parameters.optionalParameters.isEmpty) { |
614 addParameterStubs(member, defineInstanceMember); | 614 addParameterStubs(member, defineInstanceMember); |
615 } | 615 } |
616 } else if (!member.isField()) { | 616 } else if (!member.isField()) { |
617 compiler.internalError('unexpected kind: "${member.kind}"', | 617 compiler.internalError('unexpected kind: "${member.kind}"', |
618 element: member); | 618 element: member); |
619 } | 619 } |
620 emitExtraAccessors(member, defineInstanceMember); | 620 emitExtraAccessors(member, defineInstanceMember); |
621 } | 621 } |
622 | 622 |
623 /** | 623 /** |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 writeConstantToBuffer(initialValue, buffer); | 1174 writeConstantToBuffer(initialValue, buffer); |
1175 }); | 1175 }); |
1176 buffer.add(';\n'); | 1176 buffer.add(';\n'); |
1177 } | 1177 } |
1178 } | 1178 } |
1179 | 1179 |
1180 void emitLazilyInitializedStaticFields(CodeBuffer buffer) { | 1180 void emitLazilyInitializedStaticFields(CodeBuffer buffer) { |
1181 ConstantHandler handler = compiler.constantHandler; | 1181 ConstantHandler handler = compiler.constantHandler; |
1182 List<VariableElement> lazyFields = | 1182 List<VariableElement> lazyFields = |
1183 handler.getLazilyInitializedFieldsForEmission(); | 1183 handler.getLazilyInitializedFieldsForEmission(); |
1184 if (!lazyFields.isEmpty()) { | 1184 if (!lazyFields.isEmpty) { |
1185 needsLazyInitializer = true; | 1185 needsLazyInitializer = true; |
1186 for (VariableElement element in lazyFields) { | 1186 for (VariableElement element in lazyFields) { |
1187 assert(compiler.codegenWorld.generatedBailoutCode[element] == null); | 1187 assert(compiler.codegenWorld.generatedBailoutCode[element] == null); |
1188 StringBuffer code = compiler.codegenWorld.generatedCode[element]; | 1188 StringBuffer code = compiler.codegenWorld.generatedCode[element]; |
1189 assert(code != null); | 1189 assert(code != null); |
1190 // The code only computes the initial value. We build the lazy-check | 1190 // The code only computes the initial value. We build the lazy-check |
1191 // here: | 1191 // here: |
1192 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); | 1192 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); |
1193 // The name is used for error reporting. The 'initial' must be a | 1193 // The name is used for error reporting. The 'initial' must be a |
1194 // closure that constructs the initial value. | 1194 // closure that constructs the initial value. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 /** | 1243 /** |
1244 * Documentation wanted -- johnniwinther | 1244 * Documentation wanted -- johnniwinther |
1245 * | 1245 * |
1246 * Invariant: [member] must be a declaration element. | 1246 * Invariant: [member] must be a declaration element. |
1247 */ | 1247 */ |
1248 void emitExtraAccessors(Element member, | 1248 void emitExtraAccessors(Element member, |
1249 DefineMemberFunction defineInstanceMember) { | 1249 DefineMemberFunction defineInstanceMember) { |
1250 assert(invariant(member, member.isDeclaration)); | 1250 assert(invariant(member, member.isDeclaration)); |
1251 if (member.isGetter() || member.isField()) { | 1251 if (member.isGetter() || member.isField()) { |
1252 Set<Selector> selectors = compiler.codegenWorld.invokedNames[member.name]; | 1252 Set<Selector> selectors = compiler.codegenWorld.invokedNames[member.name]; |
1253 if (selectors != null && !selectors.isEmpty()) { | 1253 if (selectors != null && !selectors.isEmpty) { |
1254 emitCallStubForGetter(member, selectors, defineInstanceMember); | 1254 emitCallStubForGetter(member, selectors, defineInstanceMember); |
1255 } | 1255 } |
1256 } else if (member.isFunction()) { | 1256 } else if (member.isFunction()) { |
1257 if (compiler.codegenWorld.hasInvokedGetter(member, compiler)) { | 1257 if (compiler.codegenWorld.hasInvokedGetter(member, compiler)) { |
1258 emitDynamicFunctionGetter(member, defineInstanceMember); | 1258 emitDynamicFunctionGetter(member, defineInstanceMember); |
1259 } | 1259 } |
1260 } | 1260 } |
1261 } | 1261 } |
1262 | 1262 |
1263 void emitNoSuchMethodHandlers(DefineMemberFunction defineInstanceMember) { | 1263 void emitNoSuchMethodHandlers(DefineMemberFunction defineInstanceMember) { |
1264 // Do not generate no such method handlers if there is no class. | 1264 // Do not generate no such method handlers if there is no class. |
1265 if (compiler.codegenWorld.instantiatedClasses.isEmpty()) return; | 1265 if (compiler.codegenWorld.instantiatedClasses.isEmpty) return; |
1266 | 1266 |
1267 String noSuchMethodName = | 1267 String noSuchMethodName = |
1268 namer.publicInstanceMethodNameByArity(Compiler.NO_SUCH_METHOD, 2); | 1268 namer.publicInstanceMethodNameByArity(Compiler.NO_SUCH_METHOD, 2); |
1269 | 1269 |
1270 // Keep track of the JavaScript names we've already added so we | 1270 // Keep track of the JavaScript names we've already added so we |
1271 // do not introduce duplicates (bad for code size). | 1271 // do not introduce duplicates (bad for code size). |
1272 Set<String> addedJsNames = new Set<String>(); | 1272 Set<String> addedJsNames = new Set<String>(); |
1273 | 1273 |
1274 // Keep track of the noSuchMethod holders for each possible | 1274 // Keep track of the noSuchMethod holders for each possible |
1275 // receiver type. | 1275 // receiver type. |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 const String HOOKS_API_USAGE = """ | 1576 const String HOOKS_API_USAGE = """ |
1577 // Generated by dart2js, the Dart to JavaScript compiler. | 1577 // Generated by dart2js, the Dart to JavaScript compiler. |
1578 // The code supports the following hooks: | 1578 // The code supports the following hooks: |
1579 // dartPrint(message) - if this function is defined it is called | 1579 // dartPrint(message) - if this function is defined it is called |
1580 // instead of the Dart [print] method. | 1580 // instead of the Dart [print] method. |
1581 // dartMainRunner(main) - if this function is defined, the Dart [main] | 1581 // dartMainRunner(main) - if this function is defined, the Dart [main] |
1582 // method will not be invoked directly. | 1582 // method will not be invoked directly. |
1583 // Instead, a closure that will invoke [main] is | 1583 // Instead, a closure that will invoke [main] is |
1584 // passed to [dartMainRunner]. | 1584 // passed to [dartMainRunner]. |
1585 """; | 1585 """; |
OLD | NEW |