| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 package com.google.dart.compiler.resolver; | 5 package com.google.dart.compiler.resolver; |
| 6 | 6 |
| 7 import com.google.common.annotations.VisibleForTesting; | 7 import com.google.common.annotations.VisibleForTesting; |
| 8 import com.google.dart.compiler.DartCompilerContext; | 8 import com.google.dart.compiler.DartCompilerContext; |
| 9 import com.google.dart.compiler.ast.DartClass; | 9 import com.google.dart.compiler.ast.DartClass; |
| 10 import com.google.dart.compiler.ast.DartExpression; | 10 import com.google.dart.compiler.ast.DartExpression; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 private class ConstExpressionVisitor extends ASTVisitor<Void> { | 40 private class ConstExpressionVisitor extends ASTVisitor<Void> { |
| 41 | 41 |
| 42 @Override | 42 @Override |
| 43 public Void visitPropertyAccess(DartPropertyAccess x) { | 43 public Void visitPropertyAccess(DartPropertyAccess x) { |
| 44 DartNode qualifierNode = x.getQualifier(); | 44 DartNode qualifierNode = x.getQualifier(); |
| 45 Element qualifier = null; | 45 Element qualifier = null; |
| 46 if (qualifierNode instanceof DartIdentifier) { | 46 if (qualifierNode instanceof DartIdentifier) { |
| 47 DartIdentifier qualifierIdent = (DartIdentifier) qualifierNode; | 47 DartIdentifier qualifierIdent = (DartIdentifier) qualifierNode; |
| 48 qualifier = getContext().getScope().findElement(libraryElement, | 48 qualifier = getContext().getScope().findElement(libraryElement, |
| 49 qualifierIdent | 49 qualifierIdent |
| 50 .getTargetName()); | 50 .getName()); |
| 51 qualifierNode.setSymbol(qualifier); | 51 qualifierNode.setElement(qualifier); |
| 52 } | 52 } |
| 53 | 53 |
| 54 if (qualifier != null) { | 54 if (qualifier != null) { |
| 55 Element element = null; | 55 Element element = null; |
| 56 | 56 |
| 57 switch (ElementKind.of(qualifier)) { | 57 switch (ElementKind.of(qualifier)) { |
| 58 case CLASS: | 58 case CLASS: |
| 59 // Must be a static field. | 59 // Must be a static field. |
| 60 element = Elements.findElement(((ClassElement) qualifier), x | 60 element = Elements.findElement(((ClassElement) qualifier), x |
| 61 .getPropertyName()); | 61 .getPropertyName()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 return null; | 78 return null; |
| 79 } | 79 } |
| 80 | 80 |
| 81 @Override | 81 @Override |
| 82 public Void visitIdentifier(DartIdentifier x) { | 82 public Void visitIdentifier(DartIdentifier x) { |
| 83 x.visitChildren(this); | 83 x.visitChildren(this); |
| 84 | 84 |
| 85 Element element = getContext().getScope() | 85 Element element = getContext().getScope() |
| 86 .findElement(libraryElement, x.getTargetName()); | 86 .findElement(libraryElement, x.getName()); |
| 87 if (element != null) { | 87 if (element != null) { |
| 88 recordElement(x, element); | 88 recordElement(x, element); |
| 89 } | 89 } |
| 90 return null; | 90 return null; |
| 91 } | 91 } |
| 92 | 92 |
| 93 @Override | 93 @Override |
| 94 public Void visitSuperConstructorInvocation(DartSuperConstructorInvocation
x) { | 94 public Void visitSuperConstructorInvocation(DartSuperConstructorInvocation
x) { |
| 95 x.visitChildren(this); | 95 x.visitChildren(this); |
| 96 | 96 |
| 97 String name = x.getName() == null ? "" : x.getName().getTargetName(); | 97 String name = x.getName() == null ? "" : x.getName().getName(); |
| 98 InterfaceType supertype = ((ClassElement) currentHolder).getSupertype(); | 98 InterfaceType supertype = ((ClassElement) currentHolder).getSupertype(); |
| 99 ConstructorElement element = (supertype == null) ? | 99 ConstructorElement element = (supertype == null) ? |
| 100 null : Elements.lookupConstructor(supertype.getElement(), name); | 100 null : Elements.lookupConstructor(supertype.getElement(), name); |
| 101 if (element != null) { | 101 if (element != null) { |
| 102 recordElement(x, element); | 102 recordElement(x, element); |
| 103 } | 103 } |
| 104 return null; | 104 return null; |
| 105 } | 105 } |
| 106 | 106 |
| 107 @Override | 107 @Override |
| 108 public Void visitRedirectConstructorInvocation(DartRedirectConstructorInvo
cation x) { | 108 public Void visitRedirectConstructorInvocation(DartRedirectConstructorInvo
cation x) { |
| 109 x.visitChildren(this); | 109 x.visitChildren(this); |
| 110 | 110 |
| 111 String name = x.getName() == null ? "" : x.getName().getTargetName(); | 111 String name = x.getName() == null ? "" : x.getName().getName(); |
| 112 InterfaceType supertype = ((ClassElement) currentHolder).getSupertype(); | 112 InterfaceType supertype = ((ClassElement) currentHolder).getSupertype(); |
| 113 ConstructorElement element = (supertype == null) ? | 113 ConstructorElement element = (supertype == null) ? |
| 114 null : Elements.lookupConstructor(supertype.getElement(), name); | 114 null : Elements.lookupConstructor(supertype.getElement(), name); |
| 115 if (element != null) { | 115 if (element != null) { |
| 116 recordElement(x, element); | 116 recordElement(x, element); |
| 117 } | 117 } |
| 118 return null; | 118 return null; |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 private final LibraryElement libraryElement; | 122 private final LibraryElement libraryElement; |
| 123 private EnclosingElement currentHolder; | 123 private EnclosingElement currentHolder; |
| 124 private final ResolutionContext topLevelContext; | 124 private final ResolutionContext topLevelContext; |
| 125 private ResolutionContext context; | 125 private ResolutionContext context; |
| 126 | 126 |
| 127 private ConstResolveVisitor(DartUnit unit, | 127 private ConstResolveVisitor(DartUnit unit, |
| 128 DartCompilerContext compilerContext, Scope scope, | 128 DartCompilerContext compilerContext, Scope scope, |
| 129 CoreTypeProvider typeProvider) { | 129 CoreTypeProvider typeProvider) { |
| 130 super(typeProvider); | 130 super(typeProvider); |
| 131 this.libraryElement = unit.getLibrary() == null ? null : unit | 131 this.libraryElement = unit.getLibrary() == null ? null : unit |
| 132 .getLibrary().getElement(); | 132 .getLibrary().getElement(); |
| 133 this.topLevelContext = this.context = new ResolutionContext(scope, | 133 this.topLevelContext = this.context = new ResolutionContext(scope, |
| 134 compilerContext, typeProvider); | 134 compilerContext, typeProvider); |
| 135 this.currentHolder = libraryElement; | 135 this.currentHolder = libraryElement; |
| 136 } | 136 } |
| 137 | 137 |
| 138 private void beginClassContext(final DartClass node) { | 138 private void beginClassContext(final DartClass node) { |
| 139 assert !ElementKind.of(currentHolder).equals(ElementKind.CLASS) : "nested
class?"; | 139 assert !ElementKind.of(currentHolder).equals(ElementKind.CLASS) : "nested
class?"; |
| 140 currentHolder = node.getSymbol(); | 140 currentHolder = node.getElement(); |
| 141 context = context.extend((ClassElement) currentHolder); | 141 context = context.extend((ClassElement) currentHolder); |
| 142 } | 142 } |
| 143 | 143 |
| 144 private void endClassContext() { | 144 private void endClassContext() { |
| 145 currentHolder = libraryElement; | 145 currentHolder = libraryElement; |
| 146 context = topLevelContext; | 146 context = topLevelContext; |
| 147 } | 147 } |
| 148 | 148 |
| 149 @Override | 149 @Override |
| 150 ResolutionContext getContext() { | 150 ResolutionContext getContext() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 176 } | 176 } |
| 177 | 177 |
| 178 @Override | 178 @Override |
| 179 public Element visitField(DartField node) { | 179 public Element visitField(DartField node) { |
| 180 resolveConstantExpression(node.getValue()); | 180 resolveConstantExpression(node.getValue()); |
| 181 return null; | 181 return null; |
| 182 } | 182 } |
| 183 | 183 |
| 184 @Override | 184 @Override |
| 185 public Element visitMethodDefinition(DartMethodDefinition node) { | 185 public Element visitMethodDefinition(DartMethodDefinition node) { |
| 186 MethodElement member = node.getSymbol(); | 186 MethodElement member = node.getElement(); |
| 187 ResolutionContext previousContext = context; | 187 ResolutionContext previousContext = context; |
| 188 context = context.extend(member.getName()); | 188 context = context.extend(member.getName()); |
| 189 DartFunction functionNode = node.getFunction(); | 189 DartFunction functionNode = node.getFunction(); |
| 190 List<DartParameter> parameters = functionNode.getParameters(); | 190 List<DartParameter> parameters = functionNode.getParameters(); |
| 191 for (DartParameter parameter : parameters) { | 191 for (DartParameter parameter : parameters) { |
| 192 getContext().declare(parameter.getSymbol(), null, null); | 192 getContext().declare(parameter.getElement(), null, null); |
| 193 // Then resolve the default values. | 193 // Then resolve the default values. |
| 194 resolveConstantExpression(parameter.getDefaultExpr()); | 194 resolveConstantExpression(parameter.getDefaultExpr()); |
| 195 } | 195 } |
| 196 Element element = node.getSymbol(); | 196 Element element = node.getElement(); |
| 197 if (ElementKind.of(element) == ElementKind.CONSTRUCTOR && | 197 if (ElementKind.of(element) == ElementKind.CONSTRUCTOR && |
| 198 node.getModifiers().isConstant()) { | 198 node.getModifiers().isConstant()) { |
| 199 for (DartInitializer initializer : node.getInitializers()) { | 199 for (DartInitializer initializer : node.getInitializers()) { |
| 200 DartExpression initializerValue = initializer.getValue(); | 200 DartExpression initializerValue = initializer.getValue(); |
| 201 resolveConstantExpression(initializerValue); | 201 resolveConstantExpression(initializerValue); |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 context = previousContext; | 204 context = previousContext; |
| 205 return null; | 205 return null; |
| 206 } | 206 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 exec(unit, compilerContext, unit.getLibrary().getElement().getScope(), typeP
rovider); | 239 exec(unit, compilerContext, unit.getLibrary().getElement().getScope(), typeP
rovider); |
| 240 } | 240 } |
| 241 | 241 |
| 242 @VisibleForTesting | 242 @VisibleForTesting |
| 243 public void exec(DartUnit unit, DartCompilerContext compilerContext, | 243 public void exec(DartUnit unit, DartCompilerContext compilerContext, |
| 244 Scope scope, CoreTypeProvider typeProvider) { | 244 Scope scope, CoreTypeProvider typeProvider) { |
| 245 unit.accept(new ConstResolveVisitor(unit, compilerContext, scope, | 245 unit.accept(new ConstResolveVisitor(unit, compilerContext, scope, |
| 246 typeProvider)); | 246 typeProvider)); |
| 247 } | 247 } |
| 248 } | 248 } |
| OLD | NEW |