| 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
86 DataType type;
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
chi::DataType::module
ChiModule & module() const
Get the module this is a part of.
Definition: DataType.hpp:29
Fwd.hpp
Forward declares all the chigraph data types.
chi::DataType::llvmType
llvm::Type * llvmType() const
Get the underlying llvm::Type.
Definition: DataType.hpp:38
chi::NamedDataType::type
DataType type
The type.
Definition: DataType.hpp:86
chi::DataType::operator!=
bool operator!=(const DataType &lhs, const DataType &rhs)
Inequality check.
Definition: DataType.hpp:69
chi::NamedDataType::valid
bool valid() const
See if the pair is valid.
Definition: DataType.hpp:80
chi::NamedDataType::NamedDataType
NamedDataType(std::string n={}, DataType ty={})
Construct a NamedDataType from the name and the type.
Definition: DataType.hpp:76
chi::NamedDataType
Basicaly a std::pair<std::string, DataType>, except it has nicer names.
Definition: DataType.hpp:72
chi::NamedDataType::operator!=
bool operator!=(const NamedDataType &lhs, const NamedDataType &rhs)
Check if two NamedDataType objects aren&#39;t equal.
Definition: DataType.hpp:103
chi::ChiModule
An abstract class that represents a module of code in Chigraph Can be compiled to a llvm::Module...
Definition: ChiModule.hpp:24
chi::DataType::DataType
DataType(ChiModule *chiMod=nullptr, std::string typeName={}, llvm::Type *llvmtype=nullptr, llvm::DIType *debugTy=nullptr)
Constructor.
Definition: DataType.hpp:23
chi::DataType::qualifiedName
std::string qualifiedName() const
Get the qualified name of the type (module().fullName() + ":" name())
Definition: DataType.cpp:8
chi::DataType::unqualifiedName
const std::string & unqualifiedName() const
Get the unqualified name of the type.
Definition: DataType.hpp:32
chi::DataType::debugType
llvm::DIType * debugType() const
Get the debug type.
Definition: DataType.hpp:41
chi::NamedDataType::operator==
bool operator==(const NamedDataType &lhs, const NamedDataType &rhs)
Check if two NamedDataType objects are equal.
Definition: DataType.hpp:94
chi::DataType::valid
bool valid() const
Check if the DataType is valid (if it&#39;s actually bound to a type and module)
Definition: DataType.hpp:44
chi::NamedDataType::name
std::string name
The name.
Definition: DataType.hpp:83
chi
The namespace where chigraph lives.
Definition: BitcodeParser.hpp:12
chi::DataType
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
chi::DataType::operator==
bool operator==(const DataType &lhs, const DataType &rhs)
Equality check.
Definition: DataType.hpp:60