예제 #1
0
        private static BoundScope CreateParentScopes(BoundGlobalScope _previous)
        {
            var _stack = new Stack <BoundGlobalScope>();

            while (_previous != null)
            {
                _stack.Push(_previous);
                _previous = _previous.Previous;
            }

            BoundScope _parent = null;

            while (_stack.Count > 0)
            {
                _previous = _stack.Pop();
                var _scope = new BoundScope(_parent);
                foreach (var _v in _previous.Variables)
                {
                    _scope.TryDeclare(_v);
                }
                _parent = _scope;
            }

            return(_parent);
        }
예제 #2
0
 public BoundGlobalScope(BoundGlobalScope _previous, ImmutableArray <Diagnostic> _diagnostics, ImmutableArray <VariableSymbol> _variables, BoundStatement _statement)
 {
     Previous    = _previous;
     Diagnostics = _diagnostics;
     Variables   = _variables;
     Statement   = _statement;
 }
예제 #3
0
        public static BoundGlobalScope BindGlobalScope(BoundGlobalScope _previous, CompilationUnitSyntax _syntax)
        {
            var _parentScope = CreateParentScopes(_previous);
            var _binder      = new Binder(_parentScope);
            var _expression  = _binder.BindStatement(_syntax.Statement);
            var _variables   = _binder.scope.GetDeclaredVariables();
            var _diagnostics = _binder.Diagnostics.ToImmutableArray();

            if (_previous != null)
            {
                _diagnostics = _diagnostics.InsertRange(0, _previous.Diagnostics);
            }

            return(new BoundGlobalScope(_previous, _diagnostics, _variables, _expression));
        }