From 78ce7fb77abe273694e5e280e680d5547fff08b7 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 10 Jul 2023 22:40:03 -0400 Subject: [PATCH] Replace 'ref' arguments with plain pointers --- assets/parser.d.erb | 24 ++++++++++++------------ spec/test_d_lexer.d | 14 +++++++------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/assets/parser.d.erb b/assets/parser.d.erb index 26cf14d..85c6ded 100644 --- a/assets/parser.d.erb +++ b/assets/parser.d.erb @@ -79,8 +79,8 @@ class <%= @classname %> * - P_EOF */ static size_t decode_code_point(string input, - ref CodePoint out_code_point, - ref ubyte out_code_point_length) + CodePoint * out_code_point, + ubyte * out_code_point_length) { if (input.length == 0u) { @@ -141,8 +141,8 @@ class <%= @classname %> code_point = (code_point << 6u) | (b & 0x3Fu); } } - out_code_point = code_point; - out_code_point_length = code_point_length; + *out_code_point = code_point; + *out_code_point_length = code_point_length; return P_SUCCESS; } } @@ -291,7 +291,7 @@ class <%= @classname %> *out_token_info = token_info; // TODO: remove MatchInfo match_info; size_t unexpected_input_length; - size_t result = find_longest_match(match_info, unexpected_input_length); + size_t result = find_longest_match(&match_info, &unexpected_input_length); switch (result) { case P_SUCCESS: @@ -356,8 +356,8 @@ class <%= @classname %> * - P_EOF */ private size_t find_longest_match( - ref MatchInfo out_match_info, - ref size_t out_unexpected_input_length) + MatchInfo * out_match_info, + size_t * out_unexpected_input_length) { MatchInfo longest_match; MatchInfo attempt_match; @@ -367,7 +367,7 @@ class <%= @classname %> string input = m_input[(m_input_index + attempt_match.length)..(m_input.length)]; CodePoint code_point; ubyte code_point_length; - size_t result = Decoder.decode_code_point(input, code_point, code_point_length); + size_t result = Decoder.decode_code_point(input, &code_point, &code_point_length); switch (result) { case P_SUCCESS: @@ -393,12 +393,12 @@ class <%= @classname %> } else if (longest_match.length > 0) { - out_match_info = longest_match; + *out_match_info = longest_match; return P_SUCCESS; } else { - out_unexpected_input_length = attempt_match.length + code_point_length; + *out_unexpected_input_length = attempt_match.length + code_point_length; return P_UNEXPECTED_INPUT; } break; @@ -408,13 +408,13 @@ class <%= @classname %> if (longest_match.length > 0) { /* We have a match, so use it. */ - out_match_info = longest_match; + *out_match_info = longest_match; return P_SUCCESS; } else if (attempt_match.length != 0) { /* There is a partial match - error! */ - out_unexpected_input_length = attempt_match.length; + *out_unexpected_input_length = attempt_match.length; return P_UNEXPECTED_INPUT; } else diff --git a/spec/test_d_lexer.d b/spec/test_d_lexer.d index 485101a..7597c6f 100644 --- a/spec/test_d_lexer.d +++ b/spec/test_d_lexer.d @@ -12,31 +12,31 @@ unittest Testparser.CodePoint code_point; ubyte code_point_length; - result = Testparser.Decoder.decode_code_point("5", code_point, code_point_length); + result = Testparser.Decoder.decode_code_point("5", &code_point, &code_point_length); assert(result == Testparser.P_SUCCESS); assert(code_point == '5'); assert(code_point_length == 1u); - result = Testparser.Decoder.decode_code_point("", code_point, code_point_length); + result = Testparser.Decoder.decode_code_point("", &code_point, &code_point_length); assert(result == Testparser.P_EOF); - result = Testparser.Decoder.decode_code_point("\xC2\xA9", code_point, code_point_length); + result = Testparser.Decoder.decode_code_point("\xC2\xA9", &code_point, &code_point_length); assert(result == Testparser.P_SUCCESS); assert(code_point == 0xA9u); assert(code_point_length == 2u); - result = Testparser.Decoder.decode_code_point("\xf0\x9f\xa7\xa1", code_point, code_point_length); + result = Testparser.Decoder.decode_code_point("\xf0\x9f\xa7\xa1", &code_point, &code_point_length); assert(result == Testparser.P_SUCCESS); assert(code_point == 0x1F9E1u); assert(code_point_length == 4u); - result = Testparser.Decoder.decode_code_point("\xf0\x9f\x27", code_point, code_point_length); + result = Testparser.Decoder.decode_code_point("\xf0\x9f\x27", &code_point, &code_point_length); assert(result == Testparser.P_DECODE_ERROR); - result = Testparser.Decoder.decode_code_point("\xf0\x9f\xa7\xFF", code_point, code_point_length); + result = Testparser.Decoder.decode_code_point("\xf0\x9f\xa7\xFF", &code_point, &code_point_length); assert(result == Testparser.P_DECODE_ERROR); - result = Testparser.Decoder.decode_code_point("\xfe", code_point, code_point_length); + result = Testparser.Decoder.decode_code_point("\xfe", &code_point, &code_point_length); assert(result == Testparser.P_DECODE_ERROR); }