-
Notifications
You must be signed in to change notification settings - Fork 10
FileParser settings
This section is here to provide a brief description of each of the available settings. Some FileParser settings MUST be set for it to work correctly, but most of them are optional. You can retrieve and manipulate FileParser settings through the ParsingSettings class, which you can get with the following lines:
#include <Kodgen/Parsing/FileParser.h>
//...
kodgen::FileParser fileParser;
kodgen::ParsingSettings& settings = fileParser.getSettings();
//Manipulate settings here
List of all project include directories (target_include_directories in CMake, Project > Properties > C/C++ > Additional Include Directories in Visual Studio). This list allows the parser to localize correctly all the headers included in the parsed files. The FileParser won't be able to parse your code properly with missing project include directories.
settings.addProjectIncludeDirectory("path/to/some/include/directory");
The compiler used to compile the parsed files. This is necessary to locate all the native header files used by the compiler (std headers).
Use ParsingSettings::setCompilerExeName to set the compiler to the correct value. Valid values are "g++", "clang++" and "msvc".
settings.setCompilerExeName("clang++");
Note: If you set "msvc", make sure that vswhere.exe is located next to the generator executable.
Define which c++ standard version to use when parsing the source code. It must match with the c++ version you use to compile your project. Supported values are 17 and 20. The minimum and default value is 17.
settings.cppVersion = 17
Define whether all C++ entities of a given kind should be added to the result data structure or not. Default value is false for all entities except enum values.
settings.shouldParseAllNamespaces = false
settings.shouldParseAllEnumValues = true
Define whether the parsing process should abort if an error is encountered. Default value is true.
Define whether the diagnostic of a file parsing should be logged or not. It might give a hint to the user for potential errors, but can sometimes be misleading (generated by libclang), so use this setting with caution, for debug purposes only. Default value is false. Also, note that you need to provide the FileParser a logger for this setting to work when set to true.
#include <Kodgen/Misc/DefaultLogger.h> //replace by your logger implementation
kodgen::DefaultLogger logger; //replace by your logger implementation
fileParser.logger = &logger;
settings.shouldLogDiagnostic = true;
Name of the macros used to annotate C++ entities for parsing. These macros are also used to attach properties to parsed entities, to take advantage of the PropertyCodeGen feature. See Mark entities for parsing section for more info.
settings.propertyParsingSettings.namespaceMacroName = "Namespace";
settings.propertyParsingSettings.classMacroName = "Class";
settings.propertyParsingSettings.structMacroName = "Struct";
settings.propertyParsingSettings.fieldMacroName = "Variable";
settings.propertyParsingSettings.fieldMacroName = "Field";
settings.propertyParsingSettings.functionMacroName = "Function";
settings.propertyParsingSettings.methodMacroName = "Method";
settings.propertyParsingSettings.enumMacroName = "Enum";
settings.propertyParsingSettings.enumValueMacroName = "EnumVal";
Note: All the macros will be defined in the file "EntityMacros.h" generated by the CodeGenManager before all files are processed. You must include this file to avoid undefined macro errors.
Character used to separate multiple properties. Default value is ','.
settings.propertyParsingSettings.propertySeparator = ',';
Character used to separate arguments of a property. Default value is ','.
settings.propertyParsingSettings.argumentSeparator = ',';
Characters used to start and end arguments of a property. Default values are '(' and ')'.
settings.propertyParsingSettings.argumentSeparator[0] = '(';
settings.propertyParsingSettings.argumentSeparator[1] = ')';
With the above settings, you can now attach properties to entities like so:
#include "Generated/EntityMacros.h" //replace Generated/ by the output directory set in CodeGenUnitSettings
class Class(Property1, Property2(arg1, arg2)) MyClass
{
};
All settings can be loaded from a TOML file with a call to the "loadFromFile" method:
settings.loadFromFile("path/to/your/settingsfile.toml"); //absolute or working directory relative path
A copy of the TOML file is available in the project and the pre-compiled binaries. You can of course remove the settings you don't use. Settings that are not present will conserve their current value.
Here is how it looks like:
cppVersion = 17
compilerExeName = "clang++"
[FileParsingSettings]
projectIncludeDirectories = [
'''Path/To/Your/Project/IncludeDir1''',
'''Path/To/Your/Project/IncludeDir2'''
]
shouldParseAllNamespaces = false
shouldParseAllClasses = false
shouldParseAllStructs = false
shouldParseAllVariables = false
shouldParseAllFields = false
shouldParseAllFunctions = false
shouldParseAllMethods = false
shouldParseAllEnums = false
shouldParseAllEnumValues = true
shouldAbortParsingOnFirstError = true
[FileParsingSettings.Properties]
propertySeparator = ","
subPropertySeparator = ","
subPropertyStartEncloser = "("
subPropertyEndEncloser = ")"
namespaceMacroName = "NAMESPACE"
classMacroName = "CLASS"
structMacroName = "STRUCT"
variableMacroName = "VARIABLE"
fieldMacroName = "FIELD"
functionMacroName = "FUNCTION"
methodMacroName = "METHOD"
enumMacroName = "ENUM"
enumValueMacroName = "ENUMVALUE"
Note: Paths must be enclosed between '''.