BadScript 2
Loading...
Searching...
No Matches
BadConstantSubstitutionOptimizerScope.cs
Go to the documentation of this file.
2
4
9{
13 private readonly Dictionary<string, BadExpression> m_Constants = new Dictionary<string, BadExpression>();
14
19
24 {
25 m_Parent = null;
26 }
27
36
43 public BadExpression GetConstant(string name)
44 {
45 if (m_Constants.TryGetValue(name, out BadExpression? value))
46 {
47 return value;
48 }
49
50 if (m_Parent != null && m_Parent.IsConstant(name))
51 {
52 return m_Parent.GetConstant(name);
53 }
54
55 throw new Exception("Constant not found");
56 }
57
63 public bool IsConstant(string name)
64 {
65 return m_Constants.ContainsKey(name) || m_Parent != null && m_Parent.IsConstant(name);
66 }
67
73 public void AddConstant(string name, BadExpression expr)
74 {
75 m_Constants.Add(name, expr);
76 }
77
86}
BadConstantSubstitutionOptimizerScope(BadConstantSubstitutionOptimizerScope? parent)
Creates a new scope with a parent scope.
BadExpression GetConstant(string name)
Returns a constant from this scope or a parent scope.
void AddConstant(string name, BadExpression expr)
Adds a constant to this scope.
bool IsConstant(string name)
Returns true if the constant is defined in this scope or a parent scope.
readonly Dictionary< string, BadExpression > m_Constants
The constants in this scope.
Base Implementation for all Expressions used inside the Script.
Contains the BadScript2 Constant Substitution Optimizations.
Contains the Expressions for the BadScript2 Language.