[tools]: Minor intrinsic-gen changes

Have the resolver emit unique parameter names

Aslo: Update the parser tests to include ':' between parameter name and type.
This functionality landed a few changes up, but I missed this test from the change.

Bug: tint:832
Change-Id: If0d6d3a33bbcd8be4d70ee7182754158ed0da819
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/52641
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton 2021-06-01 09:07:10 +00:00 committed by Tint LUCI CQ
parent 39c05a902f
commit 126adb1bbb
3 changed files with 27 additions and 2 deletions

View File

@ -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<T>(a X, b Y<T>)", ast.AST{
{"fn F<T>(a: X, b: Y<T>)", ast.AST{
Functions: []ast.FunctionDecl{{
Name: "F",
TemplateParams: ast.TemplateParams{

View File

@ -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) {

View File

@ -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