Ejemplo n.º 1
0
        public override void Visit(Method method)
        {
            // Clear lists
            _argumentInformations.Clear();
            _variableDefinitions.Clear();
            _stackTransactions.Clear();

            // Read arguments
            foreach (var parameter in method.Definition.Parameters)
            {
                var parameterType = GetGenericType(method.Definition, parameter.ParameterType);

                _argumentInformations[parameter.Index] = new ArgumentInformation(parameter.Index, parameter, parameterType);
            }

            // Read variables
            if (method.Definition.Body?.Variables != null)
            {
                foreach (var variable in method.Definition.Body?.Variables)
                {
                    var variableType = GetGenericType(method.Definition, variable.VariableType);

                    _variableDefinitions[variable.Index] =
                        new VariableInformation(variable.Index, variable, variableType);
                }
            }

            // Run analyzer
            do
            {
                _changed = false;

                base.Visit(method);
            } while (_changed);

            // Add stack push information to nodes and to the method
            foreach (var nodePushInformations in _stackTransactions)
            {
                foreach (var push in nodePushInformations.Value)
                {
                    nodePushInformations.Key.AddElement(push);

                    method.AddElement(push);
                }
            }

            // Add variable info to method
            foreach (var variableInfo in _variableDefinitions)
            {
                method.AddElement(variableInfo.Value);
            }

            // Add argument information to method
            foreach (var argumentInfo in _argumentInformations)
            {
                method.AddElement(argumentInfo.Value);
            }
        }