summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChristoph Mallon <christoph.mallon@gmx.de>2011-08-22 18:27:09 +0200
committerChristoph Mallon <christoph.mallon@gmx.de>2011-08-22 18:27:09 +0200
commit6c95edd1b9abab36ff615226d04993b84873eb8c (patch)
treedaa8397b55e045253a42d6e0684583736d7632bc
parentd8b4cfb608235d6875a494220642193ae9b56925 (diff)
Implement AST-grep for type property expressions.ast_grep
-rw-r--r--ast_grep.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/ast_grep.c b/ast_grep.c
index 651b171..e05cd5f 100644
--- a/ast_grep.c
+++ b/ast_grep.c
@@ -139,6 +139,29 @@ static expression_t *skip_implicit_cast(expression_t *expression)
return expression;
}
+static bool match(expression_t *expr, expression_t *pattern);
+
+static bool match_typeprop(expression_t *const expr, expression_t *const pattern)
+{
+ switch ((match_kind_t)pattern->kind) {
+ case EXPR_MATCH_TYPE:
+ return match_type(expr->base.type, ((match_type_expression_t*)pattern)->pattern);
+
+ case EXPR_MATCH_ANY:
+ return true;
+
+ case EXPR_MATCH_OR: {
+ match_or_expression_t *const matcho = (match_or_expression_t*)pattern;
+ return
+ match_typeprop(expr, matcho->expr1) ||
+ match_typeprop(expr, matcho->expr2);
+ }
+ }
+
+ expression_t *const sub_expr = expr->typeprop.tp_expression;
+ return sub_expr != NULL && match(sub_expr, pattern);
+}
+
static bool match(expression_t *expression, expression_t *pattern)
{
/* skip implicit casts */
@@ -194,6 +217,10 @@ static bool match(expression_t *expression, expression_t *pattern)
return true;
}
+ case EXPR_ALIGNOF:
+ case EXPR_SIZEOF:
+ return match_typeprop(expression, pattern->typeprop.tp_expression);
+
default:
panic("grep for expression kind not implemented");
}