gov.llnl.babel.symbols
Class Assertion

java.lang.Object
  extended by gov.llnl.babel.symbols.ASTNode
      extended by gov.llnl.babel.symbols.Assertion
All Implemented Interfaces:
java.lang.Cloneable

public class Assertion
extends ASTNode


Field Summary
static int ENSURE
           
static int ENSURE_THEN
           
static int INVARIANT
           
static int REQUIRE
           
static int REQUIRE_ELSE
           
static java.lang.String[] s_names
           
static int UNKNOWN
           
 
Fields inherited from class gov.llnl.babel.symbols.ASTNode
d_frozen
 
Constructor Summary
Assertion(int type, java.lang.String source, java.lang.String tag, Comment comment)
          Create a new object.
 
Method Summary
 java.lang.String cExpression(java.lang.String epvVar, int[] startInd)
          Return the C version of the expression used to check for violation.
protected  void ensureNoPostAssertions(AssertionExpression expr)
          Ensure the expression does not contain any (sub)expressions specifically for post-condition assertions.
 java.lang.String errorMessage()
          Return the error message associated with a failure of this assertion.
 java.lang.String errorMessage(java.lang.String methName)
          Return the error message associated with a failure of this assertion, appending the given mehod name to the error message.
 void freeze()
           
 java.util.ArrayList getArrayIterMacros(java.lang.String epvVar, int[] startInd)
          Return the list of array iteration macro messages, if any.
 Comment getComment()
          Return the comment, if any, associated with this list of object states.
 int getDefaultComplexity()
          Returns the default complexity of the expression.
protected  java.lang.String getExceptionPrefix(Extendable ext, Method m)
          Return the prefix for exception messages based on the specified extendable and method.
 AssertionExpression getExpression()
          Return the assertion expression.
 int getNumArrayIterMacrosByType(char type)
          Returns the number of macros supported by this assertion of the specified type.
 java.lang.String getSource()
          Return the source associated with this assertion.
 java.lang.String getTag()
          Return the tag associated with this list of object states.
 int getType()
          Return the type of the assertion.
 int getType(java.lang.String name)
          Return the type of the assertion specified by name.
 java.lang.String getTypeName()
          Return the name of the type of the assertion.
static java.lang.String getTypeName(int type)
          Return the name of the specified type of the assertion, if valid; otherwise, return NULL.
 boolean hasBuiltinMethod(int type)
          Return TRUE if the assertion's expression is, or has, the specified built-in method call; otherwise, return FALSE.
 boolean hasMethodCall()
          Return TRUE if the expression is, or has, at least one method call; otherwise, return FALSE.
 boolean hasPureClause()
          Return TRUE if a pure clause is found within the expression; otherwise, return FALSE.
 boolean hasResult()
          Return TRUE if a result clause is found within the expression; otherwise, return FALSE.
 boolean hasResultOrArg()
          Return TRUE if a result clause or method argument is found within the expression; otherwise, return FALSE.
 boolean hasResultOrOutArg(boolean outOnly)
          Return TRUE if a result clause or output argument is found within the expression; otherwise, return FALSE.
 boolean hasUserDefinedMethod(boolean any)
          Return TRUE if the assertion's expression has a method AND the method is any user-defined method (when any is TRUE) or it is an user-defined method with a throws clause (if any is FALSE); otherwise, return FALSE.
 boolean isInvariant()
          Return TRUE if an invariant; otherwise, return FALSE.
static boolean isInvariant(int type)
          Return TRUE if the specified type is an invariant; otherwise, return FALSE.
 boolean isPostcondition()
          Return TRUE if a postcondition; otherwise, return FALSE.
static boolean isPostcondition(int type)
          Return TRUE if the specified type is a postcondition; otherwise, return FALSE.
 boolean isPrecondition()
          Return TRUE if a precondition; otherwise, return FALSE.
