]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/Prototype/Module.java
14 public String
name() { return name
; }
16 public Set
<LibClass
> consumesLibClasses
;
18 // The set of packages that this module depends upon.
19 Set
<Package
> packageDepends
;
20 public Set
<Package
> packageDeps() { return packageDepends
; }
22 public boolean autoBuild()
24 // This should be implemented in the derived class.
28 // Make sure that each class in this set of libclasses is declared in one
29 // of the packages that this module depends on.
30 public boolean validateLibClasses(Set
<LibClass
> classes
)
32 for(LibClass lc
: classes
)
34 // Assume we will not find it.
35 boolean found
= false;
37 for(Package p
: packageDepends
)
39 if(p
.libClassDecls
.contains(lc
))
47 // Error: This LibClass is not found in any of our Packages.
51 // Well, we never came up empty handed, so it looks good.
55 public Set
<LibClass
> libClassesProduced(Collection
<LibInst
> instances
)
57 // given a set of lib instances, what is the set of lib classes produced?
59 Set
<LibClass
> classes
= new HashSet
<LibClass
>();
61 for(LibInst li
: instances
)
63 classes
.addAll(li
.producesLibClasses
);
68 // Search the given set of lib instance to see if, among them, they
69 // produce the same LibClass more than once.
70 public Set
<LibClass
> duplicateLibClasses(Set
<LibInst
> libs
)
72 // Return true iff each class produced is produced only once.
74 List
<LibClass
> classes
= new LinkedList
<LibClass
>();
75 Set
<LibClass
> dups
= new HashSet
<LibClass
>();
77 for(LibInst li
: libs
)
79 classes
.addAll(li
.producesLibClasses
);
82 for(LibClass c
: classes
)
84 for(LibClass inner
: classes
)
95 public Set
<LibInst
> getProducers(LibClass lc
, Set
<LibInst
> libs
)
97 // Return the subset of the given libs that produce this LibClass.
99 Set
<LibInst
> producers
= new HashSet
<LibInst
>();
101 for(LibInst li
: libs
)
103 if(li
.producesLibClasses
.contains(lc
))
112 // The central dependency relationship between library instances is as follows.
113 // A LibInst "A" depends upon LibInst "B" if, and only if, there exists a LibClass
114 // "C" such that A consumes C and B produces C. This is the partial order over which
115 // we construct a Directed Acyclic Graph (DAG). The DAG can be used to detect
116 // cycles in the depends relation (which are illegal) and it can be used to implement a
117 // topological sort which is a total ordering over LibInstances. This total order on
118 // lib instances is what is needed in order to call the constructors and destructors
119 // in the proper sequence.
121 public DAG
<LibInst
> makeDAG(Set
<LibInst
> libs
)
123 DAG
<LibInst
> dag
= new DAG
<LibInst
>();
125 if(duplicateLibClasses(libs
).size()>0)
127 System
.out
.format("Error: The library instances implement at least one "
128 + "library class more than once.\n");
131 for(LibInst consumer
: libs
)
133 // Find all the producers for each LC that li consumes.
134 for(LibClass lc
: consumer
.consumesLibClasses
)
136 Set
<LibInst
> producers
= getProducers(lc
, libs
);
137 if(producers
.isEmpty())
139 System
.out
.format("Error: Unmet dependency libclass:%s .", lc
.name() );
143 // There is exactly one lib inst that produces this class.
144 LibInst producer
= producers
.iterator().next();
146 // Now we are ready to add the dependency to the dag. It will flag
147 // circular dependencies for us.
148 dag
.add(consumer
, producer
);
154 // As you evaluate each node in the graph (starting with the module node), you
155 // must call the constructors for all the child nodes before you call the
156 // constructor for the current node.
157 public List
<LibInst
> getConstructorOrder(Set
<LibInst
> libs
)
159 List
<LibInst
> rev
= new LinkedList
<LibInst
>();
161 for(LibInst li
: getDestructorOrder(libs
))
167 // The destructor order is exactly the reverese of the constructor order.
168 // As you evaluate each node in the graph (starting with the module node), you
169 // must call the destructor for the all the parent nodes before calling the
170 // destructors for the current node, and then call the destructors for all the
172 public List
<LibInst
> getDestructorOrder(Set
<LibInst
> libs
)
174 DAG
<LibInst
> dag
= makeDAG(libs
);