Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
preprocessor
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
Container registry
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
Dynare
preprocessor
Commits
ee6880bf
Commit
ee6880bf
authored
9 years ago
by
Houtan Bastani
Browse files
Options
Downloads
Patches
Plain Diff
preprocessor: macroprocessor: add @#includepath macro. #1039
parent
38443b07
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
macro/MacroDriver.hh
+6
-2
6 additions, 2 deletions
macro/MacroDriver.hh
macro/MacroFlex.ll
+60
-0
60 additions, 0 deletions
macro/MacroFlex.ll
with
66 additions
and
2 deletions
macro/MacroDriver.hh
+
6
−
2
View file @
ee6880bf
...
@@ -79,7 +79,7 @@ private:
...
@@ -79,7 +79,7 @@ private:
//! Should we omit the @#line statements ?
//! Should we omit the @#line statements ?
const
bool
no_line_macro
;
const
bool
no_line_macro
;
//! The paths to search when looking for .mod files
//! The paths to search when looking for .mod files
const
vector
<
string
>
path
;
vector
<
string
>
path
;
//! True iff current context is the body of a loop
//! True iff current context is the body of a loop
bool
is_for_context
;
bool
is_for_context
;
//! If current context is the body of a loop, contains the string of the loop body
//! If current context is the body of a loop, contains the string of the loop body
...
@@ -122,6 +122,10 @@ private:
...
@@ -122,6 +122,10 @@ private:
//! Restore last scanning context
//! Restore last scanning context
void
restore_context
(
Macro
::
parser
::
location_type
*
yylloc
);
void
restore_context
(
Macro
::
parser
::
location_type
*
yylloc
);
//! pushes the colon-separated paths passed to @#includepath onto the path vector
void
push_path
(
string
*
includepath
,
Macro
::
parser
::
location_type
*
yylloc
,
MacroDriver
&
driver
);
//! Saves current scanning context and create a new context with content of filename
//! Saves current scanning context and create a new context with content of filename
/*! Filename must be a newly allocated string which will be deleted by the lexer */
/*! Filename must be a newly allocated string which will be deleted by the lexer */
void
create_include_context
(
string
*
filename
,
Macro
::
parser
::
location_type
*
yylloc
,
void
create_include_context
(
string
*
filename
,
Macro
::
parser
::
location_type
*
yylloc
,
...
@@ -178,7 +182,7 @@ public:
...
@@ -178,7 +182,7 @@ public:
//! Starts parsing a file, returns output in out
//! Starts parsing a file, returns output in out
/*! \param no_line_macro should we omit the @#line statements ? */
/*! \param no_line_macro should we omit the @#line statements ? */
void
parse
(
const
string
&
f
,
ostream
&
out
,
bool
debug
,
bool
no_line_macro
,
void
parse
(
const
string
&
f
,
ostream
&
out
,
bool
debug
,
bool
no_line_macro
,
map
<
string
,
string
>
defines
,
const
vector
<
string
>
path
);
map
<
string
,
string
>
defines
,
vector
<
string
>
path
);
//! Name of main file being parsed
//! Name of main file being parsed
string
file
;
string
file
;
...
...
This diff is collapsed.
Click to expand it.
macro/MacroFlex.ll
+
60
−
0
View file @
ee6880bf
...
@@ -21,6 +21,9 @@
...
@@ -21,6 +21,9 @@
using
namespace
std
;
using
namespace
std
;
#include
<
fstream
>
#include
<
fstream
>
#include
<
boost/algorithm/string/trim
.
hpp
>
#include
<
boost/algorithm/string/split
.
hpp
>
#include
<
boost/tokenizer
.
hpp
>
#include
"MacroDriver.hh"
#include
"MacroDriver.hh"
...
@@ -68,6 +71,47 @@ CONT \\\\
...
@@ -68,6 +71,47 @@ CONT \\\\
yylloc-
>
step
()
;
yylloc-
>
step
()
;
%
}
%
}
<
INITIAL
>
^
{
SPC
}*
@#
{
SPC
}*
includepath
{
SPC
}
+\
"([^\"
\r\
n:
;|<>]*){1}(:[^\"\r\n:;|<>]*)*\"{SPC}*{EOL} {
yylloc-
>
lines
(
1
)
;
yylloc-
>
step
()
;
//
Get
path
string
*
includepath
=
new
string
(
yytext
)
;
int
dblq_idx1
=
includepath-
>
find
(
'
"');
int dblq_idx2 = includepath->find('"
'
,
dblq_idx1
+
1
)
;
includepath-
>
erase
(
dblq_idx2
)
;
includepath-
>
erase
(
0
,
dblq_idx1
+
1
)
;
push_path
(
includepath
,
yylloc
,
driver
)
;
BEGIN
(
INITIAL
)
;
}
<
INITIAL
>
^
{
SPC
}*
@#
{
SPC
}*
includepath
{
SPC
}
+
[
^\
"\r\n]*{SPC}*{EOL} {
yylloc->lines(1);
yylloc->step();
// Get variable name
string pathvar = string(yytext);
int dblq_idx1 = pathvar.find("
includepath
");
pathvar.erase(0, dblq_idx1 + 11);
pathvar.erase(0, pathvar.find_first_not_of("
\t
"));
size_t p = pathvar.find_last_not_of("
\t\n\r
");
if (string::npos != p)
pathvar.erase(p+1);
string *includepath = NULL;
try
{
includepath = new string(driver.get_variable(pathvar)->toString());
}
catch(MacroDriver::UnknownVariable(&e))
{
driver.error(*yylloc, "
Unknown
variable:
" + pathvar);
}
push_path(includepath, yylloc, driver);
BEGIN(INITIAL);
}
<INITIAL>^{SPC}*@#{SPC}*include{SPC}+\"
[
^\
"\r\n]*\"
{
SPC
}*{
EOL
}
{
<INITIAL>^{SPC}*@#{SPC}*include{SPC}+\"
[
^\
"\r\n]*\"
{
SPC
}*{
EOL
}
{
yylloc-
>
lines
(
1
)
;
yylloc-
>
lines
(
1
)
;
yylloc-
>
step
()
;
yylloc-
>
step
()
;
...
@@ -383,6 +427,22 @@ MacroFlex::restore_context(Macro::parser::location_type *yylloc)
...
@@ -383,6 +427,22 @@ MacroFlex::restore_context(Macro::parser::location_type *yylloc)
output_line
(
yylloc
)
;
output_line
(
yylloc
)
;
}
}
void
MacroFlex:
:push_path
(
string
*
includepath
,
Macro:
:
parser:
:location_type
*
yylloc
,
MacroDriver
&driver
)
{
using
namespace
boost
;
vector
<
string
>
tokenizedPath
;
split
(
tokenizedPath
,
*
includepath
,
is_any_of
(
":"
),
token_compress_on
)
;
for
(
vector
<
string
>
::iterator
it
=
tokenizedPath
.
begin
()
;
it
!=
tokenizedPath
.
end
()
; it++ )
if
(
!it-
>
empty
())
{
trim
(*
it
)
;
path
.
push_back
(*
it
)
;
}
}
void
void
MacroFlex:
:create_include_context
(
string
*
filename
,
Macro:
:
parser:
:location_type
*
yylloc
,
MacroFlex:
:create_include_context
(
string
*
filename
,
Macro:
:
parser:
:location_type
*
yylloc
,
MacroDriver
&driver
)
MacroDriver
&driver
)
...
...
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