WONKY



LOG | FILES | OVERVIEW


F diff --git a/src/backend/asm/intel/intel_asm.c b/src/backend/asm/intel/intel_asm.c --- a/src/backend/asm/intel/intel_asm.c +++ b/src/backend/asm/intel/intel_asm.c
wonky_assert(string->type->specifier==TS_ARRAY && string->value!=NULL);
string_type=(struct Type_Array*)string->type;
- db=get_intel_asm_define_bytes(string->value,string_type->size);
+ if(string_type->size)
+ db=get_intel_asm_define_bytes(string->value,string_type->size);
db2=get_intel_asm_define_bytes("\0",1);
label=get_intel_asm_new_unique_label(compile_data);
Queue_Push(compile_data->data_block,label);
- Queue_Push(compile_data->data_block,db);
+ if(string_type->size)
+ Queue_Push(compile_data->data_block,db);
Queue_Push(compile_data->data_block,db2);
return get_intel_asm_label_location((struct Intel_Asm_Label*)label);
F diff --git a/src/misc/print.c b/src/misc/print.c --- a/src/misc/print.c +++ b/src/misc/print.c
wonky_fprintf(out,"[TOKEN %WSl: ",token->delta->location);
print_token_text(out,token);
+ wonky_fprintf(out," | kw=");
+ print_keyword_enum(out,token->type);
wonky_fprintf(out,"]\n");
}
void print_error_tree(struct wonky_stream *out,struct AST_Error *error,short indentation)
{
- wonky_fprintf(out,"ERROR-(%WA)",error);
+ wonky_fprintf(out,"ERROR-(%WA)",error->error);
}
void print_designator_expression_tree(struct wonky_stream *out,struct AST_Designator *designator,short indentation)
{
wonky_fprintf(out,")");
}else
{
- wonky_fprintf(out,"%WAE%WA");
+ wonky_fprintf(out,"%WAE%WA",unary_expression->type,unary_expression->operand);
}
}
void print_labeled_statement_tree(struct wonky_stream *out,struct AST_Labeled_Statement *lab,short indentation)
print_enumeration(out,((struct Type_Enum*)type)->enumeration);
return;
case TS_POINTER:
- wonky_fprintf(out," pointer to");
+ wonky_fprintf(out," pointer to ");
print_type(out,((struct Type_Pointer*)type)->points_to,0);
return;
case TS_ARRAY:
case OP_GREATER_EQ:
case OP_GREATER:
case OP_NOT_EQUAL:
+ print_indentation(out,indentation);
print_binary_expression_tree(out,(struct AST_Binary_Expression*)tree);
break;
case OP_COND:
+ print_indentation(out,indentation);
print_conditional_expression_tree(out,(struct AST_Conditional_Expression*)tree);
break;
case OP_FUNCTION:
+ print_indentation(out,indentation);
print_function_expression_tree(out,(struct AST_Function_Expression*)tree);
break;
case OP_LOGICAL_NOT:
case OP_PREFIX_DEC:
case OP_CAST:
case OP_BITWISE_NOT:
+ print_indentation(out,indentation);
print_unary_expression_tree(out,(struct AST_Unary_Expression*)tree);
break;
case OP_STRING_LITERAL:
+ print_indentation(out,indentation);
print_string_literal(out,(struct AST_String_Literal*)tree);
break;
case OP_CONSTANT:
+ print_indentation(out,indentation);
print_constant_tree(out,(struct AST_Constant*)tree);
break;
case OP_NOP:
print_labeled_statement_tree(out,(struct AST_Labeled_Statement*)tree,indentation);
break;
case ST_CONTINUE:
+ print_indentation(out,indentation);
wonky_fprintf(out,"continue");
break;
case ST_BREAK:
+ print_indentation(out,indentation);
wonky_fprintf(out,"break");
break;
case ST_RETURN:
print_denoted(out,(struct Denoted*)((struct AST_Object_Declaration*)tree)->object);
break;
case ST_TYPE_DEFINITION:
+ print_indentation(out,indentation);
print_denoted(out,(struct Denoted*)((struct AST_Type_Definition*)tree)->definition);
break;
case ST_FUNCTION_DECLARATION:
+ print_indentation(out,indentation);
print_denoted(out,(struct Denoted*)((struct AST_Function_Declaration*)tree)->function);
break;
case ST_FUNCTION_DEFINITION:
case KW_DECIMAL_CONSTANT:
wonky_fprintf(out,"KW_DECIMAL_CONSTANT");
break;
+ case KW_CONSTANT:
+ wonky_fprintf(out,"KW_CONSTANT");
+ break;
case KW_OCTAL_CONSTANT:
wonky_fprintf(out,"KW_OCTAL_CONSTANT");
break;
}
void print_string_literal(struct wonky_stream *out,struct AST_String_Literal *string)
{
- wonky_fprintf(out,"%WC",string->value->constant);
+ wonky_fprintf(out,"\"%WC\"",string->value->constant);
}
void print_expression_value(struct wonky_stream *out,struct Expression_Value *value)
void print_id(struct wonky_stream *out,struct identifier *id)
{
- wonky_fprintf(out,"%s",id->data);
+ wonky_fprintf(out,"'%s'",id->data);
}
#undef TOK
#undef INDENT
break;
case KW_STRING:
case KW_WIDE_STRING:
- wonky_fprintf(out,"%s",((struct token_string*)token)->constant->value);
+ wonky_fprintf(out,"\"%s\"",((struct token_string*)token)->constant->value);
break;
case PKW_MACRO_ARGUMENT:
wonky_fprintf(out,"MACRO ARGUMENT -_(:/)_-");
F diff --git a/src/misc/wonky_string.c b/src/misc/wonky_string.c --- a/src/misc/wonky_string.c +++ b/src/misc/wonky_string.c
}
return ret;
}
+ void wonky_string_delete(struct wonky_str *str)
+ {
+ //NOP at the moment
+ }
struct wonky_str wonky_string_copy(const struct wonky_str str)
{
struct wonky_str ret=(struct wonky_str){.cs=wonky_arr_copy(str.cs),.number_of_glyphs=str.number_of_glyphs};
F diff --git a/src/misc/wonky_string.h b/src/misc/wonky_string.h --- a/src/misc/wonky_string.h +++ b/src/misc/wonky_string.h
size_t where;
};
struct wonky_str wonky_string_make();
+ void wonky_string_delete(struct wonky_str *str);
struct wonky_str wonky_string_copy(const struct wonky_str str);
struct wonky_str wonky_string_from_cstr(const char *str);
size_t wonky_string_number_of_bytes(const struct wonky_str str);
F diff --git a/src/semantics/ast.c b/src/semantics/ast.c --- a/src/semantics/ast.c +++ b/src/semantics/ast.c
}
/*if an int can represent all the values of the original type the value is converted to int
* otherwise to unsigned int. other types are untouched
- * 6.3.1.1 */
+ * 6.3.1.1
+ * !!function designators and arrays are converted to pointers here
+ * */
struct AST_Expression* get_promoted_expression(struct AST_Expression *operand,struct Translation_Data *translation_data)
{
struct Type *operand_type;
struct Type *promotion_type;
operand_type=extract_expresion_value_type(operand->value);
- promotion_type=get_type_for_promotion(operand_type);
- if(!types_are_identical(operand_type,promotion_type))
- return get_cast_expression_tree(operand,promotion_type,translation_data);
- else
- return operand;
+
+ if(operand_type->specifier==TS_ARRAY)
+ {
+ return get_cast_expression_tree(operand,get_pointer_type(((struct Type_Array*)operand_type)->is_array_of,1,0),translation_data);
+ }else
+ {
+ promotion_type=get_type_for_promotion(operand_type);
+ if(!types_are_identical(operand_type,promotion_type))
+ return get_cast_expression_tree(operand,promotion_type,translation_data);
+ else
+ return operand;
+ }
}
struct AST_Expression* get_promoted_expression_for_function_call(struct AST_Expression *operand,struct Translation_Data *translation_data)
F diff --git a/src/semantics/identifiers/denoted.c b/src/semantics/identifiers/denoted.c --- a/src/semantics/identifiers/denoted.c +++ b/src/semantics/identifiers/denoted.c
ret=wonky_malloc(sizeof(struct Denoted_Base));
ret->denotation=prototype->denotation;
ret->id=NULL;
- ret->type=get_type_error(prototype->type);
+ #warning I have *NO* idea why this line was made...
+ //ret->type=get_type_error(prototype->type);
+
+ ret->type=prototype->type;
wonky_assert(is_valid_denoted_base(ret));
return ret;
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.c
}
void chomp(struct Translation_Data *translation_data)
{
- (void)get_next_token(translation_data);
+ struct token *hold_token;
+ hold_token=get_next_token(translation_data);
+ //token_ptr_assume_location_of_token(translation_data->token_pointer,hold_token);
}
enum LEXER_TYPE kw_get(struct Translation_Data *translation_data)
}
struct token* get_next_token(struct Translation_Data *translation_data)
{
- return token_ptr_get_token_under_pointer(translation_data->token_pointer);
+ struct token *hold_token;
+ hold_token=token_ptr_get_token_under_pointer(translation_data->token_pointer);
+ token_ptr_assume_location_of_token(translation_data->token_pointer,hold_token);
+ return hold_token;
}
_Bool translation_eof(struct Translation_Data *translation_data)
{
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
{
Queue_Push(unit->tokens,token);
}
- struct token* token_ptr_get_token_under_pointer_in_preprocessing_directive(struct Token_Pointer *token_pointer)
- {
-
- }
struct token* token_ptr_get_token_under_pointer(struct Token_Pointer *token_pointer)
{
struct token *hold_token;
token_ptr_goto_next_token(token_pointer);
- wonky_printf("YYY token_ptr_get_token_under_pointer_inner\n");
- token_ptr_assume_location_of_token(token_pointer,hold_token);
+ //token_ptr_assume_location_of_token(token_pointer,hold_token);
return hold_token;
}
hold_token=(struct token*)token_pointer->context->current_token_node->data;
wonky_assert(hold_token!=NULL);
- if(assume_location)
- {
- wonky_printf("YYY token_ptr_goto_next_normal_token\n");
- token_ptr_assume_location_of_token(token_pointer,hold_token);
- }
+ //token_ptr_assume_location_of_token(token_pointer,hold_token);
if(!token_ptr_do_preprocessing_stuff(token_pointer,hold_token))
return;
if(!token_ptr_has_remaining_tokens(token_pointer))
return get_eof_token();
else
+ {
return (struct token*)token_pointer->context->current_token_node->data;
+ }
}
void token_ptr_goto_next_token(struct Token_Pointer *token_pointer)
{
struct Token_Pointer *ret;
ret=wonky_malloc(sizeof(struct Token_Pointer));
- ret->context=get_token_ptr_context(unit->tokens->first,unit->tokens->size,1);
+ ret->context=get_token_ptr_context(unit->tokens->first,unit->tokens->size,1,0,0);
ret->call_stack=wonky_malloc(sizeof(struct Stack));
ret->state=TOKEN_POINTER_STATE_NORMAL;
ret->is_in_conditional_directive=0;
{
struct token_string *hold_string_token;
struct token *hold_token;
+ struct wonky_str hold_text;
+ struct wonky_stream text_stream;
size_t i;
Queue_Node *it;
token_ptr_goto_next_token(ptr);
+ hold_text=wonky_string_make();
+ text_stream=wonky_string_stream(&hold_text);
+
- /*This wastes a LOT OF MEMORY. TODO make a temp token allocation scheme*/
+ /*This wastes a LOT OF MEMORY. and is slow as heck :/ surely you won't be stringifying a lot of things...*/
- hold_string_token=(struct token_string*)get_string_token(KW_STRING,op->delta->location,op->delta->location,"",0);
for(it=op->operand->argument->first_in_argument_substitution_tokens,i=0;i<op->operand->argument->number_of_substitution_tokens && it!=NULL;++i,it=it->prev)
{
hold_token=(struct token*)it->data;
wonky_assert(is_valid_token(hold_token));
+
+
+ wonky_fprintf(&text_stream,"%Wtr%s",hold_token,(i<op->operand->argument->number_of_substitution_tokens?" ":""));
+ /*
hold_str=get_string_from_token(hold_token,&hold_str_size);
hold_string_token=(struct token_string*)
get_token_from_two_strings_with_a_space_between(
hold_string_token,
(struct token_string*)get_string_token(KW_STRING,hold_token->delta->location,hold_token->delta->location,hold_str,hold_str_size)
);
+ */
}
+
+ hold_string_token=(struct token_string*)get_string_token(KW_STRING,op->delta->location,op->delta->location,hold_text.cs,wonky_string_number_of_bytes(hold_text));
Queue_Push(ptr->context->ungeted_tokens,hold_string_token);
+
+ wonky_string_stream_delete(&text_stream);
+ wonky_string_delete(&hold_text);
}
struct token* token_ptr_execute_concat_two_tokens(struct token *left,struct token *right,struct Program *program)
{
case PKW_IF:
case PKW_ELIF:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_if_directive(token_pointer,(struct token_if_directive*)token);
return 1;
case PKW_IFDEF:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_ifdef_directive(token_pointer,(struct token_ifdefndef_directive*)token);
return 1;
case PKW_IFNDEF:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_ifndef_directive(token_pointer,(struct token_ifdefndef_directive*)token);
return 1;
case PKW_ELSE:
+ token_ptr_assume_location_of_token(token_pointer,token);
wonky_assert(SHOULD_NOT_REACH_HERE);
return 1;
case PKW_ENDIF:
+ token_ptr_assume_location_of_token(token_pointer,token);
wonky_assert(SHOULD_NOT_REACH_HERE);
return 1;
case PKW_INCLUDE:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_include_directive(token_pointer,(struct token_include_directive*)token);
return 1;
case PKW_DEFINE:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_normal_define_directive(token_pointer,(struct token_normal_define_directive*)token);
return 1;
case PKW_FUNCTIONLIKE_DEFINE:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_functionlike_define_directive(token_pointer,(struct token_functionlike_define_directive*)token);
return 1;
case PKW_UNDEF:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_undef_directive(token_pointer,(struct token_undef_directive*)token);
return 1;
case PKW_LINE:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_line_directive(token_pointer,(struct token_line_directive*)token);
return 1;
case PKW_ERROR:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_error_directive(token_pointer,(struct token_error_directive*)token);
return 1;
case PKW_PRAGMA:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_pragma_directive(token_pointer,(struct token_pragma_directive*)token);
return 1;
case PKW_FILE_MACRO:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_file_special_macro(token_pointer,token);
return 1;/*NOTICE*/
case PKW_LINE_MACRO:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_line_special_macro(token_pointer,token);
return 1;/*NOTICE*/
case PKW_STDC_MACRO:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_stdc_special_macro(token_pointer,token);
return 1;/*NOTICE*/
case PKW_STDC_HOSTED_MACRO:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_stdc_hosted_special_macro(token_pointer,token);
return 1;/*NOTICE*/
case PKW_STDC_VERSION_MACRO:
+ token_ptr_assume_location_of_token(token_pointer,token);
token_ptr_execute_stdc_version_special_macro(token_pointer,token);
return 1;/*NOTICE*/
case PKW_DEFINED:
break;
case LT_ERROR:
/*erronous token*/
+ token_ptr_assume_location_of_token(token_pointer,token);
push_message_struct(token_pointer->program,((struct token_error*)token)->error);
token_ptr_goto_next_token(token_pointer);
return 1;
{
wonky_free(ptr);
}
- struct Token_Pointer_Context* get_token_ptr_context(struct Queue_Node *start,size_t number_of_remaining_tokens,_Bool is_file_inclusion)
+ struct Token_Pointer_Context* get_token_ptr_context(struct Queue_Node *start,size_t number_of_remaining_tokens,_Bool is_file_inclusion,size_t line,size_t column)
{
struct Token_Pointer_Context *ret;
struct Source_Location *hold_location;
//ret->line=hold_location->line;
//ret->column=hold_location->column;
- ret->line=0;
- ret->column=0;
+ ret->line=line;
+ ret->column=column;
ret->filename=hold_location->src->src_name->name;
ret->filename_size=hold_location->src->src_name->name_size;
ret->executed_macro_id=NULL;
void token_ptr_assume_location_of_token(struct Token_Pointer *ptr,struct token *token)
{
wonky_assert(token!=NULL);
- wonky_printf("XXX token_ptr_assume_location_of_token %Wt %WPc\n",token,ptr->context);
ptr->context->line+=token->delta->line_offset;
ptr->context->column=token->delta->column;
}
push_token_pointer_error(ptr,"Preprocessing bounds exceeded");
return;
}
- new_context=get_token_ptr_context(where_to,number_of_remaining_tokens,is_file_inclusion);
+ new_context=get_token_ptr_context(where_to,number_of_remaining_tokens,is_file_inclusion,ptr->context->line,ptr->context->column);
Stack_Push(ptr->call_stack,ptr->context);
ptr->context=new_context;
}
push_token_pointer_error(ptr,"Preprocessing bounds exceeded");
return;
}
- new_context=get_token_ptr_context(arg->first_in_argument_substitution_tokens,arg->number_of_substitution_tokens,0);
+ new_context=get_token_ptr_context(arg->first_in_argument_substitution_tokens,arg->number_of_substitution_tokens,0,ptr->context->line,ptr->context->column);
token_ptr_store_functionlike_macro_state_into_context(new_context,arg->belongs_to->define);
Stack_Push(ptr->call_stack,ptr->context);
ptr->context=new_context;
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 Token_Pointer* get_token_ptr(struct Preprocessing_Translation_Unit *unit,struct Program *program);
void delete_token_ptr(struct Token_Pointer *ptr);
- struct Token_Pointer_Context* get_token_ptr_context(struct Queue_Node *start,size_t number_of_remaining_tokens,_Bool is_file_inclusion);
+ struct Token_Pointer_Context* get_token_ptr_context(struct Queue_Node *start,size_t number_of_remaining_tokens,_Bool is_file_inclusion,size_t line,size_t column);
void token_ptr_pop_context(struct Token_Pointer *ptr);
_Bool token_ptr_has_remaining_tokens(struct Token_Pointer *ptr);