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 12 /* Coccinelle only does limited parsing of headers, and chokes on some idioms 13 * defined in compiler.h and queue.h. Macros that Coccinelle must know about 14 * in order to parse .c files must be in a separate macro file---which is 15 * exactly what you're staring at now. 16 * 17 * To use this file, add the "--macro-file scripts/cocci-macro-file.h" to the 18 * Coccinelle command line. 19 */ 20 21 /* From qemu/compiler.h */ 22 #define QEMU_GNUC_PREREQ(maj, min) 1 23 #define QEMU_NORETURN __attribute__ ((__noreturn__)) 24 #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 25 #define QEMU_SENTINEL __attribute__((sentinel)) 26 #define QEMU_ARTIFICIAL __attribute__((always_inline, artificial)) 27 #define QEMU_PACKED __attribute__((gcc_struct, packed)) 28 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 34 #define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m))) 35 36 #define xglue(x, y) x ## y 37 #define glue(x, y) xglue(x, y) 38 #define stringify(s) tostring(s) 39 #define tostring(s) #s 40 41 #define typeof_field(type, field) typeof(((type *)0)->field) 42 #define type_check(t1,t2) ((t1*)0 - (t2*)0) 43 44 /* From qemu/queue.h */ 45 46 #define QLIST_HEAD(name, type) \ 47 struct name { \ 48 struct type *lh_first; /* first element */ \ 49 } 50 51 #define QLIST_HEAD_INITIALIZER(head) \ 52 { NULL } 53 54 #define QLIST_ENTRY(type) \ 55 struct { \ 56 struct type *le_next; /* next element */ \ 57 struct type **le_prev; /* address of previous next element */ \ 58 } 59 60 /* 61 * Singly-linked List definitions. 62 */ 63 #define QSLIST_HEAD(name, type) \ 64 struct name { \ 65 struct type *slh_first; /* first element */ \ 66 } 67 68 #define QSLIST_HEAD_INITIALIZER(head) \ 69 { NULL } 70 71 #define QSLIST_ENTRY(type) \ 72 struct { \ 73 struct type *sle_next; /* next element */ \ 74 } 75 76 /* 77 * Simple queue definitions. 78 */ 79 #define QSIMPLEQ_HEAD(name, type) \ 80 struct name { \ 81 struct type *sqh_first; /* first element */ \ 82 struct type **sqh_last; /* addr of last next element */ \ 83 } 84 85 #define QSIMPLEQ_HEAD_INITIALIZER(head) \ 86 { NULL, &(head).sqh_first } 87 88 #define QSIMPLEQ_ENTRY(type) \ 89 struct { \ 90 struct type *sqe_next; /* next element */ \ 91 } 92 93 /* 94 * Tail queue definitions. 95 */ 96 #define Q_TAILQ_HEAD(name, type, qual) \ 97 struct name { \ 98 qual type *tqh_first; /* first element */ \ 99 qual type *qual *tqh_last; /* addr of last next element */ \ 100 } 101 #define QTAILQ_HEAD(name, type) \ 102 struct name { \ 103 type *tqh_first; /* first element */ \ 104 type **tqh_last; /* addr of last next element */ \ 105 } 106 107 #define QTAILQ_HEAD_INITIALIZER(head) \ 108 { NULL, &(head).tqh_first } 109 110 #define Q_TAILQ_ENTRY(type, qual) \ 111 struct { \ 112 qual type *tqe_next; /* next element */ \ 113 qual type *qual *tqe_prev; /* address of previous next element */\ 114 } 115 #define QTAILQ_ENTRY(type) \ 116 struct { \ 117 type *tqe_next; /* next element */ \ 118 type **tqe_prev; /* address of previous next element */ \ 119 } 120 121 /* From glib */ 122 #define g_assert_cmpint(a, op, b) g_assert(a op b) 123 #define g_assert_cmpuint(a, op, b) g_assert(a op b) 124 #define g_assert_cmphex(a, op, b) g_assert(a op b) 125 #define g_assert_cmpstr(a, op, b) g_assert(strcmp(a, b) op 0) 126