static boolean isPrecondition(int type)
          Return TRUE if the specified type is a precondition; otherwise, return FALSE.
 boolean isValid()
          Return TRUE if the expression has been validated; otherwise, return FALSE.
static boolean isValidAssertionType(int type)
          Return TRUE if the type is valid; otherwise, return FALSE.
 void setExpression(AssertionExpression expr)
          Set the assertion expression.
 java.lang.String toString()
          Return the stringified version of the expression (in SIDL form) BUT without the comment.
 void validateExpression(Extendable ext, Method m, boolean skip)
          Validate the assertion expression within the context of the given extendable and optional method.
 
Methods inherited from class gov.llnl.babel.symbols.ASTNode
checkFrozen, clone, protectCollection, protectList, protectMap, protectSet
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNKNOWN

public static final int UNKNOWN
See Also:
Constant Field Values

INVARIANT

public static final int INVARIANT
See Also:
Constant Field Values

REQUIRE

public static final int REQUIRE
See Also:
Constant Field Values

REQUIRE_ELSE

public static final int REQUIRE_ELSE
See Also:
Constant Field Values

ENSURE

public static final int ENSURE
See Also:
Constant Field Values

ENSURE_THEN

public static final int ENSURE_THEN
See Also:
Constant Field Values

s_names

public static final java.lang.String[] s_names
Constructor Detail

Assertion

public Assertion(int type,
                 java.lang.String source,
                 java.lang.String tag,
                 Comment comment)
          throws AssertionException
Create a new object.

Parameters:
type - The type of the assertion.
source - The owning interface or class. For use in generated debug messages.
tag - The tag, if any, associated with the assertion. For use in generated debug messags.
comment - The comment, if any, associated with the assertion.
Throws:
AssertionException - The exception raised if assertion type is invalid.
Method Detail

isValidAssertionType

public static boolean isValidAssertionType(int type)
Return TRUE if the type is valid; otherwise, return FALSE.


getType

public int getType()
Return the type of the assertion.


getType

public int getType(java.lang.String name)
Return the type of the assertion specified by name.

Parameters:
name - The name of the type of assertion whose type is to be returned.

isPrecondition

public boolean isPrecondition()
Return TRUE if a precondition; otherwise, return FALSE.


isPrecondition

public static boolean isPrecondition(int type)
Return TRUE if the specified type is a precondition; otherwise, return FALSE.


isPostcondition

public boolean isPostcondition()
Return TRUE if a postcondition; otherwise, return FALSE.


isPostcondition

public static boolean isPostcondition(int type)
Return TRUE if the specified type is a postcondition; otherwise, return FALSE.


isInvariant

public boolean isInvariant()
Return TRUE if an invariant; otherwise, return FALSE.


isInvariant

public static boolean isInvariant(int type)
Return TRUE if the specified type is an invariant; otherwise, return FALSE.


getTypeName

public java.lang.String getTypeName()
Return the name of the type of the assertion. It is assumed the type is valid/known thanks to the check in the constructor.


getTypeName

public static java.lang.String getTypeName(int type)
Return the name of the specified type of the assertion, if valid; otherwise, return NULL.


getSource

public java.lang.String getSource()
Return the source associated with this assertion.


getTag

public java.lang.String getTag()
Return the tag associated with this list of object states.


getComment

public Comment getComment()
Return the comment, if any, associated with this list of object states.


getExceptionPrefix

protected java.lang.String getExceptionPrefix(Extendable ext,
                                              Method m)
Return the prefix for exception messages based on the specified extendable and method.

Parameters:
ext - The interface or class that owns this expression.
m - The method that owns this expression.

ensureNoPostAssertions

protected void ensureNoPostAssertions(AssertionExpression expr)
                               throws AssertionException
Ensure the expression does not contain any (sub)expressions specifically for post-condition assertions. For example, the assertion should not contain a PURE or RESULT clause.

