- fix: Wrong code suggestion while inputing numbers in assembly files.

- fix: Defines in all files are wrongly cleared when reparsing.
This commit is contained in:
Roy Qu 2023-08-09 22:35:25 +08:00
parent 9b16e490b2
commit 0f7b4b8ce5
16 changed files with 102 additions and 60 deletions

View File

@ -19,6 +19,8 @@ Red Panda C++ Version 2.24
- fix: Can't parse virtual inherit. - fix: Can't parse virtual inherit.
- fix: Filename in the gcc 13.1 error messages when building project is using wrong encoding. - fix: Filename in the gcc 13.1 error messages when building project is using wrong encoding.
- change: Git support is disabled in the distributed buildings. - change: Git support is disabled in the distributed buildings.
- fix: Wrong code suggestion while inputing numbers in assembly files.
- fix: Defines in all files are wrongly cleared when reparsing.
Red Panda C++ Version 2.23 Red Panda C++ Version 2.23

View File

@ -121,7 +121,7 @@ void CppRefacter::renameSymbol(Editor *editor, const QSynedit::BufferCoord &pos,
// get full phrase (such as s.name instead of name) // get full phrase (such as s.name instead of name)
QStringList expression; QStringList expression;
QChar s=editor->charAt(pos); QChar s=editor->charAt(pos);
if (!editor->isIdentChar(s)) { if (!editor->isIdentStartChar(s)) {
expression = editor->getExpressionAtPosition(QSynedit::BufferCoord{pos.ch-1,pos.line}); expression = editor->getExpressionAtPosition(QSynedit::BufferCoord{pos.ch-1,pos.line});
} else { } else {
expression = editor->getExpressionAtPosition(pos); expression = editor->getExpressionAtPosition(pos);

View File

@ -843,7 +843,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
QChar ch = t[0]; QChar ch = t[0];
QSynedit::BufferCoord ws=wordStart(); QSynedit::BufferCoord ws=wordStart();
int idCharPressed=caretX()-ws.ch; int idCharPressed=caretX()-ws.ch;
if (isIdentChar(ch)) { if (isIdentStartChar(ch)) {
idCharPressed++; idCharPressed++;
if (pSettings->codeCompletion().enabled() if (pSettings->codeCompletion().enabled()
&& pSettings->codeCompletion().showCompletionWhileInput() && pSettings->codeCompletion().showCompletionWhileInput()
@ -2255,7 +2255,7 @@ QStringList Editor::getExpressionAtPosition(
if (token==">") { if (token==">") {
lastSymbolType=LastSymbolType::MatchingAngleQuotation; lastSymbolType=LastSymbolType::MatchingAngleQuotation;
symbolMatchingLevel=0; symbolMatchingLevel=0;
} else if (isIdentChar(token.front())) { } else if (isIdentStartChar(token.front())) {
lastSymbolType=LastSymbolType::Identifier; lastSymbolType=LastSymbolType::Identifier;
} else } else
return result; return result;
@ -2270,7 +2270,7 @@ QStringList Editor::getExpressionAtPosition(
} else if (token == "]") { } else if (token == "]") {
lastSymbolType=LastSymbolType::MatchingBracket; lastSymbolType=LastSymbolType::MatchingBracket;
symbolMatchingLevel = 0; symbolMatchingLevel = 0;
} else if (isIdentChar(token.front())) { } else if (isIdentStartChar(token.front())) {
lastSymbolType=LastSymbolType::Identifier; lastSymbolType=LastSymbolType::Identifier;
} else } else
return result; return result;
@ -2307,7 +2307,7 @@ QStringList Editor::getExpressionAtPosition(
lastSymbolType=LastSymbolType::AsteriskSign; lastSymbolType=LastSymbolType::AsteriskSign;
} else if (token == "&") { } else if (token == "&") {
lastSymbolType=LastSymbolType::AmpersandSign; lastSymbolType=LastSymbolType::AmpersandSign;
} else if (isIdentChar(token.front())) { } else if (isIdentStartChar(token.front())) {
lastSymbolType=LastSymbolType::Identifier; lastSymbolType=LastSymbolType::Identifier;
} else } else
return result; return result;
@ -2319,13 +2319,13 @@ QStringList Editor::getExpressionAtPosition(
} else if (token == "]") { } else if (token == "]") {
lastSymbolType=LastSymbolType::MatchingBracket; lastSymbolType=LastSymbolType::MatchingBracket;
symbolMatchingLevel = 0; symbolMatchingLevel = 0;
} else if (isIdentChar(token.front())) { } else if (isIdentStartChar(token.front())) {
lastSymbolType=LastSymbolType::Identifier; lastSymbolType=LastSymbolType::Identifier;
} else } else
return result; return result;
break; break;
case LastSymbolType::AngleQuotationMatched: //before '<>' case LastSymbolType::AngleQuotationMatched: //before '<>'
if (isIdentChar(token.front())) { if (isIdentStartChar(token.front())) {
lastSymbolType=LastSymbolType::Identifier; lastSymbolType=LastSymbolType::Identifier;
} else } else
return result; return result;
@ -2347,7 +2347,7 @@ QStringList Editor::getExpressionAtPosition(
} else if (token == "]") { } else if (token == "]") {
lastSymbolType=LastSymbolType::MatchingBracket; lastSymbolType=LastSymbolType::MatchingBracket;
symbolMatchingLevel = 0; symbolMatchingLevel = 0;
} else if (isIdentChar(token.front())) { } else if (isIdentStartChar(token.front())) {
lastSymbolType=LastSymbolType::Identifier; lastSymbolType=LastSymbolType::Identifier;
} else } else
return result; return result;

View File

@ -4309,7 +4309,7 @@ void CppParser::internalParse(const QString &fileName)
QStringList preprocessResult = mPreprocessor.result(); QStringList preprocessResult = mPreprocessor.result();
#ifdef QT_DEBUG #ifdef QT_DEBUG
// stringsToFile(mPreprocessor.result(),QString("r:\\preprocess-%1.txt").arg(extractFileName(fileName))); stringsToFile(mPreprocessor.result(),QString("r:\\preprocess-%1.txt").arg(extractFileName(fileName)));
// mPreprocessor.dumpDefinesTo("r:\\defines.txt"); // mPreprocessor.dumpDefinesTo("r:\\defines.txt");
// mPreprocessor.dumpIncludesListTo("r:\\includes.txt"); // mPreprocessor.dumpIncludesListTo("r:\\includes.txt");
#endif #endif
@ -4341,8 +4341,8 @@ void CppParser::internalParse(const QString &fileName)
} }
// qDebug()<<"parse"<<timer.elapsed(); // qDebug()<<"parse"<<timer.elapsed();
#ifdef QT_DEBUG #ifdef QT_DEBUG
// mStatementList.dumpAll(QString("r:\\all-stats-%1.txt").arg(extractFileName(fileName))); mStatementList.dumpAll(QString("r:\\all-stats-%1.txt").arg(extractFileName(fileName)));
// mStatementList.dump(QString("r:\\stats-%1.txt").arg(extractFileName(fileName))); mStatementList.dump(QString("r:\\stats-%1.txt").arg(extractFileName(fileName)));
#endif #endif
//reduce memory usage //reduce memory usage
internalClear(); internalClear();

View File

@ -39,7 +39,8 @@ void CppPreprocessor::clear()
//option data for the parser //option data for the parser
//{ List of current project's include path } //{ List of current project's include path }
mHardDefines.clear(); // set by "cpp -dM -E -xc NUL" mDefines.clear();
//mHardDefines.clear(); // set by "cpp -dM -E -xc NUL"
mProjectIncludePaths.clear(); mProjectIncludePaths.clear();
//we also need include paths in order (for #include_next) //we also need include paths in order (for #include_next)
mIncludePathList.clear(); mIncludePathList.clear();
@ -57,7 +58,7 @@ void CppPreprocessor::clearTempResults()
mCurrentIncludes=nullptr; mCurrentIncludes=nullptr;
mIncludes.clear(); // stack of files we've stepped into. last one is current file, first one is source file mIncludes.clear(); // stack of files we've stepped into. last one is current file, first one is source file
mBranchResults.clear();// stack of branch results (boolean). last one is current branch, first one is outermost branch mBranchResults.clear();// stack of branch results (boolean). last one is current branch, first one is outermost branch
mDefines.clear(); // working set, editable //mDefines.clear(); // working set, editable
mProcessed.clear(); // dictionary to save filename already processed mProcessed.clear(); // dictionary to save filename already processed
} }
@ -74,9 +75,10 @@ void CppPreprocessor::addDefineByParts(const QString &name, const QString &args,
define->hardCoded = hardCoded; define->hardCoded = hardCoded;
if (!args.isEmpty()) if (!args.isEmpty())
parseArgs(define); parseArgs(define);
if (hardCoded) if (hardCoded) {
mHardDefines.insert(name,define); mHardDefines.insert(name,define);
else { mDefines.insert(name,define);
} else {
PDefineMap defineMap = mFileDefines.value(mFileName,PDefineMap()); PDefineMap defineMap = mFileDefines.value(mFileName,PDefineMap());
if (!defineMap) { if (!defineMap) {
defineMap = std::make_shared<DefineMap>(); defineMap = std::make_shared<DefineMap>();
@ -159,7 +161,7 @@ void CppPreprocessor::preprocess(const QString &fileName)
{ {
clearTempResults(); clearTempResults();
mFileName = fileName; mFileName = fileName;
mDefines = mHardDefines; //mDefines = mHardDefines;
openInclude(fileName); openInclude(fileName);
// StringsToFile(mBuffer,"f:\\buffer.txt"); // StringsToFile(mBuffer,"f:\\buffer.txt");
preprocessBuffer(); preprocessBuffer();
@ -237,37 +239,37 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const
#else #else
<<endl; <<endl;
#endif #endif
stream<<"\t**using:**" // stream<<"\t**using:**"
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0) // #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl; // <<Qt::endl;
#else // #else
<<endl; // <<endl;
#endif // #endif
foreach (const QString& s,fileIncludes->usings) { // foreach (const QString& s,fileIncludes->usings) {
stream<<"\t++"+s // stream<<"\t++"+s
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0) // #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl; // <<Qt::endl;
#else // #else
<<endl; // <<endl;
#endif // #endif
} // }
stream<<"\t**statements:**" // stream<<"\t**statements:**"
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0) // #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl; // <<Qt::endl;
#else // #else
<<endl; // <<endl;
#endif // #endif
foreach (const PStatement& statement,fileIncludes->statements) { // foreach (const PStatement& statement,fileIncludes->statements) {
if (statement) { // if (statement) {
stream<<QString("\t**%1 , %2") // stream<<QString("\t**%1 , %2")
.arg(statement->command,statement->fullName) // .arg(statement->command,statement->fullName)
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0) // #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl; // <<Qt::endl;
#else // #else
<<endl; // <<endl;
#endif // #endif
} // }
} // }
} }
} }
} }
@ -302,6 +304,7 @@ void CppPreprocessor::clearProjectIncludePaths()
void CppPreprocessor::removeScannedFile(const QString &filename) void CppPreprocessor::removeScannedFile(const QString &filename)
{ {
invalidDefinesInFile(filename);
mScannedFiles.remove(filename); mScannedFiles.remove(filename);
mIncludesList.remove(filename); mIncludesList.remove(filename);
mFileDefines.remove(filename); mFileDefines.remove(filename);

View File

@ -5959,6 +5959,24 @@ bool QSynEdit::isIdentChar(const QChar &ch)
} }
} }
bool QSynEdit::isIdentStartChar(const QChar &ch)
{
if (mSyntaxer) {
return mSyntaxer->isIdentStartChar(ch);
} else {
if (ch == '_') {
return true;
}
if ((ch>='a') && (ch <= 'z')) {
return true;
}
if ((ch>='A') && (ch <= 'Z')) {
return true;
}
return false;
}
}
void QSynEdit::setRainbowAttrs(const PTokenAttribute &attr0, const PTokenAttribute &attr1, const PTokenAttribute &attr2, const PTokenAttribute &attr3) void QSynEdit::setRainbowAttrs(const PTokenAttribute &attr0, const PTokenAttribute &attr1, const PTokenAttribute &attr2, const PTokenAttribute &attr3)
{ {
mRainbowAttr0 = attr0; mRainbowAttr0 = attr0;

View File

@ -298,6 +298,7 @@ public:
bool pointToCharLine(const QPoint& point, BufferCoord& coord); bool pointToCharLine(const QPoint& point, BufferCoord& coord);
bool pointToLine(const QPoint& point, int& line); bool pointToLine(const QPoint& point, int& line);
bool isIdentChar(const QChar& ch); bool isIdentChar(const QChar& ch);
bool isIdentStartChar(const QChar& ch);
void setRainbowAttrs(const PTokenAttribute &attr0, void setRainbowAttrs(const PTokenAttribute &attr0,
const PTokenAttribute &attr1, const PTokenAttribute &attr1,

View File

@ -1670,14 +1670,14 @@ void ASMSyntaxer::next()
CommentProc(); CommentProc();
break; break;
case '.': case '.':
if (isIdentChar(mLine[mRun+1])) { if (isIdentStartChar(mLine[mRun+1])) {
mRun++; mRun++;
IdentProc(IdentPrefix::Period); IdentProc(IdentPrefix::Period);
} else } else
SymbolProc(); SymbolProc();
break; break;
case '%': case '%':
if (isIdentChar(mLine[mRun+1])) { if (isIdentStartChar(mLine[mRun+1])) {
mRun++; mRun++;
IdentProc(IdentPrefix::Percent); IdentProc(IdentPrefix::Percent);
} else } else
@ -1699,7 +1699,7 @@ void ASMSyntaxer::next()
default: default:
if (mLine[mRun]>='0' && mLine[mRun]<='9') { if (mLine[mRun]>='0' && mLine[mRun]<='9') {
NumberProc(); NumberProc();
} else if (isIdentChar(mLine[mRun])) { } else if (isIdentStartChar(mLine[mRun])) {
IdentProc(IdentPrefix::None); IdentProc(IdentPrefix::None);
} else if (mLine[mRun]<=32) { } else if (mLine[mRun]<=32) {
SpaceProc(); SpaceProc();

View File

@ -1386,7 +1386,7 @@ void CppSyntaxer::processChar()
procXor(); procXor();
break; break;
default: default:
if (isIdentChar(mLine[mRun])) { if (isIdentStartChar(mLine[mRun])) {
procIdentifier(); procIdentifier();
} else { } else {
procUnknown(); procUnknown();
@ -1686,6 +1686,11 @@ bool CppSyntaxer::isIdentChar(const QChar &ch) const
return ch=='_' || ch.isDigit() || ch.isLetter(); return ch=='_' || ch.isDigit() || ch.isLetter();
} }
bool CppSyntaxer::isIdentStartChar(const QChar &ch) const
{
return ch=='_' || ch.isLetter();
}
QSet<QString> CppSyntaxer::keywords() QSet<QString> CppSyntaxer::keywords()
{ {
QSet<QString> set=Keywords; QSet<QString> set=Keywords;

View File

@ -198,6 +198,7 @@ public:
// SynHighlighter interface // SynHighlighter interface
public: public:
bool isIdentChar(const QChar &ch) const override; bool isIdentChar(const QChar &ch) const override;
bool isIdentStartChar(const QChar &ch) const override;
// SynHighlighter interface // SynHighlighter interface
public: public:

View File

@ -1424,11 +1424,6 @@ SyntaxState GLSLSyntaxer::getState() const
return mRange; return mRange;
} }
bool GLSLSyntaxer::isIdentChar(const QChar &ch) const
{
return ch=='_' || (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (ch>='0' && ch<='9');
}
QSet<QString> GLSLSyntaxer::keywords() QSet<QString> GLSLSyntaxer::keywords()
{ {
return Keywords; return Keywords;

View File

@ -181,10 +181,6 @@ public:
public: public:
SyntaxState getState() const override; SyntaxState getState() const override;
// SynHighlighter interface
public:
bool isIdentChar(const QChar &ch) const override;
// SynHighlighter interface // SynHighlighter interface
public: public:
QSet<QString> keywords() override; QSet<QString> keywords() override;

View File

@ -1186,6 +1186,11 @@ bool LuaSyntaxer::isIdentChar(const QChar &ch) const
return ch=='_' || ch.isDigit() || ch.isLetter(); return ch=='_' || ch.isDigit() || ch.isLetter();
} }
bool LuaSyntaxer::isIdentStartChar(const QChar &ch) const
{
return ch=='_' || ch.isLetter();
}
QSet<QString> LuaSyntaxer::keywords() { QSet<QString> LuaSyntaxer::keywords() {
if (mKeywordsCache.isEmpty()) { if (mKeywordsCache.isEmpty()) {
mKeywordsCache = Keywords; mKeywordsCache = Keywords;

View File

@ -163,6 +163,7 @@ public:
// SynHighlighter interface // SynHighlighter interface
public: public:
bool isIdentChar(const QChar &ch) const override; bool isIdentChar(const QChar &ch) const override;
bool isIdentStartChar(const QChar& ch) const override;
// SynHighlighter interface // SynHighlighter interface
public: public:

View File

@ -169,6 +169,20 @@ bool Syntaxer::isIdentChar(const QChar &ch) const
return false; return false;
} }
bool Syntaxer::isIdentStartChar(const QChar &ch) const
{
if (ch == '_') {
return true;
}
if ((ch>='a') && (ch <= 'z')) {
return true;
}
if ((ch>='A') && (ch <= 'Z')) {
return true;
}
return false;
}
void Syntaxer::addAttribute(PTokenAttribute attribute) void Syntaxer::addAttribute(PTokenAttribute attribute)
{ {
mAttributes[attribute->name()]=attribute; mAttributes[attribute->name()]=attribute;

View File

@ -143,6 +143,7 @@ public:
const PTokenAttribute& symbolAttribute() const; const PTokenAttribute& symbolAttribute() const;
virtual bool isIdentChar(const QChar& ch) const; virtual bool isIdentChar(const QChar& ch) const;
virtual bool isIdentStartChar(const QChar& ch) const;
virtual bool getTokenFinished() const = 0; virtual bool getTokenFinished() const = 0;
virtual bool isLastLineCommentNotFinished(int state) const = 0; virtual bool isLastLineCommentNotFinished(int state) const = 0;