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
157e76cf
Commit
157e76cf
authored
5 years ago
by
FlorianKrull
Browse files
Options
Downloads
Patches
Plain Diff
Fixed symbol table printing
parent
b6e62f10
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/symbol_table_parse.c
+4
-2
4 additions, 2 deletions
src/symbol_table_parse.c
src/symbol_table_print.c
+13
-5
13 additions, 5 deletions
src/symbol_table_print.c
with
17 additions
and
7 deletions
src/symbol_table_parse.c
+
4
−
2
View file @
157e76cf
...
@@ -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
−
5
View file @
157e76cf
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
#include
"mcc/symbol_table.h"
#include
"mcc/symbol_table.h"
#include
"mcc/symbol_table_print.h"
#include
"mcc/symbol_table_print.h"
int
global_level
;
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,13 +31,20 @@ static char *symbol_type_to_string(enum mcc_symbol_type type){
...
@@ -29,13 +31,20 @@ static char *symbol_type_to_string(enum mcc_symbol_type type){
}
}
void
mcc_symbol_table_print
(
struct
mcc_symbol_table
*
symbol_table
,
FILE
*
out
,
int
level
){
void
mcc_symbol_table_print
(
struct
mcc_symbol_table
*
symbol_table
,
FILE
*
out
,
int
level
){
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
"
);
}
}
for
(
int
j
=
1
;
j
<
global_level
;
j
++
){
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 +52,7 @@ void mcc_symbol_table_print(struct mcc_symbol_table *symbol_table, FILE *out, in
...
@@ -43,7 +52,7 @@ void mcc_symbol_table_print(struct mcc_symbol_table *symbol_table, FILE *out, in
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,15 +72,14 @@ void mcc_symbol_table_print(struct mcc_symbol_table *symbol_table, FILE *out, in
...
@@ -63,15 +72,14 @@ void mcc_symbol_table_print(struct mcc_symbol_table *symbol_table, FILE *out, in
}
else
{
}
else
{
fprintf
(
out
,
"%s()"
,
sym
->
variable_name
);
fprintf
(
out
,
"%s()"
,
sym
->
variable_name
);
}
}
fprintf
(
out
,
"
\n
"
);
fprintf
(
out
,
"
\n
"
);
break
;
break
;
}
}
fprintf
(
out
,
"
\n
"
);
fprintf
(
out
,
"
\n
"
);
}
}
for
(
int
i
=
0
;
i
<
symbol_table
->
inner_tables
->
size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
symbol_table
->
inner_tables
->
size
;
i
++
)
{
mcc_symbol_table_print
(
symbol_table
->
inner_tables
->
arr
[
i
],
out
,
i
);
mcc_symbol_table_print
(
symbol_table
->
inner_tables
->
arr
[
i
],
out
,
i
);
}
}
}
}
...
...
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