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

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

Issue 10879006: Create an outline of metadata API in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
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 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 #import('../tree/tree.dart'); 9 #import('../tree/tree.dart');
10 #import('../scanner/scannerlib.dart'); 10 #import('../scanner/scannerlib.dart');
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 static final ElementKind VOID = 99 static final ElementKind VOID =
100 const ElementKind('void', ElementCategory.NONE); 100 const ElementKind('void', ElementCategory.NONE);
101 101
102 toString() => id; 102 toString() => id;
103 } 103 }
104 104
105 class Element implements Hashable { 105 class Element implements Hashable {
106 final SourceString name; 106 final SourceString name;
107 final ElementKind kind; 107 final ElementKind kind;
108 final Element enclosingElement; 108 final Element enclosingElement;
109 Link<Node> metadata = const EmptyLink<Node>(); 109 Link<MetadataAnnotation> metadata = const EmptyLink<MetadataAnnotation>();
110 110
111 Element(this.name, this.kind, this.enclosingElement) { 111 Element(this.name, this.kind, this.enclosingElement) {
112 assert(getLibrary() !== null); 112 assert(getLibrary() !== null);
113 } 113 }
114 114
115 Modifiers get modifiers => null; 115 Modifiers get modifiers => null;
116 116
117 Node parseNode(DiagnosticListener listener) { 117 Node parseNode(DiagnosticListener listener) {
118 listener.cancel("Internal Error: $this.parseNode", token: position()); 118 listener.cancel("Internal Error: $this.parseNode", token: position());
119 } 119 }
120 120
121 Type computeType(Compiler compiler) { 121 Type computeType(Compiler compiler) {
122 compiler.internalError("$this.computeType.", token: position()); 122 compiler.internalError("$this.computeType.", token: position());
123 } 123 }
124 124
125 void addMetadata(Node node) { 125 void addMetadata(MetadataAnnotation annotation) {
126 metadata = metadata.prepend(node); 126 metadata = metadata.prepend(annotation);
127 } 127 }
128 128
129 bool isFunction() => kind === ElementKind.FUNCTION; 129 bool isFunction() => kind === ElementKind.FUNCTION;
130 bool isConstructor() => isFactoryConstructor() || isGenerativeConstructor(); 130 bool isConstructor() => isFactoryConstructor() || isGenerativeConstructor();
131 bool isClosure() => false; 131 bool isClosure() => false;
132 bool isMember() { 132 bool isMember() {
133 // Check that this element is defined in the scope of a Class. 133 // Check that this element is defined in the scope of a Class.
134 Element enclosing = enclosingElement; 134 Element enclosing = enclosingElement;
135 if (enclosing !== null && 135 if (enclosing !== null &&
136 enclosing.kind === ElementKind.COMPILATION_UNIT_OVERRIDE) { 136 enclosing.kind === ElementKind.COMPILATION_UNIT_OVERRIDE) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 : super(const SourceString('erroneous element'), null, enclosing); 315 : super(const SourceString('erroneous element'), null, enclosing);
316 316
317 isErroneous() => true; 317 isErroneous() => true;
318 318
319 unsupported() { 319 unsupported() {
320 throw 'unsupported operation on erroneous element'; 320 throw 'unsupported operation on erroneous element';
321 } 321 }
322 322
323 SourceString get name => unsupported(); 323 SourceString get name => unsupported();
324 ElementKind get kind => unsupported(); 324 ElementKind get kind => unsupported();
325 Link<Node> get metadata => unsupported(); 325 Link<MetadataAnnotation> get metadata => unsupported();
326 } 326 }
327 327
328 class ErroneousFunctionElement extends ErroneousElement 328 class ErroneousFunctionElement extends ErroneousElement
329 implements FunctionElement { 329 implements FunctionElement {
330 ErroneousFunctionElement(errorMessage, Element enclosing) 330 ErroneousFunctionElement(errorMessage, Element enclosing)
331 : super(errorMessage, enclosing); 331 : super(errorMessage, enclosing);
332 332
333 get type => unsupported(); 333 get type => unsupported();
334 get cachedNode => unsupported(); 334 get cachedNode => unsupported();
335 get functionSignature => unsupported(); 335 get functionSignature => unsupported();
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 String toString() => "${enclosingElement.toString()}.${name.slowToString()}"; 1559 String toString() => "${enclosingElement.toString()}.${name.slowToString()}";
1560 1560
1561 Token position() => cachedNode.getBeginToken(); 1561 Token position() => cachedNode.getBeginToken();
1562 1562
1563 TypeVariableElement cloneTo(Element enclosing, DiagnosticListener listener) { 1563 TypeVariableElement cloneTo(Element enclosing, DiagnosticListener listener) {
1564 TypeVariableElement result = 1564 TypeVariableElement result =
1565 new TypeVariableElement(name, enclosing, cachedNode, type, bound); 1565 new TypeVariableElement(name, enclosing, cachedNode, type, bound);
1566 return result; 1566 return result;
1567 } 1567 }
1568 } 1568 }
1569
1570 /**
1571 * A single metadata annotation.
1572 *
1573 * For example, consider:
1574 *
1575 * [:
1576 * class Data {
1577 * const Data();
1578 * }
1579 *
1580 * const data = const Data();
1581 *
1582 * @data
1583 * class Foo {}
1584 *
1585 * @data @data
1586 * class Bar {}
1587 * :]
1588 *
1589 * In this example, there are three instances of [MetadataAnnotation]
1590 * and they correspond each to a location in the source code where
1591 * there is an at-sign, '@'. The [value] of each of these instances
1592 * are the same compile-time constant, [: const Data() :].
1593 *
1594 * The mirror system does not have a concept matching this class.
1595 */
1596 class MetadataAnnotation {
1597 /**
1598 * The compile-time constant which this annotation resolves to.
1599 * In the mirror system, this would be an object mirror.
1600 */
1601 abstract Constant get value();
1602
1603 // TODO(ahe): Add more functionality as needed.
1604 }
OLDNEW
« no previous file with comments | « dart/lib/compiler/implementation/compiler.dart ('k') | dart/lib/compiler/implementation/patch_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698