Beispiel #1
0
        private bool _readBeforeInitialized; // the variable is read before it's initialized and therefore needs an init check

        #endregion Fields

        #region Constructors

        public TotemVariable(string name, VariableKind kind, ScopeStatement/*!*/ scope)
        {
            Assert.NotNull(scope);
            _name = name;
            _kind = kind;
            _scope = scope;
        }
Beispiel #2
0
 public void SetLoc(TotemAst globalParent, IndexSpan span)
 {
     _span = span;
     _parent = globalParent;
 }
Beispiel #3
0
 public void SetLoc(TotemAst globalParent, int start, int end)
 {
     _span = new IndexSpan(start, end > start ? end - start : start);
     _parent = globalParent;
 }
Beispiel #4
0
 private void PushScope(ScopeStatement node)
 {
     node.Parent = _currentScope;
     _currentScope = node;
     _finallyCount.Add(0);
 }
Beispiel #5
0
 private void PopScope()
 {
     _scopes.Add(_currentScope);
     _currentScope = _currentScope.Parent;
     _finallyCount.RemoveAt(_finallyCount.Count - 1);
 }
Beispiel #6
0
        private void Bind(TotemAst unboundAst)
        {
            Assert.NotNull(unboundAst);

            _currentScope = _globalScope = unboundAst;
            _finallyCount.Add(0);

            // Find all scopes and variables
            unboundAst.Walk(this);

            // Bind
            foreach (ScopeStatement scope in _scopes)
            {
                scope.Bind(this);
            }

            // Finish the globals
            unboundAst.Bind(this);

            // Finish Binding w/ outer most scopes first.
            for (int i = _scopes.Count - 1; i >= 0; i--)
            {
                _scopes[i].FinishBind(this);
            }

            // Finish the globals
            unboundAst.FinishBind(this);

            // Run flow checker
            foreach (ScopeStatement scope in _scopes)
            {
                FlowChecker.Check(scope);
            }
        }
Beispiel #7
0
 public override void PostWalk(TotemAst node)
 {
     // Do not add the global suite to the list of processed nodes,
     // the publishing must be done after the class local binding.
     Debug.Assert(_currentScope == node);
     _currentScope = _currentScope.Parent;
     _finallyCount.RemoveAt(_finallyCount.Count - 1);
 }
Beispiel #8
0
 public DelayedProfiling(ScopeStatement ast, MSAst.Expression body, MSAst.ParameterExpression tick)
 {
     _ast = ast;
     _body = body;
     _tick = tick;
 }
Beispiel #9
0
 internal virtual bool TryBindOuter(ScopeStatement from, string name, out TotemVariable variable)
 {
     // Hide scope contents by default (only functions expose their locals)
     variable = null;
     return false;
 }
Beispiel #10
0
            private ScopeStatement VisitScope(ScopeStatement scope)
            {
                var newScope = scope.CopyForRewrite();
                ScopeStatement prevScope = _curScope;
                try
                {
                    // rewrite the method body
                    _curScope = newScope;
                    newScope.Parent = prevScope;

                    newScope.RewriteBody(this);
                }
                finally
                {
                    _curScope = prevScope;
                }
                return newScope;
            }
Beispiel #11
0
 public LookupVisitor(TotemAst ast, MSAst.Expression globalContext)
 {
     _globalContext = globalContext;
     _curScope = ast;
 }
Beispiel #12
0
        internal override bool TryBindOuter(ScopeStatement from, string name, out TotemVariable variable)
        {
            // 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 PythonVariable.
                variable = null;
                return false;
            }
            else
            {
                // Create a global variable to bind to.
                variable = EnsureGlobalVariable(name);
                return true;
            }
        }