Chromium Code Reviews| Index: lib/compiler/implementation/compiler.dart |
| diff --git a/lib/compiler/implementation/compiler.dart b/lib/compiler/implementation/compiler.dart |
| index 110d9d70608650a030bc9aa81822086d5f6a87b8..3ade4be683f686366192482aff80cce29607c9a3 100644 |
| --- a/lib/compiler/implementation/compiler.dart |
| +++ b/lib/compiler/implementation/compiler.dart |
| @@ -34,8 +34,12 @@ class WorkItem { |
| class Backend { |
| final Compiler compiler; |
| + final Map<Element, Map<SourceString, HType>> fieldInitializers; |
|
karlklose
2012/06/19 15:07:40
Why not move these datastructures to the JavaScrip
|
| + final Map<Element, Map<SourceString, bool>> fieldIntegerSetters; |
| - Backend(this.compiler); |
| + Backend(this.compiler) |
| + : fieldInitializers = new Map<Element, Map<SourceString, HType>>(), |
| + fieldIntegerSetters = new Map<Element, Map<SourceString, bool>>(); |
| void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) { |
| lib.forEachExport((Element e) { |
| @@ -49,6 +53,70 @@ class Backend { |
| Collection<LibraryElement> libraries); |
| abstract void assembleProgram(); |
| abstract List<CompilerTask> get tasks(); |
| + |
| + void updateFieldInitializers(Type type, |
| + SourceString name, |
| + HType propagatedType) { |
| + Map<SourceString, HType> fields = |
| + fieldInitializers.putIfAbsent( |
| + type.element, () => new Map<SourceString, HType>()); |
| + if (!fields.containsKey(name)) { |
| + fields[name] = propagatedType; |
| + } else { |
| + if (fields[name] != propagatedType) fields[name] = HType.UNKNOWN; |
| + } |
| + } |
| + |
| + bool couldHaveFieldSingleTypeInitializers(Type type, |
| + SourceString name, |
| + HType requestedType) { |
| + if (type == null) return false; |
| + // If there is no information on the initializer it might still be |
| + // initialized to integers only. |
| + if (!fieldInitializers.containsKey(type.element)) return true; |
| + Map<SourceString, HType> fields = fieldInitializers[type.element]; |
| + HType propagatedType = fields[name]; |
| + if (propagatedType == null) return true; |
| + return propagatedType == requestedType; |
| + } |
| + |
| + bool hasFieldSingleTypeInitializers(Type type, |
| + SourceString name, |
| + HType requestedType) { |
| + if (type == null) return false; |
| + if (!fieldInitializers.containsKey(type.element)) return false; |
| + Map<SourceString, HType> fields = fieldInitializers[type.element]; |
| + HType propagatedType = fields[name]; |
| + if (propagatedType == null) return false; |
| + return propagatedType == requestedType; |
| + } |
| + |
| + void updateFieldIntegerSetters(Type type, SourceString name, bool isInteger) { |
| + Map<SourceString, bool> fields = |
| + fieldIntegerSetters.putIfAbsent( |
| + type.element, () => new Map<SourceString, bool>()); |
| + if (!fields.containsKey(name)) { |
| + fields[name] = isInteger; |
| + } else { |
| + fields[name] = fields[name] && isInteger; |
| + } |
| + } |
| + |
| + bool couldHaveFieldOnlyIntegerSetters(Type type, SourceString name) { |
| + if (type == null) return false; |
| + if (!fieldIntegerSetters.containsKey(type.element)) return true; |
| + Map<SourceString, bool> fields = fieldIntegerSetters[type.element]; |
| + if (!fields.containsKey(name)) return false; |
| + return fields[name]; |
| + } |
| + |
| + bool hasFieldOnlyIntegerSetters(Type type, SourceString name) { |
| + if (type == null) return false; |
| + if (!fieldIntegerSetters.containsKey(type.element)) return true; |
| + Map<SourceString, bool> fields = fieldIntegerSetters[type.element]; |
| + if (!fields.containsKey(name)) return false; |
| + return fields[name]; |
| + } |
| } |
| class JavaScriptBackend extends Backend { |