JSBModule.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include <Atomic/Core/Object.h>
  24. using namespace Atomic;
  25. namespace Atomic
  26. {
  27. class JSONFile;
  28. }
  29. namespace ToolCore
  30. {
  31. class JSBPackage;
  32. class JSBHeader;
  33. class JSBClass;
  34. class JSBEnum;
  35. class JSBPrimitiveType;
  36. class JSBModule : public Object
  37. {
  38. friend class JSModuleWriter;
  39. friend class CSModuleWriter;
  40. ATOMIC_OBJECT(JSBModule, Object)
  41. public:
  42. struct Constant
  43. {
  44. JSBPrimitiveType* type;
  45. String value;
  46. };
  47. JSBModule(Context* context, JSBPackage* package);
  48. virtual ~JSBModule();
  49. const String& GetName() { return name_; }
  50. JSBPackage* GetPackage() { return package_; }
  51. JSBClass* GetClass(const String& name);
  52. Vector<SharedPtr<JSBClass>> GetClasses();
  53. Vector<SharedPtr<JSBEnum>> GetEnums();
  54. HashMap<String, Constant>& GetConstants() { return constants_; }
  55. void RegisterClass(String name);
  56. JSBEnum* GetEnum(const String& name);
  57. void RegisterEnum(JSBEnum* jenum);
  58. bool ContainsConstant(const String& constantName);
  59. void RegisterConstant(const String& constantName, const String& value, unsigned type, bool isUnsigned = false);
  60. bool Requires(const String& requirement) { return requirements_.Contains(requirement); }
  61. bool Load(const String& jsonFilename);
  62. void PreprocessHeaders();
  63. void VisitHeaders();
  64. void PreprocessClasses();
  65. void ProcessClasses();
  66. void PostProcessClasses();
  67. void SetDotNetModule(bool value) { dotNetModule_ = value; }
  68. bool GetDotNetModule() { return dotNetModule_; }
  69. /// Define guard for specific module code
  70. String GetModuleDefineGuard() const;
  71. /// Define guard for specific module code
  72. String GetClassDefineGuard(const String& name, const String& language = String::EMPTY) const;
  73. private:
  74. void ProcessOverloads();
  75. void ProcessExcludes();
  76. void ProcessClassExcludes();
  77. void ProcessTypeScriptDecl();
  78. void ProcessHaxeDecl();
  79. void ScanHeaders();
  80. String name_;
  81. SharedPtr<JSBPackage> package_;
  82. Vector<SharedPtr<JSBHeader>> headers_;
  83. Vector<String> includes_;
  84. Vector<String> jsmodulePreamble_;
  85. Vector<String> sourceDirs_;
  86. Vector<String> classnames_;
  87. Vector<String> genericClassnames_;
  88. HashMap<String, String> classRenames_;
  89. // native name -> JSBClass
  90. HashMap<StringHash, SharedPtr<JSBClass> > classes_;
  91. HashMap<StringHash, SharedPtr<JSBEnum> > enums_;
  92. HashMap<String, Constant> constants_;
  93. Vector<String> requirements_;
  94. SharedPtr<JSONFile> moduleJSON_;
  95. HashMap<String, Vector<String>> classExcludes_;
  96. bool dotNetModule_;
  97. };
  98. }