From 85f3a04bcfa07bfea772470c27d9142a0ad9ab1e Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 1 Jun 2022 17:02:03 +0800 Subject: [PATCH] - 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 --- NEWS.md | 5 +++- RedPandaIDE/editor.cpp | 3 ++- RedPandaIDE/parser/cppparser.cpp | 34 +++++++++++++++++------- RedPandaIDE/parser/parserutils.cpp | 33 +++++++++++++++++++++++ RedPandaIDE/parser/parserutils.h | 1 + windows/templates/raylib_3d_c.txt | 1 + windows/templates/raylib_3d_shader_c.txt | 1 + windows/templates/raylib_c.txt | 1 + 8 files changed, 68 insertions(+), 11 deletions(-) diff --git a/NEWS.md b/NEWS.md index ff69fdf8..554e0ed4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,10 @@ Red Panda C++ Version 1.0.10 - fix: modify watch doesn't work - 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 - fix: selection in column mode not correctly drawn when has wide chars in it diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 532a2de2..a818eaae 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -3073,7 +3073,8 @@ void Editor::completionInsert(bool appendFunc) if (newStatement) statement = newStatement; } - if (statement->kind == StatementKind::skFunction + if ( (statement->kind == StatementKind::skFunction + && !IOManipulators.contains(statement->fullName)) || statement->kind == StatementKind::skConstructor || statement->kind == StatementKind::skDestructor || diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 5be22e52..36516c22 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -467,6 +467,16 @@ PStatement CppParser::findStatementOf(const QString &fileName, const QStringList if (!ownerEvalStatement) { 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); } @@ -2520,13 +2530,16 @@ void CppParser::handleOtherTypedefs() 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 // 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(':'); if (delimPos>=0) { - mCurrentFile = s.mid(0,delimPos); + mCurrentFile = s.mid(0,delimPos).trimmed(); mIsSystemHeader = isSystemHeaderFile(mCurrentFile) || isProjectHeaderFile(mCurrentFile); mIsProjectFile = mProjectFiles.contains(mCurrentFile); mIsHeader = isHFile(mCurrentFile); @@ -2539,11 +2552,13 @@ void CppParser::handlePreprocessor() 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 - 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 QString name,args,value; mPreprocessor.getDefineParts(s,name,args,value); @@ -2562,6 +2577,7 @@ void CppParser::handlePreprocessor() true, false); } // TODO: undef ( define has limited scope) +handlePreprocessorEnd: mIndex++; } @@ -3231,8 +3247,8 @@ void CppParser::internalParse(const QString &fileName) mPreprocessor.clearResult(); #ifdef QT_DEBUG // stringsToFile(mPreprocessor.result(),"r:\\preprocess.txt"); -// mPreprocessor.dumpDefinesTo("z:\\defines.txt"); -// mPreprocessor.dumpIncludesListTo("z:\\includes.txt"); +// mPreprocessor.dumpDefinesTo("r:\\defines.txt"); +// mPreprocessor.dumpIncludesListTo("r:\\includes.txt"); #endif // Tokenize the preprocessed buffer file @@ -3251,7 +3267,7 @@ void CppParser::internalParse(const QString &fileName) //reduce memory usage internalClear(); #ifdef QT_DEBUG -// mTokenizer.dumpTokens("z:\\tokens.txt"); +// mTokenizer.dumpTokens("r:\\tokens.txt"); // // mStatementList.dumpAll("r:\\all-stats.txt"); #endif diff --git a/RedPandaIDE/parser/parserutils.cpp b/RedPandaIDE/parser/parserutils.cpp index 8956f930..dfcdbc0d 100644 --- a/RedPandaIDE/parser/parserutils.cpp +++ b/RedPandaIDE/parser/parserutils.cpp @@ -33,6 +33,7 @@ QSet STLPointers; QSet STLContainers; QSet STLElementMethods; QSet MemberOperators; +QSet IOManipulators; Q_GLOBAL_STATIC(QSet,CppHeaderExts) Q_GLOBAL_STATIC(QSet,CppSourceExts) @@ -322,6 +323,38 @@ void initParser() 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, diff --git a/RedPandaIDE/parser/parserutils.h b/RedPandaIDE/parser/parserutils.h index d95883f2..a566a925 100644 --- a/RedPandaIDE/parser/parserutils.h +++ b/RedPandaIDE/parser/parserutils.h @@ -243,6 +243,7 @@ extern QSet STLPointers; extern QSet STLContainers; extern QSet STLElementMethods; extern QSet MemberOperators; +extern QSet IOManipulators; void initParser(); diff --git a/windows/templates/raylib_3d_c.txt b/windows/templates/raylib_3d_c.txt index 6cba4009..27d12023 100644 --- a/windows/templates/raylib_3d_c.txt +++ b/windows/templates/raylib_3d_c.txt @@ -36,6 +36,7 @@ int main() const int numBlocks = 15; SetTargetFPS(60); + SetTraceLogLevel(LOG_WARNING); //-------------------------------------------------------------------------------------- // Main game loop diff --git a/windows/templates/raylib_3d_shader_c.txt b/windows/templates/raylib_3d_shader_c.txt index 50a0250a..9292ddcf 100644 --- a/windows/templates/raylib_3d_shader_c.txt +++ b/windows/templates/raylib_3d_shader_c.txt @@ -30,6 +30,7 @@ int main(void) SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second + SetTraceLogLevel(LOG_WARNING); //-------------------------------------------------------------------------------------- // Main game loop diff --git a/windows/templates/raylib_c.txt b/windows/templates/raylib_c.txt index 4d58dec3..1da79751 100644 --- a/windows/templates/raylib_c.txt +++ b/windows/templates/raylib_c.txt @@ -45,6 +45,7 @@ int main(void) int framesCounter = 0; SetTargetFPS(120); + SetTraceLogLevel(LOG_WARNING); //-------------------------------------------------------------------------------------- // Main game loop