forb
entity.hpp
1 #include <utility>
2 
3 //
4 // Created by gabriele on 16/11/18.
5 //
6 
7 #ifndef FORBCC_ENTITY_H
8 #define FORBCC_ENTITY_H
9 
10 #include <string>
11 #include <memory>
12 
13 namespace forbcc {
14  // Forward declarations
15  class code_ostream;
16 
18  class entity {
19 
20  /* *********************************************** ATTRIBUTES *********************************************** */
21  private:
23  std::shared_ptr<entity> _parent;
24 
26  std::string _name;
27 
28  /* ********************************************** CONSTRUCTORS ********************************************** */
29  public:
32  entity() : _parent(nullptr), _name("") {};
33 
35  entity(const std::shared_ptr<entity> &parent, const std::string &name)
36  : _parent(parent),
37  _name(name) {};
38 
39  /**************************************************************************************************************/
40 
41  public:
45  virtual ~entity() = default;
46 
48  entity(entity &&) = default;
49 
51  entity &operator=(entity &&) = default;
52 
54  entity(const entity &) = default;
55 
57  entity &operator=(const entity &) = default;
58 
59  /**************************************************************************************************************/
60 
61  public:
63  std::shared_ptr<entity> parent() const {
64  return _parent;
65  };
66 
68  std::string name() const {
69  return _name;
70  };
71 
73  virtual void print_declaration(code_ostream &out) const = 0;
74 
76  virtual void print_definition(code_ostream &out) const = 0;
77 
81  virtual std::string codename() const {
82  std::string parent_name = (_parent != nullptr) ? _parent->codename() : "";
83 
84  return (parent_name.length()) ? parent_name + "::" + _name : _name;
85  };
86  };
87 }
88 
89 
90 #endif //FORBCC_ENTITY_H
virtual void print_declaration(code_ostream &out) const =0
Prints the declaration of the given entity, if required.
entity & operator=(entity &&)=default
This class supports moving.
entity(const std::shared_ptr< entity > &parent, const std::string &name)
Constructs an entity within a given parent.
Definition: entity.hpp:35
virtual std::string codename() const
Returns the codename of the given entity, which is the name of the entity as seen from the global sco...
Definition: entity.hpp:81
virtual void print_definition(code_ostream &out) const =0
Prints the definition of the given entity, if required.
entity()
Constructs an empty entity, used to preallocate entity variables (like in arrays) and to later use th...
Definition: entity.hpp:32
virtual ~entity()=default
Does nothing because the destructor of the shared_ptr handles all the stuff It&#39;s necessary for the de...
std::shared_ptr< entity > parent() const
Returns the parent of the given entity.
Definition: entity.hpp:63
std::string name() const
Returns the name of the given entity.
Definition: entity.hpp:68
This output stream supports indentation of code lines, which are formatted at each std::endl...
Definition: code_ostream.hpp:14
Definition: code_ostream.hpp:11
Any code entity that should be generated by the compiler: namespaces, classes, structures, methods, variables.
Definition: entity.hpp:18