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.c
struct token* preprocessing_lex_defined_unary_operator(struct Lexer_Data *lexer_data,struct Source_Location *where)
{
- return get_error_token("PREPROCESSING DIRECTIVES NOT DONE",where,lexer_data->previous_token_location,lexer_data->program);
+ struct token_defined_unary_operator *ret;
+ struct token *hold_token;
+
+ ret=wonky_malloc(sizeof(struct token_defined_unary_operator));
+ ret->type=PKW_DEFINED;
+ ret->delta=get_source_location_delta(lexer_data->previous_token_location,where);
+
+ hold_token=preprocessing_extract_next_token(lexer_data);
+
+ if(hold_token==NULL)
+ {
+ push_lexing_error("Expected id in defined unary operator",lexer_data);
+ }else
+ {
+ if(token_is_identifier_in_preprocessing(hold_token))
+ {
+ ret->id=hold_token;
+ }else if(hold_token->type==KW_OPEN_NORMAL)
+ {
+ hold_token=preprocessing_extract_next_token(lexer_data);
+ if(token_is_identifier_in_preprocessing(hold_token))
+ {
+ ret->id=hold_token;
+ hold_token=preprocessing_extract_next_token(lexer_data);
+ if(hold_token->type!=KW_CLOSE_NORMAL)
+ push_lexing_error("Expected ')' in defined unary operator after id",lexer_data);
+ }else
+ {
+ push_lexing_error("Expected id in defined unary operator after '('",lexer_data);
+ }
+ }else
+ {
+ push_lexing_error("Expected id in defined unary operator",lexer_data);
+ }
+ }
+ return (struct token*)ret;
}
struct token* preprocessing_extract_next_directive(struct Lexer_Data *lexer_data)
{
case PKW_PRAGMA:
return get_error_token("PREPROCESSING PRAGMA NOT DONE",token_location,lexer_data->previous_token_location,lexer_data->program);
case PKW_DEFINED:
- return get_error_token("PREPROCESSING DEFINED NOT DONE",token_location,lexer_data->previous_token_location,lexer_data->program);
+ return preprocessing_lex_defined_unary_operator(lexer_data,token_location);
default:
return lexer_make_token_finishing_on_node(lexer_data,finishing_node,start_position);
}
return (struct token*)ret;
}
+ struct token* preprocessing_lex_pragma_directive(struct Lexer_Data *lexer_data,struct Source_Location *where)
+ {
+ struct token_pragma_directive *ret;
+ ret->type=PKW_PRAGMA;
+ ret->delta=get_source_location_delta(lexer_data->previous_token_location,where);
+ ret->pragma_type=PRAGMA_TYPE_END;
+ preprocessing_goto_end_of_line(lexer_data);
+ return (struct token*)ret;
+ }
void preprocessing_goto_end_of_line(struct Lexer_Data *lexer_data)
{
enum {
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
ret->context=get_token_ptr_context(unit->tokens->first,unit->tokens->size);
ret->call_stack=wonky_malloc(sizeof(struct Stack));
ret->state=TOKEN_POINTER_STATE_NORMAL;
+ ret->is_in_conditional_directive=0;
Stack_Init(ret->call_stack);
dummy_scope=get_normal_scope(NULL,BLOCK_SCOPE);
ptr->state=TOKEN_POINTER_STATE_PREPROCESSING;
+ ptr->is_in_conditional_directive=1;
control=parse_expression(dummy_data,dummy_scope);
ptr->state=TOKEN_POINTER_STATE_NORMAL;
+ ptr->is_in_conditional_directive=0;
if(evaluate_const_expression_integer(control,dummy_data)!=0)
{
}
void token_ptr_execute_defined_unary_operator(struct Token_Pointer *ptr,struct token_defined_unary_operator *operator)
{
+ struct token_constant *line;
token_ptr_goto_next_token(ptr);
+
+ if(token_is_a_macro(operator->id,ptr->macro_expansion_number,ptr->program->current_translation_unit_number))
+ {
+ line=(struct token_constant*)get_constant_token(
+ KW_DECIMAL_CONSTANT,
+ operator->delta->location,
+ operator->delta->location,
+ "1",
+ 1);
+ }else
+ {
+ line=(struct token_constant*)get_constant_token(
+ KW_DECIMAL_CONSTANT,
+ operator->delta->location,
+ operator->delta->location,
+ "0",
+ 1);
+ }
+ Queue_Push(ptr->context->ungeted_tokens,line);
}
void token_ptr_execute_file_special_macro(struct Token_Pointer *ptr,struct token *directive)
{
case PKW_STDC_VERSION_MACRO:
token_ptr_execute_stdc_version_special_macro(token_pointer,token);
return 1;/*NOTICE*/
+ case PKW_DEFINED:
+ if(token_pointer->is_in_conditional_directive)
+ {
+ token_ptr_execute_defined_unary_operator(token_pointer,(struct token_defined_unary_operator*)token);
+ }
+ return 0;
case LT_EOF:
if(token_pointer->call_stack->size>0)
{
F diff --git a/src/semantics/program/translation_unit.h b/src/semantics/program/translation_unit.h
--- a/src/semantics/program/translation_unit.h
+++ b/src/semantics/program/translation_unit.h
struct Program *program;
enum Token_Pointer_State state;
+ _Bool is_in_conditional_directive;/*TODO move this into the state*/
size_t macro_expansion_number;
};
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.h
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
- struct identifier *id;
+ struct token *id;
};
struct token_hashtag_unary_operator
{