F diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
include_directories(src/semantics/memory)
include_directories(src/semantics/value)
include_directories(src/semantics/constraints)
+ include_directories(src/debug)
include_directories(src/misc)
set(SOURCES
src/backend/print/print.c
+ src/debug/debug_ast.c
+ src/debug/debug_denoted.c
+ src/debug/debug_initialiser.c
+ src/debug/debug_lexer.c
+ src/debug/debug_linkage.c
+ src/debug/debug_scope.c
+ src/debug/debug_type.c
+ src/debug/debug_value.c
+ src/debug/debug_ast.c
src/frontend/lex/automatas/chonky.c
src/frontend/lex/automatas/chonky_jr.c
src/frontend/lex/lexer.c
src/program/program.c
src/semantics/ast.c
src/semantics/constraints/expression_constraints.c
+ src/semantics/constraints/initialiser_constraints.c
src/semantics/constraints/linkage_constraints.c
src/semantics/constraints/statement_constraints.c
- src/semantics/constraints/initialiser_constraints.c
src/semantics/identifiers/denoted.c
src/semantics/identifiers/linkage.c
src/semantics/identifiers/scope.c
F diff --git a/src/debug/debug.h b/src/debug/debug.h
new file mode 100644
--- /dev/null
+++ b/src/debug/debug.h
+ #ifndef WONKY_DEBUG_H
+ #define WONKY_DEBUG_H WONKY_DEBUG_H
+ #include<debug_ast.h>
+ #include<debug_denoted.h>
+ #include<debug_initialiser.h>
+ #include<debug_lexer.h>
+ #include<debug_linkage.h>
+ #include<debug_scope.h>
+ #include<debug_type.h>
+ #include<debug_value.h>
+
+ #endif
F diff --git a/src/debug/debug_ast.c b/src/debug/debug_ast.c
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_ast.c
+ #ifndef WONKY_DEBUG_AST_C
+ #define WONKY_DEBUG_AST_C WONKY_DEBUG_AST_C
+ #include <debug_ast.h>
+
+ _Bool is_valid_ast_enum(enum AST_Type ast_type)
+ {
+ return ast_type>=0 && ast_type<AST_TYPE_END;
+ }
+ _Bool is_valid_ast(struct AST *ast)
+ {
+ return ast==NULL || is_valid_ast_enum(ast->type);
+ }
+
+ _Bool is_valid_ast_expression(struct AST_Expression *expression)
+ {
+ if(expression==NULL || !is_valid_ast_enum(expression->type))
+ return 0;
+ else
+ return 1;
+ }
+ _Bool is_valid_ast_error(struct AST_Error *error)
+ {
+ if(error==NULL || !is_valid_ast_enum(error->type))
+ return 0;
+ else
+ return 1;
+ }
+ _Bool is_valid_binary_expression(struct AST_Binary_Expression *expression)
+ {
+ if(expression==NULL || !is_valid_ast_enum(expression->type))
+ return 0;
+ else
+ return 1;
+ }
+ _Bool is_valid_pointer_addition_expression(struct AST_Pointer_Addition_Expression *addition)
+ {
+ if(addition==NULL || !is_valid_ast_enum(addition->type))
+ return 0;
+ else
+ return 1;
+ }
+ _Bool is_valid_conditional_expression(struct AST_Conditional_Expression *conditional_expression)
+ {
+ if(conditional_expression==NULL || !is_valid_ast_enum(conditional_expression->type))
+ return 0;
+ else
+ return 1;
+ }
+ _Bool is_valid_function_expression(struct AST_Function_Expression *function_call)
+ {
+ if(function_call==NULL || !is_valid_ast_enum(function_call->type))
+ return 0;
+ else if(!is_valid_ast_expression(function_call->id))
+ return 0;
+ else
+ return 1;
+ }
+ _Bool is_valid_ast_constant(struct AST_Constant *constant)
+ {
+ if(constant==NULL || !is_valid_ast_enum(constant->type))
+ return 0;
+ else
+ return 1;
+ }
+ _Bool is_valid_ast_string_literal(struct AST_String_Literal *literal)
+ {
+ if(literal==NULL || !is_valid_ast_enum(literal->type))
+ return 0;
+ else
+ return 1;
+ }
+ _Bool is_valid_ast_designator(struct AST_Designator *designator)
+ {
+ return 1;
+ }
+ _Bool is_valid_unary_expression(struct AST_Unary_Expression *expression)
+ {
+ return 1;
+ }
+ _Bool is_valid_labeled_statement(struct AST_Labeled_Statement *statement)
+ {
+ return 1;
+ }
+ _Bool is_valid_case_statement(struct AST_Case_Statement *statement)
+ {
+ return 1;
+ }
+ _Bool is_valid_default_statement(struct AST_Default_Statement *statement)
+ {
+ return 1;
+ }
+ _Bool is_valid_break_continue_statement(struct AST_Break_Continue_Statement *statement)
+ {
+ return 1;
+ }
+ _Bool is_valid_compound_statement(struct AST_Compound_Statement *statement)
+ {
+ return 1;
+ }
+ _Bool is_valid_for_statement(struct AST_For_Statement *statement)
+ {
+ return 1;
+ }
+ _Bool is_valid_while_statement(struct AST_While_Statement *statement)
+ {
+ return 1;
+ }
+ _Bool is_valid_do_while_statement(struct AST_Do_While_Statement *statement)
+ {
+ return 1;
+ }
+ _Bool is_valid_if_statement(struct AST_If_Statement *statement)
+ {
+ return 1;
+ }
+ _Bool is_valid_goto_statement(struct AST_Goto_Statement *statement)
+ {
+ return 1;
+ }
+ _Bool is_valid_switch_statement(struct AST_Switch_Statement *statement)
+ {
+ return 1;
+ }
+ _Bool is_valid_return_statement(struct AST_Return_Statement *statement)
+ {
+ return 1;
+ }
+ _Bool is_valid_type_definition(struct AST_Type_Definition *definition)
+ {
+ return 1;
+ }
+ _Bool is_valid_object_declaration(struct AST_Object_Declaration *declaration)
+ {
+ return 1;
+ }
+ _Bool is_valid_function_definition(struct AST_Function_Definition *definition)
+ {
+ return 1;
+ }
+ _Bool is_valid_function_declaration(struct AST_Function_Declaration *declaration)
+ {
+ return 1;
+ }
+ _Bool is_valid_translation_unit(struct AST_Translation_Unit *unit)
+ {
+ return 1;
+ }
+ #endif
F diff --git a/src/debug/debug_ast.h b/src/debug/debug_ast.h
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_ast.h
+ #ifndef WONKY_DEBUG_AST_H
+ #define WONKY_DEBUG_AST_H WONKY_DEBUG_AST_H
+ #include <ast.h>
+ #include <debug.h>
+
+ _Bool is_valid_ast_enum(enum AST_Type ast_type);
+ _Bool is_valid_ast(struct AST *ast);
+
+ _Bool is_valid_ast_expression(struct AST_Expression *expression);
+ _Bool is_valid_ast_error(struct AST_Error *error);
+ _Bool is_valid_binary_expression(struct AST_Binary_Expression *expression);
+ _Bool is_valid_pointer_addition_expression(struct AST_Pointer_Addition_Expression *addition);
+ _Bool is_valid_conditional_expression(struct AST_Conditional_Expression *conditional_expression);
+ _Bool is_valid_function_expression(struct AST_Function_Expression *function_call);
+ _Bool is_valid_ast_constant(struct AST_Constant *constant);
+ _Bool is_valid_ast_string_literal(struct AST_String_Literal *literal);
+ _Bool is_valid_ast_designator(struct AST_Designator *designator);
+ _Bool is_valid_unary_expression(struct AST_Unary_Expression *expression);
+ _Bool is_valid_labeled_statement(struct AST_Labeled_Statement *statement);
+ _Bool is_valid_case_statement(struct AST_Case_Statement *statement);
+ _Bool is_valid_default_statement(struct AST_Default_Statement *statement);
+ _Bool is_valid_break_continue_statement(struct AST_Break_Continue_Statement *statement);
+ _Bool is_valid_compound_statement(struct AST_Compound_Statement *statement);
+ _Bool is_valid_for_statement(struct AST_For_Statement *statement);
+ _Bool is_valid_while_statement(struct AST_While_Statement *statement);
+ _Bool is_valid_do_while_statement(struct AST_Do_While_Statement *statement);
+ _Bool is_valid_if_statement(struct AST_If_Statement *statement);
+ _Bool is_valid_goto_statement(struct AST_Goto_Statement *statement);
+ _Bool is_valid_switch_statement(struct AST_Switch_Statement *statement);
+ _Bool is_valid_return_statement(struct AST_Return_Statement *statement);
+ _Bool is_valid_type_definition(struct AST_Type_Definition *definition);
+ _Bool is_valid_object_declaration(struct AST_Object_Declaration *declaration);
+ _Bool is_valid_function_definition(struct AST_Function_Definition *definition);
+ _Bool is_valid_function_declaration(struct AST_Function_Declaration *declaration);
+ _Bool is_valid_translation_unit(struct AST_Translation_Unit *unit);
+
+ #endif
F diff --git a/src/debug/debug_denoted.c b/src/debug/debug_denoted.c
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_denoted.c
+ #ifndef WONKY_DEBUG_DENOTED_C
+ #define WONKY_DEBUG_DENOTED_C WONKY_DEBUG_DENOTED_C
+ #include <debug_denoted.h>
+
+ _Bool is_valid_denotation_enum(enum Denotation_Type denotation_type)
+ {
+ return denotation_type>=0 && denotation_type<DENOTATION_TYPE_END;
+ }
+ _Bool is_valid_function_specifier(enum Function_Specifier function_specifier)
+ {
+ return function_specifier>=0 && function_specifier<FUNCTION_SPECIFIER_END;
+ }
+ _Bool is_valid_denoted(struct Denoted *denoted)
+ {
+ return is_valid_denotation_enum(denoted->denotation);
+ }
+
+ #endif
F diff --git a/src/debug/debug_denoted.h b/src/debug/debug_denoted.h
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_denoted.h
+ #ifndef WONKY_DEBUG_DENOTED_H
+ #define WONKY_DEBUG_DENOTED_H WONKY_DEBUG_DENOTED_H
+ #include <denoted.h>
+
+ _Bool is_valid_denotation_enum(enum Denotation_Type denotation_type);
+ _Bool is_valid_denoted(struct Denoted *denoted);
+ _Bool is_valid_function_specifier(enum Function_Specifier function_specifier);
+
+ #endif
F diff --git a/src/debug/debug_initialiser.c b/src/debug/debug_initialiser.c
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_initialiser.c
+ #ifndef WONKY_DEBUG_INITIALISER_C
+ #define WONKY_DEBUG_INITIALISER_C WONKY_DEBUG_INITIALISER_C
+ #include <debug_initialiser.h>
+
+ _Bool is_valid_initialiser_enum(enum Initialiser_Type initialiser_type)
+ {
+ return initialiser_type>=0 && initialiser_type<INITIALISER_TYPE_END;
+ }
+ _Bool is_valid_initialiser(struct Initialiser *initialiser)
+ {
+ return initialiser!=NULL && is_valid_initialiser_enum(initialiser->kind);
+ }
+ #endif
F diff --git a/src/debug/debug_initialiser.h b/src/debug/debug_initialiser.h
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_initialiser.h
+ #ifndef WONKY_DEBUG_INITIALISER_H
+ #define WONKY_DEBUG_INITIALISER_H WONKY_DEBUG_INITIALISER_H
+ #include <initialiser.h>
+
+ _Bool is_valid_initialiser_enum(enum Initialiser_Type initialiser_type);
+ _Bool is_valid_initialiser(struct Initialiser *initialiser);
+ #endif
F diff --git a/src/debug/debug_lexer.c b/src/debug/debug_lexer.c
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_lexer.c
+ #ifndef WONKY_DEBUG_LEXER_C
+ #define WONKY_DEBUG_LEXER_C WONKY_DEBUG_LEXER_C
+ #include <debug_lexer.h>
+
+ _Bool is_valid_keyword_enum(enum KEYWORDS keyword)
+ {
+ return keyword>=0 && keyword<KEYWORDS_END;
+ }
+ _Bool is_valid_token(struct token *token)
+ {
+ return is_valid_keyword_enum(token->type);
+ }
+ #endif
F diff --git a/src/debug/debug_lexer.h b/src/debug/debug_lexer.h
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_lexer.h
+ #ifndef WONKY_DEBUG_LEXER_H
+ #define WONKY_DEBUG_LEXER_H WONKY_DEBUG_LEXER_H
+ #include <chonky.h>
+ #include <lexer.h>
+
+ _Bool is_valid_keyword_enum(enum KEYWORDS keyword);
+ _Bool is_valid_token(struct token *token);
+ #endif
F diff --git a/src/debug/debug_linkage.c b/src/debug/debug_linkage.c
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_linkage.c
+ #ifndef WONKY_DEBUG_LINKAGE_C
+ #define WONKY_DEBUG_LINKAGE_C WONKY_DEBUG_LINKAGE_C
+ #include <debug_linkage.h>
+
+ _Bool is_valid_linkage_enum(enum Linkage_Type linkage_type)
+ {
+ return linkage_type>=0 && linkage_type<LINKAGE_TYPE_END;
+ }
+ _Bool is_valid_linkage(struct Linkage *linkage)
+ {
+ return 1;
+ }
+ #endif
F diff --git a/src/debug/debug_linkage.h b/src/debug/debug_linkage.h
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_linkage.h
+ #ifndef WONKY_DEBUG_LINKAGE_H
+ #define WONKY_DEBUG_LINKAGE_H WONKY_DEBUG_LINKAGE_H
+ #include <linkage.h>
+
+ _Bool is_valid_linkage_enum(enum Linkage_Type linkage_type);
+ _Bool is_valid_linkage(struct Linkage *linkage);
+
+ #endif
F diff --git a/src/debug/debug_scope.c b/src/debug/debug_scope.c
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_scope.c
+ #ifndef WONKY_DEBUG_SCOPE_C
+ #define WONKY_DEBUG_SCOPE_C WONKY_DEBUG_SCOPE_C
+ #include <debug_scope.h>
+
+ _Bool is_valid_scope_enum(enum Scope_Type scope_type)
+ {
+ return scope_type>=0 && scope_type<SCOPE_TYPE_END;
+ }
+ _Bool is_valid_scope(struct Scope *scope)
+ {
+ return is_valid_scope_enum(scope->type);
+ }
+
+ #endif
F diff --git a/src/debug/debug_scope.h b/src/debug/debug_scope.h
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_scope.h
+ #ifndef WONKY_DEBUG_SCOPE_H
+ #define WONKY_DEBUG_SCOPE_H WONKY_DEBUG_SCOPE_H
+ #include <scope.h>
+
+ _Bool is_valid_scope_enum(enum Scope_Type scope_type);
+ _Bool is_valid_scope(struct Scope *scope);
+
+ #endif
F diff --git a/src/debug/debug_type.c b/src/debug/debug_type.c
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_type.c
+ #ifndef WONKY_DEBUG_TYPE_C
+ #define WONKY_DEBUG_TYPE_C WONKY_DEBUG_TYPE_C
+ #include <debug_type.h>
+
+ _Bool is_valid_type_specifier_enum(enum Type_Specifier type_specifier)
+ {
+ return type_specifier>=0 && type_specifier<TYPE_SPECIFIER_END;
+ }
+ _Bool is_valid_type_constraint_enum(enum Type_Constraint type_constraint)
+ {
+ return type_constraint>=0 && type_constraint<TYPE_CONSTRAINT_END;
+ }
+ _Bool is_valid_type_signedness_enum(enum Type_Signedness type_signedness)
+ {
+ return type_signedness>=0 && type_signedness<TYPE_SIGNEDNESS_END;
+ }
+
+ _Bool is_valid_type(struct Type *type)
+ {
+ return is_valid_type_specifier_enum(type->specifier);
+ }
+ #endif
F diff --git a/src/debug/debug_type.h b/src/debug/debug_type.h
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_type.h
+ #ifndef WONKY_DEBUG_TYPE_H
+ #define WONKY_DEBUG_TYPE_H WONKY_DEBUG_TYPE_H
+ #include <type.h>
+
+ _Bool is_valid_type_specifier_enum(enum Type_Specifier type_specifier);
+ _Bool is_valid_type_constraint_enum(enum Type_Constraint type_constraint);
+ _Bool is_valid_type_signedness_enum(enum Type_Signedness type_signedness);
+ _Bool is_valid_type(struct Type *type);
+
+ #endif
F diff --git a/src/debug/debug_value.c b/src/debug/debug_value.c
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_value.c
+ #ifndef WONKY_DEBUG_VALUE_C
+ #define WONKY_DEBUG_VALUE_C WONKY_DEBUG_VALUE_C
+ #include <debug_value.h>
+
+ _Bool is_valid_expression_value_type(enum Expression_Value_Type expression_value_type)
+ {
+ return expression_value_type>=0 && expression_value_type<EXPRESSION_VALUE_TYPE_END;
+ }
+ _Bool is_valid_value(struct Expression_Value *value)
+ {
+ return is_valid_expression_value_type(value->type);
+ }
+ #endif
F diff --git a/src/debug/debug_value.h b/src/debug/debug_value.h
new file mode 100644
--- /dev/null
+++ b/src/debug/debug_value.h
+ #ifndef WONKY_DEBUG_VALUE_H
+ #define WONKY_DEBUG_VALUE_H WONKY_DEBUG_VALUE_H
+ #include <value.h>
+
+ _Bool is_valid_expression_value_type(enum Expression_Value_Type expression_value_type);
+ _Bool is_valid_value(struct Expression_Value *value);
+
+ #endif
F diff --git a/src/frontend/lex/automatas/chonky.h b/src/frontend/lex/automatas/chonky.h
--- a/src/frontend/lex/automatas/chonky.h
+++ b/src/frontend/lex/automatas/chonky.h
- enum KEYWORDS{KW_AUTO,KW_DO,KW_DOUBLE,KW_INT,KW_STRUCT,KW_BREAK,KW_ELSE,KW_LONG,KW_SWITCH,KW_CASE,KW_ENUM,KW_REGISTER,KW_TYPEDEF,KW_CHAR,KW_EXTERN,KW_RETURN,KW_UNION,KW_CONST,KW_FLOAT,KW_SHORT,KW_UNSIGNED,KW_CONTINUE,KW_FOR,KW_SIGNED,KW_VOID,KW_DEFAULT,KW_GOTO,KW_SIZEOF,KW_VOLATILE,KW_IF,KW_STATIC,KW_WHILE,KW_DEFINED,KW_EXCLAMATION,KW_BACK_SLASH,KW_PERCENT,KW_AND,KW_AND_AND,KW_OPEN_NORMAL,KW_CLOSE_NORMAL,KW_STAR,KW_PLUS,KW_COMMA,KW_MINUS,KW_ARROW,KW_COLUMN,KW_SEMI_COLUMN,KW_LESS,KW_EQ,KW_EQEQ,KW_MORE,KW_QUESTION,KW_OPEN_SQUARE,KW_CLOSE_SQUARE,KW_HAT,KW_FLOOR,KW_OPEN_CURLY,KW_CLOSE_CURLY,KW_PIPE,KW_PIPE_PIPE,KW_TILDE,KW_PLUSPLUS,KW_MINUSMINUS,KW_SHIFT_RIGHT,KW_SHIFT_LEFT,KW_LESS_EQ,KW_MORE_EQ,KW_NOT_EQ,KW_PLUS_EQ,KW_MINUS_EQ,KW_STAR_EQ,KW_PERCENT_EQ,KW_SHIFT_LEFT_EQ,KW_SHIFT_RIGHT_EQ,KW_AND_EQ,KW_HAT_EQ,KW_PIPE_EQ,KW_DOT,KW_DIV_EQ,KW_FORWARD_SLASH,KW_NOTYPE,KW_HEXADECIMAL_CONSTANT,KW_DECIMAL_CONSTANT,KW_OCTAL_CONSTANT ,KW_UNSIGNED_DECIMAL_CONSTANT,KW_UNSIGNED_OCTAL_CONSTANT,KW_UNSIGNED_HEXADECIMAL_CONSTANT,KW_UNSIGNED_LONG_HEXADECIMAL_CONSTANT,KW_UNSIGNED_LONG_OCTAL_CONSTANT,KW_UNSIGNED_LONG_DECIMAL_CONSTANT,KW_UNSIGNED_LONG_LONG_DECIMAL_CONSTANT,KW_UNSIGNED_LONG_LONG_HEXADECIMAL_CONSTANT,KW_UNSIGNED_LONG_LONG_OCTAL_CONSTANT,KW_LONG_HEXADECIMAL_CONSTANT,KW_LONG_OCTAL_CONSTANT,KW_LONG_DECIMAL_CONSTANT,KW_LONG_LONG_HEXADECIMAL_CONSTANT,KW_LONG_LONG_OCTAL_CONSTANT,KW_LONG_LONG_DECIMAL_CONSTANT,KW_DOUBLE_DECIMAL_CONSTANT,KW_LONG_DOUBLE_DECIMAL_CONSTANT,KW_FLOAT_DECIMAL_CONSTANT,KW_DOUBLE_HEXADECIMAL_CONSTANT,KW_LONG_DOUBLE_HEXADECIMAL_CONSTANT,KW_FLOAT_HEXADECIMAL_CONSTANT,KW_COMMENT,KW_ID,KW_CHAR_CONSTANT,KW_WIDE_CHAR_CONSTANT,KW_STRING,KW_WIDE_STRING,PKW_IF,PKW_IFDEF,PKW_IFNDEF,PKW_ELIF,PKW_ELSE,PKW_ENDIF,PKW_INCLUDE,PKW_DEFINE,PKW_UNDEF,PKW_LINE,PKW_ERROR,PKW_PRAGMA,PKW_COMMENT,PKW_NOTYPE,KW_HASHTAG,KW_HASHTAG_HASHTAG};
+ enum KEYWORDS{KW_AUTO,KW_DO,KW_DOUBLE,KW_INT,KW_STRUCT,KW_BREAK,KW_ELSE,KW_LONG,KW_SWITCH,KW_CASE,KW_ENUM,KW_REGISTER,KW_TYPEDEF,KW_CHAR,KW_EXTERN,KW_RETURN,KW_UNION,KW_CONST,KW_FLOAT,KW_SHORT,KW_UNSIGNED,KW_CONTINUE,KW_FOR,KW_SIGNED,KW_VOID,KW_DEFAULT,KW_GOTO,KW_SIZEOF,KW_VOLATILE,KW_IF,KW_STATIC,KW_WHILE,KW_DEFINED,KW_EXCLAMATION,KW_BACK_SLASH,KW_PERCENT,KW_AND,KW_AND_AND,KW_OPEN_NORMAL,KW_CLOSE_NORMAL,KW_STAR,KW_PLUS,KW_COMMA,KW_MINUS,KW_ARROW,KW_COLUMN,KW_SEMI_COLUMN,KW_LESS,KW_EQ,KW_EQEQ,KW_MORE,KW_QUESTION,KW_OPEN_SQUARE,KW_CLOSE_SQUARE,KW_HAT,KW_FLOOR,KW_OPEN_CURLY,KW_CLOSE_CURLY,KW_PIPE,KW_PIPE_PIPE,KW_TILDE,KW_PLUSPLUS,KW_MINUSMINUS,KW_SHIFT_RIGHT,KW_SHIFT_LEFT,KW_LESS_EQ,KW_MORE_EQ,KW_NOT_EQ,KW_PLUS_EQ,KW_MINUS_EQ,KW_STAR_EQ,KW_PERCENT_EQ,KW_SHIFT_LEFT_EQ,KW_SHIFT_RIGHT_EQ,KW_AND_EQ,KW_HAT_EQ,KW_PIPE_EQ,KW_DOT,KW_DIV_EQ,KW_FORWARD_SLASH,KW_NOTYPE,KW_HEXADECIMAL_CONSTANT,KW_DECIMAL_CONSTANT,KW_OCTAL_CONSTANT ,KW_UNSIGNED_DECIMAL_CONSTANT,KW_UNSIGNED_OCTAL_CONSTANT,KW_UNSIGNED_HEXADECIMAL_CONSTANT,KW_UNSIGNED_LONG_HEXADECIMAL_CONSTANT,KW_UNSIGNED_LONG_OCTAL_CONSTANT,KW_UNSIGNED_LONG_DECIMAL_CONSTANT,KW_UNSIGNED_LONG_LONG_DECIMAL_CONSTANT,KW_UNSIGNED_LONG_LONG_HEXADECIMAL_CONSTANT,KW_UNSIGNED_LONG_LONG_OCTAL_CONSTANT,KW_LONG_HEXADECIMAL_CONSTANT,KW_LONG_OCTAL_CONSTANT,KW_LONG_DECIMAL_CONSTANT,KW_LONG_LONG_HEXADECIMAL_CONSTANT,KW_LONG_LONG_OCTAL_CONSTANT,KW_LONG_LONG_DECIMAL_CONSTANT,KW_DOUBLE_DECIMAL_CONSTANT,KW_LONG_DOUBLE_DECIMAL_CONSTANT,KW_FLOAT_DECIMAL_CONSTANT,KW_DOUBLE_HEXADECIMAL_CONSTANT,KW_LONG_DOUBLE_HEXADECIMAL_CONSTANT,KW_FLOAT_HEXADECIMAL_CONSTANT,KW_COMMENT,KW_ID,KW_CHAR_CONSTANT,KW_WIDE_CHAR_CONSTANT,KW_STRING,KW_WIDE_STRING,PKW_IF,PKW_IFDEF,PKW_IFNDEF,PKW_ELIF,PKW_ELSE,PKW_ENDIF,PKW_INCLUDE,PKW_DEFINE,PKW_UNDEF,PKW_LINE,PKW_ERROR,PKW_PRAGMA,PKW_COMMENT,PKW_NOTYPE,KW_HASHTAG,KW_HASHTAG_HASHTAG,
+ KEYWORDS_END
+ };
struct automata_entry
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
}else if(current_token->type!=KW_NOTYPE)
{
-
expand_macro(current_token,src,translation_data);
}else
{
F diff --git a/src/frontend/lex/preprocessing.c b/src/frontend/lex/preprocessing.c
--- a/src/frontend/lex/preprocessing.c
+++ b/src/frontend/lex/preprocessing.c
hold_token->line=src->which_row;
hold_token->column=src->which_column;
+ assert(is_valid_token(hold_token));
+
Queue_Push(translation_data->tokens,hold_token);
}
}
}else
{
/*this isn't a macro, so we just push it to the token queue*/
+ assert(is_valid_token(macro_name));
Queue_Push(translation_data->tokens,macro_name);
}
}
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
function_type->function_prototype_scope->parent=(struct Scope*)hold_function->function_scope;
+ assert(is_valid_denoted((struct Denoted*)hold_function) && is_valid_type((struct Type*)function_type));
+
function_body
=
(struct AST_Compound_Statement*)
}
);
- Queue_Push(where_to_push,get_function_definition_tree(scope,(struct Denoted_Function*)hold,function_body,translation_data));
+ assert(is_valid_compound_statement(function_body));
+
+ Queue_Push(where_to_push,get_function_definition_tree(scope,hold_function,function_body,translation_data));
break;
}
/*this is a function declaration*/
real_type=(struct Denoted_Object*)hold;
to_be_initialised=(struct AST_Expression*)get_designator_tree_from_denoted_object(real_type,translation_data);
if(get_and_check(translation_data,KW_EQ))
+ {
initializer=parse_initialiser(translation_data,scope,real_type->object->type);
+ assert(is_valid_initialiser(initializer));
+ }
Queue_Push(where_to_push,get_object_declaration_tree((struct Denoted_Object*)hold,initializer));
break;
}
+ assert(is_valid_denoted(hold));
+
Scope_Push(scope,hold,translation_data);
parse_function_definitions=0;
+
if(!get_and_check(translation_data,KW_COMMA) && !check(translation_data,KW_SEMI_COLUMN,0))
{
/*TODO error*/
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
if(get_and_check(translation_data,KW_CLOSE_NORMAL))
{
+ assert(is_valid_function_expression(ret));
return ret;
}else
{
while(translation_data->tokens->size!=0)
{
+ assert(is_valid_ast_expression(hold_postfix_expression));
+
switch(kw_get(translation_data))
{
case KW_PLUSPLUS:
while(translation_data->tokens->size!=0)
{
+ assert(is_valid_ast_expression(hold_left_expression));
+
switch(kw_get(translation_data))
{
case KW_STAR:
while(translation_data->tokens->size!=0)
{
+ assert(is_valid_ast_expression(hold_left_expression));
switch(kw_get(translation_data))
{
case KW_PLUS:
while(translation_data->tokens->size!=0)
{
+ assert(is_valid_ast_expression(hold_left_expression));
switch(kw_get(translation_data))
{
case KW_SHIFT_LEFT:
while(translation_data->tokens->size!=0)
{
+ assert(is_valid_ast_expression(hold_left_expression));
switch(kw_get(translation_data))
{
case KW_LESS:
while(translation_data->tokens->size!=0)
{
+ assert(is_valid_ast_expression(hold_left_expression));
switch(kw_get(translation_data))
{
case KW_EQEQ:
while(get_and_check(translation_data,KW_AND))
{
+ assert(is_valid_ast_expression(hold_left_expression));
hold_right_expression=parse_equality_expression(translation_data,scope);
hold_left_expression=(struct AST_Expression*)get_bitwise_expression_tree(hold_left_expression,hold_right_expression,OP_BITWISE_AND,translation_data);
}
while(get_and_check(translation_data,KW_HAT))
{
+ assert(is_valid_ast_expression(hold_left_expression));
hold_right_expression=parse_and_expression(translation_data,scope);
hold_left_expression=(struct AST_Expression*)get_bitwise_expression_tree(hold_left_expression,hold_right_expression,OP_BITWISE_XOR,translation_data);
}
while(get_and_check(translation_data,KW_PIPE))
{
+ assert(is_valid_ast_expression(hold_left_expression));
+
hold_right_expression=parse_exclusive_or_expression(translation_data,scope);
hold_left_expression=(struct AST_Expression*)get_bitwise_expression_tree(hold_left_expression,hold_right_expression,OP_BITWISE_OR,translation_data);
}
while(get_and_check(translation_data,KW_AND_AND))
{
+ assert(is_valid_ast_expression(hold_left_expression));
+
hold_right_expression=parse_inclusive_or_expression(translation_data,scope);
hold_left_expression=(struct AST_Expression*)get_logical_expression_tree(hold_left_expression,hold_right_expression,OP_LOGICAL_AND,translation_data);
}
while(get_and_check(translation_data,KW_PIPE_PIPE))
{
+ assert(is_valid_ast_expression(hold_left_expression));
+
hold_right_expression=parse_logical_and_expression(translation_data,scope);
hold_left_expression=(struct AST_Expression*)get_logical_expression_tree(hold_left_expression,hold_right_expression,OP_LOGICAL_OR,translation_data);
}
struct AST_Expression *hold_right_expression;
hold_left_expression=parse_logical_or_expression(translation_data,scope);
+
+ assert(is_valid_ast_expression(hold_left_expression));
+
if(get_and_check(translation_data,KW_QUESTION))
{
hold_center_expression=(struct AST_Expression*)parse_expression(translation_data,scope);
hold_left_expression=parse_conditional_expression(translation_data,scope);
+ assert(is_valid_ast_expression(hold_left_expression));
+
if(translation_data->tokens->size==0)
return hold_left_expression;
default:
return hold_left_expression; /*BEWARE*/
}
+
chomp(translation_data);
hold_right_expression=parse_assignment_expression(translation_data,scope);
+ assert(is_valid_ast_expression(hold_right_expression));
+
if(operation_type==OP_ASSIGN)
return (struct AST_Expression*)get_simple_assignment_expression_tree(hold_left_expression,hold_right_expression,translation_data);
else
struct AST_Expression *hold_right_expression;
hold_left_expression=parse_assignment_expression(translation_data,scope);
+
+
while(get_and_check(translation_data,KW_COMMA))
{
+ assert(is_valid_ast_expression(hold_left_expression));
+
hold_right_expression=parse_assignment_expression(translation_data,scope);
hold_left_expression=(struct AST_Expression*)get_comma_expression_tree(hold_left_expression,hold_right_expression,translation_data);
}
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_finish_compound_statement(struct Translation_Data* translation_data,struct Scope *scope,struct Parse_Statement_Data *parse_data)
{
struct AST_Compound_Statement *hold;
+
hold=get_compound_statement_tree(scope);
+
while(!get_and_check(translation_data,KW_CLOSE_CURLY) && !has_no_tokens(translation_data))
{
if(is_type(translation_data,hold->scope,0))
chase_next_semicolumn(translation_data);
}
+ assert(is_valid_compound_statement(hold));
return (struct AST*)hold;
}
/*
push_translation_error(" '(' expected",translation_data);
return (struct AST*)get_error_tree((struct AST*)hold);
}
+
+ assert(is_valid_if_statement(hold));
return (struct AST*)hold;
}
/*
);
hold=get_switch_statement_tree(hold_control_expression,hold_body_statement);
+
+ assert(is_valid_switch_statement(hold));
return (struct AST*)hold;
}else
{
.current_switch_statement=parse_data->current_switch_statement,
}
);
+
+ assert(is_valid_while_statement(hold));
return (struct AST*)hold;
}else
{
if(get_and_check(translation_data,KW_CLOSE_NORMAL) && get_and_check(translation_data,KW_SEMI_COLUMN))
{
+ assert(is_valid_do_while_statement(hold));
return (struct AST*)hold;
}else
{
}
);
+ assert(is_valid_for_statement(hold));
return (struct AST*)hold;
}
/*
*/
struct AST* parse_finish_goto_statement(struct Translation_Data* translation_data,struct Scope *scope,struct Parse_Statement_Data *parse_data)
{
- struct AST* ret;
+ struct AST_Goto_Statement* ret;
if(check(translation_data,KW_ID,0))
{
- ret=(struct AST*)get_goto_statement_tree(Queue_Pop(translation_data->tokens),scope,translation_data);
+ ret=get_goto_statement_tree(Queue_Pop(translation_data->tokens),scope,translation_data);
if(get_and_check(translation_data,KW_SEMI_COLUMN))
{
- return ret;
+ assert(is_valid_goto_statement(ret));
+ return (struct AST*)ret;
}else
{
push_translation_error(" ';' expected",translation_data);
- return (struct AST*)get_error_tree(ret);
+ return (struct AST*)get_error_tree((struct AST*)ret);
}
}
else
struct AST* parse_finish_continue_statement(struct Translation_Data* translation_data,struct Parse_Statement_Data *parse_data)
{
+ struct AST_Break_Continue_Statement *hold;
if(get_and_check(translation_data,KW_SEMI_COLUMN))
{
- return (struct AST*)get_break_continue_statement_tree(parse_data->continue_statement_owner,translation_data,ST_CONTINUE);
+ hold=get_break_continue_statement_tree(parse_data->continue_statement_owner,translation_data,ST_CONTINUE);
+
+ assert(is_valid_break_continue_statement(hold));
+ return (struct AST*)hold;
}else
{
push_translation_error(" ';' expected",translation_data);
*/
struct AST* parse_finish_break_statement(struct Translation_Data* translation_data,struct Parse_Statement_Data *parse_data)
{
+ struct AST_Break_Continue_Statement *hold;
+
if(get_and_check(translation_data,KW_SEMI_COLUMN))
{
- return (struct AST*)get_break_continue_statement_tree(parse_data->break_statement_owner,translation_data,ST_BREAK);
+ hold=get_break_continue_statement_tree(parse_data->break_statement_owner,translation_data,ST_BREAK);
+
+ assert(is_valid_break_continue_statement(hold));
+ return (struct AST*)hold;
}else
{
push_translation_error(" ';' expected",translation_data);
{
struct AST *hold_statement;
struct token *hold_id;
+ struct AST_Labeled_Statement *hold;
+
/*id and ':' are checked for in the parse_statement function*/
hold_id=Queue_Pop(translation_data->tokens);
chomp(translation_data); /* ':' */
hold_statement=parse_statement(translation_data,scope,parse_data);
- return (struct AST*)get_labeled_statement_tree(hold_id,hold_statement,ST_LABEL,translation_data,scope);
+ hold=get_labeled_statement_tree(hold_id,hold_statement,ST_LABEL,translation_data,scope);
+
+ assert(is_valid_labeled_statement(hold));
+ return (struct AST*)hold;
}
/*
{
struct AST_Expression *hold_expression;
struct AST *hold_statement;
+ struct AST_Case_Statement *hold;
hold_expression=(struct AST_Expression*)parse_expression(translation_data,scope);
if(get_and_check(translation_data,KW_COLUMN))
{
hold_statement=parse_statement(translation_data,scope,parse_data);
- return (struct AST*)get_case_statement_tree(hold_statement,hold_expression,parse_data->current_switch_statement,translation_data);
+ hold=get_case_statement_tree(hold_statement,hold_expression,parse_data->current_switch_statement,translation_data);
+
+ assert(is_valid_case_statement(hold));
+ return (struct AST*)hold;
}else
{
push_translation_error(" ':' expected after expression in case statement",translation_data);
struct AST* parse_finish_default_statement(struct Translation_Data* translation_data,struct Scope *scope,struct Parse_Statement_Data *parse_data)
{
struct AST *statement;
+ struct AST_Default_Statement *hold;
+
if(get_and_check(translation_data,KW_COLUMN))
{
statement=parse_statement(translation_data,scope,parse_data);
- return (struct AST*)get_default_statement_tree(statement,translation_data);
+
+ hold=get_default_statement_tree(statement,translation_data);
+
+ assert(is_valid_default_statement(hold));
+ return (struct AST*)hold;
}else
{
push_translation_error(" ':' expected in default statement",translation_data);
if(get_and_check(translation_data,KW_SEMI_COLUMN))
{
hold=get_return_statement_tree(get_nop_tree(),translation_data,scope);
+
+ assert(is_valid_return_statement(hold));
return (struct AST*)hold;
}
hold=get_return_statement_tree(parse_expression(translation_data,scope),translation_data,scope);
if(get_and_check(translation_data,KW_SEMI_COLUMN))
{
+ assert(is_valid_return_statement(hold));
return (struct AST*)hold;
}else
{
}
if(get_and_check(translation_data,KW_SEMI_COLUMN))
{
+ assert(is_valid_ast(hold));
return hold;
}else
{
}
void chase_next_semicolumn(struct Translation_Data *translation_data)
{
- /*chase ; and start parsing next declaration*/
+ /*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)
{
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
chase_next_semicolumn(translation_data);
}
}
+
+ assert(is_valid_translation_unit(hold));
+
return (struct AST*)hold;
}
F diff --git a/src/semantics/ast.h b/src/semantics/ast.h
--- a/src/semantics/ast.h
+++ b/src/semantics/ast.h
#include <value.h>
#include <constraints.h>
#include <initialiser.h>
+ #include <debug.h>
F diff --git a/src/semantics/ast.hh b/src/semantics/ast.hh
--- a/src/semantics/ast.hh
+++ b/src/semantics/ast.hh
,ST_FUNCTION_DECLARATION
,TRANSLATION_UNIT
,ERROR,ERROR_DECLARATION
+ ,AST_TYPE_END
};
struct AST;
struct AST_Expression;
struct AST_Error;
struct AST_Declaration_Error;
struct AST_Binary_Expression;
+ struct AST_Pointer_Addition_Expression;
struct AST_Conditional_Expression;
struct AST_Function_Expression;
struct AST_Constant;
F diff --git a/src/semantics/identifiers/denoted.hh b/src/semantics/identifiers/denoted.hh
--- a/src/semantics/identifiers/denoted.hh
+++ b/src/semantics/identifiers/denoted.hh
DT_Struct_Union_Member,
DT_Struct_Union_Tag,
DT_Error,
- DT_Prototype
+ DT_Prototype,
+ DENOTATION_TYPE_END
};
enum Function_Specifier
{
FS_Inline,
- FS_None
+ FS_None,
+ FUNCTION_SPECIFIER_END
};
struct Denoted;
F diff --git a/src/semantics/identifiers/linkage.hh b/src/semantics/identifiers/linkage.hh
--- a/src/semantics/identifiers/linkage.hh
+++ b/src/semantics/identifiers/linkage.hh
{
LINKAGE_EXTERNAL,
LINKAGE_INTERNAL,
- LINKAGE_NONE
+ LINKAGE_NONE,
+ LINKAGE_TYPE_END
};
struct Linkage;
F diff --git a/src/semantics/identifiers/scope.hh b/src/semantics/identifiers/scope.hh
--- a/src/semantics/identifiers/scope.hh
+++ b/src/semantics/identifiers/scope.hh
FILE_SCOPE,
BLOCK_SCOPE,
FUNCTION_PROTOTYPE_SCOPE,
- FUNCTION_SCOPE
+ FUNCTION_SCOPE,
+ SCOPE_TYPE_END
};
struct Scope;
struct Normal_Scope;
F diff --git a/src/semantics/value/initialiser.hh b/src/semantics/value/initialiser.hh
--- a/src/semantics/value/initialiser.hh
+++ b/src/semantics/value/initialiser.hh
#ifndef WONKY_INITIALISER_HH
#define WONKY_INITIALISER_HH WONKY_INITIALISER_HH
- enum Initialiser_Type { INITIALISER_DENOTED , INITIALISER_INDEXED , INITIALISER_COMPOUND , INITIALISER_EXPRESSION , INITIALISER_ERROR };
+ enum Initialiser_Type
+ {
+ INITIALISER_DENOTED,
+ INITIALISER_INDEXED,
+ INITIALISER_COMPOUND,
+ INITIALISER_EXPRESSION,
+ INITIALISER_ERROR,
+ INITIALISER_TYPE_END
+ };
struct Initialiser;
struct Initialiser_Denoted;
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
#ifndef WONKY_TYPE_HH
#define WONKY_TYPE_HH WONKY_TYPE_HH
- #define PTR_SIZE 4
+ #define PTR_SIZE 8
#define INT_SIZE 4
#define CHAR_SIZE 1
#define WCHAR_SIZE 4
TS_ARRAY,
TS_FUNC,
TS_NONE,
- TS_ERROR
+ TS_ERROR,
+ TYPE_SPECIFIER_END
};
enum Type_Constraint
{
TC_LONG,
TC_LONG_LONG,
TC_SHORT,
- TC_NONE
+ TC_NONE,
+ TYPE_CONSTRAINT_END
};
enum Type_Signedness
{
TSIGN_SIGNED,
TSIGN_UNSIGNED,
- TSIGN_NONE
+ TSIGN_NONE,
+ TYPE_SIGNEDNESS_END
};
struct Type;
struct Type_Error;
F diff --git a/src/semantics/value/value.hh b/src/semantics/value/value.hh
--- a/src/semantics/value/value.hh
+++ b/src/semantics/value/value.hh
VALUE_TEMP,
VALUE_FUNCTION_DESIGNATOR,
VALUE_CONSTANT,
- VALUE_VOID
+ VALUE_VOID,
+ EXPRESSION_VALUE_TYPE_END
};
struct Expression_Value;