예제 #1
0
        // FORALL
        public override string Visit(ForAllNode node, object obj)
        {
            StringBuilder builder = new StringBuilder();

            // Counter name is scope-level dependent, so as to avoid name conflicts in nested scopes
            string i = $"i_{SymbolTable.ScopeLevelCounter}";

            builder.Append($"for(int {i} = 0; {i} < {Visit(node.Parent)}.Count; {i}++)\n");
            builder.Append($"{{\n var {node.Child.Id} = {Visit(node.Parent)}[{i}];\n");
            builder.Append($"{Visit(node.Block)}");
            builder.Append($"}}");

            return(builder.ToString());
        }
        // FORALL
        public override ASTNode VisitForAllStmt(CLUBSParser.ForAllStmtContext context)
        {
            SourcePosition forallPosition = new SourcePosition(context.start);
            SourcePosition childPosition  = new SourcePosition(context.child);

            ForAllNode node = new ForAllNode(forallPosition);

            IdentifierNode childId = new IdentifierNode(context.child.Text, childPosition);

            node.Child  = new DeclarationNode(null, childId, childPosition);
            node.Parent = Visit(context.parent) as ReferenceNode;
            node.Block  = Visit(context.blockStmt()) as BlockNode;

            return(node);
        }
예제 #3
0
        // FORALL
        public override TypeNode Visit(ForAllNode node, object obj)
        {
            node.Parent.Type = Visit(node.Parent);

            // Open local scope for FORALL node, so child only exists within this scope
            SymbolTable.OpenScope();

            // Log error if parent type is not Set, else visit child and block
            if (node.Parent.Type != StandardTypes.Set)
            {
                ErrorLogger.LogError(new ExpectedTypeError(node, StandardTypes.Set, node.Parent.SourcePosition));
                return(new ErrorTypeNode(node.SourcePosition));
            }
            else
            {
                node.Child.Type = (node.Parent.Type as SetTypeNode).Type;
                Visit(node.Child);
                Visit(node.Block);
            }

            SymbolTable.CloseScope(); // Close local scope

            return(null);
        }
예제 #4
0
 public abstract T Visit(ForAllNode node, object obj);