상속: System.Compiler.Statement
예제 #1
0
        //
        // JoinStatement nodes can be traversed in two ways - to generate a "runnable"
        // expression, or to generate the body of their basic block. We separate out
        // the first kind of traversal into the following two methods.
        //
        public Expression GetRunnablePredicate(JoinStatement joinStatement)
        {
            Expression fullExpr = null;

            for (int i = 0, n = joinStatement.joinPatternList.Length; i < n; i++)
            {
                Expression jpExpr = (Expression)this.Visit(joinStatement.joinPatternList[i]);

                if (fullExpr == null)
                    fullExpr = jpExpr;
                else
                    fullExpr = new BinaryExpression(fullExpr, jpExpr, NodeType.LogicalAnd, joinStatement.SourceContext);
            }
            return fullExpr;
        }
예제 #2
0
        private JoinStatement VisitJoinStatement(JoinStatement joinstmt)
        {
            this.VisitAttributeList(joinstmt.Attributes);
            WriteStart(string.Empty);
            for (int i = 0, n = joinstmt.joinPatternList.Length; i < n; i++)
            {
                this.Visit(joinstmt.joinPatternList[i]);

                if ((i + 1) < n)
                    Write(" && ");
            }

            Write(" -> ");
            bool indentStmt = !(joinstmt.statement is Block);

            if (indentStmt)
                In();
            this.Visit(joinstmt.statement);
            if (indentStmt)
                Out();

            return joinstmt;
        }
예제 #3
0
        private JoinStatement VisitJoinStatement(JoinStatement joinstmt)
        {
            if (joinstmt == null) return null;
            JoinPatternList newJoinPatternList = new JoinPatternList();

            for (int i = 0, n = joinstmt.joinPatternList.Length; i < n; i++)
                newJoinPatternList.Add((JoinPattern)this.Visit(joinstmt.joinPatternList[i]));

            joinstmt.joinPatternList = newJoinPatternList;
            joinstmt.statement = (Statement)this.Visit(joinstmt.statement);
            joinstmt.attributes = this.VisitAttributeList(joinstmt.attributes);
            return joinstmt;
        }
예제 #4
0
        private Statement VisitJoinStatement(JoinStatement joinstmt)
        {
            //
            // The first block of a join statement pair only tests the condition.
            // It needs no executable statements.
            //
            if (!this.secondOfTwo)
                return null;

            bool anyEvents = false;

            Block stmtBlock = new Block();
            stmtBlock.Statements = new StatementList();

            for (int i = 0, n = joinstmt.joinPatternList.Length; i < n; i++)
            {
                JoinPattern jp = joinstmt.joinPatternList[i];
                ReceivePattern receivePattern = jp as ReceivePattern;
                WaitPattern waitPattern = jp as WaitPattern;
                EventPattern eventPattern = jp as EventPattern;

                if (receivePattern != null)
                {
                    // Construct a statement to actually perform the receive.
                    Statement receiveStmt = Templates.GetStatementTemplate("ReceivePattern");
                    Replacer.Replace(receiveStmt, "_chanExpr", this.VisitExpression(receivePattern.channel));
                    Replacer.Replace(receiveStmt, "_chanType", receivePattern.channel.Type.Name);
                    Replacer.Replace(receiveStmt, "_target", this.VisitExpression(receivePattern.data));
                    Replacer.Replace(receiveStmt, "_context", splicer.SourceContextConstructor(jp.SourceContext));
                    Replacer.Replace(receiveStmt, "_contextAttr", splicer.ContextAttributeConstructor(this.attributes));

                    //
                    // If the type is complex, we need to cast to Z.Pointer instead of the given type
                    //
                    TypeNode tn = receivePattern.data.Type;
                    if (tn is Set || tn is ZArray || tn is Class || tn is Chan)
                        Replacer.Replace(receiveStmt, "_targetType", new Identifier("Pointer"));
                    else
                        Replacer.Replace(receiveStmt, "_targetType", receivePattern.data.Type.Name);

                    stmtBlock.Statements.Add(receiveStmt); ;
                }
                else if (eventPattern != null)
                {
                    Statement eventStmt = Templates.GetStatementTemplate("Event");

                    Replacer.Replace(eventStmt, "_chanExpr", this.VisitExpression(eventPattern.channelNumber));
                    Replacer.Replace(eventStmt, "_msgExpr", this.VisitExpression(eventPattern.messageType));
                    Replacer.Replace(eventStmt, "_dirExpr", this.VisitExpression(eventPattern.direction));
                    Replacer.Replace(eventStmt, "_context", splicer.SourceContextConstructor(eventPattern.SourceContext));
                    Replacer.Replace(eventStmt, "_contextAttr", splicer.ContextAttributeConstructor(this.attributes));

                    stmtBlock.Statements.Add(eventStmt);

                    anyEvents = true;
                }
            }

            if (joinstmt.visible && !anyEvents)
            {
                Statement eventStmt = Templates.GetStatementTemplate("TauEvent");
                Replacer.Replace(eventStmt, "_context", splicer.SourceContextConstructor(joinstmt.SourceContext));
                Replacer.Replace(eventStmt, "_contextAttr", splicer.ContextAttributeConstructor(this.attributes));

                stmtBlock.Statements.Add(eventStmt);
            }

            return stmtBlock;
        }
예제 #5
0
 public void Add(JoinStatement element)
 {
     int n = this.elements.Length;
     int i = this.length++;
     if (i == n)
     {
         int m = n * 2; if (m < 16) m = 16;
         JoinStatement[] newElements = new JoinStatement[m];
         for (int j = 0; j < n; j++) newElements[j] = elements[j];
         this.elements = newElements;
     }
     this.elements[i] = element;
 }
예제 #6
0
        private JoinStatement VisitJoinStatement(JoinStatement joinstmt)
        {
            if (joinstmt == null) return null;

            JoinPatternList newJoinPatternList = new JoinPatternList();

            for (int i = 0, n = joinstmt.joinPatternList.Length; i < n; i++)
            {
                if (joinstmt.joinPatternList[i] is TimeoutPattern && n != 1)
                {
                    // If we've already see a timeout in this join statement, then
                    // skip any subsequent ones and report an error
                    HandleError(joinstmt.joinPatternList[i], Error.TimeoutNotAlone);
                    return null;
                }

                JoinPattern newJoinPattern = (JoinPattern)this.Visit(joinstmt.joinPatternList[i]);

                if (newJoinPattern != null)
                    newJoinPatternList.Add(newJoinPattern);
            }

            joinstmt.joinPatternList = newJoinPatternList;
            joinstmt.statement = (Statement)this.Visit(joinstmt.statement);
            joinstmt.attributes = this.VisitAttributeList(joinstmt.attributes);

            if (joinstmt.joinPatternList.Length == 0 || joinstmt.statement == null)
                return null;

            return joinstmt;
        }