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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
27d9a80e
Commit
27d9a80e
authored
3 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add missing tests for SymbolTable
parent
d1b7dc82
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!104
Add missing tests for ASTNodeBuiltinFunctionExpressionBuilder
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/language/utils/SymbolTable.hpp
+13
-15
13 additions, 15 deletions
src/language/utils/SymbolTable.hpp
tests/test_SymbolTable.cpp
+40
-0
40 additions, 0 deletions
tests/test_SymbolTable.cpp
with
53 additions
and
15 deletions
src/language/utils/SymbolTable.hpp
+
13
−
15
View file @
27d9a80e
...
@@ -285,10 +285,8 @@ class SymbolTable
...
@@ -285,10 +285,8 @@ class SymbolTable
std
::
vector
<
Symbol
>
builtin_function_symbol_list
;
std
::
vector
<
Symbol
>
builtin_function_symbol_list
;
for
(
auto
i_stored_symbol
:
m_symbol_list
)
{
for
(
auto
i_stored_symbol
:
m_symbol_list
)
{
if
(
use_position
.
byte
<
i_stored_symbol
.
attributes
().
position
().
byte
)
continue
;
// Symbol must be defined before the call
// Symbol must be defined before the call
if
(
use_position
.
byte
>=
i_stored_symbol
.
attributes
().
position
().
byte
)
{
std
::
string_view
stored_symbol_name
=
i_stored_symbol
.
name
();
std
::
string_view
stored_symbol_name
=
i_stored_symbol
.
name
();
if
((
stored_symbol_name
.
size
()
>
symbol
.
size
())
and
(
stored_symbol_name
[
symbol
.
size
()]
==
':'
))
{
if
((
stored_symbol_name
.
size
()
>
symbol
.
size
())
and
(
stored_symbol_name
[
symbol
.
size
()]
==
':'
))
{
if
(
stored_symbol_name
.
substr
(
0
,
symbol
.
size
())
==
symbol
)
{
if
(
stored_symbol_name
.
substr
(
0
,
symbol
.
size
())
==
symbol
)
{
...
@@ -296,6 +294,7 @@ class SymbolTable
...
@@ -296,6 +294,7 @@ class SymbolTable
}
}
}
}
}
}
}
if
(
m_parent_table
)
{
if
(
m_parent_table
)
{
return
m_parent_table
->
getBuiltinFunctionSymbolList
(
symbol
,
use_position
);
return
m_parent_table
->
getBuiltinFunctionSymbolList
(
symbol
,
use_position
);
...
@@ -308,10 +307,8 @@ class SymbolTable
...
@@ -308,10 +307,8 @@ class SymbolTable
has
(
const
std
::
string
&
symbol
,
const
TAO_PEGTL_NAMESPACE
::
position
&
use_position
)
has
(
const
std
::
string
&
symbol
,
const
TAO_PEGTL_NAMESPACE
::
position
&
use_position
)
{
{
for
(
auto
i_stored_symbol
:
m_symbol_list
)
{
for
(
auto
i_stored_symbol
:
m_symbol_list
)
{
if
(
use_position
.
byte
<
i_stored_symbol
.
attributes
().
position
().
byte
)
continue
;
// Symbol must be defined before the call
// Symbol must be defined before the call
if
(
use_position
.
byte
>=
i_stored_symbol
.
attributes
().
position
().
byte
)
{
std
::
string_view
stored_symbol_name
=
i_stored_symbol
.
name
();
std
::
string_view
stored_symbol_name
=
i_stored_symbol
.
name
();
if
((
stored_symbol_name
.
size
()
==
symbol
.
size
())
or
if
((
stored_symbol_name
.
size
()
==
symbol
.
size
())
or
(
stored_symbol_name
.
size
()
>
symbol
.
size
()
and
(
stored_symbol_name
[
symbol
.
size
()]
==
':'
)))
{
(
stored_symbol_name
.
size
()
>
symbol
.
size
()
and
(
stored_symbol_name
[
symbol
.
size
()]
==
':'
)))
{
...
@@ -320,6 +317,7 @@ class SymbolTable
...
@@ -320,6 +317,7 @@ class SymbolTable
}
}
}
}
}
}
}
if
(
m_parent_table
)
{
if
(
m_parent_table
)
{
return
m_parent_table
->
has
(
symbol
,
use_position
);
return
m_parent_table
->
has
(
symbol
,
use_position
);
...
...
This diff is collapsed.
Click to expand it.
tests/test_SymbolTable.cpp
+
40
−
0
View file @
27d9a80e
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include
<language/utils/BuiltinFunctionEmbedder.hpp>
#include
<language/utils/BuiltinFunctionEmbedder.hpp>
#include
<language/utils/SymbolTable.hpp>
#include
<language/utils/SymbolTable.hpp>
#include
<language/utils/TypeDescriptor.hpp>
#include
<pegtl/internal/iterator.hpp>
#include
<pegtl/internal/iterator.hpp>
...
@@ -186,6 +187,29 @@ TEST_CASE("SymbolTable", "[language]")
...
@@ -186,6 +187,29 @@ TEST_CASE("SymbolTable", "[language]")
value_output
<<
symbol
.
attributes
();
value_output
<<
symbol
.
attributes
();
REQUIRE
(
value_output
.
str
()
==
"function_id:2"
);
REQUIRE
(
value_output
.
str
()
==
"function_id:2"
);
}
}
{
const
SymbolTable
::
Symbol
symbol_decl
{
i_symbol_a
->
name
(),
i_symbol_a
->
attributes
()};
SymbolTable
::
Attributes
attributes_b
=
attributes_a
;
SymbolTable
::
Symbol
symbol
(
"foo"
,
attributes_b
);
symbol
=
symbol_decl
;
std
::
stringstream
value_output
;
value_output
<<
symbol
.
attributes
();
REQUIRE
(
value_output
.
str
()
==
"function_id:2"
);
}
{
SymbolTable
::
Attributes
attributes_b
=
attributes_a
;
SymbolTable
::
Symbol
symbol
(
"foo"
,
attributes_b
);
symbol
=
SymbolTable
::
Symbol
{
i_symbol_a
->
name
(),
i_symbol_a
->
attributes
()};
std
::
stringstream
value_output
;
value_output
<<
symbol
.
attributes
();
REQUIRE
(
value_output
.
str
()
==
"function_id:2"
);
}
}
}
SECTION
(
"FunctionTable"
)
SECTION
(
"FunctionTable"
)
...
@@ -220,4 +244,20 @@ TEST_CASE("SymbolTable", "[language]")
...
@@ -220,4 +244,20 @@ TEST_CASE("SymbolTable", "[language]")
REQUIRE
(
builtin_function_table
.
size
()
==
1
);
REQUIRE
(
builtin_function_table
.
size
()
==
1
);
REQUIRE
(
const_builtin_function_table
.
size
()
==
1
);
REQUIRE
(
const_builtin_function_table
.
size
()
==
1
);
}
}
SECTION
(
"TypeEmbedderTable"
)
{
std
::
shared_ptr
root_st
=
std
::
make_shared
<
SymbolTable
>
();
auto
&
type_table
=
root_st
->
typeEmbedderTable
();
REQUIRE
(
type_table
.
size
()
==
0
);
const
auto
&
const_type_table
=
static_cast
<
const
SymbolTable
&>
(
*
root_st
).
typeEmbedderTable
();
REQUIRE
(
const_type_table
.
size
()
==
0
);
type_table
.
add
(
std
::
make_shared
<
TypeDescriptor
>
(
"a_type"
));
REQUIRE
(
type_table
.
size
()
==
1
);
REQUIRE
(
const_type_table
.
size
()
==
1
);
}
}
}
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