public abstract class Extendable extends Symbol
Extendable
is a base class for SIDL symbols of type
class and interface. It brings together common methods and implementation
for both final classes. Class and interfaces have a set of methods and
interface inheritance in common. Classes have the additional property
that they can be extended by another class; that functionality is not
defined here. Many of the member functions take a boolean argument that
selects whether the method refers to this particular extendable only or
to this extendable and all of its parents in the SIDL inheritance system.
Constraints on the validity of methods added to this object must be checked
by the parser.
Key design goals include providing mechanisms to:
- ensure method lookups in O(1) by both long and short names;
- ensure fast return of abstract, static, non-static, local, and both
local and parent (or all) methods;
- ensure original ordering of methods preserved when returning lists;Constructor and Description |
---|
Extendable(SymbolID id,
int type,
Comment comment,
Context context)
Create an empty
Extendable object that will be constructed
by calls to other member functions. |
Extendable(SymbolID id,
int type,
Comment comment,
Metadata m,
Context context)
Create an empty
Extendable object that will be constructed
by calls to other member functions. |
Modifier and Type | Method and Description |
---|---|
void |
addInvAssertion(Assertion assertion)
Adds the assertion to the invariant clause of this Extendable.
|
void |
addMethod(Method method)
Add the specified new method to this object.
|
protected void |
addParentData(Extendable ext)
Protected method called by parents to add their relevant information,
such as methods, interfaces, references, and arrays to this object.
|
abstract void |
addParentInterface(Interface parent)
Add a new parent interface to this object.
|
void |
addRenamedMethod(Method newM,
Method oldM,
SymbolID old_sid)
For From clauses:Add the specified "new" method to the normal method lists, and the
"old" method to the d_renamed_parent_methods HashMap.
|
void |
freeze() |
java.util.List |
getAbstractAndLocalMethods()
Return all abstract methods and all local methods (both abstract and
concrete).
|
java.util.List |
getAbstractMethods()
Return the abstract methods for this class or interface, which
includes all parent classes and interfaces.
|
java.util.List |
getAllInvAssertions()
Returns a
List of Assertion s consisting of all
assertions in the local and inherited invariant clauses. |
java.util.List |
getAllParentsInOrder()
Return the parent interfaces and/or classes in hierarchical order
from top-most down to direct parents in an
List . |
java.util.List |
getAllPostAssertions(java.lang.String longname)
Return all postcondition assertions associated with the method in this
object, if there is one, in an
List with each element in
Assertion form. |
java.util.List |
getAllPreAssertions(java.lang.String longname)
Return all precondition assertions associated with the method in this
object, if there is one, in a
List with each entry being
in Assertion form. |
java.util.Set |
getAllSymbolReferences()
Return the
Set of all symbol references for this object, each
element of which is in SymbolID form. |
java.util.Set |
getBasicArrayRefs()
Return the
Set of basic array types for this object, each
element of the set being in SymbolID form. |
java.util.List |
getInvClause()
Returns a
List of Assertion s that make up the
global invariant clause. |
java.util.List |
getInvClause(boolean all)
Returns a
List of Assertion s that make up the
invariant clause. |
int |
getInvDefaultComplexity()
Returns the default complexity for the invariants; 0 if no invariants.
|
java.util.List |
getMethods(boolean all)
Return the methods in this interface as a
Collection . |
java.util.List |
getMethodsWithNonblocking(boolean all)
Return the methods in this interface as a
Collection . |
Method |
getNewMethod(java.lang.String oldM_name)
For From clauses: Take the FQN of the renamed method and return the new
Method.
|
java.util.Set |
getNewMethods()
For From clauses: Get all the new method objects of all the renamed
methods.
|
java.util.List |
getNonstaticMethods(boolean all)
Return the
Collection non-static methods in this interface. |
int |
getNumberOfMethods(boolean all)
Return the number of methods associated with this extendable.
|
int |
getNumberOfMethodsWithContracts()
Returns the number of this Extendable's methods with contract clauses.
|
java.util.Set |
getObjectDependencies() |
java.util.Collection |
getOverloadedMethodsByName(java.lang.String shortName)
Get all methods with the same short name as the passed in method name.
|
Interface |
getParentInterface(SymbolID id,
boolean all)
Return Interface if this class has the specified parent interface;
otherwise, return FALSE.
|
java.util.Collection |
getParentInterfaces(boolean all)
Return the parent interfaces in a
Collection . |
java.util.Collection |
getParents(boolean all)
Return the parent interfaces and/or class in a
Collection . |
Method |
getRenamedMethod(Method newM)
For From clauses: Find the Parent Method Object for a renamed method.
|
java.util.Set |
getRenamedMethods()
For From clauses: Get all the orginal Method Objects of all the renamed
methods.
|
SymbolID |
getRenamedMethodSymbolID(Method oldM)
For From clauses: Get the old old method's enclosing symbolID.
|
java.util.List |
getStaticMethods(boolean all)
Return the static methods in this interface as a
Collection . |
java.util.Set |
getSymbolReferences()
Return the
Set of symbol references for this object, each
element of which is in SymbolID form. |
int |
getTotalContractAssertions(java.lang.String longname)
Returns the total number of assertions contained within all contract
clauses associated with the method -- including invariant clauses.
|
int |
getTotalInvAssertions(boolean all)
Returns the number of assertions within invariant clause(s) of this
Extendable.
|
int |
getTotalPostAssertions(java.lang.String longname)
Return the total number of postcondition clause assertions for the
specified method, if present.
|
int |
getTotalPreAssertions(java.lang.String longname)
Return the number of precondition assertions associated with the method
in this object, if it is present.
|
boolean |
hasAncestor(Extendable ext)
Return TRUE if this object implements or extends the specified
Extendable directly or indirectly. |
boolean |
hasBuiltinMethodAssertion(int type)
Returns true if the specified reserved method call is present in any
of the assertions; otherwise, returns false.
|
boolean |
hasContracts()
Returns TRUE if the Extendable has contracts (that contain assertions);
otherwise, returns FALSE.
|
boolean |
hasExceptionThrowingMethod(boolean all)
Return TRUE if any of the methods throws an exception; otherwise, return
FALSE.
|
boolean |
hasInvClause(boolean all)
Returns TRUE if this Extendable has any assertions in its invariant
clause; otherwise, returns FALSE.
|
boolean |
hasMethodByLongName(java.lang.String name,
boolean all)
Return TRUE if the specified method exists by long name; otherwise,
return FALSE.
|
boolean |
hasMethodByShortName(java.lang.String name,
boolean all)
Return TRUE if the specified method exists by short name; otherwise,
return FALSE.
|
boolean |
hasParentInterface(SymbolID id,
boolean all)
Return TRUE if this class has the specified parent interface; otherwise,
return FALSE.
|
boolean |
hasParentInterfaces()
Return true if this extendable inherts from interfaces.
|
boolean |
hasPostconditions()
Returns TRUE if the Extendable has any postconditions(), explicit or
inherited; otherwise, returns FALSE.
|
boolean |
hasPreconditions()
Returns TRUE if the Extendable has any preconditions(), explicit or
inherited; otherwise, returns FALSE.
|
abstract boolean |
hasStaticMethod(boolean all)
Return TRUE if any of the methods are static methods; otherwise,
return FALSE.
|
boolean |
hasStruct()
Returns TRUE if the Extendable has a method with an argument or return
value of type struct and FALSE otherwise.
|
boolean |
invHasMethodCall()
Return TRUE if the invariant clause includes a method call; FALSE
otherwise.
|
boolean |
invHasMethodCall(java.lang.String name)
Return TRUE if the invariant clause includes a method call to the
specified method; FALSE otherwise.
|
boolean |
invHasResultOrArg()
Return TRUE if the invariants include a Result or a method argument; FALSE
otherwise.
|
abstract boolean |
isAbstract()
Return TRUE if this object contains any abstract methods; otherwise,
return FALSE.
|
abstract boolean |
isInterface()
Return TRUE if this object represents an interface, FALSE if it is a
class.
|
boolean |
isLocal(Method m)
Return
true if and only if the method given is locally
defined in this extendable. |
Method |
lookupMethodByLongName(java.lang.String name,
boolean all)
Return the
Method with the specified long method name. |
java.util.Collection |
lookupMethodByShortName(java.lang.String name,
boolean all)
Return the
Collection of methods, each in Method
form, that are found to have the specified short method name, if any. |
boolean |
methodWasRenamed(Method newM)
For From clauses: Check a parent has a different name for this method.
|
void |
validateContracts(boolean all,
boolean skip)
Validate contracts associated with this object.
|
void |
validateInvClause(boolean all,
boolean skip)
Validates the invariant clause(s).
|
void |
validatePostClause(boolean all,
boolean skip)
Validate postcondition clauses associated with this object.
|
void |
validatePostClause(Method meth,
boolean all,
boolean skip)
Validate the postcondition clause associated with this object and the
specified method.
|
void |
validatePostClause(java.lang.String longname,
boolean all,
boolean skip)
Validate the postcondition assertions associated with this object and
the specified method.
|
void |
validatePreClause(boolean all,
boolean skip)
Validate the precondition clauses.
|
void |
validatePreClause(Method meth,
boolean all,
boolean skip)
Validate the precondition clause(s) for the specified method.
|
void |
validatePreClause(java.lang.String longname,
boolean all,
boolean skip)
Validate the precondition clauses for the specified method.
|
addMetadata, getAttribute, getAttributes, getComment, getDepth, getMetadata, getSymbolID, getSymbolType, getSymbolTypeString, getUserSpecified, hasAttribute, isClass, isPackage, isStruct, minimumDepth, removeAttribute, setAttribute, setAttribute, setComment, setUserSpecified
compareTo, equals, fromXML, getFullName, getShortName, getShortName, getSymbolName, getVersion, hashCode, setFromXML
checkFrozen, clone, protectCollection, protectList, protectMap, protectSet
public Extendable(SymbolID id, int type, Comment comment, Context context)
Extendable
object that will be constructed
by calls to other member functions.id
- The symbol id of the new objecttype
- The value of the type of the new objectcomment
- The comment associated with the objectpublic Extendable(SymbolID id, int type, Comment comment, Metadata m, Context context)
Extendable
object that will be constructed
by calls to other member functions.id
- The symbol id of the new objecttype
- The value of the type of the new objectcomment
- The comment associated with the objectm
- Object metadatapublic abstract boolean isAbstract()
public abstract boolean isInterface()
isInterface
in class Symbol
public void addMethod(Method method)
method
- The method to be added to this objectpublic void addRenamedMethod(Method newM, Method oldM, SymbolID old_sid)
public Method getRenamedMethod(Method newM)
public java.util.Set getRenamedMethods()
public java.util.Set getNewMethods()
public boolean methodWasRenamed(Method newM)
public SymbolID getRenamedMethodSymbolID(Method oldM)
public Method getNewMethod(java.lang.String oldM_name)
public int getNumberOfMethods(boolean all)
all
- If TRUE, then return the number of local and parent methods;
otherwise, return the number of local methods only.public int getNumberOfMethodsWithContracts() throws CodeGenerationException
CodeGenerationException
public java.util.List getMethods(boolean all)
Collection
.
Each element in the collection is of type Method
.all
- If TRUE, then return local and parent methods; otherwise,
return only local methods.public java.util.List getMethodsWithNonblocking(boolean all) throws CodeGenerationException
Collection
.
Each element in the collection is of type Method
.
This list includes methods NONBLOCKING_SEND and NONBLOCKING_RECV
methods spawned in response to NONBLOCKING methods.all
- If TRUE, then return local and parent methods; otherwise,
return only local methods.CodeGenerationException
public java.util.List getNonstaticMethods(boolean all)
Collection
non-static methods in this interface.
Each element in the collection is of type Method
.all
- If TRUE, then return local and parent non-static methods;
otherwise, return only local non-static methods.public java.util.List getStaticMethods(boolean all)
Collection
.
Each element in the collection is of type Method
.all
- If TRUE, then return local and parent static methods;
otherwise, return only local static methods.public java.util.List getAbstractMethods()
Method
.public java.util.List getAbstractAndLocalMethods()
public boolean isLocal(Method m)
true
if and only if the method given is locally
defined in this extendable.m
- The method of interest.true
if m
is locally defined
in this Extendable.public Method lookupMethodByLongName(java.lang.String name, boolean all)
Method
with the specified long method name.
If there is none, return null.name
- The short method name for the method to be located.all
- If TRUE then all local and parent methods are to
be searched; otherwise, only local methods are to
be searched.public java.util.Collection lookupMethodByShortName(java.lang.String name, boolean all)
Collection
of methods, each in Method
form, that are found to have the specified short method name, if any.
If none are found, then return null.name
- The short method name for the method to be located.all
- If TRUE then all local and parent methods are to
be searched; otherwise, only local methods are to
be searched.public boolean hasMethodByLongName(java.lang.String name, boolean all)
name
- The long method name for the method to be located.all
- If TRUE then all local and parent methods are to
be searched; otherwise, only local methods are to
be searched.public boolean hasMethodByShortName(java.lang.String name, boolean all)
name
- The short method name to be locatedall
- If TRUE, then all local and parent methods are to be
searched; otherwise, only local methods are to be
searchedpublic abstract boolean hasStaticMethod(boolean all)
all
- If TRUE, then local and parent methods are to be searched;
otherwise, only local methods are to be searched.public boolean hasExceptionThrowingMethod(boolean all)
all
- If TRUE, then local and parent methods are to be searched;
otherwise, only local methods are to be searched.public abstract void addParentInterface(Interface parent)
Class
and Interface
subclasses.parent
- The parent interface to be added to this object.public boolean hasParentInterfaces()
public java.util.Collection getParentInterfaces(boolean all)
Collection
. Each
member of the collection is an Interface
.all
- If TRUE, then all parents are to be returned; otherwise,
only direct parents are to be returned.public java.util.List getAllParentsInOrder() throws CodeGenerationException
List
.
Each member of the list is an Extendable
and there
are NO duplicates.
Does a DFS to return ancestors in "reverse" topolgical order.
by Jim LeekCodeGenerationException
public java.util.Collection getParents(boolean all)
Collection
.
Each member of the collection is an Extendable
. No
duplicate entries are returned in the collection.all
- If TRUE, all ancestors are to be returned; otherwise, only
direct parents.public boolean hasAncestor(Extendable ext)
Extendable
directly or indirectly. Otherwise, return
FALSE.ext
- The potential ancestorpublic boolean hasParentInterface(SymbolID id, boolean all)
id
- The parent interface to be locatedall
- Indicator of whether all parents (TRUE) or only direct
parents (FALSE) are to be searchedpublic Interface getParentInterface(SymbolID id, boolean all)
id
- The parent interface to be locatedall
- Indicator of whether all parents (TRUE) or only direct
parents (FALSE) are to be searchedpublic java.util.Set getSymbolReferences()
Set
of symbol references for this object, each
element of which is in SymbolID
form. These are
defined as all references for this object as well as its parents.
The set of references includes this symbol name.getSymbolReferences
in class Symbol
public java.util.Set getAllSymbolReferences()
Set
of all symbol references for this object, each
element of which is in SymbolID
form. Note the references
include those from this object's parents.getAllSymbolReferences
in class Symbol
public java.util.Set getBasicArrayRefs()
Set
of basic array types for this object, each
element of the set being in SymbolID
form.getBasicArrayRefs
in class Symbol
protected void addParentData(Extendable ext)
ext
- The parent whose methods and related information are to be
addedpublic java.util.Collection getOverloadedMethodsByName(java.lang.String shortName)
public java.util.Set getObjectDependencies() throws CodeGenerationException
CodeGenerationException
public void addInvAssertion(Assertion assertion) throws AssertionException
assertion
- The assertion to be added to this invariant clause.AssertionException
- The exception raised if the assertion cannot be added.public java.util.List getAllInvAssertions() throws CodeGenerationException
List
of Assertion
s consisting of all
assertions in the local and inherited invariant clauses.CodeGenerationException
public java.util.List getInvClause(boolean all) throws CodeGenerationException
List
of Assertion
s that make up the
invariant clause.all
- If TRUE then return local and inherited invariant
assertions; otherwise, return local invariants.CodeGenerationException
public java.util.List getInvClause() throws CodeGenerationException
List
of Assertion
s that make up the
global invariant clause.CodeGenerationException
public int getTotalInvAssertions(boolean all) throws CodeGenerationException
all
- If TRUE then return the number in inherited clauses;
otherwise, return only the number in the local clause.CodeGenerationException
public boolean hasInvClause(boolean all) throws CodeGenerationException
all
- If TRUE then check inherited invariant clauses; otherwise,
only check the local clause.CodeGenerationException
public void validateInvClause(boolean all, boolean skip) throws AssertionException, CodeGenerationException
all
- If TRUE then validate local and inherited invariant
clauses; otherwise, only validate the local clause.skip
- If TRUE then will skip the validation process for
assertions already marked valid.AssertionException
- The exception raised if errors are detected.CodeGenerationException
public boolean invHasMethodCall() throws CodeGenerationException
CodeGenerationException
public boolean invHasMethodCall(java.lang.String name) throws CodeGenerationException
CodeGenerationException
public boolean invHasResultOrArg() throws CodeGenerationException
CodeGenerationException
public int getInvDefaultComplexity() throws CodeGenerationException
CodeGenerationException
public boolean hasContracts() throws CodeGenerationException
CodeGenerationException
public boolean hasStruct() throws CodeGenerationException
CodeGenerationException
public int getTotalContractAssertions(java.lang.String longname) throws CodeGenerationException
longname
- The long name of the desired method.CodeGenerationException
public boolean hasPreconditions() throws CodeGenerationException
CodeGenerationException
public int getTotalPreAssertions(java.lang.String longname) throws CodeGenerationException
longname
- The long name of the method the number of whose
precondition assertions is to be returned.CodeGenerationException
public java.util.List getAllPreAssertions(java.lang.String longname) throws CodeGenerationException
List
with each entry being
in Assertion
form. Will return an empty list if no such
method is in this object's hierarchy.
WARNING:
There is no attempt at this point to optimize the precondition
assertions. That is, duplicate assertions are NOT removed.longname
- The long name of the method whose precondition
assertions are to be returned.CodeGenerationException
public void validatePreClause(Method meth, boolean all, boolean skip) throws AssertionException, CodeGenerationException
meth
- The method whose precondition clauses are to be validated.all
- If TRUE then validate local and inherited precondition
clauses; otherwise, only validate the local clause.skip
- If TRUE then will skip the validation process for
assertions already marked valid.AssertionException
- The exception raised if errors are detected.CodeGenerationException
public void validatePreClause(java.lang.String longname, boolean all, boolean skip) throws AssertionException, CodeGenerationException
longname
- The long name of the method whose precondition
clauses are to be validated.all
- If TRUE then validate local and inherited precondition
clauses; otherwise, only validate the local clause.skip
- If TRUE then will skip the validation process for
assertions already marked valid.AssertionException
- The exception raised if errors are detected.CodeGenerationException
public void validatePreClause(boolean all, boolean skip) throws AssertionException, CodeGenerationException
all
- If TRUE then validate local and inherited precondition
clauses; otherwise, only validate the local clause.skip
- If TRUE then will skip the validation process for
assertions already marked valid.AssertionException
- The exception raised if errors are detected.CodeGenerationException
public boolean hasPostconditions() throws CodeGenerationException
CodeGenerationException
public int getTotalPostAssertions(java.lang.String longname) throws CodeGenerationException
longname
- The long name of the desired method.CodeGenerationException
public java.util.List getAllPostAssertions(java.lang.String longname) throws CodeGenerationException
List
with each element in
Assertion
form. Will return an empty list if no such
method in this object's hierarchy.
WARNING:
There is no attempt at this point to optimize the postcondition
assertions. That is, duplicate assertions are NOT removed.longname
- The long name of the method whose postcondition
assertions are to be returned.CodeGenerationException
public void validatePostClause(Method meth, boolean all, boolean skip) throws AssertionException, CodeGenerationException
meth
- The method whose postcondition assertions are to be
validated.all
- If TRUE then validate local and inherited postcondition
clauses; otherwise, only validate the local clause.skip
- If TRUE then will skip the validation process for
assertions already marked valid.all
- If TRUE then all postcondition assertions of the method
will be validated; otherwise, only the locally defined
ones will.skip
- If TRUE then will skip the validation process if the
expression has already been marked as valid.AssertionException
- The exception raised if errors are detected.CodeGenerationException
public void validatePostClause(java.lang.String longname, boolean all, boolean skip) throws AssertionException, CodeGenerationException
longname
- The long name of the method whose postcondition
assertions are to be validated.all
- If TRUE then validate local and inherited postcondition
clauses; otherwise, only validate the local clause.skip
- If TRUE then will skip the validation process for
assertions already marked valid.all
- If TRUE then all postcondition assertions of the
method will be validated; otherwise, only the locally
defined ones will.skip
- If TRUE then will skip the validation process if the
expression has already been marked as valid.AssertionException
- The exception raised if errors are detected.CodeGenerationException
public void validatePostClause(boolean all, boolean skip) throws AssertionException, CodeGenerationException
skip
- If TRUE then will skip the validation process if the
expression has already been marked as valid.all
- If TRUE then validate local and inherited postcondition
clauses; otherwise, only validate the local clause.skip
- If TRUE then will skip the validation process for
assertions already marked valid.all
- If TRUE then all postcondition clauses of the method will
be validated; otherwise, only the locally defined ones will.AssertionException
- The exception raised if errors are detected.CodeGenerationException
public void validateContracts(boolean all, boolean skip) throws AssertionException, CodeGenerationException
all
- If TRUE then validate local and inherited clauses;
otherwise, only validate local clauses.skip
- If TRUE then will skip the validation process for
assertions already marked valid.skip
- If TRUE then will skip the validation process if the
expression has already been marked as valid.all
- If TRUE then all assertions including those for all
associated methods will be validated; otherwise, only
validate the locally defined ones.AssertionException
- The exception raised if errors are detected.CodeGenerationException
public boolean hasBuiltinMethodAssertion(int type) throws CodeGenerationException
CodeGenerationException