libutap
Public Member Functions | Static Public Member Functions | List of all members
UTAP::type_t Class Reference

A reference to a type. More...

#include <type.h>

Public Member Functions

 type_t ()
 Default constructor. More...
 
 type_t (const type_t &)
 Copy constructor. More...
 
 ~type_t ()
 Destructor. More...
 
const type_toperator= (const type_t &)
 Assignment operator. More...
 
bool operator== (const type_t &) const
 Equality operator. More...
 
bool operator!= (const type_t &) const
 Inequality operator. More...
 
Constants::kind_t getKind () const
 Returns the kind of type object. More...
 
position_t getPosition () const
 Returns the position of the type in the input file. More...
 
size_t size () const
 Returns the number of children. More...
 
bool operator< (const type_t &) const
 Less-than operator. More...
 
const type_t operator[] (uint32_t) const
 Returns the i'th child. More...
 
const type_t get (uint32_t) const
 Returns the i'th child. More...
 
const std::string & getLabel (uint32_t) const
 Returns the i'th label. More...
 
expression_t getExpression () const
 Returns the expression associated with the type. More...
 
type_t getArraySize () const
 Returns the size of an array (this is itself a type). More...
 
type_t getSub () const
 Returns the element type of an array. More...
 
type_t getSub (size_t) const
 Returns the 'th field of a record or process. More...
 
size_t getRecordSize () const
 Returns the number of fields of a record. More...
 
std::string getRecordLabel (size_t i) const
 Returns the label of the 'th field of a record. More...
 
int32_t findIndexOf (std::string) const
 Returns the index of the record or process field with the given label. More...
 
std::pair< expression_t,
expression_t
getRange () const
 Returns the range of a RANGE type. More...
 
std::string toString () const
 Generates string representation of the type. More...
 
std::string toDeclarationString () const
 
bool isRange () const
 Shortcut for is(RANGE). More...
 
bool isInteger () const
 Shortcut for is(INT). More...
 
bool isBoolean () const
 Shortcut for is(BOOL). More...
 
bool isFunction () const
 Shortcut for is(FUNCTION). More...
 
bool isProcess () const
 Shortcut for is(PROCESS). More...
 
bool isProcessSet () const
 Shortcut for is(PROCESSSET). More...
 
bool isLocation () const
 Shortcut for is(LOCATION). More...
 
bool isInstanceLine () const
 Shortcut for is(INSTANCELINE). More...
 
bool isBranchpoint () const
 Shortcut for is(BRANCHPOINT). More...
 
bool isChannel () const
 Shortcut for is(CHANNEL). More...
 
bool isArray () const
 Shortcut for is(ARRAY). More...
 
bool isScalar () const
 Shortcut for is(SCALAR). More...
 
bool isClock () const
 Shortcut for is(CLOCK). More...
 
bool isRecord () const
 Shortcut for is(RECORD). More...
 
bool isDiff () const
 Shortcut for is(DIFF). More...
 
bool isVoid () const
 Shortcut for is(VOID_TYPE). More...
 
bool isCost () const
 Shortcut for is(COST). More...
 
bool isDouble () const
 Shortcut for is(DOUBLE). More...
 
bool isIntegral () const
 Returns true if this is a boolean or integer. More...
 
bool isInvariant () const
 Returns true if this is an invariant, boolean or integer. More...
 
bool isGuard () const
 Returns true if this is a guard, invariant, boolean or integer. More...
 
bool isConstraint () const
 Returns true if this is a constraint, guard, invariant, boolean or integer. More...
 
bool isFormula () const
 Returns true if this is a formula, constraint, guard, invariant, boolean or integer. More...
 
type_t strip () const
 Removes any leading prefixes, RANGE, REF and LABEL types and returns the result. More...
 
type_t stripArray () const
 Removes any leading prefixes, RANGE, REF, LABEL and ARRAY types and returns the result. More...
 
bool isPrefix () const
 Returns false for non-prefix types and true otherwise. More...
 
bool isConstant () const
 Returns true if and only if all elements of the type are constant. More...
 
bool isNonConstant () const
 Returns true if and only if all elements of the type are not constant. More...
 
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().is(kind) returns true. More...
 
bool unknown () const
 Returns true if this is null-type or of kind UNKNOWN. More...
 
