more ai generated doc with human review
This commit is contained in:
@@ -64,6 +64,8 @@ typedef int (*AccessOffsetFunction)(const char *);
|
||||
//! \~english Type information
|
||||
//! \~russian Информация о типе
|
||||
struct PIP_EXPORT TypeInfo {
|
||||
//! \~english Default constructor
|
||||
//! \~russian Конструктор по умолчанию
|
||||
TypeInfo(const PIConstChars & n = PIConstChars(), const PIConstChars & t = PIConstChars(), PICodeInfo::TypeFlags f = 0, int b = -1) {
|
||||
name = n;
|
||||
type = t;
|
||||
@@ -121,6 +123,8 @@ struct PIP_EXPORT FunctionInfo {
|
||||
//! \~english Class or struct information
|
||||
//! \~russian Информация о классе или структуре
|
||||
struct PIP_EXPORT ClassInfo {
|
||||
//! \~english Default constructor
|
||||
//! \~russian Конструктор по умолчанию
|
||||
ClassInfo() { is_anonymous = false; }
|
||||
|
||||
//! \~english Custom PIMETA content
|
||||
@@ -160,10 +164,14 @@ struct PIP_EXPORT ClassInfo {
|
||||
//! \~english Enumerator information
|
||||
//! \~russian Информация об элементе перечисления
|
||||
struct PIP_EXPORT EnumeratorInfo {
|
||||
//! \~english Default constructor
|
||||
//! \~russian Конструктор по умолчанию
|
||||
EnumeratorInfo(const PIConstChars & n = PIConstChars(), int v = 0) {
|
||||
name = n;
|
||||
value = v;
|
||||
}
|
||||
//! \~english Converts to PIVariantTypes::Enumerator
|
||||
//! \~russian Конвертирует в PIVariantTypes::Enumerator
|
||||
PIVariantTypes::Enumerator toPIVariantEnumerator() { return PIVariantTypes::Enumerator(value, name.toString()); }
|
||||
|
||||
//! \~english Custom PIMETA content
|
||||
@@ -209,6 +217,8 @@ struct PIP_EXPORT EnumInfo {
|
||||
};
|
||||
|
||||
|
||||
//! \~english Output stream operator for TypeInfo
|
||||
//! \~russian Оператор вывода для TypeInfo
|
||||
inline PICout operator<<(PICout s, const PICodeInfo::TypeInfo & v) {
|
||||
if (v.flags[Inline]) s << "inline ";
|
||||
if (v.flags[Virtual]) s << "virtual ";
|
||||
@@ -221,11 +231,15 @@ inline PICout operator<<(PICout s, const PICodeInfo::TypeInfo & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \~english Output stream operator for EnumeratorInfo
|
||||
//! \~russian Оператор вывода для EnumeratorInfo
|
||||
inline PICout operator<<(PICout s, const PICodeInfo::EnumeratorInfo & v) {
|
||||
s << v.name << " = " << v.value << " Meta" << v.meta;
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \~english Output stream operator for ClassInfo
|
||||
//! \~russian Оператор вывода для ClassInfo
|
||||
inline PICout operator<<(PICout s, const PICodeInfo::ClassInfo & v) {
|
||||
s.saveAndSetControls(0);
|
||||
s << "class " << v.name;
|
||||
@@ -262,6 +276,8 @@ inline PICout operator<<(PICout s, const PICodeInfo::ClassInfo & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \~english Output stream operator for EnumInfo
|
||||
//! \~russian Оператор вывода для EnumInfo
|
||||
inline PICout operator<<(PICout s, const PICodeInfo::EnumInfo & v) {
|
||||
s.saveAndSetControls(0);
|
||||
s << "enum " << v.name << " Meta" << v.meta << " {\n";
|
||||
@@ -279,11 +295,19 @@ inline PICout operator<<(PICout s, const PICodeInfo::EnumInfo & v) {
|
||||
}
|
||||
|
||||
|
||||
//! \~english Storage singleton for PICodeInfo
|
||||
//! \~russian Синглтон хранилища для PICodeInfo
|
||||
class PIP_EXPORT __Storage__ {
|
||||
//! \~english Default constructor
|
||||
//! \~russian Конструктор по умолчанию
|
||||
__Storage__();
|
||||
//! \~english Destructor
|
||||
//! \~russian Деструктор
|
||||
~__Storage__();
|
||||
|
||||
public:
|
||||
//! \~english Returns singleton instance
|
||||
//! \~russian Возвращает экземпляр синглтона
|
||||
static __Storage__ * instance();
|
||||
|
||||
PIMap<PIConstChars, PICodeInfo::ClassInfo *> * classesInfo;
|
||||
@@ -296,71 +320,83 @@ private:
|
||||
NO_COPY_CLASS(__Storage__)
|
||||
};
|
||||
|
||||
class PIP_EXPORT
|
||||
__StorageAccess__{public:
|
||||
//! \~english Getter for single storage of PICodeInfo::ClassInfo, access by name
|
||||
//! \~russian Доступ к единому хранилищу PICodeInfo::ClassInfo, доступ по имени
|
||||
static const PIMap<PIConstChars, PICodeInfo::ClassInfo *> & classes(){return *(__Storage__::instance()->classesInfo);
|
||||
} // namespace PICodeInfo
|
||||
//! \~english Access to singleton storage of PICodeInfo
|
||||
//! \~russian Доступ к синглтону хранилища PICodeInfo
|
||||
class PIP_EXPORT __StorageAccess__ {
|
||||
public:
|
||||
//! \~english Getter for single storage of PICodeInfo::ClassInfo, access by name
|
||||
//! \~russian Доступ к единому хранилищу PICodeInfo::ClassInfo, доступ по имени
|
||||
static const PIMap<PIConstChars, PICodeInfo::ClassInfo *> & classes() {
|
||||
return *(__Storage__::instance()->classesInfo);
|
||||
} // namespace PICodeInfo
|
||||
|
||||
//! \~english Getter for single storage of PICodeInfo::EnumInfo, access by name
|
||||
//! \~russian Доступ к единому хранилищу хранилище PICodeInfo::EnumInfo, доступ по имени
|
||||
static const PIMap<PIConstChars, PICodeInfo::EnumInfo *> & enums() {
|
||||
return *(__Storage__::instance()->enumsInfo);
|
||||
}
|
||||
//! \~english Getter for single storage of PICodeInfo::EnumInfo, access by name
|
||||
//! \~russian Доступ к единому хранилищу хранилище PICodeInfo::EnumInfo, доступ по имени
|
||||
static const PIMap<PIConstChars, PICodeInfo::EnumInfo *> & enums() { return *(__Storage__::instance()->enumsInfo); }
|
||||
|
||||
static const PIMap<PIConstChars, PICodeInfo::AccessValueFunction> & accessValueFunctions() {
|
||||
return *(__Storage__::instance()->accessValueFunctions);
|
||||
}
|
||||
//! \~english Access to value functions map
|
||||
//! \~russian Доступ к карте функций значений
|
||||
static const PIMap<PIConstChars, PICodeInfo::AccessValueFunction> & accessValueFunctions() {
|
||||
return *(__Storage__::instance()->accessValueFunctions);
|
||||
}
|
||||
|
||||
static const PIMap<PIConstChars, PICodeInfo::AccessTypeFunction> & accessTypeFunctions() {
|
||||
return *(__Storage__::instance()->accessTypeFunctions);
|
||||
}
|
||||
//! \~english Access to type functions map
|
||||
//! \~russian Доступ к карте функций типов
|
||||
static const PIMap<PIConstChars, PICodeInfo::AccessTypeFunction> & accessTypeFunctions() {
|
||||
return *(__Storage__::instance()->accessTypeFunctions);
|
||||
}
|
||||
|
||||
static const PIMap<PIConstChars, PICodeInfo::AccessOffsetFunction> & accessOffsetFunctions() {
|
||||
return *(__Storage__::instance()->accessOffsetFunctions);
|
||||
}
|
||||
}
|
||||
;
|
||||
//! \~english Access to offset functions map
|
||||
//! \~russian Доступ к карте функций смещений
|
||||
static const PIMap<PIConstChars, PICodeInfo::AccessOffsetFunction> & accessOffsetFunctions() {
|
||||
return *(__Storage__::instance()->accessOffsetFunctions);
|
||||
}
|
||||
};
|
||||
|
||||
#define PICODEINFO PICodeInfo::__StorageAccess__
|
||||
|
||||
|
||||
class PIP_EXPORT
|
||||
ClassInfoInterface{public: const PIMap<PIConstChars, PICodeInfo::ClassInfo *> * operator->() const DEPRECATEDM("use PICODEINFO::classes()"){
|
||||
return __Storage__::instance() -> classesInfo;
|
||||
}
|
||||
}
|
||||
;
|
||||
//! \~english Deprecated interface for accessing classes info
|
||||
//! \~russian Устаревший интерфейс для доступа к информации о классах
|
||||
class PIP_EXPORT ClassInfoInterface {
|
||||
public:
|
||||
const PIMap<PIConstChars, PICodeInfo::ClassInfo *> * operator->() const DEPRECATEDM("use PICODEINFO::classes()") {
|
||||
return __Storage__::instance()->classesInfo;
|
||||
}
|
||||
};
|
||||
static ClassInfoInterface classesInfo;
|
||||
|
||||
|
||||
class PIP_EXPORT
|
||||
EnumsInfoInterface{public: const PIMap<PIConstChars, PICodeInfo::EnumInfo *> * operator->() const DEPRECATEDM("use PICODEINFO::enums()"){
|
||||
return __Storage__::instance() -> enumsInfo;
|
||||
}
|
||||
}
|
||||
;
|
||||
//! \~english Deprecated interface for accessing enums info
|
||||
//! \~russian Устаревший интерфейс для доступа к информации о перечислениях
|
||||
class PIP_EXPORT EnumsInfoInterface {
|
||||
public:
|
||||
const PIMap<PIConstChars, PICodeInfo::EnumInfo *> * operator->() const DEPRECATEDM("use PICODEINFO::enums()") {
|
||||
return __Storage__::instance()->enumsInfo;
|
||||
}
|
||||
};
|
||||
static EnumsInfoInterface enumsInfo;
|
||||
|
||||
|
||||
class PIP_EXPORT AccessValueFunctionInterface{
|
||||
public: const PIMap<PIConstChars, PICodeInfo::AccessValueFunction> * operator->()
|
||||
const DEPRECATEDM("use PICODEINFO::accessValueFunctions()"){
|
||||
return __Storage__::instance() -> accessValueFunctions;
|
||||
}
|
||||
}
|
||||
;
|
||||
//! \~english Deprecated interface for accessing value functions
|
||||
//! \~russian Устаревший интерфейс для доступа к функциям значений
|
||||
class PIP_EXPORT AccessValueFunctionInterface {
|
||||
public:
|
||||
const PIMap<PIConstChars, PICodeInfo::AccessValueFunction> * operator->() const DEPRECATEDM("use PICODEINFO::accessValueFunctions()") {
|
||||
return __Storage__::instance()->accessValueFunctions;
|
||||
}
|
||||
};
|
||||
static AccessValueFunctionInterface accessValueFunctions;
|
||||
|
||||
|
||||
class PIP_EXPORT AccessTypeFunctionInterface{
|
||||
public: const PIMap<PIConstChars, PICodeInfo::AccessTypeFunction> * operator->()
|
||||
const DEPRECATEDM("use PICODEINFO::accessTypeFunctions()"){
|
||||
return __Storage__::instance() -> accessTypeFunctions;
|
||||
}
|
||||
}
|
||||
;
|
||||
//! \~english Deprecated interface for accessing type functions
|
||||
//! \~russian Устаревший интерфейс для доступа к функциям типов
|
||||
class PIP_EXPORT AccessTypeFunctionInterface {
|
||||
public:
|
||||
const PIMap<PIConstChars, PICodeInfo::AccessTypeFunction> * operator->() const DEPRECATEDM("use PICODEINFO::accessTypeFunctions()") {
|
||||
return __Storage__::instance()->accessTypeFunctions;
|
||||
}
|
||||
};
|
||||
static AccessTypeFunctionInterface accessTypeFunctions;
|
||||
|
||||
|
||||
@@ -372,6 +408,8 @@ STATIC_INITIALIZER_BEGIN
|
||||
STATIC_INITIALIZER_END
|
||||
|
||||
|
||||
//! \~english Gets member value as PIByteArray
|
||||
//! \~russian Получает значение члена как PIByteArray
|
||||
inline PIByteArray getMemberValue(const void * p, const char * class_name, const char * member_name) {
|
||||
if (!p || !class_name || !member_name) return PIByteArray();
|
||||
AccessValueFunction af = PICODEINFO::accessValueFunctions().value(class_name, (AccessValueFunction)0);
|
||||
@@ -379,6 +417,8 @@ inline PIByteArray getMemberValue(const void * p, const char * class_name, const
|
||||
return af(p, member_name);
|
||||
}
|
||||
|
||||
//! \~english Gets member type as string
|
||||
//! \~russian Получает тип члена как строку
|
||||
inline const char * getMemberType(const char * class_name, const char * member_name) {
|
||||
if (!class_name || !member_name) return "";
|
||||
AccessTypeFunction af = PICODEINFO::accessTypeFunctions().value(class_name, (AccessTypeFunction)0);
|
||||
@@ -386,14 +426,20 @@ inline const char * getMemberType(const char * class_name, const char * member_n
|
||||
return af(member_name);
|
||||
}
|
||||
|
||||
//! \~english Gets member value as PIVariant
|
||||
//! \~russian Получает значение члена как PIVariant
|
||||
PIP_EXPORT PIVariant getMemberAsVariant(const void * p, const char * class_name, const char * member_name);
|
||||
|
||||
|
||||
//! \~english Serializes value to PIByteArray (for assignable types)
|
||||
//! \~russian Сериализует значение в PIByteArray (для назначаемых типов)
|
||||
template<typename T, typename std::enable_if<std::is_assignable<T &, const T &>::value, int>::type = 0>
|
||||
void serialize(PIByteArray & ret, const T & v) {
|
||||
ret << v;
|
||||
}
|
||||
|
||||
//! \~english Empty serialization (for non-assignable types)
|
||||
//! \~russian Пустая сериализация (для неназначаемых типов)
|
||||
template<typename T, typename std::enable_if<!std::is_assignable<T &, const T &>::value, int>::type = 0>
|
||||
void serialize(PIByteArray & ret, const T & v) {}
|
||||
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
/*! \file picodeparser.h
|
||||
* \ingroup Code
|
||||
* \~\brief
|
||||
* \addtogroup Code
|
||||
* \{
|
||||
* \~
|
||||
* \brief
|
||||
* \~english C++ code parser
|
||||
* \~russian Разбор C++ кода
|
||||
* \details
|
||||
* \~english Parser for analyzing C++ source files. Extracts information about classes, structures, enums, macros, functions, and members.
|
||||
* \~russian Парсер для анализа C++ исходных файлов. Извлекает информацию о классах, структурах, перечислениях, макросах, функциях и членах.
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
@@ -39,6 +44,8 @@ inline bool _isCChar(const PIString & c) {
|
||||
|
||||
class PIP_EXPORT PICodeParser {
|
||||
public:
|
||||
//! \~english Default constructor.
|
||||
//! \~russian Конструктор по умолчанию.
|
||||
PICodeParser();
|
||||
|
||||
enum Visibility {
|
||||
@@ -63,18 +70,27 @@ public:
|
||||
typedef PIPair<PIString, PIString> Typedef;
|
||||
typedef PIMap<PIString, PIString> MetaMap;
|
||||
|
||||
//! \~english Represents a preprocessor macro.
|
||||
//! \~russian Представляет препроцессорный макрос.
|
||||
struct PIP_EXPORT Macro {
|
||||
Macro(const PIString & n = PIString(), const PIString & v = PIString(), const PIStringList & a = PIStringList()) {
|
||||
name = n;
|
||||
value = v;
|
||||
args = a;
|
||||
}
|
||||
//! \~english Expand macro with given arguments.
|
||||
//! \~russian Раскрыть макрос с заданными аргументами.
|
||||
//! \param args_ Arguments string
|
||||
//! \param ok Output flag indicating success
|
||||
//! \return Expanded macro value
|
||||
PIString expand(PIString args_, bool * ok = 0) const;
|
||||
PIString name;
|
||||
PIString value;
|
||||
PIStringList args;
|
||||
};
|
||||
|
||||
//! \~english Represents a class/struct member variable or function.
|
||||
//! \~russian Представляет переменную-член или функцию класса/структуры.
|
||||
struct PIP_EXPORT Member {
|
||||
Member() {
|
||||
visibility = Global;
|
||||
@@ -83,6 +99,8 @@ public:
|
||||
is_type_ptr = false;
|
||||
attributes = NoAttributes;
|
||||
}
|
||||
//! \~english Check if member is a bitfield.
|
||||
//! \~russian Проверить, является ли член битовым полем.
|
||||
bool isBitfield() const { return bits > 0; }
|
||||
MetaMap meta;
|
||||
PIString type;
|
||||
@@ -97,6 +115,8 @@ public:
|
||||
int bits;
|
||||
};
|
||||
|
||||
//! \~english Represents a parsed entity (class, struct, namespace, etc.).
|
||||
//! \~russian Представляет разобранную сущность (класс, структуру, пространство имен и т.д.).
|
||||
struct PIP_EXPORT Entity {
|
||||
Entity() {
|
||||
visibility = Global;
|
||||
@@ -118,6 +138,8 @@ public:
|
||||
PIVector<Typedef> typedefs;
|
||||
};
|
||||
|
||||
//! \~english Represents an enumerator value.
|
||||
//! \~russian Представляет значение перечисления.
|
||||
struct PIP_EXPORT EnumeratorInfo {
|
||||
EnumeratorInfo(const PIString & n = PIString(), int v = 0, const MetaMap & m = MetaMap()) {
|
||||
name = n;
|
||||
@@ -129,6 +151,8 @@ public:
|
||||
int value;
|
||||
};
|
||||
|
||||
//! \~english Represents a parsed enum type.
|
||||
//! \~russian Представляет разобранный тип перечисления.
|
||||
struct PIP_EXPORT Enum {
|
||||
Enum(const PIString & n = PIString()) { name = n; }
|
||||
MetaMap meta;
|
||||
@@ -136,25 +160,89 @@ public:
|
||||
PIVector<EnumeratorInfo> members;
|
||||
};
|
||||
|
||||
//! \~english Parse C++ source file.
|
||||
//! \~russian Разбор C++ исходного файла.
|
||||
//! \param file Path to source file
|
||||
//! \param follow_includes Whether to follow include directives
|
||||
void parseFile(const PIString & file, bool follow_includes = true);
|
||||
|
||||
//! \~english Parse multiple C++ source files.
|
||||
//! \~russian Разбор нескольких C++ исходных файлов.
|
||||
//! \param files List of file paths
|
||||
//! \param follow_includes Whether to follow include directives
|
||||
void parseFiles(const PIStringList & files, bool follow_includes = true);
|
||||
|
||||
//! \~english Parse C++ source from string content.
|
||||
//! \~russian Разбор C++ исходного кода из строки.
|
||||
//! \param fc Source code content
|
||||
void parseFileContent(PIString fc);
|
||||
|
||||
//! \~english Add directory to search for include files.
|
||||
//! \~russian Добавить директорию для поиска включаемых файлов.
|
||||
//! \param dir Directory path
|
||||
void includeDirectory(const PIString & dir) { includes << dir; }
|
||||
|
||||
//! \~english Add custom macro definition.
|
||||
//! \~russian Добавить пользовательское определение макроса.
|
||||
//! \param def_name Macro name
|
||||
//! \param def_value Macro value
|
||||
void addDefine(const PIString & def_name, const PIString & def_value) { custom_defines << Define(def_name, def_value); }
|
||||
|
||||
//! \~english Check if name refers to an enum type.
|
||||
//! \~russian Проверить, является ли имя типом перечисления.
|
||||
//! \param name Name to check
|
||||
//! \return true if name is an enum
|
||||
bool isEnum(const PIString & name);
|
||||
|
||||
//! \~english Find entity by name.
|
||||
//! \~russian Найти сущность по имени.
|
||||
//! \param en Entity name
|
||||
//! \return Pointer to entity or nullptr
|
||||
Entity * findEntityByName(const PIString & en);
|
||||
|
||||
//! \~english Get list of parsed files.
|
||||
//! \~russian Получить список разобранных файлов.
|
||||
//! \return List of file paths
|
||||
PIStringList parsedFiles() const { return PIStringList(proc_files.toVector()); }
|
||||
|
||||
//! \~english Get main file path.
|
||||
//! \~russian Получить путь к главному файлу.
|
||||
//! \return Main file path
|
||||
PIString mainFile() const { return main_file; }
|
||||
|
||||
//! \~english Get global scope entity.
|
||||
//! \~russian Получить сущность глобальной области видимости.
|
||||
//! \return Pointer to global entity
|
||||
const PICodeParser::Entity * global() const { return &root_; }
|
||||
|
||||
//! \~english Get maximum iterations for macros substitution.
|
||||
//! \~russian Получить максимальное количество итераций для подстановки макросов.
|
||||
//! \return Maximum iterations count
|
||||
int macrosSubstitutionMaxIterations() const { return macros_iter; }
|
||||
|
||||
//! \~english Set maximum iterations for macros substitution.
|
||||
//! \~russian Установить максимальное количество итераций для подстановки макросов.
|
||||
//! \param value Maximum iterations count
|
||||
void setMacrosSubstitutionMaxIterations(int value) { macros_iter = value; }
|
||||
|
||||
//! \~english List of defined macros.
|
||||
//! \~russian Список определенных макросов.
|
||||
PIVector<Define> defines, custom_defines;
|
||||
|
||||
//! \~english List of macro definitions with expansion.
|
||||
//! \~russian Список определений макросов с подстановкой.
|
||||
PIVector<Macro> macros;
|
||||
|
||||
//! \~english List of enumerated types.
|
||||
//! \~russian Список типов перечислений.
|
||||
PIVector<Enum> enums;
|
||||
|
||||
//! \~english List of type definitions.
|
||||
//! \~russian Список определений типов.
|
||||
PIVector<Typedef> typedefs;
|
||||
|
||||
//! \~english List of parsed entities (classes, structs, etc.).
|
||||
//! \~russian Список разобранных сущностей (классов, структур и т.д.).
|
||||
PIVector<Entity *> entities;
|
||||
|
||||
private:
|
||||
@@ -195,4 +283,7 @@ private:
|
||||
PIMap<PIString, MetaMap> tmp_meta;
|
||||
};
|
||||
|
||||
/*! \}
|
||||
*/
|
||||
|
||||
#endif // PICODEPARSER_H
|
||||
|
||||
Reference in New Issue
Block a user