| 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 #library('universe'); | 5 #library('universe'); |
| 6 | 6 |
| 7 #import('../closure.dart'); | 7 #import('../closure.dart'); |
| 8 #import('../elements/elements.dart'); | 8 #import('../elements/elements.dart'); |
| 9 #import('../leg.dart'); | 9 #import('../leg.dart'); |
| 10 #import('../scanner/scannerlib.dart'); | 10 #import('../scanner/scannerlib.dart'); |
| 11 // For RuntimeTypeInformation. TODO(ngeoffray): remove this dependency. | 11 // For RuntimeTypeInformation. TODO(ngeoffray): remove this dependency. |
| 12 #import('../ssa/ssa.dart'); | 12 #import('../ssa/ssa.dart'); |
| 13 #import('../tree/tree.dart'); | 13 #import('../tree/tree.dart'); |
| 14 #import('../util/util.dart'); | 14 #import('../util/util.dart'); |
| 15 | 15 |
| 16 #source('function_set.dart'); | 16 #source('function_set.dart'); |
| 17 #source('partial_type_tree.dart'); | 17 #source('partial_type_tree.dart'); |
| 18 #source('selector_map.dart'); | 18 #source('selector_map.dart'); |
| 19 | 19 |
| 20 class Universe { | 20 class Universe { |
| 21 /** |
| 22 * Documentation wanted -- johnniwinther |
| 23 * |
| 24 * Invariant: Key elements are declaration elements. |
| 25 */ |
| 21 Map<Element, CodeBuffer> generatedCode; | 26 Map<Element, CodeBuffer> generatedCode; |
| 27 |
| 28 /** |
| 29 * Documentation wanted -- johnniwinther |
| 30 * |
| 31 * Invariant: Key elements are declaration elements. |
| 32 */ |
| 22 Map<Element, CodeBuffer> generatedBailoutCode; | 33 Map<Element, CodeBuffer> generatedBailoutCode; |
| 34 |
| 35 /** |
| 36 * Documentation wanted -- johnniwinther |
| 37 * |
| 38 * Invariant: Elements are declaration elements. |
| 39 */ |
| 23 final Set<ClassElement> instantiatedClasses; | 40 final Set<ClassElement> instantiatedClasses; |
| 41 |
| 42 /** |
| 43 * Documentation wanted -- johnniwinther |
| 44 * |
| 45 * Invariant: Elements are declaration elements. |
| 46 */ |
| 24 final Set<FunctionElement> staticFunctionsNeedingGetter; | 47 final Set<FunctionElement> staticFunctionsNeedingGetter; |
| 25 final Map<SourceString, Set<Selector>> invokedNames; | 48 final Map<SourceString, Set<Selector>> invokedNames; |
| 26 final Map<SourceString, Set<Selector>> invokedGetters; | 49 final Map<SourceString, Set<Selector>> invokedGetters; |
| 27 final Map<SourceString, Set<Selector>> invokedSetters; | 50 final Map<SourceString, Set<Selector>> invokedSetters; |
| 28 final Map<SourceString, Set<Selector>> fieldGetters; | 51 final Map<SourceString, Set<Selector>> fieldGetters; |
| 29 final Map<SourceString, Set<Selector>> fieldSetters; | 52 final Map<SourceString, Set<Selector>> fieldSetters; |
| 30 final Set<DartType> isChecks; | 53 final Set<DartType> isChecks; |
| 31 final RuntimeTypeInformation rti; | 54 final RuntimeTypeInformation rti; |
| 32 | 55 |
| 33 Universe() : generatedCode = new Map<Element, CodeBuffer>(), | 56 Universe() : generatedCode = new Map<Element, CodeBuffer>(), |
| 34 generatedBailoutCode = new Map<Element, CodeBuffer>(), | 57 generatedBailoutCode = new Map<Element, CodeBuffer>(), |
| 35 instantiatedClasses = new Set<ClassElement>(), | 58 instantiatedClasses = new Set<ClassElement>(), |
| 36 staticFunctionsNeedingGetter = new Set<FunctionElement>(), | 59 staticFunctionsNeedingGetter = new Set<FunctionElement>(), |
| 37 invokedNames = new Map<SourceString, Set<Selector>>(), | 60 invokedNames = new Map<SourceString, Set<Selector>>(), |
| 38 invokedGetters = new Map<SourceString, Set<Selector>>(), | 61 invokedGetters = new Map<SourceString, Set<Selector>>(), |
| 39 invokedSetters = new Map<SourceString, Set<Selector>>(), | 62 invokedSetters = new Map<SourceString, Set<Selector>>(), |
| 40 fieldGetters = new Map<SourceString, Set<Selector>>(), | 63 fieldGetters = new Map<SourceString, Set<Selector>>(), |
| 41 fieldSetters = new Map<SourceString, Set<Selector>>(), | 64 fieldSetters = new Map<SourceString, Set<Selector>>(), |
| 42 isChecks = new Set<DartType>(), | 65 isChecks = new Set<DartType>(), |
| 43 rti = new RuntimeTypeInformation(); | 66 rti = new RuntimeTypeInformation(); |
| 44 | 67 |
| 45 void addGeneratedCode(WorkItem work, CodeBuffer codeBuffer) { | 68 void addGeneratedCode(WorkItem work, CodeBuffer codeBuffer) { |
| 69 assert(invariant(work.element, work.element.isDeclaration)); |
| 46 generatedCode[work.element] = codeBuffer; | 70 generatedCode[work.element] = codeBuffer; |
| 47 } | 71 } |
| 48 | 72 |
| 49 void addBailoutCode(WorkItem work, CodeBuffer codeBuffer) { | 73 void addBailoutCode(WorkItem work, CodeBuffer codeBuffer) { |
| 74 assert(invariant(work.element, work.element.isDeclaration)); |
| 50 generatedBailoutCode[work.element] = codeBuffer; | 75 generatedBailoutCode[work.element] = codeBuffer; |
| 51 } | 76 } |
| 52 | 77 |
| 53 bool hasMatchingSelector(Set<Selector> selectors, | 78 bool hasMatchingSelector(Set<Selector> selectors, |
| 54 Element member, | 79 Element member, |
| 55 Compiler compiler) { | 80 Compiler compiler) { |
| 56 if (selectors === null) return false; | 81 if (selectors === null) return false; |
| 57 for (Selector selector in selectors) { | 82 for (Selector selector in selectors) { |
| 58 if (selector.applies(member, compiler)) return true; | 83 if (selector.applies(member, compiler)) return true; |
| 59 } | 84 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 } | 303 } |
| 279 | 304 |
| 280 // TODO(5074): Remove this method once we don't accept the | 305 // TODO(5074): Remove this method once we don't accept the |
| 281 // deprecated parameter specification. | 306 // deprecated parameter specification. |
| 282 bool addOptionalArgumentsToListDEPRECATED(Link<Node> arguments, | 307 bool addOptionalArgumentsToListDEPRECATED(Link<Node> arguments, |
| 283 List list, | 308 List list, |
| 284 FunctionElement element, | 309 FunctionElement element, |
| 285 compileArgument(Node argument), | 310 compileArgument(Node argument), |
| 286 compileConstant(Element element), | 311 compileConstant(Element element), |
| 287 Compiler compiler) { | 312 Compiler compiler) { |
| 313 assert(invariant(element, element.isImplementation)); |
| 288 // If there are named arguments, provide them in the order | 314 // If there are named arguments, provide them in the order |
| 289 // expected by the called function, which is the source order. | 315 // expected by the called function, which is the source order. |
| 290 FunctionSignature parameters = element.computeSignature(compiler); | 316 FunctionSignature parameters = element.computeSignature(compiler); |
| 291 | 317 |
| 292 // Visit positional arguments and add them to the list. | 318 // Visit positional arguments and add them to the list. |
| 293 for (int i = parameters.requiredParameterCount; | 319 for (int i = parameters.requiredParameterCount; |
| 294 i < positionalArgumentCount; | 320 i < positionalArgumentCount; |
| 295 arguments = arguments.tail, i++) { | 321 arguments = arguments.tail, i++) { |
| 296 list.add(compileArgument(arguments.head)); | 322 list.add(compileArgument(arguments.head)); |
| 297 } | 323 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 325 } else { | 351 } else { |
| 326 list.add(compileConstant(parameter)); | 352 list.add(compileConstant(parameter)); |
| 327 } | 353 } |
| 328 } | 354 } |
| 329 } | 355 } |
| 330 | 356 |
| 331 | 357 |
| 332 /** | 358 /** |
| 333 * Returns [:true:] if the selector and the [element] match; [:false:] | 359 * Returns [:true:] if the selector and the [element] match; [:false:] |
| 334 * otherwise. | 360 * otherwise. |
| 361 * |
| 362 * Invariant: [element] must be the implementation element. |
| 335 */ | 363 */ |
| 336 bool addArgumentsToList(Link<Node> arguments, | 364 bool addArgumentsToList(Link<Node> arguments, |
| 337 List list, | 365 List list, |
| 338 FunctionElement element, | 366 FunctionElement element, |
| 339 compileArgument(Node argument), | 367 compileArgument(Node argument), |
| 340 compileConstant(Element element), | 368 compileConstant(Element element), |
| 341 Compiler compiler) { | 369 Compiler compiler) { |
| 370 assert(invariant(element, element.isImplementation)); |
| 342 if (!this.applies(element, compiler)) return false; | 371 if (!this.applies(element, compiler)) return false; |
| 343 | 372 |
| 344 FunctionSignature parameters = element.computeSignature(compiler); | 373 FunctionSignature parameters = element.computeSignature(compiler); |
| 345 parameters.forEachRequiredParameter((element) { | 374 parameters.forEachRequiredParameter((element) { |
| 346 list.add(compileArgument(arguments.head)); | 375 list.add(compileArgument(arguments.head)); |
| 347 arguments = arguments.tail; | 376 arguments = arguments.tail; |
| 348 }); | 377 }); |
| 349 | 378 |
| 350 if (!parameters.optionalParametersAreNamed) { | 379 if (!parameters.optionalParametersAreNamed) { |
| 351 // TODO(5074): Remove this check once we don't accept the | 380 // TODO(5074): Remove this check once we don't accept the |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 | 525 |
| 497 if (!self.isInterface() && self.isSubclassOf(other)) { | 526 if (!self.isInterface() && self.isSubclassOf(other)) { |
| 498 // Resolve an invocation of [element.name] on [self]. If it | 527 // Resolve an invocation of [element.name] on [self]. If it |
| 499 // is found, this selector is a candidate. | 528 // is found, this selector is a candidate. |
| 500 return hasElementIn(self, element) && appliesUntyped(element, compiler); | 529 return hasElementIn(self, element) && appliesUntyped(element, compiler); |
| 501 } | 530 } |
| 502 | 531 |
| 503 return false; | 532 return false; |
| 504 } | 533 } |
| 505 } | 534 } |
| OLD | NEW |