tint: Add builtin tests for arguments passed by var

Change-Id: I81b69d23e40675d7f525e6369afec9aa0659d043
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92321
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton
2022-06-02 14:36:10 +00:00
committed by Dawn LUCI CQ
parent 913a1aaf62
commit c0af5c5c9c
5031 changed files with 211402 additions and 10539 deletions

View File

@@ -173,6 +173,7 @@ func (l Parameters) Format(w fmt.State, verb rune) {
if i > 0 {
fmt.Fprintf(w, ", ")
}
p.Attributes.Format(w, verb)
p.Format(w, verb)
}
fmt.Fprintf(w, ")")
@@ -180,9 +181,10 @@ func (l Parameters) Format(w fmt.State, verb rune) {
// Parameter describes a single parameter of a function
type Parameter struct {
Source tok.Source
Name string // Optional
Type TemplatedName
Source tok.Source
Attributes Attributes
Name string // Optional
Type TemplatedName
}
// Format implements the fmt.Formatter interface
@@ -303,14 +305,11 @@ type Attributes []Attribute
// Format implements the fmt.Formatter interface
func (l Attributes) Format(w fmt.State, verb rune) {
fmt.Fprint(w, "[[")
for i, d := range l {
if i > 0 {
fmt.Fprintf(w, ", ")
}
for _, d := range l {
fmt.Fprint(w, "@")
d.Format(w, verb)
fmt.Fprint(w, " ")
}
fmt.Fprint(w, "]]")
}
// Take looks up the attribute with the given name. If the attribute is found

View File

@@ -83,8 +83,9 @@ func (p *Permuter) Permute(overload *sem.Overload) ([]Permutation, error) {
return nil
}
o.Parameters = append(o.Parameters, sem.Parameter{
Name: p.Name,
Type: ty,
Name: p.Name,
Type: ty,
IsConst: p.IsConst,
})
}
if overload.ReturnType != nil {

View File

@@ -251,21 +251,24 @@ func (p *parser) parameters() ast.Parameters {
}
func (p *parser) parameter() ast.Parameter {
attributes := p.attributes()
if p.peekIs(1, tok.Colon) {
// name type
name := p.expect(tok.Identifier, "parameter name")
p.expect(tok.Colon, "parameter type")
return ast.Parameter{
Source: name.Source,
Name: string(name.Runes),
Type: p.templatedName(),
Source: name.Source,
Name: string(name.Runes),
Attributes: attributes,
Type: p.templatedName(),
}
}
// type
ty := p.templatedName()
return ast.Parameter{
Source: ty.Source,
Type: ty,
Source: ty.Source,
Attributes: attributes,
Type: ty,
}
}

View File

@@ -304,6 +304,20 @@ func TestParser(t *testing.T) {
},
}},
},
}, { ///////////////////////////////////////////////////////////////////
utils.ThisLine(),
"op F(@blah a)",
ast.AST{
Operators: []ast.IntrinsicDecl{{
Kind: ast.Operator,
Name: "F",
Parameters: ast.Parameters{
{
Attributes: ast.Attributes{{Name: "blah", Values: []string{}}},
Type: ast.TemplatedName{Name: "a"}},
},
}},
},
}, { ///////////////////////////////////////////////////////////////////
utils.ThisLine(),
"op F(a: T)",

View File

@@ -374,9 +374,17 @@ func (r *resolver) intrinsic(
if err != nil {
return err
}
isConst := false
if attribute := p.Attributes.Take("const"); attribute != nil {
isConst = true
}
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,
Name: p.Name,
Type: usage,
IsConst: isConst,
}
}

View File

@@ -211,12 +211,16 @@ 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
Name string
Type FullyQualifiedName
IsConst bool // Did this parameter have a @const attribute?
}
// Format implements the fmt.Formatter interface
func (p Parameter) Format(w fmt.State, verb rune) {
if p.IsConst {
fmt.Fprint(w, "@const ")
}
if p.Name != "" {
fmt.Fprintf(w, "%v: ", p.Name)
}