3 using System.Collections.Generic;
6 using SiliconStudio.Paradox.Shaders.Parser.Analysis;
7 using SiliconStudio.Shaders.Ast;
9 namespace SiliconStudio.
Paradox.Shaders.Parser.Mixins
11 internal class ReferencesPool
16 public Dictionary<Variable, HashSet<ExpressionNodeCouple>> VariablesReferences {
get;
private set; }
21 public Dictionary<MethodDeclaration, HashSet<MethodInvocationExpression>> MethodsReferences {
get;
private set; }
23 public ReferencesPool()
25 VariablesReferences =
new Dictionary<Variable, HashSet<ExpressionNodeCouple>>();
26 MethodsReferences =
new Dictionary<MethodDeclaration, HashSet<MethodInvocationExpression>>();
33 public void Merge(ReferencesPool pool)
36 foreach (var variableReference
in pool.VariablesReferences)
38 if (!VariablesReferences.ContainsKey(variableReference.Key))
39 VariablesReferences.Add(variableReference.Key,
new HashSet<ExpressionNodeCouple>());
41 VariablesReferences[variableReference.Key].UnionWith(variableReference.Value);
44 foreach (var methodReference
in pool.MethodsReferences)
46 if (!MethodsReferences.ContainsKey(methodReference.Key))
47 MethodsReferences.Add(methodReference.Key,
new HashSet<MethodInvocationExpression>());
49 MethodsReferences[methodReference.Key].UnionWith(methodReference.Value);
58 VariablesReferences = VariablesReferences.ToDictionary(variable => variable.Key, variable => variable.Value);
59 MethodsReferences = MethodsReferences.ToDictionary(method => method.Key, variable => variable.Value);
67 public void InsertVariable(
Variable variable, ExpressionNodeCouple expression)
69 if (!VariablesReferences.ContainsKey(variable))
70 VariablesReferences.Add(variable,
new HashSet<ExpressionNodeCouple>());
71 VariablesReferences[variable].Add(expression);
81 if (!MethodsReferences.ContainsKey(methodDeclaration))
82 MethodsReferences.Add(methodDeclaration,
new HashSet<MethodInvocationExpression>());
83 MethodsReferences[methodDeclaration].Add(expression);