eRPC Generator (erpcgen)  Rev. 1.7.0
NXP Semiconductors
Generator.h
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2014-2015, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted (subject to the limitations in the disclaimer below) provided
10  * that the following conditions are met:
11  *
12  * o Redistributions of source code must retain the above copyright notice, this list
13  * of conditions and the following disclaimer.
14  *
15  * o Redistributions in binary form must reproduce the above copyright notice, this
16  * list of conditions and the following disclaimer in the documentation and/or
17  * other materials provided with the distribution.
18  *
19  * o Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from this
21  * software without specific prior written permission.
22  *
23  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _EMBEDDED_RPC__GENERATOR_H_
37 #define _EMBEDDED_RPC__GENERATOR_H_
38 
39 #include "InterfaceDefinition.h"
40 #include "cpptempl.h"
41 #include "types/AliasType.h"
42 #include "types/ArrayType.h"
43 #include "types/BuiltinType.h"
44 #include "types/ConstType.h"
45 #include "types/DataType.h"
46 #include "types/EnumMember.h"
47 #include "types/EnumType.h"
48 #include "types/Function.h"
49 #include "types/FunctionType.h"
50 #include "types/Group.h"
51 #include "types/Interface.h"
52 #include "types/ListType.h"
53 #include "types/StructMember.h"
54 #include "types/StructType.h"
55 #include "types/UnionType.h"
56 #include "types/VoidType.h"
57 #include <fstream>
58 #include <string>
59 
61 // Classes
63 
64 namespace erpcgen {
65 
69 class Generator
70 {
71 public:
72  enum generator_type_t
73  {
74  kC,
75  kPython
76  };
85  Generator(InterfaceDefinition *def, generator_type_t generatorType);
86 
90  virtual ~Generator() {}
91 
95  virtual void generate() = 0;
96 
97 protected:
98  uint16_t m_idlCrc16;
102  std::vector<Group *> m_groups;
103  std::set<std::string> reserverdWords;
104  generator_type_t m_generatorType;
105  boost::filesystem::path m_outputDirectory;
115  void openFile(std::ofstream &fileOutputStream, const std::string &fileName);
116 
127  void generateOutputFile(const std::string &fileName, const std::string &templateName,
128  cpptempl::data_map &templateData, const char *const kParseFile);
129 
137  std::string stripExtension(const std::string &filename);
138 
150  const std::string &referenceName, const std::string &annName);
151 
162  const std::string &referenceName);
163 
173  StructMember *findParamReferencedFrom(const StructType::member_vector_t &members, const std::string &referenceName);
174 
180  std::string getTime();
181 
185  void findGroupDataTypes();
186 
197  virtual DataType *findChildDataType(std::set<DataType *> &dataTypes, DataType *dataType);
198 
204  virtual void setBinaryList(StructMember *structMember){};
205 
217 
230  virtual cpptempl::data_map getFunctionTemplateData(Group *group, Function *fn) = 0;
231 
238  virtual void setTemplateComments(Symbol *symbol, cpptempl::data_map &symbolInfo) = 0;
239 
250  cpptempl::data_list makeGroupInterfacesTemplateData(Group *group);
251 
261  virtual void generateOutputFiles(const std::string &fileNameExtension) = 0;
262 
268  void generateGroupOutputFiles(Group *group);
269 
274 
282  cpptempl::data_list makeGroupIncludesTemplateData(Group *group);
283 
291  Group *getGroupByName(std::string name);
292 
302  bool isMemberDataTypeUsingForwardDeclaration(Symbol *topSymbol, Symbol *memberSymbol);
303 
313  std::string getOutputName(Symbol *symbol, bool check = true);
314 
320  Annotation::program_lang_t getAnnotationLang();
321 
330  Annotation *findAnnotation(Symbol *symbol, std::string name);
331 
340  std::vector<Annotation *> getAnnotations(Symbol *symbol, std::string name);
341 
350  Value *getAnnValue(Symbol *symbol, std::string name);
351 
360  std::string getAnnStringValue(Symbol *symbol, std::string name);
361 
362 private:
373  cpptempl::data_list getFunctionsTemplateData(Group *group, Interface *iface);
374 };
375 
376 } // namespace erpcgen
377 
378 #endif // _EMBEDDED_RPC__GENERATOR_H_
Collects all definitions from an IDL.
Definition: InterfaceDefinition.h:56
virtual void setTemplateComments(Symbol *symbol, cpptempl::data_map &symbolInfo)=0
This function will get symbol comments and convert to language specific ones.
std::set< std::string > reserverdWords
Definition: Generator.h:103
Member of a struct.
Definition: StructMember.h:63
Annotation class.
Definition: Annotation.h:53
virtual cpptempl::data_map getFunctionTemplateData(Group *group, Function *fn)=0
This function return interface function template data.
std::vector< Annotation * > getAnnotations(Symbol *symbol, std::string name)
Find annotations matching name in the annotation list.
Definition: Generator.cpp:618
generator_type_t m_generatorType
Definition: Generator.h:104
std::vector< Group * > m_groups
Definition: Generator.h:102
uint16_t m_idlCrc16
Definition: Generator.h:98
virtual cpptempl::data_map makeGroupSymbolsTemplateData(Group *group)=0
This function sets group symbols template data.
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:250
virtual ~Generator()
Destructor.
Definition: Generator.h:90
cpptempl::data_list makeGroupInterfacesTemplateData(Group *group)
This function sets interfaces template data.
Definition: Generator.cpp:436
Function declaration.
Definition: Function.h:142
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:264
Base class for all named declarations in the IDL.
Definition: Symbol.h:53
std::string stripExtension(const std::string &filename)
Definition: Generator.cpp:237
boost::filesystem::path m_outputDirectory
Definition: Generator.h:105
Abstract base class for values of arbitrary types.
Definition: Value.h:47
cpptempl::data_list makeGroupIncludesTemplateData(Group *group)
This function sets template data for group include directives.
Definition: Generator.cpp:519
cpptempl::data_map m_templateData
Definition: Generator.h:99
void makeIncludesTemplateData()
This function sets template data for include directives from an IDL file.
Definition: Generator.cpp:505
std::string getTime()
This function return actual time string representation.
Definition: Generator.cpp:308
A scoped namespace containing symbols.
Definition: SymbolScope.h:53
Abstract code generator base class.
Definition: Generator.h:69
Annotation::program_lang_t getAnnotationLang()
Returns Generator flag used for annotation.
Definition: Generator.cpp:599
void openFile(std::ofstream &fileOutputStream, const std::string &fileName)
This function open file.
Definition: Generator.cpp:191
Generator(InterfaceDefinition *def, generator_type_t generatorType)
Constructor.
Definition: Generator.cpp:54
Base class for data types.
Definition: DataType.h:51
An interface that contains functions.
Definition: Group.h:53
std::string getAnnStringValue(Symbol *symbol, std::string name)
This function search and returns string for given annotation name.
Definition: Generator.cpp:628
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:294
Definition: cpptempl.h:190
std::vector< StructMember * > member_vector_t
Definition: StructType.h:57
bool isMemberDataTypeUsingForwardDeclaration(Symbol *topSymbol, Symbol *memberSymbol)
This function returns information if member data type symbol is using forward declared type...
Definition: Generator.cpp:555
virtual void generateOutputFiles(const std::string &fileNameExtension)=0
This function generates output files.
void findGroupDataTypes()
This function finds all group&#39;s data types.
Definition: Generator.cpp:389
An interface that contains functions.
Definition: Interface.h:54
SymbolScope * m_globals
Definition: Generator.h:101
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:218
virtual void setBinaryList(StructMember *structMember)
This function transform binary data type to list and set annotation to it.
Definition: Generator.h:204
void generateGroupOutputFiles(Group *group)
This function generates output files for defined interfaces.
Definition: Generator.cpp:477
Annotation * findAnnotation(Symbol *symbol, std::string name)
Find annotation in the annotation list.
Definition: Generator.cpp:613
Group * getGroupByName(std::string name)
This function returns pointer to a group with specified name.
Definition: Generator.cpp:178
virtual void generate()=0
Generate output files.
Definition: AstNode.h:51
InterfaceDefinition * m_def
Definition: Generator.h:100
Value * getAnnValue(Symbol *symbol, std::string name)
This function search and returns Value object for given annotation name.
Definition: Generator.cpp:623
virtual DataType * findChildDataType(std::set< DataType * > &dataTypes, DataType *dataType)
This function finds child data types of specified data type.
Definition: Generator.cpp:316