Example #1
0
                internal bool WalkName(NameExpression node, PythonReference reference)
                {
                    if (_collector.ReadFromExtractedCode(reference.Variable))
                    {
                        if ((!_collector._inputCollector._allReads.Contains(reference) &&
                             !_collector._inputCollector._allWrites.Contains(reference)))
                        {
                            // the variable is assigned outside the refactored code
                            if (node.GetStart(_collector._root) < _collector._target.StartIncludingIndentation)
                            {
                                // it's assigned before the extracted code
                                _collector._inputVars.Add(reference.Variable);
                            }
                            else
                            {
                                Debug.Assert(node.GetEnd(_collector._root) > _collector._target.End);
                                // it's assigned afterwards, we don't care...
                            }
                        }
                        else if (_collector._readBeforeInitialized.Contains(reference.Variable) &&
                                 _collector._inputCollector._allWrites.Contains(reference) &&
                                 _collector._inLoop)
                        {
                            // we read an un-initialized value, so it needs to be passed in.  If we
                            // write to it as well then we need to pass it back out for future calls.
                            _collector._outputVars.Add(reference.Variable);
                        }
                    }

                    return(false);
                }
Example #2
0
            public override bool Walk(NameExpression node)
            {
                var reference = node.GetVariableReference(_root);

                if (reference != null && !_inputCollector._allReads.Contains(reference) && !_inputCollector._allWrites.Contains(reference))
                {
                    // this variable is referenced outside of the refactored code
                    if (node.GetStart(_root) < _target.StartIncludingIndentation)
                    {
                        // it's read before the extracted code, we don't care...
                    }
                    else
                    {
                        Debug.Assert(node.GetEnd(_root) > _target.End, "didn't reference variable in extracted range");

                        // it's read after the extracted code, if its written to in the refactored
                        // code we need to include it as an output
                        if (_inputCollector._allWrittenVariables.Contains(reference.Variable) &&
                            (_readByFollowingCodeBeforeInit == null || _readByFollowingCodeBeforeInit.Contains(reference.Variable)))
                        {
                            // the variable is written to by the refactored code
                            _outputVars.Add(reference.Variable);
                        }
                    }
                }

                return(true);
            }