GP-2808 Fixed more pragma parsing issues and fixed silent failure when a

parsing error actually exists in certain cases.
This commit is contained in:
emteere
2023-06-14 23:20:14 +00:00
parent 69289358f2
commit b5002820c5
3 changed files with 37 additions and 12 deletions
@@ -1168,7 +1168,9 @@ TOKEN :
| |
<DECLSPEC : "__declspec"> <DECLSPEC : "__declspec">
| |
<PRAGMA : (("_")+ | "#") "pragma"> : PRAGMALINE <PRAGMA : "#" "pragma"> {parenNesting=-1; SwitchTo(PRAGMALINE); }
|
<PRAGMA_FUNC : ("__pragma" | "_Pragma")> {parenNesting=0; SwitchTo(PRAGMALINE); }
| |
<READABLETO : "__readableTo"> <READABLETO : "__readableTo">
| |
@@ -1352,9 +1354,9 @@ TOKEN :
| |
<#PDIGIT : [ "0"-"9" ]> <#PDIGIT : [ "0"-"9" ]>
| |
<POPEN : "("> { parenNesting++; } <POPEN : "("> { if (parenNesting != -1) parenNesting++; }
| |
<PCLOSE : ")"> { parenNesting--; if (parenNesting == 0) SwitchTo(DEFAULT); } <PCLOSE : ")"> { if (parenNesting != -1) parenNesting--; if (parenNesting == 0) SwitchTo(DEFAULT); }
| |
<PMINUS : "-"> <PMINUS : "-">
| |
@@ -1461,6 +1463,7 @@ TOKEN :
void TranslationUnit() : {} void TranslationUnit() : {}
{ {
( ExternalDeclaration() )+ ( ExternalDeclaration() )+
< EOF >
{ {
//jjt return jjtThis; //jjt return jjtThis;
} }
@@ -1910,7 +1913,8 @@ Token MultiLineString() : {
void PragmaSpec() : { void PragmaSpec() : {
} }
{ {
( ( <PRAGMA> ) PragmaSpecifier() ) <PRAGMA> (PragmaSpecifier())+ |
<PRAGMA_FUNC> PragmaSpecifier()
} }
@@ -2765,7 +2769,7 @@ Object AssignmentExpression() : {
| |
LOOKAHEAD(3) LOOKAHEAD(3)
obj = ConditionalExpression() obj = ConditionalExpression()
) ) [ PragmaSpec() ]
{ {
return obj; return obj;
} }
@@ -222,18 +222,21 @@ public class CParserTest extends AbstractGhidraHeadlessIntegrationTest {
String parseMessages = parser.getParseMessages(); String parseMessages = parser.getParseMessages();
System.out.println(parseMessages); System.out.println(parseMessages);
assertTrue("Duplicate ENUM message missing", parseMessages.contains("duplicate enum value: options_enum : PLUS_SET : 16"));
assertTrue("Duplicate ENUM message missing", parseMessages.contains("Static_Asssert has failed \"\"math fail!\"\""));
assertTrue("Duplicate ENUM message missing", parseMessages.contains("Static_Asssert has failed \"\"1 + 1 == 3, fail!\"\""));
DataType dt; DataType dt;
DataType pointedToDT; DataType pointedToDT;
ParameterDefinition[] funcArgs; ParameterDefinition[] funcArgs;
FunctionDefinition funcDef; FunctionDefinition funcDef;
String str; String str;
dt = dtMgr.getDataType(new CategoryPath("/"), "pragmaPassed");
assertNotNull("Structure after pragma not parsed", dt);
assertTrue("Duplicate ENUM message missing", parseMessages.contains("duplicate enum value: options_enum : PLUS_SET : 16"));
assertTrue("Duplicate ENUM message missing", parseMessages.contains("Static_Asssert has failed \"\"math fail!\"\""));
assertTrue("Duplicate ENUM message missing", parseMessages.contains("Static_Asssert has failed \"\"1 + 1 == 3, fail!\"\""));
dt = dtMgr.getDataType(new CategoryPath("/"), "_IO_FILE_complete"); dt = dtMgr.getDataType(new CategoryPath("/"), "_IO_FILE_complete");
Structure sldt = (Structure) dt; Structure sldt = (Structure) dt;
DataTypeComponent data3 = sldt.getComponent(2); DataTypeComponent data3 = sldt.getComponent(2);
@@ -179,6 +179,8 @@ int (__stdcall * GetSectionBlock) (
// nothing will parse after this line if the this fails // nothing will parse after this line if the this fails
#pragma test for, pragma, with, commas outside parens #pragma test for, pragma, with, commas outside parens
#pragma region System Family (kernel drivers) with Desktop Family for compat
#pragma warning(disable) #pragma warning(disable)
#pragma warning(disable:4035 4793) // re-enable below #pragma warning(disable:4035 4793) // re-enable below
@@ -191,6 +193,22 @@ int (__stdcall * GetSectionBlock) (
#pragma warning (suppress: 28128) #pragma warning (suppress: 28128)
struct pragmaPassed {
char dummy;
};
int whileWithPragma(int a)
{
do {
a++;
} while (0 __pragma(warning(disable: 28110)));
__pragma(warning(push)) __pragma(warning(disable : 4548)) do {__noop(pszDest);} while((0,0) __pragma(warning(pop)) );
return a;
}
int g(int a, int b, int c) int g(int a, int b, int c)
{ {
return a+b+c; return a+b+c;