Skip to content

Commit 686eb58

Browse files
committed
enum declaration for StrKind, ExprKind
Reduce header include, but violate `pedantic`. CIで失敗: ``` cc -ansi -std=c11 -pedantic -MMD -Wall -Wextra -Werror -Wold-style-definition -Wno-missing-field-initializers -Wno-empty-body -D_DEFAULT_SOURCE -O2 -g3 -Isrc/util -DXCC_TARGET_ARCH=XCC_ARCH_X64 -Isrc/cc/frontend -c -o obj/initializer.o src/cc/frontend/initializer.c In file included from src/cc/frontend/expr.c:2: src/cc/frontend/expr.h:22:68: error: ISO C forbids forward references to ‘enum’ types [-Werror=pedantic] 22 | Expr *string_expr(const Token *token, char *str, ssize_t len, enum StrKind kind); | ^~~~~~~ src/cc/frontend/expr.h:32:29: error: ISO C forbids forward references to ‘enum’ types [-Werror=pedantic] 32 | Expr *new_expr_num_bop(enum ExprKind kind, const Token *tok, Expr *lhs, Expr *rhs); | ^~~~~~~~ src/cc/frontend/expr.h:33:29: error: ISO C forbids forward references to ‘enum’ types [-Werror=pedantic] 33 | Expr *new_expr_int_bop(enum ExprKind kind, const Token *tok, Expr *lhs, Expr *rhs); | ^~~~~~~~ src/cc/frontend/expr.h:34:28: error: ISO C forbids forward references to ‘enum’ types [-Werror=pedantic] 34 | Expr *new_expr_addsub(enum ExprKind kind, const Token *tok, Expr *lhs, Expr *rhs); | ^~~~~~~~ src/cc/frontend/expr.h:41:22: error: ISO C forbids forward references to ‘enum’ types [-Werror=pedantic] 41 | Expr *incdec_of(enum ExprKind kind, Expr *target, const Token *tok); | ^~~~~~~~ src/cc/frontend/expr.h:42:25: error: ISO C forbids forward references to ‘enum’ types [-Werror=pedantic] 42 | Expr *new_expr_cmp(enum ExprKind kind, const Token *tok, Expr *lhs, Expr *rhs); | ^~~~~~~~ ```
1 parent 1c3c225 commit 686eb58

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/cc/frontend/expr.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
#pragma once
22

3-
#include "ast.h"
3+
#include <stdbool.h>
4+
#include <stddef.h> // size_t
5+
#include <sys/types.h> // ssize_t
6+
7+
typedef struct Expr Expr;
8+
typedef struct MemberInfo MemberInfo;
9+
typedef struct Token Token;
10+
typedef struct Type Type;
11+
12+
#if defined(__GNUC__) || defined(__clang__)
13+
#pragma GCC diagnostic push
14+
#pragma GCC diagnostic ignored "-Wpedantic"
15+
#endif
16+
enum ExprKind;
17+
enum StrKind;
18+
#if defined(__GNUC__) || defined(__clang__)
19+
#pragma GCC diagnostic pop
20+
#endif
421

522
Expr *string_expr(const Token *token, char *str, ssize_t len, enum StrKind kind);
623
Expr *calc_type_size(const Type *type);

src/cc/frontend/type.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ bool is_unsigned(const Type *type) {
242242
return (is_fixnum(type) && type->fixnum.is_unsigned) || type->kind == TY_PTR;
243243
}
244244

245-
bool is_char_type(const Type *type, /*enum FixnumKind*/int str_kind) {
245+
bool is_char_type(const Type *type, enum StrKind str_kind) {
246246
switch ((enum StrKind)str_kind) {
247247
case STR_CHAR:
248248
return type->kind == TY_FIXNUM && type->fixnum.kind == FX_CHAR;

src/cc/frontend/type.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ typedef struct Expr Expr;
1212
typedef struct Name Name;
1313
typedef struct Vector Vector;
1414

15+
#if defined(__GNUC__) || defined(__clang__)
16+
#pragma GCC diagnostic push
17+
#pragma GCC diagnostic ignored "-Wpedantic"
18+
#endif
19+
enum StrKind;
20+
#if defined(__GNUC__) || defined(__clang__)
21+
#pragma GCC diagnostic pop
22+
#endif
23+
1524
// Fixnum
1625

1726
enum FixnumKind {
@@ -156,7 +165,7 @@ static inline bool is_flonum(const Type *type) {
156165
static inline bool is_bool(const Type *type) { return type->kind == TY_FIXNUM && type->fixnum.kind == FX_BOOL; }
157166
bool is_number(const Type *type);
158167
bool is_unsigned(const Type *type);
159-
bool is_char_type(const Type *type, /*enum StrKind*/int str_kind);
168+
bool is_char_type(const Type *type, enum StrKind str_kind);
160169
bool is_void_ptr(const Type *type);
161170
bool is_prim_type(const Type *type);
162171
static inline bool ptr_or_array(const Type *type) { return type->kind == TY_PTR || type->kind == TY_ARRAY; }

0 commit comments

Comments
 (0)