This changes the way binding dependencies works slightly, to ensure that the full transitive closure of dependencies is bound appropriately before hitting code-generation. Namely, now binder.PrepareStack returns a list of unresolved dependency Refs; the compiler is responsible for turning this into a map from Ref to the loaded diag.Document, before calling BindStack; then, BindStack instantiates these as necessary (template expansion, etc), returning an array of unbound *ast.Stacks that the compiler must then bind.
98 lines
1.7 KiB
Go
98 lines
1.7 KiB
Go
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
package ast
|
|
|
|
import (
|
|
"sort"
|
|
)
|
|
|
|
func StableClusters(cs Clusters) []string {
|
|
sorted := make([]string, 0, len(cs))
|
|
for c := range cs {
|
|
sorted = append(sorted, c)
|
|
}
|
|
sort.Strings(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableDependencies(ds Dependencies) []Ref {
|
|
sorted := make(Refs, 0, len(ds))
|
|
for d := range ds {
|
|
sorted = append(sorted, d)
|
|
}
|
|
sort.Sort(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableDependencyDocuments(docs DependencyDocuments) []Ref {
|
|
sorted := make(Refs, 0, len(docs))
|
|
for doc := range docs {
|
|
sorted = append(sorted, doc)
|
|
}
|
|
sort.Sort(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableKeys(ps PropertyBag) []string {
|
|
sorted := make([]string, 0, len(ps))
|
|
for p := range ps {
|
|
sorted = append(sorted, p)
|
|
}
|
|
sort.Strings(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableProperties(ps Properties) []string {
|
|
sorted := make([]string, 0, len(ps))
|
|
for p := range ps {
|
|
sorted = append(sorted, p)
|
|
}
|
|
sort.Strings(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableServices(ss ServiceMap) []Name {
|
|
sorted := make(Names, 0, len(ss))
|
|
for s := range ss {
|
|
sorted = append(sorted, s)
|
|
}
|
|
sort.Sort(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableUntypedServices(ss UntypedServiceMap) []Name {
|
|
sorted := make(Names, 0, len(ss))
|
|
for s := range ss {
|
|
sorted = append(sorted, s)
|
|
}
|
|
sort.Sort(sorted)
|
|
return sorted
|
|
}
|
|
|
|
type Names []Name
|
|
|
|
func (s Names) Len() int {
|
|
return len(s)
|
|
}
|
|
|
|
func (s Names) Swap(i, j int) {
|
|
s[i], s[j] = s[j], s[i]
|
|
}
|
|
|
|
func (s Names) Less(i, j int) bool {
|
|
return s[i] < s[j]
|
|
}
|
|
|
|
type Refs []Ref
|
|
|
|
func (s Refs) Len() int {
|
|
return len(s)
|
|
}
|
|
|
|
func (s Refs) Swap(i, j int) {
|
|
s[i], s[j] = s[j], s[i]
|
|
}
|
|
|
|
func (s Refs) Less(i, j int) bool {
|
|
return s[i] < s[j]
|
|
}
|