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 library elements.modelx; | 5 library elements.modelx; |
6 | 6 |
7 import 'elements.dart'; | 7 import 'elements.dart'; |
8 import '../constants/expressions.dart'; | 8 import '../constants/expressions.dart'; |
| 9 import '../constants/constructors.dart'; |
9 import '../helpers/helpers.dart'; // Included for debug helpers. | 10 import '../helpers/helpers.dart'; // Included for debug helpers. |
10 import '../tree/tree.dart'; | 11 import '../tree/tree.dart'; |
11 import '../util/util.dart'; | 12 import '../util/util.dart'; |
12 import '../resolution/resolution.dart'; | 13 import '../resolution/resolution.dart'; |
13 import '../resolution/class_members.dart' show ClassMemberMixin; | 14 import '../resolution/class_members.dart' show ClassMemberMixin; |
14 | 15 |
15 import '../dart2jslib.dart' show | 16 import '../dart2jslib.dart' show |
16 Backend, | 17 Backend, |
17 Compiler, | 18 Compiler, |
18 Constant, | 19 Constant, |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 get cachedNode => unsupported(); | 300 get cachedNode => unsupported(); |
300 get functionSignature => unsupported(); | 301 get functionSignature => unsupported(); |
301 get parameters => unsupported(); | 302 get parameters => unsupported(); |
302 get patch => null; | 303 get patch => null; |
303 get origin => this; | 304 get origin => this; |
304 get immediateRedirectionTarget => unsupported(); | 305 get immediateRedirectionTarget => unsupported(); |
305 get nestedClosures => unsupported(); | 306 get nestedClosures => unsupported(); |
306 get memberContext => unsupported(); | 307 get memberContext => unsupported(); |
307 get executableContext => unsupported(); | 308 get executableContext => unsupported(); |
308 get isExternal => unsupported(); | 309 get isExternal => unsupported(); |
| 310 get constantConstructor => null; |
309 | 311 |
310 bool get isRedirectingGenerative => unsupported(); | 312 bool get isRedirectingGenerative => unsupported(); |
311 bool get isRedirectingFactory => unsupported(); | 313 bool get isRedirectingFactory => unsupported(); |
312 | 314 |
313 computeSignature(compiler) => unsupported(); | 315 computeSignature(compiler) => unsupported(); |
314 | 316 |
315 bool get hasFunctionSignature => false; | 317 bool get hasFunctionSignature => false; |
316 | 318 |
317 get effectiveTarget => this; | 319 get effectiveTarget => this; |
318 | 320 |
319 computeEffectiveTargetType(InterfaceType newType) => unsupported(); | 321 computeEffectiveTargetType(InterfaceType newType) => unsupported(); |
320 | 322 |
321 get definingConstructor => null; | 323 get definingConstructor => null; |
322 | 324 |
323 FunctionElement asFunctionElement() => this; | 325 FunctionElement asFunctionElement() => this; |
324 | 326 |
325 String get message => '${messageKind.message(messageArguments)}'; | 327 String get message => '${messageKind.message(messageArguments)}'; |
326 | 328 |
327 String toString() => '<$name: $message>'; | 329 String toString() => '<$name: $message>'; |
328 | 330 |
329 accept(ElementVisitor visitor, arg) { | 331 accept(ElementVisitor visitor, arg) { |
330 return visitor.visitErroneousElement(this, arg); | 332 return visitor.visitErroneousElement(this, arg); |
331 } | 333 } |
| 334 |
| 335 @override |
| 336 bool get isFromEnvironmentConstructor => false; |
332 } | 337 } |
333 | 338 |
334 /// A constructor that was synthesized to recover from a compile-time error. | 339 /// A constructor that was synthesized to recover from a compile-time error. |
335 class ErroneousConstructorElementX extends ErroneousElementX | 340 class ErroneousConstructorElementX extends ErroneousElementX |
336 with PatchMixin<FunctionElement>, AnalyzableElementX | 341 with PatchMixin<FunctionElement>, |
| 342 AnalyzableElementX, |
| 343 ConstantConstructorMixin |
337 implements ConstructorElementX { | 344 implements ConstructorElementX { |
338 // TODO(ahe): Instead of subclassing [ErroneousElementX], this class should | 345 // TODO(ahe): Instead of subclassing [ErroneousElementX], this class should |
339 // be more like [ErroneousFieldElementX]. In particular, its kind should be | 346 // be more like [ErroneousFieldElementX]. In particular, its kind should be |
340 // [ElementKind.GENERATIVE_CONSTRUCTOR], and it shouldn't throw as much. | 347 // [ElementKind.GENERATIVE_CONSTRUCTOR], and it shouldn't throw as much. |
341 | 348 |
342 ErroneousConstructorElementX( | 349 ErroneousConstructorElementX( |
343 MessageKind messageKind, | 350 MessageKind messageKind, |
344 Map messageArguments, | 351 Map messageArguments, |
345 String name, | 352 String name, |
346 Element enclosing) | 353 Element enclosing) |
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 assert(modifiers != null); | 1255 assert(modifiers != null); |
1249 } | 1256 } |
1250 | 1257 |
1251 VariableDefinitions parseNode(Element element, DiagnosticListener listener) { | 1258 VariableDefinitions parseNode(Element element, DiagnosticListener listener) { |
1252 return definitions; | 1259 return definitions; |
1253 } | 1260 } |
1254 | 1261 |
1255 DartType computeType(Element element, Compiler compiler) => type; | 1262 DartType computeType(Element element, Compiler compiler) => type; |
1256 } | 1263 } |
1257 | 1264 |
1258 abstract class VariableElementX extends ElementX with AstElementMixin | 1265 abstract class ConstantVariableMixin implements VariableElement { |
| 1266 ConstantExpression _constant; |
| 1267 |
| 1268 ConstantExpression get constant { |
| 1269 assert(invariant(this, _constant != null, |
| 1270 message: "Constant has not been computed for $this.")); |
| 1271 return _constant; |
| 1272 } |
| 1273 |
| 1274 void set constant(ConstantExpression value) { |
| 1275 assert(invariant(this, _constant == null || _constant == value, |
| 1276 message: "Constant has already been computed for $this.")); |
| 1277 _constant = value; |
| 1278 } |
| 1279 } |
| 1280 |
| 1281 abstract class VariableElementX extends ElementX |
| 1282 with AstElementMixin, ConstantVariableMixin |
1259 implements VariableElement { | 1283 implements VariableElement { |
1260 final Token token; | 1284 final Token token; |
1261 final VariableList variables; | 1285 final VariableList variables; |
1262 VariableDefinitions definitionsCache; | 1286 VariableDefinitions definitionsCache; |
1263 Expression initializerCache; | 1287 Expression initializerCache; |
1264 | 1288 |
1265 Modifiers get modifiers => variables.modifiers; | 1289 Modifiers get modifiers => variables.modifiers; |
1266 | 1290 |
1267 VariableElementX(String name, | 1291 VariableElementX(String name, |
1268 ElementKind kind, | 1292 ElementKind kind, |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 nestedClosures.clear(); | 1431 nestedClosures.clear(); |
1408 } | 1432 } |
1409 | 1433 |
1410 FieldElementX copyWithEnclosing(Element enclosingElement) { | 1434 FieldElementX copyWithEnclosing(Element enclosingElement) { |
1411 return new FieldElementX( | 1435 return new FieldElementX( |
1412 new Identifier(token), enclosingElement, variables); | 1436 new Identifier(token), enclosingElement, variables); |
1413 } | 1437 } |
1414 } | 1438 } |
1415 | 1439 |
1416 /// A field that was synthesized to recover from a compile-time error. | 1440 /// A field that was synthesized to recover from a compile-time error. |
1417 class ErroneousFieldElementX extends ElementX implements FieldElementX { | 1441 class ErroneousFieldElementX extends ElementX |
| 1442 with ConstantVariableMixin implements FieldElementX { |
1418 final VariableList variables; | 1443 final VariableList variables; |
1419 | 1444 |
1420 ErroneousFieldElementX(Identifier name, Element enclosingElement) | 1445 ErroneousFieldElementX(Identifier name, Element enclosingElement) |
1421 : variables = new VariableList(Modifiers.EMPTY) | 1446 : variables = new VariableList(Modifiers.EMPTY) |
1422 ..definitions = new VariableDefinitions( | 1447 ..definitions = new VariableDefinitions( |
1423 null, Modifiers.EMPTY, new NodeList.singleton(name)) | 1448 null, Modifiers.EMPTY, new NodeList.singleton(name)) |
1424 ..type = const DynamicType(), | 1449 ..type = const DynamicType(), |
1425 super(name.source, ElementKind.FIELD, enclosingElement); | 1450 super(name.source, ElementKind.FIELD, enclosingElement); |
1426 | 1451 |
1427 VariableDefinitions get definitionsCache => variables.definitions; | 1452 VariableDefinitions get definitionsCache => variables.definitions; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1552 AstElement get definingElement => declaration; | 1577 AstElement get definingElement => declaration; |
1553 } | 1578 } |
1554 | 1579 |
1555 /// [Element] for a formal parameter. | 1580 /// [Element] for a formal parameter. |
1556 /// | 1581 /// |
1557 /// A [ParameterElementX] can be patched. A parameter of an external method is | 1582 /// A [ParameterElementX] can be patched. A parameter of an external method is |
1558 /// patched with the corresponding parameter of the patch method. This is done | 1583 /// patched with the corresponding parameter of the patch method. This is done |
1559 /// to ensure that default values on parameters are computed once (on the | 1584 /// to ensure that default values on parameters are computed once (on the |
1560 /// origin parameter) but can be found through both the origin and the patch. | 1585 /// origin parameter) but can be found through both the origin and the patch. |
1561 abstract class ParameterElementX extends FormalElementX | 1586 abstract class ParameterElementX extends FormalElementX |
1562 with PatchMixin<ParameterElement> implements ParameterElement { | 1587 with PatchMixin<ParameterElement>, ConstantVariableMixin |
| 1588 implements ParameterElement { |
1563 final Expression initializer; | 1589 final Expression initializer; |
1564 final bool isOptional; | 1590 final bool isOptional; |
1565 final bool isNamed; | 1591 final bool isNamed; |
1566 | 1592 |
1567 ParameterElementX(ElementKind elementKind, | 1593 ParameterElementX(ElementKind elementKind, |
1568 FunctionElement functionDeclaration, | 1594 FunctionElement functionDeclaration, |
1569 VariableDefinitions definitions, | 1595 VariableDefinitions definitions, |
1570 Identifier identifier, | 1596 Identifier identifier, |
1571 this.initializer, | 1597 this.initializer, |
1572 {this.isOptional: false, | 1598 {this.isOptional: false, |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1942 if (node.name != null) { | 1968 if (node.name != null) { |
1943 return node.name.getBeginToken(); | 1969 return node.name.getBeginToken(); |
1944 } else { | 1970 } else { |
1945 return node.getBeginToken(); | 1971 return node.getBeginToken(); |
1946 } | 1972 } |
1947 } | 1973 } |
1948 | 1974 |
1949 bool get isLocal => true; | 1975 bool get isLocal => true; |
1950 } | 1976 } |
1951 | 1977 |
| 1978 abstract class ConstantConstructorMixin implements ConstructorElement { |
| 1979 ConstantConstructor _constantConstructor; |
| 1980 |
| 1981 ConstantConstructor get constantConstructor { |
| 1982 if (isPatch) { |
| 1983 ConstructorElement originConstructor = origin; |
| 1984 return originConstructor.constantConstructor; |
| 1985 } |
| 1986 if (!isConst || isFromEnvironmentConstructor) return null; |
| 1987 if (_constantConstructor == null) { |
| 1988 _constantConstructor = computeConstantConstructor(resolvedAst); |
| 1989 } |
| 1990 return _constantConstructor; |
| 1991 } |
| 1992 |
| 1993 bool get isFromEnvironmentConstructor { |
| 1994 return name == 'fromEnvironment' && |
| 1995 library.isDartCore && |
| 1996 (enclosingClass.name == 'bool' || |
| 1997 enclosingClass.name == 'int' || |
| 1998 enclosingClass.name == 'String'); |
| 1999 } |
| 2000 } |
| 2001 |
1952 abstract class ConstructorElementX extends FunctionElementX | 2002 abstract class ConstructorElementX extends FunctionElementX |
1953 implements ConstructorElement { | 2003 with ConstantConstructorMixin implements ConstructorElement { |
1954 bool isRedirectingGenerative = false; | 2004 bool isRedirectingGenerative = false; |
1955 | 2005 |
1956 ConstructorElementX(String name, | 2006 ConstructorElementX(String name, |
1957 ElementKind kind, | 2007 ElementKind kind, |
1958 Modifiers modifiers, | 2008 Modifiers modifiers, |
1959 Element enclosing) | 2009 Element enclosing) |
1960 : super(name, kind, modifiers, enclosing, false); | 2010 : super(name, kind, modifiers, enclosing, false); |
1961 | 2011 |
1962 FunctionElement immediateRedirectionTarget; | 2012 FunctionElement immediateRedirectionTarget; |
1963 | 2013 |
(...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3125 AstElement get definingElement; | 3175 AstElement get definingElement; |
3126 | 3176 |
3127 bool get hasResolvedAst => definingElement.hasTreeElements; | 3177 bool get hasResolvedAst => definingElement.hasTreeElements; |
3128 | 3178 |
3129 ResolvedAst get resolvedAst { | 3179 ResolvedAst get resolvedAst { |
3130 return new ResolvedAst(declaration, | 3180 return new ResolvedAst(declaration, |
3131 definingElement.node, definingElement.treeElements); | 3181 definingElement.node, definingElement.treeElements); |
3132 } | 3182 } |
3133 | 3183 |
3134 } | 3184 } |
OLD | NEW |