eRPC Generator (erpcgen)  Rev. 1.12.0
NXP Semiconductors
erpcgen::PythonGenerator Class Reference

Code generator for Python. More...

#include <PythonGenerator.hpp>

Inheritance diagram for erpcgen::PythonGenerator:
erpcgen::Generator

Public Member Functions

 PythonGenerator (InterfaceDefinition *def)
 This function is constructor of PythonGenerator class. More...
 
virtual ~PythonGenerator ()
 This function is destructor of PythonGenerator class. More...
 
virtual void generate () override
 This function generate output code for output files. More...
 
- Public Member Functions inherited from erpcgen::Generator
 Generator (InterfaceDefinition *def, generator_type_t generatorType)
 Constructor. More...
 
virtual ~Generator ()
 Destructor.
 

Protected Types

enum  comment_type_t {
  comment_type_t::kMultilineComment,
  comment_type_t::kInlineComment
}
 Possible Doxygen comment styles. More...
 

Protected Member Functions

void parseSubtemplates ()
 This function prepare helpful functions located in template files. More...
 
void generateOutputFiles (const std::string &fileName) override
 This function generate output files. More...
 
void generateCommonFile (std::string fileName)
 This function generate output common module. More...
 
void generateInitFile (std::string fileName)
 This function generate output package init file. More...
 
void generateClientFile (std::string fileName)
 This function generate output client file. More...
 
void generateServerFile (std::string fileName)
 This function generate output server file. More...
 
void generateInterfaceFile (std::string fileName)
 This function generate output interface file. More...
 
virtual void generateGlobalInitFile ()
 This function generate output crc16 source file.
 
cpptempl::data_map getFunctionTemplateData (Group *group, Function *fn) override
 This function return interface function template data. More...
 
cpptempl::data_map getFunctionTypeTemplateData (Group *group, FunctionType *fn) override
 This function returns function type (callbacks type) template data. More...
 
void setTemplateComments (Symbol *symbol, cpptempl::data_map &symbolInfo) override
 This function will get symbol comments and convert to language specific ones. More...
 
std::string getFunctionPrototype (Group *group, FunctionBase *fn, const std::string &interfaceName="", const std::string &name="", bool insideInterfaceCall=false) override
 This function return interface function prototype. More...
 
void makeConstTemplateData ()
 This function sets const template data. More...
 
void makeEnumsTemplateData ()
 This function sets enum template data. More...
 
cpptempl::data_map makeGroupSymbolsTemplateData (Group *group) override
 This function sets group symbols template data. More...
 
cpptempl::data_list getEnumMembersTemplateData (EnumType *enumType)
 This function return enum members template data. More...
 
void makeAliasesTemplateData ()
 Fill in template data for type aliases.
 
void setStructMembersTemplateData (StructType *structType, cpptempl::data_map &structInfo)
 This function sets struct member information to struct data map variable. More...
 
void setOneStructMemberTemplateData (StructMember *member, cpptempl::data_map &member_info)
 Fill in template data for a single struct member.
 
cpptempl::data_map getTypeInfo (DataType *t)
 This function return necessary template data for data type. More...
 
std::string getBuiltinTypename (const BuiltinType *t)
 This function return string representation for given BuiltinType. More...
 
std::string filterName (const std::string &name)
 Filter symbol names.
 
std::string convertComment (const std::string &comment, comment_type_t commentType)
 Converts a C++-style Doxygen comment into a Python Doxygen comment. More...
 
std::string stripWhitespace (const std::string &s)
 Strip leading and trailing whitespace. More...
 
bool checkWhitespaceChar (char c)
 Check if character is whitespace type. More...
 
void initPythonReservedWords ()
 
- Protected Member Functions inherited from erpcgen::Generator
void openFile (std::ofstream &fileOutputStream, const std::string &fileName)
 This function open file. More...
 
void generateOutputFile (const std::string &fileName, const std::string &templateName, cpptempl::data_map &templateData, const char *const kParseFile)
 This function open file, generate output into this file and close this file. More...
 
std::string stripExtension (const std::string &filename)
 
StructMemberfindParamReferencedFromAnn (const StructType::member_vector_t &members, const std::string &referenceName, const std::string &annName)
 This function will return pointer to function parameter/structure member where given reference name is referenced for. More...
 
StructMemberfindParamReferencedFromUnion (const StructType::member_vector_t &members, const std::string &referenceName)
 This function will return pointer to function parameter/structure member where given reference name is referenced for. More...
 
