@@ -8313,10 +8313,16 @@ struct declaration_specifiers* declaration_specifiers(struct parser_ctx* ctx, st
83138313
83148314struct static_assert_declaration
83158315{
8316- struct token* first;
8317- struct token* last;
8318- struct expression* p_conditional_expression;
8319- struct token* text_opt;
8316+ /*
8317+ static_assert-declaration:
8318+ "static_assert" ( constant-expression , string-literal ) ;
8319+ "static_assert" ( constant-expression ) ;
8320+ */
8321+
8322+ struct token* first_token;
8323+ struct token* last_token;
8324+ struct expression* constant_expression;
8325+ struct token* string_literal_opt;
83208326};
83218327struct static_assert_declaration* static_assert_declaration(struct parser_ctx* ctx, struct error* error);
83228328
@@ -8340,10 +8346,21 @@ struct attribute* attribute(struct parser_ctx* ctx, struct error* error);
83408346
83418347struct storage_class_specifier
83428348{
8349+ /*
8350+ storage-class-specifier:
8351+ "auto"
8352+ "constexpr"
8353+ "extern"
8354+ "register"
8355+ "static"
8356+ "thread_local"
8357+ "typedef"
8358+ */
83438359 enum storage_class_specifier_flags flags;
8360+
83448361 struct token* token;
83458362};
8346- struct storage_class_specifier* storage_class_specifier(struct parser_ctx* ctx, struct error* error );
8363+ struct storage_class_specifier* storage_class_specifier(struct parser_ctx* ctx);
83478364
83488365struct function_specifier
83498366{
@@ -15634,7 +15651,7 @@ struct declaration_specifier* declaration_specifier(struct parser_ctx* ctx, stru
1563415651 struct declaration_specifier* pDeclaration_specifier = calloc(1, sizeof * pDeclaration_specifier);
1563515652 if (first_of_storage_class_specifier(ctx))
1563615653 {
15637- pDeclaration_specifier->storage_class_specifier = storage_class_specifier(ctx, error );
15654+ pDeclaration_specifier->storage_class_specifier = storage_class_specifier(ctx);
1563815655 }
1563915656 else if (first_of_type_specifier_qualifier(ctx))
1564015657 {
@@ -15729,68 +15746,71 @@ struct init_declarator_list init_declarator_list(struct parser_ctx* ctx,
1572915746 return init_declarator_list;
1573015747}
1573115748
15732- struct storage_class_specifier* storage_class_specifier(struct parser_ctx* ctx, struct error* error )
15749+ struct storage_class_specifier* storage_class_specifier(struct parser_ctx* ctx)
1573315750{
15734- if (error->code)
15735- return NULL;
1573615751 if (ctx->current == NULL)
1573715752 return NULL;
1573815753
15739- struct storage_class_specifier* p_storage_class_specifier = calloc(1, sizeof(struct storage_class_specifier));
15754+ struct storage_class_specifier* new_storage_class_specifier = calloc(1, sizeof(struct storage_class_specifier));
15755+ if (new_storage_class_specifier == NULL)
15756+ return NULL;
1574015757
15741- p_storage_class_specifier ->token = ctx->current;
15758+ new_storage_class_specifier ->token = ctx->current;
1574215759 switch (ctx->current->type)
1574315760 {
1574415761 case TK_KEYWORD_TYPEDEF:
15745- p_storage_class_specifier ->flags = STORAGE_SPECIFIER_TYPEDEF;
15762+ new_storage_class_specifier ->flags = STORAGE_SPECIFIER_TYPEDEF;
1574615763 break;
1574715764 case TK_KEYWORD_EXTERN:
15748- p_storage_class_specifier ->flags = STORAGE_SPECIFIER_EXTERN;
15765+ new_storage_class_specifier ->flags = STORAGE_SPECIFIER_EXTERN;
1574915766 break;
1575015767 case TK_KEYWORD_CONSTEXPR:
15751- p_storage_class_specifier ->flags = STORAGE_SPECIFIER_CONSTEXPR;
15768+ new_storage_class_specifier ->flags = STORAGE_SPECIFIER_CONSTEXPR;
1575215769 break;
1575315770 case TK_KEYWORD_STATIC:
15754- p_storage_class_specifier ->flags = STORAGE_SPECIFIER_STATIC;
15771+ new_storage_class_specifier ->flags = STORAGE_SPECIFIER_STATIC;
1575515772 break;
1575615773 case TK_KEYWORD__THREAD_LOCAL:
15757- p_storage_class_specifier ->flags = STORAGE_SPECIFIER_THREAD_LOCAL;
15774+ new_storage_class_specifier ->flags = STORAGE_SPECIFIER_THREAD_LOCAL;
1575815775 break;
1575915776 case TK_KEYWORD_AUTO:
15760- p_storage_class_specifier ->flags = STORAGE_SPECIFIER_AUTO;
15777+ new_storage_class_specifier ->flags = STORAGE_SPECIFIER_AUTO;
1576115778 break;
1576215779 case TK_KEYWORD_REGISTER:
15763- p_storage_class_specifier ->flags = STORAGE_SPECIFIER_REGISTER;
15780+ new_storage_class_specifier ->flags = STORAGE_SPECIFIER_REGISTER;
1576415781 break;
1576515782 default:
1576615783 assert(false);
1576715784 }
15785+
15786+ /*
15787+ TODO
15788+ thread_local may appear with static or extern,
15789+ auto may appear with all the others except typedef138), and
15790+ constexpr may appear with auto, register, or static.
15791+ */
1576815792
1576915793 parser_match(ctx);
15770- //'typedef'
15771- //'extern'
15772- //'static'
15773- //'_Thread_local'
15774- //'auto'
15775- //'register'
15776- return p_storage_class_specifier;
15794+ return new_storage_class_specifier;
1577715795}
1577815796
1577915797struct typeof_specifier_argument* typeof_specifier_argument(struct parser_ctx* ctx, struct error* error)
1578015798{
15781- struct typeof_specifier_argument* p_typeof_specifier_argument = calloc(1, sizeof(struct typeof_specifier_argument));
15799+ struct typeof_specifier_argument* new_typeof_specifier_argument = calloc(1, sizeof(struct typeof_specifier_argument));
15800+ if (new_typeof_specifier_argument)
15801+ return NULL;
15802+
1578215803 if (first_of_type_name(ctx))
1578315804 {
15784-
15785- p_typeof_specifier_argument->type_name = type_name(ctx, error);
15805+ new_typeof_specifier_argument->type_name = type_name(ctx, error);
1578615806 }
1578715807 else
1578815808 {
1578915809 struct expression_ctx ectx = { 0 };
15790- p_typeof_specifier_argument ->expression = expression(ctx, error, &ectx);
15810+ new_typeof_specifier_argument ->expression = expression(ctx, error, &ectx);
1579115811 }
1579215812
15793- return p_typeof_specifier_argument ;
15813+ return new_typeof_specifier_argument ;
1579415814}
1579515815
1579615816bool first_of_typeof_specifier(struct parser_ctx* ctx)
@@ -17461,33 +17481,33 @@ struct static_assert_declaration* static_assert_declaration(struct parser_ctx* c
1746117481 struct static_assert_declaration* p_static_assert_declaration = calloc(1, sizeof(struct static_assert_declaration));
1746217482 try
1746317483 {
17464- p_static_assert_declaration->first = ctx->current;
17484+ p_static_assert_declaration->first_token = ctx->current;
1746517485 struct token* position = ctx->current;
1746617486 parser_match_tk(ctx, TK_KEYWORD__STATIC_ASSERT, error);
1746717487 parser_match_tk(ctx, '(', error);
1746817488 struct expression_ctx ectx = { .bConstantExpressionRequired = true };
17469- p_static_assert_declaration->p_conditional_expression = constant_expression(ctx, error, &ectx);
17489+ p_static_assert_declaration->constant_expression = constant_expression(ctx, error, &ectx);
1747017490
1747117491 if (error->code != 0)
1747217492 throw;
1747317493
1747417494 if (ctx->current->type == ',')
1747517495 {
1747617496 parser_match(ctx);
17477- p_static_assert_declaration->text_opt = ctx->current;
17497+ p_static_assert_declaration->string_literal_opt = ctx->current;
1747817498 parser_match_tk(ctx, TK_STRING_LITERAL, error);
1747917499 }
1748017500
1748117501 parser_match_tk(ctx, ')', error);
17482- p_static_assert_declaration->last = ctx->current;
17502+ p_static_assert_declaration->last_token = ctx->current;
1748317503 parser_match_tk(ctx, ';', error);
1748417504
17485- if (p_static_assert_declaration->p_conditional_expression ->constant_value == 0)
17505+ if (p_static_assert_declaration->constant_expression ->constant_value == 0)
1748617506 {
17487- if (p_static_assert_declaration->text_opt )
17507+ if (p_static_assert_declaration->string_literal_opt )
1748817508 {
1748917509 parser_seterror_with_token(ctx, position, "_Static_assert failed %s\n",
17490- p_static_assert_declaration->text_opt ->lexeme);
17510+ p_static_assert_declaration->string_literal_opt ->lexeme);
1749117511 }
1749217512 else
1749317513 {
@@ -20225,16 +20245,16 @@ static void visit_block_item_list(struct visit_ctx* ctx, struct block_item_list*
2022520245
2022620246static void visit_static_assert_declaration(struct visit_ctx* ctx, struct static_assert_declaration* p_static_assert_declaration, struct error* error)
2022720247{
20228- visit_expression(ctx, p_static_assert_declaration->p_conditional_expression , error);
20248+ visit_expression(ctx, p_static_assert_declaration->constant_expression , error);
2022920249
2023020250 if (ctx->target < LANGUAGE_C11)
2023120251 {
2023220252 /*
2023320253 * Vamos apagar a parte do static assert. Não adianta so commentar
2023420254 * pq poderia ter um comentario dentro. (so se verificar que nao tem)
2023520255 */
20236- for (struct token* p = p_static_assert_declaration->first ;
20237- p != p_static_assert_declaration->last ->next;
20256+ for (struct token* p = p_static_assert_declaration->first_token ;
20257+ p != p_static_assert_declaration->last_token ->next;
2023820258 p = p->next)
2023920259 {
2024020260 /*
@@ -20245,19 +20265,19 @@ static void visit_static_assert_declaration(struct visit_ctx* ctx, struct static
2024520265 }
2024620266 else if (ctx->target == LANGUAGE_C11)
2024720267 {
20248- if (p_static_assert_declaration->text_opt == NULL)
20268+ if (p_static_assert_declaration->string_literal_opt == NULL)
2024920269 {
20250- struct token* rp = previous_parser_token(p_static_assert_declaration->last );
20270+ struct token* rp = previous_parser_token(p_static_assert_declaration->last_token );
2025120271 rp = previous_parser_token(rp);
2025220272
2025320273 struct token_list list1 = tokenizer(", \"error\"", "", 0, TK_FLAG_NONE, error);
2025420274 token_list_insert_after(&ctx->ast.token_list, rp, &list1);
2025520275 }
20256- if (strcmp(p_static_assert_declaration->first ->lexeme, "static_assert") == 0)
20276+ if (strcmp(p_static_assert_declaration->first_token ->lexeme, "static_assert") == 0)
2025720277 {
2025820278 /*C23 has static_assert but C11 _Static_assert*/
20259- free(p_static_assert_declaration->first ->lexeme);
20260- p_static_assert_declaration->first ->lexeme = strdup("_Static_assert");
20279+ free(p_static_assert_declaration->first_token ->lexeme);
20280+ p_static_assert_declaration->first_token ->lexeme = strdup("_Static_assert");
2026120281 }
2026220282 }
2026320283}
0 commit comments