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

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 isClassOrInterfaceOrAlias() {
kasperl 2012/03/07 10:25:59 isClassOrInterfaceOrTypedef? Maybe we should have
ngeoffray 2012/03/07 10:43:48 Peter prefered Alias, that was fine by me, but now
73 return kind == ElementKind.CLASS || kind == ElementKind.TYPEDEF;
74 }
70 75
71 bool isAssignable() { 76 bool isAssignable() {
72 if (modifiers != null && modifiers.isFinal()) return false; 77 if (modifiers != null && modifiers.isFinal()) return false;
73 if (isFunction() || isGenerativeConstructor()) return false; 78 if (isFunction() || isGenerativeConstructor()) return false;
74 return true; 79 return true;
75 } 80 }
76 81
77 Token position() => null; 82 Token position() => null;
78 83
79 const Element(this.name, this.kind, this.enclosingElement); 84 const Element(this.name, this.kind, this.enclosingElement);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 final LibraryElement library; 196 final LibraryElement library;
192 197
193 PrefixElement(LiteralString prefix, 198 PrefixElement(LiteralString prefix,
194 LibraryElement this.library, 199 LibraryElement this.library,
195 Element enclosing) 200 Element enclosing)
196 : this.prefix = prefix, 201 : this.prefix = prefix,
197 super(prefix.dartString.source, ElementKind.PREFIX, enclosing) { 202 super(prefix.dartString.source, ElementKind.PREFIX, enclosing) {
198 } 203 }
199 } 204 }
200 205
206 class TypedefElement extends Element {
207 TypedefElement(SourceString name, Element enclosing)
208 : super(name, ElementKind.TYPEDEF, enclosing);
209 }
210
201 class VariableElement extends Element { 211 class VariableElement extends Element {
202 final VariableListElement variables; 212 final VariableListElement variables;
203 Expression cachedNode; // The send or the identifier in the variables list. 213 Expression cachedNode; // The send or the identifier in the variables list.
204 214
205 Modifiers get modifiers() => variables.modifiers; 215 Modifiers get modifiers() => variables.modifiers;
206 216
207 VariableElement(SourceString name, 217 VariableElement(SourceString name,
208 VariableListElement this.variables, 218 VariableListElement this.variables,
209 ElementKind kind, 219 ElementKind kind,
210 Element enclosing, 220 Element enclosing,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // information should be computed by the resolver. 327 // information should be computed by the resolver.
318 328
319 if (typeAnnotation == null || typeAnnotation.typeName == null) { 329 if (typeAnnotation == null || typeAnnotation.typeName == null) {
320 return compiler.types.dynamicType; 330 return compiler.types.dynamicType;
321 } 331 }
322 Identifier identifier = typeAnnotation.typeName.asIdentifier(); 332 Identifier identifier = typeAnnotation.typeName.asIdentifier();
323 if (identifier === null) { 333 if (identifier === null) {
324 compiler.cancel('library prefixes not handled', 334 compiler.cancel('library prefixes not handled',
325 node: typeAnnotation.typeName); 335 node: typeAnnotation.typeName);
326 } 336 }
327 final SourceString name = identifier.source; 337 SourceString name = identifier.source;
328 Element element = library.find(name); 338 Element element = library.find(name);
329 if (element !== null && element.kind === ElementKind.CLASS) { 339 if (element !== null) {
330 // TODO(karlklose): substitute type parameters. 340 if (element.kind === ElementKind.TYPEDEF) {
kasperl 2012/03/07 10:25:59 isTypedef()
ngeoffray 2012/03/07 10:43:48 Done.
331 return element.computeType(compiler); 341 // TODO(ngeoffray): This is a hack to help us get support for the
342 // DOM library.
343 return new FunctionType(compiler.types.dynamicType,
344 const EmptyLink<Type>(),
345 element);
346 }
347 if (element.kind === ElementKind.CLASS) {
kasperl 2012/03/07 10:25:59 isClass()
ngeoffray 2012/03/07 10:43:48 Done.
348 // TODO(karlklose): substitute type parameters.
349 return element.computeType(compiler);
350 }
332 } 351 }
333 Type type = compiler.types.lookup(name); 352 Type type = compiler.types.lookup(name);
334 if (type === null) { 353 if (type === null) {
335 type = compiler.types.dynamicType; 354 type = compiler.types.dynamicType;
336 } 355 }
337 return type; 356 return type;
338 } 357 }
339 358
340 class FunctionParameters { 359 class FunctionParameters {
341 Link<Element> requiredParameters; 360 Link<Element> requiredParameters;
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 803
785 LabelElement addLabel(Identifier label, String labelName) { 804 LabelElement addLabel(Identifier label, String labelName) {
786 LabelElement result = new LabelElement(label, labelName, this, 805 LabelElement result = new LabelElement(label, labelName, this,
787 enclosingElement); 806 enclosingElement);
788 labels = labels.prepend(result); 807 labels = labels.prepend(result);
789 return result; 808 return result;
790 } 809 }
791 810
792 Node parseNode(DiagnosticListener l) => statement; 811 Node parseNode(DiagnosticListener l) => statement;
793 } 812 }
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