| 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 class Universe { | 5 class Universe { |
| 6 final Element scope; | 6 final Element scope; |
| 7 | 7 |
| 8 Map<SourceString, Element> elements; | 8 Map<SourceString, Element> elements; |
| 9 Map<Element, String> generatedCode; | 9 Map<Element, String> generatedCode; |
| 10 Map<Element, String> generatedBailoutCode; | 10 Map<Element, String> generatedBailoutCode; |
| 11 final Set<ClassElement> instantiatedClasses; | 11 final Set<ClassElement> instantiatedClasses; |
| 12 // TODO(floitsch): we want more information than just the method name. For | 12 // TODO(floitsch): we want more information than just the method name. For |
| 13 // example the number of arguments, etc. | 13 // example the number of arguments, etc. |
| 14 final Map<SourceString, Set<int>> invokedNames; | 14 final Map<SourceString, Set<int>> invokedNames; |
| 15 final Set<SourceString> invokedGetters; | 15 final Set<SourceString> invokedGetters; |
| 16 final Set<SourceString> invokedSetters; | 16 final Set<SourceString> invokedSetters; |
| 17 | 17 |
| 18 Universe() : elements = {}, generatedCode = {}, generatedBailoutCode = {}, | 18 Universe() : elements = {}, generatedCode = {}, generatedBailoutCode = {}, |
| 19 instantiatedClasses = new Set<ClassElement>(), | 19 instantiatedClasses = new Set<ClassElement>(), |
| 20 invokedNames = new Map<SourceString, Set<int>>(), | 20 invokedNames = new Map<SourceString, Set<int>>(), |
| 21 invokedGetters = new Set<SourceString>(), | 21 invokedGetters = new Set<SourceString>(), |
| 22 invokedSetters = new Set<SourceString>(), | 22 invokedSetters = new Set<SourceString>(), |
| 23 scope = new Element(const SourceString('global scope'), | 23 scope = new Element(const SourceString('global scope'), |
| 24 null, null); | 24 null, null); |
| 25 | 25 |
| 26 Element find(SourceString name) { | 26 Element find(SourceString name) { |
| 27 return elements[name]; | 27 return elements[name]; |
| 28 } | 28 } |
| 29 | 29 |
| 30 void define(Element element) { | 30 void define(Element element, Compiler compiler) { |
| 31 assert(elements[element.name] == null); | 31 Element existing = elements.putIfAbsent(element.name, () => element); |
| 32 elements[element.name] = element; | 32 if (existing !== element) { |
| 33 compiler.cancel('duplicate definition', token: element.position()); |
| 34 compiler.cancel('existing definition', token: existing.position()); |
| 35 } |
| 33 } | 36 } |
| 34 | 37 |
| 35 void addGeneratedCode(WorkItem work, String code) { | 38 void addGeneratedCode(WorkItem work, String code) { |
| 36 if (work.isBailoutVersion()) { | 39 if (work.isBailoutVersion()) { |
| 37 generatedBailoutCode[work.element] = code; | 40 generatedBailoutCode[work.element] = code; |
| 38 } else { | 41 } else { |
| 39 generatedCode[work.element] = code; | 42 generatedCode[work.element] = code; |
| 40 } | 43 } |
| 41 } | 44 } |
| 42 } | 45 } |
| OLD | NEW |