Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dóra Kocsis
dynare
Commits
11c04c9b
Commit
11c04c9b
authored
Dec 10, 2013
by
Houtan Bastani
Browse files
preprocessor: streamline addSymbol
parent
6a3e0da5
Changes
3
Hide whitespace changes
Inline
Side-by-side
preprocessor/ParsingDriver.cc
View file @
11c04c9b
...
...
@@ -139,9 +139,9 @@ ParsingDriver::declare_symbol(const string *name, SymbolType type, const string
mod_file
->
symbol_table
.
addSymbol
(
*
name
,
type
);
else
if
(
tex_name
==
NULL
)
mod_file
->
symbol_table
.
createTexNameAndAddSymbolWithLongName
(
*
name
,
type
,
*
long_name
);
mod_file
->
symbol_table
.
addSymbol
(
*
name
,
type
,
""
,
*
long_name
);
else
if
(
long_name
==
NULL
)
mod_file
->
symbol_table
.
addSymbol
(
*
name
,
type
,
*
tex_name
);
mod_file
->
symbol_table
.
addSymbol
(
*
name
,
type
,
*
tex_name
,
""
);
else
mod_file
->
symbol_table
.
addSymbol
(
*
name
,
type
,
*
tex_name
,
*
long_name
);
}
...
...
preprocessor/SymbolTable.cc
View file @
11c04c9b
...
...
@@ -52,49 +52,37 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na
throw
AlreadyDeclaredException
(
name
,
false
);
}
string
final_tex_name
=
tex_name
;
if
(
final_tex_name
.
empty
())
{
final_tex_name
=
name
;
size_t
pos
=
0
;
while
((
pos
=
final_tex_name
.
find
(
'_'
,
pos
))
!=
string
::
npos
)
{
final_tex_name
.
insert
(
pos
,
"
\\
"
);
pos
+=
2
;
}
}
string
final_long_name
=
long_name
;
if
(
final_long_name
.
empty
())
final_long_name
=
name
;
int
id
=
size
++
;
symbol_table
[
name
]
=
id
;
type_table
.
push_back
(
type
);
name_table
.
push_back
(
name
);
tex_name_table
.
push_back
(
tex_name
);
long_name_table
.
push_back
(
long_name
);
tex_name_table
.
push_back
(
final_
tex_name
);
long_name_table
.
push_back
(
final_
long_name
);
return
id
;
}
int
SymbolTable
::
addSymbol
(
const
string
&
name
,
SymbolType
type
,
const
string
&
tex_name
)
throw
(
AlreadyDeclaredException
,
FrozenException
)
{
return
addSymbol
(
name
,
type
,
tex_name
,
name
);
}
int
SymbolTable
::
addSymbol
(
const
string
&
name
,
SymbolType
type
)
throw
(
AlreadyDeclaredException
,
FrozenException
)
{
string
tex_name
;
return
addSymbol
(
name
,
type
,
construct_tex_name
(
name
,
tex_name
));
}
int
SymbolTable
::
createTexNameAndAddSymbolWithLongName
(
const
string
&
name
,
SymbolType
type
,
const
string
&
long_name
)
throw
(
AlreadyDeclaredException
,
FrozenException
)
{
string
tex_name
;
return
addSymbol
(
name
,
type
,
construct_tex_name
(
name
,
tex_name
),
long_name
);
}
string
&
SymbolTable
::
construct_tex_name
(
const
string
&
name
,
string
&
tex_name
)
{
// Construct "tex_name" by prepending an antislash to all underscores in "name"
tex_name
=
name
;
size_t
pos
=
0
;
while
((
pos
=
tex_name
.
find
(
'_'
,
pos
))
!=
string
::
npos
)
{
tex_name
.
insert
(
pos
,
"
\\
"
);
pos
+=
2
;
}
return
tex_name
;
return
addSymbol
(
name
,
type
,
""
,
""
);
}
void
...
...
preprocessor/SymbolTable.hh
View file @
11c04c9b
...
...
@@ -185,18 +185,9 @@ public:
//! Add a symbol
/*! Returns the symbol ID */
int
addSymbol
(
const
string
&
name
,
SymbolType
type
,
const
string
&
tex_name
,
const
string
&
long_name
)
throw
(
AlreadyDeclaredException
,
FrozenException
);
//! Add a symbol without its long name (will be equal to its name)
/*! Returns the symbol ID */
int
addSymbol
(
const
string
&
name
,
SymbolType
type
,
const
string
&
tex_name
)
throw
(
AlreadyDeclaredException
,
FrozenException
);
//! Add a symbol without its TeX name (will be equal to its name)
/*! Returns the symbol ID */
int
addSymbol
(
const
string
&
name
,
SymbolType
type
)
throw
(
AlreadyDeclaredException
,
FrozenException
);
//! Tmp addSymbol function that creates a tex_name and declares a symbol
//! when the name and long_name are passed
/*! Returns the symbol ID */
int
createTexNameAndAddSymbolWithLongName
(
const
string
&
name
,
SymbolType
type
,
const
string
&
long_name
)
throw
(
AlreadyDeclaredException
,
FrozenException
);
//! Create a tex_name based on the variable name
string
&
construct_tex_name
(
const
string
&
name
,
string
&
tex_name
);
//! Adds an auxiliary variable for endogenous with lead >= 2
/*!
\param[in] index Used to construct the variable name
...
...
Write
Preview
Supports
Markdown
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