ROSE  0.11.2.0
AstProcessing.h
1 // Original Author (AstProcessing classes): Markus Schordan
2 // Rewritten by: Gergo Barany
3 
4 #ifndef ASTPROCESSING_H
5 #define ASTPROCESSING_H
6 #define INHERITED 0
7 #define SYNTHESIZED 1
8 #define BOTH 2
9 
10 
11 
12 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
13  #include "staticCFG.h"
14 #endif
15 
16 #include <vector>
17 #include <algorithm>
18 #include <utility>
19 #include <iostream>
20 
21 //using namespace boost;
22 
23 //bool end = false;
24 
25 //using namespace std;
26 
27 // tps (01/08/2010) Added sage3basic since this doesnt compile under gcc4.1.2
28 //#include "sage3basic.h"
29 //#include "sage3.h"
30 // Non-templated helper function in AstProcessing.C
31 
32 
33 
34 
35 ROSE_DLL_API bool
36 SgTreeTraversal_inFileToTraverse(SgNode* node, bool traversalConstraint, SgFile* fileToVisit);
37 
38 /*
39  GB (06/01/2007):
40  Changes to the original code were roughly:
41  - removed unneeded includes and other code
42  - removed everything related to visit flags
43  - changed support for SynthesizedAttributesList; synthesized attributes are
44  now handled in a smarter way, by keeping them on a stack and (in
45  principle) only passing iterators instead of copying a container;
46  traverse() is now only a thin wrapper around performTraversal() that
47  takes care of visiting nodes and pushing/popping synthesized attributes
48  - rewrote inFileToTraverse() to use new AST features instead of lots of
49  string comparisons; it is now explicitly stated (at least in this
50  comment) that we *do* visit subtrees from other files unless their root
51  is in global or namespace scope, which is how we hope to avoid headers
52  but still handle all included "code"
53  - renamed class _DummyAttribute because that identifier is reserved for the
54  implementation
55  - everything that was not changed in some other way was totally
56  reformatted, so diffing the old and new files won't do anything
57  meaningful
58  - appended "" suffix to pretty much any global identifier that would
59  clash with the existing ones; if this code is ever moved into ROSE to
60  replace the old version, it should not be exceedingly hard to remove the
61  suffix everywhere
62  - added some new virtual functions the user may choose to implement:
63  atTraversalStart(), atTraversalEnd(), destroyInheritedValue()
64  - other stuff I have probably forgotten
65  GB (7/6/2007):
66  - added new class AstPrePostProcessing and changed the traverseOrder
67  flag so that it can now be pre and post order at the same time
68  */
69 
70 
71 
72 
73 
74 #include "AstSuccessorsSelectors.h"
75 #include "StackFrameVector.h"
76 
77 // This type is used as a dummy template parameter for those traversals
78 // that do not use inherited or synthesized attributes.
79 typedef void *DummyAttribute;
80 // We initialize DummyAttributes to this value to avoid "may not be
81 // initialized" warnings. If you change the typedef, adjust the constant...
82 static const DummyAttribute defaultDummyAttribute = NULL;
83 // The attribute _DummyAttribute is reserved for the implementation, so we
84 // should deprecate it, but there is code using it explicitly. Which it
85 // shouldn't.
86 typedef DummyAttribute _DummyAttribute;
87 
88 
89 template <class InheritedAttributeType, class SynthesizedAttributeType>
91 
92 
93 
94 
95 // Base class for all traversals.
96 template <class InheritedAttributeType, class SynthesizedAttributeType>
98 {
99 public:
101 
102  SynthesizedAttributeType traverse(SgNode* basenode,
103  InheritedAttributeType inheritedValue,
104  t_traverseOrder travOrder = preandpostorder);
105 
106  SynthesizedAttributeType traverseWithinFile(SgNode* basenode,
107  InheritedAttributeType inheritedValue,
108  t_traverseOrder travOrder = preandpostorder);
109 
110  void traverseInputFiles(SgProject* projectNode,
111  InheritedAttributeType inheritedValue,
112  t_traverseOrder travOrder = preandpostorder);
113 
114  // Default destructor/constructor
115  virtual ~SgTreeTraversal();
116  SgTreeTraversal();
117 
118  // Copy operations
120  const SgTreeTraversal &operator=(const SgTreeTraversal &);
121 
122  friend class SgCombinedTreeTraversal<InheritedAttributeType, SynthesizedAttributeType>;
123 
124 
125 #include "Cxx_GrammarTreeTraversalAccessEnums.h"
126 
127 protected:
128  virtual InheritedAttributeType evaluateInheritedAttribute(SgNode* astNode,
129  InheritedAttributeType inheritedValue) = 0;
130 
131 
132  virtual SynthesizedAttributeType evaluateSynthesizedAttribute(SgNode* n,
133  InheritedAttributeType in,
134  SynthesizedAttributesList l) = 0;
135 
136 
137  typedef typename AstSuccessorsSelectors::SuccessorsContainer SuccessorsContainer;
138  typedef SuccessorsContainer& SuccessorsContainerRef;
139 
140  // GB (09/25/2007): Feel free to override this to implement custom traversals, but see the
141  // comment for set_useDefaultIndexBasedTraversal() below!
142  virtual void setNodeSuccessors(SgNode* node, SuccessorsContainer& succContainer);
143 
144  virtual SynthesizedAttributeType defaultSynthesizedAttribute(InheritedAttributeType inh);
145 
146  // GB (06/04/2007): A new virtual function called at the start of the
147  // traversal, before any node is actually visited; can be used to
148  // compute attributes that may have changed since the constructor was
149  // executed, but are constant during the traversal itself. A no-op by
150  // default. If you don't know what you would use this for, ignore it.
151  virtual void atTraversalStart();
152  // GB (06/13/2007): Added this just for symmetry, not sure if it is
153  // useful, but it won't hurt to have it.
154  virtual void atTraversalEnd();
155 
156  // GB (09/25/2007): This flag determines whether the new index-based traversal mechanism or the more general
157  // mechanism based on successor containers is to be used. Indexing should be faster, but it would be quite hard to
158  // adapt it to the reverse traversal and other specialized traversals. Thus: This is true by default, and anybody
159  // who overrides setNodeSuccessors() *must* change this to false to force the traversal to use their custom
160  // successor container.
161  void set_useDefaultIndexBasedTraversal(bool);
162 private:
163  void performTraversal(SgNode *basenode,
164  InheritedAttributeType inheritedValue,
165  t_traverseOrder travOrder);
166  SynthesizedAttributeType traversalResult();
167 
168  bool useDefaultIndexBasedTraversal;
169  bool traversalConstraint;
170  SgFile *fileToVisit;
171 
172  // stack of synthesized attributes; evaluateSynthesizedAttribute() is
173  // automagically called with the appropriate stack frame, which
174  // behaves like a non-resizable std::vector
175  SynthesizedAttributesList *synthesizedAttributes;
176 };
177 
178 
179 
180 template <class InheritedAttributeType, class SynthesizedAttributeType>
182 
183 template <class InheritedAttributeType, class SynthesizedAttributeType>
185  : public SgTreeTraversal<InheritedAttributeType, SynthesizedAttributeType>
186 {
187 public:
190 
191  // deprecated
192  typedef SynthesizedAttributesList SubTreeSynthesizedAttributes;
193 
195  SynthesizedAttributeType traverse(SgNode* node, InheritedAttributeType inheritedValue);
196 
197 
198 
199 
200 
201 
203  SynthesizedAttributeType traverseWithinFile(SgNode* node, InheritedAttributeType inheritedValue);
204 
205 
206  friend class AstCombinedTopDownBottomUpProcessing<InheritedAttributeType, SynthesizedAttributeType>;
207 
208 protected:
210  virtual InheritedAttributeType evaluateInheritedAttribute(SgNode* astNode,
211  InheritedAttributeType inheritedValue) = 0;
212 
217  virtual SynthesizedAttributeType evaluateSynthesizedAttribute(SgNode*,
218  InheritedAttributeType,
219  SynthesizedAttributesList) = 0;
220 
221 
222 
226  virtual void atTraversalStart();
227  virtual void atTraversalEnd();
228 };
229 
230 template <class InheritedAttributeType>
232 
233 template <class InheritedAttributeType>
235 
236 template <class InheritedAttributeType>
238  : public SgTreeTraversal<InheritedAttributeType, DummyAttribute>
239 {
240 public:
242  ::SynthesizedAttributesList SynthesizedAttributesList;
243 
245  void traverse(SgNode* node, InheritedAttributeType inheritedValue);
246 
247 
249  void traverseWithinFile(SgNode* node, InheritedAttributeType inheritedValue);
250 
251 
252  friend class AstCombinedTopDownProcessing<InheritedAttributeType>;
253  friend class DistributedMemoryAnalysisPreTraversal<InheritedAttributeType>;
254 
255 protected:
257  virtual InheritedAttributeType evaluateInheritedAttribute(SgNode* astNode,
258  InheritedAttributeType inheritedValue) = 0;
259 
260 
264  virtual void atTraversalStart();
265  virtual void atTraversalEnd();
266  // GB (06/04/2007): This is a new virtual function, a no-op by
267  // default. It is called for every node, after its successors have
268  // been visited, with the inherited attribute computed at this node.
269  // The intention is to be able to free any memory (or other resources)
270  // allocated by evaluateInheritedAttribute().
271  virtual void destroyInheritedValue(SgNode*, InheritedAttributeType);
272 
273 private:
274  DummyAttribute evaluateSynthesizedAttribute(SgNode* astNode,
275  InheritedAttributeType inheritedValue,
276  SynthesizedAttributesList l);
277 
278 
279  DummyAttribute defaultSynthesizedAttribute(InheritedAttributeType inh);
280 };
281 
282 template <class SynthesizedAttributeType>
284 
285 template <class InheritedAttributeType>
287 
288 template <class SynthesizedAttributeType>
290  : public SgTreeTraversal<DummyAttribute,SynthesizedAttributeType>
291 {
292 public:
294  ::SynthesizedAttributesList SynthesizedAttributesList;
295 
296  // deprecated
297  typedef SynthesizedAttributesList SubTreeSynthesizedAttributes;
298 
299 
300 
302  SynthesizedAttributeType traverse(SgNode* node);
303 
304 
306  SynthesizedAttributeType traverseWithinFile(SgNode* node);
307 
308 
310  void traverseInputFiles(SgProject* projectNode);
311 
312  friend class AstCombinedBottomUpProcessing<SynthesizedAttributeType>;
313  friend class DistributedMemoryAnalysisPostTraversal<SynthesizedAttributeType>;
314 
315 protected:
320  virtual SynthesizedAttributeType evaluateSynthesizedAttribute(SgNode*, SynthesizedAttributesList) = 0;
321 
322 
326  virtual SynthesizedAttributeType defaultSynthesizedAttribute();
330  virtual void atTraversalStart();
331  virtual void atTraversalEnd();
332 
333 private:
334  virtual DummyAttribute evaluateInheritedAttribute(SgNode* astNode, DummyAttribute inheritedValue);
335 
336 
337  virtual SynthesizedAttributeType evaluateSynthesizedAttribute(SgNode* astNode, DummyAttribute inheritedValue, SynthesizedAttributesList l);
338 
339 
340 
341  virtual SynthesizedAttributeType defaultSynthesizedAttribute(DummyAttribute inheritedValue);
342 };
343 
344 // deprecated classes (provided for compatibility with existing user code - will be removed at some point in future)
347 
350 
353 
354 
357 template <class InheritedAttributeType, class SynthesizedAttributeType>
358 class SgTopDownBottomUpProcessing : public AstTopDownBottomUpProcessing <InheritedAttributeType, SynthesizedAttributeType> {};
359 
361 template <class InheritedAttributeType>
362 class SgTopDownProcessing : public AstTopDownProcessing <InheritedAttributeType> {};
363 
365 template <class SynthesizedAttributeType>
366 class SgBottomUpProcessing : public AstBottomUpProcessing <SynthesizedAttributeType> {};
367 
368 // Original Author (AstProcessing classes): Markus Schordan
369 // Rewritten by: Gergo Barany
370 // $Id: AstProcessing.C,v 1.10 2008/01/25 02:25:48 dquinlan Exp $
371 
372 // For information about the changes introduced during the rewrite, see
373 // the comment in AstProcessing.h
374 
375 template<class InheritedAttributeType, class SynthesizedAttributeType>
376 void
378 setNodeSuccessors(SgNode* node, SuccessorsContainer& succContainer)
379 {
380  AstSuccessorsSelectors::selectDefaultSuccessors(node, succContainer);
381 }
382 
383 
384 
385 
386 // The default constructor of the internal tree traversal class
387 template<class InheritedAttributeType, class SynthesizedAttributeType>
390  : useDefaultIndexBasedTraversal(true),
391  traversalConstraint(false),
392  fileToVisit(NULL),
393  synthesizedAttributes(new SynthesizedAttributesList())
394 {
395 }
396 
397 #ifndef SWIG
398 // The destructor of the internal tree traversal class
399 template<class InheritedAttributeType, class SynthesizedAttributeType>
402 {
403  ROSE_ASSERT(synthesizedAttributes != NULL);
404  delete synthesizedAttributes;
405  synthesizedAttributes = NULL;
406 }
407 
408 
409 #endif
410 
411 
412 // DQ (3/30/2017): This is not called, but can not be removed (required for compiling ROSE).
413 template<class InheritedAttributeType, class SynthesizedAttributeType>
415 SgTreeTraversal(const SgTreeTraversal &other)
416  : useDefaultIndexBasedTraversal(other.useDefaultIndexBasedTraversal),
417  traversalConstraint(other.traversalConstraint),
418  fileToVisit(other.fileToVisit),
419  synthesizedAttributes(other.synthesizedAttributes->deepCopy())
420 {
421 }
422 
423 
424 // DQ (3/30/2017): This is not called and is not required for Linux compilers, but appears
425 // to be required when compiling with MSVC (Microsoft Windows).
426 template<class InheritedAttributeType, class SynthesizedAttributeType>
429 operator=(const SgTreeTraversal &other)
430 {
431  useDefaultIndexBasedTraversal = other.useDefaultIndexBasedTraversal;
432  traversalConstraint = other.traversalConstraint;
433  fileToVisit = other.fileToVisit;
434 
435  ROSE_ASSERT(synthesizedAttributes != NULL);
436  delete synthesizedAttributes;
437  synthesizedAttributes = other.synthesizedAttributes->deepCopy();
438 
439  return *this;
440 }
441 
442 
443 template<class InheritedAttributeType, class SynthesizedAttributeType>
444 void
447 {
448  useDefaultIndexBasedTraversal = val;
449 }
450 
451 // MS: 03/22/02ROSE/tests/nonsmoke/functional/roseTests/astProcessingTests/
452 // function to traverse all ASTs representing inputfiles (excluding include files),
453 template<class InheritedAttributeType, class SynthesizedAttributeType>
454 void
456 traverseInputFiles(SgProject* projectNode,
457  InheritedAttributeType inheritedValue,
458  t_traverseOrder travOrder)
459  {
460  const SgFilePtrList& fList = projectNode->get_fileList();
461 
462  // DQ (9/1/2008): It is observed that this prevents a SgProject from being built on the generated DOT file!
463  // We might want a better design to be used here or call the evaluation directly to force the handling of
464  // inherited and synthesized attributes on the SgProject. This detail effect the handling of multiple
465  // files on the command line (something we want to get a global perspective on if possible).
466  if ( SgProject::get_verbose() > 0 )
467  printf ("Warning: The traverseInputFiles() iteration over the file list prevents the evaluation of inherited and synthesized attributes on the SgProject IR node! \n");
468 
469  for (SgFilePtrList::const_iterator fl_iter = fList.begin(); fl_iter != fList.end(); fl_iter++)
470  {
471  ROSE_ASSERT(*fl_iter != NULL);
472  traverseWithinFile((*fl_iter), inheritedValue, travOrder);
473  }
474  }
475 
476 
477 
481 
482 
483 // MS: 04/25/02
484 template <class InheritedAttributeType, class SynthesizedAttributeType>
485 SynthesizedAttributeType
487 traverse(SgNode* node, InheritedAttributeType inheritedValue)
488 {
489  // this is now explicitly marked as a pre *and* post order traversal
491  ::traverse(node, inheritedValue, preandpostorder);
492 }
493 
494 
495 // MS: 04/25/02
496 template <class InheritedAttributeType, class SynthesizedAttributeType>
497 SynthesizedAttributeType
499 traverseWithinFile(SgNode* node, InheritedAttributeType inheritedValue)
500 {
501  // this is now explicitly marked as a pre *and* post order traversal
503 }
504 
508 
509 // MS: 04/25/02
510 template <class InheritedAttributeType>
511 DummyAttribute
514  InheritedAttributeType inheritedValue,
515  typename AstTopDownProcessing<InheritedAttributeType>::SynthesizedAttributesList l)
516 {
517  // call the cleanup function
518  destroyInheritedValue(astNode, inheritedValue);
519  // return value is not used
520  DummyAttribute a = defaultDummyAttribute;
521  return a;
522 }
523 
524 
525 // MS: 07/30/04
526 template <class InheritedAttributeType>
527 DummyAttribute
529 defaultSynthesizedAttribute(InheritedAttributeType inh)
530 {
531  // called but not used
532  DummyAttribute a = defaultDummyAttribute;
533  return a;
534 }
535 
536 // MS: 04/25/02
537 template <class InheritedAttributeType>
538 void
540 traverse(SgNode* node, InheritedAttributeType inheritedValue)
541 {
542  // "top down" is now marked as a pre *and* post order traversal because
543  // there is a post order component (the call to destroyInheritedAttribute)
545  ::traverse(node, inheritedValue, preandpostorder);
546 }
547 
548 
549 // MS: 09/30/02
550 template <class InheritedAttributeType>
551 void
553 traverseWithinFile(SgNode* node, InheritedAttributeType inheritedValue)
554 {
555  // "top down" is now marked as a pre *and* post order traversal because
556  // there is a post order component (the call to destroyInheritedAttribute)
558 }
559 
560 
564 
565 
566 // MS: 04/25/02
567 template <class SynthesizedAttributeType>
568 DummyAttribute
570 evaluateInheritedAttribute(SgNode*, DummyAttribute /*inheritedValue*/)
571 {
572  /* called but not used */
573  DummyAttribute a = defaultDummyAttribute;
574  return a;
575 }
576 
577 
578 
579 // MS: 30/07/04
580 template <class SynthesizedAttributeType>
583 {
584  // GB (8/6/2007): This can give "may not be initialized" warnings when
585  // compiling with optimization (because -O flags cause gcc to perform
586  // data-flow analysis). I wonder how this might be fixed.
587  SynthesizedAttributeType s = SynthesizedAttributeType();
588  return s;
589 }
590 
591 // MS: 30/07/04
592 template <class SynthesizedAttributeType>
594 defaultSynthesizedAttribute(DummyAttribute /*inheritedValue*/)
595 {
596  return defaultSynthesizedAttribute();
597 }
598 
599 // MS: 04/25/02//ENDEDIT
600 template <class SynthesizedAttributeType>
603  DummyAttribute /*inheritedValue*/,
604  SynthesizedAttributesList l)
605 {
606  return evaluateSynthesizedAttribute(astNode, l);
607 }
608 
609 
610 
611 
612 
613 // MS: 04/25/02
614 template <class SynthesizedAttributeType>
617 {
618 
619  static DummyAttribute da;
621  ::traverse(node, da, postorder);
622 
623 }
624 
625 // MS: 04/25/02
626 template <class SynthesizedAttributeType>
629 {
630  static DummyAttribute da;
632 }
633 
634 
635 
636 // MS: 04/25/02
637 template <class SynthesizedAttributeType>
640 {
641  static DummyAttribute da;
642  // GB (8/6/2007): This is now a postorder traversal; this did not really
643  // matter until now, but now evaluateSynthesizedAttribute is only called
644  // for traversals that have the postorder bit set.
646  ::traverseInputFiles(projectNode, da, postorder);
647 }
648 #ifdef _MSC_VER
649 //class BooleanQueryInheritedAttributeType;
650 #include "../astQuery/booleanQuery.h"
651 #include "../astQuery/booleanQueryInheritedAttribute.h"
652 #endif
653 // MS: 07/29/04
654 template <class InheritedAttributeType, class SynthesizedAttributeType>
656 defaultSynthesizedAttribute(InheritedAttributeType /*inh*/)
657 {
658  // we provide 'inh' but do not use it in the constructor of 's' to allow primitive types
659  SynthesizedAttributeType s = SynthesizedAttributeType();
660  return s;
661 }
662 
663 // MS: 09/30/02
664 template <class InheritedAttributeType, class SynthesizedAttributeType>
665 SynthesizedAttributeType
668  InheritedAttributeType inheritedValue,
669  t_traverseOrder treeTraversalOrder)
670 {
671  // DQ (1/18/2006): debugging
672  ROSE_ASSERT(this != NULL);
673  traversalConstraint = true;
674 
675  SgFile* filenode = isSgFile(node);
676  if (filenode == NULL)
677  {
678  if (node == NULL)
679  {
680  printf ("Error: traverseWithinFile(): (node should be non-null) node = %p \n",node);
681  }
682  else
683  {
684  // DQ (4/22/2014): This will fail if the input is specified as a SgProject.
685  printf ("Error: traverseWithinFile(): (node should be type SgFile) node = %p = %s \n",node,node->class_name().c_str());
686  }
687  }
688  ROSE_ASSERT(filenode != NULL); // this function will be extended to work with all nodes soon
689 
690  // GB (05/30/2007): changed to a SgFile* instead of a file name,
691  // comparisons are much cheaper this way
692  fileToVisit = filenode;
693 
694 #if 0
695  // DQ (8/17/2018): Added debugging support for new combined unparse tokens with unparse headers feature.
696  std::string filename = fileToVisit != NULL ? fileToVisit->getFileName() : "";
697  printf ("In SgTreeTraversal<>::traverseWithinFile(): fileToVisit = %p filename = %s \n",fileToVisit,filename.c_str());
698 #endif
699 
700  ROSE_ASSERT(SgTreeTraversal_inFileToTraverse(node, traversalConstraint, fileToVisit) == true);
701 
702  SynthesizedAttributeType synth = traverse(node, inheritedValue, treeTraversalOrder);
703 
704  traversalConstraint = false;
705 
706  return synth;
707 }
708 
709 
710 
711 
712 // GB (06/31/2007): Wrapper function around the performT
713 //raversal()
714 // function that does the real work; when that function is done, we call
715 // traversalResult() to get the final result off the stack of synthesized
716 // attributes.
717 /*
718 template <class InheritedAttributeType>
719 DummyAttribute
720 AstTopDownProcessing<InheritedAttributeType>::
721 defaultSynthesizedAttribute(InheritedAttributeType inh)
722 {arentset.begin(); i != parentset.end(); i++) {
723  map<SgGraphNode*, InheritedAttribute
724  // called but not used
725  DummyAttribute a = defaultDummyAttribute;
726  return a;
727 }
728 */
729 template <class InheritedAttributeType, class SynthesizedAttributeType>
731 traverse(SgNode *node, InheritedAttributeType inheritedValue,
732  t_traverseOrder treeTraversalOrder)
733 {
734  // make sure the stack is empty
735  synthesizedAttributes->resetStack();
736  ROSE_ASSERT(synthesizedAttributes->debugSize() == 0);
737 
738  // notify the concrete traversal class that a traversal is starting
739  atTraversalStart();
740 
741  // perform the actual traversal
742  performTraversal(node, inheritedValue, treeTraversalOrder);
743 
744  // notify the traversal that we are done
745  atTraversalEnd();
746 
747  // get the result off the stack
748  return traversalResult();
749 }
750 
751 
752 
753 template<class InheritedAttributeType, class SynthesizedAttributeType>
754 void
757  InheritedAttributeType inheritedValue,
758  t_traverseOrder treeTraversalOrder)
759  {
760  //cout << "In SgNode version" << endl;
761  // 1. node can be a null pointer, only traverse it if !
762 
763  // (since the SuccessorContainer is order preserving we require 0 values as well!)
764  // 2. inFileToTraverse is false if we are trying to go to a different file (than the input file)
765  // and only if traverseInputFiles was invoked, otherwise it's always true
766 
767  if (node && SgTreeTraversal_inFileToTraverse(node, traversalConstraint, fileToVisit))
768  {
769  // In case of a preorder traversal call the function to be applied to each node of the AST
770  // GB (7/6/2007): Because AstPrePostProcessing was introduced, a
771  // treeTraversalOrder can now be pre *and* post at the same time! The
772  // == comparison was therefore replaced by a bit mask check.
773  if (treeTraversalOrder & preorder)
774  inheritedValue = evaluateInheritedAttribute(node, inheritedValue);
775 
776  // Visit the traversable data members of this AST node.
777  // GB (09/25/2007): Added support for index-based traversals. The useDefaultIndexBasedTraversal flag tells us
778  // whether to use successor containers or direct index-based access to the node's successors.
779  AstSuccessorsSelectors::SuccessorsContainer succContainer;
780  size_t numberOfSuccessors;
781  if (!useDefaultIndexBasedTraversal)
782  {
783  setNodeSuccessors(node, succContainer);
784  numberOfSuccessors = succContainer.size();
785  }
786  else
787  {
788  numberOfSuccessors = node->get_numberOfTraversalSuccessors();
789  }
790 
791 #if 0
792  // DQ (8/17/2018): Add support for debugging.
793  printf ("In SgTreeTraversal<>::performTraversal(): node = %p = %s numberOfSuccessors = %zu \n",node,node->class_name().c_str(),numberOfSuccessors);
794 #endif
795 
796  for (size_t idx = 0; idx < numberOfSuccessors; idx++)
797  {
798  SgNode *child = NULL;
799 
800  if (useDefaultIndexBasedTraversal)
801  {
802  // ROSE_ASSERT(node->get_traversalSuccessorByIndex(idx) != NULL || node->get_traversalSuccessorByIndex(idx) == NULL);
803  child = node->get_traversalSuccessorByIndex(idx);
804 
805  // DQ (4/21/2014): Valgrind test to isolate uninitialised read reported where child is read below.
806  ROSE_ASSERT(child == NULL || child != NULL);
807  }
808  else
809  {
810  // ROSE_ASSERT(succContainer[idx] != NULL || succContainer[idx] == NULL);
811  child = succContainer[idx];
812 
813  // DQ (4/21/2014): Valgrind test to isolate uninitialised read reported where child is read below.
814  ROSE_ASSERT(child == NULL || child != NULL);
815  }
816 
817 #if 0
818  // DQ (8/17/2018): Add support for debugging.
819  printf ("In SgTreeTraversal<>::performTraversal(): child = %p \n",child);
820 #endif
821 
822  if (child != NULL)
823  {
824 #if 0
825  // DQ (8/17/2018): Add support for debugging.
826  printf ("In SgTreeTraversal<>::performTraversal(): child = %p = %s \n",child,child->class_name().c_str());
827 #endif
828  performTraversal(child, inheritedValue, treeTraversalOrder);
829 
830  // ENDEDIT
831  }
832  else
833  {
834  // null pointer (not traversed): we put the default value(s) of SynthesizedAttribute onto the stack
835  if (treeTraversalOrder & postorder)
836  synthesizedAttributes->push(defaultSynthesizedAttribute(inheritedValue));
837  }
838  }
839 
840  // In case of a postorder traversal call the function to be applied to each node of the AST
841  // GB (7/6/2007): Because AstPrePostProcessing was introduced, a
842  // treeTraversalOrder can now be pre *and* post at the same time! The
843  // == comparison was therefore replaced by a bit mask check.
844  // The call to evaluateInheritedAttribute at this point also had to be
845  // changed; it was never elegant anyway as we were not really
846  // evaluating attributes here.
847  if (treeTraversalOrder & postorder)
848  {
849  // Now that every child's synthesized attributes are on the stack:
850  // Tell the stack how big the stack frame containing those
851  // attributes is to be, and pass that frame to
852  // evaluateSynthesizedAttribute(); then replace those results by
853  // pushing the computed value onto the stack (which pops off the
854  // previous stack frame).
855  synthesizedAttributes->setFrameSize(numberOfSuccessors);
856  ROSE_ASSERT(synthesizedAttributes->size() == numberOfSuccessors);
857  synthesizedAttributes->push(evaluateSynthesizedAttribute(node, inheritedValue, *synthesizedAttributes));
858  }
859  }
860  else // if (node && inFileToTraverse(node))
861  {
862  if (treeTraversalOrder & postorder)
863  synthesizedAttributes->push(defaultSynthesizedAttribute(inheritedValue));
864  }
865  } // function body
866 
867 
868 // GB (05/30/2007)
869 template <class InheritedAttributeType, class SynthesizedAttributeType>
872 {
873  // If the stack of synthesizedAttributes contains exactly one object, then
874  // that one is the valid final result of the computation, so we should
875  // return it. Otherwise, either there are no objects on the stack (because
876  // the traversal didn't use any attributes), or there are more than one
877  // (usually because the traversal exited prematurely by throwing an
878  // exception); in this case, just return a default attribute.
879  if (synthesizedAttributes->debugSize() == 1)
880  {
881  return synthesizedAttributes->pop();
882  }
883  else
884  {
885  static SynthesizedAttributeType sa;
886  return sa;
887  }
888 }
889 
890 
891 // GB (05/30/2007)
892 template <class InheritedAttributeType, class SynthesizedAttributeType>
893 void
896 {
897 }
898 
899 
900 template <class InheritedAttributeType, class SynthesizedAttributeType>
901 void
904 {
905 }
906 
907 /*
908 template <class InheritedAttributeType, class SynthesizedAttributeType>
909 void
910 SgTreeTraversal<InheritedAttributeType, SynthesizedAttributeType>::
911 afterSingleTraversal()
912 {
913 }
914 
915 template <class InheritedAttributeType, class SynthesizedAttributeType>
916 void
917 SgTreeTraversal<InheritedAttributeType, SynthesizedAttributeType>::
918 
919 beforeSingleTraversal()
920 {
921 }
922 */
923 
924 template <class InheritedAttributeType, class SynthesizedAttributeType>
925 void
928 {
929 }
930 
931 template <class InheritedAttributeType, class SynthesizedAttributeType>
932 void
935 {
936 }
937 
938 template <class InheritedAttributeType>
939 void
941 destroyInheritedValue(SgNode*, InheritedAttributeType)
942 {
943 }
944 
945 template <class InheritedAttributeType>
946 void
949 {
950 }
951 
952 template <class InheritedAttributeType>
953 void
956 {
957 }
958 
959 template <class SynthesizedAttributeType>
960 void
963 {
964 }
965 
966 template <class SynthesizedAttributeType>
967 void
970 {
971 }
972 // #endif
973 
974 #include "AstSimpleProcessing.h" // that's a non-templated class which is put in a different file (for gcc to compile&link properly)
975 
976 #include "AstCombinedProcessing.h"
977 
978 // DQ (3/20/2009): Wrap this in a test to make sure that Cygwin is not being used.
979 // This causes a problem:
980 // error: there are no arguments to �cvLoadImage� that depend on a template parameter, so a declaration of <function name> must be available
981 // which requires:
982 // -fpermissive to compile without error (and then it generates a lot of warnings).
983 #if !_MSC_VER
984  #include "AstSharedMemoryParallelProcessing.h"
985 #endif
986 
987 #endif
SynthesizedAttributeType traverse(SgNode *node)
evaluates attributes on the entire AST
virtual SynthesizedAttributeType evaluateSynthesizedAttribute(SgNode *, SynthesizedAttributesList)=0
pure virtual function which must be implemented to compute the synthesized attribute at a node...
void traverse(Processor &processor, Word *words, const BitRange &range, LowToHigh)
Traverses a range of bits.
virtual SynthesizedAttributeType defaultSynthesizedAttribute()
Allows to provide a default value for a synthesized attribute of primitive type (e.g.
This class is temporary. Do not use.
Definition: AstProcessing.h:97
This class represents a source file for a project (which may contian many source files and or directo...
virtual SgNode * get_traversalSuccessorByIndex(size_t idx)
index-based access to traversal successors by index number
Attribute Evaluator for synthesized attributes.
std::string getFileName() const
associated filename
SynthesizedAttributeType traverseWithinFile(SgNode *node, InheritedAttributeType inheritedValue)
evaluates attributes only at nodes which represent the same file as where the evaluation was started ...
NodeType * deepCopy(const NodeType *subtree)
A template function for deep copying a subtree. It is also used to create deepcopy functions with spe...
virtual SynthesizedAttributeType evaluateSynthesizedAttribute(SgNode *, InheritedAttributeType, SynthesizedAttributesList)=0
pure virtual function which must be implemented to compute the synthesized attribute at a node...
Attribute Evaluator for inherited attributes.
virtual InheritedAttributeType evaluateInheritedAttribute(SgNode *astNode, InheritedAttributeType inheritedValue)=0
pure virtual function which must be implemented to compute the inherited attribute at a node ...
virtual void atTraversalStart()
Function called at the start of the traversal, before any node is visited; override if necessary...
virtual void atTraversalStart()
Function called at the start of the traversal, before any node is visited; override if necessary...
void traverseWithinFile(SgNode *node, InheritedAttributeType inheritedValue)
evaluates attributes only at nodes which represent the same file as where the evaluation was started ...
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:9311
virtual size_t get_numberOfTraversalSuccessors()
return number of children in the traversal successor list
SynthesizedAttributeType traverseWithinFile(SgNode *node)
evaluates attributes only at nodes which represent the same file as where the evaluation was started ...
virtual std::string class_name() const
returns a string representing the class name
void traverseInputFiles(SgProject *projectNode)
evaluates attributes only at nodes which represent files which were specified on the command line (=i...
virtual InheritedAttributeType evaluateInheritedAttribute(SgNode *astNode, InheritedAttributeType inheritedValue)=0
pure virtual function which must be implemented to compute the inherited attribute at a node ...
virtual void atTraversalStart()
Function called at the start of the traversal, before any node is visited; override if necessary...
static int get_verbose(void)
DQ: Modified to accept a value on the command line (no longer a boolean variable) value of 0 means qu...
This class represents a source project, with a list of SgFile objects and global information about th...
Attribute Evaluator for inherited and synthesized attributes.
SynthesizedAttributeType traverse(SgNode *node, InheritedAttributeType inheritedValue)
evaluates attributes on the entire AST
void traverse(SgNode *node, InheritedAttributeType inheritedValue)
evaluates attributes on the entire AST