aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cffc.hff4
-rw-r--r--src/common.hff5
-rw-r--r--src/parse.cff18
3 files changed, 19 insertions, 8 deletions
diff --git a/src/cffc.hff b/src/cffc.hff
index d4b0ec1..af5bd6a 100644
--- a/src/cffc.hff
+++ b/src/cffc.hff
@@ -19,10 +19,10 @@ struct Loc {
#[lax]
enum TokT : i32 {
// !sorted
- kw_and, kw_as, kw_break, kw_case, kw_const,
+ kw_alignof, kw_and, kw_as, kw_break, kw_case, kw_const,
kw_continue, kw_def, kw_defmacro, kw_do,
kw_else, kw_enum, kw_extern, kw_fn,
- kw_for, kw_if, kw_import, kw_let,
+ kw_for, kw_if, kw_import, kw_let, kw_offsetof,
kw_or, kw_return, kw_sizeof, kw_static,
kw_struct, kw_switch, kw_typedef, kw_typeof,
kw_union, kw_while,
diff --git a/src/common.hff b/src/common.hff
index 6643dda..187fbf3 100644
--- a/src/common.hff
+++ b/src/common.hff
@@ -52,11 +52,8 @@ defmacro with_tmpchange(var,x,&body) [
defmacro MAX(a,b) [((a) > (b) ? (a) : (b))]
-defmacro offsetof_(T, fld) [
- (as(isize)(&(as(*T)#null).fld))
-]
defmacro container_of(x, T, fld) [
- (as(*T)(as(*void)(x) - offsetof_(T, fld)))
+ (as(*T)(as(*void)(x) - offsetof(T, fld)))
]
// Inline functions
diff --git a/src/parse.cff b/src/parse.cff
index a2071f8..b42d45a 100644
--- a/src/parse.cff
+++ b/src/parse.cff
@@ -141,10 +141,10 @@ fn eatspaces(P *Parser) void {
// !sorted
extern static keyword2str [NUM_KEYWORDS]*const u8 = {
- "and", "as", "break", "case", "const",
+ "alignof", "and", "as", "break", "case", "const",
"continue", "def", "defmacro", "do",
"else", "enum", "extern", "fn",
- "for", "if", "import", "let",
+ "for", "if", "import", "let", "offsetof",
"or", "return", "sizeof", "static",
"struct", "switch", "typedef", "typeof",
"union", "while",
@@ -1152,6 +1152,20 @@ fn pexprimary(P *Parser) Expr {
}
ex = { tok.loc, ty_usize, :IntLit { ty.size }};
+ case :kw_alignof;
+ let ty *const Type #?;
+ if lexmatch(P, &tok, '(') {
+ let ex = parseexpr(P);
+ lexexpect(P, ')');
+ ty = ex.ty;
+ } else {
+ ty = parsetype(P);
+ }
+ if !completetype(ty) {
+ err(P, tok.loc, "alignof incomplete type (%t)", ty);
+ }
+ ex = { tok.loc, ty_usize, :IntLit { ty.align }};
+
case '(';
if lexmatch(P, &tok, :kw_do) {
let st = parseblock0(P);