Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compiler-construction
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
User expired
compiler-construction
Commits
188808c1
Commit
188808c1
authored
5 years ago
by
FlorianKrull
Browse files
Options
Downloads
Plain Diff
Merge branch 'develop' of
https://git.uibk.ac.at/csaw2672/compiler-construction
into ir
parents
55709080
7f449dae
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/symbol_table_parse.c
+4
-2
4 additions, 2 deletions
src/symbol_table_parse.c
src/symbol_table_print.c
+13
-10
13 additions, 10 deletions
src/symbol_table_print.c
test/unit/symbol_table_test.c
+3
-3
3 additions, 3 deletions
test/unit/symbol_table_test.c
with
20 additions
and
15 deletions
src/symbol_table_parse.c
+
4
−
2
View file @
188808c1
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
src/symbol_table_print.c
+
13
−
10
View file @
188808c1
...
@@ -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
];
...
...
This diff is collapsed.
Click to expand it.
test/unit/symbol_table_test.c
+
3
−
3
View file @
188808c1
...
@@ -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"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment