1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 20:12:21 +02:00

Allow catch-all '#pragma warning disable'

This commit is contained in:
Brian Fiete 2025-01-16 07:36:45 -08:00
parent d367213c31
commit f10f389400
2 changed files with 22 additions and 11 deletions

View file

@ -363,21 +363,18 @@ bool BfParserData::IsUnwarnedAt(BfAstNode* node)
bool BfParserData::IsWarningEnabledAtSrcIndex(int warningNumber, int srcIdx) bool BfParserData::IsWarningEnabledAtSrcIndex(int warningNumber, int srcIdx)
{ {
int enabled = 1; //CDH TODO if/when we add warning level support, this default will change based on the warning number and the general project warning level setting int enabled = 1; //CDH TODO if/when we add warning level support, this default will change based on the warning number and the general project warning level setting
int lastUnwarnPos = 0;
for (const auto& it : mWarningEnabledChanges) for (const auto& it : mWarningEnabledChanges)
{ {
if (it.mKey > srcIdx) if (it.mKey > srcIdx)
break; break;
if (it.mValue.mWarningNumber == warningNumber) if ((it.mValue.mWarningNumber == warningNumber) || (it.mValue.mWarningNumber == -1))
{ {
if (it.mValue.mEnable) if (it.mValue.mEnable)
enabled++; enabled++;
else else
enabled--; enabled--;
} }
if (it.mValue.mWarningNumber == -1)
lastUnwarnPos = -1;
} }
return enabled > 0; return enabled > 0;
} }
@ -923,10 +920,14 @@ void BfParser::HandlePragma(const StringImpl& pragma, BfBlock* block)
mPassInstance->FailAt("Expected \"disable\" or \"restore\" after \"warning\"", mSourceData, iterNode->GetSrcStart(), iterNode->GetSrcLength()); mPassInstance->FailAt("Expected \"disable\" or \"restore\" after \"warning\"", mSourceData, iterNode->GetSrcStart(), iterNode->GetSrcLength());
} }
//iterNode = parentNode->mChildArr.GetAs<BfAstNode*>(++curIdx); int srcStart = iterNode->GetSrcStart();
int nodeCount = 0;
iterNode = itr.Get(); iterNode = itr.Get();
while (iterNode) while (iterNode)
{ {
++nodeCount;
++itr; ++itr;
auto tokenStr = iterNode->ToString(); auto tokenStr = iterNode->ToString();
if (tokenStr != ",") // commas allowed between warning numbers but not required; we just ignore them if (tokenStr != ",") // commas allowed between warning numbers but not required; we just ignore them
@ -941,11 +942,14 @@ void BfParser::HandlePragma(const StringImpl& pragma, BfBlock* block)
break; break;
} }
} }
if (isNum)
int warningNum = atoi(tokenStr.c_str());
if ((isNum) && (warningNum > 0))
{ {
BfParserWarningEnabledChange wec; BfParserWarningEnabledChange wec;
wec.mEnable = enable; wec.mEnable = enable;
wec.mWarningNumber = atoi(tokenStr.c_str()); wec.mWarningNumber = warningNum;
mParserData->mWarningEnabledChanges[iterNode->GetSrcStart()] = wec; mParserData->mWarningEnabledChanges[iterNode->GetSrcStart()] = wec;
} }
else else
@ -953,10 +957,17 @@ void BfParser::HandlePragma(const StringImpl& pragma, BfBlock* block)
mPassInstance->FailAt("Expected decimal warning number", mSourceData, iterNode->GetSrcStart(), iterNode->GetSrcLength()); mPassInstance->FailAt("Expected decimal warning number", mSourceData, iterNode->GetSrcStart(), iterNode->GetSrcLength());
} }
} }
//iterNode = parentNode->mChildArr.Get(++curIdx);
iterNode = itr.Get(); iterNode = itr.Get();
} }
if (nodeCount == 0)
{
BfParserWarningEnabledChange wec;
wec.mEnable = enable;
wec.mWarningNumber = -1;
mParserData->mWarningEnabledChanges[srcStart] = wec;
}
} }
else else
{ {

View file

@ -1762,7 +1762,7 @@ BfError* BfPassInstance::WarnAt(int warningNumber, const StringImpl& warning, Bf
return NULL; return NULL;
auto bfParser = bfSource->ToParserData(); auto bfParser = bfSource->ToParserData();
if ((bfParser != NULL) && (warningNumber > 0) && (!bfParser->IsWarningEnabledAtSrcIndex(warningNumber, srcIdx))) if ((bfParser != NULL) && (!bfParser->IsWarningEnabledAtSrcIndex(warningNumber, srcIdx)))
return NULL; return NULL;
if (!WantsRangeRecorded(bfParser, srcIdx, srcLen, true, isDeferred)) if (!WantsRangeRecorded(bfParser, srcIdx, srcLen, true, isDeferred))