/// <summary>
        /// Merge the argument references into this one
        /// </summary>
        /// <param name="pool">the ReferencePool</param>
        public void Merge(ReferencesPool pool)
        {
            // merge the VariablesReferences
            foreach (var variableReference in pool.VariablesReferences)
            {
                if (!VariablesReferences.ContainsKey(variableReference.Key))
                    VariablesReferences.Add(variableReference.Key, new HashSet<ExpressionNodeCouple>());

                VariablesReferences[variableReference.Key].UnionWith(variableReference.Value);
            }
            // merge the MethodsReferences
            foreach (var methodReference in pool.MethodsReferences)
            {
                if (!MethodsReferences.ContainsKey(methodReference.Key))
                    MethodsReferences.Add(methodReference.Key, new HashSet<MethodInvocationExpression>());

                MethodsReferences[methodReference.Key].UnionWith(methodReference.Value);
            }
        }
Example #2
0
        /// <summary>
        /// Merge the argument references into this one
        /// </summary>
        /// <param name="pool">the ReferencePool</param>
        public void Merge(ReferencesPool pool)
        {
            // merge the VariablesReferences
            foreach (var variableReference in pool.VariablesReferences)
            {
                if (!VariablesReferences.ContainsKey(variableReference.Key))
                {
                    VariablesReferences.Add(variableReference.Key, new HashSet <ExpressionNodeCouple>());
                }

                VariablesReferences[variableReference.Key].UnionWith(variableReference.Value);
            }
            // merge the MethodsReferences
            foreach (var methodReference in pool.MethodsReferences)
            {
                if (!MethodsReferences.ContainsKey(methodReference.Key))
                {
                    MethodsReferences.Add(methodReference.Key, new HashSet <MethodInvocationExpression>());
                }

                MethodsReferences[methodReference.Key].UnionWith(methodReference.Value);
            }
        }
Example #3
0
        /// <summary>
        /// Rename the methods and their references
        /// </summary>
        /// <param name="references">the pool to rename</param>
        /// <param name="id">the id used to build the new name</param>
        private void RenameAllMethods(ReferencesPool references, HashSet<MethodDefinition> renameFreeMethods, ref int id)
        {
            foreach (var method in references.MethodsReferences)
            {
                if (renameFreeMethods.Contains(method.Key) || !(method.Key is MethodDefinition))
                    continue;

                foreach (var methodRef in method.Value)
                {
                    var targetMre = methodRef.Target as MemberReferenceExpression;
                    if (targetMre != null)
                    {
                        var vre = new VariableReferenceExpression();
                        methodRef.Target = vre;
                        vre.TypeInference.Declaration = targetMre.TypeInference.Declaration;
                        vre.TypeInference.TargetType = targetMre.TypeInference.TargetType;
                    }

                    var targetVre = methodRef.Target as VariableReferenceExpression;
                    targetVre.Name = method.Key.Name;
                }
                
                method.Key.Name.Text += "_id" + id;
                ++id;
            }
            references.RegenKeys();
        }
