private VariableDef CreateVariableInDeclaredScope(NameExpression name, bool isLocated = false) { var reference = name.GetVariableReference(_tree); InterpreterScope declScope = null; if (reference != null && reference.Variable != null) { var declNode = reference.Variable.Scope; if (_scope.Node == declNode) { declScope = _scope; } else { declScope = _scope.EnumerateTowardsGlobal.FirstOrDefault(s => s.Node == declNode); declScope = declScope?.OriginalScope ?? declScope; } } if (isLocated) { return((declScope ?? _scope).CreateLocatedVariable(name, _curUnit, name.Name, false)); } return((declScope ?? _scope).CreateVariable(name, _curUnit, name.Name, false)); }
public override bool Walk(NameExpression node) { var reference = node.GetVariableReference(_root); if (!_inputCollector._allReads.Contains(reference) && !_inputCollector._allWrites.Contains(reference)) { // this variable is referenced outside of the refactored code if (node.StartIndex < _target.StartIncludingIndentation) { // it's read before the extracted code, we don't care... } else { Debug.Assert(node.EndIndex > _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); }
public override bool Walk(NameExpression node) { var reference = node.GetVariableReference(_collector._root); _collector._allWrites.Add(reference); _collector._allWrittenVariables.Add(reference.Variable); return(false); }
public override bool Walk(NameExpression node) { var reference = node.GetVariableReference(_root); _allReads.Add(reference); _allReadVariables.Add(reference.Variable); return(true); }
private VariableDef CreateVariableInDeclaredScope(NameExpression name) { var reference = name.GetVariableReference(_tree); if (reference != null && reference.Variable != null) { var declNode = reference.Variable.Scope; var declScope = _scope.EnumerateTowardsGlobal.FirstOrDefault(s => s.Node == declNode); if (declScope != null) { return(declScope.CreateVariable(name, _curUnit, name.Name, false)); } } return(_scope.CreateVariable(name, _curUnit, name.Name, false)); }
public override bool Walk(NameExpression node) { var reference = node.GetVariableReference(_collector._root); return(WalkName(node, reference)); }