mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 16:37:08 +00:00
Add negative number parsing into @test_value
This CL updates the intrinsics lexer to allow negative values for int and float numerics. This allows doing `@test_value(-2)` in the def file. Change-Id: I2cad9b25a2932057ce9bc51dec6c32231e06f0a0 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/107440 Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com> Auto-Submit: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
91ed6f7289
commit
c3cbc35650
@@ -219,7 +219,8 @@ func (o MatcherOptions) Format(w fmt.State, verb rune) {
|
||||
|
||||
// TemplatedNames is a list of TemplatedName
|
||||
// Example:
|
||||
// a<b>, c<d, e>
|
||||
//
|
||||
// a<b>, c<d, e>
|
||||
type TemplatedNames []TemplatedName
|
||||
|
||||
// Format implements the fmt.Formatter interface
|
||||
@@ -234,7 +235,8 @@ func (l TemplatedNames) Format(w fmt.State, verb rune) {
|
||||
|
||||
// TemplatedName is an identifier with optional templated arguments
|
||||
// Example:
|
||||
// vec<N, T>
|
||||
//
|
||||
// vec<N, T>
|
||||
type TemplatedName struct {
|
||||
Source tok.Source
|
||||
Name string
|
||||
@@ -253,7 +255,8 @@ func (t TemplatedName) Format(w fmt.State, verb rune) {
|
||||
|
||||
// MemberNames is a list of MemberName
|
||||
// Example:
|
||||
// a.b, c.d
|
||||
//
|
||||
// a.b, c.d
|
||||
type MemberNames []MemberName
|
||||
|
||||
// Format implements the fmt.Formatter interface
|
||||
@@ -298,7 +301,8 @@ func (p TypeDecl) Format(w fmt.State, verb rune) {
|
||||
|
||||
// TemplateParams is a list of TemplateParam
|
||||
// Example:
|
||||
// <A, B : TyB>
|
||||
//
|
||||
// <A, B : TyB>
|
||||
type TemplateParams []TemplateParam
|
||||
|
||||
// Format implements the fmt.Formatter interface
|
||||
@@ -317,8 +321,9 @@ func (p TemplateParams) Format(w fmt.State, verb rune) {
|
||||
|
||||
// TemplateParam describes a template parameter with optional type
|
||||
// Example:
|
||||
// <Name>
|
||||
// <Name: Type>
|
||||
//
|
||||
// <Name>
|
||||
// <Name: Type>
|
||||
type TemplateParam struct {
|
||||
Source tok.Source
|
||||
Name string
|
||||
@@ -336,7 +341,8 @@ func (t TemplateParam) Format(w fmt.State, verb rune) {
|
||||
|
||||
// Attributes is a list of Attribute
|
||||
// Example:
|
||||
// [[a(x), b(y)]]
|
||||
//
|
||||
// [[a(x), b(y)]]
|
||||
type Attributes []Attribute
|
||||
|
||||
// Format implements the fmt.Formatter interface
|
||||
@@ -363,7 +369,8 @@ func (l *Attributes) Take(name string) *Attribute {
|
||||
|
||||
// Attribute describes a single attribute
|
||||
// Example:
|
||||
// @a(x)
|
||||
//
|
||||
// @a(x)
|
||||
type Attribute struct {
|
||||
Source tok.Source
|
||||
Name string
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/// Package gen holds types and helpers for generating templated code from the
|
||||
/// intrinsic.def file.
|
||||
///
|
||||
/// Used by tools/src/cmd/gen/main.go
|
||||
// Package gen holds types and helpers for generating templated code from the
|
||||
// intrinsic.def file.
|
||||
//
|
||||
// Used by tools/src/cmd/gen/main.go
|
||||
package gen
|
||||
|
||||
import (
|
||||
@@ -338,9 +338,12 @@ func (b *overloadBuilder) matcherIndex(n sem.Named) (int, error) {
|
||||
// The order of returned matcher indices is always the order of the fully
|
||||
// qualified name as read from left to right.
|
||||
// For example, calling collectMatcherIndices() for the fully qualified name:
|
||||
// A<B<C, D>, E<F, G<H>, I>
|
||||
//
|
||||
// A<B<C, D>, E<F, G<H>, I>
|
||||
//
|
||||
// Would return the matcher indices:
|
||||
// A, B, C, D, E, F, G, H, I
|
||||
//
|
||||
// A, B, C, D, E, F, G, H, I
|
||||
func (b *overloadBuilder) collectMatcherIndices(fqn sem.FullyQualifiedName) ([]int, error) {
|
||||
idx, err := b.matcherIndex(fqn.Target)
|
||||
if err != nil {
|
||||
@@ -416,9 +419,12 @@ func BuildIntrinsicTable(s *sem.Sem) (*IntrinsicTable, error) {
|
||||
// SplitDisplayName splits displayName into parts, where text wrapped in {}
|
||||
// braces are not quoted and the rest is quoted. This is used to help process
|
||||
// the string value of the [[display()]] decoration. For example:
|
||||
// SplitDisplayName("vec{N}<{T}>")
|
||||
//
|
||||
// SplitDisplayName("vec{N}<{T}>")
|
||||
//
|
||||
// would return the strings:
|
||||
// [`"vec"`, `N`, `"<"`, `T`, `">"`]
|
||||
//
|
||||
// [`"vec"`, `N`, `"<"`, `T`, `">"`]
|
||||
func SplitDisplayName(displayName string) []string {
|
||||
parts := []string{}
|
||||
pending := strings.Builder{}
|
||||
|
||||
@@ -93,7 +93,6 @@ func (l *lexer) lex() error {
|
||||
case l.match("/", tok.Divide):
|
||||
case l.match(".", tok.Dot):
|
||||
case l.match("->", tok.Arrow):
|
||||
case l.match("-", tok.Minus):
|
||||
case l.match("fn", tok.Function):
|
||||
case l.match("op", tok.Operator):
|
||||
case l.match("enum", tok.Enum):
|
||||
@@ -103,12 +102,22 @@ func (l *lexer) lex() error {
|
||||
case l.match("match", tok.Match):
|
||||
case unicode.IsLetter(l.peek(0)) || l.peek(0) == '_':
|
||||
l.tok(l.count(alphaNumericOrUnderscore), tok.Identifier)
|
||||
case unicode.IsNumber(l.peek(0)):
|
||||
case unicode.IsNumber(l.peek(0)) || l.peek(0) == '-':
|
||||
isFloat := false
|
||||
isNegative := false
|
||||
isFirst := true
|
||||
pred := func(r rune) bool {
|
||||
if isFirst && r == '-' {
|
||||
isNegative = true
|
||||
isFirst = false
|
||||
return true
|
||||
}
|
||||
isFirst = false
|
||||
|
||||
if unicode.IsNumber(r) {
|
||||
return true
|
||||
}
|
||||
|
||||
if !isFloat && r == '.' {
|
||||
isFloat = true
|
||||
return true
|
||||
@@ -116,7 +125,9 @@ func (l *lexer) lex() error {
|
||||
return false
|
||||
}
|
||||
n := l.count(pred)
|
||||
if isFloat {
|
||||
if isNegative && n == 1 {
|
||||
l.tok(1, tok.Minus)
|
||||
} else if isFloat {
|
||||
l.tok(n, tok.Float)
|
||||
} else {
|
||||
l.tok(n, tok.Integer)
|
||||
|
||||
@@ -47,9 +47,15 @@ func TestLexTokens(t *testing.T) {
|
||||
{"123456789", []tok.Token{{Kind: tok.Integer, Runes: []rune("123456789"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 10, 9),
|
||||
}}}},
|
||||
{"-123456789", []tok.Token{{Kind: tok.Integer, Runes: []rune("-123456789"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 11, 10),
|
||||
}}}},
|
||||
{"1234.56789", []tok.Token{{Kind: tok.Float, Runes: []rune("1234.56789"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 11, 10),
|
||||
}}}},
|
||||
{"-1234.56789", []tok.Token{{Kind: tok.Float, Runes: []rune("-1234.56789"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 12, 11),
|
||||
}}}},
|
||||
{"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),
|
||||
@@ -61,6 +67,14 @@ func TestLexTokens(t *testing.T) {
|
||||
S: loc(1, 9, 8), E: loc(1, 12, 11),
|
||||
}},
|
||||
}},
|
||||
{"-123.456-789", []tok.Token{
|
||||
{Kind: tok.Float, Runes: []rune("-123.456"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 9, 8),
|
||||
}},
|
||||
{Kind: tok.Integer, Runes: []rune("-789"), Source: tok.Source{
|
||||
S: loc(1, 9, 8), E: loc(1, 13, 12),
|
||||
}},
|
||||
}},
|
||||
{"match", []tok.Token{{Kind: tok.Match, Runes: []rune("match"), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 6, 5),
|
||||
}}}},
|
||||
@@ -88,6 +102,9 @@ func TestLexTokens(t *testing.T) {
|
||||
{",", []tok.Token{{Kind: tok.Comma, Runes: []rune(","), Source: tok.Source{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}}},
|
||||
{"-", []tok.Token{{Kind: tok.Minus, 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{
|
||||
S: loc(1, 1, 0), E: loc(1, 2, 1),
|
||||
}}}},
|
||||
|
||||
Reference in New Issue
Block a user