macro: Fixed macro expansion bug
authorLukas Krickl <lukas@krickl.dev>
Mon, 14 Apr 2025 15:14:31 +0000 (17:14 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 14 Apr 2025 15:14:31 +0000 (17:14 +0200)
It was not possible for macros to expand defines correctly when a
comment was preceeding the expansion.
This was caused by the comment_seen flag that instructs the preprocessor
to skip tokens in commnets.
This flag is now unset when a new line (\n) is encountered.

.clang-tidy
src/ulas.c
tests/t0.s

index 42c3dd0e0deb6fde64ddebaa60d812cbc2d477d1..ecc59c3ff67f4079544014aa0a176727771020a4 100644 (file)
@@ -29,7 +29,8 @@ Checks: "*,
   -readability-uppercase-literal-suffix,
   -hicpp-function-size,
   -readability-function-size,
-  -cert-env33-c
+  -cert-env33-c,
+  -cppcoreguidelines-macro-to-enum
 "
 WarningsAsErrors: ''
 HeaderFilterRegex: ''
index 1f8d8a708929cbfef2698954bf06c09b836bb9a9..3e7d92e724ccf338221e59765daa2defd78944b9 100644 (file)
@@ -878,6 +878,12 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
   // only expand macros if they match toks[0] though!
   // otherwise memcpy the read bytes 1:1 into the new string
   while ((read = ulas_tok(&pp->tok, &praw_line, *n))) {
+    // remove comment seen if raw line 
+    // starts a new line 
+    // this fixes expnasion in macros containing comments
+    if (*praw_line == '\n') {
+      comment_seen = 0;
+    }
     struct ulas_ppdef *def =
         ulas_preprocgetdef(pp, pp->tok.buf, pp->tok.maxlen);
 
index 89c614360cb398dc43e96a010981c31e3388234f..04c14b83d65d283f21dc539add280f8a21273f64 100644 (file)
@@ -204,9 +204,11 @@ test_scoped:
 
 .def int arg_p = 2 
 
-#macro defarg2 
+#macro defarg2
+  ; test
   .db $1 + 1, $2
   .db $1
 #endmacro
 
 defarg2 DEFARG * arg_p, arg_p
+