OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.procedure_builder; | 5 library fasta.procedure_builder; |
6 | 6 |
7 // Note: we're deliberately using AsyncMarker and ProcedureKind from kernel | 7 // Note: we're deliberately using AsyncMarker and ProcedureKind from kernel |
8 // outside the kernel-specific builders. This is simpler than creating | 8 // outside the kernel-specific builders. This is simpler than creating |
9 // additional enums. | 9 // additional enums. |
10 import 'package:kernel/ast.dart' show AsyncMarker, ProcedureKind; | 10 import 'package:kernel/ast.dart' show AsyncMarker, ProcedureKind; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 if (formals == null) return parent; | 68 if (formals == null) return parent; |
69 Map<String, Builder> local = <String, Builder>{}; | 69 Map<String, Builder> local = <String, Builder>{}; |
70 for (FormalParameterBuilder formal in formals) { | 70 for (FormalParameterBuilder formal in formals) { |
71 if (!isConstructor || !formal.hasThis) { | 71 if (!isConstructor || !formal.hasThis) { |
72 local[formal.name] = formal; | 72 local[formal.name] = formal; |
73 } | 73 } |
74 } | 74 } |
75 return new Scope(local, null, parent, isModifiable: false); | 75 return new Scope(local, null, parent, isModifiable: false); |
76 } | 76 } |
77 | 77 |
| 78 Scope computeFormalParameterInitializerScope(Scope parent) { |
| 79 // From |
| 80 // [dartLangSpec.tex](../../../../../../docs/language/dartLangSpec.tex) at |
| 81 // revision 94b23d3b125e9d246e07a2b43b61740759a0dace: |
| 82 // |
| 83 // When the formal parameter list of a non-redirecting generative |
| 84 // constructor contains any initializing formals, a new scope is |
| 85 // introduced, the _formal parameter initializer scope_, which is the |
| 86 // current scope of the initializer list of the constructor, and which is |
| 87 // enclosed in the scope where the constructor is declared. Each |
| 88 // initializing formal in the formal parameter list introduces a final |
| 89 // local variable into the formal parameter initializer scope, but not into |
| 90 // the formal parameter scope; every other formal parameter introduces a |
| 91 // local variable into both the formal parameter scope and the formal |
| 92 // parameter initializer scope. |
| 93 |
| 94 if (formals == null) return parent; |
| 95 Map<String, Builder> local = <String, Builder>{}; |
| 96 for (FormalParameterBuilder formal in formals) { |
| 97 local[formal.name] = formal.forFormalParameterInitializerScope(); |
| 98 } |
| 99 return new Scope(local, null, parent, isModifiable: false); |
| 100 } |
| 101 |
78 /// This scope doesn't correspond to any scope specified in the Dart | 102 /// This scope doesn't correspond to any scope specified in the Dart |
79 /// Programming Language Specifiction, 4th ed. It's an unspecified extension | 103 /// Programming Language Specifiction, 4th ed. It's an unspecified extension |
80 /// to support generic methods. | 104 /// to support generic methods. |
81 Scope computeTypeParameterScope(Scope parent) { | 105 Scope computeTypeParameterScope(Scope parent) { |
82 if (typeVariables == null) return parent; | 106 if (typeVariables == null) return parent; |
83 Map<String, Builder> local = <String, Builder>{}; | 107 Map<String, Builder> local = <String, Builder>{}; |
84 for (TypeVariableBuilder variable in typeVariables) { | 108 for (TypeVariableBuilder variable in typeVariables) { |
85 local[variable.name] = variable; | 109 local[variable.name] = variable; |
86 } | 110 } |
87 return new Scope(local, null, parent, isModifiable: false); | 111 return new Scope(local, null, parent, isModifiable: false); |
88 } | 112 } |
| 113 |
| 114 FormalParameterBuilder getFormal(String name) { |
| 115 for (FormalParameterBuilder formal in formals) { |
| 116 if (formal.name == name) return formal; |
| 117 } |
| 118 return null; |
| 119 } |
89 } | 120 } |
OLD | NEW |