From 0b1b4a8b29e0f7e1dba32b2708e9d5288a3146ac Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Sat, 29 Apr 2023 15:24:46 +0000 Subject: [PATCH] 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. --- src/HeaderParser.c | 6 +++--- src/include/HeaderParser.h | 1 + tools/src/hdoc.c | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/HeaderParser.c b/src/HeaderParser.c index 6d754ab..0977788 100644 --- a/src/HeaderParser.c +++ b/src/HeaderParser.c @@ -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); diff --git a/src/include/HeaderParser.h b/src/include/HeaderParser.h index ae255aa..c5a7370 100644 --- a/src/include/HeaderParser.h +++ b/src/include/HeaderParser.h @@ -57,6 +57,7 @@ typedef enum HeaderExprType HP_TYPEDEF, HP_DECLARATION, HP_GLOBAL, + HP_UNKNOWN, HP_SYNTAX_ERROR, HP_PARSE_ERROR, HP_EOF diff --git a/tools/src/hdoc.c b/tools/src/hdoc.c index 5d04bc2..8a671fe 100644 --- a/tools/src/hdoc.c +++ b/tools/src/hdoc.c @@ -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");