ROSE 2.23.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Rose::Common::Analysis::AbstractCompatibilityBridge Class Referenceabstract

Description

This is a stateless, abstract base class for implementing some functionality required by the class hierarchy analysis onto different subsets of the AST.

e.g., C++ analysis, JVM analysis, ...

Definition at line 20 of file AbstractCompatibilityBridge.h.

#include <Rose/Common/Analysis/AbstractCompatibilityBridge.h>

Inheritance diagram for Rose::Common::Analysis::AbstractCompatibilityBridge:
Inheritance graph
[legend]

Public Member Functions

 AbstractCompatibilityBridge ()=default
 Constructs a stateless compatibility bridge.
 
virtual ~AbstractCompatibilityBridge ()=default
 Destroys a compatibility bridge through the base type.
 
virtual std::string nameOf (FunctionKeyType key) const =0
 returns the source name of the function represented by key.
 
virtual std::string nameOf (ClassKeyType key) const =0
 returns the source name of the class represented by key.
 
virtual bool isAbstract (ClassKeyType key) const =0
 returns true if the class represented by key is an abstract class.
 
virtual bool isPureVirtual (FunctionKeyType key) const =0
 returns true if the class represented by key is an abstract function.
 
virtual int compareNames (FunctionKeyType lhs, FunctionKeyType rhs) const =0
 compares the source name of the functions lhs and rhs.
 
virtual int compareFunctionsByType (FunctionKeyType lhs, FunctionKeyType rhs, bool exclReturnType=true) const =0
 compares the canonical types of functions lhs and rhs
 
virtual FunctionTypeRelation haveSameOrCovariantReturn (const ClassAnalysis &classes, FunctionKeyType basId, FunctionKeyType drvId) const =0
 tests if drvId has the same or covariant return type with respect to basId
 
virtual void extractFromMemoryPool (ClassAnalysis &classes) const =0
 extracts class information from the memory pool if available
 
virtual void extractFromProject (ClassAnalysis &classes, ASTRootType root) const =0
 extracts class by walking the AST rooted at root.
 
virtual LanguageSpecificFn languageSpecificProcessing () const =0
 returns a function that handles language specific post-processing for the extract classes.
 
virtual void inheritanceEdges (ClassKeyType clkey, std::function< void(ClassKeyType, ClassKeyType, bool)> fn) const =0
 calls the callback function fn(derived, base, isvirtual) for all direct base classes of clkey
 
virtual DataMemberType typeOf (VariableKeyType var) const =0
 returns the type of a non-static data member var.
 
virtual bool isAutoGeneratable (const ClassAnalysis &classes, ClassKeyType clkey, FunctionKeyType fnkey) const
 returns whether a function with fnkey's signature can be implicitly generated in clkey.
 
virtual std::uint32_t languageStandard () const
 returns the active language standard as a C++ __cplusplus-style value when available.
 
virtual bool inheritedMethodsImplementVirtualBaseMethods () const
 returns whether a method inherited along the non-virtual inheritance chain implements an otherwise unimplemented function of a virtual base.
 
virtual bool isInheritableImplementation (FunctionKeyType fnkey) const
 returns whether the inherited function fnkey qualifies as an implementation of a virtual base function (see inheritedMethodsImplementVirtualBaseMethods).
 
virtual bool canOverride (FunctionKeyType drv, FunctionKeyType bas) const
 returns whether drv may override bas under language rules beyond name and signature, such as access control.
 
virtual bool isFinal (FunctionKeyType fnkey) const
 returns whether the virtual function fnkey cannot be overridden.
 
virtual void explicitOverrides (const ClassAnalysis &classes, ClassKeyType cls, std::function< void(FunctionKeyType, FunctionKeyType)> fn) const
 reports override relations that are declared explicitly instead of being derived from names and signatures.
 
virtual bool canOverrideInContext (const ClassAnalysis &classes, ClassKeyType drvClass, FunctionKeyType drv, ClassKeyType basClass, FunctionKeyType bas) const
 returns whether drv, declared in drvClass, may override bas, declared in basClass, with knowledge of the classes in between.
 

Member Function Documentation

◆ nameOf() [1/2]

virtual std::string Rose::Common::Analysis::AbstractCompatibilityBridge::nameOf ( FunctionKeyType  key) const
pure virtual

