Cleanup
This commit is contained in:
parent
76b57ca3f8
commit
30c3f6f19c
1 changed files with 31 additions and 15 deletions
48
ssc/scope.cs
48
ssc/scope.cs
|
@ -80,28 +80,38 @@ namespace arookas {
|
|||
}
|
||||
|
||||
class sunScope {
|
||||
List<sunStorableSymbol> Storables { get; set; }
|
||||
IEnumerable<sunVariableSymbol> Variables { get { return Storables.OfType<sunVariableSymbol>(); } }
|
||||
IEnumerable<sunConstantSymbol> Constants { get { return Storables.OfType<sunConstantSymbol>(); } }
|
||||
public sunScopeType Type { get; private set; }
|
||||
List<sunStorableSymbol> mStorables;
|
||||
sunScopeType mType;
|
||||
|
||||
public sunScope(sunScopeType type) {
|
||||
Storables = new List<sunStorableSymbol>(10);
|
||||
Type = type;
|
||||
public sunScopeType Type {
|
||||
get { return mType; }
|
||||
}
|
||||
|
||||
public int StorableCount { get { return Storables.Count; } }
|
||||
public int VariableCount { get { return Variables.Count(); } }
|
||||
public int ConstantCount { get { return Constants.Count(); } }
|
||||
public sunScope(sunScopeType type) {
|
||||
mStorables = new List<sunStorableSymbol>(10);
|
||||
mType = type;
|
||||
}
|
||||
|
||||
public bool GetIsDeclared(string name) { return Storables.Any(v => v.Name == name); }
|
||||
public int StorableCount {
|
||||
get { return mStorables.Count; }
|
||||
}
|
||||
public int VariableCount {
|
||||
get { return mStorables.Count(i => i is sunVariableSymbol); }
|
||||
}
|
||||
public int ConstantCount {
|
||||
get { return mStorables.Count(i => i is sunConstantSymbol); }
|
||||
}
|
||||
|
||||
public bool GetIsDeclared(string name) {
|
||||
return mStorables.Any(v => v.Name == name);
|
||||
}
|
||||
|
||||
public sunVariableSymbol DeclareVariable(string name, int display, int index) {
|
||||
if (GetIsDeclared(name)) {
|
||||
return null;
|
||||
}
|
||||
var symbol = new sunVariableSymbol(name, display, index);
|
||||
Storables.Add(symbol);
|
||||
mStorables.Add(symbol);
|
||||
return symbol;
|
||||
}
|
||||
public sunConstantSymbol DeclareConstant(string name, sunExpression expression) {
|
||||
|
@ -109,13 +119,19 @@ namespace arookas {
|
|||
return null;
|
||||
}
|
||||
var symbol = new sunConstantSymbol(name, expression);
|
||||
Storables.Add(symbol);
|
||||
mStorables.Add(symbol);
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public sunStorableSymbol ResolveStorable(string name) { return Storables.FirstOrDefault(i => i.Name == name); }
|
||||
public sunVariableSymbol ResolveVariable(string name) { return Variables.FirstOrDefault(i => i.Name == name); }
|
||||
public sunConstantSymbol ResolveConstant(string name) { return Constants.FirstOrDefault(i => i.Name == name); }
|
||||
public sunStorableSymbol ResolveStorable(string name) {
|
||||
return mStorables.FirstOrDefault(i => i.Name == name);
|
||||
}
|
||||
public sunVariableSymbol ResolveVariable(string name) {
|
||||
return ResolveStorable(name) as sunVariableSymbol;
|
||||
}
|
||||
public sunConstantSymbol ResolveConstant(string name) {
|
||||
return ResolveStorable(name) as sunConstantSymbol;
|
||||
}
|
||||
}
|
||||
|
||||
enum sunScopeType {
|
||||
|
|
Loading…
Reference in a new issue