From: Michael D. Lowis Date: Sun, 23 Aug 2015 01:02:34 +0000 (-0400) Subject: use a consistent brace style X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=024db6d974c0e1ff9a38548628abc5bd018d0c28;p=proto%2Fgir.git use a consistent brace style --- diff --git a/source/parser.c b/source/parser.c index 1192439..63fde05 100644 --- a/source/parser.c +++ b/source/parser.c @@ -114,8 +114,7 @@ static char* strbuf_string(strbuf_t* buf); /* *****************************************************************************/ -void exec_file(FILE* file, const char* prompt) -{ +void exec_file(FILE* file, const char* prompt) { File = file; while(true) { printf("%s", prompt); @@ -125,15 +124,13 @@ void exec_file(FILE* file, const char* prompt) /* Parsing Rules *****************************************************************************/ -static AST* expression(void) -{ +static AST* expression(void) { AST* expr = keyword_send(); optional(SEMICOLON); return expr; } -static AST* keyword_send(void) -{ +static AST* keyword_send(void) { AST* expr = binary_send(); AST* sel = NULL; while (accept(KEYWORD)) { @@ -147,8 +144,7 @@ static AST* keyword_send(void) return expr; } -static AST* binary_send(void) -{ +static AST* binary_send(void) { AST* expr = unary_send(); if (accept(OPERATOR)) { AST* msg = ast_new(BINARY_MSG); @@ -160,8 +156,7 @@ static AST* binary_send(void) return expr; } -static AST* unary_send(void) -{ +static AST* unary_send(void) { AST* expr = operand(); while (accept(IDENTIFIER)) { AST* msg = ast_new(UNARY_MSG); @@ -172,8 +167,7 @@ static AST* unary_send(void) return expr; } -static AST* operand(void) -{ +static AST* operand(void) { AST* obj = NULL; if (accept(LPAR)) { expect(LPAR); @@ -185,8 +179,7 @@ static AST* operand(void) return obj; } -static AST* literal(void) -{ +static AST* literal(void) { AST* obj = NULL; switch (CurrTok) { case IDENTIFIER: obj = ast_tok(IDENTIFIER); break; @@ -203,8 +196,7 @@ static AST* literal(void) return obj; } -static AST* array(void) -{ +static AST* array(void) { AST* array_obj = ast_new(ARRAY); expect(LBRACK); while (!accept(RBRACK)) { @@ -214,8 +206,7 @@ static AST* array(void) return array_obj; } -static AST* hashmap(void) -{ +static AST* hashmap(void) { AST* hashmap = ast_new(HASHMAP); expect(AT_LBRACE); while (!accept(RBRACE)) { @@ -229,8 +220,7 @@ static AST* hashmap(void) return hashmap; } -static AST* hashset(void) -{ +static AST* hashset(void) { AST* hashset = ast_new(HASHSET); expect(AT_LBRACK); while (!accept(RBRACK)) { @@ -240,8 +230,7 @@ static AST* hashset(void) return hashset; } -static AST* object(void) -{ +static AST* object(void) { AST* object = ast_new(OBJECT); expect(LBRACE); if (accept(PIPE)) { @@ -257,22 +246,19 @@ static AST* object(void) /* Parsing Helpers *****************************************************************************/ -static void error(const char* msg) -{ +static void error(const char* msg) { fprintf(stderr, "Error: %s\n", msg); exit(1); } -static bool accept(int expected) -{ +static bool accept(int expected) { if (CurrTok == UNKNOWN) { CurrTok = token(); } return (CurrTok == expected); } -static bool expect(int expected) -{ +static bool expect(int expected) { bool accepted = accept(expected); if (!accepted) error("unexpected symbol"); @@ -281,8 +267,7 @@ static bool expect(int expected) return accepted; } -static bool optional(int expected) -{ +static bool optional(int expected) { if (accept(expected)) return expect(expected); else @@ -291,8 +276,7 @@ static bool optional(int expected) /* Lexical Rules *****************************************************************************/ -static int token(void) -{ +static int token(void) { // Re-init the token strbuf_init(&Token); @@ -317,8 +301,7 @@ static int token(void) } } -static void whitespace(void) -{ +static void whitespace(void) { while(isspace(current()) || ('#' == current())) { if ('#' == current()) { discard(); @@ -331,16 +314,14 @@ static void whitespace(void) } } -static int symbol(void) -{ +static int symbol(void) { expect_ch('$'); while (isalnum(current())) append(); return SYMBOL; } -static int identifier(void) -{ +static int identifier(void) { while (isalnum(current())) append(); @@ -352,16 +333,14 @@ static int identifier(void) } } -static int number(void) -{ +static int number(void) { append(); while (isdigit(current())) append(); return NUMBER; } -static int string(void) -{ +static int string(void) { expect_ch('"'); while('"' != current()) append(); @@ -369,16 +348,14 @@ static int string(void) return STRING; } -static int character(void) -{ +static int character(void) { expect_ch('\''); append(); expect_ch('\''); return CHARACTER; } -static int punctuation(void) -{ +static int punctuation(void) { if ('@' == current()) { expect_ch('@'); if ('[' == current()) { @@ -415,46 +392,39 @@ static int punctuation(void) } } -static int operator(void) -{ +static int operator(void) { lex_error(); return UNKNOWN; } /* Lexical Analysis Helpers *****************************************************************************/ -static int current(void) -{ +static int current(void) { return CurrChar; } -static void append(void) -{ +static void append(void) { strbuf_putc(&Token, CurrChar); fetch(); } -static void discard(void) -{ +static void discard(void) { fetch(); } -static void expect_ch(int ch) -{ +static void expect_ch(int ch) { if (ch == current()) append(); else lex_error(); } -static void lex_error(void) -{ +static void lex_error(void) { fprintf(stderr, "Lexer error\n"); exit(1); } -static void fetch(void) -{ +static void fetch(void) { CurrChar = fgetc(File); if (CurrChar == '\n') { Line++; @@ -466,29 +436,25 @@ static void fetch(void) /* Tree Routines *****************************************************************************/ -static AST* ast_new(int type) -{ +static AST* ast_new(int type) { AST* tree = (AST*)malloc(sizeof(AST)); memset(tree, 0, sizeof(AST)); tree->type = type; return tree; } -static AST* ast_tok(int type) -{ +static AST* ast_tok(int type) { AST* ast = ast_new(type); expect(type); ast->text = strbuf_string(&Token); return ast; } -static void ast_add_child(AST* parent, AST* child) -{ +static void ast_add_child(AST* parent, AST* child) { slist_push_back(&(parent->children), &(child->link)); } -static void ast_print(AST* tree, int depth) -{ +static void ast_print(AST* tree, int depth) { int indent = depth * 2; printf("%*s(", indent, ""); printf("%d %s", tree->type, tree->text ? tree->text : ""); @@ -505,16 +471,14 @@ static void ast_print(AST* tree, int depth) /* String Buffer *****************************************************************************/ -static void strbuf_init(strbuf_t* buf) -{ +static void strbuf_init(strbuf_t* buf) { buf->index = 0; buf->capacity = 8; buf->string = (char*)malloc(buf->capacity); buf->string[buf->index] = 0; } -static void strbuf_putc(strbuf_t* buf, int ch) -{ +static void strbuf_putc(strbuf_t* buf, int ch) { if (buf->string == NULL) { strbuf_init(buf); } else if ((buf->index + 2) >= buf->capacity) { @@ -525,8 +489,7 @@ static void strbuf_putc(strbuf_t* buf, int ch) buf->string[buf->index] = '\0'; } -static char* strbuf_string(strbuf_t* buf) -{ +static char* strbuf_string(strbuf_t* buf) { char* str = buf->string; strbuf_init(buf); return str; diff --git a/source/slist.c b/source/slist.c index 4f8dcb0..e1ead4e 100644 --- a/source/slist.c +++ b/source/slist.c @@ -1,17 +1,14 @@ #include "gir_internals.h" -void slist_init(slist_t* list) -{ +void slist_init(slist_t* list) { list->head = NULL; } -bool slist_empty(slist_t* list) -{ +bool slist_empty(slist_t* list) { return (list->head == NULL); } -size_t slist_size(slist_t* list) -{ +size_t slist_size(slist_t* list) { size_t sz = 0; slist_node_t* node = list->head; while (node != NULL) { @@ -21,35 +18,30 @@ size_t slist_size(slist_t* list) return sz; } -slist_node_t* slist_front(slist_t* list) -{ +slist_node_t* slist_front(slist_t* list) { return list->head; } -void slist_push_front(slist_t* list, slist_node_t* node) -{ +void slist_push_front(slist_t* list, slist_node_t* node) { node->next = list->head; list->head = node; } -slist_node_t* slist_pop_front(slist_t* list) -{ +slist_node_t* slist_pop_front(slist_t* list) { slist_node_t* node = list->head; list->head = node->next; node->next = NULL; return node; } -slist_node_t* slist_back(slist_t* list) -{ +slist_node_t* slist_back(slist_t* list) { slist_node_t* node = list->head; while (node && node->next != NULL) node = node->next; return (node) ? node : NULL; } -void slist_push_back(slist_t* list, slist_node_t* node) -{ +void slist_push_back(slist_t* list, slist_node_t* node) { slist_node_t* back = slist_back(list); if (NULL != back) back->next = node; @@ -58,8 +50,7 @@ void slist_push_back(slist_t* list, slist_node_t* node) node->next = NULL; } -slist_node_t* slist_pop_back(slist_t* list) -{ +slist_node_t* slist_pop_back(slist_t* list) { slist_node_t* prev = NULL; slist_node_t* curr = list->head; while (curr && curr->next != NULL) { @@ -73,13 +64,11 @@ slist_node_t* slist_pop_back(slist_t* list) return curr; } -bool slist_node_has_next(slist_node_t* node) -{ +bool slist_node_has_next(slist_node_t* node) { return (node->next != NULL); } -slist_node_t* slist_node_next(slist_node_t* node) -{ +slist_node_t* slist_node_next(slist_node_t* node) { return node->next; } diff --git a/source/world.c b/source/world.c index dab195c..c10787e 100644 --- a/source/world.c +++ b/source/world.c @@ -58,7 +58,6 @@ void world_init(void) } #endif -void world_init(void) -{ +void world_init(void) { }