work save

This commit is contained in:
royqh1979@gmail.com 2021-08-07 14:08:51 +08:00
parent 59cb5d7d8b
commit 3a019a7180
7 changed files with 336 additions and 12 deletions

View File

@ -18,6 +18,7 @@ SOURCES += \
compiler/stdincompiler.cpp \
parser/cpppreprocessor.cpp \
parser/statementmodel.cpp \
parser/utils.cpp \
qsynedit/Search.cpp \
qsynedit/SearchBase.cpp \
qsynedit/SearchRegex.cpp \

View File

@ -12,6 +12,7 @@
#include "common.h"
#include "colorscheme.h"
#include "iconsmanager.h"
#include "parser/utils.h"
Settings* createAppSettings(const QString& filepath = QString()) {
QString filename;
@ -43,7 +44,7 @@ Settings* createAppSettings(const QString& filepath = QString()) {
return nullptr;
}
return new Settings(filename);
new Settings(filename);
}
int main(int argc, char *argv[])
@ -54,6 +55,8 @@ int main(int argc, char *argv[])
qRegisterMetaType<PCompileIssue>("PCompileIssue&");
qRegisterMetaType<QVector<int>>("QVector<int>");
initParser();
try {
SystemConsts systemConsts;
@ -65,12 +68,7 @@ int main(int argc, char *argv[])
return -1;
}
auto settings = std::unique_ptr<Settings>(pSettings);
settings->environment().load();
settings->compilerSets().loadSets();
settings->editor().load();
settings->executor().load();
settings->debugger().load();
settings->history().load();
//Translation must be loaded after language setting is loaded
QTranslator trans;

View File

@ -2,5 +2,22 @@
StatementModel::StatementModel(QObject *parent) : QObject(parent)
{
mCount = 0;
mClearing = false;
mBatchDeleteCount = 0;
}
const StatementMap &StatementModel::childrenStatements(PStatement statement)
{
if (!statement) {
return mGlobalStatements;
} else {
return statement->children;
}
}
const StatementMap &StatementModel::childrenStatements(std::weak_ptr<Statement> statement)
{
PStatement s = statement.lock();
return childrenStatements(s);
}

View File

@ -2,6 +2,7 @@
#define STATEMENTMODEL_H
#include <QObject>
#include "utils.h"
class StatementModel : public QObject
{
@ -9,8 +10,24 @@ class StatementModel : public QObject
public:
explicit StatementModel(QObject *parent = nullptr);
signals:
void add(PStatement statement);
// function DeleteFirst: Integer;
// function DeleteLast: Integer;
void BeginBatchDelete();
void endBatchDelete();
void deleteStatement(PStatement statement);
const StatementMap& childrenStatements(PStatement statement = PStatement());
const StatementMap& childrenStatements(std::weak_ptr<Statement> statement);
void clear();
void dumpTo(const QString& logFile);
void dumpWithScope(const QString& logFile);
signals:
private:
int mCount;
bool mClearing;
StatementMap mGlobalStatements; //may have overloaded functions, so use PStatementList to store
int mBatchDeleteCount;
};
#endif // STATEMENTMODEL_H

View File

