JSBModule.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. private:
  70. void ProcessOverloads();
  71. void ProcessExcludes();
  72. void ProcessTypeScriptDecl();
  73. void ProcessHaxeDecl();
  74. void ScanHeaders();
  75. String name_;
  76. SharedPtr<JSBPackage> package_;
  77. Vector<SharedPtr<JSBHeader>> headers_;
  78. Vector<String> includes_;
  79. Vector<String> jsmodulePreamble_;
  80. Vector<String> sourceDirs_;
  81. Vector<String> classnames_;
  82. Vector<String> genericClassnames_;
  83. HashMap<String, String> classRenames_;
  84. // native name -> JSBClass
  85. HashMap<StringHash, SharedPtr<JSBClass> > classes_;
  86. HashMap<StringHash, SharedPtr<JSBEnum> > enums_;
  87. HashMap<String, Constant> constants_;
  88. Vector<String> requirements_;
  89. SharedPtr<JSONFile> moduleJSON_;
  90. bool dotNetModule_;
  91. };
  92. }