- fix: #define followed by tab not correctly parsed

- enhancement: don't auto add () when completing C++ io manipulators ( std::endl, std::fixed, etc.)
  - fix: can't goto to definition of std::endl
This commit is contained in:
Roy Qu 2022-06-01 17:02:03 +08:00
parent 836acff739
commit 85f3a04bcf
8 changed files with 68 additions and 11 deletions

View File

@ -1,7 +1,10 @@
Red Panda C++ Version 1.0.10 Red Panda C++ Version 1.0.10
- fix: modify watch doesn't work - fix: modify watch doesn't work
- fix: make behavior consistent in adding compiler bindirs to Path (thanks for brokencuph@github) - fix: make behavior consistent in adding compiler bindirs to Path (thanks for brokencuph@github)
- enhancement: basic MacOS support ( thanks for RigoLigo@github) - enhancement: basic MacOS support ( thanks for RigoLigoRLC@github)
- fix: #define followed by tab not correctly parsed
- enhancement: don't auto add () when completing C++ io manipulators ( std::endl, std::fixed, etc.)
- fix: can't goto to definition of std::endl
Red Panda C++ Version 1.0.9 Red Panda C++ Version 1.0.9
- fix: selection in column mode not correctly drawn when has wide chars in it - fix: selection in column mode not correctly drawn when has wide chars in it

View File

@ -3073,7 +3073,8 @@ void Editor::completionInsert(bool appendFunc)
if (newStatement) if (newStatement)
statement = newStatement; statement = newStatement;
} }
if (statement->kind == StatementKind::skFunction if ( (statement->kind == StatementKind::skFunction
&& !IOManipulators.contains(statement->fullName))
|| statement->kind == StatementKind::skConstructor || statement->kind == StatementKind::skConstructor
|| statement->kind == StatementKind::skDestructor || statement->kind == StatementKind::skDestructor
|| ||

View File

@ -467,6 +467,16 @@ PStatement CppParser::findStatementOf(const QString &fileName, const QStringList
if (!ownerEvalStatement) { if (!ownerEvalStatement) {
return PStatement(); return PStatement();
} }
if (ownerEvalStatement->effectiveTypeStatement &&
ownerEvalStatement->effectiveTypeStatement->kind == StatementKind::skNamespace) {
PStatementList lst = findNamespace(ownerEvalStatement->effectiveTypeStatement->fullName);
foreach (const PStatement& namespaceStatement, *lst) {
PStatement statement = findMemberOfStatement(phrase,namespaceStatement);
if (statement)
return statement;
}
return PStatement();
}
return findMemberOfStatement(phrase, ownerEvalStatement->effectiveTypeStatement); return findMemberOfStatement(phrase, ownerEvalStatement->effectiveTypeStatement);
} }
@ -2520,13 +2530,16 @@ void CppParser::handleOtherTypedefs()
void CppParser::handlePreprocessor() void CppParser::handlePreprocessor()
{ {
if (mTokenizer[mIndex]->text.startsWith("#include ")) { // start of new file QString text = mTokenizer[mIndex]->text.mid(1).trimmed();
if (text.startsWith("include")) { // start of new file
// format: #include fullfilename:line // format: #include fullfilename:line
// Strip keyword // Strip keyword
QString s = mTokenizer[mIndex]->text.mid(QString("#include ").length()); QString s = text.mid(QString("include").length());
if (!s.startsWith(" ") && !s.startsWith("\t"))
goto handlePreprocessorEnd;
int delimPos = s.lastIndexOf(':'); int delimPos = s.lastIndexOf(':');
if (delimPos>=0) { if (delimPos>=0) {
mCurrentFile = s.mid(0,delimPos); mCurrentFile = s.mid(0,delimPos).trimmed();
mIsSystemHeader = isSystemHeaderFile(mCurrentFile) || isProjectHeaderFile(mCurrentFile); mIsSystemHeader = isSystemHeaderFile(mCurrentFile) || isProjectHeaderFile(mCurrentFile);
mIsProjectFile = mProjectFiles.contains(mCurrentFile); mIsHeader = isHFile(mCurrentFile); mIsProjectFile = mProjectFiles.contains(mCurrentFile); mIsHeader = isHFile(mCurrentFile);
@ -2539,11 +2552,13 @@ void CppParser::handlePreprocessor()
emit onProgress(mCurrentFile,mFilesToScanCount,mFilesScannedCount); emit onProgress(mCurrentFile,mFilesToScanCount,mFilesScannedCount);
} }
} }
} else if (mTokenizer[mIndex]->text.startsWith("#define ")) { } else if (text.startsWith("define") || text.startsWith("define")) {
// format: #define A B, remove define keyword // format: #define A B, remove define keyword
QString s = mTokenizer[mIndex]->text.mid(QString("#define ").length()); QString s = text.mid(QString("define").length());
if (!s.startsWith(" ") && !s.startsWith("\t"))
goto handlePreprocessorEnd;
s = s.trimmed();
// Ask the preprocessor to cut parts up // Ask the preprocessor to cut parts up
QString name,args,value; QString name,args,value;
mPreprocessor.getDefineParts(s,name,args,value); mPreprocessor.getDefineParts(s,name,args,value);
@ -2562,6 +2577,7 @@ void CppParser::handlePreprocessor()
true, true,
false); false);
} // TODO: undef ( define has limited scope) } // TODO: undef ( define has limited scope)
handlePreprocessorEnd:
mIndex++; mIndex++;
} }
@ -3231,8 +3247,8 @@ void CppParser::internalParse(const QString &fileName)
mPreprocessor.clearResult(); mPreprocessor.clearResult();
#ifdef QT_DEBUG #ifdef QT_DEBUG
// stringsToFile(mPreprocessor.result(),"r:\\preprocess.txt"); // stringsToFile(mPreprocessor.result(),"r:\\preprocess.txt");
// mPreprocessor.dumpDefinesTo("z:\\defines.txt"); // mPreprocessor.dumpDefinesTo("r:\\defines.txt");
// mPreprocessor.dumpIncludesListTo("z:\\includes.txt"); // mPreprocessor.dumpIncludesListTo("r:\\includes.txt");
#endif #endif
// Tokenize the preprocessed buffer file // Tokenize the preprocessed buffer file
@ -3251,7 +3267,7 @@ void CppParser::internalParse(const QString &fileName)
//reduce memory usage //reduce memory usage
internalClear(); internalClear();
#ifdef QT_DEBUG #ifdef QT_DEBUG
// mTokenizer.dumpTokens("z:\\tokens.txt"); // mTokenizer.dumpTokens("r:\\tokens.txt");
// //
// mStatementList.dumpAll("r:\\all-stats.txt"); // mStatementList.dumpAll("r:\\all-stats.txt");
#endif #endif

