ACT Library
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
UserDef Class Reference

UserDef stores information that is common to all user-defined types. User-defined types are more complex, because they can have definitions and template parameters. To handle this complexity and to reduce storage requirements, the "shared" part of a user-defined type is factored out into this class. That way the body of a channel x1of2 is shared with x1of2? and x1of2!, as well as an array of x1of2 (for example). More...

#include <types.h>

Inheritance diagram for UserDef:
Type Channel Data Function Interface Process

Public Member Functions

 UserDef (ActNamespace *ns)
 
 UserDef (UserDef *x)
 
virtual ~UserDef ()
 destructor, releases storage
 
const char * getFile ()
 
void setFile (const char *s)
 
int getLine ()
 
void setLine (int num)
 
int IsExported ()
 
void MkExported ()
 
int isExpanded () const
 
int AddMetaParam (InstType *t, const char *id)
 
int AddPort (InstType *t, const char *id)
 
int FindPort (const char *id)
 
const char * getPortName (int pos) const
 
InstTypegetPortType (int pos) const
 
void refinePortType (int pos, InstType *u)
 
const char * getName ()
 
char * getFullName ()
 
void printActName (FILE *fp)
 
int isEqual (const Type *t) const
 
void setName (const char *s)
 
void MkCopy (UserDef *u)
 
int isEqual (const UserDef *u) const
 
void SetParent (InstType *t)
 
InstTypegetParent () const
 
int isDefined ()
 
void MkDefined ()
 
int isPort (const char *name)
 
int getNumParams () const
 
int getRemainingParams () const
 
int getNumPorts () const
 
InstTypeLookup (ActId *id)
 
InstTypeLookup (const char *nm)
 
ScopeCurScope ()
 
int isStrictPort (const char *name)
 
virtual void Print (FILE *)
 
void PrintHeader (FILE *fp, const char *type)
 
void setBody (ActBody *x)
 
void AppendBody (ActBody *x)
 
ActBodygetBody ()
 
UserDefExpand (ActNamespace *, Scope *, int, inst_param *)
 
UserDefExpand (ActNamespace *ns, Scope *s, int nt, inst_param *u, int *cache_hit, int is_process=0)
 
ActNamespacegetns ()
 
InstTyperoot () const
 
act_prsgetprs ()
 
act_specgetspec ()
 
act_languagesgetlang ()
 
int isLeaf ()
 
void mkRefined ()
 
int hasRefinement ()
 
UserMacronewMacro (const char *name)
 
UserMacrogetMacro (const char *name)
 
- Public Member Functions inherited from Type
 Type ()
 
 ~Type ()
 constructor
 
virtual const char * getName ()=0
 destructor
 
virtual TypeExpand (ActNamespace *ns, Scope *s, int nt, inst_param *ip)=0
 
virtual int isEqual (const Type *t) const =0
 

Protected Member Functions

int emitMacros (FILE *fp)
 
 A_DECL (UserMacro *, um)
 user-defined macros
 

Protected Attributes

InstTypeparent
 implementation relationship, if any
 
unsigned int defined:1
 1 if this has been defined, 0 otherwise
 
unsigned int expanded:1
 1 if this has been expanded, 0 otherwise
 
unsigned int pending:1
 1 if this is currently being expanded, 0 otherwise
 
unsigned int exported:1
 1 if the type is exported, 0 otherwise
 
act_languageslang
 sub-languages within this type
 
int nt
 number of template parameters
 
InstType ** pt
 parameter types
 
const char ** pn
 parameter names
 
int nports
 number of ports
 
InstType ** port_t
 port types
 
const char ** port_n
 port names
 
ScopeI
 instances
 
const char * name
 Name of the user-defined type.
 
ActBodyb
 body of user-defined type
 
ActNamespace_ns
 namespace within which this type is defined
 
UserDefunexpanded
 unexpanded type, if any
 
int level
 default modeling level for the type
 
const char * file
 file name (if known) where this was defined
 
int lineno
 line number (if known) where this was defined
 
int has_refinement
 1 if there is a refinement body
 
int inherited_templ
 number of inherited template parameters
 
inst_param ** inherited_param
 the inherited parameters
 

Additional Inherited Members

