aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--src/buffer.c2
-rw-r--r--src/parser.c10
8 files changed, 25 insertions, 17 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
diff --git a/src/buffer.c b/src/buffer.c
index 4bd3b68..84fb5fa 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -16,7 +16,7 @@ void buffer_deinit(Buffer *self) {
self->capacity = 0;
}
-static WARN_UNUSED_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) {
+static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) {
usize capacity;
void *new_mem;
int alloc_result;
diff --git a/src/parser.c b/src/parser.c
index f68bbf0..a8fa207 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -4,7 +4,7 @@
#include "../include/alloc.h"
#include <stdio.h>
-static WARN_UNUSED_RESULT int parser_parse_body(Parser *self, Ast *ast);
+static CHECK_RESULT int parser_parse_body(Parser *self, Ast *ast);
int parser_init(Parser *self) {
buffer_init(&self->ast_objects);
@@ -22,7 +22,7 @@ void parser_deinit(Parser *self) {
/*
LHS = 'const'|'var' IDENTIFIER
*/
-static WARN_UNUSED_RESULT int parser_parse_lhs(Parser *self, LhsExpr **result) {
+static CHECK_RESULT int parser_parse_lhs(Parser *self, LhsExpr **result) {
bool isConst;
BufferView var_name;
*result = NULL;
@@ -46,7 +46,7 @@ static WARN_UNUSED_RESULT int parser_parse_lhs(Parser *self, LhsExpr **result) {
/*
FUNC_DECL = '(' PARAM* ')' '{' BODY* '}'
*/
-static WARN_UNUSED_RESULT int parser_parse_function_decl(Parser *self, FunctionDecl **func_decl) {
+static CHECK_RESULT int parser_parse_function_decl(Parser *self, FunctionDecl **func_decl) {
bool result;
*func_decl = NULL;
@@ -85,7 +85,7 @@ static WARN_UNUSED_RESULT int parser_parse_function_decl(Parser *self, FunctionD
/*
FUNC_CALL = IDENTIFIER '(' ARGS* ')'
*/
-static WARN_UNUSED_RESULT int parser_parse_function_call(Parser *self, FunctionCall **func_call) {
+static CHECK_RESULT int parser_parse_function_call(Parser *self, FunctionCall **func_call) {
bool result;
BufferView func_name;
*func_call = NULL;
@@ -107,7 +107,7 @@ static WARN_UNUSED_RESULT int parser_parse_function_call(Parser *self, FunctionC
/*
RHS = FUNC_DECL | FUNC_CALL
*/
-static WARN_UNUSED_RESULT int parser_parse_rhs(Parser *self, Ast *rhs_expr) {
+static CHECK_RESULT int parser_parse_rhs(Parser *self, Ast *rhs_expr) {
FunctionDecl *func_decl;
FunctionCall *func_call;
Token token;