ROSE  0.11.98.0
Factory.h
1 #ifndef ROSE_CodeGen_Factory_H
2 #define ROSE_CodeGen_Factory_H
3 
4 #include <Rose/CodeGen/API.h>
5 
6 namespace Rose { namespace CodeGen {
7 
17 template <typename CRT, typename API>
18 class Factory;
19 
28 template <typename CRT, typename apiT, Object otag>
30 
31 template <typename CRT, typename API>
32 class Factory {
33  public:
34  using factory_t = Factory<CRT, API>;
35 
36  public:
37  Driver & driver;
38  API api;
39 
40  public:
41  Factory(Driver & driver_) : driver(driver_), api() {
42  api.load(driver);
43  }
44 
58  template <Object otag, typename... Args>
59  declaration_t<otag> * instantiate(symbol_t<otag> * API::* obj, SgNamedType * parent, Args... args) {
60  symbol_t<otag> * sym = api.*obj;
61  ROSE_ASSERT(sym);
62  ROSE_ASSERT(is_template_symbol_variant<otag>(sym->variantT()));
63  return __factory_helper_t<CRT, API, otag>::instantiate(*this, sym, parent, args...);
64  }
65 
79  template <Object otag, typename... Args>
80  reference_t<otag> * reference(symbol_t<otag> * API::* obj, SgNamedType * parent, Args... args) {
81  symbol_t<otag> * sym = api.*obj;
82  ROSE_ASSERT(sym);
83 
84  if (is_template_symbol_variant<otag>(sym->variantT())) {
85  declaration_t<otag> * decl = instantiate<otag>(obj, parent, args...);
86  ROSE_ASSERT(decl != nullptr);
87 
88  ROSE_ABORT(); // TODO get symbol from decl
89  } else {
90  // FIXME sanity-check: `args` is empty
91  }
92 
93  return __factory_helper_t<CRT, API, otag>::reference(*this, sym, parent, args...);
94  }
95 
109  template <Object otag, typename... Args>
110  SgExpression * access(symbol_t<otag> * API::* obj, SgExpression * parent, Args... args) {
111 
112  SgType * ptype = parent->get_type(); // TODO strip type modifiers and references
113 
114  bool lhs_has_ptr_type = isSgPointerType(parent->get_type());
115  if (lhs_has_ptr_type) {
116  ptype = ((SgPointerType*)ptype)->get_base_type(); // TODO strip type modifiers and references
117  }
118 
119  SgClassType * xtype = isSgClassType(ptype);
120  ROSE_ASSERT(xtype != nullptr);
121 
122  reference_t<otag> * rhs = reference(obj, ptype, args...);
123  ROSE_ASSERT(rhs != nullptr);
124 
125  if (lhs_has_ptr_type) {
126  return SageBuilder::buildArrowExp(parent, rhs);
127  } else {
128  return SageBuilder::buildDotExp(parent, rhs);
129  }
130  }
131 
132 
133  protected:
140  template <Object otag>
141  using access_return_t = std::conditional_t<otag == Object::a_class || otag == Object::a_typedef, SgType, SgExpression>;
142 
143 
144  public:
156  template <Object otag, typename... Args>
157  access_return_t<otag> * access(symbol_t<otag> * API::* obj, SgNamedType * parent, Args... args) {
158  reference_t<otag> * rhs = reference(obj, parent, args...);
159  // TODO build either SgScopedRefType SgScopedRefExp
160  return rhs;
161  }
162 };
163 
164 #if 0
165 template <typename CRT, typename apiT>
166 template <>
167 reference_t<Object::a_variable> * Factory<CRT,apiT>::reference<Object::a_variable>(symbol_t<Object::a_variable> * sym) {
168  return nullptr;
169 }
170 #endif
171 
172 } }
173 
174 #include "Rose/CodeGen/factory/namespaces.txx"
175 #include "Rose/CodeGen/factory/classes.txx"
176 #include "Rose/CodeGen/factory/typedefs.txx"
177 #include "Rose/CodeGen/factory/variables.txx"
178 #include "Rose/CodeGen/factory/functions.txx"
179 
180 #endif
constructs expressions and types for the given API
Definition: Factory.h:18
This class represents the base class for all types.
typename object_helper< otag >::symbol_t symbol_t
The SgSymbol specialization for an Object kind /tparam otag an Object kind.
Definition: Object.h:26
virtual SgType * get_type() const
unparsing support for pragmas
permits to gather types and symbols to extract an API from a set of headers.
Definition: API.h:17
Main namespace for the ROSE library.
facilitates the manipulation of source-files (esp.
Definition: Driver.h:21
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes, since similar to statement, expressions have a concrete location within the user's source code.
Object
The five kind of objects manipulated by Rose::CodeGen::API and associated Rose::CodeGen::Factory.
Definition: Object.h:11
access_return_t< otag > * access(symbol_t< otag > *API::*obj, SgNamedType *parent, Args...args)
Build expression or type to access static member and subtype of the parent type.
Definition: Factory.h:157
declaration_t< otag > * instantiate(symbol_t< otag > *API::*obj, SgNamedType *parent, Args...args)
Return an instantiation.
Definition: Factory.h:59
SgExpression * access(symbol_t< otag > *API::*obj, SgExpression *parent, Args...args)
Build expression to access a member of the parent expression.
Definition: Factory.h:110
enables partial specializations w.r.t the template parameter otag
Definition: Factory.h:29
typename object_helper< otag >::decl_t declaration_t
The SgDeclarationStatement specialization for an Object kind /tparam otag an Object kind...
Definition: Object.h:38
reference_t< otag > * reference(symbol_t< otag > *API::*obj, SgNamedType *parent, Args...args)
Return an expression or type referencing the object.
Definition: Factory.h:80
ROSE_DLL_API SgArrowExp * buildArrowExp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgDotExp * buildDotExp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
typename object_helper< otag >::ref_t reference_t
The SgReference specialization for an Object kind /tparam otag an Object kind.
Definition: Object.h:32
std::conditional_t< otag==Object::a_class||otag==Object::a_typedef, SgType, SgExpression > access_return_t
Select return type for access based on Object type.
Definition: Factory.h:141