cocci-macro-file.h 4.3 KB

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