ROSE  0.9.13.81
sageGeneric.h
Go to the documentation of this file.
1 #ifndef _SAGEGENERIC_H
2 
3 #define _SAGEGENERIC_H 1
4 
11 
12 // note: the comments are right aligned to support code-blocks doxygen 1.3.X :)
13 
14 #include <stdexcept>
15 
16 #if __cplusplus >= 201103L
17 #include <type_traits>
18 #endif
19 
20 #if !defined(NDEBUG)
21 #include <typeinfo>
22 #include <iostream>
23 #include <sstream>
24 #endif /* NDEBUG */
25 
26 
27 #define WITH_BINARY_ANALYSIS 0
28 
29 // #include "Cxx_Grammar.h"
30 
31 // DQ (10/5/2014): We can't include this here.
32 // #include "rose.h"
33 
34 #define SG_UNEXPECTED_NODE(X) (sg::unexpected_node(X, __FILE__, __LINE__))
35 #define SG_DEREF(X) (sg::deref(X, __FILE__, __LINE__))
36 #define SG_ASSERT_TYPE(SAGENODE, N) (sg::assert_sage_type<SAGENODE>(N, __FILE__, __LINE__))
37 #define SG_ERROR_IF(COND, MSG) (sg::report_error_if(COND, MSG, __FILE__, __LINE__))
38 
39 namespace sg
40 {
41  //
42  // non sage specific utilities
43 
46  template <class T>
47  static inline
48  void unused(const T&) {}
49 
51  template <class T1, class T2>
52  struct ConstLike
53  {
54  typedef T2 type;
55  };
56 
57  template <class T1, class T2>
58  struct ConstLike<const T1, T2>
59  {
60  typedef const T2 type;
61  };
62 
63  //
64  // error reporting
65 
67  template <class T, class E>
68  static inline
69  T conv(const E& el)
70  {
71  T res;
72 #if !defined(NDEBUG)
73  std::stringstream s;
74 
75  s << el;
76  s >> res;
77 #endif /* NDEBUG */
78  return res;
79  }
80 
81  static inline
82  void report_error(std::string desc, const char* file = 0, size_t ln = 0)
83  {
84  if (file)
85  {
86  const std::string at(" at ");
87  const std::string sep(" : ");
88  const std::string num(conv<std::string>(ln));
89 
90  desc = desc + at + file + sep + num;
91  }
92 
93  std::cerr << desc << std::endl;
94  throw std::logic_error(desc);
95  }
96 
97  static inline
98  void report_error_if(bool iserror, const std::string& desc, const char* file = 0, size_t ln = 0)
99  {
100  if (!iserror) return;
101 
102  report_error(desc, file, ln);
103  }
104 
106  template <class T>
107  T& deref(T* ptr, const char* file = 0, size_t ln = 0)
108  {
109  report_error_if(!ptr, "null dereference ", file, ln);
110  return *ptr;
111  }
112 
113  static inline
114  void unexpected_node(const SgNode& n, const char* file = 0, size_t ln = 0)
115  {
116  static const std::string msg = "unexpected node-type: ";
117 
118  report_error(msg + typeid(n).name(), file, ln);
119  }
120 
131  template <class _ReturnType>
133  {
134  typedef _ReturnType ReturnType;
136 
138  : res()
139  {}
140 
141  explicit
142  DispatchHandler(const ReturnType& defaultval)
143  : res(defaultval)
144  {}
145 
146  operator ReturnType() const { return res; }
147 
148  protected:
149  ReturnType res;
150  };
151 
152 
153  //
154  // Sage query functions
155 
157  template <class SageNode>
158  static inline
159  SageNode& assume_sage_type(SgNode& n)
160  {
161  return static_cast<SageNode&>(n);
162  }
163 
166  template <class SageNode>
167  static inline
168  const SageNode& assume_sage_type(const SgNode& n)
169  {
170  return static_cast<const SageNode&>(n);
171  }
172 
173 #define GEN_VISIT(X) \
174  void visit(X * n) { rv.handle(*n); }
175 
176  template <class RoseVisitor>
178  {
179 
180 #if __cplusplus >= 201103L
181  // rvalue ctor
182  VisitDispatcher(RoseVisitor&& rosevisitor, std::false_type)
183  : rv(std::move(rosevisitor))
184  {}
185 
186  // lvalue ctor
187  VisitDispatcher(const RoseVisitor& rosevisitor, std::true_type)
188  : rv(rosevisitor)
189  {}
190 #else
191  explicit
192  VisitDispatcher(const RoseVisitor& rosevisitor)
193  : rv(rosevisitor)
194  {}
195 #endif
196 
197 
198  GEN_VISIT(SgNode)
199 
200  GEN_VISIT(SgName)
201  GEN_VISIT(SgSymbolTable)
202  GEN_VISIT(SgPragma)
203  GEN_VISIT(SgModifierNodes)
204  GEN_VISIT(SgConstVolatileModifier)
205  GEN_VISIT(SgStorageModifier)
206  GEN_VISIT(SgAccessModifier)
207  GEN_VISIT(SgFunctionModifier)
208  GEN_VISIT(SgUPC_AccessModifier)
209  GEN_VISIT(SgLinkageModifier)
210  GEN_VISIT(SgSpecialFunctionModifier)
211  GEN_VISIT(SgTypeModifier)
212  GEN_VISIT(SgElaboratedTypeModifier)
213  GEN_VISIT(SgBaseClassModifier)
214  GEN_VISIT(SgDeclarationModifier)
215  GEN_VISIT(SgOpenclAccessModeModifier)
216  GEN_VISIT(SgModifier)
217  GEN_VISIT(Sg_File_Info)
218  GEN_VISIT(SgSourceFile)
219 
220  GEN_VISIT(SgUnknownFile)
221  GEN_VISIT(SgFile)
222  GEN_VISIT(SgFileList)
223  GEN_VISIT(SgDirectory)
224  GEN_VISIT(SgDirectoryList)
225  GEN_VISIT(SgProject)
226  GEN_VISIT(SgOptions)
227  GEN_VISIT(SgUnparse_Info)
228  GEN_VISIT(SgFuncDecl_attr)
229  GEN_VISIT(SgClassDecl_attr)
230  GEN_VISIT(SgTypedefSeq)
231  GEN_VISIT(SgFunctionParameterTypeList)
232  GEN_VISIT(SgTemplateParameter)
233  GEN_VISIT(SgTemplateArgument)
234  GEN_VISIT(SgTemplateParameterList)
235  GEN_VISIT(SgTemplateArgumentList)
240  GEN_VISIT(SgTemplateParameterVal)
241  GEN_VISIT(SgTemplateFunctionRefExp)
243  GEN_VISIT(SgTypeTraitBuiltinOperator)
244  GEN_VISIT(SgBitAttribute)
245  GEN_VISIT(SgAttribute)
246  GEN_VISIT(SgBaseClass)
247  GEN_VISIT(SgUndirectedGraphEdge)
248  GEN_VISIT(SgDirectedGraphEdge)
249  GEN_VISIT(SgGraphNode)
250  GEN_VISIT(SgGraphEdge)
253  GEN_VISIT(SgBidirectionalGraph)
254  GEN_VISIT(SgIncidenceDirectedGraph)
255  GEN_VISIT(SgIncidenceUndirectedGraph)
256  GEN_VISIT(SgGraph)
257  GEN_VISIT(SgGraphNodeList)
258  GEN_VISIT(SgGraphEdgeList)
259  GEN_VISIT(SgQualifiedName)
260  GEN_VISIT(SgNameGroup)
261  GEN_VISIT(SgCommonBlockObject)
262  GEN_VISIT(SgDimensionObject)
263  GEN_VISIT(SgDataStatementGroup)
264  GEN_VISIT(SgDataStatementObject)
265  GEN_VISIT(SgDataStatementValue)
266  GEN_VISIT(SgFormatItem)
267  GEN_VISIT(SgFormatItemList)
268  GEN_VISIT(SgTypeTable)
269  GEN_VISIT(SgSupport)
270  GEN_VISIT(SgForStatement)
271  GEN_VISIT(SgMatlabForStatement)
272  GEN_VISIT(SgForInitStatement)
273  GEN_VISIT(SgCatchStatementSeq)
274  GEN_VISIT(SgFunctionParameterList)
275  GEN_VISIT(SgCtorInitializerList)
276  GEN_VISIT(SgBasicBlock)
277  GEN_VISIT(SgGlobal)
278  GEN_VISIT(SgIfStmt)
279  GEN_VISIT(SgFunctionDefinition)
280  GEN_VISIT(SgWhileStmt)
281  GEN_VISIT(SgDoWhileStmt)
282  GEN_VISIT(SgSwitchStatement)
283  GEN_VISIT(SgCatchOptionStmt)
284  GEN_VISIT(SgVariableDeclaration)
285  GEN_VISIT(SgVariableDefinition)
286  GEN_VISIT(SgEnumDeclaration)
287  GEN_VISIT(SgAsmStmt)
288  GEN_VISIT(SgTypedefDeclaration)
289  GEN_VISIT(SgFunctionTypeTable)
290  GEN_VISIT(SgExprStatement)
291  GEN_VISIT(SgLabelStatement)
292  GEN_VISIT(SgCaseOptionStmt)
293  GEN_VISIT(SgTryStmt)
294  GEN_VISIT(SgDefaultOptionStmt)
295  GEN_VISIT(SgBreakStmt)
296  GEN_VISIT(SgContinueStmt)
297  GEN_VISIT(SgReturnStmt)
298  GEN_VISIT(SgGotoStatement)
299  GEN_VISIT(SgSpawnStmt)
300  GEN_VISIT(SgNullStatement)
301  GEN_VISIT(SgVariantStatement)
302  GEN_VISIT(SgPragmaDeclaration)
303  GEN_VISIT(SgTemplateDeclaration)
304  GEN_VISIT(SgTemplateInstantiationDecl)
305  GEN_VISIT(SgTemplateInstantiationDefn)
306  GEN_VISIT(SgTemplateClassDeclaration)
307  GEN_VISIT(SgTemplateClassDefinition)
310  GEN_VISIT(SgProgramHeaderStatement)
311  GEN_VISIT(SgProcedureHeaderStatement)
312  GEN_VISIT(SgEntryStatement)
313  GEN_VISIT(SgFortranNonblockedDo)
314  GEN_VISIT(SgInterfaceStatement)
315  GEN_VISIT(SgParameterStatement)
316  GEN_VISIT(SgCommonBlock)
317  GEN_VISIT(SgModuleStatement)
318  GEN_VISIT(SgUseStatement)
319  GEN_VISIT(SgStopOrPauseStatement)
320  GEN_VISIT(SgPrintStatement)
321  GEN_VISIT(SgReadStatement)
322  GEN_VISIT(SgWriteStatement)
323  GEN_VISIT(SgOpenStatement)
324  GEN_VISIT(SgCloseStatement)
325  GEN_VISIT(SgInquireStatement)
326  GEN_VISIT(SgFlushStatement)
327  GEN_VISIT(SgBackspaceStatement)
328  GEN_VISIT(SgRewindStatement)
329  GEN_VISIT(SgEndfileStatement)
330  GEN_VISIT(SgWaitStatement)
331  GEN_VISIT(SgCAFWithTeamStatement)
332  GEN_VISIT(SgFormatStatement)
333  GEN_VISIT(SgFortranDo)
334  GEN_VISIT(SgForAllStatement)
335  GEN_VISIT(SgIOStatement)
336  GEN_VISIT(SgUpcNotifyStatement)
337  GEN_VISIT(SgUpcWaitStatement)
338  GEN_VISIT(SgUpcBarrierStatement)
339  GEN_VISIT(SgUpcFenceStatement)
340  GEN_VISIT(SgUpcForAllStatement)
341  GEN_VISIT(SgOmpParallelStatement)
342  GEN_VISIT(SgOmpSingleStatement)
343  GEN_VISIT(SgOmpSimdStatement)
344  GEN_VISIT(SgOmpTaskStatement)
345  GEN_VISIT(SgOmpForStatement)
346  GEN_VISIT(SgOmpForSimdStatement)
347  GEN_VISIT(SgOmpDoStatement)
348  GEN_VISIT(SgOmpSectionsStatement)
349  GEN_VISIT(SgOmpClauseBodyStatement)
350  GEN_VISIT(SgOmpAtomicStatement)
351  GEN_VISIT(SgOmpMasterStatement)
352  GEN_VISIT(SgOmpSectionStatement)
353  GEN_VISIT(SgOmpOrderedStatement)
354  GEN_VISIT(SgOmpWorkshareStatement)
355  GEN_VISIT(SgOmpCriticalStatement)
356  GEN_VISIT(SgOmpBodyStatement)
357  GEN_VISIT(SgBlockDataStatement)
358  GEN_VISIT(SgImplicitStatement)
360  GEN_VISIT(SgWhereStatement)
361  GEN_VISIT(SgNullifyStatement)
362  GEN_VISIT(SgEquivalenceStatement)
363  GEN_VISIT(SgDerivedTypeStatement)
365  GEN_VISIT(SgAllocateStatement)
366  GEN_VISIT(SgDeallocateStatement)
367  GEN_VISIT(SgContainsStatement)
368  GEN_VISIT(SgSequenceStatement)
369  GEN_VISIT(SgElseWhereStatement)
370  GEN_VISIT(SgArithmeticIfStatement)
371  GEN_VISIT(SgAssignStatement)
372  GEN_VISIT(SgComputedGotoStatement)
373  GEN_VISIT(SgAssignedGotoStatement)
374  GEN_VISIT(SgNamelistStatement)
375  GEN_VISIT(SgImportStatement)
376  GEN_VISIT(SgAssociateStatement)
377  GEN_VISIT(SgFortranIncludeLine)
381  GEN_VISIT(SgUsingDeclarationStatement)
382  GEN_VISIT(SgUsingDirectiveStatement)
384  GEN_VISIT(SgClassDeclaration)
385  GEN_VISIT(SgClassDefinition)
386  GEN_VISIT(SgScopeStatement)
387  GEN_VISIT(SgMemberFunctionDeclaration)
388  GEN_VISIT(SgFunctionDeclaration)
389  GEN_VISIT(SgIncludeDirectiveStatement)
390  GEN_VISIT(SgDefineDirectiveStatement)
391  GEN_VISIT(SgUndefDirectiveStatement)
392  GEN_VISIT(SgIfdefDirectiveStatement)
393  GEN_VISIT(SgIfndefDirectiveStatement)
394  GEN_VISIT(SgIfDirectiveStatement)
395  GEN_VISIT(SgDeadIfDirectiveStatement)
396  GEN_VISIT(SgElseDirectiveStatement)
397  GEN_VISIT(SgElseifDirectiveStatement)
398  GEN_VISIT(SgEndifDirectiveStatement)
399  GEN_VISIT(SgLineDirectiveStatement)
400  GEN_VISIT(SgWarningDirectiveStatement)
401  GEN_VISIT(SgErrorDirectiveStatement)
402  GEN_VISIT(SgEmptyDirectiveStatement)
404  GEN_VISIT(SgIdentDirectiveStatement)
407  GEN_VISIT(SgClinkageStartStatement)
408  GEN_VISIT(SgClinkageEndStatement)
410  GEN_VISIT(SgOmpFlushStatement)
411  GEN_VISIT(SgOmpDeclareSimdStatement)
412  GEN_VISIT(SgOmpBarrierStatement)
413  GEN_VISIT(SgOmpTaskwaitStatement)
414  GEN_VISIT(SgOmpThreadprivateStatement)
415  GEN_VISIT(SgDeclarationStatement)
416  GEN_VISIT(SgExprListExp)
417  GEN_VISIT(SgVarRefExp)
418  GEN_VISIT(SgLabelRefExp)
419  GEN_VISIT(SgClassNameRefExp)
420  GEN_VISIT(SgFunctionRefExp)
421  GEN_VISIT(SgMemberFunctionRefExp)
422  GEN_VISIT(SgFunctionCallExp)
423  GEN_VISIT(SgSizeOfOp)
424  GEN_VISIT(SgUpcLocalsizeofExpression)
425  GEN_VISIT(SgUpcBlocksizeofExpression)
426  GEN_VISIT(SgUpcElemsizeofExpression)
427  GEN_VISIT(SgVarArgStartOp)
428  GEN_VISIT(SgVarArgStartOneOperandOp)
429  GEN_VISIT(SgVarArgOp)
430  GEN_VISIT(SgVarArgEndOp)
431  GEN_VISIT(SgVarArgCopyOp)
432  GEN_VISIT(SgTypeIdOp)
433  GEN_VISIT(SgConditionalExp)
434  GEN_VISIT(SgNewExp)
435  GEN_VISIT(SgDeleteExp)
436  GEN_VISIT(SgThisExp)
437  GEN_VISIT(SgRefExp)
438  GEN_VISIT(SgAggregateInitializer)
439  GEN_VISIT(SgConstructorInitializer)
440  GEN_VISIT(SgAssignInitializer)
441  GEN_VISIT(SgExpressionRoot)
442  GEN_VISIT(SgMinusOp)
443  GEN_VISIT(SgUnaryAddOp)
444  GEN_VISIT(SgNotOp)
445  GEN_VISIT(SgPointerDerefExp)
446  GEN_VISIT(SgAddressOfOp)
447  GEN_VISIT(SgMinusMinusOp)
448  GEN_VISIT(SgPlusPlusOp)
449  GEN_VISIT(SgBitComplementOp)
450  GEN_VISIT(SgRealPartOp)
451  GEN_VISIT(SgImagPartOp)
452  GEN_VISIT(SgConjugateOp)
453  GEN_VISIT(SgCastExp)
454  GEN_VISIT(SgThrowOp)
455  GEN_VISIT(SgArrowExp)
456  GEN_VISIT(SgDotExp)
457  GEN_VISIT(SgDotStarOp)
458  GEN_VISIT(SgArrowStarOp)
459  GEN_VISIT(SgEqualityOp)
460  GEN_VISIT(SgLessThanOp)
461  GEN_VISIT(SgGreaterThanOp)
462  GEN_VISIT(SgNotEqualOp)
463  GEN_VISIT(SgLessOrEqualOp)
464  GEN_VISIT(SgGreaterOrEqualOp)
465  GEN_VISIT(SgAddOp)
466  GEN_VISIT(SgSubtractOp)
467  GEN_VISIT(SgMultiplyOp)
468  GEN_VISIT(SgDivideOp)
469  GEN_VISIT(SgIntegerDivideOp)
470  GEN_VISIT(SgModOp)
471  GEN_VISIT(SgAndOp)
472  GEN_VISIT(SgOrOp)
473  GEN_VISIT(SgBitXorOp)
474  GEN_VISIT(SgBitAndOp)
475  GEN_VISIT(SgBitOrOp)
476  GEN_VISIT(SgCommaOpExp)
477  GEN_VISIT(SgLshiftOp)
478  GEN_VISIT(SgRshiftOp)
479  GEN_VISIT(SgPntrArrRefExp)
480  GEN_VISIT(SgScopeOp)
481  GEN_VISIT(SgAssignOp)
482  GEN_VISIT(SgPlusAssignOp)
483  GEN_VISIT(SgMinusAssignOp)
484  GEN_VISIT(SgAndAssignOp)
485  GEN_VISIT(SgIorAssignOp)
486  GEN_VISIT(SgMultAssignOp)
487  GEN_VISIT(SgDivAssignOp)
488  GEN_VISIT(SgModAssignOp)
489  GEN_VISIT(SgXorAssignOp)
490  GEN_VISIT(SgLshiftAssignOp)
491  GEN_VISIT(SgRshiftAssignOp)
492  GEN_VISIT(SgConcatenationOp)
493  GEN_VISIT(SgBoolValExp)
494  GEN_VISIT(SgStringVal)
495  GEN_VISIT(SgShortVal)
496  GEN_VISIT(SgCharVal)
497  GEN_VISIT(SgUnsignedCharVal)
498  GEN_VISIT(SgWcharVal)
499  GEN_VISIT(SgUnsignedShortVal)
500  GEN_VISIT(SgIntVal)
501  GEN_VISIT(SgEnumVal)
502  GEN_VISIT(SgUnsignedIntVal)
503  GEN_VISIT(SgLongIntVal)
504  GEN_VISIT(SgLongLongIntVal)
505  GEN_VISIT(SgUnsignedLongLongIntVal)
506  GEN_VISIT(SgUnsignedLongVal)
507  GEN_VISIT(SgFloatVal)
508  GEN_VISIT(SgDoubleVal)
509  GEN_VISIT(SgLongDoubleVal)
510  GEN_VISIT(SgUpcThreads)
511  GEN_VISIT(SgUpcMythread)
512  GEN_VISIT(SgComplexVal)
513  GEN_VISIT(SgNullExpression)
514  GEN_VISIT(SgVariantExpression)
515  GEN_VISIT(SgStatementExpression)
516  GEN_VISIT(SgAsmOp)
517  GEN_VISIT(SgCudaKernelExecConfig)
518  GEN_VISIT(SgCudaKernelCallExp)
519  GEN_VISIT(SgSubscriptExpression)
520  GEN_VISIT(SgColonShapeExp)
521  GEN_VISIT(SgAsteriskShapeExp)
522  GEN_VISIT(SgIOItemExpression)
523  GEN_VISIT(SgImpliedDo)
524  GEN_VISIT(SgExponentiationOp)
526  GEN_VISIT(SgActualArgumentExpression)
527  GEN_VISIT(SgUserDefinedBinaryOp)
528  GEN_VISIT(SgPointerAssignOp)
529  GEN_VISIT(SgCAFCoExpression)
530  GEN_VISIT(SgDesignatedInitializer)
531  GEN_VISIT(SgInitializer)
532  GEN_VISIT(SgUserDefinedUnaryOp)
533  GEN_VISIT(SgPseudoDestructorRefExp)
534  GEN_VISIT(SgUnaryOp)
535  GEN_VISIT(SgBinaryOp)
536  GEN_VISIT(SgValueExp)
537  GEN_VISIT(SgRangeExp)
538  GEN_VISIT(SgMatrixTransposeOp)
539  GEN_VISIT(SgNonrealRefExp)
540  GEN_VISIT(SgAlignOfOp)
541  GEN_VISIT(SgNoexceptOp)
542  GEN_VISIT(SgLambdaExp)
543  GEN_VISIT(SgFunctionParameterRefExp)
544  GEN_VISIT(SgCompoundLiteralExp)
545 
546  // symbols
547  GEN_VISIT(SgVariableSymbol)
548  GEN_VISIT(SgFunctionTypeSymbol)
549  GEN_VISIT(SgClassSymbol)
550  GEN_VISIT(SgTemplateSymbol)
551  GEN_VISIT(SgEnumSymbol)
552  GEN_VISIT(SgEnumFieldSymbol)
553  GEN_VISIT(SgTypedefSymbol)
554  GEN_VISIT(SgMemberFunctionSymbol)
555  GEN_VISIT(SgLabelSymbol)
556  GEN_VISIT(SgDefaultSymbol)
557  GEN_VISIT(SgNamespaceSymbol)
558  GEN_VISIT(SgIntrinsicSymbol)
559  GEN_VISIT(SgModuleSymbol)
560  GEN_VISIT(SgInterfaceSymbol)
561  GEN_VISIT(SgCommonSymbol)
562  GEN_VISIT(SgRenameSymbol)
563  GEN_VISIT(SgFunctionSymbol)
564  GEN_VISIT(SgAsmBinaryAddressSymbol)
565  GEN_VISIT(SgAsmBinaryDataSymbol)
566  GEN_VISIT(SgAliasSymbol)
567  GEN_VISIT(SgSymbol)
568 
569 #if WITH_BINARY_ANALYSIS
570  GEN_VISIT(SgBinaryComposite)
571  GEN_VISIT(SgAsmBlock)
572  GEN_VISIT(SgAsmOperandList)
573  GEN_VISIT(SgAsmArmInstruction)
574  GEN_VISIT(SgAsmX86Instruction)
575  GEN_VISIT(SgAsmPowerpcInstruction)
576  GEN_VISIT(SgAsmInstruction)
577  GEN_VISIT(SgAsmStatement)
578  GEN_VISIT(SgAsmBinaryAdd)
579  GEN_VISIT(SgAsmBinarySubtract)
580  GEN_VISIT(SgAsmBinaryMultiply)
581  GEN_VISIT(SgAsmBinaryDivide)
582  GEN_VISIT(SgAsmBinaryMod)
583  GEN_VISIT(SgAsmBinaryAddPreupdate)
585  GEN_VISIT(SgAsmBinaryAddPostupdate)
587  GEN_VISIT(SgAsmBinaryLsl)
588  GEN_VISIT(SgAsmBinaryLsr)
589  GEN_VISIT(SgAsmBinaryAsr)
590  GEN_VISIT(SgAsmBinaryRor)
591  GEN_VISIT(SgAsmBinaryExpression)
592  GEN_VISIT(SgAsmUnaryPlus)
593  GEN_VISIT(SgAsmUnaryMinus)
594  GEN_VISIT(SgAsmUnaryRrx)
596  GEN_VISIT(SgAsmUnaryExpression)
598  GEN_VISIT(SgAsmControlFlagsExpression)
599  GEN_VISIT(SgAsmCommonSubExpression)
602  GEN_VISIT(SgAsmIntegerValueExpression)
603  GEN_VISIT(SgAsmFloatValueExpression)
604  GEN_VISIT(SgAsmValueExpression)
605  GEN_VISIT(SgAsmExprListExp)
606  GEN_VISIT(SgAsmExpression)
607  GEN_VISIT(SgAsmIntegerType)
608  GEN_VISIT(SgAsmFloatType)
609  GEN_VISIT(SgAsmScalarType)
610  GEN_VISIT(SgAsmVectorType)
611  GEN_VISIT(SgAsmType)
612  GEN_VISIT(SgAsmGenericDLL)
613  GEN_VISIT(SgAsmPEImportItemList)
614  GEN_VISIT(SgAsmPEImportDirectoryList)
615  GEN_VISIT(SgAsmGenericFormat)
616  GEN_VISIT(SgAsmGenericFile)
617  GEN_VISIT(SgAsmElfFileHeader)
618  GEN_VISIT(SgAsmPEFileHeader)
619  GEN_VISIT(SgAsmNEFileHeader)
620  GEN_VISIT(SgAsmLEFileHeader)
621  GEN_VISIT(SgAsmDOSFileHeader)
622  GEN_VISIT(SgAsmGenericHeader)
623  GEN_VISIT(SgAsmElfRelocSection)
624  GEN_VISIT(SgAsmElfDynamicSection)
625  GEN_VISIT(SgAsmElfSymbolSection)
626  GEN_VISIT(SgAsmElfStringSection)
627  GEN_VISIT(SgAsmElfEHFrameSection)
628  GEN_VISIT(SgAsmElfNoteSection)
629  GEN_VISIT(SgAsmElfSymverSection)
631  GEN_VISIT(SgAsmElfSymverNeededSection)
632  GEN_VISIT(SgAsmElfStrtab)
633  GEN_VISIT(SgAsmCoffStrtab)
634  GEN_VISIT(SgAsmGenericStrtab)
635  GEN_VISIT(SgAsmElfSection)
636  GEN_VISIT(SgAsmElfSectionTable)
637  GEN_VISIT(SgAsmElfSegmentTable)
638  GEN_VISIT(SgAsmPEImportSection)
639  GEN_VISIT(SgAsmPEExportSection)
640  GEN_VISIT(SgAsmPEStringSection)
641  GEN_VISIT(SgAsmPESection)
642  GEN_VISIT(SgAsmPESectionTable)
643  GEN_VISIT(SgAsmCoffSymbolTable)
644  GEN_VISIT(SgAsmDOSExtendedHeader)
645  GEN_VISIT(SgAsmNESection)
646  GEN_VISIT(SgAsmNESectionTable)
647  GEN_VISIT(SgAsmNENameTable)
648  GEN_VISIT(SgAsmNEModuleTable)
649  GEN_VISIT(SgAsmNEStringTable)
650  GEN_VISIT(SgAsmNEEntryTable)
651  GEN_VISIT(SgAsmNERelocTable)
652  GEN_VISIT(SgAsmLESection)
653  GEN_VISIT(SgAsmLESectionTable)
654  GEN_VISIT(SgAsmLENameTable)
655  GEN_VISIT(SgAsmLEPageTable)
656  GEN_VISIT(SgAsmLEEntryTable)
657  GEN_VISIT(SgAsmLERelocTable)
658  GEN_VISIT(SgAsmGenericSection)
659  GEN_VISIT(SgAsmCoffSymbol)
660  GEN_VISIT(SgAsmElfSymbol)
661  GEN_VISIT(SgAsmGenericSymbol)
662  GEN_VISIT(SgAsmElfSectionTableEntry)
663  GEN_VISIT(SgAsmElfSegmentTableEntry)
665  GEN_VISIT(SgAsmElfRelocEntry)
666  GEN_VISIT(SgAsmElfRelocEntryList)
667  GEN_VISIT(SgAsmElfDynamicEntry)
668  GEN_VISIT(SgAsmElfDynamicEntryList)
669  GEN_VISIT(SgAsmElfEHFrameEntryCI)
670  GEN_VISIT(SgAsmElfEHFrameEntryCIList)
671  GEN_VISIT(SgAsmElfEHFrameEntryFD)
672  GEN_VISIT(SgAsmElfEHFrameEntryFDList)
673  GEN_VISIT(SgAsmElfNoteEntry)
674  GEN_VISIT(SgAsmElfNoteEntryList)
675  GEN_VISIT(SgAsmElfSymverEntry)
676  GEN_VISIT(SgAsmElfSymverEntryList)
677  GEN_VISIT(SgAsmElfSymverDefinedEntry)
679  GEN_VISIT(SgAsmElfSymverDefinedAux)
681  GEN_VISIT(SgAsmElfSymverNeededEntry)
683  GEN_VISIT(SgAsmElfSymverNeededAux)
684  GEN_VISIT(SgAsmElfSymverNeededAuxList)
685  GEN_VISIT(SgAsmPERVASizePair)
686  GEN_VISIT(SgAsmPEExportDirectory)
687  GEN_VISIT(SgAsmPEExportEntry)
688  GEN_VISIT(SgAsmPEImportDirectory)
689  GEN_VISIT(SgAsmPEImportItem)
690  GEN_VISIT(SgAsmPESectionTableEntry)
691  GEN_VISIT(SgAsmNEEntryPoint)
692  GEN_VISIT(SgAsmNERelocEntry)
693  GEN_VISIT(SgAsmNESectionTableEntry)
694  GEN_VISIT(SgAsmLEPageTableEntry)
695  GEN_VISIT(SgAsmLEEntryPoint)
696  GEN_VISIT(SgAsmLESectionTableEntry)
697  GEN_VISIT(SgAsmGenericSectionList)
698  GEN_VISIT(SgAsmGenericHeaderList)
699  GEN_VISIT(SgAsmGenericSymbolList)
700  GEN_VISIT(SgAsmElfSymbolList)
701  GEN_VISIT(SgAsmCoffSymbolList)
702  GEN_VISIT(SgAsmGenericDLLList)
703  GEN_VISIT(SgAsmPERVASizePairList)
704  GEN_VISIT(SgAsmPEExportEntryList)
705  GEN_VISIT(SgAsmBasicString)
706  GEN_VISIT(SgAsmStoredString)
707  GEN_VISIT(SgAsmGenericString)
708  GEN_VISIT(SgAsmStringStorage)
709  GEN_VISIT(SgAsmDwarfMacro)
710  GEN_VISIT(SgAsmDwarfLine)
711  GEN_VISIT(SgAsmDwarfMacroList)
712  GEN_VISIT(SgAsmDwarfLineList)
713  GEN_VISIT(SgAsmDwarfArrayType)
714  GEN_VISIT(SgAsmDwarfClassType)
715  GEN_VISIT(SgAsmDwarfEntryPoint)
716  GEN_VISIT(SgAsmDwarfEnumerationType)
717  GEN_VISIT(SgAsmDwarfFormalParameter)
719  GEN_VISIT(SgAsmDwarfLabel)
720  GEN_VISIT(SgAsmDwarfLexicalBlock)
721  GEN_VISIT(SgAsmDwarfMember)
722  GEN_VISIT(SgAsmDwarfPointerType)
723  GEN_VISIT(SgAsmDwarfReferenceType)
724  GEN_VISIT(SgAsmDwarfCompilationUnit)
725  GEN_VISIT(SgAsmDwarfStringType)
726  GEN_VISIT(SgAsmDwarfStructureType)
727  GEN_VISIT(SgAsmDwarfSubroutineType)
728  GEN_VISIT(SgAsmDwarfTypedef)
729  GEN_VISIT(SgAsmDwarfUnionType)
731  GEN_VISIT(SgAsmDwarfVariant)
732  GEN_VISIT(SgAsmDwarfCommonBlock)
733  GEN_VISIT(SgAsmDwarfCommonInclusion)
734  GEN_VISIT(SgAsmDwarfInheritance)
735  GEN_VISIT(SgAsmDwarfInlinedSubroutine)
736  GEN_VISIT(SgAsmDwarfModule)
737  GEN_VISIT(SgAsmDwarfPtrToMemberType)
738  GEN_VISIT(SgAsmDwarfSetType)
739  GEN_VISIT(SgAsmDwarfSubrangeType)
740  GEN_VISIT(SgAsmDwarfWithStmt)
741  GEN_VISIT(SgAsmDwarfAccessDeclaration)
742  GEN_VISIT(SgAsmDwarfBaseType)
743  GEN_VISIT(SgAsmDwarfCatchBlock)
744  GEN_VISIT(SgAsmDwarfConstType)
745  GEN_VISIT(SgAsmDwarfConstant)
746  GEN_VISIT(SgAsmDwarfEnumerator)
747  GEN_VISIT(SgAsmDwarfFileType)
748  GEN_VISIT(SgAsmDwarfFriend)
749  GEN_VISIT(SgAsmDwarfNamelist)
750  GEN_VISIT(SgAsmDwarfNamelistItem)
751  GEN_VISIT(SgAsmDwarfPackedType)
752  GEN_VISIT(SgAsmDwarfSubprogram)
755  GEN_VISIT(SgAsmDwarfThrownType)
756  GEN_VISIT(SgAsmDwarfTryBlock)
757  GEN_VISIT(SgAsmDwarfVariantPart)
758  GEN_VISIT(SgAsmDwarfVariable)
759  GEN_VISIT(SgAsmDwarfVolatileType)
760  GEN_VISIT(SgAsmDwarfDwarfProcedure)
761  GEN_VISIT(SgAsmDwarfRestrictType)
762  GEN_VISIT(SgAsmDwarfInterfaceType)
763  GEN_VISIT(SgAsmDwarfNamespace)
764  GEN_VISIT(SgAsmDwarfImportedModule)
765  GEN_VISIT(SgAsmDwarfUnspecifiedType)
766  GEN_VISIT(SgAsmDwarfPartialUnit)
767  GEN_VISIT(SgAsmDwarfImportedUnit)
768  GEN_VISIT(SgAsmDwarfMutableType)
769  GEN_VISIT(SgAsmDwarfCondition)
770  GEN_VISIT(SgAsmDwarfSharedType)
771  GEN_VISIT(SgAsmDwarfFormatLabel)
772  GEN_VISIT(SgAsmDwarfFunctionTemplate)
773  GEN_VISIT(SgAsmDwarfClassTemplate)
774  GEN_VISIT(SgAsmDwarfUpcSharedType)
775  GEN_VISIT(SgAsmDwarfUpcStrictType)
776  GEN_VISIT(SgAsmDwarfUpcRelaxedType)
777  GEN_VISIT(SgAsmDwarfUnknownConstruct)
778  GEN_VISIT(SgAsmDwarfConstruct)
779  GEN_VISIT(SgAsmDwarfConstructList)
781  GEN_VISIT(SgAsmDwarfInformation)
782  GEN_VISIT(SgAsmExecutableFileFormat)
783  GEN_VISIT(SgAsmInterpretation)
784  GEN_VISIT(SgAsmInterpretationList)
785  GEN_VISIT(SgAsmGenericFileList)
786  GEN_VISIT(SgAsmNode)
787 #endif /* WITH_BINARY_ANALYSIS */
788 
789  // Support nodes
790  GEN_VISIT(SgLocatedNodeSupport)
791  GEN_VISIT(SgInitializedName)
792  GEN_VISIT(SgLambdaCapture)
793  GEN_VISIT(SgLambdaCaptureList)
794  GEN_VISIT(SgRenamePair)
795  GEN_VISIT(SgInterfaceBody)
796  GEN_VISIT(SgHeaderFileBody)
797 
798  // - OMP Nodes
799  GEN_VISIT(SgOmpOrderedClause)
800  GEN_VISIT(SgOmpNowaitClause)
801  GEN_VISIT(SgOmpUntiedClause)
802  GEN_VISIT(SgOmpMergeableClause)
803  GEN_VISIT(SgOmpDefaultClause)
804  GEN_VISIT(SgOmpCollapseClause)
805  GEN_VISIT(SgOmpIfClause)
806  GEN_VISIT(SgOmpFinalClause)
807  GEN_VISIT(SgOmpPriorityClause)
808  GEN_VISIT(SgOmpNumThreadsClause)
809  GEN_VISIT(SgOmpExpressionClause)
810  GEN_VISIT(SgOmpCopyprivateClause)
811  GEN_VISIT(SgOmpPrivateClause)
812  GEN_VISIT(SgOmpFirstprivateClause)
813  GEN_VISIT(SgOmpSharedClause)
814  GEN_VISIT(SgOmpCopyinClause)
815  GEN_VISIT(SgOmpLastprivateClause)
816  GEN_VISIT(SgOmpReductionClause)
817  GEN_VISIT(SgOmpVariablesClause)
818  GEN_VISIT(SgOmpScheduleClause)
819  GEN_VISIT(SgOmpDependClause)
820  GEN_VISIT(SgOmpClause)
821 
822  //
823  // Types
824  GEN_VISIT(SgTypeUnknown)
825  GEN_VISIT(SgTypeChar)
826  GEN_VISIT(SgTypeChar16)
827  GEN_VISIT(SgTypeSignedChar)
828  GEN_VISIT(SgTypeChar32)
829  GEN_VISIT(SgTypeUnsignedChar)
830  GEN_VISIT(SgTypeShort)
831  GEN_VISIT(SgTypeSignedShort)
832  GEN_VISIT(SgTypeUnsignedShort)
833  GEN_VISIT(SgTypeInt)
834  GEN_VISIT(SgTypeSignedInt)
835  GEN_VISIT(SgTypeUnsignedInt)
836  GEN_VISIT(SgTypeLong)
837  GEN_VISIT(SgTypeSignedLong)
838  GEN_VISIT(SgTypeUnsignedLong)
839  GEN_VISIT(SgTypeVoid)
840  GEN_VISIT(SgTypeGlobalVoid)
841  GEN_VISIT(SgTypeWchar)
842  GEN_VISIT(SgTypeFloat)
843  GEN_VISIT(SgTypeDouble)
844  GEN_VISIT(SgTypeLongLong)
845  GEN_VISIT(SgTypeSignedLongLong)
846  GEN_VISIT(SgTypeUnsignedLongLong)
847  GEN_VISIT(SgTypeLongDouble)
848  GEN_VISIT(SgTypeString)
849  GEN_VISIT(SgTypeBool)
850  GEN_VISIT(SgTypeComplex)
851  GEN_VISIT(SgTypeImaginary)
852  GEN_VISIT(SgTypeDefault)
853  GEN_VISIT(SgPointerMemberType)
854  GEN_VISIT(SgReferenceType)
855  GEN_VISIT(SgRvalueReferenceType)
856  GEN_VISIT(SgTypeCAFTeam)
857  GEN_VISIT(SgClassType)
858  GEN_VISIT(SgTemplateType)
859  GEN_VISIT(SgEnumType)
860  GEN_VISIT(SgTypedefType)
861  GEN_VISIT(SgModifierType)
863  GEN_VISIT(SgArrayType)
864  GEN_VISIT(SgTypeEllipse)
865  GEN_VISIT(SgTypeCrayPointer)
866  GEN_VISIT(SgPartialFunctionType)
867  GEN_VISIT(SgMemberFunctionType)
868  GEN_VISIT(SgFunctionType)
869  GEN_VISIT(SgPointerType)
870  GEN_VISIT(SgNamedType)
871  GEN_VISIT(SgQualifiedNameType)
872  // DQ (4/5/2017): Added this case that shows up using GNU 6.1 and Boost 1.51 (or Boost 1.52).
873  GEN_VISIT(SgDeclType)
874  GEN_VISIT(SgAutoType)
875  GEN_VISIT(SgTypeSigned128bitInteger)
876  GEN_VISIT(SgTypeUnsigned128bitInteger)
877  GEN_VISIT(SgTypeNullptr)
878 
879  // * token
880  GEN_VISIT(SgToken)
881 
882  RoseVisitor rv;
883  };
884 
885 #undef GEN_VISIT
886 
887 
888 
889 #if __cplusplus >= 201103L
890  template <class RoseVisitor>
891  inline
892  typename std::remove_const<typename std::remove_reference<RoseVisitor>::type>::type
893  _dispatch(RoseVisitor&& rv, SgNode* n)
894  {
895  typedef typename std::remove_reference<RoseVisitor>::type RoseVisitorNoref;
896  typedef typename std::remove_const<RoseVisitorNoref>::type RoseHandler;
897 
898  ROSE_ASSERT(n);
899 
900  VisitDispatcher<RoseHandler> vis( std::forward<RoseVisitor>(rv),
901  std::is_lvalue_reference<RoseVisitor>()
902  );
903 
904  n->accept(vis);
905  return std::move(vis).rv;
906  }
907 #else
908  template <class RoseVisitor>
909  inline
910  RoseVisitor
911  _dispatch(const RoseVisitor& rv, SgNode* n)
912  {
913  ROSE_ASSERT(n);
914 
915  VisitDispatcher<RoseVisitor> vis(rv);
916 
917  n->accept(vis);
918  return vis.rv;
919  }
920 #endif
921 
922 
978 #if 0
979 #endif
990 
991 #if __cplusplus >= 201103L
992  template <class RoseVisitor>
993  inline
994  typename std::remove_const<typename std::remove_reference<RoseVisitor>::type>::type
995  dispatch(RoseVisitor&& rv, SgNode* n)
996  {
997  //~ return std::move(rv);
998  return _dispatch(std::forward<RoseVisitor>(rv), n);
999  }
1000 
1001  template <class RoseVisitor>
1002  inline
1003  typename std::remove_const<typename std::remove_reference<RoseVisitor>::type>::type
1004  dispatch(RoseVisitor&& rv, const SgNode* n)
1005  {
1006  //~ return std::move(rv);
1007  return _dispatch(std::forward<RoseVisitor>(rv), const_cast<SgNode*>(n));
1008  }
1009 #else
1010  template <class RoseVisitor>
1011  inline
1012  RoseVisitor
1013  dispatch(const RoseVisitor& rv, SgNode* n)
1014  {
1015  return _dispatch(rv, n);
1016  }
1017 
1019  template <class RoseVisitor>
1020  inline
1021  RoseVisitor
1022  dispatch(const RoseVisitor& rv, const SgNode* n)
1023  {
1024  return _dispatch(rv, const_cast<SgNode*>(n));
1025  }
1026 #endif /* c++11 */
1027 
1037  template <class SageNode>
1039  {
1040  void handle(SageNode&) {}
1041  };
1042 
1050  template <class AncestorNode, class QualSgNode>
1051  struct AncestorTypeFinder : DefaultHandler<const SgProject>
1052  {
1054  typedef std::pair<AncestorNode*, QualSgNode*> Pair;
1055 
1056  Pair res;
1057 
1059  : Base(), res(NULL, NULL)
1060  {}
1061 
1062  // handling of const SgProject is outsourced to DefaultHandler
1063  // thus, AncestorNode = const SgProject does not cause conflicts
1064  using Base::handle;
1065 
1066  void handle(QualSgNode& n) { res.second = n.get_parent(); }
1067  void handle(AncestorNode& n) { res.first = &n; }
1068 
1069  operator Pair() const { return res; }
1070  };
1071 
1074  template <class AncestorNode, class QualSgNode>
1075  AncestorNode* _ancestor(QualSgNode& n)
1076  {
1077  typedef AncestorTypeFinder<AncestorNode, QualSgNode> AncestorFinder;
1078 
1079  typename AncestorFinder::Pair res(NULL, n.get_parent());
1080 
1081  while (res.second != NULL)
1082  {
1083  res = (typename AncestorFinder::Pair) sg::dispatch(AncestorFinder(), res.second);
1084  }
1085 
1086  return res.first;
1087  }
1088 
1100  template <class AncestorNode>
1101  AncestorNode* ancestor(SgNode* n)
1102  {
1103  if (n == NULL) return NULL;
1104 
1105  return _ancestor<AncestorNode>(*n);
1106  }
1107 
1109  template <class AncestorNode>
1110  const AncestorNode* ancestor(const SgNode* n)
1111  {
1112  if (n == NULL) return NULL;
1113 
1114  return _ancestor<const AncestorNode>(*n);
1115  }
1116 
1118  template <class AncestorNode>
1119  AncestorNode& ancestor(SgNode& n)
1120  {
1121  AncestorNode* res = _ancestor<AncestorNode>(n);
1122 
1123  ROSE_ASSERT(res);
1124  return *res;
1125  }
1126 
1128  template <class AncestorNode>
1129  const AncestorNode& ancestor(const SgNode& n)
1130  {
1131  const AncestorNode* res = _ancestor<const AncestorNode>(n);
1132 
1133  ROSE_ASSERT(res);
1134  return *res;
1135  }
1136 
1138  template <class SageNode>
1139  struct TypeRecoveryHandler
1140  {
1141  typedef typename ConstLike<SageNode, SgNode>::type SgBaseNode;
1142 
1143  TypeRecoveryHandler(const char* f = 0, size_t ln = 0)
1144  : res(NULL), loc(f), loc_ln(ln)
1145  {}
1146 
1147 #if __cplusplus >= 201103L
1148  TypeRecoveryHandler(TypeRecoveryHandler&&) = default;
1149 
1150  TypeRecoveryHandler() = delete;
1151  TypeRecoveryHandler(const TypeRecoveryHandler&) = delete;
1152  TypeRecoveryHandler& operator=(const TypeRecoveryHandler&) = delete;
1153  TypeRecoveryHandler& operator=(TypeRecoveryHandler&&) = delete;
1154 
1155  operator SageNode* ()&& { return res; }
1156 #else
1157  operator SageNode* () { return res; }
1158 #endif /* C++ */
1159 
1160  void handle(SgBaseNode& n) { unexpected_node(n, loc, loc_ln); }
1161  void handle(SageNode& n) { res = &n; }
1162 
1163  SageNode* res;
1164  const char* loc;
1165  size_t loc_ln;
1166  };
1167 
1168 
1177  template <class SageNode>
1178  SageNode* assert_sage_type(SgNode* n, const char* f = 0, size_t ln = 0)
1179  {
1180  return sg::dispatch(TypeRecoveryHandler<SageNode>(f, ln), n);
1181  }
1182 
1183  template <class SageNode>
1184  const SageNode* assert_sage_type(const SgNode* n, const char* f = 0, size_t ln = 0)
1185  {
1186  return sg::dispatch(TypeRecoveryHandler<const SageNode>(f, ln), n);
1187  }
1188 
1189  template <class SageNode>
1190  SageNode& assert_sage_type(SgNode& n, const char* f = 0, size_t ln = 0)
1191  {
1192  return *sg::dispatch(TypeRecoveryHandler<SageNode>(f, ln), &n);
1193  }
1194 
1195  template <class SageNode>
1196  const SageNode& assert_sage_type(const SgNode& n, const char* f = 0, size_t ln = 0)
1197  {
1198  return *sg::dispatch(TypeRecoveryHandler<const SageNode>(f, ln), &n);
1199  }
1201 
1204  static inline
1205  void swap_parent(SgNode* lhs, SgNode* rhs)
1206  {
1207  SgNode* tmp = lhs->get_parent();
1208 
1209  lhs->set_parent(rhs->get_parent());
1210  rhs->set_parent(tmp);
1211  }
1212 
1216  static inline
1217  void swap_parent(void*, void*) {}
1218 
1226  template <class SageNode, class SageChild>
1227  void swap_child(SageNode& lhs, SageNode& rhs, SageChild* (SageNode::*getter) () const, void (SageNode::*setter) (SageChild*))
1228  {
1229  SageChild* lhs_child = (lhs.*getter)();
1230  SageChild* rhs_child = (rhs.*getter)();
1231  ROSE_ASSERT(lhs_child && rhs_child);
1232 
1233  (lhs.*setter)(rhs_child);
1234  (rhs.*setter)(lhs_child);
1235 
1236  swap_parent(lhs_child, rhs_child);
1237  }
1238 
1239 
1242  template <class SageNode>
1244  {
1245  typedef void (*TransformHandlerFn)(SageNode*);
1246 
1247  explicit
1248  TraversalFunction(TransformHandlerFn fun)
1249  : fn(fun)
1250  {}
1251 
1252  void handle(SgNode&) { /* ignore */ }
1253  void handle(SageNode& n) { fn(&n); }
1254 
1255  TransformHandlerFn fn;
1256  };
1257 
1260  template <class SageNode>
1261  static inline
1263  createTraversalFunction(void (* fn)(SageNode*))
1264  {
1265  return TraversalFunction<SageNode>(fn);
1266  }
1267 
1268  //
1269  // function type extractor
1270  // see https://stackoverflow.com/questions/28033251/can-you-extract-types-from-template-parameter-function-signature
1271 
1272 
1273  template <class GVisitor>
1275  {
1276  explicit
1277  TraversalClass(GVisitor gv)
1278  : gvisitor(gv)
1279  //~ : gvisitor(std::move(gv))
1280  {}
1281 
1282  void visit(SgNode* n)
1283  {
1284  gvisitor = sg::dispatch(gvisitor, n);
1285  }
1286 
1287  // GVisitor&& visitor() { return std::move(gvisitor); }
1288  GVisitor visitor() { return gvisitor; }
1289 
1290  GVisitor gvisitor;
1291  };
1292 
1293 
1294 
1301  template <class F>
1302  static inline
1303  F
1304  forAllNodes(F fn, SgNode* root, AstSimpleProcessing::Order order = postorder)
1305  {
1306  ROSE_ASSERT(root);
1307 
1308  TraversalClass<F> tt(fn);
1309  //~ TraversalClass<F> tt(std::move(fn));
1310 
1311  tt.traverse(root, order);
1312  return tt.visitor();
1313  }
1314 
1315  template <class SageNode>
1316  static inline
1317  void
1318  forAllNodes(void (*fn)(SageNode*), SgNode* root, AstSimpleProcessing::Order order = postorder)
1319  {
1320  forAllNodes(createTransformExecutor(fn), root, order);
1321  }
1322 
1323 #if !defined(NDEBUG)
1324  static inline
1325  std::string nodeType(const SgNode& n)
1326  {
1327  return typeid(n).name();
1328  }
1329 
1330  static inline
1331  std::string nodeType(const SgNode* n)
1332  {
1333  if (n == NULL) return "<null>";
1334 
1335  return nodeType(*n);
1336  }
1337 #endif
1338 
1339  template <class GVisitor>
1341  {
1342 #if __cplusplus >= 201103L
1343  explicit
1344  DispatchHelper(GVisitor gv, SgNode* p)
1345  : gvisitor(std::move(gv)), parent(p), cnt(0)
1346  {}
1347 #else
1348  explicit
1349  DispatchHelper(GVisitor gv, SgNode* p)
1350  : gvisitor(gv), parent(p), cnt(0)
1351  {}
1352 #endif /* C++11 */
1353 
1354  void operator()(SgNode* n)
1355  {
1356  ++cnt;
1357 
1358 #if 0
1359  if (n == NULL)
1360  {
1361  std::cerr << "succ(" << nodeType(parent) << ", " << cnt << ") is null" << std::endl;
1362  return;
1363  }
1364 #endif
1365 
1366 #if __cplusplus >= 201103L
1367  if (n != NULL) gvisitor = sg::dispatch(std::move(gvisitor), n);
1368 #else
1369  if (n != NULL) gvisitor = sg::dispatch(gvisitor, n);
1370 #endif /* C++11 */
1371  }
1372 
1373 #if __cplusplus >= 201103L
1374  operator GVisitor()&& { return std::move(gvisitor); }
1375 #else
1376  operator GVisitor() { return gvisitor; }
1377 #endif /* C++11 */
1378 
1379  GVisitor gvisitor;
1380  SgNode* parent;
1381  size_t cnt;
1382  };
1383 
1384 
1385  template <class GVisitor>
1386  static inline
1388  dispatchHelper(GVisitor gv, SgNode* parent = NULL)
1389  {
1390 #if __cplusplus >= 201103L
1391  return DispatchHelper<GVisitor>(std::move(gv), parent);
1392 #else
1393  return DispatchHelper<GVisitor>(gv, parent);
1394 #endif /* C++11 */
1395  }
1396 
1397 
1398  template <class GVisitor>
1399  static inline
1400  GVisitor traverseChildren(GVisitor gv, SgNode& n)
1401  {
1402  std::vector<SgNode*> successors = n.get_traversalSuccessorContainer();
1403 
1404 #if __cplusplus >= 201103L
1405  return std::for_each(successors.begin(), successors.end(), dispatchHelper(std::move(gv), &n));
1406 #else
1407  return std::for_each(successors.begin(), successors.end(), dispatchHelper(gv, &n));
1408 #endif /* C++11 */
1409  }
1410 
1411  template <class GVisitor>
1412  static inline
1413  GVisitor traverseChildren(GVisitor gv, SgNode* n)
1414  {
1415  return traverseChildren(gv, sg::deref(n));
1416  }
1417 }
1418 #endif /* _SAGEGENERIC_H */
This class represents modifiers for SgDeclaration (declaration statements).
List of pointers to file sections.
This class represents the notion of an initializer for a variable declaration or expression in a func...
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
The GNU symbol version definitions.
This class represents the concept of a C++ template instantiation directive.
This class represents the concept of an instantiation of member function template or a member functio...
This class represents the concept of a class declaration statement. It includes the concept of an ins...
This class represents the concept of a declaration list.
This class represents a boolean value (expression value).
One entry of the ELF symbol version needed table.
This class represents a OLD concept of the structure require for qualified names when they were in th...
String associated with a binary file.
Expression that adds two operands.
This class represents the concept of an instantiated class template.
This class represents the notion of an value (expression value).
List of dynamic linking section entries.
This class represents the concept of a C or C++ goto statement.
Contiguous region of a file.
This class represents the concept of a C or C++ statement which contains a expression.
Expression that performs a post-increment operation.
Expression representing a (no-op) unary plus operation.
This class represents the notion of a binary operator. It is derived from a SgExpression because oper...
Expression that performs a right rotate.
Auxiliary info for needed symbol version.
Instruction basic block.
Base class for all binary analysis IR nodes.
This class represents a source file for a project (which may contian many source files and or directo...
List of entries for the ELF symbol version definition table.
This class represents the variable declaration or variable initialization withn a for loop...
One entry of an ELF relocation table.
This class represents the concept of a C++ sequence of catch statements.
This class represents the notion of a unary operator. It is derived from a SgExpression because opera...
Represents the file header of an ELF binary container.
This class represents the GNU extension "statement expression" (thus is non-standard C and C++)...
Class for traversing the AST.
This class represents the C++ throw expression (handled as a unary operator).
Expression that performs a post-decrement operation.
This class represents the rhs of a variable declaration which includes an optional assignment (e...
Portable Executable Import Section.
This class represents the concept of a C++ using directive.
List of generic file headers.
List of binary interpretations.
Base class for machine instructions.
This class represents the concept of a do-while statement.
This class represents a Fortran pointer assignment. It is not some weird compound assignment operator...
Section table entry.
This class represents the concept of a class name within the compiler.
This class represents the location of the code associated with the IR node in the original source cod...
This class represents the concept of an enum declaration.
Base class for scalar types.
List of expression nodes.
This class represents the "this" operator (can be applied to any member data).
Expression that performs an arithmetic, sign-bit preserving right shift.
void set_parent(SgNode *parent)
All nodes in the AST contain a reference to a parent node.
This class represents a string type used for SgStringVal IR node.
Expression that performs a logical, sign-bit non-preserving right shift.
This class represents the concept of a C style extern "C" declaration. But such information (linkage)...
This class represents the notion of a declared variable.
Strings stored in an ELF or PE container.
This class represents the concept of a member function declaration statement.
Expression that returns the remainder when dividing the first operand by the second.
This class represents the concept of a C and C++ case option (used within a switch statement)...
This class represents the concept of a function declaration statement.
Node to hold a list of symbol node pointers.
Base class for ELF file sections.
This class represents the concept of a C Assembler statement (untested).
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
Base class for PE sections.
This class represents the concept of a C and C++ expression list.
This class represents the "sizeof()" operator (applied to any type).
Expression that divides the first operand by the second.
Hods a list of symbol version aux entries.
COFF symbol string table.
Basic information about an executable container.
This class represents the concept of a C++ namespace alias declaration statement. ...
This class is not used in ROSE, but is intended to represent a list of SgModifierTypes (similar to th...
This class represents the base class of a numbr of IR nodes that don't otherwise fit into the existin...
Definition: Cxx_Grammar.h:9951
Entry in an ELF symbol version table.
This class represents a directory within a projects file structure of files and directories.
This class represents the notion of an value (expression value).
ELF error handling frame entry frame description entry.
This class represents the concept of a C trinary conditional expression (e.g. "test ...
Represents an ELF relocation section.
One import directory per library.
void visit(SgNode *n)
this method is called at every traversed node.
Definition: sageGeneric.h:1282
GNU symbol version requirements table.
List of ELF relocation entries.
This class represents the notion of a break statement (typically used in a switch statment)...
List of AST file node pointers.
This class represents the concept of a name within the compiler.
ELF section containing dynamic linking information.
executes a functor for a specific node type
Definition: sageGeneric.h:1243
Represents the file header for DOS executables.
List of ELF EH frame CI entries.
struct DefaultHandler
Definition: sageGeneric.h:1038
Represents an ELF EH frame section.
One entry of an ELF notes table.
ELF string table section.
This class represents the concept of a class definition in C++.
This class represents strings within the IR nodes.
Reference to memory locations.
projects the constness of T1 on T2
Definition: sageGeneric.h:52
struct DispatchHandler
Definition: sageGeneric.h:132
This class represents the concept of a contructor initializer list (used in constructor (member funct...
Base class for container file headers.
Expression represting negation.
List of pointers to other AST nodes.
Expression representing a machine register.
Base class for integer values.
This class represents the concept of a namespace name within the compiler.
This class represents the notion of a typedef declaration.
ELF file section containing symbols.
This class represents the notion of an value (expression value).
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:8968
List of operands for an instruction.
This class represents the concept of a catch within a try-catch construct used in C++ exception handl...
Base class for dynamically linked library information.
This class represents the notion of an value (expression value).
This class represents the concept of a variable name within the compiler (a shared container for the ...
This class represents the concept of an instantiation of function template.
Expression that performs a pre-decrement operation.
Expression that performs a pre-increment operation.
This class represents the "&" operator (applied to any lvalue).
A single imported object.
Represents one PowerPC machine instruction.
One entry from an ELF symbol version definition table.
Represents a single ELF symbol.
This class represents the base class of a number of IR nodes define modifiers within the C++ grammar...
This class represents the concept of a block (not a basic block from control flow analysis)...
This class represents the concept of a C++ namespace declaration.
Base class for strings related to binary specimens.
This class represents the concept of a namespace definition.
This class represents the concept of a for loop.
DOS exteded header.
List of COFF symbols.
Base class for unary expressions.
Base class for many binary analysis nodes.
Represents one Intel x86 machine instruction.
This class represents the concept of a C++ using declaration.
This class represents a C99 complex type.
Base class for statement-like subclasses.
This class represents a type for all functions.
This class represents the concept of a namespace definition.
This class represents the numeric negation of a value. Not to be confused with SgSubtractOp.
This class represents the concept of a C Assembler statement (untested).
Represents one entry of a segment table.
This class represents the concept of a C or C++ default case within a switch statement.
Base class for expressions.
This class represents a default type used for some IR nodes (see below).
This class represents the concept of an "if" construct.
virtual std::vector< SgNode * > get_traversalSuccessorContainer()
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
This class represents the concept of a template declaration.
Expression that performs a logical left shift operation.
List of pointers to other nodes.
Expression that multiplies two operands.
This class represents template argument within the use of a template to build an instantiation.
This class represents the variable refernece in expressions.
Represents one ARM machine instruction.
Node to hold list of ELF note entries.
This class represents the concept of a do-while statement.
This class represents a OLD concept of the structure require for qualified names when they were in th...
List of entries from a symbol version table.
List of SgAsmPERVASizePair AST nodes.
Base class for binary types.
This class represents the definition (initialization) of a variable.
This class represents the concept of a class definition in C++.
This class represents the concept of a C++ call to the delete operator.
Export file section.
virtual void accept(ROSE_VisitorPattern &visitor)
support for the classic visitor pattern done in GoF
helper class for _ancestor
Definition: sageGeneric.h:1051
Registers accessed indirectly.
This class represents the concept of a C++ call to the new operator.
This class represents the concept of a C or C++ continue statement.
This class represents an object used to initialize the unparsing.
Base class for values.
Floating-point value.
This class represents the member function being called and must be assembled in the SgFunctionCall wi...
Windows PE file header.
This class represents modifiers specific to storage.
This class represents the symbol tables used in both SgScopeStatement and the SgFunctionTypeSymbolTab...
Expression that subtracts the second operand from the first.
SgNode * get_parent() const
Access function for parent node.
This class represents the function being called and must be assembled in the SgFunctionCall with the ...
This class represents the concept of try statement within the try-catch support for exception handlin...
This class represents the concept of a C Assembler statement.
This class represents the concept of a name and a type. It may be renamed in the future to SgTypeSymb...
This class represents a list of associated typedefs for the SgType IR nodes which reference this list...
One entry from the dynamic linking table.
This class represents a source project, with a list of SgFile objects and global information about th...
This class represents the function type table (stores all function types so that they can be shared i...
Integer types.
This class represents a C99 complex type.
This class represents the concept of a C or C++ variable declaration.
This class represents the notion of an initializer for a variable declaration or expression in a func...
The ELF symbol version table.
Represents one entry in an ELF section table.
Represents an ELF segment table.
Strings stored in an ELF or PE container.
Represents an ELF section table.
ELF string table.
A list of imported items.
Represents an interpretation of a binary container.
This class represents the concept of a C or C++ label statement.
List of symbol version needed entries.
Floating point types.
This class is part of the older CC++ concept. It is not a part of C or C++ (this IR node is not used ...
This class represents the concept of a C++ function call (which is an expression).
Base class for binary files.
Base class for binary expressions.
Base class for vector types.
This class was part of CC++ support from a long time ago.
List of symbol version aux entries.
This class represents the concept of a declaration statement.
This class represents the concept of a switch.
This class represents the concept of a C++ expression built from a class name.
A list of PE Import Directories.
ELF error handling frame entry, common information entry.
COFF symbol table.