BEAST/BSE - Better Audio System and Sound Engine  0.8.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
sfidl-cbase.hh
Go to the documentation of this file.
00001  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
00002 #ifndef __SFIDL_CBASE_H__
00003 #define __SFIDL_CBASE_H__
00004 
00005 #include <map>
00006 #include <iostream>
00007 #include <algorithm>
00008 #include "sfidl-utils.hh"
00009 #include "sfidl-namespace.hh"
00010 #include "sfidl-options.hh"
00011 #include "sfidl-parser.hh"
00012 #include "sfidl-generator.hh"
00013 
00014 namespace Sfidl {
00015 
00016   /*
00017    * Base class for C and C++-like CodeGenerators
00018    */
00019   class CodeGeneratorCBase : public CodeGenerator {
00020   protected:
00021     bool generateBoxedTypes;
00022 
00023     enum TypeCodeModel {
00024       MODEL_FROM_VALUE, MODEL_TO_VALUE,
00025       MODEL_VCALL, MODEL_VCALL_ARG, 
00026       MODEL_VCALL_CARG, MODEL_VCALL_CONV, MODEL_VCALL_CFREE,
00027       MODEL_VCALL_RET, MODEL_VCALL_RCONV, MODEL_VCALL_RFREE
00028     };
00029 
00030     enum PrefixSymbolMode { generateOutput, generatePrefixSymbols };
00031     std::vector<String> prefix_symbols; /* symbols which should get a namespace prefix */
00032 
00033     const gchar *makeCStr (const String& str);
00034 
00035     String scatId (SfiSCategory c);
00036 
00037     /* record/sequence binding used by --host-c and --client-c binding */
00038     void printClientRecordPrototypes();
00039     void printClientSequencePrototypes();
00040 
00041     void printClientRecordDefinitions();
00042     void printClientSequenceDefinitions();
00043 
00044     void printClientRecordMethodPrototypes (PrefixSymbolMode mode);
00045     void printClientSequenceMethodPrototypes (PrefixSymbolMode mode);
00046 
00047     void printClientRecordMethodImpl();
00048     void printClientSequenceMethodImpl();
00049 
00050     void printClientChoiceDefinitions();
00051     void printClientChoiceConverterPrototypes (PrefixSymbolMode mode);
00052 
00053     void printProcedure (const Method& mdef, bool proto = false, const String& className = "");
00054     void printChoiceConverters ();
00055 
00056     virtual String makeProcName (const String& className, const String& procName);
00057 
00058     String makeGTypeName (const String& name);
00059     String makeParamSpec (const Param& pdef);
00060     String createTypeCode (const String& type, TypeCodeModel model);
00061 
00062     /*
00063      * data types: the following models deal with how to represent a certain
00064      * SFI type in the binding
00065      */
00066 
00067     // how "type" looks like when passed as argument to a function
00068     virtual String typeArg (const String& type);
00069     const gchar *cTypeArg (const String& type) { return makeCStr (typeArg (type)); }
00070 
00071     // how "type" looks like when stored as member in a struct or class
00072     virtual String typeField (const String& type);
00073     const gchar *cTypeField (const String& type) { return makeCStr (typeField (type)); }
00074 
00075     // how the return type of a function returning "type" looks like
00076     virtual String typeRet (const String& type);
00077     const gchar *cTypeRet (const String& type) { return makeCStr (typeRet (type)); }
00078 
00079     // how an array of "type"s looks like ( == MODEL_MEMBER + "*" ?)
00080     virtual String typeArray (const String& type);
00081     const gchar *cTypeArray (const String& type) { return makeCStr (typeArray (type)); }
00082 
00083     /*
00084      * function required to create a new "type" (blank return value allowed)
00085      * example: funcNew ("FBlock") => "sfi_fblock_new" (in C)
00086      */
00087     virtual String funcNew (const String& type);
00088     const gchar *cFuncNew (const String& type) { return makeCStr (funcNew (type)); }
00089 
00090     /*
00091      * function required to copy a "type" (blank return value allowed)
00092      * example: funcCopy ("FBlock") => "sfi_fblock_ref" (in C)
00093      */ 
00094     virtual String funcCopy (const String& type);
00095     const gchar *cFuncCopy (const String& type) { return makeCStr (funcNew (type)); }
00096 
00097     /*
00098      * function required to free a "type" (blank return value allowed)
00099      * example: funcFree ("FBlock") => "sfi_fblock_unref" (in C)
00100      */ 
00101     virtual String funcFree (const String& type);
00102     const gchar *cFuncFree (const String& type) { return makeCStr (funcNew (type)); }
00103 
00104     virtual String createTypeCode (const String& type, const String& name, 
00105                                    TypeCodeModel model);
00106 
00107     CodeGeneratorCBase (const Parser& parser) : CodeGenerator (parser) {
00108       generateBoxedTypes = false;
00109     }
00110   };
00111 
00112 };
00113 
00114 #endif  /* __SFIDL_CBASE_H__ */
00115 
00116 /* vim:set ts=8 sts=2 sw=2: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines