| 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 'common.dart'; | 7 import 'common.dart'; |
| 8 import 'elements.dart'; | 8 import 'elements.dart'; |
| 9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
| 10 import '../constants/constructors.dart'; | 10 import '../constants/constructors.dart'; |
| 11 import '../helpers/helpers.dart'; |
| 11 import '../tree/tree.dart'; | 12 import '../tree/tree.dart'; |
| 12 import '../util/util.dart'; | 13 import '../util/util.dart'; |
| 13 import '../resolution/resolution.dart'; | 14 import '../resolution/resolution.dart'; |
| 14 import '../resolution/class_members.dart' show ClassMemberMixin; | 15 import '../resolution/class_members.dart' show ClassMemberMixin; |
| 15 | 16 |
| 16 import '../dart2jslib.dart' show | 17 import '../dart2jslib.dart' show |
| 17 Backend, | 18 Backend, |
| 18 Compiler, | 19 Compiler, |
| 19 Constant, | 20 Constant, |
| 20 DartType, | 21 DartType, |
| (...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 } | 1242 } |
| 1242 | 1243 |
| 1243 VariableDefinitions parseNode(Element element, DiagnosticListener listener) { | 1244 VariableDefinitions parseNode(Element element, DiagnosticListener listener) { |
| 1244 return definitions; | 1245 return definitions; |
| 1245 } | 1246 } |
| 1246 | 1247 |
| 1247 DartType computeType(Element element, Compiler compiler) => type; | 1248 DartType computeType(Element element, Compiler compiler) => type; |
| 1248 } | 1249 } |
| 1249 | 1250 |
| 1250 abstract class ConstantVariableMixin implements VariableElement { | 1251 abstract class ConstantVariableMixin implements VariableElement { |
| 1251 ConstantExpression _constant; | 1252 ConstantExpression constantCache; |
| 1252 | 1253 |
| 1253 ConstantExpression get constant { | 1254 ConstantExpression get constant { |
| 1254 if (isPatch) { | 1255 if (isPatch) { |
| 1255 ConstantVariableMixin originVariable = origin; | 1256 ConstantVariableMixin originVariable = origin; |
| 1256 return originVariable.constant; | 1257 return originVariable.constant; |
| 1257 } | 1258 } |
| 1258 assert(invariant(this, _constant != null, | 1259 assert(invariant(this, constantCache != null, |
| 1259 message: "Constant has not been computed for $this.")); | 1260 message: "Constant has not been computed for $this.")); |
| 1260 return _constant; | 1261 return constantCache; |
| 1261 } | 1262 } |
| 1262 | 1263 |
| 1263 void set constant(ConstantExpression value) { | 1264 void set constant(ConstantExpression value) { |
| 1264 if (isPatch) { | 1265 if (isPatch) { |
| 1265 ConstantVariableMixin originVariable = origin; | 1266 ConstantVariableMixin originVariable = origin; |
| 1266 originVariable.constant = value; | 1267 originVariable.constant = value; |
| 1267 return null; | 1268 return null; |
| 1268 } | 1269 } |
| 1269 assert(invariant(this, _constant == null || _constant == value, | 1270 assert(invariant(this, constantCache == null || constantCache == value, |
| 1270 message: "Constant has already been computed for $this.")); | 1271 message: "Constant has already been computed for $this.")); |
| 1271 _constant = value; | 1272 constantCache = value; |
| 1272 } | 1273 } |
| 1273 } | 1274 } |
| 1274 | 1275 |
| 1275 abstract class VariableElementX extends ElementX | 1276 abstract class VariableElementX extends ElementX |
| 1276 with AstElementMixin, ConstantVariableMixin | 1277 with AstElementMixin, ConstantVariableMixin |
| 1277 implements VariableElement { | 1278 implements VariableElement { |
| 1278 final Token token; | 1279 final Token token; |
| 1279 final VariableList variables; | 1280 final VariableList variables; |
| 1280 VariableDefinitions definitionsCache; | 1281 VariableDefinitions definitionsCache; |
| 1281 Expression initializerCache; | 1282 Expression initializerCache; |
| (...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1959 ConstructorElement originConstructor = origin; | 1960 ConstructorElement originConstructor = origin; |
| 1960 return originConstructor.constantConstructor; | 1961 return originConstructor.constantConstructor; |
| 1961 } | 1962 } |
| 1962 if (!isConst || isFromEnvironmentConstructor) return null; | 1963 if (!isConst || isFromEnvironmentConstructor) return null; |
| 1963 if (_constantConstructor == null) { | 1964 if (_constantConstructor == null) { |
| 1964 _constantConstructor = computeConstantConstructor(resolvedAst); | 1965 _constantConstructor = computeConstantConstructor(resolvedAst); |
| 1965 } | 1966 } |
| 1966 return _constantConstructor; | 1967 return _constantConstructor; |
| 1967 } | 1968 } |
| 1968 | 1969 |
| 1970 void set constantConstructor(ConstantConstructor value) { |
| 1971 if (isPatch) { |
| 1972 ConstantConstructorMixin originConstructor = origin; |
| 1973 originConstructor.constantConstructor = value; |
| 1974 } else { |
| 1975 assert(invariant(this, isConst, |
| 1976 message: "Constant constructor set on non-constant " |
| 1977 "constructor $this.")); |
| 1978 assert(invariant(this, !isFromEnvironmentConstructor, |
| 1979 message: "Constant constructor set on fromEnvironment " |
| 1980 "constructor: $this.")); |
| 1981 assert(invariant(this, |
| 1982 _constantConstructor == null || _constantConstructor == value, |
| 1983 message: "Constant constructor already computed for $this:" |
| 1984 "Existing: $_constantConstructor, new: $value")); |
| 1985 _constantConstructor = value; |
| 1986 } |
| 1987 } |
| 1988 |
| 1969 bool get isFromEnvironmentConstructor { | 1989 bool get isFromEnvironmentConstructor { |
| 1970 return name == 'fromEnvironment' && | 1990 return name == 'fromEnvironment' && |
| 1971 library.isDartCore && | 1991 library.isDartCore && |
| 1972 (enclosingClass.name == 'bool' || | 1992 (enclosingClass.name == 'bool' || |
| 1973 enclosingClass.name == 'int' || | 1993 enclosingClass.name == 'int' || |
| 1974 enclosingClass.name == 'String'); | 1994 enclosingClass.name == 'String'); |
| 1975 } | 1995 } |
| 1976 } | 1996 } |
| 1977 | 1997 |
| 1978 abstract class ConstructorElementX extends FunctionElementX | 1998 abstract class ConstructorElementX extends FunctionElementX |
| (...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2895 AstElement get definingElement; | 2915 AstElement get definingElement; |
| 2896 | 2916 |
| 2897 bool get hasResolvedAst => definingElement.hasTreeElements; | 2917 bool get hasResolvedAst => definingElement.hasTreeElements; |
| 2898 | 2918 |
| 2899 ResolvedAst get resolvedAst { | 2919 ResolvedAst get resolvedAst { |
| 2900 return new ResolvedAst(declaration, | 2920 return new ResolvedAst(declaration, |
| 2901 definingElement.node, definingElement.treeElements); | 2921 definingElement.node, definingElement.treeElements); |
| 2902 } | 2922 } |
| 2903 | 2923 |
| 2904 } | 2924 } |
| OLD | NEW |