Chromium Code Reviews| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
| 9 * compiled. | 9 * compiled. |
| 10 */ | 10 */ |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 void dumpInferredTypes() {} | 96 void dumpInferredTypes() {} |
| 97 | 97 |
| 98 ItemCompilationContext createItemCompilationContext() { | 98 ItemCompilationContext createItemCompilationContext() { |
| 99 return new ItemCompilationContext(); | 99 return new ItemCompilationContext(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 SourceString getCheckedModeHelper(DartType type) => null; | 102 SourceString getCheckedModeHelper(DartType type) => null; |
| 103 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) {} | 103 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) {} |
| 104 } | 104 } |
| 105 | 105 |
| 106 class CommentTokenMapEntry { | |
|
ahe
2013/01/03 13:04:09
Document class please. How about:
/// An entry in
| |
| 107 final key; | |
|
ahe
2013/01/03 13:04:09
Add types one these two fields please.
| |
| 108 final value; | |
| 109 | |
| 110 CommentTokenMapEntry(this.key, this.value); | |
| 111 } | |
| 112 | |
| 113 /** | |
| 114 * Map of tokens and the first associated comment. | |
|
ahe
2013/01/03 13:04:09
One line comment?
| |
| 115 */ | |
| 116 class CommentTokenMap { | |
| 117 Link<CommentTokenMapEntry> entries = const Link<CommentTokenMapEntry>(); | |
| 118 | |
| 119 Token operator[] (Token key) { | |
| 120 for (CommentTokenMapEntry entry in entries) { | |
|
ahe
2013/01/03 13:04:09
This seems like a sub-optimal implementation. I wo
| |
| 121 if (entry.key == key) { | |
| 122 return entry.value; | |
| 123 } | |
| 124 } | |
| 125 } | |
| 126 | |
| 127 void operator[]= (Token key, Token value) { | |
| 128 entries = entries.prepend(new CommentTokenMapEntry(key, value)); | |
| 129 } | |
| 130 } | |
| 131 | |
| 106 abstract class Compiler implements DiagnosticListener { | 132 abstract class Compiler implements DiagnosticListener { |
| 107 final Map<String, LibraryElement> libraries; | 133 final Map<String, LibraryElement> libraries; |
| 108 final Stopwatch totalCompileTime = new Stopwatch(); | 134 final Stopwatch totalCompileTime = new Stopwatch(); |
| 109 int nextFreeClassId = 0; | 135 int nextFreeClassId = 0; |
| 110 World world; | 136 World world; |
| 111 String assembledCode; | 137 String assembledCode; |
| 112 Types types; | 138 Types types; |
| 113 | 139 |
| 140 /** | |
| 141 * Map from token to the first preceeding comment token. | |
| 142 */ | |
| 143 final CommentTokenMap commentMap = new CommentTokenMap(); | |
| 144 | |
| 114 final bool enableMinification; | 145 final bool enableMinification; |
| 115 final bool enableTypeAssertions; | 146 final bool enableTypeAssertions; |
| 116 final bool enableUserAssertions; | 147 final bool enableUserAssertions; |
| 117 final bool enableConcreteTypeInference; | 148 final bool enableConcreteTypeInference; |
| 118 /** | 149 /** |
| 119 * The maximum size of a concrete type before it widens to dynamic during | 150 * The maximum size of a concrete type before it widens to dynamic during |
| 120 * concrete type inference. | 151 * concrete type inference. |
| 121 */ | 152 */ |
| 122 final int maxConcreteTypeSize; | 153 final int maxConcreteTypeSize; |
| 123 final bool analyzeAll; | 154 final bool analyzeAll; |
| 124 final bool enableNativeLiveTypeAnalysis; | 155 final bool enableNativeLiveTypeAnalysis; |
| 125 final bool rejectDeprecatedFeatures; | 156 final bool rejectDeprecatedFeatures; |
| 126 final bool checkDeprecationInSdk; | 157 final bool checkDeprecationInSdk; |
| 127 | 158 |
| 159 /** | |
| 160 * If [:true:], comment tokens are collected in [commentMap] during scanning. | |
| 161 */ | |
| 162 final bool preserveComments; | |
| 163 | |
| 128 bool disableInlining = false; | 164 bool disableInlining = false; |
| 129 | 165 |
| 130 final Tracer tracer; | 166 final Tracer tracer; |
| 131 | 167 |
| 132 CompilerTask measuredTask; | 168 CompilerTask measuredTask; |
| 133 Element _currentElement; | 169 Element _currentElement; |
| 134 LibraryElement coreLibrary; | 170 LibraryElement coreLibrary; |
| 135 LibraryElement isolateLibrary; | 171 LibraryElement isolateLibrary; |
| 136 LibraryElement isolateHelperLibrary; | 172 LibraryElement isolateHelperLibrary; |
| 137 LibraryElement jsHelperLibrary; | 173 LibraryElement jsHelperLibrary; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 this.enableConcreteTypeInference: false, | 276 this.enableConcreteTypeInference: false, |
| 241 this.maxConcreteTypeSize: 5, | 277 this.maxConcreteTypeSize: 5, |
| 242 this.enableMinification: false, | 278 this.enableMinification: false, |
| 243 this.enableNativeLiveTypeAnalysis: false, | 279 this.enableNativeLiveTypeAnalysis: false, |
| 244 bool emitJavaScript: true, | 280 bool emitJavaScript: true, |
| 245 bool generateSourceMap: true, | 281 bool generateSourceMap: true, |
| 246 bool disallowUnsafeEval: false, | 282 bool disallowUnsafeEval: false, |
| 247 this.analyzeAll: false, | 283 this.analyzeAll: false, |
| 248 this.rejectDeprecatedFeatures: false, | 284 this.rejectDeprecatedFeatures: false, |
| 249 this.checkDeprecationInSdk: false, | 285 this.checkDeprecationInSdk: false, |
| 286 this.preserveComments: false, | |
| 250 List<String> strips: const []}) | 287 List<String> strips: const []}) |
| 251 : libraries = new Map<String, LibraryElement>(), | 288 : libraries = new Map<String, LibraryElement>(), |
| 252 progress = new Stopwatch() { | 289 progress = new Stopwatch() { |
| 253 progress.start(); | 290 progress.start(); |
| 254 world = new World(this); | 291 world = new World(this); |
| 255 | 292 |
| 256 closureMapping.ClosureNamer closureNamer; | 293 closureMapping.ClosureNamer closureNamer; |
| 257 if (emitJavaScript) { | 294 if (emitJavaScript) { |
| 258 js_backend.JavaScriptBackend jsBackend = | 295 js_backend.JavaScriptBackend jsBackend = |
| 259 new js_backend.JavaScriptBackend(this, generateSourceMap, | 296 new js_backend.JavaScriptBackend(this, generateSourceMap, |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 891 } | 928 } |
| 892 | 929 |
| 893 // TODO(karlklose): split into findHelperFunction and findHelperClass and | 930 // TODO(karlklose): split into findHelperFunction and findHelperClass and |
| 894 // add a check that the element has the expected kind. | 931 // add a check that the element has the expected kind. |
| 895 Element findHelper(SourceString name) | 932 Element findHelper(SourceString name) |
| 896 => jsHelperLibrary.findLocal(name); | 933 => jsHelperLibrary.findLocal(name); |
| 897 Element findInterceptor(SourceString name) | 934 Element findInterceptor(SourceString name) |
| 898 => interceptorsLibrary.findLocal(name); | 935 => interceptorsLibrary.findLocal(name); |
| 899 | 936 |
| 900 bool get isMockCompilation => false; | 937 bool get isMockCompilation => false; |
| 938 | |
| 939 Token processAndStripComments(Token currentToken) { | |
| 940 Token firstToken = currentToken; | |
| 941 Token prevToken; | |
| 942 while (currentToken.kind != EOF_TOKEN) { | |
| 943 if (identical(currentToken.kind, COMMENT_TOKEN)) { | |
| 944 Token firstCommentToken = currentToken; | |
| 945 while (identical(currentToken.kind, COMMENT_TOKEN)) { | |
| 946 currentToken = currentToken.next; | |
| 947 } | |
| 948 commentMap[currentToken] = firstCommentToken; | |
| 949 if (prevToken == null) { | |
| 950 firstToken = currentToken; | |
| 951 } else { | |
| 952 prevToken.next = currentToken; | |
| 953 } | |
| 954 } | |
| 955 prevToken = currentToken; | |
| 956 currentToken = currentToken.next; | |
| 957 } | |
| 958 return firstToken; | |
| 959 } | |
| 901 } | 960 } |
| 902 | 961 |
| 903 class CompilerTask { | 962 class CompilerTask { |
| 904 final Compiler compiler; | 963 final Compiler compiler; |
| 905 final Stopwatch watch; | 964 final Stopwatch watch; |
| 906 | 965 |
| 907 CompilerTask(this.compiler) : watch = new Stopwatch(); | 966 CompilerTask(this.compiler) : watch = new Stopwatch(); |
| 908 | 967 |
| 909 String get name => 'Unknown task'; | 968 String get name => 'Unknown task'; |
| 910 int get timing => watch.elapsedMilliseconds; | 969 int get timing => watch.elapsedMilliseconds; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 987 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 1046 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
| 988 // information on assertion errors. | 1047 // information on assertion errors. |
| 989 if (condition is Function){ | 1048 if (condition is Function){ |
| 990 condition = condition(); | 1049 condition = condition(); |
| 991 } | 1050 } |
| 992 if (spannable == null || !condition) { | 1051 if (spannable == null || !condition) { |
| 993 throw new SpannableAssertionFailure(spannable, message); | 1052 throw new SpannableAssertionFailure(spannable, message); |
| 994 } | 1053 } |
| 995 return true; | 1054 return true; |
| 996 } | 1055 } |
| OLD | NEW |