From 8163d5b64739447532c871f3c56ba7bbe236a516 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sat, 11 Jun 2022 05:48:55 -0700 Subject: [PATCH] Allow some cases of uninitialized parsers --- IDEHelper/Compiler/BfCompiler.cpp | 118 ++++++++++++++++-------------- IDEHelper/Compiler/BfParser.cpp | 6 +- 2 files changed, 68 insertions(+), 56 deletions(-) diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index df43e3c1..57e89d0e 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -9823,65 +9823,68 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo BfAstNode* regionStart = NULL; BfPreprocessorNode* prevPreprocessorNode = NULL; int ignoredSectionStart = -1; - - for (auto element : bfParser->mSidechannelRootNode->mChildArr) + + if (bfParser->mSidechannelRootNode != NULL) { - if (auto preprocessorNode = BfNodeDynCast(element)) + for (auto element : bfParser->mSidechannelRootNode->mChildArr) { - if ((ignoredSectionStart != -1) && (prevPreprocessorNode != NULL) && (prevPreprocessorNode->mCommand != NULL)) + if (auto preprocessorNode = BfNodeDynCast(element)) { - collapseVisitor.Add(prevPreprocessorNode->mCommand->mSrcStart, preprocessorNode->mSrcEnd - 1); - 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(element)) - { - if (ignoredSectionStart == -1) - { - for (int i = preprocessorNode->mSrcStart; i < preprocessorNode->mSrcEnd - 1; i++) + if ((ignoredSectionStart != -1) && (prevPreprocessorNode != NULL) && (prevPreprocessorNode->mCommand != NULL)) { - if (bfParser->mSrc[i] == '\n') - { - ignoredSectionStart = i + 1; - break; - } - } - } - } + collapseVisitor.Add(prevPreprocessorNode->mCommand->mSrcStart, preprocessorNode->mSrcEnd - 1); + ignoredSectionStart = -1; + } - char kind = 0; - if (auto commentNode = BfNodeDynCast(element)) - { - collapseVisitor.UpdateSeries(commentNode, 'C'); + 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(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(element)) + { + collapseVisitor.UpdateSeries(commentNode, 'C'); + } } } @@ -10063,7 +10066,12 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo int endLineChar = 0; if (srcEnd >= 0) 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); } } diff --git a/IDEHelper/Compiler/BfParser.cpp b/IDEHelper/Compiler/BfParser.cpp index 00c6bd8d..426c54d6 100644 --- a/IDEHelper/Compiler/BfParser.cpp +++ b/IDEHelper/Compiler/BfParser.cpp @@ -404,7 +404,11 @@ BfParser::~BfParser() { int parserCount = gParserCount--; - if (mParserData->mRefCount == -1) + if (mParserData == NULL) + { + + } + else if (mParserData->mRefCount == -1) { // Owned data, never intended for cache mParserData->mSrc = NULL; // Count on BfSource dtor to release strc