Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. struct FactoryAST {
  2.  
  3.   FactoryAST() = default;
  4.  
  5.   // in general I am not a super fan of hardcore or complex templates
  6.   // but I decided to experiment a little with it.
  7.   // This is the inner function, a generic function getting an arbitrary
  8.   // number of arguments and forwarding them to the constructor
  9.   template <typename T, typename... Args> T *allocASTNode(Args... args) {
  10.     return new (allocator.alloc(sizeof(T))) T(args...);
  11.   }
  12.  
  13.   // generating aliases for the different nodes
  14.   template <typename... Args>
  15.   codegen::VariableExprAST *allocVariableAST(Args &&... args) {
  16.     return allocASTNode<codegen::VariableExprAST>(args...);
  17.   }
  18.   template <typename... Args>
  19.   codegen::NumberExprAST *allocNuberAST(Args ... args) {
  20.     return allocASTNode<codegen::NumberExprAST>(args...);
  21.   }
  22.   template <typename... Args>
  23.   codegen::BinaryExprAST *allocBinaryAST(Args &&... args) {
  24.     return allocASTNode<codegen::BinaryExprAST>(args...);
  25.   }
  26.   template <typename... Args>
  27.   codegen::CallExprAST*allocCallexprAST(Args &&... args) {
  28.     return allocASTNode<codegen::CallExprAST>(args...);
  29.   }
  30.     template <typename... Args>
  31.     codegen::PrototypeAST*allocPrototypeAST(Args &&... args) {
  32.       return allocASTNode<codegen::PrototypeAST>(args...);
  33.     }
  34.     template <typename... Args>
  35.     codegen::FunctionAST*allocFunctionAST(Args &&... args) {
  36.       return allocASTNode<codegen::FunctionAST>(args...);
  37.     }
  38.  
  39.   SlabAllocator allocator;
  40. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement