WONKY



LOG | FILES | OVERVIEW


F diff --git a/src/backend/asm/intel/intel_asm.c b/src/backend/asm/intel/intel_asm.c --- a/src/backend/asm/intel/intel_asm.c +++ b/src/backend/asm/intel/intel_asm.c
//compile_data->offset_from_stack_frame+=size;
ret=get_intel_asm_stack_offset(compile_data->offset_from_stack_frame);
- object->location=(struct Location*)ret;
+ object->location=(struct Memory_Location*)ret;
return ret;
}
struct Intel_Asm_Memory_Location* reserve_stack_space_for_function_argument(struct Compile_Data_Intel_Asm *compile_data,struct Object *object)
ret=get_intel_asm_stack_offset(-size);
- object->location=(struct Location*)ret;
+ object->location=(struct Memory_Location*)ret;
return ret;
}
void release_object_from_stack(struct Compile_Data_Intel_Asm *compile_data,struct Object *object)
(struct Intel_Asm_Label*)get_intel_asm_label(gstr_dup(id->data,id->data+id->data_size,1024))
);
- function->location=(struct Location*)location;
+ function->location=(struct Memory_Location*)location;
}
void intel_asm_finish_comparison(struct Compile_Data_Intel_Asm *compile_data,enum Intel_Asm_Instruction_Type op)
{
F diff --git a/src/backend/asm/intel/intel_compile.c b/src/backend/asm/intel/intel_compile.c --- a/src/backend/asm/intel/intel_compile.c +++ b/src/backend/asm/intel/intel_compile.c
if(def->function->location==NULL)
{
- def->function->location=(struct Location*)
+ def->function->location=(struct Memory_Location*)
get_intel_asm_label_location(
(struct Intel_Asm_Label*)get_intel_asm_label(
gstr_dup(
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
push_line(gstr_to_heap("} TRANSLATION_UNIT_END"),compile_data->indent,compile_data->lines);
}
}
- void print_keyword_enum(FILE *out,enum KEYWORDS kw)
+ void print_keyword_enum(FILE *out,enum LEXER_TYPE kw)
{
switch(kw)
{
F diff --git a/src/backend/text/print/print.h b/src/backend/text/print/print.h --- a/src/backend/text/print/print.h +++ b/src/backend/text/print/print.h
void print_ast(struct Compile_Data_Print *compile_data,struct AST* tree);
void print_program_tokens(struct Compile_Data_Print *compile_data,struct Program *program);
void print_program_ast(struct Compile_Data_Print *compile_data,struct Program *program);
- void print_keyword_enum(FILE *out,enum KEYWORDS kw);
+ void print_keyword_enum(FILE *out,enum LEXER_TYPE kw);
void print_function_definition(struct Compile_Data_Print *compile_data,struct AST_Function_Definition *function);
void print_errors(FILE *out,struct Queue *errors);
void print_function_args(struct Compile_Data_Print *compile_data,struct Type_Function *func);
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
#define WONKY_DEBUG_LEXER_C WONKY_DEBUG_LEXER_C
#include <debug_lexer.h>
- _Bool is_valid_keyword_enum(enum KEYWORDS keyword)
+ _Bool is_valid_keyword_enum(enum LEXER_TYPE keyword)
{
- return keyword>=0 && keyword<KEYWORDS_END;
+ return keyword>=0 && keyword<LEXER_TYPE_END;
}
_Bool is_valid_token(struct token *token)
{
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 <lexer.h>
#include <common.h>
- _Bool is_valid_keyword_enum(enum KEYWORDS keyword);
+ _Bool is_valid_keyword_enum(enum LEXER_TYPE keyword);
_Bool is_valid_token(struct token *token);
#endif
F diff --git a/src/frontend/lex/automatas/automata.c b/src/frontend/lex/automatas/automata.c --- a/src/frontend/lex/automatas/automata.c +++ b/src/frontend/lex/automatas/automata.c
enum Source_Chars get_ch(const char *str,size_t limit)
{
return compress[*str];
-
}
F diff --git a/src/frontend/lex/automatas/automata.h b/src/frontend/lex/automatas/automata.h --- a/src/frontend/lex/automatas/automata.h +++ b/src/frontend/lex/automatas/automata.h
struct Automata_Node
{
enum Automata_Action action;
- enum KEYWORDS keyword;
+ enum LEXER_TYPE keyword;
void *data;
struct Automata_Node *delta[CHAR_ENUM_END];
extern struct Automata_Node chonky[];
extern struct Automata_Node chonky_jr[];
+
#endif
F diff --git a/src/frontend/lex/automatas/automata.hh b/src/frontend/lex/automatas/automata.hh --- a/src/frontend/lex/automatas/automata.hh +++ b/src/frontend/lex/automatas/automata.hh
CHAR_ENUM_END
};
- enum KEYWORDS
+ enum LEXER_TYPE
{
KW_AUTO,
KW_DO,
PKW_ELSE,
PKW_ENDIF,
PKW_INCLUDE,
+ PKW_FUNCTIONLIKE_DEFINE,
PKW_DEFINE,
PKW_UNDEF,
PKW_LINE,
PKW_PRAGMA,
PKW_COMMENT,
PKW_NOTYPE,
+ LT_EOF,
- KEYWORDS_END
+ LEXER_TYPE_END
};
struct Automata_Node;
F diff --git a/src/frontend/lex/automatas/generator/keyword_list.c b/src/frontend/lex/automatas/generator/keyword_list.c --- a/src/frontend/lex/automatas/generator/keyword_list.c +++ b/src/frontend/lex/automatas/generator/keyword_list.c
.action_string="AUTOMATA_ACTION_DISPENSE_TOKEN",
.data_string="NULL"
},
+ {
+ .keyword="defined",
+ .kw_string="KW_ID",
+ .action_string="AUTOMATA_ACTION_DISPENSE_TOKEN",
+ .data_string="&defined_id"
+ },
};
size_t number_of_chonky_keywords=sizeof(chonky_keywords)/sizeof(chonky_keywords[0]);
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
#include <token.h>
- void lex(struct Source_File *src,struct Translation_Data *translation_data);
+ struct Lexer_Data
+ {
+
+ size_t where_in_src;
+ size_t which_column;
+ size_t which_row;
+
+ size_t token_size;
+
+
+ size_t best_token_size;
+ size_t best_token_line;
+ size_t best_token_column;
+
+ size_t best_token_where_in_src_start;
+ size_t best_token_where_in_src_end;
+ char best_token_beg_line;
+
+
+ char is_in_the_begining_of_line;
+
+ struct Source_File *src;
+ struct Program *program;
+ };
+
+ void lex(struct Lexer_Data *lexer_data);
struct token* get_next_token(struct Source_File *src,struct Automata_Node *start_state,char skip_new_line);
+ struct Lexer_Data* get_lexer_data(struct Source_File *src,struct Program *program);
+ void delete_lexer_data(struct Lexer_Data *lexer_data);
#endif
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
( storage-class-specifier type-specifier type-qualifier function-specifier)* */
struct Denotation_Prototype* parse_declaration_specifiers_inner(struct Translation_Data *translation_data,struct Scope *scope,char parse_storage_class)
{
- enum KEYWORDS hold_kw;
+ enum LEXER_TYPE hold_kw;
struct Denotation_Prototype *ret;
ret=(struct Denotation_Prototype*)get_denotation_prototype(translation_data->types);
void parse_declarator_inner(struct Translation_Data *translation_data,struct Scope *scope,struct Denoted_Base *base)
{
- enum KEYWORDS hold;
+ enum LEXER_TYPE hold;
char is_const;
char is_volatile;
while(get_and_check(translation_data,KW_STAR))
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
#include <linkage.h>
#include <object.h>
#include <common.h>
- #include <location.h>
+ #include <memory_location.h>
struct Denoted
{
enum Linkage_Type linkage;
struct token *id;
struct Type *type;
- struct Location *location;
+ struct Memory_Location *location;
enum Function_Specifier function_specifier;
struct Function_Scope *function_scope;
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
#include <map.h>
#include <denoted.h>
- #include <location.h>
+ #include <memory_location.h>
#include <queue.h>
#include <constraints.h>
#include <common.h>
F diff --git a/src/semantics/memory/location.c b/src/semantics/memory/location.c deleted file mode 100644 --- a/src/semantics/memory/location.c +++ /dev/null
- #ifndef WONKY_LOCATION_C
- #define WONKY_LOCATION_C WONKY_LOCATION_C
- #include "location.h"
-
-
- #endif
F diff --git a/src/semantics/memory/location.h b/src/semantics/memory/location.h deleted file mode 100644 --- a/src/semantics/memory/location.h +++ /dev/null
- #ifndef WONKY_LOCATION_H
- #define WONKY_LOCATION_H WONKY_LOCATION_H
- #include <location.hh>
- #include <lexer.h>
- #include <type.h>
- #include <common.h>
-
- struct Location
- {
- int type;
- };
- #endif
F diff --git a/src/semantics/memory/location.hh b/src/semantics/memory/location.hh deleted file mode 100644 --- a/src/semantics/memory/location.hh +++ /dev/null
- #ifndef WONKY_LOCATION_HH
- #define WONKY_LOCATION_HH WONKY_LOCATION_HH
-
-
-
- struct Location;
-
- #endif
F diff --git a/src/semantics/memory/memory_location.c b/src/semantics/memory/memory_location.c new file mode 100644 --- /dev/null +++ b/src/semantics/memory/memory_location.c
+ #ifndef WONKY_LOCATION_C
+ #define WONKY_LOCATION_C WONKY_LOCATION_C
+ #include "location.h"
+
+
+ #endif
F diff --git a/src/semantics/memory/memory_location.h b/src/semantics/memory/memory_location.h new file mode 100644 --- /dev/null +++ b/src/semantics/memory/memory_location.h
+ #ifndef WONKY_LOCATION_H
+ #define WONKY_LOCATION_H WONKY_LOCATION_H
+ #include <location.hh>
+ #include <lexer.h>
+ #include <type.h>
+ #include <common.h>
+
+ struct Memory_Location
+ {
+ int type;
+ };
+ #endif
F diff --git a/src/semantics/memory/memory_location.hh b/src/semantics/memory/memory_location.hh new file mode 100644 --- /dev/null +++ b/src/semantics/memory/memory_location.hh
+ #ifndef WONKY_LOCATION_HH
+ #define WONKY_LOCATION_HH WONKY_LOCATION_HH
+
+
+
+ struct Memory_Location;
+
+ #endif
F diff --git a/src/semantics/memory/object.h b/src/semantics/memory/object.h --- a/src/semantics/memory/object.h +++ b/src/semantics/memory/object.h
#include <object.hh>
#include <type.h>
- #include <location.h>
+ #include <memory_location.h>
#include <common.h>
#include <lexer.h>
{
enum Object_Kind kind;
struct Type *type;
- struct Location *location;
+ struct Memory_Location *location;
enum Storage_Class_Specifier storage_class;
};
struct Object_Bitfield
{
enum Object_Kind kind;
struct Type *type;
- struct Location *location;
+ struct Memory_Location *location;
enum Storage_Class_Specifier storage_class;
size_t number_of_bits;
};
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
Queue_Push(where_to_push,tree);
}
}
- char check(struct Translation_Data *translation_data,enum KEYWORDS kw,size_t ahead)
+ char check(struct Translation_Data *translation_data,enum LEXER_TYPE kw,size_t ahead)
{
size_t i;
struct Queue_Node *current;
}
}
}
- char get_and_check(struct Translation_Data *translation_data,enum KEYWORDS kw)
+ char get_and_check(struct Translation_Data *translation_data,enum LEXER_TYPE kw)
{
struct token *hold_token;
if(translation_data->tokens->size==0)
}
}
}
- char get_and_check_unsafe(struct Translation_Data *translation_data,enum KEYWORDS kw)
+ char get_and_check_unsafe(struct Translation_Data *translation_data,enum LEXER_TYPE kw)
{
struct token *hold_token;
hold_token=translation_data->tokens->first->data;
wonky_free(Queue_Pop(translation_data->tokens));
}
- enum KEYWORDS kw_get(struct Translation_Data *translation_data)
+ enum LEXER_TYPE kw_get(struct Translation_Data *translation_data)
{
if(translation_data->tokens->size==0)
return KW_NOTYPE;
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
*/
struct Map *types;
+ struct Map *preprocessing_translation_units;
+
struct Linkage *external_linkage;
};
struct Translation_Data
{
- struct Queue *tokens;
+ struct Token_Pointer *token_pointer;
struct Queue *errors;
struct Map *macros;
- /*passed from program struct*/
- struct Map *types;
- struct Linkage *external_linkage;
struct Linkage *internal_linkage;
- /*end of passed from program struct*/
+
+ struct Program *program;
};
struct Program* get_program();
- struct Translation_Data* get_translation_data(struct Map *types,struct Linkage *internal_linkage,struct Linkage *external_linkage);
+ struct Translation_Data* get_translation_data(struct Map *types,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 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 KEYWORDS kw,size_t ahead);
- char get_and_check(struct Translation_Data *translation_data,enum KEYWORDS kw);
- char get_and_check_unsafe(struct Translation_Data *translation_data,enum KEYWORDS kw);
+ 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);
void chomp(struct Translation_Data *translation_data);
- enum KEYWORDS kw_get(struct Translation_Data *translation_data);
+ enum LEXER_TYPE kw_get(struct Translation_Data *translation_data);
void flush_tokens(struct Queue *tokens);
F diff --git a/src/semantics/program/source_file.c b/src/semantics/program/source_file.c --- a/src/semantics/program/source_file.c +++ b/src/semantics/program/source_file.c
src->which_column=0;
}
}
- struct token* src_extract_token(struct Source_File *src,enum KEYWORDS kw)
+ struct token* src_extract_token(struct Source_File *src,enum LEXER_TYPE kw)
{
struct token *ret;
ret=wonky_malloc(sizeof(struct token));
F diff --git a/src/semantics/program/source_file.h b/src/semantics/program/source_file.h --- a/src/semantics/program/source_file.h +++ b/src/semantics/program/source_file.h
char *filename;
char *base;
};
+ struct Source_Location
+ {
+ size_t line;
+ size_t column;
+ };
struct Source_File
{
- struct Source_Name *src_name;
-
+ enum Source_Text_Type type;
char *src;
size_t src_size;
- size_t where_in_src;
- size_t which_column;
- size_t which_row;
-
- size_t token_size;
-
-
- size_t best_token_size;
- size_t best_token_line;
- size_t best_token_column;
-
- size_t best_token_where_in_src_start;
- size_t best_token_where_in_src_end;
- char best_token_beg_line;
+ struct Source_Name *src_name;
+ };
+ struct Source_Section
+ {
+ enum Source_Text_Type type;
+ char *src;
+ size_t src_size
- char is_in_the_begining_of_line;
-
+ struct Source_Name *src_name;
+ struct Source_Location *where_in_source;
};
struct Source_File* extract_source_file(FILE *in,struct Source_Name *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 KEYWORDS kw);
+ 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);
F diff --git a/src/semantics/program/source_file.hh b/src/semantics/program/source_file.hh --- a/src/semantics/program/source_file.hh +++ b/src/semantics/program/source_file.hh
#ifndef WONKY_SOURCE_FILE_HH
#define WONKY_SOURCE_FILE_HH WONKY_SOURCE_FILE_HH
+ struct Source_Name;
+ struct Source_Location;
+ struct Source_File;
+ struct Source_Section;
+ enum Source_Text_Type;
#endif
F diff --git a/src/semantics/program/token.c b/src/semantics/program/token.c --- a/src/semantics/program/token.c +++ b/src/semantics/program/token.c
return ret;
}
- struct token_identifier* get_id_token(struct identifier *id,struct Location *location)
+ struct token_identifier* get_id_token(struct identifier *id,struct Source_Location *location)
{
struct token_identifier *ret;
ret=wonky_malloc(sizeof(struct token_identifier));
return ret;
}
- struct token_keyword* get_keyword_token(enum KEYWORDS type,struct Location *location)
+ struct token_keyword* get_keyword_token(enum LEXER_TYPE type,struct Source_Location *location)
{
struct token_keyword *ret;
ret=wonky_malloc(sizeof(struct token_keyword));
return ret;
}
- struct token_punctuator* get_punctuator_token(enum KEYWORDS type,struct Location *location)
+ struct token_punctuator* get_punctuator_token(enum LEXER_TYPE type,struct Source_Location *location)
{
struct token_punctuator *ret;
ret=wonky_malloc(sizeof(struct token_punctuator));
return ret;
}
- struct token_constant* get_constant_token(enum KEYWORDS bare_type,struct Location *location,char *data,size_t size)
+ struct token_constant* 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));
ret->location=location;
ret->type=bare_type;/*TODO*/
- ret->encoding=CONSTANT_TOKEN_DECIMAL;
- ret->specifier=CONSTANT_TOKEN_SPECIFIER_NONE;
- ret->signedness=CONSTANT_TOKEN_SIGNED;
- ret->value=0;
+
+ switch(bare_type)
+ {
+
+ case KW_HEXADECIMAL_CONSTANT:
+ function(KW_HEXADECIMAL_CONSTANT);
+ break;
+ case KW_DECIMAL_CONSTANT:
+ function(KW_DECIMAL_CONSTANT);
+ break;
+ case KW_OCTAL_CONSTANT:
+ function(KW_OCTAL_CONSTANT);
+ break;
+ case KW_UNSIGNED_DECIMAL_CONSTANT:
+ function(KW_UNSIGNED_DECIMAL_CONSTANT);
+ break;
+ case KW_UNSIGNED_OCTAL_CONSTANT:
+ function(KW_UNSIGNED_OCTAL_CONSTANT);
+ break;
+ case KW_UNSIGNED_HEXADECIMAL_CONSTANT:
+ function(KW_UNSIGNED_HEXADECIMAL_CONSTANT);
+ break;
+ case KW_UNSIGNED_LONG_HEXADECIMAL_CONSTANT:
+ function(KW_UNSIGNED_LONG_HEXADECIMAL_CONSTANT);
+ break;
+ case KW_UNSIGNED_LONG_OCTAL_CONSTANT:
+ function(KW_UNSIGNED_LONG_OCTAL_CONSTANT);
+ break;
+ case KW_UNSIGNED_LONG_DECIMAL_CONSTANT:
+ function(KW_UNSIGNED_LONG_DECIMAL_CONSTANT);
+ break;
+ case KW_UNSIGNED_LONG_LONG_DECIMAL_CONSTANT:
+ function(KW_UNSIGNED_LONG_LONG_DECIMAL_CONSTANT);
+ break;
+ case KW_UNSIGNED_LONG_LONG_HEXADECIMAL_CONSTANT:
+ function(KW_UNSIGNED_LONG_LONG_HEXADECIMAL_CONSTANT);
+ break;
+ case KW_UNSIGNED_LONG_LONG_OCTAL_CONSTANT:
+ function(KW_UNSIGNED_LONG_LONG_OCTAL_CONSTANT);
+ break;
+ case KW_LONG_HEXADECIMAL_CONSTANT:
+ function(KW_LONG_HEXADECIMAL_CONSTANT);
+ break;
+ case KW_LONG_OCTAL_CONSTANT:
+ function(KW_LONG_OCTAL_CONSTANT);
+ break;
+ case KW_LONG_DECIMAL_CONSTANT:
+ function(KW_LONG_DECIMAL_CONSTANT);
+ break;
+ case KW_LONG_LONG_HEXADECIMAL_CONSTANT:
+ function(KW_LONG_LONG_HEXADECIMAL_CONSTANT);
+ break;
+ case KW_LONG_LONG_OCTAL_CONSTANT:
+ function(KW_LONG_LONG_OCTAL_CONSTANT);
+ break;
+ case KW_LONG_LONG_DECIMAL_CONSTANT:
+ function(KW_LONG_LONG_DECIMAL_CONSTANT);
+ break;
+ case KW_DOUBLE_DECIMAL_CONSTANT:
+ function(KW_DOUBLE_DECIMAL_CONSTANT);
+ break;
+ case KW_LONG_DOUBLE_DECIMAL_CONSTANT:
+ function(KW_LONG_DOUBLE_DECIMAL_CONSTANT);
+ break;
+ case KW_FLOAT_DECIMAL_CONSTANT:
+ function(KW_FLOAT_DECIMAL_CONSTANT);
+ break;
+ case KW_DOUBLE_HEXADECIMAL_CONSTANT:
+ function(KW_DOUBLE_HEXADECIMAL_CONSTANT);
+ break;
+ case KW_LONG_DOUBLE_HEXADECIMAL_CONSTANT:
+ function(KW_LONG_DOUBLE_HEXADECIMAL_CONSTANT);
+ break;
+ case KW_FLOAT_HEXADECIMAL_CONSTANT:
+ function(KW_FLOAT_HEXADECIMAL_CONSTANT);
+ break;
+ case KW_CHAR_CONSTANT:
+ function(KW_CHAR_CONSTANT);
+ break;
+ case KW_WIDE_CHAR_CONSTANT:
+ function(KW_WIDE_CHAR_CONSTANT);
+ break;
+ default:
+ wonky_assert(SHOULD_NOT_REACH_HERE);
+ }
return ret;
}
- struct token_string* get_string_token(enum KEYWORDS bare_type,struct 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_string *ret;
ret=wonky_malloc(sizeof(struct token_string));
return ret;
}
- struct token_include_directive* get_include_directive_token(struct Location *location,struct Queue *tokens)
+ struct token_include_directive* get_include_directive_token(struct Source_Location *location,struct Queue *tokens)
{
struct token_include_directive *ret;
ret=wonky_malloc(sizeof(struct token_string));
ret->tokens=tokens;
return ret;
}
- struct token_if_directive* get_if_directive_token(struct 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* 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));
}
- struct token_ifdef_directive* get_ifdef_directive_token(struct 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_ifdef_directive* get_ifdef_directive_token(struct 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_normal_define_directive* get_normal_define_directive_token(struct Location *location,struct identifier *id,struct Queue *replacement_tokens);
+ struct token_normal_define_directive* 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 Location *location,struct identifier *id,struct Queue *argument_id_list_tokens,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_undef_directive* get_undef_directive_token(struct Location *location,struct identifier *id);
- struct token_line_directive* get_line_directive_token(struct Location *location,struct Location *new_location);
- struct token_error_directive* get_error_directive_token(struct Location *location,struct token_string *error_message);
- struct token_pragma_directive* get_pragma_directive(struct Location *location,enum Pragma_Type type);
- struct token_defined_unary_operator* get_defined_unary_operator(struct Location *location,struct identifier *id);
+ 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);
#endif
F diff --git a/src/semantics/program/token.h b/src/semantics/program/token.h --- a/src/semantics/program/token.h +++ b/src/semantics/program/token.h
#include <automata.h>
#include <constant.h>
+ #include <wonky_malloc.h>
+ #include <wonky_assert.h>
+ #include <source_file.h>
struct token
{
- enum KEYWORDS type;
+ enum LEXER_TYPE type;
};
struct identifier /*there is only one of these per id*/
{
};
struct token_identifier
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
struct identifier *id;
};
struct token_keyword
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
};
struct token_punctuator
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
enum Punctuator_Token_Type punctuator_type;
};
struct token_constant
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
struct Constant *constant;
};
struct token_string
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
enum String_Token_Type string_type;
size_t size;
char *data;
};
struct token_include_directive
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
struct Queue *tokens;
};
struct token_if_directive
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
struct Queue *controlling_expression;
struct Queue_Node *if_true;
struct Queue_Node *if_false;
};
struct token_ifdef_directive
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
struct token_identifier *id;
struct Queue_Node *if_defined;
struct Queue_Node *if_undefined;
};
struct token_ifndef_directive
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
struct token_identifier *id;
struct Queue_Node *if_undefined;
struct Queue_Node *if_defined;
};
struct token_normal_define_directive
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
struct token_identifier *id;
struct Queue *replacement_tokens;
struct Translation_Unit *the_last_place_this_macro_was_defined;
};
struct token_functionlike_define_directive
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
struct identifier *id;
struct Queue *arguments;
struct Queue *replacement_tokens;
};
struct token_undef_directive
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
struct identifier *id;
};
struct token_line_directive
{
- enum KEYWORDS type;
- struct Location *real_location;
- struct Location *new_location;
+ enum LEXER_TYPE type;
+ struct Source_Location *real_location;
+ struct Source_Location *new_location;
};
struct token_error_directive
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
struct token_string *error_message;
};
struct token_pragma_directive
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
enum Pragma_Type pragma_type;
};
struct token_defined_unary_operator
{
- enum KEYWORDS type;
- struct Location *location;
+ enum LEXER_TYPE type;
+ struct Source_Location *location;
struct identifier *id;
};
+ struct token_unlexed_source_part
+ {
+ enum LEXER_TYPE type;
+ struct Source_Section *section;
+ };
/*
* OLD TOKEN STRUCT
struct token
{
- enum KEYWORDS type;
+ enum LEXER_TYPE type;
size_t data_size;
char *data;
size_t line,column;
struct identifier* get_identifier(char *data,size_t size);
- struct token_identifier* get_id_token(struct identifier *id,struct Location *location);
- struct token_keyword* get_keyword_token(enum KEYWORDS type,struct Location *location);
- struct token_punctuator* get_punctuator_token(enum KEYWORDS type,struct Location *location);
- struct token_constant* get_constant_token(enum KEYWORDS bare_type,struct Location *location,char *data,size_t size);
- struct token_string* get_string_token(enum KEYWORDS bare_type,struct Location *location,char *data,size_t size);
- struct token_include_directive* get_include_directive_token(struct Location *location,struct Queue *tokens);
- struct token_if_directive* get_if_directive_token(struct 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_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_ifdef_directive* get_ifdef_directive_token(struct 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_ifdef_directive* get_ifdef_directive_token(struct 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_normal_define_directive* get_normal_define_directive_token(struct Location *location,struct identifier *id,struct Queue *replacement_tokens);
+ struct token_normal_define_directive* 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 Location *location,struct identifier *id,struct Queue *argument_id_list_tokens,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_undef_directive* get_undef_directive_token(struct Location *location,struct identifier *id);
- struct token_line_directive* get_line_directive_token(struct Location *location,struct Location *new_location);
- struct token_error_directive* get_error_directive_token(struct Location *location,struct token_string *error_message);
- struct token_pragma_directive* get_pragma_directive(struct Location *location,enum Pragma_Type type);
- struct token_defined_unary_operator* get_defined_unary_operator(struct Location *location,struct identifier *id);
+ 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);
#endif
F diff --git a/src/semantics/program/translation_unit.c b/src/semantics/program/translation_unit.c --- a/src/semantics/program/translation_unit.c +++ b/src/semantics/program/translation_unit.c
{
Queue_Push(unit->tokens,token);
}
- struct token* get_token_under_pointer(struct Token_Pointer *token_pointer)
+ struct token* token_ptr_get_token_under_pointer(struct Token_Pointer *token_pointer)
{
-
+ struct token *hold_token;
+ while(1)
+ {
+ hold_token=(struct token*)token_pointer->current_token_node->data;
+ switch(hold_token->type)
+ {
+ case PKW_IF:
+ case PKW_ELIF:
+ token_ptr_execute_if_directive(token_pointer,(struct token_if_directive*)hold_token);
+ break;
+ case PKW_IFDEF:
+ token_ptr_execute_ifdef_directive(token_pointer,(struct token_ifdef_directive*)hold_token);
+ break;
+ case PKW_IFNDEF:
+ token_ptr_execute_ifndef_directive(token_pointer,(struct token_ifndef_directive*)hold_token);
+ break;
+ case PKW_ELSE:
+ wonky_assert(SHOULD_NOT_REACH_HERE);
+ break;
+ case PKW_ENDIF:
+ wonky_assert(SHOULD_NOT_REACH_HERE);
+ break;
+ case PKW_INCLUDE:
+ token_ptr_execute_include_directive(token_pointer,(struct token_include_directive*)hold_token);
+ break;
+ case PKW_DEFINE:
+ token_ptr_execute_normal_define_directive(token_pointer,(struct token_normal_define_directive*)hold_token);
+ break;
+ case PKW_FUNCTIONLIKE_DEFINE:
+ token_ptr_execute_functionlike_define_directive(token_pointer,(struct token_functionlike_define_directive*)hold_token);
+ break
+ case PKW_UNDEF:
+ token_ptr_execute_undef_directive(token_pointer,(struct token_undef_directive*)hold_token);
+ break;
+ case PKW_LINE:
+ token_ptr_execute_line_directive(token_pointer,(struct token_line_directive*)hold_token);
+ break;
+ case PKW_ERROR:
+ token_ptr_execute_error_directive(token_pointer,(struct token_error_directive*)hold_token);
+ break;
+ case PKW_PRAGMA:
+ token_ptr_execute_pragma_directive(token_pointer,(struct token_pragma_directive*)hold_token);
+ break;
+ case LT_EOF:
+ if(token_pointer->call_stack->size>0)
+ {
+ token_pointer->current_token_node=Stack_Pop(token_pointer->call_stack);
+ }else
+ {
+ return hold_token;
+ }
+ break;
+ default:
+ token_ptr_goto_next_token(token_pointer);
+ return hold_token;
+ }
+ }
+ wonky_assert(SHOULD_NOT_REACH_HERE);
}
- void goto_next_token(struct Token_Pointer *token_pointer);
+ void token_ptr_goto_next_token(struct Token_Pointer *token_pointer)
+ {
+ wonky_assert(token_pointer!=NULL);
+ wonky_assert(token_pointer->current_token_node!=NULL);
- struct Token_Pointer* get_token_ptr(struct Preprocessing_Translation_Unit *unit);
+ if(token_pointer->current_token_node->next!=NULL && ((struct token*)token_pointer->current_token_node->data)->type!=LT_EOF)
+ {
+ token_pointer->current_token_node=token_pointer->current_token_node->next;
+ }
+ }
- 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);
- void token_ptr_execute_ifdef_directive(struct Token_Pointer *ptr,struct token_ifdef_directive *ifdef_directive);
- void token_ptr_execute_ifndef_directive(struct Token_Pointer *ptr,struct token_ifndef_directive *ifndef_directive);
- void token_ptr_execute_normal_define_directive(struct Token_Pointer *ptr,struct token_normal_define_directive *define_directive);
- void token_ptr_execute_functionlike_define_directive(struct Token_Pointer *ptr,struct token_functionlike_define_directive *define_directive);
- void token_ptr_execute_undef_directive(struct Token_Pointer *ptr,struct token_undef_directive *undef_directive);
- void token_ptr_execute_line_directive(struct Token_Pointer *ptr,struct token_line_directive *line_directive);
- void token_ptr_execute_error_directive(struct Token_Pointer *ptr,struct token_error_directive *error_directive);
- void token_ptr_execute_pragma_directive(struct Token_Pointer *ptr,struct token_pragma_directive *pragma_directive);
- void token_ptr_execute_defined_unary_operator(struct Token_Pointer *ptr,struct token_defined_unary_operator *operator);
+ struct Token_Pointer* get_token_ptr(struct Preprocessing_Translation_Unit *unit)
+ {
+ struct Token_Pointer *ret;
+ ret=wonky_malloc(sizeof(struct Token_Pointer));
+ ret->current_token_node=unit->tokens->first;
+ ret->call_stack=wonky_malloc(sizeof(struct Stack));
+ Stack_Init(ret->call_stack);
+ ret->location=NULL/*todo*/
+ }
+
+ void token_ptr_execute_include_directive(struct Token_Pointer *ptr,struct token_include_directive *include_directive)
+ {
+ token_ptr_goto_next_token(ptr);
+ }
+ void token_ptr_execute_if_directive(struct Token_Pointer *ptr,struct token_if_directive *if_directive)
+ {
+ token_ptr_goto_next_token(ptr);
+ }
+ void token_ptr_execute_ifdef_directive(struct Token_Pointer *ptr,struct token_ifdef_directive *ifdef_directive)
+ {
+ token_ptr_goto_next_token(ptr);
+ }
+ void token_ptr_execute_ifndef_directive(struct Token_Pointer *ptr,struct token_ifndef_directive *ifndef_directive)
+ {
+ token_ptr_goto_next_token(ptr);
+ }
+ void token_ptr_execute_normal_define_directive(struct Token_Pointer *ptr,struct token_normal_define_directive *define_directive)
+ {
+ token_ptr_goto_next_token(ptr);
+ }
+ void token_ptr_execute_functionlike_define_directive(struct Token_Pointer *ptr,struct token_functionlike_define_directive *define_directive)
+ {
+ token_ptr_goto_next_token(ptr);
+ }
+ void token_ptr_execute_undef_directive(struct Token_Pointer *ptr,struct token_undef_directive *undef_directive)
+ {
+ token_ptr_goto_next_token(ptr);
+ }
+ void token_ptr_execute_line_directive(struct Token_Pointer *ptr,struct token_line_directive *line_directive)
+ {
+ token_ptr_goto_next_token(ptr);
+ }
+ void token_ptr_execute_error_directive(struct Token_Pointer *ptr,struct token_error_directive *error_directive)
+ {
+ token_ptr_goto_next_token(ptr);
+ }
+ void token_ptr_execute_pragma_directive(struct Token_Pointer *ptr,struct token_pragma_directive *pragma_directive)
+ {
+ token_ptr_goto_next_token(ptr);
+ }
+ void token_ptr_execute_defined_unary_operator(struct Token_Pointer *ptr,struct token_defined_unary_operator *operator)
+ {
+ token_ptr_goto_next_token(ptr);
+ }
#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
#include <queue.h>
#include <source_file.h>
- #include <location.h>
#include <wonky_malloc.h>
+ #include <wonky_assert.h>
#include <queue.h>
+ #include <source_file.h>
struct Preprocessing_Translation_Unit
{
{
struct Queue_Node *current_token_node;
struct Stack *call_stack;
- struct Location *current_location;
- struct Translation_Unit *translation_unit;
+ struct Source_Location *current_location;
+ struct Program *program;
};
struct Preprocessing_Translation_Unit* get_preprocessing_translation_unit(struct Source_File *source);
void delete_preprocessing_translation_unit(struct Preprocessing_Translation_Unit *unit);
void push_token_into_preprocessing_translation_unit(struct Preprocessing_Translation_Unit *unit,struct token *token);
- struct token* get_token_under_pointer(struct Token_Pointer *token_pointer);
- void goto_next_token(struct Token_Pointer *token_pointer);
+ struct token* token_ptr_get_token_under_pointer(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);
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
#include <constant.hh>
#include <type.h>
#include <common.h>
+ #include <automata.h>
struct Constant
{
void *value;
};
- struct Constant* extract_constant(struct token *token,struct Translation_Data *translation_data);
- struct Constant* extract_literal_integer_octal(struct token *token,struct Translation_Data *translation_data);
- struct Constant* extract_literal_integer_dec(struct token *token,struct Translation_Data *translation_data);
- struct Constant* extract_literal_integer_hex(struct token *token,struct Translation_Data *translation_data);
- struct Constant* extract_literal_double_dec(struct token *token,struct Translation_Data *translation_data);
- struct Constant* extract_literal_double_hex(struct token *token,struct Translation_Data *translation_data);
- struct Constant* extract_literal_char(struct token *token,struct Translation_Data *translation_data);
- struct Constant* extract_literal_wide_char(struct token *token,struct Translation_Data *translation_data);
+ 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(struct token *token,struct Translation_Data *translation_data);
- struct Constant* extract_literal_wide_string(struct token *token,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);