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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 return generator.generateMethod(work, graph); | 66 return generator.generateMethod(work, graph); |
67 } | 67 } |
68 | 68 |
69 void processNativeClasses(libraries) { | 69 void processNativeClasses(libraries) { |
70 native.processNativeClasses(emitter, libraries); | 70 native.processNativeClasses(emitter, libraries); |
71 } | 71 } |
72 | 72 |
73 void assembleProgram() => emitter.assembleProgram(); | 73 void assembleProgram() => emitter.assembleProgram(); |
74 } | 74 } |
75 | 75 |
76 class ReachabilityVisitor implements Visitor { | |
Anton Muhin
2012/05/23 16:58:13
I am planning to move this stuff into a separate f
Roman
2012/05/24 09:45:48
Any comments (dartdocs should I call them?) about
ahe
2012/05/24 10:07:05
Please do so.
Anton Muhin
2012/05/24 14:23:21
Done.
| |
77 visitBlock(Block node) {} | |
78 visitBreakStatement(BreakStatement node) {} | |
79 visitCascade(Cascade node) {} | |
80 visitCascadeReceiver(CascadeReceiver node) {} | |
81 visitCaseMatch(CaseMatch node) {} | |
82 visitCatchBlock(CatchBlock node) {} | |
83 visitClassNode(ClassNode node) { | |
84 internalError('should not reach ClassNode'); | |
85 } | |
86 visitConditional(Conditional node) {} | |
87 visitContinueStatement(ContinueStatement node) {} | |
88 visitDoWhile(DoWhile node) {} | |
89 visitEmptyStatement(EmptyStatement node) {} | |
90 visitExpressionStatement(ExpressionStatement node) {} | |
91 visitFor(For node) {} | |
92 visitForIn(ForIn node) {} | |
93 visitFunctionDeclaration(FunctionDeclaration node) {} | |
94 visitFunctionExpression(FunctionExpression node) { | |
95 // TODO(antonm): add a closure to working queue. | |
96 unimplemented('FunctionExpression is not supported'); | |
97 } | |
98 visitIdentifier(Identifier node) {} | |
99 visitIf(If node) {} | |
100 visitLabel(Label node) {} | |
101 visitLabeledStatement(LabeledStatement node) {} | |
102 visitLiteralBool(LiteralBool node) {} | |
103 visitLiteralDouble(LiteralDouble node) {} | |
104 visitLiteralInt(LiteralInt node) {} | |
105 visitLiteralList(LiteralList node) {} | |
106 visitLiteralMap(LiteralMap node) {} | |
107 visitLiteralMapEntry(LiteralMapEntry node) {} | |
108 visitLiteralNull(LiteralNull node) {} | |
109 visitLiteralString(LiteralString node) {} | |
110 visitModifiers(Modifiers node) {} | |
111 visitNamedArgument(NamedArgument node) {} | |
112 visitNewExpression(NewExpression node) { | |
113 // TODO(antonm): update set of instantiated classes. | |
114 unimplemented('NewExpression is not supported'); | |
115 } | |
116 visitNodeList(NodeList node) {} | |
117 visitOperator(Operator node) {} | |
118 visitParenthesizedExpression(ParenthesizedExpression node) {} | |
119 visitReturn(Return node) {} | |
120 visitScriptTag(ScriptTag node) {} | |
121 visitSend(Send node) { | |
122 // TODO(antonm): update working queue. | |
123 unimplemented('Send is not supported'); | |
124 } | |
125 visitSendSet(SendSet node) { | |
126 // TODO(antonm): update working queue. | |
127 unimplemented('SendSet is not supported'); | |
128 } | |
129 visitStringInterpolation(StringInterpolation node) {} | |
130 visitStringInterpolationPart(StringInterpolationPart node) {} | |
131 visitStringJuxtaposition(StringJuxtaposition node) {} | |
132 visitSwitchCase(SwitchCase node) {} | |
133 visitSwitchStatement(SwitchStatement node) {} | |
134 visitThrow(Throw node) {} | |
135 visitTryStatement(TryStatement node) {} | |
136 visitTypeAnnotation(TypeAnnotation node) {} | |
137 visitTypedef(Typedef node) {} | |
138 visitTypeVariable(TypeVariable node) {} | |
139 visitVariableDefinitions(VariableDefinitions node) {} | |
140 visitWhile(While node) {} | |
141 | |
142 unimplemented(String reason) { | |
143 throw new CompilerCancelledException('not implemented: $reason'); | |
144 } | |
145 | |
146 internalError(String reason) { | |
147 throw new CompilerCancelledException('internal error: $reason'); | |
148 } | |
149 } | |
150 | |
76 class DartBackend extends Backend { | 151 class DartBackend extends Backend { |
77 DartBackend(Compiler compiler) : super(compiler); | 152 final ReachabilityVisitor reachabilityVisitor; |
153 DartBackend(Compiler compiler) | |
154 : reachabilityVisitor = new ReachabilityVisitor(), | |
155 super(compiler); | |
156 | |
157 String codegen(WorkItem work) { | |
158 // Traverse AST to populate sets of reachable classes and functions. | |
159 FunctionExpression function = work.element.parseNode(compiler); | |
160 function.body.accept(new TraversingVisitor(reachabilityVisitor)); | |
161 } | |
162 | |
163 void processNativeClasses(libraries) {} | |
164 void assembleProgram() { | |
165 compiler.assembledCode = ''; | |
166 } | |
78 } | 167 } |
79 | 168 |
80 class Compiler implements DiagnosticListener { | 169 class Compiler implements DiagnosticListener { |
81 final Map<String, LibraryElement> libraries; | 170 final Map<String, LibraryElement> libraries; |
82 int nextFreeClassId = 0; | 171 int nextFreeClassId = 0; |
83 World world; | 172 World world; |
84 String assembledCode; | 173 String assembledCode; |
85 Namer namer; | 174 Namer namer; |
86 Types types; | 175 Types types; |
87 final bool enableTypeAssertions; | 176 final bool enableTypeAssertions; |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 // invariant that endOffset > beginOffset, but for EOF the | 685 // invariant that endOffset > beginOffset, but for EOF the |
597 // charoffset of the next token may be [beginOffset]. This can | 686 // charoffset of the next token may be [beginOffset]. This can |
598 // also happen for synthetized tokens that are produced during | 687 // also happen for synthetized tokens that are produced during |
599 // error handling. | 688 // error handling. |
600 final endOffset = | 689 final endOffset = |
601 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1); | 690 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1); |
602 assert(endOffset > beginOffset); | 691 assert(endOffset > beginOffset); |
603 return f(beginOffset, endOffset); | 692 return f(beginOffset, endOffset); |
604 } | 693 } |
605 } | 694 } |
OLD | NEW |