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 class BailoutException { | 5 class BailoutException { |
| 6 final String reason; | 6 final String reason; |
| 7 | 7 |
| 8 const BailoutException(this.reason); | 8 const BailoutException(this.reason); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 void assembleProgram() { | 35 void assembleProgram() { |
| 36 resolvedElements.forEach((element, treeElements) { | 36 resolvedElements.forEach((element, treeElements) { |
| 37 unparseValidator.check(element); | 37 unparseValidator.check(element); |
| 38 }); | 38 }); |
| 39 | 39 |
| 40 // TODO(antonm): Eventually bailouts will be proper errors. | 40 // TODO(antonm): Eventually bailouts will be proper errors. |
| 41 void bailout(String reason) { | 41 void bailout(String reason) { |
| 42 throw new BailoutException(reason); | 42 throw new BailoutException(reason); |
| 43 } | 43 } |
| 44 | 44 |
| 45 /** | |
| 46 * Tells whether we should output given element. Corelib classes like | |
| 47 * Object should not be in the resulting code. | |
| 48 */ | |
| 49 bool shouldOutput(Element element) { | |
| 50 var compilationUnitUri = element.getCompilationUnit().script.uri; | |
| 51 if (compilationUnitUri !== null && compilationUnitUri.path !== null && | |
|
Anton Muhin
2012/07/09 18:31:26
I believe (but not 100% sure) that we have a refer
Roman
2012/07/10 03:20:29
Done.
Thanks! Indeed we have reference in compiler
| |
| 52 // TODO(smok): URI hacks, should we have a special 'core' flag for | |
| 53 // elements from corelib? | |
| 54 (compilationUnitUri.path.endsWith('/core.dart') | |
| 55 || compilationUnitUri.path.contains('/corelib/src/'))) { | |
| 56 return false; | |
| 57 } | |
| 58 return element.kind !== ElementKind.VOID; | |
| 59 } | |
| 60 | |
| 45 try { | 61 try { |
| 46 StringBuffer sb = new StringBuffer(); | 62 StringBuffer sb = new StringBuffer(); |
| 47 resolvedElements.forEach((element, treeElements) { | 63 resolvedElements.forEach((element, treeElements) { |
| 64 if (!shouldOutput(element)) { | |
|
Anton Muhin
2012/07/09 18:31:26
nit: single line.
Roman
2012/07/10 03:20:29
Done.
| |
| 65 return; | |
| 66 } | |
| 48 if (!element.isTopLevel()) { | 67 if (!element.isTopLevel()) { |
| 49 bailout('Cannot process non top-level $element'); | 68 bailout('Cannot process non top-level $element'); |
| 50 } | 69 } |
| 51 | 70 |
| 52 if (element.isField()) { | 71 if (element.isField()) { |
| 53 // Add modifiers first. | 72 // Add modifiers first. |
| 54 sb.add(element.modifiers.toString()); | 73 sb.add(element.modifiers.toString()); |
| 55 sb.add(' '); | 74 sb.add(' '); |
| 56 // Figure out type. | 75 // Figure out type. |
| 57 if (element is VariableElement) { | 76 if (element is VariableElement) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 74 compiler.assembledCode = ''' | 93 compiler.assembledCode = ''' |
| 75 main() { | 94 main() { |
| 76 final bailout_reason = "${e.reason}"; | 95 final bailout_reason = "${e.reason}"; |
| 77 } | 96 } |
| 78 '''; | 97 '''; |
| 79 } | 98 } |
| 80 } | 99 } |
| 81 | 100 |
| 82 log(String message) => compiler.log('[DartBackend] $message'); | 101 log(String message) => compiler.log('[DartBackend] $message'); |
| 83 } | 102 } |
| OLD | NEW |