- 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: Filename in the gcc 13.1 error messages when building project is using wrong encoding.
- 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

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)
QStringList expression;
QChar s=editor->charAt(pos);
if (!editor->isIdentChar(s)) {
if (!editor->isIdentStartChar(s)) {
expression = editor->getExpressionAtPosition(QSynedit::BufferCoord{pos.ch-1,pos.line});
} else {
expression = editor->getExpressionAtPosition(pos);

View File

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

View File

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

View File

@ -39,7 +39,8 @@ void CppPreprocessor::clear()
//option data for the parser
//{ 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();
//we also need include paths in order (for #include_next)
mIncludePathList.clear();
@ -57,7 +58,7 @@ void CppPreprocessor::clearTempResults()
mCurrentIncludes=nullptr;
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
mDefines.clear(); // working set, editable
//mDefines.clear(); // working set, editable
mProcessed.clear(); // dictionary to save filename already processed
}
@ -74,9 +75,10 @@ void CppPreprocessor::addDefineByParts(const QString &name, const QString &args,
define->hardCoded = hardCoded;
if (!args.isEmpty())
parseArgs(define);
if (hardCoded)
if (hardCoded) {
mHardDefines.insert(name,define);
else {
mDefines.insert(name,define);
} else {
PDefineMap defineMap = mFileDefines.value(mFileName,PDefineMap());
if (!defineMap) {
defineMap = std::make_shared<DefineMap>();
@ -159,7 +161,7 @@ void CppPreprocessor::preprocess(const QString &fileName)
{
clearTempResults();
mFileName = fileName;
mDefines = mHardDefines;
//mDefines = mHardDefines;
openInclude(fileName);
// StringsToFile(mBuffer,"f:\\buffer.txt");
preprocessBuffer();
@ -237,37 +239,37 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const
#else
<<endl;
#endif
stream<<"\t**using:**"
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl;
#else
<<endl;
#endif
foreach (const QString& s,fileIncludes->usings) {
stream<<"\t++"+s
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl;
#else
<<endl;
#endif
}
stream<<"\t**statements:**"
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl;
#else
<<endl;
#endif
foreach (const PStatement& statement,fileIncludes->statements) {
if (statement) {
stream<<QString("\t**%1 , %2")
.arg(statement->command,statement->fullName)
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl;
#else
<<endl;
#endif
}
}
// stream<<"\t**using:**"
// #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
// <<Qt::endl;
// #else
// <<endl;
// #endif
// foreach (const QString& s,fileIncludes->usings) {
// stream<<"\t++"+s
// #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
// <<Qt::endl;
// #else
// <<endl;
// #endif
// }
// stream<<"\t**statements:**"
// #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
// <<Qt::endl;
// #else
// <<endl;
// #endif
// foreach (const PStatement& statement,fileIncludes->statements) {
// if (statement) {
// stream<<QString("\t**%1 , %2")
// .arg(statement->command,statement->fullName)
// #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
// <<Qt::endl;
// #else
// <<endl;
// #endif
// }
// }
}
}
}
@ -302,6 +304,7 @@ void CppPreprocessor::clearProjectIncludePaths()
void CppPreprocessor::removeScannedFile(const QString &filename)
{
invalidDefinesInFile(filename);
mScannedFiles.remove(filename);
mIncludesList.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)
{
mRainbowAttr0 = attr0;

View File

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

View File

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

View File

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

View File

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

View File

@ -1424,11 +1424,6 @@ SyntaxState GLSLSyntaxer::getState() const
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()
{
return Keywords;

View File

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

View File

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

View File

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

View File

@ -169,6 +169,20 @@ bool Syntaxer::isIdentChar(const QChar &ch) const
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)
{
mAttributes[attribute->name()]=attribute;

View File

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