OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 native; | 5 part of native; |
6 | 6 |
7 /// This class is a temporary work-around until we get a more powerful DartType. | 7 /// This class is a temporary work-around until we get a more powerful DartType. |
8 class SpecialType { | 8 class SpecialType { |
9 final String name; | 9 final String name; |
10 const SpecialType._(this.name); | 10 const SpecialType._(this.name); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 dynamic resolveType(String typeString), | 207 dynamic resolveType(String typeString), |
208 List typesReturned, | 208 List typesReturned, |
209 List typesInstantiated, | 209 List typesInstantiated, |
210 objectType, nullType}) { | 210 objectType, nullType}) { |
211 | 211 |
212 | 212 |
213 bool seenError = false; | 213 bool seenError = false; |
214 | 214 |
215 void reportError(String message) { | 215 void reportError(String message) { |
216 seenError = true; | 216 seenError = true; |
217 listener.reportError(spannable, MessageKind.GENERIC, {'text': message}); | 217 listener.reportErrorMessage( |
| 218 spannable, MessageKind.GENERIC, {'text': message}); |
218 } | 219 } |
219 | 220 |
220 const List<String> knownTags = const [ | 221 const List<String> knownTags = const [ |
221 'creates', 'returns', 'depends', 'effects', | 222 'creates', 'returns', 'depends', 'effects', |
222 'throws', 'gvn', 'new']; | 223 'throws', 'gvn', 'new']; |
223 | 224 |
224 /// Resolve a type string of one of the three forms: | 225 /// Resolve a type string of one of the three forms: |
225 /// * 'void' - in which case [onVoid] is called, | 226 /// * 'void' - in which case [onVoid] is called, |
226 /// * '' or 'var' - in which case [onVar] is called, | 227 /// * '' or 'var' - in which case [onVar] is called, |
227 /// * 'T1|...|Tn' - in which case [onType] is called for each resolved Ti. | 228 /// * 'T1|...|Tn' - in which case [onType] is called for each resolved Ti. |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 // The first argument of a JS-call is a string encoding various attributes | 428 // The first argument of a JS-call is a string encoding various attributes |
428 // of the code. | 429 // of the code. |
429 // | 430 // |
430 // 'Type1|Type2'. A union type. | 431 // 'Type1|Type2'. A union type. |
431 // '=Object'. A JavaScript Object, no subtype. | 432 // '=Object'. A JavaScript Object, no subtype. |
432 | 433 |
433 NativeBehavior behavior = new NativeBehavior(); | 434 NativeBehavior behavior = new NativeBehavior(); |
434 | 435 |
435 var argNodes = jsCall.arguments; | 436 var argNodes = jsCall.arguments; |
436 if (argNodes.isEmpty || argNodes.tail.isEmpty) { | 437 if (argNodes.isEmpty || argNodes.tail.isEmpty) { |
437 compiler.reportError(jsCall, MessageKind.GENERIC, | 438 compiler.reportErrorMessage( |
| 439 jsCall, |
| 440 MessageKind.GENERIC, |
438 {'text': "JS expression takes two or more arguments."}); | 441 {'text': "JS expression takes two or more arguments."}); |
439 return behavior; | 442 return behavior; |
440 } | 443 } |
441 | 444 |
442 var specArgument = argNodes.head; | 445 var specArgument = argNodes.head; |
443 if (specArgument is !StringNode || specArgument.isInterpolation) { | 446 if (specArgument is !StringNode || specArgument.isInterpolation) { |
444 compiler.reportError(specArgument, MessageKind.GENERIC, | 447 compiler.reportErrorMessage( |
| 448 specArgument, MessageKind.GENERIC, |
445 {'text': "JS first argument must be a string literal."}); | 449 {'text': "JS first argument must be a string literal."}); |
446 return behavior; | 450 return behavior; |
447 } | 451 } |
448 | 452 |
449 var codeArgument = argNodes.tail.head; | 453 var codeArgument = argNodes.tail.head; |
450 if (codeArgument is !StringNode || codeArgument.isInterpolation) { | 454 if (codeArgument is !StringNode || codeArgument.isInterpolation) { |
451 compiler.reportError(codeArgument, MessageKind.GENERIC, | 455 compiler.reportErrorMessage( |
| 456 codeArgument, MessageKind.GENERIC, |
452 {'text': "JS second argument must be a string literal."}); | 457 {'text': "JS second argument must be a string literal."}); |
453 return behavior; | 458 return behavior; |
454 } | 459 } |
455 | 460 |
456 behavior.codeTemplate = | 461 behavior.codeTemplate = |
457 js.js.parseForeignJS(codeArgument.dartString.slowToString()); | 462 js.js.parseForeignJS(codeArgument.dartString.slowToString()); |
458 | 463 |
459 String specString = specArgument.dartString.slowToString(); | 464 String specString = specArgument.dartString.slowToString(); |
460 | 465 |
461 dynamic resolveType(String typeString) { | 466 dynamic resolveType(String typeString) { |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 lookup(name), locationNodeOrElement) { | 751 lookup(name), locationNodeOrElement) { |
747 if (typeString == '=Object') return SpecialType.JsObject; | 752 if (typeString == '=Object') return SpecialType.JsObject; |
748 if (typeString == 'dynamic') { | 753 if (typeString == 'dynamic') { |
749 return const DynamicType(); | 754 return const DynamicType(); |
750 } | 755 } |
751 var type = lookup(typeString); | 756 var type = lookup(typeString); |
752 if (type != null) return type; | 757 if (type != null) return type; |
753 | 758 |
754 int index = typeString.indexOf('<'); | 759 int index = typeString.indexOf('<'); |
755 if (index < 1) { | 760 if (index < 1) { |
756 compiler.reportError( | 761 compiler.reportErrorMessage( |
757 _errorNode(locationNodeOrElement, compiler), | 762 _errorNode(locationNodeOrElement, compiler), |
758 MessageKind.GENERIC, | 763 MessageKind.GENERIC, |
759 {'text': "Type '$typeString' not found."}); | 764 {'text': "Type '$typeString' not found."}); |
760 return const DynamicType(); | 765 return const DynamicType(); |
761 } | 766 } |
762 type = lookup(typeString.substring(0, index)); | 767 type = lookup(typeString.substring(0, index)); |
763 if (type != null) { | 768 if (type != null) { |
764 // TODO(sra): Parse type parameters. | 769 // TODO(sra): Parse type parameters. |
765 return type; | 770 return type; |
766 } | 771 } |
767 compiler.reportError( | 772 compiler.reportErrorMessage( |
768 _errorNode(locationNodeOrElement, compiler), | 773 _errorNode(locationNodeOrElement, compiler), |
769 MessageKind.GENERIC, | 774 MessageKind.GENERIC, |
770 {'text': "Type '$typeString' not found."}); | 775 {'text': "Type '$typeString' not found."}); |
771 return const DynamicType(); | 776 return const DynamicType(); |
772 } | 777 } |
773 | 778 |
774 static _errorNode(locationNodeOrElement, compiler) { | 779 static _errorNode(locationNodeOrElement, compiler) { |
775 if (locationNodeOrElement is Node) return locationNodeOrElement; | 780 if (locationNodeOrElement is Node) return locationNodeOrElement; |
776 return locationNodeOrElement.parseNode(compiler); | 781 return locationNodeOrElement.parseNode(compiler); |
777 } | 782 } |
778 } | 783 } |
OLD | NEW |