eRPC Generator (erpcgen)  Rev. 1.7.2
NXP Semiconductors
CGenerator.h
1 /*
2  * Copyright (c) 2014-2016, 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__CGENERATOR_H_
11 #define _EMBEDDED_RPC__CGENERATOR_H_
12 
13 #include "Generator.h"
14 #include "cpptempl.h"
15 #include "types/Group.h"
16 #include <set>
17 
19 // Classes
21 
22 namespace erpcgen {
26 class CGenerator : public Generator
27 {
28 public:
37 
43  virtual ~CGenerator() {}
44 
50  virtual void generate();
51 
52 private:
53  enum _direction
54  {
55  kIn,
56  kOut,
57  kInOut,
58  kNone
59  };
60 
61  cpptempl::data_list m_symbolsTemplate;
63  std::vector<ListType *>
64  m_listBinaryTypes;
70  std::vector<StructType *> m_structListTypes;
81  void parseSubtemplates();
82 
91  void generateOutputFiles(const std::string &fileNameExtension);
92 
98  void generateTypesHeaderFile();
99 
105  void generateCommonHeaderFiles(const std::string &fileName);
106 
112  void generateClientSourceFile(std::string fileName);
113 
119  void generateServerHeaderFile(std::string fileName);
120 
126  void generateServerSourceFile(std::string fileName);
127 
131  virtual void generateCrcFile();
132 
136  void transformAliases();
137 
145  cpptempl::data_map getSymbolTemplateByName(const std::string &name);
146 
159  DataType *findChildDataType(std::set<DataType *> &dataTypes, DataType *dataType);
160 
166  void setBinaryList(StructMember *structMember);
167 
179  cpptempl::data_map getFunctionBaseTemplateData(Group *group, FunctionBase *fn);
180 
192  cpptempl::data_map getFunctionTemplateData(Group *group, Function *fn);
193 
206  cpptempl::data_map getFunctionTypeTemplateData(Group *group, FunctionType *fn);
207 
214  void setTemplateComments(Symbol *symbol, cpptempl::data_map &symbolInfo);
215 
222  void makeConstTemplateData();
223 
224  // Functions that populate type-specific template data
225 
236  cpptempl::data_map makeGroupSymbolsTemplateData(Group *group);
237 
248  cpptempl::data_list makeGroupCallbacksTemplateData(Group *group);
249 
260  cpptempl::data_map getStructDeclarationTemplateData(StructType *structType);
261 
276  cpptempl::data_map getStructDefinitionTemplateData(Group *group, StructType *structType,
277  cpptempl::data_map structInfo);
278 
289  cpptempl::data_map getUnionDeclarationTemplateData(UnionType *unionType);
290 
306  cpptempl::data_map getUnionDefinitionTemplateData(Group *group, UnionType *unionType, cpptempl::data_map &unionInfo,
307  bool &needUnionsServerFree);
317  void setUnionMembersTemplateData(UnionType *unionType, cpptempl::data_map &unionInfo);
318 
330  std::string getUnionMembersData(UnionType *unionType, std::string indent);
331 
338  void makeEnumsTemplateData();
339 
346  void makeSymbolsDeclarationTemplateData();
347 
358  cpptempl::data_map getEnumTemplateData(EnumType *enumType);
359 
370  cpptempl::data_list getEnumMembersTemplateData(EnumType *enumType);
371 
378  void makeAliasesTemplateData();
379 
385  AliasType *getAliasType(DataType *dataType);
386 
392  std::string getAliasName(DataType *dataType);
393 
406  cpptempl::data_map getTypeInfo(DataType *t, bool isFunction);
407 
415  std::string getErrorReturnValue(FunctionBase *fn);
416 
426  std::string getFunctionPrototype(Group *group, FunctionBase *fn, std::string name = "");
427 
436  std::string getFunctionServerCall(Function *fn, FunctionType *functionType = nullptr);
437 
445  std::string generateIncludeGuardName(const std::string &filename);
446 
454  std::string getBuiltinTypename(const BuiltinType *t);
455 
470  std::string getTypenameName(DataType *t, const std::string &name);
471 
487  cpptempl::data_map getEncodeDecodeCall(const std::string &name, Group *group, DataType *t, StructType *structType,
488  bool inDataContainer, StructMember *structMember, bool &needTempVariable,
489  bool isFunctionParam);
490 
500  void getEncodeDecodeBuiltin(Group *group, BuiltinType *t, cpptempl::data_map &templateData, StructType *structType,
501  StructMember *structMember, bool isFunctionParam);
502 
510  void giveBracesToArrays(std::string &name);
511 
521  std::string getExtraDirectionPointer(StructMember *structMember);
522 
532  std::string getExtraPointerInReturn(DataType *dataType);
533 
544  cpptempl::data_map firstAllocOnServerWhenIsNeed(std::string name, StructMember *structMember);
545 
556  cpptempl::data_map firstAllocOnReturnWhenIsNeed(std::string name, DataType *dataType);
557 
566  cpptempl::data_map allocateCall(const std::string &name, Symbol *symbol);
567 
579  void setSymbolDataToSide(const Symbol *symbolType, const std::set<_param_direction> directions,
580  cpptempl::data_list &toClient, cpptempl::data_list &toServer, cpptempl::data_map &dataMap);
581 
590  bool isNeedCallFree(DataType *dataType);
591 
602  void setCallingFreeFunctions(Symbol *symbol, cpptempl::data_map &info, bool returnType);
603 
611  std::string returnSpaceWhenNotEmpty(const std::string &param);
612 
623  bool containsString(DataType *dataType);
624 
635  bool containsList(DataType *dataType);
636 
648  bool containsByrefParamToFree(DataType *dataType, std::set<DataType *> &dataTypes);
649 
660  bool isBinaryStruct(StructType *structType);
661 
672  bool isBinaryList(ListType *listType);
673 
682  bool isListStruct(StructType *structType);
683 
695  bool generateServerFreeFunctions(StructMember *structMember);
696 
705  void setNoSharedAnn(Symbol *parentSymbol, Symbol *childSymbol);
706 
707  bool setDiscriminatorTemp(UnionType *unionType, StructType *structType, StructMember *structMember,
708  bool isFunctionParam, cpptempl::data_map &templateData);
709 
719  std::string getScalarTypename(DataType *dataType);
720 
728  std::string getDirection(_param_direction direction);
729 
738  bool isServerNullParam(StructMember *structMember);
739 
748  bool isPointerParam(StructMember *structMember);
749 
758  bool isNullableParam(StructMember *structMember);
759 
763  void initCReservedWords();
764 
774  void scanStructForAnnotations(StructType *currentStructType, bool isFunction);
775 
785  void checkIfAnnValueIsIntNumberOrIntType(Annotation *ann, StructType *currentStructType);
786 };
787 } // namespace erpcgen
788 
789 #endif // _EMBEDDED_RPC__CGENERATOR_H_
Collects all definitions from an IDL.
Definition: InterfaceDefinition.h:30
Function data type.
Definition: FunctionType.h:30
Member of a struct.
Definition: StructMember.h:37
Annotation class.
Definition: Annotation.h:27
Typedef.
Definition: AliasType.h:25
Represents the builtin atomic types.
Definition: BuiltinType.h:25
Structure data type.
Definition: StructType.h:28
Function declaration.
Definition: Function.h:116
Base class for all named declarations in the IDL.
Definition: Symbol.h:27
virtual ~CGenerator()
This function is destructor of CGenerator class.
Definition: CGenerator.h:43
Variable length list of another data type.
Definition: ListType.h:25
CGenerator(InterfaceDefinition *def)
This function is constructor of CGenerator class.
Definition: CGenerator.cpp:45
Abstract code generator base class.
Definition: Generator.h:43
Base class for data types.
Definition: DataType.h:25
An interface that contains functions.
Definition: Group.h:27
Definition: cpptempl.h:190
Function base declaration.
Definition: Function.h:29
Enumerate data type.
Definition: EnumType.h:27
Discriminated union data type.
Definition: UnionType.h:27
Code generator for C.
Definition: CGenerator.h:26
virtual void generate()
This function generate output code for output files.
Definition: CGenerator.cpp:403
Definition: AstNode.h:25