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 serialization.elements; | 5 library serialization.elements; |
6 | 6 |
7 import 'package:analyzer/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
8 import 'package:analyzer/src/generated/resolver.dart'; | 8 import 'package:analyzer/src/generated/resolver.dart'; |
9 import 'package:analyzer/src/generated/utilities_dart.dart'; | 9 import 'package:analyzer/src/generated/utilities_dart.dart'; |
10 import 'package:analyzer/src/summary/builder.dart'; | 10 import 'package:analyzer/src/summary/builder.dart'; |
(...skipping 17 matching lines...) Expand all Loading... | |
28 * The library to be serialized. | 28 * The library to be serialized. |
29 */ | 29 */ |
30 final LibraryElement libraryElement; | 30 final LibraryElement libraryElement; |
31 | 31 |
32 /** | 32 /** |
33 * The type provider. This is used to locate the library for `dart:core`. | 33 * The type provider. This is used to locate the library for `dart:core`. |
34 */ | 34 */ |
35 final TypeProvider typeProvider; | 35 final TypeProvider typeProvider; |
36 | 36 |
37 /** | 37 /** |
38 * List of objects which should be written to [UnlinkedLibrary.classes]. | 38 * List of objects which should be written to [PrelinkedLibrary.units]. |
39 */ | 39 */ |
40 final List<UnlinkedClassBuilder> classes = <UnlinkedClassBuilder>[]; | 40 final List<PrelinkedUnitBuilder> units = <PrelinkedUnitBuilder>[]; |
41 | |
42 /** | |
43 * List of objects which should be written to [UnlinkedLibrary.enums]. | |
44 */ | |
45 final List<UnlinkedEnumBuilder> enums = <UnlinkedEnumBuilder>[]; | |
46 | |
47 /** | |
48 * List of objects which should be written to [UnlinkedLibrary.executables]. | |
49 */ | |
50 final List<UnlinkedExecutableBuilder> executables = | |
51 <UnlinkedExecutableBuilder>[]; | |
52 | |
53 /** | |
54 * List of objects which should be written to [UnlinkedLibrary.typedefs]. | |
55 */ | |
56 final List<UnlinkedTypedefBuilder> typedefs = <UnlinkedTypedefBuilder>[]; | |
57 | |
58 /** | |
59 * List of objects which should be written to [UnlinkedLibrary.units]. | |
60 */ | |
61 final List<UnlinkedUnitBuilder> units = <UnlinkedUnitBuilder>[]; | |
62 | |
63 /** | |
64 * List of objects which should be written to [UnlinkedLibrary.variables]. | |
65 */ | |
66 final List<UnlinkedVariableBuilder> variables = <UnlinkedVariableBuilder>[]; | |
67 | 41 |
68 /** | 42 /** |
69 * Map from [LibraryElement] to the index of the entry in the "dependency | 43 * Map from [LibraryElement] to the index of the entry in the "dependency |
70 * table" that refers to it. | 44 * table" that refers to it. |
71 */ | 45 */ |
72 final Map<LibraryElement, int> dependencyMap = <LibraryElement, int>{}; | 46 final Map<LibraryElement, int> dependencyMap = <LibraryElement, int>{}; |
73 | 47 |
74 /** | 48 /** |
75 * The "dependency table". This is the list of objects which should be | 49 * The "dependency table". This is the list of objects which should be |
76 * written to [PrelinkedLibrary.dependencies]. | 50 * written to [PrelinkedLibrary.dependencies]. |
77 */ | 51 */ |
78 final List<PrelinkedDependencyBuilder> dependencies = | 52 final List<PrelinkedDependencyBuilder> dependencies = |
79 <PrelinkedDependencyBuilder>[]; | 53 <PrelinkedDependencyBuilder>[]; |
80 | 54 |
81 /** | 55 /** |
82 * The unlinked portion of the "imports table". This is the list of objects | |
83 * which should be written to [UnlinkedLibrary.imports]. | |
84 */ | |
85 final List<UnlinkedImportBuilder> unlinkedImports = <UnlinkedImportBuilder>[]; | |
86 | |
87 /** | |
88 * The prelinked portion of the "imports table". This is the list of ints | 56 * The prelinked portion of the "imports table". This is the list of ints |
89 * which should be written to [PrelinkedLibrary.imports]. | 57 * which should be written to [PrelinkedLibrary.imports]. |
90 */ | 58 */ |
91 final List<int> prelinkedImports = <int>[]; | 59 final List<int> prelinkedImports = <int>[]; |
92 | 60 |
93 /** | 61 /** |
94 * Map from prefix [String] to the index of the entry in the "prefix" table | 62 * Map from prefix [String] to the index of the entry in the "prefix" table |
95 * that refers to it. The empty prefix is not included in this map. | 63 * that refers to it. The empty prefix is not included in this map. |
96 */ | 64 */ |
97 final Map<String, int> prefixMap = <String, int>{}; | 65 final Map<String, int> prefixMap = <String, int>{}; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 LibraryElement get coreLibrary => typeProvider.objectType.element.library; | 130 LibraryElement get coreLibrary => typeProvider.objectType.element.library; |
163 | 131 |
164 /** | 132 /** |
165 * Add all classes, enums, typedefs, executables, and top level variables | 133 * Add all classes, enums, typedefs, executables, and top level variables |
166 * from the given compilation unit [element] to the library summary. | 134 * from the given compilation unit [element] to the library summary. |
167 * [unitNum] indicates the ordinal position of this compilation unit in the | 135 * [unitNum] indicates the ordinal position of this compilation unit in the |
168 * library. | 136 * library. |
169 */ | 137 */ |
170 void addCompilationUnitElements(CompilationUnitElement element, int unitNum) { | 138 void addCompilationUnitElements(CompilationUnitElement element, int unitNum) { |
171 UnlinkedUnitBuilder b = new UnlinkedUnitBuilder(ctx); | 139 UnlinkedUnitBuilder b = new UnlinkedUnitBuilder(ctx); |
172 if (element.uri != null) { | 140 if (unitNum == 0) { |
173 b.uri = element.uri; | 141 // TODO(paulberry): we need to figure out a way to record library, part, |
Brian Wilkerson
2015/12/14 23:44:35
We might have discussed this already, but if not i
Paul Berry
2015/12/15 00:29:56
Agreed, that would be a good discussion to have.
| |
142 // import, and export declarations that appear in non-defining | |
143 // compilation units (even though such declarations are prohibited by the | |
144 // language), so that if the user makes code changes that cause a | |
145 // non-defining compilation unit to become a defining compilation unit, | |
146 // we can create a correct summary by simply re-linking. | |
147 if (libraryElement.name.isNotEmpty) { | |
148 b.libraryName = libraryElement.name; | |
149 } | |
150 b.exports = libraryElement.exports.map(serializeExport).toList(); | |
151 b.imports = libraryElement.imports.map(serializeImport).toList(); | |
152 b.parts = libraryElement.parts | |
153 .map( | |
154 (CompilationUnitElement e) => encodeUnlinkedPart(ctx, uri: e.uri)) | |
155 .toList(); | |
174 } | 156 } |
175 units.add(b); | 157 b.classes = element.types.map(serializeClass).toList(); |
176 for (ClassElement cls in element.types) { | 158 b.enums = element.enums.map(serializeEnum).toList(); |
177 classes.add(serializeClass(cls, unitNum)); | 159 b.typedefs = element.functionTypeAliases.map(serializeTypedef).toList(); |
178 } | 160 List<UnlinkedExecutableBuilder> executables = |
179 for (ClassElement e in element.enums) { | 161 element.functions.map(serializeExecutable).toList(); |
180 enums.add(serializeEnum(e, unitNum)); | |
181 } | |
182 for (FunctionTypeAliasElement type in element.functionTypeAliases) { | |
183 typedefs.add(serializeTypedef(type, unitNum)); | |
184 } | |
185 for (FunctionElement executable in element.functions) { | |
186 executables.add(serializeExecutable(executable, unitNum)); | |
187 } | |
188 for (PropertyAccessorElement accessor in element.accessors) { | 162 for (PropertyAccessorElement accessor in element.accessors) { |
189 if (!accessor.isSynthetic) { | 163 if (!accessor.isSynthetic) { |
190 executables.add(serializeExecutable(accessor, unitNum)); | 164 executables.add(serializeExecutable(accessor)); |
191 } else if (accessor.isGetter) { | 165 } |
166 } | |
167 b.executables = executables; | |
168 List<UnlinkedVariableBuilder> variables = <UnlinkedVariableBuilder>[]; | |
169 for (PropertyAccessorElement accessor in element.accessors) { | |
170 if (accessor.isSynthetic && accessor.isGetter) { | |
192 PropertyInducingElement variable = accessor.variable; | 171 PropertyInducingElement variable = accessor.variable; |
193 if (variable != null) { | 172 if (variable != null) { |
194 assert(!variable.isSynthetic); | 173 assert(!variable.isSynthetic); |
195 variables.add(serializeVariable(variable, unitNum)); | 174 variables.add(serializeVariable(variable)); |
196 } | 175 } |
197 } | 176 } |
198 } | 177 } |
178 b.variables = variables; | |
179 units.add(encodePrelinkedUnit(ctx, unlinked: b)); | |
199 } | 180 } |
200 | 181 |
201 /** | 182 /** |
202 * Add [exportedLibrary] (and the transitive closure of all libraries it | 183 * Add [exportedLibrary] (and the transitive closure of all libraries it |
203 * exports) to the dependency table ([PrelinkedLibrary.dependencies]). | 184 * exports) to the dependency table ([PrelinkedLibrary.dependencies]). |
204 */ | 185 */ |
205 void addTransitiveExportClosure(LibraryElement exportedLibrary) { | 186 void addTransitiveExportClosure(LibraryElement exportedLibrary) { |
206 if (librariesAddedToTransitiveExportClosure.add(exportedLibrary)) { | 187 if (librariesAddedToTransitiveExportClosure.add(exportedLibrary)) { |
207 serializeDependency(exportedLibrary); | 188 serializeDependency(exportedLibrary); |
208 for (LibraryElement transitiveExport | 189 for (LibraryElement transitiveExport |
(...skipping 26 matching lines...) Expand all Loading... | |
235 } | 216 } |
236 } | 217 } |
237 index += typeParameters.length; | 218 index += typeParameters.length; |
238 } | 219 } |
239 context = context.enclosingElement; | 220 context = context.enclosingElement; |
240 } | 221 } |
241 throw new StateError('Unbound type parameter $type'); | 222 throw new StateError('Unbound type parameter $type'); |
242 } | 223 } |
243 | 224 |
244 /** | 225 /** |
245 * Serialize the given [classElement], which exists in the unit numbered | 226 * Serialize the given [classElement], creating an [UnlinkedClass]. |
246 * [unitNum], creating an [UnlinkedClass]. | |
247 */ | 227 */ |
248 UnlinkedClassBuilder serializeClass(ClassElement classElement, int unitNum) { | 228 UnlinkedClassBuilder serializeClass(ClassElement classElement) { |
249 UnlinkedClassBuilder b = new UnlinkedClassBuilder(ctx); | 229 UnlinkedClassBuilder b = new UnlinkedClassBuilder(ctx); |
250 b.name = classElement.name; | 230 b.name = classElement.name; |
251 b.unit = unitNum; | |
252 b.typeParameters = | 231 b.typeParameters = |
253 classElement.typeParameters.map(serializeTypeParam).toList(); | 232 classElement.typeParameters.map(serializeTypeParam).toList(); |
254 if (classElement.supertype != null && !classElement.supertype.isObject) { | 233 if (classElement.supertype != null && !classElement.supertype.isObject) { |
255 b.supertype = serializeTypeRef(classElement.supertype, classElement); | 234 b.supertype = serializeTypeRef(classElement.supertype, classElement); |
256 } | 235 } |
257 b.mixins = classElement.mixins | 236 b.mixins = classElement.mixins |
258 .map((InterfaceType t) => serializeTypeRef(t, classElement)) | 237 .map((InterfaceType t) => serializeTypeRef(t, classElement)) |
259 .toList(); | 238 .toList(); |
260 b.interfaces = classElement.interfaces | 239 b.interfaces = classElement.interfaces |
261 .map((InterfaceType t) => serializeTypeRef(t, classElement)) | 240 .map((InterfaceType t) => serializeTypeRef(t, classElement)) |
262 .toList(); | 241 .toList(); |
263 List<UnlinkedVariableBuilder> fields = <UnlinkedVariableBuilder>[]; | 242 List<UnlinkedVariableBuilder> fields = <UnlinkedVariableBuilder>[]; |
264 List<UnlinkedExecutableBuilder> executables = <UnlinkedExecutableBuilder>[]; | 243 List<UnlinkedExecutableBuilder> executables = <UnlinkedExecutableBuilder>[]; |
265 for (ConstructorElement executable in classElement.constructors) { | 244 for (ConstructorElement executable in classElement.constructors) { |
266 if (!executable.isSynthetic) { | 245 if (!executable.isSynthetic) { |
267 executables.add(serializeExecutable(executable, 0)); | 246 executables.add(serializeExecutable(executable)); |
268 } | 247 } |
269 } | 248 } |
270 for (MethodElement executable in classElement.methods) { | 249 for (MethodElement executable in classElement.methods) { |
271 executables.add(serializeExecutable(executable, 0)); | 250 executables.add(serializeExecutable(executable)); |
272 } | 251 } |
273 for (PropertyAccessorElement accessor in classElement.accessors) { | 252 for (PropertyAccessorElement accessor in classElement.accessors) { |
274 if (!accessor.isSynthetic) { | 253 if (!accessor.isSynthetic) { |
275 executables.add(serializeExecutable(accessor, 0)); | 254 executables.add(serializeExecutable(accessor)); |
276 } else if (accessor.isGetter) { | 255 } else if (accessor.isGetter) { |
277 PropertyInducingElement field = accessor.variable; | 256 PropertyInducingElement field = accessor.variable; |
278 if (field != null && !field.isSynthetic) { | 257 if (field != null && !field.isSynthetic) { |
279 fields.add(serializeVariable(field, 0)); | 258 fields.add(serializeVariable(field)); |
280 } | 259 } |
281 } | 260 } |
282 } | 261 } |
283 b.fields = fields; | 262 b.fields = fields; |
284 b.executables = executables; | 263 b.executables = executables; |
285 b.isAbstract = classElement.isAbstract; | 264 b.isAbstract = classElement.isAbstract; |
286 b.isMixinApplication = classElement.isMixinApplication; | 265 b.isMixinApplication = classElement.isMixinApplication; |
287 return b; | 266 return b; |
288 } | 267 } |
289 | 268 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 assert(unlinkedReferences.length == prelinkedReferences.length); | 312 assert(unlinkedReferences.length == prelinkedReferences.length); |
334 dynamicReferenceIndex = unlinkedReferences.length; | 313 dynamicReferenceIndex = unlinkedReferences.length; |
335 unlinkedReferences.add(encodeUnlinkedReference(ctx)); | 314 unlinkedReferences.add(encodeUnlinkedReference(ctx)); |
336 prelinkedReferences.add(encodePrelinkedReference(ctx, | 315 prelinkedReferences.add(encodePrelinkedReference(ctx, |
337 kind: PrelinkedReferenceKind.classOrEnum)); | 316 kind: PrelinkedReferenceKind.classOrEnum)); |
338 } | 317 } |
339 return dynamicReferenceIndex; | 318 return dynamicReferenceIndex; |
340 } | 319 } |
341 | 320 |
342 /** | 321 /** |
343 * Serialize the given [enumElement], which exists in the unit numbered | 322 * Serialize the given [enumElement], creating an [UnlinkedEnum]. |
344 * [unitNum], creating an [UnlinkedEnum]. | |
345 */ | 323 */ |
346 UnlinkedEnumBuilder serializeEnum(ClassElement enumElement, int unitNum) { | 324 UnlinkedEnumBuilder serializeEnum(ClassElement enumElement) { |
347 UnlinkedEnumBuilder b = new UnlinkedEnumBuilder(ctx); | 325 UnlinkedEnumBuilder b = new UnlinkedEnumBuilder(ctx); |
348 b.name = enumElement.name; | 326 b.name = enumElement.name; |
349 List<UnlinkedEnumValueBuilder> values = <UnlinkedEnumValueBuilder>[]; | 327 List<UnlinkedEnumValueBuilder> values = <UnlinkedEnumValueBuilder>[]; |
350 for (FieldElement field in enumElement.fields) { | 328 for (FieldElement field in enumElement.fields) { |
351 if (field.isConst && field.type.element == enumElement) { | 329 if (field.isConst && field.type.element == enumElement) { |
352 values.add(encodeUnlinkedEnumValue(ctx, name: field.name)); | 330 values.add(encodeUnlinkedEnumValue(ctx, name: field.name)); |
353 } | 331 } |
354 } | 332 } |
355 b.values = values; | 333 b.values = values; |
356 b.unit = unitNum; | |
357 return b; | 334 return b; |
358 } | 335 } |
359 | 336 |
360 /** | 337 /** |
361 * Serialize the given [executableElement], which exists in the unit numbered | 338 * Serialize the given [executableElement], creating an [UnlinkedExecutable]. |
362 * [unitNum], creating an [UnlinkedExecutable]. For elements declared inside | |
363 * a class, [unitNum] should be zero. | |
364 */ | 339 */ |
365 UnlinkedExecutableBuilder serializeExecutable( | 340 UnlinkedExecutableBuilder serializeExecutable( |
366 ExecutableElement executableElement, int unitNum) { | 341 ExecutableElement executableElement) { |
367 if (executableElement.enclosingElement is ClassElement) { | |
368 assert(unitNum == 0); | |
369 } | |
370 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(ctx); | 342 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(ctx); |
371 b.name = executableElement.name; | 343 b.name = executableElement.name; |
372 b.unit = unitNum; | |
373 if (!executableElement.type.returnType.isVoid) { | 344 if (!executableElement.type.returnType.isVoid) { |
374 b.returnType = serializeTypeRef( | 345 b.returnType = serializeTypeRef( |
375 executableElement.type.returnType, executableElement); | 346 executableElement.type.returnType, executableElement); |
376 } | 347 } |
377 b.typeParameters = | 348 b.typeParameters = |
378 executableElement.typeParameters.map(serializeTypeParam).toList(); | 349 executableElement.typeParameters.map(serializeTypeParam).toList(); |
379 b.parameters = | 350 b.parameters = |
380 executableElement.type.parameters.map(serializeParam).toList(); | 351 executableElement.type.parameters.map(serializeParam).toList(); |
381 if (executableElement is PropertyAccessorElement) { | 352 if (executableElement is PropertyAccessorElement) { |
382 if (executableElement.isGetter) { | 353 if (executableElement.isGetter) { |
(...skipping 19 matching lines...) Expand all Loading... | |
402 * Serialize the given [exportElement] into an [UnlinkedExport]. | 373 * Serialize the given [exportElement] into an [UnlinkedExport]. |
403 */ | 374 */ |
404 UnlinkedExportBuilder serializeExport(ExportElement exportElement) { | 375 UnlinkedExportBuilder serializeExport(ExportElement exportElement) { |
405 UnlinkedExportBuilder b = new UnlinkedExportBuilder(ctx); | 376 UnlinkedExportBuilder b = new UnlinkedExportBuilder(ctx); |
406 b.uri = exportElement.uri; | 377 b.uri = exportElement.uri; |
407 b.combinators = exportElement.combinators.map(serializeCombinator).toList(); | 378 b.combinators = exportElement.combinators.map(serializeCombinator).toList(); |
408 return b; | 379 return b; |
409 } | 380 } |
410 | 381 |
411 /** | 382 /** |
412 * Serialize the given [importElement], adding information about it to | 383 * Serialize the given [importElement] yielding an [UnlinkedImportBuilder]. |
413 * the [unlinkedImports] and [prelinkedImports] lists. | 384 * Also, add pre-linked information about it to the [prelinkedImports] list. |
414 */ | 385 */ |
415 void serializeImport(ImportElement importElement) { | 386 UnlinkedImportBuilder serializeImport(ImportElement importElement) { |
416 assert(unlinkedImports.length == prelinkedImports.length); | |
417 UnlinkedImportBuilder b = new UnlinkedImportBuilder(ctx); | 387 UnlinkedImportBuilder b = new UnlinkedImportBuilder(ctx); |
418 b.isDeferred = importElement.isDeferred; | 388 b.isDeferred = importElement.isDeferred; |
419 b.offset = importElement.nameOffset; | 389 b.offset = importElement.nameOffset; |
420 b.combinators = importElement.combinators.map(serializeCombinator).toList(); | 390 b.combinators = importElement.combinators.map(serializeCombinator).toList(); |
421 if (importElement.prefix != null) { | 391 if (importElement.prefix != null) { |
422 b.prefix = prefixMap.putIfAbsent(importElement.prefix.name, () { | 392 b.prefix = prefixMap.putIfAbsent(importElement.prefix.name, () { |
423 int index = prefixes.length; | 393 int index = prefixes.length; |
424 prefixes | 394 prefixes |
425 .add(encodeUnlinkedPrefix(ctx, name: importElement.prefix.name)); | 395 .add(encodeUnlinkedPrefix(ctx, name: importElement.prefix.name)); |
426 return index; | 396 return index; |
427 }); | 397 }); |
428 } | 398 } |
429 if (importElement.isSynthetic) { | 399 if (importElement.isSynthetic) { |
430 b.isImplicit = true; | 400 b.isImplicit = true; |
431 } else { | 401 } else { |
432 b.uri = importElement.uri; | 402 b.uri = importElement.uri; |
433 } | 403 } |
434 addTransitiveExportClosure(importElement.importedLibrary); | 404 addTransitiveExportClosure(importElement.importedLibrary); |
435 unlinkedImports.add(b); | |
436 prelinkedImports.add(serializeDependency(importElement.importedLibrary)); | 405 prelinkedImports.add(serializeDependency(importElement.importedLibrary)); |
406 return b; | |
437 } | 407 } |
438 | 408 |
439 /** | 409 /** |
440 * Serialize the whole library element into a [PrelinkedLibrary]. Should be | 410 * Serialize the whole library element into a [PrelinkedLibrary]. Should be |
441 * called exactly once for each instance of [_LibrarySerializer]. | 411 * called exactly once for each instance of [_LibrarySerializer]. |
442 */ | 412 */ |
443 PrelinkedLibraryBuilder serializeLibrary() { | 413 PrelinkedLibraryBuilder serializeLibrary() { |
444 UnlinkedLibraryBuilder ub = new UnlinkedLibraryBuilder(ctx); | 414 UnlinkedLibraryBuilder ub = new UnlinkedLibraryBuilder(ctx); |
445 PrelinkedLibraryBuilder pb = new PrelinkedLibraryBuilder(ctx); | 415 PrelinkedLibraryBuilder pb = new PrelinkedLibraryBuilder(ctx); |
446 if (libraryElement.name.isNotEmpty) { | |
447 ub.name = libraryElement.name; | |
448 } | |
449 for (ImportElement importElement in libraryElement.imports) { | |
450 serializeImport(importElement); | |
451 } | |
452 ub.exports = libraryElement.exports.map(serializeExport).toList(); | |
453 addCompilationUnitElements(libraryElement.definingCompilationUnit, 0); | 416 addCompilationUnitElements(libraryElement.definingCompilationUnit, 0); |
454 for (int i = 0; i < libraryElement.parts.length; i++) { | 417 for (int i = 0; i < libraryElement.parts.length; i++) { |
455 addCompilationUnitElements(libraryElement.parts[i], i + 1); | 418 addCompilationUnitElements(libraryElement.parts[i], i + 1); |
456 } | 419 } |
457 ub.classes = classes; | |
458 ub.enums = enums; | |
459 ub.executables = executables; | |
460 ub.imports = unlinkedImports; | |
461 ub.prefixes = prefixes; | 420 ub.prefixes = prefixes; |
462 ub.references = unlinkedReferences; | 421 ub.references = unlinkedReferences; |
463 ub.typedefs = typedefs; | 422 pb.units = units; |
464 ub.units = units; | |
465 ub.variables = variables; | |
466 pb.unlinked = ub; | 423 pb.unlinked = ub; |
467 pb.dependencies = dependencies; | 424 pb.dependencies = dependencies; |
468 pb.importDependencies = prelinkedImports; | 425 pb.importDependencies = prelinkedImports; |
469 pb.references = prelinkedReferences; | 426 pb.references = prelinkedReferences; |
470 return pb; | 427 return pb; |
471 } | 428 } |
472 | 429 |
473 /** | 430 /** |
474 * Serialize the given [parameter] into an [UnlinkedParam]. | 431 * Serialize the given [parameter] into an [UnlinkedParam]. |
475 */ | 432 */ |
(...skipping 20 matching lines...) Expand all Loading... | |
496 } | 453 } |
497 b.parameters = type.parameters.map(serializeParam).toList(); | 454 b.parameters = type.parameters.map(serializeParam).toList(); |
498 } else { | 455 } else { |
499 b.type = serializeTypeRef(type, parameter); | 456 b.type = serializeTypeRef(type, parameter); |
500 b.hasImplicitType = parameter.hasImplicitType; | 457 b.hasImplicitType = parameter.hasImplicitType; |
501 } | 458 } |
502 return b; | 459 return b; |
503 } | 460 } |
504 | 461 |
505 /** | 462 /** |
506 * Serialize the given [typedefElement], which exists in the unit numbered | 463 * Serialize the given [typedefElement], creating an [UnlinkedTypedef]. |
507 * [unitNum], creating an [UnlinkedTypedef]. | |
508 */ | 464 */ |
509 UnlinkedTypedefBuilder serializeTypedef( | 465 UnlinkedTypedefBuilder serializeTypedef( |
510 FunctionTypeAliasElement typedefElement, int unitNum) { | 466 FunctionTypeAliasElement typedefElement) { |
511 UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder(ctx); | 467 UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder(ctx); |
512 b.name = typedefElement.name; | 468 b.name = typedefElement.name; |
513 b.unit = unitNum; | |
514 b.typeParameters = | 469 b.typeParameters = |
515 typedefElement.typeParameters.map(serializeTypeParam).toList(); | 470 typedefElement.typeParameters.map(serializeTypeParam).toList(); |
516 if (!typedefElement.returnType.isVoid) { | 471 if (!typedefElement.returnType.isVoid) { |
517 b.returnType = | 472 b.returnType = |
518 serializeTypeRef(typedefElement.returnType, typedefElement); | 473 serializeTypeRef(typedefElement.returnType, typedefElement); |
519 } | 474 } |
520 b.parameters = typedefElement.parameters.map(serializeParam).toList(); | 475 b.parameters = typedefElement.parameters.map(serializeParam).toList(); |
521 return b; | 476 return b; |
522 } | 477 } |
523 | 478 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 assert(unlinkedReferences.length == prelinkedReferences.length); | 556 assert(unlinkedReferences.length == prelinkedReferences.length); |
602 unresolvedReferenceIndex = unlinkedReferences.length; | 557 unresolvedReferenceIndex = unlinkedReferences.length; |
603 unlinkedReferences.add(encodeUnlinkedReference(ctx)); | 558 unlinkedReferences.add(encodeUnlinkedReference(ctx)); |
604 prelinkedReferences.add(encodePrelinkedReference(ctx, | 559 prelinkedReferences.add(encodePrelinkedReference(ctx, |
605 kind: PrelinkedReferenceKind.unresolved)); | 560 kind: PrelinkedReferenceKind.unresolved)); |
606 } | 561 } |
607 return unresolvedReferenceIndex; | 562 return unresolvedReferenceIndex; |
608 } | 563 } |
609 | 564 |
610 /** | 565 /** |
611 * Serialize the given [variable], which exists in the unit numbered | 566 * Serialize the given [variable], creating an [UnlinkedVariable]. |
612 * [unitNum], creating an [UnlinkedVariable]. For variables declared inside | |
613 * a class (i.e. fields), [unitNum] should be zero. | |
614 */ | 567 */ |
615 UnlinkedVariableBuilder serializeVariable( | 568 UnlinkedVariableBuilder serializeVariable(PropertyInducingElement variable) { |
616 PropertyInducingElement variable, int unitNum) { | |
617 if (variable.enclosingElement is ClassElement) { | |
618 assert(unitNum == 0); | |
619 } | |
620 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(ctx); | 569 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(ctx); |
621 b.name = variable.name; | 570 b.name = variable.name; |
622 b.unit = unitNum; | |
623 b.type = serializeTypeRef(variable.type, variable); | 571 b.type = serializeTypeRef(variable.type, variable); |
624 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; | 572 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; |
625 b.isFinal = variable.isFinal; | 573 b.isFinal = variable.isFinal; |
626 b.isConst = variable.isConst; | 574 b.isConst = variable.isConst; |
627 b.hasImplicitType = variable.hasImplicitType; | 575 b.hasImplicitType = variable.hasImplicitType; |
628 return b; | 576 return b; |
629 } | 577 } |
630 } | 578 } |
OLD | NEW |