Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/elements/elements.dart

Issue 11416144: Produce run-time error when type parameters are accessed from static context. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed dart2dart unchcked tests. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 'dart:uri'; 7 import 'dart:uri';
8 8
9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed. 9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed.
10 import '../../compiler.dart' as api_e; 10 import '../../compiler.dart' as api_e;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 const ElementKind('statement', ElementCategory.NONE); 113 const ElementKind('statement', ElementCategory.NONE);
114 static const ElementKind LABEL = 114 static const ElementKind LABEL =
115 const ElementKind('label', ElementCategory.NONE); 115 const ElementKind('label', ElementCategory.NONE);
116 static const ElementKind VOID = 116 static const ElementKind VOID =
117 const ElementKind('void', ElementCategory.NONE); 117 const ElementKind('void', ElementCategory.NONE);
118 118
119 static const ElementKind AMBIGUOUS = 119 static const ElementKind AMBIGUOUS =
120 const ElementKind('ambiguous', ElementCategory.NONE); 120 const ElementKind('ambiguous', ElementCategory.NONE);
121 static const ElementKind ERROR = 121 static const ElementKind ERROR =
122 const ElementKind('error', ElementCategory.NONE); 122 const ElementKind('error', ElementCategory.NONE);
123 static const ElementKind MALFORMED_TYPE =
124 const ElementKind('malformed', ElementCategory.NONE);
123 125
124 toString() => id; 126 toString() => id;
125 } 127 }
126 128
127 class Element implements Spannable { 129 class Element implements Spannable {
128 static int elementHashCode = 0; 130 static int elementHashCode = 0;
129 131
130 final SourceString name; 132 final SourceString name;
131 final ElementKind kind; 133 final ElementKind kind;
132 final Element enclosingElement; 134 final Element enclosingElement;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 bool isLibrary() => identical(kind, ElementKind.LIBRARY); 195 bool isLibrary() => identical(kind, ElementKind.LIBRARY);
194 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0; 196 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0;
195 bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0; 197 bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0;
196 198
197 /** See [ErroneousElement] for documentation. */ 199 /** See [ErroneousElement] for documentation. */
198 bool isErroneous() => false; 200 bool isErroneous() => false;
199 201
200 /** See [AmbiguousElement] for documentation. */ 202 /** See [AmbiguousElement] for documentation. */
201 bool isAmbiguous() => false; 203 bool isAmbiguous() => false;
202 204
205 bool isMalformed() => false;
206
203 /** 207 /**
204 * Is [:true:] if this element has a corresponding patch. 208 * Is [:true:] if this element has a corresponding patch.
205 * 209 *
206 * If [:true:] this element has a non-null [patch] field. 210 * If [:true:] this element has a non-null [patch] field.
207 * 211 *
208 * See [:patch_parser.dart:] for a description of the terminology. 212 * See [:patch_parser.dart:] for a description of the terminology.
209 */ 213 */
210 bool get isPatched => false; 214 bool get isPatched => false;
211 215
212 /** 216 /**
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 class VoidElement extends Element { 1316 class VoidElement extends Element {
1313 VoidElement(Element enclosing) 1317 VoidElement(Element enclosing)
1314 : super(const SourceString('void'), ElementKind.VOID, enclosing); 1318 : super(const SourceString('void'), ElementKind.VOID, enclosing);
1315 DartType computeType(compiler) => compiler.types.voidType; 1319 DartType computeType(compiler) => compiler.types.voidType;
1316 Node parseNode(_) { 1320 Node parseNode(_) {
1317 throw 'internal error: parseNode on void'; 1321 throw 'internal error: parseNode on void';
1318 } 1322 }
1319 bool impliesType() => true; 1323 bool impliesType() => true;
1320 } 1324 }
1321 1325
1326 class MalformedTypeElement extends Element {
1327 final TypeAnnotation type;
ahe 2012/11/22 12:41:30 This is an ast node. Do we assume that enclosing
ahe 2012/11/22 12:41:30 Separate field from constructor with a new line.
aam-me 2012/11/23 02:16:47 Currently in both cases when MalformedTypEelement
ahe 2012/11/23 06:16:13 All AST nodes and tokens record a character offset
aam-me 2012/11/23 14:02:27 I see. In our case "enclosing" is either class ele
ahe 2012/11/23 15:26:10 That makes sense. But we have to watch out for Jo
1328 MalformedTypeElement(this.type, Element enclosing)
1329 : super(const SourceString('malformed'),
1330 ElementKind.MALFORMED_TYPE,
1331 enclosing);
ahe 2012/11/22 12:41:30 Add newline.
aam-me 2012/11/23 02:16:47 Done.
1332 DartType computeType(compiler) => compiler.types.malformedType;
ahe 2012/11/22 12:41:30 Ditto.
aam-me 2012/11/23 02:16:47 Done.
1333 Node parseNode(_) => type;
ahe 2012/11/22 12:41:30 Ditto.
aam-me 2012/11/23 02:16:47 Done.
1334 bool impliesType() => true;
1335
1336 bool isMalformed() => true;
1337 }
1338
1322 /** 1339 /**
1323 * [TypeDeclarationElement] defines the common interface for class/interface 1340 * [TypeDeclarationElement] defines the common interface for class/interface
1324 * declarations and typedefs. 1341 * declarations and typedefs.
1325 */ 1342 */
1326 abstract class TypeDeclarationElement implements Element { 1343 abstract class TypeDeclarationElement implements Element {
1327 // TODO(johnniwinther): This class should eventually be a mixin. 1344 // TODO(johnniwinther): This class should eventually be a mixin.
1328 1345
1329 /** 1346 /**
1330 * The type variables declared on this declaration. The type variables are not 1347 * The type variables declared on this declaration. The type variables are not
1331 * available until the type of the element has been computed through 1348 * available until the type of the element has been computed through
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 return 'patch ${super.toString()}'; 1734 return 'patch ${super.toString()}';
1718 } else if (patch != null) { 1735 } else if (patch != null) {
1719 return 'origin ${super.toString()}'; 1736 return 'origin ${super.toString()}';
1720 } else { 1737 } else {
1721 return super.toString(); 1738 return super.toString();
1722 } 1739 }
1723 } 1740 }
1724 } 1741 }
1725 1742
1726 class Elements { 1743 class Elements {
1727 static bool isUnresolved(Element e) => e == null || e.isErroneous(); 1744 static bool isUnresolved(Element e) => e == null || e.isErroneous() || e.isMal formed();
ahe 2012/11/22 12:41:30 Long line. As a matter of style, I then prefer to
aam-me 2012/11/23 02:16:47 Done.
1728 static bool isErroneousElement(Element e) => e != null && e.isErroneous(); 1745 static bool isErroneousElement(Element e) => e != null && e.isErroneous();
1746 static bool isMalformedElement(Element e) => e != null && e.isMalformed();
1729 1747
1730 static bool isClass(Element e) => e != null && e.kind == ElementKind.CLASS; 1748 static bool isClass(Element e) => e != null && e.kind == ElementKind.CLASS;
1731 static bool isTypedef(Element e) { 1749 static bool isTypedef(Element e) {
1732 return e != null && e.kind == ElementKind.TYPEDEF; 1750 return e != null && e.kind == ElementKind.TYPEDEF;
1733 } 1751 }
1734 1752
1735 static bool isLocal(Element element) { 1753 static bool isLocal(Element element) {
1736 return !Elements.isUnresolved(element) 1754 return !Elements.isUnresolved(element)
1737 && !element.isInstanceMember() 1755 && !element.isInstanceMember()
1738 && !isStaticOrTopLevelField(element) 1756 && !isStaticOrTopLevelField(element)
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
2051 2069
2052 MetadataAnnotation ensureResolved(Compiler compiler) { 2070 MetadataAnnotation ensureResolved(Compiler compiler) {
2053 if (resolutionState == STATE_NOT_STARTED) { 2071 if (resolutionState == STATE_NOT_STARTED) {
2054 compiler.resolver.resolveMetadataAnnotation(this); 2072 compiler.resolver.resolveMetadataAnnotation(this);
2055 } 2073 }
2056 return this; 2074 return this;
2057 } 2075 }
2058 2076
2059 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 2077 String toString() => 'MetadataAnnotation($value, $resolutionState)';
2060 } 2078 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698