| 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 3984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3995 } | 3995 } |
| 3996 | 3996 |
| 3997 /** | 3997 /** |
| 3998 * [SignatureResolver] resolves function signatures. | 3998 * [SignatureResolver] resolves function signatures. |
| 3999 */ | 3999 */ |
| 4000 class SignatureResolver extends CommonResolverVisitor<Element> { | 4000 class SignatureResolver extends CommonResolverVisitor<Element> { |
| 4001 final Element enclosingElement; | 4001 final Element enclosingElement; |
| 4002 final bool defaultValuesAllowed; | 4002 final bool defaultValuesAllowed; |
| 4003 Link<Element> optionalParameters = const Link<Element>(); | 4003 Link<Element> optionalParameters = const Link<Element>(); |
| 4004 int optionalParameterCount = 0; | 4004 int optionalParameterCount = 0; |
| 4005 bool isOptionalParameter = false; |
| 4005 bool optionalParametersAreNamed = false; | 4006 bool optionalParametersAreNamed = false; |
| 4006 VariableDefinitions currentDefinitions; | 4007 VariableDefinitions currentDefinitions; |
| 4007 | 4008 |
| 4008 SignatureResolver(Compiler compiler, | 4009 SignatureResolver(Compiler compiler, |
| 4009 this.enclosingElement, | 4010 this.enclosingElement, |
| 4010 {this.defaultValuesAllowed: true}) | 4011 {this.defaultValuesAllowed: true}) |
| 4011 : super(compiler); | 4012 : super(compiler); |
| 4012 | 4013 |
| 4013 Element visitNodeList(NodeList node) { | 4014 Element visitNodeList(NodeList node) { |
| 4014 // This must be a list of optional arguments. | 4015 // This must be a list of optional arguments. |
| 4015 String value = node.beginToken.stringValue; | 4016 String value = node.beginToken.stringValue; |
| 4016 if ((!identical(value, '[')) && (!identical(value, '{'))) { | 4017 if ((!identical(value, '[')) && (!identical(value, '{'))) { |
| 4017 internalError(node, "expected optional parameters"); | 4018 internalError(node, "expected optional parameters"); |
| 4018 } | 4019 } |
| 4019 optionalParametersAreNamed = (identical(value, '{')); | 4020 optionalParametersAreNamed = (identical(value, '{')); |
| 4021 isOptionalParameter = true; |
| 4020 LinkBuilder<Element> elements = analyzeNodes(node.nodes); | 4022 LinkBuilder<Element> elements = analyzeNodes(node.nodes); |
| 4021 optionalParameterCount = elements.length; | 4023 optionalParameterCount = elements.length; |
| 4022 optionalParameters = elements.toLink(); | 4024 optionalParameters = elements.toLink(); |
| 4023 return null; | 4025 return null; |
| 4024 } | 4026 } |
| 4025 | 4027 |
| 4026 Element visitVariableDefinitions(VariableDefinitions node) { | 4028 Element visitVariableDefinitions(VariableDefinitions node) { |
| 4027 Link<Node> definitions = node.definitions.nodes; | 4029 Link<Node> definitions = node.definitions.nodes; |
| 4028 if (definitions.isEmpty) { | 4030 if (definitions.isEmpty) { |
| 4029 cancel(node, 'internal error: no parameter definition'); | 4031 cancel(node, 'internal error: no parameter definition'); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4046 | 4048 |
| 4047 if (currentDefinitions != null) { | 4049 if (currentDefinitions != null) { |
| 4048 cancel(node, 'function type parameters not supported'); | 4050 cancel(node, 'function type parameters not supported'); |
| 4049 } | 4051 } |
| 4050 currentDefinitions = node; | 4052 currentDefinitions = node; |
| 4051 Element element = definition.accept(this); | 4053 Element element = definition.accept(this); |
| 4052 currentDefinitions = null; | 4054 currentDefinitions = null; |
| 4053 return element; | 4055 return element; |
| 4054 } | 4056 } |
| 4055 | 4057 |
| 4058 void validateName(Identifier node) { |
| 4059 SourceString name = node.source; |
| 4060 if (isOptionalParameter && |
| 4061 optionalParametersAreNamed && |
| 4062 node.source.isPrivate()) { |
| 4063 compiler.reportError(node, MessageKind.PRIVATE_NAMED_PARAMETER); |
| 4064 } |
| 4065 } |
| 4066 |
| 4056 Element visitIdentifier(Identifier node) { | 4067 Element visitIdentifier(Identifier node) { |
| 4068 validateName(node); |
| 4057 Element variables = new VariableListElementX.node(currentDefinitions, | 4069 Element variables = new VariableListElementX.node(currentDefinitions, |
| 4058 ElementKind.VARIABLE_LIST, enclosingElement); | 4070 ElementKind.VARIABLE_LIST, enclosingElement); |
| 4059 // Ensure a parameter is not typed 'void'. | 4071 // Ensure a parameter is not typed 'void'. |
| 4060 variables.computeType(compiler); | 4072 variables.computeType(compiler); |
| 4061 return new VariableElementX(node.source, variables, | 4073 return new VariableElementX(node.source, variables, |
| 4062 ElementKind.PARAMETER, node); | 4074 ElementKind.PARAMETER, node); |
| 4063 } | 4075 } |
| 4064 | 4076 |
| 4065 SourceString getParameterName(Send node) { | 4077 SourceString getParameterName(Send node) { |
| 4066 var identifier = node.selector.asIdentifier(); | 4078 var identifier = node.selector.asIdentifier(); |
| 4067 if (identifier != null) { | 4079 if (identifier != null) { |
| 4068 // Normal parameter: [:Type name:]. | 4080 // Normal parameter: [:Type name:]. |
| 4081 validateName(identifier); |
| 4069 return identifier.source; | 4082 return identifier.source; |
| 4070 } else { | 4083 } else { |
| 4071 // Function type parameter: [:void name(DartType arg):]. | 4084 // Function type parameter: [:void name(DartType arg):]. |
| 4072 var functionExpression = node.selector.asFunctionExpression(); | 4085 var functionExpression = node.selector.asFunctionExpression(); |
| 4073 if (functionExpression != null && | 4086 if (functionExpression != null && |
| 4074 functionExpression.name.asIdentifier() != null) { | 4087 functionExpression.name.asIdentifier() != null) { |
| 4088 validateName(functionExpression.name); |
| 4075 return functionExpression.name.asIdentifier().source; | 4089 return functionExpression.name.asIdentifier().source; |
| 4076 } else { | 4090 } else { |
| 4077 cancel(node, | 4091 cancel(node, |
| 4078 'internal error: unimplemented receiver on parameter send'); | 4092 'internal error: unimplemented receiver on parameter send'); |
| 4079 } | 4093 } |
| 4080 } | 4094 } |
| 4081 } | 4095 } |
| 4082 | 4096 |
| 4083 // The only valid [Send] can be in constructors and must be of the form | 4097 // The only valid [Send] can be in constructors and must be of the form |
| 4084 // [:this.x:] (where [:x:] represents an instance field). | 4098 // [:this.x:] (where [:x:] represents an instance field). |
| (...skipping 23 matching lines...) Expand all Loading... |
| 4108 | 4122 |
| 4109 /// A [SendSet] node is an optional parameter with a default value. | 4123 /// A [SendSet] node is an optional parameter with a default value. |
| 4110 Element visitSendSet(SendSet node) { | 4124 Element visitSendSet(SendSet node) { |
| 4111 Element element; | 4125 Element element; |
| 4112 if (node.receiver != null) { | 4126 if (node.receiver != null) { |
| 4113 element = visitSend(node); | 4127 element = visitSend(node); |
| 4114 } else if (node.selector.asIdentifier() != null || | 4128 } else if (node.selector.asIdentifier() != null || |
| 4115 node.selector.asFunctionExpression() != null) { | 4129 node.selector.asFunctionExpression() != null) { |
| 4116 Element variables = new VariableListElementX.node(currentDefinitions, | 4130 Element variables = new VariableListElementX.node(currentDefinitions, |
| 4117 ElementKind.VARIABLE_LIST, enclosingElement); | 4131 ElementKind.VARIABLE_LIST, enclosingElement); |
| 4118 SourceString source = node.selector.asIdentifier() != null ? | 4132 Identifier identifier = node.selector.asIdentifier() != null ? |
| 4119 node.selector.asIdentifier().source : | 4133 node.selector.asIdentifier() : |
| 4120 node.selector.asFunctionExpression().name.asIdentifier().source; | 4134 node.selector.asFunctionExpression().name.asIdentifier(); |
| 4135 validateName(identifier); |
| 4136 SourceString source = identifier.source; |
| 4121 element = new VariableElementX(source, variables, | 4137 element = new VariableElementX(source, variables, |
| 4122 ElementKind.PARAMETER, node); | 4138 ElementKind.PARAMETER, node); |
| 4123 } | 4139 } |
| 4124 Node defaultValue = node.arguments.head; | 4140 Node defaultValue = node.arguments.head; |
| 4125 if (!defaultValuesAllowed) { | 4141 if (!defaultValuesAllowed) { |
| 4126 error(defaultValue, MessageKind.TYPEDEF_FORMAL_WITH_DEFAULT); | 4142 error(defaultValue, MessageKind.TYPEDEF_FORMAL_WITH_DEFAULT); |
| 4127 } | 4143 } |
| 4128 // Visit the value. The compile time constant handler will | 4144 // Visit the value. The compile time constant handler will |
| 4129 // make sure it's a compile time constant. | 4145 // make sure it's a compile time constant. |
| 4130 resolveExpression(defaultValue); | 4146 resolveExpression(defaultValue); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4395 return e; | 4411 return e; |
| 4396 } | 4412 } |
| 4397 | 4413 |
| 4398 /// Assumed to be called by [resolveRedirectingFactory]. | 4414 /// Assumed to be called by [resolveRedirectingFactory]. |
| 4399 Element visitReturn(Return node) { | 4415 Element visitReturn(Return node) { |
| 4400 Node expression = node.expression; | 4416 Node expression = node.expression; |
| 4401 return finishConstructorReference(visit(expression), | 4417 return finishConstructorReference(visit(expression), |
| 4402 expression, expression); | 4418 expression, expression); |
| 4403 } | 4419 } |
| 4404 } | 4420 } |
| OLD | NEW |