Example #4
0
        /// <summary>
        /// Rename all the variables and their references based on the id
        /// </summary>
        /// <param name="references">the pool to rename</param>
        /// <param name="id">the id used to build the new name</param>
        private void RenameAllVariables(ReferencesPool references, ref int id)
        {
            foreach (var variable in references.VariablesReferences)
            {
                if (variable.Key.Name.Text == FlipRendertargetVariableName) // DO NOT RENAME THIS SPECIFIC VARIABLE
                    continue;

                foreach (var varRef in variable.Value)
                {
                    if (varRef.Expression is MemberReferenceExpression)
                    {
                        if (variable.Key.Qualifiers.Contains(XenkoStorageQualifier.Stream)) // TODO: change test
                        {
                            (varRef.Expression as MemberReferenceExpression).Member = variable.Key.Name;

                            var type = (varRef.Expression as MemberReferenceExpression).Target.TypeInference.TargetType as StreamsType;
                            if (type == null || !type.IsInputOutput)
                                (varRef.Expression as MemberReferenceExpression).Target = new VariableReferenceExpression(StreamsType.ThisStreams);
                        }
                        else if (variable.Key.Qualifiers.Contains(XenkoStorageQualifier.PatchStream))
                        {
                            (varRef.Expression as MemberReferenceExpression).Member = variable.Key.Name;
                        }
                        else
                        {
                            var vre = new VariableReferenceExpression(variable.Key.Name);
                            vre.TypeInference.Declaration = variable.Key;
                            vre.TypeInference.TargetType = variable.Key.Type.ResolveType();
                            ReplaceMemberReferenceExpressionByVariableReferenceExpression(varRef.Expression as MemberReferenceExpression, vre, varRef.Node);
                            varRef.Expression = vre;
                        }
                    }
                    else
                        (varRef.Expression as VariableReferenceExpression).Name = variable.Key.Name;
                }

                variable.Key.Name.Text += "_id" + id;
                ++id;
            }
        }
 public XenkoParsingInfo()
 {
     StageInitializedVariables = new HashSet<Variable>();
     Typedefs = new List<Typedef>();
     StructureDefinitions = new List<StructType>();
     BaseMethodCalls = new HashSet<MethodInvocationExpression>();
     ThisMethodCalls = new HashSet<MethodInvocationExpression>();
     StageMethodCalls = new HashSet<MethodInvocationExpression>();
     ForEachStatements = new HashSet<StatementNodeCouple>();
     ClassReferences = new ReferencesPool();
     StaticReferences = new ReferencesPool();
     ExternReferences = new ReferencesPool();
     StageInitReferences = new ReferencesPool();
     StaticClasses = new HashSet<ModuleMixin>();
     NavigableNodes = new List<Node>();
 }
Example #6
0
        private SourceSpan? Find(ReferencesPool pool, SiliconStudio.Shaders.Ast.SourceLocation location)
        {
            foreach (var methodRef in pool.MethodsReferences)
            {
                foreach (var expression in methodRef.Value)
                {
                    if (IsExpressionMatching(expression, location))
                    {
                        return methodRef.Key.Span;
                    }
                }
            }

            foreach (var variableRef in pool.VariablesReferences)
            {
                foreach (var expression in variableRef.Value)
                {
                    if (IsExpressionMatching(expression.Expression, location))
                    {
                        return variableRef.Key.Span;
                    }
                }
            }
            return null;
        }
        /// <summary>
        /// Rename all the variables and their references based on the id
        /// </summary>
        /// <param name="references">the pool to rename</param>
        /// <param name="id">the id used to build the new name</param>
        private void RenameAllVariables(ReferencesPool references, ref int id)
        {
            foreach (var variable in references.VariablesReferences)
            {
                foreach (var varRef in variable.Value)
                {
                    var memberReferenceExpression = varRef.Expression as MemberReferenceExpression;
                    if (memberReferenceExpression != null)
                    {
                        if (variable.Key.Qualifiers.Contains(XenkoStorageQualifier.Stream)) // TODO: change test
                        {
                            memberReferenceExpression.Member = variable.Key.Name;

                            var type = memberReferenceExpression.Target.TypeInference.TargetType;
                            if (type == null || !type.IsStreamsType() || !type.IsStreamsMutable())
                                memberReferenceExpression.Target = new VariableReferenceExpression(StreamsType.ThisStreams);
                        }
                        else if (variable.Key.Qualifiers.Contains(XenkoStorageQualifier.PatchStream))
                        {
                            memberReferenceExpression.Member = variable.Key.Name;
                        }
                        else
                        {
                            var vre = new VariableReferenceExpression(variable.Key.Name);
                            vre.TypeInference.Declaration = variable.Key;
                            vre.TypeInference.TargetType = variable.Key.Type.ResolveType();
                            ReplaceMemberReferenceExpressionByVariableReferenceExpression(memberReferenceExpression, vre, varRef.Node);
                            varRef.Expression = vre;
                        }
                    }
                    else
                        ((VariableReferenceExpression)varRef.Expression).Name = variable.Key.Name;
                }

                variable.Key.Name.Text += "_id" + id;
                ++id;
            }
        }