@ -0,0 +1,235 @@
#include "utils.h"
QStringList CppDirectives;
QStringList JavadocTags;
QMap<QString,SkipType> CppKeywords;
QSet<QString> CppTypeKeywords;
QSet<QString> STLPointers;
QSet<QString> STLContainers;
QSet<QString> STLElementMethods;
void initParser()
{
// skip itself
CppKeywords.insert("and",SkipType::skItself);
CppKeywords.insert("and_eq",SkipType::skItself);
CppKeywords.insert("bitand",SkipType::skItself);
CppKeywords.insert("bitor",SkipType::skItself);
CppKeywords.insert("break",SkipType::skItself);
CppKeywords.insert("compl",SkipType::skItself);
CppKeywords.insert("constexpr",SkipType::skItself);
CppKeywords.insert("const_cast",SkipType::skItself);
CppKeywords.insert("continue",SkipType::skItself);
CppKeywords.insert("dynamic_cast",SkipType::skItself);
CppKeywords.insert("else",SkipType::skItself);
CppKeywords.insert("explicit",SkipType::skItself);
CppKeywords.insert("export",SkipType::skItself);
CppKeywords.insert("false",SkipType::skItself);
//CppKeywords.insert("for",SkipType::skItself);
CppKeywords.insert("mutable",SkipType::skItself);
CppKeywords.insert("noexcept",SkipType::skItself);
CppKeywords.insert("not",SkipType::skItself);
CppKeywords.insert("not_eq",SkipType::skItself);
CppKeywords.insert("nullptr",SkipType::skItself);
CppKeywords.insert("or",SkipType::skItself);
CppKeywords.insert("or_eq",SkipType::skItself);
CppKeywords.insert("register",SkipType::skItself);
CppKeywords.insert("reinterpret_cast",SkipType::skItself);
CppKeywords.insert("static_assert",SkipType::skItself);
CppKeywords.insert("static_cast",SkipType::skItself);
CppKeywords.insert("template",SkipType::skItself);
CppKeywords.insert("this",SkipType::skItself);
CppKeywords.insert("thread_local",SkipType::skItself);
CppKeywords.insert("true",SkipType::skItself);
CppKeywords.insert("typename",SkipType::skItself);
CppKeywords.insert("virtual",SkipType::skItself);
CppKeywords.insert("volatile",SkipType::skItself);
CppKeywords.insert("xor",SkipType::skItself);
CppKeywords.insert("xor_eq",SkipType::skItself);
//CppKeywords.insert("catch",SkipType::skItself);
CppKeywords.insert("do",SkipType::skItself);
CppKeywords.insert("try",SkipType::skItself);
// Skip to ;
CppKeywords.insert("delete",SkipType::skToSemicolon);
CppKeywords.insert("delete[]",SkipType::skToSemicolon);
CppKeywords.insert("goto",SkipType::skToSemicolon);
CppKeywords.insert("new",SkipType::skToSemicolon);
CppKeywords.insert("return",SkipType::skToSemicolon);
CppKeywords.insert("throw",SkipType::skToSemicolon);
// CppKeywords.insert("using",SkipType::skToSemicolon); //won't use it
// Skip to :
CppKeywords.insert("case",SkipType::skToColon);
CppKeywords.insert("default",SkipType::skToColon);
// Skip to )
CppKeywords.insert("__attribute__",SkipType::skToRightParenthesis);
CppKeywords.insert("alignas",SkipType::skToRightParenthesis); // not right
CppKeywords.insert("alignof",SkipType::skToRightParenthesis); // not right
CppKeywords.insert("decltype",SkipType::skToRightParenthesis); // not right
CppKeywords.insert("if",SkipType::skToRightParenthesis);
CppKeywords.insert("sizeof",SkipType::skToRightParenthesis);
CppKeywords.insert("switch",SkipType::skToRightParenthesis);
CppKeywords.insert("typeid",SkipType::skToRightParenthesis);
CppKeywords.insert("while",SkipType::skToRightParenthesis);
// Skip to }
CppKeywords.insert("asm",SkipType::skToRightBrace);
//CppKeywords.insert("namespace",SkipType::skToLeftBrace); // won't process it
// Skip to {
// wont handle
//Not supported yet
CppKeywords.insert("atomic_cancel",SkipType::skNone);
CppKeywords.insert("atomic_commit",SkipType::skNone);
CppKeywords.insert("atomic_noexcept",SkipType::skNone);
CppKeywords.insert("concept",SkipType::skNone);
CppKeywords.insert("consteval",SkipType::skNone);
CppKeywords.insert("constinit",SkipType::skNone);
CppKeywords.insert("co_wait",SkipType::skNone);
CppKeywords.insert("co_return",SkipType::skNone);
CppKeywords.insert("co_yield",SkipType::skNone);
CppKeywords.insert("reflexpr",SkipType::skNone);
CppKeywords.insert("requires",SkipType::skNone);
// its a type
CppKeywords.insert("auto",SkipType::skNone);
CppKeywords.insert("bool",SkipType::skNone);
CppKeywords.insert("char",SkipType::skNone);
CppKeywords.insert("char8_t",SkipType::skNone);
CppKeywords.insert("char16_t",SkipType::skNone);
CppKeywords.insert("char32_t",SkipType::skNone);
CppKeywords.insert("double",SkipType::skNone);
CppKeywords.insert("float",SkipType::skNone);
CppKeywords.insert("int",SkipType::skNone);
CppKeywords.insert("long",SkipType::skNone);
CppKeywords.insert("short",SkipType::skNone);
CppKeywords.insert("signed",SkipType::skNone);
CppKeywords.insert("unsigned",SkipType::skNone);
CppKeywords.insert("void",SkipType::skNone);
CppKeywords.insert("wchar_t",SkipType::skNone);
// type keywords
CppTypeKeywords.insert("auto");
CppTypeKeywords.insert("bool");
CppTypeKeywords.insert("char");
CppTypeKeywords.insert("char8_t");
CppTypeKeywords.insert("char16_t");
CppTypeKeywords.insert("char32_t");
CppTypeKeywords.insert("double");
CppTypeKeywords.insert("float");
CppTypeKeywords.insert("int");
CppTypeKeywords.insert("long");
CppTypeKeywords.insert("short");
//CppTypeKeywords.insert("signed");
//CppTypeKeywords.insert("unsigned");
CppTypeKeywords.insert("void");
CppTypeKeywords.insert("wchar_t");
// it's part of type info
CppKeywords.insert("const",SkipType::skNone);
CppKeywords.insert("extern",SkipType::skNone);
CppKeywords.insert("inline",SkipType::skNone);
// handled elsewhere
CppKeywords.insert("class",SkipType::skNone);
CppKeywords.insert("enum",SkipType::skNone);
CppKeywords.insert("friend",SkipType::skNone);
CppKeywords.insert("operator",SkipType::skNone);
CppKeywords.insert("private",SkipType::skNone);
CppKeywords.insert("protected",SkipType::skNone);
CppKeywords.insert("public",SkipType::skNone);
CppKeywords.insert("static",SkipType::skNone);
CppKeywords.insert("struct",SkipType::skNone);
CppKeywords.insert("typedef",SkipType::skNone);
CppKeywords.insert("union",SkipType::skNone);
// namespace
CppKeywords.insert("namespace",SkipType::skNone);
CppKeywords.insert("using",SkipType::skNone);
CppKeywords.insert("for",SkipType::skNone);
CppKeywords.insert("catch",SkipType::skNone);
// nullptr is value
CppKeywords.insert("nullptr",SkipType::skNone);
//STL Containers
STLContainers.insert("std::array");
STLContainers.insert("std::vector");
STLContainers.insert("std::deque");
STLContainers.insert("std::forward_list");
STLContainers.insert("std::list");
STLContainers.insert("std::set");
STLContainers.insert("std::map");
STLContainers.insert("std::multilist");
STLContainers.insert("std::multimap");
STLContainers.insert("std::unordered_set");
STLContainers.insert("std::unordered_map");
STLContainers.insert("std::unordered_multiset");
STLContainers.insert("std::unordered_multimap");
STLContainers.insert("std::stack");
STLContainers.insert("std::queue");
STLContainers.insert("std::priority_queue");
STLContainers.insert("std::span");
//STL element access methods
STLElementMethods.insert("at");
STLElementMethods.insert("back");
STLElementMethods.insert("front");
STLElementMethods.insert("top");
//STL pointers
STLPointers.insert("std::unique_ptr");
STLPointers.insert("std::auto_ptr");
STLPointers.insert("std::shared_ptr");
STLPointers.insert("std::weak_ptr");
STLPointers.insert("__gnu_cxx::__normal_iterator");
STLPointers.insert("std::reverse_iterator");
STLPointers.insert("std::iterator");
//C/CPP preprocessor directives
CppDirectives.append("#include");
CppDirectives.append("#if");
CppDirectives.append("#ifdef");
CppDirectives.append("#ifndef");
CppDirectives.append("#else");
CppDirectives.append("#elif");
CppDirectives.append("#endif");
CppDirectives.append("#define");
CppDirectives.append("#error");
CppDirectives.append("#pragma");
CppDirectives.append("#line");
// javadoc tags
JavadocTags.append("@author");
JavadocTags.append("@code");
JavadocTags.append("@docRoot");
JavadocTags.append("@deprecated");
JavadocTags.append("@exception");
JavadocTags.append("@inheritDoc");
JavadocTags.append("@link");
JavadocTags.append("@linkplain");
JavadocTags.append("@literal");
JavadocTags.append("@param");
JavadocTags.append("@return");
JavadocTags.append("@see");
JavadocTags.append("@serial");
JavadocTags.append("@serialData");
JavadocTags.append("@serialField");
JavadocTags.append("@since");
JavadocTags.append("@throws");
JavadocTags.append("@value");
JavadocTags.append("@version");
}

