forb
parameter.hpp
1 //
2 // Created by gabriele on 14/11/18.
3 //
4 
5 #ifndef FORBCC_PARAMETER_H
6 #define FORBCC_PARAMETER_H
7 
8 #include <algorithm> // std::transform
9 #include <variable.hpp>
10 
11 namespace forbcc {
12  // Forward declaration
13  class code_ostream;
14 
16  enum class direction {
17  IN, OUT, INOUT
18  };
19 
22  class parameter {
24  direction _direction;
25 
27  variable _variable;
28 
29  public:
30  /* ********************************************** CONSTRUCTORS ********************************************** */
31 
33  parameter() : _direction(direction::IN), _variable() {};
34 
36  parameter(const direction &dir, const variable &var)
37  : _direction(dir),
38  _variable(var) {};
39 
40  /**************************************************************************************************************/
41 
43  ~parameter() = default;
44 
46  parameter(parameter &&) = default;
47 
49  parameter &operator=(parameter &&) = default;
50 
52  parameter(const parameter &) = default;
53 
55  parameter &operator=(const parameter &) = default;
56 
57  /**************************************************************************************************************/
58 
60  direction dir() const {
61  return _direction;
62  };
63 
65  const variable &var() const {
66  return _variable;
67  };
68 
70  std::string name() const {
71  return _variable.name();
72  }
73 
81  void print_declaration(code_ostream &out) const {
82  if (_direction == direction::IN) {
83  // Pass by value
84  _variable.print_declaration(out);
85  } else {
86  // Pass by reference
87  _variable.print_reference(out);
88  }
89  };
90 
91 
92  };
93 
94 }
95 
96 
97 #endif //FORBCC_PARAMETER_H
const variable & var() const
Returns a reference to the variable used to express the parameter.
Definition: parameter.hpp:65
void print_reference(code_ostream &out) const
Prints the variable declaration, proxy to forbcc::type::print_var_reference, which is a virtual funct...
Definition: variable.hpp:75
Represents the parameter of a forbcc::method, each associated with a direction between either input...
Definition: parameter.hpp:22
direction dir() const
Returns the direction of the parameter.
Definition: parameter.hpp:60
void print_declaration(code_ostream &out) const
Prints the declaration, which may change whether the parameter is IN or OUT/INOUT.
Definition: parameter.hpp:81
void print_declaration(code_ostream &out) const override
Prints the variable declaration, proxy to forbcc::type::print_var_declaration, which is a virtual fun...
Definition: variable.hpp:56
std::string name() const
Returns the name of the given entity.
Definition: entity.hpp:68
parameter(const direction &dir, const variable &var)
Constructs a parameter.
Definition: parameter.hpp:36
This output stream supports indentation of code lines, which are formatted at each std::endl...
Definition: code_ostream.hpp:14
std::string name() const
Returns the name of the parameter.
Definition: parameter.hpp:70
Definition: code_ostream.hpp:11
Represents either an attribute of a forbcc::type_struct class or an automatic variable declared withi...
Definition: variable.hpp:13
parameter()
Empty parameter, used to preallocate variables in arrays or to use later assignment operator...
Definition: parameter.hpp:33