Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: pkg/fasta/lib/src/builder/class_builder.dart

Issue 2629063005: Fasta builders. (Closed)
Patch Set: Address review comments. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library fasta.class_builder;
6
7 import 'builder.dart' show
8 Builder,
9 ConstructorReferenceBuilder,
10 LibraryBuilder,
11 MetadataBuilder,
12 TypeBuilder,
13 TypeDeclarationBuilder,
14 TypeVariableBuilder;
15
16 import 'scope.dart' show
17 AmbiguousBuilder,
18 Scope;
19
20 abstract class ClassBuilder<T extends TypeBuilder, R>
21 extends TypeDeclarationBuilder<T, R> {
22 final List<TypeVariableBuilder> typeVariables;
23
24 T supertype;
25
26 List<T> interfaces;
27
28 final Map<String, Builder> members;
29
30 ClassBuilder(
31 List<MetadataBuilder> metadata, int modifiers,
32 String name, this.typeVariables, this.supertype, this.interfaces,
33 this.members, List<T> types, LibraryBuilder parent)
34 : super(metadata, modifiers, name, types, parent);
35
36 List<ConstructorReferenceBuilder> get constructorReferences => null;
37
38 Map<String, Builder> get constructors;
39
40 Map<String, Builder> get membersInScope => members;
41
42 int resolveTypes(LibraryBuilder library) {
43 Scope scope;
44 int count = 0;
45 if (types != null) {
46 scope = computeInstanceScope(library.scope);
47 for (T t in types) {
48 t.resolveIn(scope);
49 }
50 count += types.length;
51 }
52 return count;
53 }
54
55 int resolveConstructors(LibraryBuilder library) {
56 if (constructorReferences == null) return 0;
57 Scope scope = computeInstanceScope(library.scope);
58 for (ConstructorReferenceBuilder ref in constructorReferences) {
59 ref.resolveIn(scope);
60 }
61 return constructorReferences.length;
62 }
63
64 Scope computeInstanceScope(Scope parent) {
65 if (typeVariables != null) {
66 Map<String, Builder> local = <String, Builder>{};
67 for (TypeVariableBuilder t in typeVariables) {
68 local[t.name] = t;
69 }
70 parent = new Scope(local, parent, isModifiable: false);
71 }
72 return new Scope(membersInScope, parent, isModifiable: false);
73 }
74
75 /// Used to lookup a static member of this class.
76 Builder findStaticBuilder(String name, {bool isSetter: false}) {
77 Builder builder = members[name];
78 if (builder?.next != null) {
79 Builder getterBuilder;
80 Builder setterBuilder;
81 Builder current = builder;
82 while (current != null) {
83 if (current.isGetter && getterBuilder == null) {
84 getterBuilder = current;
85 } else if (current.isSetter && setterBuilder == null) {
86 setterBuilder = current;
87 } else {
88 return new AmbiguousBuilder(builder);
89 }
90 current = current.next;
91 }
92 builder = isSetter ? setterBuilder : getterBuilder;
93 }
94 if (builder == null) {
95 return null;
96 } else if (isSetter && builder.isGetter) {
97 return null;
98 } else {
99 return builder.isInstanceMember ? null : builder;
100 }
101 }
102
103 Builder findConstructorOrFactory(String name);
104 }
OLDNEW
« no previous file with comments | « pkg/fasta/lib/src/builder/builder.dart ('k') | pkg/fasta/lib/src/builder/constructor_reference_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698