diff --git a/Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/CPP/CPP.jj b/Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/CPP/CPP.jj index 14a0b8c3fc..33560bbcb8 100644 --- a/Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/CPP/CPP.jj +++ b/Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/CPP/CPP.jj @@ -1726,10 +1726,10 @@ PPToken MacroVals() : {Token s,t,u=new Token();u.image="";} } PPToken Pragma() : -{Token t;} -{ t= { - PPToken pt = new PPToken(t); - if (emitExecSwitch==true) println("#pragma " + defs.expand(t.image,true)); return pt; +{Token t,u=null; } +{ (LOOKAHEAD(2)(t= { if (u==null) { u = t; } else { u.image += t.image; } } ))+ { + PPToken pt = new PPToken(u); + if (emitExecSwitch==true) println("#pragma " + defs.expand(u.image,true)); return pt; } } @@ -1908,7 +1908,7 @@ PPToken NewLines() : t= | // newline coming from // t= | t= | - t= | + t= | t= | t= | t= | @@ -2691,13 +2691,19 @@ TOKEN : { TOKEN : { - ()* > : DEFAULT | - > : DEFAULT + ( ~["\\","\n","\r","/"," ","\t"] | + () + )+ > : PRAGMA | + > : DEFAULT } SKIP : { - <_WSP1: > : PRAGMA + <_LCMTPRAG: > : LINECOMMENT | + <_SCMT_PRAG: ( ( | ("*" ~["/"]) | ("/"))+ ) > : PRAGMA | + <_COD_WSP: > : PRAGMA | + <_COD_PRAG: > : PRAGMA } diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/util/cparser/PreProcessorTest.java b/Ghidra/Features/Base/src/test/java/ghidra/app/util/cparser/PreProcessorTest.java index ae699694b2..fcbd7af84e 100644 --- a/Ghidra/Features/Base/src/test/java/ghidra/app/util/cparser/PreProcessorTest.java +++ b/Ghidra/Features/Base/src/test/java/ghidra/app/util/cparser/PreProcessorTest.java @@ -127,6 +127,15 @@ public class PreProcessorTest extends AbstractGenericTest { "\" second line\"\n" + "\" third line\"\n" + "\" fourth line\")") != -1); + + assertTrue("multi line #pragma failed ", results + .indexOf("#pragma multiple lines pragma") != -1); + + assertTrue("#pragma with comment failed ", results + .indexOf("#pragma no comment here") != -1); + + assertTrue("#pragma with EOL comment failed ", results + .indexOf("#pragma with no EOL comment here") != -1); } @Test diff --git a/Ghidra/Features/Base/src/test/resources/ghidra/app/util/cparser/PreProcessorTest.h b/Ghidra/Features/Base/src/test/resources/ghidra/app/util/cparser/PreProcessorTest.h index 093a181628..cc3afcb769 100644 --- a/Ghidra/Features/Base/src/test/resources/ghidra/app/util/cparser/PreProcessorTest.h +++ b/Ghidra/Features/Base/src/test/resources/ghidra/app/util/cparser/PreProcessorTest.h @@ -106,6 +106,14 @@ int foo; #pragma once +#pragma multiple \ + lines \ + pragma + +#pragma no comment here /* no comment / here */ + +#pragma with no EOL comment here // no comment here + #define PTYPE 4 #define TYPE2 2 /* 2 */