Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
gherkin: (C) Avoid using repeated typedefs (support gcc <v4.6)
Browse files Browse the repository at this point in the history
Technically C does not support repeated typedefs until C11, however
modern compilers do allow it (gcc also using -std=c90). But since
gcc <v4.6 does not support that, remove the usage of them.
  • Loading branch information
brasmusson authored and aslakhellesoy committed May 1, 2017
1 parent 00ee9b1 commit 8f31c2f
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 50 deletions.
5 changes: 2 additions & 3 deletions gherkin-c-parser.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "token_scanner.h"
#include "token_matcher.h"
#include "token_queue.h"
#include "builder.h"
#include "error_list.h"
#include <stdlib.h>
#include <setjmp.h>
Expand All @@ -46,11 +45,11 @@ typedef struct ParserContext {
ErrorList* errors;
} ParserContext;

typedef struct @Model.ParserClassName {
struct @Model.ParserClassName {
ParserContext* parser_context;
Builder* builder;
ErrorList* errors;
} @Model.ParserClassName;
};

static Token* read_token(ParserContext* context);

Expand Down
9 changes: 3 additions & 6 deletions include/builder.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#ifndef GHERKIN_BUILDER_H_
#define GHERKIN_BUILDER_H_

#include "error_list.h"
#include "rule_type.h"
#include "token.h"

typedef struct ErrorList ErrorList;

typedef struct Builder Builder;

typedef void (*builder_reset_function) (Builder*);
Expand All @@ -16,14 +15,12 @@ typedef void (*build_function) (Builder*, Token*);

typedef void (*rule_function) (Builder*, RuleType);

typedef void (*rule_function) (Builder*, RuleType);

typedef struct Builder {
struct Builder {
builder_reset_function reset;
builder_error_context_function set_error_context;
build_function build;
rule_function start_rule;
rule_function end_rule;
} Builder;
};

#endif /* GHERKIN_BUILDER_H_ */
6 changes: 2 additions & 4 deletions include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@

#include <stdbool.h>
#include <wchar.h>
#include "gherkin_document.h"
#include "pickle.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct Compiler Compiler;

typedef struct GherkinDocument GherkinDocument;

typedef struct Pickle Pickle;

Compiler* Compiler_new();

void Compiler_delete(Compiler* compiler);
Expand Down
4 changes: 2 additions & 2 deletions include/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ typedef enum EventType {
Gherkin_PickleEvent
} EventType;

typedef struct Event {
struct Event {
event_delete_function event_delete;
event_print_function event_print;
EventType event_type;
} Event;
};

void Event_delete(const Event* event);

Expand Down
4 changes: 2 additions & 2 deletions include/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ typedef struct Item Item;

typedef void (*item_delete_function) (Item*);

typedef struct Item {
struct Item {
item_delete_function item_delete;
} Item;
};

#endif /* GHERKIN_ITEM_H_ */
11 changes: 3 additions & 8 deletions include/parser.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#ifndef GHERKIN_PARSER_H_
#define GHERKIN_PARSER_H_

#include "builder.h"
#include "error.h"
#include "token_matcher.h"
#include "token_scanner.h"
#include <stdbool.h>
#include <wchar.h>

