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 dart_backend; | 5 part of dart_backend; |
6 | 6 |
7 class LocalPlaceholder { | 7 class LocalPlaceholder { |
8 final String identifier; | 8 final String identifier; |
9 final Set<Node> nodes; | 9 final Set<Node> nodes; |
10 LocalPlaceholder(this.identifier) : nodes = new Set<Node>(); | 10 LocalPlaceholder(this.identifier) : nodes = new Set<Node>(); |
(...skipping 27 matching lines...) Expand all Loading... |
38 class DeclarationTypePlaceholder { | 38 class DeclarationTypePlaceholder { |
39 final TypeAnnotation typeNode; | 39 final TypeAnnotation typeNode; |
40 final bool requiresVar; | 40 final bool requiresVar; |
41 DeclarationTypePlaceholder(this.typeNode, this.requiresVar); | 41 DeclarationTypePlaceholder(this.typeNode, this.requiresVar); |
42 } | 42 } |
43 | 43 |
44 class SendVisitor extends ResolvedVisitor { | 44 class SendVisitor extends ResolvedVisitor { |
45 final PlaceholderCollector collector; | 45 final PlaceholderCollector collector; |
46 | 46 |
47 get compiler => collector.compiler; | 47 get compiler => collector.compiler; |
48 DartBackend get backend => compiler.backend; | |
49 | 48 |
50 SendVisitor(this.collector, TreeElements elements) : super(elements); | 49 SendVisitor(this.collector, TreeElements elements) : super(elements); |
51 | 50 |
52 visitOperatorSend(Send node) { | 51 visitOperatorSend(Send node) { |
53 } | 52 } |
54 | 53 |
55 visitForeignSend(Send node) {} | 54 visitForeignSend(Send node) {} |
56 | 55 |
57 visitSuperSend(Send node) { | 56 visitSuperSend(Send node) { |
58 Element element = elements[node]; | 57 Element element = elements[node]; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 collector.tryMakeLocalPlaceholder(element, node.selector); | 99 collector.tryMakeLocalPlaceholder(element, node.selector); |
101 } else { | 100 } else { |
102 assert(node.selector is FunctionExpression); | 101 assert(node.selector is FunctionExpression); |
103 } | 102 } |
104 } | 103 } |
105 } | 104 } |
106 } | 105 } |
107 | 106 |
108 visitStaticSend(Send node) { | 107 visitStaticSend(Send node) { |
109 final element = elements[node]; | 108 final element = elements[node]; |
110 backend.registerStaticSend(element, node); | 109 collector.backend.registerStaticSend(element, node); |
111 | 110 |
112 if (Elements.isUnresolved(element) | 111 if (Elements.isUnresolved(element) |
113 || identical(element, compiler.assertMethod)) { | 112 || identical(element, compiler.assertMethod)) { |
114 return; | 113 return; |
115 } | 114 } |
116 if (element.isConstructor() || element.isFactoryConstructor()) { | 115 if (element.isConstructor() || element.isFactoryConstructor()) { |
117 // Rename named constructor in redirection position: | 116 // Rename named constructor in redirection position: |
118 // class C { C.named(); C.redirecting() : this.named(); } | 117 // class C { C.named(); C.redirecting() : this.named(); } |
119 if (node.receiver is Identifier | 118 if (node.receiver is Identifier |
120 && node.receiver.asIdentifier().isThis()) { | 119 && node.receiver.asIdentifier().isThis()) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 final List<DeclarationTypePlaceholder> declarationTypePlaceholders; | 153 final List<DeclarationTypePlaceholder> declarationTypePlaceholders; |
155 final Map<String, Set<Identifier>> memberPlaceholders; | 154 final Map<String, Set<Identifier>> memberPlaceholders; |
156 final Map<Element, List<ConstructorPlaceholder>> constructorPlaceholders; | 155 final Map<Element, List<ConstructorPlaceholder>> constructorPlaceholders; |
157 Map<String, LocalPlaceholder> currentLocalPlaceholders; | 156 Map<String, LocalPlaceholder> currentLocalPlaceholders; |
158 Element currentElement; | 157 Element currentElement; |
159 FunctionElement topmostEnclosingFunction; | 158 FunctionElement topmostEnclosingFunction; |
160 TreeElements treeElements; | 159 TreeElements treeElements; |
161 | 160 |
162 LibraryElement get coreLibrary => compiler.coreLibrary; | 161 LibraryElement get coreLibrary => compiler.coreLibrary; |
163 FunctionElement get entryFunction => compiler.mainApp.find(Compiler.MAIN); | 162 FunctionElement get entryFunction => compiler.mainApp.find(Compiler.MAIN); |
| 163 DartBackend get backend => compiler.backend; |
164 | 164 |
165 get currentFunctionScope => functionScopes.putIfAbsent( | 165 get currentFunctionScope => functionScopes.putIfAbsent( |
166 topmostEnclosingFunction, () => new FunctionScope()); | 166 topmostEnclosingFunction, () => new FunctionScope()); |
167 | 167 |
168 PlaceholderCollector(this.compiler, this.fixedMemberNames, this.elementAsts) : | 168 PlaceholderCollector(this.compiler, this.fixedMemberNames, this.elementAsts) : |
169 nullNodes = new Set<Node>(), | 169 nullNodes = new Set<Node>(), |
170 unresolvedNodes = new Set<Node>(), | 170 unresolvedNodes = new Set<Node>(), |
171 elementNodes = new Map<Element, Set<Node>>(), | 171 elementNodes = new Map<Element, Set<Node>>(), |
172 functionScopes = new Map<FunctionElement, FunctionScope>(), | 172 functionScopes = new Map<FunctionElement, FunctionScope>(), |
173 privateNodes = new Map<LibraryElement, Set<Identifier>>(), | 173 privateNodes = new Map<LibraryElement, Set<Identifier>>(), |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 498 |
499 visitVariableDefinitions(VariableDefinitions node) { | 499 visitVariableDefinitions(VariableDefinitions node) { |
500 // Collect only local placeholders. | 500 // Collect only local placeholders. |
501 for (Node definition in node.definitions.nodes) { | 501 for (Node definition in node.definitions.nodes) { |
502 Element definitionElement = treeElements[definition]; | 502 Element definitionElement = treeElements[definition]; |
503 // definitionElement may be null if we're inside variable definitions | 503 // definitionElement may be null if we're inside variable definitions |
504 // of a function that is a parameter of another function. | 504 // of a function that is a parameter of another function. |
505 // TODO(smok): Fix this when resolver correctly deals with | 505 // TODO(smok): Fix this when resolver correctly deals with |
506 // such cases. | 506 // such cases. |
507 if (definitionElement == null) continue; | 507 if (definitionElement == null) continue; |
| 508 if (definitionElement == backend.mirrorHelperSymbolsMap) { |
| 509 backend.registerMirrorHelperElement(definitionElement, node); |
| 510 } |
508 Send send = definition.asSend(); | 511 Send send = definition.asSend(); |
509 if (send != null) { | 512 if (send != null) { |
510 // May get FunctionExpression here in definition.selector | 513 // May get FunctionExpression here in definition.selector |
511 // in case of A(int this.f()); | 514 // in case of A(int this.f()); |
512 if (send.selector is Identifier) { | 515 if (send.selector is Identifier) { |
513 if (identical(definitionElement.kind, ElementKind.FIELD_PARAMETER)) { | 516 if (identical(definitionElement.kind, ElementKind.FIELD_PARAMETER)) { |
514 tryMakeMemberPlaceholder(send.selector); | 517 tryMakeMemberPlaceholder(send.selector); |
515 } else { | 518 } else { |
516 tryMakeLocalPlaceholder(definitionElement, send.selector); | 519 tryMakeLocalPlaceholder(definitionElement, send.selector); |
517 } | 520 } |
(...skipping 13 matching lines...) Expand all Loading... |
531 } | 534 } |
532 } | 535 } |
533 node.visitChildren(this); | 536 node.visitChildren(this); |
534 } | 537 } |
535 | 538 |
536 visitFunctionExpression(FunctionExpression node) { | 539 visitFunctionExpression(FunctionExpression node) { |
537 bool isKeyword(Identifier id) => | 540 bool isKeyword(Identifier id) => |
538 id != null && Keyword.keywords[id.source.slowToString()] != null; | 541 id != null && Keyword.keywords[id.source.slowToString()] != null; |
539 | 542 |
540 Element element = treeElements[node]; | 543 Element element = treeElements[node]; |
| 544 if (element == backend.mirrorHelperGetNameFunction) { |
| 545 backend.registerMirrorHelperElement(element, node); |
| 546 } |
541 // May get null here in case of A(int this.f()); | 547 // May get null here in case of A(int this.f()); |
542 if (element != null) { | 548 if (element != null) { |
543 // Rename only local functions. | 549 // Rename only local functions. |
544 if (topmostEnclosingFunction == null) { | 550 if (topmostEnclosingFunction == null) { |
545 topmostEnclosingFunction = element; | 551 topmostEnclosingFunction = element; |
546 } | 552 } |
547 if (!identical(element, currentElement)) { | 553 if (!identical(element, currentElement)) { |
548 if (node.name != null) { | 554 if (node.name != null) { |
549 assert(node.name is Identifier); | 555 assert(node.name is Identifier); |
550 tryMakeLocalPlaceholder(element, node.name); | 556 tryMakeLocalPlaceholder(element, node.name); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 | 624 |
619 visitBlock(Block node) { | 625 visitBlock(Block node) { |
620 for (Node statement in node.statements.nodes) { | 626 for (Node statement in node.statements.nodes) { |
621 if (statement is VariableDefinitions) { | 627 if (statement is VariableDefinitions) { |
622 makeVarDeclarationTypePlaceholder(statement); | 628 makeVarDeclarationTypePlaceholder(statement); |
623 } | 629 } |
624 } | 630 } |
625 node.visitChildren(this); | 631 node.visitChildren(this); |
626 } | 632 } |
627 } | 633 } |
OLD | NEW |