- Public Types inherited from Type
enum  direction {
  NONE = 0 , IN = 1 , OUT = 2 , INOUT = 3 ,
  OUTIN = 4
}
 
- Static Public Member Functions inherited from Type
static void Init ()
 
static const char * dirstring (direction d)
 

Detailed Description

UserDef stores information that is common to all user-defined types. User-defined types are more complex, because they can have definitions and template parameters. To handle this complexity and to reduce storage requirements, the "shared" part of a user-defined type is factored out into this class. That way the body of a channel x1of2 is shared with x1of2? and x1of2!, as well as an array of x1of2 (for example).

UserDef types can be either a Process, Data, Channel, Function, or Interface.

Parameters to the type are

Constructor & Destructor Documentation

◆ UserDef() [1/2]

UserDef::UserDef ( ActNamespace ns)
Parameters
nsis the namespace in which the type is defined

◆ UserDef() [2/2]

UserDef::UserDef ( UserDef x)

This moves all the information from the specified user-defined type over into this one.

Parameters
xis a previously created UserDef type

◆ ~UserDef()

virtual UserDef::~UserDef ( )
virtual

destructor, releases storage

Member Function Documentation

◆ A_DECL()

UserDef::A_DECL ( UserMacro ,
um   
)
protected

user-defined macros

◆ AddMetaParam()

int UserDef::AddMetaParam ( InstType t,
const char *  id 
)

Add a new template ("meta") parameter

Parameters
tis the type of the parameter
idis the the identifier for this parameter
Returns
1 on success, 0 on error (duplicate parameter name)

◆ AddPort()

int UserDef::AddPort ( InstType t,
const char *  id 
)

Add a new port

Parameters
tis the type of the port
idis the the identifier for this parameter
Returns
1 on success, 0 on error (duplicate parameter name)

◆ AppendBody()

void UserDef::AppendBody ( ActBody x)

Append to the current body of the user-defined type

Parameters
xis the additional body to append

◆ CurScope()

Scope * UserDef::CurScope ( )
inline
Returns
the scope pointer for the user-defined type

◆ emitMacros()

int UserDef::emitMacros ( FILE *  fp)
protected

Used to print macros in the type

Parameters
fpis the output file
Returns
1 if there are some macros, 0 otherwise

◆ Expand() [1/2]

UserDef * UserDef::Expand ( ActNamespace ,
Scope ,
int  ,
inst_param  
)
inlinevirtual

Here in case someone called the wrong Expand!

Implements Type.

Reimplemented in Interface, Process, Function, Data, and Channel.

◆ Expand() [2/2]

UserDef * UserDef::Expand ( ActNamespace ns,
Scope s,
int  nt,
inst_param u,
int *  cache_hit,
int  is_process = 0 
)

Expand the user-defined type

Parameters
nsis the namespace
sis the scope
ntis the number of specified template parameters
uholds the template parameters
cache_hitreturns 1 on a hit (i.e. found a previously expanded identical type that is being returned), 0 otherwise
is_processis 0 by default, 1 for processes, 2 for functions
Returns
expanded type either from the construction, or from the cache

◆ FindPort()

int UserDef::FindPort ( const char *  id)

Find a port. Returns the port number encoded in the following way:

  • if the parameter is a port at position k in the port list, the value returned is (k+1)
  • if the parameter is a port at position k in the meta-parameter/template parameter list, the value returned is -(k+1)
  • if the name is not in the port list, 0 is returned
Parameters
idis the name of the port
Returns
0 if not found. Positive values mean ports; negative values mean template parameters

◆ getBody()

ActBody * UserDef::getBody ( )
inline
Returns
the current body of the user-defined type

◆ getFile()

const char * UserDef::getFile ( )
inline

Get file name where this was defined

Returns
the file name

◆ getFullName()

char * UserDef::getFullName ( )
Returns
a freshly allocated string with full name (including namespace) for the type.

◆ getlang()

act_languages * UserDef::getlang ( )
inline
Returns
all the sub-language bodies, NULL if there are none

◆ getLine()

int UserDef::getLine ( )
inline
Returns
the line number where this was defined

◆ getMacro()

UserMacro * UserDef::getMacro ( const char *  name)

Return a user-defined macro

