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

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

Issue 9447100: Return null from stringValue and call slowToString() instead of toString(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: changes Created 8 years, 10 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/native_handler.dart ('k') | dart/frog/leg/scanner/byte_strings.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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // [intrface] is an interface, let's say "MyInterface". 172 // [intrface] is an interface, let's say "MyInterface".
173 // [defaultClass] is a class, let's say "MyClass". 173 // [defaultClass] is a class, let's say "MyClass".
174 174
175 // First look up the constructor named "MyInterface.name". 175 // First look up the constructor named "MyInterface.name".
176 constructor.defaultImplementation = 176 constructor.defaultImplementation =
177 defaultClass.lookupConstructor(constructor.name); 177 defaultClass.lookupConstructor(constructor.name);
178 178
179 // If that fails, try looking up "MyClass.name". 179 // If that fails, try looking up "MyClass.name".
180 if (constructor.defaultImplementation === null) { 180 if (constructor.defaultImplementation === null) {
181 SourceString name = 181 SourceString name =
182 new SourceString(constructor.name.toString().replaceFirst( 182 new SourceString(constructor.name.slowToString().replaceFirst(
183 intrface.name.toString(), 183 intrface.name.slowToString(),
184 defaultClass.name.toString())); 184 defaultClass.name.slowToString()));
185 constructor.defaultImplementation = defaultClass.lookupConstructor(name); 185 constructor.defaultImplementation = defaultClass.lookupConstructor(name);
186 186
187 if (constructor.defaultImplementation === null 187 if (constructor.defaultImplementation === null
188 && name == defaultClass.name 188 && name == defaultClass.name
189 && constructor.computeParameters(compiler).parameterCount === 0) { 189 && constructor.computeParameters(compiler).parameterCount === 0) {
190 constructor.defaultImplementation = 190 constructor.defaultImplementation =
191 defaultClass.getSynthesizedConstructor(); 191 defaultClass.getSynthesizedConstructor();
192 } 192 }
193 193
194 if (constructor.defaultImplementation === null) { 194 if (constructor.defaultImplementation === null) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } else { 366 } else {
367 visitor.error(call, MessageKind.CONSTRUCTOR_CALL_EXPECTED); 367 visitor.error(call, MessageKind.CONSTRUCTOR_CALL_EXPECTED);
368 validTarget = false; 368 validTarget = false;
369 } 369 }
370 370
371 if (validTarget) { 371 if (validTarget) {
372 ResolverTask resolver = visitor.compiler.resolver; 372 ResolverTask resolver = visitor.compiler.resolver;
373 result = resolver.lookupConstructor(lookupTarget, call); 373 result = resolver.lookupConstructor(lookupTarget, call);
374 if (result === null) { 374 if (result === null) {
375 SourceString constructorName = resolver.getConstructorName(call); 375 SourceString constructorName = resolver.getConstructorName(call);
376 SourceString className = lookupTarget.name; 376 String className = lookupTarget.name.slowToString();
377 String name = (constructorName === const SourceString('')) 377 String name = (constructorName === const SourceString(''))
378 ? className.stringValue 378 ? className
379 : "$className.$constructorName"; 379 : "$className.${constructorName.slowToString()}";
380 error(call, MessageKind.CANNOT_RESOLVE_CONSTRUCTOR, [name]); 380 error(call, MessageKind.CANNOT_RESOLVE_CONSTRUCTOR, [name]);
381 } else { 381 } else {
382 final Compiler compiler = visitor.compiler; 382 final Compiler compiler = visitor.compiler;
383 // TODO(karlklose): support optional arguments. 383 // TODO(karlklose): support optional arguments.
384 if (result.parameterCount(compiler) != call.argumentCount()) { 384 if (result.parameterCount(compiler) != call.argumentCount()) {
385 error(call, MessageKind.NO_MATCHING_CONSTRUCTOR); 385 error(call, MessageKind.NO_MATCHING_CONSTRUCTOR);
386 } 386 }
387 } 387 }
388 visitor.useElement(call, result); 388 visitor.useElement(call, result);
389 } 389 }
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 1016
1017 visitBreakStatement(BreakStatement node) { 1017 visitBreakStatement(BreakStatement node) {
1018 StatementElement target; 1018 StatementElement target;
1019 if (node.target === null) { 1019 if (node.target === null) {
1020 target = statementScope.currentBreakTarget(); 1020 target = statementScope.currentBreakTarget();
1021 if (target === null) { 1021 if (target === null) {
1022 error(node, MessageKind.NO_BREAK_TARGET); 1022 error(node, MessageKind.NO_BREAK_TARGET);
1023 return; 1023 return;
1024 } 1024 }
1025 } else { 1025 } else {
1026 String labelName = node.target.source.stringValue; 1026 String labelName = node.target.source.slowToString();
1027 target = statementScope.lookupLabel(labelName); 1027 target = statementScope.lookupLabel(labelName);
1028 if (target === null) { 1028 if (target === null) {
1029 error(node.target, MessageKind.UNBOUND_LABEL, [labelName]); 1029 error(node.target, MessageKind.UNBOUND_LABEL, [labelName]);
1030 return; 1030 return;
1031 } 1031 }
1032 } 1032 }
1033 target.isBreakTarget = true; 1033 target.isBreakTarget = true;
1034 mapping[node] = target; 1034 mapping[node] = target;
1035 } 1035 }
1036 1036
1037 visitContinueStatement(ContinueStatement node) { 1037 visitContinueStatement(ContinueStatement node) {
1038 StatementElement target; 1038 StatementElement target;
1039 if (node.target === null) { 1039 if (node.target === null) {
1040 target = statementScope.currentContinueTarget(); 1040 target = statementScope.currentContinueTarget();
1041 if (target === null) { 1041 if (target === null) {
1042 error(node, MessageKind.NO_CONTINUE_TARGET); 1042 error(node, MessageKind.NO_CONTINUE_TARGET);
1043 return; 1043 return;
1044 } 1044 }
1045 } else { 1045 } else {
1046 String labelName = node.target.source.stringValue; 1046 String labelName = node.target.source.slowToString();
1047 target = statementScope.lookupLabel(labelName); 1047 target = statementScope.lookupLabel(labelName);
1048 if (target === null) { 1048 if (target === null) {
1049 error(node.target, MessageKind.UNBOUND_LABEL, [labelName]); 1049 error(node.target, MessageKind.UNBOUND_LABEL, [labelName]);
1050 return; 1050 return;
1051 } 1051 }
1052 if (!target.origin.isValidContinueTarget()) { 1052 if (!target.origin.isValidContinueTarget()) {
1053 error(node.target, MessageKind.INVALID_CONTINUE, [labelName]); 1053 error(node.target, MessageKind.INVALID_CONTINUE, [labelName]);
1054 } 1054 }
1055 } 1055 }
1056 target.isContinueTarget = true; 1056 target.isContinueTarget = true;
(...skipping 12 matching lines...) Expand all
1069 && (declaration is !VariableDefinitions || 1069 && (declaration is !VariableDefinitions ||
1070 !declaration.asVariableDefinitions().definitions.nodes.tail.isEmpty())) 1070 !declaration.asVariableDefinitions().definitions.nodes.tail.isEmpty()))
1071 { 1071 {
1072 // The variable declaration is either not an identifier, not a 1072 // The variable declaration is either not an identifier, not a
1073 // declaration, or it's declaring more than one variable. 1073 // declaration, or it's declaring more than one variable.
1074 error(node.declaredIdentifier, MessageKind.INVALID_FOR_IN, []); 1074 error(node.declaredIdentifier, MessageKind.INVALID_FOR_IN, []);
1075 } 1075 }
1076 } 1076 }
1077 1077
1078 visitLabelledStatement(LabelledStatement node) { 1078 visitLabelledStatement(LabelledStatement node) {
1079 String labelName = node.label.source.stringValue; 1079 String labelName = node.label.source.slowToString();
1080 StatementElement existingElement = statementScope.lookupLabel(labelName); 1080 StatementElement existingElement = statementScope.lookupLabel(labelName);
1081 if (existingElement !== null) { 1081 if (existingElement !== null) {
1082 LabelledStatement declaration = existingElement.origin; 1082 LabelledStatement declaration = existingElement.origin;
1083 warning(node.label, MessageKind.DUPLICATE_LABEL, [labelName]); 1083 warning(node.label, MessageKind.DUPLICATE_LABEL, [labelName]);
1084 warning(declaration.label, MessageKind.EXISTING_LABEL, [labelName]); 1084 warning(declaration.label, MessageKind.EXISTING_LABEL, [labelName]);
1085 } 1085 }
1086 StatementElement element = 1086 StatementElement element =
1087 new StatementElement.label(labelName, node, enclosingElement); 1087 new StatementElement.label(labelName, node, enclosingElement);
1088 statementScope.enterLabelScope(labelName, element); 1088 statementScope.enterLabelScope(labelName, element);
1089 visit(node.statement); 1089 visit(node.statement);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 class TopScope extends Scope { 1432 class TopScope extends Scope {
1433 LibraryElement get library() => element; 1433 LibraryElement get library() => element;
1434 1434
1435 TopScope(LibraryElement library) : super(null, library); 1435 TopScope(LibraryElement library) : super(null, library);
1436 Element lookup(SourceString name) => library.find(name); 1436 Element lookup(SourceString name) => library.find(name);
1437 1437
1438 Element add(Element element) { 1438 Element add(Element element) {
1439 throw "Cannot add an element in the top scope"; 1439 throw "Cannot add an element in the top scope";
1440 } 1440 }
1441 } 1441 }
OLDNEW
« no previous file with comments | « dart/frog/leg/native_handler.dart ('k') | dart/frog/leg/scanner/byte_strings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698