2014-04-28 21:09:25 +04:00
|
|
|
#pragma once
|
2010-01-30 07:26:05 +03:00
|
|
|
|
2011-09-03 08:10:36 +04:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2012-02-18 02:05:36 +04:00
|
|
|
#include <list>
|
2013-08-18 19:18:43 +04:00
|
|
|
#include <deque>
|
2011-09-03 08:10:36 +04:00
|
|
|
#include <boost/unordered_map.hpp>
|
2013-06-13 09:16:26 +04:00
|
|
|
#include <boost/unordered_set.hpp>
|
2013-05-20 08:31:18 +04:00
|
|
|
#include <time.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2010-01-30 07:26:05 +03:00
|
|
|
#include "value.h"
|
2013-04-19 02:34:14 +04:00
|
|
|
#include "typedefs.h"
|
2013-04-20 01:52:01 +04:00
|
|
|
#include "localscope.h"
|
2014-01-03 01:41:21 +04:00
|
|
|
#include "feature.h"
|
2010-01-30 07:26:05 +03:00
|
|
|
|
|
|
|
class ModuleInstantiation
|
|
|
|
{
|
|
|
|
public:
|
2013-04-05 09:30:09 +04:00
|
|
|
ModuleInstantiation(const std::string &name = "")
|
2014-11-25 02:12:58 +03:00
|
|
|
: tag_root(false), tag_highlight(false), tag_background(false), modname(name) { }
|
2011-12-26 19:34:47 +04:00
|
|
|
virtual ~ModuleInstantiation();
|
|
|
|
|
2013-06-02 00:05:09 +04:00
|
|
|
virtual std::string dump(const std::string &indent) const;
|
2013-04-20 01:52:01 +04:00
|
|
|
class AbstractNode *evaluate(const class Context *ctx) const;
|
|
|
|
std::vector<AbstractNode*> instantiateChildren(const Context *evalctx) const;
|
2011-12-26 19:34:47 +04:00
|
|
|
|
2013-04-05 09:30:09 +04:00
|
|
|
void setPath(const std::string &path) { this->modpath = path; }
|
|
|
|
const std::string &path() const { return this->modpath; }
|
|
|
|
std::string getAbsolutePath(const std::string &filename) const;
|
|
|
|
|
2011-12-26 19:34:47 +04:00
|
|
|
const std::string &name() const { return this->modname; }
|
|
|
|
bool isBackground() const { return this->tag_background; }
|
|
|
|
bool isHighlight() const { return this->tag_highlight; }
|
|
|
|
bool isRoot() const { return this->tag_root; }
|
|
|
|
|
2013-04-19 02:34:14 +04:00
|
|
|
AssignmentList arguments;
|
2013-04-20 01:52:01 +04:00
|
|
|
LocalScope scope;
|
2010-01-30 07:26:05 +03:00
|
|
|
|
|
|
|
bool tag_root;
|
|
|
|
bool tag_highlight;
|
|
|
|
bool tag_background;
|
2011-12-26 19:34:47 +04:00
|
|
|
protected:
|
|
|
|
std::string modname;
|
2013-04-05 09:30:09 +04:00
|
|
|
std::string modpath;
|
2010-01-30 07:26:05 +03:00
|
|
|
|
2011-12-26 19:34:47 +04:00
|
|
|
friend class Module;
|
2010-01-30 07:26:05 +03:00
|
|
|
};
|
|
|
|
|
2010-02-12 16:20:15 +03:00
|
|
|
class IfElseModuleInstantiation : public ModuleInstantiation {
|
|
|
|
public:
|
2011-12-26 19:34:47 +04:00
|
|
|
IfElseModuleInstantiation() : ModuleInstantiation("if") { }
|
2010-02-12 16:20:15 +03:00
|
|
|
virtual ~IfElseModuleInstantiation();
|
2013-04-20 01:52:01 +04:00
|
|
|
std::vector<AbstractNode*> instantiateElseChildren(const Context *evalctx) const;
|
2013-06-02 00:05:09 +04:00
|
|
|
virtual std::string dump(const std::string &indent) const;
|
2010-02-12 16:20:15 +03:00
|
|
|
|
2013-04-20 01:52:01 +04:00
|
|
|
LocalScope else_scope;
|
2010-02-12 16:20:15 +03:00
|
|
|
};
|
|
|
|
|
2010-01-30 07:26:05 +03:00
|
|
|
class AbstractModule
|
|
|
|
{
|
2014-01-03 01:41:21 +04:00
|
|
|
private:
|
|
|
|
const Feature *feature;
|
2010-01-30 07:26:05 +03:00
|
|
|
public:
|
2014-01-03 01:41:21 +04:00
|
|
|
AbstractModule() : feature(NULL) {}
|
|
|
|
AbstractModule(const Feature& feature) : feature(&feature) {}
|
2010-01-30 07:26:05 +03:00
|
|
|
virtual ~AbstractModule();
|
2014-03-05 00:16:13 +04:00
|
|
|
virtual bool is_experimental() const { return feature != NULL; }
|
|
|
|
virtual bool is_enabled() const { return (feature == NULL) || feature->is_enabled(); }
|
2014-11-17 08:57:36 +03:00
|
|
|
virtual class AbstractNode *instantiate(const Context *ctx, const ModuleInstantiation *inst, class EvalContext *evalctx = NULL) const;
|
2011-09-03 08:10:36 +04:00
|
|
|
virtual std::string dump(const std::string &indent, const std::string &name) const;
|
2014-01-19 06:05:00 +04:00
|
|
|
virtual double lookup_double_variable_with_default(Context &c, std::string variable, double def) const;
|
|
|
|
virtual std::string lookup_string_variable_with_default(Context &c, std::string variable, std::string def) const;
|
2010-01-30 07:26:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class Module : public AbstractModule
|
|
|
|
{
|
|
|
|
public:
|
2013-04-20 01:52:01 +04:00
|
|
|
Module() { }
|
2014-01-03 01:41:21 +04:00
|
|
|
Module(const Feature& feature) : AbstractModule(feature) { }
|
2011-12-26 19:34:47 +04:00
|
|
|
virtual ~Module();
|
2013-04-05 09:30:09 +04:00
|
|
|
|
2014-11-17 08:57:36 +03:00
|
|
|
virtual AbstractNode *instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx = NULL) const;
|
2011-12-26 19:34:47 +04:00
|
|
|
virtual std::string dump(const std::string &indent, const std::string &name) const;
|
2013-08-18 19:18:43 +04:00
|
|
|
static const std::string& stack_element(int n) { return module_stack[n]; };
|
|
|
|
static int stack_size() { return module_stack.size(); };
|
2011-12-26 19:34:47 +04:00
|
|
|
|
2013-04-20 01:52:01 +04:00
|
|
|
AssignmentList definition_arguments;
|
2010-01-30 07:26:05 +03:00
|
|
|
|
2013-04-20 01:52:01 +04:00
|
|
|
LocalScope scope;
|
2013-08-18 19:18:43 +04:00
|
|
|
|
2013-08-15 13:25:55 +04:00
|
|
|
private:
|
2013-08-18 19:18:43 +04:00
|
|
|
static std::deque<std::string> module_stack;
|
2013-04-20 01:52:01 +04:00
|
|
|
};
|
2010-01-30 07:26:05 +03:00
|
|
|
|
2013-04-24 17:17:25 +04:00
|
|
|
// FIXME: A FileModule doesn't have definition arguments, so we shouldn't really
|
|
|
|
// inherit from a Module
|
2013-04-20 01:52:01 +04:00
|
|
|
class FileModule : public Module
|
|
|
|
{
|
|
|
|
public:
|
2014-11-30 00:44:40 +03:00
|
|
|
FileModule() : context(NULL), is_handling_dependencies(false) {}
|
|
|
|
virtual ~FileModule();
|
2010-01-30 07:26:05 +03:00
|
|
|
|
2013-04-20 01:52:01 +04:00
|
|
|
void setModulePath(const std::string &path) { this->path = path; }
|
|
|
|
const std::string &modulePath() const { return this->path; }
|
2014-01-19 06:05:00 +04:00
|
|
|
void registerUse(const std::string path);
|
2013-05-26 01:45:13 +04:00
|
|
|
void registerInclude(const std::string &localpath, const std::string &fullpath);
|
2013-06-06 06:25:58 +04:00
|
|
|
bool includesChanged() const;
|
2013-04-20 01:52:01 +04:00
|
|
|
bool handleDependencies();
|
2014-11-30 00:44:40 +03:00
|
|
|
virtual AbstractNode *instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx = NULL);
|
2013-06-06 06:25:58 +04:00
|
|
|
bool hasIncludes() const { return !this->includes.empty(); }
|
|
|
|
bool usesLibraries() const { return !this->usedlibs.empty(); }
|
2013-06-13 09:16:26 +04:00
|
|
|
bool isHandlingDependencies() const { return this->is_handling_dependencies; }
|
2014-12-02 01:34:47 +03:00
|
|
|
ValuePtr lookup_variable(const std::string &name) const;
|
2010-01-30 07:26:05 +03:00
|
|
|
|
2013-06-13 09:16:26 +04:00
|
|
|
typedef boost::unordered_set<std::string> ModuleContainer;
|
2013-04-20 01:52:01 +04:00
|
|
|
ModuleContainer usedlibs;
|
2013-06-06 06:25:58 +04:00
|
|
|
private:
|
2014-11-30 00:44:40 +03:00
|
|
|
/** Reference to retain the context that was used in the last evaluation */
|
|
|
|
class FileContext *context;
|
2013-06-06 06:25:58 +04:00
|
|
|
struct IncludeFile {
|
|
|
|
std::string filename;
|
|
|
|
bool valid;
|
|
|
|
time_t mtime;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool include_modified(const IncludeFile &inc) const;
|
2013-05-29 00:29:53 +04:00
|
|
|
|
2013-05-20 08:31:18 +04:00
|
|
|
typedef boost::unordered_map<std::string, struct IncludeFile> IncludeContainer;
|
2013-04-20 01:52:01 +04:00
|
|
|
IncludeContainer includes;
|
|
|
|
bool is_handling_dependencies;
|
2013-04-09 08:28:16 +04:00
|
|
|
std::string path;
|
2010-01-30 07:26:05 +03:00
|
|
|
};
|