Skip to content

Commit 62766f6

Browse files
authored
Merge pull request #17138 from jketema/generic
C++: Support C11 `_Generic` expressions
2 parents 5e390a3 + 5281943 commit 62766f6

File tree

22 files changed

+11314
-1127
lines changed

22 files changed

+11314
-1127
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Approach: replace conversion expressions of kind 389 (= @c11_generic) by
3+
* conversion expressions of kind 12 (= @parexpr), i.e., a `ParenthesisExpr`,
4+
* and drop the relation which its child expressions, which are just syntactic
5+
* sugar. Parenthesis expressions are equally benign as C11 _Generic expressions,
6+
* and behave similarly in the context of the IR.
7+
*/
8+
9+
class Expr extends @expr {
10+
string toString() { none() }
11+
}
12+
13+
class Location extends @location {
14+
string toString() { none() }
15+
}
16+
17+
class ExprParent extends @exprparent {
18+
string toString() { none() }
19+
}
20+
21+
query predicate new_exprs(Expr expr, int new_kind, Location loc) {
22+
exists(int kind | exprs(expr, kind, loc) | if kind = 389 then new_kind = 12 else new_kind = kind)
23+
}
24+
25+
query predicate new_exprparents(Expr expr, int index, ExprParent expr_parent) {
26+
exprparents(expr, index, expr_parent) and
27+
(
28+
not expr_parent instanceof @expr
29+
or
30+
exists(int kind | exprs(expr_parent.(Expr), kind, _) | kind != 389)
31+
)
32+
}

0 commit comments

Comments
 (0)