summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Context.h
blob: c4329246a5b9356c379e77dac9cdcd5c9b5bffa1 (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
/*
 * Context.h
 *
 *  Created on: Dec 30, 2012
 *      Author: att
 */

#ifndef CONTEXT_H_
#define CONTEXT_H_
#include <map>
#include <string>
#include "Utils/to_string.h"
#include "Elements/SenchaObject.h"
#include "Elements/SenchaFunction.h"
#include "AST/ASTExpression.h"



/**
 * Context is object used to store variables for some execution context.
 * It's most useful in function calls. Every function has to have its own execution contexts,
 * for its variables. Arguments are passed to functions by predefining them in new Context, assigned to
 * function.
 */
class Context {
public:
	Context(std::string name);
	std::string name;
	typedef SenchaObject (*PointerToNativeFunction)(std::vector<ASTExpression *>);
	void register_function(std::string name, PointerToNativeFunction f);
	void register_function(std::string name, SenchaFunction * f);
	SenchaObject execute_native_function(std::string name, std::vector<ASTExpression *> arguments);
	SenchaObject get_updated_string(std::string name);
	std::string debug() ;
	void add(std::string name, SenchaObject object);
	void set(std::string name, SenchaObject object);
	SenchaObject get(std::string name);
	bool contains_function(std::string name);
	bool contains_sfunction(std::string name);
	bool contains_nfunction(std::string name);
	std::map<std::string, PointerToNativeFunction> registered_functions;
	std::map<std::string, SenchaFunction *> registered_sfunctions;
	virtual ~Context();

private:
	unsigned int index;



	std::map<std::string, SenchaObject> object_store;
};

#endif /* CONTEXT_H_ */