Inheritance: System.Compiler.Statement
Beispiel #1
0
        private Select VisitSelect(Select select)
        {
            JoinStatementList newJoinStatementList = new JoinStatementList();

            int numJoinStatements = 0;

            for (int i = 0, n = select.joinStatementList.Length; i < n; i++)
            {
                if (select.joinStatementList[i] != null)
                    numJoinStatements++;

                if (numJoinStatements <= 64)
                    newJoinStatementList.Add((JoinStatement)this.VisitJoinStatement(select.joinStatementList[i]));
                else
                    this.HandleError(select.joinStatementList[i], Error.TooManyJoinStatements);
            }

            select.joinStatementList = newJoinStatementList;

            return select;
        }
Beispiel #2
0
        private Select VisitSelect(Select select)
        {
            WriteStart("select ");

            if (select.deterministicSelection)
                Write("first ");

            if (select.Visible)
                Write("visible ");

            if (select.validEndState)
                Write("end ");

            if (this.braceOnNewLine)
            {
                WriteFinish(string.Empty);
                WriteLine("{");
            }
            else
                WriteFinish("{");

            In();

            for (int i = 0, n = select.joinStatementList.Length; i < n; i++)
                this.VisitJoinStatement(select.joinStatementList[i]);

            Out();
            WriteLine("}");

            return select;
        }
Beispiel #3
0
        private Select VisitSelect(Select select)
        {
            JoinStatementList newJoinStatementList = new JoinStatementList();

            for (int i = 0, n = select.joinStatementList.Length; i < n; i++)
            {
                JoinStatement js = this.VisitJoinStatement(select.joinStatementList[i]);
                js.visible = select.visible;
                newJoinStatementList.Add(js);
            }

            select.joinStatementList = newJoinStatementList;

            return select;
        }
Beispiel #4
0
        private Select VisitSelect(Select select)
        {
            if (select == null) return null;
            Select result = (Select)select.Clone();

            result.joinStatementList = new JoinStatementList();

            for (int i = 0, n = select.joinStatementList.Length; i < n; i++)
                result.joinStatementList.Add((JoinStatement)this.VisitJoinStatement(select.joinStatementList[i]));

            return result;
        }
Beispiel #5
0
        private Select VisitSelect(Select select)
        {
            JoinStatementList newJoinStatementList = new JoinStatementList();

            for (int i = 0, n = select.joinStatementList.Length; i < n; i++)
                newJoinStatementList.Add((JoinStatement)this.VisitJoinStatement(select.joinStatementList[i]));

            select.joinStatementList = newJoinStatementList;

            return select;
        }
