JSBClass.h 4.4 KB

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