ACT Library
Loading...
Searching...
No Matches
Macros | Functions
typecheck.h File Reference

Typechecking identifiers and expression. More...

Go to the source code of this file.

Macros

#define T_ERR   -1
 
#define T_ARRAYOF   0x20
 array flag
 
#define T_STRICT   0x40
 
#define T_PARAM   0x80
 a parameter type flag for pint/... etc
 
#define T_INT   0x1
 an integer (data or parameter type)
 
#define T_REAL   0x2
 a real number
 
#define T_BOOL   0x4
 a Boolean (data or parameter)
 
#define T_PROC   0x5
 a process
 
#define T_CHAN   0x6
 a channel
 
#define T_DATA_INT   0x7
 an integer within a channel
 
#define T_DATA_BOOL   0x8
 a bool within a channel
 
#define T_SELF   0x9
 special type, "self"
 
#define T_DATA   0xa
 a structure
 
#define T_DATA_ENUM   0xb
 an enum that is not an int
 
#define T_PTYPE   0x10
 used when the expression is a type
 
#define T_MASK   0x1f
 mask for the list of options
 
#define T_FIXBASETYPE(x)   ((((x) & T_MASK) == T_DATA_BOOL) ? T_BOOL : ((((x) & T_MASK) == T_DATA_INT) ? T_INT : ((x) & T_MASK)))
 
#define T_BASETYPE(x)   ((x) & T_MASK)
 
#define T_BASETYPE_ISNUM(x)   (T_FIXBASETYPE (x) == T_INT || T_BASETYPE (x) == T_REAL)
 
#define T_BASETYPE_INT(x)   (T_FIXBASETYPE(x) == T_INT)
 
#define T_BASETYPE_BOOL(x)   (T_FIXBASETYPE(x) == T_BOOL)
 
#define T_BASETYPE_ISINTBOOL(x)   (T_BASETYPE_INT(x) || T_BASETYPE_BOOL(x))
 

Functions

int act_type_expr (Scope *s, Expr *e, int *width, int only_chan=0)
 
int act_type_var (Scope *s, ActId *id, InstType **xit)
 
int act_type_chan (Scope *sc, Chan *ch, int is_send, Expr *e, ActId *id, int override_id)
 
int act_type_conn (Scope *, ActId *, AExpr *)
 
int act_type_conn (Scope *, AExpr *, AExpr *)
 
int type_connectivity_check (InstType *lhs, InstType *rhs, int skip_last_array=0)
 
int type_chp_check_assignable (InstType *lhs, InstType *rhs)
 
InstTypeact_expr_insttype (Scope *s, Expr *e, int *islocal, int only_chan)
 
InstTypeact_actual_insttype (Scope *s, ActId *id, int *islocal)
 
void type_set_position (int l, int c, char *n)
 
const char * act_type_errmsg (void)
 
void typecheck_err (const char *s,...)
 

Detailed Description

Typechecking identifiers and expression.

The typechecking functions return an integer code. This code is T_ERR on an error, or a flag that is used to summarize the type of the result.

The function act_type_errmsg() can be used to get a string that corresponds to a more verbose message corresponding to the last error that was encountered during type-checking.

Macro Definition Documentation

◆ T_ARRAYOF

#define T_ARRAYOF   0x20

array flag

◆ T_BASETYPE

#define T_BASETYPE (   x)    ((x) & T_MASK)

Used to extract the type case minus any flags (the "base type")

◆ T_BASETYPE_BOOL

#define T_BASETYPE_BOOL (   x)    (T_FIXBASETYPE(x) == T_BOOL)

Check if the processed base type is a bool

◆ T_BASETYPE_INT

#define T_BASETYPE_INT (   x)    (T_FIXBASETYPE(x) == T_INT)

Check if the processed base type is an int

◆ T_BASETYPE_ISINTBOOL

#define T_BASETYPE_ISINTBOOL (   x)    (T_BASETYPE_INT(x) || T_BASETYPE_BOOL(x))

Check if the processed base type is an integer or a boolean. This means it could be a chan(bool) or a chan(int) as well.

◆ T_BASETYPE_ISNUM

#define T_BASETYPE_ISNUM (   x)    (T_FIXBASETYPE (x) == T_INT || T_BASETYPE (x) == T_REAL)

Check if the base type is an integer or real number, i.e. a numeric value

◆ T_BOOL

#define T_BOOL   0x4

a Boolean (data or parameter)

◆ T_CHAN

#define T_CHAN   0x6

a channel

◆ T_DATA

#define T_DATA   0xa

a structure

◆ T_DATA_BOOL

#define T_DATA_BOOL   0x8

a bool within a channel

◆ T_DATA_ENUM

#define T_DATA_ENUM   0xb

an enum that is not an int

◆ T_DATA_INT

#define T_DATA_INT   0x7

an integer within a channel

◆ T_ERR

#define T_ERR   -1

return if the checking function returns an error

◆ T_FIXBASETYPE

#define T_FIXBASETYPE (   x)    ((((x) & T_MASK) == T_DATA_BOOL) ? T_BOOL : ((((x) & T_MASK) == T_DATA_INT) ? T_INT : ((x) & T_MASK)))

Used to process return types by converting T_DATA_BOOL to T_BOOL, and T_DATA_INT to T_INT.

◆ T_INT

#define T_INT   0x1

an integer (data or parameter type)

◆ T_MASK

