diff options
author | Marius Kintel <marius@kintel.net> | 2013-04-09 04:28:16 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-04-09 04:28:16 (GMT) |
commit | a37813a8999571f4b9235f33fdc7c22bcbe5fd17 (patch) | |
tree | 266d8c106100edab9f51b93cf229cf55cd083918 /src/modcontext.h | |
parent | b16c24fb2888d932ec035fff27cb29b4ffbc256b (diff) |
Refactored context handling into using separate Module contexts and Eval contexts. This allows for recursive module calls, and cascading children. I believe this fixes issue #116
Diffstat (limited to 'src/modcontext.h')
-rw-r--r-- | src/modcontext.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/modcontext.h b/src/modcontext.h new file mode 100644 index 0000000..cecf91f --- /dev/null +++ b/src/modcontext.h @@ -0,0 +1,37 @@ +#ifndef FILECONTEXT_H_ +#define FILECONTEXT_H_ + +#include "context.h" + +/*! + This holds the context for a Module definition; keeps track of + global variables, submodules and functions defined inside a module. + + NB! every .scad file defines an implicit unnamed module holding the contents of the file. +*/ +class ModuleContext : public Context +{ +public: + ModuleContext(const class Module *module = NULL, const Context *parent = NULL, const EvalContext *evalctx = NULL); + virtual ~ModuleContext(); + + void setModule(const Module &module, const EvalContext *evalctx = NULL); + void registerBuiltin(); + + virtual Value evaluate_function(const std::string &name, const EvalContext *evalctx) const; + virtual AbstractNode *evaluate_module(const ModuleInstantiation &inst, const EvalContext *evalctx) const; + + const boost::unordered_map<std::string, class AbstractFunction*> *functions_p; + const boost::unordered_map<std::string, class AbstractModule*> *modules_p; + typedef boost::unordered_map<std::string, class Module*> ModuleContainer; + const ModuleContainer *usedlibs_p; + + // FIXME: Points to the eval context for the call to this module. Not sure where it belongs + const class EvalContext *evalctx; + +#ifdef DEBUG + virtual void dump(const class AbstractModule *mod, const ModuleInstantiation *inst); +#endif +}; + +#endif |