예제 #1
0
        //================================================================================================//
        // check IF conditions
        //================================================================================================//
        private static bool ProcessIfCondition(SignalHead head, SignalScripts.SCRScripts.SCRConditionBlock condition, int[] localFloats)
        {
            bool performed = false;

            // check condition

            // if set : execute IF block
            if (ProcessConditionStatement(head, condition.Conditions, localFloats))
            {
                if (!ProcessStatementBlock(head, condition.IfBlock.Statements, localFloats))
                {
                    return(false);
                }
                performed = true;
            }

            // not set : check through ELSEIF
            if (!performed)
            {
                int totalElseIf = condition.ElseIfBlock == null ? 0 : condition.ElseIfBlock.Count;

                for (int ielseif = 0; ielseif < totalElseIf && !performed; ielseif++)
                {
                    // first (and only ) entry in ELSEIF block must be IF condition - extract condition
                    object elseifStat = condition.ElseIfBlock[ielseif].Statements[0];
                    if (elseifStat is SignalScripts.SCRScripts.SCRConditionBlock elseifCond)
                    {
                        if (ProcessConditionStatement(head, elseifCond.Conditions, localFloats))
                        {
                            if (!ProcessStatementBlock(head, elseifCond.IfBlock.Statements, localFloats))
                            {
                                return(false);
                            }
                            performed = true;
                        }
                    }
                }
            }

            // ELSE block
            if (!performed && condition.ElseBlock != null)
            {
                if (!ProcessStatementBlock(head, condition.ElseBlock.Statements, localFloats))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #2
0
        //================================================================================================//
        //
        // check IF conditions
        //
        //================================================================================================//

        public bool SH_processIfCondition(SignalHead thisHead, SignalScripts.SCRScripts.SCRConditionBlock thisCond,
                                          int[] localFloats, SIGSCRfile sigscr)
        {
            //                                SCRScripts.SCRConditionBlock thisCond = (SCRScripts.SCRConditionBlock) scriptstat;
            //                                SH_processIfCondition(thisHead, thisCond, localFloats, sigscr);
            //                                public ArrayList       Conditions;
            //                                public SCRBlock        IfBlock;
            //                                public List <SCRBlock> ElseIfBlock;
            //                                public SCRBlock        ElseBlock;

            bool condition = true;
            bool performed = false;

            // check condition

            condition = SH_processConditionStatement(thisHead, thisCond.Conditions, localFloats, sigscr);

            // if set : execute IF block

            if (condition)
            {
                if (!SH_process_StatementBlock(thisHead, thisCond.IfBlock.Statements, localFloats, sigscr))
                {
                    return(false);
                }
                performed = true;
            }

            // not set : check through ELSEIF

            if (!performed)
            {
                int totalElseIf;
                if (thisCond.ElseIfBlock == null)
                {
                    totalElseIf = 0;
                }
                else
                {
                    totalElseIf = thisCond.ElseIfBlock.Count;
                }

                for (int ielseif = 0; ielseif < totalElseIf && !performed; ielseif++)
                {
                    // first (and only ) entry in ELSEIF block must be IF condition - extract condition

                    object elseifStat = thisCond.ElseIfBlock[ielseif].Statements[0];
                    if (elseifStat is SignalScripts.SCRScripts.SCRConditionBlock)
                    {
                        SignalScripts.SCRScripts.SCRConditionBlock elseifCond =
                            (SignalScripts.SCRScripts.SCRConditionBlock)elseifStat;

                        condition = SH_processConditionStatement(thisHead, elseifCond.Conditions,
                                                                 localFloats, sigscr);

                        if (condition)
                        {
                            if (!SH_process_StatementBlock(thisHead, elseifCond.IfBlock.Statements,
                                                           localFloats, sigscr))
                            {
                                return(false);
                            }
                            performed = true;
                        }
                    }
                }
            }

            // ELSE block

            if (!performed && thisCond.ElseBlock != null)
            {
                if (!SH_process_StatementBlock(thisHead, thisCond.ElseBlock.Statements, localFloats, sigscr))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #3
0
        //================================================================================================//
        //
        // process statement block
        // called for full script as well as for IF and ELSE blocks
        // if returns false : abort further processing
        //
        //================================================================================================//

        public bool SH_process_StatementBlock(SignalHead thisHead, ArrayList Statements,
                                              int[] localFloats, SIGSCRfile sigscr)
        {
            // loop through all lines

            foreach (object scriptstat in Statements)
            {
                // process statement lines

                if (scriptstat is SignalScripts.SCRScripts.SCRStatement)
                {
                    SignalScripts.SCRScripts.SCRStatement ThisStat = (SignalScripts.SCRScripts.SCRStatement)scriptstat;

                    if (ThisStat.StatementTerms[0].Function == SignalScripts.SCRExternalFunctions.RETURN)
                    {
                        return(false);
                    }

                    SH_processAssignStatement(thisHead, ThisStat, localFloats, sigscr);

#if DEBUG_PRINT_ENABLED
                    if (thisHead.mainSignal.enabledTrain != null)
                    {
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Statement : \n");
                        foreach (string statstring in ThisStat.StatementParts)
                        {
                            File.AppendAllText(dpe_fileLoc + @"printproc.txt", "   " + statstring + "\n");
                        }
                        foreach (int lfloat in localFloats)
                        {
                            File.AppendAllText(dpe_fileLoc + @"printproc.txt", " local : " + lfloat.ToString() + "\n");
                        }
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Externals : \n");
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", " state      : " + thisHead.state.ToString() + "\n");
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", " draw_state : " + thisHead.draw_state.ToString() + "\n");
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", " enabled    : " + thisHead.mainSignal.enabled.ToString() + "\n");
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", " blockstate : " + thisHead.mainSignal.blockState.ToString() + "\n");
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", "\n");
                    }
#endif

#if DEBUG_PRINT_PROCESS
                    if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                    {
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Statement : \n");
                        foreach (string statstring in ThisStat.StatementParts)
                        {
                            File.AppendAllText(dpr_fileLoc + @"printproc.txt", "   " + statstring + "\n");
                        }
                        foreach (int lfloat in localFloats)
                        {
                            File.AppendAllText(dpr_fileLoc + @"printproc.txt", " local : " + lfloat.ToString() + "\n");
                        }
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Externals : \n");
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", " state      : " + thisHead.state.ToString() + "\n");
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", " draw_state : " + thisHead.draw_state.ToString() + "\n");
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", " enabled    : " + thisHead.mainSignal.enabled.ToString() + "\n");
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", " blockstate : " + thisHead.mainSignal.blockState.ToString() + "\n");
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", "\n");
                    }
#endif
                }

                if (scriptstat is SignalScripts.SCRScripts.SCRConditionBlock)
                {
                    SignalScripts.SCRScripts.SCRConditionBlock thisCond = (SignalScripts.SCRScripts.SCRConditionBlock)scriptstat;
                    if (!SH_processIfCondition(thisHead, thisCond, localFloats, sigscr))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }