diff --git a/libs/qsynedit/qsynedit/CodeFolding.cpp b/libs/qsynedit/qsynedit/CodeFolding.cpp index 5d7957d1..e4006b98 100644 --- a/libs/qsynedit/qsynedit/CodeFolding.cpp +++ b/libs/qsynedit/qsynedit/CodeFolding.cpp @@ -55,13 +55,13 @@ CodeFoldingOptions::CodeFoldingOptions(): bool CodeFoldingRange::parentCollapsed() { - PCodeFoldingRange parentFold = parent; + PCodeFoldingRange parentFold = parent.lock(); // Find first parent that is collapsed while (parentFold) { if (parentFold->collapsed) { return true; } - parentFold = parentFold->parent; + parentFold = parentFold->parent.lock(); } return false; } @@ -73,14 +73,12 @@ void CodeFoldingRange::move(int count) } CodeFoldingRange::CodeFoldingRange(PCodeFoldingRange aParent, - PCodeFoldingRanges aAllFold, int aFromLine, PCodeFoldingDefine aFoldRegion, int aToLine): fromLine(aFromLine), toLine(aToLine), linesCollapsed(0), collapsed(false), - allFoldRanges(aAllFold), foldRegion(aFoldRegion), hintMarkLeft(0), parent(aParent) @@ -115,7 +113,7 @@ PCodeFoldingRange CodeFoldingRanges::addByParts(PCodeFoldingRange aParent, PCodeFoldingDefine aFoldRegion, int aToLine) { - PCodeFoldingRange range=std::make_shared(aParent,aAllFold, aFromLine,aFoldRegion,aToLine); + PCodeFoldingRange range=std::make_shared(aParent, aFromLine,aFoldRegion,aToLine); mRanges.append(range); if (aAllFold && aAllFold.get()!=this) { aAllFold->add(range); diff --git a/libs/qsynedit/qsynedit/CodeFolding.h b/libs/qsynedit/qsynedit/CodeFolding.h index 066a8511..3eb4d522 100644 --- a/libs/qsynedit/qsynedit/CodeFolding.h +++ b/libs/qsynedit/qsynedit/CodeFolding.h @@ -38,7 +38,6 @@ typedef std::shared_ptr PSynFoldRegions; struct CodeFoldingDefine { bool addEnding; - CodeFoldingDefines subFoldRegions; QChar openSymbol; QChar closeSymbol; QString highlight; @@ -85,14 +84,12 @@ public: int linesCollapsed; // Number of collapsed lines PCodeFoldingRanges subFoldRanges; // Sub fold ranges bool collapsed; // Is collapsed? - PCodeFoldingRanges allFoldRanges;// TAllFoldRanges pointer - PCodeFoldingDefine foldRegion; // FoldRegion + std::weak_ptr foldRegion; // FoldRegion int hintMarkLeft; - PCodeFoldingRange parent; + std::weak_ptr parent; bool parentCollapsed(); void move(int count); - explicit CodeFoldingRange(PCodeFoldingRange aParent, PCodeFoldingRanges aAllFold, - int aFromLine, PCodeFoldingDefine aFoldRegion, int aToLine); + explicit CodeFoldingRange(PCodeFoldingRange aParent, int aFromLine, PCodeFoldingDefine aFoldRegion, int aToLine); }; } diff --git a/libs/qsynedit/qsynedit/SynEdit.cpp b/libs/qsynedit/qsynedit/SynEdit.cpp index e85eae79..c8ef0e29 100644 --- a/libs/qsynedit/qsynedit/SynEdit.cpp +++ b/libs/qsynedit/qsynedit/SynEdit.cpp @@ -3689,7 +3689,7 @@ void SynEdit::findSubFoldRange(PCodeFoldingRanges TopFoldRanges, int FoldIndex,P // Stop the recursion if we find a closing char, and return to our parent if (Parent) { Parent->toLine = Line + 1; - Parent = Parent->parent; + Parent = Parent->parent.lock(); if (!Parent) { parentFoldRanges = TopFoldRanges; } else { @@ -3749,7 +3749,7 @@ void SynEdit::findSubFoldRange(PCodeFoldingRanges TopFoldRanges, int FoldIndex,P // Stop the recursion if we find a closing char, and return to our parent if (Parent) { Parent->toLine = Line + 1; - Parent = Parent->parent; + Parent = Parent->parent.lock(); if (!Parent) { parentFoldRanges = TopFoldRanges; } else { diff --git a/libs/qsynedit/qsynedit/highlighter/cpp.cpp b/libs/qsynedit/qsynedit/highlighter/cpp.cpp index 8b73596c..d19a1abf 100644 --- a/libs/qsynedit/qsynedit/highlighter/cpp.cpp +++ b/libs/qsynedit/qsynedit/highlighter/cpp.cpp @@ -18,6 +18,7 @@ #include "../Constants.h" #include +#include namespace QSynedit { @@ -296,16 +297,16 @@ void CppHighlighter::ansiCppProc() mTokenId = TokenId::Comment; if (mRun>=mLineSize) { nullProc(); - if ( (mRun<1) || (mLine[mRun-1]!='\\')) { + if ( (mRun-1<0) || (mLine[mRun-1]!='\\')) { mRange.state = RangeState::rsUnknown; - return; } + return; } while (mRun=0) && isSpaceChar(mLine[mRun-1]) && + if ( (mRange.state == RangeState::rsCppComment || mRange.state == RangeState::rsDirective || mRange.state == RangeState::rsString || mRange.state == RangeState::rsMultiLineString - || mRange.state == RangeState::rsMultiLineDirective) ) { + || mRange.state == RangeState::rsMultiLineDirective) + && (mRun-1>=0) + && (mRun-1 float. an arithmetic operator return; - if (mLine[mRun-1]!= 'e' && mLine[mRun-1]!='E') // number = float, but no exponent. an arithmetic operator + if (mRun-1>=0 && mLine[mRun-1]!= 'e' && mLine[mRun-1]!='E') // number = float, but no exponent. an arithmetic operator return; if (mRun+1'9')) {// invalid mRun+=1; @@ -749,7 +753,7 @@ void CppHighlighter::numberProc() case 'e': case 'E': if (mTokenId!=TokenId::Hex) { - if (mLine[mRun-1]>='0' || mLine[mRun-1]<='9' ) {//exponent + if (mRun-1>=0 && (mLine[mRun-1]>='0' || mLine[mRun-1]<='9') ) {//exponent for (int i=idx1;i=0 && (mLine[mRun-1]=='l' || mLine[mRun-1]=='L')) { mRun+=1; mTokenId = TokenId::Unknown; return; @@ -843,7 +847,7 @@ void CppHighlighter::numberProc() } mRun+=1; } - if (mLine[mRun-1] == '\'') { + if (mRun-1>=0 && mLine[mRun-1] == '\'') { mTokenId = TokenId::Unknown; } } @@ -851,7 +855,7 @@ void CppHighlighter::numberProc() void CppHighlighter::orSymbolProc() { mTokenId = TokenId::Symbol; - if (mRun+1<=mLineSize) { + if (mRun+1'7') - break; + if (mRun='0' && mLine[mRun]<='9') - || (mLine[mRun]>='a' && mLine[mRun]<='f') - || (mLine[mRun]>='A' && mLine[mRun]<='F') - )) { - mTokenId = TokenId::Unknown; - } else { - while ( - (mLine[mRun]>='0' && mLine[mRun]<='9') - || (mLine[mRun]>='a' && mLine[mRun]<='f') - || (mLine[mRun]>='A' && mLine[mRun]<='F') - ) { + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + for (int i=0;i<3;i++) { + if (mRun>=mLineSize || mLine[mRun]<'0' || mLine[mRun]>'7') + break; mRun+=1; } - } - break; - case 'u': - mRun+=1; - for (int i=0;i<4;i++) { - if (mLine[mRun]<'0' || mLine[mRun]>'7') { - mTokenId = TokenId::Unknown; - return; - } + break; + case '8': + case '9': + mTokenId = TokenId::Unknown; mRun+=1; - } - break; - case 'U': - mRun+=1; - for (int i=0;i<8;i++) { - if (mLine[mRun]<'0' || mLine[mRun]>'7') { - mTokenId = TokenId::Unknown; - return; - } + break; + case 'x': mRun+=1; + if (mRun>=mLineSize || !( + (mLine[mRun]>='0' && mLine[mRun]<='9') + || (mLine[mRun]>='a' && mLine[mRun]<='f') + || (mLine[mRun]>='A' && mLine[mRun]<='F') + )) { + mTokenId = TokenId::Unknown; + } else { + while (mRun='0' && mLine[mRun]<='9') + || (mLine[mRun]>='a' && mLine[mRun]<='f') + || (mLine[mRun]>='A' && mLine[mRun]<='F') + )) { + mRun+=1; + } + } + break; + case 'u': + mRun+=1; + for (int i=0;i<4;i++) { + if (mRun>=mLineSize || mLine[mRun]<'0' || mLine[mRun]>'7') { + mTokenId = TokenId::Unknown; + return; + } + mRun+=1; + } + break; + case 'U': + mRun+=1; + for (int i=0;i<8;i++) { + if (mRun>=mLineSize || mLine[mRun]<'0' || mLine[mRun]>'7') { + mTokenId = TokenId::Unknown; + return; + } + mRun+=1; + } + break; } - break; } if (mRange.state == RangeState::rsMultiLineStringEscapeSeq) mRange.state = RangeState::rsMultiLineString; @@ -1522,30 +1528,40 @@ void CppHighlighter::next() case RangeState::rsAnsiCAsm: case RangeState::rsAnsiCAsmBlock: case RangeState::rsDirectiveComment: + //qDebug()<<"*0-0-0*"; ansiCProc(); break; case RangeState::rsString: + //qDebug()<<"*1-0-0*"; stringProc(); break; case RangeState::rsCppComment: + //qDebug()<<"*2-0-0*"; ansiCppProc(); break; case RangeState::rsMultiLineDirective: + //qDebug()<<"*3-0-0*"; directiveEndProc(); break; case RangeState::rsMultiLineString: + //qDebug()<<"*4-0-0*"; stringEndProc(); break; case RangeState::rsRawStringEscaping: case RangeState::rsRawStringNotEscaping: + //qDebug()<<"*5-0-0*"; rawStringProc(); break; case RangeState::rsStringEscapeSeq: case RangeState::rsMultiLineStringEscapeSeq: + //qDebug()<<"*6-0-0*"; stringEscapeSeqProc(); break; case RangeState::rsChar: - if (mLine[mRun]=='\'') { + //qDebug()<<"*7-0-0*"; + if (mRun>=mLineSize) { + nullProc(); + } else if (mLine[mRun]=='\'') { mRange.state = rsUnknown; mTokenId = TokenId::Char; mRun+=1; @@ -1554,26 +1570,38 @@ void CppHighlighter::next() } break; case RangeState::rsDefineIdentifier: + //qDebug()<<"*8-0-0*"; defineIdentProc(); break; case RangeState::rsDefineRemaining: + //qDebug()<<"*9-0-0*"; defineRemainingProc(); break; default: + //qDebug()<<"*a-0-0*"; mRange.state = RangeState::rsUnknown; - if (mLine[mRun] == 'R' && mRun+1=mLineSize) { + //qDebug()<<"*b-0-0*"; + nullProc(); + } else if (mRun+1