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

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

Issue 10831332: Support new getter syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments and disable one test. Created 8 years, 4 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 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 useElement(annotation, type.element); 985 useElement(annotation, type.element);
986 } 986 }
987 return type; 987 return type;
988 } 988 }
989 989
990 void setupFunction(FunctionExpression node, FunctionElement function) { 990 void setupFunction(FunctionExpression node, FunctionElement function) {
991 scope = new MethodScope(scope, function); 991 scope = new MethodScope(scope, function);
992 // Put the parameters in scope. 992 // Put the parameters in scope.
993 FunctionSignature functionParameters = 993 FunctionSignature functionParameters =
994 function.computeSignature(compiler); 994 function.computeSignature(compiler);
995 Link<Node> parameterNodes = node.parameters.nodes; 995 Link<Node> parameterNodes = (node.parameters === null)
996 ? const EmptyLink<Node>() : node.parameters.nodes;
996 functionParameters.forEachParameter((Element element) { 997 functionParameters.forEachParameter((Element element) {
997 if (element == functionParameters.optionalParameters.head) { 998 if (element == functionParameters.optionalParameters.head) {
998 NodeList nodes = parameterNodes.head; 999 NodeList nodes = parameterNodes.head;
999 parameterNodes = nodes.nodes; 1000 parameterNodes = nodes.nodes;
1000 } 1001 }
1001 VariableDefinitions variableDefinitions = parameterNodes.head; 1002 VariableDefinitions variableDefinitions = parameterNodes.head;
1002 Node parameterNode = variableDefinitions.definitions.nodes.head; 1003 Node parameterNode = variableDefinitions.definitions.nodes.head;
1003 initializerDo(parameterNode, (n) => n.accept(this)); 1004 initializerDo(parameterNode, (n) => n.accept(this));
1004 // Field parameters (this.x) are not visible inside the constructor. The 1005 // Field parameters (this.x) are not visible inside the constructor. The
1005 // fields they reference are visible, but must be resolved independently. 1006 // fields they reference are visible, but must be resolved independently.
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 } 2248 }
2248 2249
2249 /** 2250 /**
2250 * Resolves formal parameters and return type to a [FunctionSignature]. 2251 * Resolves formal parameters and return type to a [FunctionSignature].
2251 */ 2252 */
2252 static FunctionSignature analyze(Compiler compiler, 2253 static FunctionSignature analyze(Compiler compiler,
2253 NodeList formalParameters, 2254 NodeList formalParameters,
2254 Node returnNode, 2255 Node returnNode,
2255 Element element) { 2256 Element element) {
2256 SignatureResolver visitor = new SignatureResolver(compiler, element); 2257 SignatureResolver visitor = new SignatureResolver(compiler, element);
2257 LinkBuilder<Element> parametersBuilder = 2258 Link<Element> parameters = const EmptyLink<Element>();
2259 int requiredParameterCount = 0;
2260 if (formalParameters === null) {
2261 if (!element.isGetter()) {
2262 compiler.reportMessage(compiler.spanFromElement(element),
2263 MessageKind.MISSING_FORMALS.error([]),
2264 api.Diagnostic.ERROR);
2265 }
2266 } else {
2267 if (element.isGetter()) {
2268 if (!element.getLibrary().isPlatformLibrary) {
2269 // TODO(ahe): Remove the isPlatformLibrary check.
2270 if (formalParameters.getEndToken().next.stringValue !== 'native') {
2271 // TODO(ahe): Remove the check for native keyword.
2272 compiler.reportMessage(compiler.spanFromNode(formalParameters),
2273 MessageKind.EXTRA_FORMALS.error([]),
2274 api.Diagnostic.WARNING);
2275 }
2276 }
2277 }
2278 LinkBuilder<Element> parametersBuilder =
2258 visitor.analyzeNodes(formalParameters.nodes); 2279 visitor.analyzeNodes(formalParameters.nodes);
2259 Link<Element> parameters = parametersBuilder.toLink(); 2280 requiredParameterCount = parametersBuilder.length;
2260 Type returnType = 2281 parameters = parametersBuilder.toLink();
2261 compiler.resolveTypeAnnotation(element, returnNode); 2282 }
2283 Type returnType = compiler.resolveTypeAnnotation(element, returnNode);
2262 return new FunctionSignature(parameters, 2284 return new FunctionSignature(parameters,
2263 visitor.optionalParameters, 2285 visitor.optionalParameters,
2264 parametersBuilder.length, 2286 requiredParameterCount,
2265 visitor.optionalParameterCount, 2287 visitor.optionalParameterCount,
2266 returnType); 2288 returnType);
2267 } 2289 }
2268 2290
2269 // TODO(ahe): This is temporary. 2291 // TODO(ahe): This is temporary.
2270 void resolveExpression(Node node) { 2292 void resolveExpression(Node node) {
2271 if (node == null) return; 2293 if (node == null) return;
2272 node.accept(new ResolverVisitor(compiler, enclosingElement)); 2294 node.accept(new ResolverVisitor(compiler, enclosingElement));
2273 } 2295 }
2274 2296
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2472 TopScope(LibraryElement library) : super(null, library); 2494 TopScope(LibraryElement library) : super(null, library);
2473 Element lookup(SourceString name) { 2495 Element lookup(SourceString name) {
2474 return library.find(name); 2496 return library.find(name);
2475 } 2497 }
2476 2498
2477 Element add(Element newElement) { 2499 Element add(Element newElement) {
2478 throw "Cannot add an element in the top scope"; 2500 throw "Cannot add an element in the top scope";
2479 } 2501 }
2480 String toString() => '$element'; 2502 String toString() => '$element';
2481 } 2503 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698