| 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 /** | 5 class DartBackend extends Backend { |
| 6 * Visitor to gather conservative estimate of functions which | 6 final List<CompilerTask> tasks; |
| 7 * can be invoked and classes which can be instantiated. | 7 final UnparseValidator unparseValidator; |
| 8 */ | |
| 9 class ReachabilityVisitor implements Visitor { | |
| 10 final Compiler compiler; | |
| 11 final TreeElements elements; | |
| 12 | 8 |
| 13 ResolverTask get resolver() => compiler.resolver; | 9 Map<Element, TreeElements> get resolvedElements() => |
| 14 Enqueuer get world() => compiler.enqueuer.codegen; | 10 compiler.enqueuer.resolution.resolvedElements; |
| 15 | 11 |
| 16 ReachabilityVisitor(this.compiler, this.elements); | 12 DartBackend(Compiler compiler, [bool validateUnparse = false]) |
| 17 | 13 : tasks = <CompilerTask>[], |
| 18 visitBlock(Block node) {} | 14 unparseValidator = new UnparseValidator(compiler, validateUnparse), |
| 19 visitBreakStatement(BreakStatement node) {} | 15 super(compiler) { |
| 20 visitCascade(Cascade node) {} | 16 tasks.add(unparseValidator); |
| 21 visitCascadeReceiver(CascadeReceiver node) {} | |
| 22 visitCaseMatch(CaseMatch node) {} | |
| 23 visitCatchBlock(CatchBlock node) {} | |
| 24 visitClassNode(ClassNode node) { | |
| 25 internalError('should not reach ClassNode'); | |
| 26 } | 17 } |
| 27 visitConditional(Conditional node) {} | |
| 28 visitContinueStatement(ContinueStatement node) {} | |
| 29 visitDoWhile(DoWhile node) {} | |
| 30 visitEmptyStatement(EmptyStatement node) {} | |
| 31 visitExpressionStatement(ExpressionStatement node) {} | |
| 32 visitFor(For node) {} | |
| 33 visitForIn(ForIn node) {} | |
| 34 visitFunctionDeclaration(FunctionDeclaration node) {} | |
| 35 visitFunctionExpression(FunctionExpression node) { | |
| 36 // TODO(antonm): add a closure to working queue. | |
| 37 unimplemented('FunctionExpression is not supported'); | |
| 38 } | |
| 39 visitIdentifier(Identifier node) {} | |
| 40 visitIf(If node) {} | |
| 41 visitLabel(Label node) {} | |
| 42 visitLabeledStatement(LabeledStatement node) {} | |
| 43 visitLiteralBool(LiteralBool node) {} | |
| 44 visitLiteralDouble(LiteralDouble node) {} | |
| 45 visitLiteralInt(LiteralInt node) {} | |
| 46 visitLiteralList(LiteralList node) {} | |
| 47 visitLiteralMap(LiteralMap node) {} | |
| 48 visitLiteralMapEntry(LiteralMapEntry node) {} | |
| 49 visitLiteralNull(LiteralNull node) {} | |
| 50 visitLiteralString(LiteralString node) {} | |
| 51 visitModifiers(Modifiers node) {} | |
| 52 visitNamedArgument(NamedArgument node) {} | |
| 53 visitNodeList(NodeList node) {} | |
| 54 visitOperator(Operator node) {} | |
| 55 visitParenthesizedExpression(ParenthesizedExpression node) {} | |
| 56 visitReturn(Return node) {} | |
| 57 visitScriptTag(ScriptTag node) {} | |
| 58 visitSend(Send node) { | |
| 59 // TODO(antonm): update working queue. | |
| 60 unimplemented('Send is not supported'); | |
| 61 } | |
| 62 visitSendSet(SendSet node) { | |
| 63 // TODO(antonm): update working queue. | |
| 64 unimplemented('SendSet is not supported'); | |
| 65 } | |
| 66 visitStringInterpolation(StringInterpolation node) {} | |
| 67 visitStringInterpolationPart(StringInterpolationPart node) {} | |
| 68 visitStringJuxtaposition(StringJuxtaposition node) {} | |
| 69 visitSwitchCase(SwitchCase node) {} | |
| 70 visitSwitchStatement(SwitchStatement node) {} | |
| 71 visitThrow(Throw node) {} | |
| 72 visitTryStatement(TryStatement node) {} | |
| 73 visitTypeAnnotation(TypeAnnotation node) {} | |
| 74 visitTypedef(Typedef node) {} | |
| 75 visitTypeVariable(TypeVariable node) {} | |
| 76 visitVariableDefinitions(VariableDefinitions node) {} | |
| 77 visitWhile(While node) {} | |
| 78 | |
| 79 visitNewExpression(NewExpression node) { | |
| 80 FunctionElement constructor = elements[node.send]; | |
| 81 resolver.resolveMethodElement(constructor); | |
| 82 world.registerStaticUse(constructor.defaultImplementation); | |
| 83 } | |
| 84 | |
| 85 unimplemented(String reason) { | |
| 86 throw new CompilerCancelledException('not implemented: $reason'); | |
| 87 } | |
| 88 | |
| 89 internalError(String reason) { | |
| 90 throw new CompilerCancelledException('internal error: $reason'); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 class DartBackend extends Backend { | |
| 95 final List<CompilerTask> tasks = const <CompilerTask>[]; | |
| 96 | |
| 97 DartBackend(Compiler compiler) : super(compiler); | |
| 98 | 18 |
| 99 void enqueueHelpers(Enqueuer world) { | 19 void enqueueHelpers(Enqueuer world) { |
| 100 // TODO(antonm): Implement this method, if needed. | 20 // TODO(antonm): Implement this method, if needed. |
| 101 } | 21 } |
| 102 | 22 |
| 103 String codegen(WorkItem work) { | 23 String codegen(WorkItem work) { } |
| 104 // Traverse AST to populate sets of reachable classes and functions. | |
| 105 log('codegen(${work.element})'); | |
| 106 FunctionExpression function = work.element.parseNode(compiler); | |
| 107 function.body.accept(new TraversingVisitor( | |
| 108 new ReachabilityVisitor(compiler, work.resolutionTree))); | |
| 109 } | |
| 110 | 24 |
| 111 void processNativeClasses(Enqueuer world, | 25 void processNativeClasses(Enqueuer world, |
| 112 Collection<LibraryElement> libraries) { | 26 Collection<LibraryElement> libraries) { |
| 113 } | 27 } |
| 114 | 28 |
| 115 void assembleProgram() { | 29 void assembleProgram() { |
| 30 resolvedElements.forEach((element, treeElements) { |
| 31 unparseValidator.check(element); |
| 32 }); |
| 116 compiler.assembledCode = ''; | 33 compiler.assembledCode = ''; |
| 117 } | 34 } |
| 118 | 35 |
| 119 log(String message) => compiler.log('[DartBackend] $message'); | 36 log(String message) => compiler.log('[DartBackend] $message'); |
| 120 } | 37 } |
| OLD | NEW |