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

Side by Side Diff: dart/frog/leg/resolver.dart

Issue 9646030: Find diagnostic locations for use in new compiler API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 8 years, 9 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
« no previous file with comments | « dart/frog/leg/frog_leg.dart ('k') | dart/frog/leg/ssa/builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 } 8 }
9 9
10 class TreeElementMapping implements TreeElements { 10 class TreeElementMapping implements TreeElements {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 return node.selector.asIdentifier().source; 63 return node.selector.asIdentifier().source;
64 } else { 64 } else {
65 return const SourceString(''); 65 return const SourceString('');
66 } 66 }
67 } 67 }
68 68
69 FunctionElement lookupConstructor(ClassElement classElement, Send send, 69 FunctionElement lookupConstructor(ClassElement classElement, Send send,
70 [noConstructor(Element)]) { 70 [noConstructor(Element)]) {
71 final SourceString constructorName = getConstructorName(send); 71 final SourceString constructorName = getConstructorName(send);
72 final SourceString className = classElement.name; 72 final SourceString className = classElement.name;
73 FunctionElement result = classElement.lookupConstructor(className, 73 return classElement.lookupConstructor(className,
74 constructorName, 74 constructorName,
75 noConstructor); 75 noConstructor);
76 if (result === null && send.arguments.isEmpty()) {
77 result = classElement.getSynthesizedConstructor();
78 }
79 return result;
80 } 76 }
81 77
82 FunctionElement resolveConstructorRedirection(FunctionElement constructor) { 78 FunctionElement resolveConstructorRedirection(FunctionElement constructor) {
83 FunctionExpression node = constructor.parseNode(compiler); 79 FunctionExpression node = constructor.parseNode(compiler);
84 // A synthetic constructor does not have a node. 80 // A synthetic constructor does not have a node.
85 if (node === null) return null; 81 if (node === null) return null;
86 if (node.initializers === null) return null; 82 if (node.initializers === null) return null;
87 Link<Node> initializers = node.initializers.nodes; 83 Link<Node> initializers = node.initializers.nodes;
88 if (!initializers.isEmpty() && 84 if (!initializers.isEmpty() &&
89 Initializers.isConstructorRedirect(initializers.head)) { 85 Initializers.isConstructorRedirect(initializers.head)) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 defaultClass.lookupConstructor(constructor.name); 169 defaultClass.lookupConstructor(constructor.name);
174 170
175 // If that fails, try looking up "MyClass.name". 171 // If that fails, try looking up "MyClass.name".
176 if (constructor.defaultImplementation === null) { 172 if (constructor.defaultImplementation === null) {
177 SourceString name = 173 SourceString name =
178 new SourceString(constructor.name.slowToString().replaceFirst( 174 new SourceString(constructor.name.slowToString().replaceFirst(
179 intrface.name.slowToString(), 175 intrface.name.slowToString(),
180 defaultClass.name.slowToString())); 176 defaultClass.name.slowToString()));
181 constructor.defaultImplementation = defaultClass.lookupConstructor(name); 177 constructor.defaultImplementation = defaultClass.lookupConstructor(name);
182 178
183 if (constructor.defaultImplementation === null
184 && name == defaultClass.name
185 && constructor.computeParameters(compiler).parameterCount === 0) {
186 constructor.defaultImplementation =
187 defaultClass.getSynthesizedConstructor();
188 }
189
190 if (constructor.defaultImplementation === null) { 179 if (constructor.defaultImplementation === null) {
191 // We failed find a constrcutor named either 180 // We failed find a constrcutor named either
192 // "MyInterface.name" or "MyClass.name". 181 // "MyInterface.name" or "MyClass.name".
193 error(node, MessageKind.CANNOT_FIND_CONSTRUCTOR2, 182 error(node, MessageKind.CANNOT_FIND_CONSTRUCTOR2,
194 [constructor.name, name]); 183 [constructor.name, name]);
195 } 184 }
196 } 185 }
197 } 186 }
198 187
199 TreeElements resolveVariableElement(Element element) { 188 TreeElements resolveVariableElement(Element element) {
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 } 1129 }
1141 if (node.defaultClause !== null) { 1130 if (node.defaultClause !== null) {
1142 element.defaultClass = visit(node.defaultClause.nodes.head); 1131 element.defaultClass = visit(node.defaultClause.nodes.head);
1143 } 1132 }
1144 for (Link<Node> link = node.interfaces.nodes; 1133 for (Link<Node> link = node.interfaces.nodes;
1145 !link.isEmpty(); 1134 !link.isEmpty();
1146 link = link.tail) { 1135 link = link.tail) {
1147 element.interfaces = element.interfaces.prepend(visit(link.head)); 1136 element.interfaces = element.interfaces.prepend(visit(link.head));
1148 } 1137 }
1149 calculateAllSupertypes(element, new Set<ClassElement>()); 1138 calculateAllSupertypes(element, new Set<ClassElement>());
1139 addDefaultConstructorIfNeeded(element);
1150 return element.computeType(compiler); 1140 return element.computeType(compiler);
1151 } 1141 }
1152 1142
1153 Type visitTypeAnnotation(TypeAnnotation node) { 1143 Type visitTypeAnnotation(TypeAnnotation node) {
1154 return visit(node.typeName); 1144 return visit(node.typeName);
1155 } 1145 }
1156 1146
1157 Type visitIdentifier(Identifier node) { 1147 Type visitIdentifier(Identifier node) {
1158 Element element = context.lookup(node.source); 1148 Element element = context.lookup(node.source);
1159 if (element === null) { 1149 if (element === null) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 supertypes = supertypes.reversePrependAll(interfaceSupertypes); 1224 supertypes = supertypes.reversePrependAll(interfaceSupertypes);
1235 supertypes = supertypes.prepend(interfaces.head); 1225 supertypes = supertypes.prepend(interfaces.head);
1236 } 1226 }
1237 seen.remove(classElement); 1227 seen.remove(classElement);
1238 classElement.allSupertypes = supertypes; 1228 classElement.allSupertypes = supertypes;
1239 } else { 1229 } else {
1240 classElement.allSupertypes = const EmptyLink<Type>(); 1230 classElement.allSupertypes = const EmptyLink<Type>();
1241 } 1231 }
1242 } 1232 }
1243 1233
1234 /**
1235 * Add a synthetic nullary constructor if there are no other
1236 * constructors.
1237 */
1238 void addDefaultConstructorIfNeeded(ClassElement element) {
1239 if (element.constructors.length != 0) return;
1240 SynthesizedConstructorElement constructor =
1241 new SynthesizedConstructorElement(element);
1242 element.constructors[element.name] = constructor;
1243 Type returnType = compiler.types.voidType;
1244 constructor.type = new FunctionType(returnType, const EmptyLink<Type>(),
1245 constructor);
1246 constructor.cachedNode =
1247 new FunctionExpression(new Identifier(element.position()),
1248 new NodeList.empty(),
1249 new Block(new NodeList.empty()),
1250 null, null, null, null);
1251 }
1244 } 1252 }
1245 1253
1246 class VariableDefinitionsVisitor extends CommonResolverVisitor<SourceString> { 1254 class VariableDefinitionsVisitor extends CommonResolverVisitor<SourceString> {
1247 VariableDefinitions definitions; 1255 VariableDefinitions definitions;
1248 ResolverVisitor resolver; 1256 ResolverVisitor resolver;
1249 ElementKind kind; 1257 ElementKind kind;
1250 VariableListElement variables; 1258 VariableListElement variables;
1251 1259
1252 VariableDefinitionsVisitor(Compiler compiler, 1260 VariableDefinitionsVisitor(Compiler compiler,
1253 this.definitions, this.resolver, this.kind) 1261 this.definitions, this.resolver, this.kind)
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 visitNewExpression(NewExpression node) { 1444 visitNewExpression(NewExpression node) {
1437 Node selector = node.send.selector; 1445 Node selector = node.send.selector;
1438 Element e = visit(selector); 1446 Element e = visit(selector);
1439 if (e !== null && e.kind === ElementKind.CLASS) { 1447 if (e !== null && e.kind === ElementKind.CLASS) {
1440 ClassElement cls = e; 1448 ClassElement cls = e;
1441 cls.ensureResolved(compiler); 1449 cls.ensureResolved(compiler);
1442 compiler.resolver.toResolve.add(cls); 1450 compiler.resolver.toResolve.add(cls);
1443 if (cls.isInterface() && (cls.defaultClass === null)) { 1451 if (cls.isInterface() && (cls.defaultClass === null)) {
1444 error(selector, MessageKind.CANNOT_INSTANTIATE_INTERFACE, [cls.name]); 1452 error(selector, MessageKind.CANNOT_INSTANTIATE_INTERFACE, [cls.name]);
1445 } 1453 }
1446 FunctionElement constructor = cls.lookupConstructor(cls.name); 1454 e = cls.lookupConstructor(cls.name);
1447 if (constructor === null && node.send.argumentsNode.isEmpty()) {
1448 e = cls.getSynthesizedConstructor();
1449 } else {
1450 e = constructor;
1451 }
1452 } 1455 }
1453 return e; 1456 return e;
1454 } 1457 }
1455 1458
1456 visitTypeAnnotation(TypeAnnotation node) { 1459 visitTypeAnnotation(TypeAnnotation node) {
1457 // TODO(ahe): Do not ignore type arguments. 1460 // TODO(ahe): Do not ignore type arguments.
1458 return visit(node.typeName); 1461 return visit(node.typeName);
1459 } 1462 }
1460 1463
1461 visitSend(Send node) { 1464 visitSend(Send node) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 class TopScope extends Scope { 1566 class TopScope extends Scope {
1564 LibraryElement get library() => element; 1567 LibraryElement get library() => element;
1565 1568
1566 TopScope(LibraryElement library) : super(null, library); 1569 TopScope(LibraryElement library) : super(null, library);
1567 Element lookup(SourceString name) => library.find(name); 1570 Element lookup(SourceString name) => library.find(name);
1568 1571
1569 Element add(Element element) { 1572 Element add(Element element) {
1570 throw "Cannot add an element in the top scope"; 1573 throw "Cannot add an element in the top scope";
1571 } 1574 }
1572 } 1575 }
OLDNEW
« no previous file with comments | « dart/frog/leg/frog_leg.dart ('k') | dart/frog/leg/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698