Skip to content

Commit

Permalink
Suffix states stack bottom with _b to differentiate from the enum
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Dec 4, 2023
1 parent 683615f commit 351a9fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions lib/lrama/grammar/parser_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def states_functions
# define YYPUSH_STATE_#{state_name.upcase}(value) \\
do \\
{ \\
if (#{stack_prefix} + #{states_stack_size_name} - 1 <= #{stack_prefix}_p) \\
YYSTATE_STACK_INCREASE (#{stack_prefix}_a, #{stack_prefix}, #{stack_prefix}_p, #{states_stack_size_name}, "#{state_name}"); \\
if (#{stack_prefix}_b + #{states_stack_size_name} - 1 <= #{stack_prefix}_p) \\
YYSTATE_STACK_INCREASE (#{stack_prefix}_a, #{stack_prefix}_b, #{stack_prefix}_p, #{states_stack_size_name}, "#{state_name}"); \\
YYDPRINTF ((stderr, "Push %s to #{state_name}\\n", #{state_name_macro} (yyparser_state_ ## value))); \\
*++#{stack_prefix}_p = yyparser_state_ ## value; \\
} \\
Expand All @@ -56,7 +56,7 @@ def states_functions
do \\
{ \\
YYDPRINTF ((stderr, "Pop #{state_name}\\n")); \\
if (#{stack_prefix}_p != #{stack_prefix}) \\
if (#{stack_prefix}_p != #{stack_prefix}_b) \\
{ \\
#{stack_prefix}_p -= 1; \\
} \\
Expand All @@ -81,8 +81,8 @@ def states_functions

def states_clean_up_stack
<<~CODE
if (#{stack_prefix} != #{stack_prefix}_a)
YYSTACK_FREE (#{stack_prefix});
if (#{stack_prefix}_b != #{stack_prefix}_a)
YYSTACK_FREE (#{stack_prefix}_b);
CODE
end

Expand All @@ -97,8 +97,8 @@ def states_stacks
/* The parser state stack (#{stack_prefix}): array, bottom, top. */
int #{stack_prefix}_a[YYINITDEPTH];
int *#{stack_prefix} = #{stack_prefix}_a;
int *#{stack_prefix}_p = #{stack_prefix};
int *#{stack_prefix}_b = #{stack_prefix}_a;
int *#{stack_prefix}_p = #{stack_prefix}_b;
STACKS
end

Expand Down
14 changes: 7 additions & 7 deletions spec/lrama/grammar/parser_state_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
# define YYPUSH_STATE_IN_RESCUE(value) \\
do \\
{ \\
if (yyparser_state_in_rescue + yyparser_state_in_rescue_stacksize - 1 <= yyparser_state_in_rescue_p) \\
YYSTATE_STACK_INCREASE (yyparser_state_in_rescue_a, yyparser_state_in_rescue, yyparser_state_in_rescue_p, yyparser_state_in_rescue_stacksize, "in_rescue"); \\
if (yyparser_state_in_rescue_b + yyparser_state_in_rescue_stacksize - 1 <= yyparser_state_in_rescue_p) \\
YYSTATE_STACK_INCREASE (yyparser_state_in_rescue_a, yyparser_state_in_rescue_b, yyparser_state_in_rescue_p, yyparser_state_in_rescue_stacksize, "in_rescue"); \\
YYDPRINTF ((stderr, "Push %s to in_rescue\\n", YY_STATE_IN_RESCUE_NAME (yyparser_state_ ## value))); \\
*++yyparser_state_in_rescue_p = yyparser_state_ ## value; \\
} \\
Expand All @@ -69,7 +69,7 @@
do \\
{ \\
YYDPRINTF ((stderr, "Pop in_rescue\\n")); \\
if (yyparser_state_in_rescue_p != yyparser_state_in_rescue) \\
if (yyparser_state_in_rescue_p != yyparser_state_in_rescue_b) \\
{ \\
yyparser_state_in_rescue_p -= 1; \\
} \\
Expand All @@ -96,8 +96,8 @@
describe "#states_clean_up_stack" do
it "returns states clean up codes" do
expect(parser_state.states_clean_up_stack).to eq <<~CODE
if (yyparser_state_in_rescue != yyparser_state_in_rescue_a)
YYSTACK_FREE (yyparser_state_in_rescue);
if (yyparser_state_in_rescue_b != yyparser_state_in_rescue_a)
YYSTACK_FREE (yyparser_state_in_rescue_b);
CODE
end
end
Expand All @@ -116,8 +116,8 @@
/* The parser state stack (yyparser_state_in_rescue): array, bottom, top. */
int yyparser_state_in_rescue_a[YYINITDEPTH];
int *yyparser_state_in_rescue = yyparser_state_in_rescue_a;
int *yyparser_state_in_rescue_p = yyparser_state_in_rescue;
int *yyparser_state_in_rescue_b = yyparser_state_in_rescue_a;
int *yyparser_state_in_rescue_p = yyparser_state_in_rescue_b;
STACKS
end
end
Expand Down

0 comments on commit 351a9fd

Please sign in to comment.