libutap
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 <inttypes.h>
26 #include <string>
27 
28 #include "utap/common.h"
29 #include "utap/position.h"
30 
31 namespace UTAP
32 {
33  class expression_t;
34  class frame_t;
35  class symbol_t;
36 
92  class type_t
93  {
94  private:
95  struct child_t;
96  struct type_data;
97  type_data *data;
98 
99  explicit type_t(Constants::kind_t kind,
100  const position_t &pos, size_t size);
101  public:
105  type_t();
106 
108  type_t(const type_t &);
109 
111  ~type_t();
112 
114  const type_t &operator = (const type_t &);
115 
117  bool operator == (const type_t &) const;
118 
120  bool operator != (const type_t &) const;
121 
123  Constants::kind_t getKind() const;
124 
129  position_t getPosition() const;
130 
134  size_t size() const;
135 
137  bool operator < (const type_t &) const;
138 
140  const type_t operator[](uint32_t) const;
141 
143  const type_t get(uint32_t) const;
144 
146  const std::string &getLabel(uint32_t) const;
147 
149  expression_t getExpression() const;
150 
155  type_t getArraySize() const;
156 
161  type_t getSub() const;
162 
167  type_t getSub(size_t) const;
168 
172  size_t getRecordSize() const;
173 
178  std::string getRecordLabel(size_t i) const;
179 
185  int32_t findIndexOf(std::string) const;
186 
190  std::pair<expression_t, expression_t> getRange() const;
191 
193  std::string toString() const;
194 
195  std::string toDeclarationString() const;
196 
198  bool isRange() const { return is(Constants::RANGE); }
199 
201  bool isInteger() const { return is(Constants::INT); }
202 
204  bool isBoolean() const { return is(Constants::BOOL); }
205 
207  bool isFunction() const { return is(Constants::FUNCTION); }
208 
210  bool isProcess() const { return is(Constants::PROCESS); }
211 
213  bool isProcessSet() const { return is(Constants::PROCESSSET); }
214 
216  bool isLocation() const { return is(Constants::LOCATION); }
217 
219  bool isInstanceLine() const { return is(Constants::INSTANCELINE); }
220 
222  bool isBranchpoint() const { return is(Constants::BRANCHPOINT); }
223 
225  bool isChannel() const { return is(Constants::CHANNEL); }
226 
228  bool isArray() const { return is(Constants::ARRAY); }
229 
231  bool isScalar() const { return is(Constants::SCALAR); }
232 
234  bool isClock() const { return is(Constants::CLOCK); }
235 
237  bool isRecord() const { return is(Constants::RECORD); }
238 
240  bool isDiff() const { return is(Constants::DIFF); }
241 
243  bool isVoid() const { return is(Constants::VOID_TYPE); }
244 
246  bool isCost() const { return is(Constants::COST); }
247 
249  bool isDouble() const { return is(Constants::DOUBLE); }
250 
255  bool isIntegral() const;
256 
261  bool isInvariant() const;
262 
267  bool isGuard() const;
268 
269 #ifdef ENABLE_PROB
270 
274  bool isProbability() const;
275 #endif
276 
282  bool isConstraint() const;
283 
289  bool isFormula() const;
290 
295  type_t strip() const;
296 
301  type_t stripArray() const;
302 
308  bool isPrefix() const;
309 
314  bool isConstant() const;
315 
320  bool isNonConstant() const;
321 
327  bool is(Constants::kind_t kind) const;
328 
332  bool unknown() const;
333 
339  type_t rename(std::string from, std::string to) const;
340 
346  type_t subst(symbol_t symbol, expression_t expr) const;
353 
355  type_t createLabel(std::string, position_t = position_t()) const;
356 
359 
363  position_t = position_t());
364 
367  position_t = position_t());
368 
370  static type_t createArray(type_t sub, type_t size, position_t = position_t());
371 
373  static type_t createTypeDef(std::string, type_t, position_t = position_t());
374 
377 
379  static type_t createProcessSet(type_t instance, position_t = position_t());
380 
382  static type_t createRecord(const std::vector<type_t> &,
383  const std::vector<std::string> &,
384  position_t = position_t());
385 
387  static type_t createFunction(type_t,
388  const std::vector<type_t> &,
389  const std::vector<std::string> &,
390  position_t = position_t());
391 
396  };
397 }
398 
399 std::ostream &operator << (std::ostream &o, UTAP::type_t t);
400 
401 #endif
Definition: common.h:198
size_t size() const
Returns the number of children.
Definition: type.cpp:119
const type_t & operator=(const type_t &)
Assignment operator.
Definition: type.cpp:85
bool isDiff() const
Shortcut for is(DIFF).
Definition: type.h:240
Definition: common.h:230
A reference to a symbol.
Definition: symbols.h:107
bool isDouble() const
Shortcut for is(DOUBLE).
Definition: type.h:249
bool isScalar() const
Shortcut for is(SCALAR).
Definition: type.h:231
bool isRange() const
Shortcut for is(RANGE).
Definition: type.h:198
static type_t createLscInstance(frame_t, position_t=position_t())
Creates a new lsc instance type.
Definition: type.cpp:532
bool isInteger() const
Shortcut for is(INT).
Definition: type.h:201
std::pair< expression_t, expression_t > getRange() const
Returns the range of a RANGE type.
Definition: type.cpp:304
Definition: common.h:196
bool operator!=(const type_t &) const
Inequality operator.
Definition: type.cpp:109
Definition: common.h:226
expression_t getExpression() const
Returns the expression associated with the type.
Definition: type.cpp:317
type_t getArraySize() const
Returns the size of an array (this is itself a type).
Definition: type.cpp:265
Definition: common.h:208
bool isArray() const
Shortcut for is(ARRAY).
Definition: type.h:228
bool isFormula() const
Returns true if this is a formula, constraint, guard, invariant, boolean or integer.
Definition: type.cpp:408
std::string toString() const
Generates string representation of the type.
Definition: type.cpp:585
position_t getPosition() const
Returns the position of the type in the input file.
Definition: type.cpp:376
Definition: common.h:195
type_t()
Default constructor.
Definition: type.cpp:48
static type_t createPrimitive(Constants::kind_t, position_t=position_t())
Create a primitive type.
Definition: type.cpp:565
Definition: common.h:227
bool isGuard() const
Returns true if this is a guard, invariant, boolean or integer.
Definition: type.cpp:391
Definition: lexer.cc:585
bool isRecord() const
Shortcut for is(RECORD).
Definition: type.h:237
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:570
bool isCost() const
Shortcut for is(COST).
Definition: type.h:246
kind_t
Definition: common.h:37
static string symbol(const char *str)
Extracts the alpha-numerical symbol used for variable/type identifiers.
Definition: xmlreader.cpp:107
std::string getRecordLabel(size_t i) const
Returns the label of the 'th field of a record.
Definition: type.cpp:291
A reference to a frame.
Definition: symbols.h:183
Definition: common.h:175
bool isVoid() const
Shortcut for is(VOID_TYPE).
Definition: type.h:243
bool isBranchpoint() const
Shortcut for is(BRANCHPOINT).
Definition: type.h:222
Definition: common.h:199
type_t createLabel(std::string, position_t=position_t()) const
Creates a LABEL.
Definition: type.cpp:577
Definition: common.h:197
bool isInvariant() const
Returns true if this is an invariant, boolean or integer.
Definition: type.cpp:386
static type_t createProcessSet(type_t instance, position_t=position_t())
Creates a new processset type.
Definition: type.cpp:554
bool isPrefix() const
Returns false for non-prefix types and true otherwise.
Definition: type.cpp:163
A reference to an expression.
Definition: expression.h:68
bool isChannel() const
Shortcut for is(CHANNEL).
Definition: type.h:225
size_t getRecordSize() const
Returns the number of fields of a record.
Definition: type.cpp:278
bool operator<(const type_t &) const
Less-than operator.
Definition: type.cpp:114
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:475
bool operator==(const type_t &) const
Equality operator.
Definition: type.cpp:104
Definition: common.h:219
Definition: position.h:42
std::ostream & operator<<(std::ostream &o, UTAP::type_t t)
Definition: type.cpp:962
static type_t createInstance(frame_t, position_t=position_t())
Creates a new instance type.
Definition: type.cpp:521
bool isBoolean() const
Shortcut for is(BOOL).
Definition: type.h:204
const type_t operator[](uint32_t) const
Returns the i'th child.
Definition: type.cpp:125
Definition: common.h:200
Definition: common.h:194
type_t strip() const
Removes any leading prefixes, RANGE, REF and LABEL types and returns the result.
Definition: type.cpp:323
type_t getSub() const
Returns the element type of an array.
Definition: type.cpp:231
Definition: common.h:217
std::string toDeclarationString() const
Definition: type.cpp:772
A reference to a type.
Definition: type.h:92
static type_t createTypeDef(std::string, type_t, position_t=position_t())
Creates a new type definition.
Definition: type.cpp:513
static type_t createArray(type_t sub, type_t size, position_t=position_t())
Creates an array type.
Definition: type.cpp:505
Definition: common.h:212
const std::string & getLabel(uint32_t) const
Returns the i'th label.
Definition: type.cpp:137
bool isIntegral() const
Returns true if this is a boolean or integer.
Definition: type.cpp:381
bool isNonConstant() const
Returns true if and only if all elements of the type are not constant.
Definition: type.cpp:438
bool isLocation() const
Shortcut for is(LOCATION).
Definition: type.h:216
type_t createPosition(position_t=position_t()) const
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:489
bool isClock() const
Shortcut for is(CLOCK).
Definition: type.h:234
static type_t createProcess(frame_t, position_t=position_t())
Creates a new process type.
Definition: type.cpp:543
Definition: common.h:201
bool isConstraint() const
Returns true if this is a constraint, guard, invariant, boolean or integer.
Definition: type.cpp:403
bool isInstanceLine() const
Shortcut for is(INSTANCELINE).
Definition: type.h:219
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:361
~type_t()
Destructor.
Definition: type.cpp:72
Constants::kind_t getKind() const
Returns the kind of type object.
Definition: type.cpp:158
bool unknown() const
Returns true if this is null-type or of kind UNKNOWN.
Definition: type.cpp:209
type_t rename(std::string from, std::string to) const
Replaces any LABEL labeled from occuring in the type with a LABEL to.
Definition: type.cpp:345
type_t stripArray() const
Removes any leading prefixes, RANGE, REF, LABEL and ARRAY types and returns the result.
Definition: type.cpp:335
bool isFunction() const
Shortcut for is(FUNCTION).
Definition: type.h:207
Definition: common.h:193
bool isProcessSet() const
Shortcut for is(PROCESSSET).
Definition: type.h:213
Definition: common.h:205
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:214
bool isProcess() const
Shortcut for is(PROCESS).
Definition: type.h:210
bool isConstant() const
Returns true if and only if all elements of the type are constant.
Definition: type.cpp:413
static type_t createRange(type_t, expression_t, expression_t, position_t=position_t())
Definition: type.cpp:463
int32_t findIndexOf(std::string) const
Returns the index of the record or process field with the given label.
Definition: type.cpp:143