summaryrefslogtreecommitdiff
path: root/src/module.h
blob: ace3c1b33986218f58f1d8f6274229d7ec967127 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef MODULE_H_
#define MODULE_H_

#include <string>
#include <vector>
#include <list>
#include <boost/unordered_map.hpp>
#include "value.h"
#include "typedefs.h"

class ModuleInstantiation
{
public:
	ModuleInstantiation(const std::string &name = "")
	: tag_root(false), tag_highlight(false), tag_background(false), modname(name) { }
	virtual ~ModuleInstantiation();

	std::string dump(const std::string &indent) const;
	class AbstractNode *evaluate_instance(const class Context *ctx) const;
	std::vector<AbstractNode*> evaluateChildren(const Context *evalctx) const;

	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;

	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; }

	AssignmentList arguments;
	std::vector<ModuleInstantiation*> children;

	bool tag_root;
	bool tag_highlight;
	bool tag_background;
protected:
	std::string modname;
	std::string modpath;

	friend class Module;
};

class IfElseModuleInstantiation : public ModuleInstantiation {
public:
	IfElseModuleInstantiation() : ModuleInstantiation("if") { }
	virtual ~IfElseModuleInstantiation();
	std::vector<AbstractNode*> evaluateElseChildren(const Context *evalctx) const;

	std::vector<ModuleInstantiation*> else_children;
};

class AbstractModule
{
public:
	virtual ~AbstractModule();
	virtual class AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst, const class EvalContext *evalctx = NULL) const;
	virtual std::string dump(const std::string &indent, const std::string &name) const;
};

class Module : public AbstractModule
{
public:
	Module() : is_handling_dependencies(false) { }
	virtual ~Module();

	void setModulePath(const std::string &path) { this->path = path; }
	const std::string &modulePath() const { return this->path; }

	virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst, const EvalContext *evalctx) const;
	virtual std::string dump(const std::string &indent, const std::string &name) const;

	void addChild(ModuleInstantiation *ch) { this->children.push_back(ch); }

	typedef boost::unordered_map<std::string, class Module*> ModuleContainer;
	ModuleContainer usedlibs;
	void registerInclude(const std::string &filename);
	typedef boost::unordered_map<std::string, time_t> IncludeContainer;
	IncludeContainer includes;
	bool is_handling_dependencies;
	bool handleDependencies();

	std::list<std::string> assignments_var;
	typedef boost::unordered_map<std::string, Expression*> AssignmentMap;
	AssignmentMap assignments;

	typedef boost::unordered_map<std::string, class AbstractFunction*> FunctionContainer;
	FunctionContainer functions;
	typedef boost::unordered_map<std::string, AbstractModule*> AbstractModuleContainer;
	AbstractModuleContainer	modules;

	std::vector<ModuleInstantiation*> children;

	std::vector<Assignment> definition_arguments;

protected:

private:
	std::string path;
};

#endif
contact: Jan Huwald // Impressum