cocci-macro-file.h 4.2 KB

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