Skip to content

Commit 381a3dd

Browse files
committed
u
1 parent f7f0192 commit 381a3dd

File tree

3 files changed

+255
-16
lines changed

3 files changed

+255
-16
lines changed

src/build.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ int main()
172172
HEADER("Build amalgamated file");
173173

174174

175-
execute_cmd(RUN "amalgamator.exe -olib.c" CAKE_LIB_SOURCE_FILES);
175+
execute_cmd(RUN "amalgamator.exe -olib.c" CAKE_SOURCE_FILES);
176176
remove("amalgamator.exe");
177177

178178

src/lib.c

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58569,3 +58569,242 @@ const struct type* type_get_specifer_part(const struct type* p_type)
5856958569
}
5857058570

5857158571

58572+
58573+
/*
58574+
* This file is part of cake compiler
58575+
* https://github.com/thradams/cake
58576+
*/
58577+
58578+
#pragma safety enable
58579+
58580+
58581+
#ifdef _WIN32
58582+
#undef assert
58583+
#define assert _ASSERTE
58584+
#endif
58585+
58586+
#ifdef TEST
58587+
58588+
58589+
/*do not edit this file*/
58590+
58591+
58592+
#ifdef TEST
58593+
#define TESTCODE
58594+
#endif
58595+
int g_unit_test_error_count = 0;
58596+
int g_unit_test_success_count = 0;
58597+
#ifdef TESTCODE
58598+
58599+
/*forward declarations*/
58600+
58601+
/* tests from token.c*/
58602+
void token_list_remove_get_test(void);
58603+
void token_list_remove_get_test2(void);
58604+
58605+
/* tests from tokenizer.c*/
58606+
void test_lexeme_cmp(void);
58607+
void token_list_pop_front_test(void);
58608+
void token_list_pop_back_test(void);
58609+
int token_list_append_list_test(void);
58610+
void test_collect(void);
58611+
void test_va_opt_0(void);
58612+
void test_va_opt_1(void);
58613+
void test_va_opt_2(void);
58614+
void test_va_opt_3(void);
58615+
void test_va_opt_4(void);
58616+
void test_va_opt_5(void);
58617+
void test_va_opt_6(void);
58618+
void test_va_opt_7(void);
58619+
void concatenation_problem(void);
58620+
void test_va_opt_G2(void);
58621+
void test_va_opt(void);
58622+
void test_empty_va_args(void);
58623+
void test_va_args_single(void);
58624+
void test_va_args_extra_args(void);
58625+
void test_empty_va_args_empty(void);
58626+
void test_defined(void);
58627+
void testline(void);
58628+
void ifelse(void);
58629+
void T1(void);
58630+
int EXAMPLE5(void);
58631+
void recursivetest1(void);
58632+
void rectest(void);
58633+
void emptycall(void);
58634+
void semiempty(void);
58635+
void calling_one_arg_with_empty_arg(void);
58636+
void test_argument_with_parentesis(void);
58637+
void two_empty_arguments(void);
58638+
void simple_object_macro(void);
58639+
void test2(void);
58640+
void test3(void);
58641+
void tetris(void);
58642+
void recursive_macro_expansion(void);
58643+
void empty_and_no_args(void);
58644+
void empty_and_args(void);
58645+
void test4(void);
58646+
void test_string(void);
58647+
void test6(void);
58648+
void testerror(void);
58649+
int test_expression(void);
58650+
void test_concatenation_o(void);
58651+
void test_concatenation(void);
58652+
void bad_test(void);
58653+
void test_spaces(void);
58654+
void test_stringfy(void);
58655+
void test_stringfy_scape(void);
58656+
void test_stringfy_scape3(void);
58657+
int test_tokens(void);
58658+
int test_predefined_macros(void);
58659+
int test_utf8(void);
58660+
void test_counter(void);
58661+
void bug_test(void);
58662+
int test_line_continuation(void);
58663+
int stringify_test(void);
58664+
void recursive_macro_expr(void);
58665+
void quasi_recursive_macro(void);
58666+
void newline_macro_func(void);
58667+
58668+
/* tests from target.c*/
58669+
void target_self_test(void);
58670+
58671+
/*end of forward declarations*/
58672+
58673+
int test_main(void)
58674+
{
58675+
g_unit_test_error_count = 0;
58676+
g_unit_test_success_count = 0;
58677+
token_list_remove_get_test();
58678+
token_list_remove_get_test2();
58679+
test_lexeme_cmp();
58680+
token_list_pop_front_test();
58681+
token_list_pop_back_test();
58682+
token_list_append_list_test();
58683+
test_collect();
58684+
test_va_opt_0();
58685+
test_va_opt_1();
58686+
test_va_opt_2();
58687+
test_va_opt_3();
58688+
test_va_opt_4();
58689+
test_va_opt_5();
58690+
test_va_opt_6();
58691+
test_va_opt_7();
58692+
concatenation_problem();
58693+
test_va_opt_G2();
58694+
test_va_opt();
58695+
test_empty_va_args();
58696+
test_va_args_single();
58697+
test_va_args_extra_args();
58698+
test_empty_va_args_empty();
58699+
test_defined();
58700+
testline();
58701+
ifelse();
58702+
T1();
58703+
EXAMPLE5();
58704+
recursivetest1();
58705+
rectest();
58706+
emptycall();
58707+
semiempty();
58708+
calling_one_arg_with_empty_arg();
58709+
test_argument_with_parentesis();
58710+
two_empty_arguments();
58711+
simple_object_macro();
58712+
test2();
58713+
test3();
58714+
tetris();
58715+
recursive_macro_expansion();
58716+
empty_and_no_args();
58717+
empty_and_args();
58718+
test4();
58719+
test_string();
58720+
test6();
58721+
testerror();
58722+
test_expression();
58723+
test_concatenation_o();
58724+
test_concatenation();
58725+
bad_test();
58726+
test_spaces();
58727+
test_stringfy();
58728+
test_stringfy_scape();
58729+
test_stringfy_scape3();
58730+
test_tokens();
58731+
test_predefined_macros();
58732+
test_utf8();
58733+
test_counter();
58734+
bug_test();
58735+
test_line_continuation();
58736+
stringify_test();
58737+
recursive_macro_expr();
58738+
quasi_recursive_macro();
58739+
newline_macro_func();
58740+
target_self_test();
58741+
return g_unit_test_error_count;
58742+
58743+
}
58744+
#undef TESTCODE
58745+
#endif /*TEST*/
58746+
58747+
#endif
58748+
58749+
int main(int argc, char** argv)
58750+
{
58751+
enable_vt_mode();
58752+
58753+
#if 0
58754+
//Help debug emscript on desktop
58755+
//MOCKFILES needs to be defined
58756+
const char* source =
58757+
"#include <stdio.h>\n";
58758+
58759+
char* _Owner _Opt r =
58760+
CompileText("", source);
58761+
return;
58762+
#endif
58763+
58764+
printf("Cake " CAKE_VERSION " (%s)\n", get_platform(CAKE_COMPILE_TIME_SELECTED_TARGET)->name);
58765+
58766+
if (argc < 2)
58767+
{
58768+
print_help();
58769+
return 1;
58770+
}
58771+
58772+
58773+
if (argc > 1 && strcmp(argv[1], "-selftest") == 0)
58774+
{
58775+
printf("*** SELF TEST ***.\n");
58776+
58777+
#ifdef TEST
58778+
58779+
clock_t begin_clock = clock();
58780+
58781+
test_main();
58782+
58783+
struct report report = { 0 };
58784+
report.test_mode = true;
58785+
report.test_failed = g_unit_test_error_count;
58786+
report.test_succeeded = g_unit_test_success_count;
58787+
58788+
clock_t end_clock = clock();
58789+
double cpu_time_used = ((double)(end_clock - begin_clock)) / CLOCKS_PER_SEC;
58790+
report.no_files = g_unit_test_error_count + g_unit_test_success_count;
58791+
report.cpu_time_used_sec = cpu_time_used;
58792+
58793+
print_report(&report);
58794+
58795+
return g_unit_test_error_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
58796+
#else
58797+
printf("Error: self-tests not included. To run the self-tests, compile with -DTEST and try again.\n");
58798+
return EXIT_FAILURE;
58799+
#endif
58800+
}
58801+
58802+
58803+
struct report report = { 0 };
58804+
int result = compile(argc, (const char**)argv, &report);
58805+
58806+
return result;
58807+
}
58808+
58809+
58810+

src/parser.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,7 @@ struct declaration* _Owner _Opt declaration(struct parser_ctx* ctx,
22942294
struct defer_visit_ctx ctx2 = { .ctx = ctx };
22952295
defer_start_visit_declaration(&ctx2, p_declaration);
22962296
defer_visit_ctx_destroy(&ctx2);
2297-
2297+
22982298
if (ctx->p_report->error_count == 0 && ctx->options.flow_analysis)
22992299
{
23002300
/*
@@ -6952,7 +6952,7 @@ void defer_list_clear(struct defer_list* p)
69526952
free(item);
69536953
item = next;
69546954
}
6955-
6955+
69566956
p->head = NULL;
69576957
p->tail = NULL;
69586958
}
@@ -8064,7 +8064,7 @@ enum attribute_flags attribute_token(struct parser_ctx* ctx, struct attribute* p
80648064
if (ctx->current->type == '::')
80658065
{
80668066
p_attribute->attribute_prefix = p_attribute->attribute_token;
8067-
8067+
80688068
parser_match(ctx);
80698069
if (is_cake_attr)
80708070
{
@@ -8090,7 +8090,7 @@ enum attribute_flags attribute_token(struct parser_ctx* ctx, struct attribute* p
80908090
unexpected_end_of_file(ctx);
80918091
throw;
80928092
}
8093-
8093+
80948094
if (token_is_identifier_or_keyword(ctx->current->type))
80958095
{
80968096
p_attribute->attribute_token = ctx->current;
@@ -8132,7 +8132,7 @@ struct attribute* _Owner _Opt attribute(struct parser_ctx* ctx, struct attribute
81328132
if (p_attribute == NULL)
81338133
throw;
81348134

8135-
enum attribute_flags attribute_flags = attribute_token(ctx, p_attribute , p_attribute_specifier);
8135+
enum attribute_flags attribute_flags = attribute_token(ctx, p_attribute, p_attribute_specifier);
81368136

81378137
if (ctx->current == NULL)
81388138
{
@@ -8239,14 +8239,14 @@ struct balanced_token_sequence* _Owner _Opt balanced_token_sequence_opt(struct p
82398239
count2--;
82408240
else if (ctx->current->type == '{')
82418241
count3--;
8242-
8243-
if(ctx->current->type != TK_COMMA)
8242+
8243+
if (ctx->current->type != TK_COMMA)
82448244
{
82458245
struct balanced_token* new_token = calloc(1, sizeof(struct balanced_token));
82468246
if (new_token == NULL) throw;
82478247

82488248
new_token->token = ctx->current;
8249-
if(p_balanced_token_sequence->tail == NULL)
8249+
if (p_balanced_token_sequence->tail == NULL)
82508250
{
82518251
p_balanced_token_sequence->head = new_token;
82528252
}
@@ -8256,7 +8256,7 @@ struct balanced_token_sequence* _Owner _Opt balanced_token_sequence_opt(struct p
82568256
}
82578257
p_balanced_token_sequence->tail = new_token;
82588258
}
8259-
8259+
82608260
parser_match(ctx);
82618261
}
82628262
if (count2 != 0)
@@ -8344,7 +8344,7 @@ struct primary_block* _Owner _Opt primary_block(struct parser_ctx* ctx)
83448344
p_primary_block->iteration_statement = iteration_statement(ctx);
83458345
if (p_primary_block->iteration_statement == NULL)
83468346
throw;
8347-
}
8347+
}
83488348
else if (ctx->current->type == TK_KEYWORD_CAKE_TRY ||
83498349
ctx->current->type == TK_KEYWORD_MSVC__TRY)
83508350
{
@@ -8485,7 +8485,7 @@ void primary_block_delete(struct primary_block* _Owner _Opt p)
84858485
{
84868486
if (p)
84878487
{
8488-
compound_statement_delete(p->compound_statement);
8488+
compound_statement_delete(p->compound_statement);
84898489
iteration_statement_delete(p->iteration_statement);
84908490
selection_statement_delete(p->selection_statement);
84918491
try_statement_delete(p->try_statement);
@@ -8500,7 +8500,7 @@ static bool first_of_primary_block(const struct parser_ctx* ctx)
85008500

85018501
if (first_of_compound_statement(ctx) ||
85028502
first_of_selection_statement(ctx) ||
8503-
first_of_iteration_statement(ctx) ||
8503+
first_of_iteration_statement(ctx) ||
85048504
ctx->current->type == TK_KEYWORD_CAKE_TRY /*extension*/ ||
85058505
ctx->current->type == TK_KEYWORD_MSVC__TRY ||
85068506
ctx->current->type == TK_KEYWORD__ASM
@@ -10051,7 +10051,7 @@ struct selection_statement* _Owner _Opt selection_statement(struct parser_ctx* c
1005110051
assert(p_selection_statement->secondary_block == NULL);
1005210052
p_selection_statement->secondary_block = p_secondary_block;
1005310053

10054-
10054+
1005510055
ctx->p_current_selection_statement = previous;
1005610056

1005710057

@@ -10158,7 +10158,7 @@ struct defer_statement* _Owner _Opt defer_statement(struct parser_ctx* ctx)
1015810158

1015910159
struct unlabeled_statement* _Owner _Opt p_unlabeled_statement = unlabeled_statement(ctx, NULL); //TODO unlabeled_statement
1016010160
if (p_unlabeled_statement == NULL) throw;
10161-
10161+
1016210162

1016310163
p_defer_statement->unlabeled_statement = p_unlabeled_statement;
1016410164
if (ctx->previous == NULL) throw;
@@ -10479,7 +10479,7 @@ struct jump_statement* _Owner _Opt jump_statement(struct parser_ctx* ctx)
1047910479
}
1048010480
else if (ctx->current->type == TK_KEYWORD_BREAK)
1048110481
{
10482-
const bool in_switch =
10482+
const bool in_switch =
1048310483
ctx->p_current_selection_statement && ctx->p_current_selection_statement->first_token->type == TK_KEYWORD_SWITCH;
1048410484

1048510485
if (ctx->p_current_iteration_statement == NULL && !in_switch)

0 commit comments

Comments
 (0)