F diff --git a/src/frontend/lex/lex_preprocessing_directive.c b/src/frontend/lex/lex_preprocessing_directive.c --- a/src/frontend/lex/lex_preprocessing_directive.c +++ b/src/frontend/lex/lex_preprocessing_directive.cswitch(finishing_node->preprocessing_keyword){case PKW_IF:- return get_error_token("PREPROCESSING IF NOT DONE",token_location,lexer_data->previous_token_location,lexer_data->program);+ return preprocessing_lex_if_directive(lexer_data,token_location);case PKW_IFDEF:return get_error_token("PREPROCESSING IFDEF NOT DONE",token_location,lexer_data->previous_token_location,lexer_data->program);case PKW_IFNDEF:return get_error_token("PREPROCESSING IFNDEF NOT DONE",token_location,lexer_data->previous_token_location,lexer_data->program);case PKW_ELIF:- return get_error_token("PREPROCESSING ELIF NOT DONE",token_location,lexer_data->previous_token_location,lexer_data->program);+ return preprocessing_lex_if_directive(lexer_data,token_location);case PKW_ELSE:- return get_error_token("PREPROCESSING ELSE NOT DONE",token_location,lexer_data->previous_token_location,lexer_data->program);+ return preprocessing_return_else_token(lexer_data,token_location);case PKW_ENDIF:- return get_error_token("PREPROCESSING ENDIF NOT DONE",token_location,lexer_data->previous_token_location,lexer_data->program);+ return preprocessing_return_endif_token(lexer_data,token_location);case PKW_INCLUDE:return preprocessing_lex_include_directive(lexer_data,token_location);case PKW_DEFINE:return (struct token*)ret;}+ struct token* preprocessing_lex_if_directive(struct Lexer_Data *lexer_data,struct Source_Location *where)+ {+ struct token_if_directive *ret;+ struct token *hold_token;++ ret=wonky_malloc(sizeof(struct token_if_directive));+ ret->type=PKW_IF;+ ret->delta=get_source_location_delta(lexer_data->previous_token_location,where);++ ret->controlling_expression=wonky_malloc(sizeof(struct Queue));+ ret->if_true=wonky_malloc(sizeof(struct Queue));+ ret->if_false=wonky_malloc(sizeof(struct Queue));++ Queue_Init(ret->controlling_expression);+ Queue_Init(ret->if_true);+ Queue_Init(ret->if_false);++ while(!preprocessing_eol(lexer_data))+ Queue_Push(ret->controlling_expression,preprocessing_extract_next_token(lexer_data));++ while((hold_token=lexer_extract_next_token(lexer_data))!=NULL)+ {+ if(hold_token->type==PKW_ELSE)+ {+ while((hold_token=lexer_extract_next_token(lexer_data))!=NULL)+ {+ if(hold_token->type==PKW_ENDIF)+ break;+ else+ Queue_Push(ret->if_false,hold_token);+ }+ if(hold_token==NULL)+ push_lexing_error("Reached end of file before reaching a #endif",lexer_data);++ delete_token(hold_token);+ break;+ }else if(hold_token->type==PKW_ELIF)+ {+ Queue_Push(ret->if_false,hold_token);+ break;+ }else if(hold_token->type==PKW_ENDIF)+ {+ break;+ }else+ {+ Queue_Push(ret->if_true,hold_token);+ }+ }+ return ret;+ }struct token* preprocessing_lex_define_directive(struct Lexer_Data *lexer_data,struct Source_Location *where){struct token *hold_token;}}}+ /*these two are quite the pair of hacks*/+ struct token* preprocessing_return_else_token(struct Lexer_Data *lexer_data,struct Source_Location *where)+ {+ static struct token error={.type=PKW_ELSE};+ error.delta=get_source_location_delta(lexer_data->previous_token_location,where);+ return (struct token*)&error;+ }+ struct token* preprocessing_return_endif_token(struct Lexer_Data *lexer_data,struct Source_Location *where)+ {+ static struct token endif={.type=PKW_ENDIF};+ endif.delta=get_source_location_delta(lexer_data->previous_token_location,where);+ return (struct token*)&endif;+ }#endifF diff --git a/src/frontend/lex/lex_preprocessing_directive.h b/src/frontend/lex/lex_preprocessing_directive.h --- a/src/frontend/lex/lex_preprocessing_directive.h +++ b/src/frontend/lex/lex_preprocessing_directive.hstruct token* preprocessing_lex_pragma_directive(struct Lexer_Data *lexer_data,struct Source_Location *where);struct token* preprocessing_lex_defined_unary_operator(struct Lexer_Data *lexer_data,struct Source_Location *where);+ struct token* preprocessing_return_else_token(struct Lexer_Data *lexer_data,struct Source_Location *where);+ struct token* preprocessing_return_endif_token(struct Lexer_Data *lexer_data,struct Source_Location *where);+void preprocessing_push_tokens_into_queue_until_eol(struct Lexer_Data *lexer_data,struct Queue *queue);void preprocessing_push_functionlike_macro_substitution_tokens(struct Lexer_Data *lexer_data,struct Source_Location *where,struct functionlike_define_directive *directive);F diff --git a/src/semantics/program/program.c b/src/semantics/program/program.c --- a/src/semantics/program/program.c +++ b/src/semantics/program/program.creturn ret;}+ struct Translation_Data* get_dummy_translation_data_for_parsing_const_expressions(struct Token_Pointer *ptr)+ {+ struct Translation_Data *ret;+ ret=wonky_malloc(sizeof(struct Translation_Data));++ ret->token_pointer=ptr;+ ret->internal_linkage=get_linkage();+ ret->program=ptr->program;++ return ret;+ }struct Program* parse_program(char **base_source_names){struct Source_File *base_file;F diff --git a/src/semantics/program/program.h b/src/semantics/program/program.h --- a/src/semantics/program/program.h +++ b/src/semantics/program/program.hstruct Program* get_program();struct Translation_Data* get_translation_data(struct Preprocessing_Translation_Unit *start_unit,struct Linkage *internal_linkage,struct Program *program);+ struct Translation_Data* get_dummy_translation_data_for_parsing_const_expressions(struct Token_Pointer *ptr);struct Program* parse_program(char **base_source_names);struct Preprocessing_Translation_Unit* program_get_translation_unit(struct Program *program,char *filename,size_t filename_size);F diff --git a/src/semantics/program/translation_unit.c b/src/semantics/program/translation_unit.c --- a/src/semantics/program/translation_unit.c +++ b/src/semantics/program/translation_unit.c}void token_ptr_execute_if_directive(struct Token_Pointer *ptr,struct token_if_directive *if_directive){+ struct AST *control;+ struct Translation_Data *dummy_data;+ struct Scope *dummy_scope;++ #warning not done yet+token_ptr_goto_next_token(ptr);+ token_ptr_jump_to_first(ptr,if_directive->controlling_expression);+++ dummy_data=get_dummy_translation_data_for_parsing_const_expressions(ptr);+ dummy_scope=get_normal_scope(NULL,BLOCK_SCOPE);++ ptr->state=TOKEN_POINTER_STATE_PREPROCESSING;+ control=parse_expression(dummy_data,dummy_scope);+ ptr->state=TOKEN_POINTER_STATE_NORMAL;++ if(evaluate_const_expression_integer(control,dummy_data)!=0)+ {+ token_ptr_jump_to_first(ptr,if_directive->if_true);+ }else+ {+ if(if_directive->if_false!=NULL)+ token_ptr_jump_to_first(ptr,if_directive->if_false);+ }+++ /*As of writing these don't do anything*/+ delete_ast(control);+ delete_translation_data(dummy_data);+ delete_scope(dummy_scope);}void token_ptr_execute_ifdef_directive(struct Token_Pointer *ptr,struct token_ifdef_directive *ifdef_directive){}void token_ptr_load_functionlike_macro_arguments_with_tokens(struct Token_Pointer *ptr,struct functionlike_define_directive *macro){- #warning this is not done!-int open_bracket_count=1;size_t number_of_tokens_in_argument;F diff --git a/src/semantics/value/evaluation.c b/src/semantics/value/evaluation.c --- a/src/semantics/value/evaluation.c +++ b/src/semantics/value/evaluation.cRET_BIN_EXPR(expression,==);case OP_NOT_EQUAL:RET_BIN_EXPR(expression,!=);+ case OP_CONSTANT:+ {+ struct Constant *c;+ c=((struct AST_Constant*)expression)->value->constant;+ /*TODO add other types*/+ if(type_is_integer_type(c->type))+ return *(long long int*)c->value;+++ }}/*shouldnt reach here*/return 0;F diff --git a/src/syntax/token/token.h b/src/syntax/token/token.h --- a/src/syntax/token/token.h +++ b/src/syntax/token/token.henum LEXER_TYPE type;struct Source_Location_Delta *delta;struct Queue *controlling_expression;- struct Queue_Node *if_true;- struct Queue_Node *if_false;- struct Queue_Node *end_of_if_directive;+ struct Queue *if_true;+ struct Queue *if_false;};struct token_ifdef_directive{