#ifndef WONKY_TOKEN_H
#define WONKY_TOKEN_H WONKY_TOKEN_H
#include <token.hh>
#include <time.h>
#include <automata.h>
#include <constant.h>
#include <wonky_malloc.h>
#include <wonky_assert.h>
#include <source_file.h>
#include <macro.h>
/*the tokens are a bit heavy*/
struct token
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
};
struct token_identifier
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct identifier *id;
};
struct token_keyword
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct identifier *id;
};
struct token_punctuator
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
enum Punctuator_Token_Type punctuator_type;
};
struct token_constant
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct Constant *constant;
};
struct token_string
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct Constant *constant;
};
struct token_include_directive
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct Queue *tokens;
};
struct token_if_directive
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct Queue *controlling_expression;
struct Queue *if_true;
struct Queue *if_false;
};
struct token_ifdefndef_directive
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct token *id; /*keywords are also identifiers in preprocessing*/
struct Queue *if_defined;
struct Queue *if_undefined;
};
struct token_normal_define_directive
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct normal_define_directive *define;
};
struct token_functionlike_define_directive
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct functionlike_define_directive *define;
};
struct token_functionlike_define_argument
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct functionlike_define_directive_argument *argument;
};
struct token_undef_directive
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct token *id; /*keywords are also identifiers in preprocessing*/
};
struct token_line_directive
{
enum LEXER_TYPE type;
struct Source_Location_Delta *directive_delta;
size_t line;
char *filename;
size_t filename_size;
};
struct token_error_directive
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct Wonky_Message *error_message;
};
struct token_pragma_directive
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
enum Pragma_Type pragma_type;
};
struct token_defined_unary_operator
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct token *id;
};
struct token_hashtag_unary_operator
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct token_functionlike_define_argument *operand;
};
struct token_hashtag_hastag_operator
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct Queue *operands; /*queue of id and/or functionlike macro argument tokens*/
};
struct token_error
{
enum LEXER_TYPE type;
struct Source_Location_Delta *delta;
struct Wonky_Message *error;
};
/*
* OLD TOKEN STRUCT
struct token
{
enum LEXER_TYPE type;
size_t data_size;
char *data;
size_t line,column;
const char *filename;
};
*/
void handle_splicing(struct token *word);
char compare_tokens(struct token *a,struct token *b);
struct token* get_small_token(enum LEXER_TYPE type,struct Source_Location *current_location,struct Source_Location *previous_location);
struct token* get_id_token(struct identifier *id,struct Source_Location *current_location,struct Source_Location *previous_location);
struct token* get_keyword_token(enum LEXER_TYPE type,struct Source_Location *current_location,struct Source_Location *previous_location,struct identifier *id);
struct token* get_punctuator_token(enum LEXER_TYPE type,struct Source_Location *current_location,struct Source_Location *previous_location);
struct token* get_constant_token(enum LEXER_TYPE bare_type,struct Source_Location *current_location,struct Source_Location *previous_location,char *data,size_t size);
struct token* get_constant_long_long_int_token(struct Source_Location *current_location,struct Source_Location *previous_location,long long int number);
struct token* get_string_token(enum LEXER_TYPE bare_type,struct Source_Location *current_location,struct Source_Location *previous_location,char *data,size_t size);
struct token* get_include_directive_token(struct Source_Location *current_location,struct Source_Location *previous_location,struct Queue *tokens);
struct token* get_if_directive_token(struct Source_Location *current_location,struct Source_Location *previous_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_ifdef_directive_token(struct Source_Location *current_location,struct Source_Location *previous_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 *current_location,struct Source_Location *previous_location,struct identifier *id,struct Queue_Node *if_true,struct Queue_Node *if_false,struct Queue_Node *end_of_if_directive);
struct token* get_normal_define_directive_token(struct Source_Location *current_location,struct Source_Location *previous_location,struct identifier *id);
struct token* get_functionlike_define_directive_token(struct Source_Location *current_location,struct Source_Location *previous_location,struct identifier *id);
struct token* get_functionlike_define_directive_argument_token(struct Source_Location *current_location,struct Source_Location *previous_location,struct functionlike_define_directive_argument *argument);
struct token* get_undef_directive_token(struct Source_Location *current_location,struct Source_Location *previous_location,struct identifier *id);
struct token* get_line_directive_token(struct Source_Location *current_location,struct Source_Location *new_location,struct Source_Location *previous_location);
struct token* get_error_directive_token(struct Source_Location *current_location,struct Source_Location *previous_location,struct token_string *error_message);
struct token* get_pragma_directive(struct Source_Location *current_location,struct Source_Location *previous_location,enum Pragma_Type type);
struct token* get_defined_unary_operator(struct Source_Location *current_location,struct Source_Location *previous_location,struct identifier *id);
struct token* get_hashtag_unary_operator(struct Source_Location *current_location,struct Source_Location *previous_location,struct token_functionlike_define_directive *operand);
struct token* get_hashtag_hashtag_operator(struct Source_Location *current_location,struct Source_Location *previous_location,struct Queue *operands);
struct token* get_error_token(const char *msg,struct Source_Location *current_location,struct Source_Location *previous_location,struct Program *program,...);
struct token* get_eof_token();
struct token* get_token_from_two_adjacent_strings(struct token_string *first,struct token_string *second);
struct token* get_token_from_two_strings_with_a_space_between(struct token_string *first,struct token_string *second);
struct token* get_file_macro_token(struct Source_Location *current_location,struct Source_Location *previous_location);
struct token* get_date_macro_token(struct Source_Location *current_location,struct Source_Location *previous_location);
struct token* get_line_macro_token(struct Source_Location *current_location,struct Source_Location *previous_location);
struct token* get_stdc_macro_token(struct Source_Location *current_location,struct Source_Location *previous_location);
struct token* get_stdc_hosted_macro_token(struct Source_Location *current_location,struct Source_Location *previous_location);
struct token* get_stdc_version_macro_token(struct Source_Location *current_location,struct Source_Location *previous_location);
struct token* get_time_macro_token(struct Source_Location *current_location,struct Source_Location *previous_location);
char* get_string_from_token(struct token* token,size_t *size);
_Bool token_is_keyword(struct token *token);
_Bool token_is_identifier_in_preprocessing(struct token *token);
_Bool token_is_a_special_macro(struct token *token);
_Bool token_is_a_macro(struct token *token,size_t translation_unit_number);
void delete_token(struct token* token);
#endif