mirror of https://github.com/KLayout/klayout.git
WIP
This commit is contained in:
parent
0c29c930b1
commit
a0758aa493
|
|
@ -3156,6 +3156,10 @@ Expression::execute () const
|
|||
void
|
||||
Expression::execute (EvalTarget &v) const
|
||||
{
|
||||
if (! mp_eval.get ()) {
|
||||
throw tl::Exception (tl::to_string (tr ("Context was destroyed")));
|
||||
}
|
||||
mp_eval->check ();
|
||||
if (m_root.get ()) {
|
||||
m_root->execute (v);
|
||||
}
|
||||
|
|
@ -3167,13 +3171,13 @@ Expression::execute (EvalTarget &v) const
|
|||
Eval Eval::m_global (0, 0, false);
|
||||
|
||||
Eval::Eval (Eval *parent, bool sloppy)
|
||||
: mp_parent (parent), mp_global (&Eval::m_global), m_sloppy (sloppy), mp_ctx_handler (0)
|
||||
: mp_parent (parent), m_has_parent (parent != 0), mp_global (&Eval::m_global), m_has_global (false), m_sloppy (sloppy), mp_ctx_handler (0)
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
|
||||
Eval::Eval (Eval *global, Eval *parent, bool sloppy)
|
||||
: mp_parent (parent), mp_global (global), m_sloppy (sloppy), mp_ctx_handler (0)
|
||||
: mp_parent (parent), m_has_parent (parent != 0), mp_global (global), m_has_global (global != 0), m_sloppy (sloppy), mp_ctx_handler (0)
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
|
|
@ -3186,6 +3190,23 @@ Eval::~Eval ()
|
|||
m_local_functions.clear ();
|
||||
}
|
||||
|
||||
void
|
||||
Eval::check ()
|
||||
{
|
||||
if (m_has_parent) {
|
||||
if (! mp_parent.get ()) {
|
||||
throw tl::Exception (tl::to_string (tr ("Parent context was destroyed")));
|
||||
}
|
||||
mp_parent->check ();
|
||||
}
|
||||
if (m_has_global) {
|
||||
if (! mp_global.get ()) {
|
||||
throw tl::Exception (tl::to_string (tr ("Global context was destroyed")));
|
||||
}
|
||||
mp_global->check ();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Eval::set_var (const std::string &name, const tl::Variant &var)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -356,7 +356,7 @@ private:
|
|||
const char *mp_text;
|
||||
std::string m_local_text;
|
||||
std::unique_ptr<ExpressionNode> m_root;
|
||||
Eval *mp_eval;
|
||||
tl::weak_ptr<Eval> mp_eval;
|
||||
|
||||
friend class Eval;
|
||||
|
||||
|
|
@ -580,10 +580,18 @@ public:
|
|||
return mp_parent.get ();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks the contexts and throws an exception if one of them got lost
|
||||
*/
|
||||
void check ();
|
||||
|
||||
private:
|
||||
friend class Expression;
|
||||
|
||||
tl::weak_ptr<Eval> mp_parent, mp_global;
|
||||
tl::weak_ptr<Eval> mp_parent;
|
||||
bool m_has_parent;
|
||||
tl::weak_ptr<Eval> mp_global;
|
||||
bool m_has_global;
|
||||
std::map <std::string, tl::Variant> m_local_vars;
|
||||
std::map <std::string, EvalFunction *> m_local_functions;
|
||||
bool m_sloppy;
|
||||
|
|
|
|||
Loading…
Reference in New Issue