forb
module.hpp
1 //
2 // Created by gabriele on 14/11/18.
3 //
4 
5 #ifndef FORBCC_MODULE_H
6 #define FORBCC_MODULE_H
7 
8 #include <string>
9 
10 #include <entity.hpp>
11 #include <templates/ordered_unique_list.hpp>
12 #include <templates/shareable.hpp>
13 
14 namespace forbcc {
15 
16  // Forward declaration
17  class type_struct;
18 
21  class module : public entity, public shareable<module>, public ordered_unique_list<std::shared_ptr<entity>> {
22 
23  /* ************************************************* STATIC ************************************************* */
24  public:
26  static const std::shared_ptr<module> global_module;
27 
28  /* ********************************************** CONSTRUCTORS ********************************************** */
29  public:
32  module() : entity() {};
33 
35  module(const std::shared_ptr<entity> &parent, const std::string &name) : entity(parent, name) {};
36 
37  /**************************************************************************************************************/
38  public:
40  ~module() override = default;
41 
43  module(module &&) = default;
44 
46  module &operator=(module &&) = default;
47 
49  module(const module &) = default;
50 
52  module &operator=(const module &) = default;
53 
54  /**************************************************************************************************************/
55 
57  void print_declaration(code_ostream &out) const override;
58 
60  void print_definition(code_ostream &out) const override;
61 
64  std::shared_ptr<module> get_module(const std::string &name);
65 
71  std::shared_ptr<module> find_module(const std::string &name);
72 
78  std::shared_ptr<type_struct> find_struct(const std::string &name);
79 
80  private:
85  std::shared_ptr<entity> find(const std::string &name);
86 
87  };
88 
89 
90 }
91 
92 
93 #endif //FORBCC_NAMESPACE_H
void print_definition(code_ostream &out) const override
Prints module definition (should be called within a source file)
Definition: module.cpp:35
A template that can be used to declare a list of unique ordered items.
Definition: ordered_unique_list.hpp:16
module(const std::shared_ptr< entity > &parent, const std::string &name)
Using constructor from superclass.
Definition: module.hpp:35
module & operator=(module &&)=default
This class supports moving.
A template that can be used to ease the declaration of a shared_pointer of a given type...
Definition: shareable.hpp:13
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
std::shared_ptr< module > find_module(const std::string &name)
Finds a module by its name (which may contain :: qualifiers), following C++ scope resolution and visi...
Definition: module.cpp:47
Represents a module, which basically is a namespace, so it&#39;s a collection of other entities...
Definition: module.hpp:21
~module() override=default
This class is virtual, so it requires a virtual destructor.
module()
Empty module, used to preallocate variables in arrays or to use later assignment operator.
Definition: module.hpp:32
static const std::shared_ptr< module > global_module
Static member representing the global namespace, used as base for the tree-like structure of entities...
Definition: module.hpp:26
This output stream supports indentation of code lines, which are formatted at each std::endl...
Definition: code_ostream.hpp:14
std::shared_ptr< module > get_module(const std::string &name)
Returns a pointer to a module identified by name, but only if said module is defined directly within ...
Definition: module.cpp:43
std::shared_ptr< type_struct > find_struct(const std::string &name)
Finds a custom structure type by its name (which may contain :: qualifiers), following C++ scope reso...
Definition: module.cpp:51
Definition: code_ostream.hpp:11
Any code entity that should be generated by the compiler: namespaces, classes, structures, methods, variables.
Definition: entity.hpp:18
void print_declaration(code_ostream &out) const override
Prints module declaration (should be called within a header file)
Definition: module.cpp:16