[wgsl-in] Remove unused field Token::Number::width.

This commit is contained in:
Jim Blandy
2022-02-26 09:14:49 -08:00
committed by Dzmitry Malyshau
parent e6c202dc70
commit f24018dc36
3 changed files with 10 additions and 46 deletions

View File

@@ -286,7 +286,6 @@ fn consume_number(input: &str) -> (Token, &str) {
} else {
NumberType::Sint
},
width: None,
},
rest,
)
@@ -664,7 +663,6 @@ fn test_tokens() {
Token::Number {
value: "92",
ty: NumberType::Sint,
width: None,
},
Token::Word("No"),
],
@@ -675,12 +673,10 @@ fn test_tokens() {
Token::Number {
value: "2",
ty: NumberType::Uint,
width: None,
},
Token::Number {
value: "3",
ty: NumberType::Sint,
width: None,
},
Token::Word("o"),
],
@@ -691,7 +687,6 @@ fn test_tokens() {
Token::Number {
value: "2.4",
ty: NumberType::Float,
width: None,
},
Token::Word("f44po"),
],
@@ -725,7 +720,6 @@ fn test_variable_decl() {
Token::Number {
value: "0",
ty: NumberType::Sint,
width: None,
},
Token::Paren(')'),
Token::Word("var"),

View File

@@ -60,11 +60,7 @@ pub enum Token<'a> {
DoubleColon,
Paren(char),
Attribute,
Number {
value: &'a str,
ty: NumberType,
width: Option<Bytes>,
},
Number { value: &'a str, ty: NumberType },
String(&'a str),
Word(&'a str),
Operation(char),
@@ -1266,18 +1262,10 @@ impl Parser {
fn get_constant_inner<'a>(
word: &'a str,
ty: NumberType,
width: Option<Bytes>,
token_span: TokenSpan<'a>,
) -> Result<ConstantInner, Error<'a>> {
let span = token_span.1;
if let Some(width) = width {
if width != 4 {
// Only 32-bit literals supported by the spec and naga for now!
return Err(Error::BadScalarWidth(span, width));
}
}
let value = match ty {
NumberType::Sint => {
get_i32_literal(word, span).map(|val| crate::ScalarValue::Sint(val as i64))?
@@ -1290,25 +1278,13 @@ impl Parser {
}
};
Ok(crate::ConstantInner::Scalar {
value,
width: width.unwrap_or(4),
})
Ok(crate::ConstantInner::Scalar { value, width: 4 })
}
fn parse_switch_value<'a>(lexer: &mut Lexer<'a>, uint: bool) -> Result<i32, Error<'a>> {
let token_span = lexer.next();
let word = match token_span.0 {
Token::Number { value, width, .. } => {
if let Some(width) = width {
if width != 4 {
// Only 32-bit literals supported by the spec and naga for now!
return Err(Error::BadScalarWidth(token_span.1, width));
}
}
value
}
Token::Number { value, .. } => value,
_ => return Err(Error::Unexpected(token_span, ExpectedToken::Integer)),
};
@@ -1856,7 +1832,6 @@ impl Parser {
Token::Number {
value,
ty: NumberType::Sint,
width: None,
},
span,
) = lexer.peek()
@@ -2223,8 +2198,8 @@ impl Parser {
let inner = match first_token_span {
(Token::Word("true"), _) => crate::ConstantInner::boolean(true),
(Token::Word("false"), _) => crate::ConstantInner::boolean(false),
(Token::Number { value, ty, width }, _) => {
Self::get_constant_inner(value, ty, width, first_token_span)?
(Token::Number { value, ty }, _) => {
Self::get_constant_inner(value, ty, first_token_span)?
}
(Token::Word(name), name_span) => {
// look for an existing constant first

View File

@@ -85,10 +85,9 @@ pub(super) fn _parse_uint_literal<'a>(
Token::Number {
value,
ty: NumberType::Uint,
width: token_width,
},
span,
) if token_width.unwrap_or(4) == width => get_u32_literal(value, span),
) => get_u32_literal(value, span),
other => Err(Error::Unexpected(
other,
ExpectedToken::Number {
@@ -117,10 +116,9 @@ pub(super) fn parse_non_negative_sint_literal<'a>(
Token::Number {
value,
ty: NumberType::Sint,
width: token_width,
},
span,
) if token_width.unwrap_or(4) == width => {
) => {
let i32_val = get_i32_literal(value, span.clone())?;
u32::try_from(i32_val).map_err(|_| Error::NegativeInt(span))
}
@@ -153,10 +151,9 @@ pub(super) fn parse_generic_non_negative_int_literal<'a>(
Token::Number {
value,
ty: NumberType::Sint,
width: token_width,
},
span,
) if token_width.unwrap_or(4) == width => {
) => {
let i32_val = get_i32_literal(value, span.clone())?;
u32::try_from(i32_val).map_err(|_| Error::NegativeInt(span))
}
@@ -164,10 +161,9 @@ pub(super) fn parse_generic_non_negative_int_literal<'a>(
Token::Number {
value,
ty: NumberType::Uint,
width: token_width,
},
span,
) if token_width.unwrap_or(4) == width => get_u32_literal(value, span),
) => get_u32_literal(value, span),
other => Err(Error::Unexpected(
other,
ExpectedToken::Number {
@@ -194,10 +190,9 @@ pub(super) fn _parse_float_literal<'a>(
Token::Number {
value,
ty: NumberType::Float,
width: token_width,
},
span,
) if token_width.unwrap_or(4) == width => get_f32_literal(value, span),
) => get_f32_literal(value, span),
other => Err(Error::Unexpected(
other,
ExpectedToken::Number {