cocci-macro-file.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
  25. # define QEMU_PACKED __attribute__((gcc_struct, packed))
  26. #else
  27. # define QEMU_PACKED __attribute__((packed))
  28. #endif
  29. #define cat(x,y) x ## y
  30. #define cat2(x,y) cat(x,y)
  31. #define QEMU_BUILD_BUG_ON(x) \
  32. typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1] __attribute__((unused));
  33. #define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
  34. #define xglue(x, y) x ## y
  35. #define glue(x, y) xglue(x, y)
  36. #define stringify(s) tostring(s)
  37. #define tostring(s) #s
  38. #define typeof_field(type, field) typeof(((type *)0)->field)
  39. #define type_check(t1,t2) ((t1*)0 - (t2*)0)
  40. /* From qemu/queue.h */
  41. #define QLIST_HEAD(name, type) \
  42. struct name { \
  43. struct type *lh_first; /* first element */ \
  44. }
  45. #define QLIST_HEAD_INITIALIZER(head) \
  46. { NULL }
  47. #define QLIST_ENTRY(type) \
  48. struct { \
  49. struct type *le_next; /* next element */ \
  50. struct type **le_prev; /* address of previous next element */ \
  51. }
  52. /*
  53. * Singly-linked List definitions.
  54. */
  55. #define QSLIST_HEAD(name, type) \
  56. struct name { \
  57. struct type *slh_first; /* first element */ \
  58. }
  59. #define QSLIST_HEAD_INITIALIZER(head) \
  60. { NULL }
  61. #define QSLIST_ENTRY(type) \
  62. struct { \
  63. struct type *sle_next; /* next element */ \
  64. }
  65. /*
  66. * Simple queue definitions.
  67. */
  68. #define QSIMPLEQ_HEAD(name, type) \
  69. struct name { \
  70. struct type *sqh_first; /* first element */ \
  71. struct type **sqh_last; /* addr of last next element */ \
  72. }
  73. #define QSIMPLEQ_HEAD_INITIALIZER(head) \
  74. { NULL, &(head).sqh_first }
  75. #define QSIMPLEQ_ENTRY(type) \
  76. struct { \
  77. struct type *sqe_next; /* next element */ \
  78. }
  79. /*
  80. * Tail queue definitions.
  81. */
  82. #define QTAILQ_HEAD(name, type) \
  83. union name { \
  84. struct type *tqh_first; /* first element */ \
  85. QTailQLink tqh_circ; /* link for last element */ \
  86. }
  87. #define QTAILQ_HEAD_INITIALIZER(head) \
  88. { .tqh_circ = { NULL, &(head).tqh_circ } }
  89. #define QTAILQ_ENTRY(type) \
  90. union { \
  91. struct type *tqe_next; /* next element */ \
  92. QTailQLink tqe_circ; /* link for prev element */ \
  93. }
  94. /* From glib */
  95. #define g_assert_cmpint(a, op, b) g_assert(a op b)
  96. #define g_assert_cmpuint(a, op, b) g_assert(a op b)
  97. #define g_assert_cmphex(a, op, b) g_assert(a op b)
  98. #define g_assert_cmpstr(a, op, b) g_assert(strcmp(a, b) op 0)