JSBHeader.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include <Atomic/IO/File.h>
  23. #include "cplusplus/CPlusPlus.h"
  24. using namespace CPlusPlus;
  25. #include "JSBPreprocessVisitor.h"
  26. #include "JSBHeaderVisitor.h"
  27. #include "JSBModule.h"
  28. #include "JSBHeader.h"
  29. namespace ToolCore
  30. {
  31. JSBHeader::JSBHeader(Context* context, JSBModule* module, const String& filepath) : Object(context),
  32. translationUnit_(0),
  33. globalNamespace_(0),
  34. filepath_(filepath),
  35. module_(module)
  36. {
  37. }
  38. JSBHeader::~JSBHeader()
  39. {
  40. }
  41. void JSBHeader::Parse()
  42. {
  43. Control* control = new Control();
  44. const StringLiteral *fileId = control->stringLiteral(filepath_.CString(), filepath_.Length() );
  45. LanguageFeatures features;
  46. features.qtEnabled = false;
  47. features.qtMocRunEnabled = false;
  48. features.qtKeywordsEnabled = false;
  49. features.cxx11Enabled = true;
  50. features.objCEnabled = false;
  51. features.c99Enabled = false;
  52. translationUnit_ = new TranslationUnit(control, fileId);
  53. translationUnit_->setLanguageFeatures(features);
  54. control->switchTranslationUnit(translationUnit_);
  55. File file(context_);
  56. file.Open(filepath_);
  57. unsigned size = file.GetSize();
  58. data_ = new char[size + 1];
  59. data_[size] = '\0';
  60. file.Read(data_, size);
  61. // TODO: add error reporting
  62. translationUnit_->blockErrors(true);
  63. translationUnit_->setSource(data_, size);
  64. translationUnit_->tokenize();
  65. translationUnit_->parse();
  66. globalNamespace_ = control->newNamespace(0);
  67. Bind* semantic = new Bind(translationUnit_);
  68. semantic->setSkipFunctionBodies(true);
  69. (*semantic)(translationUnit_->ast()->asTranslationUnit(), globalNamespace_);
  70. }
  71. void JSBHeader::VisitPreprocess()
  72. {
  73. JSBPreprocessVisitor(this, translationUnit_,globalNamespace_);
  74. }
  75. void JSBHeader::VisitHeader()
  76. {
  77. JSBHeaderVisitor(this, translationUnit_, globalNamespace_);
  78. }
  79. }