Beispiel #6
0
        private Select VisitSelect(Select select)
        {
            if (select == null) return null;
            BasicBlock[] jsBodies = new BasicBlock[select.joinStatementList.Length];

            // Traverse each join statement body, with the current continuation
            // pointing to the statement following the "select". Remember where
            // each join statement body begins so we can wire things up correctly.
            for (int i = 0, n = select.joinStatementList.Length; i < n; i++)
            {
                PushContinuationStack();
                this.Visit(select.joinStatementList[i].statement);

                // We add an extra block in front of the body because all of the transitions
                // within the internal processing of select are atomic. We need for the
                // transition to a join statement body to be appropriate for the context
                // (atomic or not). Having an extra block here is the simplest way to do
                // that. Otherwise, for our tester blocks, we'd need for one outgoing link
                // to be atomic, and the other one not. In the case of a select within an
                // atomic block, these extra blocks should be optimized away at some point.
                jsBodies[i] = new BasicBlock(null, PopContinuationStack());
                jsBodies[i].SourceContext = select.joinStatementList[i].statement.SourceContext;
                AddBlock(jsBodies[i]);
            }

            // For each join statement, create a pair of basic blocks - one to
            // see whether the join statement is runnable, and another to do
            // any "receives" contained in the join pattern list. If there are
            // no receives to be processed, the second block may be omitted.
            //
            // We walk through the list backward to make the wiring easier.
            BasicBlock nextTester = null;

            for (int i = select.joinStatementList.Length - 1; i >= 0; i--)
            {
                JoinStatement js = select.joinStatementList[i];

                if (i == select.joinStatementList.Length - 1)
                {
                    // If we fall through all of the select test blocks, then we must have
                    // reached this select statement from within an atomic block. Otherwise,
                    // we'd know that at least one branch is runnable. In this case, we raise
                    // a well-known exception and report this as an invalid state.
                    nextTester = new BasicBlock(Templates.GetStatementTemplate("InvalidBlockingSelect"));
                    nextTester.SourceContext = select.SourceContext;
                    AddBlock(nextTester);
                    nextTester.SkipNormalizer = true;
                }

                BasicBlock jsTester = new BasicBlock(js);
                AddBlock(jsTester);
                jsTester.MiddleOfTransition = true;
                jsTester.UnconditionalTarget = nextTester;
                nextTester = jsTester;
                jsTester.ConditionalExpression = Templates.GetExpressionTemplate("JoinStatementTester");
                Replacer.Replace(jsTester.ConditionalExpression, "_jsBitMask", (Expression)new Literal((ulong)1 << i, SystemTypes.UInt64));

                bool jsHasReceives = false;
                for (int j = 0, n = js.joinPatternList.Length; j < n; j++)
                {
                    if (js.joinPatternList[j] is ReceivePattern)
                    {
                        jsHasReceives = true;
                        break;
                    }
                }

                //
                // We need an executable block if there are receives to be processed
                // OR if we need to generate any external events OR if there are
                // attributes that we need to deal with on the join statement.
                //
                if (jsHasReceives || select.visible || js.attributes != null)
                {
                    BasicBlock jsReceiver = new BasicBlock(js);
                    AddBlock(jsReceiver);
                    jsReceiver.Attributes = js.Attributes;
                    jsReceiver.MiddleOfTransition = true;
                    jsReceiver.SecondOfTwo = true;
                    jsReceiver.UnconditionalTarget = jsBodies[i];
                    jsTester.ConditionalTarget = jsReceiver;
                }
                else
                    jsTester.ConditionalTarget = jsBodies[i];
            }

            BasicBlock selectBlock = new BasicBlock(Templates.GetStatementTemplate("SelectStatementProlog"));

            if (select.deterministicSelection || select.joinStatementList.Length == 1)
            {
                // For deterministic selection, we fall directly through to the first
                // "tester" block.
                selectBlock.UnconditionalTarget = nextTester;
                selectBlock.MiddleOfTransition = true;
            }
            else
            {
                // For non-deterministic selection, we conditionally branch to a "choice" block if
                // more than one join statement is runnable. Otherwise, we fall through to the first
                // tester.
                BasicBlock choiceHelper = new BasicBlock(Templates.GetStatementTemplate("NDSelectBlock"));
                choiceHelper.UnconditionalTarget = nextTester;
                AddBlock(choiceHelper);
                choiceHelper.MiddleOfTransition = true;
                choiceHelper.SkipNormalizer = true;
                choiceHelper.SourceContext = select.SourceContext;

                selectBlock.UnconditionalTarget = nextTester;
                selectBlock.ConditionalExpression = Templates.GetExpressionTemplate("NDSelectTest");
                selectBlock.ConditionalTarget = choiceHelper;
                selectBlock.MiddleOfTransition = false;
            }

            AddBlock(selectBlock);
            selectBlock.selectStmt = select;
            selectBlock.SkipNormalizer = true;
            // selectBlock.MiddleOfTransition = true;
            selectBlock.SourceContext = select.SourceContext;

            CurrentContinuation = selectBlock;

            return select;
        }
Beispiel #7
0
        private Select VisitSelect(Select select)
        {
            if (select == null) return null;

            PushSelectStatement(select);

            JoinStatementList newJoinStatementList = new JoinStatementList();

            int timeoutIndex = -1;

            for (int i = 0, n = select.joinStatementList.Length; i < n; i++)
            {
                if (select.joinStatementList[i].joinPatternList[0] is TimeoutPattern)
                {
                    if (timeoutIndex >= 0)
                    {
                        // If we've already seen a "timeout" join statement, then skip
                        // subsequent ones and report an error.
                        HandleError(select.joinStatementList[i], Error.TooManyTimeouts);
                        continue;
                    }
                    timeoutIndex = i;
                }

                JoinStatement newJoinStatement = (JoinStatement)this.VisitJoinStatement(select.joinStatementList[i]);

                if (newJoinStatement != null)
                    newJoinStatementList.Add(newJoinStatement);
            }

            select.joinStatementList = newJoinStatementList;

            // If a timeout is present and it isn't already last, move it to the
            // end of the list. This will be helpful during code generation.
            if (timeoutIndex >= 0 && timeoutIndex != (select.joinStatementList.Length - 1))
            {
                JoinStatement temp;
                temp = select.joinStatementList[select.joinStatementList.Length - 1];
                select.joinStatementList[select.joinStatementList.Length - 1] = select.joinStatementList[timeoutIndex];
                select.joinStatementList[timeoutIndex] = temp;
            }

            if (select.joinStatementList.Length == 1)
                select.deterministicSelection = true;

            PopSelectStatement();

            if (select.joinStatementList.Length == 0)
                return null;

            return select;
        }
Beispiel #8
0
 private void PushSelectStatement(Select select)
 {
     selectStatementStack.Push(select);
 }
Beispiel #9
0
        private Select VisitSelect(Select select)
        {
            if (select == null) return null;

            for (int i = 0, n = select.joinStatementList.Length; i < n; i++)
                select.joinStatementList[i] = (JoinStatement)this.VisitJoinStatement(select.joinStatementList[i]);

            return select;
        }