public abstract class WhileyFile.FunctionOrMethodOrProperty extends WhileyFile.NamedDeclaration
FunctionDeclaration ::= "function" TypePattern "=>" TypePattern (FunctionMethodClause)* ':' NewLine Block MethodDeclaration ::= "method" TypePattern "=>" TypePattern (FunctionMethodClause)* ':' NewLine Block FunctionMethodClause ::= "throws" Type | "requires" Expression | "ensures" ExpressionHere, the first type pattern (i.e. before "=>") is referred to as the "parameter", whilst the second is referred to as the "return". There are three kinds of option clause:
The following function declaration provides a small example to illustrate:
function max(int x, int y) -> (int z)
// return must be greater than either parameter
ensures x <= z && y <= z
// return must equal one of the parmaeters
ensures x == z || y == z:
...
Here, we see the specification for the well-known max()
function which returns the largest of its parameters. This does not throw
any exceptions, and does not enforce any preconditions on its parameters.
Function and method declarations may also have modifiers, such as
public and private.
| Modifier and Type | Field and Description |
|---|---|
List<Expr> |
ensures |
ArrayList<String> |
lifetimeParameters |
ArrayList<WhileyFile.Parameter> |
parameters |
List<Expr> |
requires |
ArrayList<WhileyFile.Parameter> |
returns |
ArrayList<Stmt> |
statements |
| Constructor and Description |
|---|
FunctionOrMethodOrProperty(List<Modifier> modifiers,
String name,
List<WhileyFile.Parameter> returns,
List<WhileyFile.Parameter> parameters,
List<String> lifetimeParameters,
List<Expr> requires,
List<Expr> ensures,
List<Stmt> statements,
wybs.lang.Attribute... attributes)
Construct an object representing a Whiley function.
|
| Modifier and Type | Method and Description |
|---|---|
abstract Type.FunctionOrMethod |
resolvedType() |
abstract wyal.lang.WyalFile.Type.FunctionOrMethodOrProperty |
unresolvedType() |
hasModifier, modifiers, namepublic final ArrayList<WhileyFile.Parameter> parameters
public final ArrayList<WhileyFile.Parameter> returns
public FunctionOrMethodOrProperty(List<Modifier> modifiers, String name, List<WhileyFile.Parameter> returns, List<WhileyFile.Parameter> parameters, List<String> lifetimeParameters, List<Expr> requires, List<Expr> ensures, List<Stmt> statements, wybs.lang.Attribute... attributes)
name - - The name of the function.returnType - - The return type of this methodparamTypes - - The list of parameter names and their types for this
methodrequires - - The constraints which must hold true on entryensures - - The constraints which must hold true on exitstatements - - The Statements making up the function body.public abstract wyal.lang.WyalFile.Type.FunctionOrMethodOrProperty unresolvedType()
public abstract Type.FunctionOrMethod resolvedType()
Copyright © 2017. All rights reserved.