From 4ca3b74621c3608de42a91730a71892d9d7c27b5 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 1 Aug 2019 20:36:51 +0200 Subject: Remove nullable... it's bad to have magic. Static analysis can do it instead --- include/ast.h | 4 +--- include/nullable.h | 24 ++---------------------- 2 files changed, 3 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/include/ast.h b/include/ast.h index 6a40980..9f01b1b 100644 --- a/include/ast.h +++ b/include/ast.h @@ -88,8 +88,6 @@ struct Ast { SsaRegister ssa_reg; }; -DefineNullablePtrType(Ast); - struct Scope { Buffer/**/ ast_objects; HashMap/*(key=BufferView, value=Ast*)*/ named_objects; @@ -160,7 +158,7 @@ struct LhsExpr { bool is_const; BufferView var_name; VariableType type; - NullablePtr(Ast) rhs_expr; + Ast *rhs_expr; }; struct AssignmentExpr { diff --git a/include/nullable.h b/include/nullable.h index 6c4d3a7..f84100b 100644 --- a/include/nullable.h +++ b/include/nullable.h @@ -3,27 +3,7 @@ struct __nullable_type_dummy{ int _; }; -int assert_not_null(void *val); - -#ifdef DEBUG -#define DefineNullablePtrType(type) \ - typedef struct type##_nullable type##_nullable; \ - struct type##_nullable { \ - type *value; \ - } -#define NullablePtr(type) type##_nullable -#define nullable_unwrap(nullable_type) \ - (assert_not_null((nullable_type).value) ? ((nullable_type).value) : NULL) -#define nullable_assign(nullable_type, new_value) ((nullable_type).value = (new_value)) -#define is_not_null(nullable_type) ((nullable_type).value != NULL) -#define nullable_raw(nullable_type) ((nullable_type).value) -#else -#define DefineNullablePtrType(type) -#define NullablePtr(type) type* -#define nullable_unwrap(value) value -#define nullable_assign(nullable_type, new_value) ((nullable_type) = (new_value)) -#define is_not_null(nullable_type) ((nullable_type) != NULL) -#define nullable_raw(nullable_type) (nullable_type) -#endif +/* Used by static analysis tool to find null-pointer dereference errors */ +#define nullable #endif -- cgit v1.2.3