type_t rename (std::string from, std::string to) const
 Replaces any LABEL labeled from occuring in the type with a LABEL to. More...
 
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 either on array sizes, scalars or integers) with expr. More...
 
type_t createPrefix (Constants::kind_t kind, position_t=position_t()) const
 Creates a new type by adding a prefix to it. More...
 
type_t createLabel (std::string, position_t=position_t()) const
 Creates a LABEL. More...
 
type_t createPosition (position_t=position_t()) const
 

Static Public Member Functions

static type_t createRange (type_t, expression_t, expression_t, position_t=position_t())
 
static type_t createPrimitive (Constants::kind_t, position_t=position_t())
 Create a primitive type. More...
 
static type_t createArray (type_t sub, type_t size, position_t=position_t())
 Creates an array type. More...
 
static type_t createTypeDef (std::string, type_t, position_t=position_t())
 Creates a new type definition. More...
 
static type_t createProcess (frame_t, position_t=position_t())
 Creates a new process type. More...
 
static type_t createProcessSet (type_t instance, position_t=position_t())
 Creates a new processset type. More...
 
static type_t createRecord (const std::vector< type_t > &, const std::vector< std::string > &, position_t=position_t())
 Creates a new record type. More...
 
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. More...
 
static type_t createInstance (frame_t, position_t=position_t())
 Creates a new instance type. More...
 
static type_t createLscInstance (frame_t, position_t=position_t())
 Creates a new lsc instance type. More...
 

Detailed Description

A reference to a type.

Types are represented as trees of types. The type cannot be access directly. You need to use an instance of type_t to access a type. Internally, types are reference counted and do not need to be deallocated manually. Types are immutable.

Types are either primitive such as clocks or channels, or contructed types such as structs and array. Constructed types are created using one of the factory methods in the type_t class. Primitive types are leaves in the tree, constructed types are inner nodes.

All types have a kind - a type for the type. The kind is a value of kind_t. In anticipation of a future homogeneous AST, this kind is defined in the same enumerable as the kind of expressions.

Some constructed types are considered prefixes for other types: URGENT, COMMITTED, BROADCAST, CONSTANT and BROADCAST.

LABEL types are references to named types. These are introduced by references to types defined with a typedef or by scalar set declarations. They have one child: The type which has been named.

Constructed types are:

Constructor & Destructor Documentation

type_t::type_t ( )

Default constructor.

This creates a null-type.

type_t::type_t ( const type_t type)

Copy constructor.

type_t::~type_t ( )

Destructor.

Member Function Documentation

type_t type_t::createArray ( type_t  sub,
type_t  size,
position_t  pos = position_t() 
)
static
type_t type_t::createFunction ( type_t  ret,
const std::vector< type_t > &  parameters,
const std::vector< std::string > &  labels,
position_t  pos = position_t() 
)
static

Creates a new function type.

References UTAP::Constants::FUNCTION.

Referenced by UTAP::StatementBuilder::declFuncBegin().

type_t type_t::createInstance ( frame_t  parameters,
position_t  pos = position_t() 
)
static
type_t type_t::createLabel ( std::string  ,
position_t  = position_t() 
) const
type_t type_t::createLscInstance ( frame_t  parameters,
position_t  pos = position_t() 
)
static
type_t UTAP::type_t::createPosition ( position_t  = position_t()) const
type_t type_t::createPrefix ( Constants::kind_t  kind,
position_t  pos = position_t() 
) const

Creates a new type by adding a prefix to it.

The prefix could be anything and it is the responsibility of the caller to make sure that the given kind is a valid prefix.

Referenced by UTAP::SystemBuilder::addSelectSymbolToFrame(), UTAP::ExpressionBuilder::applyPrefix(), UTAP::StatementBuilder::declParameter(), UTAP::ExpressionBuilder::exprForAllBegin(), UTAP::StatementBuilder::iterationBegin(), UTAP::SystemBuilder::procStateCommit(), and UTAP::SystemBuilder::procStateUrgent().

type_t type_t::createPrimitive ( Constants::kind_t  kind,
position_t  pos = position_t() 
)
static
type_t type_t::createProcess ( frame_t  frame,
position_t  pos = position_t() 
)
static
type_t type_t::createProcessSet ( type_t  instance,
position_t  pos = position_t() 
)
static

Creates a new processset type.

