chigraph  master
Systems programming language written for beginners in LLVM
DataType.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #ifndef CHI_DATA_TYPE_HPP
7 #define CHI_DATA_TYPE_HPP
8 
9 #include "chi/Fwd.hpp"
10 
11 #include <string>
12 
13 namespace chi {
17 struct DataType {
23  DataType(ChiModule* chiMod = nullptr, std::string typeName = {}, llvm::Type* llvmtype = nullptr,
24  llvm::DIType* debugTy = nullptr)
25  : mModule(chiMod), mName{typeName}, mLLVMType{llvmtype}, mDIType{debugTy} {}
26 
29  ChiModule& module() const { return *mModule; }
32  const std::string& unqualifiedName() const { return mName; }
35  std::string qualifiedName() const;
38  llvm::Type* llvmType() const { return mLLVMType; }
41  llvm::DIType* debugType() const { return mDIType; }
44  bool valid() const {
45  return mModule != nullptr && mName != "" && mLLVMType != nullptr && mDIType != nullptr;
46  }
47 
48 private:
49  ChiModule* mModule;
50  std::string mName;
51  llvm::Type* mLLVMType;
52  llvm::DIType* mDIType;
53 };
54 
60 inline bool operator==(const DataType& lhs, const DataType& rhs) {
61  return &lhs.module() == &rhs.module() && lhs.unqualifiedName() == rhs.unqualifiedName();
62 }
63 
69 inline bool operator!=(const DataType& lhs, const DataType& rhs) { return !(lhs == rhs); }
70 
72 struct NamedDataType {
76  NamedDataType(std::string n = {}, DataType ty = {}) : name{std::move(n)}, type{std::move(ty)} {}
77 
80  bool valid() const { return type.valid(); }
81 
83  std::string name;
84 
87 };
88 
94 inline bool operator==(const NamedDataType& lhs, const NamedDataType& rhs) {
95  return lhs.name == rhs.name && lhs.type == rhs.type;
96 }
97 
103 inline bool operator!=(const NamedDataType& lhs, const NamedDataType& rhs) { return !(lhs == rhs); }
104 } // namespace chi
105 
106 #endif // CHI_DATA_TYPE_HPP
ChiModule & module() const
Get the module this is a part of.
Definition: DataType.hpp:29
Forward declares all the chigraph data types.
llvm::Type * llvmType() const
Get the underlying llvm::Type.
Definition: DataType.hpp:38
DataType type
The type.
Definition: DataType.hpp:86
bool operator!=(const DataType &lhs, const DataType &rhs)
Inequality check.
Definition: DataType.hpp:69
bool valid() const
See if the pair is valid.
Definition: DataType.hpp:80
NamedDataType(std::string n={}, DataType ty={})
Construct a NamedDataType from the name and the type.
Definition: DataType.hpp:76
Basicaly a std::pair<std::string, DataType>, except it has nicer names.
Definition: DataType.hpp:72
bool operator!=(const NamedDataType &lhs, const NamedDataType &rhs)
Check if two NamedDataType objects aren&#39;t equal.
Definition: DataType.hpp:103
An abstract class that represents a module of code in Chigraph Can be compiled to a llvm::Module...
Definition: ChiModule.hpp:24
DataType(ChiModule *chiMod=nullptr, std::string typeName={}, llvm::Type *llvmtype=nullptr, llvm::DIType *debugTy=nullptr)
Constructor.
Definition: DataType.hpp:23
std::string qualifiedName() const
Get the qualified name of the type (module().fullName() + ":" name())
Definition: DataType.cpp:8
const std::string & unqualifiedName() const
Get the unqualified name of the type.
Definition: DataType.hpp:32
llvm::DIType * debugType() const
Get the debug type.
Definition: DataType.hpp:41
bool operator==(const NamedDataType &lhs, const NamedDataType &rhs)
Check if two NamedDataType objects are equal.
Definition: DataType.hpp:94
bool valid() const
Check if the DataType is valid (if it&#39;s actually bound to a type and module)
Definition: DataType.hpp:44
std::string name
The name.
Definition: DataType.hpp:83
The namespace where chigraph lives.
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
bool operator==(const DataType &lhs, const DataType &rhs)
Equality check.
Definition: DataType.hpp:60