Parameters:
expr - The assertion expression being checked.
Throws:
AssertionException - The exception raised if post-condition assertions present.

setExpression

public void setExpression(AssertionExpression expr)
                   throws AssertionException
Set the assertion expression. Note this is added during syntactic parsing so not all of the information for evaluating the validity of the expression is available (e.g., function return values). Hence, the validity of the expression itself is left as a separate step in the process once the symbols for the associated extendable are created. Assumptions: 1) requiresMethodContext() returns TRUE ONLY if the assertion expression really requires method context. For example, an expression that contains a method call with no arguments only requires the extendable context, NOT the method context. Same is TRUE if the arguments are literals. However, method context is required if one or more of the arguments are identifiers.

Parameters:
expr - The assertion expression being checked.
Throws:
AssertionException - The exception raised if type validation fails.

getExpression

public AssertionExpression getExpression()
Return the assertion expression.


isValid

public boolean isValid()
Return TRUE if the expression has been validated; otherwise, return FALSE.


validateExpression

public void validateExpression(Extendable ext,
                               Method m,
                               boolean skip)
                        throws AssertionException
Validate the assertion expression within the context of the given extendable and optional method.

Parameters:
ext - The interface or class that owns this expression.
m - The method that owns this expression.
skip - If TRUE, will skip the validation process if the expression has already been marked as being valid.
Throws:
AssertionException - The exception that can be raised during the validation.

hasPureClause

public boolean hasPureClause()
Return TRUE if a pure clause is found within the expression; otherwise, return FALSE.


hasResult

public boolean hasResult()
Return TRUE if a result clause is found within the expression; otherwise, return FALSE.


hasResultOrArg

public boolean hasResultOrArg()
Return TRUE if a result clause or method argument is found within the expression; otherwise, return FALSE.


hasResultOrOutArg

public boolean hasResultOrOutArg(boolean outOnly)
Return TRUE if a result clause or output argument is found within the expression; otherwise, return FALSE.

Parameters:
outOnly - TRUE if only concerned with output arguments that are out only; FALSE otherwise.

hasMethodCall

public boolean hasMethodCall()
Return TRUE if the expression is, or has, at least one method call; otherwise, return FALSE.


getDefaultComplexity

public int getDefaultComplexity()
Returns the default complexity of the expression.


hasBuiltinMethod

public boolean hasBuiltinMethod(int type)
Return TRUE if the assertion's expression is, or has, the specified built-in method call; otherwise, return FALSE.


hasUserDefinedMethod

public boolean hasUserDefinedMethod(boolean any)
Return TRUE if the assertion's expression has a method AND the method is any user-defined method (when any is TRUE) or it is an user-defined method with a throws clause (if any is FALSE); otherwise, return FALSE.


errorMessage

public java.lang.String errorMessage()
Return the error message associated with a failure of this assertion.


errorMessage

public java.lang.String errorMessage(java.lang.String methName)
Return the error message associated with a failure of this assertion, appending the given mehod name to the error message. (ToDo...This is only necessary until it gets added properly by the parser!)


getArrayIterMacros

public java.util.ArrayList getArrayIterMacros(java.lang.String epvVar,
                                              int[] startInd)
Return the list of array iteration macro messages, if any. Each message is a string where the first character indicates the return type associated with the iteration. The remaining characters will be the actual macro invocation.


getNumArrayIterMacrosByType

public int getNumArrayIterMacrosByType(char type)
Returns the number of macros supported by this assertion of the specified type. Valid types are given in MethodCall.java.


cExpression

public java.lang.String cExpression(java.lang.String epvVar,
                                    int[] startInd)
Return the C version of the expression used to check for violation.


toString

public java.lang.String toString()
Return the stringified version of the expression (in SIDL form) BUT without the comment. That must be retrieved separately.

Overrides:
toString in class java.lang.Object

freeze

public void freeze()
Overrides:
freeze in class ASTNode