References getLabel(), UTAP::Constants::PROCESSSET, and size().

Referenced by UTAP::TimedAutomataSystem::addProcess().

type_t type_t::createRange ( type_t  type,
expression_t  lower,
expression_t  upper,
position_t  pos = position_t() 
)
static
type_t type_t::createRecord ( const std::vector< type_t > &  ,
const std::vector< std::string > &  ,
position_t  = position_t() 
)
static
type_t type_t::createTypeDef ( std::string  label,
type_t  type,
position_t  pos = position_t() 
)
static

Creates a new type definition.

References UTAP::Constants::TYPEDEF.

Referenced by UTAP::StatementBuilder::declTypeDef().

int32_t type_t::findIndexOf ( std::string  label) const

Returns the index of the record or process field with the given label.

Returns -1 if such a field does not exist.

Precondition
isRecord() or isProcess().

References getLabel(), and size().

Referenced by UTAP::ExpressionBuilder::exprDot(), and UTAP::ExpressionBuilder::exprScenario().

const type_t type_t::get ( uint32_t  i) const

Returns the i'th child.

Referenced by stripArray().

type_t type_t::getArraySize ( ) const

Returns the size of an array (this is itself a type).

Precondition
isArray().

References UTAP::Constants::ARRAY, UTAP::Constants::LABEL, and UTAP::Constants::REF.

Referenced by UTAP::TypeChecker::checkExpression(), and initRec().

expression_t type_t::getExpression ( ) const

Returns the expression associated with the type.

kind_t type_t::getKind ( ) const
const std::string & type_t::getLabel ( uint32_t  i) const
position_t type_t::getPosition ( ) const

Returns the position of the type in the input file.

This exposes the fact that the type is actually part of the AST.

std::pair< expression_t, expression_t > type_t::getRange ( ) const

Returns the range of a RANGE type.

Precondition
isRange().

References UTAP::Constants::RANGE.

Referenced by UTAP::StatementBuilder::collectDependencies(), and isSameScalarType().

string type_t::getRecordLabel ( size_t  i) const

Returns the label of the 'th field of a record.

Precondition
isRecord().

References UTAP::Constants::LABEL, UTAP::Constants::PROCESS, UTAP::Constants::RECORD, and UTAP::Constants::REF.

size_t type_t::getRecordSize ( ) const

Returns the number of fields of a record.

Precondition
isRecord().

References UTAP::Constants::LABEL, UTAP::Constants::RECORD, and UTAP::Constants::REF.

type_t type_t::getSub ( ) const
type_t type_t::getSub ( size_t  i) const

Returns the 'th field of a record or process.

Preserves any prefixes.

Precondition
isRecord() or isProcess().

References UTAP::Constants::LABEL, and UTAP::Constants::REF.

bool type_t::is ( Constants::kind_t  kind) const
bool UTAP::type_t::isArray ( ) const
inline
bool UTAP::type_t::isBoolean ( ) const
inline

Shortcut for is(BOOL).

References UTAP::Constants::BOOL, and is().

bool UTAP::type_t::isBranchpoint ( ) const
inline

Shortcut for is(BRANCHPOINT).

References UTAP::Constants::BRANCHPOINT, and is().

Referenced by UTAP::SystemBuilder::procEdgeBegin().

bool UTAP::type_t::isChannel ( ) const
inline
bool UTAP::type_t::isClock ( ) const
inline

Shortcut for is(CLOCK).

References UTAP::Constants::CLOCK, and is().

Referenced by initRec(), and isClock().

bool type_t::isConstant ( ) const
bool type_t::isConstraint ( ) const

Returns true if this is a constraint, guard, invariant, boolean or integer.

Shortcut for is(CONSTRAINT) || isGuard().

References UTAP::Constants::CONSTRAINT, and isGuard().

Referenced by isConstraint().

bool UTAP::type_t::isCost ( ) const
inline

Shortcut for is(COST).

References UTAP::Constants::COST, and is().

bool UTAP::type_t::isDiff ( ) const
inline

Shortcut for is(DIFF).

References UTAP::Constants::DIFF, and is().

Referenced by isDiff().

bool UTAP::type_t::isDouble ( ) const
inline
bool type_t::isFormula ( ) const

Returns true if this is a formula, constraint, guard, invariant, boolean or integer.

