Objective
The recent use of a C + + project requires scripting, which is related to how to bind an object to the script runtime environment. Due to the use of multiple scripting languages, the existing binding technology does not meet the requirements. So you can only seek to parse the C + + header file and then bind it according to the description. At first, there was a set of boost, but the boost was too bloated to have a certain requirement for the development environment after the project. I strive for the most concise project management, boost is not very suitable. Write your own set.
Body
Summary of syntax formatting for C + +
Except for the beginning of the compiler directive # and the function, you must require a semicolon to end
Code blocks except for the IF, Do/while, and for of a single statement must be in curly braces/curly braces "{}"
There are 8 blocks of code, namespaces, global, class, structure, global functions, member functions, lambda, nameless code blocks within functions.
The namespace is the same as the global, with the "namespace::" prefix preceded by the declaration
The difference between a class declaration block and a global block is a friend declaration, a member access permission
Template support classes and functions
function and template have parameter list
A declaration at the end of a semicolon can be a built-in type (int, double, and so on), a class, a template class, a typedef-out type, a function pointer, a lambda
function can have duplicate names
The member functions of a class can be declared after this function definition, not as if the global function must have been declared, so it is not possible to scan a C + + file with a pointer once.
If a class enumeration (enum Class) does not need to be visible to the scope of the declaration, the member is also added to the owning scope at the same time
I'm not going to support it, there's no need for it.
Name space
Template
function body
Comma-separated multiple variables I don't want to be very supportive.
Type of checksum
Default parameters
Union
Enumeration does not judge name collisions
Lambda
Variable names cannot start with a number
Inheritance of Classes
function pointers
Principles of development
No cross-platform, only VS, no system API to adapt to cross-platform
Using C + +
ITER is only in the back
A syntax error or file end is encountered, throwing an exception
Encountered {then entered block processing
The end of the language unit, the function must be processed by itself, and the previous content to return
The member function definition code is not parsed because the first principle cannot be done, and the member function may refer to other member functions that have not yet been declared
Not for the best performance, but can be optimized on this structure to the extreme
Does not seek complete parsing, but in this framework can be done to resolve all c++11 and higher version features
No comments, English is not good, Chinese comments are not suitable for globalization
Structure description
Variant,method,type,comment,enumeration,enumeration_value inherit from object, and they can all belong to the global or class or struct body.
Document represents a C + + compilation unit.
The context is a contextual representation of a queue that can be looked up. After parsing, the document stores the parsed variables, functions, and types.
Reader, a file reader, a forward char iterator that can be substituted with istreambuf_iterator<char> (Ifstream).
Use
The main function has _DEBUG macro protection and is recommended to be compiled for use with library release.
#include <cpp_analysis.h>
Try
{
Auto result = Cpp_analysis::analysis ("[Cpp_header_file]");
Todo
}
catch (logic_error& e)
{
Todo:
}
Project Location
https://github.com/fettluo/cpp_analysis[new Tab Opens]