Program Listing for File sageGeneric.h#
↰ Return to documentation for file (src/frontend/SageIII/sageInterface/sageGeneric.h)
#ifndef _SAGEGENERIC_H
#define _SAGEGENERIC_H 1
// note: the comments are right aligned to support code-blocks doxygen 1.3.X :)
#include <type_traits>
#if !defined(NDEBUG)
#include <typeinfo>
#include <sstream>
#endif /* NDEBUG */
#define WITH_BINARY_NODES 0
#define WITH_UNTYPED_NODES 0
// #include "Cxx_Grammar.h"
// DQ (10/5/2014): We can't include this here.
// #include "rose.h"
#define SG_UNEXPECTED_NODE(X) (sg::unexpected_node(X, __FILE__, __LINE__))
#define SG_DEREF(X) (sg::deref(X, __FILE__, __LINE__))
#define SG_ASSERT_TYPE(SAGENODE, N) (sg::assert_sage_type<SAGENODE>(N, __FILE__, __LINE__))
#define SG_ERROR_IF(COND, MSG) (sg::report_error_if(COND, MSG, __FILE__, __LINE__))
namespace sg
{
//
// non sage specific utilities
template <class T>
static inline
void unused(const T&) {}
template <class T1, class T2>
struct ConstLike
{
typedef T2 type;
};
template <class T1, class T2>
struct ConstLike<const T1, T2>
{
typedef const T2 type;
};
//
// error reporting
template <class T, class E>
static inline
T conv(const E& el)
{
T res;
#if !defined(NDEBUG)
std::stringstream s;
s << el;
s >> res;
#endif /* NDEBUG */
return res;
}
// \note implemented originall in SageInterfaceAda.h. Now the implementations are moved to SageInterface.C since
// SageInterfaceAda.h is deleted when we remove Ada support for rexompiler
// \{
[[noreturn]]
void report_error(std::string desc, const char* file = nullptr, size_t ln = 0);
[[noreturn]]
void unexpected_node(const SgNode& n, const char* file = nullptr, size_t ln = 0);
static inline
void report_error_if(bool iserror, const std::string& desc, const char* file = nullptr, size_t ln = 0)
{
if (!iserror) return;
report_error(desc, file, ln);
}
template <class T>
T& deref(T* ptr, const char* file = 0, size_t ln = 0)
{
report_error_if(!ptr, "assertion failed: null dereference ", file, ln);
return *ptr;
}
// \note implemented in SageInterfaceAda.h
template <class _ReturnType>
struct DispatchHandler
{
typedef _ReturnType ReturnType;
typedef DispatchHandler<ReturnType> Base;
DispatchHandler()
: res()
{}
explicit
DispatchHandler(const ReturnType& defaultval)
: res(defaultval)
{}
operator ReturnType() const { return res; }
protected:
ReturnType res;
};
//
// Sage query functions
template <class SageNode>
static inline
SageNode& assume_sage_type(SgNode& n)
{
return static_cast<SageNode&>(n);
}
template <class SageNode>
static inline
const SageNode& assume_sage_type(const SgNode& n)
{
return static_cast<const SageNode&>(n);
}
#define GEN_VISIT(X) \
void visit(X * n) { rv.handle(*n); }
template <class RoseVisitor>
struct VisitDispatcher : ROSE_VisitorPatternDefaultBase
{
// rvalue ctor
VisitDispatcher(RoseVisitor&& rosevisitor, std::false_type)
: rv(std::move(rosevisitor))
{}
// lvalue ctor
VisitDispatcher(const RoseVisitor& rosevisitor, std::true_type)
: rv(rosevisitor)
{}
GEN_VISIT(SgAccessModifier)
GEN_VISIT(SgActualArgumentExpression)
GEN_VISIT(SgAddOp)
GEN_VISIT(SgAddressOfOp)
GEN_VISIT(SgAggregateInitializer)
GEN_VISIT(SgAliasSymbol)
GEN_VISIT(SgAlignOfOp)
GEN_VISIT(SgAllocateStatement)
GEN_VISIT(SgAndAssignOp)
GEN_VISIT(SgAndOp)
GEN_VISIT(SgArithmeticIfStatement)
GEN_VISIT(SgArrayType)
GEN_VISIT(SgArrowExp)
GEN_VISIT(SgArrowStarOp)
GEN_VISIT(SgAssertStmt)
GEN_VISIT(SgAssignInitializer)
GEN_VISIT(SgAssignOp)
GEN_VISIT(SgAssignStatement)
GEN_VISIT(SgAssignedGotoStatement)
GEN_VISIT(SgAssociateStatement)
GEN_VISIT(SgAsteriskShapeExp)
GEN_VISIT(SgAttribute)
GEN_VISIT(SgAttributeSpecificationStatement)
GEN_VISIT(SgAutoType)
GEN_VISIT(SgAwaitExpression)
GEN_VISIT(SgBackspaceStatement)
GEN_VISIT(SgBaseClass)
GEN_VISIT(SgExpBaseClass)
GEN_VISIT(SgBaseClassModifier)
GEN_VISIT(SgBasicBlock)
GEN_VISIT(SgBidirectionalGraph)
GEN_VISIT(SgBinaryOp)
GEN_VISIT(SgBitAndOp)
GEN_VISIT(SgBitAttribute)
GEN_VISIT(SgBitComplementOp)
GEN_VISIT(SgBitEqvOp)
GEN_VISIT(SgBitOrOp)
GEN_VISIT(SgBitXorOp)
GEN_VISIT(SgBlockDataStatement)
GEN_VISIT(SgBoolValExp)
GEN_VISIT(SgBreakStmt)
GEN_VISIT(SgBracedInitializer)
GEN_VISIT(SgC_PreprocessorDirectiveStatement)
GEN_VISIT(SgCaseOptionStmt)
GEN_VISIT(SgCastExp)
GEN_VISIT(SgCatchOptionStmt)
GEN_VISIT(SgCatchStatementSeq)
GEN_VISIT(SgCharVal)
GEN_VISIT(SgChar16Val)
GEN_VISIT(SgChar32Val)
GEN_VISIT(SgChooseExpression)
GEN_VISIT(SgClassDecl_attr)
GEN_VISIT(SgClassDeclaration)
GEN_VISIT(SgClassDefinition)
GEN_VISIT(SgClassNameRefExp)
GEN_VISIT(SgClassSymbol)
GEN_VISIT(SgClassType)
GEN_VISIT(SgClinkageDeclarationStatement)
GEN_VISIT(SgClinkageEndStatement)
GEN_VISIT(SgClinkageStartStatement)
GEN_VISIT(SgCloseStatement)
GEN_VISIT(SgColonShapeExp)
GEN_VISIT(SgCommaOpExp)
GEN_VISIT(SgCommonBlock)
GEN_VISIT(SgCommonBlockObject)
GEN_VISIT(SgCommonSymbol)
GEN_VISIT(SgComplexVal)
GEN_VISIT(SgComprehension)
GEN_VISIT(SgCompoundAssignOp)
GEN_VISIT(SgCompoundInitializer)
GEN_VISIT(SgCompoundLiteralExp)
GEN_VISIT(SgComputedGotoStatement)
GEN_VISIT(SgConcatenationOp)
GEN_VISIT(SgConditionalExp)
GEN_VISIT(SgConjugateOp)
GEN_VISIT(SgConstVolatileModifier)
GEN_VISIT(SgConstructorInitializer)
GEN_VISIT(SgContainsStatement)
GEN_VISIT(SgContinueStmt)
GEN_VISIT(SgCtorInitializerList)
GEN_VISIT(SgDataStatementGroup)
GEN_VISIT(SgDataStatementObject)
GEN_VISIT(SgDataStatementValue)
GEN_VISIT(SgDeadIfDirectiveStatement)
GEN_VISIT(SgDeallocateStatement)
GEN_VISIT(SgDeclarationModifier)
GEN_VISIT(SgDeclarationScope)
GEN_VISIT(SgDeclarationStatement)
GEN_VISIT(SgDeclType)
GEN_VISIT(SgDefaultOptionStmt)
GEN_VISIT(SgDefaultSymbol)
GEN_VISIT(SgDefineDirectiveStatement)
GEN_VISIT(SgDeleteExp)
GEN_VISIT(SgDerivedTypeStatement)
GEN_VISIT(SgDesignatedInitializer)
GEN_VISIT(SgDictionaryComprehension)
GEN_VISIT(SgDictionaryExp)
GEN_VISIT(SgDimensionObject)
GEN_VISIT(SgDirectory)
GEN_VISIT(SgDirectoryList)
GEN_VISIT(SgDivAssignOp)
GEN_VISIT(SgDivideOp)
GEN_VISIT(SgDoWhileStmt)
GEN_VISIT(SgDotExp)
GEN_VISIT(SgDotStarOp)
GEN_VISIT(SgDoubleVal)
GEN_VISIT(SgElaboratedTypeModifier)
GEN_VISIT(SgElementwiseOp)
GEN_VISIT(SgElementwiseAddOp)
GEN_VISIT(SgElementwiseDivideOp)
GEN_VISIT(SgElementwiseLeftDivideOp)
GEN_VISIT(SgElementwiseMultiplyOp)
GEN_VISIT(SgElementwisePowerOp)
GEN_VISIT(SgElementwiseSubtractOp)
GEN_VISIT(SgElseDirectiveStatement)
GEN_VISIT(SgElseWhereStatement)
GEN_VISIT(SgElseifDirectiveStatement)
GEN_VISIT(SgEmptyDeclaration)
GEN_VISIT(SgEmptyDirectiveStatement)
GEN_VISIT(SgEndfileStatement)
GEN_VISIT(SgEndifDirectiveStatement)
GEN_VISIT(SgEntryStatement)
GEN_VISIT(SgEnumDeclaration)
GEN_VISIT(SgEnumFieldSymbol)
GEN_VISIT(SgEnumSymbol)
GEN_VISIT(SgEnumType)
GEN_VISIT(SgEnumVal)
GEN_VISIT(SgEqualityOp)
GEN_VISIT(SgEquivalenceStatement)
GEN_VISIT(SgErrorDirectiveStatement)
GEN_VISIT(SgExecStatement)
GEN_VISIT(SgExponentiationOp)
GEN_VISIT(SgExponentiationAssignOp)
GEN_VISIT(SgExprListExp)
GEN_VISIT(SgExprStatement)
GEN_VISIT(SgExpression)
GEN_VISIT(SgExpressionRoot)
GEN_VISIT(SgFile)
GEN_VISIT(SgFileList)
GEN_VISIT(SgFloatVal)
GEN_VISIT(SgFloat128Val)
GEN_VISIT(SgFloat80Val)
GEN_VISIT(SgFoldExpression)
GEN_VISIT(SgFlushStatement)
GEN_VISIT(SgForAllStatement)
GEN_VISIT(SgForInitStatement)
GEN_VISIT(SgForStatement)
GEN_VISIT(SgFormatItem)
GEN_VISIT(SgFormatItemList)
GEN_VISIT(SgFormatStatement)
GEN_VISIT(SgFortranDo)
GEN_VISIT(SgOmpMetadirectiveStatement)
GEN_VISIT(SgOmpParallelStatement)
GEN_VISIT(SgOmpTeamsStatement)
GEN_VISIT(SgOmpCancellationPointStatement)
GEN_VISIT(SgOmpDeclareMapperStatement)
GEN_VISIT(SgOmpCancelStatement)
GEN_VISIT(SgOmpTaskgroupStatement)
GEN_VISIT(SgOmpDepobjStatement)
GEN_VISIT(SgOmpDistributeStatement)
GEN_VISIT(SgOmpLoopStatement)
GEN_VISIT(SgOmpScanStatement)
GEN_VISIT(SgOmpTaskloopStatement)
GEN_VISIT(SgOmpTargetEnterDataStatement)
GEN_VISIT(SgOmpTargetExitDataStatement)
GEN_VISIT(SgOmpTargetParallelForStatement)
GEN_VISIT(SgOmpTargetParallelStatement)
GEN_VISIT(SgOmpDistributeSimdStatement)
GEN_VISIT(SgOmpDistributeParallelForStatement)
GEN_VISIT(SgOmpDistributeParallelForSimdStatement)
GEN_VISIT(SgOmpTaskloopSimdStatement)
GEN_VISIT(SgOmpTargetUpdateStatement)
GEN_VISIT(SgOmpTargetParallelForSimdStatement)
GEN_VISIT(SgOmpTargetParallelLoopStatement)
GEN_VISIT(SgOmpTargetSimdStatement)
GEN_VISIT(SgOmpTargetTeamsStatement)
GEN_VISIT(SgOmpTargetTeamsDistributeStatement)
GEN_VISIT(SgOmpTargetTeamsDistributeSimdStatement)
GEN_VISIT(SgOmpTargetTeamsLoopStatement)
GEN_VISIT(SgOmpTargetTeamsDistributeParallelForStatement)
GEN_VISIT(SgOmpTargetTeamsDistributeParallelForSimdStatement)
GEN_VISIT(SgOmpMasterTaskloopSimdStatement)
GEN_VISIT(SgOmpParallelMasterTaskloopStatement)
GEN_VISIT(SgOmpParallelMasterTaskloopSimdStatement)
GEN_VISIT(SgOmpTeamsDistributeStatement)
GEN_VISIT(SgOmpTeamsDistributeSimdStatement)
GEN_VISIT(SgOmpTeamsDistributeParallelForStatement)
GEN_VISIT(SgOmpTeamsDistributeParallelForSimdStatement)
GEN_VISIT(SgOmpTeamsLoopStatement)
GEN_VISIT(SgOmpParallelMasterStatement)
GEN_VISIT(SgOmpMasterTaskloopStatement)
GEN_VISIT(SgOmpParallelLoopStatement)
GEN_VISIT(SgOmpSingleStatement)
GEN_VISIT(SgOmpSimdStatement)
GEN_VISIT(SgOmpTaskStatement)
GEN_VISIT(SgOmpForStatement)
GEN_VISIT(SgOmpForSimdStatement)
GEN_VISIT(SgOmpDoStatement)
GEN_VISIT(SgOmpSectionsStatement)
GEN_VISIT(SgOmpClauseBodyStatement)
GEN_VISIT(SgOmpAtomicStatement)
GEN_VISIT(SgOmpMasterStatement)
GEN_VISIT(SgOmpTaskyieldStatement)
GEN_VISIT(SgOmpSectionStatement)
GEN_VISIT(SgOmpOrderedStatement)
GEN_VISIT(SgOmpOrderedDependStatement)
GEN_VISIT(SgOmpWorkshareStatement)
GEN_VISIT(SgOmpCriticalStatement)
GEN_VISIT(SgOmpBodyStatement)
GEN_VISIT(SgFortranIncludeLine)
GEN_VISIT(SgFortranNonblockedDo)
GEN_VISIT(SgFuncDecl_attr)
GEN_VISIT(SgFunctionCallExp)
GEN_VISIT(SgFunctionDeclaration)
GEN_VISIT(SgFunctionDefinition)
GEN_VISIT(SgFunctionParameterScope)
GEN_VISIT(SgFunctionModifier)
GEN_VISIT(SgFunctionParameterList)
GEN_VISIT(SgFunctionParameterRefExp)
GEN_VISIT(SgFunctionParameterTypeList)
GEN_VISIT(SgFunctionRefExp)
GEN_VISIT(SgFunctionSymbol)
GEN_VISIT(SgFunctionType)
GEN_VISIT(SgFunctionTypeSymbol)
GEN_VISIT(SgFunctionTypeTable)
GEN_VISIT(SgTypeTable)
GEN_VISIT(SgGlobal)
GEN_VISIT(SgGotoStatement)
GEN_VISIT(SgGraph)
GEN_VISIT(SgGraphEdge)
GEN_VISIT(SgGraphEdgeList)
GEN_VISIT(SgGraphNode)
GEN_VISIT(SgGraphNodeList)
GEN_VISIT(SgGreaterOrEqualOp)
GEN_VISIT(SgGreaterThanOp)
GEN_VISIT(SgIOItemExpression)
GEN_VISIT(SgIOStatement)
GEN_VISIT(SgIdentDirectiveStatement)
GEN_VISIT(SgIfDirectiveStatement)
GEN_VISIT(SgIfStmt)
GEN_VISIT(SgIfdefDirectiveStatement)
GEN_VISIT(SgIfndefDirectiveStatement)
GEN_VISIT(SgImageControlStatement)
GEN_VISIT(SgImagPartOp)
GEN_VISIT(SgImplicitStatement)
GEN_VISIT(SgImpliedDo)
GEN_VISIT(SgImportStatement)
GEN_VISIT(SgIncidenceDirectedGraph)
GEN_VISIT(SgIncidenceUndirectedGraph)
GEN_VISIT(SgIncludeDirectiveStatement)
GEN_VISIT(SgIncludeFile)
GEN_VISIT(SgIncludeNextDirectiveStatement)
GEN_VISIT(SgInitializedName)
GEN_VISIT(SgInitializer)
GEN_VISIT(SgInquireStatement)
GEN_VISIT(SgIntKeyedBidirectionalGraph)
GEN_VISIT(SgIntVal)
GEN_VISIT(SgIntegerDivideOp)
GEN_VISIT(SgIntegerDivideAssignOp)
GEN_VISIT(SgInterfaceBody)
GEN_VISIT(SgHeaderFileBody)
GEN_VISIT(SgHeaderFileReport)
GEN_VISIT(SgInterfaceStatement)
GEN_VISIT(SgInterfaceSymbol)
GEN_VISIT(SgIntrinsicSymbol)
GEN_VISIT(SgIsOp)
GEN_VISIT(SgIsNotOp)
GEN_VISIT(SgIorAssignOp)
GEN_VISIT(SgKeyDatumPair)
GEN_VISIT(SgCudaKernelExecConfig)
GEN_VISIT(SgCudaKernelCallExp)
GEN_VISIT(SgLabelRefExp)
GEN_VISIT(SgLabelStatement)
GEN_VISIT(SgLabelSymbol)
GEN_VISIT(SgLambdaCapture)
GEN_VISIT(SgLambdaCaptureList)
GEN_VISIT(SgLambdaExp)
GEN_VISIT(SgLambdaRefExp)
GEN_VISIT(SgLeftDivideOp)
GEN_VISIT(SgLessOrEqualOp)
GEN_VISIT(SgLessThanOp)
GEN_VISIT(SgLineDirectiveStatement)
GEN_VISIT(SgLinemarkerDirectiveStatement)
GEN_VISIT(SgLinkageModifier)
GEN_VISIT(SgListComprehension)
GEN_VISIT(SgListExp)
GEN_VISIT(SgLocatedNode)
GEN_VISIT(SgLocatedNodeSupport)
GEN_VISIT(SgLongDoubleVal)
GEN_VISIT(SgLongIntVal)
GEN_VISIT(SgLongLongIntVal)
GEN_VISIT(SgLshiftAssignOp)
GEN_VISIT(SgLshiftOp)
GEN_VISIT(SgMagicColonExp)
GEN_VISIT(SgMatrixExp)
GEN_VISIT(SgMatrixTransposeOp)
GEN_VISIT(SgMemberFunctionDeclaration)
GEN_VISIT(SgMemberFunctionRefExp)
GEN_VISIT(SgMemberFunctionSymbol)
GEN_VISIT(SgMemberFunctionType)
GEN_VISIT(SgMembershipOp)
GEN_VISIT(SgMicrosoftAttributeDeclaration)
GEN_VISIT(SgMinusAssignOp)
GEN_VISIT(SgMinusMinusOp)
GEN_VISIT(SgMinusOp)
GEN_VISIT(SgModAssignOp)
GEN_VISIT(SgModOp)
GEN_VISIT(SgModifier)
GEN_VISIT(SgModifierNodes)
GEN_VISIT(SgModifierType)
GEN_VISIT(SgModuleStatement)
GEN_VISIT(SgModuleSymbol)
GEN_VISIT(SgMultAssignOp)
GEN_VISIT(SgMultiplyOp)
GEN_VISIT(SgName)
GEN_VISIT(SgNameGroup)
GEN_VISIT(SgNamedType)
GEN_VISIT(SgNamelistStatement)
GEN_VISIT(SgNamespaceAliasDeclarationStatement)
GEN_VISIT(SgNamespaceDeclarationStatement)
GEN_VISIT(SgNamespaceDefinitionStatement)
GEN_VISIT(SgNamespaceSymbol)
GEN_VISIT(SgNaryOp)
GEN_VISIT(SgNaryBooleanOp)
GEN_VISIT(SgNaryComparisonOp)
GEN_VISIT(SgNewExp)
GEN_VISIT(SgNode)
GEN_VISIT(SgNoexceptOp)
GEN_VISIT(SgNotEqualOp)
GEN_VISIT(SgNotOp)
GEN_VISIT(SgNonMembershipOp)
GEN_VISIT(SgNonrealDecl)
GEN_VISIT(SgNonrealRefExp)
GEN_VISIT(SgNonrealSymbol)
GEN_VISIT(SgNonrealType)
GEN_VISIT(SgNonrealBaseClass)
GEN_VISIT(SgNullExpression)
GEN_VISIT(SgNullptrValExp)
GEN_VISIT(SgNullStatement)
GEN_VISIT(SgNullifyStatement)
GEN_VISIT(SgOmpOrderedClause)
GEN_VISIT(SgOmpNowaitClause)
GEN_VISIT(SgOmpReadClause)
GEN_VISIT(SgOmpReverseOffloadClause)
GEN_VISIT(SgOmpUnifiedAddressClause)
GEN_VISIT(SgOmpUnifiedSharedMemoryClause)
GEN_VISIT(SgOmpDynamicAllocatorsClause)
GEN_VISIT(SgOmpAtomicDefaultMemOrderClause)
GEN_VISIT(SgOmpExtImplementationDefinedRequirementClause)
GEN_VISIT(SgOmpWriteClause)
GEN_VISIT(SgOmpThreadsClause)
GEN_VISIT(SgOmpSimdClause)
GEN_VISIT(SgOmpUpdateClause)
GEN_VISIT(SgOmpCaptureClause)
GEN_VISIT(SgOmpSeqCstClause)
GEN_VISIT(SgOmpAcqRelClause)
GEN_VISIT(SgOmpReleaseClause)
GEN_VISIT(SgOmpAcquireClause)
GEN_VISIT(SgOmpRelaxedClause)
GEN_VISIT(SgOmpUntiedClause)
GEN_VISIT(SgOmpMergeableClause)
GEN_VISIT(SgOmpDefaultClause)
GEN_VISIT(SgOmpCollapseClause)
GEN_VISIT(SgOmpIfClause)
GEN_VISIT(SgOmpFinalClause)
GEN_VISIT(SgOmpPriorityClause)
GEN_VISIT(SgOmpNumThreadsClause)
GEN_VISIT(SgOmpParallelClause)
GEN_VISIT(SgOmpSectionsClause)
GEN_VISIT(SgOmpForClause)
GEN_VISIT(SgOmpTaskgroupClause)
GEN_VISIT(SgOmpNumTeamsClause)
GEN_VISIT(SgOmpGrainsizeClause)
GEN_VISIT(SgOmpDetachClause)
GEN_VISIT(SgOmpNumTasksClause)
GEN_VISIT(SgOmpNogroupClause)
GEN_VISIT(SgOmpHintClause)
GEN_VISIT(SgOmpOrderClause)
GEN_VISIT(SgOmpBindClause)
GEN_VISIT(SgOmpThreadLimitClause)
GEN_VISIT(SgOmpExpressionClause)
GEN_VISIT(SgOmpCopyprivateClause)
GEN_VISIT(SgOmpPrivateClause)
GEN_VISIT(SgOmpFirstprivateClause)
GEN_VISIT(SgOmpNontemporalClause)
GEN_VISIT(SgOmpInclusiveClause)
GEN_VISIT(SgOmpExclusiveClause)
GEN_VISIT(SgOmpIsDevicePtrClause)
GEN_VISIT(SgOmpUseDevicePtrClause)
GEN_VISIT(SgOmpUseDeviceAddrClause)
GEN_VISIT(SgOmpSharedClause)
GEN_VISIT(SgOmpCopyinClause)
GEN_VISIT(SgOmpLastprivateClause)
GEN_VISIT(SgOmpReductionClause)
GEN_VISIT(SgOmpInReductionClause)
GEN_VISIT(SgOmpTaskReductionClause)
GEN_VISIT(SgOmpAllocateClause)
GEN_VISIT(SgOmpAllocatorClause)
GEN_VISIT(SgOmpWhenClause)
GEN_VISIT(SgOmpVariablesClause)
GEN_VISIT(SgOmpScheduleClause)
GEN_VISIT(SgOmpDistScheduleClause)
GEN_VISIT(SgOmpDefaultmapClause)
GEN_VISIT(SgOmpDependClause)
GEN_VISIT(SgOmpAffinityClause)
GEN_VISIT(SgOmpClause)
GEN_VISIT(SgOpenclAccessModeModifier)
GEN_VISIT(SgOpenStatement)
GEN_VISIT(SgOptions)
GEN_VISIT(SgOrOp)
GEN_VISIT(SgParameterStatement)
GEN_VISIT(SgPartialFunctionModifierType)
GEN_VISIT(SgPartialFunctionType)
GEN_VISIT(SgPassStatement)
GEN_VISIT(SgPlusAssignOp)
GEN_VISIT(SgPlusPlusOp)
GEN_VISIT(SgPntrArrRefExp)
GEN_VISIT(SgPointerAssignOp)
GEN_VISIT(SgPointerDerefExp)
GEN_VISIT(SgPointerMemberType)
GEN_VISIT(SgPointerType)
GEN_VISIT(SgPowerOp)
GEN_VISIT(SgPragma)
GEN_VISIT(SgPragmaDeclaration)
GEN_VISIT(SgPrintStatement)
GEN_VISIT(SgProcedureHeaderStatement)
GEN_VISIT(SgProgramHeaderStatement)
GEN_VISIT(SgProject)
GEN_VISIT(SgPseudoDestructorRefExp)
GEN_VISIT(SgQualifiedName)
GEN_VISIT(SgQualifiedNameType)
GEN_VISIT(SgRangeExp)
GEN_VISIT(SgRangeBasedForStatement)
GEN_VISIT(SgReadStatement)
GEN_VISIT(SgRealPartOp)
GEN_VISIT(SgRefExp)
GEN_VISIT(SgReferenceType)
GEN_VISIT(SgRenamePair)
GEN_VISIT(SgRenameSymbol)
GEN_VISIT(SgReturnStmt)
GEN_VISIT(SgRewindStatement)
GEN_VISIT(SgRshiftAssignOp)
GEN_VISIT(SgRshiftOp)
GEN_VISIT(SgRvalueReferenceType)
GEN_VISIT(SgScopeOp)
GEN_VISIT(SgScopeStatement)
GEN_VISIT(SgSequenceStatement)
GEN_VISIT(SgSetComprehension)
GEN_VISIT(SgShortVal)
GEN_VISIT(SgSizeOfOp)
GEN_VISIT(SgSourceFile)
GEN_VISIT(SgSpaceshipOp)
GEN_VISIT(SgSpawnStmt)
GEN_VISIT(SgSyncAllStatement)
GEN_VISIT(SgSyncImagesStatement)
GEN_VISIT(SgSyncMemoryStatement)
GEN_VISIT(SgSyncTeamStatement)
GEN_VISIT(SgLockStatement)
GEN_VISIT(SgUnlockStatement)
GEN_VISIT(SgProcessControlStatement)
GEN_VISIT(SgSpecialFunctionModifier)
GEN_VISIT(SgStatement)
GEN_VISIT(SgStaticAssertionDeclaration)
GEN_VISIT(SgStmtDeclarationStatement)
GEN_VISIT(SgStatementExpression)
GEN_VISIT(SgStatementFunctionStatement)
GEN_VISIT(SgStorageModifier)
GEN_VISIT(SgStringConversion)
GEN_VISIT(SgStringKeyedBidirectionalGraph)
GEN_VISIT(SgStringVal)
GEN_VISIT(SgStructureModifier)
GEN_VISIT(SgSubscriptExpression)
GEN_VISIT(SgSubtractOp)
GEN_VISIT(SgSupport)
GEN_VISIT(SgSwitchStatement)
GEN_VISIT(SgSymbol)
GEN_VISIT(SgSymbolTable)
GEN_VISIT(SgTemplateArgument)
GEN_VISIT(SgTemplateArgumentList)
GEN_VISIT(SgTemplateDeclaration)
GEN_VISIT(SgTemplateClassDeclaration)
GEN_VISIT(SgTemplateClassSymbol)
GEN_VISIT(SgTemplateFunctionDeclaration)
GEN_VISIT(SgTemplateFunctionRefExp)
GEN_VISIT(SgTemplateFunctionSymbol)
GEN_VISIT(SgTemplateMemberFunctionDeclaration)
GEN_VISIT(SgTemplateMemberFunctionRefExp)
GEN_VISIT(SgTemplateMemberFunctionSymbol)
GEN_VISIT(SgTemplateTypedefDeclaration)
GEN_VISIT(SgTemplateTypedefSymbol)
GEN_VISIT(SgTemplateVariableDeclaration)
GEN_VISIT(SgTemplateVariableSymbol)
GEN_VISIT(SgTemplateClassDefinition)
GEN_VISIT(SgTemplateFunctionDefinition)
GEN_VISIT(SgTemplateInstantiationDecl)
GEN_VISIT(SgTemplateInstantiationDefn)
GEN_VISIT(SgTemplateInstantiationDirectiveStatement)
GEN_VISIT(SgTemplateInstantiationFunctionDecl)
GEN_VISIT(SgTemplateInstantiationMemberFunctionDecl)
GEN_VISIT(SgTemplateInstantiationTypedefDeclaration)
GEN_VISIT(SgTemplateParameter)
GEN_VISIT(SgTemplateParameterVal)
GEN_VISIT(SgTemplateParameterList)
GEN_VISIT(SgTemplateSymbol)
GEN_VISIT(SgTemplateType)
GEN_VISIT(SgThisExp)
GEN_VISIT(SgTypeTraitBuiltinOperator)
GEN_VISIT(SgSuperExp)
GEN_VISIT(SgThrowOp)
GEN_VISIT(SgToken)
GEN_VISIT(SgTryStmt)
GEN_VISIT(SgTupleExp)
GEN_VISIT(SgType)
GEN_VISIT(SgTypeBool)
GEN_VISIT(SgTypeChar)
GEN_VISIT(SgTypeChar16)
GEN_VISIT(SgTypeChar32)
GEN_VISIT(SgTypeComplex)
GEN_VISIT(SgTypeDefault)
GEN_VISIT(SgTypeExpression)
GEN_VISIT(SgTypeLabel)
GEN_VISIT(SgTypeDouble)
GEN_VISIT(SgTypeEllipse)
GEN_VISIT(SgTypeFixed)
GEN_VISIT(SgTypeFloat)
GEN_VISIT(SgTypeFloat128)
GEN_VISIT(SgTypeFloat80)
GEN_VISIT(SgTypeGlobalVoid)
GEN_VISIT(SgTypeIdOp)
GEN_VISIT(SgTypeImaginary)
GEN_VISIT(SgTypeInt)
GEN_VISIT(SgTypeLong)
GEN_VISIT(SgTypeLongDouble)
GEN_VISIT(SgTypeLongLong)
GEN_VISIT(SgTypeModifier)
GEN_VISIT(SgTypeMatrix)
GEN_VISIT(SgTypeTuple)
GEN_VISIT(SgTypeNullptr)
GEN_VISIT(SgTypeOfType)
GEN_VISIT(SgTypeShort)
GEN_VISIT(SgTypeSigned128bitInteger)
GEN_VISIT(SgTypeSignedChar)
GEN_VISIT(SgTypeSignedInt)
GEN_VISIT(SgTypeSignedLong)
GEN_VISIT(SgTypeSignedLongLong)
GEN_VISIT(SgTypeSignedShort)
GEN_VISIT(SgTypeString)
GEN_VISIT(SgTypeUnknown)
GEN_VISIT(SgTypeUnsigned128bitInteger)
GEN_VISIT(SgTypeUnsignedChar)
GEN_VISIT(SgTypeUnsignedInt)
GEN_VISIT(SgTypeUnsignedLong)
GEN_VISIT(SgTypeUnsignedLongLong)
GEN_VISIT(SgTypeUnsignedShort)
GEN_VISIT(SgTypeVoid)
GEN_VISIT(SgTypeWchar)
GEN_VISIT(SgTypedefDeclaration)
GEN_VISIT(SgTypedefSeq)
GEN_VISIT(SgTypedefSymbol)
GEN_VISIT(SgTypedefType)
GEN_VISIT(SgUPC_AccessModifier)
GEN_VISIT(SgUnaryAddOp)
GEN_VISIT(SgUnaryOp)
GEN_VISIT(SgUndefDirectiveStatement)
GEN_VISIT(SgUndirectedGraphEdge)
GEN_VISIT(SgUnknownArrayOrFunctionReference)
GEN_VISIT(SgUnknownFile)
GEN_VISIT(SgUnparse_Info)
GEN_VISIT(SgUnsignedCharVal)
GEN_VISIT(SgUnsignedIntVal)
GEN_VISIT(SgUnsignedLongLongIntVal)
GEN_VISIT(SgUnsignedLongVal)
GEN_VISIT(SgUnsignedShortVal)
GEN_VISIT(SgUpcBarrierStatement)
GEN_VISIT(SgUpcBlocksizeofExpression)
GEN_VISIT(SgUpcElemsizeofExpression)
GEN_VISIT(SgUpcFenceStatement)
GEN_VISIT(SgUpcForAllStatement)
GEN_VISIT(SgUpcLocalsizeofExpression)
GEN_VISIT(SgUpcMythread)
GEN_VISIT(SgUpcNotifyStatement)
GEN_VISIT(SgUpcThreads)
GEN_VISIT(SgUpcWaitStatement)
GEN_VISIT(SgUseStatement)
GEN_VISIT(SgUserDefinedBinaryOp)
GEN_VISIT(SgUserDefinedUnaryOp)
GEN_VISIT(SgUsingDeclarationStatement)
GEN_VISIT(SgUsingDirectiveStatement)
GEN_VISIT(SgValueExp)
GEN_VISIT(SgVarArgCopyOp)
GEN_VISIT(SgVarArgEndOp)
GEN_VISIT(SgVarArgOp)
GEN_VISIT(SgVarArgStartOneOperandOp)
GEN_VISIT(SgVarArgStartOp)
GEN_VISIT(SgVarRefExp)
GEN_VISIT(SgVariableDeclaration)
GEN_VISIT(SgVariableDefinition)
GEN_VISIT(SgVariableSymbol)
GEN_VISIT(SgVariantExpression)
GEN_VISIT(SgVariantStatement)
GEN_VISIT(SgVoidVal)
GEN_VISIT(SgWaitStatement)
GEN_VISIT(SgWarningDirectiveStatement)
GEN_VISIT(SgWithStatement)
GEN_VISIT(SgWcharVal)
GEN_VISIT(SgWhereStatement)
GEN_VISIT(SgWhileStmt)
GEN_VISIT(SgWriteStatement)
GEN_VISIT(SgXorAssignOp)
GEN_VISIT(SgYieldExpression)
GEN_VISIT(Sg_File_Info)
GEN_VISIT(SgTypeCAFTeam)
GEN_VISIT(SgCAFWithTeamStatement)
GEN_VISIT(SgCAFCoExpression)
GEN_VISIT(SgCallExpression)
GEN_VISIT(SgTypeCrayPointer)
GEN_VISIT(SgClassExp)
// GEN_VISIT(SgClassPropertyList)
/*
GEN_VISIT(SgBinaryComposite)
GEN_VISIT(SgComprehensionList)
*
GEN_VISIT(SgDirectedGraph)
GEN_VISIT(SgDirectedGraphEdge)
GEN_VISIT(SgDirectedGraphNode)
GEN_VISIT(SgUnknownMemberFunctionType)
*/
RoseVisitor rv;
};
#undef GEN_VISIT
template <class RoseVisitor>
inline
typename std::remove_const<typename std::remove_reference<RoseVisitor>::type>::type
_dispatch(RoseVisitor&& rv, SgNode* n)
{
typedef typename std::remove_reference<RoseVisitor>::type RoseVisitorNoref;
typedef typename std::remove_const<RoseVisitorNoref>::type RoseHandler;
ROSE_ASSERT(n);
VisitDispatcher<RoseHandler> vis( std::forward<RoseVisitor>(rv),
std::is_lvalue_reference<RoseVisitor>()
);
n->accept(vis);
return std::move(vis).rv;
}
#if 0
#endif
template <class RoseVisitor>
inline
typename std::remove_const<typename std::remove_reference<RoseVisitor>::type>::type
dispatch(RoseVisitor&& rv, SgNode* n)
{
//~ return std::move(rv);
return _dispatch(std::forward<RoseVisitor>(rv), n);
}
template <class RoseVisitor>
inline
typename std::remove_const<typename std::remove_reference<RoseVisitor>::type>::type
dispatch(RoseVisitor&& rv, const SgNode* n)
{
//~ return std::move(rv);
return _dispatch(std::forward<RoseVisitor>(rv), const_cast<SgNode*>(n));
}
template <class SageNode>
struct DefaultHandler
{
void handle(SageNode&) {}
};
template <class AncestorNode, class QualSgNode>
struct AncestorTypeFinder : DefaultHandler<const SgProject>
{
typedef DefaultHandler<const SgProject> Base;
typedef std::pair<AncestorNode*, QualSgNode*> Pair;
Pair res;
AncestorTypeFinder()
: Base(), res(NULL, NULL)
{}
// handling of const SgProject is outsourced to DefaultHandler
// thus, AncestorNode = const SgProject does not cause conflicts
using Base::handle;
void handle(QualSgNode& n) { res.second = n.get_parent(); }
void handle(AncestorNode& n) { res.first = &n; }
operator Pair() const { return res; }
};
template <class AncestorNode, class QualSgNode>
AncestorNode* _ancestor(QualSgNode& n)
{
typedef AncestorTypeFinder<AncestorNode, QualSgNode> AncestorFinder;
typename AncestorFinder::Pair res(NULL, n.get_parent());
while (res.second != NULL)
{
res = (typename AncestorFinder::Pair) sg::dispatch(AncestorFinder(), res.second);
}
return res.first;
}
template <class AncestorNode>
AncestorNode* ancestor(SgNode* n)
{
if (n == NULL) return NULL;
return _ancestor<AncestorNode>(*n);
}
template <class AncestorNode>
const AncestorNode* ancestor(const SgNode* n)
{
if (n == NULL) return NULL;
return _ancestor<const AncestorNode>(*n);
}
template <class AncestorNode>
AncestorNode& ancestor(SgNode& n)
{
AncestorNode* res = _ancestor<AncestorNode>(n);
ROSE_ASSERT(res);
return *res;
}
template <class AncestorNode>
const AncestorNode& ancestor(const SgNode& n)
{
const AncestorNode* res = _ancestor<const AncestorNode>(n);
ROSE_ASSERT(res);
return *res;
}
template <class SageNode>
struct TypeRecoveryHandler
{
typedef typename ConstLike<SageNode, SgNode>::type SgBaseNode;
TypeRecoveryHandler(const char* f = 0, size_t ln = 0)
: res(NULL), loc(f), loc_ln(ln)
{}
TypeRecoveryHandler(TypeRecoveryHandler&&) = default;
TypeRecoveryHandler& operator=(TypeRecoveryHandler&&) = default;
operator SageNode* ()&& { return res; }
void handle(SgBaseNode& n) { unexpected_node(n, loc, loc_ln); }
void handle(SageNode& n) { res = &n; }
private:
SageNode* res;
const char* loc;
size_t loc_ln;
TypeRecoveryHandler() = delete;
TypeRecoveryHandler(const TypeRecoveryHandler&) = delete;
TypeRecoveryHandler& operator=(const TypeRecoveryHandler&) = delete;
};
template <class SageNode>
SageNode* assert_sage_type(SgNode* n, const char* f = 0, size_t ln = 0)
{
return sg::dispatch(TypeRecoveryHandler<SageNode>(f, ln), n);
}
template <class SageNode>
const SageNode* assert_sage_type(const SgNode* n, const char* f = 0, size_t ln = 0)
{
return sg::dispatch(TypeRecoveryHandler<const SageNode>(f, ln), n);
}
template <class SageNode>
SageNode& assert_sage_type(SgNode& n, const char* f = 0, size_t ln = 0)
{
return *sg::dispatch(TypeRecoveryHandler<SageNode>(f, ln), &n);
}
template <class SageNode>
const SageNode& assert_sage_type(const SgNode& n, const char* f = 0, size_t ln = 0)
{
return *sg::dispatch(TypeRecoveryHandler<const SageNode>(f, ln), &n);
}
static inline
void swap_parent(SgNode* lhs, SgNode* rhs)
{
SgNode* tmp = lhs->get_parent();
lhs->set_parent(rhs->get_parent());
rhs->set_parent(tmp);
}
static inline
void swap_parent(void*, void*) {}
template <class SageNode, class SageChild>
void swap_child(SageNode& lhs, SageNode& rhs, SageChild* (SageNode::*getter) () const, void (SageNode::*setter) (SageChild*))
{
SageChild* lhs_child = (lhs.*getter)();
SageChild* rhs_child = (rhs.*getter)();
ROSE_ASSERT(lhs_child && rhs_child);
(lhs.*setter)(rhs_child);
(rhs.*setter)(lhs_child);
swap_parent(lhs_child, rhs_child);
}
template <class SageNode>
struct TraversalFunction
{
typedef void (*TransformHandlerFn)(SageNode*);
explicit
TraversalFunction(TransformHandlerFn fun)
: fn(fun)
{}
void handle(SgNode&) { /* ignore */ }
void handle(SageNode& n) { fn(&n); }
TransformHandlerFn fn;
};
template <class SageNode>
static inline
TraversalFunction<SageNode>
createTraversalFunction(void (* fn)(SageNode*))
{
return TraversalFunction<SageNode>(fn);
}
//
// function type extractor
// see https://stackoverflow.com/questions/28033251/can-you-extract-types-from-template-parameter-function-signature
template <class GVisitor>
struct TraversalClass : AstSimpleProcessing
{
explicit
TraversalClass(GVisitor gv)
: gvisitor(gv)
//~ : gvisitor(std::move(gv))
{}
void visit(SgNode* n)
{
gvisitor = sg::dispatch(gvisitor, n);
}
// GVisitor&& visitor() { return std::move(gvisitor); }
GVisitor visitor() { return gvisitor; }
GVisitor gvisitor;
};
template <class F>
static inline
F
forAllNodes(F fn, SgNode* root, AstSimpleProcessing::Order order = postorder)
{
ROSE_ASSERT(root);
TraversalClass<F> tt(fn);
//~ TraversalClass<F> tt(std::move(fn));
tt.traverse(root, order);
return tt.visitor();
}
template <class SageNode>
static inline
void
forAllNodes(void (*fn)(SageNode*), SgNode* root, AstSimpleProcessing::Order order = postorder)
{
forAllNodes(createTransformExecutor(fn), root, order);
}
#if !defined(NDEBUG)
static inline
std::string nodeType(const SgNode& n)
{
return typeid(n).name();
}
static inline
std::string nodeType(const SgNode* n)
{
if (n == NULL) return "<null>";
return nodeType(*n);
}
#endif
template <class GVisitor>
struct DispatchHelper
{
explicit
DispatchHelper(GVisitor gv, SgNode* p)
: gvisitor(std::move(gv)), parent(p), cnt(0)
{}
void operator()(SgNode* n)
{
++cnt;
#if 0
if (n == NULL)
{
std::cerr << "succ(" << nodeType(parent) << ", " << cnt << ") is null" << std::endl;
return;
}
#endif
if (n != NULL) gvisitor = sg::dispatch(std::move(gvisitor), n);
}
operator GVisitor()&& { return std::move(gvisitor); }
GVisitor gvisitor;
SgNode* parent;
size_t cnt;
};
template <class GVisitor>
static inline
DispatchHelper<GVisitor>
dispatchHelper(GVisitor gv, SgNode* parent = NULL)
{
return DispatchHelper<GVisitor>(std::move(gv), parent);
}
template <class GVisitor>
static inline
GVisitor traverseChildren(GVisitor gv, SgNode& n)
{
std::vector<SgNode*> successors = n.get_traversalSuccessorContainer();
return std::for_each(successors.begin(), successors.end(), dispatchHelper(std::move(gv), &n));
}
template <class GVisitor>
static inline
GVisitor traverseChildren(GVisitor gv, SgNode* n)
{
return traverseChildren(gv, sg::deref(n));
}
template <class SageParent, class SageChild>
void linkParentChild(SageParent& parent, SageChild& child, void (SageParent::*setter)(SageChild*))
{
(parent.*setter)(&child);
child.set_parent(&parent);
}
template <class SageNode>
typename SageNode::base_node_type&
asBaseType(SageNode& n) { return n; }
template <class SageNode>
const typename SageNode::base_node_type&
asBaseType(const SageNode& n) { return n; }
template <class SageNode>
typename SageNode::base_node_type*
asBaseType(SageNode* n) { return n; }
template <class SageNode>
const typename SageNode::base_node_type*
asBaseType(const SageNode* n) { return n; }
}
#endif /* _SAGEGENERIC_H */