| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of resolution; | 5 part of resolution; |
| 6 | 6 |
| 7 abstract class TreeElements { | 7 abstract class TreeElements { |
| 8 AnalyzableElement get analyzedElement; | 8 AnalyzableElement get analyzedElement; |
| 9 Iterable<Node> get superUses; | 9 Iterable<Node> get superUses; |
| 10 | 10 |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 Modifiers modifiers = element.modifiers; | 690 Modifiers modifiers = element.modifiers; |
| 691 if (initializer != null) { | 691 if (initializer != null) { |
| 692 // TODO(johnniwinther): Avoid analyzing initializers if | 692 // TODO(johnniwinther): Avoid analyzing initializers if |
| 693 // [Compiler.analyzeSignaturesOnly] is set. | 693 // [Compiler.analyzeSignaturesOnly] is set. |
| 694 visitor.visit(initializer); | 694 visitor.visit(initializer); |
| 695 } else if (modifiers.isConst) { | 695 } else if (modifiers.isConst) { |
| 696 compiler.reportError(element, MessageKind.CONST_WITHOUT_INITIALIZER); | 696 compiler.reportError(element, MessageKind.CONST_WITHOUT_INITIALIZER); |
| 697 } else if (modifiers.isFinal && !element.isInstanceMember) { | 697 } else if (modifiers.isFinal && !element.isInstanceMember) { |
| 698 compiler.reportError(element, MessageKind.FINAL_WITHOUT_INITIALIZER); | 698 compiler.reportError(element, MessageKind.FINAL_WITHOUT_INITIALIZER); |
| 699 } else { | 699 } else { |
| 700 registry.registerLiteralNull(); | 700 registry.registerInstantiatedClass(compiler.nullClass); |
| 701 } | 701 } |
| 702 | 702 |
| 703 if (Elements.isStaticOrTopLevelField(element)) { | 703 if (Elements.isStaticOrTopLevelField(element)) { |
| 704 visitor.addDeferredAction(element, () { | 704 visitor.addDeferredAction(element, () { |
| 705 if (element.modifiers.isConst) { | 705 if (element.modifiers.isConst) { |
| 706 constantCompiler.compileConstant(element); | 706 constantCompiler.compileConstant(element); |
| 707 } else { | 707 } else { |
| 708 constantCompiler.compileVariable(element); | 708 constantCompiler.compileVariable(element); |
| 709 } | 709 } |
| 710 }); | 710 }); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 element.supertypeLoadState = STATE_DONE; | 938 element.supertypeLoadState = STATE_DONE; |
| 939 element.resolutionState = STATE_DONE; | 939 element.resolutionState = STATE_DONE; |
| 940 // TODO(johnniwinther): Check matching type variables and | 940 // TODO(johnniwinther): Check matching type variables and |
| 941 // empty extends/implements clauses. | 941 // empty extends/implements clauses. |
| 942 } | 942 } |
| 943 } | 943 } |
| 944 | 944 |
| 945 void _postProcessClassElement(BaseClassElementX element) { | 945 void _postProcessClassElement(BaseClassElementX element) { |
| 946 for (MetadataAnnotation metadata in element.metadata) { | 946 for (MetadataAnnotation metadata in element.metadata) { |
| 947 metadata.ensureResolved(compiler); | 947 metadata.ensureResolved(compiler); |
| 948 if (!element.isProxy) { | 948 if (!element.isProxy && |
| 949 ConstantExpression constantExpression = metadata.constant; | 949 metadata.constant.value == compiler.proxyConstant) { |
| 950 if (constantExpression != null) { | 950 element.isProxy = true; |
| 951 ConstantValue constant = constantExpression.value; | |
| 952 if (constant.isConstructedObject) { | |
| 953 ObjectConstantValue object = constant; | |
| 954 if (object.type.element == compiler.proxyClass) { | |
| 955 element.isProxy = true; | |
| 956 } | |
| 957 } | |
| 958 } | |
| 959 } | 951 } |
| 960 } | 952 } |
| 961 | 953 |
| 962 // Force resolution of metadata on non-instance members since they may be | 954 // Force resolution of metadata on non-instance members since they may be |
| 963 // inspected by the backend while emitting. Metadata on instance members is | 955 // inspected by the backend while emitting. Metadata on instance members is |
| 964 // handled as a result of processing instantiated class members in the | 956 // handled as a result of processing instantiated class members in the |
| 965 // enqueuer. | 957 // enqueuer. |
| 966 // TODO(ahe): Avoid this eager resolution. | 958 // TODO(ahe): Avoid this eager resolution. |
| 967 element.forEachMember((_, Element member) { | 959 element.forEachMember((_, Element member) { |
| 968 if (!member.isInstanceMember) { | 960 if (!member.isInstanceMember) { |
| (...skipping 1553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2522 // Run the body in a fresh statement scope. | 2514 // Run the body in a fresh statement scope. |
| 2523 StatementScope oldStatementScope = statementScope; | 2515 StatementScope oldStatementScope = statementScope; |
| 2524 statementScope = new StatementScope(); | 2516 statementScope = new StatementScope(); |
| 2525 visit(node.body); | 2517 visit(node.body); |
| 2526 statementScope = oldStatementScope; | 2518 statementScope = oldStatementScope; |
| 2527 | 2519 |
| 2528 scope = oldScope; | 2520 scope = oldScope; |
| 2529 enclosingElement = previousEnclosingElement; | 2521 enclosingElement = previousEnclosingElement; |
| 2530 | 2522 |
| 2531 registry.registerClosure(function); | 2523 registry.registerClosure(function); |
| 2532 registry.registerLiteralFunction(); | 2524 registry.registerInstantiatedClass(compiler.functionClass); |
| 2533 } | 2525 } |
| 2534 | 2526 |
| 2535 visitIf(If node) { | 2527 visitIf(If node) { |
| 2536 doInPromotionScope(node.condition.expression, () => visit(node.condition)); | 2528 doInPromotionScope(node.condition.expression, () => visit(node.condition)); |
| 2537 doInPromotionScope(node.thenPart, | 2529 doInPromotionScope(node.thenPart, |
| 2538 () => visitIn(node.thenPart, new BlockScope(scope))); | 2530 () => visitIn(node.thenPart, new BlockScope(scope))); |
| 2539 visitIn(node.elsePart, new BlockScope(scope)); | 2531 visitIn(node.elsePart, new BlockScope(scope)); |
| 2540 } | 2532 } |
| 2541 | 2533 |
| 2542 ResolutionResult resolveSend(Send node) { | 2534 ResolutionResult resolveSend(Send node) { |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3045 | 3037 |
| 3046 // Make sure we include the + and - operators if we are using | 3038 // Make sure we include the + and - operators if we are using |
| 3047 // the ++ and -- ones. Also, if op= form is used, include op itself. | 3039 // the ++ and -- ones. Also, if op= form is used, include op itself. |
| 3048 void registerBinaryOperator(String name) { | 3040 void registerBinaryOperator(String name) { |
| 3049 Selector binop = new Selector.binaryOperator(name); | 3041 Selector binop = new Selector.binaryOperator(name); |
| 3050 registry.registerDynamicInvocation(binop); | 3042 registry.registerDynamicInvocation(binop); |
| 3051 registry.setOperatorSelectorInComplexSendSet(node, binop); | 3043 registry.setOperatorSelectorInComplexSendSet(node, binop); |
| 3052 } | 3044 } |
| 3053 if (identical(source, '++')) { | 3045 if (identical(source, '++')) { |
| 3054 registerBinaryOperator('+'); | 3046 registerBinaryOperator('+'); |
| 3055 registry.registerLiteralInt(); | 3047 registry.registerInstantiatedClass(compiler.intClass); |
| 3056 } else if (identical(source, '--')) { | 3048 } else if (identical(source, '--')) { |
| 3057 registerBinaryOperator('-'); | 3049 registerBinaryOperator('-'); |
| 3058 registry.registerLiteralInt(); | 3050 registry.registerInstantiatedClass(compiler.intClass); |
| 3059 } else if (source.endsWith('=')) { | 3051 } else if (source.endsWith('=')) { |
| 3060 registerBinaryOperator(Elements.mapToUserOperator(operatorName)); | 3052 registerBinaryOperator(Elements.mapToUserOperator(operatorName)); |
| 3061 } | 3053 } |
| 3062 } | 3054 } |
| 3063 | 3055 |
| 3064 registerSend(selector, setter); | 3056 registerSend(selector, setter); |
| 3065 return new ElementResult(registry.useElement(node, setter)); | 3057 return new ElementResult(registry.useElement(node, setter)); |
| 3066 } | 3058 } |
| 3067 | 3059 |
| 3068 void registerSend(Selector selector, Element target) { | 3060 void registerSend(Selector selector, Element target) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3079 // instead resolved through their enclosing type declaration. | 3071 // instead resolved through their enclosing type declaration. |
| 3080 if (!target.isTypeVariable) { | 3072 if (!target.isTypeVariable) { |
| 3081 // [target] might be the implementation element and only declaration | 3073 // [target] might be the implementation element and only declaration |
| 3082 // elements may be registered. | 3074 // elements may be registered. |
| 3083 registry.registerStaticUse(target.declaration); | 3075 registry.registerStaticUse(target.declaration); |
| 3084 } | 3076 } |
| 3085 } | 3077 } |
| 3086 } | 3078 } |
| 3087 | 3079 |
| 3088 visitLiteralInt(LiteralInt node) { | 3080 visitLiteralInt(LiteralInt node) { |
| 3089 registry.registerLiteralInt(); | 3081 registry.registerInstantiatedClass(compiler.intClass); |
| 3090 } | 3082 } |
| 3091 | 3083 |
| 3092 visitLiteralDouble(LiteralDouble node) { | 3084 visitLiteralDouble(LiteralDouble node) { |
| 3093 registry.registerLiteralDouble(); | 3085 registry.registerInstantiatedClass(compiler.doubleClass); |
| 3094 } | 3086 } |
| 3095 | 3087 |
| 3096 visitLiteralBool(LiteralBool node) { | 3088 visitLiteralBool(LiteralBool node) { |
| 3097 registry.registerLiteralBool(); | 3089 registry.registerInstantiatedClass(compiler.boolClass); |
| 3098 } | 3090 } |
| 3099 | 3091 |
| 3100 visitLiteralString(LiteralString node) { | 3092 visitLiteralString(LiteralString node) { |
| 3101 registry.registerLiteralString(); | 3093 registry.registerInstantiatedClass(compiler.stringClass); |
| 3102 } | 3094 } |
| 3103 | 3095 |
| 3104 visitLiteralNull(LiteralNull node) { | 3096 visitLiteralNull(LiteralNull node) { |
| 3105 registry.registerLiteralNull(); | 3097 registry.registerInstantiatedClass(compiler.nullClass); |
| 3106 } | 3098 } |
| 3107 | 3099 |
| 3108 visitLiteralSymbol(LiteralSymbol node) { | 3100 visitLiteralSymbol(LiteralSymbol node) { |
| 3109 registry.registerLiteralSymbol(node.slowNameString); | 3101 registry.registerInstantiatedClass(compiler.symbolClass); |
| 3102 registry.registerStaticUse(compiler.symbolConstructor.declaration); |
| 3103 registry.registerConstSymbol(node.slowNameString); |
| 3110 if (!validateSymbol(node, node.slowNameString, reportError: false)) { | 3104 if (!validateSymbol(node, node.slowNameString, reportError: false)) { |
| 3111 compiler.reportError(node, | 3105 compiler.reportError(node, |
| 3112 MessageKind.UNSUPPORTED_LITERAL_SYMBOL, | 3106 MessageKind.UNSUPPORTED_LITERAL_SYMBOL, |
| 3113 {'value': node.slowNameString}); | 3107 {'value': node.slowNameString}); |
| 3114 } | 3108 } |
| 3115 analyzeConstantDeferred(node); | 3109 analyzeConstantDeferred(node); |
| 3116 } | 3110 } |
| 3117 | 3111 |
| 3118 visitStringJuxtaposition(StringJuxtaposition node) { | 3112 visitStringJuxtaposition(StringJuxtaposition node) { |
| 3119 registry.registerLiteralString(); | 3113 registry.registerInstantiatedClass(compiler.stringClass); |
| 3120 node.visitChildren(this); | 3114 node.visitChildren(this); |
| 3121 } | 3115 } |
| 3122 | 3116 |
| 3123 visitNodeList(NodeList node) { | 3117 visitNodeList(NodeList node) { |
| 3124 for (Link<Node> link = node.nodes; !link.isEmpty; link = link.tail) { | 3118 for (Link<Node> link = node.nodes; !link.isEmpty; link = link.tail) { |
| 3125 visit(link.head); | 3119 visit(link.head); |
| 3126 } | 3120 } |
| 3127 } | 3121 } |
| 3128 | 3122 |
| 3129 visitOperator(Operator node) { | 3123 visitOperator(Operator node) { |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3515 sendIsMemberAccess = false; | 3509 sendIsMemberAccess = false; |
| 3516 } | 3510 } |
| 3517 | 3511 |
| 3518 visitConditional(Conditional node) { | 3512 visitConditional(Conditional node) { |
| 3519 doInPromotionScope(node.condition, () => visit(node.condition)); | 3513 doInPromotionScope(node.condition, () => visit(node.condition)); |
| 3520 doInPromotionScope(node.thenExpression, () => visit(node.thenExpression)); | 3514 doInPromotionScope(node.thenExpression, () => visit(node.thenExpression)); |
| 3521 visit(node.elseExpression); | 3515 visit(node.elseExpression); |
| 3522 } | 3516 } |
| 3523 | 3517 |
| 3524 visitStringInterpolation(StringInterpolation node) { | 3518 visitStringInterpolation(StringInterpolation node) { |
| 3525 registry.registerLiteralString(); | 3519 registry.registerInstantiatedClass(compiler.stringClass); |
| 3526 registry.registerStringInterpolation(); | 3520 registry.registerStringInterpolation(); |
| 3527 node.visitChildren(this); | 3521 node.visitChildren(this); |
| 3528 } | 3522 } |
| 3529 | 3523 |
| 3530 visitStringInterpolationPart(StringInterpolationPart node) { | 3524 visitStringInterpolationPart(StringInterpolationPart node) { |
| 3531 registerImplicitInvocation('toString', 0); | 3525 registerImplicitInvocation('toString', 0); |
| 3532 node.visitChildren(this); | 3526 node.visitChildren(this); |
| 3533 } | 3527 } |
| 3534 | 3528 |
| 3535 visitBreakStatement(BreakStatement node) { | 3529 visitBreakStatement(BreakStatement node) { |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3980 DartType exceptionType = registry.getType(node.type); | 3974 DartType exceptionType = registry.getType(node.type); |
| 3981 Node exceptionVariable = exceptionDefinition.definitions.nodes.head; | 3975 Node exceptionVariable = exceptionDefinition.definitions.nodes.head; |
| 3982 VariableElementX exceptionElement = | 3976 VariableElementX exceptionElement = |
| 3983 registry.getDefinition(exceptionVariable); | 3977 registry.getDefinition(exceptionVariable); |
| 3984 exceptionElement.variables.type = exceptionType; | 3978 exceptionElement.variables.type = exceptionType; |
| 3985 } | 3979 } |
| 3986 if (stackTraceDefinition != null) { | 3980 if (stackTraceDefinition != null) { |
| 3987 Node stackTraceVariable = stackTraceDefinition.definitions.nodes.head; | 3981 Node stackTraceVariable = stackTraceDefinition.definitions.nodes.head; |
| 3988 VariableElementX stackTraceElement = | 3982 VariableElementX stackTraceElement = |
| 3989 registry.getDefinition(stackTraceVariable); | 3983 registry.getDefinition(stackTraceVariable); |
| 3984 registry.registerInstantiatedClass(compiler.stackTraceClass); |
| 3990 stackTraceElement.variables.type = compiler.stackTraceClass.rawType; | 3985 stackTraceElement.variables.type = compiler.stackTraceClass.rawType; |
| 3991 } | 3986 } |
| 3992 } | 3987 } |
| 3993 | 3988 |
| 3994 visitTypedef(Typedef node) { | 3989 visitTypedef(Typedef node) { |
| 3995 internalError(node, 'typedef'); | 3990 internalError(node, 'typedef'); |
| 3996 } | 3991 } |
| 3997 } | 3992 } |
| 3998 | 3993 |
| 3999 class TypeDefinitionVisitor extends MappingVisitor<DartType> { | 3994 class TypeDefinitionVisitor extends MappingVisitor<DartType> { |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4772 if (scope.variableReferencedInInitializer) { | 4767 if (scope.variableReferencedInInitializer) { |
| 4773 compiler.reportError( | 4768 compiler.reportError( |
| 4774 identifier, MessageKind.REFERENCE_IN_INITIALIZATION, | 4769 identifier, MessageKind.REFERENCE_IN_INITIALIZATION, |
| 4775 {'variableName': name}); | 4770 {'variableName': name}); |
| 4776 } | 4771 } |
| 4777 return identifier; | 4772 return identifier; |
| 4778 } | 4773 } |
| 4779 | 4774 |
| 4780 Identifier visitIdentifier(Identifier node) { | 4775 Identifier visitIdentifier(Identifier node) { |
| 4781 // The variable is initialized to null. | 4776 // The variable is initialized to null. |
| 4782 registry.registerLiteralNull(); | 4777 registry.registerInstantiatedClass(compiler.nullClass); |
| 4783 if (definitions.modifiers.isConst) { | 4778 if (definitions.modifiers.isConst) { |
| 4784 compiler.reportError(node, MessageKind.CONST_WITHOUT_INITIALIZER); | 4779 compiler.reportError(node, MessageKind.CONST_WITHOUT_INITIALIZER); |
| 4785 } | 4780 } |
| 4786 if (definitions.modifiers.isFinal && | 4781 if (definitions.modifiers.isFinal && |
| 4787 !resolver.allowFinalWithoutInitializer) { | 4782 !resolver.allowFinalWithoutInitializer) { |
| 4788 compiler.reportError(node, MessageKind.FINAL_WITHOUT_INITIALIZER); | 4783 compiler.reportError(node, MessageKind.FINAL_WITHOUT_INITIALIZER); |
| 4789 } | 4784 } |
| 4790 return node; | 4785 return node; |
| 4791 } | 4786 } |
| 4792 | 4787 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5058 } | 5053 } |
| 5059 | 5054 |
| 5060 /// The result for the resolution of the `assert` method. | 5055 /// The result for the resolution of the `assert` method. |
| 5061 class AssertResult implements ResolutionResult { | 5056 class AssertResult implements ResolutionResult { |
| 5062 const AssertResult(); | 5057 const AssertResult(); |
| 5063 | 5058 |
| 5064 Element get element => null; | 5059 Element get element => null; |
| 5065 | 5060 |
| 5066 String toString() => 'AssertResult()'; | 5061 String toString() => 'AssertResult()'; |
| 5067 } | 5062 } |
| OLD | NEW |