Skip to content

Commit

Permalink
fixes / refactoring / sarif dir
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Jul 31, 2024
1 parent f0c9305 commit 8ae15c8
Show file tree
Hide file tree
Showing 19 changed files with 87,171 additions and 86,324 deletions.
2 changes: 1 addition & 1 deletion src/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ int main()
" /out:cake.exe");

//Runs cake on its own source
execute_cmd("cake.exe -ownership=enable -Wstyle -fanalyzer -Wno-unused-parameter -Wno-unused-variable " CAKE_HEADER_FILES CAKE_SOURCE_FILES);
execute_cmd("cake.exe -sarif -sarif-path \"../vc/.sarif\" -ownership=enable -Wstyle -fanalyzer -Wno-unused-parameter -Wno-unused-variable " CAKE_HEADER_FILES CAKE_SOURCE_FILES);


#endif
Expand Down
57 changes: 48 additions & 9 deletions src/expressions.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ bool is_enumeration_constant(const struct parser_ctx* ctx)

bool is_first_of_floating_constant(const struct parser_ctx* ctx)
{
if (ctx->current == NULL)
return false;

/*
floating-constant:
decimal-floating-constant
Expand All @@ -628,6 +631,9 @@ bool is_first_of_integer_constant(const struct parser_ctx* ctx)
binary-constant integer-suffixop
*/

if (ctx->current == NULL)
return false;

return ctx->current->type == TK_COMPILER_DECIMAL_CONSTANT ||
ctx->current->type == TK_COMPILER_OCTAL_CONSTANT ||
ctx->current->type == TK_COMPILER_HEXADECIMAL_CONSTANT ||
Expand All @@ -636,6 +642,9 @@ bool is_first_of_integer_constant(const struct parser_ctx* ctx)

bool is_predefined_constant(const struct parser_ctx* ctx)
{
if (ctx->current == NULL)
return false;

return ctx->current->type == TK_KEYWORD_TRUE ||
ctx->current->type == TK_KEYWORD_FALSE ||
ctx->current->type == TK_KEYWORD_NULLPTR;
Expand All @@ -651,6 +660,9 @@ bool is_first_of_constant(const struct parser_ctx* ctx)
character-constant
predefined-constant
*/
if (ctx->current == NULL)
return false;

return is_first_of_integer_constant(ctx) ||
is_first_of_floating_constant(ctx) ||
is_enumeration_constant(ctx) ||
Expand Down Expand Up @@ -757,6 +769,9 @@ struct generic_assoc_list generic_association_list(struct parser_ctx* ctx)

generic_assoc_list_add(&list, p_generic_association);

if (ctx->current == NULL)
throw;

while (ctx->current->type == ',')
{
parser_match(ctx);
Expand All @@ -767,6 +782,8 @@ struct generic_assoc_list generic_association_list(struct parser_ctx* ctx)
throw;

generic_assoc_list_add(&list, p_generic_association2);
if (ctx->current == NULL)
throw;
}
}
catch
Expand Down Expand Up @@ -1717,6 +1734,8 @@ struct argument_expression_list argument_expression_list(struct parser_ctx* ctx)
p_argument_expression->expression = p_assignment_expression;
argument_expression_list_push(&list, p_argument_expression);

if (ctx->current == NULL)
throw;

while (ctx->current->type == ',')
{
Expand Down Expand Up @@ -1748,7 +1767,7 @@ struct argument_expression_list argument_expression_list(struct parser_ctx* ctx)
return list;
}

bool first_of_postfix_expression(struct parser_ctx* ctx)
bool first_of_postfix_expression(const struct parser_ctx* ctx)
{
//( type-name ) postfix confunde com (expression) primary
if (first_of_type_name_ahead(ctx))
Expand Down Expand Up @@ -2366,7 +2385,7 @@ struct expression* _Owner _Opt postfix_expression(struct parser_ctx* ctx)
if (p_expression_node == NULL)
throw;


assert(ctx->current != NULL);
p_expression_node->first_token = ctx->current;
if (parser_match_tk(ctx, '(') != 0)
Expand Down Expand Up @@ -2397,6 +2416,9 @@ struct expression* _Owner _Opt postfix_expression(struct parser_ctx* ctx)
{
p_expression_node->expression_type = POSTFIX_EXPRESSION_COMPOUND_LITERAL;
p_expression_node->braced_initializer = braced_initializer(ctx);
if (p_expression_node->braced_initializer == NULL) throw;
if (ctx->current == NULL) throw;

p_expression_node->last_token = ctx->current;
}
}
Expand Down Expand Up @@ -2539,6 +2561,9 @@ struct expression* _Owner _Opt unary_expression(struct parser_ctx* ctx)
struct expression* _Owner _Opt p_expression_node = NULL;
try
{
if (ctx->current == NULL)
throw;

if (ctx->current->type == '++' || ctx->current->type == '--')
{
struct expression* _Owner _Opt new_expression = calloc(1, sizeof * new_expression);
Expand Down Expand Up @@ -3207,7 +3232,7 @@ struct expression* _Owner _Opt multiplicative_expression(struct parser_ctx* ctx)
p_expression_node = NULL;
throw;
}

new_expression->first_token = ctx->current;
enum token_type op = ctx->current->type;
parser_match(ctx);
Expand Down Expand Up @@ -3559,7 +3584,7 @@ struct expression* _Owner _Opt shift_expression(struct parser_ctx* ctx)
if (new_expression == NULL) throw;

new_expression->first_token = ctx->current;


enum token_type op = ctx->current->type;
parser_match(ctx);
Expand Down Expand Up @@ -3717,6 +3742,9 @@ void check_diferent_enuns(struct parser_ctx* ctx,
if (left->type.type_specifier_flags & TYPE_SPECIFIER_ENUM &&
right->type.type_specifier_flags & TYPE_SPECIFIER_ENUM)
{
assert(left->type.enum_specifier);
assert(right->type.enum_specifier);

if (get_complete_enum_specifier(left->type.enum_specifier) !=
get_complete_enum_specifier(right->type.enum_specifier))
{
Expand Down Expand Up @@ -3795,7 +3823,7 @@ struct expression* _Owner _Opt equality_expression(struct parser_ctx* ctx)
throw;

new_expression->first_token = ctx->current;

struct token* operator_token = ctx->current;
parser_match(ctx);
if (ctx->current == NULL) throw;
Expand Down Expand Up @@ -3986,8 +4014,8 @@ struct expression* _Owner _Opt inclusive_or_expression(struct parser_ctx* ctx)
{
/*
inclusive-OR-expression:
exclusive-OR-expression
inclusive-OR-expression | exclusive-OR-expression
exclusive-OR-expression
inclusive-OR-expression | exclusive-OR-expression
*/
struct expression* _Owner _Opt p_expression_node = NULL;
try
Expand All @@ -4007,7 +4035,7 @@ struct expression* _Owner _Opt inclusive_or_expression(struct parser_ctx* ctx)
if (new_expression == NULL)
throw;


new_expression->first_token = ctx->current;
new_expression->expression_type = INCLUSIVE_OR_EXPRESSION;
new_expression->left = p_expression_node;
Expand Down Expand Up @@ -4403,10 +4431,16 @@ struct expression* _Owner _Opt expression(struct parser_ctx* ctx)
struct expression* _Owner _Opt p_expression_node = NULL;
try
{
if (ctx->current == NULL)
throw;

p_expression_node = assignment_expression(ctx);
if (p_expression_node == NULL)
throw;

if (ctx->current == NULL)
throw;

if (ctx->current->type == ',')
{
while (ctx->current->type == ',')
Expand All @@ -4418,7 +4452,6 @@ struct expression* _Owner _Opt expression(struct parser_ctx* ctx)
if (p_expression_node_new == NULL)
throw;


p_expression_node_new->first_token = ctx->current;
p_expression_node_new->expression_type = ASSIGNMENT_EXPRESSION;
p_expression_node_new->left = p_expression_node;
Expand All @@ -4433,6 +4466,12 @@ struct expression* _Owner _Opt expression(struct parser_ctx* ctx)
p_expression_node_new->left->last_token = p_expression_node_new->right->last_token;

p_expression_node = p_expression_node_new;

if (ctx->current == NULL)
{
//unexpected end of file
throw;
}
}

if (p_expression_node->right == NULL)
Expand Down
9 changes: 7 additions & 2 deletions src/file.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#pragma safety enable

#pragma safety enable

void printf(char * sa, int i);
int main(void)
{
int iiiiiiii;
printf("%d", iiiiiiii);
}
2 changes: 1 addition & 1 deletion src/flow_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ void flow_object_add_new_state_as_a_copy_of_current_state(struct flow_object* ob
object->current.next = pnew;

flow_object_state_copy(pnew, &object->current);

//TODO fix pnew is changed..
}

void object_remove_state(struct flow_object* object, int state_number)
Expand Down
Loading

0 comments on commit 8ae15c8

Please sign in to comment.