#define T_MASK   0x1f

mask for the list of options

◆ T_PARAM

#define T_PARAM   0x80

a parameter type flag for pint/... etc

◆ T_PROC

#define T_PROC   0x5

a process

◆ T_PTYPE

#define T_PTYPE   0x10

used when the expression is a type

◆ T_REAL

#define T_REAL   0x2

a real number

◆ T_SELF

#define T_SELF   0x9

special type, "self"

◆ T_STRICT

#define T_STRICT   0x40

a port parameter flag that is in the "strict" list... i.e. not optional, i.e. before the vertical bar (NOT USED)

Function Documentation

◆ act_actual_insttype()

InstType * act_actual_insttype ( Scope s,
ActId id,
int *  islocal 
)

Returns the actual type of the identifier.

Parameters
sis the scope
idis the identifier
islocalis used to return 1 if the identifier is only accessible within the local scope specified, 0 otherwise
Returns
the type of the identifier (NULL if not found)

◆ act_expr_insttype()

InstType * act_expr_insttype ( Scope s,
Expr e,
int *  islocal,
int  only_chan 
)

Returns the actual type of the expression. only_chan is the same flag as act_type_expr(), and can be 0, 1, 2, or 3.

Parameters
sis the scope
eis the expression
islocalis used to return 1 if all identifiers within this expression are local to the scope and cannot be accessed from outside the scope, 0 otherwise
only_chanis the same as the only_chan flag for act_type_expr()
Returns
the InstType for the expression (if successful), NULL otherwise.

◆ act_type_chan()

int act_type_chan ( Scope sc,
Chan ch,
int  is_send,
Expr e,
ActId id,
int  override_id 
)

Used to type-check a channel operation. The channel operation is of one of the following forms: ch!e ch?v ch!e?v ch?v!e

An identifier could also be of the form bool(v) or int(v), which is used to implicitly convert the identifier type from int to bool or bool to int. The override_id flag is used for this purpose.

Parameters
scis the scope in which the type-checking is performed
chis the channel type
is_sendis 1 for a send operation, 0 for a receive operation
eis the (optional) expression being sent
idis the (optional) identifer for the receive operation
override_idis -1 if int/bool overrides are absent, 0 for bool(.), and 1 for int(.)
Returns
1 on success, 0 on error

◆ act_type_conn() [1/2]

int act_type_conn ( Scope ,
ActId ,
AExpr  
)

Used to type-check a connection between an identifier and an array expression

Returns
1 on success, 0 on error

◆ act_type_conn() [2/2]

int act_type_conn ( Scope ,
AExpr ,
AExpr  
)

Used to type-check a connection between two array expressions

Returns
1 on success, 0 on error

◆ act_type_errmsg()

const char * act_type_errmsg ( void  )

Used to return the type-checking error message

Returns
error string from last recorded type-check error message

◆ act_type_expr()

int act_type_expr ( Scope s,
Expr e,
int *  width,
int  only_chan = 0 
)

Typecheck an expression, and return the result type if the type-checking succeeds.

The only_chan flag is used to set the mode of the check.

  • only_chan = 0 : normal expression, used for standard expression type checking.
  • only_chan = 1 : the identifiers must always be channel types, and the type corresponds to the data values being communicated on the channels. This is used for dataflow checking.
  • only_chan = 2 : permit both identifiers and channels. This is used for CHP expressions that can inspect the value pending on a channel.
Parameters
sis the scope in which the type-checking is performed
eis the expression
widthif non-NULL, this is used to return the bit-width of the result
only_chanis a flag that determines valid identifiers.
Returns
a T_... flag that describes the result of checking

◆ act_type_var()

int act_type_var ( Scope s,
ActId id,
InstType **  xit 
)

Used to type-check a variable

Parameters
sis the scope in which to peform the type-checking
idis the variable to be checked
xitis used to return the actual InstType * for the identifier, if xit is non-NULL
Returns
a T_... flag that describes the result of the checking

◆ type_chp_check_assignable()

int type_chp_check_assignable ( InstType lhs,
InstType rhs 
)

This checks if a value with a type corresponding to the rhs can be assigned to one on the lhs in a CHP program

Parameters
lhsis the left-hand side type: the type of the id
rhsis the right-hand side type: the type of the expression
Returns
1 if they are assignable, 0 otherwise

◆ type_connectivity_check()

int type_connectivity_check ( InstType lhs,
InstType rhs,
int  skip_last_array = 0 
)

Used to check if two types can be connected to each other. If a type is an array type, then for unexpanded types this only checks that the number of dimensions are equal. For expanded types, it checks that the dimension sizes also match.

If skip_last_array is set to 1, this will skip checking the size of the first dimension.

Return values:

  • 0 = they are not compatible
  • 1 = they are compatible
  • 2 = they are compatible, lhs is more specific
  • 3 = they are compatible, rhs is more specific
Parameters
lhsis the first type to check
rhsis the second type to check
skip_last_arrayis used to omit the first dimension check
Returns
the result of checking if the types can be connected to each other

◆ type_set_position()

void type_set_position ( int  l,
int  c,
char *  n 
)

Used to record the line, column, and file for error reporting

Parameters
lis the line number
cis the column number
nis the file name

◆ typecheck_err()

void typecheck_err ( const char *  s,
  ... 
)

Use this to set the type-checking error message that is later returned by act_type_errmsg()

Parameters
sis the printf-style format string