mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Allow some cases of uninitialized parsers
This commit is contained in:
parent
931e29a1f3
commit
8163d5b647
2 changed files with 68 additions and 56 deletions
|
@ -9823,65 +9823,68 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo
|
||||||
BfAstNode* regionStart = NULL;
|
BfAstNode* regionStart = NULL;
|
||||||
BfPreprocessorNode* prevPreprocessorNode = NULL;
|
BfPreprocessorNode* prevPreprocessorNode = NULL;
|
||||||
int ignoredSectionStart = -1;
|
int ignoredSectionStart = -1;
|
||||||
|
|
||||||
for (auto element : bfParser->mSidechannelRootNode->mChildArr)
|
if (bfParser->mSidechannelRootNode != NULL)
|
||||||
{
|
{
|
||||||
if (auto preprocessorNode = BfNodeDynCast<BfPreprocessorNode>(element))
|
for (auto element : bfParser->mSidechannelRootNode->mChildArr)
|
||||||
{
|
{
|
||||||
if ((ignoredSectionStart != -1) && (prevPreprocessorNode != NULL) && (prevPreprocessorNode->mCommand != NULL))
|
if (auto preprocessorNode = BfNodeDynCast<BfPreprocessorNode>(element))
|
||||||
{
|
{
|
||||||
collapseVisitor.Add(prevPreprocessorNode->mCommand->mSrcStart, preprocessorNode->mSrcEnd - 1);
|
if ((ignoredSectionStart != -1) && (prevPreprocessorNode != NULL) && (prevPreprocessorNode->mCommand != NULL))
|
||||||
ignoredSectionStart = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringView sv = preprocessorNode->mCommand->ToStringView();
|
|
||||||
if (sv == "region")
|
|
||||||
regionStart = preprocessorNode->mCommand;
|
|
||||||
else if (sv == "endregion")
|
|
||||||
{
|
|
||||||
if (regionStart != NULL)
|
|
||||||
collapseVisitor.Add(regionStart->mSrcStart, preprocessorNode->mCommand->mSrcStart, 'R');
|
|
||||||
regionStart = NULL;
|
|
||||||
}
|
|
||||||
else if (sv == "if")
|
|
||||||
{
|
|
||||||
condStart = preprocessorNode->mCommand;
|
|
||||||
}
|
|
||||||
else if (sv == "endif")
|
|
||||||
{
|
|
||||||
if (condStart != NULL)
|
|
||||||
collapseVisitor.Add(condStart->mSrcStart, preprocessorNode->mCommand->mSrcStart);
|
|
||||||
condStart = NULL;
|
|
||||||
}
|
|
||||||
else if ((sv == "else") || (sv == "elif"))
|
|
||||||
{
|
|
||||||
if (condStart != NULL)
|
|
||||||
collapseVisitor.Add(condStart->mSrcStart, collapseVisitor.GetLineEndBefore(preprocessorNode->mSrcStart));
|
|
||||||
condStart = preprocessorNode->mCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
prevPreprocessorNode = preprocessorNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto preprocessorNode = BfNodeDynCast<BfPreprocesorIgnoredSectionNode>(element))
|
|
||||||
{
|
|
||||||
if (ignoredSectionStart == -1)
|
|
||||||
{
|
|
||||||
for (int i = preprocessorNode->mSrcStart; i < preprocessorNode->mSrcEnd - 1; i++)
|
|
||||||
{
|
{
|
||||||
if (bfParser->mSrc[i] == '\n')
|
collapseVisitor.Add(prevPreprocessorNode->mCommand->mSrcStart, preprocessorNode->mSrcEnd - 1);
|
||||||
{
|
ignoredSectionStart = -1;
|
||||||
ignoredSectionStart = i + 1;
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char kind = 0;
|
StringView sv = preprocessorNode->mCommand->ToStringView();
|
||||||
if (auto commentNode = BfNodeDynCast<BfCommentNode>(element))
|
if (sv == "region")
|
||||||
{
|
regionStart = preprocessorNode->mCommand;
|
||||||
collapseVisitor.UpdateSeries(commentNode, 'C');
|
else if (sv == "endregion")
|
||||||
|
{
|
||||||
|
if (regionStart != NULL)
|
||||||
|
collapseVisitor.Add(regionStart->mSrcStart, preprocessorNode->mCommand->mSrcStart, 'R');
|
||||||
|
regionStart = NULL;
|
||||||
|
}
|
||||||
|
else if (sv == "if")
|
||||||
|
{
|
||||||
|
condStart = preprocessorNode->mCommand;
|
||||||
|
}
|
||||||
|
else if (sv == "endif")
|
||||||
|
{
|
||||||
|
if (condStart != NULL)
|
||||||
|
collapseVisitor.Add(condStart->mSrcStart, preprocessorNode->mCommand->mSrcStart);
|
||||||
|
condStart = NULL;
|
||||||
|
}
|
||||||
|
else if ((sv == "else") || (sv == "elif"))
|
||||||
|
{
|
||||||
|
if (condStart != NULL)
|
||||||
|
collapseVisitor.Add(condStart->mSrcStart, collapseVisitor.GetLineEndBefore(preprocessorNode->mSrcStart));
|
||||||
|
condStart = preprocessorNode->mCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
prevPreprocessorNode = preprocessorNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto preprocessorNode = BfNodeDynCast<BfPreprocesorIgnoredSectionNode>(element))
|
||||||
|
{
|
||||||
|
if (ignoredSectionStart == -1)
|
||||||
|
{
|
||||||
|
for (int i = preprocessorNode->mSrcStart; i < preprocessorNode->mSrcEnd - 1; i++)
|
||||||
|
{
|
||||||
|
if (bfParser->mSrc[i] == '\n')
|
||||||
|
{
|
||||||
|
ignoredSectionStart = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char kind = 0;
|
||||||
|
if (auto commentNode = BfNodeDynCast<BfCommentNode>(element))
|
||||||
|
{
|
||||||
|
collapseVisitor.UpdateSeries(commentNode, 'C');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10063,7 +10066,12 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo
|
||||||
int endLineChar = 0;
|
int endLineChar = 0;
|
||||||
if (srcEnd >= 0)
|
if (srcEnd >= 0)
|
||||||
emitParser->GetLineCharAtIdx(srcEnd, endLine, endLineChar);
|
emitParser->GetLineCharAtIdx(srcEnd, endLine, endLineChar);
|
||||||
outString += StrFormat("e%d,%d,%d,%d,%d\n", embedId, charIdx, startLine, endLine + 1, typeInst->mTypeDef->mTypeDeclaration->GetParser()->mTextVersion);
|
|
||||||
|
int textVersion = -1;
|
||||||
|
auto declParser = typeInst->mTypeDef->mTypeDeclaration->GetParser();
|
||||||
|
if (declParser != NULL)
|
||||||
|
textVersion = declParser->mTextVersion;
|
||||||
|
outString += StrFormat("e%d,%d,%d,%d,%d\n", embedId, charIdx, startLine, endLine + 1, textVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -404,7 +404,11 @@ BfParser::~BfParser()
|
||||||
{
|
{
|
||||||
int parserCount = gParserCount--;
|
int parserCount = gParserCount--;
|
||||||
|
|
||||||
if (mParserData->mRefCount == -1)
|
if (mParserData == NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (mParserData->mRefCount == -1)
|
||||||
{
|
{
|
||||||
// Owned data, never intended for cache
|
// Owned data, never intended for cache
|
||||||
mParserData->mSrc = NULL; // Count on BfSource dtor to release strc
|
mParserData->mSrc = NULL; // Count on BfSource dtor to release strc
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue