ASClassBinderNew.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  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. #include "ASResult.h"
  23. #include "ASUtils.h"
  24. #include "Tuning.h"
  25. #include "Utils.h"
  26. #include "XmlAnalyzer.h"
  27. #include "XmlSourceData.h"
  28. #include <cassert>
  29. #include <fstream>
  30. #include <iostream>
  31. #include <regex>
  32. #include <vector>
  33. namespace ASBindingGenerator
  34. {
  35. static void RegisterObjectType(const ClassAnalyzer& classAnalyzer, ProcessedClass& inoutProcessedClass)
  36. {
  37. string className = classAnalyzer.GetClassName();
  38. if (classAnalyzer.IsRefCounted() || Contains(classAnalyzer.GetComment(), "FAKE_REF"))
  39. {
  40. inoutProcessedClass.objectTypeRegistration_ = "engine->RegisterObjectType(\"" + className + "\", 0, asOBJ_REF);";
  41. }
  42. else // Value type
  43. {
  44. string flags = "asOBJ_VALUE | asGetTypeTraits<" + className + ">()";
  45. if (classAnalyzer.IsPod())
  46. {
  47. flags += " | asOBJ_POD";
  48. if (classAnalyzer.AllFloats())
  49. flags += " | asOBJ_APP_CLASS_ALLFLOATS";
  50. else if (classAnalyzer.AllInts())
  51. flags += " | asOBJ_APP_CLASS_ALLINTS";
  52. }
  53. inoutProcessedClass.objectTypeRegistration_ = "engine->RegisterObjectType(\"" + className + "\", sizeof(" + className + "), " + flags + ");";
  54. }
  55. }
  56. static void ProcessClass(const ClassAnalyzer& classAnalyzer)
  57. {
  58. if (classAnalyzer.IsInternal())
  59. return;
  60. // TODO: Remove
  61. if (classAnalyzer.IsTemplate())
  62. return;
  63. // TODO: Remove
  64. if (classAnalyzer.IsAbstract() && !(classAnalyzer.IsRefCounted() || Contains(classAnalyzer.GetComment(), "FAKE_REF")))
  65. return;
  66. string header = classAnalyzer.GetHeaderFile();
  67. Result::AddHeader(header);
  68. if (IsIgnoredHeader(header))
  69. return;
  70. ProcessedClass processedClass;
  71. processedClass.name_ = classAnalyzer.GetClassName();
  72. processedClass.comment_ = classAnalyzer.GetLocation();
  73. processedClass.insideDefine_ = InsideDefine(header);
  74. string classComment = classAnalyzer.GetComment();
  75. if (Contains(classComment, "NO_BIND"))
  76. {
  77. processedClass.objectTypeRegistration_ = "// Not registered because have @nobind mark";
  78. Result::classes_.push_back(processedClass);
  79. return;
  80. }
  81. if (Contains(classComment, "MANUAL_BIND"))
  82. {
  83. processedClass.objectTypeRegistration_ = "// Not registered because have @manualbind mark";
  84. Result::classes_.push_back(processedClass);
  85. return;
  86. }
  87. RegisterObjectType(classAnalyzer, processedClass);
  88. Result::classes_.push_back(processedClass);
  89. }
  90. void ProcessAllClassesNew()
  91. {
  92. for (auto element : SourceData::classesByID_)
  93. {
  94. xml_node compounddef = element.second;
  95. ClassAnalyzer analyzer(compounddef);
  96. ProcessClass(analyzer);
  97. }
  98. }
  99. } // namespace ASBindingGenerator