libutap  0.93
Uppaal Timed Automata Parser
type.h
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-2006 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 #ifndef UTAP_TYPE_HH
23 #define UTAP_TYPE_HH
24 
25 #include "utap/common.h"
26 #include "utap/position.h"
27 
28 #include <cinttypes>
29 #include <string>
30 #include <memory> // shared_ptr
31 
32 namespace UTAP
33 {
34  class expression_t;
35  class frame_t;
36  class symbol_t;
37 
93  class type_t
94  {
95  private:
96  struct child_t;
97  struct type_data;
98  std::shared_ptr<type_data> data;
99 
100  explicit type_t(Constants::kind_t kind,
101  const position_t &pos, size_t size);
102  public:
106  type_t(){};
107 
109  type_t(const type_t &);
110 
112  ~type_t(){};
113 
115  const type_t &operator = (const type_t &);
116 
118  bool operator == (const type_t &) const;
119 
121  bool operator != (const type_t &) const;
122 
124  Constants::kind_t getKind() const;
125 
130  position_t getPosition() const;
131 
135  size_t size() const;
136 
138  bool operator < (const type_t &) const;
139 
141  const type_t operator[](uint32_t) const;
142 
144  const type_t get(uint32_t) const;
145 
147  const std::string &getLabel(uint32_t) const;
148 
150  expression_t getExpression() const;
151 
156  type_t getArraySize() const;
157 
162  type_t getSub() const;
163 
168  type_t getSub(size_t) const;
169 
173  size_t getRecordSize() const;
174 
179  std::string getRecordLabel(size_t i) const;
180 
186  int32_t findIndexOf(const std::string&) const;
187 
191  std::pair<expression_t, expression_t> getRange() const;
192 
194  std::string toString() const;
195 
196  std::string toDeclarationString() const;
197 
199  bool isRange() const { return is(Constants::RANGE); }
200 
202  bool isInteger() const { return is(Constants::INT); }
203 
205  bool isBoolean() const { return is(Constants::BOOL); }
206 
208  bool isFunction() const { return is(Constants::FUNCTION); }
209 
211  bool isProcess() const { return is(Constants::PROCESS); }
212 
214  bool isProcessSet() const { return is(Constants::PROCESSSET); }
215 
217  bool isLocation() const { return is(Constants::LOCATION); }
218 
220  bool isInstanceLine() const { return is(Constants::INSTANCELINE); }
221 
223  bool isBranchpoint() const { return is(Constants::BRANCHPOINT); }
224 
226  bool isChannel() const { return is(Constants::CHANNEL); }
227 
229  bool isArray() const { return is(Constants::ARRAY); }
230 
232  bool isScalar() const { return is(Constants::SCALAR); }
233 
235  bool isClock() const { return is(Constants::CLOCK); }
236 
238  bool isRecord() const { return is(Constants::RECORD); }
239 
241  bool isDiff() const { return is(Constants::DIFF); }
242 
244  bool isVoid() const { return is(Constants::VOID_TYPE); }
245 
247  bool isCost() const { return is(Constants::COST); }
248 
250  bool isDouble() const { return is(Constants::DOUBLE); }
251 
256  bool isIntegral() const;
257 
262  bool isInvariant() const;
263 
268  bool isGuard() const;
269 
270 #ifdef ENABLE_PROB
271 
275  bool isProbability() const;
276 #endif
277 
283  bool isConstraint() const;
284 
290  bool isFormula() const;
291 
296  type_t strip() const;
297 
302  type_t stripArray() const;
303 
309  bool isPrefix() const;
310 
315  bool isConstant() const;
316 
321  bool isNonConstant() const;
322 
328  bool is(Constants::kind_t kind) const;
329 
333  bool unknown() const;
334 
340  type_t rename(const std::string& from, const std::string& to) const;
341 
347  type_t subst(symbol_t symbol, expression_t expr) const;
354 
356  type_t createLabel(const std::string&, position_t = position_t()) const;
357 
360 
364  position_t = position_t());
365 
368  position_t = position_t());
369 
371  static type_t createArray(type_t sub, type_t size, position_t = position_t());
372 
374  static type_t createTypeDef(const std::string&, type_t,
375  position_t = position_t());
376 
379 
381  static type_t createProcessSet(type_t instance, position_t = position_t());
382 
384  static type_t createRecord(const std::vector<type_t> &,
385  const std::vector<std::string> &,
386  position_t = position_t());
387 
390  const std::vector<type_t> &,
391  const std::vector<std::string> &,
392  position_t = position_t());
393 
398  };
399 }
400 
401 std::ostream &operator << (std::ostream &o, UTAP::type_t t);
402 
403 #endif
bool isPrefix() const
Returns false for non-prefix types and true otherwise.
Definition: type.cpp:125
bool isRange() const
Shortcut for is(RANGE).
Definition: type.h:199
bool isClock() const
Shortcut for is(CLOCK).
Definition: type.h:235
bool isProcessSet() const
Shortcut for is(PROCESSSET).
Definition: type.h:214
const type_t & operator=(const type_t &)
Assignment operator.
Definition: type.cpp:60
~type_t()
Destructor.
Definition: type.h:112
bool unknown() const
Returns true if this is null-type or of kind UNKNOWN.
Definition: type.cpp:171
bool isVoid() const
Shortcut for is(VOID_TYPE).
Definition: type.h:244
bool isIntegral() const
Returns true if this is a boolean or integer.
Definition: type.cpp:343
bool isInvariant() const
Returns true if this is an invariant, boolean or integer.
Definition: type.cpp:348
bool isInteger() const
Shortcut for is(INT).
Definition: type.h:202
bool operator==(const type_t &) const
Equality operator.
Definition: type.cpp:66
static type_t createRange(type_t, expression_t, expression_t, position_t=position_t())
Definition: type.cpp:425
A reference to a symbol.
Definition: symbols.h:107
static type_t createInstance(frame_t, position_t=position_t())
Creates a new instance type.
Definition: type.cpp:483
type_t createPrefix(Constants::kind_t kind, position_t=position_t()) const
Creates a new type by adding a prefix to it.
Definition: type.cpp:532
std::string toDeclarationString() const
Definition: type.cpp:734
static type_t createPrimitive(Constants::kind_t, position_t=position_t())
Create a primitive type.
Definition: type.cpp:527
static type_t createLscInstance(frame_t, position_t=position_t())
Creates a new lsc instance type.
Definition: type.cpp:494
bool isArray() const
Shortcut for is(ARRAY).
Definition: type.h:229
std::string toString() const
Generates string representation of the type.
Definition: type.cpp:547
std::pair< expression_t, expression_t > getRange() const
Returns the range of a RANGE type.
Definition: type.cpp:266
type_t rename(const std::string &from, const std::string &to) const
Replaces any LABEL labeled from occuring in the type with a LABEL to.
Definition: type.cpp:307
position_t getPosition() const
Returns the position of the type in the input file.
Definition: type.cpp:338
const std::string & getLabel(uint32_t) const
Returns the i&#39;th label.
Definition: type.cpp:99
std::ostream & operator<<(std::ostream &os, const SignalFlow::strs_t &s)
Definition: signalflow.h:189
bool operator<(const type_t &) const
Less-than operator.
Definition: type.cpp:76
bool isFormula() const
Returns true if this is a formula, constraint, guard, invariant, boolean or integer.
Definition: type.cpp:370
type_t strip() const
Removes any leading prefixes, RANGE, REF and LABEL types and returns the result.
Definition: type.cpp:285
static type_t createFunction(type_t, const std::vector< type_t > &, const std::vector< std::string > &, position_t=position_t())
Creates a new function type.
Definition: type.cpp:451
bool isConstant() const
Returns true if and only if all elements of the type are constant.
Definition: type.cpp:375
bool isConstraint() const
Returns true if this is a constraint, guard, invariant, boolean or integer.
Definition: type.cpp:365
bool isCost() const
Shortcut for is(COST).
Definition: type.h:247
type_t stripArray() const
Removes any leading prefixes, RANGE, REF, LABEL and ARRAY types and returns the result.
Definition: type.cpp:297
type_t getSub() const
Returns the element type of an array.
Definition: type.cpp:193
static string symbol(const char *str)
Extracts the alpha-numerical symbol used for variable/type identifiers.
Definition: xmlreader.cpp:107
bool isBranchpoint() const
Shortcut for is(BRANCHPOINT).
Definition: type.h:223
bool isFunction() const
Shortcut for is(FUNCTION).
Definition: type.h:208
bool isDiff() const
Shortcut for is(DIFF).
Definition: type.h:241
expression_t getExpression() const
Returns the expression associated with the type.
Definition: type.cpp:279
bool isNonConstant() const
Returns true if and only if all elements of the type are not constant.
Definition: type.cpp:400
type_t subst(symbol_t symbol, expression_t expr) const
Substitutes any occurence of symbol in any expression in the type (expressions that occur as ranges e...
Definition: type.cpp:323
static type_t createTypeDef(const std::string &, type_t, position_t=position_t())
Creates a new type definition.
Definition: type.cpp:475
static type_t createProcessSet(type_t instance, position_t=position_t())
Creates a new processset type.
Definition: type.cpp:516
const type_t operator[](uint32_t) const
Returns the i&#39;th child.
Definition: type.cpp:87
A reference to a frame.
Definition: symbols.h:183
A reference to a type.
Definition: type.h:93
bool isGuard() const
Returns true if this is a guard, invariant, boolean or integer.
Definition: type.cpp:353
bool isBoolean() const
Shortcut for is(BOOL).
Definition: type.h:205
type_t()
Default constructor.
Definition: type.h:106
size_t size() const
Returns the number of children.
Definition: type.cpp:81
int32_t findIndexOf(const std::string &) const
Returns the index of the record or process field with the given label.
Definition: type.cpp:105
std::string getRecordLabel(size_t i) const
Returns the label of the &#39;th field of a record.
Definition: type.cpp:253
type_t createLabel(const std::string &, position_t=position_t()) const
Creates a LABEL.
Definition: type.cpp:539
static type_t createRecord(const std::vector< type_t > &, const std::vector< std::string > &, position_t=position_t())
Creates a new record type.
Definition: type.cpp:437
bool operator!=(const type_t &) const
Inequality operator.
Definition: type.cpp:71
A reference to an expression.
Definition: expression.h:70
type_t getArraySize() const
Returns the size of an array (this is itself a type).
Definition: type.cpp:227
type_t createPosition(position_t=position_t()) const
bool is(Constants::kind_t kind) const
Returns true if the type has kind kind or if type is a prefix, RANGE or REF type and the getChild()...
Definition: type.cpp:176
bool isLocation() const
Shortcut for is(LOCATION).
Definition: type.h:217
Definition: lexer.cc:817
bool isScalar() const
Shortcut for is(SCALAR).
Definition: type.h:232
static type_t createArray(type_t sub, type_t size, position_t=position_t())
Creates an array type.
Definition: type.cpp:467
bool isDouble() const
Shortcut for is(DOUBLE).
Definition: type.h:250
bool isInstanceLine() const
Shortcut for is(INSTANCELINE).
Definition: type.h:220
static type_t createProcess(frame_t, position_t=position_t())
Creates a new process type.
Definition: type.cpp:505
bool isRecord() const
Shortcut for is(RECORD).
Definition: type.h:238
Constants::kind_t getKind() const
Returns the kind of type object.
Definition: type.cpp:120
bool isChannel() const
Shortcut for is(CHANNEL).
Definition: type.h:226
bool isProcess() const
Shortcut for is(PROCESS).
Definition: type.h:211
size_t getRecordSize() const
Returns the number of fields of a record.
Definition: type.cpp:240