#ifndef WONKY_AST_H
#define WONKY_AST_H WONKY_AST_H
#include <ast.hh>
#include <scope.h>
#include <parse_declaration.h>
#include <denoted.h>
#include <linkage.h>
#include <value.h>
#include <constraints.h>
#include <initialiser.h>
#include <debug.h>
#include <common.h>
enum AST_Type;
struct AST
{
enum AST_Type type;
};
struct AST_Expression
{
enum AST_Type type;
struct Expression_Value *value;
};
struct AST_Error
{
enum AST_Type type;
struct AST *error;
};
struct AST_Declaration_Error
{
enum AST_Type type;
struct Denoted *error;
};
struct AST_Binary_Expression
{
enum AST_Type type;
struct Expression_Value *value;
struct AST_Expression *left;
struct AST_Expression *right;
};
struct AST_Pointer_Addition_Expression
{
enum AST_Type type;
struct Expression_Value *value;
struct AST_Expression *pointer;
struct AST_Expression *integer;
};
struct AST_Conditional_Expression
{
enum AST_Type type;
struct Expression_Value *value;
struct AST_Expression *left;
struct AST_Expression *center;
struct AST_Expression *right;
};
struct AST_Function_Expression
{
enum AST_Type type;
struct Expression_Value *value;
struct AST_Expression *id;
size_t number_of_arguments;
struct AST_Expression **arg_list;
};
struct AST_Constant
{
enum AST_Type type;
struct Expression_Value_Constant *value;
};
struct AST_String_Literal
{
enum AST_Type type;
struct Expression_Value_Constant *value;
};
struct AST_Designator
{
enum AST_Type type;
struct Expression_Value *value;
struct identifier *id;
};
struct AST_Unary_Expression
{
enum AST_Type type;
struct Expression_Value *value;
struct AST_Expression *operand;
};
struct AST_Labeled_Statement
{
enum AST_Type type;
struct Denoted_Statement *label;
};
struct AST_Case_Statement
{
enum AST_Type type;
struct AST_Expression *control;
struct AST *statement;
};
struct AST_Default_Statement
{
enum AST_Type type;
struct AST *statement;
};
struct AST_Break_Continue_Statement
{
enum AST_Type type;
struct AST *parent;
};
struct AST_Compound_Statement
{
enum AST_Type type;
struct Scope *scope;
struct Queue *components;
};
struct AST_For_Statement
{
enum AST_Type type;
struct AST *condition;
struct AST *initialisation;
struct AST *update;
struct AST *body_statement;
};
struct AST_While_Statement
{
enum AST_Type type;
struct AST *condition;
struct AST *body_statement;
};
struct AST_Do_While_Statement
{
enum AST_Type type;
struct AST *body_statement;
struct AST *condition;
};
struct AST_If_Statement
{
enum AST_Type type;
struct AST* condition;
struct AST* body_statement;
struct AST* else_statement;
};
struct AST_Goto_Statement
{
enum AST_Type type;
struct Denoted_Statement *label;
struct Denoted_Object *previous_denoted_object;
};
struct AST_Switch_Statement
{
enum AST_Type type;
struct AST_Expression* condition;
struct AST* body_statement;
struct Queue *cases;
};
struct AST_Return_Statement
{
enum AST_Type type;
struct Scope *checkpoint;
struct AST *return_expression;
};
struct AST_Type_Definition
{
enum AST_Type type;
struct Denoted_Type *definition;
};
struct AST_Object_Declaration
{
enum AST_Type type;
struct Denoted_Object *object;
struct Initialiser *initializer;
};
struct AST_Function_Definition
{
enum AST_Type type;
struct Denoted_Function *function;
struct AST_Compound_Statement *body;
};
struct AST_Function_Declaration
{
enum AST_Type type;
struct Denoted_Function *function;
};
struct AST_Translation_Unit
{
enum AST_Type type;
//struct Queue *components; /*Queue of external declarations*/
struct Queue *function_definitions;
struct Queue *object_declarations;
struct Scope *file_scope;
struct Linkage *internal_linkage;
};
struct AST_Error* get_error_tree(struct AST *error);
struct AST_Declaration_Error* get_declaration_error_tree(struct Denoted *error);
struct AST_Expression* get_promoted_expression(struct AST_Expression *operand,struct Translation_Data *translation_data);
struct AST_Expression* get_promoted_expression_for_function_call(struct AST_Expression *operand,struct Translation_Data *translation_data);
struct AST_Expression* get_cast_expression_tree(struct AST_Expression *operand,struct Type *type,struct Translation_Data *translation_data);
struct AST_Expression* get_degraded_array_expression_if_it_has_the_right_type(struct AST_Expression *expression,struct Translation_Data *translation_data);
struct AST_Binary_Expression* get_binary_expression_after_conversion(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type type,struct Translation_Data *translation_data);
struct AST_Binary_Expression* get_binary_expression_tree(struct AST_Expression *left,struct AST_Expression *right,struct Expression_Value *value,enum AST_Type type);
struct AST_Binary_Expression* get_modulo_tree(struct AST_Expression *left,struct AST_Expression *right,struct Translation_Data *translation_data);
struct AST_Binary_Expression* get_multiplicative_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
struct AST_Binary_Expression* get_additive_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
struct AST_Binary_Expression* get_shift_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
struct AST_Binary_Expression* get_bitwise_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
struct AST_Binary_Expression* get_relation_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
struct AST_Binary_Expression* get_equality_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
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);
struct AST_Binary_Expression* get_simple_assignment_expression_tree(struct AST_Expression *left,struct AST_Expression *right,struct Translation_Data *translation_data);
struct AST_Binary_Expression* get_compound_assignment_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data);
struct AST_Binary_Expression* get_comma_expression_tree(struct AST_Expression *left,struct AST_Expression *right,struct Translation_Data *translation_data);
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 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_Unary_Expression* get_unary_expression_tree(struct AST_Expression *operand,struct Expression_Value *value,enum AST_Type type);
struct AST_Unary_Expression* get_indirection_expression_tree(struct AST_Expression *operand,struct Translation_Data *translation_data);
struct AST_Unary_Expression* get_address_expression_tree(struct AST_Expression *operand,struct Translation_Data *translation_data);
struct AST_Unary_Expression* get_sizeof_by_type_tree(struct Type *type);
struct AST_Unary_Expression* get_unary_plus_minus_expression(struct AST_Expression *operand,enum AST_Type operation,struct Translation_Data *translation_data);
struct AST_Unary_Expression* get_unary_bitwise_not_expression(struct AST_Expression *operand,struct Translation_Data *translation_data);
struct AST_Unary_Expression* get_unary_logical_not_expression(struct AST_Expression *operand,struct Translation_Data *translation_data);
struct AST_Unary_Expression* get_postfix_inc_dec_tree(struct AST_Expression *operand,enum AST_Type operation,struct Translation_Data *translation_data);
struct AST_Unary_Expression* get_prefix_inc_dec_tree(struct AST_Expression *operand,enum AST_Type operation,struct Translation_Data *translation_data);
struct AST_Unary_Expression* get_unary_sizeof_tree(struct AST_Expression *operand,struct Translation_Data *translation_data);
//TODO compound literals
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_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 identifier *id,struct Normal_Scope *inner_scope,struct Translation_Data *translation_data);
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_Compound_Statement* get_compound_statement_tree(struct Scope *parent_scope);
struct AST_If_Statement* get_if_statement_tree();
struct AST_Switch_Statement* get_switch_statement_tree(struct AST_Expression *condidion,struct AST *body_statement);
struct AST_While_Statement* get_while_statement_tree();
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 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);
struct AST_Function_Declaration* get_function_declaration_tree(struct Scope *scope,struct Denoted_Function *function);
struct AST_Function_Definition* get_function_definition_tree(struct Scope *scope,struct Denoted_Function *function,struct AST_Compound_Statement *function_body,struct Translation_Data *translation_data);
struct AST_Translation_Unit* get_translation_unit_tree();
void delete_ast(struct AST* ast);
void delete_ast_error(struct AST_Error *error);
void delete_ast_declaration_error(struct AST_Declaration_Error *error);
void delete_ast_binary_expression(struct AST_Binary_Expression *binary_expression);
void delete_ast_conditional_expression(struct AST_Conditional_Expression *cond_expression);
void delete_ast_function_expression(struct AST_Function_Expression *function_expression);
void delete_ast_constant(struct AST_Constant *constant);
void delete_ast_string_literal(struct AST_String_Literal *string);
void delete_ast_designator_expression(struct AST_Designator *designator);
void delete_ast_unary_expression(struct AST_Unary_Expression *unary_expression);
void delete_ast_labeled_statement(struct AST_Labeled_Statement *labeled_statement);
void delete_ast_default_statement(struct AST_Default_Statement *default_statement);
void delete_ast_break_continue_statement(struct AST_Break_Continue_Statement *break_continue);
void delete_ast_compound_statement(struct AST_Compound_Statement *compound_statement);
void delete_ast_for_statement(struct AST_For_Statement *for_statement);
void delete_ast_while_statemtent(struct AST_While_Statement *while_statement);
void delete_ast_do_while_statement(struct AST_Do_While_Statement *do_while_statement);
void delete_ast_if_statemtent(struct AST_If_Statement *if_statement);
void delete_ast_goto_statemtent(struct AST_Goto_Statement *goto_statement);
void delete_ast_switch_statement(struct AST_Switch_Statement *switch_statement);
void delete_ast_case_statement(struct AST_Case_Statement *case_statement);
void delete_ast_return_statement(struct AST_Return_Statement *return_statement);
void delete_ast_type_definition(struct AST_Type_Definition *type_definition);
void delete_ast_object_declaration(struct AST_Object_Declaration *object_declaration);
void delete_ast_function_definition(struct AST_Function_Definition *function_definition);
void delete_ast_function_declaration(struct AST_Function_Declaration *function_declaration);
void delete_ast_translation_unit(struct AST_Translation_Unit *translation_unit);
#endif