📄 smctclgenerator.java
字号:
} else { _source.println(); } _source.print(indent4); _source.println( "[$context getState] Entry $context;"); if (defaultFlag == true) { _source.print(indent3); _source.println("}"); } else { _source.println(); } } _source.print(indent3); _source.print("$context pushState ${"); _source.print(_pkgScope); _source.print(pushStateName); _source.println("};"); } else if (transType == Smc.TRANS_POP) { _source.print(indent3); _source.println("$context popState;"); } // Re-throw the caught Tcl error so the // application may now see it. _source.print(indent3); _source.println("error $result;"); // Close off the then body and start the else // body. _source.print(indent2); _source.println("} else {"); } } // Print the setState() call, if necessary. Do NOT // generate the set state if: // 1. The transition has no actions AND is a loopback OR // 2. This is a push or pop transition. // // v. 2.0.2: The following code must be generated twice - // once for the catch body and again in the if's then // body. if (transType == Smc.TRANS_SET && (actions.size() > 0 || loopbackFlag == false)) { _source.print(indent3); _source.print("$context setState "); _source.print(endStateName); _source.println(";"); } else if (transType == Smc.TRANS_PUSH) { // Set the next 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(endStateName); _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; _source.println(); if (defaultFlag == true) { indent4 = indent3 + " "; _source.print(indent3); _source.println( "if {$loopbackFlag == 0} {"); } _source.print(indent4); _source.println( "[$context getState] Entry $context;"); if (defaultFlag == true) { _source.print(indent3); _source.println("}"); } else { _source.println(); } } _source.print(indent3); _source.print("$context pushState ${"); _source.print(_pkgScope); _source.print(pushStateName); _source.println("};"); } else if (transType == Smc.TRANS_POP) { _source.print(indent3); _source.println("$context popState;"); } // Close off the else body if there is one. // v. 2.2.0: There won't be one if the user turned off // guards. if (actions.size() > 0 && Smc.isNoCatch() == false) { _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) { indent4 = indent2; // 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 == 0} {"); } _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.println(); _source.print(indent2); _source.print("$context "); _source.print(endStateName); // Output any and all pop arguments. if (popArgs.length() > 0) { _source.print(" "); _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 elseif 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(); _source.print(_indent); // 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. if (name.equals("emptyStateStack") == true) { _source.print("$context "); } else { _source.print("$ctxt "); } _source.print(name); for (String arg: action.getArguments()) { _source.print(" "); _source.print(arg); } _source.println(";"); return; } // end of visit(SmcAction) public void visit(SmcParameter parameter) { // v. 2.0.2: Tcl differentiates between // call-by-value and call-by-name. If this is // call-by-value, prepend the name with a "$". if (parameter.getType().equals("value") == true) { _source.print("$"); } // Types? Types?!!! We don't need no stinkin' types! // I'm Tcl dammit! _source.print(parameter.getName()); return; } // end of visit(SmcParameter) // Returns the _transition initializations for reflection. private void _reflectTransitions( SmcState state, List<SmcTransition> stateTransitions, List<SmcTransition> defaultTransitions, List<SmcTransition> allTransitions) { Iterator<SmcTransition> it; SmcTransition transition; String transName; int transDefinition; String sep; _source.print(_indent); _source.print("array set "); _source.print(state.getMap().getName()); _source.print("_"); _source.print(state.getClassName()); _source.print("::_transitions {"); for (it = allTransitions.iterator(), sep = ""; it.hasNext() == true; sep = " ") { transition = it.next(); transName = transition.getName(); // If the transition is in this state, then its // value is 1. if (stateTransitions.contains( transition) == true) { transDefinition = 1; } // If the transition is defined in this map's // default state, then the value is 2. else if (defaultTransitions.contains( transition) == true) { transDefinition = 2; } // Otherwise the value is 0 - undefined. else { transDefinition = 0; } _source.print(sep); _source.print("\""); _source.print(transName); _source.print("\" "); _source.print(transDefinition); } _source.println("};"); return; } // end of _reflectTransitions(...)//---------------------------------------------------------------// Member data// // Use this string to fully-qualify names. private String _pkgScope;} // end of class SmcTclGenerator//// CHANGE LOG// $Log: SmcTclGenerator.java,v $// Revision 1.7 2008/03/21 14:03:17 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.6 2007/08/05 14:36:12 cwrapp// Version 5.0.1 check-in. See net/sf/smc/CODE_README.txt for more informaiton.//// Revision 1.5 2007/02/21 13:56:54 cwrapp// Moved Java code to release 1.5.0//// Revision 1.4 2007/01/15 00:23:52 cwrapp// Release 4.4.0 initial commit.//// Revision 1.3 2006/09/16 15:04:29 cwrapp// Initial v. 4.3.3 check-in.//// 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:38:32 charlesr// Added Francois Perrad to Contributors section for Python work.//// Revision 1.1 2005/02/21 15:22:14 charlesr// Modified isLoopback method call to new signature due to moving// method from SmcGuard to SmcCodeGenerator.//// Revision 1.0 2005/02/03 17:12:44 charlesr// Initial revision//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -