OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Fletch 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library fletchc.fletch_context; | 5 library fletchc.fletch_context; |
6 | 6 |
7 import 'package:compiler/src/tree/tree.dart' show | 7 import 'package:compiler/src/tree/tree.dart' show |
8 Node; | 8 Node; |
9 | 9 |
10 import 'package:compiler/src/universe/universe.dart' show | |
11 Selector; | |
12 | |
13 import 'package:compiler/src/elements/elements.dart' show | 10 import 'package:compiler/src/elements/elements.dart' show |
14 ClassElement, | 11 ClassElement, |
15 Element, | 12 Element, |
16 FieldElement, | 13 FieldElement, |
17 FunctionElement, | 14 FunctionElement, |
18 FunctionSignature, | 15 FunctionSignature, |
19 LibraryElement, | 16 LibraryElement, |
20 ParameterElement; | 17 ParameterElement, |
18 Name; | |
21 | 19 |
22 import 'package:compiler/src/resolution/resolution.dart' show | 20 import 'package:compiler/src/resolution/tree_elements.dart' show |
23 TreeElements; | 21 TreeElements; |
24 | 22 |
23 import 'package:compiler/src/universe/selector.dart' show | |
24 Selector; | |
25 | |
25 import 'package:compiler/src/constants/expressions.dart' show | 26 import 'package:compiler/src/constants/expressions.dart' show |
26 ConstantExpression; | 27 ConstantExpression; |
27 | 28 |
28 import 'package:compiler/src/constants/values.dart' show | 29 import 'package:compiler/src/constants/values.dart' show |
29 ConstantValue, | 30 ConstantValue, |
30 ConstructedConstantValue, | 31 ConstructedConstantValue, |
31 FunctionConstantValue; | 32 FunctionConstantValue; |
32 | 33 |
33 import 'package:compiler/src/dart2jslib.dart' show | |
34 isPrivateName; | |
35 | |
36 import 'fletch_compiler_implementation.dart' show | 34 import 'fletch_compiler_implementation.dart' show |
37 FletchCompilerImplementation; | 35 FletchCompilerImplementation; |
38 | 36 |
39 export 'fletch_compiler_implementation.dart' show | 37 export 'fletch_compiler_implementation.dart' show |
40 FletchCompilerImplementation; | 38 FletchCompilerImplementation; |
41 | 39 |
42 import 'fletch_backend.dart' show | 40 import 'fletch_backend.dart' show |
43 FletchBackend; | 41 FletchBackend; |
44 | 42 |
45 export 'fletch_backend.dart' show | 43 export 'fletch_backend.dart' show |
(...skipping 21 matching lines...) Expand all Loading... | |
67 | 65 |
68 Map<String, FletchNativeDescriptor> nativeDescriptors; | 66 Map<String, FletchNativeDescriptor> nativeDescriptors; |
69 | 67 |
70 Set<String> names = new Set<String>(); | 68 Set<String> names = new Set<String>(); |
71 | 69 |
72 Map<FieldElement, int> staticIndices = <FieldElement, int>{}; | 70 Map<FieldElement, int> staticIndices = <FieldElement, int>{}; |
73 | 71 |
74 Map<LibraryElement, String> libraryTag = <LibraryElement, String>{}; | 72 Map<LibraryElement, String> libraryTag = <LibraryElement, String>{}; |
75 List<String> symbols = <String>[]; | 73 List<String> symbols = <String>[]; |
76 Map<String, int> symbolIds = <String, int>{}; | 74 Map<String, int> symbolIds = <String, int>{}; |
75 Map<Name, String> nameToSymbol = <Name, String>{}; | |
77 Map<Selector, String> selectorToSymbol = <Selector, String>{}; | 76 Map<Selector, String> selectorToSymbol = <Selector, String>{}; |
78 | 77 |
79 FletchContext(this.compiler); | 78 FletchContext(this.compiler); |
80 | 79 |
81 FletchBackend get backend => compiler.backend; | 80 FletchBackend get backend => compiler.backend; |
82 | 81 |
83 bool get enableBigint { | 82 bool get enableBigint { |
84 String enableBigintConstant = compiler.environment['fletch.enable-bigint']; | 83 String enableBigintConstant = compiler.environment['fletch.enable-bigint']; |
85 return enableBigintConstant != "false"; | 84 return enableBigintConstant != "false"; |
86 } | 85 } |
87 | 86 |
88 void setNames(Map<String, String> names) { | 87 void setNames(Map<String, String> names) { |
89 // Generate symbols of the values. | 88 // Generate symbols of the values. |
90 for (String name in names.values) { | 89 for (String name in names.values) { |
91 this.names.add(name); | 90 this.names.add(name); |
92 getSymbolId(name); | 91 getSymbolId(name); |
93 } | 92 } |
94 } | 93 } |
95 | 94 |
96 String mangleName(String name, LibraryElement library) { | 95 String mangleName(Name name) { |
97 if (!isPrivateName(name)) return name; | 96 if (!name.isPrivate) return name.text; |
98 if (library.isPlatformLibrary && names.contains(name)) return name; | 97 if (name.library.isPlatformLibrary && names.contains(name.text)) { |
99 return name + getLibraryTag(library); | 98 return name.text; |
99 } | |
100 return name.text + getLibraryTag(name.library); | |
100 } | 101 } |
101 | 102 |
102 String getLibraryTag(LibraryElement library) { | 103 String getLibraryTag(LibraryElement library) { |
103 return libraryTag.putIfAbsent(library, () { | 104 return libraryTag.putIfAbsent(library, () { |
104 // Give the core library the unique mangling of the empty string. That | 105 // Give the core library the unique mangling of the empty string. That |
105 // will make the VM able to create selector into core (used for e.g. | 106 // will make the VM able to create selector into core (used for e.g. |
106 // _noSuchMethodTrampoline). | 107 // _noSuchMethodTrampoline). |
107 if (library == compiler.coreLibrary) return ""; | 108 if (library == compiler.coreLibrary) return ""; |
108 return "%${libraryTag.length}"; | 109 return "%${libraryTag.length}"; |
109 }); | 110 }); |
110 } | 111 } |
111 | 112 |
112 int getStaticFieldIndex(FieldElement element, Element referrer) { | 113 int getStaticFieldIndex(FieldElement element, Element referrer) { |
113 return staticIndices.putIfAbsent(element, () => staticIndices.length); | 114 return staticIndices.putIfAbsent(element, () => staticIndices.length); |
114 } | 115 } |
115 | 116 |
116 String getSymbolFromSelector(Selector selector) { | 117 String getSymbolFromSelector(Selector selector) { |
117 return selectorToSymbol.putIfAbsent(selector, () { | 118 return selectorToSymbol.putIfAbsent(selector, () { |
118 StringBuffer buffer = new StringBuffer(); | 119 StringBuffer buffer = new StringBuffer(); |
119 buffer.write(mangleName(selector.name, selector.library)); | 120 buffer.write(mangleName(selector.memberName)); |
120 for (String namedArgument in selector.namedArguments) { | 121 for (String namedArgument in selector.namedArguments) { |
121 buffer.write(":"); | 122 buffer.write(":"); |
122 buffer.write(namedArgument); | 123 buffer.write(namedArgument); |
123 } | 124 } |
124 return buffer.toString(); | 125 return buffer.toString(); |
125 }); | 126 }); |
126 } | 127 } |
127 | 128 |
128 void writeNamedArguments(StringBuffer buffer, FunctionSignature signature) { | 129 void writeNamedArguments(StringBuffer buffer, FunctionSignature signature) { |
129 signature.orderedForEachParameter((ParameterElement parameter) { | 130 signature.orderedForEachParameter((ParameterElement parameter) { |
130 if (parameter.isNamed) { | 131 if (parameter.isNamed) { |
131 buffer.write(":"); | 132 buffer.write(":"); |
132 buffer.write(parameter.name); | 133 buffer.write(parameter.name); |
133 } | 134 } |
134 }); | 135 }); |
135 } | 136 } |
136 | 137 |
137 String getSymbolForFunction( | 138 String getSymbolForFunction( |
138 String name, | 139 String name, |
139 FunctionSignature signature, | 140 FunctionSignature signature, |
140 LibraryElement library) { | 141 LibraryElement library) { |
141 StringBuffer buffer = new StringBuffer(); | 142 StringBuffer buffer = new StringBuffer(); |
142 buffer.write(mangleName(name, library)); | 143 buffer.write(mangleName(new Name(name, library))); |
143 writeNamedArguments(buffer, signature); | 144 writeNamedArguments(buffer, signature); |
144 return buffer.toString(); | 145 return buffer.toString(); |
145 } | 146 } |
146 | 147 |
147 String getCallSymbol(FunctionSignature signature) { | 148 String getCallSymbol(FunctionSignature signature) { |
148 return getSymbolForFunction('call', signature, null); | 149 return getSymbolForFunction('call', signature, null); |
149 } | 150 } |
150 | 151 |
151 int getSymbolId(String symbol) { | 152 int getSymbolId(String symbol) { |
152 return symbolIds.putIfAbsent(symbol, () { | 153 return symbolIds.putIfAbsent(symbol, () { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 if (selector.isSetter) return SelectorKind.Setter; | 202 if (selector.isSetter) return SelectorKind.Setter; |
202 return SelectorKind.Method; | 203 return SelectorKind.Method; |
203 } | 204 } |
204 | 205 |
205 void registerConstructedConstantValue(ConstructedConstantValue value) { | 206 void registerConstructedConstantValue(ConstructedConstantValue value) { |
206 ClassElement classElement = value.type.element; | 207 ClassElement classElement = value.type.element; |
207 backend.registerClassElement(classElement); | 208 backend.registerClassElement(classElement); |
208 // TODO(ahe): This should not be required. Also, instantiate type, | 209 // TODO(ahe): This should not be required. Also, instantiate type, |
209 // not class. | 210 // not class. |
210 FletchRegistry registry = | 211 FletchRegistry registry = |
211 new FletchRegistry(compiler, classElement.resolvedAst.elements); | 212 new FletchRegistry(compiler, null); |
ahe
2015/11/17 16:44:09
Fits one line?
sigurdm
2015/11/19 14:33:47
Done.
| |
212 registry.registerInstantiatedClass(classElement); | 213 registry.registerInstantiatedClass(classElement); |
213 } | 214 } |
214 | 215 |
215 void registerFunctionConstantValue(FunctionConstantValue value) { | 216 void registerFunctionConstantValue(FunctionConstantValue value) { |
216 backend.markFunctionConstantAsUsed(value); | 217 backend.markFunctionConstantAsUsed(value); |
217 } | 218 } |
218 | 219 |
219 void markConstantUsed(ConstantValue constant) { | 220 void markConstantUsed(ConstantValue constant) { |
220 backend.systemBuilder.registerConstant(constant, this); | 221 backend.systemBuilder.registerConstant(constant, this); |
221 } | 222 } |
(...skipping 24 matching lines...) Expand all Loading... | |
246 // TODO(johnniwinther): Should be handled in resolution. | 247 // TODO(johnniwinther): Should be handled in resolution. |
247 ConstantExpression expression = | 248 ConstantExpression expression = |
248 compiler.resolver.constantCompiler.compileNode( | 249 compiler.resolver.constantCompiler.compileNode( |
249 node, elements, enforceConst: isConst); | 250 node, elements, enforceConst: isConst); |
250 return expression; | 251 return expression; |
251 } | 252 } |
252 | 253 |
253 ConstantValue getConstantValue(ConstantExpression expression) { | 254 ConstantValue getConstantValue(ConstantExpression expression) { |
254 return compiler.constants.getConstantValue(expression); | 255 return compiler.constants.getConstantValue(expression); |
255 } | 256 } |
257 | |
ahe
2015/11/17 16:44:09
Extra line.
sigurdm
2015/11/19 14:33:47
Done.
| |
256 } | 258 } |
OLD | NEW |