Chromium Code Reviews| Index: compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java |
| diff --git a/compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java b/compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java |
| index 79fadd59d835ddd8afc9b328264b1f175de57f04..4bd735e1abd5f8c4fcd36f4a6081cf2e87b109f0 100644 |
| --- a/compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java |
| +++ b/compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java |
| @@ -82,6 +82,7 @@ import com.google.dart.compiler.ast.DartUnit; |
| import com.google.dart.compiler.ast.DartUnqualifiedInvocation; |
| import com.google.dart.compiler.ast.DartVariable; |
| import com.google.dart.compiler.ast.DartVariableStatement; |
| +import com.google.dart.compiler.ast.DartVisitor; |
| import com.google.dart.compiler.ast.DartWhileStatement; |
| import com.google.dart.compiler.ast.Modifiers; |
| import com.google.dart.compiler.backend.common.TypeHeuristic.FieldKind; |
| @@ -148,6 +149,7 @@ import com.google.dart.compiler.resolver.MethodElement; |
| import com.google.dart.compiler.resolver.SuperElement; |
| import com.google.dart.compiler.resolver.VariableElement; |
| import com.google.dart.compiler.type.InterfaceType; |
| +import com.google.dart.compiler.type.FunctionAliasType; |
| import com.google.dart.compiler.type.Type; |
| import com.google.dart.compiler.type.TypeKind; |
| import com.google.dart.compiler.type.Types; |
| @@ -178,6 +180,25 @@ public class GenerateJavascriptAST { |
| private final CoreTypeProvider typeProvider; |
| private final boolean generateClosureCompatibleCode; |
| + static class FunctionAliasDiscover extends DartNodeTraverser<Void> { |
| + boolean aliasFound = false; |
| + FunctionAliasDiscover() { |
| + } |
| + |
| + @Override |
| + public Void visitFunctionTypeAlias(DartFunctionTypeAlias node) { |
|
zundel
2011/11/08 15:28:42
you could set the return value to Boolean instead
codefu
2011/11/14 19:33:40
I'll have to override some other methods that by d
|
| + aliasFound = true; |
| + return null; |
| + } |
|
zundel
2011/11/08 15:28:42
missing n/l
codefu
2011/11/14 19:33:40
Done.
|
| + @Override |
| + public Void visitTypeNode(DartTypeNode node) { |
| + if( node.getType() instanceof FunctionAliasType) { |
| + aliasFound = true; |
|
zundel
2011/11/08 15:28:42
Efficiency: if you find an alias, do you really wa
codefu
2011/11/14 19:33:40
Done.
|
| + } |
| + return visitNode(node); |
| + } |
| + } |
| + |
| /** |
| * Generates the Javascript AST using the names created in {@link GenerateNamesAndScopes}. |
| */ |
| @@ -1105,6 +1126,14 @@ public class GenerateJavascriptAST { |
| JsFunction func = (JsFunction) generate(x.getFunction()); |
| + Element element = x.getSymbol(); |
|
zundel
2011/11/08 15:28:42
I think you can be pretty sure that element is of
codefu
2011/11/14 19:33:40
Done.
|
| + if (element.getKind().equals(ElementKind.METHOD) && |
| + !element.getModifiers().isOperator() && |
| + !element.getModifiers().isGetter() && |
| + !element.getModifiers().isSetter()) { |
| + rtt.generateRuntimeTypeInfo(x); |
| + } |
| + |
| assert currentScopeInfo != null; |
| inFactoryOrStaticContext = false; |
| currentScopeInfo = null; |
| @@ -3533,6 +3562,15 @@ public class GenerateJavascriptAST { |
| @Override |
| public JsNode visitFunctionTypeAlias(DartFunctionTypeAlias node) { |
| + // TODO: If we're never in an instanceOf check, we don't need to generate this |
|
zundel
2011/11/08 15:28:42
I'm not sure what you mean by instanceOf, do you m
codefu
2011/11/14 19:33:40
Yep. I was using the function name from rtt.gener
|
| + ClassElement classElement = node.getSymbol(); |
| + JsName classJsName = getJsName(node.getSymbol()); |
|
zundel
2011/11/08 15:28:42
node.getSymbol() == classElement
codefu
2011/11/14 19:33:40
Done.
|
| + JsFunction jsClass = new JsFunction(globalScope, classJsName).setSourceRef(node); |
| + jsClass.setIsConstructor(false); |
| + jsClass.setBody(new JsBlock()); |
| + globalBlock.getStatements().add(jsClass.makeStmt()); |
| + |
| + rtt.generateRuntimeTypeInfo(node); |
| return null; |
| } |
| @@ -3620,8 +3658,16 @@ public class GenerateJavascriptAST { |
| String mangledName = mangler.mangleNamedMethod(methodElement, unitLibrary); |
| boolean isSuperCall = (qualifier != null) && isSuperCall(qualifier.getSymbol()); |
| if (isSuperCall) { |
| - boundMethod = generateSuperFieldAccess(qualifier, |
| - mangler.createGetterSyntax(methodElement.getName(), unitLibrary)); |
| + switch(TypeKind.of(methodElement.getType())) { |
| + case FUNCTION: |
| + boundMethod = generateSuperFieldAccess(qualifier, |
| + mangler.mangleLookupMethod(methodElement.getName(), unitLibrary)); |
|
zundel
2011/11/08 15:28:42
out of curiousity, why didn't you use the overload
codefu
2011/11/14 19:33:40
Done.
|
| + break; |
| + default: |
| + boundMethod = generateSuperFieldAccess(qualifier, |
| + mangler.createGetterSyntax(methodElement.getName(), unitLibrary)); |
| + break; |
| + } |
| } else if (Elements.isTopLevel(methodElement)) { |
| boundMethod = AstUtil.newNameRef(null, mangledName); |
| } else if (methodElement.isStatic()) { |
| @@ -3642,8 +3688,18 @@ public class GenerateJavascriptAST { |
| ClassElement classElement = (ClassElement) methodElement.getEnclosingElement(); |
| String className = mangler.mangleClassName(classElement); |
| JsNameRef prototypeRef = AstUtil.newPrototypeNameRef(new JsNameRef(className)); |
| - JsExpression methodToCall = AstUtil.newNameRef(prototypeRef, mangledName); |
| - boundMethod = AstUtil.newInvocation(new JsNameRef("$bind"), methodToCall, methodQualifier); |
| + JsExpression methodToCall; |
| + switch(TypeKind.of(methodElement.getType())) { |
| + case FUNCTION: |
| + mangledName = mangler.mangleLookupMethod(methodElement, unitLibrary); |
| + methodToCall = AstUtil.newNameRef(methodQualifier, mangledName); |
| + boundMethod = AstUtil.newInvocation(methodToCall); |
| + break; |
| + default: |
| + methodToCall = AstUtil.newNameRef(prototypeRef, mangledName); |
| + boundMethod = AstUtil.newInvocation(new JsNameRef("$bind"), methodToCall, methodQualifier); |
| + break; |
| + } |
| } |
| boundMethod.setSourceRef(methodNode); |
| return boundMethod; |
| @@ -3674,9 +3730,18 @@ public class GenerateJavascriptAST { |
| return generateSuperFieldAccess(qualifier, |
| mangler.createGetterSyntax(node.getTargetName(), unitLibrary)); |
| } |
| + |
| + if (node.getParent().getParent() instanceof DartBinaryExpression) { |
|
zundel
2011/11/08 15:28:42
Not sure what's going on here - could you add some
|
| + FunctionAliasDiscover visitForAlias = new FunctionAliasDiscover(); |
| + ((DartBinaryExpression) node.getParent().getParent()).getArg2().accept(visitForAlias); |
| + if(visitForAlias.aliasFound) { |
| + return generateUnresolvedAccess(qualifier, |
| + mangler.mangleLookupMethod(node.getTargetName(), unitLibrary)); |
| + } |
| + } |
| return generateUnresolvedAccess(qualifier, |
| mangler.createGetterSyntax(node.getTargetName(), unitLibrary)); |
| - |
| + |
| case FIELD: { |
| FieldElement field = (FieldElement) element; |
| String accessorName; |