ROSE 0.11.145.192
AstProcessing.h
1// Original Author (AstProcessing classes): Markus Schordan
2// Rewritten by: Gergo Barany
3
4#ifndef ROSE_ASTPROCESSING_H
5#define ROSE_ASTPROCESSING_H
6#define ROSE_INHERITED 0
7#define ROSE_SYNTHESIZED 1
8#define ROSE_BOTH 2
9
10typedef enum {preorder = 1, postorder = 2, preandpostorder = preorder | postorder} t_traverseOrder;
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
35ROSE_DLL_API bool
36SgTreeTraversal_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.
79typedef 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...
82static const DummyAttribute defaultDummyAttribute = nullptr;
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.
86typedef DummyAttribute _DummyAttribute;
87
88
89template <class InheritedAttributeType, class SynthesizedAttributeType>
91
92
93
94
95// Base class for all traversals.
96template <class InheritedAttributeType, class SynthesizedAttributeType>
98{
99public:
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();
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
127protected:
128 virtual InheritedAttributeType evaluateInheritedAttribute(SgNode* astNode,
129 InheritedAttributeType inheritedValue) = 0;
130
131
132 virtual SynthesizedAttributeType evaluateSynthesizedAttribute(SgNode* n,
133 InheritedAttributeType in,
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);
162private:
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
180template <class InheritedAttributeType, class SynthesizedAttributeType>
182
183template <class InheritedAttributeType, class SynthesizedAttributeType>
185 : public SgTreeTraversal<InheritedAttributeType, SynthesizedAttributeType>
186{
187public:
189 ::SynthesizedAttributesList SynthesizedAttributesList;
190
191 // deprecated
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
208protected:
210 virtual InheritedAttributeType evaluateInheritedAttribute(SgNode* astNode,
211 InheritedAttributeType inheritedValue) = 0;
212
217 virtual SynthesizedAttributeType evaluateSynthesizedAttribute(SgNode*,
218 InheritedAttributeType,
220
221
222
226 virtual void atTraversalStart();
227 virtual void atTraversalEnd();
228};
229
230template <class InheritedAttributeType>
232
233template <class InheritedAttributeType>
235
236template <class InheritedAttributeType>
238 : public SgTreeTraversal<InheritedAttributeType, DummyAttribute>
239{
240public:
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
255protected:
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
273private:
274 DummyAttribute evaluateSynthesizedAttribute(SgNode* astNode,
275 InheritedAttributeType inheritedValue,
276 SynthesizedAttributesList l);
277
278
279 DummyAttribute defaultSynthesizedAttribute(InheritedAttributeType inh);
280};
281
282template <class SynthesizedAttributeType>
284
285template <class InheritedAttributeType>
287
288template <class SynthesizedAttributeType>
290 : public SgTreeTraversal<DummyAttribute,SynthesizedAttributeType>
291{
292public:
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
315protected:
320 virtual SynthesizedAttributeType evaluateSynthesizedAttribute(SgNode*, SynthesizedAttributesList) = 0;
321
322
326 virtual SynthesizedAttributeType defaultSynthesizedAttribute();
330 virtual void atTraversalStart();
331 virtual void atTraversalEnd();
332
333private:
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
357template <class InheritedAttributeType, class SynthesizedAttributeType>
358class SgTopDownBottomUpProcessing : public AstTopDownBottomUpProcessing <InheritedAttributeType, SynthesizedAttributeType> {};
359
361template <class InheritedAttributeType>
362class SgTopDownProcessing : public AstTopDownProcessing <InheritedAttributeType> {};
363
365template <class SynthesizedAttributeType>
366class 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
375template<class InheritedAttributeType, class SynthesizedAttributeType>
376void
378setNodeSuccessors(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
387template<class InheritedAttributeType, class SynthesizedAttributeType>
390 : useDefaultIndexBasedTraversal(true),
391 traversalConstraint(false),
392 fileToVisit(nullptr),
393 synthesizedAttributes(new SynthesizedAttributesList())
394{
395}
396
397#ifndef SWIG
398// The destructor of the internal tree traversal class
399template<class InheritedAttributeType, class SynthesizedAttributeType>
402{
403 ASSERT_not_null(synthesizedAttributes);
404 delete synthesizedAttributes;
405 synthesizedAttributes = nullptr;
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).
413template<class InheritedAttributeType, class SynthesizedAttributeType>
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).
426template<class InheritedAttributeType, class SynthesizedAttributeType>
429operator=(const SgTreeTraversal &other)
430{
431 useDefaultIndexBasedTraversal = other.useDefaultIndexBasedTraversal;
432 traversalConstraint = other.traversalConstraint;
433 fileToVisit = other.fileToVisit;
434
435 ASSERT_not_null(synthesizedAttributes);
436 delete synthesizedAttributes;
437 synthesizedAttributes = other.synthesizedAttributes->deepCopy();
438
439 return *this;
440}
441
442
443template<class InheritedAttributeType, class SynthesizedAttributeType>
444void
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),
453template<class InheritedAttributeType, class SynthesizedAttributeType>
454void
456traverseInputFiles(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 ASSERT_not_null(*fl_iter);
472 traverseWithinFile((*fl_iter), inheritedValue, travOrder);
473 }
474 }
475
476
477
481
482
483// MS: 04/25/02
484template <class InheritedAttributeType, class SynthesizedAttributeType>
485SynthesizedAttributeType
487traverse(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
496template <class InheritedAttributeType, class SynthesizedAttributeType>
497SynthesizedAttributeType
499traverseWithinFile(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
510template <class InheritedAttributeType>
511DummyAttribute
514 InheritedAttributeType inheritedValue,
515 typename AstTopDownProcessing<InheritedAttributeType>::SynthesizedAttributesList)
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
526template <class InheritedAttributeType>
527DummyAttribute
529defaultSynthesizedAttribute(InheritedAttributeType)
530{
531 // called but not used
532 DummyAttribute a = defaultDummyAttribute;
533 return a;
534}
535
536// MS: 04/25/02
537template <class InheritedAttributeType>
538void
540traverse(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
550template <class InheritedAttributeType>
551void
553traverseWithinFile(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
567template <class SynthesizedAttributeType>
568DummyAttribute
570evaluateInheritedAttribute(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
580template <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
592template <class SynthesizedAttributeType>
594defaultSynthesizedAttribute(DummyAttribute /*inheritedValue*/)
595{
596 return defaultSynthesizedAttribute();
597}
598
599// MS: 04/25/02//ENDEDIT
600template <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
614template <class SynthesizedAttributeType>
616traverse(SgNode* node)
617{
618
619 static DummyAttribute da;
621 ::traverse(node, da, postorder);
622
623}
624
625// MS: 04/25/02
626template <class SynthesizedAttributeType>
629{
630 static DummyAttribute da;
632}
633
634
635
636// MS: 04/25/02
637template <class SynthesizedAttributeType>
639traverseInputFiles(SgProject* projectNode)
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
654template <class InheritedAttributeType, class SynthesizedAttributeType>
656defaultSynthesizedAttribute(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
664template <class InheritedAttributeType, class SynthesizedAttributeType>
665SynthesizedAttributeType
668 InheritedAttributeType inheritedValue,
669 t_traverseOrder treeTraversalOrder)
670{
671 ASSERT_this();
672 traversalConstraint = true;
673
674 SgFile* filenode = isSgFile(node);
675 if (filenode == nullptr)
676 {
677 if (node == nullptr)
678 {
679 printf ("Error: traverseWithinFile(): (node should be non-null) node = %p \n",node);
680 }
681 else
682 {
683 // DQ (4/22/2014): This will fail if the input is specified as a SgProject.
684 printf ("Error: traverseWithinFile(): (node should be type SgFile) node = %p = %s \n",node,node->class_name().c_str());
685 }
686 }
687 ASSERT_not_null(filenode); // this function will be extended to work with all nodes soon
688
689 // GB (05/30/2007): changed to a SgFile* instead of a file name,
690 // comparisons are much cheaper this way
691 fileToVisit = filenode;
692
693#if 0
694 // DQ (8/17/2018): Added debugging support for new combined unparse tokens with unparse headers feature.
695 std::string filename = fileToVisit != nullptr ? fileToVisit->getFileName() : "";
696 printf ("In SgTreeTraversal<>::traverseWithinFile(): fileToVisit = %p filename = %s \n",fileToVisit,filename.c_str());
697#endif
698
699 ROSE_ASSERT(SgTreeTraversal_inFileToTraverse(node, traversalConstraint, fileToVisit) == true);
700
701 SynthesizedAttributeType synth = traverse(node, inheritedValue, treeTraversalOrder);
702
703 traversalConstraint = false;
704
705 return synth;
706}
707
708
709
710
711// GB (06/31/2007): Wrapper function around the performT
712//raversal()
713// function that does the real work; when that function is done, we call
714// traversalResult() to get the final result off the stack of synthesized
715// attributes.
716/*
717template <class InheritedAttributeType>
718DummyAttribute
719AstTopDownProcessing<InheritedAttributeType>::
720defaultSynthesizedAttribute(InheritedAttributeType inh)
721{arentset.begin(); i != parentset.end(); i++) {
722 map<SgGraphNode*, InheritedAttribute
723 // called but not used
724 DummyAttribute a = defaultDummyAttribute;
725 return a;
726}
727*/
728template <class InheritedAttributeType, class SynthesizedAttributeType>
730traverse(SgNode *node, InheritedAttributeType inheritedValue,
731 t_traverseOrder treeTraversalOrder)
732{
733 // make sure the stack is empty
734 synthesizedAttributes->resetStack();
735 ROSE_ASSERT(synthesizedAttributes->debugSize() == 0);
736
737 // notify the concrete traversal class that a traversal is starting
738 atTraversalStart();
739
740 // perform the actual traversal
741 performTraversal(node, inheritedValue, treeTraversalOrder);
742
743 // notify the traversal that we are done
744 atTraversalEnd();
745
746 // get the result off the stack
747 return traversalResult();
748}
749
750
751
752template<class InheritedAttributeType, class SynthesizedAttributeType>
753void
756 InheritedAttributeType inheritedValue,
757 t_traverseOrder treeTraversalOrder)
758 {
759 //cout << "In SgNode version" << endl;
760 // 1. node can be a null pointer, only traverse it if !
761
762 // (since the SuccessorContainer is order preserving we require 0 values as well!)
763 // 2. inFileToTraverse is false if we are trying to go to a different file (than the input file)
764 // and only if traverseInputFiles was invoked, otherwise it's always true
765
766 if (node && SgTreeTraversal_inFileToTraverse(node, traversalConstraint, fileToVisit))
767 {
768 // In case of a preorder traversal call the function to be applied to each node of the AST
769 // GB (7/6/2007): Because AstPrePostProcessing was introduced, a
770 // treeTraversalOrder can now be pre *and* post at the same time! The
771 // == comparison was therefore replaced by a bit mask check.
772 if (treeTraversalOrder & preorder)
773 inheritedValue = evaluateInheritedAttribute(node, inheritedValue);
774
775 // Visit the traversable data members of this AST node.
776 // GB (09/25/2007): Added support for index-based traversals. The useDefaultIndexBasedTraversal flag tells us
777 // whether to use successor containers or direct index-based access to the node's successors.
778 AstSuccessorsSelectors::SuccessorsContainer succContainer;
779 size_t numberOfSuccessors;
780 if (!useDefaultIndexBasedTraversal)
781 {
782 setNodeSuccessors(node, succContainer);
783 numberOfSuccessors = succContainer.size();
784 }
785 else
786 {
787 numberOfSuccessors = node->get_numberOfTraversalSuccessors();
788 }
789
790#if 0
791 // DQ (8/17/2018): Add support for debugging.
792 printf ("In SgTreeTraversal<>::performTraversal(): node = %p = %s numberOfSuccessors = %zu \n",node,node->class_name().c_str(),numberOfSuccessors);
793#endif
794
795 for (size_t idx = 0; idx < numberOfSuccessors; idx++)
796 {
797 SgNode* child = nullptr;
798
799 if (useDefaultIndexBasedTraversal)
800 {
801 child = node->get_traversalSuccessorByIndex(idx);
802
803 // DQ (4/21/2014): Valgrind test to isolate uninitialised read reported where child is read below.
804 ASSERT_require(child == nullptr || child != nullptr);
805 }
806 else
807 {
808 child = succContainer[idx];
809
810 // DQ (4/21/2014): Valgrind test to isolate uninitialised read reported where child is read below.
811 ASSERT_require(child == nullptr || child != nullptr);
812 }
813
814#if 0
815 // DQ (8/17/2018): Add support for debugging.
816 printf ("In SgTreeTraversal<>::performTraversal(): child = %p \n",child);
817#endif
818
819 if (child != nullptr)
820 {
821#if 0
822 // DQ (8/17/2018): Add support for debugging.
823 printf ("In SgTreeTraversal<>::performTraversal(): child = %p = %s \n",child,child->class_name().c_str());
824#endif
825 performTraversal(child, inheritedValue, treeTraversalOrder);
826
827 // ENDEDIT
828 }
829 else
830 {
831 // null pointer (not traversed): we put the default value(s) of SynthesizedAttribute onto the stack
832 if (treeTraversalOrder & postorder)
833 synthesizedAttributes->push(defaultSynthesizedAttribute(inheritedValue));
834 }
835 }
836
837 // In case of a postorder traversal call the function to be applied to each node of the AST
838 // GB (7/6/2007): Because AstPrePostProcessing was introduced, a
839 // treeTraversalOrder can now be pre *and* post at the same time! The
840 // == comparison was therefore replaced by a bit mask check.
841 // The call to evaluateInheritedAttribute at this point also had to be
842 // changed; it was never elegant anyway as we were not really
843 // evaluating attributes here.
844 if (treeTraversalOrder & postorder)
845 {
846 // Now that every child's synthesized attributes are on the stack:
847 // Tell the stack how big the stack frame containing those
848 // attributes is to be, and pass that frame to
849 // evaluateSynthesizedAttribute(); then replace those results by
850 // pushing the computed value onto the stack (which pops off the
851 // previous stack frame).
852 synthesizedAttributes->setFrameSize(numberOfSuccessors);
853 ROSE_ASSERT(synthesizedAttributes->size() == numberOfSuccessors);
854 synthesizedAttributes->push(evaluateSynthesizedAttribute(node, inheritedValue, *synthesizedAttributes));
855 }
856 }
857 else // if (node && inFileToTraverse(node))
858 {
859 if (treeTraversalOrder & postorder)
860 synthesizedAttributes->push(defaultSynthesizedAttribute(inheritedValue));
861 }
862 } // function body
863
864
865// GB (05/30/2007)
866template <class InheritedAttributeType, class SynthesizedAttributeType>
869{
870 // If the stack of synthesizedAttributes contains exactly one object, then
871 // that one is the valid final result of the computation, so we should
872 // return it. Otherwise, either there are no objects on the stack (because
873 // the traversal didn't use any attributes), or there are more than one
874 // (usually because the traversal exited prematurely by throwing an
875 // exception); in this case, just return a default attribute.
876 if (synthesizedAttributes->debugSize() == 1)
877 {
878 return synthesizedAttributes->pop();
879 }
880 else
881 {
882 static SynthesizedAttributeType sa;
883 return sa;
884 }
885}
886
887
888// GB (05/30/2007)
889template <class InheritedAttributeType, class SynthesizedAttributeType>
890void
893{
894}
895
896
897template <class InheritedAttributeType, class SynthesizedAttributeType>
898void
901{
902}
903
904/*
905template <class InheritedAttributeType, class SynthesizedAttributeType>
906void
907SgTreeTraversal<InheritedAttributeType, SynthesizedAttributeType>::
908afterSingleTraversal()
909{
910}
911
912template <class InheritedAttributeType, class SynthesizedAttributeType>
913void
914SgTreeTraversal<InheritedAttributeType, SynthesizedAttributeType>::
915
916beforeSingleTraversal()
917{
918}
919*/
920
921template <class InheritedAttributeType, class SynthesizedAttributeType>
922void
927
928template <class InheritedAttributeType, class SynthesizedAttributeType>
929void
932{
933}
934
935template <class InheritedAttributeType>
936void
938destroyInheritedValue(SgNode*, InheritedAttributeType)
939{
940}
941
942template <class InheritedAttributeType>
943void
948
949template <class InheritedAttributeType>
950void
953{
954}
955
956template <class SynthesizedAttributeType>
957void
962
963template <class SynthesizedAttributeType>
964void
967{
968}
969// #endif
970
971#include "AstSimpleProcessing.h" // that's a non-templated class which is put in a different file (for gcc to compile&link properly)
972
973#include "AstCombinedProcessing.h"
974
975// DQ (3/20/2009): Wrap this in a test to make sure that Cygwin is not being used.
976// This causes a problem:
977// error: there are no arguments to �cvLoadImage� that depend on a template parameter, so a declaration of <function name> must be available
978// which requires:
979// -fpermissive to compile without error (and then it generates a lot of warnings).
980#if !_MSC_VER
981 #include "AstSharedMemoryParallelProcessing.h"
982#endif
983
984#endif
Attribute Evaluator for synthesized attributes.
void traverseInputFiles(SgProject *projectNode)
evaluates attributes only at nodes which represent files which were specified on the command line (=i...
virtual void atTraversalStart()
Function called at the start of the traversal, before any node is visited; override if necessary,...
SynthesizedAttributeType traverse(SgNode *node)
evaluates attributes on the entire AST
virtual SynthesizedAttributeType defaultSynthesizedAttribute()
Allows to provide a default value for a synthesized attribute of primitive type (e....
virtual SynthesizedAttributeType evaluateSynthesizedAttribute(SgNode *, SynthesizedAttributesList)=0
pure virtual function which must be implemented to compute the synthesized attribute at a node.
SynthesizedAttributeType traverseWithinFile(SgNode *node)
evaluates attributes only at nodes which represent the same file as where the evaluation was started
Attribute Evaluator for inherited and synthesized attributes.
SynthesizedAttributeType traverseWithinFile(SgNode *node, InheritedAttributeType inheritedValue)
evaluates attributes only at nodes which represent the same file as where the evaluation was started
virtual void atTraversalStart()
Function called at the start of the traversal, before any node is visited; override if necessary,...
virtual InheritedAttributeType evaluateInheritedAttribute(SgNode *astNode, InheritedAttributeType inheritedValue)=0
pure virtual function which must be implemented to compute the inherited attribute at a node
SynthesizedAttributeType traverse(SgNode *node, InheritedAttributeType inheritedValue)
evaluates attributes on the entire AST
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 void atTraversalStart()
Function called at the start of the traversal, before any node is visited; override if necessary,...
void traverse(SgNode *node, InheritedAttributeType inheritedValue)
evaluates attributes on the entire AST
virtual InheritedAttributeType evaluateInheritedAttribute(SgNode *astNode, InheritedAttributeType inheritedValue)=0
pure virtual function which must be implemented to compute the inherited attribute at a node
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 a source file for a project (which may contian many source files and or directo...
std::string getFileName() const
associated filename
This class represents the base class for all IR nodes within Sage III.
virtual size_t get_numberOfTraversalSuccessors()
return number of children in the traversal successor list
virtual std::string class_name() const
returns a string representing the class name
virtual SgNode * get_traversalSuccessorByIndex(size_t idx)
index-based access to traversal successors by index number
This class represents a source project, with a list of SgFile objects and global information about th...
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 is temporary. Do not use.
NodeType * deepCopy(const NodeType *subtree)
A template function for deep copying a subtree. It is also used to create deepcopy functions with spe...