tint/intrinsics.def: Change language for enums

Previously enum members were added to the global namespace, so that
overload template parameters could be constrained to a single
enum-entry without the need to declare a matcher. While this was a minor
convenience feature, it means that you cannot declare an enum with
members that share the same name as a type. This will be very common for
extensions, like 'f16' where 'f16' is the name of an extension and a
type name.

Change scoping so that enum members need to be fully qualified. Also
change the intrinsic syntax so that enums always need to use a matcher
for enums.

Change-Id: Ided91130e9df537d38dc8ecb41325c0992dea14b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97146
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2022-07-26 17:49:54 +00:00
committed by Dawn LUCI CQ
parent 1260a53018
commit c768e640f4
9 changed files with 1677 additions and 1607 deletions

View File

@@ -109,10 +109,19 @@ func (p *parser) matcherDecl() ast.MatcherDecl {
name := p.expect(tok.Identifier, "matcher name")
m := ast.MatcherDecl{Source: name.Source, Name: string(name.Runes)}
p.expect(tok.Colon, "matcher declaration")
for p.err == nil {
m.Options = append(m.Options, p.templatedName())
if p.match(tok.Or) == nil {
break
if p.peekIs(1, tok.Dot) { // enum list
for p.err == nil {
m.Options.Enums = append(m.Options.Enums, p.memberName())
if p.match(tok.Or) == nil {
break
}
}
} else { // type list
for p.err == nil {
m.Options.Types = append(m.Options.Types, p.templatedName())
if p.match(tok.Or) == nil {
break
}
}
}
return m
@@ -277,6 +286,17 @@ func (p *parser) string() string {
return string(s.Runes)
}
func (p *parser) memberName() ast.MemberName {
owner := p.expect(tok.Identifier, "member name")
p.expect(tok.Dot, "member name")
member := p.expect(tok.Identifier, "member name")
return ast.MemberName{
Source: member.Source,
Owner: string(owner.Runes),
Member: string(member.Runes),
}
}
func (p *parser) templatedName() ast.TemplatedName {
name := p.expect(tok.Identifier, "type name")
m := ast.TemplatedName{Source: name.Source, Name: string(name.Runes)}

View File

@@ -129,7 +129,9 @@ func TestParser(t *testing.T) {
Matchers: []ast.MatcherDecl{{
Name: "M",
Options: ast.MatcherOptions{
ast.TemplatedName{Name: "A"},
Types: ast.TemplatedNames{
{Name: "A"},
},
},
}},
},
@@ -140,8 +142,37 @@ func TestParser(t *testing.T) {
Matchers: []ast.MatcherDecl{{
Name: "M",
Options: ast.MatcherOptions{
ast.TemplatedName{Name: "A"},
ast.TemplatedName{Name: "B"},
Types: ast.TemplatedNames{
{Name: "A"},
{Name: "B"},
},
},
}},
},
}, { ///////////////////////////////////////////////////////////////////
utils.ThisLine(),
"match M : A.B",
ast.AST{
Matchers: []ast.MatcherDecl{{
Name: "M",
Options: ast.MatcherOptions{
Enums: ast.MemberNames{
{Owner: "A", Member: "B"},
},
},
}},
},
}, { ///////////////////////////////////////////////////////////////////
utils.ThisLine(),
"match M : A.B | B.C",
ast.AST{
Matchers: []ast.MatcherDecl{{
Name: "M",
Options: ast.MatcherOptions{
Enums: ast.MemberNames{
{Owner: "A", Member: "B"},
{Owner: "B", Member: "C"},
},
},
}},
},