| 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 class WorkItem { | 5 class WorkItem { |
| 6 final Element element; | 6 final Element element; |
| 7 TreeElements resolutionTree; | 7 TreeElements resolutionTree; |
| 8 bool allowSpeculativeOptimization = true; | 8 bool allowSpeculativeOptimization = true; |
| 9 List<HTypeGuard> guards = const <HTypeGuard>[]; | 9 List<HTypeGuard> guards = const <HTypeGuard>[]; |
| 10 | 10 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 HInstruction instruction, Element element]) { | 142 HInstruction instruction, Element element]) { |
| 143 SourceSpan span = const SourceSpan(null, null, null); | 143 SourceSpan span = const SourceSpan(null, null, null); |
| 144 if (node !== null) { | 144 if (node !== null) { |
| 145 span = spanFromNode(node); | 145 span = spanFromNode(node); |
| 146 } else if (token !== null) { | 146 } else if (token !== null) { |
| 147 span = spanFromTokens(token, token); | 147 span = spanFromTokens(token, token); |
| 148 } else if (instruction !== null) { | 148 } else if (instruction !== null) { |
| 149 span = spanFromElement(currentElement); | 149 span = spanFromElement(currentElement); |
| 150 } else if (element !== null) { | 150 } else if (element !== null) { |
| 151 span = spanFromElement(element); | 151 span = spanFromElement(element); |
| 152 } else { |
| 153 throw 'No error location for error: $reason'; |
| 152 } | 154 } |
| 153 reportDiagnostic(span, red(reason), true); | 155 reportDiagnostic(span, red(reason), true); |
| 154 throw new CompilerCancelledException(reason); | 156 throw new CompilerCancelledException(reason); |
| 155 } | 157 } |
| 156 | 158 |
| 159 void reportFatalError(String reason, Element element, |
| 160 [Node node, Token token, HInstruction instruction]) { |
| 161 withCurrentElement(element, () { |
| 162 cancel(reason, node, token, instruction, element); |
| 163 }); |
| 164 } |
| 165 |
| 157 void log(message) { | 166 void log(message) { |
| 158 reportDiagnostic(null, message, false); | 167 reportDiagnostic(null, message, false); |
| 159 } | 168 } |
| 160 | 169 |
| 161 bool run(Uri uri) { | 170 bool run(Uri uri) { |
| 162 try { | 171 try { |
| 163 runCompiler(uri); | 172 runCompiler(uri); |
| 164 } catch (CompilerCancelledException exception) { | 173 } catch (CompilerCancelledException exception) { |
| 165 log(exception.toString()); | 174 log(exception.toString()); |
| 166 log('compilation failed'); | 175 log('compilation failed'); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 const SourceString('JS_CALL_IN_ISOLATE'), library), this); | 275 const SourceString('JS_CALL_IN_ISOLATE'), library), this); |
| 267 library.define(new ForeignElement( | 276 library.define(new ForeignElement( |
| 268 const SourceString('DART_CLOSURE_TO_JS'), library), this); | 277 const SourceString('DART_CLOSURE_TO_JS'), library), this); |
| 269 } | 278 } |
| 270 | 279 |
| 271 void runCompiler(Uri uri) { | 280 void runCompiler(Uri uri) { |
| 272 scanBuiltinLibraries(); | 281 scanBuiltinLibraries(); |
| 273 mainApp = scanner.loadLibrary(uri, null); | 282 mainApp = scanner.loadLibrary(uri, null); |
| 274 final Element main = mainApp.find(MAIN); | 283 final Element main = mainApp.find(MAIN); |
| 275 if (main === null) { | 284 if (main === null) { |
| 276 withCurrentElement(mainApp, () => cancel('Could not find $MAIN')); | 285 reportFatalError('Could not find $MAIN', mainApp); |
| 277 } else { | 286 } else { |
| 278 withCurrentElement(main, () { | 287 if (!main.isFunction()) reportFatalError('main is not a function', main); |
| 279 if (!main.isFunction()) { | 288 FunctionElement mainMethod = main; |
| 280 cancel('main is not a function', element: main); | 289 FunctionSignature parameters = mainMethod.computeSignature(this); |
| 281 } | 290 parameters.forEachParameter((Element parameter) { |
| 282 FunctionElement mainMethod = main; | 291 reportFatalError('main cannot have parameters', parameter); |
| 283 FunctionSignature parameters = mainMethod.computeSignature(this); | |
| 284 if (parameters.parameterCount > 0) { | |
| 285 cancel('main cannot have parameters', element: mainMethod); | |
| 286 } | |
| 287 }); | 292 }); |
| 288 } | 293 } |
| 289 Collection<LibraryElement> libraries = universe.libraries.getValues(); | 294 Collection<LibraryElement> libraries = universe.libraries.getValues(); |
| 290 native.processNativeClasses(this, libraries); | 295 native.processNativeClasses(this, libraries); |
| 291 world.populate(this, libraries); | 296 world.populate(this, libraries); |
| 292 addToWorkList(main); | 297 addToWorkList(main); |
| 293 codegenProgress.reset(); | 298 codegenProgress.reset(); |
| 294 while (!codegenQueue.isEmpty()) { | 299 while (!codegenQueue.isEmpty()) { |
| 295 WorkItem work = codegenQueue.removeLast(); | 300 WorkItem work = codegenQueue.removeLast(); |
| 296 withCurrentElement(work.element, () => work.run(this)); | 301 withCurrentElement(work.element, () => work.run(this)); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 // error" or "not implemented yet", so the vicinity is good | 473 // error" or "not implemented yet", so the vicinity is good |
| 469 // enough for now. | 474 // enough for now. |
| 470 element = element.enclosingElement; | 475 element = element.enclosingElement; |
| 471 // TODO(ahe): I plan to overhaul this infrastructure anyways. | 476 // TODO(ahe): I plan to overhaul this infrastructure anyways. |
| 472 } | 477 } |
| 473 if (element === null) { | 478 if (element === null) { |
| 474 element = currentElement; | 479 element = currentElement; |
| 475 } | 480 } |
| 476 Token position = element.position(); | 481 Token position = element.position(); |
| 477 if (position === null) { | 482 if (position === null) { |
| 478 // TODO(ahe): Find the enclosing library. | 483 Uri uri = element.getCompilationUnit().script.uri; |
| 479 return const SourceSpan(null, null, null); | 484 return new SourceSpan(uri, 0, 0); |
| 480 } | 485 } |
| 481 return spanFromTokens(position, position); | 486 return spanFromTokens(position, position); |
| 482 } | 487 } |
| 483 | 488 |
| 484 Script readScript(Uri uri, [ScriptTag node]) { | 489 Script readScript(Uri uri, [ScriptTag node]) { |
| 485 unimplemented('Compiler.readScript'); | 490 unimplemented('Compiler.readScript'); |
| 486 } | 491 } |
| 487 | 492 |
| 488 String get legDirectory() { | 493 String get legDirectory() { |
| 489 unimplemented('Compiler.legDirectory'); | 494 unimplemented('Compiler.legDirectory'); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 } | 550 } |
| 546 } | 551 } |
| 547 | 552 |
| 548 class SourceSpan { | 553 class SourceSpan { |
| 549 final Uri uri; | 554 final Uri uri; |
| 550 final int begin; | 555 final int begin; |
| 551 final int end; | 556 final int end; |
| 552 | 557 |
| 553 const SourceSpan(this.uri, this.begin, this.end); | 558 const SourceSpan(this.uri, this.begin, this.end); |
| 554 } | 559 } |
| OLD | NEW |