Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Docker-in-Docker (DinD) capabilities of public runners deactivated.
More info
Open sidebar
CTA-LAPP
PHOENIX_LIBS
ParserGenerator
Commits
a4557676
Commit
a4557676
authored
Jan 13, 2021
by
Pierre Aubert
Browse files
Add function to get the last operand of an operator
parent
146586c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
7 deletions
+35
-7
src/CppBackEnd/repr_cpp_operator.cpp
src/CppBackEnd/repr_cpp_operator.cpp
+34
-6
src/CppBackEnd/repr_cpp_token_operator.cpp
src/CppBackEnd/repr_cpp_token_operator.cpp
+1
-1
No files found.
src/CppBackEnd/repr_cpp_operator.cpp
View file @
a4557676
...
...
@@ -60,6 +60,7 @@ std::string repr_cpp_operatorHeader(const PTabGraphToken & tabGraphToken){
body
+=
"
\n
"
;
body
+=
"bool isAnOperator(const PStmt & _op);
\n
"
;
body
+=
"long get_priority_operator(const PStmt & _op);
\n
"
;
body
+=
"PStmt* get_last_operand_of_operator(PStmt & _op);
\n
"
;
body
+=
"
\n\n
"
;
body
+=
"#endif
\n\n\n
"
;
...
...
@@ -78,11 +79,12 @@ std::string repr_cpp_operatorSource(const PTabGraphToken & tabGraphToken, const
PMapVecOperator
mapOp
;
repr_cpp_operatorGetClass
(
mapOp
,
tabGraphToken
.
getVecOperator
());
body
+=
"///Say if the given
expression
is an operator
\n
"
;
body
+=
"/**
\t
@param _op :
expression
to be checked
\n
"
;
body
+=
" *
\t
@return true if it is an
expression
, false otherwise
\n
"
;
body
+=
"///Say if the given
PStmt
is an operator
\n
"
;
body
+=
"/**
\t
@param _op :
PStmt
to be checked
\n
"
;
body
+=
" *
\t
@return true if it is an
PStmt
, false otherwise
\n
"
;
body
+=
"*/
\n
"
;
body
+=
"bool isAnOperator(const PStmt & _op){
\n
"
;
body
+=
"
\t
//repr_cpp_operator : say if the given PStmt is an operator
\n
"
;
std
::
string
prevElse
(
""
);
for
(
PMapVecOperator
::
iterator
itVec
(
mapOp
.
begin
());
itVec
!=
mapOp
.
end
();
++
itVec
){
body
+=
"
\t
"
+
prevElse
+
"if(is"
+
(
itVec
->
first
)
+
"(_op)){
\n
"
;
...
...
@@ -98,11 +100,12 @@ std::string repr_cpp_operatorSource(const PTabGraphToken & tabGraphToken, const
body
+=
"
\t
return false;
\n
"
;
body
+=
"}
\n\n
"
;
body
+=
"///Get the priority of the given
expression
\n
"
;
body
+=
"/**
\t
@param _op :
expression
to be checked
\n
"
;
body
+=
" *
\t
@return priority of the
expression
, -1 otherwise
\n
"
;
body
+=
"///Get the priority of the given
PStmt
\n
"
;
body
+=
"/**
\t
@param _op :
PStmt
to be checked
\n
"
;
body
+=
" *
\t
@return priority of the
PStmt
, -1 otherwise
\n
"
;
body
+=
"*/
\n
"
;
body
+=
"long get_priority_operator(const PStmt & _op){
\n
"
;
body
+=
"
\t
//repr_cpp_operator : Get the priority of the given operator
\n
"
;
prevElse
=
""
;
for
(
PMapVecOperator
::
iterator
itVec
(
mapOp
.
begin
());
itVec
!=
mapOp
.
end
();
++
itVec
){
body
+=
"
\t
"
+
prevElse
+
"if(is"
+
(
itVec
->
first
)
+
"(_op)){
\n
"
;
...
...
@@ -116,6 +119,31 @@ std::string repr_cpp_operatorSource(const PTabGraphToken & tabGraphToken, const
}
body
+=
"
\n
"
;
body
+=
"
\t
return -1l;
\n
"
;
body
+=
"}
\n\n
"
;
body
+=
"///Get the last operand of the given PStmt
\n
"
;
body
+=
"/**
\t
@param _op : expression to be checked
\n
"
;
body
+=
" *
\t
@return pointer to the last operand of the given operator, NULL otherwise
\n
"
;
body
+=
"*/
\n
"
;
body
+=
"PStmt* get_last_operand_of_operator(PStmt & _op){
\n
"
;
body
+=
"
\t
//repr_cpp_operator : Get the last operand of the given operator
\n
"
;
body
+=
"
\t
PStmt * outputPtr = NULL;
\n
"
;
prevElse
=
""
;
for
(
PMapVecOperator
::
iterator
itVec
(
mapOp
.
begin
());
itVec
!=
mapOp
.
end
();
++
itVec
){
body
+=
"
\t
"
+
prevElse
+
"if(is"
+
(
itVec
->
first
)
+
"(_op)){
\n
"
;
std
::
string
itPrevElse
(
""
);
for
(
PVecOperator
::
iterator
it
(
itVec
->
second
.
begin
());
it
!=
itVec
->
second
.
end
();
++
it
){
body
+=
"
\t\t
"
+
itPrevElse
+
"if("
+
it
->
getExprClass
()
+
"_get"
+
firstToUpper
(
it
->
getAttrEnum
())
+
"(_op) == "
+
it
->
getValueEnum
()
+
"){
\n
"
;
body
+=
"
\t\t\t
//repr_cpp_operator : let's get the number of operand of this operator
\n
"
;
body
+=
"
\t\t\t
PStmt & vecOp = "
+
it
->
getExprClass
()
+
"_get"
+
firstToUpper
(
it
->
getVecOp
())
+
"(_op);
\n
"
;
body
+=
"
\t\t\t
if(vecOp.size() != 0lu){outputPtr = &(vecOp.back());}
\n
"
;
body
+=
"
\t\t
}
\n
"
;
itPrevElse
=
"else "
;
}
body
+=
"
\t
}"
;
prevElse
=
"else "
;
}
body
+=
"
\n\t
return outputPtr;
\n
"
;
body
+=
"}
\n\n\n
"
;
return
body
;
}
...
...
src/CppBackEnd/repr_cpp_token_operator.cpp
View file @
a4557676
...
...
@@ -51,7 +51,7 @@ std::string repr_cpp_singleTokenOperator(const POperator & op, const PGraphToken
body
+=
"
\t
PStmt op = "
+
op
.
getExprClass
()
+
"_default();
\n
"
;
body
+=
"
\t
"
+
op
.
getExprClass
()
+
"_set"
+
firstToUpper
(
op
.
getAttrEnum
())
+
"(op, "
+
op
.
getValueEnum
()
+
");
\n
"
;
body
+=
"
\t
PStmt & vecOperand =
PExpr_getVecOperand
(op);
\n
"
;
body
+=
"
\t
PStmt & vecOperand =
"
+
op
.
getExprClass
()
+
"_get"
+
firstToUpper
(
op
.
getVecOp
())
+
"
(op);
\n
"
;
body
+=
"
\t\n
"
;
body
+=
"
\t
bool isStandardPushBack(true);
\n
"
;
body
+=
"
\t
if(isAnOperator(e)){
\n
"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment