Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
72ef7497
Commit
72ef7497
authored
Oct 29, 2019
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Update ASTSymbolTableBuilder tests to take functions into account
parent
11a52edf
No related branches found
No related tags found
1 merge request
!37
Feature/language
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/language/ASTSymbolTableBuilder.cpp
+7
-6
7 additions, 6 deletions
src/language/ASTSymbolTableBuilder.cpp
tests/test_ASTSymbolTableBuilder.cpp
+40
-12
40 additions, 12 deletions
tests/test_ASTSymbolTableBuilder.cpp
with
47 additions
and
18 deletions
src/language/ASTSymbolTableBuilder.cpp
+
7
−
6
View file @
72ef7497
...
@@ -46,23 +46,24 @@ ASTSymbolTableBuilder::buildSymbolTable(ASTNode& n, std::shared_ptr<SymbolTable>
...
@@ -46,23 +46,24 @@ ASTSymbolTableBuilder::buildSymbolTable(ASTNode& n, std::shared_ptr<SymbolTable>
throw
parse_error
(
error_message
.
str
(),
std
::
vector
{
n
.
begin
()});
throw
parse_error
(
error_message
.
str
(),
std
::
vector
{
n
.
begin
()});
}
}
}
else
if
(
n
.
is_type
<
language
::
function_definition
>
())
{
}
else
if
(
n
.
is_type
<
language
::
function_definition
>
())
{
auto
register_symbol
=
[
&
](
const
std
::
string
&
symbol
)
{
auto
register_symbol
=
[
&
](
const
ASTNode
&
argument_node
)
{
auto
[
i_symbol
,
success
]
=
symbol_table
->
add
(
symbol
,
n
.
children
[
0
]
->
begin
());
auto
[
i_symbol
,
success
]
=
symbol_table
->
add
(
argument_node
.
string
(),
argument_node
.
begin
());
if
(
not
success
)
{
if
(
not
success
)
{
std
::
ostringstream
error_message
;
std
::
ostringstream
error_message
;
error_message
<<
"symbol '"
<<
rang
::
fg
::
red
<<
symbol
<<
rang
::
fg
::
reset
<<
"' was already defined!"
;
error_message
<<
"symbol '"
<<
rang
::
fg
::
red
<<
argument_node
.
string
()
<<
rang
::
fg
::
reset
throw
parse_error
(
error_message
.
str
(),
std
::
vector
{
n
.
begin
()});
<<
"' was already defined!"
;
throw
parse_error
(
error_message
.
str
(),
std
::
vector
{
argument_node
.
begin
()});
}
}
// Symbols will be initialized at call
// Symbols will be initialized at call
i_symbol
->
attributes
().
setIsInitialized
();
i_symbol
->
attributes
().
setIsInitialized
();
};
};
if
(
n
.
children
[
0
]
->
is_type
<
language
::
name
>
())
{
if
(
n
.
children
[
0
]
->
is_type
<
language
::
name
>
())
{
register_symbol
(
n
.
children
[
0
]
->
string
()
);
register_symbol
(
*
n
.
children
[
0
]);
}
else
{
// treats the case of list of parameters
}
else
{
// treats the case of list of parameters
Assert
(
n
.
children
[
0
]
->
is_type
<
language
::
name_list
>
());
Assert
(
n
.
children
[
0
]
->
is_type
<
language
::
name_list
>
());
for
(
auto
&
child
:
n
.
children
[
0
]
->
children
)
{
for
(
auto
&
child
:
n
.
children
[
0
]
->
children
)
{
register_symbol
(
child
->
string
()
);
register_symbol
(
*
child
);
}
}
}
}
}
else
if
(
n
.
is_type
<
language
::
name
>
())
{
}
else
if
(
n
.
is_type
<
language
::
name
>
())
{
...
...
This diff is collapsed.
Click to expand it.
tests/test_ASTSymbolTableBuilder.cpp
+
40
−
12
View file @
72ef7497
...
@@ -21,6 +21,8 @@ N n = 2;
...
@@ -21,6 +21,8 @@ N n = 2;
ASTSymbolTableBuilder
{
*
ast
};
ASTSymbolTableBuilder
{
*
ast
};
}
}
SECTION
(
"errors"
)
{
SECTION
(
"Undeclared symbol"
)
SECTION
(
"Undeclared symbol"
)
{
{
std
::
string_view
data
=
R"(
std
::
string_view
data
=
R"(
...
@@ -45,4 +47,30 @@ N n = 1;
...
@@ -45,4 +47,30 @@ N n = 1;
REQUIRE_THROWS_AS
(
ASTSymbolTableBuilder
{
*
ast
},
parse_error
);
REQUIRE_THROWS_AS
(
ASTSymbolTableBuilder
{
*
ast
},
parse_error
);
}
}
SECTION
(
"Re-declared symbol (function)"
)
{
std
::
string_view
data
=
R"(
N f;
let f : R -> R, x -> 1;
)"
;
string_input
input
{
data
,
"test.pgs"
};
auto
ast
=
ASTBuilder
::
build
(
input
);
REQUIRE_THROWS_AS
(
ASTSymbolTableBuilder
{
*
ast
},
parse_error
);
}
SECTION
(
"Re-declared parameter (function)"
)
{
std
::
string_view
data
=
R"(
let f : R*R*N -> R, (x,y,x) -> 1;
)"
;
string_input
input
{
data
,
"test.pgs"
};
auto
ast
=
ASTBuilder
::
build
(
input
);
REQUIRE_THROWS_AS
(
ASTSymbolTableBuilder
{
*
ast
},
parse_error
);
}
}
}
}
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
sign in
to comment