| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Defines static information collected by the type checker and used later by | 5 /// Defines static information collected by the type checker and used later by |
| 6 /// emitters to generate code. | 6 /// emitters to generate code. |
| 7 library dev_compiler.src.info; | 7 library dev_compiler.src.info; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 DartType get baseType => rules.getStaticType(node); | 117 DartType get baseType => rules.getStaticType(node); |
| 118 DartType get staticType => convertedType; | 118 DartType get staticType => convertedType; |
| 119 | 119 |
| 120 // safe iff this cannot throw | 120 // safe iff this cannot throw |
| 121 bool get safe => false; | 121 bool get safe => false; |
| 122 | 122 |
| 123 Level get level => safe ? Level.CONFIG : Level.INFO; | 123 Level get level => safe ? Level.CONFIG : Level.INFO; |
| 124 | 124 |
| 125 String get description => '${this.runtimeType}: $baseType to $convertedType'; | 125 String get description => '${this.runtimeType}: $baseType to $convertedType'; |
| 126 | 126 |
| 127 static const String _propertyName = 'dev_compiler.Conversion'; | 127 static const String _propertyName = 'dev_compiler.src.info.CoercionInfo'; |
| 128 | 128 |
| 129 /// Gets the coercion info associated with this node. | 129 /// Gets the coercion info associated with this node. |
| 130 static CoercionInfo get(AstNode node) => node.getProperty(_propertyName); | 130 static CoercionInfo get(AstNode node) => node.getProperty(_propertyName); |
| 131 | 131 |
| 132 /// Sets the coercion info associated with this node. | 132 /// Sets the coercion info associated with this node. |
| 133 static CoercionInfo set(AstNode node, CoercionInfo info) { | 133 static CoercionInfo set(AstNode node, CoercionInfo info) { |
| 134 node.setProperty(_propertyName, info); | 134 node.setProperty(_propertyName, info); |
| 135 return info; | 135 return info; |
| 136 } | 136 } |
| 137 } | 137 } |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 : super._internal(rules, expression, type); | 338 : super._internal(rules, expression, type); |
| 339 } | 339 } |
| 340 | 340 |
| 341 class DynamicInvoke extends CoercionInfo { | 341 class DynamicInvoke extends CoercionInfo { |
| 342 DynamicInvoke(TypeRules rules, Expression expression) | 342 DynamicInvoke(TypeRules rules, Expression expression) |
| 343 : super(rules, expression); | 343 : super(rules, expression); |
| 344 | 344 |
| 345 DartType get convertedType => rules.provider.dynamicType; | 345 DartType get convertedType => rules.provider.dynamicType; |
| 346 String get message => '$node requires dynamic invoke'; | 346 String get message => '$node requires dynamic invoke'; |
| 347 Level get level => Level.INFO; | 347 Level get level => Level.INFO; |
| 348 |
| 349 static const String _propertyName = 'dev_compiler.src.info.DynamicInvoke'; |
| 350 |
| 351 /// Whether this [node] is the target of a dynamic operation. |
| 352 static bool get(AstNode node) { |
| 353 var value = node.getProperty(_propertyName); |
| 354 return value != null ? value : false; |
| 355 } |
| 356 |
| 357 /// Sets whether this node is the target of a dynamic operation. |
| 358 static bool set(AstNode node, bool value) { |
| 359 // Free the storage for things that aren't dynamic. |
| 360 if (value == false) value = null; |
| 361 node.setProperty(_propertyName, value); |
| 362 return value; |
| 363 } |
| 348 } | 364 } |
| 349 | 365 |
| 350 abstract class StaticError extends StaticInfo { | 366 abstract class StaticError extends StaticInfo { |
| 351 final AstNode node; | 367 final AstNode node; |
| 352 | 368 |
| 353 StaticError(this.node); | 369 StaticError(this.node); |
| 354 | 370 |
| 355 Level get level => Level.SEVERE; | 371 Level get level => Level.SEVERE; |
| 356 } | 372 } |
| 357 | 373 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 var isError = severity == analyzer.ErrorSeverity.WARNING; | 534 var isError = severity == analyzer.ErrorSeverity.WARNING; |
| 519 var level = isError ? Level.SEVERE : Level.WARNING; | 535 var level = isError ? Level.SEVERE : Level.WARNING; |
| 520 int begin = error.offset; | 536 int begin = error.offset; |
| 521 int end = begin + error.length; | 537 int end = begin + error.length; |
| 522 return new AnalyzerError(error.message, level, begin, end); | 538 return new AnalyzerError(error.message, level, begin, end); |
| 523 } | 539 } |
| 524 | 540 |
| 525 const AnalyzerError(String message, Level level, int begin, int end) | 541 const AnalyzerError(String message, Level level, int begin, int end) |
| 526 : super(message, level, begin, end); | 542 : super(message, level, begin, end); |
| 527 } | 543 } |
| OLD | NEW |