mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 17:05:31 +00:00
tools/cmd/gen: Add more utilities to the templates
* Ensure that copyright years are preserved when regenerating. * Add 'Split' function which maps to strings.Split. * Add 'Scramble' function with messes with a string. * Add 'Import' function which allows templates to be imported, allowing for reusable macros. Change-Id: Ib77f59a989cf55addcced3e337c9031062a83470 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97149 Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
2aea0e957f
commit
695a6d82ae
@@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"dawn.googlesource.com/dawn/tools/src/container"
|
||||
"dawn.googlesource.com/dawn/tools/src/tint/intrinsic/ast"
|
||||
)
|
||||
|
||||
@@ -39,6 +40,16 @@ type Sem struct {
|
||||
UniqueParameterNames []string
|
||||
}
|
||||
|
||||
// Enum returns the enum with the given name
|
||||
func (s *Sem) Enum(name string) *Enum {
|
||||
for _, e := range s.Enums {
|
||||
if e.Name == name {
|
||||
return e
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// New returns a new Sem
|
||||
func New() *Sem {
|
||||
return &Sem{
|
||||
@@ -69,6 +80,26 @@ func (e *Enum) FindEntry(name string) *EnumEntry {
|
||||
return nil
|
||||
}
|
||||
|
||||
// PublicEntries returns the enum entries that are not annotated with @internal
|
||||
func (e *Enum) PublicEntries() []*EnumEntry {
|
||||
out := make([]*EnumEntry, 0, len(e.Entries))
|
||||
for _, entry := range e.Entries {
|
||||
if !entry.IsInternal {
|
||||
out = append(out, entry)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// NameSet returns a set of all the enum entry names
|
||||
func (e *Enum) NameSet() container.Set[string] {
|
||||
out := container.NewSet[string]()
|
||||
for _, entry := range e.Entries {
|
||||
out.Add(entry.Name)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// EnumEntry is an entry in an enumerator
|
||||
type EnumEntry struct {
|
||||
Enum *Enum
|
||||
|
||||
Reference in New Issue
Block a user