BfDefBuilder.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "BeefySysLib/Common.h"
  2. #include "BfAst.h"
  3. #include "BfSystem.h"
  4. NS_BF_BEGIN
  5. // This is the first pass through our ASTs, builds up Def structures in BfSystem
  6. // so when we go to compile we'll be able to resolve references
  7. class BfResolvePassData;
  8. class BfDefBuilder : public BfStructuralVisitor
  9. {
  10. public:
  11. struct NamespaceState
  12. {
  13. BfAtomComposite mNamespace;
  14. int mNamespaceSearchCount;
  15. NamespaceState()
  16. {
  17. mNamespaceSearchCount = -1;
  18. }
  19. };
  20. public:
  21. BfSource* mCurSource;
  22. BfSystem* mSystem;
  23. BfPassInstance* mPassInstance;
  24. BfTypeDef* mCurTypeDef;
  25. BfTypeDef* mCurDeclaringTypeDef;
  26. BfTypeDef* mCurActualTypeDef;
  27. bool mFullRefresh;
  28. bool mIsComptime;
  29. BfResolvePassData* mResolvePassData;
  30. BfAtomComposite mNamespace;
  31. Array<BfAtomComposite> mNamespaceSearch;
  32. Array<BfTypeReference*> mStaticSearch;
  33. Array<BfTypeReference*> mInternalAccessSet;
  34. HashContext* mFullHashCtx;
  35. HashContext* mSignatureHashCtx;
  36. Array<NamespaceState> mFileLevelNamespaceState;
  37. int mNamespaceBlockDepth;
  38. public:
  39. void ParseGenericParams(BfGenericParamsDeclaration* genericParamsDecl, BfGenericConstraintsDeclaration* genericConstraints, Array<BfGenericParamDef*>& genericParams, Array<BfExternalConstraintDef>* externConstraintDefs, int outerGenericSize, bool isInGeneric);
  40. BfProtection GetProtection(BfAstNode* protectionNode);
  41. bool WantsNode(BfAstNode* wholeNode, BfAstNode* startNode = NULL, int addLen = 0);
  42. //static BfNamedTypeReference* AllocTypeReference(BfSource* bfSource, const StringImpl& typeName);
  43. //static BfResolvedTypeReference* AllocTypeReference(BfSource* bfSource, BfType* type);
  44. static BfFieldDef* AddField(BfTypeDef* typeDef, BfTypeReference* typeRef, const StringImpl& name);
  45. static BfMethodDef* AddMethod(BfTypeDef* typeDef, BfMethodType methodType, BfProtection protection, bool isStatic, const StringImpl& name, bool addedAfterEmit = false);
  46. static BfMethodDef* AddDtor(BfTypeDef* typeDef);
  47. static void AddDynamicCastMethods(BfTypeDef* typeDef, bool needsDynamicCastMethods);
  48. static void AddParam(BfMethodDef* methodDef, BfTypeReference* typeRef, const StringImpl& paramName);
  49. BfTypeDef* ComparePrevTypeDef(BfTypeDef* prevTypeDef, BfTypeDef* checkTypeDef);
  50. void FinishTypeDef(bool wantsToString);
  51. void ParseAttributes(BfAttributeDirective* attributes, BfMethodDef* methodDef, bool checkReturnType = true);
  52. void ParseAttributes(BfAttributeDirective* attributes, BfTypeDef* typeDef);
  53. BfMethodDef* CreateMethodDef(BfMethodDeclaration* methodDecl, BfMethodDef* outerMethodDef = NULL);
  54. BfError* Fail(const StringImpl& errorStr, BfAstNode* refNode);
  55. void SetNamespaceState(const NamespaceState& namespaceState);
  56. public:
  57. BfDefBuilder(BfSystem* bfSystem);
  58. ~BfDefBuilder();
  59. void Process(BfPassInstance* passInstance, BfSource* bfSource, bool fullRefresh);
  60. void RemoveDefsFrom(BfSource* bfSource);
  61. virtual void Visit(BfIdentifierNode* identifier) override;
  62. virtual void Visit(BfMethodDeclaration* methodDeclaration) override;
  63. virtual void Visit(BfConstructorDeclaration* ctorDeclaration) override;
  64. virtual void Visit(BfPropertyDeclaration* propertyDeclaration) override;
  65. virtual void Visit(BfFieldDeclaration* fieldDeclaration) override;
  66. virtual void Visit(BfEnumCaseDeclaration* enumCaseDeclaration) override;
  67. virtual void Visit(BfTypeDeclaration* typeDeclaration) override;
  68. virtual void Visit(BfUsingDirective* usingDirective) override;
  69. virtual void Visit(BfUsingModDirective* usingDirective) override;
  70. virtual void Visit(BfNamespaceDeclaration* namespaceDeclaration) override;
  71. virtual void Visit(BfBlock* block) override;
  72. virtual void Visit(BfRootNode* rootNode) override;
  73. };
  74. NS_BF_END