ASUtils.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // Copyright (c) 2008-2022 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. #pragma once
  23. #include "XmlAnalyzer.h"
  24. #include <map>
  25. #include <stdexcept>
  26. #include <string>
  27. namespace ASBindingGenerator
  28. {
  29. enum class TypeUsage
  30. {
  31. FunctionParameter = 0,
  32. FunctionReturn,
  33. StaticField,
  34. Field,
  35. };
  36. struct ConvertedVariable
  37. {
  38. std::string asDeclaration_;
  39. std::string cppDeclaration_;
  40. std::string glue_;
  41. bool NeedWrapper() const { return !glue_.empty(); }
  42. };
  43. std::string JoinASDeclarations(const std::vector<ConvertedVariable>& vars);
  44. enum class VariableUsage
  45. {
  46. FunctionParameter = 0,
  47. FunctionReturn,
  48. StaticField,
  49. Field,
  50. };
  51. ConvertedVariable CppVariableToAS(const TypeAnalyzer& type, VariableUsage usage, const std::string& name = "", const std::string& defaultValue = "");
  52. std::string CppTypeToAS(const TypeAnalyzer& type, TypeUsage typeUsage);
  53. std::shared_ptr<EnumAnalyzer> FindEnum(const std::string& name);
  54. std::string CppPrimitiveTypeToAS(const std::string& cppType);
  55. std::string CppValueToAS(const std::string& cppValue);
  56. class Exception : public std::runtime_error
  57. {
  58. using runtime_error::runtime_error;
  59. };
  60. bool IsKnownCppType(const std::string& name);
  61. std::shared_ptr<ClassAnalyzer> FindClassByName(const std::string& name);
  62. std::shared_ptr<ClassAnalyzer> FindClassByID(const std::string& name);
  63. std::string GenerateWrapperName(const GlobalFunctionAnalyzer& functionAnalyzer);
  64. std::string GenerateWrapperName(const ClassStaticFunctionAnalyzer& functionAnalyzer);
  65. std::string GenerateWrapperName(const MethodAnalyzer& methodAnalyzer, bool templateVersion = false);
  66. std::string GenerateWrapper(const GlobalFunctionAnalyzer& functionAnalyzer, const std::vector<ConvertedVariable>& convertedParams, const ConvertedVariable& convertedReturn);
  67. std::string GenerateWrapper(const ClassStaticFunctionAnalyzer& functionAnalyzer, bool templateVersion, const std::vector<ConvertedVariable>& convertedParams, const ConvertedVariable& convertedReturn);
  68. std::string GenerateWrapper(const MethodAnalyzer& methodAnalyzer, bool templateVersion, const std::vector<ConvertedVariable>& convertedParams, const ConvertedVariable& convertedReturn);
  69. std::string GenerateConstructorWrapper(const MethodAnalyzer& methodAnalyzer, const std::vector<ConvertedVariable>& convertedParams);
  70. std::string GenerateFactoryWrapper(const MethodAnalyzer& methodAnalyzer, const std::vector<ConvertedVariable>& convertedParams);
  71. std::string Generate_asFUNCTIONPR(const GlobalFunctionAnalyzer& functionAnalyzer);
  72. std::string Generate_asFUNCTIONPR(const ClassStaticFunctionAnalyzer& functionAnalyzer, bool templateVersion);
  73. std::string Generate_asMETHODPR(const MethodAnalyzer& methodAnalyzer, bool templateVersion);
  74. }