Shortcut for is(FORMULA) || isConstraint().

References UTAP::Constants::FORMULA, and isConstraint().

Referenced by isFormula().

bool UTAP::type_t::isFunction ( ) const
inline
bool type_t::isGuard ( ) const

Returns true if this is a guard, invariant, boolean or integer.

Shortcut for is(GUARD) || isInvariant().

References UTAP::Constants::GUARD, and isInvariant().

Referenced by isGuard().

bool UTAP::type_t::isInstanceLine ( ) const
inline

Shortcut for is(INSTANCELINE).

References UTAP::Constants::INSTANCELINE, and is().

Referenced by UTAP::SystemBuilder::procLscUpdate(), and UTAP::SystemBuilder::procMessage().

bool UTAP::type_t::isInteger ( ) const
inline
bool type_t::isIntegral ( ) const

Returns true if this is a boolean or integer.

Shortcut for isInt() || isBoolean().

References UTAP::Constants::BOOL, UTAP::Constants::INT, and UTAP::Constants::PROCESSVAR.

Referenced by UTAP::TypeChecker::checkExpression(), initRec(), isIntegral(), and UTAP::StatementBuilder::structField().

bool type_t::isInvariant ( ) const

Returns true if this is an invariant, boolean or integer.

Shortcut for isIntegral() || is(INVARIANT).

References UTAP::Constants::INVARIANT, and isIntegral().

Referenced by isInvariant().

bool UTAP::type_t::isLocation ( ) const
inline
bool type_t::isNonConstant ( ) const
bool type_t::isPrefix ( ) const
bool UTAP::type_t::isProcess ( ) const
inline

Shortcut for is(PROCESS).

References is(), and UTAP::Constants::PROCESS.

Referenced by UTAP::ExpressionBuilder::exprDot().

bool UTAP::type_t::isProcessSet ( ) const
inline

Shortcut for is(PROCESSSET).

References is(), and UTAP::Constants::PROCESSSET.

bool UTAP::type_t::isRange ( ) const
inline

Shortcut for is(RANGE).

References is(), and UTAP::Constants::RANGE.

Referenced by UTAP::TypeChecker::visitProcess().

bool UTAP::type_t::isRecord ( ) const
inline

Shortcut for is(RECORD).

References is(), and UTAP::Constants::RECORD.

Referenced by UTAP::ExpressionBuilder::exprDot(), and UTAP::StatementBuilder::structField().

bool UTAP::type_t::isScalar ( ) const
inline
bool UTAP::type_t::isVoid ( ) const
inline
bool type_t::operator!= ( const type_t type) const

Inequality operator.

bool type_t::operator< ( const type_t type) const

Less-than operator.

const type_t & type_t::operator= ( const type_t type)

Assignment operator.

bool type_t::operator== ( const type_t type) const

Equality operator.

const type_t type_t::operator[] ( uint32_t  i) const

Returns the i'th child.

type_t type_t::rename ( std::string  from,
std::string  to 
) const

Replaces any LABEL labeled from occuring in the type with a LABEL to.

As always, a type is immutable, so a copy of the type will be created.

References UTAP::Constants::LABEL.

Referenced by UTAP::ExpressionBuilder::exprDot().

size_t type_t::size ( ) const
type_t type_t::strip ( ) const

Removes any leading prefixes, RANGE, REF and LABEL types and returns the result.

References UTAP::Constants::LABEL, UTAP::Constants::RANGE, and UTAP::Constants::REF.

Referenced by initRec(), and stripArray().

type_t type_t::stripArray ( ) const

Removes any leading prefixes, RANGE, REF, LABEL and ARRAY types and returns the result.

References UTAP::Constants::ARRAY, get(), getKind(), and strip().

Referenced by UTAP::TimedAutomataSystem::accept(), UTAP::StatementBuilder::structField(), and visit().

type_t 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 either on array sizes, scalars or integers) with expr.

Referenced by UTAP::ExpressionBuilder::exprDot().

string type_t::toDeclarationString ( ) const
string type_t::toString ( ) const
bool type_t::unknown ( ) const

Returns true if this is null-type or of kind UNKNOWN.

References UTAP::Constants::UNKNOWN.

Referenced by UTAP::TypeChecker::checkExpression().


The documentation for this class was generated from the following files: