@@ -21,7 +21,8 @@ typedef enum {
2121 PCD_LOGOR ,
2222} Preced ;
2323
24- enum {
24+ typedef enum {
25+ SC_NONE = 0 ,
2526 SC_AUTO = 1 ,
2627 SC_CONSTEXPR = 1 << 1 ,
2728 SC_EXTERN = 1 << 2 ,
@@ -30,15 +31,12 @@ enum {
3031 SC_THREAD = 1 << 5 ,
3132 SC_TYPEDEF = 1 << 6 ,
3233 SC_ALL = (1 << 7 ) - 1 ,
33- SC_NONE = 0 ,
34- };
35-
36- typedef uint8_t StorageClass ;
34+ SC_INLINE = 1 << 7 ,
35+ } StorageClass ;
3736
3837typedef struct {
3938 Node * typeof_vm_expr ;
40- StorageClass strg ;
41- bool is_inline ;
39+ StorageClass strg : 8 ;
4240 bool is_weak ;
4341 bool is_packed ;
4442 bool is_common ;
@@ -1078,7 +1076,7 @@ static void cleanup_attr(Token *name, Token *tok, VarAttr *attr, Obj *var) {
10781076 }
10791077}
10801078
1081- static bool chk_storage_class (uint8_t msk , StorageClass allow ) {
1079+ static bool chk_storage_class (StorageClass msk , StorageClass allow ) {
10821080 if (msk == SC_NONE )
10831081 return false;
10841082 if (msk & ~allow )
@@ -1143,7 +1141,7 @@ static Type *declspec(Token **rest, Token *tok, VarAttr *attr, StorageClass ctx)
11431141 case TK_static : attr -> strg |= SC_STATIC ; continue ;
11441142 case TK_typedef : attr -> strg |= SC_TYPEDEF ; continue ;
11451143 case TK_thread_local : attr -> strg |= SC_THREAD ; continue ;
1146- case TK_inline : attr -> is_inline = true ; continue ;
1144+ case TK_inline : attr -> strg |= SC_INLINE ; continue ;
11471145 case TK_Noreturn : attr -> is_noreturn = true; continue ;
11481146 case TK_constexpr :
11491147 attr -> strg |= SC_CONSTEXPR ;
@@ -1802,6 +1800,8 @@ static Node *declaration2(Token **rest, Token *tok, Type *basety, VarAttr *attr,
18021800 error_tok (tok , "variable declared void" );
18031801 if (!name )
18041802 error_tok (tok , "variable name omitted" );
1803+ if (attr -> strg & SC_INLINE )
1804+ error_tok (tok , "only function delcarations can be 'inline'" );
18051805
18061806 Node * expr = calc_vla (ty , tok );
18071807
@@ -1926,7 +1926,7 @@ static Node *cond_declaration(Token **rest, Token *tok, const char *stopper, int
19261926
19271927static Node * declaration (Token * * rest , Token * tok ) {
19281928 VarAttr attr = {0 };
1929- Type * basety = declspec (& tok , tok , & attr , SC_ALL );
1929+ Type * basety = declspec (& tok , tok , & attr , SC_ALL | SC_INLINE );
19301930
19311931 if (attr .strg & SC_EXTERN ) {
19321932 global_declaration (rest , tok , basety , & attr );
@@ -5585,6 +5585,9 @@ static Node *primary(Token **rest, Token *tok) {
55855585}
55865586
55875587static Node * parse_typedef (Token * * rest , Token * tok , Type * basety , VarAttr * attr ) {
5588+ if (attr -> strg & SC_INLINE )
5589+ error_tok (tok , "only function delcarations can be 'inline'" );
5590+
55885591 Node * node = NULL ;
55895592 bool first = true;
55905593 for (; comma_list (rest , & tok , ";" , !first ); first = false) {
@@ -5866,11 +5869,11 @@ static Obj *func_prototype(Token **rest, Token *tok, Token *name, Type *ty, VarA
58665869
58675870static void func_exportness (Obj * fn , VarAttr * attr , bool is_def ) {
58685871 if (!fn -> is_static && !scope -> parent ) {
5869- fn -> export_fn |= !(attr -> is_inline && !(attr -> strg & SC_EXTERN ));
5872+ fn -> export_fn |= !(( attr -> strg & SC_INLINE ) && !(attr -> strg & SC_EXTERN ));
58705873 if (is_def )
5871- fn -> export_fn_gnu |= !(attr -> is_inline && (attr -> strg & SC_EXTERN ));
5874+ fn -> export_fn_gnu |= !(( attr -> strg & SC_INLINE ) && (attr -> strg & SC_EXTERN ));
58725875 else
5873- fn -> export_fn_gnu |= (attr -> is_inline && !(attr -> strg & SC_EXTERN ));
5876+ fn -> export_fn_gnu |= (( attr -> strg & SC_INLINE ) && !(attr -> strg & SC_EXTERN ));
58745877 }
58755878}
58765879
@@ -5895,6 +5898,8 @@ static void global_declaration(Token **rest, Token *tok, Type *basety, VarAttr *
58955898
58965899 if (!name )
58975900 error_tok (tok , "variable name omitted" );
5901+ if (attr -> strg & SC_INLINE )
5902+ error_tok (tok , "only function delcarations can be 'inline'" );
58985903
58995904 bool is_definition = !(attr -> strg & SC_EXTERN );
59005905 if (!is_definition ) {
@@ -6010,7 +6015,7 @@ Obj *parse(Token *tok) {
60106015 }
60116016
60126017 VarAttr attr = {0 };
6013- Type * basety = declspec (& tok , tok , & attr , SC_ALL );
6018+ Type * basety = declspec (& tok , tok , & attr , SC_ALL | SC_INLINE );
60146019
60156020 if (attr .strg & SC_TYPEDEF ) {
60166021 parse_typedef (& tok , tok , basety , & attr );
0 commit comments