4 #ifndef ROSE_ASTPROCESSING_H
5 #define ROSE_ASTPROCESSING_H
6 #define ROSE_INHERITED 0
7 #define ROSE_SYNTHESIZED 1
12 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
13 #include "staticCFG.h"
36 SgTreeTraversal_inFileToTraverse(
SgNode* node,
bool traversalConstraint,
SgFile* fileToVisit);
74 #include "AstSuccessorsSelectors.h"
75 #include "StackFrameVector.h"
79 typedef void *DummyAttribute;
82 static const DummyAttribute defaultDummyAttribute = NULL;
86 typedef DummyAttribute _DummyAttribute;
89 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
96 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
102 SynthesizedAttributeType traverse(
SgNode* basenode,
103 InheritedAttributeType inheritedValue,
104 t_traverseOrder travOrder = preandpostorder);
106 SynthesizedAttributeType traverseWithinFile(
SgNode* basenode,
107 InheritedAttributeType inheritedValue,
108 t_traverseOrder travOrder = preandpostorder);
110 void traverseInputFiles(
SgProject* projectNode,
111 InheritedAttributeType inheritedValue,
112 t_traverseOrder travOrder = preandpostorder);
125 #include "Cxx_GrammarTreeTraversalAccessEnums.h"
128 virtual InheritedAttributeType evaluateInheritedAttribute(
SgNode* astNode,
129 InheritedAttributeType inheritedValue) = 0;
132 virtual SynthesizedAttributeType evaluateSynthesizedAttribute(
SgNode* n,
133 InheritedAttributeType in,
137 typedef typename AstSuccessorsSelectors::SuccessorsContainer SuccessorsContainer;
138 typedef SuccessorsContainer& SuccessorsContainerRef;
142 virtual void setNodeSuccessors(
SgNode* node, SuccessorsContainer& succContainer);
144 virtual SynthesizedAttributeType defaultSynthesizedAttribute(InheritedAttributeType inh);
151 virtual void atTraversalStart();
154 virtual void atTraversalEnd();
161 void set_useDefaultIndexBasedTraversal(
bool);
163 void performTraversal(
SgNode *basenode,
164 InheritedAttributeType inheritedValue,
165 t_traverseOrder travOrder);
166 SynthesizedAttributeType traversalResult();
168 bool useDefaultIndexBasedTraversal;
169 bool traversalConstraint;
180 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
183 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
185 :
public SgTreeTraversal<InheritedAttributeType, SynthesizedAttributeType>
195 SynthesizedAttributeType
traverse(
SgNode* node, InheritedAttributeType inheritedValue);
211 InheritedAttributeType inheritedValue) = 0;
218 InheritedAttributeType,
227 virtual void atTraversalEnd();
230 template <
class InheritedAttributeType>
233 template <
class InheritedAttributeType>
236 template <
class InheritedAttributeType>
242 ::SynthesizedAttributesList SynthesizedAttributesList;
245 void traverse(
SgNode* node, InheritedAttributeType inheritedValue);
258 InheritedAttributeType inheritedValue) = 0;
265 virtual void atTraversalEnd();
271 virtual void destroyInheritedValue(
SgNode*, InheritedAttributeType);
274 DummyAttribute evaluateSynthesizedAttribute(
SgNode* astNode,
275 InheritedAttributeType inheritedValue,
276 SynthesizedAttributesList l);
279 DummyAttribute defaultSynthesizedAttribute(InheritedAttributeType inh);
282 template <
class SynthesizedAttributeType>
285 template <
class InheritedAttributeType>
288 template <
class SynthesizedAttributeType>
294 ::SynthesizedAttributesList SynthesizedAttributesList;
297 typedef SynthesizedAttributesList SubTreeSynthesizedAttributes;
331 virtual void atTraversalEnd();
334 virtual DummyAttribute evaluateInheritedAttribute(
SgNode* astNode, DummyAttribute inheritedValue);
357 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
361 template <
class InheritedAttributeType>
365 template <
class SynthesizedAttributeType>
375 template<
class InheritedAttributeType,
class SynthesizedAttributeType>
380 AstSuccessorsSelectors::selectDefaultSuccessors(node, succContainer);
387 template<
class InheritedAttributeType,
class SynthesizedAttributeType>
390 : useDefaultIndexBasedTraversal(true),
391 traversalConstraint(false),
393 synthesizedAttributes(new SynthesizedAttributesList())
399 template<
class InheritedAttributeType,
class SynthesizedAttributeType>
403 ROSE_ASSERT(synthesizedAttributes != NULL);
404 delete synthesizedAttributes;
405 synthesizedAttributes = NULL;
413 template<
class InheritedAttributeType,
class SynthesizedAttributeType>
416 : useDefaultIndexBasedTraversal(other.useDefaultIndexBasedTraversal),
417 traversalConstraint(other.traversalConstraint),
418 fileToVisit(other.fileToVisit),
419 synthesizedAttributes(other.synthesizedAttributes->
deepCopy())
426 template<
class InheritedAttributeType,
class SynthesizedAttributeType>
431 useDefaultIndexBasedTraversal = other.useDefaultIndexBasedTraversal;
432 traversalConstraint = other.traversalConstraint;
433 fileToVisit = other.fileToVisit;
435 ROSE_ASSERT(synthesizedAttributes != NULL);
436 delete synthesizedAttributes;
437 synthesizedAttributes = other.synthesizedAttributes->deepCopy();
443 template<
class InheritedAttributeType,
class SynthesizedAttributeType>
448 useDefaultIndexBasedTraversal = val;
453 template<
class InheritedAttributeType,
class SynthesizedAttributeType>
457 InheritedAttributeType inheritedValue,
458 t_traverseOrder travOrder)
460 const SgFilePtrList& fList = projectNode->get_fileList();
467 printf (
"Warning: The traverseInputFiles() iteration over the file list prevents the evaluation of inherited and synthesized attributes on the SgProject IR node! \n");
469 for (SgFilePtrList::const_iterator fl_iter = fList.begin(); fl_iter != fList.end(); fl_iter++)
471 ROSE_ASSERT(*fl_iter != NULL);
472 traverseWithinFile((*fl_iter), inheritedValue, travOrder);
484 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
485 SynthesizedAttributeType
491 ::traverse(node, inheritedValue, preandpostorder);
496 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
497 SynthesizedAttributeType
510 template <
class InheritedAttributeType>
514 InheritedAttributeType inheritedValue,
515 typename AstTopDownProcessing<InheritedAttributeType>::SynthesizedAttributesList l)
518 destroyInheritedValue(astNode, inheritedValue);
520 DummyAttribute a = defaultDummyAttribute;
526 template <
class InheritedAttributeType>
532 DummyAttribute a = defaultDummyAttribute;
537 template <
class InheritedAttributeType>
545 ::traverse(node, inheritedValue, preandpostorder);
550 template <
class InheritedAttributeType>
567 template <
class SynthesizedAttributeType>
573 DummyAttribute a = defaultDummyAttribute;
580 template <
class SynthesizedAttributeType>
587 SynthesizedAttributeType s = SynthesizedAttributeType();
592 template <
class SynthesizedAttributeType>
596 return defaultSynthesizedAttribute();
600 template <
class SynthesizedAttributeType>
604 SynthesizedAttributesList l)
606 return evaluateSynthesizedAttribute(astNode, l);
614 template <
class SynthesizedAttributeType>
619 static DummyAttribute da;
626 template <
class SynthesizedAttributeType>
630 static DummyAttribute da;
637 template <
class SynthesizedAttributeType>
641 static DummyAttribute da;
650 #include "../astQuery/booleanQuery.h"
651 #include "../astQuery/booleanQueryInheritedAttribute.h"
654 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
659 SynthesizedAttributeType s = SynthesizedAttributeType();
664 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
665 SynthesizedAttributeType
668 InheritedAttributeType inheritedValue,
669 t_traverseOrder treeTraversalOrder)
672 ROSE_ASSERT(
this != NULL);
673 traversalConstraint =
true;
675 SgFile* filenode = isSgFile(node);
676 if (filenode == NULL)
680 printf (
"Error: traverseWithinFile(): (node should be non-null) node = %p \n",node);
685 printf (
"Error: traverseWithinFile(): (node should be type SgFile) node = %p = %s \n",node,node->
class_name().c_str());
688 ROSE_ASSERT(filenode != NULL);
692 fileToVisit = filenode;
696 std::string filename = fileToVisit != NULL ? fileToVisit->
getFileName() :
"";
697 printf (
"In SgTreeTraversal<>::traverseWithinFile(): fileToVisit = %p filename = %s \n",fileToVisit,filename.c_str());
700 ROSE_ASSERT(SgTreeTraversal_inFileToTraverse(node, traversalConstraint, fileToVisit) ==
true);
702 SynthesizedAttributeType synth =
traverse(node, inheritedValue, treeTraversalOrder);
704 traversalConstraint =
false;
729 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
732 t_traverseOrder treeTraversalOrder)
735 synthesizedAttributes->resetStack();
736 ROSE_ASSERT(synthesizedAttributes->debugSize() == 0);
742 performTraversal(node, inheritedValue, treeTraversalOrder);
748 return traversalResult();
753 template<
class InheritedAttributeType,
class SynthesizedAttributeType>
757 InheritedAttributeType inheritedValue,
758 t_traverseOrder treeTraversalOrder)
767 if (node && SgTreeTraversal_inFileToTraverse(node, traversalConstraint, fileToVisit))
773 if (treeTraversalOrder & preorder)
774 inheritedValue = evaluateInheritedAttribute(node, inheritedValue);
779 AstSuccessorsSelectors::SuccessorsContainer succContainer;
780 size_t numberOfSuccessors;
781 if (!useDefaultIndexBasedTraversal)
783 setNodeSuccessors(node, succContainer);
784 numberOfSuccessors = succContainer.size();
793 printf (
"In SgTreeTraversal<>::performTraversal(): node = %p = %s numberOfSuccessors = %zu \n",node,node->
class_name().c_str(),numberOfSuccessors);
796 for (
size_t idx = 0; idx < numberOfSuccessors; idx++)
800 if (useDefaultIndexBasedTraversal)
806 ROSE_ASSERT(child == NULL || child != NULL);
811 child = succContainer[idx];
814 ROSE_ASSERT(child == NULL || child != NULL);
819 printf (
"In SgTreeTraversal<>::performTraversal(): child = %p \n",child);
826 printf (
"In SgTreeTraversal<>::performTraversal(): child = %p = %s \n",child,child->
class_name().c_str());
828 performTraversal(child, inheritedValue, treeTraversalOrder);
835 if (treeTraversalOrder & postorder)
836 synthesizedAttributes->push(defaultSynthesizedAttribute(inheritedValue));
847 if (treeTraversalOrder & postorder)
855 synthesizedAttributes->setFrameSize(numberOfSuccessors);
856 ROSE_ASSERT(synthesizedAttributes->size() == numberOfSuccessors);
857 synthesizedAttributes->push(evaluateSynthesizedAttribute(node, inheritedValue, *synthesizedAttributes));
862 if (treeTraversalOrder & postorder)
863 synthesizedAttributes->push(defaultSynthesizedAttribute(inheritedValue));
869 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
879 if (synthesizedAttributes->debugSize() == 1)
881 return synthesizedAttributes->pop();
885 static SynthesizedAttributeType sa;
892 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
900 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
924 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
931 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
938 template <
class InheritedAttributeType>
945 template <
class InheritedAttributeType>
952 template <
class InheritedAttributeType>
959 template <
class SynthesizedAttributeType>
966 template <
class SynthesizedAttributeType>
974 #include "AstSimpleProcessing.h"
976 #include "AstCombinedProcessing.h"