Menu

Commit [r13019]  Maximize  Restore  History

P-code: fix the typedef rule reading its type through the wrong union member

The TYPEDEF rule passed $<define_variables>2 for a dtype, but dtype yields
$<define_var> - a variable_element, not a define_variables. named_structs holds
a define_variables (a member list), so every typedef registered a
variable_element through the wrong union member and the name was unusable
afterwards.

A typedef name is only ever used as a pointer target or a sizeof operand, and
the named-struct machinery is the only way to record a name here, so the
typedef'd type is now wrapped in a one-element member list. That gives the
right size for sizeof and the right behaviour for a pointer.

Two things fell out of testing it:

* dtype had no pointer form for a typedef name, so "_dynelem_aa *aa=0;" - which
is how the generator declares every dynamic array - was a syntax error. Added
alongside the STRUCT and built-in pointer forms. The grammar conflict count is
unchanged (64 shift/reduce, 1 reduce/reduce).

* add_default_struct_list() was static; it is now exported so the rule can build
that one-element list.

Also removed three leftover debug printfs that went to stdout on every typedef
or typedef-name use ("TD", "Adding : x", "v=%p" and friends). c2pcode's output
is read by callers, so these were noise in it.

The p-code corpus run is now 28 passing with a single compile failure left - a
22,000 line module that exhausts the parser. It was 21 passing with 15 compile
failures before this round of work.

Grammar and lexer only; the C code generator is untouched. Full build clean,
OO suite passes, multi-module p-code still links and runs.

mikeaubury 2026-08-31

changed /aubit4glsrc/trunk/compilers/pcode/compiler_variables.c
changed /aubit4glsrc/trunk/compilers/pcode/lex.pregen.c
changed /aubit4glsrc/trunk/compilers/pcode/npcode_defs.h
changed /aubit4glsrc/trunk/compilers/pcode/simple.lex
changed /aubit4glsrc/trunk/compilers/pcode/simple.yacc
/aubit4glsrc/trunk/compilers/pcode/compiler_variables.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/lex.pregen.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/npcode_defs.h Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/simple.lex Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/simple.yacc Diff Switch to side-by-side view
Loading...