F diff --git a/src/backend/text/print/print.c b/src/backend/text/print/print.c
--- a/src/backend/text/print/print.c
+++ b/src/backend/text/print/print.c
char print_tokens_of_program(FILE *out,char **base_source_names)
{
- struct Source_Name *name;
+ struct Source_File *src;
struct Program *program;
char *this_directory[]={"./",NULL};
_Bool ret;
do
{
- name=get_source_name(*base_source_names,program);
+ src=get_source_file_from_string(*base_source_names,gstrnlen(*base_source_names,1000));
- if(name==NULL)
+ lex(src,program);
+ if(program->errors->size>0)
{
- continue;
- }else
- {
- lex(name,program);
- if(program->errors->size>0)
- {
- ret=1;
- print_errors(out,program->errors);
- break;
- }
-
- fprintf(out,"\nTOKENS OF %s {\n",name->normalised_name);
- print_tokens(out,((struct Preprocessing_Translation_Unit*)program->preprocessing_translation_units_to_be_compiled->first)->tokens);
- fprintf(out,"\n} END OF TOKENS\n");
+ ret=1;
+ print_errors(out,program->errors);
+ break;
+ }
+ fprintf(out,"\nTOKENS OF %s {\n",src->src_name->full_name);
+ print_tokens(out,((struct Preprocessing_Translation_Unit*)program->preprocessing_translation_units_to_be_compiled->first)->tokens);
+ fprintf(out,"\n} END OF TOKENS\n");
- }
}while(*(++base_source_names));
}
void print_designator_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Designator *designator)
{
- print_token(compile_data,designator->id);
+ print_id(compile_data,designator->id);
}
void print_binary_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Binary_Expression *bin)
{
F diff --git a/src/debug/debug_lexer.c b/src/debug/debug_lexer.c
--- a/src/debug/debug_lexer.c
+++ b/src/debug/debug_lexer.c
{
return keyword>=0 && keyword<LEXER_TYPE_END;
}
- _Bool is_valid_token(struct token *token)
+ _Bool is_valid_token(struct identifier *token)
{
- return is_valid_keyword_enum(token->type);
+ return 1;
}
#endif
F diff --git a/src/debug/debug_lexer.h b/src/debug/debug_lexer.h
--- a/src/debug/debug_lexer.h
+++ b/src/debug/debug_lexer.h
#include <common.h>
_Bool is_valid_keyword_enum(enum LEXER_TYPE keyword);
- _Bool is_valid_token(struct token *token);
+ _Bool is_valid_token(struct identifier *token);
_Bool is_valid_automata_node(struct Automata_Node *node);
#endif
F diff --git a/src/environment/error/gcc_error.c b/src/environment/error/gcc_error.c
--- a/src/environment/error/gcc_error.c
+++ b/src/environment/error/gcc_error.c
struct Translation_Message *ret;
- hold_return_string=get_translation_message_location_prefix(location->src_name->normalised_name,location->line,location->column);
+ hold_return_string=get_translation_message_location_prefix(location->src_name->full_name,location->line,location->column);
for(i=0;i<1000 && message_format[i]!='\0';++i)
ret->message=hold_return_string;
ret->line=location->line;
ret->column=location->column;
- ret->filename=location->src_name->normalised_name;
+ ret->filename=location->src_name->full_name;
return ret;
}
hold_message->line=line;
hold_message->column=column;
- Queue_Push(translation_data->errors,hold_message);
+ Queue_Push(translation_data->program->errors,hold_message);
}
void push_compile_error(const char *message,struct Compile_Data *compile_data)
F diff --git a/src/environment/error/gcc_error.h b/src/environment/error/gcc_error.h
--- a/src/environment/error/gcc_error.h
+++ b/src/environment/error/gcc_error.h
void print_compile_errors(FILE *out,struct Queue *errors);
+ void hard_error(char *format,...);
+
/*
F diff --git a/src/frontend/lex/lexer.c b/src/frontend/lex/lexer.c
--- a/src/frontend/lex/lexer.c
+++ b/src/frontend/lex/lexer.c
/*asdf*/#include <lexer.h>
- void lex(struct Source_Name *src_name,struct Program *program)
+ void lex(struct Source_File *src,struct Program *program)
{
struct Lexer_Data *lexer_data;
struct Preprocessing_Translation_Unit *lexed_unit;
- lexer_data=get_lexer_data(src_name,program);
+ lexer_data=get_lexer_data(src,program);
lexed_unit=lex_inner(lexer_data);
Map_Push(
program->preprocessing_translation_units,
- src_name->normalised_name,
- src_name->normalised_name_size,
+ src->src_name->full_name,
+ src->src_name->full_name_size,
lexed_unit
);
}
- struct Lexer_Data* get_lexer_data(struct Source_Name *src_name,struct Program *program)
+ struct Lexer_Data* get_lexer_data(struct Source_File *src,struct Program *program)
{
struct Lexer_Data *ret;
ret->which_row=0;
ret->is_in_the_begining_of_line=0;
ret->automata_view=AUTOMATA_VIEW_NORMAL;
- ret->src=get_source_file(src_name,program);
+ ret->src=src;
ret->program=program;
return ret;
F diff --git a/src/frontend/lex/lexer.h b/src/frontend/lex/lexer.h
--- a/src/frontend/lex/lexer.h
+++ b/src/frontend/lex/lexer.h
- void lex(struct Source_Name *src_name,struct Program *program);
+ void lex(struct Source_File *src,struct Program *program);
struct Preprocessing_Translation_Unit* lex_inner(struct Lexer_Data *lexer_data);
- struct Lexer_Data* get_lexer_data(struct Source_Name *src_name,struct Program *program);
+ struct Lexer_Data* get_lexer_data(struct Source_File *src,struct Program *program);
void lexer_skip_white_space(struct Lexer_Data *lexer_data);
_Bool lexer_eof(struct Lexer_Data *lexer_data);
F diff --git a/src/frontend/parse/parse_declaration.c b/src/frontend/parse/parse_declaration.c
--- a/src/frontend/parse/parse_declaration.c
+++ b/src/frontend/parse/parse_declaration.c
parse_function_definitions=0; /*here so we don't have int a,main(){ return 0 }*/
- if(!get_and_check(translation_data,KW_COMMA) && !check(translation_data,KW_SEMI_COLUMN,0))
+ if(!get_and_check(translation_data,KW_COMMA) && !check(translation_data,KW_SEMI_COLUMN))
{
/*TODO error*/
Queue_Push(where_to_push_objects,get_declaration_error_tree(NULL));
ret->specifier=TS_UNION;
hack:
chomp(translation_data);
- if(check(translation_data,KW_ID,0))
+ if(check(translation_data,KW_ID))
{
struct identifier *id;
struct token_identifier *hold_token;
case KW_ENUM:
chomp(translation_data);
ret->specifier=TS_ENUM;
- if(check(translation_data,KW_ID,0))
+ if(check(translation_data,KW_ID))
{
struct identifier *id;
struct token_identifier *hold_token;
exit:
if(ret->specifier==TS_ENUM)
{
- ret->type=(struct Type*)get_enum_type(ret,translation_data);
+ ret->type=(struct Type*)get_enum_type(ret);
}else if(ret->specifier==TS_STRUCT || ret->specifier==TS_UNION)
{
- ret->type=(struct Type*)get_struct_union_type(ret,translation_data);
+ ret->type=(struct Type*)get_struct_union_type(ret);
}else if(ret->type==NULL)
{
- ret->type=(struct Type*)get_basic_type(ret,translation_data);
+ ret->type=(struct Type*)get_basic_type(ret);
}
return ret;
}
break;
}
}
- base->type=(struct Type*)get_pointer_type(base->type,is_const,is_volatile,translation_data);
+ base->type=(struct Type*)get_pointer_type(base->type,is_const,is_volatile);
}
parse_direct_declarator(translation_data,scope,base);
*/
void parse_direct_declarator(struct Translation_Data *translation_data,struct Scope *scope,struct Denoted_Base *base)
{
- if(check(translation_data,KW_ID,0))
+ if(check(translation_data,KW_ID))
{
struct token_identifier *hold_token;
struct identifier *id;
}else if(get_and_check(translation_data,KW_OPEN_NORMAL))
{
- struct Queue *hack;
- struct Queue *hold;
- hack=wonky_malloc(sizeof(struct Queue));
- Queue_Init(hack);
-
- while(!check(translation_data,KW_CLOSE_NORMAL,0))
- {
- Queue_Push(hack,get_next_token(translation_data));
- }
- /*remove closing )*/
- chomp(translation_data);
- parse_direct_declarator_finish(translation_data,scope,base);
-
-
-
- hold=translation_data->tokens;
- translation_data->tokens=hack;
+ struct Type *hold_first_part;
+ struct Type *hold_middle_part;
+ hold_first_part=base->type;
+ base->type=NULL;
parse_declarator_inner(translation_data,scope,base);
- translation_data->tokens=hold;
- if(hack->size!=0)
+ if(get_and_check(translation_data,KW_CLOSE_NORMAL))
{
- /*TODO error*/
- base->denotation=DT_Error;
- while(hack->size)
+ hold_middle_part=base->type;
+ base->type=hold_first_part;
+ parse_declarator_inner(translation_data,scope,base);
+ if(!rebase_type(hold_middle_part,base->type))
+ {
+ base->type=hold_middle_part;
+ }else
{
- wonky_free(Queue_Pop(hack));
+ wonky_assert(SHOULD_NOT_REACH_HERE);
}
- wonky_free(hack);
- push_translation_error("declarator error",translation_data);
- return;
+ }else
+ {
+ base->type=get_type_error(hold_first_part);
+ push_translation_error("Expected a ')' at %L",translation_data);
}
- wonky_free(hack);
-
}else
{
/*this might be an abstract declarator*/
{
/*TODO error*/
push_translation_error("']' expected",translation_data);
- base->type=(struct Type*)get_type_error(base->type,translation_data);
+ base->type=(struct Type*)get_type_error(base->type);
delete_ast(hold_expression);
return;
}
return 0;
}
- if(!get_and_check(translation_data,KW_COMMA) && !check(translation_data,KW_SEMI_COLUMN,0))
+ if(!get_and_check(translation_data,KW_COMMA) && !check(translation_data,KW_SEMI_COLUMN))
{
wonky_free(prototype);
push_translation_error("semi column expected in struct declaration",translation_data);
*/
void parse_enum_specifier_finish(struct Translation_Data *translation_data,struct Scope *scope,struct Enum *enumeration)
{
- struct token *id;
+ struct identifier *id;
struct Denoted_Enum_Const *hold;
int where_in_enumeration=0;
if(get_and_check(translation_data,KW_OPEN_CURLY))
enumeration->is_finished=1;
do
{
- if(check(translation_data,KW_ID,0))
+ if(check(translation_data,KW_ID))
{
- id=Queue_Pop(translation_data->tokens);
+ id=((struct token_identifier*)get_next_token(translation_data))->id;
if(get_and_check(translation_data,KW_EQ))
{
hold=(struct Denoted_Enum_Const*)get_denoted_enum_const_expr(id,enumeration,parse_expression(translation_data,scope),translation_data);
*/
struct Initialiser* parse_initialiser_list_component(struct Translation_Data *translation_data,struct Scope *scope,struct Type *type_of_initialised)
{
- if(check(translation_data,KW_DOT,0) || check(translation_data,KW_OPEN_SQUARE,0))
+ if(check(translation_data,KW_DOT) || check(translation_data,KW_OPEN_SQUARE))
return parse_designation(translation_data,scope,type_of_initialised);
else
return parse_initialiser(translation_data,scope,type_of_initialised);
{
struct Denoted_Object *member;
struct Type_Struct_Union *real_type;
- struct token *id;
+ struct identifier *id;
if(!type_is_struct_union(type_of_initialised))
{
push_translation_error("expected struct/union type in initialiser, got %T instead",translation_data,type_of_initialised);
return get_initialiser_error(NULL);
}
- if(!check(translation_data,KW_ID,0))
+ if(!check(translation_data,KW_ID))
{
push_translation_error("expected id in the initialisation of type %T",translation_data,type_of_initialised);
return get_initialiser_error(NULL);
}
- id=Queue_Pop(translation_data->tokens);
+ id=((struct token_identifier*)get_next_token(translation_data))->id;
real_type=(struct Type_Struct_Union*)type_of_initialised;
member=check_struct_union_member(real_type->struct_union->inner_namespace,id);
F diff --git a/src/frontend/parse/parse_expression.c b/src/frontend/parse/parse_expression.c
--- a/src/frontend/parse/parse_expression.c
+++ b/src/frontend/parse/parse_expression.c
struct token *hold_token;
struct AST_Expression *hold;
- if(translation_data->tokens->size==0)
+ if(translation_eof(translation_data))
{
/*TODO error*/
push_translation_error("expected something here",translation_data);
return (struct AST_Expression*)get_error_tree(NULL);
}
- hold_token=Queue_Pop(translation_data->tokens);
+ hold_token=get_next_token(translation_data);
switch(hold_token->type) /*the token is not wonky_freed so there is a memory leak here*/
{
case KW_STRING:
case KW_WIDE_STRING:
- return (struct AST_Expression*)get_string_literal_tree(get_expression_value_constant(extract_literal_string(hold_token,translation_data)));
- case KW_CHAR_CONSTANT:
- return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_char(hold_token,translation_data)));
- case KW_WIDE_CHAR_CONSTANT:
- return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_wide_char(hold_token,translation_data)));
- case KW_HEXADECIMAL_CONSTANT:
- case KW_UNSIGNED_LONG_HEXADECIMAL_CONSTANT:
- case KW_UNSIGNED_LONG_LONG_HEXADECIMAL_CONSTANT:
- case KW_UNSIGNED_HEXADECIMAL_CONSTANT:
- case KW_LONG_HEXADECIMAL_CONSTANT:
- case KW_LONG_LONG_HEXADECIMAL_CONSTANT:
- return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_integer_hex(hold_token,translation_data)));
-
- case KW_DECIMAL_CONSTANT:
- case KW_UNSIGNED_LONG_LONG_DECIMAL_CONSTANT:
- case KW_UNSIGNED_LONG_DECIMAL_CONSTANT:
- case KW_UNSIGNED_DECIMAL_CONSTANT:
- case KW_LONG_DECIMAL_CONSTANT:
- case KW_LONG_LONG_DECIMAL_CONSTANT:
- return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_integer_dec(hold_token,translation_data)));
-
- case KW_OCTAL_CONSTANT:
- case KW_UNSIGNED_OCTAL_CONSTANT:
- case KW_UNSIGNED_LONG_OCTAL_CONSTANT:
- case KW_UNSIGNED_LONG_LONG_OCTAL_CONSTANT:
- case KW_LONG_OCTAL_CONSTANT:
- case KW_LONG_LONG_OCTAL_CONSTANT:
- return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_integer_octal(hold_token,translation_data)));
-
- case KW_DOUBLE_DECIMAL_CONSTANT:
- case KW_LONG_DOUBLE_DECIMAL_CONSTANT:
- case KW_FLOAT_DECIMAL_CONSTANT:
- return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_double_dec(hold_token,translation_data)));
- case KW_DOUBLE_HEXADECIMAL_CONSTANT:
- case KW_LONG_DOUBLE_HEXADECIMAL_CONSTANT:
- case KW_FLOAT_HEXADECIMAL_CONSTANT:
- return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_double_hex(hold_token,translation_data)));
-
+ return (struct AST_Expression*)get_string_literal_tree(get_expression_value_constant(((struct token_string*)hold_token)->constant));
+ case KW_CONSTANT:
+ return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(((struct token_constant*)hold_token)->constant));
case KW_ID:
- return (struct AST_Expression*)get_designator_tree(hold_token,scope,translation_data);
+ return (struct AST_Expression*)get_designator_tree(((struct token_identifier*)hold_token)->id,scope,translation_data);
case KW_OPEN_NORMAL:
hold=(struct AST_Expression*)parse_expression(translation_data,scope);
if(get_and_check(translation_data,KW_CLOSE_NORMAL))
hold_postfix_expression=parse_primary_expression(translation_data,scope);
- while(translation_data->tokens->size!=0)
+ while(!translation_eof(translation_data))
{
wonky_assert(is_valid_ast_expression(hold_postfix_expression));
break;
case KW_DOT:
chomp(translation_data);
- if(check(translation_data,KW_ID,0))
+ if(check(translation_data,KW_ID))
{
- hold_postfix_expression=(struct AST_Expression*)get_struct_union_member_tree(hold_postfix_expression,Queue_Pop(translation_data->tokens),translation_data);
+ struct identifier *id;
+ id=((struct token_identifier*)get_next_token(translation_data))->id;
+ hold_postfix_expression=(struct AST_Expression*)get_struct_union_member_tree(hold_postfix_expression,id,translation_data);
}
break;
case KW_ARROW:
chomp(translation_data);
- if(check(translation_data,KW_ID,0))
+ if(check(translation_data,KW_ID))
{
- hold_postfix_expression=(struct AST_Expression*)get_struct_union_member_trough_ptr_tree(hold_postfix_expression,Queue_Pop(translation_data->tokens),translation_data);
+ struct identifier *id;
+ id=((struct token_identifier*)get_next_token(translation_data))->id;
+ hold_postfix_expression=(struct AST_Expression*)get_struct_union_member_trough_ptr_tree(hold_postfix_expression,id,translation_data);
}
break;
case KW_OPEN_SQUARE:
struct AST_Expression* parse_cast_expression(struct Translation_Data *translation_data,struct Scope *scope)
{
struct AST_Unary_Expression *ret;
- if(check(translation_data,KW_OPEN_NORMAL,0) && is_type(translation_data,scope,1))
+ if(check(translation_data,KW_OPEN_NORMAL) && is_type_name(translation_data,scope))
{
struct Type *cast_type;
struct AST_Expression *operand;
struct AST_Expression *hold_expression;
enum AST_Type operation_type;
- if(translation_data->tokens->size==0)
+ if(translation_eof(translation_data))
{
/*TODO error*/
push_translation_error("expected something here",translation_data);
hold_left_expression=parse_cast_expression(translation_data,scope);
- while(translation_data->tokens->size!=0)
+ while(!translation_eof(translation_data))
{
wonky_assert(is_valid_ast_expression(hold_left_expression));
hold_left_expression=parse_multiplicative_expression(translation_data,scope);
- while(translation_data->tokens->size!=0)
+ while(!translation_eof(translation_data))
{
wonky_assert(is_valid_ast_expression(hold_left_expression));
switch(kw_get(translation_data))
hold_left_expression=parse_additive_expression(translation_data,scope);
- while(translation_data->tokens->size!=0)
+ while(!translation_eof(translation_data))
{
wonky_assert(is_valid_ast_expression(hold_left_expression));
switch(kw_get(translation_data))
hold_left_expression=parse_shift_expression(translation_data,scope);
- while(translation_data->tokens->size!=0)
+ while(!translation_eof(translation_data))
{
wonky_assert(is_valid_ast_expression(hold_left_expression));
switch(kw_get(translation_data))
hold_left_expression=parse_relational_expression(translation_data,scope);
- while(translation_data->tokens->size!=0)
+ while(!translation_eof(translation_data))
{
wonky_assert(is_valid_ast_expression(hold_left_expression));
switch(kw_get(translation_data))
struct AST_Expression *hold_right_expression;
enum AST_Type operation_type;
- if(translation_data->tokens->size==0)
+ if(translation_eof(translation_data))
{
push_translation_error("expected something here",translation_data);
return (struct AST_Expression*)get_error_tree(NULL);
wonky_assert(is_valid_ast_expression(hold_left_expression));
- if(translation_data->tokens->size==0)
+ if(translation_eof(translation_data))
return hold_left_expression;
/*TODO make it iterative*/
F diff --git a/src/frontend/parse/parse_statement.c b/src/frontend/parse/parse_statement.c
--- a/src/frontend/parse/parse_statement.c
+++ b/src/frontend/parse/parse_statement.c
struct AST* parse_statement(struct Translation_Data* translation_data,struct Scope *scope,struct Parse_Statement_Data *parse_data)
{
- if(translation_data->tokens->size==0)
+ if(translation_eof(translation_data))
return NULL;
switch(kw_get(translation_data))
chomp(translation_data);
return parse_finish_default_statement(translation_data,scope,parse_data);
case KW_ID:
- if(check(translation_data,KW_COLUMN,1))
{
- return parse_finish_labeled_statement(translation_data,scope,parse_data);
- }else
- {
- return parse_expression_statement(translation_data,scope,parse_data);
+ struct token_identifier *hold_token;
+ hold_token=(struct token_identifier*)get_next_token(translation_data);
+ if(check(translation_data,KW_COLUMN))
+ {
+ token_ptr_unget_token(translation_data->token_pointer,(struct token*)hold_token);
+ return parse_finish_labeled_statement(translation_data,scope,parse_data);
+ }else
+ {
+ token_ptr_unget_token(translation_data->token_pointer,(struct token*)hold_token);
+ return parse_expression_statement(translation_data,scope,parse_data);
+ }
}
case KW_CONTINUE:
chomp(translation_data);
while(!get_and_check(translation_data,KW_CLOSE_CURLY) && !has_no_tokens(translation_data))
{
- if(is_type(translation_data,hold->scope,0))
+ if(is_type_name(translation_data,hold->scope))
parse_declaration(translation_data,hold->scope,hold->components);
else
Queue_Push(hold->components,parse_statement(translation_data,hold->scope,parse_data));
{
struct AST_Goto_Statement* ret;
- if(check(translation_data,KW_ID,0))
+ if(check(translation_data,KW_ID))
{
- ret=get_goto_statement_tree(Queue_Pop(translation_data->tokens),scope,translation_data);
+ struct token_identifier *hold_id_token;
+ hold_id_token=(struct token_identifier*)get_next_token(translation_data);
+ ret=get_goto_statement_tree(hold_id_token->id,scope,translation_data);
if(get_and_check(translation_data,KW_SEMI_COLUMN))
{
wonky_assert(is_valid_goto_statement(ret));
struct AST* parse_finish_labeled_statement(struct Translation_Data* translation_data,struct Scope *scope,struct Parse_Statement_Data *parse_data)
{
struct AST *hold_statement;
- struct token *hold_id;
+ struct token_identifier *hold_id;
struct AST_Labeled_Statement *hold;
/*id and ':' are checked for in the parse_statement function*/
- hold_id=Queue_Pop(translation_data->tokens);
+ hold_id=(struct token_identifier*)get_next_token(translation_data);
chomp(translation_data); /* ':' */
hold_statement=parse_statement(translation_data,scope,parse_data);
- hold=get_labeled_statement_tree(hold_id,hold_statement,ST_LABEL,translation_data,scope);
+ hold=get_labeled_statement_tree(hold_id->id,hold_statement,ST_LABEL,translation_data,scope);
wonky_assert(is_valid_labeled_statement(hold));
return (struct AST*)hold;
void chase_next_semicolumn(struct Translation_Data *translation_data)
{
/*chase ; and start parsing next declaration*/
- while(!get_and_check(translation_data,KW_SEMI_COLUMN) && !check(translation_data,KW_CLOSE_CURLY,0) &&
- translation_data->tokens->size>0)
+ while(!get_and_check(translation_data,KW_SEMI_COLUMN) && !check(translation_data,KW_CLOSE_CURLY) &&
+ !translation_eof(translation_data))
{
chomp(translation_data);
}
F diff --git a/src/frontend/parse/parse_translation_unit.c b/src/frontend/parse/parse_translation_unit.c
--- a/src/frontend/parse/parse_translation_unit.c
+++ b/src/frontend/parse/parse_translation_unit.c
*/
struct AST* parse_translation_unit(struct Translation_Data *translation_data)
{
- size_t loop_preventer;
struct AST_Translation_Unit *hold;
hold=get_translation_unit_tree();
- loop_preventer=0;
- while(translation_data->tokens->size>0 && loop_preventer!=translation_data->tokens->size)
+ while(!translation_eof(translation_data))
{
- loop_preventer=translation_data->tokens->size;
-
- if(is_type(translation_data,hold->file_scope,0) || kw_get(translation_data)==KW_ID)
+ if(is_type_name(translation_data,hold->file_scope) || kw_get(translation_data)==KW_ID)
{
parse_external_definition(translation_data,hold);
if(has_new_errors(translation_data))
F diff --git a/src/misc/gcc_string.c b/src/misc/gcc_string.c
--- a/src/misc/gcc_string.c
+++ b/src/misc/gcc_string.c
for(i=0;str[i]!='\0';++i);
return i;
}
+ size_t gstrnlen(const char *str,size_t limit)
+ {
+ size_t i;
+ for(i=0;i<limit && str[i]!='\0';++i);
+ return i;
+ }
char* gstr_append(const char *lead,const char *follower)
{
F diff --git a/src/misc/gcc_string.h b/src/misc/gcc_string.h
--- a/src/misc/gcc_string.h
+++ b/src/misc/gcc_string.h
size_t gstrlen(const char *str);
+ size_t gstrnlen(const char *str,size_t limit);
char* gstr_append(const char *lead,const char *follower);
char* gstrcpy(const char *str);
char* gstrncpy(const char *str,size_t size);
F diff --git a/src/semantics/ast.c b/src/semantics/ast.c
--- a/src/semantics/ast.c
+++ b/src/semantics/ast.c
struct Type *promotion_type;
operand_type=extract_expresion_value_type(operand->value);
- promotion_type=get_type_for_promotion(operand_type,translation_data);
+ 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
operand_type=extract_expresion_value_type(operand->value);
if(operand_type->specifier==TS_FLOAT)
{
- return get_cast_expression_tree(operand,(struct Type*)get_type_insecure(TS_DOUBLE,TSIGN_NONE,TC_NONE,DOUBLE_SIZE,translation_data),translation_data);
+ return get_cast_expression_tree(operand,(struct Type*)get_type_insecure(TS_DOUBLE,TSIGN_NONE,TC_NONE,DOUBLE_SIZE),translation_data);
}else
{
return get_promoted_expression(operand,translation_data);
if(expression_type->specifier==TS_ARRAY)
{
array_type=(struct Type_Array*)expression_type;
- expression_type=get_pointer_type(array_type->is_array_of,1,0,translation_data);
+ expression_type=get_pointer_type(array_type->is_array_of,1,0);
wonky_assert(expression_type!=NULL);
if(right_type->sign==TSIGN_SIGNED || left_rank!=right_rank)
greater_type=(left_rank<right_rank?right_type:left_type);
else
- greater_type=get_type_insecure(left_type->specifier,TSIGN_UNSIGNED,left_type->constraint,left_type->size,translation_data);
+ greater_type=get_type_insecure(left_type->specifier,TSIGN_UNSIGNED,left_type->constraint,left_type->size);
}
else
{
if(right_type->sign==TSIGN_UNSIGNED || left_rank!=right_rank)
greater_type=(left_rank<right_rank?right_type:left_type);
else
- greater_type=get_type_insecure(right_type->specifier,TSIGN_UNSIGNED,right_type->constraint,right_type->size,translation_data);
+ greater_type=get_type_insecure(right_type->specifier,TSIGN_UNSIGNED,right_type->constraint,right_type->size);
}
left=get_cast_expression_tree(left,(struct Type*)greater_type,translation_data);
{
if(constraint_check_relational_operation(left,right,operation,translation_data))
{
- return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object((struct Type*)get_type_insecure(TS_INT,TSIGN_SIGNED,TC_NONE,INT_SIZE,translation_data))),operation);
+ return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object((struct Type*)get_type_insecure(TS_INT,TSIGN_SIGNED,TC_NONE,INT_SIZE))),operation);
}else
{
return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,operation));
{
if(constraint_check_equality_expression(left,right,translation_data))
{
- return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object((struct Type*)get_type_insecure(TS_INT,TSIGN_SIGNED,TC_NONE,INT_SIZE,translation_data))),operation);
+ return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object((struct Type*)get_type_insecure(TS_INT,TSIGN_SIGNED,TC_NONE,INT_SIZE))),operation);
}else
{
return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,operation));
}
struct AST_Binary_Expression* get_logical_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
{
- return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object((struct Type*)get_type_insecure(TS_INT,TSIGN_SIGNED,TC_NONE,INT_SIZE,translation_data))),operation);
+ return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object((struct Type*)get_type_insecure(TS_INT,TSIGN_SIGNED,TC_NONE,INT_SIZE))),operation);
}
struct AST_Binary_Expression* get_simple_assignment_expression_tree(struct AST_Expression *left,struct AST_Expression *right,struct Translation_Data *translation_data)
left_type=extract_expresion_value_type(left->value);
- left_type=get_unqualified_version_of_type(left_type,translation_data);
+ left_type=get_unqualified_version_of_type(left_type);
right=get_cast_expression_tree(right,left_type,translation_data);
{
struct Type *left_type;
left_type=extract_expresion_value_type(left->value);
- left_type=get_unqualified_version_of_type(left_type,translation_data);
+ left_type=get_unqualified_version_of_type(left_type);
right=get_cast_expression_tree(right,left_type,translation_data);
return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object(left_type)),operation);
return get_binary_expression_tree(left,right,get_expression_value_lvalue(get_temp_object(member_type)),OP_ARR_SUBSCRIPT);
}
- struct AST_Binary_Expression* get_struct_union_member_tree(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data)
+ struct AST_Binary_Expression* get_struct_union_member_tree(struct AST_Expression *left,struct identifier *id,struct Translation_Data *translation_data)
{
struct AST_Binary_Expression *ret;
struct Type_Struct_Union *left_type;
}
/*TODO beware const type qualifier*/
- struct AST_Binary_Expression* get_struct_union_member_trough_ptr_tree(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data)
+ struct AST_Binary_Expression* get_struct_union_member_trough_ptr_tree(struct AST_Expression *left,struct identifier *id,struct Translation_Data *translation_data)
{
struct AST_Expression *hold_derefernced;
hold_derefernced=(struct AST_Expression*)get_indirection_expression_tree(left,translation_data);
ret->operand=operand;
operand_type=extract_expresion_value_type(operand->value);
- ret->value=get_expression_value_rvalue(get_temp_object(get_pointer_type(operand_type,0,0,translation_data)));
+ ret->value=get_expression_value_rvalue(get_temp_object(get_pointer_type(operand_type,0,0)));
return ret;
}else
return ret;
}
- struct AST_Expression* get_designator_tree(struct token *id,struct Scope* scope,struct Translation_Data *translation_data)
+ struct AST_Expression* get_designator_tree(struct identifier *id,struct Scope* scope,struct Translation_Data *translation_data)
{
struct AST_Designator *ret;
struct Denoted *hold_denoted;
switch(hold_denoted->denotation)
{
case DT_Enum_Constant:
- ret->value=(struct Expression_Value*)get_expression_value_constant(extract_enum_constant((struct Denoted_Enum_Const*)hold_denoted,translation_data));
+ ret->value=(struct Expression_Value*)get_expression_value_constant(extract_enum_constant((struct Denoted_Enum_Const*)hold_denoted));
break;
case DT_Object:
ret->value=get_expression_value_lvalue( ((struct Denoted_Object*)hold_denoted)->object );
return ret;
}
- struct AST_Designator* get_struct_union_member_tree_designator(struct token *id,struct Normal_Scope *inner_scope,struct Translation_Data *translation_data)
+ struct AST_Designator* get_struct_union_member_tree_designator(struct identifier *id,struct Normal_Scope *inner_scope,struct Translation_Data *translation_data)
{
struct AST_Designator *ret;
struct Denoted *hold_denoted;
return (struct AST_Case_Statement*)get_error_tree((struct AST*)ret);
}
- struct AST_Labeled_Statement* get_labeled_statement_tree(struct token *label,struct AST* statement,enum AST_Type type,struct Translation_Data *translation_data,struct Scope *scope)
+ struct AST_Labeled_Statement* get_labeled_statement_tree(struct identifier *label,struct AST* statement,enum AST_Type type,struct Translation_Data *translation_data,struct Scope *scope)
{
struct AST_Labeled_Statement *ret;
ret=wonky_malloc(sizeof(struct AST_Labeled_Statement));
}
}
- struct AST_Goto_Statement* get_goto_statement_tree(struct token *label,struct Scope *scope,struct Translation_Data *translation_data)
+ struct AST_Goto_Statement* get_goto_statement_tree(struct identifier *label,struct Scope *scope,struct Translation_Data *translation_data)
{
struct AST_Goto_Statement *ret;
struct Denoted_Statement *hold_statement;
F diff --git a/src/semantics/ast.h b/src/semantics/ast.h
--- a/src/semantics/ast.h
+++ b/src/semantics/ast.h
{
enum AST_Type type;
struct Expression_Value *value;
- struct token *id;
+ struct identifier *id;
};
struct AST_Unary_Expression
struct AST_Binary_Expression* get_array_subscript_tree(struct AST_Expression *left,struct AST_Expression *right,struct Translation_Data *translation_data);
- struct AST_Binary_Expression* get_struct_union_member_tree(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data);
- struct AST_Binary_Expression* get_struct_union_member_trough_ptr_tree(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data);
+ struct AST_Binary_Expression* get_struct_union_member_tree(struct AST_Expression *left,struct identifier *id,struct Translation_Data *translation_data);
+ struct AST_Binary_Expression* get_struct_union_member_trough_ptr_tree(struct AST_Expression *left,struct identifier *id,struct Translation_Data *translation_data);
struct AST_Conditional_Expression* get_conditional_expression_tree(struct AST_Expression *left,struct AST_Expression *center,struct AST_Expression *right,struct Translation_Data *translation_data);
struct AST_Function_Expression* get_function_expression_tree(struct AST_Expression *id,struct Queue *arg_list,struct Translation_Data *translation_data);
struct AST_Constant* get_constant_tree(struct Expression_Value_Constant *value);
struct AST_String_Literal* get_string_literal_tree(struct Expression_Value_Constant *value);
- struct AST_Expression* get_designator_tree(struct token *id,struct Scope* scope,struct Translation_Data *translation_data);
+ struct AST_Expression* get_designator_tree(struct identifier *id,struct Scope* scope,struct Translation_Data *translation_data);
struct AST_Designator* get_designator_tree_from_denoted_object(struct Denoted_Object *object,struct Translation_Data *translation_data);
- struct AST_Designator* get_struct_union_member_tree_designator(struct token *id,struct Normal_Scope *inner_scope,struct Translation_Data *translation_data);
+ struct AST_Designator* get_struct_union_member_tree_designator(struct identifier *id,struct Normal_Scope *inner_scope,struct Translation_Data *translation_data);
- struct AST_Labeled_Statement* get_labeled_statement_tree(struct token *label,struct AST *statement,enum AST_Type type,struct Translation_Data *translation_data,struct Scope *scope);
+ struct AST_Labeled_Statement* get_labeled_statement_tree(struct identifier *label,struct AST *statement,enum AST_Type type,struct Translation_Data *translation_data,struct Scope *scope);
struct AST_Case_Statement* get_case_statement_tree(struct AST *statement,struct AST_Expression *control,struct AST_Switch_Statement *parent,struct Translation_Data *translation_data);
struct AST_Default_Statement* get_default_statement_tree(struct AST *statement,struct Translation_Data *translation_data);
struct AST_Break_Continue_Statement* get_break_continue_statement_tree(struct AST *parent,struct Translation_Data *translation_data,enum AST_Type break_or_continue);
struct AST_Do_While_Statement* get_do_while_statement_tree();
struct AST_For_Statement* get_for_statement_tree();
struct AST_Return_Statement* get_return_statement_tree(struct AST* return_expression,struct Translation_Data *translation_data,struct Scope *scope);
- struct AST_Goto_Statement* get_goto_statement_tree(struct token *label,struct Scope *scope,struct Translation_Data *translation_data);
+ struct AST_Goto_Statement* get_goto_statement_tree(struct identifier *label,struct Scope *scope,struct Translation_Data *translation_data);
struct AST* get_nop_tree();
struct AST_Type_Definition* get_type_definition_tree(struct Denoted_Type *definition);
struct AST_Object_Declaration* get_object_declaration_tree(struct Denoted_Object *object,struct Initialiser *initialiser);
F diff --git a/src/semantics/constraints/expression_constraints.c b/src/semantics/constraints/expression_constraints.c
--- a/src/semantics/constraints/expression_constraints.c
+++ b/src/semantics/constraints/expression_constraints.c
left is (un)qualified struct or union, second is an id of a memeber of the struct or union
NOTE: we don't check if id is a member of the struct or union here
*/
- _Bool constraint_check_struct_union_member_expression(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data)
+ _Bool constraint_check_struct_union_member_expression(struct AST_Expression *left,struct identifier *id,struct Translation_Data *translation_data)
{
struct Type *left_type;
/*
see above
*/
- _Bool constraint_check_struct_union_member_trough_ptr_expression(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data)
+ _Bool constraint_check_struct_union_member_trough_ptr_expression(struct AST_Expression *left,struct identifier *id,struct Translation_Data *translation_data)
{
struct Type *left_type;
F diff --git a/src/semantics/constraints/expression_constraints.h b/src/semantics/constraints/expression_constraints.h
--- a/src/semantics/constraints/expression_constraints.h
+++ b/src/semantics/constraints/expression_constraints.h
_Bool constraint_check_compound_assignment_expression(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
_Bool constraint_check_comma_expression(struct AST_Expression *left,struct AST_Expression *right,struct Translation_Data *translation_data);
_Bool constraint_check_array_subscript_expression(struct AST_Expression *left,struct AST_Expression *right,struct Translation_Data *translation_data);
- _Bool constraint_check_struct_union_member_expression(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data);
- _Bool constraint_check_struct_union_member_trough_ptr_expression(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data);
+ _Bool constraint_check_struct_union_member_expression(struct AST_Expression *left,struct identifier *id,struct Translation_Data *translation_data);
+ _Bool constraint_check_struct_union_member_trough_ptr_expression(struct AST_Expression *left,struct identifier *id,struct Translation_Data *translation_data);
_Bool constraint_check_conditional_expression(struct AST_Expression *left,struct AST_Expression *center,struct AST_Expression *right,struct Translation_Data *translation_data);
_Bool constraint_check_function_expression(struct AST_Function_Expression *proposed_function,struct Translation_Data *translation_data);
_Bool constraint_check_indirection_expression(struct AST_Expression *operand,struct Translation_Data *translation_data);
F diff --git a/src/semantics/constraints/linkage_constraints.c b/src/semantics/constraints/linkage_constraints.c
--- a/src/semantics/constraints/linkage_constraints.c
+++ b/src/semantics/constraints/linkage_constraints.c
}else if(denoted_object->linkage==LINKAGE_EXTERNAL || denoted_object->linkage==LINKAGE_INTERNAL)
{
struct AST_Object_Declaration *hold_object;
- linkage=(denoted_object->linkage==LINKAGE_EXTERNAL?translation_data->external_linkage:translation_data->internal_linkage);
+ linkage=(denoted_object->linkage==LINKAGE_EXTERNAL?translation_data->program->external_linkage:translation_data->internal_linkage);
hold_object=check_and_push_id(denoted_object,linkage->ids,denoted_object->id,translation_data);
return 0;
}else if(denoted_function->linkage==LINKAGE_EXTERNAL || denoted_function->linkage==LINKAGE_INTERNAL)
{
- linkage=(denoted_function->linkage==LINKAGE_EXTERNAL?translation_data->external_linkage:translation_data->internal_linkage);
+ linkage=(denoted_function->linkage==LINKAGE_EXTERNAL?translation_data->program->external_linkage:translation_data->internal_linkage);
function_tree=check_and_push_id(denoted_function,linkage->ids,denoted_function->id,translation_data);
if(function_tree!=NULL)
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
wonky_assert(is_valid_denoted_base(ret));
return ret;
}
- struct Denoted* get_denoted_function(struct token *id,struct Type *type,enum Function_Specifier fs)
+ struct Denoted* get_denoted_function(struct identifier *id,struct Type *type,enum Function_Specifier fs)
{
struct Denoted_Function *ret;
ret=wonky_malloc(sizeof(struct Denoted_Function));
wonky_assert(is_valid_denoted_function(ret));
return (struct Denoted*)ret;
}
- struct Denoted* get_denoted_object(struct token *id, enum Storage_Class_Specifier sc,struct Type *type,struct AST *initializer)
+ struct Denoted* get_denoted_object(struct identifier *id, enum Storage_Class_Specifier sc,struct Type *type,struct AST *initializer)
{
struct Denoted_Object *ret;
ret=wonky_malloc(sizeof(struct Denoted_Object));
wonky_assert(is_valid_denoted_type(ret));
return (struct Denoted*)ret;
}
- struct Denoted* get_denoted_enum_const_expr(struct token *id,struct Enum *parent,struct AST* expression,struct Translation_Data *translation_data)
+ struct Denoted* get_denoted_enum_const_expr(struct identifier *id,struct Enum *parent,struct AST* expression,struct Translation_Data *translation_data)
{
struct Denoted_Enum_Const *ret;
ret=wonky_malloc(sizeof(struct Denoted_Enum_Const));
return (struct Denoted*)ret;
}
- struct Denoted* get_denoted_enum_const_num(struct token *id,struct Enum *parent,int value)
+ struct Denoted* get_denoted_enum_const_num(struct identifier *id,struct Enum *parent,int value)
{
struct Denoted_Enum_Const *ret;
ret=wonky_malloc(sizeof(struct Denoted_Enum_Const));
}
}
- struct Denoted* get_denoted_statement(struct token *id,struct AST *statement,struct Denoted_Object *previous_denoted_object)
+ struct Denoted* get_denoted_statement(struct identifier *id,struct AST *statement,struct Denoted_Object *previous_denoted_object)
{
struct Denoted_Statement *ret;
ret=wonky_malloc(sizeof(struct Denoted_Statement));
F diff --git a/src/semantics/identifiers/denoted.h b/src/semantics/identifiers/denoted.h
--- a/src/semantics/identifiers/denoted.h
+++ b/src/semantics/identifiers/denoted.h
{
enum Denotation_Type denotation;
- struct token *label;
+ struct identifier *label;
struct AST *statement;
struct Queue *gotos_jumping_to_this_statement;
struct Denoted_Base* get_denoted_base(struct Denotation_Prototype *prototype);
struct Denoted* get_denoted_error(struct Denoted *error);
- struct Denoted* get_denoted_function(struct token *id,struct Type *type,enum Function_Specifier fs);
- struct Denoted* get_denoted_object(struct token *id, enum Storage_Class_Specifier sc,struct Type *type,struct AST *initializer);
+ struct Denoted* get_denoted_function(struct identifier *id,struct Type *type,enum Function_Specifier fs);
+ struct Denoted* get_denoted_object(struct identifier *id, enum Storage_Class_Specifier sc,struct Type *type,struct AST *initializer);
struct Denoted* get_denoted_typedef(struct Denoted_Base *base);
- struct Denoted* get_denoted_enum_const_expr(struct token *id,struct Enum *parent,struct AST* expression,struct Translation_Data *translation_data);
- struct Denoted* get_denoted_enum_const_num(struct token *id,struct Enum *parent,int value);
+ struct Denoted* get_denoted_enum_const_expr(struct identifier *id,struct Enum *parent,struct AST* expression,struct Translation_Data *translation_data);
+ struct Denoted* get_denoted_enum_const_num(struct identifier *id,struct Enum *parent,int value);
struct Denoted* get_denoted_enum(struct Enum *enumerator);
struct Denoted* get_denoted_struct_union(struct Struct_Union *struct_union);
struct Denoted* extract_denoted(struct Denoted_Base *base,struct Denotation_Prototype *prototype,_Bool allow_abstract);
- struct Denoted* get_denoted_statement(struct token *id,struct AST *statement,struct Denoted_Object *previous_denoted_object);
+ struct Denoted* get_denoted_statement(struct identifier *id,struct AST *statement,struct Denoted_Object *previous_denoted_object);
struct Denoted* get_denotation_prototype(struct Program *program);
F diff --git a/src/semantics/identifiers/linkage.c b/src/semantics/identifiers/linkage.c
--- a/src/semantics/identifiers/linkage.c
+++ b/src/semantics/identifiers/linkage.c
/*check if id is linked oppositely*/
if(denoted_object->linkage==LINKAGE_EXTERNAL &&
- Map_Check(translation_data->internal_linkage->ids,denoted_object->id->data,denoted_object->id->data_size)!=NULL)
+ Map_Check(translation_data->internal_linkage->ids,denoted_object->id->data,denoted_object->id->size)!=NULL)
{
push_translation_error("linking id both internally and externally",translation_data);
}else if(denoted_object->linkage==LINKAGE_INTERNAL &&
- Map_Check(translation_data->external_linkage->ids,denoted_object->id->data,denoted_object->id->data_size)!=NULL)
+ Map_Check(translation_data->program->external_linkage->ids,denoted_object->id->data,denoted_object->id->size)!=NULL)
{
push_translation_error("linking id both internally and externally",translation_data);
}
/*check if id is linked oppositely*/
if(denoted_function->linkage==LINKAGE_EXTERNAL &&
- Map_Check(translation_data->internal_linkage->ids,denoted_function->id->data,denoted_function->id->data_size)!=NULL)
+ Map_Check(translation_data->internal_linkage->ids,denoted_function->id->data,denoted_function->id->size)!=NULL)
{
push_translation_error("linking id both internally and externally",translation_data);
}else if(denoted_function->linkage==LINKAGE_INTERNAL &&
- Map_Check(translation_data->external_linkage->ids,denoted_function->id->data,denoted_function->id->data_size)!=NULL)
+ Map_Check(translation_data->program->external_linkage->ids,denoted_function->id->data,denoted_function->id->size)!=NULL)
{
push_translation_error("linking id both internally and externally",translation_data);
}
struct AST_Object_Declaration *possible_declaration;
wonky_assert(is_valid_ast((struct AST*)object));
- possible_declaration=Map_Check(translation_data->external_linkage->ids,object->object->id->data,object->object->id->data_size);
+ possible_declaration=Map_Check(translation_data->program->external_linkage->ids,object->object->id->data,object->object->id->size);
if(possible_declaration==NULL)
{
if(object->object->linkage==LINKAGE_EXTERNAL)
- Map_Push(translation_data->external_linkage->ids,object->object->id->data,object->object->id->data_size,object);
+ Map_Push(translation_data->program->external_linkage->ids,object->object->id->data,object->object->id->size,object);
else if(object->object->linkage==LINKAGE_INTERNAL)
- Map_Push(translation_data->internal_linkage->ids,object->object->id->data,object->object->id->data_size,object);
+ Map_Push(translation_data->internal_linkage->ids,object->object->id->data,object->object->id->size,object);
}else
{
if(object->initializer!=NULL && possible_declaration->initializer!=NULL)
{
struct AST *possible_declaration;
- possible_declaration=Map_Check(translation_data->external_linkage->ids,function->function->id->data,function->function->id->data_size);
+ possible_declaration=Map_Check(translation_data->program->external_linkage->ids,function->function->id->data,function->function->id->size);
if(function->function->linkage==LINKAGE_EXTERNAL)
- Map_Push(translation_data->external_linkage->ids,function->function->id->data,function->function->id->data_size,function);
+ Map_Push(translation_data->program->external_linkage->ids,function->function->id->data,function->function->id->size,function);
else
- Map_Push(translation_data->internal_linkage->ids,function->function->id->data,function->function->id->data_size,function);
+ Map_Push(translation_data->internal_linkage->ids,function->function->id->data,function->function->id->size,function);
if(possible_declaration!=NULL)
{
void push_function_declaration_into_linkage(struct Translation_Data *translation_data,struct AST_Function_Declaration *function)
{
struct AST *possible_definition;
- possible_definition=Map_Check(translation_data->external_linkage->ids,function->function->id->data,function->function->id->data_size);
+ possible_definition=Map_Check(translation_data->program->external_linkage->ids,function->function->id->data,function->function->id->size);
if(possible_definition==NULL)
{
if(function->function->linkage==LINKAGE_EXTERNAL)
- Map_Push(translation_data->external_linkage->ids,function->function->id->data,function->function->id->data_size,function);
+ Map_Push(translation_data->program->external_linkage->ids,function->function->id->data,function->function->id->size,function);
else
- Map_Push(translation_data->internal_linkage->ids,function->function->id->data,function->function->id->data_size,function);
+ Map_Push(translation_data->internal_linkage->ids,function->function->id->data,function->function->id->size,function);
}
}
#endif
F diff --git a/src/semantics/identifiers/scope.c b/src/semantics/identifiers/scope.c
--- a/src/semantics/identifiers/scope.c
+++ b/src/semantics/identifiers/scope.c
}
- struct Denoted_Statement* check_label(struct Scope *current,struct token *id)
+ struct Denoted_Statement* check_label(struct Scope *current,struct identifier *id)
{
struct Denoted_Statement *hold=NULL;
struct Function_Scope *function_scope;
function_scope=get_enclosing_function_scope(current);
if(function_scope!=NULL)
- hold=Map_Check(function_scope->labels,id->data,id->data_size);
+ hold=Map_Check(function_scope->labels,id->data,id->size);
return hold;
}
case FILE_SCOPE:
case BLOCK_SCOPE:
case FUNCTION_PROTOTYPE_SCOPE:
- hold=Map_Check(((struct Normal_Scope*)current)->tags,id->data,id->data_size);
+ hold=Map_Check(((struct Normal_Scope*)current)->tags,id->data,id->size);
}
current=current->parent;
}
return hold;
}
- void* check_ordinary(struct Scope *current,struct token *id)
+ void* check_ordinary(struct Scope *current,struct identifier *id)
{
void *hold;
hold=NULL;
case FILE_SCOPE:
case BLOCK_SCOPE:
case FUNCTION_PROTOTYPE_SCOPE:
- hold=Map_Check(((struct Normal_Scope*)current)->ordinary,id->data,id->data_size);
+ hold=Map_Check(((struct Normal_Scope*)current)->ordinary,id->data,id->size);
}
current=current->parent;
return hold;
}
- void* check_struct_union_member(struct Normal_Scope *inner,struct token *id)
+ void* check_struct_union_member(struct Normal_Scope *inner,struct identifier *id)
{
- return Map_Check(inner->ordinary,id->data,id->data_size);
+ return Map_Check(inner->ordinary,id->data,id->size);
}
void Scope_Push(struct Scope *scope,struct Denoted *declarator,struct Translation_Data *translation_data)
{
return function_scope->function;
}
- _Bool check_if_typedefed(struct Scope* scope,struct token *id)
+ _Bool check_if_typedefed(struct Scope* scope,struct identifier *id)
{
struct Denoted *hold;
hold=check_ordinary(scope,id);
return 1;
}
- struct Denoted* push_label(struct Scope *current,struct token *label,struct AST *statement,struct Translation_Data *translation_data)
+ struct Denoted* push_label(struct Scope *current,struct identifier *label,struct AST *statement,struct Translation_Data *translation_data)
{
struct Denoted_Statement *hold_statement;
struct Function_Scope *current_function_scope;
current_function_scope=get_enclosing_function_scope(current);
- hold_statement=(struct Denoted_Statement*)Map_Check(current_function_scope->labels,label->data,label->data_size);
+ hold_statement=(struct Denoted_Statement*)Map_Check(current_function_scope->labels,label->data,label->size);
if(hold_statement!=NULL)
{
{
hold_statement=(struct Denoted_Statement*)get_denoted_statement(label,statement,get_last_known_denoted_object((struct Normal_Scope*)current));
- Map_Push(current_function_scope->labels,label->data,label->data_size,hold_statement);
+ Map_Push(current_function_scope->labels,label->data,label->size,hold_statement);
Queue_Push(current_function_scope->label_order,hold_statement);
if(has_new_errors(translation_data) || !constraint_check_object_linkage(denoted_object,hold_previous,current,translation_data) )
{
- translation_data->number_of_errors_when_last_checked--; /*TODO make a new function for this for gods sake*/
+ translation_data->program->number_of_errors_when_last_checked--; /*TODO make a new function for this for gods sake*/
//delete_denoted_object(denoted_object);
}
if(has_new_errors(translation_data) || !constraint_check_function_linkage(denoted_function,hold_previous,current,translation_data))
{
//delete_denoted_function(denoted_function);
- translation_data->number_of_errors_when_last_checked--;
+ translation_data->program->number_of_errors_when_last_checked--;
}
}
- #define CHECK_AND_PUSH(thing,scope) Map_Check_And_Push(scope,thing->id->data,thing->id->data_size,thing)
+ #define CHECK_AND_PUSH(thing,scope) Map_Check_And_Push(scope,thing->id->data,thing->id->size,thing)
void push_typedef(struct Scope *current,struct Translation_Data *translation_data,struct Denoted_Type *denoted_typedef)
{
struct Denoted *hold_denotated;
void push_denoted_enum_tag(struct Scope *current,struct Translation_Data *translation_data,struct Denoted_Enum *denoted_enum)
{
struct Denoted *hold_denotated;
- hold_denotated=Map_Check_And_Push(AS_NORMAL_SCOPE(current)->tags,denoted_enum->enumeration->id->data,denoted_enum->enumeration->id->data_size,denoted_enum);
+ hold_denotated=Map_Check_And_Push(AS_NORMAL_SCOPE(current)->tags,denoted_enum->enumeration->id->data,denoted_enum->enumeration->id->size,denoted_enum);
if(hold_denotated)
{
delete_denoted_enum(denoted_enum);
void push_denoted_struct_union_tag(struct Scope *current,struct Translation_Data *translation_data,struct Denoted_Struct_Union *denoted_struct_union)
{
struct Denoted *hold_denotated;
- hold_denotated=Map_Check_And_Push(AS_NORMAL_SCOPE(current)->tags,denoted_struct_union->struct_union->id->data,denoted_struct_union->struct_union->id->data_size,denoted_struct_union);
+ hold_denotated=Map_Check_And_Push(AS_NORMAL_SCOPE(current)->tags,denoted_struct_union->struct_union->id->data,denoted_struct_union->struct_union->id->size,denoted_struct_union);
if(hold_denotated)
{
delete_denoted_struct_union(denoted_struct_union);
push_translation_error("redefinition of tag",translation_data);
}
}
- void* check_and_push_id(void *data,struct Map *scope_map,struct token *id,struct Translation_Data *translation_data)
+ void* check_and_push_id(void *data,struct Map *scope_map,struct identifier *id,struct Translation_Data *translation_data)
{
- return Map_Check_And_Push(scope_map,id->data,id->data_size,data);
+ return Map_Check_And_Push(scope_map,id->data,id->size,data);
}
#endif
F diff --git a/src/semantics/identifiers/scope.h b/src/semantics/identifiers/scope.h
--- a/src/semantics/identifiers/scope.h
+++ b/src/semantics/identifiers/scope.h
* TODO refactor this into something more sensible
*
* */
- struct Denoted* push_label(struct Scope *current,struct token *label,struct AST *statement,struct Translation_Data *translation_data);
+ struct Denoted* push_label(struct Scope *current,struct identifier *label,struct AST *statement,struct Translation_Data *translation_data);
void push_object(struct Scope *current,struct Translation_Data *translation_data,struct Denoted_Object *denoted_object);
void push_function(struct Scope *current,struct Translation_Data *translation_data,struct Denoted_Function *denoted_function);
- void* check_and_push_id(void *data,struct Map *scope_map,struct token *id,struct Translation_Data *translation_data);
+ void* check_and_push_id(void *data,struct Map *scope_map,struct identifier *id,struct Translation_Data *translation_data);
- _Bool check_if_typedefed(struct Scope* scope,struct token *id);
+ _Bool check_if_typedefed(struct Scope* scope,struct identifier *id);
#endif
F diff --git a/src/semantics/memory/memory_location.c b/src/semantics/memory/memory_location.c
--- a/src/semantics/memory/memory_location.c
+++ b/src/semantics/memory/memory_location.c
- #ifndef WONKY_LOCATION_C
- #define WONKY_LOCATION_C WONKY_LOCATION_C
- #include "location.h"
+ #ifndef WONKY_MEMORY_LOCATION_C
+ #define WONKY_MEMORY_LOCATION_C WONKY_MEMORY_LOCATION_C
+ #include "memory_location.h"
#endif
F diff --git a/src/semantics/memory/memory_location.h b/src/semantics/memory/memory_location.h
--- a/src/semantics/memory/memory_location.h
+++ b/src/semantics/memory/memory_location.h
- #ifndef WONKY_LOCATION_H
- #define WONKY_LOCATION_H WONKY_LOCATION_H
+ #ifndef WONKY_MEMORY_LOCATION_H
+ #define WONKY_MEMORY_LOCATION_H WONKY_MEMORY_LOCATION_H
#include <memory_location.hh>
#include <lexer.h>
#include <type.h>
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
return ret;
}
- struct Translation_Data* get_translation_data(struct Map *types,struct Linkage *internal_linkage,struct Program *program)
+ struct Translation_Data* get_translation_data(struct Preprocessing_Translation_Unit *start_unit,struct Linkage *internal_linkage,struct Program *program)
{
struct Translation_Data *ret;
ret=wonky_malloc(sizeof(struct Translation_Data));
- ret->tokens=wonky_malloc(sizeof(struct Queue));
- ret->errors=wonky_malloc(sizeof(struct Queue));
- ret->source_files=wonky_malloc(sizeof(struct Queue));
- Queue_Init(ret->tokens);
- Queue_Init(ret->errors);
- Queue_Init(ret->source_files);
-
- ret->macros=wonky_malloc(sizeof(struct Map));
- Map_Init(ret->macros);
- ret->types=types;
-
- ret->number_of_errors_when_last_checked=0;
-
- ret->external_linkage=external_linkage;
+ ret->token_pointer=get_token_ptr(start_unit);
+ ret->internal_linkage=internal_linkage;
ret->program=program;
return ret;
}
- struct Source_Name* get_source_name(char *filename,char *base)
- {
- struct Source_Name *ret;
- ret=wonky_malloc(sizeof(struct Source_Name));
- ret->base=gstrcpy(base);
- ret->filename=gstrcpy(filename);
- normalise_source_name(ret);
- return ret;
- }
-
-
struct Program* parse_program(char **base_source_names)
{
struct Source_File *base_file;
struct Program *program;
struct Translation_Data *hold_translation_data;
+ struct Queue_Node *hold_node;
+
char *this_directory[]={"./","",NULL};
wonky_assert(base_source_names!=NULL);
if(*base_source_names==NULL)
- {
return NULL;
- }
program=get_program();
- hold_translation_data=get_translation_data(program->types,get_linkage(),program->external_linkage);
+
do
{
- base_file=get_source_file(*base_source_names,this_directory);
- if(base_file==NULL)
- {
- /*TODO error*/
- wonky_free(base_file);
- continue;
- }else
- {
- Queue_Push(hold_translation_data->source_files,base_file);
- lex(base_file,hold_translation_data);
- if(!has_new_errors(hold_translation_data))
- {
- Queue_Push(program->translation_units,parse_translation_unit(hold_translation_data));
- }else
- {
- flush_tokens(hold_translation_data->tokens);
- }
- assimilate_translation_data(program,hold_translation_data);
- }
- }while(*(++base_source_names));
+ base_file=get_source_file_from_string(*base_source_names,gstrnlen(*base_source_names,1000));
+ lex(base_file,program);
+ }while(*(++base_source_names) != NULL);
+
+ if(program_has_errors(program))
+ return program;
+
+ for(
+ hold_node=program->preprocessing_translation_units_to_be_compiled->first;
+ hold_node!=NULL;
+ hold_node=hold_node->prev
+ )
+ {
+ hold_translation_data=get_translation_data(
+ (struct Preprocessing_Translation_Unit*)hold_node->data,
+ get_linkage(),
+ program);
+
+ Queue_Push(
+ program->translation_units,
+ parse_translation_unit(hold_translation_data)
+ );
+ }
+
find_functions_without_definitions(program);
find_external_objects_without_an_initialiser(program);
- delete_translation_data(hold_translation_data);
return program;
}
- void lex_program(struct Translation_Data *hold,struct Source_File *file)
+
+ _Bool has_new_errors(struct Translation_Data *translation_data)
{
- Queue_Push(hold->source_files,file);
- lex(file,hold);
+ return program_has_new_errors(translation_data->program);
}
-
- _Bool has_new_errors(struct Translation_Data *translation_data)
+ _Bool program_has_new_errors(struct Program *program)
{
- if(translation_data->errors->size != translation_data->number_of_errors_when_last_checked)
+ if(program->errors->size != program->number_of_errors_when_last_checked)
+ {
+ program->number_of_errors_when_last_checked=program->errors->size;
+ return 1;
+ }else
+ {
+ return 0;
+ }
+ }
+ _Bool program_has_errors(struct Program *program)
+ {
+ if(program->errors->size != program->number_of_errors_when_last_checked)
{
- translation_data->number_of_errors_when_last_checked=translation_data->errors->size;
return 1;
}else
{
return 0;
}
}
-
void delete_program(struct Program *program)
{
while(program->translation_units->size>0)
}
void delete_translation_data(struct Translation_Data *translation_data)
{
- wonky_assert(translation_data->tokens->size==0 &&
- translation_data->errors->size==0 &&
- translation_data->source_files->size==0);
- wonky_free(translation_data->tokens);
- wonky_free(translation_data->errors);
- wonky_free(translation_data->source_files);
-
- Map_Map(translation_data->macros,delete_macro);
- Map_Destroy(translation_data->macros);
- wonky_free(translation_data->macros);
-
+ wonky_assert(translation_data->token_pointer!=NULL);
+ delete_token_ptr(translation_data->token_pointer);
wonky_free(translation_data);
}
- void assimilate_translation_data(struct Program *program,struct Translation_Data *translation_data)
- {
- Queue_Append(program->errors,translation_data->errors);
- Queue_Append(program->source_files,translation_data->source_files);
-
- flush_tokens(translation_data->tokens);
-
- Queue_Init(translation_data->errors);
- Queue_Init(translation_data->source_files);
-
- translation_data->number_of_errors_when_last_checked=0;
-
-
- }
_Bool has_no_tokens(struct Translation_Data *translation_data)
{
- return (translation_data->tokens->size)==0;
+ return token_ptr_has_remaining_tokens(translation_data->token_pointer);
}
/*TODO*/
Queue_Push(where_to_push,tree);
}
}
- char check(struct Translation_Data *translation_data,enum LEXER_TYPE kw,size_t ahead)
+ _Bool check(struct Translation_Data *translation_data,enum LEXER_TYPE kw)
{
- size_t i;
- struct Queue_Node *current;
- if(translation_data->tokens->size<=ahead)
+ struct token *hold_token;
+ if(token_ptr_has_remaining_tokens(translation_data->token_pointer))
{
- return 0;
+ hold_token=token_ptr_check_next_normal_token(translation_data->token_pointer);
+
+ return hold_token->type==kw;
}else
{
- for(i=0,current=translation_data->tokens->first;i<ahead;++i,current=current->prev);
-
- if( ((struct token*)(current->data))->type == kw )
- {
- return 1;
- }else
- {
- return 0;
- }
+ return 0;
}
}
- char get_and_check(struct Translation_Data *translation_data,enum LEXER_TYPE kw)
+ _Bool get_and_check(struct Translation_Data *translation_data,enum LEXER_TYPE kw)
{
struct token *hold_token;
- if(translation_data->tokens->size==0)
+ if(token_ptr_has_remaining_tokens(translation_data->token_pointer))
{
return 0;
}else
{
- hold_token=translation_data->tokens->first->data;
+ hold_token=token_ptr_check_next_normal_token(translation_data->token_pointer);
if(hold_token->type!=kw)
{
return 0;
}else
{
- hold_token=Queue_Pop(translation_data->tokens);
- wonky_free(hold_token);
+ (void)get_next_token(translation_data);
return 1;
}
}
}
- char get_and_check_unsafe(struct Translation_Data *translation_data,enum LEXER_TYPE kw)
+ _Bool get_and_check_unsafe(struct Translation_Data *translation_data,enum LEXER_TYPE kw)
{
- struct token *hold_token;
- hold_token=translation_data->tokens->first->data;
- if(hold_token->type!=kw)
- {
- return 0;
- }else
- {
- hold_token=Queue_Pop(translation_data->tokens);
- wonky_free(hold_token);
- return 1;
- }
+ return get_and_check(translation_data,kw);
}
void chomp(struct Translation_Data *translation_data)
{
- wonky_free(Queue_Pop(translation_data->tokens));
+ (void)get_next_token(translation_data);
}
enum LEXER_TYPE kw_get(struct Translation_Data *translation_data)
{
- if(translation_data->tokens->size==0)
- return KW_NOTYPE;
- return ((struct token*)(translation_data->tokens->first->data))->type;
+ struct token *hold_token;
+ if(token_ptr_has_remaining_tokens(translation_data->token_pointer))
+ {
+ return 0;
+ }else
+ {
+ hold_token=token_ptr_check_next_normal_token(translation_data->token_pointer);
+ return hold_token->type;
+ }
}
- void flush_tokens(struct Queue *tokens)
- {
- while(tokens->size>0)
- wonky_free(Queue_Pop(tokens));
- }
#endif
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.h
#include <common.h>
#include <ast.h>
#include <wonky_malloc.h>
+ #include <translation_unit.h>
struct Program
struct Queue *translation_units;
struct Queue *source_files;
+
struct Queue *errors;
+ size_t number_of_errors_when_last_checked;
/*
the type node structures from
struct Translation_Data
{
struct Token_Pointer *token_pointer;
-
-
- struct Queue *errors;
- size_t number_of_errors_when_last_checked;
-
-
- struct Queue *source_files;
-
- struct Map *macros;
-
struct Linkage *internal_linkage;
-
struct Program *program;
};
struct Program* get_program();
- struct Translation_Data* get_translation_data(struct Map *types,struct Linkage *internal_linkage,struct Program *program);
+ struct Translation_Data* get_translation_data(struct Preprocessing_Translation_Unit *start_unit,struct Linkage *internal_linkage,struct Program *program);
struct Program* parse_program(char **base_source_names);
- void lex_program(struct Translation_Data *hold,struct Source_File *file);
void entype_program(struct Program *program);
_Bool has_new_errors(struct Translation_Data *translation_data);
_Bool has_no_tokens(struct Translation_Data *translation_data);
+ _Bool program_has_new_errors(struct Program *program);
+ _Bool program_has_errors(struct Program *program);
+
+
void delete_program(struct Program *program);
void delete_translation_data(struct Translation_Data *translation_data);
void destroy_translation_data(struct Translation_Data *translation_data);
- void assimilate_translation_data(struct Program *program,struct Translation_Data *translation_data);
void find_functions_without_definitions(struct Program *program);
void find_external_objects_without_an_initialiser(struct Program *program);
void push_if_tree_is_undefined_function(struct AST *tree,struct Queue *where_to_push);
void push_if_tree_is_uninitialised_object(struct AST *tree,struct Queue *where_to_push);
- char check(struct Translation_Data *translation_data,enum LEXER_TYPE kw,size_t ahead);
- char get_and_check(struct Translation_Data *translation_data,enum LEXER_TYPE kw);
- char get_and_check_unsafe(struct Translation_Data *translation_data,enum LEXER_TYPE kw);
+ _Bool check(struct Translation_Data *translation_data,enum LEXER_TYPE kw);
+ _Bool get_and_check(struct Translation_Data *translation_data,enum LEXER_TYPE kw);
+ _Bool get_and_check_unsafe(struct Translation_Data *translation_data,enum LEXER_TYPE kw);
void chomp(struct Translation_Data *translation_data);
enum LEXER_TYPE kw_get(struct Translation_Data *translation_data);
struct token* get_next_token(struct Translation_Data *translation_data);
+ _Bool translation_eof(struct Translation_Data *translation_data);
- void flush_tokens(struct Queue *tokens);
#endif
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
void push_token_into_preprocessing_translation_unit(struct Preprocessing_Translation_Unit *unit,struct token *token);
struct token* token_ptr_get_token_under_pointer(struct Token_Pointer *token_pointer);
+ struct token* token_ptr_check_next_normal_token(struct Token_Pointer *token_pointer);
void token_ptr_goto_next_token(struct Token_Pointer *token_pointer);
struct Token_Pointer* get_token_ptr(struct Preprocessing_Translation_Unit *unit);
+ void delete_token_ptr(struct Token_Pointer *ptr);
+
+ _Bool token_ptr_has_remaining_tokens(struct Token_Pointer *ptr);
+
+
+ void token_ptr_unget_token(struct Token_Pointer *ptr,struct token *token);
+
void token_ptr_execute_include_directive(struct Token_Pointer *ptr,struct token_include_directive *include_directive);
void token_ptr_execute_if_directive(struct Token_Pointer *ptr,struct token_if_directive *if_directive);
F diff --git a/src/semantics/value/constant.c b/src/semantics/value/constant.c
--- a/src/semantics/value/constant.c
+++ b/src/semantics/value/constant.c
wonky_free(constant);
}
- /*TODO*/
- struct Constant* extract_constant(struct token *token,struct Translation_Data *translation_data)
- {
- return extract_literal_integer_dec(token,translation_data);
- }
- struct Constant* extract_literal_integer_dec(struct token *token,struct Translation_Data *translation_data)
- {
- /*the sign is acounted for during parsing ( not lexing )*/
- unsigned long long int cache=0;
- unsigned long long int *ret_component;
- struct Constant *ret;
- size_t i;
-
- ret_component=wonky_malloc(sizeof(unsigned long long int));
- ret=wonky_malloc(sizeof(struct Constant));
-
- for(i=0;i<token->data_size;++i)
- cache*=10 , cache+=token->data[i]-'0';
-
- *ret_component=cache;
- ret->value=ret_component;
- ret->type=(struct Type*)get_type_insecure(TS_INT,TSIGN_NONE,TC_NONE,INT_SIZE,translation_data);
-
- return ret;
-
- }
-
- struct Constant* extract_literal_integer_octal(struct token *token,struct Translation_Data *translation_data)
+ struct Constant* extract_literal_integer_octal(char *data,size_t data_size,enum Type_Constraint constraint,enum Type_Signedness sign)
{
unsigned long long int cache=0;
unsigned long long int *ret_component;
ret_component=wonky_malloc(sizeof(unsigned long long int));
ret=wonky_malloc(sizeof(struct Constant));
- for(i=0;i<token->data_size;++i)
- cache*=8 , cache+=token->data[i]-'0';
+ for(i=0;i<data_size;++i)
+ cache*=8 , cache+=data[i]-'0';
*ret_component=cache;
ret->value=ret_component;
- ret->type=(struct Type*)get_type_insecure(TS_INT,TSIGN_NONE,TC_NONE,INT_SIZE,translation_data);
+ ret->type=(struct Type*)get_type_insecure(TS_INT,sign,constraint,INT_SIZE);
return ret;
}
- struct Constant* extract_literal_integer_hex(struct token *token,struct Translation_Data *translation_data)
+ struct Constant* extract_literal_integer_hex(char *data,size_t data_size,enum Type_Constraint constraint,enum Type_Signedness sign)
{
unsigned long long int cache=0;
unsigned char digit;
ret=wonky_malloc(sizeof(struct Constant));
/* skip the leading 0x */
- for(i=2;i<token->data_size;++i)
- {
- if(token->data[i]<='9')
- digit=token->data[i]-'0';
- else if(token->data[i]<='f' && token->data[i]>='a')
- digit=10+(token->data[i]-'a');
+ for(i=2;i<data_size;++i) {
+ if(data[i]<='9')
+ digit=data[i]-'0';
+ else if(data[i]<='f' && data[i]>='a')
+ digit=10+(data[i]-'a');
else
- digit=10+(token->data[i]-'A');
+ digit=10+(data[i]-'A');
cache|=digit,cache<<=4;
}
*ret_component=cache;
ret->value=ret_component;
- ret->type=(struct Type*)get_type_insecure(TS_INT,TSIGN_NONE,TC_NONE,INT_SIZE,translation_data);
+ ret->type=(struct Type*)get_type_insecure(TS_INT,sign,constraint,INT_SIZE);
return ret;
}
/*Various flavours of TODO*/
- struct Constant* extract_literal_double_dec(struct token *token,struct Translation_Data *translation_data)
+ struct Constant* extract_literal_double_dec(char *data,size_t data_size,enum Type_Constraint constraint)
{
long double *ret_component;
struct Constant *ret;
*ret_component=.0l;
ret->value=ret_component;
- ret->type=(struct Type*)get_type_insecure(TS_DOUBLE,TSIGN_NONE,TC_NONE,DOUBLE_SIZE,translation_data);
+ ret->type=(struct Type*)get_type_insecure(TS_DOUBLE,TSIGN_NONE,constraint,DOUBLE_SIZE);
return ret;
}
- struct Constant* extract_literal_double_hex(struct token *token,struct Translation_Data *translation_data)
+ struct Constant* extract_literal_double_hex(char *data,size_t data_size,enum Type_Constraint constraint)
{
long double *ret_component;
struct Constant *ret;
*ret_component=.0l;
ret->value=ret_component;
- ret->type=(struct Type*)get_type_insecure(TS_DOUBLE,TSIGN_NONE,TC_NONE,DOUBLE_SIZE,translation_data);
+ ret->type=(struct Type*)get_type_insecure(TS_DOUBLE,TSIGN_NONE,constraint,DOUBLE_SIZE);
return ret;
}
- struct Constant* extract_literal_char(struct token *token,struct Translation_Data *translation_data)
+ struct Constant* extract_literal_char(char *data,size_t data_size)
{
char *ret_component;
struct Constant *ret;
ret_component=wonky_malloc(sizeof(char));
ret=wonky_malloc(sizeof(struct Constant));
- *ret_component=token->data[1];
+ *ret_component=data[1];
ret->value=ret_component;
- ret->type=(struct Type*)get_type_insecure(TS_CHAR,TSIGN_NONE,TC_NONE,CHAR_SIZE,translation_data);
+ ret->type=(struct Type*)get_type_insecure(TS_CHAR,TSIGN_NONE,TC_NONE,CHAR_SIZE);
return ret;
}
/*TODO make wide*/
- struct Constant* extract_literal_wide_char(struct token *token,struct Translation_Data *translation_data)
+ struct Constant* extract_literal_wide_char(char *data,size_t data_size)
{
char *ret_component;
struct Constant *ret;
ret_component=wonky_malloc(sizeof(char));
ret=wonky_malloc(sizeof(struct Constant));
- *ret_component=token->data[1];
+ *ret_component=data[1];
ret->value=ret_component;
- ret->type=(struct Type*)get_type_insecure(TS_CHAR,TSIGN_NONE,TC_NONE,CHAR_SIZE,translation_data);
+ ret->type=(struct Type*)get_type_insecure(TS_CHAR,TSIGN_NONE,TC_NONE,CHAR_SIZE);
return ret;
}
- struct Constant* extract_enum_constant(struct Denoted_Enum_Const *constant,struct Translation_Data *translation_data)
+ struct Constant* extract_enum_constant(struct Denoted_Enum_Const *constant)
{
struct Constant *ret;
ret=wonky_malloc(sizeof(struct Constant));
ret->value=wonky_malloc(sizeof(int));
*((int*)ret->value)=constant->value;
- ret->type=(struct Type*)get_type_insecure(INT_SIZE,TSIGN_NONE,TC_NONE,INT_SIZE,translation_data);
+ ret->type=(struct Type*)get_type_insecure(INT_SIZE,TSIGN_NONE,TC_NONE,INT_SIZE);
return ret;
return tree->type==OP_CONSTANT &&
constant_is_null_pointer(AS_EXPRESSION_VALUE_CONSTANT(AS_AST_CONSTANT(tree)->value)->constant);
}
- struct Constant* extract_literal_string(struct token *token,struct Translation_Data *translation_data)
+ struct Constant* extract_literal_string(char *data,size_t data_size)
{
char *ret_component;
struct Constant *ret;
ret=wonky_malloc(sizeof(struct Constant));
- ret_component=gstrncpy(token->data+1,token->data_size-2);
+ ret_component=gstrncpy(data+1,data_size-2);
ret->value=ret_component;
- ret->type=(struct Type*)get_type_insecure(TS_CHAR,TSIGN_NONE,TC_NONE,CHAR_SIZE,translation_data);
- ret->type=get_array_type_raw(ret->type,token->data_size,translation_data);
+ ret->type=(struct Type*)get_type_insecure(TS_CHAR,TSIGN_NONE,TC_NONE,CHAR_SIZE);
+ ret->type=get_array_type_raw(ret->type,data_size);
return ret;
}
/*TODO*/
- struct Constant* extract_literal_wide_string(struct token *token,struct Translation_Data *translation_data)
+ struct Constant* extract_literal_wide_string(char *data,size_t data_size)
{
char *ret_component;
struct Constant *ret;
ret=wonky_malloc(sizeof(struct Constant));
- ret_component=gstrncpy(token->data+1,token->data_size-2);
+ ret_component=gstrncpy(data+1,data_size-2);
ret->value=ret_component;
- ret->type=(struct Type*)get_type_insecure(TS_CHAR,TSIGN_NONE,TC_NONE,CHAR_SIZE,translation_data);
- ret->type=get_array_type_raw(ret->type,token->data_size,translation_data);
+ ret->type=(struct Type*)get_type_insecure(TS_CHAR,TSIGN_NONE,TC_NONE,CHAR_SIZE);
+ ret->type=get_array_type_raw(ret->type,data_size);
return ret;
}
F diff --git a/src/semantics/value/constant.h b/src/semantics/value/constant.h
--- a/src/semantics/value/constant.h
+++ b/src/semantics/value/constant.h
void *value;
};
- struct Constant* extract_constant(enum LEXER_TYPE bare_type,char *data,size_t data_size,struct Translation_Data *translation_data);
- struct Constant* extract_literal_integer_octal(char *data,size_t data_size,struct Translation_Data *translation_data);
- struct Constant* extract_literal_integer_dec(char *data,size_t data_size,struct Translation_Data *translation_data);
- struct Constant* extract_literal_integer_hex(char *data,size_t data_size,struct Translation_Data *translation_data);
- struct Constant* extract_literal_double_dec(char *data,size_t data_size,struct Translation_Data *translation_data);
- struct Constant* extract_literal_double_hex(char *data,size_t data_size,struct Translation_Data *translation_data);
- struct Constant* extract_literal_char(char *data,size_t data_size,struct Translation_Data *translation_data);
- struct Constant* extract_literal_wide_char(char *data,size_t data_size,struct Translation_Data *translation_data);
- struct Constant* extract_enum_constant(struct Denoted_Enum_Const *constant,struct Translation_Data *translation_data);
- struct Constant* extract_literal_string(char *data,size_t data_size,struct Translation_Data *translation_data);
- struct Constant* extract_literal_wide_string(char *data,size_t data_size,struct Translation_Data *translation_data);
+ struct Constant* extract_literal_integer_octal(char *data,size_t data_size,enum Type_Constraint constraint,enum Type_Signedness sign);
+ struct Constant* extract_literal_integer_dec(char *data,size_t data_size,enum Type_Constraint constraint,enum Type_Signedness sign);
+ struct Constant* extract_literal_integer_hex(char *data,size_t data_size,enum Type_Constraint constraint,enum Type_Signedness sign);
+ struct Constant* extract_literal_double_dec(char *data,size_t data_size,enum Type_Constraint constraint);
+ struct Constant* extract_literal_double_hex(char *data,size_t data_size,enum Type_Constraint constraint);
+
+ struct Constant* extract_literal_float_dec(char *data,size_t data_size);
+ struct Constant* extract_literal_float_hex(char *data,size_t data_size);
+
+ struct Constant* extract_literal_char(char *data,size_t data_size);
+ struct Constant* extract_literal_wide_char(char *data,size_t data_size);
+ struct Constant* extract_enum_constant(struct Denoted_Enum_Const *constant);
+ struct Constant* extract_literal_string(char *data,size_t data_size);
+ struct Constant* extract_literal_wide_string(char *data,size_t data_size);
F diff --git a/src/semantics/value/type.c b/src/semantics/value/type.c
--- a/src/semantics/value/type.c
+++ b/src/semantics/value/type.c
#define WONKY_TYPE_C WONKY_TYPE_C
#include "type.h"
-
-
- struct Type* type_check_and_push(struct Type *type,struct Map *base,size_t struct_size,struct Translation_Data *translation_data)
- {
- struct Map *hold_node;
- hold_node=Map_Check_And_Get(base,type,struct_size);
-
- if(hold_node==NULL)
- {
- type->node=Map_Push_And_Get(base,type,struct_size,type);
- return type;
- }else
- {
- wonky_free(type);
-
- wonky_assert(is_valid_type((struct Type*)hold_node->ID));
- return (struct Type*)hold_node->ID;
- }
- }
-
- struct Type* get_type_error(struct Type *type,struct Translation_Data *translation_data)
+ struct Type* get_type_error(struct Type *type)
{
struct Type_Error *ret;
ret=wonky_calloc(1,sizeof(struct Type_Error));
+
ret->specifier=TS_ERROR;
ret->error=type;
- if(type!=NULL)
- ret=(struct Type_Error*)type_check_and_push((struct Type*)ret,type->node,sizeof(struct Type_Error),translation_data);
- wonky_assert(is_valid_type_error(ret));
return (struct Type*)ret;
}
- struct Type* get_struct_union_type(struct Denotation_Prototype *prototype,struct Translation_Data *translation_data)
+ struct Type* get_struct_union_type(struct Denotation_Prototype *prototype)
{
struct Type_Struct_Union *ret;
ret->is_const=prototype->is_const;
ret->is_volatile=prototype->is_volatile;
- ret=(struct Type_Struct_Union*)type_check_and_push((struct Type*)ret,prototype->node,sizeof(struct Type_Struct_Union),translation_data);
if(prototype->constraint!=TC_NONE || prototype->sign!=TSIGN_NONE || (prototype->specifier!=TS_UNION && prototype->specifier!=TS_STRUCT))
{
- return get_type_error((struct Type*)ret,translation_data);
+ return get_type_error((struct Type*)ret);
}else
{
- wonky_assert(is_valid_type_struct(ret) || is_valid_type_union(ret));
return (struct Type*)ret;
}
}
- struct Struct_Union* get_struct_union_base(struct Scope *scope ,enum Type_Specifier struct_or_union,struct token *id)
+ struct Struct_Union* get_struct_union_base(struct Scope *scope ,enum Type_Specifier struct_or_union,struct identifier *id)
{
struct Struct_Union *ret;
ret->has_constant_member=0;
ret->id=id;
- wonky_assert(is_valid_struct_union(ret));
return ret;
}
- struct Enum *get_enum_base(struct token *id)
+ struct Enum *get_enum_base(struct identifier *id)
{
struct Enum *ret;
ret=wonky_malloc(sizeof(struct Enum));
return ret;
}
- struct Type* get_basic_type(struct Denotation_Prototype *prototype,struct Translation_Data *translation_data)
+ struct Type* get_basic_type(struct Denotation_Prototype *prototype)
{
struct Type_Basic *ret;
ret=wonky_calloc(1,sizeof(struct Type_Basic));
- wonky_assert(prototype->denotation=DT_Prototype);
+ wonky_assert(prototype->denotation==DT_Prototype);
prototype->denotation=DT_Object;
ret->size=prototype->size;
}
- ret=(struct Type_Basic*)type_check_and_push((struct Type*)ret,prototype->node,sizeof(struct Type_Basic),translation_data);
-
switch(ret->specifier)
{
case TS_DOUBLE:
|| prototype->constraint==TC_SHORT
|| prototype->sign!=TSIGN_NONE)
{
- return get_type_error((struct Type*)ret,translation_data);
+ return get_type_error((struct Type*)ret);
}
break;
case TS_CHAR:
if(prototype->constraint!=TC_NONE)
{
- return get_type_error((struct Type*)ret,translation_data);
+ return get_type_error((struct Type*)ret);
}
break;
case TS_INT:
default:
if(prototype->constraint!=TC_NONE || prototype->sign!=TSIGN_NONE)
{
- return get_type_error((struct Type*)ret,translation_data);
+ return get_type_error((struct Type*)ret);
}
}
- wonky_assert(is_valid_type_basic(ret));
return (struct Type*)ret;
}
- struct Type* get_pointer_type(struct Type *points_to,_Bool is_const,_Bool is_volatile,struct Translation_Data *translation_data)
+ struct Type* get_pointer_type(struct Type *points_to,_Bool is_const,_Bool is_volatile)
{
struct Type_Pointer *ret;
ret=wonky_calloc(1,sizeof(struct Type_Pointer));
ret->is_const=is_const;
ret->is_volatile=is_volatile;
- ret=(struct Type_Pointer*)type_check_and_push((struct Type*)ret,points_to->node,sizeof(struct Type_Pointer),translation_data);
-
- wonky_assert(is_valid_type_pointer(ret));
return (struct Type*)ret;
}
ret->number_of_elements=0;
}
ret->is_array_of=array_of;
- ret=(struct Type_Array*)type_check_and_push((struct Type*)ret,array_of->node,sizeof(struct Type_Array),translation_data);
- wonky_assert(is_valid_type_array(ret));
return (struct Type*)ret;
}
- struct Type* get_array_type_raw(struct Type *array_of,size_t size,struct Translation_Data *translation_data)
+ struct Type* get_array_type_raw(struct Type *array_of,size_t size)
{
struct Type_Array *ret;
ret=wonky_calloc(1,sizeof(struct Type_Array));
ret->specifier=TS_ARRAY;
ret->size=size;
ret->is_array_of=array_of;
- ret=(struct Type_Array*)type_check_and_push((struct Type*)ret,array_of->node,sizeof(struct Type_Array),translation_data);
- wonky_assert(is_valid_type_array(ret));
return (struct Type*)ret;
}
- struct Type* get_enum_type(struct Denotation_Prototype *prototype,struct Translation_Data *translation_data)
+ struct Type* get_enum_type(struct Denotation_Prototype *prototype)
{
struct Type_Enum *ret;
- wonky_assert(prototype->denotation=DT_Prototype);
+ wonky_assert(prototype->denotation==DT_Prototype);
prototype->denotation=DT_Object;
ret=wonky_calloc(1,sizeof(struct Type_Enum));
ret->is_const=prototype->is_const;
ret->is_volatile=prototype->is_volatile;
- ret=(struct Type_Enum*)type_check_and_push((struct Type*)ret,prototype->node,sizeof(struct Type_Enum),translation_data);
if(prototype->sign!=TSIGN_NONE || prototype->constraint!=TC_NONE)
{
- return get_type_error((struct Type*)ret,translation_data);
+ return get_type_error((struct Type*)ret);
}
- wonky_assert(is_valid_type_enum(ret));
return (struct Type*)ret;
}
ret->arguments[i]=(struct Denoted_Object*)Queue_Pop(parameters);
}
wonky_free(parameters);
- ret=(struct Type_Function*)type_check_and_push((struct Type*)ret,return_type->node,sizeof(struct Type_Function),translation_data);
if(is_variadic && ret->number_of_arguments==0)
{
push_translation_error("variadic function needs atleast one named argument",translation_data);
- return (struct Type*)get_type_error((struct Type*)ret,translation_data);
+ return (struct Type*)get_type_error((struct Type*)ret);
}
wonky_assert(is_valid_type_function(ret));
return (struct Type*)ret;
}
- _Bool is_type(struct Translation_Data *translation_data,struct Scope *scope,size_t look_ahead)
+ _Bool rebase_type(struct Type *rebase,struct Type *onto)
+ {
+ switch(rebase->specifier)
+ {
+ case TS_POINTER:
+ ((struct Type_Pointer*)rebase)->points_to=onto;
+ return 1;
+ case TS_ARRAY:
+ ((struct Type_Array*)rebase)->is_array_of=onto;
+ return 1;
+ case TS_VARIABLE_LENGTH_ARRAY:
+ ((struct Type_Variable_Length_Array*)rebase)->is_array_of=onto;
+ return 1;
+ case TS_FUNC:
+ ((struct Type_Function*)rebase)->return_type=onto;
+ default:
+ return 0;
+ }
+ wonky_assert(SHOULD_NOT_REACH_HERE);
+ }
+ _Bool is_type_name(struct Translation_Data *translation_data,struct Scope *scope)
{
struct token *hold;
struct Denoted *thing;
- hold=Queue_At(translation_data->tokens,look_ahead);
-
+ hold=token_ptr_check_next_normal_token(translation_data->token_pointer);
switch(hold->type)
{
case KW_ID:
- thing=check_ordinary(scope,hold);
+ thing=check_ordinary(scope,((struct token_identifier*)hold)->id);
if(thing!=NULL && thing->denotation==DT_Typedef)
return 1;
else return 0;
- struct Type_Basic* get_type_insecure(enum Type_Specifier type_specifier,enum Type_Signedness sign,enum Type_Constraint constraint,size_t type_size,struct Translation_Data *translation_data)
+ struct Type_Basic* get_type_insecure(enum Type_Specifier type_specifier,enum Type_Signedness sign,enum Type_Constraint constraint,size_t type_size)
{
struct Type_Basic *ret;
ret=wonky_calloc(1,sizeof(struct Type_Basic));
ret->constraint=constraint;
ret->sign=sign;
- ret=(struct Type_Basic*)type_check_and_push((struct Type*)ret,translation_data->types,sizeof(struct Type_Basic),translation_data);
-
- wonky_assert(is_valid_type_basic(ret));
return ret;
}
- /*TODO !!!*/
_Bool types_are_identical(struct Type *a,struct Type *b)
{
if(a->specifier!=b->specifier)
if( (a->id==NULL || b->id==NULL ) && b->id!=a->id)
return 0;
- if(a->id!=NULL && !compare_tokens(a->id,b->id))
+ if(a->id!=NULL && a->id!=b->id)
return 0;
if(a->members->size!=b->members->size)
return 0;
return 0;
if((object_a->id==NULL || object_b->id==NULL) && object_b->id!=object_a->id)
return 0;
- if(object_a->id!=NULL && !compare_tokens(object_a->id,object_b->id))
+ if(object_a->id!=NULL && a->id!=b->id)
return 0;
}
return 1;
{
return 1;
}
- struct Type* get_type_for_promotion(struct Type *type,struct Translation_Data *translation_data)
+ struct Type* get_type_for_promotion(struct Type *type)
{
if(type->specifier==TS_CHAR)
{
- return (struct Type*)get_type_insecure(TS_INT,TSIGN_NONE,TC_NONE,INT_SIZE,translation_data);
+ return (struct Type*)get_type_insecure(TS_INT,TSIGN_NONE,TC_NONE,INT_SIZE);
}
else if(type->specifier==TS_INT)
{
struct Type_Basic *cache_type;
cache_type=(struct Type_Basic*)type;
if(cache_type->constraint==TC_SHORT)
- return (struct Type*)get_type_insecure(TS_INT,TSIGN_NONE,TC_NONE,INT_SIZE,translation_data);
+ return (struct Type*)get_type_insecure(TS_INT,TSIGN_NONE,TC_NONE,INT_SIZE);
else
return type;
}
/*TODO*/
- struct Type* get_unqualified_version_of_type(struct Type *type,struct Translation_Data *translation_data)
+ struct Type* get_unqualified_version_of_type(struct Type *type)
{
- struct Denotation_Prototype *prototype;
struct Type *hold_unqualified_type;
- prototype=(struct Denotation_Prototype*)get_denotation_prototype(translation_data->types);
+ return type;
+ /*
switch(type->specifier)
{
case TS_VOID:
case TS_INT:
case TS_FLOAT:
case TS_DOUBLE:
- prototype->specifier=type->specifier;
- hold_unqualified_type=get_basic_type(prototype,translation_data);
+ hold_unqualified_type=type;
break;
case TS_STRUCT:
case TS_UNION:
}
delete_denoted_prototype(prototype);
return hold_unqualified_type;
+ */
}
/*TODO*/
int type_get_integer_conversion_rank(struct Type_Basic *type)
F diff --git a/src/semantics/value/type.h b/src/semantics/value/type.h
--- a/src/semantics/value/type.h
+++ b/src/semantics/value/type.h
struct Type
{
enum Type_Specifier specifier;
- struct Map *node;
};
struct Type_Error
{
enum Type_Specifier specifier;
- struct Map *node;
struct Type *error;
};
struct Type_Struct_Union
{
enum Type_Specifier specifier;
- struct Map *node;
struct Struct_Union *struct_union;
_Bool is_const:1;
struct Struct_Union
{
enum Type_Specifier specifier;
- struct Map *node;
struct identifier *id;
size_t size;
struct Type_Basic
{
enum Type_Specifier specifier;
- struct Map *node;
enum Type_Constraint constraint;
enum Type_Signedness sign;
size_t size;
struct Type_Pointer
{
enum Type_Specifier specifier;
- struct Map *node;
size_t size;
struct Type *points_to;
char is_const:1;
struct Type_Array
{
enum Type_Specifier specifier;
- struct Map *node;
size_t size;
size_t number_of_elements;
struct Type *is_array_of;
struct Type_Variable_Length_Array
{
enum Type_Specifier specifier;
- struct Map *node;
size_t size;
struct AST_Expression *number_of_elements;
struct Type *is_array_of;
struct Type_Function
{
enum Type_Specifier specifier;
- struct Map *node;
struct Type *return_type;
/*types*/
size_t number_of_arguments;
struct Type_Enum
{
enum Type_Specifier specifier;
- struct Map *node;
struct Enum *enumeration;
char is_const:1;
- struct Type* type_check_and_push(struct Type *type,struct Map *base,size_t struct_size,struct Translation_Data *translation_data);
-
-
- struct Type* get_type_error(struct Type *type,struct Translation_Data *translation_data);
- struct Type* get_struct_union_type(struct Denotation_Prototype *prototype,struct Translation_Data *translation_data);
+ struct Type* get_type_error(struct Type *type);
+ struct Type* get_struct_union_type(struct Denotation_Prototype *prototype);
struct Struct_Union* get_struct_union_base(struct Scope *scope ,enum Type_Specifier struct_or_union,struct identifier *id);
struct Enum *get_enum_base(struct identifier *id);
- struct Type* get_basic_type(struct Denotation_Prototype *prototype,struct Translation_Data *translation_data);
- struct Type* get_pointer_type(struct Type *points_to,_Bool is_const,_Bool is_volatile,struct Translation_Data *translation_data);
+ struct Type* get_basic_type(struct Denotation_Prototype *prototype);
+ struct Type* get_pointer_type(struct Type *points_to,_Bool is_const,_Bool is_volatile);
struct Type* get_array_type(struct Type *array_of,struct AST* number_of_elements,struct Translation_Data *translation_data);
- struct Type* get_array_type_raw(struct Type *array_of,size_t size,struct Translation_Data *translation_data);
- struct Type* get_enum_type(struct Denotation_Prototype *prototype,struct Translation_Data *translation_data);
+ struct Type* get_array_type_raw(struct Type *array_of,size_t size);
+ struct Type* get_enum_type(struct Denotation_Prototype *prototype);
struct Type* get_function_type(struct Type *return_type,struct Queue *parameters,struct Normal_Scope* function_prototype_scope,_Bool is_variadic,struct Translation_Data *translation_data);
/*returns 0 if the rebasing of the type makes no sense*/
_Bool rebase_type(struct Type *rebase,struct Type *onto);
- struct Type_Basic* get_type_insecure(enum Type_Specifier type_specifier,enum Type_Signedness sign,enum Type_Constraint constraint,size_t type_size,struct Translation_Data *translation_data);
- struct Type* get_type_for_promotion(struct Type *type,struct Translation_Data *translation_data);
+ struct Type_Basic* get_type_insecure(enum Type_Specifier type_specifier,enum Type_Signedness sign,enum Type_Constraint constraint,size_t type_size);
+ struct Type* get_type_for_promotion(struct Type *type);
- struct Type* get_unqualified_version_of_type(struct Type *type,struct Translation_Data *translation_data);
+ struct Type* get_unqualified_version_of_type(struct Type *type);
void delete_enum(struct Enum *enumeration);
void delete_struct_union(struct Struct_Union *su);
void delete_type(void *type);
- _Bool is_type(struct Translation_Data *translation_data,struct Scope *scope,size_t look_ahead);
+ _Bool is_type_name(struct Translation_Data *translation_data,struct Scope *scope);
size_t get_type_size(struct Type *type);
F diff --git a/src/semantics/value/type.hh b/src/semantics/value/type.hh
--- a/src/semantics/value/type.hh
+++ b/src/semantics/value/type.hh
TS_UNION,
TS_POINTER,
TS_ARRAY,
+ TS_VARIABLE_LENGTH_ARRAY,
TS_FUNC,
TS_NONE,
TS_ERROR,
F diff --git a/src/semantics/value/value.c b/src/semantics/value/value.c
--- a/src/semantics/value/value.c
+++ b/src/semantics/value/value.c
struct Expression_Value_Void *ret;
ret=wonky_malloc(sizeof(struct Expression_Value_Void));
ret->type=VALUE_VOID;
- ret->void_type=(struct Type*)get_type_insecure(TS_VOID,TSIGN_NONE,TC_NONE,0,translation_data);
+ ret->void_type=(struct Type*)get_type_insecure(TS_VOID,TSIGN_NONE,TC_NONE,0);
wonky_assert(is_valid_value((struct Expression_Value*)ret));
return (struct Expression_Value*)ret;
F diff --git a/src/syntax/automatas/automata.hh b/src/syntax/automatas/automata.hh
--- a/src/syntax/automatas/automata.hh
+++ b/src/syntax/automatas/automata.hh
KW_DOUBLE_HEXADECIMAL_CONSTANT,
KW_LONG_DOUBLE_HEXADECIMAL_CONSTANT,
KW_FLOAT_HEXADECIMAL_CONSTANT,
+ KW_CONSTANT,
KW_COMMENT,
KW_ID,
KW_CHAR_CONSTANT,
F diff --git a/src/syntax/source_file.c b/src/syntax/source_file.c
--- a/src/syntax/source_file.c
+++ b/src/syntax/source_file.c
#include <source_file.h>
char *well_known_locations_base[]={"","/usr/include/","/usr/include/x86_64-linux-gnu/",NULL};
- struct Source_File* extract_source_file(FILE *in,struct Source_Name *name)
+ /*TODO this is not giving correct results, but was left as it is because of time constraits*/
+ struct Source_File* get_source_file_from_string(char *filename,size_t filename_size)
{
- long file_size;
- struct Source_File *src;
+ struct Source_Name *src_name;
+ struct Source_File *ret;
+ FILE *file;
+ src_name=get_source_name_from_string(filename,filename_size);
+ ret=wonky_malloc(sizeof(struct Source_File));
+ ret->src_name=src_name;
- if(fseek(in,0,SEEK_END)==-1)
- return NULL;
- if((file_size=ftell(in))==-1)
- return NULL;
- if(fseek(in,0,SEEK_SET)==-1)
- return NULL;
+ file=fopen(filename,"r");
+ if(file==NULL)
+ {
+ filename[filename_size-1]='\0';
+ hard_error("Could not open file %s",filename);
+
+ ret->src="";
+ ret->src_size=0;
+ return ret;
+ }
+ fseek(file,0,SEEK_END);
- src=wonky_malloc(sizeof(struct Source_File));
+ ret->src_size=ftell(file);
- src->src_name=name;
+ rewind(file);
- src->src=wonky_malloc(file_size+1);
- src->src_size=file_size;
+ ret->src=wonky_malloc(ret->src_size);
- src->where_in_src=0;
+ fread(ret->src,1,ret->src_size,file);
+ fclose(file);
- src->which_column=0;
- src->which_row=0;
- src->is_in_the_begining_of_line=1;
- src->src[file_size]='\0';
+ ret->type=SOURCE_TEXT_FULL_TEXT;
+
+ return ret;
+ }
+ struct Source_Name* get_source_name_from_string(char *filename,size_t filename_size)
+ {
+ size_t which_base;
+ which_base=0;
- fread(src->src,1,file_size,in);
- fclose(in);
- return src;
+ }
+ struct Source_Name* get_source_name_from_string_inner(char *filename,size_t filename_size)
+ {
+ struct Source_Name *ret;
+ ret=wonky_malloc(sizeof(struct Source_Name));
+ return ret;
}
/*this might cause compatability issues TODO*/
void normalise_source_name(struct Source_Name *name)
}
- /*here be dragons*/
- char src_getc(struct Source_File *src,char skip_line_splice,char skip_comments,char skip_new_line)
- {
- superhack:
- if(src->src[src->where_in_src]=='\\' && skip_line_splice)
- {
- if(src->where_in_src < src->src_size-1 && src->src[src->where_in_src+1]=='\n')
- {
- src->where_in_src+=2;
- ++src->which_row;
- src->token_size+=2;
- src->which_column=0;
- goto superhack;
- }else
- {
- ++src->token_size;
- ++src->which_column;
- ++src->where_in_src;
- src->is_in_the_begining_of_line=0;
- return '\\';
- }
- }else
- {
- if(src->src[src->where_in_src]=='\n' && skip_new_line)
- {
- ++src->which_row;
- src->which_column=0;
- src->is_in_the_begining_of_line=1;
-
- ++src->where_in_src;
- goto superhack;
- }else if(src->src[src->where_in_src]=='/' && skip_comments)
- {
- if(src->src[src->where_in_src+1]=='*')
- {
- char hold_char;
-
-
- src->where_in_src+=2;
- hold_char=src_getc(src,1,0,1);
- while(hold_char)
- {
- if(hold_char=='*')
- {
- hold_char=src_getc(src,1,0,1);
- if(hold_char=='\0')
- {
- src->where_in_src=src->src_size;
- return '\0';
- }
- else if(hold_char=='/')
- {
- goto superhack;
- }
- }else
- {
- hold_char=src_getc(src,1,0,1);
- }
- }
- src->where_in_src=src->src_size;
- return '\0';
-
- }
- }else
- {
- ++src->which_column;
- }
- ++src->token_size;
- if(src->src[src->where_in_src]!='#' || src->is_in_the_begining_of_line!=1)
- src->is_in_the_begining_of_line=0;
- if(src->src[src->where_in_src]=='\n')
- {
- return '\n';
- }
-
- if(src->src[src->where_in_src]=='\0')
- return src->src[src->where_in_src];
- else
- return src->src[src->where_in_src++];
- }
- }
- void src_ungetc(struct Source_File *src)
- {
- --src->where_in_src;
- if(src->src[src->where_in_src]=='\n')
- {
- --src->which_row;
- src->which_column=0;
- }
- }
- struct token* src_extract_token(struct Source_File *src,enum LEXER_TYPE kw)
- {
- struct token *ret;
- ret=wonky_malloc(sizeof(struct token));
- ret->type=kw;
-
- ret->data_size=src->best_token_size;
- ret->column=src->best_token_column;
- ret->line=src->best_token_line;
- ret->data=src->src+src->best_token_where_in_src_start;
- ret->filename=src->src_name->filename;
- handle_splicing(ret);
- src->where_in_src=src->best_token_where_in_src_end;
- src->is_in_the_begining_of_line=src->best_token_beg_line;
- return ret;
- }
-
- void src_reset_token_data(struct Source_File *src,char use_src_as_base)
- {
- src->token_size=0;
- src->best_token_size=0;
- src->best_token_line=src->which_row;
- src->best_token_column=src->which_column;
- if(use_src_as_base)
- {
- src->best_token_where_in_src_end=src->where_in_src;
- }else
- {
- src->where_in_src=src->best_token_where_in_src_end;
- }
- src->best_token_where_in_src_start=src->where_in_src;
- }
- void src_assimilate_into_best_token(struct Source_File *src)
- {
- src->best_token_size=src->token_size;
- src->best_token_line=src->which_row;
- src->best_token_column=src->which_column;
- src->best_token_where_in_src_end=src->where_in_src;
- src->best_token_beg_line=src->is_in_the_begining_of_line;
- }
- void delete_source_file(struct Source_File *src)
- {
- delete_source_name(src->src_name);
- wonky_free(src->src);
- wonky_free(src);
- }
- void delete_source_name(struct Source_Name *name)
- {
- wonky_free(name->filename);
- wonky_free(name->base);
- wonky_free(name);
- }
- void goto_new_line(struct Source_File *src,struct Translation_Data *translation_data)
- {
- char hold_char;
- while( (hold_char=src_getc(src,1,1,0)) != '\0' && hold_char != '\n');
- src->is_in_the_begining_of_line=1;
- ++src->where_in_src;
- ++src->which_row;
- src->which_column=0;
- }
- void chase_new_line(struct Source_File *src,struct Translation_Data *translation_data)
- {
- char hold_char;
- for(hold_char=src_getc(src,1,1,0);hold_char!='\n' && hold_char!='\0';
- hold_char=src_getc(src,1,1,0));
-
- ++src->where_in_src;
- ++src->which_row;
- src->is_in_the_begining_of_line=1;
- src->which_column=0;
-
-
- }
- /*returns the number of bytes skipped*/
- size_t skip_line_splice(struct Source_File *src)
- {
- size_t current_size=0;
- while(src->where_in_src<src->src_size-1 && src->src[src->where_in_src]=='\\' && src->src[src->where_in_src+1]=='\n')
- {
- src->where_in_src+=2;
- current_size+=2;
- }
- return current_size;
- }
-
- void skip_white_space(struct Source_File *src,char skip_new_line)
- {
- char hold_char;
- while(hold_char=src_getc(src,1,1,skip_new_line))
- {
- if(hold_char=='\n' && !skip_new_line)
- {
- return ;
- }
- if(hold_char!=' ' && hold_char!='\t')
- {
- src_ungetc(src);
- return ;
- }
- }
- }
- /*where_to_search ends in a NULL pointer*/
- struct Source_File* get_source_file(struct Source_Name *name,struct Protram *program)
- {
- FILE *in;
- char *temp_name;
- char is_directory=0;
- struct Source_Name *name;
- struct Source_File *file;
-
- wonky_assert(where_to_search!=NULL);
- wonky_assert(*where_to_search!=NULL);
- do
- {
- temp_name=gstr_append(*where_to_search,filename);
- in=fopen(temp_name,"r");
- wonky_free(temp_name);
- if(in==NULL)
- continue;
-
- name=get_source_name(filename,*where_to_search);
- file=extract_source_file(in,name);
- if(file!=NULL)
- {
- return file;
- }else
- {
- delete_source_name(name);
- }
- }while(*(++where_to_search));
- return NULL;
- }
#endif
F diff --git a/src/syntax/source_file.h b/src/syntax/source_file.h
--- a/src/syntax/source_file.h
+++ b/src/syntax/source_file.h
#include <stdio.h>
#include <automata.h>
#include <gcc_string.h>
+ #include <translation_unit.h>
+ #include <gcc_error.h>
+
extern char *well_known_locations_base[];
struct Source_Name
{
char *filename;
char *base;
- char *normalised_name;
+ char *full_name;
size_t filename_size;
size_t base_size;
- size_t normalised_name_size;
+ size_t full_name_size;
};
struct Source_Location
{
};
struct Source_File* extract_source_file(FILE *in,struct Source_Name *name);
- struct Source_File* get_source_file(struct Source_Name *name,struct Program *program);
- struct Source_Name* get_source_name(char *filename,struct Program *program);
+
+ struct Source_File* get_source_file_from_tokens(struct Token_Pointer *ptr);
+ struct Source_File* get_source_file_from_string(char *filename,size_t filename_size);
+
+ struct Source_Name* get_source_name_from_string(char *unprocessed_filename,size_t filename_size);
+ struct Source_Name* get_source_name_from_tokens(struct Token_Pointer *ptr);
+
struct Source_Location* get_source_location(size_t line,size_t column,size_t on_which_byte,struct Source_Name *src_name);
void normalise_source_name(struct Source_Name *name);
- char src_getc(struct Source_File *src,char skip_line_splice,char skip_comments,char skip_new_line);
- void src_ungetc(struct Source_File *src);
- struct token* src_extract_token(struct Source_File *src,enum LEXER_TYPE kw);
- void src_reset_token_data(struct Source_File *src,char use_src_as_base);
- void src_assimilate_into_best_token(struct Source_File *src);
- void chase_new_line(struct Source_File *src,struct Translation_Data *translation_data);
- void goto_new_line(struct Source_File *src,struct Translation_Data *translation_data);
- void skip_white_space(struct Source_File *src,char skip_new_line);
- size_t skip_line_splice(struct Source_File *src);
void delete_source_file(struct Source_File *src);
void delete_source_name(struct Source_Name *name);
#endif
F diff --git a/src/syntax/token/token.c b/src/syntax/token/token.c
--- a/src/syntax/token/token.c
+++ b/src/syntax/token/token.c
return cpy;
}
- char compare_tokens(struct token *a,struct token *b)
- {
- size_t i;
- if(a->data_size!=b->data_size)
- return 0;
- for(i=0;i<a->data_size;++i)
- {
- if(a->data[i]!=b->data[i])
- return 0;
- }
- return 1;
- }
- struct token_identifier* get_id_token(struct identifier *id,struct Source_Location *location)
+ struct token* get_id_token(struct identifier *id,struct Source_Location *location)
{
struct token_identifier *ret;
ret=wonky_malloc(sizeof(struct token_identifier));
ret->id=id;
- return ret;
+ return (struct token*)ret;
}
- struct token_keyword* get_keyword_token(enum LEXER_TYPE type,struct Source_Location *location)
+ struct token* get_keyword_token(enum LEXER_TYPE type,struct Source_Location *location)
{
struct token_keyword *ret;
ret=wonky_malloc(sizeof(struct token_keyword));
ret->type=type;
ret->location=location;
- return ret;
+ return (struct token*)ret;
}
- struct token_punctuator* get_punctuator_token(enum LEXER_TYPE type,struct Source_Location *location)
+ struct token* get_punctuator_token(enum LEXER_TYPE type,struct Source_Location *location)
{
struct token_punctuator *ret;
ret=wonky_malloc(sizeof(struct token_punctuator));
ret->location=location;
ret->punctuator_type=PUNCTUATOR_NORMAL;/*TODO*/
- return ret;
+ return (struct token*)ret;
}
- struct token_constant* get_constant_token(enum LEXER_TYPE bare_type,struct Source_Location *location,char *data,size_t size)
+ struct token* get_constant_token(enum LEXER_TYPE bare_type,struct Source_Location *location,char *data,size_t size)
{
struct token_constant *ret;
ret=wonky_malloc(sizeof(struct token_constant));
{
case KW_HEXADECIMAL_CONSTANT:
- function(KW_HEXADECIMAL_CONSTANT);
+ ret->constant=extract_literal_integer_hex(data,size,TC_NONE,TSIGN_SIGNED);
break;
case KW_DECIMAL_CONSTANT:
- function(KW_DECIMAL_CONSTANT);
+ ret->constant=extract_literal_integer_dec(data,size,TC_NONE,TSIGN_SIGNED);
break;
case KW_OCTAL_CONSTANT:
- function(KW_OCTAL_CONSTANT);
+ ret->constant=extract_literal_integer_octal(data,size,TC_NONE,TSIGN_SIGNED);
break;
case KW_UNSIGNED_DECIMAL_CONSTANT:
- function(KW_UNSIGNED_DECIMAL_CONSTANT);
+ ret->constant=extract_literal_integer_dec(data,size,TC_NONE,TSIGN_UNSIGNED);
break;
case KW_UNSIGNED_OCTAL_CONSTANT:
- function(KW_UNSIGNED_OCTAL_CONSTANT);
+ ret->constant=extract_literal_integer_octal(data,size,TC_NONE,TSIGN_UNSIGNED);
break;
case KW_UNSIGNED_HEXADECIMAL_CONSTANT:
- function(KW_UNSIGNED_HEXADECIMAL_CONSTANT);
+ ret->constant=extract_literal_integer_hex(data,size,TC_NONE,TSIGN_UNSIGNED);
break;
case KW_UNSIGNED_LONG_HEXADECIMAL_CONSTANT:
- function(KW_UNSIGNED_LONG_HEXADECIMAL_CONSTANT);
+ ret->constant=extract_literal_integer_hex(data,size,TC_LONG,TSIGN_UNSIGNED);
break;
case KW_UNSIGNED_LONG_OCTAL_CONSTANT:
- function(KW_UNSIGNED_LONG_OCTAL_CONSTANT);
+ ret->constant=extract_literal_integer_octal(data,size,TC_LONG,TSIGN_UNSIGNED);
break;
case KW_UNSIGNED_LONG_DECIMAL_CONSTANT:
- function(KW_UNSIGNED_LONG_DECIMAL_CONSTANT);
+ ret->constant=extract_literal_integer_dec(data,size,TC_LONG,TSIGN_UNSIGNED);
break;
case KW_UNSIGNED_LONG_LONG_DECIMAL_CONSTANT:
- function(KW_UNSIGNED_LONG_LONG_DECIMAL_CONSTANT);
+ ret->constant=extract_literal_integer_dec(data,size,TC_LONG_LONG,TSIGN_UNSIGNED);
break;
case KW_UNSIGNED_LONG_LONG_HEXADECIMAL_CONSTANT:
- function(KW_UNSIGNED_LONG_LONG_HEXADECIMAL_CONSTANT);
+ ret->constant=extract_literal_integer_hex(data,size,TC_LONG_LONG,TSIGN_UNSIGNED);
break;
case KW_UNSIGNED_LONG_LONG_OCTAL_CONSTANT:
- function(KW_UNSIGNED_LONG_LONG_OCTAL_CONSTANT);
+ ret->constant=extract_literal_integer_octal(data,size,TC_LONG_LONG,TSIGN_UNSIGNED);
break;
case KW_LONG_HEXADECIMAL_CONSTANT:
- function(KW_LONG_HEXADECIMAL_CONSTANT);
+ ret->constant=extract_literal_integer_hex(data,size,TC_LONG,TSIGN_SIGNED);
break;
case KW_LONG_OCTAL_CONSTANT:
- function(KW_LONG_OCTAL_CONSTANT);
+ ret->constant=extract_literal_integer_octal(data,size,TC_LONG,TSIGN_SIGNED);
break;
case KW_LONG_DECIMAL_CONSTANT:
- function(KW_LONG_DECIMAL_CONSTANT);
+ ret->constant=extract_literal_integer_dec(data,size,TC_LONG,TSIGN_SIGNED);
break;
case KW_LONG_LONG_HEXADECIMAL_CONSTANT:
- function(KW_LONG_LONG_HEXADECIMAL_CONSTANT);
+ ret->constant=extract_literal_integer_hex(data,size,TC_LONG_LONG,TSIGN_SIGNED);
break;
case KW_LONG_LONG_OCTAL_CONSTANT:
- function(KW_LONG_LONG_OCTAL_CONSTANT);
+ ret->constant=extract_literal_integer_hex(data,size,TC_LONG_LONG,TSIGN_SIGNED);
break;
case KW_LONG_LONG_DECIMAL_CONSTANT:
- function(KW_LONG_LONG_DECIMAL_CONSTANT);
+ ret->constant=extract_literal_integer_dec(data,size,TC_LONG_LONG,TSIGN_SIGNED);
break;
case KW_DOUBLE_DECIMAL_CONSTANT:
- function(KW_DOUBLE_DECIMAL_CONSTANT);
+ ret->constant=extract_literal_double_dec(data,size,TC_NONE);
break;
case KW_LONG_DOUBLE_DECIMAL_CONSTANT:
- function(KW_LONG_DOUBLE_DECIMAL_CONSTANT);
+ ret->constant=extract_literal_double_dec(data,size,TC_LONG);
break;
case KW_FLOAT_DECIMAL_CONSTANT:
- function(KW_FLOAT_DECIMAL_CONSTANT);
+ ret->constant=extract_literal_float_dec(data,size);
break;
case KW_DOUBLE_HEXADECIMAL_CONSTANT:
- function(KW_DOUBLE_HEXADECIMAL_CONSTANT);
+ ret->constant=extract_literal_double_hex(data,size,TC_NONE);
break;
case KW_LONG_DOUBLE_HEXADECIMAL_CONSTANT:
- function(KW_LONG_DOUBLE_HEXADECIMAL_CONSTANT);
+ ret->constant=extract_literal_double_hex(data,size,TC_LONG);
break;
case KW_FLOAT_HEXADECIMAL_CONSTANT:
- function(KW_FLOAT_HEXADECIMAL_CONSTANT);
+ ret->constant=extract_literal_float_hex(data,size);
break;
case KW_CHAR_CONSTANT:
- function(KW_CHAR_CONSTANT);
+ ret->constant=extract_literal_char(data,size);
break;
case KW_WIDE_CHAR_CONSTANT:
- function(KW_WIDE_CHAR_CONSTANT);
+ ret->constant=extract_literal_wide_char(data,size);
break;
default:
wonky_assert(SHOULD_NOT_REACH_HERE);
}
- return ret;
+ return (struct token*)ret;
}
- struct token_string* get_string_token(enum LEXER_TYPE bare_type,struct Source_Location *location,char *data,size_t size)
+ struct token* get_string_token(enum LEXER_TYPE bare_type,struct Source_Location *location,char *data,size_t size)
{
struct token_string *ret;
ret=wonky_malloc(sizeof(struct token_string));
ret->type=bare_type;
ret->location=location;
- ret->size=size;
- ret->data=data;
-
+
+ if(bare_type==KW_STRING)
+ {
+ ret->constant=extract_literal_string(data,size);
+ }else if(bare_type==KW_WIDE_STRING)
+ {
+ ret->constant=extract_literal_wide_string(data,size);
+ }else
+ {
+ wonky_assert(SHOULD_NOT_REACH_HERE);
+ }
- return ret;
+ return (struct token*)ret;
}
- struct token_include_directive* get_include_directive_token(struct Source_Location *location,struct Queue *tokens)
+ struct token* get_include_directive_token(struct Source_Location *location,struct Queue *tokens)
{
struct token_include_directive *ret;
ret=wonky_malloc(sizeof(struct token_string));
ret->location=location;
ret->tokens=tokens;
- return ret;
- }
- struct token_if_directive* get_if_directive_token(struct Source_Location *location,struct Queue *controlling_tokens,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive)
- {
- struct token_if_directive *ret;
- ret=wonky_malloc(sizeof(struct token_if_directive));
- ret->
-
+ return (struct token*)ret;
}
+ struct token* get_if_directive_token(struct Source_Location *location,struct Queue *controlling_tokens,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive);
- struct token_ifdef_directive* get_ifdef_directive_token(struct Source_Location *location,struct identifier *id,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive);
+ struct token* get_ifdef_directive_token(struct Source_Location *location,struct identifier *id,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive);
- struct token_ifdef_directive* get_ifdef_directive_token(struct Source_Location *location,struct identifier *id,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive);
+ struct token* get_ifdef_directive_token(struct Source_Location *location,struct identifier *id,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive);
- struct token_normal_define_directive* get_normal_define_directive_token(struct Source_Location *location,struct identifier *id,struct Queue *replacement_tokens);
+ struct token* get_normal_define_directive_token(struct Source_Location *location,struct identifier *id,struct Queue *replacement_tokens);
- struct token_functionlike_define_directive* get_functionlike_define_directive_token(struct Source_Location *location,struct identifier *id,struct Queue *argument_id_list_tokens,struct Queue *replacement_tokens);
+ struct token* get_functionlike_define_directive_token(struct Source_Location *location,struct identifier *id,struct Queue *argument_id_list_tokens,struct Queue *replacement_tokens);
- struct token_undef_directive* get_undef_directive_token(struct Source_Location *location,struct identifier *id);
- struct token_line_directive* get_line_directive_token(struct Source_Location *location,struct Source_Location *new_location);
- struct token_error_directive* get_error_directive_token(struct Source_Location *location,struct token_string *error_message);
- struct token_pragma_directive* get_pragma_directive(struct Source_Location *location,enum Pragma_Type type);
- struct token_defined_unary_operator* get_defined_unary_operator(struct Source_Location *location,struct identifier *id);
+ struct token* get_undef_directive_token(struct Source_Location *location,struct identifier *id);
+ struct token* get_line_directive_token(struct Source_Location *location,struct Source_Location *new_location);
+ struct token* get_error_directive_token(struct Source_Location *location,struct token_string *error_message);
+ struct token* get_pragma_directive(struct Source_Location *location,enum Pragma_Type type);
+ struct token* get_defined_unary_operator(struct Source_Location *location,struct identifier *id);
#endif
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 *location;
- enum String_Token_Type string_type;
- size_t size;
- char *data;
+ struct Constant *constant;
};
struct token_include_directive
{
char compare_tokens(struct token *a,struct token *b);
- struct token_identifier* get_id_token(struct identifier *id,struct Source_Location *location);
- struct token_keyword* get_keyword_token(enum LEXER_TYPE type,struct Source_Location *location);
- struct token_punctuator* get_punctuator_token(enum LEXER_TYPE type,struct Source_Location *location);
- struct token_constant* get_constant_token(enum LEXER_TYPE bare_type,struct Source_Location *location,char *data,size_t size);
- struct token_string* get_string_token(enum LEXER_TYPE bare_type,struct Source_Location *location,char *data,size_t size);
- struct token_include_directive* get_include_directive_token(struct Source_Location *location,struct Queue *tokens);
- struct token_if_directive* get_if_directive_token(struct Source_Location *location,struct Queue *controlling_tokens,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive);
+ struct token* get_id_token(struct identifier *id,struct Source_Location *location);
+ struct token* get_keyword_token(enum LEXER_TYPE type,struct Source_Location *location);
+ struct token* get_punctuator_token(enum LEXER_TYPE type,struct Source_Location *location);
+ struct token* get_constant_token(enum LEXER_TYPE bare_type,struct Source_Location *location,char *data,size_t size);
+ struct token* get_string_token(enum LEXER_TYPE bare_type,struct Source_Location *location,char *data,size_t size);
+ struct token* get_include_directive_token(struct Source_Location *location,struct Queue *tokens);
+ struct token* get_if_directive_token(struct Source_Location *location,struct Queue *controlling_tokens,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive);
- struct token_ifdef_directive* get_ifdef_directive_token(struct Source_Location *location,struct identifier *id,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive);
+ struct token* get_ifdef_directive_token(struct Source_Location *location,struct identifier *id,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive);
- struct token_ifdef_directive* get_ifdef_directive_token(struct Source_Location *location,struct identifier *id,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive);
+ struct token* get_ifdef_directive_token(struct Source_Location *location,struct identifier *id,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive);
- struct token_normal_define_directive* get_normal_define_directive_token(struct Source_Location *location,struct identifier *id,struct Queue *replacement_tokens);
+ struct token* get_normal_define_directive_token(struct Source_Location *location,struct identifier *id,struct Queue *replacement_tokens);
- struct token_functionlike_define_directive* get_functionlike_define_directive_token(struct Source_Location *location,struct identifier *id,struct Queue *argument_id_list_tokens,struct Queue *replacement_tokens);
+ struct token* get_functionlike_define_directive_token(struct Source_Location *location,struct identifier *id,struct Queue *argument_id_list_tokens,struct Queue *replacement_tokens);
- struct token_undef_directive* get_undef_directive_token(struct Source_Location *location,struct identifier *id);
- struct token_line_directive* get_line_directive_token(struct Source_Location *location,struct Source_Location *new_location);
- struct token_error_directive* get_error_directive_token(struct Source_Location *location,struct token_string *error_message);
- struct token_pragma_directive* get_pragma_directive(struct Source_Location *location,enum Pragma_Type type);
- struct token_defined_unary_operator* get_defined_unary_operator(struct Source_Location *location,struct identifier *id);
+ struct token* get_undef_directive_token(struct Source_Location *location,struct identifier *id);
+ struct token* get_line_directive_token(struct Source_Location *location,struct Source_Location *new_location);
+ struct token* get_error_directive_token(struct Source_Location *location,struct token_string *error_message);
+ struct token* get_pragma_directive(struct Source_Location *location,enum Pragma_Type type);
+ struct token* get_defined_unary_operator(struct Source_Location *location,struct identifier *id);
struct token* get_hashtag_unary_operator(struct Source_Location *location,struct token_functionlike_define_directive *operand);
struct token* get_hashtag_hashtag_unary_operator(struct Source_Location *location,struct Queue *operands);
struct token* get_error_token(const char *msg,struct Source_Location *location,struct Program *program, ...);