authorgravatar for twostepted@gmail.comTravis Staloch <twostepted@gmail.com> 2021-09-08 15:58:37-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-28 17:03:43-07:00
logdcbc52ec85d00fbd3603c314aaaab98fb3866892
treecda1709af1515d51ada13319119f9f79544ff4f3
parentb9a95f2dd94e6175322d3388c3936eb600ec90ea

sat-arithmetic: correctly tokenize <<|, <<|=

- set state rather than result.tag in tokenizer.zig - add test to tokenizer.zig for <<, <<|, <<|=

3 files changed, 10 insertions(+), 5 deletions(-)

lib/std/zig/tokenizer.zig+7-1
......@@ -1007,7 +1007,7 @@ pub const Tokenizer = struct {
10071007 break;
10081008 },
10091009 '|' => {
1010 result.tag = .angle_bracket_angle_bracket_left_pipe;
1010 state = .angle_bracket_angle_bracket_left_pipe;
10111011 },
10121012 else => {
10131013 result.tag = .angle_bracket_angle_bracket_left;
......@@ -2015,6 +2015,12 @@ test "tokenizer - invalid token with unfinished escape right before eof" {
20152015 try testTokenize("'\\u", &.{.invalid});
20162016}
20172017
2018test "tokenizer - saturating" {
2019 try testTokenize("<<", &.{.angle_bracket_angle_bracket_left});
2020 try testTokenize("<<|", &.{.angle_bracket_angle_bracket_left_pipe});
2021 try testTokenize("<<|=", &.{.angle_bracket_angle_bracket_left_pipe_equal});
2022}
2023
20182024fn testTokenize(source: [:0]const u8, expected_tokens: []const Token.Tag) !void {
20192025 var tokenizer = Tokenizer.init(source);
20202026 for (expected_tokens) |expected_token_id| {
src/Air.zig+3-3
......@@ -44,7 +44,7 @@ pub const Inst = struct {
4444 /// is the same as both operands.
4545 /// Uses the `bin_op` field.
4646 addwrap,
47 /// Saturating integer addition.
47 /// Saturating integer addition.
4848 /// Both operands are guaranteed to be the same type, and the result type
4949 /// is the same as both operands.
5050 /// Uses the `bin_op` field.
......@@ -59,7 +59,7 @@ pub const Inst = struct {
5959 /// is the same as both operands.
6060 /// Uses the `bin_op` field.
6161 subwrap,
62 /// Saturating integer subtraction.
62 /// Saturating integer subtraction.
6363 /// Both operands are guaranteed to be the same type, and the result type
6464 /// is the same as both operands.
6565 /// Uses the `bin_op` field.
......@@ -74,7 +74,7 @@ pub const Inst = struct {
7474 /// is the same as both operands.
7575 /// Uses the `bin_op` field.
7676 mulwrap,
77 /// Saturating integer multiplication.
77 /// Saturating integer multiplication.
7878 /// Both operands are guaranteed to be the same type, and the result type
7979 /// is the same as both operands.
8080 /// Uses the `bin_op` field.
src/stage1/tokenizer.cpp-1
......@@ -995,7 +995,6 @@ void tokenize(const char *source, Tokenization *out) {
995995 t.state = TokenizeState_start;
996996 break;
997997 case '|':
998 // t.out->ids.last() = TokenIdBitShiftLeftPipe;
999998 t.state = TokenizeState_angle_bracket_angle_bracket_left_pipe;
1000999 break;
10011000 default: