torture.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /// Torture fixture for the C++ kernel walker (R7a) — namespaces (incl. C++17
  2. /// nested + anonymous), out-of-line Cls::method defs, templates + template
  3. /// bases, operator definitions, stack construction, local fn-ptrs, UE-macro
  4. /// shapes THROUGH the hoisted preParse, using-aliases, access specifiers,
  5. /// static-member value reads, and the cpp call shapes. Must parse ERROR-FREE
  6. /// post-preParse or the kernel arm defers (spaced operator CALL SITES live in
  7. /// torture-defer.cpp — they produce ERROR nodes by design).
  8. #include <vector>
  9. #include "widget_base.hpp"
  10. namespace app {
  11. /** Engine config (docstring). */
  12. class Config {
  13. public:
  14. int retries;
  15. void apply();
  16. int helper_count() const { return 2; }
  17. private:
  18. int secret;
  19. };
  20. void Config::apply() { retries = helper_count(); }
  21. namespace detail {
  22. struct Counter {
  23. int value;
  24. Counter *next;
  25. };
  26. } // namespace detail
  27. int detail_probe() { return 1; }
  28. } // namespace app
  29. namespace app::net {
  30. class Session {
  31. public:
  32. void open();
  33. virtual ~Session() {}
  34. // #1727 — pure virtual must mint a method node (parity between wasm + kernel).
  35. virtual int read(int key) = 0;
  36. };
  37. void Session::open() {}
  38. } // namespace app::net
  39. namespace {
  40. int hidden_helper() { return 3; }
  41. } // namespace
  42. template <typename T>
  43. class Base {
  44. public:
  45. T item;
  46. };
  47. template <typename T>
  48. class Box : public Base<T> {
  49. public:
  50. T get() const { return value_; }
  51. T unwrap();
  52. private:
  53. T value_;
  54. };
  55. template <typename T>
  56. T Box<T>::unwrap() {
  57. return value_;
  58. }
  59. class Derived : public Base<int>, private app::Config {
  60. public:
  61. Derived() : total_(0) {}
  62. int total() const { return total_; }
  63. private:
  64. int total_;
  65. };
  66. struct Vec2 {
  67. float x, y;
  68. Vec2 operator+(const Vec2 &o) const { return {x + o.x, y + o.y}; }
  69. explicit operator bool() const { return x != 0 || y != 0; }
  70. Vec2 origin();
  71. };
  72. enum class Mode : unsigned char { Off, On };
  73. enum Legacy { LEGACY_A, LEGACY_B };
  74. typedef struct {
  75. int id;
  76. } packet_t;
  77. using Handle = app::Config;
  78. // UE-macro shapes — every one below is recovered by the hoisted preParse
  79. // (export macro, reflection markup, inline specifier, API member prefix).
  80. class MYMODULE_API Widget : public app::Config {
  81. public:
  82. UPROPERTY(EditAnywhere, Category = "State")
  83. float Health;
  84. FORCEINLINE float GetHealth() const { return Health; }
  85. ENGINE_API virtual void Tick(float Delta);
  86. };
  87. void Widget::Tick(float Delta) { Health += Delta; }
  88. Config GlobalConfig;
  89. int build_number = 7;
  90. template <typename T>
  91. T compute_seed(T v) {
  92. return v + 1;
  93. }
  94. float drive_helper(float v) { return v; }
  95. Widget *make_widget() { return new Widget(); }
  96. float drive() {
  97. Widget local;
  98. app::Config cfg;
  99. Vec2 a{1, 2};
  100. Vec2 b(a);
  101. Vec2 c2(1.5f, 2.5f);
  102. float f = a.x + b.y + c2.x;
  103. make_widget()->Tick(0.5f);
  104. auto kernel = &compute_seed<float>;
  105. if (f > 1) {
  106. kernel = &drive_helper;
  107. }
  108. float r = kernel(f);
  109. int flags = GlobalConfig.retries;
  110. Mode m = Mode::Off;
  111. int leg = LEGACY_A;
  112. app::detail_probe();
  113. compute_seed<int>(2);
  114. auto mp = &app::Config::apply;
  115. (void)mp;
  116. (void)m;
  117. return r + f + flags + leg;
  118. }