Example #1
0
 public ExtractedMethodCreator(JAst ast, ScopeStatement[] scopes, HashSet<JVariable> inputVariables, HashSet<JVariable> outputVariables, SelectionTarget target, int indentSize, bool insertTabs)
 {
     _ast = ast;
     _scopes = scopes;
     _inputVars = new List<JVariable>(inputVariables);
     _outputVars = new List<JVariable>(outputVariables);
     _inputVars.Sort(CompareVariables);
     _outputVars.Sort(CompareVariables);
     _target = target;
     _indentSize = indentSize;
     _insertTabs = insertTabs;
 }
Example #2
0
 public ExtractMethodRequest(ScopeStatement targetScope, string name, string[] parameters)
 {
     _name = name;
     _parameters = parameters;
     _targetScope = targetScope;
 }
Example #3
0
 public NodeTarget(Dictionary<ScopeStatement, int> insertLocations, ScopeStatement[] parents, Node node)
     : base(insertLocations, parents)
 {
     _node = node;
 }
Example #4
0
 public SuiteTarget(Dictionary<ScopeStatement, int> insertLocations, ScopeStatement[] parents, SuiteStatement suite, SuiteStatement[] followingSuites, Span selectedSpan, int startIndex, int endIndex)
     : base(insertLocations, parents)
 {
     _suite = suite;
     _start = startIndex;
     _end = endIndex;
     _followingSuites = followingSuites;
     _selectedSpan = selectedSpan;
 }
Example #5
0
 public SelectionTarget(Dictionary<ScopeStatement, int> insertLocations, ScopeStatement[] parents)
 {
     _parents = parents;
     _insertLocations = insertLocations;
 }
Example #6
0
        internal override bool TryBindOuter(ScopeStatement from, string name, bool allowGlobals, out JVariable variable)
        {
            // Functions expose their locals to direct access
            ContainsNestedFreeVariables = true;
            if (TryGetVariable(name, out variable)) {
                variable.AccessedInNestedScope = true;

                if (variable.Kind == VariableKind.Local || variable.Kind == VariableKind.Parameter) {
                    from.AddFreeVariable(variable, true);

                    for (ScopeStatement scope = from.Parent; scope != this; scope = scope.Parent) {
                        scope.AddFreeVariable(variable, false);
                    }

                    AddCellVariable(variable);
                } else if(allowGlobals) {
                    from.AddReferencedGlobal(name);
                }
                return true;
            }
            return false;
        }
Example #7
0
 public static void Check(ScopeStatement scope)
 {
     if (scope.ScopeVariables != null) {
         FlowChecker fc = new FlowChecker(scope);
         scope.Walk(fc);
     }
 }
Example #8
0
        public FlowChecker(ScopeStatement scope)
        {
            var scopeVars = scope.ScopeVariables;

            _variables = new Dictionary<string, JVariable>(scopeVars.Count);
            foreach (var scopeVar in scopeVars) {
                _variables[scopeVar.Name] = scopeVar;
            }

            _bits = new BitArray(_variables.Count * 2);
            int index = 0;
            _variableIndices = new Dictionary<JVariable, int>(_variables.Count);
            foreach (var binding in _variables) {
                _variableIndices[binding.Value] = index++;
            }
            _scope = scope;
            _fdef = new FlowDefiner(this);
            _fdel = new FlowDeleter(this);
        }
Example #9
0
 internal virtual bool TryBindOuter(ScopeStatement from, string name, bool allowGlobals, out JVariable variable)
 {
     // Hide scope contents by default (only functions expose their locals)
     variable = null;
     return false;
 }
Example #10
0
 public ImportWalker(ScopeStatement targetStmt)
 {
     _targetStmt = targetStmt;
 }
Example #11
0
File: JAst.cs Project: borota/JTVS
        internal override bool TryBindOuter(ScopeStatement from, string name, bool allowGlobals, out JVariable variable)
        {
            if (allowGlobals) {
                // Unbound variable
                from.AddReferencedGlobal(name);

                if (from.HasLateBoundVariableSets) {
                    // If the context contains unqualified exec, new locals can be introduced
                    // Therefore we need to turn this into a fully late-bound lookup which
                    // happens when we don't have a JVariable.
                    variable = null;
                    return false;
                } else {
                    // Create a global variable to bind to.
                    variable = EnsureGlobalVariable(name);
                    return true;
                }
            }
            variable = null;
            return false;
        }