cocci-macro-file.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* Macro file for Coccinelle
  2. *
  3. * Copyright (C) 2015 Red Hat, Inc.
  4. *
  5. * Authors:
  6. * Paolo Bonzini <pbonzini@redhat.com>
  7. *
  8. * This work is licensed under the terms of the GNU GPL, version 2 or, at your
  9. * option, any later version. See the COPYING file in the top-level directory.
  10. */
  11. /* Coccinelle only does limited parsing of headers, and chokes on some idioms
  12. * defined in compiler.h and queue.h. Macros that Coccinelle must know about
  13. * in order to parse .c files must be in a separate macro file---which is
  14. * exactly what you're staring at now.
  15. *
  16. * To use this file, add the "--macro-file scripts/cocci-macro-file.h" to the
  17. * Coccinelle command line.
  18. */
  19. /* From qemu/compiler.h */
  20. #define QEMU_GNUC_PREREQ(maj, min) 1
  21. #define QEMU_NORETURN __attribute__ ((__noreturn__))
  22. #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  23. #define QEMU_SENTINEL __attribute__((sentinel))
  24. #define QEMU_ARTIFICIAL __attribute__((always_inline, artificial))
  25. #define QEMU_PACKED __attribute__((gcc_struct, packed))
  26. #define cat(x,y) x ## y
  27. #define cat2(x,y) cat(x,y)
  28. #define QEMU_BUILD_BUG_ON(x) \
  29. typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1] __attribute__((unused));
  30. #define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
  31. #define xglue(x, y) x ## y
  32. #define glue(x, y) xglue(x, y)
  33. #define stringify(s) tostring(s)
  34. #define tostring(s) #s
  35. #define typeof_field(type, field) typeof(((type *)0)->field)
  36. #define type_check(t1,t2) ((t1*)0 - (t2*)0)
  37. /* From qemu/queue.h */
  38. #define QLIST_HEAD(name, type) \
  39. struct name { \
  40. struct type *lh_first; /* first element */ \
  41. }
  42. #define QLIST_HEAD_INITIALIZER(head) \
  43. { NULL }
  44. #define QLIST_ENTRY(type) \
  45. struct { \
  46. struct type *le_next; /* next element */ \
  47. struct type **le_prev; /* address of previous next element */ \
  48. }
  49. /*
  50. * Singly-linked List definitions.
  51. */
  52. #define QSLIST_HEAD(name, type) \
  53. struct name { \
  54. struct type *slh_first; /* first element */ \
  55. }
  56. #define QSLIST_HEAD_INITIALIZER(head) \
  57. { NULL }
  58. #define QSLIST_ENTRY(type) \
  59. struct { \
  60. struct type *sle_next; /* next element */ \
  61. }
  62. /*
  63. * Simple queue definitions.
  64. */
  65. #define QSIMPLEQ_HEAD(name, type) \
  66. struct name { \
  67. struct type *sqh_first; /* first element */ \
  68. struct type **sqh_last; /* addr of last next element */ \
  69. }
  70. #define QSIMPLEQ_HEAD_INITIALIZER(head) \
  71. { NULL, &(head).sqh_first }
  72. #define QSIMPLEQ_ENTRY(type) \
  73. struct { \
  74. struct type *sqe_next; /* next element */ \
  75. }
  76. /*
  77. * Tail queue definitions.
  78. */
  79. #define Q_TAILQ_HEAD(name, type, qual) \
  80. struct name { \
  81. qual type *tqh_first; /* first element */ \
  82. qual type *qual *tqh_last; /* addr of last next element */ \
  83. }
  84. #define QTAILQ_HEAD(name, type) \
  85. struct name { \
  86. type *tqh_first; /* first element */ \
  87. type **tqh_last; /* addr of last next element */ \
  88. }
  89. #define QTAILQ_HEAD_INITIALIZER(head) \
  90. { NULL, &(head).tqh_first }
  91. #define Q_TAILQ_ENTRY(type, qual) \
  92. struct { \
  93. qual type *tqe_next; /* next element */ \
  94. qual type *qual *tqe_prev; /* address of previous next element */\
  95. }
  96. #define QTAILQ_ENTRY(type) \
  97. struct { \
  98. type *tqe_next; /* next element */ \
  99. type **tqe_prev; /* address of previous next element */ \
  100. }
  101. /* From glib */
  102. #define g_assert_cmpint(a, op, b) g_assert(a op b)
  103. #define g_assert_cmpuint(a, op, b) g_assert(a op b)
  104. #define g_assert_cmphex(a, op, b) g_assert(a op b)
  105. #define g_assert_cmpstr(a, op, b) g_assert(strcmp(a, b) op 0)