aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorJimmi HC <jhc@liab.dk>2018-06-08 09:21:31 +0200
committerJimmi HC <jhc@liab.dk>2018-06-08 09:21:31 +0200
commitbf3d1c1aab336c4a650bb67dcaca132d4a0f6164 (patch)
treec97dceae3e7ea164cfd3154f91e5b314df762c92 /src/analyze.cpp
parentffb089a9f5fa95fd559a7c88081310d0be73f206 (diff)
downloadzig-bf3d1c1aab336c4a650bb67dcaca132d4a0f6164.tar.gz
zig-bf3d1c1aab336c4a650bb67dcaca132d4a0f6164.zip
Allow access of array.len through a pointer
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index e05fb23237..84f1473ea1 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -3761,14 +3761,24 @@ static bool is_container(TypeTableEntry *type_entry) {
zig_unreachable();
}
+bool is_ref(TypeTableEntry *type_entry) {
+ return type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle;
+}
+
+bool is_array_ref(TypeTableEntry *type_entry) {
+ TypeTableEntry *array = is_ref(type_entry) ?
+ type_entry->data.pointer.child_type : type_entry;
+ return array->id == TypeTableEntryIdArray;
+}
+
bool is_container_ref(TypeTableEntry *type_entry) {
- return (type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle) ?
+ return is_ref(type_entry) ?
is_container(type_entry->data.pointer.child_type) : is_container(type_entry);
}
TypeTableEntry *container_ref_type(TypeTableEntry *type_entry) {
assert(is_container_ref(type_entry));
- return (type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle) ?
+ return is_ref(type_entry) ?
type_entry->data.pointer.child_type : type_entry;
}