eRPC Generator (erpcgen)  Rev. 1.9.0
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 
17 #include <set>
18 
20 // Classes
22 
23 namespace erpcgen {
27 class CGenerator : public Generator
28 {
29 public:
38 
44  virtual ~CGenerator() {}
45 
51  virtual void generate();
52 
53 private:
54  enum _direction
55  {
56  kIn,
57  kOut,
58  kInOut,
59  kNone
60  };
61 
62  cpptempl::data_list m_symbolsTemplate;
64  std::vector<ListType *>
65  m_listBinaryTypes;
71  std::vector<StructType *> m_structListTypes;
82  void parseSubtemplates();
83 
92  void generateOutputFiles(const std::string &fileNameExtension);
93 
99  void generateTypesHeaderFile();
100 
106  void generateCommonHeaderFiles(const std::string &fileName);
107 
113  void generateClientSourceFile(std::string fileName);
114 
120  void generateServerHeaderFile(std::string fileName);
121 
127  void generateServerSourceFile(std::string fileName);
128 
132  virtual void generateCrcFile();
133 
137  void transformAliases();
138 
146  cpptempl::data_map getSymbolTemplateByName(const std::string &name);
147 
160  DataType *findChildDataType(std::set<DataType *> &dataTypes, DataType *dataType);
161 
167  void setBinaryList(StructMember *structMember);
168 
180  cpptempl::data_map getFunctionBaseTemplateData(Group *group, FunctionBase *fn);
181 
193  cpptempl::data_map getFunctionTemplateData(Group *group, Function *fn);
194 
207  cpptempl::data_map getFunctionTypeTemplateData(Group *group, FunctionType *fn);
208 
215  void setTemplateComments(Symbol *symbol, cpptempl::data_map &symbolInfo);
216 
223  void makeConstTemplateData();
224 
225  // Functions that populate type-specific template data
226 
237  cpptempl::data_map makeGroupSymbolsTemplateData(Group *group);
238 
249  cpptempl::data_list makeGroupCallbacksTemplateData(Group *group);
250 
261  cpptempl::data_map getStructDeclarationTemplateData(StructType *structType);
262 
277  cpptempl::data_map getStructDefinitionTemplateData(Group *group, StructType *structType,
278  cpptempl::data_map structInfo);
279 
290  cpptempl::data_map getUnionDeclarationTemplateData(UnionType *unionType);
291 
307  cpptempl::data_map getUnionDefinitionTemplateData(Group *group, UnionType *unionType, cpptempl::data_map &unionInfo,
308  bool &needUnionsServerFree);
318  void setUnionMembersTemplateData(UnionType *unionType, cpptempl::data_map &unionInfo);
319 
331  std::string getUnionMembersData(UnionType *unionType, std::string indent);
332 
339  void makeEnumsTemplateData();
340 
347  void makeSymbolsDeclarationTemplateData();
348 
359  cpptempl::data_map getEnumTemplateData(EnumType *enumType);
360 
371  cpptempl::data_list getEnumMembersTemplateData(EnumType *enumType);
372 
379  void makeAliasesTemplateData();
380 
386  AliasType *getAliasType(DataType *dataType);
387 
393  std::string getAliasName(DataType *dataType);
394 
407  cpptempl::data_map getTypeInfo(DataType *t, bool isFunction);
408 
416  std::string getErrorReturnValue(FunctionBase *fn);
417 
427  std::string getFunctionPrototype(Group *group, FunctionBase *fn, std::string name = "");
428 
437  std::string getFunctionServerCall(Function *fn, FunctionType *functionType = nullptr);
438 
446  std::string generateIncludeGuardName(const std::string &filename);
447 
455  std::string getBuiltinTypename(const BuiltinType *t);
456 
471  std::string getTypenameName(DataType *t, const std::string &name);
472 
488  cpptempl::data_map getEncodeDecodeCall(const std::string &name, Group *group, DataType *t, StructType *structType,
489  bool inDataContainer, StructMember *structMember, bool &needTempVariable,
490  bool isFunctionParam);
491 
501  void getEncodeDecodeBuiltin(Group *group, BuiltinType *t, cpptempl::data_map &templateData, StructType *structType,
502  StructMember *structMember, bool isFunctionParam);
503 
511  void giveBracesToArrays(std::string &name);
512 
522  std::string getExtraDirectionPointer(StructMember *structMember);
523 
533  std::string getExtraPointerInReturn(DataType *dataType);
534 
545  cpptempl::data_map firstAllocOnServerWhenIsNeed(std::string name, StructMember *structMember);
546 
557  cpptempl::data_map firstAllocOnReturnWhenIsNeed(std::string name, DataType *dataType);
558 
567  cpptempl::data_map allocateCall(const std::string &name, Symbol *symbol);
568 
580  void setSymbolDataToSide(const Symbol *symbolType, const std::set<_param_direction> directions,
581  cpptempl::data_list &toClient, cpptempl::data_list &toServer, cpptempl::data_map &dataMap);
582 
591  bool isNeedCallFree(DataType *dataType);
592 
603  void setCallingFreeFunctions(Symbol *symbol, cpptempl::data_map &info, bool returnType);
604 
612  std::string returnSpaceWhenNotEmpty(const std::string &param);
613 
624  bool containsString(DataType *dataType);
625 
636  bool containsList(DataType *dataType);
637 
649  bool containsByrefParamToFree(DataType *dataType, std::set<DataType *> &dataTypes);
650 
661  bool isBinaryStruct(StructType *structType);
662 
673  bool isBinaryList(ListType *listType);
674 
683  bool isListStruct(StructType *structType);
684 
696  bool generateServerFreeFunctions(StructMember *structMember);
697 
706  void setNoSharedAnn(Symbol *parentSymbol, Symbol *childSymbol);
707 
708  bool setDiscriminatorTemp(UnionType *unionType, StructType *structType, StructMember *structMember,
709  bool isFunctionParam, cpptempl::data_map &templateData);
710 
720  std::string getScalarTypename(DataType *dataType);
721 
729  std::string getDirection(_param_direction direction);
730 
739  bool isServerNullParam(StructMember *structMember);
740 
749  bool isPointerParam(StructMember *structMember);
750 
759  bool isNullableParam(StructMember *structMember);
760 
764  void initCReservedWords();
765 
775  void scanStructForAnnotations(StructType *currentStructType, bool isFunction);
776 
786  void checkIfAnnValueIsIntNumberOrIntType(Annotation *ann, StructType *currentStructType);
787 };
788 } // namespace erpcgen
789 
790 #endif // _EMBEDDED_RPC__CGENERATOR_H_
Collects all definitions from an IDL.
Definition: InterfaceDefinition.h:31
Function data type.
Definition: FunctionType.h:31
Member of a struct.
Definition: StructMember.h:38
Annotation class.
Definition: Annotation.h:28
Typedef.
Definition: AliasType.h:26
Represents the builtin atomic types.
Definition: BuiltinType.h:26
Structure data type.
Definition: StructType.h:29
Function declaration.
Definition: Function.h:117
Base class for all named declarations in the IDL.
Definition: Symbol.h:28
virtual ~CGenerator()
This function is destructor of CGenerator class.
Definition: CGenerator.h:44
Variable length list of another data type.
Definition: ListType.h:26
CGenerator(InterfaceDefinition *def)
This function is constructor of CGenerator class.
Definition: CGenerator.cpp:47
Abstract code generator base class.
Definition: Generator.h:44
Base class for data types.
Definition: DataType.h:26
An interface that contains functions.
Definition: Group.h:28
Definition: cpptempl.h:190
Function base declaration.
Definition: Function.h:30
Enumerate data type.
Definition: EnumType.h:28
Discriminated union data type.
Definition: UnionType.h:28
Code generator for C.
Definition: CGenerator.h:27
virtual void generate()
This function generate output code for output files.
Definition: CGenerator.cpp:397
Definition: AstNode.h:26