Skip to content
Snippets Groups Projects
Commit 188808c1 authored by FlorianKrull's avatar FlorianKrull
Browse files

Merge branch 'develop' of https://git.uibk.ac.at/csaw2672/compiler-construction into ir

parents 55709080 7f449dae
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include "mcc/ast.h" #include "mcc/ast.h"
#include "mcc/ast_print.h"
#include "mcc/symbol_table_parse.h" #include "mcc/symbol_table_parse.h"
#include "utils/unused.h" #include "utils/unused.h"
...@@ -137,7 +138,7 @@ int mcc_symbol_table_parse_statement( ...@@ -137,7 +138,7 @@ int mcc_symbol_table_parse_statement(
struct mcc_symbol_table *table = symbol_table; struct mcc_symbol_table *table = symbol_table;
if (create_new) { if (create_new) {
table = mcc_symbol_table_create_inner_table(symbol_table,symbol_table->parent->sym_table_name); table = mcc_symbol_table_create_inner_table(symbol_table,"COMPOUND_STMT");
} }
switch(statement->type) { switch(statement->type) {
...@@ -340,6 +341,7 @@ struct mcc_symbol_table *mcc_symbol_table_build_program(struct mcc_ast_program * ...@@ -340,6 +341,7 @@ struct mcc_symbol_table *mcc_symbol_table_build_program(struct mcc_ast_program *
assert(program); assert(program);
struct mcc_symbol_table *st = mcc_symbol_table_new_table(NULL); struct mcc_symbol_table *st = mcc_symbol_table_new_table(NULL);
st->sym_table_name = "functions";
mcc_symbol_table_add_builtins(st); mcc_symbol_table_add_builtins(st);
...@@ -361,7 +363,7 @@ struct mcc_symbol_table *mcc_symbol_table_build_function(struct mcc_ast_function ...@@ -361,7 +363,7 @@ struct mcc_symbol_table *mcc_symbol_table_build_function(struct mcc_ast_function
assert(function); assert(function);
struct mcc_symbol_table *st = mcc_symbol_table_new_table(NULL); struct mcc_symbol_table *st = mcc_symbol_table_new_table(NULL);
st->sym_table_name = "functions";
mcc_symbol_table_add_builtins(st); mcc_symbol_table_add_builtins(st);
int parse_function = mcc_symbol_table_add_function_declaration(function, st, ec); int parse_function = mcc_symbol_table_add_function_declaration(function, st, ec);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "mcc/symbol_table.h" #include "mcc/symbol_table.h"
#include "mcc/symbol_table_print.h" #include "mcc/symbol_table_print.h"
static char *type_to_string(enum mcc_ast_data_type type){ static char *type_to_string(enum mcc_ast_data_type type){
switch (type) switch (type)
{ {
...@@ -29,12 +30,16 @@ static char *symbol_type_to_string(enum mcc_symbol_type type){ ...@@ -29,12 +30,16 @@ static char *symbol_type_to_string(enum mcc_symbol_type type){
} }
void mcc_symbol_table_print(struct mcc_symbol_table *symbol_table, FILE *out){ void mcc_symbol_table_print(struct mcc_symbol_table *symbol_table, FILE *out){
printf("----------------------------------\n");
printf("Table: %s // Child of: %s\n", symbol_table ? symbol_table->sym_table_name : "no name",
symbol_table->parent ? symbol_table->parent->sym_table_name : "no parent");
printf("----------------------------------\n");
for(int i = 0; i < symbol_table->symbols->size; i++){ for(int i = 0; i < symbol_table->symbols->size; i++){
struct mcc_symbol *sym = (struct mcc_symbol *) symbol_table->symbols->arr[i]; struct mcc_symbol *sym = (struct mcc_symbol *) symbol_table->symbols->arr[i];
if(sym->symbol_type != MCC_SYMBOL_TYPE_FUNCTION){ if(sym->symbol_type != MCC_SYMBOL_TYPE_FUNCTION){
fprintf(out,"\t"); fprintf(out,"\t");
} }
fprintf(out,"%*s | ", 15, symbol_type_to_string(sym->symbol_type)); fprintf(out,"%*s | ", 15, symbol_type_to_string(sym->symbol_type));
fprintf(out,"%*s | ", 6, type_to_string(sym->data_type)); fprintf(out,"%*s | ", 6, type_to_string(sym->data_type));
...@@ -43,7 +48,7 @@ void mcc_symbol_table_print(struct mcc_symbol_table *symbol_table, FILE *out){ ...@@ -43,7 +48,7 @@ void mcc_symbol_table_print(struct mcc_symbol_table *symbol_table, FILE *out){
case MCC_SYMBOL_TYPE_BUILTIN_FUNCTION: case MCC_SYMBOL_TYPE_BUILTIN_FUNCTION:
case MCC_SYMBOL_TYPE_VARIABLE: case MCC_SYMBOL_TYPE_VARIABLE:
fprintf(out,"%s", sym->variable_name); fprintf(out,"%s", sym->variable_name);
break; break;
case MCC_SYMBOL_TYPE_ARRAY: case MCC_SYMBOL_TYPE_ARRAY:
fprintf(out,"%s[%ld]", sym->variable_name, sym->array_size); fprintf(out,"%s[%ld]", sym->variable_name, sym->array_size);
break; break;
...@@ -63,21 +68,19 @@ void mcc_symbol_table_print(struct mcc_symbol_table *symbol_table, FILE *out){ ...@@ -63,21 +68,19 @@ void mcc_symbol_table_print(struct mcc_symbol_table *symbol_table, FILE *out){
}else{ }else{
fprintf(out,"%s()", sym->variable_name); fprintf(out,"%s()", sym->variable_name);
} }
fprintf(out,"\n"); fprintf(out,"\n");
for(int j = 0; j < symbol_table-> inner_tables -> size; j++){
struct mcc_symbol_table *it= (struct mcc_symbol_table *) symbol_table -> inner_tables -> arr[j];
if(it->sym_table_name == sym->variable_name){
mcc_symbol_table_print(it,out);
}
}
break; break;
} }
fprintf(out,"\n"); fprintf(out,"\n");
} }
for (int i = 0; i < symbol_table->inner_tables->size; i++) {
mcc_symbol_table_print(symbol_table->inner_tables->arr[i],out);
}
} }
void mcc_symbol_table_print_error(struct mcc_symbol_table_error_collector *ec, FILE *out) { void mcc_symbol_table_print_error(struct mcc_symbol_table_error_collector *ec, FILE *out) {
// for now only one error in collector // for now only one error in collector
struct mcc_semantic_error *error = ec -> errors -> arr[0]; struct mcc_semantic_error *error = ec -> errors -> arr[0];
......
...@@ -39,7 +39,7 @@ void clean_pointers( ...@@ -39,7 +39,7 @@ void clean_pointers(
struct mcc_ast_program *p, struct mcc_ast_program *p,
struct mcc_symbol_table_error_collector *ec) { struct mcc_symbol_table_error_collector *ec) {
mcc_symbol_table_delete_error_collector(ec); mcc_symbol_table_delete_error_collector(ec);
// mcc_ast_delete_program(p); mcc_ast_delete_program(p);
} }
...@@ -406,11 +406,11 @@ void InvalidReturnType(CuTest *ct) { ...@@ -406,11 +406,11 @@ void InvalidReturnType(CuTest *ct) {
TEST(BinaryOpHandsideNumberType) \ TEST(BinaryOpHandsideNumberType) \
TEST(BinaryOpHandsideDivisionByZero) \ TEST(BinaryOpHandsideDivisionByZero) \
TEST(ConditionBoolExpected) \ TEST(ConditionBoolExpected) \
// The following tests are currently not working due to unknown reasons /*The following tests are currently not working due to unknown reasons
// TEST(WrongArgumentType) \ // TEST(WrongArgumentType) \
// TEST(NoReturnInNonVoidFunction) \ // TEST(NoReturnInNonVoidFunction) \
// TEST(InvalidReturnType) \ // TEST(InvalidReturnType) \
// TEST(WrongNumOfArguments) \ // TEST(WrongNumOfArguments) \ */
#include "main_stub.inc" #include "main_stub.inc"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment