| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // IrNodes are kept in a separate library to have precise control over their | 5 // IrNodes are kept in a separate library to have precise control over their |
| 6 // dependencies on other parts of the system. | 6 // dependencies on other parts of the system. |
| 7 library dart2js.ir_nodes; | 7 library dart2js.ir_nodes; |
| 8 | 8 |
| 9 import '../dart2jslib.dart' as dart2js show Constant; | 9 import '../dart2jslib.dart' as dart2js show Constant, ConstructedConstant; |
| 10 import '../elements/elements.dart' | 10 import '../elements/elements.dart' |
| 11 show FunctionElement, LibraryElement, ParameterElement, ClassElement, | 11 show FunctionElement, LibraryElement, ParameterElement, ClassElement, |
| 12 Element, VariableElement; | 12 Element, VariableElement; |
| 13 import '../universe/universe.dart' show Selector, SelectorKind; | 13 import '../universe/universe.dart' show Selector, SelectorKind; |
| 14 import '../dart_types.dart' show DartType, GenericType; | 14 import '../dart_types.dart' show DartType, GenericType; |
| 15 import '../helpers/helpers.dart'; | 15 import '../helpers/helpers.dart'; |
| 16 | 16 |
| 17 abstract class Node { | 17 abstract class Node { |
| 18 static int hashCount = 0; | 18 static int hashCount = 0; |
| 19 final int hashCode = hashCount = (hashCount + 1) & 0x3fffffff; | 19 final int hashCode = hashCount = (hashCount + 1) & 0x3fffffff; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 abstract class Primitive extends Definition { | 54 abstract class Primitive extends Definition { |
| 55 /// The [VariableElement] or [ParameterElement] from which the primitive | 55 /// The [VariableElement] or [ParameterElement] from which the primitive |
| 56 /// binding originated. | 56 /// binding originated. |
| 57 Element element; | 57 Element element; |
| 58 | 58 |
| 59 /// Register in which the variable binding this primitive can be allocated. | 59 /// Register in which the variable binding this primitive can be allocated. |
| 60 /// Separate register spaces are used for primitives with different [element]. | 60 /// Separate register spaces are used for primitives with different [element]. |
| 61 /// Assigned by [RegisterAllocator], is null before that phase. | 61 /// Assigned by [RegisterAllocator], is null before that phase. |
| 62 int registerIndex; | 62 int registerIndex; |
| 63 | 63 |
| 64 /// If non-null, this primitive is a reference to the given constant. |
| 65 dart2js.Constant get constant; |
| 66 |
| 64 /// Use the given element as a hint for naming this primitive. | 67 /// Use the given element as a hint for naming this primitive. |
| 65 /// | 68 /// |
| 66 /// Has no effect if this primitive already has a non-null [element]. | 69 /// Has no effect if this primitive already has a non-null [element]. |
| 67 void useElementAsHint(Element hint) { | 70 void useElementAsHint(Element hint) { |
| 68 if (element == null) { | 71 if (element == null) { |
| 69 element = hint; | 72 element = hint; |
| 70 } | 73 } |
| 71 } | 74 } |
| 72 } | 75 } |
| 73 | 76 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 210 |
| 208 accept(Visitor visitor) => visitor.visitInvokeConstructor(this); | 211 accept(Visitor visitor) => visitor.visitInvokeConstructor(this); |
| 209 } | 212 } |
| 210 | 213 |
| 211 class InvokeConstConstructor extends Primitive { | 214 class InvokeConstConstructor extends Primitive { |
| 212 final GenericType type; | 215 final GenericType type; |
| 213 final FunctionElement constructor; | 216 final FunctionElement constructor; |
| 214 final List<Reference> arguments; | 217 final List<Reference> arguments; |
| 215 final Selector selector; | 218 final Selector selector; |
| 216 | 219 |
| 220 final dart2js.ConstructedConstant constant; |
| 221 |
| 217 /// The class being instantiated. This is the same as `target.enclosingClass` | 222 /// The class being instantiated. This is the same as `target.enclosingClass` |
| 218 /// and `type.element`. | 223 /// and `type.element`. |
| 219 ClassElement get targetClass => constructor.enclosingElement; | 224 ClassElement get targetClass => constructor.enclosingElement; |
| 220 | 225 |
| 221 /// True if this is an invocation of a factory constructor. | 226 /// True if this is an invocation of a factory constructor. |
| 222 bool get isFactory => constructor.isFactoryConstructor; | 227 bool get isFactory => constructor.isFactoryConstructor; |
| 223 | 228 |
| 224 InvokeConstConstructor(this.type, | 229 InvokeConstConstructor(this.type, |
| 225 this.constructor, | 230 this.constructor, |
| 226 this.selector, | 231 this.selector, |
| 227 List<Definition> args) | 232 List<Definition> args, |
| 233 this.constant) |
| 228 : arguments = _referenceList(args) { | 234 : arguments = _referenceList(args) { |
| 229 assert(constructor.isConstructor); | 235 assert(constructor.isConstructor); |
| 230 assert(type.element == constructor.enclosingElement); | 236 assert(type.element == constructor.enclosingElement); |
| 237 assert(constant.type == type); |
| 231 } | 238 } |
| 232 | 239 |
| 233 accept(Visitor visitor) => visitor.visitInvokeConstConstructor(this); | 240 accept(Visitor visitor) => visitor.visitInvokeConstConstructor(this); |
| 234 } | 241 } |
| 235 | 242 |
| 236 /// Invoke [toString] on each argument and concatenate the results. | 243 /// Invoke [toString] on each argument and concatenate the results. |
| 237 class ConcatenateStrings extends Expression { | 244 class ConcatenateStrings extends Expression { |
| 238 final Reference continuation; | 245 final Reference continuation; |
| 239 final List<Reference> arguments; | 246 final List<Reference> arguments; |
| 240 | 247 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 falseContinuation = new Reference(falseCont); | 295 falseContinuation = new Reference(falseCont); |
| 289 | 296 |
| 290 accept(Visitor visitor) => visitor.visitBranch(this); | 297 accept(Visitor visitor) => visitor.visitBranch(this); |
| 291 } | 298 } |
| 292 | 299 |
| 293 class Constant extends Primitive { | 300 class Constant extends Primitive { |
| 294 final dart2js.Constant value; | 301 final dart2js.Constant value; |
| 295 | 302 |
| 296 Constant(this.value); | 303 Constant(this.value); |
| 297 | 304 |
| 305 dart2js.Constant get constant => value; |
| 306 |
| 298 accept(Visitor visitor) => visitor.visitConstant(this); | 307 accept(Visitor visitor) => visitor.visitConstant(this); |
| 299 } | 308 } |
| 300 | 309 |
| 301 class LiteralList extends Primitive { | 310 class LiteralList extends Primitive { |
| 302 List<Reference> values; | 311 /// The List type being created; this is not the type argument. |
| 312 final GenericType type; |
| 313 final List<Reference> values; |
| 303 | 314 |
| 304 LiteralList(List<Primitive> values) | 315 /// Set to null if this is not a const literal list. |
| 316 final dart2js.Constant constant; |
| 317 |
| 318 LiteralList(this.type, List<Primitive> values, [this.constant]) |
| 305 : this.values = _referenceList(values); | 319 : this.values = _referenceList(values); |
| 306 | 320 |
| 307 accept(Visitor visitor) => visitor.visitLiteralList(this); | 321 accept(Visitor visitor) => visitor.visitLiteralList(this); |
| 308 } | 322 } |
| 309 | 323 |
| 310 class LiteralMap extends Primitive { | 324 class LiteralMap extends Primitive { |
| 311 List<Reference> keys; | 325 final GenericType type; |
| 312 List<Reference> values; | 326 final List<Reference> keys; |
| 327 final List<Reference> values; |
| 313 | 328 |
| 314 LiteralMap(List<Primitive> keys, List<Primitive> values) | 329 /// Set to null if this is not a const literal map. |
| 330 final dart2js.Constant constant; |
| 331 |
| 332 LiteralMap(this.type, List<Primitive> keys, List<Primitive> values, |
| 333 [this.constant]) |
| 315 : this.keys = _referenceList(keys), | 334 : this.keys = _referenceList(keys), |
| 316 this.values = _referenceList(values); | 335 this.values = _referenceList(values); |
| 317 | 336 |
| 318 accept(Visitor visitor) => visitor.visitLiteralMap(this); | 337 accept(Visitor visitor) => visitor.visitLiteralMap(this); |
| 319 } | 338 } |
| 320 | 339 |
| 321 class Parameter extends Primitive { | 340 class Parameter extends Primitive { |
| 322 Parameter(Element element) { | 341 Parameter(Element element) { |
| 323 super.element = element; | 342 super.element = element; |
| 324 } | 343 } |
| 325 | 344 |
| 345 dart2js.Constant get constant => null; |
| 346 |
| 326 accept(Visitor visitor) => visitor.visitParameter(this); | 347 accept(Visitor visitor) => visitor.visitParameter(this); |
| 327 } | 348 } |
| 328 | 349 |
| 329 /// Continuations are normally bound by 'let cont'. A continuation with no | 350 /// Continuations are normally bound by 'let cont'. A continuation with no |
| 330 /// parameter (or body) is used to represent a function's return continuation. | 351 /// parameter (or body) is used to represent a function's return continuation. |
| 331 /// The return continuation is bound by the Function, not by 'let cont'. | 352 /// The return continuation is bound by the Function, not by 'let cont'. |
| 332 class Continuation extends Definition { | 353 class Continuation extends Definition { |
| 333 final List<Parameter> parameters; | 354 final List<Parameter> parameters; |
| 334 Expression body = null; | 355 Expression body = null; |
| 335 | 356 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 for (int i = node.parameters.length - 1; i >= 0; --i) { | 674 for (int i = node.parameters.length - 1; i >= 0; --i) { |
| 654 release(node.parameters[i]); | 675 release(node.parameters[i]); |
| 655 } | 676 } |
| 656 } | 677 } |
| 657 | 678 |
| 658 void visitIsTrue(IsTrue node) { | 679 void visitIsTrue(IsTrue node) { |
| 659 visitReference(node.value); | 680 visitReference(node.value); |
| 660 } | 681 } |
| 661 | 682 |
| 662 } | 683 } |
| OLD | NEW |