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

Unified Diff: lib/compiler/implementation/elements/elements.dart

Issue 10829379: Add erroneous elements for function types and use them to allow unresolvable constructors to be han… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/compiler/implementation/resolver.dart » ('j') | lib/compiler/implementation/resolver.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/elements/elements.dart
diff --git a/lib/compiler/implementation/elements/elements.dart b/lib/compiler/implementation/elements/elements.dart
index 778084f1ac497624543c7427eeb4448360e779c7..49184f34651b8afd0da82adfd9508f6ae9b52e7d 100644
--- a/lib/compiler/implementation/elements/elements.dart
+++ b/lib/compiler/implementation/elements/elements.dart
@@ -160,6 +160,9 @@ class Element implements Hashable {
bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0;
bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0;
+ /** See [ErroneousElement] for documentation. */
+ bool isValid() => true;
ahe 2012/08/20 15:06:47 How about isErroneous instead (and reversed).
karlklose 2012/08/21 11:44:10 Done.
+
// TODO(johnniwinther): This breaks for libraries (for which enclosing
// elements are null) and is invalid for top level variable declarations for
// which the enclosing element is a VariableDeclarations and not a compilation
@@ -287,6 +290,56 @@ class Element implements Hashable {
Link<Type> get allSupertypesAndSelf() {
return allSupertypes.prepend(new InterfaceType(this));
}
+
+ static bool isInvalid(Element e) => e == null || !e.isValid();
+}
+
+/**
+ * [ErroneousElement]s are used to mark something as unresolvable, but in
ahe 2012/08/20 15:06:47 Try to keep the first line a summary of the class
karlklose 2012/08/21 11:44:10 Done.
+ * contrast to using [null], there is additional information about the error
+ * that caused the element to be unresolvable.
+ *
+ * Accessing any field or calling any method defined on [Element] except
+ * [isValid] will throw an exception.
ahe 2012/08/20 15:06:47 I don't think that is a good idea.
karlklose 2012/08/21 11:44:10 On 2012/08/20 15:06:47, ahe wrote: I added a comme
+ *
+ * Code that does not handle [ErroneousElement]s should use
+ * [Element.isInvalid(element)]
ahe 2012/08/20 15:06:47 [: Element.isInvalid(element) :]
karlklose 2012/08/21 11:44:10 Done.
+ * to check for unresolvable elements instead of
+ * [element == null].
ahe 2012/08/20 15:06:47 [: element == null :]
karlklose 2012/08/21 11:44:10 Done.
+ */
+class ErroneousElement extends Element {
+ final Message errorMessage;
+
+ ErroneousElement(this.errorMessage, Element enclosing)
+ : super(const SourceString('erroneous element'), null, enclosing);
+
+ isValid() => false;
+
+ unsupported() {
+ throw 'unsupported operation on erroneous element';
+ }
+
+ SourceString get name() => unsupported();
+ ElementKind get kind() => unsupported();
+ Link<Node> get metadata() => unsupported();
+}
+
+class ErroneousFunctionElement extends ErroneousElement
+ implements FunctionElement {
+ ErroneousFunctionElement(errorMessage, Element enclosing)
+ : super(errorMessage, enclosing);
+
+ get type() => unsupported();
+ get cachedNode() => unsupported();
+ get functionSignature() => unsupported();
+ get patch() => unsupported();
+ get defaultImplementation() => unsupported();
+ bool get isPatched() => unsupported();
+ setPatch(patch) => unsupported();
+ computeSignature(compiler) => unsupported();
+ requiredParameterCount(compiler) => unsupported();
+ optionalParameterCount(compiler) => unsupported();
+ parameterCount(copmiler) => unsupported();
}
class ContainerElement extends Element {
@@ -1293,17 +1346,17 @@ class ClassElement extends ScopeContainerElement
class Elements {
static bool isLocal(Element element) {
- return ((element !== null)
+ return !Element.isInvalid(element)
&& !element.isInstanceMember()
&& !isStaticOrTopLevelField(element)
&& !isStaticOrTopLevelFunction(element)
&& (element.kind === ElementKind.VARIABLE ||
element.kind === ElementKind.PARAMETER ||
- element.kind === ElementKind.FUNCTION));
+ element.kind === ElementKind.FUNCTION);
}
static bool isInstanceField(Element element) {
- return (element !== null)
+ return !Element.isInvalid(element)
&& element.isInstanceMember()
&& (element.kind === ElementKind.FIELD
|| element.kind === ElementKind.GETTER
@@ -1311,7 +1364,7 @@ class Elements {
}
static bool isStaticOrTopLevel(Element element) {
- return (element != null)
+ return !Element.isInvalid(element)
&& !element.isInstanceMember()
&& !element.isPrefix()
&& element.enclosingElement !== null
@@ -1333,7 +1386,7 @@ class Elements {
}
static bool isInstanceMethod(Element element) {
- return (element != null)
+ return !Element.isInvalid(element)
&& element.isInstanceMember()
&& (element.kind === ElementKind.FUNCTION);
}
« no previous file with comments | « no previous file | lib/compiler/implementation/resolver.dart » ('j') | lib/compiler/implementation/resolver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698