示例#1
0
文件: Flow.C 项目: 8l/rose
Flow Flow::operator+(Flow& s2) {
  Flow result;
  result=*this;
  for(Flow::iterator i2=s2.begin();i2!=s2.end();++i2)
    result.insert(*i2);
  return result;
}
示例#2
0
list<pair<Edge, ParProEState> > ParProAnalyzer::parProTransferFunction(const ParProEState* source) {
  list<pair<Edge, ParProEState> > result;
  ParProLabel sourceLabel = source->getLabel();
  // compute successor EStates based on the out edges of every CFG (one per parallel component)
  //  for (ParProLabel::iterator i=sourceLabel.begin(); i!=sourceLabel.end(); i++) {
  ROSE_ASSERT(_cfas.size() == sourceLabel.size());
  for (unsigned int i=0; i<_cfas.size(); i++) {
    if (_cfas[i]->contains(sourceLabel[i])) { // the artifical termination label will not be in the cfa, but has no outEdges anyways
      Flow outEdges = _cfas[i]->outEdges(sourceLabel[i]);
      for(Flow::iterator k=outEdges.begin(); k!=outEdges.end(); ++k) { 
	Edge e=*k;
	// TODO: combine "feasibleAccordingToGlobalState(...)" and "transfer(...)" to avoid 2nd lookup and iteration
	if (isPreciseTransition(e, source)) {
	  if (feasibleAccordingToGlobalState(e, source)) {
	    ParProEState target = transfer(source, e);
	    result.push_back(pair<Edge, ParProEState>(e, target));
	  }
	} else {
	  // we do not know whether or not the transition can be triggered
	  if (_approximation==COMPONENTS_OVER_APPROX) {
	    // we over-approximate the global system's behavior, therefore we generate the path where the tranistion is triggered...
	    ParProEState target = transfer(source, e);
	    result.push_back(pair<Edge, ParProEState>(e, target));
	    // ...but also include the case where the execution stops (none of these two cases is guaranteed to be part of the actual global behavior).
	    Edge terminationEdge = Edge(source->getLabel()[i], _artificalTerminationLabels[i]);
	    terminationEdge.setAnnotation("terminate (due to approximation)");
	    result.push_back(pair<Edge, ParProEState>(terminationEdge, setComponentToTerminationState(i, source)));
	  } else if (_approximation==COMPONENTS_UNDER_APPROX) {
	    // under-approximation here means to simply not include transitions that may or may not be feasible
	  } else {
	    cerr << "ERROR: some parallel CFGs are ignored and a synchronization tries to communicate with one of them, however no abstraction is selected." << endl;
	    ROSE_ASSERT(0);
	  }
	}
      }
    } // for each outgoing CFG edge of a particular parallel component's current label
  } // for each parallel component of the analyzed system
  return result;
}
string PromelaCodeGenerator::generateCode(Flow& automaton, int id, EdgeAnnotationMap edgeAnnotationMap, 
					  bool useTransitionIds, boost::unordered_map<string, int>& transitionIdMap) {
  stringstream ss;
  ss << "/* Process "<<id<<" */" << endl;
  ss << "active proctype Proc"<<id<<"()" << endl;
  ss << "{" << endl;
  ss << "  int state = "<<automaton.getStartLabel().getId()<<";" << endl;
  ss << "  do" << endl;

  set<Label> visited; //TODO: maybe change to hashset
  list<Label> worklist;
  worklist.push_back(automaton.getStartLabel());
  visited.insert(automaton.getStartLabel());
  while (!worklist.empty()) {
    Label label = worklist.front();
    worklist.pop_front();
    ss << "  :: state == "<<label.getId()<<" ->" << endl;
    ss << "    atomic {" << endl;
    ss << "      if" << endl;
    Flow outEdges = automaton.outEdges(label);
    for (Flow::iterator i=outEdges.begin(); i!= outEdges.end(); ++i) {
      ss << "      :: "<<communicationDetails((*i).getAnnotation(), id, edgeAnnotationMap, useTransitionIds, transitionIdMap) << endl;
      ss << "        state = "<<(*i).target().getId()<<";" << endl;
      if (visited.find((*i).target()) == visited.end()) {
	worklist.push_back((*i).target());
        visited.insert((*i).target());
      }
    }
    ss << "      fi" << endl;
    ss << "    }" << endl;
  }

  ss << "  od" << endl;
  ss << "}" << endl;
  return ss.str();
}