returns the source name of the function represented by key.

Parameters
keyabstract function key to name.
Returns
frontend-specific source name for key.

Implemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility, Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility, and Rose::Source::Analysis::CppCompatibility.

◆ nameOf() [2/2]

virtual std::string Rose::Common::Analysis::AbstractCompatibilityBridge::nameOf ( ClassKeyType  key) const
pure virtual

returns the source name of the class represented by key.

Parameters
keyabstract class key to name.
Returns
frontend-specific source name for key.

Implemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility, Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility, and Rose::Source::Analysis::CppCompatibility.

◆ isAbstract()

virtual bool Rose::Common::Analysis::AbstractCompatibilityBridge::isAbstract ( ClassKeyType  key) const
pure virtual

returns true if the class represented by key is an abstract class.

Parameters
keyabstract class key to test.
Returns
true if key denotes an abstract class.

Implemented in Rose::Source::Analysis::CppCompatibility, Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility, and Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility.

◆ isPureVirtual()

virtual bool Rose::Common::Analysis::AbstractCompatibilityBridge::isPureVirtual ( FunctionKeyType  key) const
pure virtual

returns true if the class represented by key is an abstract function.

Parameters
keyabstract function key to test.
Returns
true if key denotes an abstract member function.
Note
abstract member functions are called pure virtual in C++

Implemented in Rose::Source::Analysis::CppCompatibility, Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility, and Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility.

◆ compareNames()

virtual int Rose::Common::Analysis::AbstractCompatibilityBridge::compareNames ( FunctionKeyType  lhs,
FunctionKeyType  rhs 
) const
pure virtual

compares the source name of the functions lhs and rhs.

Parameters
lhsleft-hand side function
rhsright-hand side function
Returns
-1 iff nameOf(lhs) < nameOf(rhs) 0 iff nameOf(lhs) == nameOf(rhs) 1 iff nameOf(lhs) > nameOf(rhs)
Note
abstract member functions are called pure virtual in C++

Implemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility, Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility, and Rose::Source::Analysis::CppCompatibility.

◆ compareFunctionsByType()

virtual int Rose::Common::Analysis::AbstractCompatibilityBridge::compareFunctionsByType ( FunctionKeyType  lhs,
FunctionKeyType  rhs,
bool  exclReturnType = true 
) const
pure virtual

compares the canonical types of functions lhs and rhs

Parameters
lhsleft-hand side function
rhsright-hand side function
exclReturnTypeif true the return types of lhs and rhs are not considered (though the return types of potential arguments and return types are). This can be useful for obtaining equality of functions that have covariant return types.
Returns
0 iff lhs and rhs have the same type 1 iff lhs > rhs -1 iff lhs < rhs

if lhs and rhs are not equal, the ordering is not specified but produces consistent results

Implemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility, Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility, and Rose::Source::Analysis::CppCompatibility.

◆ haveSameOrCovariantReturn()

virtual FunctionTypeRelation Rose::Common::Analysis::AbstractCompatibilityBridge::haveSameOrCovariantReturn ( const ClassAnalysis &  classes,
FunctionKeyType  basId,
FunctionKeyType  drvId 
) const
pure virtual

tests if drvId has the same or covariant return type with respect to basId

Parameters
classesthe extracted class analysis
basIdID of a function in a base class
drvIdID of a function in a derived class
Returns
the return-type relationship between basId and drvId.

The function only checks the return type, and does not check whether the classes in which the functions drvId and basId are defined are in a inheritance relationship.

Implemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility, Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility, and Rose::Source::Analysis::CppCompatibility.

◆ extractFromMemoryPool()

virtual void Rose::Common::Analysis::AbstractCompatibilityBridge::extractFromMemoryPool ( ClassAnalysis &  classes) const
pure virtual

extracts class information from the memory pool if available

Parameters
classesanalysis object to populate with discovered classes.
  1. For each class in the memory pool an entry in classes is created
  2. Adds all member functions declared in a class to the class representation CRep
  3. Adds all data members declared in a class to the class representation CRep

Implemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility, Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility, and Rose::Source::Analysis::CppCompatibility.

◆ extractFromProject()

virtual void Rose::Common::Analysis::AbstractCompatibilityBridge::extractFromProject ( ClassAnalysis &  classes,
ASTRootType  root 
) const
pure virtual

