Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: dart/lib/compiler/implementation/resolver.dart

Issue 10542073: RFC: Resolution based tree-shaking. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 interface TreeElements { 5 interface TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 Type getType(TypeAnnotation annotation); 8 Type getType(TypeAnnotation annotation);
9 } 9 }
10 10
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 return compiler.withCurrentElement(element, () { 116 return compiler.withCurrentElement(element, () {
117 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR; 117 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR;
118 if (constructorElements.containsKey(element)) { 118 if (constructorElements.containsKey(element)) {
119 assert(isConstructor); 119 assert(isConstructor);
120 TreeElements elements = constructorElements[element]; 120 TreeElements elements = constructorElements[element];
121 if (elements !== null) return elements; 121 if (elements !== null) return elements;
122 } 122 }
123 FunctionExpression tree = element.parseNode(compiler); 123 FunctionExpression tree = element.parseNode(compiler);
124 if (isConstructor) { 124 if (isConstructor) {
125 resolveConstructorImplementation(element, tree); 125 resolveConstructorImplementation(element, tree);
126 compiler.enqueuer.resolution.registerStaticUse(
127 element.defaultImplementation);
126 } 128 }
127 ResolverVisitor visitor = new ResolverVisitor(compiler, element); 129 ResolverVisitor visitor = new ResolverVisitor(compiler, element);
128 visitor.useElement(tree, element); 130 visitor.useElement(tree, element);
129 visitor.setupFunction(tree, element); 131 visitor.setupFunction(tree, element);
130 132
131 if (isConstructor) { 133 if (isConstructor) {
132 // Even if there is no initializer list we still have to do the 134 // Even if there is no initializer list we still have to do the
133 // resolution in case there is an implicit super constructor call. 135 // resolution in case there is an implicit super constructor call.
134 InitializerResolver resolver = new InitializerResolver(visitor); 136 InitializerResolver resolver = new InitializerResolver(visitor);
135 FunctionElement redirection = 137 FunctionElement redirection =
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 Element existing = context.add(element); 798 Element existing = context.add(element);
797 if (existing != element) { 799 if (existing != element) {
798 error(node, MessageKind.DUPLICATE_DEFINITION, [node]); 800 error(node, MessageKind.DUPLICATE_DEFINITION, [node]);
799 } 801 }
800 } 802 }
801 return element; 803 return element;
802 } 804 }
803 805
804 Element useElement(Node node, Element element) { 806 Element useElement(Node node, Element element) {
805 if (element === null) return null; 807 if (element === null) return null;
808 ElementKind kind = element.kind;
809 if (element.isTopLevel() || element.isMember()) {
810 int allowed = ElementCategory.VARIABLE | ElementCategory.FUNCTION
811 | ElementCategory.FACTORY;
812 if ((element.kind.category & allowed) != 0 || element.isAccessor()) {
813 if (element.isInstanceMember()) {
814 compiler.enqueuer.resolution.registerDynamicInvocationOf(element);
815 } else {
816 compiler.enqueuer.resolution.registerStaticUse(element);
817 }
818 }
819 }
806 return mapping[node] = element; 820 return mapping[node] = element;
807 } 821 }
808 822
809 Type useType(TypeAnnotation annotation, Type type) { 823 Type useType(TypeAnnotation annotation, Type type) {
810 if (type !== null) { 824 if (type !== null) {
811 mapping.setType(annotation, type); 825 mapping.setType(annotation, type);
812 useElement(annotation, type.element); 826 useElement(annotation, type.element);
813 } 827 }
814 return type; 828 return type;
815 } 829 }
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 if (target === compiler.assertMethod && !node.isCall) { 1071 if (target === compiler.assertMethod && !node.isCall) {
1058 // We can only use assert by calling it. 1072 // We can only use assert by calling it.
1059 if (!inInstanceContext) { 1073 if (!inInstanceContext) {
1060 error(node, MessageKind.MISSING_ARGUMENTS_TO_ASSERT, [node]); 1074 error(node, MessageKind.MISSING_ARGUMENTS_TO_ASSERT, [node]);
1061 } 1075 }
1062 target = null; 1076 target = null;
1063 } 1077 }
1064 // TODO(ngeoffray): Warn if target is null and the send is 1078 // TODO(ngeoffray): Warn if target is null and the send is
1065 // unqualified. 1079 // unqualified.
1066 useElement(node, target); 1080 useElement(node, target);
1081 if (target === null || target.isMember()) {
1082 Identifier id = node.selector.asIdentifier();
1083 if (id !== null) {
1084 compiler.enqueuer.resolution.registerDynamicInvocation(
1085 id.source,
1086 mapping.getSelector(node));
1087 }
1088 // target = new Interceptors(compiler).getStaticInterceptor(
1089 // node.selector.asIdentifier().source,
1090 // node.argumentCount());
1091 }
1092 if (target !== null &&
1093 target.kind !== ElementKind.VARIABLE &&
1094 target.kind !== ElementKind.CLASS) {
1095 if (target.isInstanceMember()) {
1096 compiler.enqueuer.resolution.registerDynamicInvocationOf(target);
1097 } else {
1098 compiler.enqueuer.resolution.registerStaticUse(target);
1099 }
1100 }
1067 if (node.isPropertyAccess) return target; 1101 if (node.isPropertyAccess) return target;
1068 } 1102 }
1069 1103
1070 visitSendSet(SendSet node) { 1104 visitSendSet(SendSet node) {
1071 Element target = resolveSend(node); 1105 Element target = resolveSend(node);
1072 Element setter = null; 1106 Element setter = null;
1073 Element getter = null; 1107 Element getter = null;
1074 if (target != null && target.kind == ElementKind.ABSTRACT_FIELD) { 1108 if (target != null && target.kind == ElementKind.ABSTRACT_FIELD) {
1075 AbstractFieldElement field = target; 1109 AbstractFieldElement field = target;
1076 setter = field.setter; 1110 setter = field.setter;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 1195
1162 FunctionElement constructor = resolveConstructor(node); 1196 FunctionElement constructor = resolveConstructor(node);
1163 handleArguments(node.send); 1197 handleArguments(node.send);
1164 if (constructor === null) return null; 1198 if (constructor === null) return null;
1165 // TODO(karlklose): handle optional arguments. 1199 // TODO(karlklose): handle optional arguments.
1166 if (node.send.argumentCount() != constructor.parameterCount(compiler)) { 1200 if (node.send.argumentCount() != constructor.parameterCount(compiler)) {
1167 // TODO(ngeoffray): resolution error with wrong number of 1201 // TODO(ngeoffray): resolution error with wrong number of
1168 // parameters. We cannot do this rigth now because of the 1202 // parameters. We cannot do this rigth now because of the
1169 // List constructor. 1203 // List constructor.
1170 } 1204 }
1205 compiler.enqueuer.resolution.registerStaticUse(constructor);
1171 useElement(node.send, constructor); 1206 useElement(node.send, constructor);
1172 return null; 1207 return null;
1173 } 1208 }
1174 1209
1175 TypeAnnotation getTypeAnnotationFromSend(Send send) { 1210 TypeAnnotation getTypeAnnotationFromSend(Send send) {
1176 if (send.selector.asTypeAnnotation() !== null) { 1211 if (send.selector.asTypeAnnotation() !== null) {
1177 return send.selector; 1212 return send.selector;
1178 } else if (send.selector.asSend() !== null) { 1213 } else if (send.selector.asSend() !== null) {
1179 Send selector = send.selector; 1214 Send selector = send.selector;
1180 if (selector.receiver.asTypeAnnotation() !== null) { 1215 if (selector.receiver.asTypeAnnotation() !== null) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 1260
1226 visitLiteralList(LiteralList node) { 1261 visitLiteralList(LiteralList node) {
1227 visit(node.elements); 1262 visit(node.elements);
1228 } 1263 }
1229 1264
1230 visitConditional(Conditional node) { 1265 visitConditional(Conditional node) {
1231 node.visitChildren(this); 1266 node.visitChildren(this);
1232 } 1267 }
1233 1268
1234 visitStringInterpolation(StringInterpolation node) { 1269 visitStringInterpolation(StringInterpolation node) {
1270 compiler.enqueuer.resolution.registerStaticUse(compiler.findHelper(
1271 const SourceString("S")));
1235 node.visitChildren(this); 1272 node.visitChildren(this);
1236 } 1273 }
1237 1274
1238 visitStringInterpolationPart(StringInterpolationPart node) { 1275 visitStringInterpolationPart(StringInterpolationPart node) {
1239 node.visitChildren(this); 1276 node.visitChildren(this);
1240 } 1277 }
1241 1278
1242 visitBreakStatement(BreakStatement node) { 1279 visitBreakStatement(BreakStatement node) {
1243 TargetElement target; 1280 TargetElement target;
1244 if (node.target === null) { 1281 if (node.target === null) {
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
2013 2050
2014 TopScope(LibraryElement library) : super(null, library); 2051 TopScope(LibraryElement library) : super(null, library);
2015 Element lookup(SourceString name) { 2052 Element lookup(SourceString name) {
2016 return library.find(name); 2053 return library.find(name);
2017 } 2054 }
2018 2055
2019 Element add(Element newElement) { 2056 Element add(Element newElement) {
2020 throw "Cannot add an element in the top scope"; 2057 throw "Cannot add an element in the top scope";
2021 } 2058 }
2022 } 2059 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698