ROSE  0.9.10.135
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 
478 
479 
483 
484 
485 // MS: 04/25/02
486 template <class InheritedAttributeType, class SynthesizedAttributeType>
487 SynthesizedAttributeType
489 traverse(SgNode* node, InheritedAttributeType inheritedValue)
490 {
491  // this is now explicitly marked as a pre *and* post order traversal
493  ::traverse(node, inheritedValue, preandpostorder);
494 }
495 
496 
497 // MS: 04/25/02
498 template <class InheritedAttributeType, class SynthesizedAttributeType>
499 SynthesizedAttributeType
501 traverseWithinFile(SgNode* node, InheritedAttributeType inheritedValue)
502 {
503  // this is now explicitly marked as a pre *and* post order traversal
505 }
506 
510 
511 // MS: 04/25/02
512 template <class InheritedAttributeType>
513 DummyAttribute
516  InheritedAttributeType inheritedValue,
517  typename AstTopDownProcessing<InheritedAttributeType>::SynthesizedAttributesList l)
518 {
519  // call the cleanup function
520  destroyInheritedValue(astNode, inheritedValue);
521  // return value is not used
522  DummyAttribute a = defaultDummyAttribute;
523  return a;
524 }
525 
526 
527 // MS: 07/30/04
528 template <class InheritedAttributeType>
529 DummyAttribute
531 defaultSynthesizedAttribute(InheritedAttributeType inh)
532 {
533  // called but not used
534  DummyAttribute a = defaultDummyAttribute;
535  return a;
536 }
537 
538 // MS: 04/25/02
539 template <class InheritedAttributeType>
540 void
542 traverse(SgNode* node, InheritedAttributeType inheritedValue)
543 {
544  // "top down" is now marked as a pre *and* post order traversal because
545  // there is a post order component (the call to destroyInheritedAttribute)
547  ::traverse(node, inheritedValue, preandpostorder);
548 }
549 
550 
551 // MS: 09/30/02
552 template <class InheritedAttributeType>
553 void
555 traverseWithinFile(SgNode* node, InheritedAttributeType inheritedValue)
556 {
557  // "top down" is now marked as a pre *and* post order traversal because
558  // there is a post order component (the call to destroyInheritedAttribute)
560 }
561 
562 
566 
567 
568 // MS: 04/25/02
569 template <class SynthesizedAttributeType>
570 DummyAttribute
572 evaluateInheritedAttribute(SgNode*, DummyAttribute /*inheritedValue*/)
573 {
574  /* called but not used */
575  DummyAttribute a = defaultDummyAttribute;
576  return a;
577 }
578 
579 
580 
581 // MS: 30/07/04
582 template <class SynthesizedAttributeType>
585 {
586  // GB (8/6/2007): This can give "may not be initialized" warnings when
587  // compiling with optimization (because -O flags cause gcc to perform
588  // data-flow analysis). I wonder how this might be fixed.
589  SynthesizedAttributeType s = SynthesizedAttributeType();
590  return s;
591 }
592 
593 // MS: 30/07/04
594 template <class SynthesizedAttributeType>
596 defaultSynthesizedAttribute(DummyAttribute /*inheritedValue*/)
597 {
598  return defaultSynthesizedAttribute();
599 }
600 
601 // MS: 04/25/02//ENDEDIT
602 template <class SynthesizedAttributeType>
605  DummyAttribute /*inheritedValue*/,
606  SynthesizedAttributesList l)
607 {
608  return evaluateSynthesizedAttribute(astNode, l);
609 }
610 
611 
612 
613 
614 
615 // MS: 04/25/02
616 template <class SynthesizedAttributeType>
619 {
620 
621  static DummyAttribute da;
623  ::traverse(node, da, postorder);
624 
625 }
626 
627 // MS: 04/25/02
628 template <class SynthesizedAttributeType>
631 {
632  static DummyAttribute da;
634 }
635 
636 
637 
638 // MS: 04/25/02
639 template <class SynthesizedAttributeType>
642 {
643  static DummyAttribute da;
644  // GB (8/6/2007): This is now a postorder traversal; this did not really
645  // matter until now, but now evaluateSynthesizedAttribute is only called
646  // for traversals that have the postorder bit set.
648  ::traverseInputFiles(projectNode, da, postorder);
649 }
650 #ifdef _MSC_VER
651 //class BooleanQueryInheritedAttributeType;
652 #include "../astQuery/booleanQuery.h"
653 #include "../astQuery/booleanQueryInheritedAttribute.h"
654 #endif
655 // MS: 07/29/04
656 template <class InheritedAttributeType, class SynthesizedAttributeType>
658 defaultSynthesizedAttribute(InheritedAttributeType /*inh*/)
659 {
660  // we provide 'inh' but do not use it in the constructor of 's' to allow primitive types
661  SynthesizedAttributeType s = SynthesizedAttributeType();
662  return s;
663 }
664 
665 // MS: 09/30/02
666 template <class InheritedAttributeType, class SynthesizedAttributeType>
667 SynthesizedAttributeType
670  InheritedAttributeType inheritedValue,
671  t_traverseOrder treeTraversalOrder)
672 {
673  // DQ (1/18/2006): debugging
674  ROSE_ASSERT(this != NULL);
675  traversalConstraint = true;
676 
677  SgFile* filenode = isSgFile(node);
678  if (filenode == NULL)
679  {
680  if (node == NULL)
681  {
682  printf ("Error: traverseWithinFile(): (node should be non-null) node = %p \n",node);
683  }
684  else
685  {
686  // DQ (4/22/2014): This will fail if the input is specified as a SgProject.
687  printf ("Error: traverseWithinFile(): (node should be type SgFile) node = %p = %s \n",node,node->class_name().c_str());
688  }
689  }
690  ROSE_ASSERT(filenode != NULL); // this function will be extended to work with all nodes soon
691 
692  // GB (05/30/2007): changed to a SgFile* instead of a file name,
693  // comparisons are much cheaper this way
694  fileToVisit = filenode;
695 
696 #if 0
697  // DQ (8/17/2018): Added debugging support for new combined unparse tokens with unparse headers feature.
698  std::string filename = fileToVisit != NULL ? fileToVisit->getFileName() : "";
699  printf ("In SgTreeTraversal<>::traverseWithinFile(): fileToVisit = %p filename = %s \n",fileToVisit,filename.c_str());
700 #endif
701 
702  ROSE_ASSERT(SgTreeTraversal_inFileToTraverse(node, traversalConstraint, fileToVisit) == true);
703 
704  SynthesizedAttributeType synth = traverse(node, inheritedValue, treeTraversalOrder);
705 
706  traversalConstraint = false;
707 
708  return synth;
709 }
710 
711 
712 
713 
714 // GB (06/31/2007): Wrapper function around the performT
715 //raversal()
716 // function that does the real work; when that function is done, we call
717 // traversalResult() to get the final result off the stack of synthesized
718 // attributes.
719 /*
720 template <class InheritedAttributeType>
721 DummyAttribute
722 AstTopDownProcessing<InheritedAttributeType>::
723 defaultSynthesizedAttribute(InheritedAttributeType inh)
724 {arentset.begin(); i != parentset.end(); i++) {
725  map<SgGraphNode*, InheritedAttribute
726  // called but not used
727  DummyAttribute a = defaultDummyAttribute;
728  return a;
729 }
730 */
731 template <class InheritedAttributeType, class SynthesizedAttributeType>
733 traverse(SgNode *node, InheritedAttributeType inheritedValue,
734  t_traverseOrder treeTraversalOrder)
735 {
736  // make sure the stack is empty
737  synthesizedAttributes->resetStack();
738  ROSE_ASSERT(synthesizedAttributes->debugSize() == 0);
739 
740  // notify the concrete traversal class that a traversal is starting
741  atTraversalStart();
742 
743  // perform the actual traversal
744  performTraversal(node, inheritedValue, treeTraversalOrder);
745 
746  // notify the traversal that we are done
747  atTraversalEnd();
748 
749  // get the result off the stack
750  return traversalResult();
751 }
752 
753 
754 
755 template<class InheritedAttributeType, class SynthesizedAttributeType>
756 void
759  InheritedAttributeType inheritedValue,
760  t_traverseOrder treeTraversalOrder)
761  {
762  //cout << "In SgNode version" << endl;
763  // 1. node can be a null pointer, only traverse it if !
764 
765  // (since the SuccessorContainer is order preserving we require 0 values as well!)
766  // 2. inFileToTraverse is false if we are trying to go to a different file (than the input file)
767  // and only if traverseInputFiles was invoked, otherwise it's always true
768 
769  if (node && SgTreeTraversal_inFileToTraverse(node, traversalConstraint, fileToVisit))
770  {
771  // In case of a preorder traversal call the function to be applied to each node of the AST
772  // GB (7/6/2007): Because AstPrePostProcessing was introduced, a
773  // treeTraversalOrder can now be pre *and* post at the same time! The
774  // == comparison was therefore replaced by a bit mask check.
775  if (treeTraversalOrder & preorder)
776  inheritedValue = evaluateInheritedAttribute(node, inheritedValue);
777 
778  // Visit the traversable data members of this AST node.
779  // GB (09/25/2007): Added support for index-based traversals. The useDefaultIndexBasedTraversal flag tells us
780  // whether to use successor containers or direct index-based access to the node's successors.
781  AstSuccessorsSelectors::SuccessorsContainer succContainer;
782  size_t numberOfSuccessors;
783  if (!useDefaultIndexBasedTraversal)
784  {
785  setNodeSuccessors(node, succContainer);
786  numberOfSuccessors = succContainer.size();
787  }
788  else
789  {
790  numberOfSuccessors = node->get_numberOfTraversalSuccessors();
791  }
792 
793 #if 0
794  // DQ (8/17/2018): Add support for debugging.
795  printf ("In SgTreeTraversal<>::performTraversal(): node = %p = %s numberOfSuccessors = %zu \n",node,node->class_name().c_str(),numberOfSuccessors);
796 #endif
797 
798  for (size_t idx = 0; idx < numberOfSuccessors; idx++)
799  {
800  SgNode *child = NULL;
801 
802  if (useDefaultIndexBasedTraversal)
803  {
804  // ROSE_ASSERT(node->get_traversalSuccessorByIndex(idx) != NULL || node->get_traversalSuccessorByIndex(idx) == NULL);
805  child = node->get_traversalSuccessorByIndex(idx);
806 
807  // DQ (4/21/2014): Valgrind test to isolate uninitialised read reported where child is read below.
808  ROSE_ASSERT(child == NULL || child != NULL);
809  }
810  else
811  {
812  // ROSE_ASSERT(succContainer[idx] != NULL || succContainer[idx] == NULL);
813  child = succContainer[idx];
814 
815  // DQ (4/21/2014): Valgrind test to isolate uninitialised read reported where child is read below.
816  ROSE_ASSERT(child == NULL || child != NULL);
817  }
818 
819 #if 0
820  // DQ (8/17/2018): Add support for debugging.
821  printf ("In SgTreeTraversal<>::performTraversal(): child = %p \n",child);
822 #endif
823 
824  if (child != NULL)
825  {
826 #if 0
827  // DQ (8/17/2018): Add support for debugging.
828  printf ("In SgTreeTraversal<>::performTraversal(): child = %p = %s \n",child,child->class_name().c_str());
829 #endif
830  performTraversal(child, inheritedValue, treeTraversalOrder);
831 
832  // ENDEDIT
833  }
834  else
835  {
836  // null pointer (not traversed): we put the default value(s) of SynthesizedAttribute onto the stack
837  if (treeTraversalOrder & postorder)
838  synthesizedAttributes->push(defaultSynthesizedAttribute(inheritedValue));
839  }
840  }
841 
842  // In case of a postorder traversal call the function to be applied to each node of the AST
843  // GB (7/6/2007): Because AstPrePostProcessing was introduced, a
844  // treeTraversalOrder can now be pre *and* post at the same time! The
845  // == comparison was therefore replaced by a bit mask check.
846  // The call to evaluateInheritedAttribute at this point also had to be
847  // changed; it was never elegant anyway as we were not really
848  // evaluating attributes here.
849  if (treeTraversalOrder & postorder)
850  {
851  // Now that every child's synthesized attributes are on the stack:
852  // Tell the stack how big the stack frame containing those
853  // attributes is to be, and pass that frame to
854  // evaluateSynthesizedAttribute(); then replace those results by
855  // pushing the computed value onto the stack (which pops off the
856  // previous stack frame).
857  synthesizedAttributes->setFrameSize(numberOfSuccessors);
858  ROSE_ASSERT(synthesizedAttributes->size() == numberOfSuccessors);
859  synthesizedAttributes->push(evaluateSynthesizedAttribute(node, inheritedValue, *synthesizedAttributes));
860  }
861  }
862  else // if (node && inFileToTraverse(node))
863  {
864  if (treeTraversalOrder & postorder)
865  synthesizedAttributes->push(defaultSynthesizedAttribute(inheritedValue));
866  }
867  } // function body
868 
869 
870 // GB (05/30/2007)
871 template <class InheritedAttributeType, class SynthesizedAttributeType>
874 {
875  // If the stack of synthesizedAttributes contains exactly one object, then
876  // that one is the valid final result of the computation, so we should
877  // return it. Otherwise, either there are no objects on the stack (because
878  // the traversal didn't use any attributes), or there are more than one
879  // (usually because the traversal exited prematurely by throwing an
880  // exception); in this case, just return a default attribute.
881  if (synthesizedAttributes->debugSize() == 1)
882  {
883  return synthesizedAttributes->pop();
884  }
885  else
886  {
887  static SynthesizedAttributeType sa;
888  return sa;
889  }
890 }
891 
892 
893 // GB (05/30/2007)
894 template <class InheritedAttributeType, class SynthesizedAttributeType>
895 void
898 {
899 }
900 
901 
902 template <class InheritedAttributeType, class SynthesizedAttributeType>
903 void
906 {
907 }
908 
909 /*
910 template <class InheritedAttributeType, class SynthesizedAttributeType>
911 void
912 SgTreeTraversal<InheritedAttributeType, SynthesizedAttributeType>::
913 afterSingleTraversal()
914 {
915 }
916 
917 template <class InheritedAttributeType, class SynthesizedAttributeType>
918 void
919 SgTreeTraversal<InheritedAttributeType, SynthesizedAttributeType>::
920 
921 beforeSingleTraversal()
922 {
923 }
924 */
925 
926 template <class InheritedAttributeType, class SynthesizedAttributeType>
927 void
930 {
931 }
932 
933 template <class InheritedAttributeType, class SynthesizedAttributeType>
934 void
937 {
938 }
939 
940 template <class InheritedAttributeType>
941 void
943 destroyInheritedValue(SgNode*, InheritedAttributeType)
944 {
945 }
946 
947 template <class InheritedAttributeType>
948 void
951 {
952 }
953 
954 template <class InheritedAttributeType>
955 void
958 {
959 }
960 
961 template <class SynthesizedAttributeType>
962 void
965 {
966 }
967 
968 template <class SynthesizedAttributeType>
969 void
972 {
973 }
974 // #endif
975 
976 #include "AstSimpleProcessing.h" // that's a non-templated class which is put in a different file (for gcc to compile&link properly)
977 
978 #include "AstCombinedProcessing.h"
979 
980 // DQ (3/20/2009): Wrap this in a test to make sure that Cygwin is not being used.
981 // This causes a problem:
982 // error: there are no arguments to �cvLoadImage� that depend on a template parameter, so a declaration of <function name> must be available
983 // which requires:
984 // -fpermissive to compile without error (and then it generates a lot of warnings).
985 #if !_MSC_VER
986  #include "AstSharedMemoryParallelProcessing.h"
987 #endif
988 
989 #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:8778
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