[PATCH 03/13] format-check: add helper type_class()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This will help the next patch to verify the types.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 verify-format.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/verify-format.c b/verify-format.c
index ae5bb2e6e985..fd5a9ed821e1 100644
--- a/verify-format.c
+++ b/verify-format.c
@@ -70,6 +70,35 @@ struct format_state {
 	unsigned int		used_position: 1;
 };
 
+enum {
+	CLASS_OTHER,
+	CLASS_INT,
+	CLASS_BITWISE,
+	CLASS_FLOAT,
+	CLASS_PTR,
+};
+
+static inline int type_class(struct symbol *type, struct symbol **base)
+{
+	if (type->type == SYM_NODE)
+		type = type->ctype.base_type;
+	if (type->type == SYM_ENUM)
+		type = type->ctype.base_type;
+	*base = type;
+	if (type->type == SYM_BASETYPE) {
+		struct symbol *kind = type->ctype.base_type;
+		if (kind == &int_type)
+			return CLASS_INT;
+		if (kind == &fp_type)
+			return CLASS_FLOAT;
+	}
+	if (type->type == SYM_PTR)
+		return CLASS_PTR;
+	if (type->type == SYM_RESTRICT)
+		return CLASS_BITWISE;
+	return CLASS_OTHER;
+}
+
 static int printf_fmt_numtype(struct format_type *fmt,
 			      struct expression **expr,
 			      struct symbol *ctype,
-- 
2.28.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux