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

📄 smctclgenerator.java

📁 SMC takes a state machine stored in a .sm file and generates a State pattern in twelve programming l
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            {                defaultState = map.getDefaultState();                defaultTransitions =                    defaultState.getTransitions();                stateTransitions =                    new ArrayList<SmcTransition>();                // Generate the default state's transitions                // first.                _reflectTransitions(defaultState,                                    stateTransitions,                                    defaultTransitions,                                    transitions);                for (SmcState state: map.getStates())                {                    stateTransitions = state.getTransitions();                    _reflectTransitions(state,                                        stateTransitions,                                        defaultTransitions,                                        transitions);                    ++index;                }            }        }        // v. 2.2.0: If we are supporting serialization, then        // declare the min and max indices.        if (Smc.isSerial() == true)        {            // Output the state deserialization static data.            _source.print(_indent);            _source.print("set ");            _source.print(context);            _source.println("Context::MIN_ID 0;");            _source.print(_indent);            _source.print("set ");            _source.print(context);            _source.print("Context::MAX_ID ");            _source.print(index - 1);            _source.println(";");            _source.print(_indent);            _source.print("array set ");            _source.print(context);            _source.print("Context::_States [list");            for (SmcMap map: maps)            {                mapName = map.getName();                for (SmcState state: map.getStates())                {                    _source.print(" ");                    _source.print(index);                    _source.print(" ${");                    _source.print(mapName);                    _source.print("::");                    _source.print(state.getInstanceName());                    _source.print("}");                    ++index;                }            }            _source.println("];");        }        // If necessary, place an end brace for the namespace.        if (packageName != null && packageName.length() > 0)        {            _source.println("}");        }        return;    } // end of visit(SmcFSM)    public void visit(SmcMap map)    {        List<SmcTransition> definedDefaultTransitions;        SmcState defaultState = map.getDefaultState();        String context = map.getFSM().getContext();        String mapName = map.getName();        List<SmcState> states = map.getStates();        if (defaultState != null)        {            definedDefaultTransitions =                    defaultState.getTransitions();        }        else        {            definedDefaultTransitions =                new ArrayList<SmcTransition>();        }        // Declare the map class.        _source.print(_indent);        _source.print("class ");        _source.print(mapName);        _source.println(" {");        _source.print(_indent);        _source.println("# Member data.");        _source.println();        // Print all the static state objects.        for (SmcState state: states)        {            _source.print(_indent);            _source.print("    public common ");            _source.print(state.getClassName());            _source.println(" \"\";");        }        // End of map class.        _source.print(_indent);        _source.println("}");        _source.println();        // Declare the map's default state class.        _source.print(_indent);        _source.print("class ");        _source.print(mapName);        _source.println("_Default {");        _source.print(_indent);        _source.print("    inherit ");        _source.print(context);        _source.println("State;");        _source.println();        _source.print(_indent);        _source.println("# Member functions.");        _source.println();        _source.print(_indent);        _source.println("    constructor {name id} {");        _source.print(_indent);        _source.print("       ");        _source.print(context);        _source.println("State::constructor $name $id;");        _source.print(_indent);        _source.println("    } {}");        // If -reflection was specified, then generate the        // getTransitions method.        if (Smc.isReflection() == true)        {            _source.println();            _source.print(_indent);            _source.println(                "    public method getTransitions {} {");            _source.print(_indent);            _source.print("        ");            _source.println(                "return -code ok [array get _transitions];");            _source.println("    }");        }        // Dump out the user-defined default transitions.        if (defaultState != null)        {            for (SmcTransition transition:                     definedDefaultTransitions)            {                transition.accept(this);            }        }        // If -reflect specified, then generate the transitions        // class data.        if (Smc.isReflection() == true)        {            _source.println();            _source.print(_indent);            _source.println("# Member data.");            _source.println();            _source.print(_indent);            _source.println("    public common _transitions;");        }        // End the map's default state class declaration.        _source.print(_indent);        _source.println("}");        _source.println();        // Have each state now generate itself.        for (SmcState state: states)        {            state.accept(this);        }        // v. 1.4.0: This functionality moved to        // SmcFSM.java.        // Now create each of the static states.//          for (stateIt = _states.iterator();//               stateIt.hasNext() == true;//              )//          {//              state = (SmcState) stateIt.next();//              source.println(indent +//                             "set " +//                             _name +//                             "::" +//                             state.getClassName() +//                             " " +//                             pkg +//                             "[" +//                             _name +//                             "_" +//                             state.getClassName() +//                             " #auto \"" +//                             _name +//                             "::" +//                             state.getClassName() +//                             "\"];");//          }        _source.println();        return;    } // end of visit(SmcMap)    public void visit(SmcState state)    {        String mapName = state.getMap().getName();        String stateName = state.getClassName();        List<SmcAction> actions;        _source.print(_indent);        _source.print("class ");        _source.print(mapName);        _source.print("_");        _source.print(stateName);        _source.println(" {");        _source.print(_indent);        _source.print("    inherit ");        _source.print(mapName);        _source.println("_Default;");        _source.println();        _source.print(_indent);        _source.println("    constructor {name id} {");        _source.print(_indent);        _source.print("        ");        _source.print(mapName);        _source.println("_Default::constructor $name $id;");        _source.print(_indent);        _source.println("    } {}");        // If -reflection was specified, then generate the        // getTransitions method.        if (Smc.isReflection() == true)        {            _source.println();            _source.print(_indent);            _source.println(                "    public method getTransitions {} {");            _source.print(_indent);            _source.print("        ");            _source.println(                "return -code ok [array get _transitions];");            _source.println("    }");        }        // Add the Entry() and Exit() member functions if this        // state defines them.        actions = state.getEntryActions();        if (actions != null && actions.size() > 0)        {            _source.println();            _source.print(_indent);            _source.println(                "    public method Entry {context} {");            // Declare the ctxt local variable.            _source.println(                "        set ctxt [$context getOwner];");            _source.println();            // Generate the actions associated with this code.            for (SmcAction action: actions)            {                action.accept(this);            }            //` End the Entry() method with a return.            _source.println();            _source.print(_indent);            _source.println("        return -code ok;");            _source.print(_indent);            _source.println("    }");        }        actions = state.getExitActions();        if (actions != null && actions.size() > 0)        {            _source.println();            _source.print(_indent);            _source.println(                "    public method Exit {context} {");            // Declare the ctxt local variable.            _source.println(                "        set ctxt [$context getOwner];");            _source.println();            // Generate the actions associated with this code.            for (SmcAction action: actions)            {                action.accept(this);            }            // End the Exit() method with a return.            _source.print(_indent);            _source.println("        return -code ok;");            _source.print(_indent);            _source.println("    }");        }        // Have the transitions generate their code.        for (SmcTransition transition: state.getTransitions())        {            transition.accept(this);        }        // If -reflect specified, then generate the transitions        // class data.        if (Smc.isReflection() == true)        {            _source.println();            _source.print(_indent);            _source.println("# Member data.");            _source.println();            _source.print(_indent);            _source.println("    public common _transitions;");        }        // End of the state class declaration.        _source.print(_indent);        _source.println("}");        _source.println();        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();        List<SmcParameter> parameters =            transition.getParameters();        List<SmcGuard> guards = transition.getGuards();        boolean nullCondition = false;        Iterator<SmcParameter> pit;        Iterator<SmcGuard> git;        SmcGuard guard;        _source.println();        _source.print(_indent);        _source.print("    public method ");        _source.print(transName);        _source.print(" {context");        // Add user-defined parameters.        for (SmcParameter param: parameters)        {            _source.print(" ");            param.accept(this);        }        _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.println(                "        set ctxt [$context getOwner];");        }        // If this is a default transition, create the loopback        // flag.

⌨️ 快捷键说明

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