⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smccppgenerator.java

📁 SMC takes a state machine stored in a .sm file and generates a State pattern in twelve programming l
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        //        // v. 2.0.2: The following code must be generated twice -        // once for the try body and again for the catch body.        // Unlike Java, C++ does not have a finally clause.        if (transType == Smc.TRANS_SET &&            (actions.size() > 0 || loopbackFlag == false))        {            _source.print(indent3);            _source.print("context.setState(");            _source.print(fqEndStateName);            _source.println(");");        }        else if (transType == Smc.TRANS_PUSH)        {            // Set the end state so that it can be pushed            // onto the state stack. But only do so if a clear            // state was done.            if (loopbackFlag == false || actions.size() > 0)            {                _source.print(indent3);                _source.print("context.setState(");                _source.print(fqEndStateName);                _source.println(");");            }            // Before doing the push, execute the end state's            // entry actions (if any) if this is not a loopback.            if (loopbackFlag == false)            {                if (defaultFlag == true)                {                    indent4 = indent3 + "    ";                    _source.println();                    _source.print(indent3);                    _source.println(                        "if (loopbackFlag == false)");                    _source.print(indent3);                    _source.println("{");                }                else                {                    indent4 = indent3;                    _source.println();                }                _source.print(indent4);                _source.println(                    "(context.getState()).Entry(context);");                if (defaultFlag == true)                {                    _source.print(indent3);                    _source.println("}");                }            }            _source.print(indent3);            _source.print("context.pushState(");            _source.print(pushStateName);            _source.println(");");        }        else if (transType == Smc.TRANS_POP)        {            _source.print(indent3);            _source.println("context.popState();");        }        // v. 2.0.2: Generate the set state, push or pop        // code for the catch body. Note: The try body was        // generated only if there were actions.        // Place the try block's closing brace and open the        // catch-all block.        // v. 2.2.0: Check if the user has turned off this        // feature first.        if (actions.isEmpty() == false &&            Smc.isNoCatch() == false)        {            _source.print(indent2);            _source.println("}");            _source.print(indent2);            _source.println("catch (...)");            _source.print(indent2);            _source.println("{");            if (transType == Smc.TRANS_SET)            {                _source.print(indent3);                _source.print("context.setState(");                _source.print(fqEndStateName);                _source.println(");");            }            else if (transType == Smc.TRANS_PUSH)            {                // Set the end state so that it can be pushed                // onto the state stack.                _source.print(indent3);                _source.print("context.setState(");                _source.print(fqEndStateName);                _source.println(");");                // Before doing the push, execute the end state's                // entry actions (if any) if this is not a                // loopback.                if (loopbackFlag == false)                {                    indent4 = indent3;                    if (defaultFlag == true)                    {                        indent4 = indent3 + "    ";                        _source.println();                        _source.print(indent3);                        _source.println(                            "if (loopbackFlag == false)");                        _source.print(indent3);                        _source.println("{");                    }                    else                    {                        _source.println();                    }                    _source.print(indent4);                    _source.println(                        "(context.getState()).Entry(context);");                    if (defaultFlag == true)                    {                        _source.print(indent3);                        _source.println("}");                    }                }                _source.print(indent3);                _source.print("context.pushState(");                _source.print(pushStateName);                _source.println(");");            }            else if (transType == Smc.TRANS_POP)            {                _source.print(indent3);                _source.println("context.popState();");            }            // Rethrow the exception so the application can            // handle it (or not). This is the end of the            // catch block.            _source.print(indent3);            _source.println("throw;");            _source.print(indent2);            _source.println("}");        }        // Perform the new state's entry actions.        // v. 1.0, beta 3: Not any more. The entry actions are        // executed only if 1) this is a standard, non-loopback        // transition or a push transition.        if ((transType == Smc.TRANS_SET &&             loopbackFlag == false) ||             transType == Smc.TRANS_PUSH)        {            // If this is a non-loopback, generic transition,            // do runtime loopback checking.            if (transType == Smc.TRANS_SET &&                defaultFlag == true)            {                indent4 = indent2 + "    ";                _source.println();                _source.print(indent2);                _source.println("if (loopbackFlag == false)");                _source.print(indent2);                _source.println("{");            }            else            {                indent4 = indent2;            }            _source.print(indent4);            _source.println(                "(context.getState()).Entry(context);");            if (transType == Smc.TRANS_SET &&                defaultFlag == true)            {                _source.print(indent2);                _source.println("}");            }        }        // If there is a transition associated with the pop, then        // issue that transition here.        if (transType == Smc.TRANS_POP &&            endStateName.equals(NIL_STATE) == false &&            endStateName.length() > 0)        {            String popArgs = guard.getPopArgs();            _source.print(indent2);            _source.print("context.");            _source.print(endStateName);            _source.print("(");            // Output any and all pop arguments.            if (popArgs.length() > 0)            {                _source.print(popArgs);            }            _source.println(");");        }        // If this is a guarded transition, it will be necessary        // to close off the "if" body. DON'T PRINT A NEW LINE!        // Why? Because an "else" or "else if" may follow and we        // won't know until we go back to the transition source        // generator whether all clauses have been done.        if (_guardCount > 1)        {            _source.print(_indent);            _source.print("    }");        }        return;    } // end of visit(SmcGuard)    public void visit(SmcAction action)    {        String name = action.getName();        Iterator<String> it;        String sep;        // Need to distinguish between FSMContext actions and        // application class actions. If the action is        // "emptyStateStack", then pass it to the context.        // Otherwise, let the application class handle it.        _source.print(_indent);        if (name.equals("emptyStateStack") == true)        {            _source.print("context.");        }        else        {            _source.print("ctxt.");        }        _source.print(name);        _source.print('(');        for (it = action.getArguments().iterator(), sep = "";             it.hasNext() == true;             sep = ", ")        {            _source.print(sep);            _source.print(it.next());        }        _source.println(");");        return;    } // end of visit(SmcAction)    public void visit(SmcParameter parameter)    {        _source.print(parameter.getType());        _source.print(" ");        _source.print(parameter.getName());        return;    } // end of visit(SmcParameter)//---------------------------------------------------------------// Member data//} // end of class SmcCppGenerator//// CHANGE LOG// $Log: SmcCppGenerator.java,v $// Revision 1.10  2008/03/21 14:03:16  fperrad// refactor : move from the main file Smc.java to each language generator the following data ://  - the default file name suffix,//  - the file name format for the generated SMC files//// Revision 1.9  2007/12/28 12:34:41  cwrapp// Version 5.0.1 check-in.//// Revision 1.8  2007/08/05 14:36:11  cwrapp// Version 5.0.1 check-in. See net/sf/smc/CODE_README.txt for more informaiton.//// Revision 1.7  2007/02/21 13:54:27  cwrapp// Moved Java code to release 1.5.0//// Revision 1.6  2007/01/15 00:23:50  cwrapp// Release 4.4.0 initial commit.//// Revision 1.5  2006/09/16 15:04:28  cwrapp// Initial v. 4.3.3 check-in.//// Revision 1.4  2006/07/11 18:12:16  cwrapp// Added support for new -headerd command line option.//// Revision 1.3  2006/04/22 12:45:26  cwrapp// Version 4.3.1//// Revision 1.2  2005/11/07 19:34:54  cwrapp// Changes in release 4.3.0:// New features://// + Added -reflect option for Java, C#, VB.Net and Tcl code//   generation. When used, allows applications to query a state//   about its supported transitions. Returns a list of//   transition names. This feature is useful to GUI developers//   who want to enable/disable features based on the current//   state. See Programmer's Manual section 11: On Reflection//   for more information.//// + Updated LICENSE.txt with a missing final paragraph which//   allows MPL 1.1 covered code to work with the GNU GPL.//// + Added a Maven plug-in and an ant task to a new tools//   directory.//   Added Eiten Suez's SMC tutorial (in PDF) to a new docs//   directory.//// Fixed the following bugs://// + (GraphViz) DOT file generation did not properly escape//   double quotes appearing in transition guards. This has been//   corrected.//// + A note: the SMC FAQ incorrectly stated that C/C++ generated//   code is thread safe. This is wrong. C/C++ generated is//   certainly *not* thread safe. Multi-threaded C/C++//   applications are required to synchronize access to the FSM//   to allow for correct performance.//// + (Java) The generated getState() method is now public.//// Revision 1.1  2005/05/28 19:28:42  cwrapp// Moved to visitor pattern.//// Revision 1.2  2005/02/21 15:34:59  charlesr// Added Francois Perrad to Contributors section for Python work.//// Revision 1.1  2005/02/21 15:13:03  charlesr// Modified isLoopback() to new signature due to moving method// from SmcGuard to SmcCodeGenerator.//// Revision 1.0  2005/02/03 17:10:26  charlesr// Initial revision//

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -