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

Unified Diff: dart/frog/leg/elements/elements.dart

Issue 9634008: Introduce element categories and move resolver towards being more compositional. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 9 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 | dart/frog/leg/resolver.dart » ('j') | dart/frog/leg/resolver.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/elements/elements.dart
diff --git a/dart/frog/leg/elements/elements.dart b/dart/frog/leg/elements/elements.dart
index 98e17dcad99eea8d6c6c29d7f1bde769605bfafb..c8b046a5efedf920dae32d4deda07b23cb3b81ad 100644
--- a/dart/frog/leg/elements/elements.dart
+++ b/dart/frog/leg/elements/elements.dart
@@ -9,34 +9,74 @@
#import('../leg.dart'); // TODO(karlklose): we only need type.
#import('../util/util.dart');
-class ElementKind {
- final String id;
+class ElementCategory {
+ static final int NONE = 0;
ngeoffray 2012/03/08 14:00:45 I would add a comment on what has NONE category (g
ahe 2012/03/08 18:13:40 Done.
+
+ /** Field, parameter, or variable. */
+ static final int SLOT = 1;
+
+ /** Function, method, or foreign function. */
+ static final int FUNCTION = 2;
+
+ static final int CLASS = 4;
- const ElementKind(String this.id);
+ static final int PREFIX = 8;
+
+ /** Constructor or factory. */
+ static final int FACTORY = 16;
+
+ static final int ALIAS = 32;
+
+ static final int SUPER = 64;
+
+ static final int IMPLIES_TYPE = CLASS | ALIAS;
+}
- static final ElementKind VARIABLE = const ElementKind('variable');
- static final ElementKind PARAMETER = const ElementKind('parameter');
- static final ElementKind FUNCTION = const ElementKind('function');
- static final ElementKind CLASS = const ElementKind('class');
- static final ElementKind FOREIGN = const ElementKind('foreign');
+class ElementKind {
+ final String id;
+ final int category;
+
+ const ElementKind(String this.id, this.category);
+
+ static final ElementKind VARIABLE =
+ const ElementKind('variable', ElementCategory.SLOT);
+ static final ElementKind PARAMETER =
+ const ElementKind('parameter', ElementCategory.SLOT);
+ static final ElementKind FUNCTION =
+ const ElementKind('function', ElementCategory.FUNCTION);
+ static final ElementKind CLASS =
+ const ElementKind('class', ElementCategory.CLASS);
+ static final ElementKind FOREIGN =
+ const ElementKind('foreign', ElementCategory.FUNCTION);
static final ElementKind GENERATIVE_CONSTRUCTOR =
- const ElementKind('generative_constructor');
- static final ElementKind FIELD = const ElementKind('field');
- static final ElementKind VARIABLE_LIST = const ElementKind('variable_list');
- static final ElementKind FIELD_LIST = const ElementKind('field_list');
+ const ElementKind('generative_constructor', ElementCategory.FACTORY);
+ static final ElementKind FIELD =
+ const ElementKind('field', ElementCategory.SLOT);
+ static final ElementKind VARIABLE_LIST =
+ const ElementKind('variable_list', ElementCategory.NONE);
+ static final ElementKind FIELD_LIST =
+ const ElementKind('field_list', ElementCategory.NONE);
static final ElementKind GENERATIVE_CONSTRUCTOR_BODY =
- const ElementKind('generative_constructor_body');
+ const ElementKind('generative_constructor_body', ElementCategory.NONE);
static final ElementKind COMPILATION_UNIT =
- const ElementKind('compilation_unit');
- static final ElementKind GETTER = const ElementKind('getter');
- static final ElementKind SETTER = const ElementKind('setter');
- static final ElementKind ABSTRACT_FIELD = const ElementKind('abstract_field');
- static final ElementKind LIBRARY = const ElementKind('library');
- static final ElementKind PREFIX = const ElementKind('prefix');
- static final ElementKind TYPEDEF = const ElementKind('typedef');
-
- static final ElementKind STATEMENT = const ElementKind('statement');
- static final ElementKind LABEL = const ElementKind('label');
+ const ElementKind('compilation_unit', ElementCategory.NONE);
+ static final ElementKind GETTER =
+ const ElementKind('getter', ElementCategory.SLOT); // TODO(ahe): Sb. NONE.
+ static final ElementKind SETTER =
+ const ElementKind('setter', ElementCategory.SLOT); // TODO(ahe): Sb. NONE.
+ static final ElementKind ABSTRACT_FIELD =
+ const ElementKind('abstract_field', ElementCategory.SLOT);
+ static final ElementKind LIBRARY =
+ const ElementKind('library', ElementCategory.NONE);
+ static final ElementKind PREFIX =
+ const ElementKind('prefix', ElementCategory.PREFIX);
+ static final ElementKind TYPEDEF =
+ const ElementKind('typedef', ElementCategory.ALIAS);
+
+ static final ElementKind STATEMENT =
+ const ElementKind('statement', ElementCategory.NONE);
+ static final ElementKind LABEL =
+ const ElementKind('label', ElementCategory.NONE);
toString() => id;
}
@@ -70,10 +110,7 @@ class Element implements Hashable {
bool isParameter() => kind === ElementKind.PARAMETER;
bool isStatement() => kind === ElementKind.STATEMENT;
bool isTypedef() => kind === ElementKind.TYPEDEF;
- // TODO(ahe): Remove this method.
- bool isClassOrInterfaceOrTypedef() {
- return kind == ElementKind.CLASS || kind == ElementKind.TYPEDEF;
- }
+ bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0;
bool isAssignable() {
if (modifiers != null && modifiers.isFinal()) return false;
@@ -201,8 +238,9 @@ class PrefixElement extends Element {
LibraryElement this.library,
Element enclosing)
: this.prefix = prefix,
- super(prefix.dartString.source, ElementKind.PREFIX, enclosing) {
- }
+ super(prefix.dartString.source, ElementKind.PREFIX, enclosing);
+
+ lookupLocalMember(SourceString name) => library.lookupLocalMember(name);
}
class TypedefElement extends Element {
@@ -520,7 +558,7 @@ class SynthesizedConstructorElement extends FunctionElement {
Node parseNode(DiagnosticListener listener) {
if (cachedNode != null) return cachedNode;
cachedNode = new FunctionExpression(
- new Identifier.synthetic(''),
+ new Identifier(enclosingElement.position()),
new NodeList.empty(),
new Block(new NodeList.empty()),
null, null, null, null);
@@ -618,6 +656,14 @@ class ClassElement extends ContainerElement {
return localMembers[memberName];
}
+ Element lookupSuperMember(SourceString name) {
+ for (ClassElement s = superclass; s != null; s = s.superclass) {
+ Element e = s.lookupLocalMember(name);
+ if (e !== null) return e;
+ }
+ return null;
+ }
+
Element lookupConstructor(SourceString className,
[SourceString constructorName =
const SourceString(''),
« no previous file with comments | « no previous file | dart/frog/leg/resolver.dart » ('j') | dart/frog/leg/resolver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698