This module represents the abstract syntax tree of machine CSP.
Most of the datatypes are parameterised over the type of variables that they
contain. Before renaming (by CSPM.Renamer
) the variables are of type
UnRenamedName
, wheras after renaming they are of type Name
(and are
hence associated with their bindings instances). Furthermore, nearly all
pieces of syntax are annoated with their location in the source code, and
(sometimes) with their type (but only after type checking). This is done
using the Annotated
datatype.
- data Module id = GlobalModule [AnDecl id]
- data Decl id
- = FunBind id [AnMatch id]
- | PatBind (AnPat id) (AnExp id)
- | Assert (Assertion id)
- | External {
- externalImportedNames :: [id]
- | Transparent {
- transparentImportedNames :: [id]
- | Channel [id] (Maybe (AnExp id))
- | DataType id [AnDataTypeClause id]
- | NameType id (AnExp id)
- data Match id = Match {
- matchPatterns :: [[AnPat id]]
- matchRightHandSide :: AnExp id
- data Assertion id
- = Refinement { }
- | PropertyCheck { }
- | BoolAssertion (AnExp id)
- | ASNot (Assertion id)
- data Model
- data ModelOption id = TauPriority (AnExp id)
- data SemanticProperty
- data DataTypeClause id = DataTypeClause {
- dataTypeClauseName :: id
- dataTypeClauseTypeExpression :: Maybe (AnExp id)
- data Exp id
- = App {
- appFunction :: AnExp id
- appArguments :: [AnExp id]
- | BooleanBinaryOp { }
- | BooleanUnaryOp { }
- | Concat {
- concatLeftList :: AnExp id
- concatRightList :: AnExp id
- | DotApp {
- dotAppLeftArgument :: AnExp id
- dotAppRighArgument :: AnExp id
- | If {
- ifCondition :: AnExp id
- ifThenBranch :: AnExp id
- ifElseBranch :: AnExp id
- | Lambda {
- lambdaBindingPattern :: AnPat id
- lambdaRightHandSide :: AnExp id
- | Let {
- letDeclarations :: [AnDecl id]
- letExpression :: AnExp id
- | Lit { }
- | List { }
- | ListComp {
- listCompItems :: [AnExp id]
- listCompStatements :: [AnStmt id]
- | ListEnumFrom {
- listEnumFromLowerBound :: AnExp id
- | ListEnumFromTo { }
- | ListLength {
- listLengthExpression :: AnExp id
- | MathsBinaryOp { }
- | MathsUnaryOp { }
- | Paren {
- parenExpression :: AnExp id
- | Set { }
- | SetComp {
- setCompItems :: [AnExp id]
- setCompStatements :: [AnStmt id]
- | SetEnum {
- setEnumItems :: [AnExp id]
- | SetEnumComp {
- setEnumCompItems :: [AnExp id]
- setEnumCompStatements :: [AnStmt id]
- | SetEnumFrom {
- setEnumFromLowerBound :: AnExp id
- | SetEnumFromTo {
- setEnumFromToLowerBound :: AnExp id
- setEnumFromToUpperBound :: AnExp id
- | Tuple {
- tupleItems :: [AnExp id]
- | Var {
- varIdentity :: id
- | AlphaParallel { }
- | Exception {
- exceptionLeftProcess :: AnExp id
- exceptionAlphabet :: AnExp id
- exceptionRightProcess :: AnExp id
- | ExternalChoice {
- extChoiceLeftProcess :: AnExp id
- extChoiceRightOperator :: AnExp id
- | GenParallel {
- genParallelLeftProcess :: AnExp id
- genParallelAlphabet :: AnExp id
- genParallelRightProcess :: AnExp id
- | GuardedExp {
- guardedExpCondition :: AnExp id
- guardedExpProcess :: AnExp id
- | Hiding {
- hidingProcess :: AnExp id
- hidingAlphabet :: AnExp id
- | InternalChoice {
- intChoiceLeftProcess :: AnExp id
- intChoiceRightProcess :: AnExp id
- | Interrupt {
- interruptLeftProcess :: AnExp id
- interruptRightProcess :: AnExp id
- | Interleave {
- interleaveLeftProcess :: AnExp id
- interleaveRightProcess :: AnExp id
- | LinkParallel {
- linkParLeftProcess :: AnExp id
- linkParTiedEvents :: [(AnExp id, AnExp id)]
- linkParTieStatements :: [AnStmt id]
- linkParRightProcess :: AnExp id
- | Prefix {
- prefixChannel :: AnExp id
- prefixFields :: [AnField id]
- prefixProcess :: AnExp id
- | Rename {
- renameProcess :: AnExp id
- renameTiedEvents :: [(AnExp id, AnExp id)]
- renameTieStatements :: [AnStmt id]
- | SequentialComp {
- seqCompLeftProcess :: AnExp id
- seqCompRightProcess :: AnExp id
- | SlidingChoice { }
- | ReplicatedAlphaParallel {
- repAlphaParReplicatedStatements :: [AnStmt id]
- repAlphaParAlphabet :: AnExp id
- repAlphaParProcess :: AnExp id
- | ReplicatedExternalChoice {
- repExtChoiceReplicatedStatements :: [AnStmt id]
- repExtChoiceProcess :: AnExp id
- | ReplicatedInterleave {
- repInterleaveReplicatedStatements :: [AnStmt id]
- repInterleaveProcess :: AnExp id
- | ReplicatedInternalChoice {
- repIntChoiceReplicatedStatements :: [AnStmt id]
- repIntChoiceProcess :: AnExp id
- | ReplicatedLinkParallel {
- repLinkParTiedChannels :: [(AnExp id, AnExp id)]
- repLinkParTieStatements :: [AnStmt id]
- repLinkParReplicatedStatements :: [AnStmt id]
- repLinkParProcess :: AnExp id
- | ReplicatedParallel {
- repParAlphabet :: AnExp id
- repParReplicatedStatements :: [AnStmt id]
- repParProcess :: AnExp id
- | ExpPatWildCard
- | ExpPatDoublePattern (AnExp id) (AnExp id)
- = App {
- data BinaryMathsOp
- data BinaryBooleanOp
- = And
- | Or
- | Equals
- | NotEquals
- | LessThan
- | GreaterThan
- | LessThanEq
- | GreaterThanEq
- data UnaryMathsOp = Negate
- data UnaryBooleanOp = Not
- data Field id
- data Stmt id
- data Pat id
- = PConcat {
- pConcatLeftPat :: AnPat id
- pConcatRightPat :: AnPat id
- | PDotApp {
- pDotLeftPat :: AnPat id
- pDotRightPat :: AnPat id
- | PDoublePattern {
- pDoublePatLeftPat :: AnPat id
- pDoublePatRightPat :: AnPat id
- | PList {
- pListItems :: [AnPat id]
- | PLit { }
- | PParen {
- pParenPattern :: AnPat id
- | PSet { }
- | PTuple {
- pTupleItems :: [AnPat id]
- | PVar {
- pVarIdentity :: id
- | PWildCard
- | PCompList {
- pListStartItems :: [AnPat id]
- pListMiddleEndItems :: Maybe (AnPat id, [AnPat id])
- pListOriginalPattern :: Pat id
- | PCompDot {
- pDotItems :: [AnPat id]
- pDotOriginalpattern :: Pat id
- = PConcat {
- data InteractiveStmt id
- type AnModule id = Annotated () (Module id)
- type AnDecl id = Annotated (Maybe SymbolTable, PSymbolTable) (Decl id)
- type AnMatch id = Annotated () (Match id)
- type AnPat id = Annotated () (Pat id)
- type AnExp id = Annotated (Maybe Type, PType) (Exp id)
- type AnField id = Annotated () (Field id)
- type AnStmt id = Annotated () (Stmt id)
- type AnDataTypeClause id = Annotated () (DataTypeClause id)
- type AnAssertion id = Annotated () (Assertion id)
- type AnInteractiveStmt id = Annotated () (InteractiveStmt id)
- type PModule = AnModule UnRenamedName
- type PDecl = AnDecl UnRenamedName
- type PMatch = AnMatch UnRenamedName
- type PPat = AnPat UnRenamedName
- type PExp = AnExp UnRenamedName
- type PField = AnField UnRenamedName
- type PStmt = AnStmt UnRenamedName
- type PDataTypeClause = AnDataTypeClause UnRenamedName
- type PAssertion = AnAssertion UnRenamedName
- type PInteractiveStmt = AnInteractiveStmt UnRenamedName
- type TCModule = AnModule Name
- type TCDecl = AnDecl Name
- type TCMatch = AnMatch Name
- type TCPat = AnPat Name
- type TCExp = AnExp Name
- type TCField = AnField Name
- type TCStmt = AnStmt Name
- type TCDataTypeClause = AnDataTypeClause Name
- type TCAssertion = AnAssertion Name
- type TCInteractiveStmt = AnInteractiveStmt Name
- getType :: Annotated (Maybe Type, PType) a -> Type
- getSymbolTable :: Annotated (Maybe SymbolTable, PSymbolTable) a -> SymbolTable
Modules
GlobalModule [AnDecl id] |
TypeCheckable TCModule () | |
Eq id => Eq (Module id) | |
Show id => Show (Module id) | |
PrettyPrintable id => PrettyPrintable [Module id] | |
PrettyPrintable id => PrettyPrintable (Module id) | |
Desugarable (Module Name) | |
Compressable (Module a) | |
TypeCheckable [TCModule] () | |
TypeCheckable (Module Name) () | |
Renamable (Module UnRenamedName) (Module Name) |
Declarations
FunBind id [AnMatch id] | A function binding, e.g. |
PatBind (AnPat id) (AnExp id) | The binding of a pattern to an expression, e.g. |
Assert (Assertion id) | An assertion in a file, e.g. |
External | An import of an external function, e.g. |
| |
Transparent | An import of a transparent function, e.g. |
| |
Channel [id] (Maybe (AnExp id)) | A channel declaration, e.g. |
DataType id [AnDataTypeClause id] | A datatype declaration, e.g. |
NameType id (AnExp id) | A nametype declaration, e.g. |
TypeCheckable TCDecl [(Name, Type)] | |
Eq id => Eq (Decl id) | |
Show id => Show (Decl id) | |
PrettyPrintable id => PrettyPrintable (Decl id) | |
Desugarable (Decl Name) | |
FreeVars (Decl UnRenamedName) | |
Compressable (Decl a) | |
Dependencies (Decl Name) | |
TypeCheckable (Decl Name) [(Name, Type)] |
Matches occur on the left hand side of a function declaration and there
is one Match
for each clause of the declaration. For example, given the
declaration:
f() = 0 f(x^xs) = 1+f(xs)
there would be two matches.
Match | |
|
TypeCheckable TCMatch Type | |
Eq id => Eq (Match id) | |
Show id => Show (Match id) | |
Desugarable (Match Name) | |
Compressable (Match a) | |
Dependencies (Match Name) | |
TypeCheckable (Match Name) Type | |
Renamable (Match UnRenamedName) (Match Name) |
Assertions
Refinement | A refinement assertion, e.g. |
| |
PropertyCheck | A check of property, like deadlock freedom, e.g.
|
BoolAssertion (AnExp id) | A boolean assertion, not currently supported. |
ASNot (Assertion id) | The negation of an assertion, not currently supported. |
Eq id => Eq (Assertion id) | |
Show id => Show (Assertion id) | |
PrettyPrintable id => PrettyPrintable (Assertion id) | |
Desugarable (Assertion Name) | |
Compressable (Assertion a) | |
Dependencies (Assertion Name) | |
TypeCheckable (Assertion Name) () | |
Renamable (Assertion UnRenamedName) (Assertion Name) |
data ModelOption id Source
TauPriority (AnExp id) |
Eq id => Eq (ModelOption id) | |
Show id => Show (ModelOption id) | |
PrettyPrintable id => PrettyPrintable (ModelOption id) | |
Desugarable (ModelOption Name) | |
Compressable (ModelOption a) | |
Dependencies (ModelOption Name) | |
TypeCheckable (ModelOption Name) () | |
Renamable (ModelOption UnRenamedName) (ModelOption Name) |
data SemanticProperty Source
Data Type Clauses
data DataTypeClause id Source
The clause of a datatype, e.g. if a datatype declaration was:
datatype T = A.Int.Bool | B.Bool | C
Then T would have three datatype clauses, one for each of its tags (i.e.
A
, B
and C
).
DataTypeClause | |
|
TypeCheckable TCDataTypeClause (Name, [Type]) | |
Eq id => Eq (DataTypeClause id) | |
Show id => Show (DataTypeClause id) | |
PrettyPrintable id => PrettyPrintable (DataTypeClause id) | |
Desugarable (DataTypeClause Name) | |
Compressable (DataTypeClause a) | |
Dependencies (DataTypeClause Name) | |
TypeCheckable (DataTypeClause Name) (Name, [Type]) |
Expressions
An expression.
App | Function application. |
| |
BooleanBinaryOp | Application of a binary boolean operator. |
BooleanUnaryOp | Application of a unary boolean operator. |
Concat | List concatenation, e.g. |
| |
DotApp | Dot operator application, e.g. |
| |
If | If statements, e.g. |
| |
Lambda | Lambda functions, e.g. |
| |
Let | Let declarations, e.g. |
| |
Lit | Literals, e.g. |
List | List literals, e.g. |
ListComp | List comprehensions, e.g. |
| |
ListEnumFrom | Infinite list of integers from the given value, e.g. |
| |
ListEnumFromTo | Bounded list of integers between the given values, e.g. |
| |
ListLength | The length of the list, e.g. |
| |
MathsBinaryOp | Application of binary maths operator, e.g. |
MathsUnaryOp | Application of unary maths operator, e.g. |
Paren | A user provided bracket, e.g. |
| |
Set | Set literals, e.g. |
SetComp | Set comprehensions, e.g. |
| |
SetEnum | Enumerated Sets, i.e. sets that complete the events, e.g. |
| |
SetEnumComp | Set comprehension version of |
| |
SetEnumFrom | The infinite set of integers from the given value, e.g. |
| |
SetEnumFromTo | The bounded set of integers between the two given values, e.g.
|
| |
Tuple | Tuples, e.g. |
| |
Var | Variables, e.g. |
| |
AlphaParallel | Alphabetised parallel, e.g. |
| |
Exception | Exception operator, e.g. |
| |
ExternalChoice | External choice, e.g. |
| |
GenParallel | Generalised parallel, e.g. |
| |
GuardedExp | Guarded expressions, e.g. |
| |
Hiding | Hiding of events, e.g. |
| |
InternalChoice | Internal choice, e.g. |
| |
Interrupt | Interrupt (where the left process is turned off once the right process
performs an event), e.g. |
| |
Interleave | Interleaving of processes, e.g. |
| |
LinkParallel | |
| |
Prefix | Event prefixing, e.g. |
| |
Rename | Event renaming, e.g. |
| |
SequentialComp | Sequential composition, e.g. |
| |
SlidingChoice | Sliding choice, e.g. |
| |
ReplicatedAlphaParallel | Replicated alphabetised parallel, e.g. |
| |
ReplicatedExternalChoice | Replicated external choice, e.g. |
| |
ReplicatedInterleave | Replicated interleave, e.g. |
| |
ReplicatedInternalChoice | Replicated internal choice, e.g. |
| |
ReplicatedLinkParallel | Replicated link parallel, e.g.
|
| |
ReplicatedParallel | Replicated parallel, e.g. |
| |
ExpPatWildCard | Used only for parsing - never appears in an AST. |
ExpPatDoublePattern (AnExp id) (AnExp id) | Used only for parsing - never appears in an AST. |
TypeCheckable TCExp Type | |
Eq id => Eq (Exp id) | |
Show id => Show (Exp id) | |
PrettyPrintable id => PrettyPrintable (Exp id) | |
Desugarable (Exp Name) | |
Evaluatable (Exp Name) | |
Compressable (Exp a) | |
Dependencies (Exp Name) | |
TypeCheckable (Exp Name) Type | |
Renamable (Exp UnRenamedName) (Exp Name) |
data BinaryMathsOp Source
data BinaryBooleanOp Source
Fields
Fields occur within prefix statements. For example, if the prefix
was c$x?y!z
then there would be three fields, of type NonDetInput
,
Input
and Output
respectively.
Output (AnExp id) | !x |
Input (AnPat id) (Maybe (AnExp id)) | ?x:A |
NonDetInput (AnPat id) (Maybe (AnExp id)) |
|
Eq id => Eq (Field id) | |
Show id => Show (Field id) | |
PrettyPrintable id => PrettyPrintable (Field id) | |
Desugarable (Field Name) | |
FreeVars (Field UnRenamedName) | |
Compressable (Field a) | |
FreeVars (Field Name) | |
Dependencies (Field Name) |
Statements
Statements occur on the right hand side of a list comprehension, or
in the context of replicated operators. For example, in
... | x <- y, func(b)
, x <- y
and func(b)
are both statements,
of type Generator
and Qualifier
respectively.
Eq id => Eq (Stmt id) | |
Show id => Show (Stmt id) | |
PrettyPrintable id => PrettyPrintable (Stmt id) | |
Desugarable (Stmt Name) | |
FreeVars (Stmt UnRenamedName) | |
Compressable (Stmt a) | |
FreeVars (Stmt Name) | |
Dependencies (Stmt Name) |
Patterns
Patterns match against values and may bind some components of the values to variables.
PConcat | The concatenation of two patterns, e.g. |
| |
PDotApp | The dot of two patterns, e.g. |
| |
PDoublePattern | A double pattern match, e.g. |
| |
PList | A literal pattern list, e.g. |
| |
PLit | A literal pattern, e.g. |
PParen | A user supplied parenthesis in a pattern. |
| |
PSet | A set pattern. Only singleton patterns, or zero patterns are supported.
This is checked by the desugarer. For example, |
PTuple | A tuple pattern, e.g. |
| |
PVar | A variable pattern, e.g. |
| |
PWildCard | Matches anything but does not bind it. |
PCompList | Since you can write list patterns such as: f(<x,y>^xs^<z,p>^<9,0>) f(<x,y>) f(xs^<x,y>) we need an easy may of matching them. Thus, we compile
the patterns to a
|
| |
PCompDot | Like with a |
|
TypeCheckable TCPat Type | |
Eq id => Eq (Pat id) | |
Show id => Show (Pat id) | |
PrettyPrintable id => PrettyPrintable (Pat id) | |
Desugarable (Pat Name) | |
FreeVars (Pat UnRenamedName) | |
Bindable (Pat Name) | |
FreeVars (Pat Name) | |
Compressable (Pat a) | |
FreeVars (Pat Name) | |
Dependencies (Pat Name) | |
TypeCheckable (Pat Name) Type |
Interactive Statements
Interactive statements are intended to be input by an interactive editor.
data InteractiveStmt id Source
A statement in an interactive session.
TypeCheckable TCInteractiveStmt () | |
Show id => Show (InteractiveStmt id) | |
PrettyPrintable id => PrettyPrintable (InteractiveStmt id) | |
Desugarable (InteractiveStmt Name) | |
Compressable (InteractiveStmt a) | |
TypeCheckable (InteractiveStmt Name) () | |
Renamable (InteractiveStmt UnRenamedName) (InteractiveStmt Name) |
Type Synonyms
As the types are parameterised over the type of names it can be laborious to type the names. Therefore, some shortcuts are provided.
type AnDecl id = Annotated (Maybe SymbolTable, PSymbolTable) (Decl id)Source
type AnDataTypeClause id = Annotated () (DataTypeClause id)Source
type AnAssertion id = Annotated () (Assertion id)Source
type AnInteractiveStmt id = Annotated () (InteractiveStmt id)Source
Pre-Renaming Types
type PModule = AnModule UnRenamedNameSource
type PDecl = AnDecl UnRenamedNameSource
type PMatch = AnMatch UnRenamedNameSource
type PPat = AnPat UnRenamedNameSource
type PExp = AnExp UnRenamedNameSource
type PField = AnField UnRenamedNameSource
type PStmt = AnStmt UnRenamedNameSource
Post-Renaming Types
type TCAssertion = AnAssertion NameSource