StructMemberfindParamReferencedFrom (const StructType::member_vector_t &members, const std::string &referenceName)
 This function will return pointer to function parameter/structure member where given reference name is referenced for. Combines findParamReferencedFromUnion and findParamReferencedFromAnn. More...
 
std::string getTime ()
 This function return actual time string representation. More...
 
void findGroupDataTypes ()
 This function finds all group's data types.
 
virtual DataTypefindChildDataType (std::set< DataType * > &dataTypes, DataType *dataType)
 This function finds child data types of specified data type. More...
 
virtual void setBinaryList (StructMember *structMember)
 This function transform binary data type to list and set annotation to it. More...
 
cpptempl::data_list makeGroupInterfacesTemplateData (Group *group)
 This function sets interfaces template data. More...
 
std::string getGroupCommonFileName (Group *group)
 Function return common fileName part for group generated files. More...
 
void generateGroupOutputFiles (Group *group)
 This function generates output files for defined interfaces. More...
 
void makeIncludesTemplateData ()
 This function sets template data for include directives from an IDL file.
 
cpptempl::data_list makeGroupIncludesTemplateData (Group *group)
 This function sets template data for group include directives. More...
 
GroupgetGroupByName (const std::string &name)
 This function returns pointer to a group with specified name. More...
 
bool isMemberDataTypeUsingForwardDeclaration (Symbol *topSymbol, Symbol *memberSymbol)
 This function returns information if member data type symbol is using forward declared type. More...
 
std::string getOutputName (Symbol *symbol, bool check=true)
 
Annotation::program_lang_t getAnnotationLang ()
 Returns Generator flag used for annotation. More...
 
AnnotationfindAnnotation (Symbol *symbol, const std::string &name)
 Find annotation in the annotation list. More...
 
std::vector< Annotation * > getAnnotations (Symbol *symbol, const std::string &name)
 Find annotations matching name in the annotation list. More...
 
ValuegetAnnValue (Symbol *symbol, const std::string &name)
 This function search and returns Value object for given annotation name. More...
 
std::string getAnnStringValue (Symbol *symbol, const std::string &name)
 This function search and returns string for given annotation name. More...
 
datatype_vector_t getDataTypesFromSymbolScope (SymbolScope *scope, DataType::data_type_t datatype)
 This function returns vector of data types from scope. More...
 

Protected Attributes

std::string m_suffixStrip
 String to remove from suffixes of names.
 
size_t m_suffixStripSize
 Length of the suffix filter string.
 
- Protected Attributes inherited from erpcgen::Generator
uint16_t m_idlCrc16
 
cpptempl::data_map m_templateData
 
InterfaceDefinitionm_def
 
SymbolScopem_globals
 
std::vector< Group * > m_groups
 
std::set< std::string > reserverdWords
 
generator_type_t m_generatorType
 
std::filesystem::path m_outputDirectory
 

Additional Inherited Members

- Public Types inherited from erpcgen::Generator
enum  generator_type_t {
  kC,
  kPython,
  kJava
}
 
typedef std::vector< DataType * > datatype_vector_t
 

Detailed Description

Code generator for Python.

Member Enumeration Documentation

Possible Doxygen comment styles.

Enumerator
kMultilineComment 

Leading multi-line comment.

kInlineComment 

Trailing inline comment.

Constructor & Destructor Documentation

PythonGenerator::PythonGenerator ( InterfaceDefinition def)
explicit

This function is constructor of PythonGenerator class.

Parameters
[in]defContains all Symbols parsed from IDL files.
virtual erpcgen::PythonGenerator::~PythonGenerator ( )
inlinevirtual

This function is destructor of PythonGenerator class.

This function close opened files.

Member Function Documentation

bool PythonGenerator::checkWhitespaceChar ( char  c)
protected

Check if character is whitespace type.

Parameters
[in]cChecked character.
string PythonGenerator::convertComment ( const std::string &  comment,
comment_type_t  commentType 
)
protected

Converts a C++-style Doxygen comment into a Python Doxygen comment.

Parameters
[in,out]commentThe C++ comment.
[in]commentTypeInline or multiline comment.
Returns
Python form of the provided comment.
void PythonGenerator::generate ( )
overridevirtual

This function generate output code for output files.

This code call all necessary functions for prepare output code and parse it into output files.

Implements erpcgen::Generator.

void PythonGenerator::generateClientFile ( std::string  fileName)
protected

This function generate output client file.

Parameters
[in]fileNameName for output files.
void PythonGenerator::generateCommonFile ( std::string  fileName)
protected

This function generate output common module.

Parameters
[in]fileNameName for output files.
void PythonGenerator::generateInitFile ( std::string  fileName)
protected

This function generate output package init file.

