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 /** A formal parameter to a [Method]. */ | 5 /** A formal parameter to a [Method]. */ |
6 class Parameter { | 6 class Parameter { |
7 FormalNode definition; | 7 FormalNode definition; |
8 Member method; | 8 Member method; |
9 | 9 |
10 String name; | 10 String name; |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 var code = null; | 1141 var code = null; |
1142 if (args.length == 0) { | 1142 if (args.length == 0) { |
1143 if (name == ':negate') { | 1143 if (name == ':negate') { |
1144 code = '-${target.code}'; | 1144 code = '-${target.code}'; |
1145 } else if (name == ':bit_not') { | 1145 } else if (name == ':bit_not') { |
1146 code = '~${target.code}'; | 1146 code = '~${target.code}'; |
1147 } | 1147 } |
1148 } else if (args.length == 1 && args.values[0].type.isNum) { | 1148 } else if (args.length == 1 && args.values[0].type.isNum) { |
1149 if (name == ':truncdiv' || name == ':mod') { | 1149 if (name == ':truncdiv' || name == ':mod') { |
1150 world.gen.corejs.useOperator(name); | 1150 world.gen.corejs.useOperator(name); |
1151 code = '$jsname(${target.code}, ${argsCode[0]})'; | 1151 code = '\$$jsname(${target.code}, ${argsCode[0]})'; |
1152 } else { | 1152 } else { |
1153 var op = TokenKind.rawOperatorFromMethod(name); | 1153 var op = TokenKind.rawOperatorFromMethod(name); |
1154 code = '${target.code} $op ${argsCode[0]}'; | 1154 code = '${target.code} $op ${argsCode[0]}'; |
1155 } | 1155 } |
1156 } | 1156 } |
1157 if (code !== null) { | 1157 if (code !== null) { |
1158 return new Value(inferredResult, code, node.span); | 1158 return new Value(inferredResult, code, node.span); |
1159 } | 1159 } |
1160 } else if (target.type.isString) { | 1160 } else if (target.type.isString) { |
1161 if (name == ':index' && args.values[0].type.isNum) { | 1161 if (name == ':index' && args.values[0].type.isNum) { |
(...skipping 28 matching lines...) Expand all Loading... |
1190 if (argsCode[0] == 'null') { | 1190 if (argsCode[0] == 'null') { |
1191 return new Value(inferredResult, '${target.code} $op null', node.span); | 1191 return new Value(inferredResult, '${target.code} $op null', node.span); |
1192 } else if (target.type.isNum || target.type.isString) { | 1192 } else if (target.type.isNum || target.type.isString) { |
1193 // TODO(jimhug): Maybe check rhs. | 1193 // TODO(jimhug): Maybe check rhs. |
1194 return new Value(inferredResult, '${target.code} $op ${argsCode[0]}', | 1194 return new Value(inferredResult, '${target.code} $op ${argsCode[0]}', |
1195 node.span); | 1195 node.span); |
1196 } | 1196 } |
1197 world.gen.corejs.useOperator(name); | 1197 world.gen.corejs.useOperator(name); |
1198 // TODO(jimhug): Should be able to use faster path sometimes here! | 1198 // TODO(jimhug): Should be able to use faster path sometimes here! |
1199 return new Value(inferredResult, | 1199 return new Value(inferredResult, |
1200 '$jsname(${target.code}, ${argsCode[0]})', node.span); | 1200 '\$$jsname(${target.code}, ${argsCode[0]})', node.span); |
1201 } | 1201 } |
1202 | 1202 |
1203 if (isCallMethod) { | 1203 if (isCallMethod) { |
1204 declaringType.markUsed(); | 1204 declaringType.markUsed(); |
1205 return new Value(inferredResult, | 1205 return new Value(inferredResult, |
1206 '${target.code}(${Strings.join(argsCode, ", ")})', node.span); | 1206 '${target.code}(${Strings.join(argsCode, ", ")})', node.span); |
1207 } | 1207 } |
1208 | 1208 |
1209 // TODO(jimhug): Reconcile with MethodSet version - ideally just eliminate | 1209 // TODO(jimhug): Reconcile with MethodSet version - ideally just eliminate |
1210 if (name == ':index') { | 1210 if (name == ':index') { |
1211 world.gen.corejs.useIndex = true; | 1211 world.gen.corejs.useIndex = true; |
1212 } else if (name == ':setindex') { | 1212 } else if (name == ':setindex') { |
1213 world.gen.corejs.useSetIndex = true; | 1213 world.gen.corejs.useSetIndex = true; |
1214 } else { | 1214 } else { |
1215 world.gen.corejs.useOperator(name); | 1215 world.gen.corejs.useOperator(name); |
1216 var argsString = argsCode.length == 0 ? '' : ', ${argsCode[0]}'; | 1216 var argsString = argsCode.length == 0 ? '' : ', ${argsCode[0]}'; |
1217 return new Value(returnType, '$jsname(${target.code}${argsString})', | 1217 return new Value(returnType, '\$$jsname(${target.code}${argsString})', |
1218 node.span); | 1218 node.span); |
1219 } | 1219 } |
1220 | 1220 |
1221 // Fall back to normal method invocation. | 1221 // Fall back to normal method invocation. |
1222 var argsString = Strings.join(argsCode, ', '); | 1222 var argsString = Strings.join(argsCode, ', '); |
1223 return new Value(inferredResult, '${target.code}.$jsname($argsString)', | 1223 return new Value(inferredResult, '${target.code}.$jsname($argsString)', |
1224 node.span); | 1224 node.span); |
1225 } | 1225 } |
1226 | 1226 |
1227 resolve() { | 1227 resolve() { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 f(member); | 1387 f(member); |
1388 }); | 1388 }); |
1389 }); | 1389 }); |
1390 } | 1390 } |
1391 | 1391 |
1392 bool isEmpty() { | 1392 bool isEmpty() { |
1393 return factories.getValues() | 1393 return factories.getValues() |
1394 .every((Map constructors) => constructors.isEmpty()); | 1394 .every((Map constructors) => constructors.isEmpty()); |
1395 } | 1395 } |
1396 } | 1396 } |
OLD | NEW |