gov.llnl.babel.symbols
public class Assertion extends ASTNode
Modifier and Type | Field and Description |
---|---|
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 |
Constructor and Description |
---|
Assertion(int type,
java.lang.String source,
java.lang.String tag,
Comment comment)
Create a new object.
|
Modifier and Type | Method and Description |
---|---|
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.
|
checkFrozen, clone, protectCollection, protectList, protectMap, protectSet
public static final int UNKNOWN
public static final int INVARIANT
public static final int REQUIRE
public static final int REQUIRE_ELSE
public static final int ENSURE
public static final int ENSURE_THEN
public static final java.lang.String[] s_names
public Assertion(int type, java.lang.String source, java.lang.String tag, Comment comment) throws AssertionException
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.AssertionException
- The exception raised if assertion type is invalid.public static boolean isValidAssertionType(int type)
public int getType()
public int getType(java.lang.String name)
name
- The name of the type of assertion whose type is to be
returned.public boolean isPrecondition()
public static boolean isPrecondition(int type)
public boolean isPostcondition()
public static boolean isPostcondition(int type)
public boolean isInvariant()
public static boolean isInvariant(int type)
public java.lang.String getTypeName()
public static java.lang.String getTypeName(int type)
public java.lang.String getSource()
public java.lang.String getTag()
public Comment getComment()
protected java.lang.String getExceptionPrefix(Extendable ext, Method m)
ext
- The interface or class that owns this expression.m
- The method that owns this expression.protected void ensureNoPostAssertions(AssertionExpression expr) throws AssertionException
expr
- The assertion expression being checked.AssertionException
- The exception raised if post-condition assertions present.public void setExpression(AssertionExpression expr) throws AssertionException
expr
- The assertion expression being checked.AssertionException
- The exception raised if type validation fails.public AssertionExpression getExpression()
public boolean isValid()
public void validateExpression(Extendable ext, Method m, boolean skip) throws AssertionException
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.AssertionException
- The exception that can be raised during the validation.public boolean hasPureClause()
public boolean hasResult()
public boolean hasResultOrArg()
public boolean hasResultOrOutArg(boolean outOnly)
outOnly
- TRUE if only concerned with output arguments that are
out only; FALSE otherwise.public boolean hasMethodCall()
public int getDefaultComplexity()
public boolean hasBuiltinMethod(int type)
public boolean hasUserDefinedMethod(boolean any)
public java.lang.String errorMessage()
public java.lang.String errorMessage(java.lang.String methName)
public java.util.ArrayList getArrayIterMacros(java.lang.String epvVar, int[] startInd)
public int getNumArrayIterMacrosByType(char type)
public java.lang.String cExpression(java.lang.String epvVar, int[] startInd)
public java.lang.String toString()
toString
in class java.lang.Object