-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScope.cpp
87 lines (70 loc) · 1.73 KB
/
Scope.cpp
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
#include "Scope.h"
#include "ClassConstructor.h"
Scope::Scope()
{
}
Scope::~Scope()
{
qDeleteAll(m_children);
qDeleteAll(m_constructors);
qDeleteAll(m_classPrototypes);
}
bool Scope::hasVariable(const QString &variableName) const
{
return m_variables.contains(variableName);
}
QVariant Scope::variable(const QString &identifier) const
{
return m_variables.value(identifier);
}
void Scope::setVariable(const QString &identifier, const QVariant &value)
{
m_variables.insert(identifier,value);
}
bool Scope::hasScope(const QString &name) const
{
return m_children.contains(name);
}
void Scope::addScope(const QString &name, Scope *child)
{
m_children.insert(name, child);
}
Scope* Scope::scope(const QString &name) const
{
if(hasScope(name))
{
return m_children.value(name);
}
else
{
return 0;
}
}
QString Scope::findIdentifierAndScope(const QString &qualifiedIdentifier, Scope *& foundScope)
{
foundScope = this;
QString identifier;
int lastPosition = 0;
int position = 0;
position = qualifiedIdentifier.indexOf('.');
while((position = qualifiedIdentifier.indexOf('.',lastPosition)) != -1)
{
identifier = qualifiedIdentifier.mid(lastPosition, position);
foundScope = foundScope->scope(identifier);
lastPosition = position+1;
}
identifier = qualifiedIdentifier.mid(lastPosition, position);
return identifier;
}
void Scope::addClassPrototype(const QString &className, IClassPrototype* prototype)
{
m_classPrototypes.insert(className,prototype);
}
void Scope::addClassConstructor(const QString &constructorName, ClassConstructor* constructor)
{
m_constructors.insert(constructorName, constructor);
}
ClassConstructor* Scope::constructor(const QString &constructorName)
{
return m_constructors.value(constructorName);
}