📄 smccppgenerator.java
字号:
_source.print("State::Default("); _source.print(context); _source.println("Context& context)"); _source.print(_indent); _source.println("{"); // Print the transition out to the verbose log. if (Smc.isDebug() == true) { _source.print(_indent); _source.println( " if (context.getDebugFlag() == true)"); _source.print(_indent); _source.println(" {"); // Are we using C++ iostreams or the app's TRACE // macro? if (Smc.isNoStreams() == true) { // The TRACE macro. _source.print(_indent); _source.print(" TRACE("); _source.println( "\"TRANSITION : Default\\n\\r\");"); } else { _source.print(_indent); _source.print(" std::ostream& str = "); _source.println("context.getDebugStream();"); _source.println(); _source.print(_indent); _source.println( " str << \"TRANSITION : Default\""); _source.print(_indent); _source.println(" << std::endl;"); } _source.print(_indent); _source.println(" }"); _source.println(); } // A transition has been issued which has no // definition in the current state and there // is no default to cover for it. Throw an // exception. // v. 1.3.1: But only if -noex was not specified. if (Smc.isNoExceptions() == false) { _source.print(_indent); _source.println(" throw ("); _source.print(_indent); _source.println( " TransitionUndefinedException("); _source.print(_indent); _source.println( " context.getState().getName(),"); _source.print(_indent); _source.println( " context.getTransition()));"); _source.println(); } else { // Otherwise, generate an assert. _source.print(_indent); _source.println(" assert(1==0);"); _source.println(); } _source.print(_indent); _source.println(" return;"); _source.print(_indent); _source.println("}"); // Have each map print out its source code now. for (mapIt = fsm.getMaps().iterator(); mapIt.hasNext() == true; ) { (mapIt.next()).accept(this); } // If a namespace was specified, then put the // ending braces on the namespace now. if (packageName != null && packageName.length() > 0) { int i; int j; for (i = (packageDepth - 1); i >= 0; --i) { // Output the proper indent. for (j = 0; j < i; ++j) { _source.print(" "); } _source.println("}"); } } return; } // end of visit(SmcFSM) public void visit(SmcMap map) { // Declare the user-defined default transitions first. if (map.hasDefaultState() == true) { SmcState defaultState = map.getDefaultState(); for (SmcTransition trans: defaultState.getTransitions()) { trans.accept(this); } } // Have each state now generate its code. for (SmcState state: map.getStates()) { state.accept(this); } return; } // end of visit(SmcMap) public void visit(SmcState state) { SmcMap map = state.getMap(); String context = map.getFSM().getContext(); String mapName = map.getName(); String className = state.getClassName(); String indent2; List<SmcAction> actions; // Add the Entry() and Exit() methods if this state // defines them. actions = state.getEntryActions(); if (actions != null && actions.isEmpty() == false) { _source.println(); _source.print(_indent); _source.print("void "); _source.print(mapName); _source.print("_"); _source.print(className); _source.print("::Entry("); _source.print(context); _source.println("Context& context)"); _source.println(); _source.println("{"); // Declare the "ctxt" local variable. _source.print(_indent); _source.print(" "); _source.print(context); _source.println("& ctxt(context.getOwner());"); _source.println(); // Generate the actions associated with this code. indent2 = _indent; _indent = _indent + " "; for (SmcAction action: actions) { action.accept(this); } _indent = indent2; // End the Entry() method with a return. _source.print(_indent); _source.println(" return;"); _source.print(_indent); _source.println("}"); } actions = state.getExitActions(); if (actions != null && actions.isEmpty() == false) { _source.println(); _source.print(_indent); _source.print("void "); _source.print(mapName); _source.print("_"); _source.print(className); _source.print("::Exit("); _source.print(context); _source.println("Context& context)"); _source.println(); _source.println("{"); // Declare the "ctxt" local variable. _source.print(_indent); _source.print(" "); _source.print(context); _source.println("& ctxt(context.getOwner());"); _source.println(); // Generate the actions associated with this code. indent2 = _indent; _indent = _indent + " "; for (SmcAction action: actions) { action.accept(this); } _indent = indent2; // End the Entry() method with a return. _source.print(_indent); _source.println(" return;"); _source.print(_indent); _source.println("}"); } // Have the transitions generate their code. for (SmcTransition trans: state.getTransitions()) { trans.accept(this); } return; } // end of visit(SmcState) public void visit(SmcTransition transition) { SmcState state = transition.getState(); SmcMap map = state.getMap(); String context = map.getFSM().getContext(); String mapName = map.getName(); String stateName = state.getClassName(); String transName = transition.getName(); boolean defaultFlag = false; boolean nullCondition = false; List<SmcGuard> guards = transition.getGuards(); Iterator<SmcGuard> git; SmcGuard guard; Iterator<SmcParameter> pit; String fqStateName; // Set a flag to denote if this is a Default state // transition. if (stateName.equals("Default") == true) { defaultFlag = true; } // Qualify the state name as well. if (stateName.indexOf("::") < 0) { fqStateName = mapName + "::" + stateName; } else { fqStateName = stateName; } _source.println(); _source.print(_indent); _source.print("void "); _source.print(mapName); _source.print("_"); _source.print(stateName); _source.print("::"); _source.print(transName); _source.print("("); _source.print(context); _source.print("Context& context"); // Add user-defined parameters. for (SmcParameter param: transition.getParameters()) { _source.print(", "); param.accept(this); } _source.println(")"); _source.print(_indent); _source.println("{"); // All transitions have a "ctxt" local variable. // 8/14/2003: // Do this only if there are any transition actions or // guard conditions which reference it. if (transition.hasCtxtReference() == true) { _source.print(_indent); _source.print(" "); _source.print(context); _source.println("& ctxt(context.getOwner());"); } // The loopbackFlag local variable is needed if there // is one guard with a non-nil end state. Conversely, // if all the transition guards use a nil end state, // then we don't use the loopbackFlag local variable. if (defaultFlag == true && allNilEndStates(guards) == false) { _source.print(_indent); _source.println(" bool loopbackFlag = false;"); _source.println(); } else { _source.println(); } // Print the transition to the verbose log. if (Smc.isDebug() == true) { String sep; _source.print(_indent); _source.println( " if (context.getDebugFlag() == true)"); _source.print(_indent); _source.println(" {"); if (Smc.isNoStreams() == true) { _source.print(_indent); _source.print(" TRACE(\"TRANSITION : "); _source.print(mapName); _source.print(" "); _source.print(transName); _source.print("("); for (pit = transition.getParameters().iterator(), sep = ""; pit.hasNext() == true; sep = ", ") { _source.print(sep); (pit.next()).accept(this); } _source.println(")\\n\\r\");"); } else { _source.print(_indent); _source.print(" std::ostream& str = "); _source.println("context.getDebugStream();"); _source.println(); _source.print(_indent); _source.print( " str << \"TRANSITION : "); _source.print(mapName); _source.print(" "); _source.print(transName); _source.print("(");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -