Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:analyzer/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 7 import 'package:analyzer/dart/ast/token.dart'; | 7 import 'package:analyzer/dart/ast/token.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/dart/element/type.dart'; | 9 import 'package:analyzer/dart/element/type.dart'; |
| 10 import 'package:analyzer/src/dart/element/element.dart'; | 10 import 'package:analyzer/src/dart/element/element.dart'; |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 class _KernelLibraryResynthesizerContextImpl | 377 class _KernelLibraryResynthesizerContextImpl |
| 378 implements KernelLibraryResynthesizerContext { | 378 implements KernelLibraryResynthesizerContext { |
| 379 final KernelResynthesizer _resynthesizer; | 379 final KernelResynthesizer _resynthesizer; |
| 380 | 380 |
| 381 @override | 381 @override |
| 382 final kernel.Library library; | 382 final kernel.Library library; |
| 383 | 383 |
| 384 _KernelLibraryResynthesizerContextImpl(this._resynthesizer, this.library); | 384 _KernelLibraryResynthesizerContextImpl(this._resynthesizer, this.library); |
| 385 | 385 |
| 386 @override | 386 @override |
| 387 UnitExplicitTopLevelAccessors buildTopLevelAccessors( | |
| 388 CompilationUnitElementImpl unit) { | |
| 389 var accessorsData = new UnitExplicitTopLevelAccessors(); | |
| 390 var implicitVariables = <String, TopLevelVariableElementImpl>{}; | |
| 391 // Build explicit property accessors and implicit fields. | |
| 392 for (var k in library.procedures) { | |
|
Brian Wilkerson
2017/07/26 18:17:11
"k" --> "procedure"? ("k" seems like a strange nam
| |
| 393 bool isGetter = k.kind == kernel.ProcedureKind.Getter; | |
| 394 bool isSetter = k.kind == kernel.ProcedureKind.Setter; | |
| 395 if (isGetter || isSetter) { | |
| 396 var accessor = new PropertyAccessorElementImpl.forKernel(unit, k); | |
| 397 accessorsData.accessors.add(accessor); | |
| 398 | |
| 399 // Create or update the implicit variable. | |
| 400 String name = accessor.displayName; | |
| 401 TopLevelVariableElementImpl variable = implicitVariables[name]; | |
| 402 if (variable == null) { | |
| 403 variable = new TopLevelVariableElementImpl(name, -1); | |
| 404 implicitVariables[name] = variable; | |
| 405 variable.enclosingElement = unit; | |
| 406 variable.isSynthetic = true; | |
| 407 variable.isFinal = isGetter; | |
| 408 } else { | |
| 409 variable.isFinal = false; | |
| 410 } | |
| 411 | |
| 412 // Attach the accessor to the variable. | |
| 413 accessor.variable = variable; | |
| 414 if (isGetter) { | |
| 415 variable.getter = accessor; | |
| 416 } else { | |
| 417 variable.setter = accessor; | |
| 418 } | |
| 419 } | |
| 420 } | |
| 421 accessorsData.implicitVariables.addAll(implicitVariables.values); | |
| 422 return accessorsData; | |
| 423 } | |
| 424 | |
| 425 @override | |
| 426 UnitExplicitTopLevelVariables buildTopLevelVariables( | |
| 427 CompilationUnitElementImpl unit) { | |
| 428 int numberOfVariables = library.fields.length; | |
| 429 var variablesData = new UnitExplicitTopLevelVariables(numberOfVariables); | |
| 430 for (int i = 0; i < numberOfVariables; i++) { | |
| 431 kernel.Field kField = library.fields[i]; | |
|
Brian Wilkerson
2017/07/26 18:17:11
"kField" --> "field"?
| |
| 432 | |
| 433 // Add the explicit variables. | |
| 434 TopLevelVariableElementImpl variable; | |
| 435 if (kField.isConst && kField.initializer != null) { | |
| 436 variable = new ConstTopLevelVariableElementImpl.forKernel(unit, kField); | |
| 437 } else { | |
| 438 variable = new TopLevelVariableElementImpl.forKernel(unit, kField); | |
| 439 } | |
| 440 variablesData.variables[i] = variable; | |
| 441 | |
| 442 // Add the implicit accessors. | |
| 443 variablesData.implicitAccessors | |
| 444 .add(new PropertyAccessorElementImpl_ImplicitGetter(variable)); | |
| 445 if (!(variable.isConst || variable.isFinal)) { | |
| 446 variablesData.implicitAccessors | |
| 447 .add(new PropertyAccessorElementImpl_ImplicitSetter(variable)); | |
| 448 } | |
| 449 } | |
| 450 return variablesData; | |
| 451 } | |
| 452 | |
| 453 @override | |
| 387 ConstructorInitializer getConstructorInitializer( | 454 ConstructorInitializer getConstructorInitializer( |
| 388 ConstructorElementImpl constructor, kernel.Initializer k) { | 455 ConstructorElementImpl constructor, kernel.Initializer k) { |
| 389 if (k is kernel.LocalInitializer || | 456 if (k is kernel.LocalInitializer || |
| 390 k is kernel.FieldInitializer && k.isSynthetic || | 457 k is kernel.FieldInitializer && k.isSynthetic || |
| 391 k is kernel.SuperInitializer && k.isSynthetic) { | 458 k is kernel.SuperInitializer && k.isSynthetic) { |
| 392 return null; | 459 return null; |
| 393 } | 460 } |
| 394 return new _ExprBuilder(this).buildInitializer(k); | 461 return new _ExprBuilder(this).buildInitializer(k); |
| 395 } | 462 } |
| 396 | 463 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 for (var typeParameter in ctx.typeParameters) { | 649 for (var typeParameter in ctx.typeParameters) { |
| 583 if (typeParameter.name == name) { | 650 if (typeParameter.name == name) { |
| 584 return typeParameter; | 651 return typeParameter; |
| 585 } | 652 } |
| 586 } | 653 } |
| 587 } | 654 } |
| 588 } | 655 } |
| 589 throw new StateError('Not found $kernelTypeParameter in $context'); | 656 throw new StateError('Not found $kernelTypeParameter in $context'); |
| 590 } | 657 } |
| 591 } | 658 } |
| OLD | NEW |