Refactored out count/filter properties
I find using the Get<T> and GetCount<T> methods better (even though the naming convention sucks ass) in that it automatically supports any and all future symbol types I may add in the future.
This commit is contained in:
parent
ca7057bf02
commit
4a1f0ec855
3 changed files with 8 additions and 21 deletions
|
@ -55,9 +55,9 @@ namespace arookas {
|
|||
}
|
||||
results.DataCount = mContext.DataTable.Count;
|
||||
results.SymbolCount = mContext.SymbolTable.Count;
|
||||
results.BuiltinCount = mContext.SymbolTable.BuiltinCount;
|
||||
results.FunctionCount = mContext.SymbolTable.FunctionCount;
|
||||
results.VariableCount = mContext.SymbolTable.VariableCount;
|
||||
results.BuiltinCount = mContext.SymbolTable.GetCount<sunBuiltinSymbol>();
|
||||
results.FunctionCount = mContext.SymbolTable.GetCount<sunFunctionSymbol>();
|
||||
results.VariableCount = mContext.SymbolTable.GetCount<sunVariableSymbol>();
|
||||
}
|
||||
catch (sunCompilerException ex) {
|
||||
results.Error = ex;
|
||||
|
@ -79,7 +79,7 @@ namespace arookas {
|
|||
}
|
||||
int DoCompileFunctions() {
|
||||
var count = 0;
|
||||
foreach (var callable in mContext.SymbolTable.Callables.Where(i => i.HasRelocations && i.CompileCount == 0)) {
|
||||
foreach (var callable in mContext.SymbolTable.Get<sunCallableSymbol>().Where(i => i.HasRelocations && i.CompileCount == 0)) {
|
||||
callable.Compile(this);
|
||||
++count;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace arookas {
|
|||
|
||||
// callables
|
||||
public sunBuiltinSymbol DeclareBuiltin(sunBuiltinDeclaration node) {
|
||||
if (SymbolTable.Callables.Any(i => i.Name == node.Name.Value)) {
|
||||
if (SymbolTable.Get<sunCallableSymbol>().Any(i => i.Name == node.Name.Value)) {
|
||||
throw new sunRedeclaredBuiltinException(node);
|
||||
}
|
||||
var symbol = new sunBuiltinSymbol(node.Name.Value, node.Parameters.ParameterInfo, SymbolTable.Count);
|
||||
|
@ -58,7 +58,7 @@ namespace arookas {
|
|||
if (node.Parameters.IsVariadic) {
|
||||
throw new sunVariadicFunctionException(node);
|
||||
}
|
||||
if (SymbolTable.Callables.Any(i => i.Name == name)) {
|
||||
if (SymbolTable.Get<sunCallableSymbol>().Any(i => i.Name == name)) {
|
||||
throw new sunRedefinedFunctionException(node);
|
||||
}
|
||||
var symbol = new sunFunctionSymbol(name, node.Parameters.ParameterInfo, node.Body);
|
||||
|
@ -69,11 +69,11 @@ namespace arookas {
|
|||
public sunCallableSymbol ResolveCallable(sunFunctionCall node) {
|
||||
var global = node.Name.Value;
|
||||
var local = MangleSymbolName(global, node.Location.ScriptId, false, true);
|
||||
var symbol = SymbolTable.Callables.FirstOrDefault(i => i.Name == local);
|
||||
var symbol = SymbolTable.Get<sunCallableSymbol>().FirstOrDefault(i => i.Name == local);
|
||||
if (symbol != null) {
|
||||
return symbol;
|
||||
}
|
||||
symbol = SymbolTable.Callables.FirstOrDefault(i => i.Name == global);
|
||||
symbol = SymbolTable.Get<sunCallableSymbol>().FirstOrDefault(i => i.Name == global);
|
||||
if (symbol != null) {
|
||||
return symbol;
|
||||
}
|
||||
|
|
|
@ -9,19 +9,6 @@ namespace arookas {
|
|||
List<sunSymbol> mSymbols;
|
||||
|
||||
public int Count { get { return mSymbols.Count; } }
|
||||
public int CallableCount { get { return Callables.Count(); } }
|
||||
public int BuiltinCount { get { return Builtins.Count(); } }
|
||||
public int FunctionCount { get { return Functions.Count(); } }
|
||||
public int StorableCount { get { return Storables.Count(); } }
|
||||
public int VariableCount { get { return Variables.Count(); } }
|
||||
public int ConstantCount { get { return Constants.Count(); } }
|
||||
|
||||
public IEnumerable<sunCallableSymbol> Callables { get { return mSymbols.OfType<sunCallableSymbol>(); } }
|
||||
public IEnumerable<sunBuiltinSymbol> Builtins { get { return mSymbols.OfType<sunBuiltinSymbol>(); } }
|
||||
public IEnumerable<sunFunctionSymbol> Functions { get { return mSymbols.OfType<sunFunctionSymbol>(); } }
|
||||
public IEnumerable<sunStorableSymbol> Storables { get { return mSymbols.OfType<sunStorableSymbol>(); } }
|
||||
public IEnumerable<sunVariableSymbol> Variables { get { return mSymbols.OfType<sunVariableSymbol>(); } }
|
||||
public IEnumerable<sunConstantSymbol> Constants { get { return mSymbols.OfType<sunConstantSymbol>(); } }
|
||||
|
||||
public sunSymbol this[int index] {
|
||||
get { return mSymbols[index]; }
|
||||
|
|
Loading…
Reference in a new issue