C/C++ use differnet parser
This commit is contained in:
parent
833be397b0
commit
2ce732cfa5
2
NEWS.md
2
NEWS.md
|
@ -1,7 +1,7 @@
|
|||
Red Panda C++ Version 2.1
|
||||
|
||||
- fix: editors that not in the editing panel shouldn't trigger switch breakpoint
|
||||
- fix:editors that not in the editing panel shouldn't show context menu
|
||||
- fix: editors that not in the editing panel shouldn't show context menu
|
||||
- enhancement: add "editors share one code parser" in "options" / "editor" / "code completion", to reduce memory usage.
|
||||
Turned off by default on PCs with memory > 4G; Force turned on PCs with memory < 1G.
|
||||
- enhancement: add "goto block start"/"goto block end" in "Code" menu
|
||||
|
|
|
@ -69,7 +69,7 @@ const char* SaveException::what() const noexcept {
|
|||
return mReasonBuffer;
|
||||
}
|
||||
|
||||
std::weak_ptr<CppParser> Editor::mSharedParser;
|
||||
QHash<ParserLanguage,std::weak_ptr<CppParser>> Editor::mSharedParsers;
|
||||
|
||||
Editor::Editor(QWidget *parent):
|
||||
Editor(parent,QObject::tr("untitled"),ENCODING_AUTO_DETECT,nullptr,true,nullptr)
|
||||
|
@ -2584,7 +2584,7 @@ void Editor::initParser()
|
|||
if (pSettings->codeCompletion().enabled()
|
||||
&& (highlighter() && highlighter()->getClass() == QSynedit::HighlighterClass::CppHighlighter)
|
||||
) {
|
||||
mParser = sharedParser();
|
||||
mParser = sharedParser(mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -2743,7 +2743,13 @@ void Editor::reparse(bool resetParser)
|
|||
return;
|
||||
//mParser->setEnabled(pSettings->codeCompletion().enabled());
|
||||
ParserLanguage language = mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C;
|
||||
if (!inProject() && !pSettings->codeCompletion().shareParser()) {
|
||||
if (!inProject()) {
|
||||
if (pSettings->codeCompletion().shareParser()) {
|
||||
if (language!=mParser->language()) {
|
||||
mParser->invalidateFile(mFilename);
|
||||
mParser=sharedParser(language);
|
||||
}
|
||||
} else {
|
||||
if (language!=mParser->language()) {
|
||||
mParser->setLanguage(language);
|
||||
resetCppParser(mParser);
|
||||
|
@ -2751,6 +2757,7 @@ void Editor::reparse(bool resetParser)
|
|||
resetCppParser(mParser);
|
||||
}
|
||||
}
|
||||
}
|
||||
parseFile(mParser,mFilename, inProject());
|
||||
}
|
||||
|
||||
|
@ -3942,19 +3949,22 @@ void Editor::onScrollBarValueChanged()
|
|||
pMainWindow->functionTip()->hide();
|
||||
}
|
||||
|
||||
PCppParser Editor::sharedParser()
|
||||
PCppParser Editor::sharedParser(ParserLanguage language)
|
||||
{
|
||||
PCppParser parser=mSharedParser.lock();
|
||||
PCppParser parser;
|
||||
if (mSharedParsers.contains(language)) {
|
||||
std::weak_ptr<CppParser> weakParser=mSharedParsers[language].lock();
|
||||
}
|
||||
if (!parser) {
|
||||
parser=std::make_shared<CppParser>();
|
||||
parser->setLanguage(ParserLanguage::CPlusPlus);
|
||||
parser->setLanguage(language);
|
||||
parser->setOnGetFileStream(
|
||||
std::bind(
|
||||
&EditorList::getContentFromOpenedEditor,pMainWindow->editorList(),
|
||||
std::placeholders::_1, std::placeholders::_2));
|
||||
resetCppParser(parser);
|
||||
parser->setEnabled(true);
|
||||
mSharedParser=parser;
|
||||
mSharedParsers.insert(language,parser);
|
||||
}
|
||||
return parser;
|
||||
}
|
||||
|
|
|
@ -292,7 +292,7 @@ private:
|
|||
void onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int Line, int column, const QString& token,
|
||||
QSynedit::PHighlighterAttribute &attr);
|
||||
void onScrollBarValueChanged();
|
||||
static PCppParser sharedParser();
|
||||
static PCppParser sharedParser(ParserLanguage language);
|
||||
private:
|
||||
QByteArray mEncodingOption; // the encoding type set by the user
|
||||
QByteArray mFileEncoding; // the real encoding of the file (auto detected)
|
||||
|
@ -343,7 +343,7 @@ private:
|
|||
QTimer mFunctionTipTimer;
|
||||
int mHoverModifiedLine;
|
||||
|
||||
static std::weak_ptr<CppParser> mSharedParser;
|
||||
static QHash<ParserLanguage,std::weak_ptr<CppParser>> mSharedParsers;
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
|
|
|
@ -201,6 +201,11 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
|
|||
} else {
|
||||
pMainWindow->updateClassBrowserForEditor(nullptr);
|
||||
}
|
||||
} else {
|
||||
editor = getEditor();
|
||||
if (!editor) {
|
||||
pMainWindow->updateClassBrowserForEditor(nullptr);
|
||||
}
|
||||
}
|
||||
emit editorClosed();
|
||||
endUpdate();
|
||||
|
|
|
@ -1188,6 +1188,9 @@ PStatement CppParser::addStatement(const PStatement& parent,
|
|||
newType += newCommand.front();
|
||||
newCommand.remove(0,1); // remove first
|
||||
}
|
||||
// if (newCommand.startsWith("::") && parent && kind!=StatementKind::skBlock ) {
|
||||
// qDebug()<<command<<fileName<<line<<kind<<parent->fullName;
|
||||
// }
|
||||
|
||||
QString noNameArgs = "";
|
||||
if (kind == StatementKind::skConstructor
|
||||
|
@ -3334,13 +3337,14 @@ void CppParser::internalParse(const QString &fileName)
|
|||
if (!handleStatement())
|
||||
break;
|
||||
}
|
||||
//reduce memory usage
|
||||
internalClear();
|
||||
#ifdef QT_DEBUG
|
||||
// mTokenizer.dumpTokens("r:\\tokens.txt");
|
||||
// mTokenizer.dumpTokens(QString("r:\\tokens-%1.txt").arg(extractFileName(fileName)));
|
||||
//
|
||||
// mStatementList.dumpAll("r:\\all-stats.txt");
|
||||
#endif
|
||||
//reduce memory usage
|
||||
internalClear();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
using GetFileStreamCallBack = std::function<bool (const QString&, QStringList&)>;
|
||||
|
||||
enum class ParserLanguage {
|
||||
enum ParserLanguage {
|
||||
C,
|
||||
CPlusPlus
|
||||
};
|
||||
|
|
|
@ -3926,7 +3926,7 @@ void Settings::CodeCompletion::doLoad()
|
|||
statex.dwLength = sizeof (statex);
|
||||
|
||||
GlobalMemoryStatusEx (&statex);
|
||||
if (statex.ullAvailPhys > (long long int)4*1024*1024*1024) {
|
||||
if (statex.ullAvailPhys > (long long int)8*1024*1024*1024) {
|
||||
shouldShare = false;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -181,14 +181,9 @@ void CodeCompletionPopup::addChildren(PStatement scopeStatement, const QString &
|
|||
if (childStatement->fileName.isEmpty()) {
|
||||
// hard defines
|
||||
addStatement(childStatement,fileName,-1);
|
||||
} else if (!( childStatement->kind == StatementKind::skConstructor
|
||||
|| childStatement->kind == StatementKind::skDestructor
|
||||
|| childStatement->kind == StatementKind::skBlock)
|
||||
&& (!mAddedStatements.contains(childStatement->command))
|
||||
&& (
|
||||
} else if (
|
||||
isIncluded(childStatement->fileName)
|
||||
|| isIncluded(childStatement->definitionFileName)
|
||||
)
|
||||
) {
|
||||
//we must check if the statement is included by the file
|
||||
addStatement(childStatement,fileName,line);
|
||||
|
@ -196,10 +191,6 @@ void CodeCompletionPopup::addChildren(PStatement scopeStatement, const QString &
|
|||
}
|
||||
} else {
|
||||
for (const PStatement& childStatement: children) {
|
||||
if (!( childStatement->kind == StatementKind::skConstructor
|
||||
|| childStatement->kind == StatementKind::skDestructor
|
||||
|| childStatement->kind == StatementKind::skBlock)
|
||||
&& (!mAddedStatements.contains(childStatement->command)))
|
||||
addStatement(childStatement,fileName,line);
|
||||
}
|
||||
}
|
||||
|
@ -209,6 +200,10 @@ void CodeCompletionPopup::addStatement(PStatement statement, const QString &file
|
|||
{
|
||||
if (mAddedStatements.contains(statement->command))
|
||||
return;
|
||||
if (statement->kind == StatementKind::skConstructor
|
||||
|| statement->kind == StatementKind::skDestructor
|
||||
|| statement->kind == StatementKind::skBlock)
|
||||
return;
|
||||
if ((line!=-1)
|
||||
&& (line < statement->line)
|
||||
&& (fileName == statement->fileName))
|
||||
|
@ -409,9 +404,9 @@ void CodeCompletionPopup::filterList(const QString &member)
|
|||
int totalPos = 0;
|
||||
statement->matchPositions.clear();
|
||||
if (hideSymbolsTwoUnderline && statement->command.startsWith("__")) {
|
||||
|
||||
continue;
|
||||
} else if (hideSymbolsUnderline && statement->command.startsWith("_")) {
|
||||
|
||||
continue;
|
||||
} else {
|
||||
foreach (const QChar& ch, member) {
|
||||
if (mIgnoreCase)
|
||||
|
|
Loading…
Reference in New Issue