BEAST - Free Software Audio Synthesizer and Tracker  0.10.0
sfidl-cbase.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __SFIDL_CBASE_H__
3 #define __SFIDL_CBASE_H__
4 
5 #include <map>
6 #include <iostream>
7 #include <algorithm>
8 #include "sfidl-utils.hh"
9 #include "sfidl-namespace.hh"
10 #include "sfidl-options.hh"
11 #include "sfidl-parser.hh"
12 #include "sfidl-generator.hh"
13 
14 namespace Sfidl {
15 
16  /*
17  * Base class for C and C++-like CodeGenerators
18  */
20  protected:
21  bool generateBoxedTypes;
22 
23  enum TypeCodeModel {
24  MODEL_FROM_VALUE, MODEL_TO_VALUE,
25  MODEL_VCALL, MODEL_VCALL_ARG,
26  MODEL_VCALL_CARG, MODEL_VCALL_CONV, MODEL_VCALL_CFREE,
27  MODEL_VCALL_RET, MODEL_VCALL_RCONV, MODEL_VCALL_RFREE
28  };
29 
30  enum PrefixSymbolMode { generateOutput, generatePrefixSymbols };
31  std::vector<String> prefix_symbols; /* symbols which should get a namespace prefix */
32 
33  const gchar *makeCStr (const String& str);
34 
35  String scatId (SfiSCategory c);
36 
37  /* record/sequence binding used by --host-c and --client-c binding */
38  void printClientRecordPrototypes();
39  void printClientSequencePrototypes();
40 
41  void printClientRecordDefinitions();
42  void printClientSequenceDefinitions();
43 
44  void printClientRecordMethodPrototypes (PrefixSymbolMode mode);
45  void printClientSequenceMethodPrototypes (PrefixSymbolMode mode);
46 
47  void printClientRecordMethodImpl();
48  void printClientSequenceMethodImpl();
49 
50  void printClientChoiceDefinitions();
51  void printClientChoiceConverterPrototypes (PrefixSymbolMode mode);
52 
53  void printProcedure (const Method& mdef, bool proto = false, const String& className = "");
54  void printChoiceConverters ();
55 
56  virtual String makeProcName (const String& className, const String& procName);
57 
58  String makeGTypeName (const String& name);
59  String makeParamSpec (const Param& pdef);
60  String createTypeCode (const String& type, TypeCodeModel model);
61 
62  /*
63  * data types: the following models deal with how to represent a certain
64  * SFI type in the binding
65  */
66 
67  // how "type" looks like when passed as argument to a function
68  virtual String typeArg (const String& type);
69  const gchar *cTypeArg (const String& type) { return makeCStr (typeArg (type)); }
70 
71  // how "type" looks like when stored as member in a struct or class
72  virtual String typeField (const String& type);
73  const gchar *cTypeField (const String& type) { return makeCStr (typeField (type)); }
74 
75  // how the return type of a function returning "type" looks like
76  virtual String typeRet (const String& type);
77  const gchar *cTypeRet (const String& type) { return makeCStr (typeRet (type)); }
78 
79  // how an array of "type"s looks like ( == MODEL_MEMBER + "*" ?)
80  virtual String typeArray (const String& type);
81  const gchar *cTypeArray (const String& type) { return makeCStr (typeArray (type)); }
82 
83  /*
84  * function required to create a new "type" (blank return value allowed)
85  * example: funcNew ("FBlock") => "sfi_fblock_new" (in C)
86  */
87  virtual String funcNew (const String& type);
88  const gchar *cFuncNew (const String& type) { return makeCStr (funcNew (type)); }
89 
90  /*
91  * function required to copy a "type" (blank return value allowed)
92  * example: funcCopy ("FBlock") => "sfi_fblock_ref" (in C)
93  */
94  virtual String funcCopy (const String& type);
95  const gchar *cFuncCopy (const String& type) { return makeCStr (funcNew (type)); }
96 
97  /*
98  * function required to free a "type" (blank return value allowed)
99  * example: funcFree ("FBlock") => "sfi_fblock_unref" (in C)
100  */
101  virtual String funcFree (const String& type);
102  const gchar *cFuncFree (const String& type) { return makeCStr (funcNew (type)); }
103 
104  virtual String createTypeCode (const String& type, const String& name,
105  TypeCodeModel model);
106 
107  CodeGeneratorCBase (const Parser& parser) : CodeGenerator (parser) {
108  generateBoxedTypes = false;
109  }
110  };
111 
112 };
113 
114 #endif /* __SFIDL_CBASE_H__ */
115 
116 /* vim:set ts=8 sts=2 sw=2: */
Definition: sfidl-parser.hh:92
Definition: sfidl-generator.hh:16
The Sfidl namespace contains implementation and API of the Sfi IDL compiler.
Definition: sfidl-cbase.hh:14
Definition: sfidl-parser.hh:231
Definition: sfidl-cbase.hh:19
STL class.
Definition: sfidl-parser.hh:157
STL class.