Parameters
[in]fileNameName for output files.
void PythonGenerator::generateInterfaceFile ( std::string  fileName)
protected

This function generate output interface file.

Parameters
[in]fileNameName for output files.
void PythonGenerator::generateOutputFiles ( const std::string &  fileName)
overrideprotectedvirtual

This function generate output files.

This function call functions for generating client/server source files.

Parameters
[in]fileNameName for output files.

Implements erpcgen::Generator.

void PythonGenerator::generateServerFile ( std::string  fileName)
protected

This function generate output server file.

Parameters
[in]fileNameName for output files.
string PythonGenerator::getBuiltinTypename ( const BuiltinType t)
protected

This function return string representation for given BuiltinType.

Parameters
[in]tBuiltin type.
Returns
String representation for given builtin type.
data_list PythonGenerator::getEnumMembersTemplateData ( EnumType enumType)
protected

This function return enum members template data.

This function return enum members template data with all data, which are necessary for generating output code for output files.

Parameters
[in]enumTypePointer to enum.
Returns
Contains enum members data.
string PythonGenerator::getFunctionPrototype ( Group group,
FunctionBase fn,
const std::string &  interfaceName = "",
const std::string &  name = "",
bool  insideInterfaceCall = false 
)
overrideprotectedvirtual

This function return interface function prototype.

Parameters
[in]groupGroup to which function belongs.
[in]fnFunction for prototyping.
[in]interfaceNameInterface name used for function declaration.
[in]nameName used for shared code in case of function type.
[in]insideInterfaceCallinterfaceClass specific.
Returns
String prototype representation for given function.

Implements erpcgen::Generator.

data_map PythonGenerator::getFunctionTemplateData ( Group group,
Function fn 
)
overrideprotectedvirtual

This function return interface function template data.

This function return interface function template data with all data, which are necessary for generating output code for output files.

Parameters
[in]groupPointer to a group.
[in]fnFrom this are set interface function template data.
Returns
Contains interface function data.

Implements erpcgen::Generator.

cpptempl::data_map erpcgen::PythonGenerator::getFunctionTypeTemplateData ( Group group,
FunctionType fn 
)
inlineoverrideprotectedvirtual

This function returns function type (callbacks type) template data.

This function returns function type (callbacks type) template data with all data, which are necessary for generating output code for output files. Shim code is generating common function for serialization/deserialization of data.

Parameters
[in]groupGroup to which function belongs.
[in]fnFrom this are set function type template data.
Returns
Contains interface function data.

Implements erpcgen::Generator.

data_map PythonGenerator::getTypeInfo ( DataType t)
protected

This function return necessary template data for data type.

This function return data type template data with all necessary data, which are necessary for generating output code for output files.

Parameters
[in]tData type. From this are set data type template data.
Returns
Contains data type template data.
void PythonGenerator::initPythonReservedWords ( )
protected

Stores reserved words for Python program language.

void PythonGenerator::makeConstTemplateData ( )
protected

This function sets const template data.

This function sets const template data with all data, which are necessary for generating output code for output files.

void PythonGenerator::makeEnumsTemplateData ( )
protected

This function sets enum template data.

This function sets enum template data with all data, which are necessary for generating output code for output files.

data_map PythonGenerator::makeGroupSymbolsTemplateData ( Group group)
overrideprotectedvirtual

This function sets group symbols template data.

This function sets group symbols template data with all data, which are necessary for generating output code for output files.

Parameters
[in]groupPointer to a group.
Returns
Data map with group symbols templates.

Implements erpcgen::Generator.

void PythonGenerator::parseSubtemplates ( )
protected

This function prepare helpful functions located in template files.

These function may be used while parsing templates

void PythonGenerator::setStructMembersTemplateData ( StructType structType,
cpptempl::data_map &  structInfo 
)
protected

This function sets struct member information to struct data map variable.

This function sets struct member information to struct data map variable, which are necessary for generating output code for output files.

Parameters
[in]structTypeStruct, which contains struct members.
[in,out]structInfoData map, which contains information about struct and struct members.
void PythonGenerator::setTemplateComments ( Symbol symbol,
cpptempl::data_map &  symbolInfo 
)
overrideprotectedvirtual

This function will get symbol comments and convert to language specific ones.

Parameters
[in]symbolPointer to symbol.
[in,out]symbolInfoData map, which contains information about symbol.

Implements erpcgen::Generator.

string PythonGenerator::stripWhitespace ( const std::string &  s)
protected

Strip leading and trailing whitespace.

Parameters
[in]sString from which are stripped white spaces.

The documentation for this class was generated from the following files: