eRPC Generator (erpcgen)  Rev. 1.7.2
NXP Semiconductors
erpcgen::Generator Class Referenceabstract

Abstract code generator base class. More...

#include <Generator.h>

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

Public Types

enum  generator_type_t {
  kC,
  kPython
}
 

Public Member Functions

 Generator (InterfaceDefinition *def, generator_type_t generatorType)
 Constructor. More...
 
virtual ~Generator ()
 Destructor.
 
virtual void generate ()=0
 Generate output files.
 

Protected Member Functions

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...
 
virtual cpptempl::data_map makeGroupSymbolsTemplateData (Group *group)=0
 This function sets group symbols template data. More...
 
virtual cpptempl::data_map getFunctionTemplateData (Group *group, Function *fn)=0
 This function return interface function template data. More...
 
virtual void setTemplateComments (Symbol *symbol, cpptempl::data_map &symbolInfo)=0
 This function will get symbol comments and convert to language specific ones. More...
 
cpptempl::data_list makeGroupInterfacesTemplateData (Group *group)
 This function sets interfaces template data. More...
 
virtual void generateOutputFiles (const std::string &fileNameExtension)=0
 This function generates output 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 (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...
 

Protected Attributes

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
 
boost::filesystem::path m_outputDirectory
 

is used.

This function returns symbol output name. Can be different to getName() when

Parameters
[in]symbolSymbol.
[in]checkCheck if output name is not reserved names.
Returns
Return symbol output name.
std::string getOutputName (Symbol *symbol, bool check=true)
 
Annotation::program_lang_t getAnnotationLang ()
 Returns Generator flag used for annotation. More...
 
AnnotationfindAnnotation (Symbol *symbol, std::string name)
 Find annotation in the annotation list. More...
 
std::vector< Annotation * > getAnnotations (Symbol *symbol, std::string name)
 Find annotations matching name in the annotation list. More...
 
ValuegetAnnValue (Symbol *symbol, std::string name)
 This function search and returns Value object for given annotation name. More...
 
std::string getAnnStringValue (Symbol *symbol, std::string name)
 This function search and returns string for given annotation name. More...
 

Detailed Description

Abstract code generator base class.

Constructor & Destructor Documentation

Generator::Generator ( InterfaceDefinition def,
generator_type_t  generatorType 
)

Constructor.

Interface definition contains all information about parsed files and builtin types.

Parameters
[in]defContains all Symbols parsed from IDL files.

Member Function Documentation

Annotation * Generator::findAnnotation ( Symbol symbol,
std::string  name 
)
protected

Find annotation in the annotation list.

Parameters
[in]symbolSymbol from which is annotation extracted.
[in]nameAnnotation name.
Returns
An index into the annotation list
DataType * Generator::findChildDataType ( std::set< DataType * > &  dataTypes,
DataType dataType 
)
protectedvirtual

This function finds child data types of specified data type.

This function should be overridden by language specific generator, if there is a need to transform data types.

Parameters
[in,out]dataTypesVector of found data types.
[in]dataTypeTop data type.
Returns
Pointer to given or new DataType.
StructMember * Generator::findParamReferencedFrom ( const StructType::member_vector_t members,
const std::string &  referenceName 
)
protected

This function will return pointer to function parameter/structure member where given reference name is referenced for. Combines findParamReferencedFromUnion and findParamReferencedFromAnn.

Parameters
[in]membersMembers contain references members and searched members.
[in]referenceNameName of reference for which is member searched.
Returns
Searched member.
StructMember * Generator::findParamReferencedFromAnn ( const StructType::member_vector_t members,
const std::string &  referenceName,
const std::string &  annName 
)
protected

This function will return pointer to function parameter/structure member where given reference name is referenced for.

Parameters
[in]membersMembers contain references members and searched members.
[in]referenceNameName of reference for which is member searched.
[in]annNameAnnotation name for which is member searched.
Returns
Searched member.
StructMember * Generator::findParamReferencedFromUnion ( const StructType::member_vector_t members,
const std::string &  referenceName 
)
protected

This function will return pointer to function parameter/structure member where given reference name is referenced for.

Parameters
[in]membersMembers contain references members and searched members.
[in]referenceNameName of reference for which is member searched.
Returns
Searched member.
void Generator::generateGroupOutputFiles ( Group group)
protected

This function generates output files for defined interfaces.

Parameters
[in]groupPointer to a group.
void Generator::generateOutputFile ( const std::string &  fileName,
const std::string &  templateName,
cpptempl::data_map templateData,
const char *const  kParseFile 
)
protected

This function open file, generate output into this file and close this file.

Parameters
[in]fileNameOutput file name.
[in]templateNameName of template file, which is used for parser.
[in]templateDataTemplate data used for parser.
[in]kParseFileTemplates strings converted from text file by txt_to_c.py used for parser.
Exceptions
TemplateExceptionThrown, when parse template data into output is not successfully.
virtual void erpcgen::Generator::generateOutputFiles ( const std::string &  fileNameExtension)
protectedpure virtual

This function generates output files.

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

Parameters
[in]fileNameExtensionExtension for file name (for example for case that each interface will be generated in its set of output files).

Implemented in erpcgen::PythonGenerator.

Annotation::program_lang_t Generator::getAnnotationLang ( )
protected

Returns Generator flag used for annotation.

Returns
Generator flag used for annotation.
vector< Annotation * > Generator::getAnnotations ( Symbol symbol,
std::string  name 
)
protected

Find annotations matching name in the annotation list.

Parameters
[in]symbolSymbol from which is annotation extracted.
[in]nameAnnotation name.
Returns
A vector of matching annotations
string Generator::getAnnStringValue ( Symbol symbol,
std::string  name 
)
protected

This function search and returns string for given annotation name.

Parameters
[in]symbolSymbol from which is annotation extracted.
[in]nameGiven annotation name.
Returns
empty string if annotation is not found else string value.
Value * Generator::getAnnValue ( Symbol symbol,
std::string  name 
)
protected

This function search and returns Value object for given annotation name.

Parameters
[in]symbolSymbol from which is annotation extracted.
[in]nameGiven annotation name.
Returns
NULL if annotation is not found else value object.
virtual cpptempl::data_map erpcgen::Generator::getFunctionTemplateData ( Group group,
Function fn 
)
protectedpure virtual

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.
[in]fnIndexFunction index.
Returns
Contains interface function data.

Implemented in erpcgen::PythonGenerator.

Group * Generator::getGroupByName ( std::string  name)
protected

This function returns pointer to a group with specified name.

Parameters
[in]nameName of the searched group.
Returns
Pointer to a group with specified name.
string Generator::getTime ( )
protected

This function return actual time string representation.

Returns
Actual time.
bool Generator::isMemberDataTypeUsingForwardDeclaration ( Symbol topSymbol,
Symbol memberSymbol 
)
protected

This function returns information if member data type symbol is using forward declared type.

Parameters
[in]topSymbolSymbol data type which is using as a member memberSymbol data type.
[in]memberSymbolMember symbol data type of topSymbol.
Return values
Truewhen memberSymbol is using forward declared type.
Falsewhen memberSymbol is not using forward declared type.
data_list Generator::makeGroupIncludesTemplateData ( Group group)
protected

This function sets template data for group include directives.

Parameters
[in]groupPointer to a group.
Returns
List with all group related includes.
data_list Generator::makeGroupInterfacesTemplateData ( Group group)
protected

This function sets interfaces template data.

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

Parameters
[in]groupPointer to a group.
Returns
Data list of interfaces templates.
virtual cpptempl::data_map erpcgen::Generator::makeGroupSymbolsTemplateData ( Group group)
protectedpure virtual

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.

Implemented in erpcgen::PythonGenerator.

void Generator::openFile ( std::ofstream &  fileOutputStream,
const std::string &  fileName 
)
protected

This function open file.

Parameters
[in]fileNameOutput file name.
[in,out]fileOutputStreamOpened output file stream.
Exceptions
std::runtime_errorThrown, when can't create directory.
std::runtime_errorThrown, when file is not open.
virtual void erpcgen::Generator::setBinaryList ( StructMember structMember)
inlineprotectedvirtual

This function transform binary data type to list and set annotation to it.

Parameters
[in]structMemberStructure member, Function parameter or Union member.
virtual void erpcgen::Generator::setTemplateComments ( Symbol symbol,
cpptempl::data_map symbolInfo 
)
protectedpure virtual

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.

Implemented in erpcgen::PythonGenerator.

string Generator::stripExtension ( const std::string &  filename)
protected
Parameters
[in]filename
Returns
Filename with stripped extension

Member Data Documentation

InterfaceDefinition* erpcgen::Generator::m_def
protected

Interface definitions.

generator_type_t erpcgen::Generator::m_generatorType
protected

Type of generator.

SymbolScope* erpcgen::Generator::m_globals
protected

Symbol scope data.

std::vector<Group *> erpcgen::Generator::m_groups
protected

List of groups.

uint16_t erpcgen::Generator::m_idlCrc16
protected

Storing crc16 of IDL files and erpcgen version.

boost::filesystem::path erpcgen::Generator::m_outputDirectory
protected

Output file path.

cpptempl::data_map erpcgen::Generator::m_templateData
protected

Data prepared for templates files.

std::set<std::string> erpcgen::Generator::reserverdWords
protected

Program language reserved words.


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