View File

@ -36,6 +36,7 @@ enum class StatementKind {
skTypedef,
skClass,
skFunction,
skOperator,
skConstructor,
skDestructor,
skVariable,
@ -85,6 +86,9 @@ using PRemovedStatement = std::shared_ptr<RemovedStatement>;
struct Statement;
using PStatement = std::shared_ptr<Statement>;
using StatementList = QVector<PStatement>;
using PStatementList = std::shared_ptr<StatementList>;
using StatementMap = QMap<QString, PStatementList>;
struct Statement {
std::weak_ptr<Statement> parentScope; // parent class/struct/namespace scope, don't use auto pointer to prevent circular reference
QString hintText; // text to force display when using PrettyPrintStatement
@ -99,20 +103,60 @@ struct Statement {
StatementClassScope classScope; // protected/private/public
bool hasDefinition; // definiton line/filename is valid
int line; // declaration
int endLine;
int definitionLine; // definition
int definitionEndLine;
QString fileName; // declaration
QString definitionFileName; // definition
bool inProject; // statement in project
bool inSystemHeader; // statement in system header (#include <>)
QList<std::weak_ptr<Statement>> children; // Children Statements
QHash<QString,std::weak_ptr<Statement>> childrenMap; //children map index to speedup search
StatementMap children; // functions can be overloaded,so we use list to save children with the same name
QSet<QString> friends; // friend class / functions
bool isStatic; // static function / variable
bool isInherited; // inherted member;
QString fullName; // fullname(including class and namespace)
QString fullName; // fullname(including class and namespace), ClassA::foo
QStringList usingList; // using namespaces
int usageCount; //Usage Count, used by TCodeCompletion
int freqTop; // Usage Count Rank, used by TCodeCompletion
QString noNameArgs;// Args without name
};
struct UsingNamespace {
QStringList namespaces; // List['std','foo'] for using namespace std::foo;
QString filename;
int line;
int endLine;
bool fromHeader;
};
using PUsingNamespace = std::shared_ptr<UsingNamespace>;
struct IncompleteClass {
std::weak_ptr<Statement> statement;
int count;
};
using PIncompleteClass = std::shared_ptr<IncompleteClass>;
struct FileIncludes {
QString baseFile;
QMap<QString,bool> includeFiles; // true means the file is directly included, false means included indirectly
QSet<QString> usings; // namespaces it usings
QVector<std::weak_ptr<Statement>> statements; // but we don't save temporary statements
//StatementsIndex: TDevStringHash;
QVector<std::weak_ptr<Statement>> declaredStatements; // statements declared in this file
QMap<int, std::weak_ptr<Statement>> scopes; // int is start line of the statement scope
QSet<QString> dependingFiles; // The files I depeneds on
QSet<QString> dependedFiles; // the files depends on me
};
using PFileIncludes = std::shared_ptr<FileIncludes>;
extern QStringList CppDirectives;
extern QStringList JavadocTags;
extern QMap<QString,SkipType> CppKeywords;
extern QSet<QString> CppTypeKeywords;
extern QSet<QString> STLPointers;
extern QSet<QString> STLContainers;
extern QSet<QString> STLElementMethods;
void initParser();
#endif // PARSER_UTILS_H

View File

@ -25,6 +25,7 @@ Settings::Settings(const QString &filename):
mDebugger(this),
mHistory(this)
{
load();
}
Settings::~Settings()
@ -69,6 +70,17 @@ QVariant Settings::value(const QString &key, const QVariant &defaultValue)
return mSettings.value(key,defaultValue);
}
void Settings::load()
{
mCompilerSets.loadSets();
mEnvironment.load();
mEditor.load();
mExecutor.load();
mDebugger.load();
mHistory.load();
}
Settings::Dirs &Settings::dirs()
{
return mDirs;