Example #1
0
 public AnnotationGlobalScope(AnnotationGlobalScope prev, ImmutableArray <Diagnostic> diagnostics, ImmutableArray <VariableSymbol> symbols, AnnotatedStatement expression)
 {
     Previous    = prev;
     Diagnostics = diagnostics;
     Symbols     = symbols;
     Expression  = expression;
 }
Example #2
0
        public static AnnotationGlobalScope AnnotateGlobalScope(AnnotationGlobalScope previous, CompilationUnitSyntax syntax)
        {
            var parentScope = CreateParentScope(previous);
            var annotator   = new Annotator(parentScope);
            var expression  = annotator.AnnotateStatement(syntax.Statement);
            var symbols     = annotator._scope.GetDeclaredVariables();
            var diagnostics = annotator.Diagnostics.ToImmutableArray();

            if (previous != null)
            {
                diagnostics = diagnostics.InsertRange(0, previous.Diagnostics);
            }
            return(new AnnotationGlobalScope(previous, diagnostics, symbols, expression));
        }
Example #3
0
        private static AnnotationScope CreateParentScope(AnnotationGlobalScope previous)
        {
            var stack = new Stack <AnnotationGlobalScope>();

            while (previous != null)
            {
                stack.Push(previous);
                previous = previous.Previous;
            }
            AnnotationScope parent = null;

            while (stack.Count > 0)
            {
                previous = stack.Pop();
                var scope = new AnnotationScope(parent);
                foreach (var v in previous.Symbols)
                {
                    scope.TryDeclare(v);
                }
                parent = scope;
            }
            return(parent);
        }