JSBType.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #pragma once
  5. #include <Atomic/Container/Str.h>
  6. #include "JSBClass.h"
  7. using namespace Atomic;
  8. class JSBClass;
  9. class JSBPrimitiveType;
  10. class JSBStringType;
  11. class JSBStringHashType;
  12. class JSBClassType;
  13. class JSBEnumType;
  14. class JSBHeapPtrType;
  15. class JSBType
  16. {
  17. public:
  18. virtual JSBPrimitiveType* asPrimitiveType() { return 0; }
  19. virtual JSBClassType* asClassType() { return 0; }
  20. virtual JSBStringType* asStringType() { return 0; }
  21. virtual JSBStringHashType* asStringHashType() { return 0; }
  22. virtual JSBEnumType* asEnumType() { return 0; }
  23. virtual JSBHeapPtrType* asHeapPtrType() { return 0; }
  24. static JSBType* Parse(const String& value);
  25. virtual String ToString() = 0;
  26. };
  27. class JSBPrimitiveType : public JSBType
  28. {
  29. public:
  30. // needs to match IntegerType::Kind
  31. enum Kind {
  32. Char,
  33. Char16,
  34. Char32,
  35. WideChar,
  36. Bool,
  37. Short,
  38. Int,
  39. Long,
  40. LongLong,
  41. Float // this doesn't exist in IntegerType::Kind
  42. };
  43. JSBPrimitiveType(int kind, bool isUnsigned = false)
  44. {
  45. kind_ = (Kind) kind;
  46. isUnsigned_ = isUnsigned;
  47. }
  48. String ToString()
  49. {
  50. switch (kind_)
  51. {
  52. case Char:
  53. case Char16:
  54. case Char32:
  55. case WideChar:
  56. return "char";
  57. case Bool:
  58. return "bool";
  59. case Short:
  60. return "short";
  61. case Int:
  62. return "int";
  63. case Long:
  64. return "long";
  65. case LongLong:
  66. return "long long";
  67. case Float:
  68. return "float";
  69. }
  70. return "???";
  71. }
  72. Kind kind_;
  73. bool isUnsigned_;
  74. virtual JSBPrimitiveType* asPrimitiveType() { return this; }
  75. };
  76. class JSBStringType : public JSBType
  77. {
  78. public:
  79. virtual JSBStringType* asStringType() { return this; }
  80. String ToString() { return "String"; }
  81. };
  82. class JSBStringHashType : public JSBType
  83. {
  84. public:
  85. virtual JSBStringHashType* asStringHashType() { return this; }
  86. String ToString() { return "StringHash"; }
  87. };
  88. class JSBHeapPtrType : public JSBType
  89. {
  90. public:
  91. virtual JSBHeapPtrType* asHeapPtrType() { return this; }
  92. String ToString() { return "JS_HEAP_PTR"; }
  93. };
  94. class JSBEnumType : public JSBType
  95. {
  96. public:
  97. JSBEnum* enum_;
  98. JSBEnumType(JSBEnum* penum) : enum_(penum) {}
  99. virtual JSBEnumType* asEnumType() { return this; }
  100. String ToString() { return enum_->name_; }
  101. };
  102. class JSBClassType : public JSBType
  103. {
  104. public:
  105. JSBClass* class_;
  106. virtual JSBClassType* asClassType() { return this; }
  107. JSBClassType(JSBClass* klass) : class_(klass)
  108. {
  109. }
  110. String ToString()
  111. {
  112. return class_->GetClassName();
  113. }
  114. };