JSBPreprocessVisitor.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #pragma once
  8. #include <Atomic/IO/Log.h>
  9. #include "JSBNameVisitor.h"
  10. #include "JSBEnum.h"
  11. #include "JSBModule.h"
  12. #include "JSBHeader.h"
  13. namespace ToolCore
  14. {
  15. class JSBPreprocessVisitor : public SymbolVisitor
  16. {
  17. public:
  18. JSBPreprocessVisitor(JSBHeader* header, TranslationUnit *unit, Namespace* globalNamespace) :
  19. header_(header),
  20. globalNamespace_(globalNamespace)
  21. {
  22. module_ = header_->GetModule();
  23. accept(globalNamespace_);
  24. }
  25. String getNameString(const Name* name)
  26. {
  27. JSBNameVisitor nvisitor;
  28. return nvisitor(name);
  29. }
  30. // reject template types
  31. virtual bool visit(Template *t)
  32. {
  33. return false;
  34. }
  35. virtual bool visit(Enum *penum)
  36. {
  37. // don't want enum's in classes
  38. if (classes_.Size())
  39. return true;
  40. JSBModule* module = header_->GetModule();
  41. JSBEnum* jenum = new JSBEnum(header_->GetContext(), module_, getNameString(penum->name()));
  42. jenum->SetHeader(header_);
  43. for (unsigned i = 0; i < penum->memberCount(); i++)
  44. {
  45. Symbol* symbol = penum->memberAt(i);
  46. String name = getNameString(symbol->name());
  47. String value = "";
  48. Declaration* decl = symbol->asDeclaration();
  49. if (decl)
  50. {
  51. EnumeratorDeclaration* enumDecl = decl->asEnumeratorDeclarator();
  52. const StringLiteral* constantValue = enumDecl->constantValue();
  53. if (constantValue)
  54. {
  55. value = constantValue->chars();
  56. }
  57. }
  58. jenum->AddValue(name);
  59. }
  60. jenum->Preprocess();
  61. module->RegisterEnum(jenum);
  62. return true;
  63. }
  64. virtual bool visit(Class *klass)
  65. {
  66. classes_.Push(klass);
  67. String name = getNameString(klass->name());
  68. JSBModule* module = header_->GetModule();
  69. module->RegisterClass(name);
  70. return true;
  71. }
  72. void postVisit(Symbol *symbol)
  73. {
  74. if (symbol->asClass())
  75. {
  76. classes_.Remove((Class*) symbol);
  77. }
  78. }
  79. private:
  80. SharedPtr<JSBHeader> header_;
  81. SharedPtr<JSBModule> module_;
  82. PODVector<Class*> classes_;
  83. Namespace* globalNamespace_;
  84. };
  85. }