BfSource.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. #include "BeefySysLib/Common.h"
  3. #include "BfAst.h"
  4. #include "BeefySysLib/util/BumpAllocator.h"
  5. #include "BeefySysLib/util/Hash.h"
  6. NS_BF_BEGIN;
  7. class BfProject;
  8. class BfParser;
  9. class BfParserData;
  10. class BfSourceData
  11. {
  12. public:
  13. enum ExternalNodesState : int8
  14. {
  15. ExternalNodesState_Unchecked,
  16. ExternalNodesState_Success,
  17. ExternalNodesState_Failed
  18. };
  19. public:
  20. const char* mSrc;
  21. int mSrcLength;
  22. BfAstAllocManager* mAstAllocManager;
  23. BfAstAllocator mAlloc;
  24. BfRootNode* mSidechannelRootNode; // Holds comments and preprocessor nodes
  25. BfRootNode* mRootNode;
  26. BfRootNode* mErrorRootNode;
  27. BfSizedArray<BfExteriorNode> mExteriorNodes;
  28. int mExteriorNodesCheckIdx; // 0 = unchecked, -1 = failed, >0 means success and equals the BfSystem.mTypesIdx
  29. BfSourceData()
  30. {
  31. mSrc = NULL;
  32. mSrcLength = 0;
  33. mAstAllocManager = NULL;
  34. mSidechannelRootNode = NULL;
  35. mRootNode = NULL;
  36. mErrorRootNode = NULL;
  37. mExteriorNodesCheckIdx = 0;
  38. }
  39. virtual ~BfSourceData()
  40. {
  41. BF_ASSERT(mExteriorNodes.mSize >= 0);
  42. BF_ASSERT(mExteriorNodes.mSize < 0x00FFFFFF);
  43. delete [] mSrc;
  44. }
  45. virtual BfParserData* ToParserData()
  46. {
  47. return NULL;
  48. }
  49. virtual BfParser* ToParser()
  50. {
  51. return NULL;
  52. }
  53. };
  54. class BfSource
  55. {
  56. public:
  57. static const int SCRATCH_SIZE = sizeof(BfGenericInstanceTypeRef) + sizeof(BfDirectStrTypeReference);
  58. BfSourceData* mSourceData;
  59. BfProject* mProject;
  60. BfSystem* mSystem;
  61. BfAstAllocManager* mAstAllocManager;
  62. BfAstAllocator* mAlloc;
  63. const char* mSrc;
  64. int mSrcLength;
  65. int mSrcAllocSize;
  66. bool mParsingFailed;
  67. bool mIsClosed;
  68. uint8* mAstScratch;
  69. int mRefCount; // Refs from BfTypeDefs
  70. Array<BfTypeDef*> mTypeDefs;
  71. BfRootNode* mSidechannelRootNode; // Holds comments and preprocessor nodes
  72. BfRootNode* mRootNode;
  73. BfRootNode* mErrorRootNode;
  74. BfParser* mNextRevision;
  75. BfParser* mPrevRevision;
  76. SizedArray<BfAstNode*, 8> mPendingSideNodes;
  77. SizedArray<BfAstNode*, 8> mPendingErrorNodes;
  78. public:
  79. bool WantsStats();
  80. public:
  81. BfSource(BfSystem* bfSystem);
  82. virtual ~BfSource();
  83. virtual BfParser* ToParser() { return NULL; }
  84. virtual void HadSrcRealloc() {}
  85. BfErrorNode* CreateErrorNode(BfAstNode* astNode);
  86. bool HasPendingError(BfAstNode* astNode);
  87. void AddErrorNode(BfAstNode* astNode);
  88. int AllocChars(int charCount);
  89. void FinishSideNodes();
  90. virtual void Close(); // Writing done, return unused pages but retain used pages
  91. };
  92. NS_BF_END;