Refactor the parser to have fewer *_no_str intermediate rules

This commit is contained in:
Rangi42
2025-02-04 14:24:00 +01:00
parent fbde24ee17
commit d9d381cb62

View File

@@ -327,14 +327,11 @@
%type <Expression> relocexpr %type <Expression> relocexpr
%type <Expression> relocexpr_no_str %type <Expression> relocexpr_no_str
%type <Expression> reloc_8bit %type <Expression> reloc_8bit
%type <Expression> reloc_8bit_no_str
%type <Expression> reloc_8bit_offset %type <Expression> reloc_8bit_offset
%type <Expression> reloc_16bit %type <Expression> reloc_16bit
%type <Expression> reloc_16bit_no_str
// Constant numbers // Constant numbers
%type <int32_t> iconst %type <int32_t> iconst
%type <int32_t> const_no_str
%type <int32_t> uconst %type <int32_t> uconst
// Constant numbers used only in specific contexts // Constant numbers used only in specific contexts
%type <int32_t> bit_const %type <int32_t> bit_const
@@ -1226,8 +1223,8 @@ print_exprs:
; ;
print_expr: print_expr:
const_no_str { relocexpr_no_str {
printf("$%" PRIX32, $1); printf("$%" PRIX32, $1.getConstVal());
} }
| string { | string {
// Allow printing NUL characters // Allow printing NUL characters
@@ -1251,7 +1248,8 @@ constlist_8bit:
; ;
constlist_8bit_entry: constlist_8bit_entry:
reloc_8bit_no_str { relocexpr_no_str {
$1.checkNBit(8);
sect_RelByte($1, 0); sect_RelByte($1, 0);
} }
| string { | string {
@@ -1266,7 +1264,8 @@ constlist_16bit:
; ;
constlist_16bit_entry: constlist_16bit_entry:
reloc_16bit_no_str { relocexpr_no_str {
$1.checkNBit(16);
sect_RelWord($1, 0); sect_RelWord($1, 0);
} }
| string { | string {
@@ -1297,13 +1296,6 @@ reloc_8bit:
} }
; ;
reloc_8bit_no_str:
relocexpr_no_str {
$$ = std::move($1);
$$.checkNBit(8);
}
;
reloc_8bit_offset: reloc_8bit_offset:
OP_ADD relocexpr { OP_ADD relocexpr {
$$ = std::move($2); $$ = std::move($2);
@@ -1322,13 +1314,6 @@ reloc_16bit:
} }
; ;
reloc_16bit_no_str:
relocexpr_no_str {
$$ = std::move($1);
$$.checkNBit(16);
}
;
relocexpr: relocexpr:
relocexpr_no_str { relocexpr_no_str {
$$ = std::move($1); $$ = std::move($1);
@@ -1545,12 +1530,6 @@ iconst:
} }
; ;
const_no_str:
relocexpr_no_str {
$$ = $1.getConstVal();
}
;
precision_arg: precision_arg:
%empty { %empty {
$$ = fix_Precision(); $$ = fix_Precision();
@@ -1647,9 +1626,9 @@ strfmt_args:
strfmt_va_args: strfmt_va_args:
%empty {} %empty {}
| strfmt_va_args COMMA const_no_str { | strfmt_va_args COMMA relocexpr_no_str {
$$ = std::move($1); $$ = std::move($1);
$$.args.push_back(static_cast<uint32_t>($3)); $$.args.push_back(static_cast<uint32_t>($3.getConstVal()));
} }
| strfmt_va_args COMMA string { | strfmt_va_args COMMA string {
$$ = std::move($1); $$ = std::move($1);