From 9f3d50d6a273cb551ac686e595f71959e8d0b065 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Fri, 20 Aug 2021 01:06:10 +0800 Subject: [PATCH] work save --- RedPandaIDE/parser/cppparser.cpp | 61 ++++++++++++++++++++++++++++++++ RedPandaIDE/parser/cppparser.h | 16 +++++---- 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 4fb1bda8..4d7c5906 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -2,12 +2,53 @@ #include "parserutils.h" #include "../utils.h" +#include #include #include +#include +static QAtomicInt cppParserCount(0); CppParser::CppParser(QObject *parent) : QObject(parent) { + mParserId = cppParserCount.fetchAndAddRelaxed(1); + mSerialCount = 0; + updateSerialId(); + mUniqId = 0; + mParsing = false; + //mStatementList ; // owns the objects + mIncludesList = std::make_shared>(); + //mFilesToScan; + mScannedFiles = std::make_shared>(); + //mIncludePaths; + //mProjectIncludePaths; + //mProjectFiles; + // mCurrentScope; + //mCurrentClassScope; + //mSkipList; + mParseLocalHeaders = true; + mParseGlobalHeaders = true; + mLockCount = 0; + //mNamespaces; + //mBlockBeginSkips; + //mBlockEndSkips; + //mInlineNamespaceEndSkips; +} +CppParser::~CppParser() +{ + while (true) { + //wait for all methods finishes running + { + QMutexLocker locker(&mMutex); + if (!mParsing && (mLockCount == 0)) { + mParsing = true; + break; + } + } + QThread::msleep(50); + QCoreApplication* app = QApplication::instance(); + app->processEvents(); + } } void CppParser::addHardDefineByLine(const QString &line) @@ -22,14 +63,34 @@ void CppParser::addHardDefineByLine(const QString &line) void CppParser::addIncludePath(const QString &value) { + QMutexLocker locker(&mMutex); mIncludePaths.insert(value); } void CppParser::addProjectIncludePath(const QString &value) { + QMutexLocker locker(&mMutex); mProjectIncludePaths.insert(value); } +void CppParser::clearIncludePaths() +{ + QMutexLocker locker(&mMutex); + mIncludePaths.clear(); +} + +void CppParser::clearProjectIncludePaths() +{ + QMutexLocker locker(&mMutex); + mProjectIncludePaths.clear(); +} + +void CppParser::clearProjectFiles() +{ + QMutexLocker locker(&mMutex); + mProjectFiles.clear(); +} + void CppParser::addFileToScan(QString value, bool inProject) { QMutexLocker locker(&mMutex); diff --git a/RedPandaIDE/parser/cppparser.h b/RedPandaIDE/parser/cppparser.h index 476b4f02..8826c642 100644 --- a/RedPandaIDE/parser/cppparser.h +++ b/RedPandaIDE/parser/cppparser.h @@ -14,10 +14,17 @@ class CppParser : public QObject using GetFileStreamCallBack = std::function; public: explicit CppParser(QObject *parent = nullptr); + ~CppParser(); + void addHardDefineByLine(const QString& line); + void addFileToScan(QString value, bool inProject = false); + void addIncludePath(const QString& value); + void addProjectIncludePath(const QString& value); + void clearIncludePaths(); + void clearProjectIncludePaths(); + void clearProjectFiles(); void parseHardDefines(); PFileIncludes findFileIncludes(const QString &filename, bool deleteIt = false); - void addHardDefineByLine(const QString& line); void invalidateFile(const QString& fileName); QStringList getFileDirectIncludes(const QString& filename) const; const QList& getFileIncludes(const QString& filename) const; @@ -43,12 +50,7 @@ public: QString statementKindStr(StatementKind value); QString statementClassScopeStr(StatementClassScope value); void reset(); - void clearIncludePaths(); - void clearProjectIncludePaths(); - void clearProjectFiles(); - void addIncludePath(const QString& value); - void addProjectIncludePath(const QString& value); - void addFileToScan(QString value, bool inProject = false); + QString prettyPrintStatement(PStatement statement, int line = -1); void fillListOfFunctions(const QString& fileName, const QString& phrase,