"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "projects/CodeThorn/src/RoseCompatibility.C" between
rose-0.11.53.0.tar.gz and rose-0.11.54.0.tar.gz

About: ROSE is a compiler infrastructure to build source-to-source program transformation and analysis tools for large-scale C, C++, UPC, Fortran, OpenMP, Java, Python and PHP applications.

RoseCompatibility.C  (rose-0.11.53.0):RoseCompatibility.C  (rose-0.11.54.0)
#include <sage3basic.h> #include <sage3basic.h>
#include <sageInterface.h> #include <sageInterface.h>
#include <sageGeneric.h> #include <sageGeneric.h>
#include <VariableIdMapping.h> //~ #include <VariableIdMapping.h>
#include <tuple> #include <tuple>
#include <unordered_set> #include <unordered_set>
#include "CodeThornLib.h" #include "CodeThornLib.h"
#include "FunctionIdMapping.h"
#include "RoseCompatibility.h" #include "RoseCompatibility.h"
#include "ClassHierarchyAnalysis.h" #include "ClassHierarchyAnalysis.h"
namespace si = SageInterface; namespace si = SageInterface;
namespace ct = CodeThorn; namespace ct = CodeThorn;
namespace namespace
{ {
static constexpr bool firstDecisiveComparison = false; // syntactic sugar tag static constexpr bool firstDecisiveComparison = false; // syntactic sugar tag
std::string typeNameOf(const SgClassDeclaration* dcl) std::string typeNameOf(const SgClassDeclaration* dcl)
skipping to change at line 48 skipping to change at line 49
void handle(SgTemplateMemberFunctionDeclaration&) {} void handle(SgTemplateMemberFunctionDeclaration&) {}
void handle(SgTemplateVariableDeclaration&) {} void handle(SgTemplateVariableDeclaration&) {}
//~ void handle(SgTemplateTypedefDeclaration&) {} // may need some ha ndling //~ void handle(SgTemplateTypedefDeclaration&) {} // may need some ha ndling
}; };
bool isVirtual(const SgMemberFunctionDeclaration& dcl) bool isVirtual(const SgMemberFunctionDeclaration& dcl)
{ {
return dcl.get_functionModifier().isVirtual(); return dcl.get_functionModifier().isVirtual();
} }
bool isPureVirtual(const SgMemberFunctionDeclaration& dcl)
{
return dcl.get_functionModifier().isPureVirtual();
}
bool isPureVirtual(FunctionKeyType fn)
{
return isPureVirtual(SG_DEREF(fn));
}
std::string functionName(FunctionKeyType fn)
{
return SG_DEREF(fn).get_name();
}
const SgFunctionType& functionType(FunctionKeyType fn)
{
return SG_DEREF(SG_DEREF(fn).get_type());
}
struct NodeCollector : ExcludeTemplates struct NodeCollector : ExcludeTemplates
{ {
typedef std::unordered_set<SgNode*> NodeTracker; typedef std::unordered_set<SgNode*> NodeTracker;
NodeCollector( NodeTracker& visited, NodeCollector( NodeTracker& visited,
ct::ClassAnalysis& classes, ct::ClassAnalysis& classes,
ct::CastAnalysis& casts, ct::CastAnalysis& casts,
const ct::RoseCompatibilityBridge& compat const ct::RoseCompatibilityBridge& compat
) )
: visitedNodes(&visited), allClasses(&classes), allCasts(&casts), rcb(&com pat), currentClass(nullptr) : visitedNodes(&visited), allClasses(&classes), allCasts(&casts), rcb(&com pat), currentClass(nullptr)
skipping to change at line 558 skipping to change at line 579
const Sg_File_Info& where = SG_DEREF(castnode.get_startOfConstruct()); const Sg_File_Info& where = SG_DEREF(castnode.get_startOfConstruct());
os << castnode.unparseToString() os << castnode.unparseToString()
<< " [" << castnode.get_cast_type() << "] " << " [" << castnode.get_cast_type() << "] "
<< "@" << where.get_line() << ":" << where.get_col(); << "@" << where.get_line() << ":" << where.get_col();
return os; return os;
} }
int int
RoseCompatibilityBridge::compareNames(FunctionId lhs, FunctionId rhs) const RoseCompatibilityBridge::compareNames(FunctionKeyType lhs, FunctionKeyType rhs) const
{ {
const std::string lhsname{funMap.getFunctionNameFromFunctionId(lhs)}; const std::string lhsname{functionName(lhs)};
const std::string rhsname{funMap.getFunctionNameFromFunctionId(rhs)}; const std::string rhsname{functionName(rhs)};
const bool lhsIsDtor = lhsname.front() == '~'; const bool lhsIsDtor = lhsname.front() == '~';
const bool rhsIsDtor = rhsname.front() == '~'; const bool rhsIsDtor = rhsname.front() == '~';
int cmpres = 0; int cmpres = 0;
firstDecisiveComparison firstDecisiveComparison
|| (cmpres = cmpValue(lhsIsDtor, rhsIsDtor)) || (cmpres = cmpValue(lhsIsDtor, rhsIsDtor))
|| (cmpres = lhsname.compare(rhsname)) || (cmpres = lhsname.compare(rhsname))
; ;
return cmpres; return cmpres;
} }
int compareTypes(const SgType& lhs, const SgType& rhs) int compareTypes(const SgType& lhs, const SgType& rhs)
{ {
return TypeComparator::compare(lhs, rhs, false, false); return TypeComparator::compare(lhs, rhs, false, false);
} }
int int
RoseCompatibilityBridge::compareTypes(FunctionId lhs, FunctionId rhs, bool exclR eturn) const RoseCompatibilityBridge::compareTypes(FunctionKeyType lhs, FunctionKeyType rhs, bool exclReturn) const
{ {
static constexpr bool withArrayDecay = true; static constexpr bool withArrayDecay = true;
const SgFunctionType& lhsty = SG_DEREF(funMap.getTypeFromFunctionId(lhs)); const SgFunctionType& lhsty = functionType(lhs);
const SgFunctionType& rhsty = SG_DEREF(funMap.getTypeFromFunctionId(rhs)); const SgFunctionType& rhsty = functionType(rhs);
return sg::dispatch(TypeComparator{rhsty, withArrayDecay, exclReturn}, &lhsty) ; return sg::dispatch(TypeComparator{rhsty, withArrayDecay, exclReturn}, &lhsty) ;
} }
VariableId VariableKeyType
RoseCompatibilityBridge::variableId(SgInitializedName* var) const RoseCompatibilityBridge::variableId(SgInitializedName* var) const
{ {
return varMap.variableId(var); ASSERT_not_null(var);
return var;
} }
VariableId VariableKeyType
RoseCompatibilityBridge::variableId(SgVariableDeclaration* var) const RoseCompatibilityBridge::variableId(SgVariableDeclaration* var) const
{ {
return varMap.variableId(var); ASSERT_not_null(var);
SgInitializedNamePtrList& lst = var->get_variables();
ROSE_ASSERT(lst.size() == 1);
return variableId(lst[0]);
} }
std::string std::string
RoseCompatibilityBridge::nameOf(VariableId vid) const RoseCompatibilityBridge::nameOf(VariableKeyType vid) const
{ {
return vid.toString(&varMap); //~ return vid.toString(varMap);
return SG_DEREF(vid).get_name();
} }
std::string std::string
RoseCompatibilityBridge::nameOf(FunctionId fid) const RoseCompatibilityBridge::nameOf(FunctionKeyType fun) const
{ {
return funMap.getFunctionNameFromFunctionId(fid); return functionName(fun);
} }
namespace namespace
{ {
struct CovarianceChecker : sg::DispatchHandler<RoseCompatibilityBridge::Return TypeRelation> struct CovarianceChecker : sg::DispatchHandler<RoseCompatibilityBridge::Return TypeRelation>
{ {
using base = sg::DispatchHandler<RoseCompatibilityBridge::ReturnTypeRelati on>; using base = sg::DispatchHandler<RoseCompatibilityBridge::ReturnTypeRelati on>;
explicit explicit
CovarianceChecker(const ClassAnalysis& classAnalysis, const SgType& baseTy pe) CovarianceChecker(const ClassAnalysis& classAnalysis, const SgType& baseTy pe)
skipping to change at line 784 skipping to change at line 813
void handle(const SgReferenceType& drv) { res = check(drv); } void handle(const SgReferenceType& drv) { res = check(drv); }
void handle(const SgRvalueReferenceType& drv) { res = check(drv); } void handle(const SgRvalueReferenceType& drv) { res = check(drv); }
void handle(const SgPointerType& drv) { res = check(drv); } void handle(const SgPointerType& drv) { res = check(drv); }
// @} // @}
private: private:
const SgType* basTy; const SgType* basTy;
}; };
} }
RoseCompatibilityBridge::ReturnTypeRelation RoseCompatibilityBridge::ReturnTypeRelation
RoseCompatibilityBridge::haveSameOrCovariantReturn(const ClassAnalysis& classes, RoseCompatibilityBridge::haveSameOrCovariantReturn( const ClassAnalysis& classes
FunctionId basId, FunctionId drvId) const ,
FunctionKeyType basId,
FunctionKeyType drvId
) const
{ {
using PolymorphicRootTypes = CovariantPrefixChecker::ReturnType; using PolymorphicRootTypes = CovariantPrefixChecker::ReturnType;
const SgFunctionType& basTy = SG_DEREF(funMap.getTypeFromFunctionId(basId const SgFunctionType& basTy = functionType(basId);
)); const SgFunctionType& drvTy = functionType(drvId);
const SgFunctionType& drvTy = SG_DEREF(funMap.getTypeFromFunctionId(drvId
));
const SgType& basRet = SG_DEREF(basTy.get_return_type()); const SgType& basRet = SG_DEREF(basTy.get_return_type());
const SgType& drvRet = SG_DEREF(drvTy.get_return_type()); const SgType& drvRet = SG_DEREF(drvTy.get_return_type());
// skip polymorphic root (e.g., reference, pointer) // skip polymorphic root (e.g., reference, pointer)
const PolymorphicRootTypes rootTypes = sg::dispatch(CovariantPrefixChecker{bas Ret}, &drvRet); const PolymorphicRootTypes rootTypes = sg::dispatch(CovariantPrefixChecker{bas Ret}, &drvRet);
const SgType* drvRoot = std::get<0>(rootTypes); const SgType* drvRoot = std::get<0>(rootTypes);
if (!drvRoot) if (!drvRoot)
{ {
//~ std::cerr << "w/o root: " << basId.getIdCode() << "<>" << drvId.getIdCod e() << std::endl; //~ std::cerr << "w/o root: " << basId.getIdCode() << "<>" << drvId.getIdCod e() << std::endl;
return sg::dispatch(CovarianceChecker{classes, basRet}, &drvRet); return sg::dispatch(CovarianceChecker{classes, basRet}, &drvRet);
} }
//~ std::cerr << "w/ root: " << basId.getIdCode() << "<>" << drvId.getIdCode( ) << std::endl; //~ std::cerr << "w/ root: " << basId.getIdCode() << "<>" << drvId.getIdCode( ) << std::endl;
// test if the roots are covariant // test if the roots are covariant
return sg::dispatch(CovarianceChecker{classes, SG_DEREF(std::get<1>(rootTypes) )}, drvRoot); return sg::dispatch(CovarianceChecker{classes, SG_DEREF(std::get<1>(rootTypes) )}, drvRoot);
} }
FunctionId FunctionKeyType
RoseCompatibilityBridge::functionId(const SgFunctionDeclaration* fun) const RoseCompatibilityBridge::functionId(const SgMemberFunctionDeclaration* fun) cons
t
{ {
return funMap.getFunctionIdFromDeclaration(fun); return fun;
//~ return funLabeler.getFunctionEntryLabel(fun);
} }
void void
RoseCompatibilityBridge::extractFromProject(ClassAnalysis& classes, CastAnalysis & casts, ASTRootType n) const RoseCompatibilityBridge::extractFromProject(ClassAnalysis& classes, CastAnalysis & casts, ASTRootType n) const
{ {
NodeCollector::NodeTracker visited; NodeCollector::NodeTracker visited;
sg::dispatch(NodeCollector{visited, classes, casts, *this}, n); sg::dispatch(NodeCollector{visited, classes, casts, *this}, n);
} }
bool bool
RoseCompatibilityBridge::isPureVirtual(FunctionId id) const RoseCompatibilityBridge::isPureVirtual(FunctionKeyType id) const
{ {
return SG_DEREF(funMap.getFunctionDeclaration(id)).get_functionModifier().isPu reVirtual(); return ::isPureVirtual(id);
} }
FuncNameFn FuncNameFn
RoseCompatibilityBridge::functionNomenclator() const RoseCompatibilityBridge::functionNomenclator() const
{ {
const RoseCompatibilityBridge* rcb = this; const RoseCompatibilityBridge* rcb = this;
return [=](FunctionId id) -> std::string { return rcb->nameOf(id); }; return [=](FunctionKeyType id) -> std::string { return rcb->nameOf(id); };
} }
VarNameFn VarNameFn
RoseCompatibilityBridge::variableNomenclator() const RoseCompatibilityBridge::variableNomenclator() const
{ {
const RoseCompatibilityBridge* rcb = this; const RoseCompatibilityBridge* rcb = this;
return [=](VariableId id) -> std::string { return rcb->nameOf(id); }; return [=](VariableKeyType id) -> std::string { return rcb->nameOf(id); };
} }
ClassNameFn ClassNameFn
RoseCompatibilityBridge::classNomenclator() const RoseCompatibilityBridge::classNomenclator() const
{ {
return typeNameOf; return typeNameOf;
} }
} }
 End of changes. 24 change blocks. 
29 lines changed or deleted 61 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)