| eRPC Generator (erpcgen) Rev. 1.8.1 NXP Semiconductors

- Main Page
- Classes
- Files

- File List

Generator.h
1 /*
2 * Copyright (c) 2014-2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2017 NXP
4 * All rights reserved.
5 *
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 */
9
10 #ifndef _EMBEDDED_RPC__GENERATOR_H_
11 #define _EMBEDDED_RPC__GENERATOR_H_
12
13 #include "InterfaceDefinition.h"
14 #include "cpptempl.h"
15 #include "types/AliasType.h"
16 #include "types/ArrayType.h"
17 #include "types/BuiltinType.h"
18 #include "types/ConstType.h"
19 #include "types/DataType.h"
20 #include "types/EnumMember.h"
21 #include "types/EnumType.h"
22 #include "types/Function.h"
23 #include "types/FunctionType.h"
24 #include "types/Group.h"
25 #include "types/Interface.h"
26 #include "types/ListType.h"
27 #include "types/StructMember.h"
28 #include "types/StructType.h"
29 #include "types/UnionType.h"
30 #include "types/VoidType.h"
31
32 #include <fstream>
33 #include <string>
34
36 // Classes
38
39 namespace erpcgen {
40
44 class Generator
45 {
46 public:
47 enum generator_type_t
48 {
49 kC,
50 kPython
51 };
60 Generator(InterfaceDefinition *def, generator_type_t generatorType);
61
65 virtual ~Generator() {}
66
70 virtual void generate() = 0;
71
72 protected:
73 uint16_t m_idlCrc16;
74 cpptempl::data_map m_templateData;
75 InterfaceDefinition *m_def;
76 SymbolScope *m_globals;
77 std::vector<Group *> m_groups;
78 std::set<std::string> reserverdWords;
79 generator_type_t m_generatorType;
80 boost::filesystem::path m_outputDirectory;
90 void openFile(std::ofstream &fileOutputStream, const std::string &fileName);
91
102 void generateOutputFile(const std::string &fileName, const std::string &templateName,
103 cpptempl::data_map &templateData, const char *const kParseFile);
104
112 std::string stripExtension(const std::string &filename);
113
124 StructMember *findParamReferencedFromAnn(const StructType::member_vector_t &members,
125 const std::string &referenceName, const std::string &annName);
126
136 StructMember *findParamReferencedFromUnion(const StructType::member_vector_t &members,
137 const std::string &referenceName);
138
148 StructMember *findParamReferencedFrom(const StructType::member_vector_t &members, const std::string &referenceName);
149
155 std::string getTime();
156
160 void findGroupDataTypes();
161
172 virtual DataType *findChildDataType(std::set<DataType *> &dataTypes, DataType *dataType);
173
179 virtual void setBinaryList(StructMember *structMember) { (void)structMember; };
180
191 virtual cpptempl::data_map makeGroupSymbolsTemplateData(Group *group) = 0;
192
205 virtual cpptempl::data_map getFunctionTemplateData(Group *group, Function *fn) = 0;
206
213 virtual void setTemplateComments(Symbol *symbol, cpptempl::data_map &symbolInfo) = 0;
214
225 cpptempl::data_list makeGroupInterfacesTemplateData(Group *group);
226
236 virtual void generateOutputFiles(const std::string &fileNameExtension) = 0;
237
243 void generateGroupOutputFiles(Group *group);
244
248 void makeIncludesTemplateData();
249
257 cpptempl::data_list makeGroupIncludesTemplateData(Group *group);
258
266 Group *getGroupByName(std::string name);
267
277 bool isMemberDataTypeUsingForwardDeclaration(Symbol *topSymbol, Symbol *memberSymbol);
278
288 std::string getOutputName(Symbol *symbol, bool check = true);
289
295 Annotation::program_lang_t getAnnotationLang();
296
305 Annotation *findAnnotation(Symbol *symbol, std::string name);
306
315 std::vector<Annotation *> getAnnotations(Symbol *symbol, std::string name);
316
325 Value *getAnnValue(Symbol *symbol, std::string name);
326
335 std::string getAnnStringValue(Symbol *symbol, std::string name);
336
337 private:
348 cpptempl::data_list getFunctionsTemplateData(Group *group, Interface *iface);
349 };
350
351 } // namespace erpcgen
352
353 #endif // _EMBEDDED_RPC__GENERATOR_H_
erpcgen::InterfaceDefinition
Collects all definitions from an IDL.
Definition: InterfaceDefinition.h:31
erpcgen::Generator::setTemplateComments
virtual void setTemplateComments(Symbol *symbol, cpptempl::data_map &symbolInfo)=0
This function will get symbol comments and convert to language specific ones.
erpcgen::Generator::reserverdWords
std::set< std::string > reserverdWords
Definition: Generator.h:78
erpcgen::StructMember
Member of a struct.
Definition: StructMember.h:38
erpcgen::Annotation
Annotation class.
Definition: Annotation.h:28
erpcgen::Generator::getFunctionTemplateData
virtual cpptempl::data_map getFunctionTemplateData(Group *group, Function *fn)=0
This function return interface function template data.
erpcgen::Generator::getAnnotations
std::vector< Annotation * > getAnnotations(Symbol *symbol, std::string name)
Find annotations matching name in the annotation list.
Definition: Generator.cpp:587
erpcgen::Generator::m_generatorType
generator_type_t m_generatorType
Definition: Generator.h:79
erpcgen::Generator::m_groups
std::vector< Group * > m_groups
Definition: Generator.h:77
erpcgen::Generator::m_idlCrc16
uint16_t m_idlCrc16
Definition: Generator.h:73
erpcgen::Generator::makeGroupSymbolsTemplateData
virtual cpptempl::data_map makeGroupSymbolsTemplateData(Group *group)=0
This function sets group symbols template data.
erpcgen::Generator::findParamReferencedFromAnn
StructMember * findParamReferencedFromAnn(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 i...
Definition: Generator.cpp:225
erpcgen::Generator::~Generator
virtual ~Generator()
Destructor.
Definition: Generator.h:65
erpcgen::Generator::makeGroupInterfacesTemplateData
cpptempl::data_list makeGroupInterfacesTemplateData(Group *group)
This function sets interfaces template data.
Definition: Generator.cpp:405
erpcgen::Function
Function declaration.
Definition: Function.h:117
erpcgen::Generator::findParamReferencedFromUnion
StructMember * findParamReferencedFromUnion(const StructType::member_vector_t &members, const std::string &referenceName)
This function will return pointer to function parameter/structure member where given reference name i...
Definition: Generator.cpp:239
erpcgen::Symbol
Base class for all named declarations in the IDL.
Definition: Symbol.h:28
erpcgen::Generator::stripExtension
std::string stripExtension(const std::string &filename)
Definition: Generator.cpp:212
erpcgen::Generator::m_outputDirectory
boost::filesystem::path m_outputDirectory
Definition: Generator.h:80
Value
Abstract base class for values of arbitrary types.
Definition: Value.h:27
erpcgen::Generator::makeGroupIncludesTemplateData
cpptempl::data_list makeGroupIncludesTemplateData(Group *group)
This function sets template data for group include directives.
Definition: Generator.cpp:488
erpcgen::Generator::m_templateData
cpptempl::data_map m_templateData
Definition: Generator.h:74
erpcgen::Generator::makeIncludesTemplateData
void makeIncludesTemplateData()
This function sets template data for include directives from an IDL file.
Definition: Generator.cpp:474
erpcgen::Generator::getTime
std::string getTime()
This function return actual time string representation.
Definition: Generator.cpp:283
erpcgen::SymbolScope
A scoped namespace containing symbols.
Definition: SymbolScope.h:28
erpcgen::Generator
Abstract code generator base class.
Definition: Generator.h:44
erpcgen::Generator::getAnnotationLang
Annotation::program_lang_t getAnnotationLang()
Returns Generator flag used for annotation.
Definition: Generator.cpp:568
erpcgen::Generator::openFile
void openFile(std::ofstream &fileOutputStream, const std::string &fileName)
This function open file.
Definition: Generator.cpp:166
erpcgen::Generator::Generator
Generator(InterfaceDefinition *def, generator_type_t generatorType)
Constructor.
Definition: Generator.cpp:31
erpcgen::DataType
Base class for data types.
Definition: DataType.h:26
erpcgen::Group
An interface that contains functions.
Definition: Group.h:28
erpcgen::Generator::getAnnStringValue
std::string getAnnStringValue(Symbol *symbol, std::string name)
This function search and returns string for given annotation name.
Definition: Generator.cpp:597
erpcgen::Generator::findParamReferencedFrom
StructMember * findParamReferencedFrom(const StructType::member_vector_t &members, const std::string &referenceName)
This function will return pointer to function parameter/structure member where given reference name i...
Definition: Generator.cpp:269
cpptempl::data_map
Definition: cpptempl.h:190
erpcgen::StructType::member_vector_t
std::vector< StructMember * > member_vector_t
Definition: StructType.h:32
erpcgen::Generator::isMemberDataTypeUsingForwardDeclaration
bool isMemberDataTypeUsingForwardDeclaration(Symbol *topSymbol, Symbol *memberSymbol)
This function returns information if member data type symbol is using forward declared type...
Definition: Generator.cpp:524
erpcgen::Generator::generateOutputFiles
virtual void generateOutputFiles(const std::string &fileNameExtension)=0
This function generates output files.
erpcgen::Generator::findGroupDataTypes
void findGroupDataTypes()
This function finds all group&#39;s data types.
Definition: Generator.cpp:358
erpcgen::Interface
An interface that contains functions.
Definition: Interface.h:29
erpcgen::Generator::m_globals
SymbolScope * m_globals
Definition: Generator.h:76
erpcgen::Generator::generateOutputFile
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.
Definition: Generator.cpp:193
erpcgen::Generator::setBinaryList
virtual void setBinaryList(StructMember *structMember)
This function transform binary data type to list and set annotation to it.
Definition: Generator.h:179
erpcgen::Generator::generateGroupOutputFiles
void generateGroupOutputFiles(Group *group)
This function generates output files for defined interfaces.
Definition: Generator.cpp:446
erpcgen::Generator::findAnnotation
Annotation * findAnnotation(Symbol *symbol, std::string name)
Find annotation in the annotation list.
Definition: Generator.cpp:582
erpcgen::Generator::getGroupByName
Group * getGroupByName(std::string name)
This function returns pointer to a group with specified name.
Definition: Generator.cpp:153
erpcgen::Generator::generate
virtual void generate()=0
Generate output files.
erpcgen
Definition: AstNode.h:26
erpcgen::Generator::m_def
InterfaceDefinition * m_def
Definition: Generator.h:75
erpcgen::Generator::getAnnValue
Value * getAnnValue(Symbol *symbol, std::string name)
This function search and returns Value object for given annotation name.
Definition: Generator.cpp:592
erpcgen::Generator::findChildDataType
virtual DataType * findChildDataType(std::set< DataType * > &dataTypes, DataType *dataType)
This function finds child data types of specified data type.
Definition: Generator.cpp:291