code.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef AFUN_CODE_H
  2. #define AFUN_CODE_H
  3. #include "aFuntool.h"
  4. #include "aFunCoreExport.h"
  5. #include "core.h"
  6. namespace aFuncore {
  7. class AFUN_CORE_EXPORT Code {
  8. CodeType type;
  9. char prefix=NUL;
  10. union {
  11. char *element = nullptr; // union 内不使用 std::string
  12. struct { // NOLINT 不需要初始化
  13. BlockType block_type;
  14. Code *son;
  15. };
  16. };
  17. Code *father = nullptr;;
  18. Code *next = nullptr;;
  19. Code *prev = nullptr;;
  20. aFuntool::FileLine line;
  21. aFuntool::FilePath file;
  22. protected:
  23. explicit Code(FileLine line, ConstFilePath file="");
  24. Code(const std::string &element, aFuntool::FileLine line, aFuntool::ConstFilePath file="", char prefix=NUL);
  25. Code(BlockType block_type, Code *son, aFuntool::FileLine line, aFuntool::ConstFilePath file="", char prefix=NUL);
  26. ~Code();
  27. public:
  28. Code(const Code &)=delete;
  29. Code &operator=(const Code &)=delete;
  30. static Code *create(FileLine line, ConstFilePath file="");
  31. static Code *create(const std::string &element,
  32. aFuntool::FileLine line, aFuntool::ConstFilePath file="", char prefix=NUL);
  33. static Code *create(BlockType block_type, Code *son,
  34. aFuntool::FileLine line, aFuntool::ConstFilePath file="", char prefix=NUL);
  35. static void destruct(Code *code);
  36. Code *connect(Code *code);
  37. void display() const;
  38. void displayAll() const;
  39. bool write_v1(FILE *f, bool debug=false) const;
  40. bool writeAll_v1(FILE *f, bool debug=false) const;
  41. Code *read_v1(FILE *f, bool debug=false, int8_t read_type=code_element, bool to_son=false);
  42. bool readAll_v1(FILE *f, bool debug=false);
  43. [[nodiscard]] std::string getMD5_v1() const;
  44. [[nodiscard]] std::string getMD5All_v1() const;
  45. bool writeByteCode(ConstFilePath file_path, bool debug=false) const; // NOLINT 允许忽略返回值
  46. bool readByteCode(ConstFilePath file_path);
  47. [[nodiscard]] CodeType getType() const;
  48. [[nodiscard]] char getPrefix() const;
  49. [[nodiscard]] const char *getElement() const;
  50. [[nodiscard]] BlockType getBlockType() const;
  51. [[nodiscard]] Code *getSon() const;
  52. [[nodiscard]] Code *toNext() const;
  53. [[nodiscard]] Code *toPrev() const;
  54. [[nodiscard]] Code *toFather() const;
  55. [[nodiscard]] aFuntool::FileLine getFileLine() const;
  56. [[nodiscard]] aFuntool::FilePath getFilePath() const;
  57. };
  58. }
  59. #include "code.inline.h"
  60. #endif //AFUN_CODE_H