an attempt to improve error correction on unknown type identifiers.
Also, a minor fix to ival.g
This commit is contained in:
parent
b53309f9f6
commit
1c85c44fad
5 changed files with 28 additions and 6 deletions
|
@ -68,7 +68,8 @@ decl_specifiers /* non-empty */ (register struct decspecs *ds;)
|
||||||
:
|
:
|
||||||
[
|
[
|
||||||
other_specifier(ds)+
|
other_specifier(ds)+
|
||||||
[%prefer /* the thin ice in R.M. 11.1 */
|
[%if (DOT != IDENTIFIER || AHEAD == IDENTIFIER)
|
||||||
|
/* the thin ice in R.M. 11.1 */
|
||||||
single_type_specifier(ds) other_specifier(ds)*
|
single_type_specifier(ds) other_specifier(ds)*
|
||||||
|
|
|
|
||||||
empty
|
empty
|
||||||
|
@ -121,6 +122,11 @@ type_specifier(struct type **tpp;)
|
||||||
single_type_specifier(register struct decspecs *ds;):
|
single_type_specifier(register struct decspecs *ds;):
|
||||||
TYPE_IDENTIFIER /* this includes INT, CHAR, etc. */
|
TYPE_IDENTIFIER /* this includes INT, CHAR, etc. */
|
||||||
{idf2type(dot.tk_idf, &ds->ds_type);}
|
{idf2type(dot.tk_idf, &ds->ds_type);}
|
||||||
|
|
|
||||||
|
IDENTIFIER
|
||||||
|
{error("%s is not a type identifier", dot.tk_idf->id_text);
|
||||||
|
ds->ds_type = error_type;
|
||||||
|
}
|
||||||
|
|
|
|
||||||
struct_or_union_specifier(&ds->ds_type)
|
struct_or_union_specifier(&ds->ds_type)
|
||||||
|
|
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ postfixed(struct expr **expp;)
|
||||||
unary(register struct expr **expp;)
|
unary(register struct expr **expp;)
|
||||||
{struct type *tp; int oper;}
|
{struct type *tp; int oper;}
|
||||||
:
|
:
|
||||||
%if (first_of_type_specifier(AHEAD))
|
%if (first_of_type_specifier(AHEAD) && AHEAD != IDENTIFIER)
|
||||||
cast(&tp) unary(expp)
|
cast(&tp) unary(expp)
|
||||||
{ ch7cast(expp, CAST, tp);
|
{ ch7cast(expp, CAST, tp);
|
||||||
(*expp)->ex_flags |= EX_CAST;
|
(*expp)->ex_flags |= EX_CAST;
|
||||||
|
@ -114,7 +114,7 @@ size_of(register struct expr **expp;)
|
||||||
{struct type *tp;}
|
{struct type *tp;}
|
||||||
:
|
:
|
||||||
SIZEOF
|
SIZEOF
|
||||||
[%if (first_of_type_specifier(AHEAD))
|
[%if (first_of_type_specifier(AHEAD) && AHEAD != IDENTIFIER)
|
||||||
cast(&tp)
|
cast(&tp)
|
||||||
{
|
{
|
||||||
*expp = intexpr(size_of_type(tp, "type"), INT);
|
*expp = intexpr(size_of_type(tp, "type"), INT);
|
||||||
|
|
|
@ -193,6 +193,10 @@ gen_tphead(tpp, nest)
|
||||||
register struct e_stack *p;
|
register struct e_stack *p;
|
||||||
register struct sdef *sd;
|
register struct sdef *sd;
|
||||||
|
|
||||||
|
if (tpp && *tpp == error_type) {
|
||||||
|
gen_error = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (gen_error) return tpp;
|
if (gen_error) return tpp;
|
||||||
p = new_e_stack();
|
p = new_e_stack();
|
||||||
p->next = p_stack;
|
p->next = p_stack;
|
||||||
|
@ -217,6 +221,13 @@ gen_tphead(tpp, nest)
|
||||||
sd = next_field(sd, p);
|
sd = next_field(sd, p);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (! sd) {
|
||||||
|
/* something wrong with this struct */
|
||||||
|
gen_error = 1;
|
||||||
|
p_stack = p->next;
|
||||||
|
free_e_stack(p);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
p->s_def = sd;
|
p->s_def = sd;
|
||||||
if (AHEAD != '{' && aggregate_type(sd->sd_type)) {
|
if (AHEAD != '{' && aggregate_type(sd->sd_type)) {
|
||||||
return gen_tphead(&(sd->sd_type), 1);
|
return gen_tphead(&(sd->sd_type), 1);
|
||||||
|
@ -236,7 +247,10 @@ gen_tpmiddle()
|
||||||
register struct sdef *sd;
|
register struct sdef *sd;
|
||||||
register struct e_stack *p = p_stack;
|
register struct e_stack *p = p_stack;
|
||||||
|
|
||||||
if (gen_error) if (p) return p->s_tpp; else return 0;
|
if (gen_error) {
|
||||||
|
if (p) return p->s_tpp;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
again:
|
again:
|
||||||
tp = *(p->s_tpp);
|
tp = *(p->s_tpp);
|
||||||
switch(tp->tp_fund) {
|
switch(tp->tp_fund) {
|
||||||
|
|
|
@ -140,7 +140,7 @@ external_definition
|
||||||
;
|
;
|
||||||
|
|
||||||
ext_decl_specifiers(struct decspecs *ds;) :
|
ext_decl_specifiers(struct decspecs *ds;) :
|
||||||
%prefer /* the thin ice in R.M. 11.1 */
|
%if (DOT != IDENTIFIER || AHEAD == IDENTIFIER) /* the thin ice in R.M. 11.1 */
|
||||||
decl_specifiers(ds)
|
decl_specifiers(ds)
|
||||||
|
|
|
|
||||||
empty
|
empty
|
||||||
|
|
|
@ -358,7 +358,9 @@ compound_statement:
|
||||||
{
|
{
|
||||||
stack_level();
|
stack_level();
|
||||||
}
|
}
|
||||||
[%while (AHEAD != ':') /* >>> conflict on TYPE_IDENTIFIER */
|
[%while ((DOT != IDENTIFIER && AHEAD != ':') ||
|
||||||
|
(DOT == IDENTIFIER && AHEAD == IDENTIFIER))
|
||||||
|
/* >>> conflict on TYPE_IDENTIFIER, IDENTIFIER */
|
||||||
declaration
|
declaration
|
||||||
]*
|
]*
|
||||||
[%persistent
|
[%persistent
|
||||||
|
|
Loading…
Reference in a new issue