treservedcidentsasfields.nim 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. discard """
  2. targets: "c cpp"
  3. """
  4. import macros
  5. macro make_test_type(idents: varargs[untyped]): untyped =
  6. result = nnkStmtList.newTree()
  7. var ident_defs: seq[NimNode] = @[]
  8. for i in idents:
  9. ident_defs.add newIdentDefs(i, ident("int"))
  10. result.add newTree(nnkTypeSection,
  11. newTree(nnkTypeDef,
  12. ident("TestType"),
  13. newEmptyNode(),
  14. newTree(nnkObjectTy,
  15. newEmptyNode(),
  16. newEmptyNode(),
  17. newTree(nnkRecList,
  18. ident_defs
  19. )
  20. )
  21. )
  22. )
  23. make_test_type(
  24. auto, bool, catch, char, class, compl, const_cast, default, delete, double,
  25. dynamic_cast, explicit, extern, false, float, friend, goto, int, long,
  26. mutable, namespace, new, operator, private, protected, public, register,
  27. reinterpret_cast, restrict, short, signed, sizeof, static_cast, struct, switch,
  28. this, throw, true, typedef, typeid, typeof, typename, union, packed, unsigned,
  29. virtual, void, volatile, wchar_t, alignas, alignof, constexpr, decltype, nullptr,
  30. noexcept, thread_local, static_assert, char16_t, char32_t
  31. )
  32. # Make sure the type makes it to codegen.
  33. var test_instance: TestType