| 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 Element get currentElement; | 8 Element get currentElement; |
| 9 Set<Node> get superUses; | 9 Set<Node> get superUses; |
| 10 | 10 |
| (...skipping 3263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3274 TypedefElement typedefElement, | 3274 TypedefElement typedefElement, |
| 3275 TreeElementMapping mapping) | 3275 TreeElementMapping mapping) |
| 3276 : super(compiler, typedefElement, mapping); | 3276 : super(compiler, typedefElement, mapping); |
| 3277 | 3277 |
| 3278 visitTypedef(Typedef node) { | 3278 visitTypedef(Typedef node) { |
| 3279 TypedefType type = element.computeType(compiler); | 3279 TypedefType type = element.computeType(compiler); |
| 3280 scope = new TypeDeclarationScope(scope, element); | 3280 scope = new TypeDeclarationScope(scope, element); |
| 3281 resolveTypeVariableBounds(node.typeParameters); | 3281 resolveTypeVariableBounds(node.typeParameters); |
| 3282 | 3282 |
| 3283 element.functionSignature = SignatureResolver.analyze( | 3283 element.functionSignature = SignatureResolver.analyze( |
| 3284 compiler, node.formals, node.returnType, element); | 3284 compiler, node.formals, node.returnType, element, |
| 3285 defaultValuesAllowed: false); |
| 3285 | 3286 |
| 3286 element.alias = compiler.computeFunctionType( | 3287 element.alias = compiler.computeFunctionType( |
| 3287 element, element.functionSignature); | 3288 element, element.functionSignature); |
| 3288 | 3289 |
| 3289 // TODO(johnniwinther): Check for cyclic references in the typedef alias. | 3290 // TODO(johnniwinther): Check for cyclic references in the typedef alias. |
| 3290 } | 3291 } |
| 3291 } | 3292 } |
| 3292 | 3293 |
| 3293 /** | 3294 /** |
| 3294 * The implementation of [ResolverTask.resolveClass]. | 3295 * The implementation of [ResolverTask.resolveClass]. |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3772 resolver.defineElement(link.head, element); | 3773 resolver.defineElement(link.head, element); |
| 3773 } | 3774 } |
| 3774 } | 3775 } |
| 3775 } | 3776 } |
| 3776 | 3777 |
| 3777 /** | 3778 /** |
| 3778 * [SignatureResolver] resolves function signatures. | 3779 * [SignatureResolver] resolves function signatures. |
| 3779 */ | 3780 */ |
| 3780 class SignatureResolver extends CommonResolverVisitor<Element> { | 3781 class SignatureResolver extends CommonResolverVisitor<Element> { |
| 3781 final Element enclosingElement; | 3782 final Element enclosingElement; |
| 3783 final bool defaultValuesAllowed; |
| 3782 Link<Element> optionalParameters = const Link<Element>(); | 3784 Link<Element> optionalParameters = const Link<Element>(); |
| 3783 int optionalParameterCount = 0; | 3785 int optionalParameterCount = 0; |
| 3784 bool optionalParametersAreNamed = false; | 3786 bool optionalParametersAreNamed = false; |
| 3785 VariableDefinitions currentDefinitions; | 3787 VariableDefinitions currentDefinitions; |
| 3786 | 3788 |
| 3787 SignatureResolver(Compiler compiler, this.enclosingElement) : super(compiler); | 3789 SignatureResolver(Compiler compiler, |
| 3790 this.enclosingElement, |
| 3791 {this.defaultValuesAllowed: true}) |
| 3792 : super(compiler); |
| 3788 | 3793 |
| 3789 Element visitNodeList(NodeList node) { | 3794 Element visitNodeList(NodeList node) { |
| 3790 // This must be a list of optional arguments. | 3795 // This must be a list of optional arguments. |
| 3791 String value = node.beginToken.stringValue; | 3796 String value = node.beginToken.stringValue; |
| 3792 if ((!identical(value, '[')) && (!identical(value, '{'))) { | 3797 if ((!identical(value, '[')) && (!identical(value, '{'))) { |
| 3793 internalError(node, "expected optional parameters"); | 3798 internalError(node, "expected optional parameters"); |
| 3794 } | 3799 } |
| 3795 optionalParametersAreNamed = (identical(value, '{')); | 3800 optionalParametersAreNamed = (identical(value, '{')); |
| 3796 LinkBuilder<Element> elements = analyzeNodes(node.nodes); | 3801 LinkBuilder<Element> elements = analyzeNodes(node.nodes); |
| 3797 optionalParameterCount = elements.length; | 3802 optionalParameterCount = elements.length; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3869 } else if (!fieldElement.isInstanceMember()) { | 3874 } else if (!fieldElement.isInstanceMember()) { |
| 3870 error(node, MessageKind.NOT_INSTANCE_FIELD, {'fieldName': name}); | 3875 error(node, MessageKind.NOT_INSTANCE_FIELD, {'fieldName': name}); |
| 3871 } | 3876 } |
| 3872 Element variables = new VariableListElementX.node(currentDefinitions, | 3877 Element variables = new VariableListElementX.node(currentDefinitions, |
| 3873 ElementKind.VARIABLE_LIST, enclosingElement); | 3878 ElementKind.VARIABLE_LIST, enclosingElement); |
| 3874 element = new FieldParameterElementX(name, fieldElement, variables, node); | 3879 element = new FieldParameterElementX(name, fieldElement, variables, node); |
| 3875 } | 3880 } |
| 3876 return element; | 3881 return element; |
| 3877 } | 3882 } |
| 3878 | 3883 |
| 3884 /// A [SendSet] node is an optional parameter with a default value. |
| 3879 Element visitSendSet(SendSet node) { | 3885 Element visitSendSet(SendSet node) { |
| 3880 Element element; | 3886 Element element; |
| 3881 if (node.receiver != null) { | 3887 if (node.receiver != null) { |
| 3882 element = visitSend(node); | 3888 element = visitSend(node); |
| 3883 } else if (node.selector.asIdentifier() != null || | 3889 } else if (node.selector.asIdentifier() != null || |
| 3884 node.selector.asFunctionExpression() != null) { | 3890 node.selector.asFunctionExpression() != null) { |
| 3885 Element variables = new VariableListElementX.node(currentDefinitions, | 3891 Element variables = new VariableListElementX.node(currentDefinitions, |
| 3886 ElementKind.VARIABLE_LIST, enclosingElement); | 3892 ElementKind.VARIABLE_LIST, enclosingElement); |
| 3887 SourceString source = node.selector.asIdentifier() != null ? | 3893 SourceString source = node.selector.asIdentifier() != null ? |
| 3888 node.selector.asIdentifier().source : | 3894 node.selector.asIdentifier().source : |
| 3889 node.selector.asFunctionExpression().name.asIdentifier().source; | 3895 node.selector.asFunctionExpression().name.asIdentifier().source; |
| 3890 element = new VariableElementX(source, variables, | 3896 element = new VariableElementX(source, variables, |
| 3891 ElementKind.PARAMETER, node); | 3897 ElementKind.PARAMETER, node); |
| 3892 } | 3898 } |
| 3899 Node defaultValue = node.arguments.head; |
| 3900 if (!defaultValuesAllowed) { |
| 3901 error(defaultValue, MessageKind.TYPEDEF_FORMAL_WITH_DEFAULT); |
| 3902 } |
| 3893 // Visit the value. The compile time constant handler will | 3903 // Visit the value. The compile time constant handler will |
| 3894 // make sure it's a compile time constant. | 3904 // make sure it's a compile time constant. |
| 3895 resolveExpression(node.arguments.head); | 3905 resolveExpression(defaultValue); |
| 3896 return element; | 3906 return element; |
| 3897 } | 3907 } |
| 3898 | 3908 |
| 3899 Element visitFunctionExpression(FunctionExpression node) { | 3909 Element visitFunctionExpression(FunctionExpression node) { |
| 3900 // This is a function typed parameter. | 3910 // This is a function typed parameter. |
| 3901 // TODO(ahe): Resolve the function type. | 3911 // TODO(ahe): Resolve the function type. |
| 3902 return visit(node.name); | 3912 return visit(node.name); |
| 3903 } | 3913 } |
| 3904 | 3914 |
| 3905 LinkBuilder<Element> analyzeNodes(Link<Node> link) { | 3915 LinkBuilder<Element> analyzeNodes(Link<Node> link) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3918 } | 3928 } |
| 3919 return elements; | 3929 return elements; |
| 3920 } | 3930 } |
| 3921 | 3931 |
| 3922 /** | 3932 /** |
| 3923 * Resolves formal parameters and return type to a [FunctionSignature]. | 3933 * Resolves formal parameters and return type to a [FunctionSignature]. |
| 3924 */ | 3934 */ |
| 3925 static FunctionSignature analyze(Compiler compiler, | 3935 static FunctionSignature analyze(Compiler compiler, |
| 3926 NodeList formalParameters, | 3936 NodeList formalParameters, |
| 3927 Node returnNode, | 3937 Node returnNode, |
| 3928 Element element) { | 3938 Element element, |
| 3929 SignatureResolver visitor = new SignatureResolver(compiler, element); | 3939 {bool defaultValuesAllowed: true}) { |
| 3940 SignatureResolver visitor = new SignatureResolver(compiler, element, |
| 3941 defaultValuesAllowed: defaultValuesAllowed); |
| 3930 Link<Element> parameters = const Link<Element>(); | 3942 Link<Element> parameters = const Link<Element>(); |
| 3931 int requiredParameterCount = 0; | 3943 int requiredParameterCount = 0; |
| 3932 if (formalParameters == null) { | 3944 if (formalParameters == null) { |
| 3933 if (!element.isGetter()) { | 3945 if (!element.isGetter()) { |
| 3934 compiler.reportError(element, MessageKind.MISSING_FORMALS); | 3946 compiler.reportError(element, MessageKind.MISSING_FORMALS); |
| 3935 } | 3947 } |
| 3936 } else { | 3948 } else { |
| 3937 if (element.isGetter()) { | 3949 if (element.isGetter()) { |
| 3938 if (!identical(formalParameters.getEndToken().next.stringValue, | 3950 if (!identical(formalParameters.getEndToken().next.stringValue, |
| 3939 // TODO(ahe): Remove the check for native keyword. | 3951 // TODO(ahe): Remove the check for native keyword. |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4149 return e; | 4161 return e; |
| 4150 } | 4162 } |
| 4151 | 4163 |
| 4152 /// Assumed to be called by [resolveRedirectingFactory]. | 4164 /// Assumed to be called by [resolveRedirectingFactory]. |
| 4153 Element visitReturn(Return node) { | 4165 Element visitReturn(Return node) { |
| 4154 Node expression = node.expression; | 4166 Node expression = node.expression; |
| 4155 return finishConstructorReference(visit(expression), | 4167 return finishConstructorReference(visit(expression), |
| 4156 expression, expression); | 4168 expression, expression); |
| 4157 } | 4169 } |
| 4158 } | 4170 } |
| OLD | NEW |