Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 dynamic member stub. */ | 5 /** A dynamic member stub. */ |
| 6 class VarMember { | 6 class VarMember { |
| 7 final String name; | 7 final String name; |
| 8 bool isGenerated = false; | 8 bool isGenerated = false; |
| 9 | 9 |
| 10 VarMember(this.name); | 10 VarMember(this.name); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 return false; | 173 return false; |
| 174 } | 174 } |
| 175 | 175 |
| 176 // If we have the right number of parameters, or all defaults would be | 176 // If we have the right number of parameters, or all defaults would be |
| 177 // filled in as "undefined" anyway, we can just call the method directly. | 177 // filled in as "undefined" anyway, we can just call the method directly. |
| 178 for (int i = args.length; i < method.parameters.length; i++) { | 178 for (int i = args.length; i < method.parameters.length; i++) { |
| 179 if (method.parameters[i].value.code != 'null') { | 179 if (method.parameters[i].value.code != 'null') { |
| 180 return false; | 180 return false; |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 return method.namesInOrder(args); | 183 return method.namesInHomePositions(args); |
| 184 } else { | 184 } else { |
| 185 return false; | 185 return false; |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 /** | 190 /** |
| 191 * A special member with a mangled name that represents a dynamic call | 191 * A special member with a mangled name that represents a dynamic call |
| 192 * (i.e. a call with multiple valid targets). We generate this if we have | 192 * (i.e. a call with multiple valid targets). We generate this if we have |
| 193 * a dynamic call that needs different implementation methods for different | 193 * a dynamic call that needs different implementation methods for different |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 219 | 219 |
| 220 bool hasObjectType = false; | 220 bool hasObjectType = false; |
| 221 for (var member in members) { | 221 for (var member in members) { |
| 222 // Invoke the member with the stub args (this gives us the method body), | 222 // Invoke the member with the stub args (this gives us the method body), |
| 223 // then create the stub method. | 223 // then create the stub method. |
| 224 final type = member.declaringType; | 224 final type = member.declaringType; |
| 225 final target = new Value(type, 'this', node.span); | 225 final target = new Value(type, 'this', node.span); |
| 226 var result = member.invoke(context, node, target, args, isDynamic:true); | 226 var result = member.invoke(context, node, target, args, isDynamic:true); |
| 227 var stub = new VarMethodStub(name, member, args, 'return ' + result.code); | 227 var stub = new VarMethodStub(name, member, args, 'return ' + result.code); |
| 228 type.varStubs[stub.name] = stub; | 228 type.varStubs[stub.name] = stub; |
| 229 | |
| 230 if (type.isObject) hasObjectType = true; | 229 if (type.isObject) hasObjectType = true; |
| 231 } | 230 } |
| 232 | 231 |
| 233 // Create a noSuchMethod fallback on Object if needed. | 232 // Create a noSuchMethod fallback on Object if needed. |
| 234 // Some methods, like toString and == already have a fallback on Object. | 233 // Some methods, like toString and == already have a fallback on Object. |
| 235 if (!hasObjectType) { | 234 if (!hasObjectType) { |
| 236 final target = new Value(world.objectType, 'this', node.span); | 235 final target = new Value(world.objectType, 'this', node.span); |
| 237 var result = target.invokeNoSuchMethod(context, baseName, node, args); | 236 var result = target.invokeNoSuchMethod(context, baseName, node, args); |
| 238 var stub = new VarMethodStub(name, null, args, 'return ' + result.code); | 237 var stub = new VarMethodStub(name, null, args, 'return ' + result.code); |
| 239 world.objectType.varStubs[stub.name] = stub; | 238 world.objectType.varStubs[stub.name] = stub; |
| 240 } | 239 } |
| 241 } | 240 } |
| 242 | 241 |
| 243 // TODO(jmesserly): get rid of this as it's unused now | 242 // TODO(jmesserly): get rid of this as it's unused now |
| 244 void generate(CodeWriter code) {} | 243 void generate(CodeWriter code) {} |
| 245 } | 244 } |
| 246 | 245 |
| 247 String _getCallStubName(String name, Arguments args) { | 246 String _getCallStubName(String name, Arguments args) { |
| 247 // TODO: This code needs global knowledge to ensure the stub name does not | |
| 248 // collide with any other name. | |
|
Jennifer Messerly
2011/12/14 19:15:33
Some examples would be helpful--I'm not sure what
sra1
2011/12/14 22:04:32
Done.
| |
| 248 final nameBuilder = new StringBuffer('${name}\$${args.bareCount}'); | 249 final nameBuilder = new StringBuffer('${name}\$${args.bareCount}'); |
| 249 for (int i = args.bareCount; i < args.length; i++) { | 250 for (int i = args.bareCount; i < args.length; i++) { |
| 250 nameBuilder.add('\$').add(args.getName(i)); | 251 var name = args.getName(i); |
| 252 nameBuilder.add('\$'); | |
| 253 if (name.contains('\$')) { | |
| 254 // Disambiguate "a:b:" from "a$b:" | |
| 255 nameBuilder.add('${name.length}'); | |
|
Jennifer Messerly
2011/12/14 19:15:33
do you need length here, or would it be enough to
sra1
2011/12/14 22:04:32
I've kept the length. If you put '_' in there, ho
| |
| 256 } | |
| 257 nameBuilder.add(name); | |
| 251 } | 258 } |
| 252 return nameBuilder.toString(); | 259 return nameBuilder.toString(); |
| 253 } | 260 } |
| OLD | NEW |