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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/elements/modelx.dart

Issue 14168003: Implement implicit constructors in mixin applications. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove debug code and rebase Created 7 years, 8 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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.modelx; 5 library elements.modelx;
6 6
7 import 'dart:uri'; 7 import 'dart:uri';
8 import 'dart:collection' show LinkedHashMap; 8 import 'dart:collection' show LinkedHashMap;
9 9
10 import 'elements.dart'; 10 import 'elements.dart';
(...skipping 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 new NodeList.empty(), 1281 new NodeList.empty(),
1282 new Block(new NodeList.empty()), 1282 new Block(new NodeList.empty()),
1283 null, Modifiers.EMPTY, null, null); 1283 null, Modifiers.EMPTY, null, null);
1284 } 1284 }
1285 1285
1286 bool get isSynthesized => true; 1286 bool get isSynthesized => true;
1287 1287
1288 Token position() => enclosingElement.position(); 1288 Token position() => enclosingElement.position();
1289 } 1289 }
1290 1290
1291 /**
1292 * A synthetic constructor that directly forwards to a constructor in the super
1293 * class of a mixin application.
1294 *
1295 * In a mixin application `Base with M`, any constructor defined in `Base` is
1296 * available as if they were a constructor defined in the mixin application with
1297 * the same formal parameters that calls the constructor in the super class via
1298 * a `super` initializer (see Ch. 9.1 in the language specification).
1299 */
1300 class ForwardingConstructorElementX extends FunctionElementX
1301 implements ForwardingConstructorElement {
1302 final FunctionElement superConstructor;
1303
1304 ForwardingConstructorElementX(SourceString name,
1305 FunctionElement superConstructor,
1306 Element enclosing)
1307 : super(name, superConstructor.kind, superConstructor.modifiers, enclosing),
1308 this.superConstructor = superConstructor;
1309
1310 parseNode(compiler) { throw 'parseNode in synthetic constructor forward.'; }
ahe 2013/04/15 13:36:46 compiler.internalErrorOnElement
karlklose 2013/04/25 11:25:53 Removed.
1311
1312 get declaration => this;
1313
1314 get implementation => this;
1315
1316 get defaultImplementation => this;
1317
1318 FunctionSignature computeSignature(compiler) {
1319 return superConstructor.computeSignature(compiler);
1320 }
1321
1322 Token position() => superConstructor.position();
ahe 2013/04/15 13:36:46 I'm not sure this is a good position. Wouldn't th
karlklose 2013/04/25 11:25:53 Removed.
1323
1324 get redirectionTarget => superConstructor.redirectionTarget;
1325
1326 bool get isSynthesized => true;
1327 }
1328
1291 class VoidElementX extends ElementX { 1329 class VoidElementX extends ElementX {
1292 VoidElementX(Element enclosing) 1330 VoidElementX(Element enclosing)
1293 : super(const SourceString('void'), ElementKind.VOID, enclosing); 1331 : super(const SourceString('void'), ElementKind.VOID, enclosing);
1294 DartType computeType(compiler) => compiler.types.voidType; 1332 DartType computeType(compiler) => compiler.types.voidType;
1295 Node parseNode(_) { 1333 Node parseNode(_) {
1296 throw 'internal error: parseNode on void'; 1334 throw 'internal error: parseNode on void';
1297 } 1335 }
1298 bool impliesType() => true; 1336 bool impliesType() => true;
1299 } 1337 }
1300 1338
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 return super.toString(); 1868 return super.toString();
1831 } 1869 }
1832 } 1870 }
1833 } 1871 }
1834 1872
1835 class MixinApplicationElementX extends BaseClassElementX 1873 class MixinApplicationElementX extends BaseClassElementX
1836 implements MixinApplicationElement { 1874 implements MixinApplicationElement {
1837 final Node node; 1875 final Node node;
1838 final Modifiers modifiers; 1876 final Modifiers modifiers;
1839 1877
1840 FunctionElement constructor; 1878 Link<FunctionElement> constructors = new Link<FunctionElement>();
1879
1841 ClassElement mixin; 1880 ClassElement mixin;
1842 1881
1843 // TODO(kasperl): The analyzer complains when I don't have these two 1882 // TODO(kasperl): The analyzer complains when I don't have these two
1844 // fields. This is pretty weird. I cannot replace them with getters. 1883 // fields. This is pretty weird. I cannot replace them with getters.
1845 final ClassElement patch = null; 1884 final ClassElement patch = null;
1846 final ClassElement origin = null; 1885 final ClassElement origin = null;
1847 1886
1848 MixinApplicationElementX(SourceString name, Element enclosing, int id, 1887 MixinApplicationElementX(SourceString name, Element enclosing, int id,
1849 this.node, this.modifiers) 1888 this.node, this.modifiers)
1850 : super(name, enclosing, id, STATE_NOT_STARTED); 1889 : super(name, enclosing, id, STATE_NOT_STARTED);
1851 1890
1852 bool get isMixinApplication => true; 1891 bool get isMixinApplication => true;
1853 bool get hasConstructor => constructor != null; 1892 bool get hasConstructor => !constructors.isEmpty;
1854 bool get hasLocalScopeMembers => false; 1893 bool get hasLocalScopeMembers => constructors.isEmpty;
1855 1894
1856 Token position() => node.getBeginToken(); 1895 Token position() => node.getBeginToken();
1857 1896
1858 Node parseNode(DiagnosticListener listener) => node; 1897 Node parseNode(DiagnosticListener listener) => node;
1859 1898
1860 Element localLookup(SourceString name) { 1899 Element localLookup(SourceString name) {
1861 if (this.name == name) return constructor; 1900 for (Link<Element> link = constructors;
1901 !link.isEmpty;
1902 link = link.tail) {
1903 if (link.head.name == name) return link.head;
1904 }
1862 if (mixin == null) return null; 1905 if (mixin == null) return null;
1863 Element mixedInElement = mixin.localLookup(name); 1906 Element mixedInElement = mixin.localLookup(name);
1864 if (mixedInElement == null) return null; 1907 if (mixedInElement == null) return null;
1865 return mixedInElement.isInstanceMember() ? mixedInElement : null; 1908 return mixedInElement.isInstanceMember() ? mixedInElement : null;
1866 } 1909 }
1867 1910
1868 void forEachLocalMember(void f(Element member)) { 1911 void forEachLocalMember(void f(Element member)) {
1869 if (mixin != null) mixin.forEachLocalMember((Element mixedInElement) { 1912 if (mixin != null) mixin.forEachLocalMember((Element mixedInElement) {
1870 if (mixedInElement.isInstanceMember()) f(mixedInElement); 1913 if (mixedInElement.isInstanceMember()) f(mixedInElement);
1871 }); 1914 });
1872 } 1915 }
1873 1916
1874 void addMember(Element element, DiagnosticListener listener) { 1917 void addMember(Element element, DiagnosticListener listener) {
1875 throw new UnsupportedError("cannot add member to $this"); 1918 throw new UnsupportedError("cannot add member to $this");
1876 } 1919 }
1877 1920
1878 void addToScope(Element element, DiagnosticListener listener) { 1921 void addToScope(Element element, DiagnosticListener listener) {
1879 throw new UnsupportedError("cannot add to scope of $this"); 1922 if (!element.isConstructor()) {
1923 listener.cancel('can only add constructors to mixin application scope,'
ahe 2013/04/15 13:36:46 Please emit a proper error instead of calling canc
karlklose 2013/04/25 11:25:53 Done.
1924 ' but got $element', element: this);
1925 }
1926 constructors = constructors.prepend(element);
1880 } 1927 }
1881 1928
1882 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) { 1929 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) {
1883 assert(!hasConstructor); 1930 assert(!hasConstructor);
1884 this.constructor = constructor; 1931 addToScope(constructor, compiler);
1885 } 1932 }
1886 1933
1887 Link<DartType> computeTypeParameters(Compiler compiler) { 1934 Link<DartType> computeTypeParameters(Compiler compiler) {
1888 NamedMixinApplication named = node.asNamedMixinApplication(); 1935 NamedMixinApplication named = node.asNamedMixinApplication();
1889 if (named == null) return const Link<DartType>(); 1936 if (named == null) return const Link<DartType>();
1890 return TypeDeclarationElementX.createTypeVariables( 1937 return TypeDeclarationElementX.createTypeVariables(
1891 this, named.typeParameters); 1938 this, named.typeParameters);
1892 } 1939 }
1893 } 1940 }
1894 1941
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 2063
2017 MetadataAnnotation ensureResolved(Compiler compiler) { 2064 MetadataAnnotation ensureResolved(Compiler compiler) {
2018 if (resolutionState == STATE_NOT_STARTED) { 2065 if (resolutionState == STATE_NOT_STARTED) {
2019 compiler.resolver.resolveMetadataAnnotation(this); 2066 compiler.resolver.resolveMetadataAnnotation(this);
2020 } 2067 }
2021 return this; 2068 return this;
2022 } 2069 }
2023 2070
2024 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 2071 String toString() => 'MetadataAnnotation($value, $resolutionState)';
2025 } 2072 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698