예제 #1
0
파일: Binder.cs 프로젝트: fr3gu/minsk
        private static BoundScope CreateParentScope(BoundGlobalScope previous)
        {
            // submission 3 -> submission 2 -> submission 1
            // submission 1 -> submission 2 -> submission 3
            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 variable in previous.Variables)
                {
                    scope.TryDeclare(variable);
                }

                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
파일: Binder.cs 프로젝트: fr3gu/minsk
        public static BoundGlobalScope BindGlobalScope(BoundGlobalScope previous, CompilationUnitSyntax syntax)
        {
            var parentScope = CreateParentScope(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.InsertRange(0, previous.Diagnostics);
            }

            return(new BoundGlobalScope(previous, diagnostics, variables, expression));
        }