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

Side by Side Diff: frog/leg/elements/elements.dart

Issue 9618053: Introduce the TYPEDEF element, and use it in order to catch passing closures to the DOM. I make the… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | frog/leg/lib/js_helper.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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('../tree/tree.dart'); 7 #import('../tree/tree.dart');
8 #import('../scanner/scannerlib.dart'); 8 #import('../scanner/scannerlib.dart');
9 #import('../leg.dart'); // TODO(karlklose): we only need type. 9 #import('../leg.dart'); // TODO(karlklose): we only need type.
10 #import('../util/util.dart'); 10 #import('../util/util.dart');
(...skipping 15 matching lines...) Expand all
26 static final ElementKind FIELD_LIST = const ElementKind('field_list'); 26 static final ElementKind FIELD_LIST = const ElementKind('field_list');
27 static final ElementKind GENERATIVE_CONSTRUCTOR_BODY = 27 static final ElementKind GENERATIVE_CONSTRUCTOR_BODY =
28 const ElementKind('generative_constructor_body'); 28 const ElementKind('generative_constructor_body');
29 static final ElementKind COMPILATION_UNIT = 29 static final ElementKind COMPILATION_UNIT =
30 const ElementKind('compilation_unit'); 30 const ElementKind('compilation_unit');
31 static final ElementKind GETTER = const ElementKind('getter'); 31 static final ElementKind GETTER = const ElementKind('getter');
32 static final ElementKind SETTER = const ElementKind('setter'); 32 static final ElementKind SETTER = const ElementKind('setter');
33 static final ElementKind ABSTRACT_FIELD = const ElementKind('abstract_field'); 33 static final ElementKind ABSTRACT_FIELD = const ElementKind('abstract_field');
34 static final ElementKind LIBRARY = const ElementKind('library'); 34 static final ElementKind LIBRARY = const ElementKind('library');
35 static final ElementKind PREFIX = const ElementKind('prefix'); 35 static final ElementKind PREFIX = const ElementKind('prefix');
36 static final ElementKind TYPEDEF = const ElementKind('typedef');
36 37
37 static final ElementKind STATEMENT = const ElementKind('statement'); 38 static final ElementKind STATEMENT = const ElementKind('statement');
38 static final ElementKind LABEL = const ElementKind('label'); 39 static final ElementKind LABEL = const ElementKind('label');
39 40
40 toString() => id; 41 toString() => id;
41 } 42 }
42 43
43 class Element implements Hashable { 44 class Element implements Hashable {
44 final SourceString name; 45 final SourceString name;
45 final ElementKind kind; 46 final ElementKind kind;
(...skipping 11 matching lines...) Expand all
57 bool isFunction() => kind === ElementKind.FUNCTION; 58 bool isFunction() => kind === ElementKind.FUNCTION;
58 bool isMember() => 59 bool isMember() =>
59 enclosingElement !== null && enclosingElement.kind === ElementKind.CLASS; 60 enclosingElement !== null && enclosingElement.kind === ElementKind.CLASS;
60 bool isInstanceMember() => false; 61 bool isInstanceMember() => false;
61 bool isFactoryConstructor() => modifiers !== null && modifiers.isFactory(); 62 bool isFactoryConstructor() => modifiers !== null && modifiers.isFactory();
62 bool isGenerativeConstructor() => kind === ElementKind.GENERATIVE_CONSTRUCTOR; 63 bool isGenerativeConstructor() => kind === ElementKind.GENERATIVE_CONSTRUCTOR;
63 bool isCompilationUnit() { 64 bool isCompilationUnit() {
64 return kind === ElementKind.COMPILATION_UNIT || 65 return kind === ElementKind.COMPILATION_UNIT ||
65 kind === ElementKind.LIBRARY; 66 kind === ElementKind.LIBRARY;
66 } 67 }
68 bool isClass() => kind == ElementKind.CLASS;
67 bool isVariable() => kind === ElementKind.VARIABLE; 69 bool isVariable() => kind === ElementKind.VARIABLE;
68 bool isParameter() => kind === ElementKind.PARAMETER; 70 bool isParameter() => kind === ElementKind.PARAMETER;
69 bool isStatement() => kind === ElementKind.STATEMENT; 71 bool isStatement() => kind === ElementKind.STATEMENT;
72 bool isTypedef() => kind === ElementKind.TYPEDEF;
73 // TODO(ahe): Remove this method.
74 bool isClassOrInterfaceOrTypedef() {
75 return kind == ElementKind.CLASS || kind == ElementKind.TYPEDEF;
76 }
70 77
71 bool isAssignable() { 78 bool isAssignable() {
72 if (modifiers != null && modifiers.isFinal()) return false; 79 if (modifiers != null && modifiers.isFinal()) return false;
73 if (isFunction() || isGenerativeConstructor()) return false; 80 if (isFunction() || isGenerativeConstructor()) return false;
74 return true; 81 return true;
75 } 82 }
76 83
77 Token position() => null; 84 Token position() => null;
78 85
79 const Element(this.name, this.kind, this.enclosingElement); 86 const Element(this.name, this.kind, this.enclosingElement);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 final LibraryElement library; 198 final LibraryElement library;
192 199
193 PrefixElement(LiteralString prefix, 200 PrefixElement(LiteralString prefix,
194 LibraryElement this.library, 201 LibraryElement this.library,
195 Element enclosing) 202 Element enclosing)
196 : this.prefix = prefix, 203 : this.prefix = prefix,
197 super(prefix.dartString.source, ElementKind.PREFIX, enclosing) { 204 super(prefix.dartString.source, ElementKind.PREFIX, enclosing) {
198 } 205 }
199 } 206 }
200 207
208 class TypedefElement extends Element {
209 TypedefElement(SourceString name, Element enclosing)
210 : super(name, ElementKind.TYPEDEF, enclosing);
211 }
212
201 class VariableElement extends Element { 213 class VariableElement extends Element {
202 final VariableListElement variables; 214 final VariableListElement variables;
203 Expression cachedNode; // The send or the identifier in the variables list. 215 Expression cachedNode; // The send or the identifier in the variables list.
204 216
205 Modifiers get modifiers() => variables.modifiers; 217 Modifiers get modifiers() => variables.modifiers;
206 218
207 VariableElement(SourceString name, 219 VariableElement(SourceString name,
208 VariableListElement this.variables, 220 VariableListElement this.variables,
209 ElementKind kind, 221 ElementKind kind,
210 Element enclosing, 222 Element enclosing,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // information should be computed by the resolver. 329 // information should be computed by the resolver.
318 330
319 if (typeAnnotation == null || typeAnnotation.typeName == null) { 331 if (typeAnnotation == null || typeAnnotation.typeName == null) {
320 return compiler.types.dynamicType; 332 return compiler.types.dynamicType;
321 } 333 }
322 Identifier identifier = typeAnnotation.typeName.asIdentifier(); 334 Identifier identifier = typeAnnotation.typeName.asIdentifier();
323 if (identifier === null) { 335 if (identifier === null) {
324 compiler.cancel('library prefixes not handled', 336 compiler.cancel('library prefixes not handled',
325 node: typeAnnotation.typeName); 337 node: typeAnnotation.typeName);
326 } 338 }
327 final SourceString name = identifier.source; 339 SourceString name = identifier.source;
328 Element element = library.find(name); 340 Element element = library.find(name);
329 if (element !== null && element.kind === ElementKind.CLASS) { 341 if (element !== null) {
330 // TODO(karlklose): substitute type parameters. 342 if (element.isTypedef()) {
331 return element.computeType(compiler); 343 // TODO(ngeoffray): This is a hack to help us get support for the
344 // DOM library.
345 // TODO(ngeoffray): The list of types for the argument is wrong.
346 return new FunctionType(compiler.types.dynamicType,
347 const EmptyLink<Type>(),
348 element);
349 }
350 if (element.isClass()) {
351 // TODO(karlklose): substitute type parameters.
352 return element.computeType(compiler);
353 }
332 } 354 }
333 Type type = compiler.types.lookup(name); 355 Type type = compiler.types.lookup(name);
334 if (type === null) { 356 if (type === null) {
335 type = compiler.types.dynamicType; 357 type = compiler.types.dynamicType;
336 } 358 }
337 return type; 359 return type;
338 } 360 }
339 361
340 class FunctionParameters { 362 class FunctionParameters {
341 Link<Element> requiredParameters; 363 Link<Element> requiredParameters;
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 806
785 LabelElement addLabel(Identifier label, String labelName) { 807 LabelElement addLabel(Identifier label, String labelName) {
786 LabelElement result = new LabelElement(label, labelName, this, 808 LabelElement result = new LabelElement(label, labelName, this,
787 enclosingElement); 809 enclosingElement);
788 labels = labels.prepend(result); 810 labels = labels.prepend(result);
789 return result; 811 return result;
790 } 812 }
791 813
792 Node parseNode(DiagnosticListener l) => statement; 814 Node parseNode(DiagnosticListener l) => statement;
793 } 815 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/lib/js_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698