00001 #ifndef _TEMPLATE_H
00002 #define _TEMPLATE_H
00003 
00004 #include "xi-Construct.h"
00005 #include "xi-Type.h"
00006 
00007 namespace xi {
00008 
00009 
00010 
00011 class TParam : public Printable {
00012  public:
00013   virtual void genSpec(XStr& str) = 0;
00014 };
00015 
00016 
00017 class TParamList : public Printable {
00018   TParam* tparam;
00019   TParamList* next;
00020 
00021  public:
00022   TParamList(TParam* t, TParamList* n = 0);
00023   void print(XStr& str);
00024   void genSpec(XStr& str);
00025   std::string to_string();
00026 };
00027 
00028 
00029 class TParamType : public TParam {
00030   Type* type;
00031 
00032  public:
00033   TParamType(Type* t);
00034   void print(XStr& str);
00035   void genSpec(XStr& str);
00036 };
00037 
00038 
00039 class TParamVal : public TParam {
00040   const char* val;
00041 
00042  public:
00043   TParamVal(const char* v);
00044   void print(XStr& str);
00045   void genSpec(XStr& str);
00046 };
00047 
00048 class Scope : public ConstructList {
00049  protected:
00050   const char* name_;
00051 
00052  public:
00053   Scope(const char* name, ConstructList* contents);
00054   void genDecls(XStr& str);
00055   void genDefs(XStr& str);
00056   void genReg(XStr& str);
00057   void genGlobalCode(XStr scope, XStr& decls, XStr& defs);
00058   void print(XStr& str);
00059   void outputClosuresDecl(XStr& str);
00060   void outputClosuresDef(XStr& str);
00061 };
00062 
00063 class UsingScope : public Construct {
00064  protected:
00065   const char* name_;
00066   bool symbol_;
00067 
00068  public:
00069   UsingScope(const char* name, bool symbol = false);
00070   virtual void genDecls(XStr& str);
00071   virtual void print(XStr& str);
00072 };
00073 
00074 
00075 class TVarList;
00076 class TEntity;
00077 
00078 class Template : public Construct {
00079   TVarList* tspec;
00080   TEntity* entity;
00081 
00082  public:
00083   Template(TVarList* t, TEntity* e) : tspec(t), entity(e) {}
00084   virtual void setExtern(int e);
00085   void print(XStr& str);
00086   void genDecls(XStr& str);
00087   void genDefs(XStr& str);
00088   void genSpec(XStr& str, bool printDefault = true);
00089   void genVars(XStr& str);
00090   void genGlobalCode(XStr scope, XStr& decls, XStr& defs);
00091   void outputClosuresDecl(XStr& str);
00092   void outputClosuresDef(XStr& str);
00093   void preprocess();
00094   void check();
00095 
00096   
00097   int genAccels_spe_c_funcBodies(XStr& str);
00098   void genAccels_spe_c_regFuncs(XStr& str);
00099   void genAccels_spe_c_callInits(XStr& str);
00100   void genAccels_spe_h_includes(XStr& str);
00101   void genAccels_spe_h_fiCountDefs(XStr& str);
00102   void genAccels_ppe_c_regFuncs(XStr& str);
00103 };
00104 
00105 
00106 class TEntity : public Construct {
00107  protected:
00108   Template* templat;
00109 
00110  public:
00111   void setTemplate(Template* t);
00112   virtual XStr tspec(bool printDefault = true) const;
00113   virtual XStr tvars(void) const;
00114 };
00115 
00116 class TVar : public Printable {
00117  public:
00118   virtual void genLong(XStr& str, bool printDefault = true) = 0;
00119   virtual void genShort(XStr& str) = 0;
00120 };
00121 
00122 
00123 class TTypeEllipsis : public TVar {
00124   NamedEllipsisType* type;
00125   Type* init;
00126 
00127  public:
00128   TTypeEllipsis(NamedEllipsisType* t, Type* i = 0);
00129   void print(XStr& str);
00130   void genLong(XStr& str, bool printDefault = true);
00131   void genShort(XStr& str);
00132 };
00133 
00134 
00135 class TType : public TVar {
00136   Type* type;
00137   Type* init;
00138 
00139  public:
00140   TType(Type* t, Type* i = 0);
00141   void print(XStr& str);
00142   void genLong(XStr& str, bool printDefault = true);
00143   void genShort(XStr& str);
00144 };
00145 
00146 
00147 class TFunc : public TVar {
00148   FuncType* type;
00149   const char* init;
00150 
00151  public:
00152   TFunc(FuncType* t, const char* v = 0);
00153   void print(XStr& str);
00154   void genLong(XStr& str, bool printDefault = true);
00155   void genShort(XStr& str);
00156 };
00157 
00158 
00159 class TName : public TVar {
00160   Type* type;
00161   const char* name;
00162   const char* val;
00163 
00164  public:
00165   TName(Type* t, const char* n, const char* v = 0);
00166   void print(XStr& str);
00167   void genLong(XStr& str, bool printDefault = true);
00168   void genShort(XStr& str);
00169 };
00170 
00171 
00172 class TVarList : public Printable {
00173   TVar* tvar;
00174   TVarList* next;
00175 
00176  public:
00177   TVarList(TVar* v, TVarList* n = 0);
00178   void print(XStr& str);
00179   void genLong(XStr& str, bool printDefault = true);
00180   void genShort(XStr& str);
00181 };
00182 
00183 }  
00184 
00185 #endif  // ifndef _TEMPLATE_H