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 /// Additional data model classes used by the summary builder. | 5 /// Additional data model classes used by the summary builder. |
6 /// | 6 /// |
7 /// The summary builder uses 4 pieces of data: | 7 /// The summary builder uses 4 pieces of data: |
8 /// | 8 /// |
9 /// * Unlinked**Builders: builder classes for each piece of output in the | 9 /// * Unlinked**Builders: builder classes for each piece of output in the |
10 /// summary (see format.dart). | 10 /// summary (see format.dart). |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 final UnlinkedUnitBuilder unit = new UnlinkedUnitBuilder( | 130 final UnlinkedUnitBuilder unit = new UnlinkedUnitBuilder( |
131 classes: [], | 131 classes: [], |
132 enums: [], | 132 enums: [], |
133 executables: [], | 133 executables: [], |
134 exports: [], | 134 exports: [], |
135 imports: [], | 135 imports: [], |
136 parts: [], | 136 parts: [], |
137 references: [new UnlinkedReferenceBuilder()], | 137 references: [new UnlinkedReferenceBuilder()], |
138 typedefs: [], | 138 typedefs: [], |
139 variables: []); | 139 variables: []); |
| 140 |
140 /// Stores publicly visible names exported from the unit. | 141 /// Stores publicly visible names exported from the unit. |
141 final UnlinkedPublicNamespaceBuilder publicNamespace = | 142 final UnlinkedPublicNamespaceBuilder publicNamespace = |
142 new UnlinkedPublicNamespaceBuilder(names: [], exports: [], parts: []); | 143 new UnlinkedPublicNamespaceBuilder(names: [], exports: [], parts: []); |
143 | 144 |
144 /// Lazy references that need to be expanded after all scope information is | 145 /// Lazy references that need to be expanded after all scope information is |
145 /// known. | 146 /// known. |
146 List<LazyEntityRef> _toExpand = []; | 147 List<LazyEntityRef> _toExpand = []; |
147 | 148 |
148 final Map<int, Map<String, int>> nameToReference = <int, Map<String, int>>{}; | 149 final Map<int, Map<String, int>> nameToReference = <int, Map<String, int>>{}; |
149 | 150 |
150 TopScope() { | 151 TopScope() { |
151 unit.publicNamespace = publicNamespace; | 152 unit.publicNamespace = publicNamespace; |
152 } | 153 } |
153 | 154 |
154 get parent => null; | 155 get parent => null; |
155 | 156 |
156 void computeReference(LazyEntityRef ref) { | 157 void computeReference(LazyEntityRef ref) { |
157 ref.reference = serializeReference(null, ref.name); | 158 ref.reference = serializeReference(null, ref.name); |
158 } | 159 } |
159 | 160 |
160 void expandLazyReferences() { | 161 void expandLazyReferences() { |
161 _toExpand.forEach((r) => r.expand()); | 162 _toExpand.forEach((r) => r.expand()); |
162 } | 163 } |
| 164 |
163 int serializeReference(int prefixIndex, String name) => nameToReference | 165 int serializeReference(int prefixIndex, String name) => nameToReference |
164 .putIfAbsent(prefixIndex, () => <String, int>{}) | 166 .putIfAbsent(prefixIndex, () => <String, int>{}) |
165 .putIfAbsent(name, () { | 167 .putIfAbsent(name, () { |
166 int index = unit.references.length; | 168 int index = unit.references.length; |
167 unit.references.add(new UnlinkedReferenceBuilder( | 169 unit.references.add(new UnlinkedReferenceBuilder( |
168 prefixReference: prefixIndex, name: name)); | 170 prefixReference: prefixIndex, name: name)); |
169 return index; | 171 return index; |
170 }); | 172 }); |
171 | 173 |
172 toString() => "<top-scope>"; | 174 toString() => "<top-scope>"; |
173 } | 175 } |
174 | 176 |
175 class TypeParameterScope extends Scope { | 177 class TypeParameterScope extends Scope { |
176 final Scope parent; | 178 final Scope parent; |
177 List<String> typeParameters = []; | 179 List<String> typeParameters = []; |
178 | 180 |
179 TypeParameterScope(this.parent); | 181 TypeParameterScope(this.parent); |
180 | 182 |
181 void computeReference(LazyEntityRef ref) { | 183 void computeReference(LazyEntityRef ref) { |
182 var i = typeParameters.indexOf(ref.name); | 184 var i = typeParameters.indexOf(ref.name); |
183 if (i < 0) return parent.computeReference(ref); | 185 if (i < 0) return parent.computeReference(ref); |
184 // Note: there is no indexOffset here because we don't go into functions at | 186 // Note: there is no indexOffset here because we don't go into functions at |
185 // all (so there is no nesting of type-parameter scopes). | 187 // all (so there is no nesting of type-parameter scopes). |
186 ref.paramReference = typeParameters.length - i; | 188 ref.paramReference = typeParameters.length - i; |
187 } | 189 } |
188 } | 190 } |
OLD | NEW |