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.source_class_builder; | 5 library fasta.source_class_builder; |
6 | 6 |
7 import 'package:kernel/ast.dart' show | 7 import 'package:kernel/ast.dart' |
8 Class, | 8 show Class, Constructor, Supertype, TreeNode, setParents; |
9 Constructor, | |
10 Supertype, | |
11 TreeNode, | |
12 setParents; | |
13 | 9 |
14 import '../errors.dart' show | 10 import '../errors.dart' show internalError; |
15 internalError; | |
16 | 11 |
17 import '../kernel/kernel_builder.dart' show | 12 import '../kernel/kernel_builder.dart' |
18 Builder, | 13 show |
19 ConstructorReferenceBuilder, | 14 Builder, |
20 KernelClassBuilder, | 15 ConstructorReferenceBuilder, |
21 KernelFieldBuilder, | 16 KernelClassBuilder, |
22 KernelFunctionBuilder, | 17 KernelFieldBuilder, |
23 KernelLibraryBuilder, | 18 KernelFunctionBuilder, |
24 KernelTypeBuilder, | 19 KernelLibraryBuilder, |
25 KernelTypeVariableBuilder, | 20 KernelTypeBuilder, |
26 LibraryBuilder, | 21 KernelTypeVariableBuilder, |
27 MetadataBuilder, | 22 LibraryBuilder, |
28 ProcedureBuilder, | 23 MetadataBuilder, |
29 TypeVariableBuilder; | 24 ProcedureBuilder, |
| 25 TypeVariableBuilder; |
30 | 26 |
31 import '../dill/dill_member_builder.dart' show | 27 import '../dill/dill_member_builder.dart' show DillMemberBuilder; |
32 DillMemberBuilder; | |
33 | 28 |
34 import '../util/relativize.dart' show | 29 import '../util/relativize.dart' show relativizeUri; |
35 relativizeUri; | |
36 | 30 |
37 Class initializeClass(Class cls, String name, LibraryBuilder parent, | 31 Class initializeClass( |
38 int charOffset) { | 32 Class cls, String name, LibraryBuilder parent, int charOffset) { |
39 cls ??= new Class(name: name); | 33 cls ??= new Class(name: name); |
40 cls.fileUri ??= relativizeUri(parent.fileUri); | 34 cls.fileUri ??= relativizeUri(parent.fileUri); |
41 if (cls.fileOffset != TreeNode.noOffset) { | 35 if (cls.fileOffset != TreeNode.noOffset) { |
42 cls.fileOffset = charOffset; | 36 cls.fileOffset = charOffset; |
43 } | 37 } |
44 return cls; | 38 return cls; |
45 } | 39 } |
46 | 40 |
47 class SourceClassBuilder extends KernelClassBuilder { | 41 class SourceClassBuilder extends KernelClassBuilder { |
48 final Class cls; | 42 final Class cls; |
49 | 43 |
50 final Map<String, Builder> constructors; | 44 final Map<String, Builder> constructors; |
51 | 45 |
52 final Map<String, Builder> membersInScope; | 46 final Map<String, Builder> membersInScope; |
53 | 47 |
54 final List<ConstructorReferenceBuilder> constructorReferences; | 48 final List<ConstructorReferenceBuilder> constructorReferences; |
55 | 49 |
56 final KernelTypeBuilder mixedInType; | 50 final KernelTypeBuilder mixedInType; |
57 | 51 |
58 SourceClassBuilder(List<MetadataBuilder> metadata, int modifiers, | 52 SourceClassBuilder( |
59 String name, List<TypeVariableBuilder> typeVariables, | 53 List<MetadataBuilder> metadata, |
60 KernelTypeBuilder supertype, List<KernelTypeBuilder> interfaces, | 54 int modifiers, |
61 Map<String, Builder> members, LibraryBuilder parent, | 55 String name, |
62 this.constructorReferences, int charOffset, [Class cls, this.mixedInType]) | 56 List<TypeVariableBuilder> typeVariables, |
| 57 KernelTypeBuilder supertype, |
| 58 List<KernelTypeBuilder> interfaces, |
| 59 Map<String, Builder> members, |
| 60 LibraryBuilder parent, |
| 61 this.constructorReferences, |
| 62 int charOffset, |
| 63 [Class cls, |
| 64 this.mixedInType]) |
63 : cls = initializeClass(cls, name, parent, charOffset), | 65 : cls = initializeClass(cls, name, parent, charOffset), |
64 membersInScope = computeMembersInScope(members), | 66 membersInScope = computeMembersInScope(members), |
65 constructors = computeConstructors(members), | 67 constructors = computeConstructors(members), |
66 super(metadata, modifiers, name, typeVariables, supertype, interfaces, | 68 super(metadata, modifiers, name, typeVariables, supertype, interfaces, |
67 members, parent, charOffset); | 69 members, parent, charOffset); |
68 | 70 |
69 int resolveTypes(LibraryBuilder library) { | 71 int resolveTypes(LibraryBuilder library) { |
70 int count = 0; | 72 int count = 0; |
71 if (typeVariables != null) { | 73 if (typeVariables != null) { |
72 for (KernelTypeVariableBuilder t in typeVariables) { | 74 for (KernelTypeVariableBuilder t in typeVariables) { |
(...skipping 10 matching lines...) Expand all Loading... |
83 if (builder is KernelFieldBuilder) { | 85 if (builder is KernelFieldBuilder) { |
84 // TODO(ahe): It would be nice to have a common interface for the build | 86 // TODO(ahe): It would be nice to have a common interface for the build |
85 // method to avoid duplicating these two cases. | 87 // method to avoid duplicating these two cases. |
86 cls.addMember(builder.build(library.library)); | 88 cls.addMember(builder.build(library.library)); |
87 } else if (builder is KernelFunctionBuilder) { | 89 } else if (builder is KernelFunctionBuilder) { |
88 cls.addMember(builder.build(library.library)); | 90 cls.addMember(builder.build(library.library)); |
89 } else { | 91 } else { |
90 internalError("Unhandled builder: ${builder.runtimeType}"); | 92 internalError("Unhandled builder: ${builder.runtimeType}"); |
91 } | 93 } |
92 } | 94 } |
| 95 |
93 members.forEach((String name, Builder builder) { | 96 members.forEach((String name, Builder builder) { |
94 do { | 97 do { |
95 buildBuilder(builder); | 98 buildBuilder(builder); |
96 builder = builder.next; | 99 builder = builder.next; |
97 } while (builder != null); | 100 } while (builder != null); |
98 }); | 101 }); |
99 cls.supertype = supertype?.buildSupertype(); | 102 cls.supertype = supertype?.buildSupertype(); |
100 cls.mixedInType = mixedInType?.buildSupertype(); | 103 cls.mixedInType = mixedInType?.buildSupertype(); |
101 // TODO(ahe): If `cls.supertype` is null, and this isn't Object, report a | 104 // TODO(ahe): If `cls.supertype` is null, and this isn't Object, report a |
102 // compile-time error. | 105 // compile-time error. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 Map<String, Builder> computeConstructors(Map<String, Builder> members) { | 142 Map<String, Builder> computeConstructors(Map<String, Builder> members) { |
140 Map<String, Builder> constructors = <String, Builder>{}; | 143 Map<String, Builder> constructors = <String, Builder>{}; |
141 members.forEach((String name, Builder builder) { | 144 members.forEach((String name, Builder builder) { |
142 if (builder is ProcedureBuilder && | 145 if (builder is ProcedureBuilder && |
143 (builder.isConstructor || builder.isFactory)) { | 146 (builder.isConstructor || builder.isFactory)) { |
144 constructors[name] = builder; | 147 constructors[name] = builder; |
145 } | 148 } |
146 }); | 149 }); |
147 return constructors; | 150 return constructors; |
148 } | 151 } |
OLD | NEW |