-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScope.h
91 lines (70 loc) · 1.92 KB
/
Scope.h
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
#ifndef SCOPE_H
#define SCOPE_H
#include <QtCore/QString>
#include <QtCore/QHash>
#include <QtCore/QVariant>
#include <QtCore/QList>
#include <QtCore/QSharedPointer>
#include "ClassPrototype.h"
class ClassConstructor;
class Expression;
class Scope
{
public:
Scope();
virtual ~Scope();
bool hasVariable(const QString &variableName) const;
QVariant variable(const QString &identifier) const;
void setVariable(const QString &identifier, const QVariant &value);
bool hasScope(const QString &name) const;
void addScope(const QString& name, Scope* child);
Scope *scope(const QString& name) const;
QString findIdentifierAndScope(const QString &qualifiedIdentifier, Scope *& foundScope);
virtual QVariant asQVariant() const
{
return QVariant();
}
virtual bool isValidFunction(const QString &/*functionName*/) const
{
return false;
}
virtual QMetaType::Type functionReturnType(const QString &/*functionName*/) const
{
return QMetaType::Void;
}
virtual QVariant execute(const QString &/*functionName*/, const QList<Expression*> &/*parameters*/)
{
return QVariant();
}
bool hasClassPrototype(const QString &className) const
{
return m_classPrototypes.contains(className);
}
void addClassPrototype(const QString &className, IClassPrototype* prototype);
IClassPrototype* classPrototype(const QString &className) const
{
return m_classPrototypes.value(className);
}
void addClassConstructor(const QString &constructorName, ClassConstructor* constructor);
ClassConstructor* constructor(const QString &constructorName);
private:
QHash<QString,QVariant> m_variables;
QHash<QString,Scope*> m_children;
QHash<QString,ClassConstructor*> m_constructors;
QHash<QString,IClassPrototype*> m_classPrototypes;
};
class ClassInstance
{
public:
ClassInstance()
: classInstance(0)
{
}
ClassInstance(Scope* _classInstance)
: classInstance(_classInstance)
{
}
Scope* classInstance;
};
Q_DECLARE_METATYPE(ClassInstance)
#endif