예제 #1
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 (var scope in _scopes)
            {
                scope.Bind(this);
            }

            // Bind 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 (var scope in _scopes)
            {
                //FlowChecker.Check(totemCode);
            }
        }
예제 #2
0
        public TotemVariable(string name, VariableKind kind, ScopeStmt scope)
        {
            ContractUtils.RequiresNotNull(scope, "totemCode");

            _name = name;
            _kind = kind;
            _scope = scope;
        }
예제 #3
0
 public void SetLoc(TotemAst globalParent, IndexSpan span)
 {
     _span = span;
     _parent = globalParent;
 }
예제 #4
0
 public void SetLoc(TotemAst globalParent, int start, int end)
 {
     _span = new IndexSpan(start, end > start ? end - start : start);
     _parent = globalParent;
 }
예제 #5
0
            private ScopeStmt VisitScope(ScopeStmt scope)
            {
                var newScope = scope.CopyForRewrite();
                ScopeStmt prevScope = _curScope;
                try
                {
                    _curScope = newScope;
                    newScope.Parent = prevScope;

                    newScope.RewriteBody(this);
                }
                finally
                {
                    _curScope = prevScope;
                }

                return newScope;
            }
예제 #6
0
 public LookupVisitor(TotemAst ast, Expression globalContext)
 {
     _globalContext = globalContext;
     _curScope = ast;
 }
예제 #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);
 }
예제 #8
0
 private void PopScope()
 {
     _scopes.Add(_currentScope);
     _currentScope = _currentScope.Parent;
     _finallyCount.RemoveAt(_finallyCount.Count - 1);
     if (_currentScope is FunctionDefinition)
         _currentFunc = (FunctionDefinition)_currentScope;
 }
예제 #9
0
 private void PushScope(ScopeStmt node)
 {
     node.Parent = _currentScope;
     _currentScope = node;
     _finallyCount.Add(0);
     if (_currentScope is FunctionDefinition)
         _currentFunc = (FunctionDefinition)_currentScope;
 }