chigraph  master
Systems programming language written for beginners in LLVM
ChiModule.hpp
Go to the documentation of this file.
1 
4 #ifndef CHI_CHI_MODULE_HPP
5 #define CHI_CHI_MODULE_HPP
6 
7 #pragma once
8 
9 #include "chi/Fwd.hpp"
11 #include "chi/Support/json.hpp"
12 
13 #include <boost/filesystem.hpp>
14 #include <boost/utility/string_view.hpp>
15 
16 #include <set>
17 
18 #include <ctime>
19 
21 namespace chi {
24 struct ChiModule {
28  ChiModule(Context& contextArg, boost::filesystem::path moduleFullName);
29 
31  virtual ~ChiModule() = default;
32 
40  virtual Result nodeTypeFromName(boost::string_view name, const nlohmann::json& jsonData,
41  std::unique_ptr<NodeType>* toFill) = 0;
42 
46  virtual DataType typeFromName(boost::string_view name) = 0;
47 
50  virtual std::vector<std::string> nodeTypeNames() const = 0;
51 
54  virtual std::vector<std::string> typeNames() const = 0;
55 
58  std::string shortName() const { return mName; }
61  std::string fullName() const { return mFullName.generic_string(); }
64  boost::filesystem::path fullNamePath() const { return mFullName; }
67 
68  Context& context() const { return *mContext; }
69 
73  virtual Result addForwardDeclarations(llvm::Module& module) const = 0;
74 
79  virtual Result generateModule(llvm::Module& module) = 0;
80 
83  const std::set<boost::filesystem::path>& dependencies() const { return mDependencies; }
84 
89  Result addDependency(boost::filesystem::path newDepFullPath);
90 
95  bool removeDependency(std::string depName) {
96  return mDependencies.erase(std::move(depName)) == 1;
97  }
98 
101  std::time_t lastEditTime() const { return mLastEditTime; }
102 
105  void updateLastEditTime(std::time_t newLastEditTime = std::time(nullptr)) {
106  mLastEditTime = newLastEditTime;
107  }
108 
109 private:
110  boost::filesystem::path mFullName;
111  std::string mName;
112  Context* mContext;
113 
114  std::set<boost::filesystem::path> mDependencies;
115 
116  std::time_t mLastEditTime = 0;
117 };
118 } // namespace chi
119 
120 #endif // CHI_CHI_MODULE_HPP
virtual Result generateModule(llvm::Module &module)=0
Generate a llvm::Module from the module.
Forward declares all the chigraph data types.
virtual std::vector< std::string > typeNames() const =0
Get the possible DataType names.
virtual Result nodeTypeFromName(boost::string_view name, const nlohmann::json &jsonData, std::unique_ptr< NodeType > *toFill)=0
Create a node type that is in the module from the name and json.
Result addDependency(boost::filesystem::path newDepFullPath)
Add a dependency to the module Loads the module from context() if it isn&#39;t already loaded...
Definition: ChiModule.cpp:13
ChiModule(Context &contextArg, boost::filesystem::path moduleFullName)
Default constructor.
Definition: ChiModule.cpp:8
virtual ~ChiModule()=default
Destructor.
virtual std::vector< std::string > nodeTypeNames() const =0
Get the possible node type names.
std::string fullName() const
Get the full name of the module.
Definition: ChiModule.hpp:61
The class that handles the loading, creation, storing, and compilation of modules It also stores a LL...
Definition: Context.hpp:55
An abstract class that represents a module of code in Chigraph Can be compiled to a llvm::Module...
Definition: ChiModule.hpp:24
const std::set< boost::filesystem::path > & dependencies() const
Get the dependencies.
Definition: ChiModule.hpp:83
virtual Result addForwardDeclarations(llvm::Module &module) const =0
Adds forward declartions for the functions in this module.
void updateLastEditTime(std::time_t newLastEditTime=std::time(nullptr))
Update the last edit time, signifying that it&#39;s been edited.
Definition: ChiModule.hpp:105
boost::filesystem::path fullNamePath() const
Get the full name of the module in a path.
Definition: ChiModule.hpp:64
bool removeDependency(std::string depName)
Remove a dependency Does not unload from context.
Definition: ChiModule.hpp:95
virtual DataType typeFromName(boost::string_view name)=0
Get a DataType from the name.
The namespace where chigraph lives.
Context & context() const
Get the Context that this module belongs to.
Definition: ChiModule.hpp:68
A type of data Loose wrapper around llvm::Type*, except it knows which ChiModule it&#39;s in and it embed...
Definition: DataType.hpp:17
std::time_t lastEditTime() const
Get the time that this module was last edited.
Definition: ChiModule.hpp:101
std::string shortName() const
Get the short name of the module (the last bit)
Definition: ChiModule.hpp:58
The result object, used for identifiying errors with good diagnostics.
Definition: Result.hpp:72