ROSE  0.9.9.109
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* astNode, 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  ROSE_ASSERT(SgTreeTraversal_inFileToTraverse(node, traversalConstraint, fileToVisit) == true);
697 
698  SynthesizedAttributeType synth = traverse(node, inheritedValue, treeTraversalOrder);
699  traversalConstraint = false;
700  return synth;
701 }
702 
703 
704 
705 
706 // GB (06/31/2007): Wrapper function around the performT
707 //raversal()
708 // function that does the real work; when that function is done, we call
709 // traversalResult() to get the final result off the stack of synthesized
710 // attributes.
711 /*
712 template <class InheritedAttributeType>
713 DummyAttribute
714 AstTopDownProcessing<InheritedAttributeType>::
715 defaultSynthesizedAttribute(InheritedAttributeType inh)
716 {arentset.begin(); i != parentset.end(); i++) {
717  map<SgGraphNode*, InheritedAttribute
718  // called but not used
719  DummyAttribute a = defaultDummyAttribute;
720  return a;
721 }
722 */
723 template <class InheritedAttributeType, class SynthesizedAttributeType>
725 traverse(SgNode *node, InheritedAttributeType inheritedValue,
726  t_traverseOrder treeTraversalOrder)
727 {
728  // make sure the stack is empty
729  synthesizedAttributes->resetStack();
730  ROSE_ASSERT(synthesizedAttributes->debugSize() == 0);
731 
732  // notify the concrete traversal class that a traversal is starting
733  atTraversalStart();
734 
735  // perform the actual traversal
736  performTraversal(node, inheritedValue, treeTraversalOrder);
737 
738  // notify the traversal that we are done
739  atTraversalEnd();
740 
741  // get the result off the stack
742  return traversalResult();
743 }
744 
745 
746 
747 template<class InheritedAttributeType, class SynthesizedAttributeType>
748 void
751  InheritedAttributeType inheritedValue,
752  t_traverseOrder treeTraversalOrder)
753  {
754  //cout << "In SgNode version" << endl;
755  // 1. node can be a null pointer, only traverse it if !
756 
757  // (since the SuccessorContainer is order preserving we require 0 values as well!)
758  // 2. inFileToTraverse is false if we are trying to go to a different file (than the input file)
759  // and only if traverseInputFiles was invoked, otherwise it's always true
760 
761  if (node && SgTreeTraversal_inFileToTraverse(node, traversalConstraint, fileToVisit))
762  {
763  // In case of a preorder traversal call the function to be applied to each node of the AST
764  // GB (7/6/2007): Because AstPrePostProcessing was introduced, a
765  // treeTraversalOrder can now be pre *and* post at the same time! The
766  // == comparison was therefore replaced by a bit mask check.
767  if (treeTraversalOrder & preorder)
768  inheritedValue = evaluateInheritedAttribute(node, inheritedValue);
769 
770  // Visit the traversable data members of this AST node.
771  // GB (09/25/2007): Added support for index-based traversals. The useDefaultIndexBasedTraversal flag tells us
772  // whether to use successor containers or direct index-based access to the node's successors.
773  AstSuccessorsSelectors::SuccessorsContainer succContainer;
774  size_t numberOfSuccessors;
775  if (!useDefaultIndexBasedTraversal)
776  {
777  setNodeSuccessors(node, succContainer);
778  numberOfSuccessors = succContainer.size();
779  }
780  else
781  {
782  numberOfSuccessors = node->get_numberOfTraversalSuccessors();
783  }
784 
785  for (size_t idx = 0; idx < numberOfSuccessors; idx++)
786  {
787  SgNode *child = NULL;
788 
789  if (useDefaultIndexBasedTraversal)
790  {
791  // ROSE_ASSERT(node->get_traversalSuccessorByIndex(idx) != NULL || node->get_traversalSuccessorByIndex(idx) == NULL);
792  child = node->get_traversalSuccessorByIndex(idx);
793 
794  // DQ (4/21/2014): Valgrind test to isolate uninitialised read reported where child is read below.
795  ROSE_ASSERT(child == NULL || child != NULL);
796  }
797  else
798  {
799  // ROSE_ASSERT(succContainer[idx] != NULL || succContainer[idx] == NULL);
800  child = succContainer[idx];
801 
802  // DQ (4/21/2014): Valgrind test to isolate uninitialised read reported where child is read below.
803  ROSE_ASSERT(child == NULL || child != NULL);
804  }
805 
806  if (child != NULL)
807  {
808 
809 
810 
811  performTraversal(child, inheritedValue, treeTraversalOrder);
812 
813 
814 
815  //ENDEDIT
816  }
817  else
818  {
819  // null pointer (not traversed): we put the default value(s) of SynthesizedAttribute onto the stack
820  if (treeTraversalOrder & postorder)
821  synthesizedAttributes->push(defaultSynthesizedAttribute(inheritedValue));
822  }
823  }
824 
825  // In case of a postorder traversal call the function to be applied to each node of the AST
826  // GB (7/6/2007): Because AstPrePostProcessing was introduced, a
827  // treeTraversalOrder can now be pre *and* post at the same time! The
828  // == comparison was therefore replaced by a bit mask check.
829  // The call to evaluateInheritedAttribute at this point also had to be
830  // changed; it was never elegant anyway as we were not really
831  // evaluating attributes here.
832  if (treeTraversalOrder & postorder)
833  {
834  // Now that every child's synthesized attributes are on the stack:
835  // Tell the stack how big the stack frame containing those
836  // attributes is to be, and pass that frame to
837  // evaluateSynthesizedAttribute(); then replace those results by
838  // pushing the computed value onto the stack (which pops off the
839  // previous stack frame).
840  synthesizedAttributes->setFrameSize(numberOfSuccessors);
841  ROSE_ASSERT(synthesizedAttributes->size() == numberOfSuccessors);
842  synthesizedAttributes->push(evaluateSynthesizedAttribute(node, inheritedValue, *synthesizedAttributes));
843  }
844  }
845  else // if (node && inFileToTraverse(node))
846  {
847  if (treeTraversalOrder & postorder)
848  synthesizedAttributes->push(defaultSynthesizedAttribute(inheritedValue));
849  }
850  } // function body
851 
852 
853 // GB (05/30/2007)
854 template <class InheritedAttributeType, class SynthesizedAttributeType>
857 {
858  // If the stack of synthesizedAttributes contains exactly one object, then
859  // that one is the valid final result of the computation, so we should
860  // return it. Otherwise, either there are no objects on the stack (because
861  // the traversal didn't use any attributes), or there are more than one
862  // (usually because the traversal exited prematurely by throwing an
863  // exception); in this case, just return a default attribute.
864  if (synthesizedAttributes->debugSize() == 1)
865  {
866  return synthesizedAttributes->pop();
867  }
868  else
869  {
870  static SynthesizedAttributeType sa;
871  return sa;
872  }
873 }
874 
875 
876 // GB (05/30/2007)
877 template <class InheritedAttributeType, class SynthesizedAttributeType>
878 void
881 {
882 }
883 
884 
885 template <class InheritedAttributeType, class SynthesizedAttributeType>
886 void
889 {
890 }
891 
892 /*
893 template <class InheritedAttributeType, class SynthesizedAttributeType>
894 void
895 SgTreeTraversal<InheritedAttributeType, SynthesizedAttributeType>::
896 afterSingleTraversal()
897 {
898 }
899 
900 template <class InheritedAttributeType, class SynthesizedAttributeType>
901 void
902 SgTreeTraversal<InheritedAttributeType, SynthesizedAttributeType>::
903 
904 beforeSingleTraversal()
905 {
906 }
907 */
908 
909 template <class InheritedAttributeType, class SynthesizedAttributeType>
910 void
913 {
914 }
915 
916 template <class InheritedAttributeType, class SynthesizedAttributeType>
917 void
920 {
921 }
922 
923 template <class InheritedAttributeType>
924 void
926 destroyInheritedValue(SgNode*, InheritedAttributeType)
927 {
928 }
929 
930 template <class InheritedAttributeType>
931 void
934 {
935 }
936 
937 template <class InheritedAttributeType>
938 void
941 {
942 }
943 
944 template <class SynthesizedAttributeType>
945 void
948 {
949 }
950 
951 template <class SynthesizedAttributeType>
952 void
955 {
956 }
957 // #endif
958 
959 #include "AstSimpleProcessing.h" // that's a non-templated class which is put in a different file (for gcc to compile&link properly)
960 
961 #include "AstCombinedProcessing.h"
962 
963 // DQ (3/20/2009): Wrap this in a test to make sure that Cygwin is not being used.
964 // This causes a problem:
965 // error: there are no arguments to �cvLoadImage� that depend on a template parameter, so a declaration of <function name> must be available
966 // which requires:
967 // -fpermissive to compile without error (and then it generates a lot of warnings).
968 #if !_MSC_VER
969  #include "AstSharedMemoryParallelProcessing.h"
970 #endif
971 
972 #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.
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:8322
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