eRPC Generator (erpcgen)  Rev. 1.7.0
NXP Semiconductors
CGenerator.h
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2014-2016, 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__CGENERATOR_H_
37 #define _EMBEDDED_RPC__CGENERATOR_H_
38 
39 #include "Generator.h"
40 #include "cpptempl.h"
41 #include "types/Group.h"
42 #include <set>
43 
45 // Classes
47 
48 namespace erpcgen {
52 class CGenerator : public Generator
53 {
54 public:
63 
69  virtual ~CGenerator() {}
70 
76  virtual void generate();
77 
78 private:
79  enum _direction
80  {
81  kIn,
82  kOut,
83  kInOut,
84  kNone
85  };
86 
87  cpptempl::data_list m_symbolsTemplate;
89  std::vector<ListType *>
90  m_listBinaryTypes;
96  std::vector<StructType *> m_structListTypes;
107  void parseSubtemplates();
108 
117  void generateOutputFiles(const std::string &fileNameExtension);
118 
124  void generateTypesHeaderFile();
125 
131  void generateCommonHeaderFiles(const std::string &fileName);
132 
138  void generateClientSourceFile(std::string fileName);
139 
145  void generateServerHeaderFile(std::string fileName);
146 
152  void generateServerSourceFile(std::string fileName);
153 
157  virtual void generateCrcFile();
158 
162  void transformAliases();
163 
171  cpptempl::data_map getSymbolTemplateByName(const std::string &name);
172 
185  DataType *findChildDataType(std::set<DataType *> &dataTypes, DataType *dataType);
186 
192  void setBinaryList(StructMember *structMember);
193 
205  cpptempl::data_map getFunctionBaseTemplateData(Group *group, FunctionBase *fn);
206 
218  cpptempl::data_map getFunctionTemplateData(Group *group, Function *fn);
219 
232  cpptempl::data_map getFunctionTypeTemplateData(Group *group, FunctionType *fn);
233 
240  void setTemplateComments(Symbol *symbol, cpptempl::data_map &symbolInfo);
241 
248  void makeConstTemplateData();
249 
250  // Functions that populate type-specific template data
251 
262  cpptempl::data_map makeGroupSymbolsTemplateData(Group *group);
263 
274  cpptempl::data_list makeGroupCallbacksTemplateData(Group *group);
275 
286  cpptempl::data_map getStructDeclarationTemplateData(StructType *structType);
287 
302  cpptempl::data_map getStructDefinitionTemplateData(Group *group, StructType *structType,
303  cpptempl::data_map structInfo);
304 
315  cpptempl::data_map getUnionDeclarationTemplateData(UnionType *unionType);
316 
332  cpptempl::data_map getUnionDefinitionTemplateData(Group *group, UnionType *unionType, cpptempl::data_map &unionInfo,
333  bool &needUnionsServerFree);
343  void setUnionMembersTemplateData(UnionType *unionType, cpptempl::data_map &unionInfo);
344 
356  std::string getUnionMembersData(UnionType *unionType, std::string indent);
357 
364  void makeEnumsTemplateData();
365 
372  void makeSymbolsDeclarationTemplateData();
373 
384  cpptempl::data_map getEnumTemplateData(EnumType *enumType);
385 
396  cpptempl::data_list getEnumMembersTemplateData(EnumType *enumType);
397 
404  void makeAliasesTemplateData();
405 
411  AliasType *getAliasType(DataType *dataType);
412 
418  std::string getAliasName(DataType *dataType);
419 
432  cpptempl::data_map getTypeInfo(DataType *t, bool isFunction);
433 
441  std::string getErrorReturnValue(FunctionBase *fn);
442 
452  std::string getFunctionPrototype(Group *group, FunctionBase *fn, std::string name = "");
453 
462  std::string getFunctionServerCall(Function *fn, FunctionType *functionType = nullptr);
463 
471  std::string generateIncludeGuardName(const std::string &filename);
472 
480  std::string getBuiltinTypename(const BuiltinType *t);
481 
496  std::string getTypenameName(DataType *t, const std::string &name);
497 
513  cpptempl::data_map getEncodeDecodeCall(const std::string &name, Group *group, DataType *t, StructType *structType,
514  bool inDataContainer, StructMember *structMember, bool &needTempVariable,
515  bool isFunctionParam);
516 
526  void getEncodeDecodeBuiltin(Group *group, BuiltinType *t, cpptempl::data_map &templateData, StructType *structType,
527  StructMember *structMember, bool isFunctionParam);
528 
536  void giveBracesToArrays(std::string &name);
537 
547  std::string getExtraDirectionPointer(StructMember *structMember);
548 
558  std::string getExtraPointerInReturn(DataType *dataType);
559 
570  cpptempl::data_map firstAllocOnServerWhenIsNeed(std::string name, StructMember *structMember);
571 
582  cpptempl::data_map firstAllocOnReturnWhenIsNeed(std::string name, DataType *dataType);
583 
592  cpptempl::data_map allocateCall(const std::string &name, Symbol *symbol);
593 
605  void setSymbolDataToSide(const Symbol *symbolType, const std::set<_param_direction> directions,
606  cpptempl::data_list &toClient, cpptempl::data_list &toServer, cpptempl::data_map &dataMap);
607 
616  bool isNeedCallFree(DataType *dataType);
617 
628  void setCallingFreeFunctions(Symbol *symbol, cpptempl::data_map &info, bool returnType);
629 
637  std::string returnSpaceWhenNotEmpty(const std::string &param);
638 
649  bool containsString(DataType *dataType);
650 
661  bool containsList(DataType *dataType);
662 
674  bool containsByrefParamToFree(DataType *dataType, std::set<DataType *> &dataTypes);
675 
686  bool isBinaryStruct(StructType *structType);
687 
698  bool isBinaryList(ListType *listType);
699 
708  bool isListStruct(StructType *structType);
709 
721  bool generateServerFreeFunctions(StructMember *structMember);
722 
731  void setNoSharedAnn(Symbol *parentSymbol, Symbol *childSymbol);
732 
733  bool setDiscriminatorTemp(UnionType *unionType, StructType *structType, StructMember *structMember,
734  bool isFunctionParam, cpptempl::data_map &templateData);
735 
745  std::string getScalarTypename(DataType *dataType);
746 
754  std::string getDirection(_param_direction direction);
755 
764  bool isServerNullParam(StructMember *structMember);
765 
774  bool isPointerParam(StructMember *structMember);
775 
784  bool isNullableParam(StructMember *structMember);
785 
789  void initCReservedWords();
790 
800  void scanStructForAnnotations(StructType *currentStructType, bool isFunction);
801 
811  void checkIfAnnValueIsIntNumberOrIntType(Annotation *ann, StructType *currentStructType);
812 };
813 } // namespace erpcgen
814 
815 #endif // _EMBEDDED_RPC__CGENERATOR_H_
Collects all definitions from an IDL.
Definition: InterfaceDefinition.h:56
Function data type.
Definition: FunctionType.h:56
Member of a struct.
Definition: StructMember.h:63
Annotation class.
Definition: Annotation.h:53
Typedef.
Definition: AliasType.h:51
Represents the builtin atomic types.
Definition: BuiltinType.h:51
Structure data type.
Definition: StructType.h:54
Function declaration.
Definition: Function.h:142
Base class for all named declarations in the IDL.
Definition: Symbol.h:53
virtual ~CGenerator()
This function is destructor of CGenerator class.
Definition: CGenerator.h:69
Variable length list of another data type.
Definition: ListType.h:51
CGenerator(InterfaceDefinition *def)
This function is constructor of CGenerator class.
Definition: CGenerator.cpp:71
Abstract code generator base class.
Definition: Generator.h:69
Base class for data types.
Definition: DataType.h:51
An interface that contains functions.
Definition: Group.h:53
Definition: cpptempl.h:190
Function base declaration.
Definition: Function.h:55
Enumerate data type.
Definition: EnumType.h:53
Discriminated union data type.
Definition: UnionType.h:53
Code generator for C.
Definition: CGenerator.h:52
virtual void generate()
This function generate output code for output files.
Definition: CGenerator.cpp:429
Definition: AstNode.h:51