extracts class by walking the AST rooted at root.

Parameters
classesanalysis object to populate with discovered classes.
rootabstract key for the AST root to traverse.
  1. For each known class an entry in classes is created
  2. Adds all member functions declared in a class to the class representation CRep
  3. Adds all data members declared in a class to the class representation CRep

Implemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility, Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility, and Rose::Source::Analysis::CppCompatibility.

◆ languageSpecificProcessing()

virtual LanguageSpecificFn Rose::Common::Analysis::AbstractCompatibilityBridge::languageSpecificProcessing ( ) const
pure virtual

returns a function that handles language specific post-processing for the extract classes.

Returns
a function post-processing all classes

a use case is applying additional analysis rules after the common inheritance relationships have been computed.

Implemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility, Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility, and Rose::Source::Analysis::CppCompatibility.

◆ inheritanceEdges()

virtual void Rose::Common::Analysis::AbstractCompatibilityBridge::inheritanceEdges ( ClassKeyType  clkey,
std::function< void(ClassKeyType, ClassKeyType, bool)>  fn 
) const
pure virtual

calls the callback function fn(derived, base, isvirtual) for all direct base classes of clkey

Parameters
clkeyclass whose direct inheritance edges are requested.
fncallback invoked for each edge as (derived, base, isVirtual).

◆ typeOf()

virtual DataMemberType Rose::Common::Analysis::AbstractCompatibilityBridge::typeOf ( VariableKeyType  var) const
pure virtual

returns the type of a non-static data member var.

Parameters
vardata member key to inspect.
Returns
summarized data member type properties.

Implemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility, Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility, and Rose::Source::Analysis::CppCompatibility.

◆ isAutoGeneratable()

virtual bool Rose::Common::Analysis::AbstractCompatibilityBridge::isAutoGeneratable ( const ClassAnalysis &  classes,
ClassKeyType  clkey,
FunctionKeyType  fnkey 
) const
inlinevirtual

returns whether a function with fnkey's signature can be implicitly generated in clkey.

Parameters
classesclass analysis context.
clkeyclass for which implicit generation is tested.
fnkeyfunction whose signature is tested.
Returns
true if the bridge can determine that the function can be implicitly generated.
Note
The base implementation is conservative and returns false.

Reimplemented in Rose::Source::Analysis::CppCompatibility.

Definition at line 191 of file AbstractCompatibilityBridge.h.

◆ languageStandard()

virtual std::uint32_t Rose::Common::Analysis::AbstractCompatibilityBridge::languageStandard ( ) const
inlinevirtual

returns the active language standard as a C++ __cplusplus-style value when available.

Returns
language standard version, or zero when the bridge cannot provide one.

Reimplemented in Rose::Source::Analysis::CppCompatibility.

Definition at line 203 of file AbstractCompatibilityBridge.h.

◆ inheritedMethodsImplementVirtualBaseMethods()

virtual bool Rose::Common::Analysis::AbstractCompatibilityBridge::inheritedMethodsImplementVirtualBaseMethods ( ) const
inlinevirtual

returns whether a method inherited along the non-virtual inheritance chain implements an otherwise unimplemented function of a virtual base.

Returns
true if the language has this rule; the base implementation returns false.

This is the rule of Java (JLS 8.4.8.1, JVMS 5.4.6) and CIL (ECMA-335 II.12.2): for a class C extending B and implementing interface I, a concrete method B.m inherited by C implements I.m. C++ has no such rule; the class stays abstract. When enabled, analyzeVirtualFunctions records such relationships as implied overrides with C as witness (see OverrideDesc::witness).

Note
Only the rule above is modelled. The selection among default methods of unrelated interfaces (JVMS 5.4.6, maximally-specific superinterface methods) is not.

Reimplemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility.

Definition at line 220 of file AbstractCompatibilityBridge.h.

◆ isInheritableImplementation()

virtual bool Rose::Common::Analysis::AbstractCompatibilityBridge::isInheritableImplementation ( FunctionKeyType  fnkey) const
inlinevirtual

returns whether the inherited function fnkey qualifies as an implementation of a virtual base function (see inheritedMethodsImplementVirtualBaseMethods).