View File

@ -33,6 +33,7 @@ QSet<QString> STLPointers;
QSet<QString> STLContainers; QSet<QString> STLContainers;
QSet<QString> STLElementMethods; QSet<QString> STLElementMethods;
QSet<QString> MemberOperators; QSet<QString> MemberOperators;
QSet<QString> IOManipulators;
Q_GLOBAL_STATIC(QSet<QString>,CppHeaderExts) Q_GLOBAL_STATIC(QSet<QString>,CppHeaderExts)
Q_GLOBAL_STATIC(QSet<QString>,CppSourceExts) Q_GLOBAL_STATIC(QSet<QString>,CppSourceExts)
@ -322,6 +323,38 @@ void initParser()
MemberOperators.insert("->"); MemberOperators.insert("->");
MemberOperators.insert("->*"); MemberOperators.insert("->*");
MemberOperators.insert(".*"); MemberOperators.insert(".*");
IOManipulators.insert("std::boolalpha");
IOManipulators.insert("std::noboolalpha");
IOManipulators.insert("std::showbase");
IOManipulators.insert("std::noshowbase");
IOManipulators.insert("std::showpoint");
IOManipulators.insert("std::noshowpoint");
IOManipulators.insert("std::showpos");
IOManipulators.insert("std::noshowpos");
IOManipulators.insert("std::skipws");
IOManipulators.insert("std::noskipws");
IOManipulators.insert("std::uppercase");
IOManipulators.insert("std::nouppercase");
IOManipulators.insert("std::unitbuf");
IOManipulators.insert("std::nounitbuf");
IOManipulators.insert("std::left");
IOManipulators.insert("std::right");
IOManipulators.insert("std::internal");
IOManipulators.insert("std::dec");
IOManipulators.insert("std::hex");
IOManipulators.insert("std::oct");
IOManipulators.insert("std::fixed");
IOManipulators.insert("std::scientific");
IOManipulators.insert("std::hexfloat");
IOManipulators.insert("std::defaultfloat");
IOManipulators.insert("std::ws");
IOManipulators.insert("std::ends");
IOManipulators.insert("std::flush");
IOManipulators.insert("std::endl");
} }
QString getHeaderFilename(const QString &relativeTo, const QString &line, QString getHeaderFilename(const QString &relativeTo, const QString &line,

View File

@ -243,6 +243,7 @@ extern QSet<QString> STLPointers;
extern QSet<QString> STLContainers; extern QSet<QString> STLContainers;
extern QSet<QString> STLElementMethods; extern QSet<QString> STLElementMethods;
extern QSet<QString> MemberOperators; extern QSet<QString> MemberOperators;
extern QSet<QString> IOManipulators;
void initParser(); void initParser();

View File

@ -36,6 +36,7 @@ int main()
const int numBlocks = 15; const int numBlocks = 15;
SetTargetFPS(60); SetTargetFPS(60);
SetTraceLogLevel(LOG_WARNING);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop

View File

@ -30,6 +30,7 @@ int main(void)
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
SetTraceLogLevel(LOG_WARNING);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop

View File

@ -45,6 +45,7 @@ int main(void)
int framesCounter = 0; int framesCounter = 0;
SetTargetFPS(120); SetTargetFPS(120);
SetTraceLogLevel(LOG_WARNING);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop