devana

Subpackages

devana.configuration

class CommentsParsing(accumulate=True, unpinned_comments_allowed=False, deep_parsing=False, remove_blank_lines=True, remove_asterisks=True)[source]

Bases: IValidateConfig

The class defines how and how extensively the parsing of comments in the code is performed.

accumulate: bool = True

Setting that defines whether consecutive C ++ style one-line comments starting with ‘//’ will be combined into a single collective instance.

deep_parsing: bool = False

Defines parsing of additional content, e.g. comments to function arguments.

remove_asterisks: bool = True

Removal of leading ‘*’ characters from text parsing and subsequent whitespace.

remove_blank_lines: bool = True

If the first and last lines are empty (after initial processing by other rules) they will be deleted.

unpinned_comments_allowed: bool = False

Specifies whether to parse or omit comments that are not attached to the code (they do not precede classes, functions, type definitions, class fields, methods, etc.). This does not affect the parsing of the file preamble.

validate()[source]

This method does not return value. Each problem should be reported as an appropriate exception. This exception will be propagated to the client using the library.

class Configuration(parsing=<factory>, logger=<factory>)[source]

Bases: IValidateConfig

Main configuration.

static get_configuration(this)[source]
logger: <module 'logging' from '/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/logging/__init__.py'>

Currently used standard logger instance.

parsing: ParsingConfiguration

Configuring the parsing of C ++ files, this is how the C ++ code will be transformed into the appropriate python classes instances.

validate()[source]

This method does not return value. Each problem should be reported as an appropriate exception. This exception will be propagated to the client using the library.

class IValidateConfig[source]

Bases: ABC

Every sub-config should implement this interface to provide cohesion and implementation check.

abstract validate()[source]

This method does not return value. Each problem should be reported as an appropriate exception. This exception will be propagated to the client using the library.

class IncludesSet(directories=<factory>)[source]

Bases: IValidateConfig

A set of directories containing header files.

directories: List[Path]
get_compilation_flags()[source]
Return type

List[str]

validate()[source]

This method does not return value. Each problem should be reported as an appropriate exception. This exception will be propagated to the client using the library.

class LanguageStandard(value)[source]

Bases: Enum

Defines, according to the rules, which language version the parsing of files will take place.

CPP_03 = <devana.configuration.LanguageStandard.LanguageStandardData object>
CPP_11 = <devana.configuration.LanguageStandard.LanguageStandardData object>
CPP_17 = <devana.configuration.LanguageStandard.LanguageStandardData object>
CPP_20 = <devana.configuration.LanguageStandard.LanguageStandardData object>
CPP_23 = <devana.configuration.LanguageStandard.LanguageStandardData object>
CPP_98 = <devana.configuration.LanguageStandard.LanguageStandardData object>
C_11 = <devana.configuration.LanguageStandard.LanguageStandardData object>
C_17 = <devana.configuration.LanguageStandard.LanguageStandardData object>
C_89 = <devana.configuration.LanguageStandard.LanguageStandardData object>
C_99 = <devana.configuration.LanguageStandard.LanguageStandardData object>
LanguageStandardData(options, value) = <class 'devana.configuration.LanguageStandard.LanguageStandardData'>[source]
classmethod create_default()[source]
class ParsingConfiguration(comments=<factory>, language_version=<factory>, error_strategy=<factory>, standard_library=<factory>, libraries=<factory>, compiler_commands=<factory>, file_by_file_parsing=False)[source]

Bases: IValidateConfig

Code parser configuration.

comments: CommentsParsing

Comments parsing settings.

compiler_commands: List[str]

Allows you to use any valid clang commands.

error_strategy: ParsingErrorPolicy

Behavior when non-parsable elements are detected.

file_by_file_parsing: bool = False

If true, it does not load all files into memory and builds a full type lexicon for all given files. Instead, it parses files about one another, treating other files as external dependencies. This is a less powerful solution but more economical in terms of RAM. When working with larger projects, we recommend creating multiple modules used sequentially, containing a small slice of local context instead of this option.

language_version: LanguageStandard

C or C++ standard version.

libraries: IncludesSet

Library search directories. It can contain both normal paths to directories, header paths that will support parsing, and paths to the location of an external library that will not be parsed within the module.

parsing_options()[source]
Return type

List[str]

standard_library: StandardLibraryConfiguration

How to provide the language standard library.

validate()[source]

This method does not return value. Each problem should be reported as an appropriate exception. This exception will be propagated to the client using the library.

class ParsingErrorPolicy(value)[source]

Bases: Enum

Rules for dealing with errors when parsing.

ABORT = 3

Throw exception.

IGNORE = 1

Ignore all errors.

LOG = 2

Only log error.

classmethod create_default()[source]
class StandardLibraryConfiguration(mode=<factory>, path=None)[source]

Bases: IValidateConfig

Configuration of std usage.

get_compilation_flags()[source]
Return type

List[str]

mode: StandardLibraryMode

Delivery mode

path: Optional[Path] = None

Path for custom standard library, if any.

validate()[source]

This method does not return value. Each problem should be reported as an appropriate exception. This exception will be propagated to the client using the library.

class StandardLibraryMode(value)[source]

Bases: Enum

C/C++ Standard Library delivery mode.

CUSTOM = 4

Use custom std Library provided by path.

DEVANA_CLANG = 3

Library shipped with Devan. Recommended choice for Linux platform.

NONE = 1

Disable standard library delivery.

PLATFORM = 2

Library provided by the default compiler on your platform, if any are installed.

classmethod create_default()[source]

This feature is platform dependent, trying to return the best way to provide a standard library for a given machine. For macOS platform, you may need to provide libc path from your xcode or other sdk.

Devana is a python tool that make it easy to parsing, format, transform and generate C++ (or C) code. This tool uses libclang to parse the code. Fundamental problems, bugs and missing features of libclang are fixed in Devann’s internal code.

Please note that Devana focuses on the header-level code e.g. class and functions definitions, templates resolving, typedefs and includes. Control statements, arithmetics operations etc. (pure body of functions) are supported as access to raw string field “body”. It is planned to introduce more control over this type of code in future versions. Devana is still under development.