| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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; | 5 library elements; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/resolution.dart' show Resolution; | 8 import '../common/resolution.dart' show Resolution; |
| 9 import '../compiler.dart' show Compiler; | |
| 10 import '../constants/constructors.dart'; | 9 import '../constants/constructors.dart'; |
| 11 import '../constants/expressions.dart'; | 10 import '../constants/expressions.dart'; |
| 12 import '../core_types.dart' show CommonElements; | 11 import '../core_types.dart' show CommonElements; |
| 13 import '../ordered_typeset.dart' show OrderedTypeSet; | 12 import '../ordered_typeset.dart' show OrderedTypeSet; |
| 14 import '../resolution/scope.dart' show Scope; | 13 import '../resolution/scope.dart' show Scope; |
| 15 import '../resolution/tree_elements.dart' show TreeElements; | 14 import '../resolution/tree_elements.dart' show TreeElements; |
| 16 import '../script.dart'; | 15 import '../script.dart'; |
| 17 import '../tokens/token.dart' | 16 import '../tokens/token.dart' |
| 18 show Token, isUserDefinableOperator, isMinusOperator; | 17 show Token, isUserDefinableOperator, isMinusOperator; |
| 19 import '../tree/tree.dart'; | 18 import '../tree/tree.dart'; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 static const ElementKind AMBIGUOUS = | 110 static const ElementKind AMBIGUOUS = |
| 112 const ElementKind('ambiguous', ElementCategory.NONE); | 111 const ElementKind('ambiguous', ElementCategory.NONE); |
| 113 static const ElementKind WARN_ON_USE = | 112 static const ElementKind WARN_ON_USE = |
| 114 const ElementKind('warn_on_use', ElementCategory.NONE); | 113 const ElementKind('warn_on_use', ElementCategory.NONE); |
| 115 static const ElementKind ERROR = | 114 static const ElementKind ERROR = |
| 116 const ElementKind('error', ElementCategory.NONE); | 115 const ElementKind('error', ElementCategory.NONE); |
| 117 | 116 |
| 118 toString() => id; | 117 toString() => id; |
| 119 } | 118 } |
| 120 | 119 |
| 121 /// Abstract interface for entities. | |
| 122 /// | |
| 123 /// Implement this directly if the entity is not a Dart language entity. | |
| 124 /// Entities defined within the Dart language should implement [Element]. | |
| 125 /// | |
| 126 /// For instance, the JavaScript backend need to create synthetic variables for | |
| 127 /// calling intercepted classes and such variables do not correspond to an | |
| 128 /// entity in the Dart source code nor in the terminology of the Dart language | |
| 129 /// and should therefore implement [Entity] directly. | |
| 130 abstract class Entity implements Spannable { | |
| 131 String get name; | |
| 132 } | |
| 133 | |
| 134 /** | 120 /** |
| 135 * A declared element of a program. | 121 * A declared element of a program. |
| 136 * | 122 * |
| 137 * The declared elements of a program include classes, methods, | 123 * The declared elements of a program include classes, methods, |
| 138 * fields, variables, parameters, etc. | 124 * fields, variables, parameters, etc. |
| 139 * | 125 * |
| 140 * Sometimes it makes sense to construct "synthetic" elements that | 126 * Sometimes it makes sense to construct "synthetic" elements that |
| 141 * have not been declared anywhere in a program, for example, there | 127 * have not been declared anywhere in a program, for example, there |
| 142 * are elements corresponding to "dynamic", "null", and unresolved | 128 * are elements corresponding to "dynamic", "null", and unresolved |
| 143 * references. | 129 * references. |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 implements ExecutableElement, MemberEntity { | 1150 implements ExecutableElement, MemberEntity { |
| 1165 /// The local functions defined within this member. | 1151 /// The local functions defined within this member. |
| 1166 List<FunctionElement> get nestedClosures; | 1152 List<FunctionElement> get nestedClosures; |
| 1167 | 1153 |
| 1168 /// The name of this member, taking privacy into account. | 1154 /// The name of this member, taking privacy into account. |
| 1169 Name get memberName; | 1155 Name get memberName; |
| 1170 } | 1156 } |
| 1171 | 1157 |
| 1172 /// A function, variable or parameter defined in an executable context. | 1158 /// A function, variable or parameter defined in an executable context. |
| 1173 abstract class LocalElement extends Element | 1159 abstract class LocalElement extends Element |
| 1174 implements AstElement, TypedElement, Local {} | 1160 implements AstElement, TypedElement, Local { |
| 1161 ExecutableElement get executableContext; |
| 1162 } |
| 1175 | 1163 |
| 1176 /// A top level, static or instance field, a formal parameter or local variable. | 1164 /// A top level, static or instance field, a formal parameter or local variable. |
| 1177 abstract class VariableElement extends ExecutableElement { | 1165 abstract class VariableElement extends ExecutableElement { |
| 1178 @override | 1166 @override |
| 1179 VariableDefinitions get node; | 1167 VariableDefinitions get node; |
| 1180 | 1168 |
| 1181 Expression get initializer; | 1169 Expression get initializer; |
| 1182 | 1170 |
| 1183 bool get hasConstant; | 1171 bool get hasConstant; |
| 1184 | 1172 |
| 1185 /// The constant expression defining the (initial) value of the variable. | 1173 /// The constant expression defining the (initial) value of the variable. |
| 1186 /// | 1174 /// |
| 1187 /// If the variable is `const` the value is always non-null, possibly an | 1175 /// If the variable is `const` the value is always non-null, possibly an |
| 1188 /// [ErroneousConstantExpression], otherwise, the value is null when the | 1176 /// [ErroneousConstantExpression], otherwise, the value is null when the |
| 1189 /// initializer isn't a constant expression. | 1177 /// initializer isn't a constant expression. |
| 1190 ConstantExpression get constant; | 1178 ConstantExpression get constant; |
| 1191 } | 1179 } |
| 1192 | 1180 |
| 1193 /// An entity that defines a local entity (memory slot) in generated code. | |
| 1194 /// | |
| 1195 /// Parameters, local variables and local functions (can) define local entity | |
| 1196 /// and thus implement [Local] through [LocalElement]. For non-element locals, | |
| 1197 /// like `this` and boxes, specialized [Local] classes are created. | |
| 1198 /// | |
| 1199 /// Type variables can introduce locals in factories and constructors | |
| 1200 /// but since one type variable can introduce different locals in different | |
| 1201 /// factories and constructors it is not itself a [Local] but instead | |
| 1202 /// a non-element [Local] is created through a specialized class. | |
| 1203 // TODO(johnniwinther): Should [Local] have `isAssignable` or `type`? | |
| 1204 // TODO(johnniwinther): Move this to 'entities.dart' when it does not refer | |
| 1205 // to [ExecutableElement]. | |
| 1206 abstract class Local extends Entity { | |
| 1207 /// The context in which this local is defined. | |
| 1208 ExecutableElement get executableContext; | |
| 1209 } | |
| 1210 | |
| 1211 /// A variable or parameter that is local to an executable context. | 1181 /// A variable or parameter that is local to an executable context. |
| 1212 /// | 1182 /// |
| 1213 /// The executable context is the [ExecutableElement] in which this variable | 1183 /// The executable context is the [ExecutableElement] in which this variable |
| 1214 /// is defined. | 1184 /// is defined. |
| 1215 abstract class LocalVariableElement extends VariableElement | 1185 abstract class LocalVariableElement extends VariableElement |
| 1216 implements LocalElement {} | 1186 implements LocalElement {} |
| 1217 | 1187 |
| 1218 /// A top-level, static or instance field. | 1188 /// A top-level, static or instance field. |
| 1219 abstract class FieldElement extends VariableElement | 1189 abstract class FieldElement extends VariableElement |
| 1220 implements MemberElement, FieldEntity {} | 1190 implements MemberElement, FieldEntity {} |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2045 /// by a field. | 2015 /// by a field. |
| 2046 bool get isDeclaredByField; | 2016 bool get isDeclaredByField; |
| 2047 | 2017 |
| 2048 /// Returns `true` if this member is abstract. | 2018 /// Returns `true` if this member is abstract. |
| 2049 bool get isAbstract; | 2019 bool get isAbstract; |
| 2050 | 2020 |
| 2051 /// If abstract, [implementation] points to the overridden concrete member, | 2021 /// If abstract, [implementation] points to the overridden concrete member, |
| 2052 /// if any. Otherwise [implementation] points to the member itself. | 2022 /// if any. Otherwise [implementation] points to the member itself. |
| 2053 Member get implementation; | 2023 Member get implementation; |
| 2054 } | 2024 } |
| OLD | NEW |