minor cleanup of stack handling

master
Marius Kintel 2014-04-10 01:23:01 -04:00
parent 2a16aa1a4f
commit e30a40f432
5 changed files with 7 additions and 28 deletions

View File

@ -37,7 +37,6 @@ public:
std::string autoReloadId;
QTimer *waitAfterReloadTimer;
Context::Stack top_ctx_stack;
ModuleContext top_ctx;
FileModule *root_module; // Result of parsing
ModuleInstantiation root_inst; // Top level instance

View File

@ -54,38 +54,22 @@ static bool is_config_variable(const std::string &name) {
Context::Context(const Context *parent)
: parent(parent)
{
this->ctx_stack = NULL;
if (parent) {
document_path = parent->document_path;
if (!parent->ctx_stack) {
PRINT("ERROR: parent context stack was null!");
} else {
this->setStackAndPush( parent->ctx_stack );
}
assert(parent->ctx_stack && "Parent context stack was null!");
this->ctx_stack = parent->ctx_stack;
this->document_path = parent->document_path;
}
else {
this->ctx_stack = new Stack;
}
}
void Context::setStackAndPush( Context::Stack *stack )
{
if (this->ctx_stack) {
PRINT("ERROR: Context stack not null! Cannot overwrite.");
return;
}
if (!stack) {
PRINT("ERROR: Cannot set Context Stack to null!");
return;
}
this->ctx_stack = stack;
this->ctx_stack->push_back(this);
}
Context::~Context()
{
if (!this->ctx_stack) {
PRINT("ERROR: Context stack was null!");
return;
}
this->ctx_stack->pop_back();
if (!parent) delete this->ctx_stack;
}
/*!

View File

@ -15,7 +15,6 @@ public:
virtual ~Context();
const Context *getParent() const { return this->parent; }
void setStackAndPush( Context::Stack *stack = NULL );
virtual Value evaluate_function(const std::string &name, const class EvalContext *evalctx) const;
virtual class AbstractNode *instantiate_module(const class ModuleInstantiation &inst, const EvalContext *evalctx) const;

View File

@ -173,7 +173,6 @@ MainWindow::MainWindow(const QString &filename)
this, SLOT(actionRenderDone(shared_ptr<const Geometry>)));
#endif
top_ctx.setStackAndPush( &(this->top_ctx_stack) );
top_ctx.registerBuiltin();
this->openglbox = NULL;

View File

@ -254,8 +254,6 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c
// Top context - this context only holds builtins
ModuleContext top_ctx;
Context::Stack top_ctx_stack;
top_ctx.setStackAndPush( &top_ctx_stack );
top_ctx.registerBuiltin();
#ifdef DEBUG
PRINTDB("Top ModuleContext:\n%s",top_ctx.dump(NULL, NULL));