Cope with preprocessor macro usage at the top level of the header.

This workaround allows us to parse the Routes.h properly, although it
notably lacks support for multi-word unknown expressions.
This commit is contained in:
Jordan Bancino 2023-04-29 15:24:46 +00:00
parent a3cc06ff2a
commit 0b1b4a8b29
3 changed files with 8 additions and 3 deletions

View file

@ -651,9 +651,9 @@ HeaderParse(Stream * stream, HeaderExpr * expr)
}
else
{
expr->type = HP_SYNTAX_ERROR;
expr->data.error.msg = "Expected comment, typedef, or extern.";
expr->data.error.lineNo = expr->state.lineNo;
/* Cope with preprocessor macro expansions at the top level. */
expr->type = HP_UNKNOWN;
strncpy(expr->data.text, word, HEADER_EXPR_MAX);
}
Free(word);

View file

@ -57,6 +57,7 @@ typedef enum HeaderExprType
HP_TYPEDEF,
HP_DECLARATION,
HP_GLOBAL,
HP_UNKNOWN,
HP_SYNTAX_ERROR,
HP_PARSE_ERROR,
HP_EOF

View file

@ -315,6 +315,10 @@ main(int argc, char **argv)
isDocumented = 0;
}
break;
case HP_UNKNOWN:
StreamPrintf(StreamStderr(), "Warning: Unknown expression: %s\n",
expr.data.text);
break;
default:
StreamPrintf(StreamStderr(), "Unknown header type: %d\n", expr.type);
StreamPrintf(StreamStderr(), "This is a programming error.\n");