Esempio n. 1
0
        private AnnotatedStatement AnnotateBlockStatement(BlockStatementSyntax statement)
        {
            var statements = ImmutableArray.CreateBuilder <AnnotatedStatement>();

            _scope = new AnnotationScope(_scope);
            foreach (var statementSyntax in statement.Statements)
            {
                var st = AnnotateStatement(statementSyntax);
                statements.Add(st);
            }
            _scope = _scope.Parent;
            return(new AnnotatedBlockStatement(statements.ToImmutable()));
        }
Esempio n. 2
0
        private AnnotatedStatement AnnotateForStatement(ForStatementSyntax statement)
        {
            _scope = new AnnotationScope(_scope);

            var lowerBound = AnnotateExpression(statement.LowerBound, typeof(int));
            var upperBound = AnnotateExpression(statement.UpperBound, typeof(int));
            var name       = statement.Identifier.Text;
            var variable   = new VariableSymbol(name, typeof(int), false);

            _scope.TryDeclare(variable);
            var body = AnnotateStatement(statement.Body);

            _scope = _scope.Parent;
            return(new AnnotatedForStatement(variable, lowerBound, upperBound, body));
        }
Esempio n. 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);
        }
Esempio n. 4
0
 public AnnotationScope(AnnotationScope parent)
 {
     Parent = parent;
 }
Esempio n. 5
0
 public Annotator(AnnotationScope parent)
 {
     _scope = new AnnotationScope(parent);
 }