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
P
preprocessor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dynare
preprocessor
Commits
5d564eed
Unverified
Commit
5d564eed
authored
Nov 02, 2020
by
Sébastien Villemot
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the interpretation of @#elseif clauses within an @#ifdef or @#ifndef
parent
df8d8ef1
Pipeline
#4326
passed with stages
in 3 minutes and 2 seconds
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
44 deletions
+32
-44
src/macro/Directives.cc
src/macro/Directives.cc
+25
-37
src/macro/Directives.hh
src/macro/Directives.hh
+7
-7
No files found.
src/macro/Directives.cc
View file @
5d564eed
...
...
@@ -245,8 +245,23 @@ For::interpret(ostream &output, vector<filesystem::path> &paths)
void
If
::
interpret
(
ostream
&
output
,
vector
<
filesystem
::
path
>
&
paths
)
{
bool
first_clause
=
true
;
for
(
const
auto
&
[
expr
,
body
]
:
expr_and_body
)
try
{
if
((
ifdef
||
ifndef
)
&&
first_clause
)
{
first_clause
=
false
;
VariablePtr
vp
=
dynamic_pointer_cast
<
Variable
>
(
expr
);
assert
(
vp
);
if
((
ifdef
&&
env
.
isVariableDefined
(
vp
->
getName
()))
||
(
ifndef
&&
!
env
.
isVariableDefined
(
vp
->
getName
())))
{
interpretBody
(
body
,
output
,
paths
);
break
;
}
}
else
{
auto
tmp
=
expr
->
eval
();
RealPtr
dp
=
dynamic_pointer_cast
<
Real
>
(
tmp
);
...
...
@@ -260,6 +275,7 @@ If::interpret(ostream &output, vector<filesystem::path> &paths)
break
;
}
}
}
catch
(
StackTrace
&
ex
)
{
ex
.
push
(
"@#if"
,
location
);
...
...
@@ -286,31 +302,3 @@ If::interpretBody(const vector<DirectivePtr> &body, ostream &output, vector<file
statement
->
interpret
(
output
,
paths
);
}
}
void
Ifdef
::
interpret
(
ostream
&
output
,
vector
<
filesystem
::
path
>
&
paths
)
{
for
(
const
auto
&
[
expr
,
body
]
:
expr_and_body
)
if
(
VariablePtr
vp
=
dynamic_pointer_cast
<
Variable
>
(
expr
);
dynamic_pointer_cast
<
BaseType
>
(
expr
)
||
(
vp
&&
env
.
isVariableDefined
(
vp
->
getName
())))
{
interpretBody
(
body
,
output
,
paths
);
break
;
}
printEndLineInfo
(
output
);
}
void
Ifndef
::
interpret
(
ostream
&
output
,
vector
<
filesystem
::
path
>
&
paths
)
{
for
(
const
auto
&
[
expr
,
body
]
:
expr_and_body
)
if
(
VariablePtr
vp
=
dynamic_pointer_cast
<
Variable
>
(
expr
);
dynamic_pointer_cast
<
BaseType
>
(
expr
)
||
(
vp
&&
!
env
.
isVariableDefined
(
vp
->
getName
())))
{
interpretBody
(
body
,
output
,
paths
);
break
;
}
printEndLineInfo
(
output
);
}
src/macro/Directives.hh
View file @
5d564eed
...
...
@@ -175,24 +175,25 @@ namespace macro
* If there is an `else` statement it is the last element in the vector. Its condition is true.
*/
const
vector
<
pair
<
ExpressionPtr
,
vector
<
DirectivePtr
>>>
expr_and_body
;
const
bool
ifdef
,
ifndef
;
public:
If
(
vector
<
pair
<
ExpressionPtr
,
vector
<
DirectivePtr
>>>
expr_and_body_arg
,
Environment
&
env_arg
,
Tokenizer
::
location
location_arg
)
:
Directive
(
env_arg
,
move
(
location_arg
)),
expr_and_body
{
move
(
expr_and_body_arg
)}
{
}
Environment
&
env_arg
,
Tokenizer
::
location
location_arg
,
bool
ifdef_arg
=
false
,
bool
ifndef_arg
=
false
)
:
Directive
(
env_arg
,
move
(
location_arg
)),
expr_and_body
{
move
(
expr_and_body_arg
)},
ifdef
{
ifdef_arg
},
ifndef
{
ifndef_arg
}
{
}
void
interpret
(
ostream
&
output
,
vector
<
filesystem
::
path
>
&
paths
)
override
;
protected:
void
interpretBody
(
const
vector
<
DirectivePtr
>
&
body
,
ostream
&
output
,
vector
<
filesystem
::
path
>
&
paths
);
};
class
Ifdef
:
public
If
{
public:
Ifdef
(
vector
<
pair
<
ExpressionPtr
,
vector
<
DirectivePtr
>>>
expr_and_body_arg
,
Environment
&
env_arg
,
Tokenizer
::
location
location_arg
)
:
If
(
move
(
expr_and_body_arg
),
env_arg
,
move
(
location_arg
))
{
}
void
interpret
(
ostream
&
output
,
vector
<
filesystem
::
path
>
&
paths
)
override
;
If
(
move
(
expr_and_body_arg
),
env_arg
,
move
(
location_arg
),
true
,
false
)
{
}
};
...
...
@@ -201,8 +202,7 @@ namespace macro
public:
Ifndef
(
vector
<
pair
<
ExpressionPtr
,
vector
<
DirectivePtr
>>>
expr_and_body_arg
,
Environment
&
env_arg
,
Tokenizer
::
location
location_arg
)
:
If
(
move
(
expr_and_body_arg
),
env_arg
,
move
(
location_arg
))
{
}
void
interpret
(
ostream
&
output
,
vector
<
filesystem
::
path
>
&
paths
)
override
;
If
(
move
(
expr_and_body_arg
),
env_arg
,
move
(
location_arg
),
false
,
true
)
{
}
};
}
#endif
Sébastien Villemot
@sebastien
mentioned in commit
bd64c91c
·
Nov 02, 2020
mentioned in commit
bd64c91c
mentioned in commit bd64c91ca47bf840deb83bd51332467b7c97dd54
Toggle commit list
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