Skip to content

Commit

Permalink
Fixes to build on Ubuntu 18.04 with gcc-9.4 #105
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Feb 21, 2024
1 parent 4413170 commit e5b289e
Show file tree
Hide file tree
Showing 11 changed files with 636 additions and 662 deletions.
21 changes: 12 additions & 9 deletions src/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
" pre_expressions.h " \
" expressions.h " \
" visit.h " \
" format_visit.h "
" format_visit.h "


#define SOURCE_FILES \
" token.c " \
Expand All @@ -52,7 +52,7 @@
" error.c " \
" format_visit.c " \
" tests.c "


void compile_cake()
{
Expand Down Expand Up @@ -254,7 +254,7 @@ int main()
generate_doc("../README.md", "./web/index.html");
generate_doc("../warnings.md", "./web/warnings.html");
generate_doc("../ownership.md", "./web/ownership.html");


remove("hoedown.exe");

Expand All @@ -277,7 +277,7 @@ int main()
running cake on its own source code
*/

//-flow-analysis
//-flow-analysis
//-nullchecks
#ifdef NULLCHECKS
#define NC " -nullchecks "
Expand All @@ -292,17 +292,20 @@ int main()
#if defined BUILD_LINUX_GCC
/*
running cake on its own source code
To find GCC directories use
To find GCC directories use
echo | gcc -E -Wp,-v -
*/
if (system("./cake "
const char *cake_cmd = "./cake "
" -D__x86_64__ "
" -I/usr/lib/gcc/x86_64-linux-gnu/11/include/ "
" -I/usr/local/include/ "
" -I/usr/include/x86_64-linux-gnu/ "
" -I/usr/include/ "
" -I/usr/include/ "
HEADER_FILES
SOURCE_FILES) != 0)
SOURCE_FILES;
printf("%s\n", cake_cmd);
fflush(stdout);
if (system(cake_cmd) != 0)
{
exit(1);
}
Expand Down
48 changes: 28 additions & 20 deletions src/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,33 @@

#endif

/*
WITH_ANSI_COLOR - Controls the build output colors
*/


#define ESC "\x1b"
#define CSI "\x1b["
#define RESET ESC "[0m"
#define BLACK "\x1b[30m"
#define BLUE "\x1b[34m"
#define GREEN "\x1b[32m"
#define CYAN "\x1b[36m"
#define RED "\x1b[31;1m"
#define MAGENTA "\x1b[35m"
#define BROWN "\x1b[31m"
#define LIGHTGRAY "\x1b[30;1m"
#define DARKGRAY "\x1b[30m"
#define LIGHTBLUE "\x1b[34;1m"
#define LIGHTGREEN "\x1b[32,1m"
#define LIGHTCYAN "\x1b[36;1m"
#define LIGHTRED "\x1b[31;1m"
#define LIGHTMAGENTA "\x1b[35;1m"
#define YELLOW "\x1b[33;1m"
#define WHITE "\x1b[37;1m"
#ifdef WITH_ANSI_COLOR
#define COLOR_ESC(x) x
#else
#define COLOR_ESC(x) ""
#endif

#define ESC COLOR_ESC("\x1b")
#define CSI COLOR_ESC("\x1b[")
#define RESET ESC COLOR_ESC("[0m")
#define BLACK COLOR_ESC("\x1b[30m")
#define BLUE COLOR_ESC("\x1b[34m")
#define GREEN COLOR_ESC("\x1b[32m")
#define CYAN COLOR_ESC("\x1b[36m")
#define RED COLOR_ESC("\x1b[31;1m")
#define MAGENTA COLOR_ESC("\x1b[35m")
#define BROWN COLOR_ESC("\x1b[31m")
#define LIGHTGRAY COLOR_ESC("\x1b[30;1m")
#define DARKGRAY COLOR_ESC("\x1b[30m")
#define LIGHTBLUE COLOR_ESC("\x1b[34;1m")
#define LIGHTGREEN COLOR_ESC("\x1b[32,1m")
#define LIGHTCYAN COLOR_ESC("\x1b[36;1m")
#define LIGHTRED COLOR_ESC("\x1b[31;1m")
#define LIGHTMAGENTA COLOR_ESC("\x1b[35;1m")
#define YELLOW COLOR_ESC("\x1b[33;1m")
#define WHITE COLOR_ESC("\x1b[37;1m")

136 changes: 51 additions & 85 deletions src/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,98 +12,64 @@

bool enable_vt_mode(void);

//#define DISABLE_COLORS 1

#ifdef DISABLE_COLORS

#define ESC ""
#define CSI ""

#define BLACK ""
#define BLUE ""
#define GREEN ""
#define CYAN ""
#define RED ""
#define MAGENTA ""
#define BROWN ""
#define LIGHTGRAY ""
#define DARKGRAY ""
#define LIGHTBLUE ""
#define LIGHTGREEN ""
#define LIGHTCYAN ""
#define LIGHTRED ""
#define LIGHTMAGENTA ""
#define YELLOW ""
#define WHITE ""

//https//en.wikipedia.org/wiki/ANSI_escape_code


#define BK_BLACK ""
#define BK_BLUE ""
#define BK_GREEN ""
#define BK_CYAN ""
#define BK_RED ""
#define BK_MAGENTA ""
#define BK_BROWN ""
#define BK_LIGHTGRAY ""
#define BK_DARKGRAY ""
#define BK_LIGHTBLUE ""
#define BK_LIGHTGREEN ""
#define BK_LIGHTCYAN ""
#define BK_LIGHTRED ""
#define BK_LIGHTMAGENTA ""
#define BK_YELLOW ""
#define BK_WHITE ""
#define BK_BLINK ""
#define RESET ESC ""
/*
DISABLE_COLORS is defined to generate a
version of cake that does not ouput colors
A runtime flag msvcouput is already used..
but some utility functions are not using
*/
#ifndef DISABLE_COLORS
#define COLOR_ESC(x) x
#define COLOR_ESC_PRINT(x) x
#else
#define COLOR_ESC(x) ""
#define COLOR_ESC_PRINT(x)
#endif

/*change foreground color*/

#define ESC "\x1b"
#define CSI "\x1b["

#define BLACK "\x1b[30m"
#define BLUE "\x1b[34m"
#define GREEN "\x1b[32m"
#define CYAN "\x1b[36m"
#define RED "\x1b[31;1m"
#define MAGENTA "\x1b[35m"
#define BROWN "\x1b[31m"
#define LIGHTGRAY "\x1b[37m"
#define DARKGRAY "\x1b[90m"
#define LIGHTBLUE "\x1b[34;1m"
#define LIGHTGREEN "\x1b[92m"
#define LIGHTCYAN "\x1b[36;1m"
#define LIGHTRED "\x1b[91m"
#define LIGHTMAGENTA "\x1b[95m"
#define YELLOW "\x1b[93m"
#define WHITE "\x1b[97m"
#define ESC COLOR_ESC("\x1b")
#define CSI COLOR_ESC("\x1b[")

#define BLACK COLOR_ESC("\x1b[30m")
#define BLUE COLOR_ESC("\x1b[34m")
#define GREEN COLOR_ESC("\x1b[32m")
#define CYAN COLOR_ESC("\x1b[36m")
#define RED COLOR_ESC("\x1b[31;1m")
#define MAGENTA COLOR_ESC("\x1b[35m")
#define BROWN COLOR_ESC("\x1b[31m")
#define LIGHTGRAY COLOR_ESC("\x1b[37m")
#define DARKGRAY COLOR_ESC("\x1b[90m")
#define LIGHTBLUE COLOR_ESC("\x1b[34;1m")
#define LIGHTGREEN COLOR_ESC("\x1b[92m")
#define LIGHTCYAN COLOR_ESC("\x1b[36;1m")
#define LIGHTRED COLOR_ESC("\x1b[91m")
#define LIGHTMAGENTA COLOR_ESC("\x1b[95m")
#define YELLOW COLOR_ESC("\x1b[93m")
#define WHITE COLOR_ESC("\x1b[97m")

//https//en.wikipedia.org/wiki/ANSI_escape_code


#define BK_BLACK "\x1b[40m"
#define BK_BLUE "\x1b[44m"
#define BK_GREEN "\x1b[42m"
#define BK_CYAN "\x1b[46m"
#define BK_RED "\x1b[41;1m"
#define BK_MAGENTA "\x1b[45m"
#define BK_BROWN "\x1b[41m"
#define BK_LIGHTGRAY "\x1b[40;1m"
#define BK_DARKGRAY "\x1b[40m"
#define BK_LIGHTBLUE "\x1b[44;1m"
#define BK_LIGHTGREEN "\x1b[42,1m"
#define BK_LIGHTCYAN "\x1b[46;1m"
#define BK_LIGHTRED "\x1b[41;1m"
#define BK_LIGHTMAGENTA "\x1b[45;1m"
#define BK_YELLOW "\x1b[43;1m"
#define BK_WHITE "\x1b[47;1m"
#define BK_BLINK "\x1b[40m"

#define RESET ESC "[0m"

#endif
#define BK_BLACK COLOR_ESC("\x1b[40m")
#define BK_BLUE COLOR_ESC("\x1b[44m")
#define BK_GREEN COLOR_ESC("\x1b[42m")
#define BK_CYAN COLOR_ESC("\x1b[46m")
#define BK_RED COLOR_ESC("\x1b[41;1m")
#define BK_MAGENTA COLOR_ESC("\x1b[45m")
#define BK_BROWN COLOR_ESC("\x1b[41m")
#define BK_LIGHTGRAY COLOR_ESC("\x1b[40;1m")
#define BK_DARKGRAY COLOR_ESC("\x1b[40m")
#define BK_LIGHTBLUE COLOR_ESC("\x1b[44;1m")
#define BK_LIGHTGREEN COLOR_ESC("\x1b[42,1m")
#define BK_LIGHTCYAN COLOR_ESC("\x1b[46;1m")
#define BK_LIGHTRED COLOR_ESC("\x1b[41;1m")
#define BK_LIGHTMAGENTA COLOR_ESC("\x1b[45;1m")
#define BK_YELLOW COLOR_ESC("\x1b[43;1m")
#define BK_WHITE COLOR_ESC("\x1b[47;1m")
#define BK_BLINK COLOR_ESC("\x1b[40m")

#define RESET COLOR_ESC(ESC "[0m")


int c_kbhit(void);
Expand Down
52 changes: 26 additions & 26 deletions src/flow_visit.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ struct flow_defer_scope
{

//things must called at end of scope
struct declarator* declarator; // declarator
struct defer_statement* defer_statement; // defer
struct declarator* declarator; // declarator
struct defer_statement* defer_statement; // defer

//statements for controling where jump like break, throw stop.

Expand Down Expand Up @@ -523,7 +523,7 @@ static struct object* expression_is_comparing_owner_with_not_null(struct express
expression_is_null_pointer_constant(p_expression->right) &&
type_is_pointer(&p_expression->left->type))
{
//NULL != p
//NULL != p
struct type type = { 0 };
struct object* p_object = expression_get_object(p_expression->right, &type);
type_destroy(&type);
Expand Down Expand Up @@ -1333,7 +1333,7 @@ static void flow_visit_expression(struct flow_visit_ctx* ctx, struct expression*
//TODO inside sizeof(v) is not an error. :D
//TODO function type...

if (!ctx->is_left_expression &&
if (!ctx->is_left_expression &&
!ctx->is_size_of_expression)
{
compiler_set_warning_with_token(W_UNINITIALZED,
Expand Down Expand Up @@ -1373,28 +1373,28 @@ static void flow_visit_expression(struct flow_visit_ctx* ctx, struct expression*
break;
case POSTFIX_DECREMENT:
break;
case POSTFIX_ARRAY:
case POSTFIX_ARRAY: {

flow_visit_expression(ctx, p_expression->left);
flow_visit_expression(ctx, p_expression->right);
flow_visit_expression(ctx, p_expression->left);
flow_visit_expression(ctx, p_expression->right);

struct type t = { 0 };
struct object* p_object = expression_get_object(p_expression->left, &t);
struct type t = { 0 };
struct object* p_object = expression_get_object(p_expression->left, &t);

if (p_object && p_object->state == OBJECT_STATE_UNINITIALIZED)
{
compiler_set_error_with_token(C_STATIC_ASSERT_FAILED,
ctx->ctx,
p_expression->left->first_token, "using a uninitialized object");
}
else if (p_object && p_object->state & OBJECT_STATE_UNINITIALIZED)
{
compiler_set_error_with_token(C_STATIC_ASSERT_FAILED,
ctx->ctx,
p_expression->left->first_token, "maybe using a uninitialized object");
if (p_object && p_object->state == OBJECT_STATE_UNINITIALIZED)
{
compiler_set_error_with_token(C_STATIC_ASSERT_FAILED,
ctx->ctx,
p_expression->left->first_token, "using a uninitialized object");
}
else if (p_object && p_object->state & OBJECT_STATE_UNINITIALIZED)
{
compiler_set_error_with_token(C_STATIC_ASSERT_FAILED,
ctx->ctx,
p_expression->left->first_token, "maybe using a uninitialized object");
}
type_destroy(&t);
}
type_destroy(&t);

break;

case POSTFIX_FUNCTION_CALL:
Expand Down Expand Up @@ -1483,7 +1483,7 @@ static void flow_visit_expression(struct flow_visit_ctx* ctx, struct expression*
break;

case UNARY_EXPRESSION_SIZEOF_EXPRESSION:

if (p_expression->right)
{
const bool t2 = ctx->is_size_of_expression;
Expand All @@ -1498,7 +1498,7 @@ static void flow_visit_expression(struct flow_visit_ctx* ctx, struct expression*
flow_visit_type_name(ctx, p_expression->type_name);
}


break;

case UNARY_EXPRESSION_SIZEOF_TYPE:
Expand Down Expand Up @@ -1757,7 +1757,7 @@ static void flow_visit_do_while_statement(struct flow_visit_ctx* ctx, struct ite
}
else
{
//do { } while (p);
//do { } while (p);

if (p_object_compared_with_not_null)
{
Expand Down Expand Up @@ -2185,7 +2185,7 @@ static void flow_visit_static_assert_declaration(struct flow_visit_ctx* ctx, str

if (strcmp(lexeme, "\"zero\"") == 0)
{
//gives the semantics of {0} or calloc
//gives the semantics of {0} or calloc
set_direct_state(&t, p_obj, OBJECT_STATE_ZERO);
}
else
Expand Down
4 changes: 4 additions & 0 deletions src/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ int copy_file(const char* pathfrom, const char* pathto)

int copy_folder(const char* from, const char* to)
{
#if !defined __EMSCRIPTEN__
int errcode = mkdir(to, 0700);
if (errcode != 0)
{
Expand Down Expand Up @@ -278,6 +279,9 @@ int copy_folder(const char* from, const char* to)

closedir(dir);
return errcode;
#else
return -1;
#endif
}

#ifdef _WIN32
Expand Down
Loading

0 comments on commit e5b289e

Please sign in to comment.