From 82d9eeb1904523ef77f5843f13d9004771296430 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 10 Jul 2024 02:10:49 +0100 Subject: [PATCH] Preprocesser: do not add file body if there's nothing there Before this if a file only defined constants and was then included, the root unit set would still have an empty PP_USE unit. We should only have that if there's something there past preprocessing. Hence, do not add empty bodies to the unit list. --- src/preprocesser.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/preprocesser.cpp b/src/preprocesser.cpp index 0839c2e..5091d88 100644 --- a/src/preprocesser.cpp +++ b/src/preprocesser.cpp @@ -154,11 +154,12 @@ namespace Preprocesser std::vector body_units; Err *err = preprocess(body, body_units, new_token_bag, const_map, file_map, depth + 1); - // TODO: Introduce stack traces for this error (this error occurs in - // outside file that has use site in current file). if (err) return new Err{ET::IN_ERROR, token, err}; - units.push_back(Unit{token, body_units}); + + // Compile away empty bodies + if (body_units.size() != 0) + units.push_back(Unit{token, body_units}); ++i; } // Otherwise file must be part of the source tree already, so skip this