libutap  0.93
Uppaal Timed Automata Parser
taflow.cpp
Go to the documentation of this file.
1 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 
3 /* libutap - Uppaal Timed Automata Parser.
4  Copyright (C) 2002-2015 Uppsala University and Aalborg University.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public License
8  as published by the Free Software Foundation; either version 2.1 of
9  the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  USA
20 */
21 
22 #include "utap/signalflow.h"
23 #include "utap/systembuilder.h"
24 #include "utap/typechecker.h"
25 #include "utap/system.h"
26 
27 #include <unistd.h>
28 #include <iostream>
29 #include <fstream>
30 #include <string>
31 
35 using UTAP::TypeChecker;
38 using UTAP::SignalFlow;
39 using UTAP::Partitioner;
41 
42 using std::vector;
43 using std::cerr;
44 using std::cout;
45 using std::endl;
46 using std::ifstream;
47 using std::istream;
48 using std::string;
49 
50 void printHelp(const char* binary)
51 {
52  cout <<
53  "Utility for extracting I/O information from UPPAAL system spec.\n"
54  "Usage:\n " << binary << " [-bxrce -f format -i iofile] model.xml\n"
55  "Options:\n"
56  " -b use old (v. <=3.4) syntax for system specification;\n"
57  " -d calculate distances from needles rather than partition;\n"
58  " -f <dot|tron>\n"
59  " dot: for DOT (graphviz.org) format (default),\n"
60  " tron: for UPPAAL TRON format;\n"
61  " -i <filename>\n"
62  " for partitioning provide input and output channels:\n"
63  " \"input\" (chan)* \"output\" (chan)*\n"
64  " for calculating distances provide a list of needles, e.g.:\n"
65  " Process.Location1 Proc.localVariable globalVariable"
66  " -r [DOT] rank symbols instead of plain map of system;\n"
67  " -c [DOT] put channels on edges between processes;\n"
68  " -e [DOT] use entity relationship notation;\n"
69  " -v increment output verbosity level.\n";
70 }
71 
72 int main(int argc, char *argv[])
73 {
74  bool old=false, ranked=false, erd=false, chanEdge=false, distances=false;
75  int format = 2, verbosity=0;
76  char c;
77  const char* iofile = NULL;
78 
79  while ((c = getopt(argc,argv,"bcdef:hi:rxv")) != -1)
80  {
81  switch(c) {
82  case 'b':
83  old = true;
84  break;
85  case 'c':
86  chanEdge = true;
87  break;
88  case 'd':
89  distances = true;
90  break;
91  case 'e':
92  erd = true;
93  break;
94  case 'f':
95  if (strcmp(optarg, "dot")==0)
96  {
97  format = 0;
98  }
99  else if (strcmp(optarg, "tron")==0)
100  {
101  format = 1;
102  }
103  else
104  {
105  cerr << "-f expects either 'gui' or 'dot' argument.\n";
106  exit(EXIT_FAILURE);
107  }
108  break;
109  case 'h':
110  printHelp(argv[0]); exit(EXIT_FAILURE);
111  break;
112  case 'i':
113  iofile = optarg;
114  break;
115  case 'r':
116  ranked = true;
117  break;
118  case 'v':
119  ++verbosity;
120  break;
121  default:
122  cerr << "Unrecognized option: " << c << endl;
123  exit(EXIT_FAILURE);
124  }
125  }
126 
127  TimedAutomataSystem system;
128 
129  try
130  {
131  if (argc - optind != 1)
132  {
133  printHelp(argv[0]); exit(EXIT_FAILURE);
134  }
135  if (strcasecmp(".xml", argv[optind] + strlen(argv[optind]) - 4) == 0)
136  {
137  parseXMLFile(argv[optind], &system, !old);
138  }
139  else
140  {
141  parseXTA(argv[optind], &system, !old);
142  }
143  }
144  catch (TypeException& e)
145  {
146  cerr << e.what() << endl;
147  }
148 
149  TypeChecker tc(&system);
150  system.accept(tc);
151 
152  vector<UTAP::error_t>::const_iterator it;
153  const vector<UTAP::error_t> &errors = system.getErrors();
154  const vector<UTAP::error_t> &warns = system.getWarnings();
155 
156  for (it = errors.begin(); it != errors.end(); it++)
157  {
158  cerr << *it << endl;
159  }
160  for (it = warns.begin(); it != warns.end(); it++)
161  {
162  cerr << *it << endl;
163  }
164 
165  if (iofile!=NULL) {
166  SignalFlow *flow = NULL;
167  if (!distances) {
168  Partitioner *partitioner = new Partitioner(argv[optind], system);
169  partitioner->setVerbose(verbosity);
170  ifstream f(iofile);
171  if (partitioner->partition(f)>1)
172  cerr << "Partitioning is inconsistent" << endl;
173  f.close();
174  flow = partitioner;
175  } else {
176  DistanceCalculator *dcalc =
177  new DistanceCalculator(argv[optind], system);
178  ifstream f(iofile);
179  string needle;
180  while (f) {
181  f >> needle;
182  dcalc->addProcessNeedle(needle.c_str());
183  }
184  flow = dcalc;
185  }
186  switch (format)
187  {
188  case 0:
189  default:
190  flow->printForDot(std::cout, ranked, erd, chanEdge);
191  break;
192  case 1:
193  flow->printForTron(std::cout);
194  break;
195  }
196  delete flow;
197  exit(EXIT_SUCCESS);
198  }
199 
200  SignalFlow flow(argv[optind], system);
201  switch (format)
202  {
203  case 0:
204  default:
205  flow.printForDot(std::cout, ranked, erd, chanEdge);
206  break;
207  case 1:
208  flow.printForTron(std::cout);
209  break;
210  }
211  return 0;
212 }
Class SignalFlow is for analysing UPPAAL specifications and extracting the timed automata input/outpu...
Definition: signalflow.h:56
int main(int argc, char *argv[])
Definition: taflow.cpp:72
int32_t parseXMLFile(const char *file, TimedAutomataSystem *system, bool newxta)
DistanceCalculator is used in TargetFirst heuristic search order of Uppaal.
Definition: signalflow.h:266
virtual void printForDot(std::ostream &os, bool ranked, bool erd, bool cEdged)
Print I/O information in DOT format into given output stream.
Definition: signalflow.cpp:326
A visitor which type checks the system it visits.
Definition: typechecker.h:57
This class constructs a TimedAutomataSystem.
Definition: systembuilder.h:69
The ParserBuilder interface is used by the parser to output the parsed system.
Definition: builder.h:80
const std::vector< error_t > & getErrors() const
Definition: system.cpp:1420
Partitions the system into environment and IUT according to TRON assumptions.
Definition: signalflow.h:228
void addProcessNeedle(const char *proc)
adds a variable needle to I/O map
int partition(const strs_t &inputs, const strs_t &outputs)
const std::vector< error_t > & getWarnings() const
Definition: system.cpp:1426
Exception indicating a type error.
Definition: builder.h:39
void printForTron(std::ostream &os)
Print I/O information in TRON format into given output stream.
Definition: signalflow.cpp:66
void accept(SystemVisitor &)
Definition: system.cpp:1239
static int32_t parseXTA(ParserBuilder *aParserBuilder, bool newxta, xta_part_t part, std::string xpath)
Definition: parser.cc:8906
void printHelp(const char *binary)
Definition: taflow.cpp:50
void setVerbose(int verbose)
Definition: signalflow.h:129