GP-3611 fix C-parsing of #pragma lines with multiple lines and comments

This commit is contained in:
emteere 2023-07-05 23:36:39 +00:00
parent 76c52ba9a4
commit 2d2584517c
3 changed files with 31 additions and 8 deletions

View File

@ -1726,10 +1726,10 @@ PPToken MacroVals() : {Token s,t,u=new Token();u.image="";}
}
PPToken Pragma() :
{Token t;}
{ t=<PRAGMA_EXPRN> {
PPToken pt = new PPToken(t);
if (emitExecSwitch==true) println("#pragma " + defs.expand(t.image,true)); return pt;
{Token t,u=null; }
{ (LOOKAHEAD(2)(t=<PRAGMA_EXPRN> { 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=<EOLCMNTNL> | // newline coming from //
t=<ERRLINE> |
t=<LINLINE> |
t=<PRGLINE> |
t=<PRAGLINE> |
t=<IFDLINE> |
t=<IFNDLINE> |
t=<DIRLINE> |
@ -2691,13 +2691,19 @@ TOKEN : {
<PRAGMA>
TOKEN : {
<PRAGMA_EXPRN: <NOTWS> (<NOTENDL>)* > : DEFAULT |
<PRGLINE: <ENDL> > : DEFAULT
<PRAGMA_EXPRN:
<WSP> ( ~["\\","\n","\r","/"," ","\t"] |
(<CMT><NOTENDLSTAR>)
)+ > : PRAGMA |
<PRAGLINE: <ENDL> > : DEFAULT
}
<PRAGMA>
SKIP : {
<_WSP1: <WSP> > : PRAGMA
<_LCMTPRAG: <CMT><CMT>> : LINECOMMENT |
<_SCMT_PRAG: (<STARTCMT> (<NOTENDLSTAR> | ("*" ~["/"]) | ("/"))+ <ENDCMT>) > : PRAGMA |
<_COD_WSP: <WSP>> : PRAGMA |
<_COD_PRAG: <COD>> : PRAGMA
}

View File

@ -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

View File

@ -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 */