diff --git a/tools/src/cmd/intrinsic-gen/parser/parser_test.go b/tools/src/cmd/intrinsic-gen/parser/parser_test.go index 009aa7c9f1..dddb166d43 100644 --- a/tools/src/cmd/intrinsic-gen/parser/parser_test.go +++ b/tools/src/cmd/intrinsic-gen/parser/parser_test.go @@ -96,7 +96,7 @@ func TestParser(t *testing.T) { }, }}, }}, - {"fn F(a T)", ast.AST{ + {"fn F(a: T)", ast.AST{ Functions: []ast.FunctionDecl{{ Name: "F", Parameters: ast.Parameters{ @@ -128,7 +128,7 @@ func TestParser(t *testing.T) { }, }}, }}, - {"fn F(a X, b Y)", ast.AST{ + {"fn F(a: X, b: Y)", ast.AST{ Functions: []ast.FunctionDecl{{ Name: "F", TemplateParams: ast.TemplateParams{ diff --git a/tools/src/cmd/intrinsic-gen/resolver/resolve.go b/tools/src/cmd/intrinsic-gen/resolver/resolve.go index 792a33a3c1..1798d0d324 100644 --- a/tools/src/cmd/intrinsic-gen/resolver/resolve.go +++ b/tools/src/cmd/intrinsic-gen/resolver/resolve.go @@ -16,6 +16,7 @@ package resolver import ( "fmt" + "sort" "dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/ast" "dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/sem" @@ -65,6 +66,9 @@ func Resolve(a *ast.AST) (*sem.Sem, error) { } } + // Calculate the unique parameter names + r.s.UniqueParameterNames = r.calculateUniqueParameterNames() + return r.s, nil } @@ -444,6 +448,25 @@ func (r *resolver) lookupNamed(s *scope, a ast.TemplatedName) (sem.Named, error) return ty, nil } +// calculateUniqueParameterNames() iterates over all the parameters of all +// overloads, calculating the list of unique parameter names +func (r *resolver) calculateUniqueParameterNames() []string { + set := map[string]struct{}{"": {}} + names := []string{} + for _, f := range r.s.Functions { + for _, o := range f.Overloads { + for _, p := range o.Parameters { + if _, dup := set[p.Name]; !dup { + set[p.Name] = struct{}{} + names = append(names, p.Name) + } + } + } + } + sort.Strings(names) + return names +} + // describe() returns a string describing a sem.Named func describe(n sem.Named) string { switch n := n.(type) { diff --git a/tools/src/cmd/intrinsic-gen/sem/sem.go b/tools/src/cmd/intrinsic-gen/sem/sem.go index 9cf135b7e5..1a615fe0ef 100644 --- a/tools/src/cmd/intrinsic-gen/sem/sem.go +++ b/tools/src/cmd/intrinsic-gen/sem/sem.go @@ -29,6 +29,8 @@ type Sem struct { MaxOpenTypes int // Maximum number of open-numbers used across all intrinsics MaxOpenNumbers int + // The alphabetically sorted list of unique parameter names + UniqueParameterNames []string } // New returns a new Sem