Parameters
nameis the name of the macro
Returns
the user-defined macro (NULL if it doesn't exist)

◆ getName()

const char * UserDef::getName ( )
virtual
Returns
the name of the type. For expanded types, this uses the expanded type naming convention.

Implements Type.

◆ getns()

ActNamespace * UserDef::getns ( )
inline
Returns
the namespace in which the user-defined type was defined

◆ getNumParams()

int UserDef::getNumParams ( ) const
inline
Returns
the number of template parameters

◆ getNumPorts()

int UserDef::getNumPorts ( ) const
inline
Returns
the number of ports

◆ getParent()

InstType * UserDef::getParent ( ) const
inline
Returns
the parent type in the implementation hierarchy, if any

◆ getPortName()

const char * UserDef::getPortName ( int  pos) const

Returns name of port at specified position. 0..k are the port list, -1 to -(l+1) are the template parameters.

Parameters
posis the position of the port in the port list. Negative numbers indicate meta-parameters, 0 and positive parameters indicate physical port parameters.
Returns
the name of the specified port

◆ getPortType()

InstType * UserDef::getPortType ( int  pos) const

Returns the type of the port at specified position. 0..k are the port list, -1 to -(l+1) are the template parameters.

Parameters
posis the position of the port in the port list. Negative numbers indicate meta-parameters, 0 and positive parameters indicate physical port parameters.
Returns
the name of the specified port

◆ getprs()

act_prs * UserDef::getprs ( )
Returns
the prs body (NULL if it does not exist)

◆ getRemainingParams()

int UserDef::getRemainingParams ( ) const
inline

Template parameters may be explicitly declared, or inherited by un-specified template parameters in parent types. The "remaining" template parameters are the fresh ones for this user-defined type.

Returns
the number of remaining template parameters

◆ getspec()

act_spec * UserDef::getspec ( )
Returns
the spec body (NULL if it does not exist)

◆ hasRefinement()

int UserDef::hasRefinement ( )
inline
Returns
1 if this has a refinement body, 0 otherwise

◆ isDefined()

int UserDef::isDefined ( )
inline

Specify if this type has been fully defined yet or not. It may only be a declared type at this point.

Returns
1 if the type has been defined, 0 if it has only been declared.

◆ isEqual() [1/2]

int UserDef::isEqual ( const Type t) const
virtual

Check if two types are equal to each other.

Parameters
tis the type to compare against
Returns
the result of comparing two types

Implements Type.

Reimplemented in Data.

◆ isEqual() [2/2]

int UserDef::isEqual ( const UserDef u) const

Compare user-defined types to see if the port parameters match

Parameters
uis the user-defined type to compare with
Returns
1 if the types are equal, 0 otherwise

◆ isExpanded()

int UserDef::isExpanded ( ) const
inline
Returns
1 if the type is expanded, or 0 if it is not

◆ IsExported()

int UserDef::IsExported ( )
inline

Specifies if this is an exported user-defined type or not

Returns
1 if this is an exported type, 0 otherwise

◆ isLeaf()

int UserDef::isLeaf ( )

Only useful for process types.

Returns
1 if there are no sub-circuits within this type, 0 otherwise

◆ isPort()

int UserDef::isPort ( const char *  name)

Is this parameter a port?

Parameters
nameis the name of the instance to be checked.
Returns
1 if name is a port, 0 otherwise

◆ isStrictPort()

int UserDef::isStrictPort ( const char *  name)

THIS IS NOT USED NOW. Always returns 1.

Parameters
nameis the name of the port to be checked
Returns
1 if this is a port name that is also in the "strict" parameter list

◆ Lookup() [1/2]

InstType * UserDef::Lookup ( ActId id)
inline

Looks up an identifier within the scope of the body of the type

Parameters
idis the ActId to look up
Returns
the type for the identifier in the local scope, or NULL if it does not exist. Essentially a direct way to call Lookup() for the scope.

◆ Lookup() [2/2]

InstType * UserDef::Lookup ( const char *  nm)
inline

Looks up an identifier within the scope of the body of the type

Parameters
nmis the name to look up
Returns
the type for the identifier in the local scope, or NULL if it does not exist. Essentially a direct way to call Lookup() for the scope.

◆ MkCopy()

void UserDef::MkCopy ( UserDef u)

Make a copy: copy over all fields from u, and clear the fields of u at the same time.

Parameters
uis the user-defined type to "take over"

◆ MkDefined()

void UserDef::MkDefined ( )
inline

Mark this type as defined

◆ MkExported()

void UserDef::MkExported ( )
inline

Set this to be an exported type

◆ mkRefined()

void UserDef::mkRefined ( )
inline

Mark this as a type that has a refinement body

◆ newMacro()

UserMacro * UserDef::newMacro ( const char *  name)

Create a new user-defined macro

Parameters
nameis the name of the macro
Returns
the blank macro

◆ Print()

virtual void UserDef::Print ( FILE *  )
inlinevirtual

Print out user defined type

Reimplemented in Process, Function, Data, and Channel.

◆ printActName()

void UserDef::printActName ( FILE *  fp)

Print the ACT name for the type. WARNING: this does not do the right thing for array template parameters.

Parameters
fpis the output file

◆ PrintHeader()

void UserDef::PrintHeader ( FILE *  fp,
const char *  type 
)

Print out the header for the type. This function can be used for all the different ways a UserDef can be used. The type field is used to print out one of the following strings: "defproc", "deftype", "defchan", "interface", "function".

Parameters
fpis the output file
typeis the string for the kind of user-defined type.

◆ refinePortType()

void UserDef::refinePortType ( int  pos,
InstType u 
)

Used for overrides. Refine the type for the port parameter at the specified position.

Parameters
posis 0..k for the port list (temlpate parameters are never refined)
uis the updated instance type

◆ root()

InstType * UserDef::root ( ) const

This should only be called for user-defined data types or channels.

Returns
the root type for this one in the implementation hierarchy. NULL if there is no root non user-defined type.

◆ setBody()

void UserDef::setBody ( ActBody x)
inline

Directly set the body of the user-defined type

Parameters
xthe body to assign to this user-defined type

◆ setFile()

void UserDef::setFile ( const char *  s)
inline

Set file name for this type

Parameters
sis the file name

◆ setLine()

void UserDef::setLine ( int  num)
inline

Set the line number where this type was defined

Parameters
numis the line number

◆ setName()

void UserDef::setName ( const char *  s)
inline

Set the name of the type. Used to share the string pointer between this data structure and the hash table that holds the type name as well.

Parameters
sis the new string pointer to use for the type name

◆ SetParent()

void UserDef::SetParent ( InstType t)

Setup parent relationship for the imlementation relation between types.

Parameters
tis the parent type

Member Data Documentation

◆ _ns

ActNamespace* UserDef::_ns
protected

namespace within which this type is defined

◆ b

ActBody* UserDef::b
protected

body of user-defined type

◆ defined

unsigned int UserDef::defined
protected

1 if this has been defined, 0 otherwise

◆ expanded

unsigned int UserDef::expanded
protected

1 if this has been expanded, 0 otherwise

◆ exported

unsigned int UserDef::exported
protected

1 if the type is exported, 0 otherwise

◆ file

const char* UserDef::file
protected

file name (if known) where this was defined

◆ has_refinement

int UserDef::has_refinement
protected

1 if there is a refinement body

◆ I

Scope* UserDef::I
protected

instances

◆ inherited_param

inst_param** UserDef::inherited_param
protected

the inherited parameters

◆ inherited_templ

int UserDef::inherited_templ
protected

number of inherited template parameters

◆ lang

act_languages* UserDef::lang
protected

sub-languages within this type

◆ level

int UserDef::level
protected

default modeling level for the type

◆ lineno

int UserDef::lineno
protected

line number (if known) where this was defined

◆ name

const char* UserDef::name
protected

Name of the user-defined type.

◆ nports

int UserDef::nports
protected

number of ports

◆ nt

int UserDef::nt
protected

number of template parameters

◆ parent

InstType* UserDef::parent
protected

implementation relationship, if any

◆ pending

unsigned int UserDef::pending
protected

1 if this is currently being expanded, 0 otherwise

◆ pn

const char** UserDef::pn
protected

parameter names

◆ port_n

const char** UserDef::port_n
protected

port names

◆ port_t

InstType** UserDef::port_t
protected

port types

◆ pt

InstType** UserDef::pt
protected

parameter types

◆ unexpanded

UserDef* UserDef::unexpanded
protected

unexpanded type, if any


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