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

Unified Diff: frog/leg/resolver.dart

Issue 9166010: Implement super calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 11 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 | frog/leg/ssa/builder.dart » ('j') | frog/leg/ssa/builder.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/resolver.dart
diff --git a/frog/leg/resolver.dart b/frog/leg/resolver.dart
index 0719b23532b118b0a745d247f5e136ca5e7ec904..a48e22605fb7715088bfe0024ae82e5cee36214e 100644
--- a/frog/leg/resolver.dart
+++ b/frog/leg/resolver.dart
@@ -116,6 +116,7 @@ class ResolverVisitor extends AbstractVisitor/*<Element>*/ {
final Element enclosingElement;
bool inInstanceContext;
Scope context;
+ ClassElement currentClass;
ResolverVisitor(Compiler compiler, Element element)
: this.compiler = compiler,
@@ -125,14 +126,16 @@ class ResolverVisitor extends AbstractVisitor/*<Element>*/ {
|| element.isGenerativeConstructor(),
this.context = element.isMember()
? new ClassScope(element.enclosingElement, compiler.universe)
- : new TopScope(compiler.universe);
+ : new TopScope(compiler.universe),
+ this.currentClass = element.isMember() ? element.enclosingElement : null;
ResolverVisitor.from(ResolverVisitor other)
: compiler = other.compiler,
mapping = other.mapping,
enclosingElement = other.enclosingElement,
inInstanceContext = other.inInstanceContext,
- context = other.context;
+ context = other.context,
+ currentClass = other.currentClass;
error(Node node, MessageKind kind, [arguments = const []]) {
ResolutionError error = new ResolutionError(kind, arguments);
@@ -172,6 +175,9 @@ class ResolverVisitor extends AbstractVisitor/*<Element>*/ {
if (node.isThis()) {
if (!inInstanceContext) error(node, MessageKind.NO_THIS_IN_STATIC);
return null;
+ } else if (node.isSuper()) {
+ if (!inInstanceContext) error(node, MessageKind.NO_SUPER_IN_STATIC);
+ return null;
} else {
Element element = lookup(node, node.source);
if (element == null) {
@@ -331,7 +337,24 @@ class FullResolverVisitor extends ResolverVisitor {
if (isLogicalOperator(selector)) return null;
Element target = null;
- if (node.isOperator) {
+ if (node.receiver !== null
+ && node.receiver.asIdentifier() !== null
+ && node.receiver.asIdentifier().isSuper()) {
+ SourceString superName = const SourceString('');
+print(currentClass);
ngeoffray 2012/01/11 13:00:48 Remove debugging code
karlklose 2012/01/11 13:46:12 Done.
+ if (currentClass !== null) {
+ ClassElement superElement = currentClass.superClass;
+ if (superElement !== null) {
+ target = superElement.lookupLocalMember(name);
+ superName = superElement.name;
+ } else {
+ superName = compiler.types.OBJECT;
+ }
+ }
+ if (target == null) {
+ error(node, MessageKind.METHOD_NOT_FOUND, [superName, name]);
ngeoffray 2012/01/11 13:00:48 I think I'd prefer two kinds of errors, one for th
karlklose 2012/01/11 13:46:12 Yes we already report an error if we encounter sup
+ }
+ } else if (node.isOperator) {
return null;
} else if (node.receiver === null) {
target = lookup(node, name);
@@ -344,9 +367,9 @@ class FullResolverVisitor extends ResolverVisitor {
ClassElement receiverClass = receiver;
target = receiverClass.resolve(compiler).lookupLocalMember(name);
if (target == null) {
- error(node, MessageKind.METHOD_NOT_FOUND, [receiver, name]);
+ error(node, MessageKind.METHOD_NOT_FOUND, [receiver.name, name]);
} else if (target.isInstanceMember()) {
- error(node, MessageKind.MEMBER_NOT_STATIC, [receiver, name]);
+ error(node, MessageKind.MEMBER_NOT_STATIC, [receiver.name, name]);
}
}
return target;
@@ -542,6 +565,18 @@ class ClassResolverVisitor extends AbstractVisitor/* <Type> */ {
compiler.ensure(element !== null);
compiler.ensure(!element.isResolved);
element.supertype = visit(node.superclass);
+ if (element.name != Types.OBJECT && element.supertype === null) {
+ ClassElement objectElement = context.lookup(Types.OBJECT);
+ if (objectElement !== null && !objectElement.isResolved) {
+ compiler.resolver.toResolve.add(objectElement);
+ } else if (objectElement === null){
+ compiler.reportError(node,
+ new ResolutionError(MessageKind.CANNOT_RESOLVE_TYPE,
+ [Types.OBJECT]));
+ }
+ element.supertype = new SimpleType(Types.OBJECT,
+ objectElement);
+ }
for (Link<Node> link = node.interfaces.nodes;
!link.isEmpty();
link = link.tail) {
« no previous file with comments | « no previous file | frog/leg/ssa/builder.dart » ('j') | frog/leg/ssa/builder.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698