RedPanda-CPP/RedPandaIDE/parser/parserutils.h

174 lines
5.4 KiB
C
Raw Normal View History

2021-08-05 23:13:21 +08:00
#ifndef PARSER_UTILS_H
#define PARSER_UTILS_H
2021-08-06 11:28:02 +08:00
#include <QMap>
2021-08-05 23:13:21 +08:00
#include <QObject>
2021-08-06 10:58:24 +08:00
#include <QSet>
2021-08-05 23:13:21 +08:00
#include <memory>
// preprocess/ macro define
struct Define {
2021-08-07 18:02:57 +08:00
QString name;
2021-08-05 23:13:21 +08:00
QString args;
QString value;
QString filename;
bool hardCoded;// if true, don't free memory (points to hard defines)
QStringList argList; // args list to format values
QString formatValue; // format template to format values
};
using PDefine = std::shared_ptr<Define>;
2021-08-07 18:02:57 +08:00
using DefineMap = QHash<QString,PDefine>;
using PDefineMap = std::shared_ptr<DefineMap>;
2021-08-05 23:13:21 +08:00
enum class SkipType {
skItself, // skip itself
skToSemicolon, // skip to ;
skToColon, // skip to :
skToRightParenthesis, // skip to )
skToLeftBrace,// Skip to {
skToRightBrace, // skip to }
skNone // It's a keyword but don't process here
};
enum class StatementKind {
skUnknown,
skPreprocessor,
skEnumType,
skEnum,
skTypedef,
skClass,
skFunction,
2021-08-07 14:08:51 +08:00
skOperator,
2021-08-05 23:13:21 +08:00
skConstructor,
skDestructor,
skVariable,
skParameter,
skNamespace,
skNamespaceAlias,
skBlock,
skUserCodeIn, // user code template
skKeyword, // keywords
skGlobalVariable,
skLocalVariable,
skAlias
};
2021-08-06 10:58:24 +08:00
using StatementKindSet = QSet<StatementKind>;
enum class StatementScope {
ssGlobal,
ssLocal,
ssClassLocal
};
enum class StatementClassScope {
scsNone,
scsPrivate,
scsProtected,
scsPublic
};
enum class MemberOperatorType {
otArrow,
otDot,
otDColon,
otOther
};
struct RemovedStatement{
QString type; // type "int"
QString command; // identifier/name of statement "foo"
int definitionLine; // definition
QString definitionFileName; // definition
QString fullName; // fullname(including class and namespace)
QString noNameArgs; // Args without name
};
using PRemovedStatement = std::shared_ptr<RemovedStatement>;
struct Statement;
using PStatement = std::shared_ptr<Statement>;
2021-08-11 11:47:47 +08:00
using StatementList = QList<PStatement>;
2021-08-07 14:08:51 +08:00
using PStatementList = std::shared_ptr<StatementList>;
2021-08-15 16:49:37 +08:00
using StatementMap = QMultiMap<QString, PStatement>;
2021-08-06 10:58:24 +08:00
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
QString type; // type "int"
QString command; // identifier/name of statement "foo"
QString args; // args "(int a,float b)"
QStringList argList;
QString value; // Used for macro defines/typedef, "100" in "#defin COUNT 100"
StatementKind kind; // kind of statement class/variable/function/etc
QList<std::weak_ptr<Statement>> inheritanceList; // list of statements this one inherits from, can be nil
StatementScope scope; // global/local/classlocal
StatementClassScope classScope; // protected/private/public
bool hasDefinition; // definiton line/filename is valid
int line; // declaration
2021-08-07 14:08:51 +08:00
int endLine;
2021-08-06 10:58:24 +08:00
int definitionLine; // definition
2021-08-07 14:08:51 +08:00
int definitionEndLine;
2021-08-06 10:58:24 +08:00
QString fileName; // declaration
2021-08-06 11:28:02 +08:00
QString definitionFileName; // definition
bool inProject; // statement in project
bool inSystemHeader; // statement in system header (#include <>)
2021-08-07 14:08:51 +08:00
StatementMap children; // functions can be overloaded,so we use list to save children with the same name
2021-08-06 11:28:02 +08:00
QSet<QString> friends; // friend class / functions
bool isStatic; // static function / variable
bool isInherited; // inherted member;
2021-08-07 14:08:51 +08:00
QString fullName; // fullname(including class and namespace), ClassA::foo
2021-08-06 11:28:02 +08:00
QStringList usingList; // using namespaces
int usageCount; //Usage Count, used by TCodeCompletion
int freqTop; // Usage Count Rank, used by TCodeCompletion
QString noNameArgs;// Args without name
};
2021-08-07 14:08:51 +08:00
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 {
2021-08-15 16:49:37 +08:00
PStatement statement;
2021-08-07 14:08:51 +08:00
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
2021-08-15 16:49:37 +08:00
StatementMap statements; // but we don't save temporary statements
StatementMap declaredStatements; // statements declared in this file
QMap<int, PStatement> scopes; // int is start line of the statement scope
2021-08-07 14:08:51 +08:00
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();
2021-08-10 21:27:24 +08:00
QString getHeaderFileName(const QString& relativeTo, const QString& line,
2021-08-11 20:06:28 +08:00
const QStringList& includePaths, const QStringList& projectIncludePaths);
2021-08-10 21:27:24 +08:00
QString getLocalHeaderFileName(const QString& relativeTo, const QString& fileName);
2021-08-11 20:06:28 +08:00
QString getSystemHeaderFileName(const QString& fileName, const QStringList& includePaths);
bool isSystemHeaderFile(const QString& fileName, const QStringList& includePaths);
2021-08-15 17:52:39 +08:00
bool isKeyword(const QString& word);
2021-08-05 23:13:21 +08:00
#endif // PARSER_UTILS_H