2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-08-14 22:52:37 +08:00
|
|
|
#ifndef CPPPARSER_H
|
|
|
|
#define CPPPARSER_H
|
|
|
|
|
2021-08-15 04:31:57 +08:00
|
|
|
#include <QMutex>
|
2021-08-14 22:52:37 +08:00
|
|
|
#include <QObject>
|
2021-08-23 10:16:06 +08:00
|
|
|
#include <QThread>
|
2022-01-04 16:50:54 +08:00
|
|
|
#include <QVector>
|
2021-08-14 22:52:37 +08:00
|
|
|
#include "statementmodel.h"
|
|
|
|
#include "cpptokenizer.h"
|
|
|
|
#include "cpppreprocessor.h"
|
|
|
|
|
|
|
|
class CppParser : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2021-08-15 04:31:57 +08:00
|
|
|
|
2021-08-14 22:52:37 +08:00
|
|
|
public:
|
2024-05-02 16:58:01 +08:00
|
|
|
|
|
|
|
struct ParseFileCommand {
|
|
|
|
QString fileName;
|
|
|
|
bool inProject;
|
|
|
|
bool onlyIfNotParsed;
|
|
|
|
bool updateView;
|
2024-05-03 08:48:58 +08:00
|
|
|
std::shared_ptr<CppParser> parserPtr;
|
2024-05-02 16:58:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
using PParseFileCommand = std::unique_ptr<ParseFileCommand>;
|
2021-08-14 22:52:37 +08:00
|
|
|
explicit CppParser(QObject *parent = nullptr);
|
2023-01-12 12:07:22 +08:00
|
|
|
CppParser(const CppParser&)=delete;
|
|
|
|
CppParser& operator=(const CppParser)=delete;
|
|
|
|
|
2021-08-20 01:06:10 +08:00
|
|
|
~CppParser();
|
2021-08-14 22:52:37 +08:00
|
|
|
|
2021-08-20 01:06:10 +08:00
|
|
|
void addHardDefineByLine(const QString& line);
|
2022-11-07 11:24:23 +08:00
|
|
|
void addProjectFile(const QString &fileName, bool needScan);
|
2021-08-20 01:06:10 +08:00
|
|
|
void addIncludePath(const QString& value);
|
2022-11-06 22:51:14 +08:00
|
|
|
void removeProjectFile(const QString& value);
|
2021-08-20 01:06:10 +08:00
|
|
|
void addProjectIncludePath(const QString& value);
|
|
|
|
void clearIncludePaths();
|
|
|
|
void clearProjectIncludePaths();
|
|
|
|
void clearProjectFiles();
|
2021-09-24 18:02:42 +08:00
|
|
|
QList<PStatement> getListOfFunctions(const QString& fileName,
|
2021-08-22 16:08:46 +08:00
|
|
|
const QString& phrase,
|
2024-05-28 19:01:18 +08:00
|
|
|
int line) const;
|
|
|
|
PStatement findScopeStatement(const QString& filename, int line) const;
|
|
|
|
PParsedFileInfo findFileInfo(const QString &filename) const;
|
2021-08-22 16:08:46 +08:00
|
|
|
QString findFirstTemplateParamOf(const QString& fileName,
|
|
|
|
const QString& phrase,
|
2024-05-28 19:01:18 +08:00
|
|
|
const PStatement& currentScope) const;
|
2023-06-08 17:15:55 +08:00
|
|
|
QString findTemplateParamOf(const QString& fileName,
|
|
|
|
const QString& phrase,
|
|
|
|
int index,
|
2024-05-28 19:01:18 +08:00
|
|
|
const PStatement& currentScope) const;
|
2021-08-22 16:08:46 +08:00
|
|
|
PStatement findFunctionAt(const QString& fileName,
|
2024-05-28 19:01:18 +08:00
|
|
|
int line) const;
|
2021-08-22 16:08:46 +08:00
|
|
|
int findLastOperator(const QString& phrase) const;
|
2024-05-28 19:01:18 +08:00
|
|
|
PStatementList findNamespace(const QString& name) const; // return a list of PSTATEMENTS (of the namespace)
|
|
|
|
PStatement findStatement(const QString& fullname) const;
|
2021-08-22 16:08:46 +08:00
|
|
|
PStatement findStatementOf(const QString& fileName,
|
|
|
|
const QString& phrase,
|
2024-05-28 19:01:18 +08:00
|
|
|
int line) const;
|
2021-08-22 16:08:46 +08:00
|
|
|
PStatement findStatementOf(const QString& fileName,
|
|
|
|
const QString& phrase,
|
2021-08-29 00:48:23 +08:00
|
|
|
const PStatement& currentScope,
|
2024-05-28 19:01:18 +08:00
|
|
|
PStatement& parentScopeType) const;
|
2021-12-18 23:36:58 +08:00
|
|
|
|
|
|
|
PStatement findStatementOf(const QString& fileName,
|
|
|
|
const QStringList& expression,
|
2024-05-28 19:01:18 +08:00
|
|
|
const PStatement& currentScope) const;
|
2021-12-19 10:16:46 +08:00
|
|
|
PStatement findStatementOf(const QString& fileName,
|
|
|
|
const QStringList& expression,
|
2024-05-28 19:01:18 +08:00
|
|
|
int line) const;
|
|
|
|
PStatement findAliasedStatement(const PStatement& statement) const;
|
2021-12-19 10:16:46 +08:00
|
|
|
|
2024-05-28 19:01:18 +08:00
|
|
|
QList<PStatement> listTypeStatements(const QString& fileName,int line) const;
|
2023-07-03 09:36:27 +08:00
|
|
|
|
2021-12-06 09:02:39 +08:00
|
|
|
/**
|
|
|
|
* @brief evaluate the expression
|
|
|
|
* @param fileName
|
|
|
|
* @param expression
|
|
|
|
* @param currentScope
|
|
|
|
* @return the statement of the evaluation result
|
|
|
|
*/
|
2021-12-06 11:37:37 +08:00
|
|
|
PEvalStatement evalExpression(const QString& fileName,
|
2022-12-11 19:47:43 +08:00
|
|
|
QStringList& expression,
|
2024-05-28 19:01:18 +08:00
|
|
|
const PStatement& currentScope) const;
|
2021-08-22 21:23:58 +08:00
|
|
|
PStatement findTypeDefinitionOf(const QString& fileName,
|
|
|
|
const QString& aType,
|
2024-05-28 19:01:18 +08:00
|
|
|
const PStatement& currentClass) const;
|
2022-01-26 12:17:15 +08:00
|
|
|
PStatement findTypeDef(const PStatement& statement,
|
2024-05-28 19:01:18 +08:00
|
|
|
const QString& fileName) const;
|
2021-08-22 21:23:58 +08:00
|
|
|
bool freeze(); // Freeze/Lock (stop reparse while searching)
|
|
|
|
bool freeze(const QString& serialId); // Freeze/Lock (stop reparse while searching)
|
2024-05-28 19:01:18 +08:00
|
|
|
QStringList getClassesList() const;
|
|
|
|
QStringList getFileDirectIncludes(const QString& filename) const;
|
|
|
|
QSet<QString> getIncludedFiles(const QString& filename) const;
|
|
|
|
QSet<QString> getFileUsings(const QString& filename) const;
|
2021-08-22 16:08:46 +08:00
|
|
|
|
2024-05-28 19:01:18 +08:00
|
|
|
QString getHeaderFileName(const QString& relativeTo, const QString& headerName, bool fromNext=false) const;
|
2022-01-27 20:31:44 +08:00
|
|
|
|
2021-08-15 16:49:37 +08:00
|
|
|
void invalidateFile(const QString& fileName);
|
2024-05-28 19:01:18 +08:00
|
|
|
bool isLineVisible(const QString& fileName, int line) const;
|
|
|
|
bool isIncludeLine(const QString &line) const;
|
|
|
|
bool isIncludeNextLine(const QString &line) const;
|
|
|
|
bool isProjectHeaderFile(const QString& fileName) const;
|
|
|
|
bool isSystemHeaderFile(const QString& fileName) const;
|
2021-08-22 21:23:58 +08:00
|
|
|
void parseFile(const QString& fileName, bool inProject,
|
2024-05-03 07:50:05 +08:00
|
|
|
bool onlyIfNotParsed = false, bool updateView = true,
|
2024-05-03 08:48:58 +08:00
|
|
|
std::shared_ptr<CppParser> parserPtr = nullptr);
|
2021-08-22 21:23:58 +08:00
|
|
|
void parseFileList(bool updateView = true);
|
|
|
|
void parseHardDefines();
|
2021-08-22 23:48:00 +08:00
|
|
|
bool parsing() const;
|
2022-10-18 12:24:59 +08:00
|
|
|
void resetParser();
|
2021-08-22 23:48:00 +08:00
|
|
|
void unFreeze(); // UnFree/UnLock (reparse while searching)
|
2024-05-28 19:01:18 +08:00
|
|
|
bool fileScanned(const QString& fileName) const;
|
2021-08-22 21:23:58 +08:00
|
|
|
|
2024-05-28 19:01:18 +08:00
|
|
|
bool isFileParsed(const QString& filename) const;
|
2022-08-24 17:05:16 +08:00
|
|
|
|
2024-05-28 19:01:18 +08:00
|
|
|
QString prettyPrintStatement(const PStatement& statement, const QString& filename, int line = -1) const;
|
2021-08-22 05:50:26 +08:00
|
|
|
|
2021-08-21 22:15:44 +08:00
|
|
|
bool enabled() const;
|
|
|
|
void setEnabled(bool newEnabled);
|
|
|
|
|
|
|
|
const QSet<QString> &filesToScan() const;
|
|
|
|
void setFilesToScan(const QSet<QString> &newFilesToScan);
|
|
|
|
|
2021-08-22 21:23:58 +08:00
|
|
|
void setOnGetFileStream(const GetFileStreamCallBack &newOnGetFileStream);
|
|
|
|
|
2021-08-22 23:48:00 +08:00
|
|
|
int parserId() const;
|
|
|
|
|
2021-08-23 03:47:28 +08:00
|
|
|
const QString &serialId() const;
|
|
|
|
|
2021-08-23 10:16:06 +08:00
|
|
|
bool parseLocalHeaders() const;
|
|
|
|
void setParseLocalHeaders(bool newParseLocalHeaders);
|
|
|
|
|
|
|
|
bool parseGlobalHeaders() const;
|
|
|
|
void setParseGlobalHeaders(bool newParseGlobalHeaders);
|
|
|
|
|
2021-08-29 00:48:23 +08:00
|
|
|
const QSet<QString>& includePaths();
|
|
|
|
const QSet<QString>& projectIncludePaths();
|
|
|
|
|
2021-08-24 15:05:10 +08:00
|
|
|
const StatementModel &statementList() const;
|
|
|
|
|
2022-07-28 13:51:38 +08:00
|
|
|
ParserLanguage language() const;
|
|
|
|
void setLanguage(ParserLanguage newLanguage);
|
|
|
|
|
2022-11-07 11:24:23 +08:00
|
|
|
const QSet<QString> &projectFiles() const;
|
|
|
|
|
2022-11-27 13:32:14 +08:00
|
|
|
QList<QString> namespaces();
|
|
|
|
|
2021-08-14 22:52:37 +08:00
|
|
|
signals:
|
2021-08-19 23:49:23 +08:00
|
|
|
void onProgress(const QString& fileName, int total, int current);
|
|
|
|
void onBusy();
|
|
|
|
void onStartParsing();
|
|
|
|
void onEndParsing(int total, int updateView);
|
2021-08-15 04:31:57 +08:00
|
|
|
private:
|
|
|
|
PStatement addInheritedStatement(
|
2021-08-29 00:48:23 +08:00
|
|
|
const PStatement& derived,
|
|
|
|
const PStatement& inherit,
|
2023-03-12 18:24:58 +08:00
|
|
|
StatementAccessibility access);
|
2021-08-15 04:31:57 +08:00
|
|
|
|
|
|
|
PStatement addChildStatement(
|
|
|
|
// support for multiple parents (only typedef struct/union use multiple parents)
|
2021-08-29 00:48:23 +08:00
|
|
|
const PStatement& parent,
|
2021-08-15 04:31:57 +08:00
|
|
|
const QString& fileName,
|
|
|
|
const QString& aType, // "Type" is already in use
|
|
|
|
const QString& command,
|
|
|
|
const QString& args,
|
2022-10-31 19:37:24 +08:00
|
|
|
const QString& noNameArgs,
|
2021-08-15 04:31:57 +08:00
|
|
|
const QString& value,
|
|
|
|
int line,
|
|
|
|
StatementKind kind,
|
2021-08-29 00:48:23 +08:00
|
|
|
const StatementScope& scope,
|
2023-03-12 18:24:58 +08:00
|
|
|
const StatementAccessibility& classScope,
|
2022-11-16 10:29:20 +08:00
|
|
|
StatementProperties properties); // TODO: InheritanceList not supported
|
2021-08-15 04:31:57 +08:00
|
|
|
PStatement addStatement(
|
2021-08-29 00:48:23 +08:00
|
|
|
const PStatement& parent,
|
2021-08-15 04:31:57 +08:00
|
|
|
const QString &fileName,
|
|
|
|
const QString &aType, // "Type" is already in use
|
|
|
|
const QString &command,
|
|
|
|
const QString &args,
|
2022-10-31 19:37:24 +08:00
|
|
|
const QString &noNameArgs,
|
|
|
|
const QString& value,
|
|
|
|
int line,
|
|
|
|
StatementKind kind,
|
|
|
|
const StatementScope& scope,
|
2023-03-12 18:24:58 +08:00
|
|
|
const StatementAccessibility& classScope,
|
2022-11-16 10:29:20 +08:00
|
|
|
StatementProperties properties);
|
2022-10-31 19:37:24 +08:00
|
|
|
PStatement addStatement(
|
|
|
|
const PStatement& parent,
|
|
|
|
const QString &fileName,
|
|
|
|
const QString &aType, // "Type" is already in use
|
|
|
|
const QString &command,
|
|
|
|
int argStart,
|
|
|
|
int argEnd,
|
2021-08-15 04:31:57 +08:00
|
|
|
const QString& value,
|
|
|
|
int line,
|
|
|
|
StatementKind kind,
|
2021-08-29 00:48:23 +08:00
|
|
|
const StatementScope& scope,
|
2023-03-12 18:24:58 +08:00
|
|
|
const StatementAccessibility& classScope,
|
2022-11-16 10:29:20 +08:00
|
|
|
StatementProperties properties);
|
2023-05-29 09:34:07 +08:00
|
|
|
void addMethodParameterStatement(QStringList words,int line, const PStatement& functionStatement);
|
2024-03-22 17:54:08 +08:00
|
|
|
void setInheritance(int index, const PStatement& classStatement, bool isStruct, int maxIndex);
|
2023-03-11 17:32:57 +08:00
|
|
|
bool isCurrentScope(const QString& command) const;
|
2022-11-02 13:38:26 +08:00
|
|
|
void addSoloScopeLevel(PStatement& statement, int line, bool shouldResetBlock=false); // adds new solo level
|
2024-03-22 17:54:08 +08:00
|
|
|
void removeScopeLevel(int line, int maxIndex); // removes level
|
2022-11-01 09:02:17 +08:00
|
|
|
|
2023-03-11 17:32:57 +08:00
|
|
|
int indexOfMatchingBrace(int startAt) const {
|
2022-11-01 00:01:46 +08:00
|
|
|
return mTokenizer[startAt]->matchIndex;
|
|
|
|
}
|
2021-11-12 07:26:13 +08:00
|
|
|
|
|
|
|
void internalClear();
|
|
|
|
|
2022-10-22 19:33:20 +08:00
|
|
|
QStringList sortFilesByIncludeRelations(const QSet<QString> &files);
|
|
|
|
|
2023-08-07 14:23:57 +08:00
|
|
|
int evaluateConstExpr(int endIndex, bool &ok);
|
|
|
|
int evaluateAdditionConstExpr(int endIndex, bool &ok);
|
|
|
|
int evaluateMultiplyConstExpr(int endIndex, bool &ok);
|
|
|
|
int evaluateConstExprTerm(int endIndex, bool &ok);
|
|
|
|
int evaluateLiteralNumber(int endIndex, bool &ok);
|
|
|
|
|
2023-10-22 13:19:03 +08:00
|
|
|
bool checkForConcept(KeywordType &keywordType) { return keywordType == KeywordType::Concept; }
|
2022-11-01 09:02:17 +08:00
|
|
|
bool checkForKeyword(KeywordType &keywordType);
|
2024-03-22 17:54:08 +08:00
|
|
|
bool checkForNamespace(KeywordType keywordType, int maxIndex);
|
2021-08-15 16:49:37 +08:00
|
|
|
bool checkForPreprocessor();
|
2022-11-04 20:27:35 +08:00
|
|
|
// bool checkForLambda();
|
2023-03-12 18:24:58 +08:00
|
|
|
bool checkForAccessibilitySpecifiers(KeywordType keywordType);
|
2023-10-22 13:19:03 +08:00
|
|
|
bool checkForRequires(KeywordType keywordType) { return keywordType == KeywordType::Requires; }
|
2024-03-22 17:54:08 +08:00
|
|
|
bool checkForStructs(KeywordType keywordType, int maxIndex);
|
|
|
|
bool checkForTypedefEnum(int maxIndex);
|
|
|
|
bool checkForTypedefStruct(int maxIndex);
|
|
|
|
bool checkForUsing(KeywordType keywordType, int maxIndex);
|
2022-10-22 10:44:10 +08:00
|
|
|
|
2024-03-22 17:54:08 +08:00
|
|
|
void checkAndHandleMethodOrVar(KeywordType keywordType, int maxIndex);
|
2022-11-04 20:27:35 +08:00
|
|
|
|
2023-03-11 17:32:57 +08:00
|
|
|
QSet<QString> internalGetFileUsings(const QString& filename) const;
|
|
|
|
|
|
|
|
PStatement doFindScopeStatement(const QString& filename, int line) const;
|
|
|
|
|
|
|
|
PStatementList doFindNamespace(const QString& name) const; // return a list of PSTATEMENTS (of the namespace)
|
|
|
|
PStatement doFindStatement(const QString& fullname) const;
|
|
|
|
PStatement doFindStatementOf(const QString& fileName,
|
|
|
|
const QString& phrase,
|
|
|
|
int line) const;
|
|
|
|
PStatement doFindStatementOf(const QString& fileName,
|
|
|
|
const QString& phrase,
|
|
|
|
const PStatement& currentScope,
|
|
|
|
PStatement& parentScopeType) const;
|
|
|
|
PStatement doFindStatementOf(const QString& fileName,
|
|
|
|
const QString& phrase,
|
|
|
|
const PStatement& currentClass) const;
|
|
|
|
|
|
|
|
PStatement doFindStatementOf(const QString& fileName,
|
|
|
|
const QStringList& expression,
|
|
|
|
const PStatement& currentScope) const;
|
|
|
|
PStatement doFindStatementOf(const QString& fileName,
|
|
|
|
const QStringList& expression,
|
|
|
|
int line) const;
|
2024-03-19 21:22:46 +08:00
|
|
|
PStatement doFindAliasedStatement(const PStatement& statement, QSet<Statement *> foundSet) const;
|
2023-03-11 17:32:57 +08:00
|
|
|
PStatement doFindAliasedStatement(const PStatement& statement) const;
|
2024-04-01 10:59:01 +08:00
|
|
|
PStatement doFindNoTemplateSpecializationClass(const PStatement& statement) const;
|
2023-03-11 17:32:57 +08:00
|
|
|
|
2023-07-03 09:36:27 +08:00
|
|
|
QList<PStatement> doListTypeStatements(const QString& fileName,int line) const;
|
|
|
|
|
2023-03-11 17:32:57 +08:00
|
|
|
PStatement doFindTypeDefinitionOf(const QString& fileName,
|
|
|
|
const QString& aType,
|
|
|
|
const PStatement& currentClass) const;
|
2022-11-27 13:32:14 +08:00
|
|
|
QString doFindFirstTemplateParamOf(const QString& fileName,
|
|
|
|
const QString& phrase,
|
2023-03-11 17:32:57 +08:00
|
|
|
const PStatement& currentScope) const;
|
2022-11-29 16:48:40 +08:00
|
|
|
QString doFindTemplateParamOf(const QString& fileName,
|
|
|
|
const QString& phrase,
|
|
|
|
int index,
|
2023-03-11 17:32:57 +08:00
|
|
|
const PStatement& currentScope) const;
|
2021-09-24 18:02:42 +08:00
|
|
|
QList<PStatement> getListOfFunctions(const QString& fileName, int line,
|
|
|
|
const PStatement& statement,
|
2023-03-11 17:32:57 +08:00
|
|
|
const PStatement& scopeStatement) const;
|
2024-03-08 08:30:41 +08:00
|
|
|
QSet<QString> internalGetIncludedFiles(const QString &filename) const;
|
2023-03-11 17:32:57 +08:00
|
|
|
PStatement findMacro(const QString& phrase, const QString& fileName) const;
|
2023-07-27 15:44:33 +08:00
|
|
|
PStatement findMemberOfStatement(
|
|
|
|
const QString& filename,
|
|
|
|
const QString& phrase,
|
|
|
|
const PStatement& scopeStatement) const ;
|
2021-08-16 00:47:35 +08:00
|
|
|
PStatement findMemberOfStatement(
|
|
|
|
const QString& phrase,
|
2023-03-11 17:32:57 +08:00
|
|
|
const PStatement& scopeStatement) const ;
|
2022-03-16 16:24:39 +08:00
|
|
|
QList<PStatement> findMembersOfStatement(const QString& phrase,
|
2023-03-11 17:32:57 +08:00
|
|
|
const PStatement& scopeStatement) const;
|
2021-08-16 00:47:35 +08:00
|
|
|
PStatement findStatementInScope(
|
|
|
|
const QString& name,
|
|
|
|
const QString& noNameArgs,
|
|
|
|
StatementKind kind,
|
2023-03-11 17:32:57 +08:00
|
|
|
const PStatement& scope) const;
|
2021-08-22 21:23:58 +08:00
|
|
|
PStatement findStatementInScope(
|
|
|
|
const QString& name,
|
2023-03-11 17:32:57 +08:00
|
|
|
const PStatement& scope) const;
|
2021-08-22 21:23:58 +08:00
|
|
|
PStatement findStatementInNamespace(
|
|
|
|
const QString& name,
|
2023-03-11 17:32:57 +08:00
|
|
|
const QString& namespaceName) const;
|
2021-12-04 18:38:54 +08:00
|
|
|
|
2021-12-07 08:23:27 +08:00
|
|
|
//{Find statement starting from startScope}
|
|
|
|
PStatement findStatementStartingFrom(const QString& fileName,
|
|
|
|
const QString& phrase,
|
2023-03-11 17:32:57 +08:00
|
|
|
const PStatement& startScope) const;
|
2021-12-07 08:23:27 +08:00
|
|
|
|
2021-12-06 09:02:39 +08:00
|
|
|
/**
|
|
|
|
* @brief evaluate the expression (starting from pos) in the scope
|
|
|
|
* @param fileName
|
|
|
|
* @param phraseExpression
|
|
|
|
* @param pos
|
|
|
|
* @param scope
|
|
|
|
* @param previousResult the result of evalution for expression from 0 to pos-1
|
|
|
|
* @param freeScoped if the expression left is
|
|
|
|
* @return
|
|
|
|
*/
|
2021-12-06 11:37:37 +08:00
|
|
|
PEvalStatement doEvalExpression(const QString& fileName,
|
2023-11-26 15:44:13 +08:00
|
|
|
QStringList phraseExpression,
|
2021-12-06 09:02:39 +08:00
|
|
|
int &pos,
|
|
|
|
const PStatement& scope,
|
2021-12-06 11:37:37 +08:00
|
|
|
const PEvalStatement& previousResult,
|
2023-11-26 15:44:13 +08:00
|
|
|
bool freeScoped,
|
|
|
|
bool expandMacros) const;
|
2021-12-06 09:02:39 +08:00
|
|
|
|
2024-04-14 09:24:39 +08:00
|
|
|
/* add + / minus - */
|
|
|
|
PEvalStatement doEvalArithmeticOperation(
|
2021-12-08 19:55:15 +08:00
|
|
|
const QString& fileName,
|
2023-11-26 15:44:13 +08:00
|
|
|
const QStringList& phraseExpression,
|
2021-12-08 19:55:15 +08:00
|
|
|
int &pos,
|
|
|
|
const PStatement& scope,
|
|
|
|
const PEvalStatement& previousResult,
|
2023-03-11 17:32:57 +08:00
|
|
|
bool freeScoped) const;
|
2024-04-14 09:24:39 +08:00
|
|
|
/* Pointer to members .* / ->* */
|
2021-12-06 11:37:37 +08:00
|
|
|
PEvalStatement doEvalPointerToMembers(
|
2021-12-04 18:38:54 +08:00
|
|
|
const QString& fileName,
|
2023-11-26 15:44:13 +08:00
|
|
|
const QStringList& phraseExpression,
|
2021-12-04 18:38:54 +08:00
|
|
|
int &pos,
|
2021-12-06 09:02:39 +08:00
|
|
|
const PStatement& scope,
|
2021-12-06 11:37:37 +08:00
|
|
|
const PEvalStatement& previousResult,
|
2023-03-11 17:32:57 +08:00
|
|
|
bool freeScoped) const;
|
2024-04-13 10:39:55 +08:00
|
|
|
|
|
|
|
/*
|
2024-04-14 09:24:39 +08:00
|
|
|
* Dereference * / Address-of & / Type Cast / Prefix increment and decrement
|
2024-04-13 10:39:55 +08:00
|
|
|
* */
|
|
|
|
PEvalStatement doEvalTypeCast(
|
2021-12-05 10:52:17 +08:00
|
|
|
const QString& fileName,
|
2023-11-26 15:44:13 +08:00
|
|
|
const QStringList& phraseExpression,
|
2021-12-05 10:52:17 +08:00
|
|
|
int &pos,
|
2021-12-06 09:02:39 +08:00
|
|
|
const PStatement& scope,
|
2021-12-06 11:37:37 +08:00
|
|
|
const PEvalStatement& previousResult,
|
2023-03-11 17:32:57 +08:00
|
|
|
bool freeScoped) const;
|
2024-04-13 10:39:55 +08:00
|
|
|
|
|
|
|
|
2021-12-06 11:37:37 +08:00
|
|
|
PEvalStatement doEvalMemberAccess(
|
2021-12-05 10:52:17 +08:00
|
|
|
const QString& fileName,
|
2023-11-26 15:44:13 +08:00
|
|
|
const QStringList& phraseExpression,
|
2021-12-05 10:52:17 +08:00
|
|
|
int &pos,
|
2021-12-06 09:02:39 +08:00
|
|
|
const PStatement& scope,
|
2021-12-06 11:37:37 +08:00
|
|
|
const PEvalStatement& previousResult,
|
2023-03-11 17:32:57 +08:00
|
|
|
bool freeScoped) const;
|
2021-12-06 11:37:37 +08:00
|
|
|
PEvalStatement doEvalScopeResolution(
|
2021-12-05 10:52:17 +08:00
|
|
|
const QString& fileName,
|
2023-11-26 15:44:13 +08:00
|
|
|
const QStringList& phraseExpression,
|
2021-12-05 10:52:17 +08:00
|
|
|
int &pos,
|
2021-12-06 09:02:39 +08:00
|
|
|
const PStatement& scope,
|
2021-12-06 11:37:37 +08:00
|
|
|
const PEvalStatement& previousResult,
|
2023-03-11 17:32:57 +08:00
|
|
|
bool freeScoped) const;
|
2021-12-06 11:37:37 +08:00
|
|
|
PEvalStatement doEvalTerm(
|
2021-12-06 09:02:39 +08:00
|
|
|
const QString& fileName,
|
2023-11-26 15:44:13 +08:00
|
|
|
const QStringList& phraseExpression,
|
2021-12-06 09:02:39 +08:00
|
|
|
int &pos,
|
|
|
|
const PStatement& scope,
|
2021-12-06 11:37:37 +08:00
|
|
|
const PEvalStatement& previousResult,
|
2023-03-11 17:32:57 +08:00
|
|
|
bool freeScoped) const;
|
2021-12-05 20:27:09 +08:00
|
|
|
|
2023-11-26 15:44:13 +08:00
|
|
|
bool expandMacro(QStringList& phraseExpression,int pos,
|
|
|
|
PStatement macro, QList< QSet<QString> > &usedMacros) const;
|
2022-12-11 19:47:43 +08:00
|
|
|
|
2023-03-11 17:32:57 +08:00
|
|
|
PEvalStatement doCreateEvalNamespace(const PStatement& namespaceStatement) const;
|
2021-12-07 08:23:27 +08:00
|
|
|
|
2023-10-22 13:19:03 +08:00
|
|
|
PEvalStatement doFindAliasedNamespace(const PStatement& namespaceAlias) const;
|
|
|
|
|
2023-06-20 10:58:14 +08:00
|
|
|
PEvalStatement doCreateEvalType(const QString& fileName,const QString& typeName, const PStatement& parentScope) const;
|
2023-03-11 17:32:57 +08:00
|
|
|
PEvalStatement doCreateEvalType(const QString& fileName,const PStatement& typeStatement) const;
|
|
|
|
PEvalStatement doCreateEvalType(const QString& primitiveType) const;
|
2021-12-07 08:23:27 +08:00
|
|
|
|
2023-10-19 19:32:08 +08:00
|
|
|
PEvalStatement doCreateTypedEvalVar(const QString& fileName,const QString& typeName, const PStatement& parentScope, const PStatement &baseStatement) const;
|
|
|
|
|
2022-11-29 16:48:40 +08:00
|
|
|
PEvalStatement doCreateEvalVariable(
|
|
|
|
const QString& fileName,
|
|
|
|
const PStatement& varStatement,
|
|
|
|
const QString& baseTemplateParams,
|
2023-03-11 17:32:57 +08:00
|
|
|
const PStatement& scope) const;
|
|
|
|
PEvalStatement doCreateEvalFunction(const QString& fileName, const PStatement& funcStatement) const;
|
|
|
|
PEvalStatement doCreateEvalLiteral(const QString& type) const;
|
|
|
|
void doSkipInExpression(const QStringList& expression, int&pos, const QString& startSymbol, const QString& endSymbol) const;
|
2022-03-23 12:30:58 +08:00
|
|
|
|
2023-03-01 11:29:30 +08:00
|
|
|
QString findFunctionPointerName(int startIdx);
|
2022-03-23 12:30:58 +08:00
|
|
|
bool isIdentifier(const QString& token) const {
|
2022-11-04 20:27:35 +08:00
|
|
|
return (!token.isEmpty() && isIdentChar(token.front())
|
2022-03-23 12:30:58 +08:00
|
|
|
&& !token.contains('\"'));
|
|
|
|
}
|
|
|
|
|
2022-11-01 22:10:54 +08:00
|
|
|
bool isIdentifierOrPointer(const QString& term) const {
|
|
|
|
switch(term[0].unicode()) {
|
|
|
|
case '*':
|
|
|
|
return true;
|
|
|
|
case '\"':
|
|
|
|
case '\'':
|
|
|
|
return false;
|
|
|
|
default:
|
2022-11-04 20:27:35 +08:00
|
|
|
return isIdentChar(term[0]);
|
2022-11-01 22:10:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-23 12:30:58 +08:00
|
|
|
bool isIntegerLiteral(const QString& token) const {
|
|
|
|
if (token.isEmpty())
|
|
|
|
return false;
|
|
|
|
QChar ch = token.front();
|
|
|
|
return (ch>='0' && ch<='9' && !token.contains(".") && !token.contains("e"));
|
|
|
|
}
|
|
|
|
bool isFloatLiteral(const QString& token) const {
|
|
|
|
if (token.isEmpty())
|
|
|
|
return false;
|
|
|
|
QChar ch = token.front();
|
|
|
|
return (ch>='0' && ch<='9' && (token.contains(".") || token.contains("e")));
|
|
|
|
}
|
|
|
|
bool isStringLiteral(const QString& token) const {
|
|
|
|
if (token.isEmpty())
|
|
|
|
return false;
|
|
|
|
return (!token.startsWith('\'') && token.contains('"'));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isCharLiteral(const QString& token) const{
|
|
|
|
if (token.isEmpty())
|
|
|
|
return false;
|
|
|
|
return (token.startsWith('\''));
|
|
|
|
}
|
2022-11-04 20:27:35 +08:00
|
|
|
|
|
|
|
bool isKeyword(const QString& token) const {
|
|
|
|
return mCppKeywords.contains(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tokenIsIdentifier(const QString& token) const {
|
|
|
|
//token won't be empty
|
|
|
|
return isIdentChar(token[0]);
|
|
|
|
}
|
|
|
|
|
2022-11-05 18:58:15 +08:00
|
|
|
bool tokenIsTypeOrNonKeyword(const QString& token) const {
|
|
|
|
return tokenIsIdentifier(token) &&
|
|
|
|
(mCppTypeKeywords.contains(token)
|
|
|
|
|| !mCppKeywords.contains(token)
|
|
|
|
|| token=="const");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-12-07 08:23:27 +08:00
|
|
|
PStatement doParseEvalTypeInfo(
|
|
|
|
const QString& fileName,
|
|
|
|
const PStatement& scope,
|
|
|
|
const QString& type,
|
|
|
|
QString& baseType,
|
2022-11-29 12:06:29 +08:00
|
|
|
PStatement& typeStatement,
|
|
|
|
int& pointerLevel,
|
2023-03-11 17:32:57 +08:00
|
|
|
QString& templateParams) const;
|
|
|
|
|
|
|
|
int getBracketEnd(const QString& s, int startAt) const;
|
2023-03-12 18:24:58 +08:00
|
|
|
StatementAccessibility getClassMemberAccessibility(const QString& text) const;
|
|
|
|
StatementAccessibility getClassMemberAccessibility(KeywordType keywordType) const;
|
2023-10-22 18:33:53 +08:00
|
|
|
// int getCurrentBlockBeginSkip() const;
|
|
|
|
// int getCurrentBlockEndSkip() const;
|
2024-03-22 17:54:08 +08:00
|
|
|
int getCurrentInlineNamespaceEndSkip(int endIndex) const;
|
2023-03-11 17:32:57 +08:00
|
|
|
PStatement getCurrentScope() const; // gets last item from last level
|
2022-11-30 09:54:23 +08:00
|
|
|
QString getTemplateParam(const PStatement& statement, const QString& filename,
|
2023-03-11 17:32:57 +08:00
|
|
|
const QString& phrase, int index, const PStatement& currentScope) const;
|
|
|
|
int getTemplateParamStart(const QString& s, int startAt, int index) const;
|
|
|
|
int getTemplateParamEnd(const QString& s, int startAt) const ;
|
2021-08-22 21:23:58 +08:00
|
|
|
|
2021-08-22 16:08:46 +08:00
|
|
|
void getFullNamespace(
|
2021-08-16 00:47:35 +08:00
|
|
|
const QString& phrase,
|
|
|
|
QString& sNamespace,
|
2023-03-11 17:32:57 +08:00
|
|
|
QString& member) const;
|
2021-08-17 23:30:14 +08:00
|
|
|
QString getFullStatementName(
|
|
|
|
const QString& command,
|
2023-03-11 17:32:57 +08:00
|
|
|
const PStatement& parent) const;
|
2021-08-16 00:47:35 +08:00
|
|
|
PStatement getIncompleteClass(
|
|
|
|
const QString& command,
|
2021-08-29 00:48:23 +08:00
|
|
|
const PStatement& parentScope);
|
2023-03-11 17:32:57 +08:00
|
|
|
QString getScopePrefix(const PStatement& statement) const;
|
2021-08-16 00:47:35 +08:00
|
|
|
StatementScope getScope();
|
2021-08-17 23:30:14 +08:00
|
|
|
QString getStatementKey(const QString& sName,
|
|
|
|
const QString& sType,
|
2023-03-11 17:32:57 +08:00
|
|
|
const QString& sNoNameArgs) const;
|
2021-08-29 00:48:23 +08:00
|
|
|
PStatement getTypeDef(const PStatement& statement,
|
2023-03-11 17:32:57 +08:00
|
|
|
const QString& fileName, const QString& aType) const;
|
2023-10-22 18:33:53 +08:00
|
|
|
// void handleCatchBlock();
|
2024-05-03 10:39:44 +08:00
|
|
|
void doAddVar(const QString& name, const QString& type, bool isConst, const QString& suffix);
|
2024-03-22 17:54:08 +08:00
|
|
|
void handleConcept(int maxIndex);
|
|
|
|
void handleEnum(bool isTypedef, int maxIndex);
|
|
|
|
void handleForBlock(int maxIndex);
|
|
|
|
void handleKeyword(KeywordType skipType, int maxIndex);
|
|
|
|
void handleLambda(int index, int maxIndex);
|
2023-02-06 14:04:38 +08:00
|
|
|
void handleOperatorOverloading(
|
|
|
|
const QString& sType,
|
|
|
|
int operatorTokenIndex,
|
2024-03-22 17:54:08 +08:00
|
|
|
bool isStatic, int maxIndex);
|
2021-08-19 12:01:01 +08:00
|
|
|
void handleMethod(
|
2022-11-04 20:27:35 +08:00
|
|
|
StatementKind functionKind,
|
2021-08-15 04:31:57 +08:00
|
|
|
const QString& sType,
|
|
|
|
const QString& sName,
|
2022-10-31 19:37:24 +08:00
|
|
|
int argStart,
|
2021-08-15 04:31:57 +08:00
|
|
|
bool isStatic,
|
2023-03-10 20:13:52 +08:00
|
|
|
bool isFriend,
|
2024-03-22 17:54:08 +08:00
|
|
|
bool isOperatorOverload,
|
|
|
|
int maxIndex);
|
|
|
|
void handleNamespace(KeywordType skipType, int maxIndex);
|
|
|
|
void handleOtherTypedefs(int maxIndex);
|
2021-08-17 23:30:14 +08:00
|
|
|
void handlePreprocessor();
|
2024-03-22 17:54:08 +08:00
|
|
|
void handleAccessibilitySpecifiers(KeywordType keywordType, int maxIndex);
|
|
|
|
bool handleStatement(int maxIndex);
|
|
|
|
void handleStructs(bool isTypedef, int maxIndex);
|
2024-05-03 10:39:44 +08:00
|
|
|
void handleStructredBinding(const QString& sType, int maxIndex);
|
2024-03-22 17:54:08 +08:00
|
|
|
void handleUsing(int maxIndex);
|
|
|
|
void handleVar(const QString& typePrefix,bool isExtern,bool isStatic, int maxIndex);
|
2024-02-28 09:17:30 +08:00
|
|
|
void handleInheritance(PStatement derivedClass, PClassInheritanceInfo pInfo);
|
2024-02-27 18:08:38 +08:00
|
|
|
void handleInheritances();
|
2024-03-22 17:54:08 +08:00
|
|
|
void skipRequires(int maxIndex);
|
2021-08-19 23:49:23 +08:00
|
|
|
void internalParse(const QString& fileName);
|
2021-08-15 04:31:57 +08:00
|
|
|
// function FindMacroDefine(const Command: AnsiString): PStatement;
|
|
|
|
void inheritClassStatement(
|
2021-08-29 00:48:23 +08:00
|
|
|
const PStatement& derived,
|
2021-08-15 04:31:57 +08:00
|
|
|
bool isStruct,
|
2021-08-29 00:48:23 +08:00
|
|
|
const PStatement& base,
|
2023-03-12 18:24:58 +08:00
|
|
|
StatementAccessibility access);
|
2021-08-16 00:47:35 +08:00
|
|
|
PStatement doFindStatementInScope(const QString& name,
|
|
|
|
const QString& noNameArgs,
|
|
|
|
StatementKind kind,
|
2023-03-11 19:30:56 +08:00
|
|
|
const PStatement& scope) const;
|
2021-08-15 04:31:57 +08:00
|
|
|
void internalInvalidateFile(const QString& fileName);
|
2021-08-22 21:23:58 +08:00
|
|
|
void internalInvalidateFiles(const QSet<QString>& files);
|
|
|
|
QSet<QString> calculateFilesToBeReparsed(const QString& fileName);
|
2021-08-17 23:30:14 +08:00
|
|
|
void scanMethodArgs(
|
2021-08-29 00:48:23 +08:00
|
|
|
const PStatement& functionStatement,
|
2022-11-05 08:42:54 +08:00
|
|
|
int argStart);
|
2024-03-23 09:03:20 +08:00
|
|
|
QSet<QString> parseLambdaCaptures(int index);
|
2022-04-17 19:49:04 +08:00
|
|
|
QString splitPhrase(const QString& phrase, QString& sClazz,
|
2023-03-11 17:32:57 +08:00
|
|
|
QString& sOperator, QString &sMember) const;
|
|
|
|
QString removeTemplateParams(const QString& phrase) const;
|
2021-08-15 16:49:37 +08:00
|
|
|
|
2022-11-04 20:27:35 +08:00
|
|
|
bool splitLastMember(const QString& token, QString& lastMember, QString& remaining);
|
2021-08-15 17:52:39 +08:00
|
|
|
|
2022-03-23 12:30:58 +08:00
|
|
|
bool isSpaceChar(const QChar& ch) const {
|
|
|
|
return ch==' ' || ch =='\t';
|
|
|
|
}
|
2021-08-15 17:52:39 +08:00
|
|
|
|
2022-03-23 12:30:58 +08:00
|
|
|
bool isWordChar(const QChar& ch) const {
|
|
|
|
return ch.isLetter()
|
|
|
|
|| ch == '_'
|
|
|
|
|| ch == '*'
|
|
|
|
|| ch == '&';
|
2023-05-24 19:30:38 +08:00
|
|
|
}
|
2021-08-15 20:25:54 +08:00
|
|
|
|
2022-11-04 20:27:35 +08:00
|
|
|
bool isIdentifier(const QChar& ch) const {
|
|
|
|
return ch.isLetter()
|
|
|
|
|| ch == '_'
|
|
|
|
|| ch == '~'
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isIdentChar(const QChar& ch) const {
|
2022-03-23 12:30:58 +08:00
|
|
|
return ch.isLetter()
|
|
|
|
|| ch == '_';
|
|
|
|
}
|
2021-08-15 17:52:39 +08:00
|
|
|
|
2022-03-23 12:30:58 +08:00
|
|
|
bool isDigitChar(const QChar& ch) const {
|
|
|
|
return (ch>='0' && ch<='9');
|
|
|
|
}
|
2021-08-15 17:52:39 +08:00
|
|
|
|
2022-11-02 22:48:25 +08:00
|
|
|
bool isInvalidFunctionArgsSuffixChar(const QChar& ch) const {
|
2022-11-03 00:49:22 +08:00
|
|
|
|
|
|
|
// &&
|
2022-11-02 22:48:25 +08:00
|
|
|
switch(ch.unicode()){
|
|
|
|
case '.':
|
|
|
|
case '-':
|
|
|
|
case '+':
|
|
|
|
case '/':
|
|
|
|
case '%':
|
|
|
|
case '*':
|
|
|
|
case '|':
|
|
|
|
case '?':
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 17:52:39 +08:00
|
|
|
/*'(', ';', ':', '{', '}', '#' */
|
2022-03-23 12:30:58 +08:00
|
|
|
bool isSeperator(const QChar& ch) const {
|
|
|
|
switch(ch.unicode()){
|
|
|
|
case '(':
|
|
|
|
case ';':
|
|
|
|
case ':':
|
|
|
|
case '{':
|
|
|
|
case '}':
|
|
|
|
case '#':
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-08-15 17:52:39 +08:00
|
|
|
|
2021-08-18 05:34:04 +08:00
|
|
|
/*';', '{', '}'*/
|
2022-03-23 12:30:58 +08:00
|
|
|
bool isblockChar(const QChar& ch) const {
|
|
|
|
switch(ch.unicode()){
|
|
|
|
case ';':
|
|
|
|
case '{':
|
|
|
|
case '}':
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-08-18 05:34:04 +08:00
|
|
|
|
2021-08-16 00:47:35 +08:00
|
|
|
/* '#', ',', ';', ':', '{', '}', '!', '/', '+', '-', '<', '>' */
|
2022-03-23 12:30:58 +08:00
|
|
|
bool isInvalidVarPrefixChar(const QChar& ch) const {
|
|
|
|
switch (ch.unicode()) {
|
|
|
|
case '#':
|
|
|
|
case ',':
|
|
|
|
case ';':
|
|
|
|
case ':':
|
|
|
|
case '{':
|
|
|
|
case '}':
|
|
|
|
case '!':
|
|
|
|
case '/':
|
|
|
|
case '+':
|
|
|
|
case '-':
|
|
|
|
case '<':
|
|
|
|
case '>':
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-08-16 00:47:35 +08:00
|
|
|
|
2021-08-18 17:02:57 +08:00
|
|
|
/*'{', '}' */
|
2022-03-23 12:30:58 +08:00
|
|
|
bool isBraceChar(const QChar& ch) const {
|
|
|
|
return ch == '{' || ch =='}';
|
|
|
|
}
|
2021-08-18 17:02:57 +08:00
|
|
|
|
2022-03-23 12:30:58 +08:00
|
|
|
bool isLineChar(const QChar& ch) const {
|
|
|
|
return ch=='\n' || ch=='\r';
|
|
|
|
}
|
2021-08-15 20:25:54 +08:00
|
|
|
|
2022-11-04 20:27:35 +08:00
|
|
|
bool isNotFuncArgs(int startIndex);
|
2021-08-15 20:25:54 +08:00
|
|
|
|
2021-08-17 23:30:14 +08:00
|
|
|
/**
|
|
|
|
* @brief Test if a statement is a class/struct/union/namespace/function
|
|
|
|
* @param kind
|
|
|
|
* @return
|
|
|
|
*/
|
2021-12-08 19:13:47 +08:00
|
|
|
bool isNamedScope(StatementKind kind) const;
|
2021-08-17 23:30:14 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Test if a statement is a class/struct/union/enum/enum class/typedef
|
|
|
|
* @param kind
|
|
|
|
* @return
|
|
|
|
*/
|
2021-12-08 19:13:47 +08:00
|
|
|
bool isTypeStatement(StatementKind kind) const;
|
2021-08-17 23:30:14 +08:00
|
|
|
|
2021-08-15 04:31:57 +08:00
|
|
|
void updateSerialId();
|
2021-12-04 18:38:54 +08:00
|
|
|
|
2024-03-22 17:54:08 +08:00
|
|
|
int indexOfNextSemicolon(int index, int maxIndex);
|
|
|
|
int indexOfNextPeriodOrSemicolon(int index, int maxIndex);
|
|
|
|
int indexOfNextSemicolonOrLeftBrace(int index, int maxIndex);
|
|
|
|
int indexOfNextColon(int index, int maxIndex);
|
|
|
|
int indexOfNextLeftBrace(int index, int maxIndex);
|
|
|
|
int indexPassParenthesis(int index, int maxIndex);
|
|
|
|
int indexOfNextRightParenthesis(int index, int maxIndex);
|
2023-07-05 09:01:38 +08:00
|
|
|
// int indexPassBraces(int index);
|
2024-03-22 17:54:08 +08:00
|
|
|
int skipAssignment(int index, int maxIndex);
|
|
|
|
void skipNextSemicolon(int index, int maxIndex);
|
|
|
|
int moveToEndOfStatement(int index, bool checkLambda, int maxIndex);
|
2022-11-09 22:22:33 +08:00
|
|
|
// int moveToNextAssignmentOrEndOfStatement(int index, bool checkLambda, int endIndex=-1);
|
2024-03-22 17:54:08 +08:00
|
|
|
void skipParenthesis(int index, int maxIndex);
|
2022-11-01 22:10:54 +08:00
|
|
|
QString mergeArgs(int startIndex, int endIndex);
|
|
|
|
void parseCommandTypeAndArgs(QString& command,
|
|
|
|
QString& typeSuffix,
|
2023-03-12 23:45:03 +08:00
|
|
|
QString& args) const;
|
2024-03-06 19:35:35 +08:00
|
|
|
QString expandMacro(const QString& text) const;
|
2024-03-21 16:55:32 +08:00
|
|
|
static QStringList splitExpression(const QString& expr);
|
2021-08-14 22:52:37 +08:00
|
|
|
private:
|
|
|
|
int mParserId;
|
2022-07-28 13:51:38 +08:00
|
|
|
ParserLanguage mLanguage;
|
2021-08-14 22:52:37 +08:00
|
|
|
int mSerialCount;
|
2021-08-19 23:49:23 +08:00
|
|
|
QString mSerialId;
|
2021-08-14 22:52:37 +08:00
|
|
|
int mUniqId;
|
|
|
|
bool mEnabled;
|
|
|
|
int mIndex;
|
|
|
|
bool mIsHeader;
|
|
|
|
bool mIsSystemHeader;
|
|
|
|
QString mCurrentFile;
|
|
|
|
// stack list , each element is a list of one/many scopes(like intypedef struct s1,s2;
|
|
|
|
// It's used for store scope nesting infos
|
|
|
|
QVector<PStatement> mCurrentScope;
|
2023-03-12 18:24:58 +08:00
|
|
|
QVector<StatementAccessibility> mMemberAccessibilities;
|
2021-08-14 22:52:37 +08:00
|
|
|
|
2023-03-12 18:24:58 +08:00
|
|
|
StatementAccessibility mCurrentMemberAccessibility;
|
2021-08-14 22:52:37 +08:00
|
|
|
StatementModel mStatementList;
|
|
|
|
//It's used in preprocessor, so we can't use fIncludeList instead
|
2021-08-22 21:23:58 +08:00
|
|
|
|
2021-08-14 22:52:37 +08:00
|
|
|
CppTokenizer mTokenizer;
|
2022-10-22 10:44:10 +08:00
|
|
|
CppPreprocessor mPreprocessor;
|
2021-08-15 04:31:57 +08:00
|
|
|
QSet<QString> mProjectFiles;
|
2023-10-22 18:33:53 +08:00
|
|
|
// QVector<int> mBlockBeginSkips; //list of for/catch block begin token index;
|
|
|
|
// QVector<int> mBlockEndSkips; //list of for/catch block end token index;
|
2021-08-15 04:31:57 +08:00
|
|
|
QVector<int> mInlineNamespaceEndSkips; // list for inline namespace end token index;
|
2021-08-19 23:49:23 +08:00
|
|
|
QSet<QString> mFilesToScan; // list of base files to scan
|
2021-08-15 04:31:57 +08:00
|
|
|
int mFilesScannedCount; // count of files that have been scanned
|
|
|
|
int mFilesToScanCount; // count of files and files included in files that have to be scanned
|
|
|
|
bool mParseLocalHeaders;
|
|
|
|
bool mParseGlobalHeaders;
|
|
|
|
bool mIsProjectFile;
|
|
|
|
int mLockCount; // lock(don't reparse) when we need to find statements in a batch
|
|
|
|
bool mParsing;
|
2022-10-18 19:09:46 +08:00
|
|
|
QHash<QString,PStatementList> mNamespaces; // namespace and the statements in its scope
|
2024-02-27 18:08:38 +08:00
|
|
|
QList<PClassInheritanceInfo> mClassInheritances;
|
2021-08-28 09:01:40 +08:00
|
|
|
QSet<QString> mInlineNamespaces;
|
2023-02-21 22:40:29 +08:00
|
|
|
#ifdef QT_DEBUG
|
|
|
|
int mLastIndex;
|
|
|
|
#endif
|
2024-05-28 19:01:18 +08:00
|
|
|
mutable QRecursiveMutex mMutex;
|
2022-11-01 09:02:17 +08:00
|
|
|
QMap<QString,KeywordType> mCppKeywords;
|
2021-10-30 21:15:07 +08:00
|
|
|
QSet<QString> mCppTypeKeywords;
|
2024-05-02 16:58:01 +08:00
|
|
|
|
|
|
|
PParseFileCommand mLastParseFileCommand;
|
2021-08-14 22:52:37 +08:00
|
|
|
};
|
2021-08-23 03:47:28 +08:00
|
|
|
using PCppParser = std::shared_ptr<CppParser>;
|
2021-08-23 10:16:06 +08:00
|
|
|
|
|
|
|
class CppFileParserThread : public QThread {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit CppFileParserThread(
|
|
|
|
PCppParser parser,
|
|
|
|
QString fileName,
|
|
|
|
bool inProject,
|
|
|
|
bool onlyIfNotParsed = false,
|
|
|
|
bool updateView = true,
|
|
|
|
QObject *parent = nullptr);
|
|
|
|
|
|
|
|
private:
|
|
|
|
PCppParser mParser;
|
|
|
|
QString mFileName;
|
|
|
|
bool mInProject;
|
|
|
|
bool mOnlyIfNotParsed;
|
|
|
|
bool mUpdateView;
|
|
|
|
|
|
|
|
// QThread interface
|
|
|
|
protected:
|
|
|
|
void run() override;
|
|
|
|
};
|
|
|
|
using PCppParserThread = std::shared_ptr<CppFileParserThread>;
|
|
|
|
|
|
|
|
class CppFileListParserThread: public QThread {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit CppFileListParserThread(
|
|
|
|
PCppParser parser,
|
|
|
|
bool updateView = true,
|
|
|
|
QObject *parent = nullptr);
|
|
|
|
private:
|
|
|
|
PCppParser mParser;
|
|
|
|
bool mUpdateView;
|
|
|
|
// QThread interface
|
|
|
|
protected:
|
|
|
|
void run() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
void parseFile(
|
|
|
|
PCppParser parser,
|
2021-08-29 00:48:23 +08:00
|
|
|
const QString& fileName,
|
2021-08-23 10:16:06 +08:00
|
|
|
bool inProject,
|
|
|
|
bool onlyIfNotParsed = false,
|
|
|
|
bool updateView = true);
|
|
|
|
|
|
|
|
void parseFileList(
|
|
|
|
PCppParser parser,
|
|
|
|
bool updateView = true);
|
|
|
|
|
|
|
|
|
2021-08-14 22:52:37 +08:00
|
|
|
#endif // CPPPARSER_H
|