aboutsummaryrefslogtreecommitdiff
path: root/src/stage1/parser.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-08-28 12:41:24 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-08-28 12:41:24 -0700
commit6aeab0f323ff14d7ad248e18c372573f7a5a8cd1 (patch)
tree7080297f629f39baa0b742985c5804cf6a2047e8 /src/stage1/parser.cpp
parent47f7ed1c4cb8acf7fed99a057fb84202962e4b1b (diff)
parent05cf44933d753f7a5a53ab289ea60fd43761de57 (diff)
downloadzig-6aeab0f323ff14d7ad248e18c372573f7a5a8cd1.tar.gz
zig-6aeab0f323ff14d7ad248e18c372573f7a5a8cd1.zip
Merge remote-tracking branch 'origin/master' into llvm13
Conflicts: lib/libcxx/include/__config d57c0cc3bfeff9af297279759ec2b631e6d95140 added support for DragonFlyBSD to libc++ by updating some ifdefs. This needed to be synced with llvm13.
Diffstat (limited to 'src/stage1/parser.cpp')
-rw-r--r--src/stage1/parser.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/stage1/parser.cpp b/src/stage1/parser.cpp
index 9a429364b1..b06a944172 100644
--- a/src/stage1/parser.cpp
+++ b/src/stage1/parser.cpp
@@ -3482,8 +3482,7 @@ Error source_char_literal(const char *source, uint32_t *result, size_t *bad_inde
}
}
-
-Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) {
+static Buf *token_identifier_buf2(RootStruct *root_struct, TokenIndex token, bool *is_at_syntax) {
Error err;
const char *source = buf_ptr(root_struct->source_code);
size_t byte_offset = root_struct->token_locs[token].offset;
@@ -3495,6 +3494,7 @@ Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) {
assert(source[byte_offset] != '.'); // wrong token index
if (source[byte_offset] == '@') {
+ *is_at_syntax = true;
size_t bad_index;
Buf *str = buf_alloc();
if ((err = source_string_literal_buf(source + byte_offset + 1, str, &bad_index))) {
@@ -3503,6 +3503,7 @@ Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) {
}
return str;
} else {
+ *is_at_syntax = false;
size_t start = byte_offset;
for (;; byte_offset += 1) {
if (source[byte_offset] == 0) break;
@@ -3519,7 +3520,17 @@ Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) {
}
}
+Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) {
+ bool trash;
+ return token_identifier_buf2(root_struct, token, &trash);
+}
+
Buf *node_identifier_buf(AstNode *node) {
+ bool trash;
+ return node_identifier_buf2(node, &trash);
+}
+
+Buf *node_identifier_buf2(AstNode *node, bool *is_at_syntax) {
assert(node->type == NodeTypeIdentifier);
// Currently, stage1 runs astgen for every comptime function call,
// resulting the allocation here wasting memory. As a workaround until
@@ -3527,8 +3538,10 @@ Buf *node_identifier_buf(AstNode *node) {
// we memoize the result into the AST here.
if (node->data.identifier.name == nullptr) {
RootStruct *root_struct = node->owner->data.structure.root_struct;
- node->data.identifier.name = token_identifier_buf(root_struct, node->main_token);
+ node->data.identifier.name = token_identifier_buf2(root_struct, node->main_token,
+ &node->data.identifier.is_at_syntax);
}
+ *is_at_syntax = node->data.identifier.is_at_syntax;
return node->data.identifier.name;
}