Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

dtool/src/interrogate/interfaceMaker.h

Go to the documentation of this file.
00001 // Filename: interfaceMaker.h
00002 // Created by:  drose (19Sep01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef INTERFACEMAKER_H
00020 #define INTERFACEMAKER_H
00021 
00022 #include "dtoolbase.h"
00023 
00024 #include "interrogate_interface.h"
00025 #include "interrogate_request.h"
00026 #include "functionWriters.h"
00027 
00028 #include <vector>
00029 #include <map>
00030 
00031 class FunctionRemap;
00032 class ParameterRemap;
00033 class CPPType;
00034 class CPPInstance;
00035 class InterrogateBuilder;
00036 class InterrogateType;
00037 class InterrogateFunction;
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //       Class : InterfaceMaker
00041 // Description : This is an abstract base class that defines how to
00042 //               generate code that can be called from an external
00043 //               language (like Python or Squeak) and that can call
00044 //               into Panda.
00045 //
00046 //               The specializations of this class like
00047 //               InterfaceMakerPython and InterfaceMakerC will
00048 //               generate the actual wrappers for the various language
00049 //               calling conventions.
00050 ////////////////////////////////////////////////////////////////////
00051 class InterfaceMaker {
00052 public:
00053   InterfaceMaker(InterrogateModuleDef *def);
00054   virtual ~InterfaceMaker();
00055 
00056   virtual void generate_wrappers();
00057 
00058   virtual void write_includes(ostream &out);
00059   virtual void write_prototypes(ostream &out);
00060   virtual void write_functions(ostream &out);
00061 
00062   virtual void write_module(ostream &out, InterrogateModuleDef *def);
00063 
00064   virtual ParameterRemap *
00065   remap_parameter(CPPType *struct_type, CPPType *param_type);
00066 
00067   virtual bool synthesize_this_parameter();
00068   virtual bool separate_overloading();
00069 
00070   void get_function_remaps(vector<FunctionRemap *> &remaps);
00071 
00072   static ostream &indent(ostream &out, int indent_level);
00073 
00074 protected:
00075   class Function {
00076   public:
00077     Function(const string &name,
00078              const InterrogateType &itype,
00079              const InterrogateFunction &ifunc);
00080     ~Function();
00081 
00082     string _name;
00083     const InterrogateType &_itype;
00084     const InterrogateFunction &_ifunc;
00085     typedef vector<FunctionRemap *> Remaps;
00086     Remaps _remaps;
00087     bool _has_this;
00088   };
00089   typedef vector<Function *> Functions;
00090   Functions _functions;
00091 
00092   class Object {
00093   public:
00094     Object(const InterrogateType &itype);
00095     ~Object();
00096 
00097     void add_method(Function *method);
00098 
00099     const InterrogateType &_itype;
00100     Functions _constructors;
00101     Functions _methods;
00102     Function *_destructor;
00103   };
00104   typedef map<TypeIndex, Object *> Objects;
00105   Objects _objects;
00106 
00107   typedef map<string, FunctionRemap *> WrappersByHash;
00108   WrappersByHash _wrappers_by_hash;
00109 
00110   virtual FunctionRemap *
00111   make_function_remap(const InterrogateType &itype,
00112                       const InterrogateFunction &ifunc,
00113                       CPPInstance *cppfunc, int num_default_parameters);
00114 
00115   virtual string
00116   get_wrapper_name(const InterrogateType &itype, 
00117                    const InterrogateFunction &ifunc,
00118                    FunctionIndex func_index);
00119   virtual string get_wrapper_prefix();
00120   virtual string get_unique_prefix();
00121   
00122   Function *
00123   record_function(const InterrogateType &itype, FunctionIndex func_index);
00124 
00125   virtual void
00126   record_function_wrapper(InterrogateFunction &ifunc, 
00127                           FunctionWrapperIndex wrapper_index);
00128 
00129   Object *
00130   record_object(TypeIndex type_index);
00131 
00132   void hash_function_signature(FunctionRemap *remap);
00133   
00134 
00135   string
00136   manage_return_value(ostream &out, int indent_level,
00137                       FunctionRemap *remap, const string &return_expr) const;
00138 
00139   void output_ref(ostream &out, int indent_level, FunctionRemap *remap, 
00140                   const string &varname) const;
00141   void write_spam_message(ostream &out, FunctionRemap *remap) const;
00142 
00143 protected:
00144   InterrogateModuleDef *_def;
00145 
00146   FunctionWriters _function_writers;
00147 };
00148 
00149 #endif

Generated on Thu May 1 22:13:01 2003 for DTool by doxygen1.3