Index: lib/compiler/implementation/resolver.dart |
diff --git a/lib/compiler/implementation/resolver.dart b/lib/compiler/implementation/resolver.dart |
index 4b6a8f49fdbe5ed61d7e91227689569694408830..062350f298d17a7ab7524dc8d567a264cf54f020 100644 |
--- a/lib/compiler/implementation/resolver.dart |
+++ b/lib/compiler/implementation/resolver.dart |
@@ -1137,7 +1137,32 @@ class ResolverVisitor extends CommonResolverVisitor<Element> { |
visitEmptyStatement(EmptyStatement node) { } |
+ bool isAssertSyntax(Expression expression) { |
ngeoffray
2012/09/05 10:37:10
I'm not sure about this code. I wish we could avoi
Lasse Reichstein Nielsen
2012/09/05 12:51:20
I've moved this into visitSend now, so it only dec
|
+ Send send = expression.asSend(); |
+ if (send === null) return false; |
+ if (send.receiver !== null) return false; |
+ if (!send.isCall) return false; |
+ Identifier selector = send.selector.asIdentifier(); |
+ if (selector === null) return false; |
+ if (selector.source.stringValue !== "assert") return false; |
+ if (send.argumentCount() != 1) return false; |
+ return true; |
+ } |
+ |
visitExpressionStatement(ExpressionStatement node) { |
+ if (isAssertSyntax(node.expression)) { |
ahe
2012/09/05 11:09:54
I'm going to express myself unambiguously. I do no
Lasse Reichstein Nielsen
2012/09/05 12:51:20
Try seeing if the new version is better.
|
+ Send send = node.expression; |
+ Element scopedAssert = scope.lexicalLookup(const SourceString("assert")); |
+ if (scopedAssert == null) { |
+ // Compile as a call to a top-level function. |
+ Element target = compiler.assertMethod; |
+ Selector selector = resolveSelector(send); |
+ resolveArguments(send.argumentsNode); |
+ useElement(send, target); |
+ registerSend(selector, target); |
+ return; |
+ } |
+ } |
visit(node.expression); |
} |
@@ -1379,16 +1404,6 @@ class ResolverVisitor extends CommonResolverVisitor<Element> { |
world.registerDynamicInvocation(call.name, call); |
} |
- // TODO(ngeoffray): We should do the check in |
- // visitExpressionStatement instead. |
- if (target === compiler.assertMethod && !node.isCall) { |
- // We can only use assert by calling it. |
- if (!inInstanceContext) { |
- error(node, MessageKind.MISSING_ARGUMENTS_TO_ASSERT, [node]); |
- } |
- target = null; |
- } |
- |
// TODO(ngeoffray): Warn if target is null and the send is |
// unqualified. |
useElement(node, target); |
@@ -2557,7 +2572,20 @@ class Scope { |
Scope(this.parent, this.element); |
abstract Element add(Element element); |
- abstract Element lookup(SourceString name); |
+ |
+ Element lookup(SourceString name) { |
+ Element result = localLookup(name); |
+ if (result != null) return result; |
+ return parent.lookup(name); |
+ } |
+ |
+ Element lexicalLookup(SourceString name) { |
+ Element result = localLookup(name); |
+ if (result != null) return result; |
+ return parent.lexicalLookup(name); |
+ } |
+ |
+ abstract Element localLookup(SourceString name); |
} |
/** |
@@ -2586,7 +2614,7 @@ class TypeDeclarationScope extends Scope { |
return null; |
} |
- Element lookup(SourceString name) { |
+ Element localLookup(SourceString name) { |
Link<DartType> typeVariableLink = element.typeVariables; |
while (!typeVariableLink.isEmpty()) { |
TypeVariableType typeVariable = typeVariableLink.head; |
@@ -2595,8 +2623,7 @@ class TypeDeclarationScope extends Scope { |
} |
typeVariableLink = typeVariableLink.tail; |
} |
- |
- return parent.lookup(name); |
+ return null; |
} |
String toString() => |
@@ -2612,11 +2639,7 @@ class MethodScope extends Scope { |
assert(parent !== null); |
} |
- Element lookup(SourceString name) { |
- Element found = elements[name]; |
- if (found !== null) return found; |
- return parent.lookup(name); |
- } |
+ Element localLookup(SourceString name) => elements[name]; |
Element add(Element newElement) { |
if (elements.containsKey(newElement.name)) { |
@@ -2644,12 +2667,19 @@ class ClassScope extends TypeDeclarationScope { |
ClassScope(Scope parentScope, ClassElement element) |
: super(parentScope, element); |
- Element lookup(SourceString name) { |
+ Element localLookup(SourceString name) { |
ClassElement cls = element; |
Element result = cls.lookupLocalMember(name); |
if (result !== null) return result; |
- result = super.lookup(name); |
- if (result != null) return result; |
+ return super.localLookup(name); |
+ } |
+ |
+ Element lookup(SourceString name) { |
+ Element result = localLookup(name); |
+ if (result !== null) return result; |
+ result = parent.lexicalLookup(name); |
+ if (result !== null) return result; |
+ ClassElement cls = element; |
return cls.lookupSuperMember(name); |
} |
@@ -2664,9 +2694,10 @@ class TopScope extends Scope { |
LibraryElement get library => element; |
TopScope(LibraryElement library) : super(null, library); |
- Element lookup(SourceString name) { |
- return library.find(name); |
- } |
+ |
+ Element localLookup(SourceString name) => library.find(name); |
+ Element lookup(SourceString name) => localLookup(name); |
+ Element lexicalLookup(SourceString name) => localLookup(name); |
Element add(Element newElement) { |
throw "Cannot add an element in the top scope"; |