linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christopher Li <sparse@chrisli.org>
To: Linux-Sparse <linux-sparse@vger.kernel.org>
Cc: Kamil Dudka <kdudka@redhat.com>, Josh Triplett <josh@joshtriplett.org>
Subject: PATCH 4/4] inspect: add some expression inspection
Date: Fri, 2 Apr 2010 11:46:03 -0700	[thread overview]
Message-ID: <r2s70318cbf1004021146je5db05e6ya493f16593c69a16@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

More example extending the inspector.

Chris

[-- Attachment #2: 0004-inspect-add-some-expression-inspection.patch --]
[-- Type: application/octet-stream, Size: 4353 bytes --]

From 6a09d04c3e9e9a9c0d1406ff6e00bab0032c22a3 Mon Sep 17 00:00:00 2001
From: Christopher <sparse@chrisli.org>
Date: Wed, 31 Mar 2010 11:03:27 -0700
Subject: [PATCH 4/4] inspect: add some expression inspection

---
 ast-inspect.c |   78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 ast-inspect.h |    4 +++
 2 files changed, 81 insertions(+), 1 deletions(-)

diff --git a/ast-inspect.c b/ast-inspect.c
index 72f3fe0..293334e 100644
--- a/ast-inspect.c
+++ b/ast-inspect.c
@@ -3,6 +3,7 @@
 #include "parse.h"
 #include "symbol.h"
 #include "ast-inspect.h"
+#include "expression.h"
 
 static inline void inspect_ptr_list(AstNode *node, const char *name, void (*inspect)(AstNode *))
 {
@@ -39,7 +40,6 @@ static const char *statement_type_name(enum statement_type type)
 	return statement_type_name[type] ?: "UNKNOWN_STATEMENT_TYPE";
 }
 
-
 void inspect_statement(AstNode *node)
 {
 	struct statement *stmt = node->ptr;
@@ -48,9 +48,24 @@ void inspect_statement(AstNode *node)
 		case STMT_COMPOUND:
 			ast_append_child(node, "stmts:", stmt->stmts, inspect_statement_list);
 			break;
+		case STMT_EXPRESSION:
+			ast_append_child(node, "expression:", stmt->expression, inspect_expression);
+			break;
 		case STMT_IF:
+			ast_append_child(node, "conditional:", stmt->if_conditional, inspect_expression);
 			ast_append_child(node, "if_true:", stmt->if_true, inspect_statement);
 			ast_append_child(node, "if_false:", stmt->if_false, inspect_statement);
+			break;
+		case STMT_ITERATOR:
+			ast_append_child(node, "break:", stmt->iterator_break, inspect_symbol);
+			ast_append_child(node, "continue:", stmt->iterator_continue, inspect_symbol);
+			ast_append_child(node, "pre_statement:", stmt->iterator_pre_statement,
+					 inspect_statement);
+			ast_append_child(node, "statement:", stmt->iterator_statement,
+					 inspect_statement);
+			ast_append_child(node, "post_statement:", stmt->iterator_post_statement,
+					 inspect_statement);
+			break;
 		default:
 			break;
 	}
@@ -112,3 +127,64 @@ void inspect_symbol_list(AstNode *node)
 	inspect_ptr_list(node, "symbol_list", inspect_symbol);
 }
 
+
+static const char *expression_type_name(enum expression_type type)
+{
+	static const char *expression_type_name[] = {
+		[EXPR_VALUE] = "EXPR_VALUE",
+		[EXPR_STRING] = "EXPR_STRING",
+		[EXPR_SYMBOL] = "EXPR_SYMBOL",
+		[EXPR_TYPE] = "EXPR_TYPE",
+		[EXPR_BINOP] = "EXPR_BINOP",
+		[EXPR_ASSIGNMENT] = "EXPR_ASSIGNMENT",
+		[EXPR_LOGICAL] = "EXPR_LOGICAL",
+		[EXPR_DEREF] = "EXPR_DEREF",
+		[EXPR_PREOP] = "EXPR_PREOP",
+		[EXPR_POSTOP] = "EXPR_POSTOP",
+		[EXPR_CAST] = "EXPR_CAST",
+		[EXPR_FORCE_CAST] = "EXPR_FORCE_CAST",
+		[EXPR_IMPLIED_CAST] = "EXPR_IMPLIED_CAST",
+		[EXPR_SIZEOF] = "EXPR_SIZEOF",
+		[EXPR_ALIGNOF] = "EXPR_ALIGNOF",
+		[EXPR_PTRSIZEOF] = "EXPR_PTRSIZEOF",
+		[EXPR_CONDITIONAL] = "EXPR_CONDITIONAL",
+		[EXPR_SELECT] = "EXPR_SELECT",
+		[EXPR_STATEMENT] = "EXPR_STATEMENT",
+		[EXPR_CALL] = "EXPR_CALL",
+		[EXPR_COMMA] = "EXPR_COMMA",
+		[EXPR_COMPARE] = "EXPR_COMPARE",
+		[EXPR_LABEL] = "EXPR_LABEL",
+		[EXPR_INITIALIZER] = "EXPR_INITIALIZER",
+		[EXPR_IDENTIFIER] = "EXPR_IDENTIFIER",
+		[EXPR_INDEX] = "EXPR_INDEX",
+		[EXPR_POS] = "EXPR_POS",
+		[EXPR_FVALUE] = "EXPR_FVALUE",
+		[EXPR_SLICE] = "EXPR_SLICE",
+		[EXPR_OFFSETOF] = "EXPR_OFFSETOF",
+	};
+	return expression_type_name[type] ?: "UNKNOWN_EXPRESSION_TYPE";
+}
+
+void inspect_expression(AstNode *node)
+{
+	struct expression *expr = node->ptr;
+	node->text = g_strdup_printf("%s %s", node->text, expression_type_name(expr->type));
+	switch (expr->type) {
+		case EXPR_STATEMENT:
+			ast_append_child(node, "statement:", expr->statement, inspect_statement);
+			break;
+		case EXPR_BINOP:
+		case EXPR_COMMA:
+		case EXPR_COMPARE:
+		case EXPR_LOGICAL:
+		case EXPR_ASSIGNMENT:
+			ast_append_child(node, "left:", expr->left, inspect_expression);
+			ast_append_child(node, "right:", expr->right, inspect_expression);
+			break;
+		default:
+			break;
+	}
+}
+
+
+
diff --git a/ast-inspect.h b/ast-inspect.h
index e01d847..6e15c91 100644
--- a/ast-inspect.h
+++ b/ast-inspect.h
@@ -10,4 +10,8 @@ void inspect_symbol_list(AstNode *node);
 void inspect_statement(AstNode *node);
 void inspect_statement_list(AstNode *node);
 
+void inspect_expression(AstNode *node);
+void inspect_expression_list(AstNode *node);
+
+
 #endif
-- 
1.6.6.1


                 reply	other threads:[~2010-04-02 18:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=r2s70318cbf1004021146je5db05e6ya493f16593c69a16@mail.gmail.com \
    --to=sparse@chrisli.org \
    --cc=josh@joshtriplett.org \
    --cc=kdudka@redhat.com \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).