edu.mit.csail.sdg.alloy4compiler.ast
Class Func

java.lang.Object
  extended by edu.mit.csail.sdg.alloy4compiler.ast.Browsable
      extended by edu.mit.csail.sdg.alloy4compiler.ast.Func

public final class Func
extends Browsable

Mutable; represents a predicate or function.

Invariant: the list of parameters do not contain duplicates

Invariant: none of the parameter declaration contains a predicate/function call

Invariant: the return type declaration does not contain a predicate/function call


Field Summary
 ConstList<Decl> decls
          The list of parameter declarations; may be an empty list if this predicate/function has no parameters.
 boolean isPred
          True if this is a predicate; false if this is a function.
 Pos isPrivate
          If nonnull, then this predicate/function is private (and this.isPrivate is the location of the "private" keyword)
 java.lang.String label
          The label of this predicate/function; it does not need to be unique.
 Pos pos
          The location in the original file where this predicate/function is declared; never null.
 Expr returnDecl
          The declared return type; never null.
 
Constructor Summary
Func(Pos pos, Pos isPrivate, java.lang.String label, java.util.List<Decl> decls, Expr returnDecl, Expr body)
          Constructs a new predicate/function.
Func(Pos pos, java.lang.String label, java.util.List<Decl> decls, Expr returnDecl, Expr body)
          Constructs a new predicate/function.
 
Method Summary
 Expr call(Expr... args)
          Convenience method that calls this function with the given list of arguments.
 int count()
          Return the number of parameters.
 ExprVar get(int i)
          Return the i-th parameter where i goes from 0 to count()-1
 Expr getBody()
          Return the body of this predicate/function.
 java.lang.String getHTML()
          Returns the description (as HTML) to show for this node.
 java.util.List<? extends Browsable> getSubnodes()
          Returns a list of subnodes for this node.
 java.util.List<ExprVar> params()
          Return the list of all parameters.
 Pos pos()
          Returns a Pos object representing the position of this Expr.
 void setBody(Expr newBody)
          Changes the method body.
 Pos span()
          Returns a Pos object representing the entire span of this Expr and all its subexpressions.
 java.lang.String toString()
          Returns a human-readable description for this predicate/function
 
Methods inherited from class edu.mit.csail.sdg.alloy4compiler.ast.Browsable
make, make, make, make, showAsTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pos

public final Pos pos
The location in the original file where this predicate/function is declared; never null.


isPrivate

public final Pos isPrivate
If nonnull, then this predicate/function is private (and this.isPrivate is the location of the "private" keyword)


label

public final java.lang.String label
The label of this predicate/function; it does not need to be unique.


isPred

public final boolean isPred
True if this is a predicate; false if this is a function.


decls

public final ConstList<Decl> decls
The list of parameter declarations; may be an empty list if this predicate/function has no parameters.


returnDecl

public final Expr returnDecl
The declared return type; never null.

Constructor Detail

Func

public Func(Pos pos,
            java.lang.String label,
            java.util.List<Decl> decls,
            Expr returnDecl,
            Expr body)
     throws Err
Constructs a new predicate/function.

The first declaration's bound should be an expression with no free variables.
The second declaration's bound should be an expression with no free variables, except possibly the parameters in first declaration.
The third declaration's bound should be an expression with no free variables, except possibly the parameters in first two declarations.
etc.
The return declaration should have no free variables, except possibly the list of input parameters.

Parameters:
pos - - the original position in the file
label - - the label for this predicate/function (does not have to be unique)
decls - - the list of parameter declarations (can be null or an empty list if this predicate/function has no parameters)
returnDecl - - the return declaration (null if this is a predicate rather than a function)
Throws:
ErrorType - if returnType!=null and returnType cannot be unambiguously typechecked to be a set/relation
ErrorSyntax - if the list of parameters contain duplicates
ErrorSyntax - if at least one of the parameter declaration contains a predicate/function call
ErrorSyntax - if this function's return type declaration contains a predicate/function call
Err

Func

public Func(Pos pos,
            Pos isPrivate,
            java.lang.String label,
            java.util.List<Decl> decls,
            Expr returnDecl,
            Expr body)
     throws Err
Constructs a new predicate/function.

The first declaration's bound should be an expression with no free variables.
The second declaration's bound should be an expression with no free variables, except possibly the parameters in first declaration.
The third declaration's bound should be an expression with no free variables, except possibly the parameters in first two declarations.
etc.
The return declaration should have no free variables, except possibly the list of input parameters.

Parameters:
pos - - the original position in the file
isPrivate - - if nonnull, then the user intended this func/pred to be "private"
label - - the label for this predicate/function (does not have to be unique)
decls - - the list of parameter declarations (can be null or an empty list if this predicate/function has no parameters)
returnDecl - - the return declaration (null if this is a predicate rather than a function)
Throws:
ErrorType - if returnType!=null and returnType cannot be unambiguously typechecked to be a set/relation
ErrorSyntax - if the list of parameters contain duplicates
ErrorSyntax - if at least one of the parameter declaration contains a predicate/function call
ErrorSyntax - if this function's return type declaration contains a predicate/function call
Err
Method Detail

count

public int count()
Return the number of parameters.


get

public ExprVar get(int i)
Return the i-th parameter where i goes from 0 to count()-1


params

public java.util.List<ExprVar> params()
Return the list of all parameters.


setBody

public void setBody(Expr newBody)
             throws Err
Changes the method body. Precondition: The expression should have no free variables, except possibly the list of function parameters.

Throws:
ErrorSyntax - if newBody.mult!=0
ErrorType - if newBody cannot be unambiguously resolved
ErrorType - if newBody's type is incompatible with the original declared type of this predicate/function
Err

getBody

public Expr getBody()
Return the body of this predicate/function.
If the user has not called setBody() to set the body,
then the default body is "false" (if this is a predicate),
or the empty set/relation of the appropriate arity (if this is a function).


call

public Expr call(Expr... args)
Convenience method that calls this function with the given list of arguments.


toString

public final java.lang.String toString()
Returns a human-readable description for this predicate/function

Overrides:
toString in class java.lang.Object

pos

public final Pos pos()
Returns a Pos object representing the position of this Expr.

Overrides:
pos in class Browsable

span

public final Pos span()
Returns a Pos object representing the entire span of this Expr and all its subexpressions.

Overrides:
span in class Browsable

getHTML

public java.lang.String getHTML()
Returns the description (as HTML) to show for this node.

Specified by:
getHTML in class Browsable

getSubnodes

public java.util.List<? extends Browsable> getSubnodes()
Returns a list of subnodes for this node.

Specified by:
getSubnodes in class Browsable