JSBClass.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #pragma once
  8. #include <Atomic/Core/Object.h>
  9. #include "JSBHeader.h"
  10. #include "JSBModule.h"
  11. using namespace Atomic;
  12. namespace ToolCore
  13. {
  14. class JSBPackage;
  15. class JSBFunction;
  16. class JSBType;
  17. // chosen function overrides
  18. class JSBFunctionSignature
  19. {
  20. public:
  21. JSBFunctionSignature(const String& name, const Vector<String>& sig);
  22. String name_;
  23. Vector<String> sig_;
  24. Vector<JSBType*> types_;
  25. bool Match(JSBFunction* function);
  26. void Parse() ;
  27. bool parsed_;
  28. };
  29. class JSBProperty
  30. {
  31. public:
  32. String name_;
  33. JSBFunction* getter_;
  34. JSBFunction* setter_;
  35. JSBProperty() : getter_(0), setter_(0)
  36. {
  37. }
  38. // returns proper case for property name
  39. // based on whether the Getter/Setter is all caps
  40. // GetMyValue -> myValue;
  41. // GetGUID -> guid
  42. String GetCasePropertyName()
  43. {
  44. if (!name_.Length())
  45. return name_;
  46. bool allUpper = true;
  47. for (unsigned k = 0; k < name_.Length(); k++)
  48. {
  49. if (!isupper(name_[k]))
  50. {
  51. allUpper = false;
  52. break;
  53. }
  54. }
  55. if (allUpper)
  56. {
  57. return name_.ToLower();
  58. }
  59. String name = name_;
  60. name[0] = tolower(name[0]);
  61. return name;
  62. }
  63. };
  64. class JSBClass : public Object
  65. {
  66. friend class JSBClassWriter;
  67. OBJECT(JSBClass)
  68. public:
  69. JSBClass(Context* context, JSBModule* module, const String& name, const String& nativeName);
  70. virtual ~JSBClass();
  71. const String& GetName() { return name_; }
  72. const String& GetNativeName() { return nativeName_; }
  73. JSBClass* GetBaseClass();
  74. PODVector<JSBClass*>& GetBaseClasses() {return baseClasses_; }
  75. PODVector<JSBFunction*>& GetFunctions() { return functions_; }
  76. bool IsAbstract() { return isAbstract_; }
  77. /// Note that if we at some point want to generate bindings for JSBClass
  78. /// this override will need to be addressed, as we'll need to know that JSBClass is
  79. /// itself an object
  80. bool IsObject() { return isObject_; }
  81. bool HasProperties() { return hasProperties_; }
  82. void GetPropertyNames(Vector<String>& names) { names = properties_.Keys(); }
  83. JSBProperty* GetProperty(const String& name)
  84. {
  85. if (!properties_.Contains(name))
  86. return 0;
  87. return properties_[name];
  88. }
  89. JSBHeader* GetHeader() { return header_; }
  90. JSBModule* GetModule() { return module_; }
  91. JSBPackage* GetPackage() { return module_->GetPackage(); }
  92. bool IsNumberArray() { return numberArrayElements_ != 0; }
  93. int GetNumberArrayElements() { return numberArrayElements_;}
  94. const String& GetArrayElementType() const { return arrayElementType_; }
  95. JSBFunction* GetConstructor();
  96. void SetAbstract(bool value = true) { isAbstract_ = value; }
  97. void SetObject(bool value = true) { isObject_ = value; }
  98. void SetHeader(JSBHeader* header) { header_ = header; }
  99. void SetBaseClass(JSBClass* baseClass);
  100. void SetSkipFunction(const String& name, bool skip = true);
  101. void AddFunction(JSBFunction* function);
  102. void AddFunctionOverride(JSBFunctionSignature* override) { overrides_.Push(override); }
  103. void AddFunctionExclude(JSBFunctionSignature* exclude) { excludes_.Push(exclude); }
  104. void AddPropertyFunction(JSBFunction* function);
  105. void AddTypeScriptDecl(const String& decl) { typeScriptDecls_.Push(decl); }
  106. unsigned GetNumTypeScriptDecl() { return typeScriptDecls_.Size(); }
  107. const String& GetTypeScriptDecl(unsigned idx) { return typeScriptDecls_[idx]; }
  108. void AddHaxeDecl(const String& decl) { haxeDecls_.Push(decl); }
  109. unsigned GetNumHaxeDecl() { return haxeDecls_.Size(); }
  110. const String& GetHaxeDecl(unsigned idx) { return haxeDecls_[idx]; }
  111. void Preprocess();
  112. void Process();
  113. void PostProcess();
  114. void Dump();
  115. private:
  116. void RecursiveAddBaseClass(PODVector<JSBClass *> &baseClasses);
  117. String name_;
  118. String nativeName_;
  119. SharedPtr<JSBHeader> header_;
  120. SharedPtr<JSBModule> module_;
  121. PODVector<JSBFunction*> functions_;
  122. PODVector<JSBClass*> baseClasses_;
  123. PODVector<JSBFunctionSignature*> overrides_;
  124. PODVector<JSBFunctionSignature*> excludes_;
  125. Vector<String> typeScriptDecls_;
  126. Vector<String> haxeDecls_;
  127. bool isAbstract_;
  128. bool isObject_;
  129. // Vector3, Color, etc are marshalled via arrays
  130. int numberArrayElements_;
  131. String arrayElementType_;
  132. bool hasProperties_;
  133. HashMap<String, JSBProperty*> properties_;
  134. };
  135. }