Type.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "Type.h"
  2. #include "Semantic.h"
  3. #include "Builtin.h"
  4. #include <llvm/IR/DerivedTypes.h>
  5. #include <llvm/IR/Type.h>
  6. using namespace qlow;
  7. sem::Type::~Type(void)
  8. {
  9. }
  10. bool sem::Type::equals(const Type* other) const
  11. {
  12. return this == other;
  13. }
  14. sem::Type* sem::Type::VOID = new sem::NativeType(sem::NativeType::Type::VOID);
  15. sem::Type* sem::Type::INTEGER = new sem::NativeType(sem::NativeType::Type::INTEGER);
  16. sem::Type* sem::Type::BOOLEAN = new sem::NativeType(sem::NativeType::Type::BOOLEAN);
  17. llvm::Type* sem::ClassType::getLlvmType (llvm::LLVMContext& context) const
  18. {
  19. return classType->llvmType;
  20. }
  21. bool sem::ClassType::equals(const Type* other) const
  22. {
  23. if (auto* oct = dynamic_cast<const ClassType*>(other); oct) {
  24. return this->classType == oct->classType;
  25. }
  26. else {
  27. return false;
  28. }
  29. }
  30. llvm::Type* sem::ArrayType::getLlvmType (llvm::LLVMContext& context) const
  31. {
  32. // TODO implement
  33. return nullptr;
  34. }
  35. bool sem::ArrayType::equals(const Type* other) const
  36. {
  37. if (auto* oct = dynamic_cast<const ArrayType*>(other); oct) {
  38. return this->arrayType->equals(oct->arrayType);
  39. }
  40. else {
  41. return false;
  42. }
  43. }
  44. llvm::Type* sem::NativeType::getLlvmType (llvm::LLVMContext& context) const
  45. {
  46. switch (type) {
  47. case VOID:
  48. return llvm::Type::getVoidTy(context);
  49. case INTEGER:
  50. return llvm::Type::getInt32Ty(context);
  51. case BOOLEAN:
  52. return llvm::Type::getInt1Ty(context);
  53. /*case Kind::CLASS:
  54. return data.classType->llvmType;*/
  55. }
  56. }
  57. bool sem::NativeType::equals(const sem::Type* other) const
  58. {
  59. if (auto* oct = dynamic_cast<const NativeType*>(other); oct) {
  60. return this->type == oct->type;
  61. }
  62. else {
  63. return false;
  64. }
  65. }