CSClassWriter.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #include <Atomic/IO/FileSystem.h>
  8. #include "../JSBind.h"
  9. #include "../JSBModule.h"
  10. #include "../JSBPackage.h"
  11. #include "../JSBEnum.h"
  12. #include "../JSBClass.h"
  13. #include "../JSBFunction.h"
  14. #include "CSClassWriter.h"
  15. #include "CSFunctionWriter.h"
  16. namespace ToolCore
  17. {
  18. CSClassWriter::CSClassWriter(JSBClass *klass) : JSBClassWriter(klass)
  19. {
  20. }
  21. void CSClassWriter::WriteNativeFunctions(String& source)
  22. {
  23. for (unsigned i = 0; i < klass_->functions_.Size(); i++)
  24. {
  25. JSBFunction* function = klass_->functions_.At(i);
  26. if (function->Skip())
  27. continue;
  28. if (function->IsDestructor())
  29. continue;
  30. CSFunctionWriter writer(function);
  31. writer.GenerateNativeSource(source);
  32. }
  33. }
  34. void CSClassWriter::GenerateNativeSource(String& sourceOut)
  35. {
  36. String source = "";
  37. if (klass_->IsNumberArray())
  38. return;
  39. source.AppendWithFormat("ClassID csb_%s_GetClassID()\n{\n", klass_->GetNativeName().CString());
  40. source.AppendWithFormat("return %s::GetClassIDStatic();\n}\n", klass_->GetNativeName().CString());
  41. WriteNativeFunctions(source);
  42. sourceOut += source;
  43. }
  44. void CSClassWriter::GenerateManagedSource(String& sourceOut)
  45. {
  46. String source = "";
  47. if (klass_->IsNumberArray())
  48. return;
  49. Indent();
  50. source += "\n";
  51. String line;
  52. if (klass_->GetBaseClass())
  53. line = "public partial class " + klass_->GetName() + " : " + klass_->GetBaseClass()->GetName() + "\n";
  54. else
  55. line = "public partial class " + klass_->GetName() + "\n";
  56. source += IndentLine(line);
  57. source += IndentLine("{\n");
  58. Indent();
  59. // managed functions
  60. for (unsigned i = 0; i < klass_->functions_.Size(); i++)
  61. {
  62. JSBFunction* function = klass_->functions_.At(i);
  63. if (function->Skip())
  64. continue;
  65. if (function->IsDestructor())
  66. continue;
  67. CSFunctionWriter fwriter(function);
  68. fwriter.GenerateManagedSource(source);
  69. }
  70. Dedent();
  71. source += IndentLine("}\n");
  72. Dedent();
  73. sourceOut += source;
  74. }
  75. void CSClassWriter::GenerateSource(String& sourceOut)
  76. {
  77. }
  78. }