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
436e0721
Commit
436e0721
authored
Jun 25, 2019
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Implement affectation operators for string
Remains to code binary operators for strings (mainly '+')
parent
07a1b0a3
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/ASTNodeAffectationExpressionBuilder.cpp
+90
-0
90 additions, 0 deletions
src/language/ASTNodeAffectationExpressionBuilder.cpp
src/language/PugsParser.cpp
+1
-3
1 addition, 3 deletions
src/language/PugsParser.cpp
with
91 additions
and
3 deletions
src/language/ASTNodeAffectationExpressionBuilder.cpp
+
90
−
0
View file @
436e0721
...
@@ -147,6 +147,58 @@ class AffectationProcessor final : public INodeProcessor
...
@@ -147,6 +147,58 @@ class AffectationProcessor final : public INodeProcessor
}
}
};
};
template
<
typename
OperatorT
,
typename
DataT
>
class
AffectationToStringProcessor
final
:
public
INodeProcessor
{
private:
Node
&
m_node
;
DataVariant
*
p_value
{
nullptr
};
static
inline
const
bool
_is_defined
{[]
{
if
constexpr
(
std
::
is_same_v
<
OperatorT
,
language
::
bit_andeq_op
>
or
std
::
is_same_v
<
OperatorT
,
language
::
bit_xoreq_op
>
or
std
::
is_same_v
<
OperatorT
,
language
::
bit_oreq_op
>
)
return
false
;
else
{
return
true
;
}
}()};
public
:
AffectationToStringProcessor
(
Node
&
node
)
:
m_node
{
node
}
{
if
constexpr
(
_is_defined
)
{
const
std
::
string
&
symbol
=
m_node
.
children
[
0
]
->
string
();
auto
[
i_symbol
,
found
]
=
m_node
.
m_symbol_table
->
find
(
symbol
);
Assert
(
found
);
p_value
=
&
i_symbol
->
second
.
value
();
}
else
{
throw
parse_error
(
"invalid operands to binary expression"
,
std
::
vector
{
m_node
.
begin
()});
}
}
void
execute
(
ExecUntilBreakOrContinue
&
exec_policy
)
{
if
constexpr
(
_is_defined
)
{
m_node
.
children
[
1
]
->
execute
(
exec_policy
);
if
constexpr
(
std
::
is_same_v
<
OperatorT
,
language
::
eq_op
>
)
{
if
constexpr
(
std
::
is_same_v
<
std
::
string
,
DataT
>
)
{
*
p_value
=
m_node
.
children
[
1
]
->
m_value
;
}
else
{
*
p_value
=
std
::
to_string
(
std
::
get
<
DataT
>
(
m_node
.
children
[
1
]
->
m_value
));
}
}
else
if
constexpr
(
std
::
is_same_v
<
OperatorT
,
language
::
pluseq_op
>
)
{
if
constexpr
(
std
::
is_same_v
<
std
::
string
,
DataT
>
)
{
std
::
get
<
std
::
string
>
(
*
p_value
)
+=
std
::
get
<
std
::
string
>
(
m_node
.
children
[
1
]
->
m_value
);
}
else
{
std
::
get
<
std
::
string
>
(
*
p_value
)
+=
std
::
to_string
(
std
::
get
<
DataT
>
(
m_node
.
children
[
1
]
->
m_value
));
}
}
}
}
};
// namespace language
ASTNodeAffectationExpressionBuilder
::
ASTNodeAffectationExpressionBuilder
(
Node
&
n
)
ASTNodeAffectationExpressionBuilder
::
ASTNodeAffectationExpressionBuilder
(
Node
&
n
)
{
{
auto
set_affectation_processor
=
[](
Node
&
n
,
const
auto
&
operator_v
)
{
auto
set_affectation_processor
=
[](
Node
&
n
,
const
auto
&
operator_v
)
{
...
@@ -176,6 +228,40 @@ ASTNodeAffectationExpressionBuilder::ASTNodeAffectationExpressionBuilder(Node& n
...
@@ -176,6 +228,40 @@ ASTNodeAffectationExpressionBuilder::ASTNodeAffectationExpressionBuilder(Node& n
}
}
};
};
auto
set_affectation_processor_for_string_data
=
[
&
](
const
DataType
&
data_type
)
{
using
OperatorT
=
std
::
decay_t
<
decltype
(
operator_v
)
>
;
if
constexpr
(
std
::
is_same_v
<
OperatorT
,
language
::
eq_op
>
or
std
::
is_same_v
<
OperatorT
,
language
::
pluseq_op
>
)
{
switch
(
data_type
)
{
case
DataType
::
bool_t
:
{
n
.
m_node_processor
=
std
::
make_unique
<
AffectationToStringProcessor
<
OperatorT
,
bool
>>
(
n
);
break
;
}
case
DataType
::
unsigned_int_t
:
{
n
.
m_node_processor
=
std
::
make_unique
<
AffectationToStringProcessor
<
OperatorT
,
uint64_t
>>
(
n
);
break
;
}
case
DataType
::
int_t
:
{
n
.
m_node_processor
=
std
::
make_unique
<
AffectationToStringProcessor
<
OperatorT
,
int64_t
>>
(
n
);
break
;
}
case
DataType
::
double_t
:
{
n
.
m_node_processor
=
std
::
make_unique
<
AffectationToStringProcessor
<
OperatorT
,
double
>>
(
n
);
break
;
}
case
DataType
::
string_t
:
{
n
.
m_node_processor
=
std
::
make_unique
<
AffectationToStringProcessor
<
OperatorT
,
std
::
string
>>
(
n
);
break
;
}
default
:
{
throw
parse_error
(
"undefined operand type for affectation"
,
std
::
vector
{
n
.
children
[
0
]
->
begin
()});
}
}
}
else
{
throw
parse_error
(
"undefined operator type"
,
std
::
vector
{
n
.
children
[
0
]
->
begin
()});
}
};
auto
set_affectation_processor_for_value
=
[
&
](
const
DataType
&
value_type
)
{
auto
set_affectation_processor_for_value
=
[
&
](
const
DataType
&
value_type
)
{
const
DataType
data_type
=
n
.
children
[
1
]
->
m_data_type
;
const
DataType
data_type
=
n
.
children
[
1
]
->
m_data_type
;
switch
(
value_type
)
{
switch
(
value_type
)
{
...
@@ -195,6 +281,10 @@ ASTNodeAffectationExpressionBuilder::ASTNodeAffectationExpressionBuilder(Node& n
...
@@ -195,6 +281,10 @@ ASTNodeAffectationExpressionBuilder::ASTNodeAffectationExpressionBuilder(Node& n
set_affectation_processor_for_data
(
double
{},
data_type
);
set_affectation_processor_for_data
(
double
{},
data_type
);
break
;
break
;
}
}
case
DataType
::
string_t
:
{
set_affectation_processor_for_string_data
(
data_type
);
break
;
}
default
:
{
default
:
{
throw
parse_error
(
"undefined value type for affectation"
,
std
::
vector
{
n
.
begin
()});
throw
parse_error
(
"undefined value type for affectation"
,
std
::
vector
{
n
.
begin
()});
}
}
...
...
This diff is collapsed.
Click to expand it.
src/language/PugsParser.cpp
+
1
−
3
View file @
436e0721
...
@@ -613,9 +613,7 @@ print(const Node& n)
...
@@ -613,9 +613,7 @@ print(const Node& n)
}
}
},
},
n
.
m_value
);
n
.
m_value
);
std
::
cout
<<
rang
::
fg
::
reset
;
std
::
cout
<<
rang
::
fg
::
reset
<<
")
\n
"
;
std
::
cout
<<
")
\n
"
;
if
(
not
n
.
children
.
empty
())
{
if
(
not
n
.
children
.
empty
())
{
print
(
n
.
children
);
print
(
n
.
children
);
...
...
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