aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-08-29 16:52:31 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-08-29 16:52:31 -0400
commit816689a3b1c98ec008438e7f868e1a123889b2a7 (patch)
tree84dcf5e1cb51689543fea4c39b4c9f24dde681e9 /src/analyze.cpp
parentbe94299666e57486be6bdb8fee2b79dbf3623c5d (diff)
downloadzig-816689a3b1c98ec008438e7f868e1a123889b2a7.tar.gz
zig-816689a3b1c98ec008438e7f868e1a123889b2a7.zip
ptrCast gives compile error for increasing alignment
See #37
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 69a50253d2..35ccd3b4d3 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -2899,14 +2899,29 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) {
}
}
-bool type_is_codegen_pointer(TypeTableEntry *type) {
- if (type->id == TypeTableEntryIdPointer) return true;
- if (type->id == TypeTableEntryIdFn) return true;
+TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) {
+ if (type->id == TypeTableEntryIdPointer) return type;
+ if (type->id == TypeTableEntryIdFn) return type;
if (type->id == TypeTableEntryIdMaybe) {
- if (type->data.maybe.child_type->id == TypeTableEntryIdPointer) return true;
- if (type->data.maybe.child_type->id == TypeTableEntryIdFn) return true;
+ if (type->data.maybe.child_type->id == TypeTableEntryIdPointer) return type->data.maybe.child_type;
+ if (type->data.maybe.child_type->id == TypeTableEntryIdFn) return type->data.maybe.child_type;
+ }
+ return nullptr;
+}
+
+bool type_is_codegen_pointer(TypeTableEntry *type) {
+ return get_codegen_ptr_type(type) != nullptr;
+}
+
+uint32_t get_ptr_align(TypeTableEntry *type) {
+ TypeTableEntry *ptr_type = get_codegen_ptr_type(type);
+ if (ptr_type->id == TypeTableEntryIdPointer) {
+ return ptr_type->data.pointer.alignment;
+ } else if (ptr_type->id == TypeTableEntryIdFn) {
+ return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;
+ } else {
+ zig_unreachable();
}
- return false;
}
AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index) {