Parameters
fnkeyan inherited function that matches a virtual base function by signature.
Returns
true if fnkey may implement the virtual base function.

Only consulted when inheritedMethodsImplementVirtualBaseMethods returns true. A Java bridge returns true for non-abstract public methods (JLS 8.4.8.4: an inherited abstract method does not implement; interface methods are public, so the implementing method must be public).

Reimplemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility.

Definition at line 233 of file AbstractCompatibilityBridge.h.

◆ canOverride()

virtual bool Rose::Common::Analysis::AbstractCompatibilityBridge::canOverride ( FunctionKeyType  drv,
FunctionKeyType  bas 
) const
inlinevirtual

returns whether drv may override bas under language rules beyond name and signature, such as access control.

Parameters
drvfunction in a derived class (or inherited by it) that matches bas by signature.
basfunction in an ancestor class.
Returns
true if the override relation may be recorded for the pair; the base implementation returns true.

In C++ access does not affect overriding, so the default applies. The JVM (JVMS 5.4.5) excludes private methods on either side and lets a package-private method be overridden only from the same run-time package. If this query rejects a pair, the analysis still records the relation when it holds transitively: drv overrides an intermediate function that in turn overrides bas (JVMS 5.4.5, rule (b)). Bridges therefore only need to decide the direct relation.

Reimplemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::JvmCompatibility.

Definition at line 254 of file AbstractCompatibilityBridge.h.

Referenced by canOverrideInContext().

◆ isFinal()

virtual bool Rose::Common::Analysis::AbstractCompatibilityBridge::isFinal ( FunctionKeyType  fnkey) const
inlinevirtual

returns whether the virtual function fnkey cannot be overridden.

Parameters
fnkeyvirtual function to inspect.
Returns
true if fnkey is final (e.g., a sealed override in C#); the base implementation returns false.

The result is recorded in the VirtualFunctionDesc so that clients know that the function has no possible overriders. Bridges for languages in which a final function is not part of the override relation also reject such pairs in canOverride.

Reimplemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility.

Definition at line 271 of file AbstractCompatibilityBridge.h.

◆ explicitOverrides()

virtual void Rose::Common::Analysis::AbstractCompatibilityBridge::explicitOverrides ( const ClassAnalysis &  classes,
ClassKeyType  cls,
std::function< void(FunctionKeyType, FunctionKeyType)>  fn 
) const
inlinevirtual

reports override relations that are declared explicitly instead of being derived from names and signatures.

Parameters
classesclass analysis context; inheritance relations are complete.
clsclass whose explicit overrides are requested.
fncallback invoked as fn(overrider, overridden) for each explicit pair where overrider is a virtual function declared in cls.

CIL expresses explicit interface implementations, overrides under a different name, covariant returns, and default interface method overrides in the MethodImpl table. The analysis records each reported pair as an override, without consulting canOverride, but only if both functions are known virtual functions. Return types are not required to be identical. The base implementation reports nothing.

Definition at line 292 of file AbstractCompatibilityBridge.h.

◆ canOverrideInContext()

virtual bool Rose::Common::Analysis::AbstractCompatibilityBridge::canOverrideInContext ( const ClassAnalysis &  classes,
ClassKeyType  drvClass,
FunctionKeyType  drv,
ClassKeyType  basClass,
FunctionKeyType  bas 
) const
inlinevirtual

returns whether drv, declared in drvClass, may override bas, declared in basClass, with knowledge of the classes in between.

Parameters
classesclass analysis context; inheritance relations are complete.
drvClassclass that declares drv; invalid for an implied override, where the declaring class of the inherited function is not known.
drvfunction in a derived class that matches bas by signature.
basClassclass that declares bas.
basfunction in an ancestor class.
Returns
true if the override relation may be recorded for the pair; the base implementation forwards to canOverride(drv, bas).

Languages whose override rules depend on the classes between drvClass and basClass (e.g., a CIL method that starts a new vtable slot in an intermediate class) implement this query. The analysis calls this function; it is not necessary to also implement canOverride(drv, bas). Rejected pairs are resolved transitively as described for canOverride.

Reimplemented in Rose::BinaryAnalysis::ByteCode::ClassHierarchy::CilCompatibility.

Definition at line 320 of file AbstractCompatibilityBridge.h.

References canOverride().


The documentation for this class was generated from the following file: