mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-12 14:46:08 +00:00
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:
@@ -303,6 +303,7 @@ func (g *generator) bindAndParse(t *template.Template, text string) error {
|
||||
"Title": strings.Title,
|
||||
"PascalCase": pascalCase,
|
||||
"SplitDisplayName": gen.SplitDisplayName,
|
||||
"Contains": strings.Contains,
|
||||
"HasPrefix": strings.HasPrefix,
|
||||
"HasSuffix": strings.HasSuffix,
|
||||
"TrimPrefix": strings.TrimPrefix,
|
||||
|
||||
@@ -367,7 +367,7 @@ func (l *Attributes) Take(name string) *Attribute {
|
||||
type Attribute struct {
|
||||
Source tok.Source
|
||||
Name string
|
||||
Values []string
|
||||
Values []any
|
||||
}
|
||||
|
||||
// Format implements the fmt.Formatter interface
|
||||
|
||||
@@ -83,9 +83,10 @@ func (p *Permuter) Permute(overload *sem.Overload) ([]Permutation, error) {
|
||||
return nil
|
||||
}
|
||||
o.Parameters = append(o.Parameters, sem.Parameter{
|
||||
Name: p.Name,
|
||||
Type: ty,
|
||||
IsConst: p.IsConst,
|
||||
Name: p.Name,
|
||||
Type: ty,
|
||||
IsConst: p.IsConst,
|
||||
TestValue: p.TestValue,
|
||||
})
|
||||
}
|
||||
if overload.ReturnType != nil {
|
||||
|
||||
@@ -104,7 +104,23 @@ func (l *lexer) lex() error {
|
||||
case unicode.IsLetter(l.peek(0)) || l.peek(0) == '_':
|
||||
l.tok(l.count(alphaNumericOrUnderscore), tok.Identifier)
|
||||
case unicode.IsNumber(l.peek(0)):
|
||||
l.tok(l.count(unicode.IsNumber), tok.Integer)
|
||||
isFloat := false
|
||||
pred := func(r rune) bool {
|
||||
if unicode.IsNumber(r) {
|
||||
return true
|
||||
}
|
||||
if !isFloat && r == '.' {
|
||||
isFloat = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
n := l.count(pred)
|
||||
if isFloat {
|
||||
l.tok(n, tok.Float)
|
||||
} else {
|
||||
l.tok(n, tok.Integer)
|
||||
}
|
||||
case l.match("&&", tok.AndAnd):
|
||||
case l.match("&", tok.And):
|
||||
case l.match("||", tok.OrOr):
|
||||
|
||||
@@ -20,12 +20,13 @@ import (
|
||||
|
||||
"dawn.googlesource.com/dawn/tools/src/tint/intrinsic/lexer"
|
||||
"dawn.googlesource.com/dawn/tools/src/tint/intrinsic/tok"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func TestLexTokens(t *testing.T) {
|
||||
type test struct {
|
||||
src string
|
||||
expect tok.Token
|
||||
expect []tok.Token
|
||||
}
|
||||
|
||||
filepath := "test.txt"
|
||||
@@ -34,144 +35,153 @@ func TestLexTokens(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range []test{
|
||||
{"ident", tok.Token{Kind: tok.Identifier, Runes: []rune("ident"), Source: tok.Source{
|
||||
{"ident", []tok.Token{{Kind: tok.Identifier, Runes: []rune("ident"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 6, 5),
|
||||
}}},
|
||||
{"ident_123", tok.Token{Kind: tok.Identifier, Runes: []rune("ident_123"), Source: tok.Source{
|
||||
}}}},
|
||||
{"ident_123", []tok.Token{{Kind: tok.Identifier, Runes: []rune("ident_123"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 10, 9),
|
||||
}}},
|
||||
{"_ident_", tok.Token{Kind: tok.Identifier, Runes: []rune("_ident_"), Source: tok.Source{
|
||||
}}}},
|
||||
{"_ident_", []tok.Token{{Kind: tok.Identifier, Runes: []rune("_ident_"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 8, 7),
|
||||
}}},
|
||||
{"123456789", tok.Token{Kind: tok.Integer, Runes: []rune("123456789"), Source: tok.Source{
|
||||
}}}},
|
||||
{"123456789", []tok.Token{{Kind: tok.Integer, Runes: []rune("123456789"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 10, 9),
|
||||
}}},
|
||||
{"match", tok.Token{Kind: tok.Match, Runes: []rune("match"), Source: tok.Source{
|
||||
}}}},
|
||||
{"1234.56789", []tok.Token{{Kind: tok.Float, Runes: []rune("1234.56789"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 11, 10),
|
||||
}}}},
|
||||
{"123.456.789", []tok.Token{
|
||||
{Kind: tok.Float, Runes: []rune("123.456"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 8, 7),
|
||||
}},
|
||||
{Kind: tok.Dot, Runes: []rune("."), Source: tok.Source{
|
||||
S: loc(1, 8, 7), E: loc(1, 9, 8),
|
||||
}},
|
||||
{Kind: tok.Integer, Runes: []rune("789"), Source: tok.Source{
|
||||
S: loc(1, 9, 8), E: loc(1, 12, 11),
|
||||
}},
|
||||
}},
|
||||
{"match", []tok.Token{{Kind: tok.Match, Runes: []rune("match"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 6, 5),
|
||||
}}},
|
||||
{"fn", tok.Token{Kind: tok.Function, Runes: []rune("fn"), Source: tok.Source{
|
||||
}}}},
|
||||
{"fn", []tok.Token{{Kind: tok.Function, Runes: []rune("fn"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 3, 2),
|
||||
}}},
|
||||
{"op", tok.Token{Kind: tok.Operator, Runes: []rune("op"), Source: tok.Source{
|
||||
}}}},
|
||||
{"op", []tok.Token{{Kind: tok.Operator, Runes: []rune("op"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 3, 2),
|
||||
}}},
|
||||
{"type", tok.Token{Kind: tok.Type, Runes: []rune("type"), Source: tok.Source{
|
||||
}}}},
|
||||
{"type", []tok.Token{{Kind: tok.Type, Runes: []rune("type"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 5, 4),
|
||||
}}},
|
||||
{"init", tok.Token{Kind: tok.Initializer, Runes: []rune("init"), Source: tok.Source{
|
||||
}}}},
|
||||
{"init", []tok.Token{{Kind: tok.Initializer, Runes: []rune("init"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 5, 4),
|
||||
}}},
|
||||
{"conv", tok.Token{Kind: tok.Converter, Runes: []rune("conv"), Source: tok.Source{
|
||||
}}}},
|
||||
{"conv", []tok.Token{{Kind: tok.Converter, Runes: []rune("conv"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 5, 4),
|
||||
}}},
|
||||
{"enum", tok.Token{Kind: tok.Enum, Runes: []rune("enum"), Source: tok.Source{
|
||||
}}}},
|
||||
{"enum", []tok.Token{{Kind: tok.Enum, Runes: []rune("enum"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 5, 4),
|
||||
}}},
|
||||
{":", tok.Token{Kind: tok.Colon, Runes: []rune(":"), Source: tok.Source{
|
||||
}}}},
|
||||
{":", []tok.Token{{Kind: tok.Colon, Runes: []rune(":"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{",", tok.Token{Kind: tok.Comma, Runes: []rune(","), Source: tok.Source{
|
||||
}}}},
|
||||
{",", []tok.Token{{Kind: tok.Comma, Runes: []rune(","), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"<", tok.Token{Kind: tok.Lt, Runes: []rune("<"), Source: tok.Source{
|
||||
}}}},
|
||||
{"<", []tok.Token{{Kind: tok.Lt, Runes: []rune("<"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{">", tok.Token{Kind: tok.Gt, Runes: []rune(">"), Source: tok.Source{
|
||||
}}}},
|
||||
{">", []tok.Token{{Kind: tok.Gt, Runes: []rune(">"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"{", tok.Token{Kind: tok.Lbrace, Runes: []rune("{"), Source: tok.Source{
|
||||
}}}},
|
||||
{"{", []tok.Token{{Kind: tok.Lbrace, Runes: []rune("{"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"}", tok.Token{Kind: tok.Rbrace, Runes: []rune("}"), Source: tok.Source{
|
||||
}}}},
|
||||
{"}", []tok.Token{{Kind: tok.Rbrace, Runes: []rune("}"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"&&", tok.Token{Kind: tok.AndAnd, Runes: []rune("&&"), Source: tok.Source{
|
||||
}}}},
|
||||
{"&&", []tok.Token{{Kind: tok.AndAnd, Runes: []rune("&&"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 3, 2),
|
||||
}}},
|
||||
{"&", tok.Token{Kind: tok.And, Runes: []rune("&"), Source: tok.Source{
|
||||
}}}},
|
||||
{"&", []tok.Token{{Kind: tok.And, Runes: []rune("&"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"||", tok.Token{Kind: tok.OrOr, Runes: []rune("||"), Source: tok.Source{
|
||||
}}}},
|
||||
{"||", []tok.Token{{Kind: tok.OrOr, Runes: []rune("||"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 3, 2),
|
||||
}}},
|
||||
{"|", tok.Token{Kind: tok.Or, Runes: []rune("|"), Source: tok.Source{
|
||||
}}}},
|
||||
{"|", []tok.Token{{Kind: tok.Or, Runes: []rune("|"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"!", tok.Token{Kind: tok.Not, Runes: []rune("!"), Source: tok.Source{
|
||||
}}}},
|
||||
{"!", []tok.Token{{Kind: tok.Not, Runes: []rune("!"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"!=", tok.Token{Kind: tok.NotEqual, Runes: []rune("!="), Source: tok.Source{
|
||||
}}}},
|
||||
{"!=", []tok.Token{{Kind: tok.NotEqual, Runes: []rune("!="), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 3, 2),
|
||||
}}},
|
||||
{"==", tok.Token{Kind: tok.Equal, Runes: []rune("=="), Source: tok.Source{
|
||||
}}}},
|
||||
{"==", []tok.Token{{Kind: tok.Equal, Runes: []rune("=="), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 3, 2),
|
||||
}}},
|
||||
{"=", tok.Token{Kind: tok.Assign, Runes: []rune("="), Source: tok.Source{
|
||||
}}}},
|
||||
{"=", []tok.Token{{Kind: tok.Assign, Runes: []rune("="), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"<<", tok.Token{Kind: tok.Shl, Runes: []rune("<<"), Source: tok.Source{
|
||||
}}}},
|
||||
{"<<", []tok.Token{{Kind: tok.Shl, Runes: []rune("<<"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 3, 2),
|
||||
}}},
|
||||
{"<=", tok.Token{Kind: tok.Le, Runes: []rune("<="), Source: tok.Source{
|
||||
}}}},
|
||||
{"<=", []tok.Token{{Kind: tok.Le, Runes: []rune("<="), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 3, 2),
|
||||
}}},
|
||||
{"<", tok.Token{Kind: tok.Lt, Runes: []rune("<"), Source: tok.Source{
|
||||
}}}},
|
||||
{"<", []tok.Token{{Kind: tok.Lt, Runes: []rune("<"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{">=", tok.Token{Kind: tok.Ge, Runes: []rune(">="), Source: tok.Source{
|
||||
}}}},
|
||||
{">=", []tok.Token{{Kind: tok.Ge, Runes: []rune(">="), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 3, 2),
|
||||
}}},
|
||||
{">>", tok.Token{Kind: tok.Shr, Runes: []rune(">>"), Source: tok.Source{
|
||||
}}}},
|
||||
{">>", []tok.Token{{Kind: tok.Shr, Runes: []rune(">>"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 3, 2),
|
||||
}}},
|
||||
{">", tok.Token{Kind: tok.Gt, Runes: []rune(">"), Source: tok.Source{
|
||||
}}}},
|
||||
{">", []tok.Token{{Kind: tok.Gt, Runes: []rune(">"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"@", tok.Token{Kind: tok.Attr, Runes: []rune("@"), Source: tok.Source{
|
||||
}}}},
|
||||
{"@", []tok.Token{{Kind: tok.Attr, Runes: []rune("@"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"(", tok.Token{Kind: tok.Lparen, Runes: []rune("("), Source: tok.Source{
|
||||
}}}},
|
||||
{"(", []tok.Token{{Kind: tok.Lparen, Runes: []rune("("), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{")", tok.Token{Kind: tok.Rparen, Runes: []rune(")"), Source: tok.Source{
|
||||
}}}},
|
||||
{")", []tok.Token{{Kind: tok.Rparen, Runes: []rune(")"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"|", tok.Token{Kind: tok.Or, Runes: []rune("|"), Source: tok.Source{
|
||||
}}}},
|
||||
{"|", []tok.Token{{Kind: tok.Or, Runes: []rune("|"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"*", tok.Token{Kind: tok.Star, Runes: []rune("*"), Source: tok.Source{
|
||||
}}}},
|
||||
{"*", []tok.Token{{Kind: tok.Star, Runes: []rune("*"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{"->", tok.Token{Kind: tok.Arrow, Runes: []rune("->"), Source: tok.Source{
|
||||
}}}},
|
||||
{"->", []tok.Token{{Kind: tok.Arrow, Runes: []rune("->"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 3, 2),
|
||||
}}},
|
||||
{"x // y ", tok.Token{Kind: tok.Identifier, Runes: []rune("x"), Source: tok.Source{
|
||||
}}}},
|
||||
{"x // y ", []tok.Token{{Kind: tok.Identifier, Runes: []rune("x"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}},
|
||||
{`"abc"`, tok.Token{Kind: tok.String, Runes: []rune("abc"), Source: tok.Source{
|
||||
}}}},
|
||||
{`"abc"`, []tok.Token{{Kind: tok.String, Runes: []rune("abc"), Source: tok.Source{
|
||||
S: loc(1, 2, 1), E: loc(1, 5, 4),
|
||||
}}},
|
||||
}}}},
|
||||
{`
|
||||
//
|
||||
ident
|
||||
|
||||
`, tok.Token{Kind: tok.Identifier, Runes: []rune("ident"), Source: tok.Source{
|
||||
`, []tok.Token{{Kind: tok.Identifier, Runes: []rune("ident"), Source: tok.Source{
|
||||
S: loc(3, 4, 10), E: loc(3, 9, 15),
|
||||
}}},
|
||||
}}}},
|
||||
} {
|
||||
got, err := lexer.Lex([]rune(test.src), filepath)
|
||||
name := fmt.Sprintf(`Lex("%v")`, test.src)
|
||||
switch {
|
||||
case err != nil:
|
||||
if err != nil {
|
||||
t.Errorf("%v returned error: %v", name, err)
|
||||
case len(got) != 1:
|
||||
t.Errorf("%v returned %d tokens: %v", name, len(got), got)
|
||||
case got[0].Kind != test.expect.Kind:
|
||||
t.Errorf(`%v returned unexpected token kind: got "%+v", expected "%+v"`, name, got[0], test.expect)
|
||||
case string(got[0].Runes) != string(test.expect.Runes):
|
||||
t.Errorf(`%v returned unexpected token runes: got "%+v", expected "%+v"`, name, string(got[0].Runes), string(test.expect.Runes))
|
||||
case got[0].Source != test.expect.Source:
|
||||
t.Errorf(`%v returned unexpected token source: got %+v, expected %+v`, name, got[0].Source, test.expect.Source)
|
||||
continue
|
||||
}
|
||||
if diff := cmp.Diff(got, test.expect); diff != "" {
|
||||
t.Errorf(`%v: %v`, name, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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{},
|
||||
}},
|
||||
|
||||
@@ -17,7 +17,6 @@ package resolver
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"dawn.googlesource.com/dawn/tools/src/container"
|
||||
"dawn.googlesource.com/dawn/tools/src/tint/intrinsic/ast"
|
||||
@@ -184,15 +183,15 @@ func (r *resolver) ty(a ast.TypeDecl) error {
|
||||
if len(d.Values) != 1 {
|
||||
return fmt.Errorf("%v expected a single value for 'display' attribute", d.Source)
|
||||
}
|
||||
t.DisplayName = d.Values[0]
|
||||
t.DisplayName = fmt.Sprint(d.Values[0])
|
||||
}
|
||||
if d := a.Attributes.Take("precedence"); d != nil {
|
||||
if len(d.Values) != 1 {
|
||||
return fmt.Errorf("%v expected a single integer value for 'precedence' attribute", d.Source)
|
||||
}
|
||||
n, err := strconv.Atoi(d.Values[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v %v", d.Source, err)
|
||||
n, ok := d.Values[0].(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("%v @precedence value must be an integer", d.Source)
|
||||
}
|
||||
t.Precedence = n
|
||||
}
|
||||
@@ -358,7 +357,11 @@ func (r *resolver) intrinsic(
|
||||
overload.ConstEvalFunction = "Conv"
|
||||
}
|
||||
case 1:
|
||||
overload.ConstEvalFunction = constEvalFn.Values[0]
|
||||
fn, ok := constEvalFn.Values[0].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("%v optional @const value must be a string", constEvalFn.Source)
|
||||
}
|
||||
overload.ConstEvalFunction = fn
|
||||
default:
|
||||
return fmt.Errorf("%v too many values for @const attribute", constEvalFn.Source)
|
||||
}
|
||||
@@ -405,13 +408,25 @@ func (r *resolver) intrinsic(
|
||||
if attribute := p.Attributes.Take("const"); attribute != nil {
|
||||
isConst = true
|
||||
}
|
||||
testValue := 1.0
|
||||
if attribute := p.Attributes.Take("test_value"); attribute != nil {
|
||||
switch v := attribute.Values[0].(type) {
|
||||
case int:
|
||||
testValue = float64(v)
|
||||
case float64:
|
||||
testValue = v
|
||||
default:
|
||||
return fmt.Errorf("%v @test_value must be an integer or float", p.Attributes[0].Source)
|
||||
}
|
||||
}
|
||||
if len(p.Attributes) != 0 {
|
||||
return fmt.Errorf("%v unknown attribute", p.Attributes[0].Source)
|
||||
}
|
||||
overload.Parameters[i] = sem.Parameter{
|
||||
Name: p.Name,
|
||||
Type: usage,
|
||||
IsConst: isConst,
|
||||
Name: p.Name,
|
||||
Type: usage,
|
||||
IsConst: isConst,
|
||||
TestValue: testValue,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -242,9 +242,10 @@ func (o Overload) Format(w fmt.State, verb rune) {
|
||||
|
||||
// Parameter describes a single parameter of a function overload
|
||||
type Parameter struct {
|
||||
Name string
|
||||
Type FullyQualifiedName
|
||||
IsConst bool // Did this parameter have a @const attribute?
|
||||
Name string
|
||||
Type FullyQualifiedName
|
||||
IsConst bool // Did this parameter have a @const attribute?
|
||||
TestValue float64 // Value to use for end-to-end tests
|
||||
}
|
||||
|
||||
// Format implements the fmt.Formatter interface
|
||||
|
||||
@@ -26,6 +26,7 @@ const (
|
||||
InvalidToken Kind = "<invalid>"
|
||||
Identifier Kind = "ident"
|
||||
Integer Kind = "integer"
|
||||
Float Kind = "float"
|
||||
String Kind = "string"
|
||||
Match Kind = "match"
|
||||
Function Kind = "fn"
|
||||
|
||||
Reference in New Issue
Block a user