| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.resolution.constructors; | 5 library dart2js.resolution.constructors; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/resolution.dart' show Resolution; | 8 import '../common/resolution.dart' show Resolution; |
| 9 import '../constants/constructors.dart' | 9 import '../constants/constructors.dart' |
| 10 show | 10 show |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 node, constructorName, kind, {}); | 287 node, constructorName, kind, {}); |
| 288 } | 288 } |
| 289 } | 289 } |
| 290 return result; | 290 return result; |
| 291 } | 291 } |
| 292 | 292 |
| 293 /** | 293 /** |
| 294 * Resolve all initializers of this constructor. In the case of a redirecting | 294 * Resolve all initializers of this constructor. In the case of a redirecting |
| 295 * constructor, the resolved constructor's function element is returned. | 295 * constructor, the resolved constructor's function element is returned. |
| 296 */ | 296 */ |
| 297 ConstructorElement resolveInitializers( | 297 ConstructorElement resolveInitializers() { |
| 298 {bool enableInitializingFormalAccess: false}) { | |
| 299 Map<dynamic /*String|int*/, ConstantExpression> defaultValues = | 298 Map<dynamic /*String|int*/, ConstantExpression> defaultValues = |
| 300 <dynamic /*String|int*/, ConstantExpression>{}; | 299 <dynamic /*String|int*/, ConstantExpression>{}; |
| 301 ConstructedConstantExpression constructorInvocation; | 300 ConstructedConstantExpression constructorInvocation; |
| 302 // Keep track of all "this.param" parameters specified for constructor so | 301 // Keep track of all "this.param" parameters specified for constructor so |
| 303 // that we can ensure that fields are initialized only once. | 302 // that we can ensure that fields are initialized only once. |
| 304 FunctionSignature functionParameters = constructor.functionSignature; | 303 FunctionSignature functionParameters = constructor.functionSignature; |
| 305 Scope oldScope = visitor.scope; | 304 Scope oldScope = visitor.scope; |
| 306 if (enableInitializingFormalAccess) { | 305 // In order to get the correct detection of name clashes between all |
| 307 // In order to get the correct detection of name clashes between all | 306 // parameters (regular ones and initializing formals) we must extend |
| 308 // parameters (regular ones and initializing formals) we must extend | 307 // the parameter scope rather than adding a new nested scope. |
| 309 // the parameter scope rather than adding a new nested scope. | 308 visitor.scope = new ExtensionScope(visitor.scope); |
| 310 visitor.scope = new ExtensionScope(visitor.scope); | |
| 311 } | |
| 312 Link<Node> parameterNodes = (functionNode.parameters == null) | 309 Link<Node> parameterNodes = (functionNode.parameters == null) |
| 313 ? const Link<Node>() | 310 ? const Link<Node>() |
| 314 : functionNode.parameters.nodes; | 311 : functionNode.parameters.nodes; |
| 315 functionParameters.forEachParameter((ParameterElementX element) { | 312 functionParameters.forEachParameter((ParameterElementX element) { |
| 316 List<Element> optionals = functionParameters.optionalParameters; | 313 List<Element> optionals = functionParameters.optionalParameters; |
| 317 if (!optionals.isEmpty && element == optionals.first) { | 314 if (!optionals.isEmpty && element == optionals.first) { |
| 318 NodeList nodes = parameterNodes.head; | 315 NodeList nodes = parameterNodes.head; |
| 319 parameterNodes = nodes.nodes; | 316 parameterNodes = nodes.nodes; |
| 320 } | 317 } |
| 321 if (isConst) { | 318 if (isConst) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 342 } | 339 } |
| 343 if (element.isInitializingFormal) { | 340 if (element.isInitializingFormal) { |
| 344 VariableDefinitions variableDefinitions = parameterNodes.head; | 341 VariableDefinitions variableDefinitions = parameterNodes.head; |
| 345 Node parameterNode = variableDefinitions.definitions.nodes.head; | 342 Node parameterNode = variableDefinitions.definitions.nodes.head; |
| 346 InitializingFormalElementX initializingFormal = element; | 343 InitializingFormalElementX initializingFormal = element; |
| 347 FieldElement field = initializingFormal.fieldElement; | 344 FieldElement field = initializingFormal.fieldElement; |
| 348 if (!field.isMalformed) { | 345 if (!field.isMalformed) { |
| 349 registry.registerStaticUse(new StaticUse.fieldInit(field)); | 346 registry.registerStaticUse(new StaticUse.fieldInit(field)); |
| 350 } | 347 } |
| 351 checkForDuplicateInitializers(field, element.initializer); | 348 checkForDuplicateInitializers(field, element.initializer); |
| 352 if (enableInitializingFormalAccess) { | 349 visitor.defineLocalVariable(parameterNode, initializingFormal); |
| 353 visitor.defineLocalVariable(parameterNode, initializingFormal); | 350 visitor.addToScope(initializingFormal); |
| 354 visitor.addToScope(initializingFormal); | |
| 355 } | |
| 356 if (isConst) { | 351 if (isConst) { |
| 357 if (element.isNamed) { | 352 if (element.isNamed) { |
| 358 fieldInitializers[field] = new NamedArgumentReference(element.name); | 353 fieldInitializers[field] = new NamedArgumentReference(element.name); |
| 359 } else { | 354 } else { |
| 360 int index = element.functionDeclaration.parameters.indexOf(element); | 355 int index = element.functionDeclaration.parameters.indexOf(element); |
| 361 fieldInitializers[field] = new PositionalArgumentReference(index); | 356 fieldInitializers[field] = new PositionalArgumentReference(index); |
| 362 } | 357 } |
| 363 } else { | 358 } else { |
| 364 isValidAsConstant = false; | 359 isValidAsConstant = false; |
| 365 } | 360 } |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 // constructors. | 879 // constructors. |
| 885 return null; | 880 return null; |
| 886 } | 881 } |
| 887 // TODO(johnniwinther): Use [Name] for lookup. | 882 // TODO(johnniwinther): Use [Name] for lookup. |
| 888 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 883 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
| 889 if (constructor != null) { | 884 if (constructor != null) { |
| 890 constructor = constructor.declaration; | 885 constructor = constructor.declaration; |
| 891 } | 886 } |
| 892 return constructor; | 887 return constructor; |
| 893 } | 888 } |
| OLD | NEW |