aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-02-24 16:00:03 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit12e5135d95dc34fd7f7a7c50d6dbac453f252683 (patch)
treeeb9d1225855a02aa90f4fa5f90228018e6fa1785 /include
parentf11c4b63ff74bffb1d42d95167b3384a2f7765ea (diff)
Add result check for msvc
Diffstat (limited to 'include')
-rw-r--r--include/alloc.h4
-rw-r--r--include/ast.h2
-rw-r--r--include/buffer.h2
-rw-r--r--include/misc.h10
-rw-r--r--include/parser.h4
-rw-r--r--include/tokenizer.h8
6 files changed, 19 insertions, 11 deletions
diff --git a/include/alloc.h b/include/alloc.h
index 35223b3..6809287 100644
--- a/include/alloc.h
+++ b/include/alloc.h
@@ -7,8 +7,8 @@
#define ALLOC_OK 0
#define ALLOC_FAIL -1
-WARN_UNUSED_RESULT int am_malloc(usize size, void **mem);
-WARN_UNUSED_RESULT int am_realloc(void *mem, usize new_size, void **new_mem);
+CHECK_RESULT int am_malloc(usize size, void **mem);
+CHECK_RESULT int am_realloc(void *mem, usize new_size, void **new_mem);
void am_free(void *mem);
#endif
diff --git a/include/ast.h b/include/ast.h
index edbe70f..b14c26d 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -47,7 +47,7 @@ void ast_deinit(Ast *ast);
void funcdecl_init(FunctionDecl *self);
void funcdecl_deinit(FunctionDecl *self);
-WARN_UNUSED_RESULT int funcdecl_add_to_body(FunctionDecl *self, Ast ast);
+CHECK_RESULT int funcdecl_add_to_body(FunctionDecl *self, Ast ast);
void funccall_init(FunctionCall *self, BufferView name);
diff --git a/include/buffer.h b/include/buffer.h
index 57efe9e..c45fbde 100644
--- a/include/buffer.h
+++ b/include/buffer.h
@@ -16,7 +16,7 @@ typedef struct {
void buffer_init(Buffer *self);
void buffer_deinit(Buffer *self);
-WARN_UNUSED_RESULT int buffer_append(Buffer *self, void *data, usize size);
+CHECK_RESULT int buffer_append(Buffer *self, void *data, usize size);
void* buffer_get(Buffer *self, usize index, usize type_size);
#endif \ No newline at end of file
diff --git a/include/misc.h b/include/misc.h
index c83eeb2..633ccfd 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -8,8 +8,16 @@ do { \
if((return_if_result) != 0) \
return return_if_result; \
} while(0)
+
#define cleanup_if_error(result) do { if((result) != 0) goto cleanup; } while(0)
-#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
+
+#if defined(__GNUC__) && __GNUC__ >= 4
+#define CHECK_RESULT __attribute__ ((CHECK_RESULT))
+#elif defined(_MSC_VER) && _MSC_VER >= 1700
+#define CHECK_RESULT _Check_return_
+#else
+#define CHECK_RESULT
+#endif
typedef enum {
bool_false,
diff --git a/include/parser.h b/include/parser.h
index 8207381..d66a096 100644
--- a/include/parser.h
+++ b/include/parser.h
@@ -15,9 +15,9 @@ typedef struct {
Tokenizer tokenizer;
} Parser;
-WARN_UNUSED_RESULT int parser_init(Parser *self);
+CHECK_RESULT int parser_init(Parser *self);
void parser_deinit(Parser *self);
-WARN_UNUSED_RESULT int parser_parse_buffer(Parser *self, BufferView code_buffer);
+CHECK_RESULT int parser_parse_buffer(Parser *self, BufferView code_buffer);
#endif
diff --git a/include/tokenizer.h b/include/tokenizer.h
index 7dd377f..f572860 100644
--- a/include/tokenizer.h
+++ b/include/tokenizer.h
@@ -31,16 +31,16 @@ typedef struct {
} value;
} Tokenizer;
-WARN_UNUSED_RESULT int tokenizer_init(Tokenizer *self, BufferView code);
+CHECK_RESULT int tokenizer_init(Tokenizer *self, BufferView code);
void tokenizer_deinit(Tokenizer *self);
-WARN_UNUSED_RESULT int tokenizer_next(Tokenizer *self, Token *token);
-WARN_UNUSED_RESULT int tokenizer_accept(Tokenizer *self, Token expected_token);
+CHECK_RESULT int tokenizer_next(Tokenizer *self, Token *token);
+CHECK_RESULT int tokenizer_accept(Tokenizer *self, Token expected_token);
/*
@result is set to 0 if the next token is equal to @expected_token,
otherwise @result is set to 1
*/
-WARN_UNUSED_RESULT int tokenizer_consume_if(Tokenizer *self, Token expected_token, bool *result);
+CHECK_RESULT int tokenizer_consume_if(Tokenizer *self, Token expected_token, bool *result);
void tokenizer_print_error(Tokenizer *self, const char *fmt, ...);
#endif