コード例 #1
0
 /**
  * Extracts the morphism from rule nodes to input graph nodes corresponding to the transition's
  * input parameters.
  *
  * @return if {@code null}, the binding cannot be constructed and so the rule cannot match
  */
 private RuleToHostMap extractBinding(Step step) {
   RuleToHostMap result = this.state.getGraph().getFactory().createRuleToHostMap();
   Object[] sourceValues = this.state.getActualValues();
   for (Assignment assign : step.getEnterAssignments()) {
     sourceValues = assign.compute(sourceValues);
   }
   for (Pair<Var, Binding> entry : step.getRuleSwitch().getCallBinding()) {
     Binding bind = entry.two();
     HostNode value;
     if (bind == null) {
       // this corresponds to an output parameter of the call
       continue;
     }
     switch (bind.getSource()) {
       case CONST:
         value = bind.getValue().getNode();
         break;
       case VAR:
         value = Valuator.get(sourceValues, bind);
         break;
       default:
         assert false;
         value = null;
     }
     RuleNode ruleNode = entry.one().getRuleNode();
     if (isCompatible(ruleNode, value)) {
       result.putNode(ruleNode, value);
     } else {
       result = null;
       break;
     }
   }
   return result;
 }
コード例 #2
0
 /**
  * Exports a given state using a filename derived from a state pattern.
  *
  * @param state the state to be exported
  * @param pattern the filename pattern
  * @throws IOException if anything went wrong during export
  */
 public static File exportState(GraphState state, String pattern) throws IOException {
   String stateFilename = pattern.replace(PLACEHOLDER, "" + state.getNumber());
   File stateFile = new File(stateFilename);
   Pair<FileType, Exporter> stateFormat = Exporters.getAcceptingFormat(stateFilename);
   if (stateFormat != null) {
     try {
       stateFormat.two().doExport(new Exportable(state.getGraph()), stateFile, stateFormat.one());
     } catch (PortException e1) {
       throw new IOException(e1);
     }
   } else {
     if (!FileType.hasAnyExtension(stateFile)) {
       stateFile = FileType.STATE.addExtension(stateFile);
     }
     Groove.saveGraph(GraphConverter.toAspect(state.getGraph()), stateFile);
   }
   return stateFile;
 }