Expand All @@ -11,14 +14,6 @@ extern "C" {

typedef struct Parser Parser;

typedef struct Builder Builder;

typedef struct TokenMatcher TokenMatcher;

typedef struct TokenScanner TokenScanner;

typedef struct Feature Feature;

Parser* Parser_new(Builder* builder);

void Parser_delete(Parser* parser);
Expand Down
10 changes: 4 additions & 6 deletions include/token_matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
#define GHERKIN_TOKEN_MATCHER_H_

#include <stdbool.h>
#include "dialect.h"
#include "error_list.h"
#include "token.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct Dialect Dialect;

typedef struct ErrorList ErrorList;

typedef struct TokenMatcher TokenMatcher;

typedef void (*matcher_reset_function) (TokenMatcher*);

typedef bool (*match_function) (TokenMatcher*, Token*);

typedef struct TokenMatcher {
struct TokenMatcher {
const wchar_t* default_language;
const wchar_t* language;
const Dialect* dialect;
Expand All @@ -40,7 +38,7 @@ typedef struct TokenMatcher {
match_function match_Language;
match_function match_Other;
match_function match_EOF;
} TokenMatcher;
};

TokenMatcher* TokenMatcher_new(const wchar_t* default_language);

Expand Down
4 changes: 2 additions & 2 deletions include/token_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ typedef Token* (*read_function) (TokenScanner*);

typedef void (*delete_function) (TokenScanner*);

typedef struct TokenScanner {
struct TokenScanner {
read_function read;
delete_function delete;
} TokenScanner;
};

void TokenScanner_delete(TokenScanner* token_scanner);

Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GCC_FLAGS=-c -Wall -Werror -g
CLANG_FLAGS=-c -Wall -Wno-typedef-redefinition -Werror -g
CLANG_FLAGS=-c -Wall -Werror -g

ifeq ($(CC),i686-w64-mingw32-gcc)
CC=i686-w64-mingw32-gcc
Expand Down
1 change: 0 additions & 1 deletion src/ast_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "scenario_outline.h"
#include "data_table.h"
#include "doc_string.h"
#include "error_list.h"
#include <stdio.h>
#include <stdlib.h>

Expand Down
4 changes: 2 additions & 2 deletions src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include "string_utilities.h"
#include <stdlib.h>

typedef struct Compiler {
struct Compiler {
ItemQueue* pickle_list;
} Compiler;
};

typedef struct ReplacementItem {
item_delete_function item_delete;
Expand Down
4 changes: 2 additions & 2 deletions src/error_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <stdlib.h>
#include <setjmp.h>

typedef struct ErrorList {
struct ErrorList {
ItemQueue* errors;
QueueItem* current_error;
jmp_buf* global_env;
jmp_buf* local_env;
} ErrorList;
};

static int calculate_string_length_for_location(int line_width, int column_width);

Expand Down
4 changes: 2 additions & 2 deletions src/file_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "unicode_utilities.h"
#include <stdlib.h>

typedef struct FileReader {
struct FileReader {
const char* file_name;
} FileReader;
};

static void extend_buffer_if_needed(wchar_t** buffer, int* buffer_size, int pos);

Expand Down
4 changes: 2 additions & 2 deletions src/item_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ extern "C" {

typedef struct QueueItem QueueItem;

typedef struct QueueItem {
struct QueueItem {
Item* item;
QueueItem* next;
} QueueItem;
};

typedef struct ItemQueue {
QueueItem* first;
Expand Down
5 changes: 2 additions & 3 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "token_scanner.h"
#include "token_matcher.h"
#include "token_queue.h"
#include "builder.h"
#include "error_list.h"
#include <stdlib.h>
#include <setjmp.h>
Expand All @@ -18,11 +17,11 @@ typedef struct ParserContext {
ErrorList* errors;
} ParserContext;

typedef struct Parser {
struct Parser {
ParserContext* parser_context;
Builder* builder;
ErrorList* errors;
} Parser;
};

static Token* read_token(ParserContext* context);

Expand Down
2 changes: 0 additions & 2 deletions src/token_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include "item_queue.h"
#include <stdlib.h>

typedef struct QueueItem QueueItem;

TokenQueue* TokenQueue_new() {
return (TokenQueue*)ItemQueue_new();
}
Expand Down
4 changes: 2 additions & 2 deletions src/utf8_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ typedef unsigned char (*utf8_source_read_function) (Utf8Source*);

typedef void (*utf8_source_delete_function) (Utf8Source*);

typedef struct Utf8Source {
struct Utf8Source {
utf8_source_read_function read;
utf8_source_delete_function delete;
} Utf8Source;
};

unsigned char Utf8Source_read(Utf8Source* utf8_source);

Expand Down

0 comments on commit 8f31c2f

Please sign in to comment.