tint/intrinsics.def: Add @test_value() annotation

Specifies the value to use for argument values when generating end-to-end tests.

Use this to provide a legal value for atanh().

Change-Id: I008050c856f9d687ab918c68e90678c4e74f3a1d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/106887
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2022-10-25 13:08:45 +00:00
parent c3adc78cbc
commit 95dd428c75
69 changed files with 394 additions and 313 deletions

View File

@@ -18,6 +18,7 @@ package parser
import (
"fmt"
"strconv"
"dawn.googlesource.com/dawn/tools/src/tint/intrinsic/ast"
"dawn.googlesource.com/dawn/tools/src/tint/intrinsic/lexer"
@@ -145,10 +146,26 @@ func (p *parser) attributes() ast.Attributes {
var out ast.Attributes
for p.match(tok.Attr) != nil && p.err == nil {
name := p.expect(tok.Identifier, "attribute name")
values := []string{}
var values []any
if p.match(tok.Lparen) != nil {
loop:
for p.err == nil {
values = append(values, string(p.next().Runes))
t := p.next()
switch t.Kind {
case tok.Rparen:
break loop
case tok.String:
values = append(values, string(t.Runes))
case tok.Integer:
i, _ := strconv.ParseInt(string(t.Runes), 10, 64)
values = append(values, int(i))
case tok.Float:
f, _ := strconv.ParseFloat(string(t.Runes), 64)
values = append(values, f)
default:
p.err = fmt.Errorf("%v invalid attribute value kind: %v", t.Source, t.Kind)
return nil
}
if p.match(tok.Comma) == nil {
break
}

View File

@@ -52,7 +52,7 @@ func TestParser(t *testing.T) {
{
Attributes: ast.Attributes{{
Name: "attr",
Values: []string{},
Values: nil,
}},
Name: "B",
},
@@ -85,7 +85,7 @@ func TestParser(t *testing.T) {
ast.AST{
Types: []ast.TypeDecl{{
Attributes: ast.Attributes{
{Name: "attr", Values: []string{}},
{Name: "attr", Values: nil},
},
Name: "T",
}},
@@ -96,8 +96,8 @@ func TestParser(t *testing.T) {
ast.AST{
Types: []ast.TypeDecl{{
Attributes: ast.Attributes{
{Name: "attr_a", Values: []string{}},
{Name: "attr_b", Values: []string{}},
{Name: "attr_a", Values: nil},
{Name: "attr_b", Values: nil},
},
Name: "T",
}},
@@ -107,17 +107,17 @@ func TestParser(t *testing.T) {
`@attr("a", "b") type T`, ast.AST{
Types: []ast.TypeDecl{{
Attributes: ast.Attributes{
{Name: "attr", Values: []string{"a", "b"}},
{Name: "attr", Values: []any{"a", "b"}},
},
Name: "T",
}},
},
}, { ///////////////////////////////////////////////////////////////////
utils.ThisLine(),
`@attr(1, "x") type T`, ast.AST{
`@attr(1, "x", 2.0) type T`, ast.AST{
Types: []ast.TypeDecl{{
Attributes: ast.Attributes{
{Name: "attr", Values: []string{"1", "x"}},
{Name: "attr", Values: []any{1, "x", 2.0}},
},
Name: "T",
}},
@@ -194,7 +194,7 @@ func TestParser(t *testing.T) {
Kind: ast.Builtin,
Name: "F",
Attributes: ast.Attributes{
{Name: "attr", Values: []string{}},
{Name: "attr", Values: nil},
},
Parameters: ast.Parameters{},
}},
@@ -318,7 +318,7 @@ func TestParser(t *testing.T) {
Kind: ast.Operator,
Name: "F",
Attributes: ast.Attributes{
{Name: "attr", Values: []string{}},
{Name: "attr", Values: nil},
},
Parameters: ast.Parameters{},
}},
@@ -344,7 +344,7 @@ func TestParser(t *testing.T) {
Name: "F",
Parameters: ast.Parameters{
{
Attributes: ast.Attributes{{Name: "blah", Values: []string{}}},
Attributes: ast.Attributes{{Name: "blah", Values: nil}},
Type: ast.TemplatedName{Name: "a"}},
},
}},
@@ -456,7 +456,7 @@ func TestParser(t *testing.T) {
Kind: ast.Initializer,
Name: "F",
Attributes: ast.Attributes{
{Name: "attr", Values: []string{}},
{Name: "attr", Values: nil},
},
Parameters: ast.Parameters{},
}},
@@ -580,7 +580,7 @@ func TestParser(t *testing.T) {
Kind: ast.Converter,
Name: "F",
Attributes: ast.Attributes{
{Name: "attr", Values: []string{}},
{Name: "attr", Values: nil},
},
Parameters: ast.Parameters{},
}},