diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-03-25 12:55:45 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-03-25 12:55:45 -0400 |
| commit | 5eaead6a56ed95c200e249737c4ecf3c7cacf794 (patch) | |
| tree | 70fe5c0238d6f1d72fc8504a4aaec710f059db37 /src/parser.cpp | |
| parent | 3306e43984a8b17472ecc4b13a2f2815d6630eef (diff) | |
| download | zig-5eaead6a56ed95c200e249737c4ecf3c7cacf794.tar.gz zig-5eaead6a56ed95c200e249737c4ecf3c7cacf794.zip | |
implement allowzero pointer attribute
closes #1953
only needed for freestanding targets.
also adds safety for `@intToPtr` when the address is zero.
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index a2c17f401f..9172e21b92 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -2530,6 +2530,12 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) { if (array != nullptr) { assert(array->type == NodeTypeArrayType); while (true) { + Token *allowzero_token = eat_token_if(pc, TokenIdKeywordAllowZero); + if (allowzero_token != nullptr) { + array->data.array_type.allow_zero_token = allowzero_token; + continue; + } + AstNode *align_expr = ast_parse_byte_align(pc); if (align_expr != nullptr) { array->data.array_type.align_expr = align_expr; @@ -2545,7 +2551,6 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) { array->data.array_type.is_volatile = true; continue; } - break; } @@ -2560,6 +2565,12 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) { if (child == nullptr) child = ptr; while (true) { + Token *allowzero_token = eat_token_if(pc, TokenIdKeywordAllowZero); + if (allowzero_token != nullptr) { + child->data.pointer_type.allow_zero_token = allowzero_token; + continue; + } + if (eat_token_if(pc, TokenIdKeywordAlign) != nullptr) { expect_token(pc, TokenIdLParen); AstNode *align_expr = ast_parse_expr(pc); |
