ROSE 0.11.145.210
sageInterface.C
1
2#include "sage3basic.h"
3#include "markLhsValues.h"
4#include "fixupNames.h"
5#include "FileUtility.h"
6#include <Sawyer/Message.h>
7
8#include "AstJSONGeneration.h"
9
10#include "SgNodeHelper.h" //Markus's helper functions
11
12#include "Rose/AST/Utility.h"
13
14#include "sageInterface.h"
15#include "Combinatorics.h"
16
17
18#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
19#include "replaceExpressionWithStatement.h"
20
21#include "constantFolding.h"
22#endif
23
24// DQ (10/14/2006): Added supporting help functions. tps commented out since it caused no compilation errors
25//#include "rewrite.h"
26
27// Liao 1/24/2008 : need access to scope stack sometimes
28#include "sageBuilder.h"
29
30// DQ (3/14/2017): Try to comment this out since it is not tested (used in get_C_array_dimensions(),
31// from midend/programTransformation/ompLowering/omp_lowering.cpp, but not tested).
32#include "sageGeneric.h"
33
34#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
35// For reusing some code from Qing's loop optimizer
36// Liao, 2/26/2009
37#include "AstInterface_ROSE.h"
38#include "LoopTransformInterface.h"
39
40#include "DepInfoAnal.h" // for AnalyzeStmtRefs()
41#include "ArrayAnnot.h"
42#include "ArrayInterface.h"
43
44#include "LoopUnroll.h"
45#include "abstract_handle.h"
46#include "roseAdapter.h"
47#endif
48
49#include <boost/lexical_cast.hpp>
50#include <boost/foreach.hpp>
51#include <sstream>
52#include <iostream>
53#include <algorithm> // for set operations
54#include <numeric> // for std::accumulate
55#include <map>
56#include <unordered_map>
57
58#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
59# include "jni.h"
60
61namespace Rose {
62 namespace Frontend {
63 namespace Java {
64 namespace Ecj {
65
66 extern jclass currentJavaTraversalClass;
67 extern JNIEnv *currentEnvironment;
68 extern jmethodID mainMethod;
69 extern jmethodID hasConflictsMethod;
70 extern jmethodID getTempDirectoryMethod;
71 extern jmethodID createTempFileMethod;
72 extern jmethodID createTempNamedFileMethod;
73 extern jmethodID createTempNamedDirectoryMethod;
74
75 } // ::Rose::Frontend::Java::Ecj
76 }// ::Rose::frontend::java
77 }// ::Rose::frontend
78}// ::Rose
79
80using namespace Rose::Frontend::Java::Ecj;
81
82#endif
83
84
85// DQ (11/5/2019): Added to support SageInterface::statementCanBeTransformed().
86namespace EDG_ROSE_Translation
87 {
88 // DQ (9/18/2018): Declare this map so that we can use it for the unparse header files option.
89#if defined(ROSE_BUILD_CXX_LANGUAGE_SUPPORT) && !defined(ROSE_USE_CLANG_FRONTEND)
90 // DQ (12/11/2018): Use the definition in the EDG edgRose.C file if C/C++ support IS defined.
91 extern std::map<std::string, SgIncludeFile*> edg_include_file_map;
92#else
93 // DQ (12/11/2018): Allow this to be the definition if C/C++ support is NOT defined.
94 std::map<std::string, SgIncludeFile*> edg_include_file_map;
95#endif
96 }
97
98
99
100// DQ (12/1/2015): Added to support macro handling.
101#include "detectMacroOrIncludeFileExpansions.h"
102
103namespace SageInterface {
104 template<class T> void setSourcePositionToDefault( T* node );
105}
106
107
108#ifdef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
109 #include "transformationSupport.h"
110#endif
111
112// We need this so that USE_CMAKE will be seen (set via configure).
113#include "rose_config.h"
114
115// DQ (3/4/2014): We need this feature to support the function: isStructurallyEquivalentAST().
116#include "RoseAst.h"
117
118// DQ (2/13/2022): We need this feature to support the function: deleteAllNodes().
119#include "AST_FILE_IO.h"
120
121
122// DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
123// The value of 0 allows the old implementation to be tested, and the value of 1 allows the new optimized implementation to be tested.
124#define OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS 1
125
128
129// DQ (3/21/2016): Added support for generateUniqueNameForUseAsIdentifier().
131std::map<std::string,SgNode*> SageInterface::local_name_to_node_map;
132std::map<SgNode*,std::string> SageInterface::local_node_to_name_map;
133
134typedef std::set<SgLabelStatement*> SgLabelStatementPtrSet;
135
136namespace SageInterface
137{
138 Transformation_Record trans_records;
139}
140
141// DQ (12/31/2005): This is OK if not declared in a header file
142using namespace std;
143using namespace Rose;
144using namespace SageBuilder;
145//using namespace Rose::Diagnostics; // for mlog, INFO, WARN, ERROR, FATAL, etc.
146
147// Used by serialize() to collect all types visited
148//std::set<SgType*> type_set;
149// DQ (1/18/2015): Define this container locally in this file only.
150namespace SageInterface
151 {
152 // DQ (1/18/2015): Save the SgBasicBlock that has been added so that we can undo this transformation later.
153 vector<SgBasicBlock*> addedBasicBlockNodes;
154 }
155
156
157#if 1
158// DQ (2/13/2022): Adding support to delete the whole AST (every SgNode).
159void
161 {
162 // This function uses a memory pool traversal specific to the SgFile IR nodes
163
164 // We need to use this function to get all of the SgNodes.
165 // template <typename NodeType> std::vector<NodeType*> getSgNodeListFromMemoryPool()
166
167 class MyTraversal : public ROSE_VisitTraversal
168 {
169 public:
170 std::vector<SgNode*> resultlist;
171 void visit ( SgNode* node)
172 {
173 SgNode* result = dynamic_cast<SgNode*>(node);
174 ROSE_ASSERT(result != NULL);
175#if 0
176 printf ("In SageInterface::deleteAllNodes(): result = %p = %s \n",result,result->class_name().c_str());
177#endif
178#if 0
179 if (result != NULL)
180 {
181 resultlist.push_back(result);
182 }
183#else
184 resultlist.push_back(result);
185#endif
186 };
187
188 virtual ~MyTraversal() {}
189 };
190
191 // For debugging, recode the number of IR nodes before we delete the AST.
192 size_t numberOfNodes_before = numberOfNodes();
193
194 MyTraversal my_traversal;
195
196 // We need to visit all of the IR nodes, not just those of a specific class in ROSE.
197 // NodeType::traverseMemoryPoolNodes(my_traversal);
198 my_traversal.traverseMemoryPool();
199
200 // return my_traversal.resultlist;
201
202
203 // vector<SgNode*> nodeList = getSgNodeListFromMemoryPool<SgNode>();
204 vector<SgNode*> & nodeList = my_traversal.resultlist;
205
206 printf ("In SageInterface::deleteAllNodes(): get list of SgNode: nodeList.size() = %zu \n",nodeList.size());
207
208 vector<SgNode*>::iterator i = nodeList.begin();
209
210 // This loop will call the delete operator on all of the IR nodes in the AST.
211 while (i != nodeList.end())
212 {
213 SgNode* node = *i;
214#if 0
215 // It is an error to be calling get_name() while so many nodes are being deleted.
216 // printf (" --- calling delete (and thus the destructor) node = %p = %s name = %s \n",node,node->class_name().c_str(),SageInterface::get_name(node).c_str());
217 printf (" --- calling delete (and thus the destructor) node = %p = %s \n",node,node->class_name().c_str());
218#endif
219 delete node;
220 node = NULL;
221
222 i++;
223 }
224
225#if 0
226 // This demonstrates that this function only visits the specific IR node that is used as a template parameter.
227 vector<SgFunctionDeclaration*> functionDeclarationList = getSgNodeListFromMemoryPool<SgFunctionDeclaration>();
228 printf ("In SageInterface::deleteAllNodes(): get list of SgFunctionDeclaration: functionDeclarationList.size() = %zu \n",functionDeclarationList.size());
229#endif
230
231 // Now we need to delete the memory pools (implemented by ROSETTA).
232 AST_FILE_IO::clearAllMemoryPools();
233
234 size_t numberOfNodes_after = numberOfNodes();
235
236#if 1
237 printf ("Leaving SageInterface::deleteAllNodes(): numberOfNodes_before = %zu numberOfNodes_after = %zu \n",numberOfNodes_before,numberOfNodes_after);
238#endif
239 }
240#endif
241
242
243#if 0
244// DQ (3/5/2022): Adding support to check AST for invalide poionters.
245void
247 {
248 // This function uses a memory pool traversal to look for any pointers to invalid IR nodes.
249
250 // Step 1: is to build a map of the boundaries of the memory pools for each IR node kind.
251 // Step 2: traverse all of the IR nodes across all of the memory pools and check
252 // a) if the pointer to each node in the list of child IR nodes is in the map from step 1.
253 // b) if it is then we can expect to dereference the pointer and check the value of
254 // get_freepointer(), the value should be 0xffffffffffffffff, else it is an error
255 // (when it is an error it usually should be a value that is in the map from step 1, but it
256 // is a node that was previously deleted, so it is a stale pointer).
257
258 class BuildMapTraversal : public ROSE_VisitTraversal
259 {
260 public:
261 // std::vector<SgNode*> resultlist;
262 // std::map<enum VariantT,std::vector<std::pair<SgNode*,SgNode*>> mapOfMemoryPoolsBounds;
263
264 // We need to get the pools variable for each IR node.
265
266 void visit ( SgNode* node)
267 {
268 // Get list of all pointers to all IR nodes in the current node.
269
270 // $CLASSNAME::pools
272
273 resultlist.push_back(result);
274 };
275
276 virtual ~MyTraversal() {}
277 };
278
279 // For debugging, recode the number of IR nodes before we delete the AST.
280 size_t numberOfNodes_before = numberOfNodes();
281
282 MyTraversal my_traversal;
283
284 // We need to visit all of the IR nodes, not just those of a specific class in ROSE.
285 // NodeType::traverseMemoryPoolNodes(my_traversal);
286 my_traversal.traverseMemoryPool();
287 }
288#endif
289
290void
291SageInterface::DeclarationSets::addDeclaration(SgDeclarationStatement* decl)
292 {
293 // DQ (4/3/2014): This function either builds a new set or inserts declarations into an
294 // existing set based on if a set defined by the key (firstNondefiningDeclaration) is present.
295 ASSERT_not_null(decl);
296
297#if 0
298 printf ("TOP of SageInterface::DeclarationSets::addDeclaration(): decl = %p = %s = %s \n",decl,decl->class_name().c_str(),get_name(decl).c_str());
299#endif
300
301 SgDeclarationStatement* firstNondefiningDeclaration = decl->get_firstNondefiningDeclaration();
302
303 if (firstNondefiningDeclaration == nullptr)
304 {
305 // It appears that some loop transformations (pass3.C) don't set the firstNondefiningDeclaration.
306#if 0
307 printf ("WARNING: SageInterface::DeclarationSets::addDeclaration(): firstNondefiningDeclaration == NULL: decl = %p = %s = %s \n",decl,decl->class_name().c_str(),get_name(decl).c_str());
308#endif
309 return;
310 }
311 ASSERT_not_null(firstNondefiningDeclaration);
312
313 if (decl == firstNondefiningDeclaration)
314 {
315#if 0
316 if (isSgTypedefDeclaration(decl) != nullptr)
317 {
318 printf ("TOP of SageInterface::DeclarationSets::addDeclaration(): decl = %p = %s = %s \n",decl,decl->class_name().c_str(),get_name(decl).c_str());
319 }
320#endif
321 if (declarationMap.find(firstNondefiningDeclaration) == declarationMap.end())
322 {
323#if 0
324 printf ("In SageInterface::DeclarationSets::addDeclaration(): Add a set for decl = %p = %s = %s \n",decl,decl->class_name().c_str(),get_name(decl).c_str());
325#endif
326#if 0
327 if (isSgTypedefDeclaration(decl) != nullptr)
328 {
329 printf ("In SageInterface::DeclarationSets::addDeclaration(): Add a set for decl = %p = %s = %s \n",decl,decl->class_name().c_str(),get_name(decl).c_str());
330 }
331#endif
332 // Add a new set.
333 declarationMap[decl] = new set<SgDeclarationStatement*>();
334
335 ROSE_ASSERT (declarationMap.find(firstNondefiningDeclaration) != declarationMap.end());
336 ROSE_ASSERT(declarationMap[decl] != nullptr);
337
338 // Add a declaration to an existing set.
339 declarationMap[firstNondefiningDeclaration]->insert(decl);
340 }
341 else
342 {
343 if (declarationMap[firstNondefiningDeclaration]->find(decl) == declarationMap[firstNondefiningDeclaration]->end())
344 {
345#if 0
346 printf ("In SageInterface::DeclarationSets::addDeclaration(): Add the declaration to the existing set: decl = %p = %s = %s \n",decl,decl->class_name().c_str(),get_name(decl).c_str());
347#endif
348#if 0
349 if (isSgTypedefDeclaration(decl) != nullptr)
350 {
351 printf ("In SageInterface::DeclarationSets::addDeclaration(): Add the declaration to the existing set: decl = %p = %s = %s \n",decl,decl->class_name().c_str(),get_name(decl).c_str());
352 }
353#endif
354 // Add a declaration to an existing set.
355 declarationMap[firstNondefiningDeclaration]->insert(decl);
356 }
357 else
358 {
359#if 0
360 printf ("WARNING: SageInterface::DeclarationSets::addDeclaration(): A set already exists for decl = %p = %s = %s \n",decl,decl->class_name().c_str(),get_name(decl).c_str());
361#endif
362 // DQ (4/5/2014): The case of SgFunctionParameterList fails only for boost examples (e.g. test2014_240.C).
363 // Problem uses are associated with SgTemplateInstantiationFunctionDecl IR nodes.
364 bool ignore_error = (isSgFunctionParameterList(decl) != nullptr);
365
366 // DQ (4/17/2014): This is required for the EDG version 4.8 and I don't know why.
367 // Currently the priority is to pass our existing tests.
368 // An idea is that this is sharing introduced as a result of the use of default parameters.
369
370 // DQ (7/2/2014): I am seeing that this is required for a new application using GNU 4.4.7.
371 // It allows a boost issue specific to a revisited SgTypedefDeclaration pass, but I still
372 // don't understand the problem. so this needs a better fix.
373
375 bool isInTemplateFunctionDeclaration = enclosingFunction != nullptr && (isSgTemplateMemberFunctionDeclaration(enclosingFunction) || isSgTemplateFunctionDeclaration(enclosingFunction));
376
377 // Use short-circuit evaluation to improve performance.
378 SgClassDefinition* enclosingClassDefinition = isInTemplateFunctionDeclaration == true ? nullptr : getEnclosingClassDefinition(decl);
379 bool isInTemplateClassDefinition = enclosingClassDefinition != nullptr && isSgTemplateClassDefinition(enclosingClassDefinition);
380
381 bool isInTemplateDeclaration = isInTemplateFunctionDeclaration || isInTemplateClassDefinition;
382
383 ignore_error = ignore_error || (isSgTypedefDeclaration(decl) != nullptr) || (isSgTemplateInstantiationDecl(decl) != nullptr) || (isInTemplateDeclaration == true);
384
385 // DQ (2/5/2015): We need to ignore the case of un-named classes (or maybe those classes
386 // from unnamed classes with lambda member functions). See test2015_13.C for an example.
387 // Or maybe these should have been added to the declarationMap in the front-end?
388 if (isSgClassDeclaration(decl) != nullptr)
389 {
390 ignore_error = ignore_error || (isSgClassDeclaration(decl)->get_isUnNamed() == true);
391 }
392 }
393 }
394 }
395 else
396 {
397 // Add the declaration (make sure there is a set that exists).
398 if (declarationMap.find(firstNondefiningDeclaration) != declarationMap.end())
399 {
400 // Make sure it does not already exist in the set.
401 ROSE_ASSERT (declarationMap[firstNondefiningDeclaration] != nullptr);
402 if (declarationMap[firstNondefiningDeclaration]->find(decl) == declarationMap[firstNondefiningDeclaration]->end())
403 {
404 // Add a declaration to an existing set.
405 declarationMap[firstNondefiningDeclaration]->insert(decl);
406 }
407 else
408 {
409#if 0
410 printf ("This declaration is already in the set (skip adding it twice): decl = %p = %s = %s \n",decl,decl->class_name().c_str(),get_name(decl).c_str());
411#endif
412 }
413 }
414 else
415 {
416 // In this case the defining declaration might be the only declaration to be traversed and
417 // so a set has not been built yet.
418#if 0
419 printf ("In SageInterface::DeclarationSets::addDeclaration(): Adding set and declaration for the firstNondefiningDeclaration = %p = %s = %s \n",
420 firstNondefiningDeclaration,firstNondefiningDeclaration->class_name().c_str(),get_name(firstNondefiningDeclaration).c_str());
421#endif
422
423 // DQ (4/5/2014): Just build the set and don't insert the firstNondefiningDeclaration.
424 // If we were to do so then it would be an error to use the insert it later.
425 // Note recursive call.
426 // addDeclaration(firstNondefiningDeclaration);
427 declarationMap[firstNondefiningDeclaration] = new set<SgDeclarationStatement*>();
428
429 ROSE_ASSERT (declarationMap.find(firstNondefiningDeclaration) != declarationMap.end());
430
431 // DQ (4/5/2014): We have to insert this since it is different from the firstNondefiningDeclaration.
432 // Add the declaration to the existing set.
433 declarationMap[firstNondefiningDeclaration]->insert(decl);
434
435 // DQ (4/5/2014): Added assertion.
436 ROSE_ASSERT(declarationMap[firstNondefiningDeclaration]->find(decl) != declarationMap[firstNondefiningDeclaration]->end());
437#if 0
438 printf ("SageInterface::DeclarationSets::addDeclaration(): No set exists for the firstNondefiningDeclaration = %p = %s = %s \n",firstNondefiningDeclaration,firstNondefiningDeclaration->class_name().c_str(),get_name(firstNondefiningDeclaration).c_str());
439 ROSE_ABORT();
440#endif
441 }
442 }
443
444#if 0
445 printf ("Leaving SageInterface::DeclarationSets::addDeclaration(): decl = %p = %s = %s \n",decl,decl->class_name().c_str(),get_name(decl).c_str());
446#endif
447 }
448
449const std::set<SgDeclarationStatement*>*
450SageInterface::DeclarationSets::getDeclarations(SgDeclarationStatement* decl)
451 {
452 // DQ (4/3/2014): This function returns the associated set of declarations.
453 SgDeclarationStatement* firstNondefiningDeclaration = decl->get_firstNondefiningDeclaration();
454
455 ROSE_ASSERT(declarationMap.find(firstNondefiningDeclaration) != declarationMap.end());
456
457 const set<SgDeclarationStatement*>* declarationSet = declarationMap[firstNondefiningDeclaration];
458
459 // return this->declarationMap[firstNondefiningDeclaration];
460 return declarationSet;
461 }
462
463std::map<SgDeclarationStatement*,std::set<SgDeclarationStatement*>* > &
464SageInterface::DeclarationSets::getDeclarationMap()
465 {
466 return declarationMap;
467 }
468
469bool
470SageInterface::DeclarationSets::isLocatedInDefiningScope(SgDeclarationStatement* decl)
471 {
472 // DQ (4/7/2014): This function assumes that the input is a friend declaration.
473
474 // The existence of a declaration in a named scope (if a friend function) will cause
475 // subsequent declarations to be qualified where name qualification is required.
476 // A couple of issues:
477 // We likely need to keep track of the order of the declarations in the more
478 // complex cases because name qualification will be required after the declaration
479 // that appears in the named scope; but will not be required before the declaration in
480 // the named scope.
481
482#define DEBUG_LOCATED_IN_DEFINING_SCOPE 0
483
484 SgDeclarationStatement* firstNondefiningDeclaration = decl->get_firstNondefiningDeclaration();
485 ROSE_ASSERT(firstNondefiningDeclaration != nullptr);
486
487 set<SgDeclarationStatement*>* declarationSet = declarationMap[firstNondefiningDeclaration];
488 ROSE_ASSERT(declarationSet != nullptr);
489
490 set<SgDeclarationStatement*>::iterator i = declarationSet->begin();
491
492 bool isDefinedInNamedScope = false;
493
494#if DEBUG_LOCATED_IN_DEFINING_SCOPE
495 printf ("In DeclarationSets::isLocatedInDefiningScope(): decl = %p = %s \n",decl,decl->class_name().c_str());
496 printf (" --- declarationSet->size() = %" PRIuPTR " \n",declarationSet->size());
497#endif
498
499 while (isDefinedInNamedScope == false && i != declarationSet->end())
500 {
501 ROSE_ASSERT(*i != nullptr);
502#if DEBUG_LOCATED_IN_DEFINING_SCOPE
503 printf (" --- *i = %p = %s \n",*i,(*i)->class_name().c_str());
504#endif
505 // We want to know the structural position, not the semantic scope.
506 SgScopeStatement* semantic_scope = (*i)->get_scope();
507 SgScopeStatement* structural_scope = isSgScopeStatement((*i)->get_parent());
508
509#if DEBUG_LOCATED_IN_DEFINING_SCOPE
510 printf (" --- semantic_scope = %p = %s \n",semantic_scope,semantic_scope->class_name().c_str());
511 printf (" --- structural_scope = %p = %s \n",structural_scope,structural_scope->class_name().c_str());
512#endif
513 // DQ (4/7/2014): If it is a member of a class then we don't consider the structural scope, else it makes a difference,
514 SgScopeStatement* scope = isSgClassDefinition(semantic_scope) != nullptr ? semantic_scope : structural_scope;
515 ASSERT_not_null(scope);
516
517#if DEBUG_LOCATED_IN_DEFINING_SCOPE
518 printf (" --- scope = %p = %s \n",scope,scope->class_name().c_str());
519 printf (" --- scope->isNamedScope() = %s \n",scope->isNamedScope() ? "true" : "false");
520#endif
521 SgGlobal* globalScope = isSgGlobal(scope);
522
523 // Friend functions declared in the class definition are not meaningful for determining name qualification.
524 if (globalScope != nullptr || (scope->isNamedScope() == true && isSgClassDefinition(structural_scope) == nullptr) )
525 {
526 // Check if the function is output in the unparing, else it would not be defined.
527 bool willBeOutput = ((*i)->get_file_info()->isCompilerGenerated() == false ||
528 ((*i)->get_file_info()->isCompilerGenerated() &&
529 (*i)->get_file_info()->isOutputInCodeGeneration()) );
530#if DEBUG_LOCATED_IN_DEFINING_SCOPE
531 printf (" --- before: willBeOutput = %s \n",willBeOutput ? "true" : "false");
532#endif
533 // Being output only count when it is output where it is located structurally.
534 willBeOutput = willBeOutput && scope == structural_scope;
535
536#if DEBUG_LOCATED_IN_DEFINING_SCOPE
537 printf (" --- after: willBeOutput = %s \n",willBeOutput ? "true" : "false");
538#endif
539 // DQ (3/20/2016): this is reported by GNU as set but not used.
540 // associatedDeclaration = *i;
541
542 // isDefinedInNamedScope = true;
543 isDefinedInNamedScope = willBeOutput;
544 }
545
546 i++;
547 }
548
549#if DEBUG_LOCATED_IN_DEFINING_SCOPE
550 if (associatedDeclaration != nullptr)
551 {
552 printf ("Leaving DeclarationSets::isLocatedInDefiningScope(): associatedDeclaration = %p = %s \n",associatedDeclaration,associatedDeclaration->class_name().c_str());
553 }
554 else
555 {
556 printf ("Leaving DeclarationSets::isLocatedInDefiningScope(): associatedDeclaration = %p \n",associatedDeclaration);
557 }
558#endif
559
560 return isDefinedInNamedScope;
561 }
562
564SageInterface::buildDeclarationSets(SgNode* n)
565 {
566 DeclarationSets* declarationSet = new DeclarationSets();
567
568 class DeclarationSetTraversal : public AstSimpleProcessing
569 {
570 private:
571 DeclarationSets* declarationSet;
572
573 public:
574 DeclarationSetTraversal(DeclarationSets* ds) : declarationSet(ds) {}
575 void visit (SgNode* node)
576 {
577 SgDeclarationStatement* decl = isSgDeclarationStatement(node);
578 if (decl != nullptr)
579 {
580 declarationSet->addDeclaration(decl);
581 }
582 }
583 };
584
585 // Now buid the traveral object and call the traversal (preorder) on the AST subtree.
586 DeclarationSetTraversal traversal(declarationSet);
587 traversal.traverse(n, preorder);
588
589 return declarationSet;
590 }
591
593// DQ: 09/23/03
594// We require a global function for getting the string associated
595// with the definition of a variant (which is a global enum).
596string getVariantName ( VariantT v )
597 {
598 ROSE_ASSERT( int(v) < int(V_SgNumVariants));
599
600 // This code is far simpler (if the function is static)
601
602 // DQ (4/8/2004): Modified code to use new global list of sage
603 // class names (simpler this way)
604 // return string(SgTreeTraversal<int,int>::get_variantName(v));
605 extern const char* roseGlobalVariantNameList[];
606 return string(roseGlobalVariantNameList[v]);
607 }
608
609bool
611 {
612 // DQ (6/7/2012): This refactors the test for template instantiation syntax in names used for classes, member functions, and functions
613 bool usingTemplateSyntax = false;
614 string nameString = name.getString();
615
616 // DQ (6/7/2012): We need to avoid the identification of the "operator<()" as valid template syntax.
617 usingTemplateSyntax = (nameString.find('<') != string::npos) && (nameString.find('>') != string::npos);
618
619 // DQ (5/10/2016): Debugging case of C++11 using the Intel v16 compiler and it's associated mutex header file.
620 // See Cxx11_tests/test2016_32.C for an example that demonstrates this problem.
621 if (nameString == "<unnamed>")
622 {
623 printf ("In SageInterface::hasTemplateSyntax(): Identified case of name == <unnamed> \n");
624
625 usingTemplateSyntax = false;
626 }
627
628 // return (name.getString().find('<') == string::npos);
629 return usingTemplateSyntax;
630 }
631
632
633
634void
636 {
637 // DQ (2/12/2012): Refactoring disagnostic support for detecting where we are when something fails.
638
639 // This highest level node acceptable for us by this function is a SgGlobal (global scope).
640
641 ROSE_ASSERT(node != NULL);
642// printf ("Inside of SageInterface::whereAmI(node = %p = %s) \n",node,node->class_name().c_str());
643
644 // Enforce that some IR nodes should not be acepted inputs.
645 ROSE_ASSERT(isSgFile(node) == NULL);
646 ROSE_ASSERT(isSgFileList(node) == NULL);
647 ROSE_ASSERT(isSgProject(node) == NULL);
648
649 SgNode* parent = node->get_parent();
650
651 // Don't traverse past the SgFile level.
652 while (parent != nullptr && isSgFileList(parent) == nullptr)
653 {
654 // DQ (7/14/2019): These were commented out, but they are intended for debugging, so
655 // if someone does not need this output then the function should not have been called.
656 printf ("--- parent = %p = %s \n",parent,parent->class_name().c_str());
657
658 ROSE_ASSERT(parent->get_file_info() != NULL);
659 parent->get_file_info()->display("In SageInterface::whereAmI() diagnostics support");
660
661 parent = parent->get_parent();
662 }
663 }
664
665void
666SageInterface::initializeIfStmt(SgIfStmt *ifstmt, SgStatement* conditional, SgStatement * true_body, SgStatement * false_body)
667 {
668 // DQ (2/13/2012): Added new function to support proper initialization of a SgIfStmt that has already been built.
669 // This is important when we have to build the scope ahead of the test becasue the text contains a simple
670 // declaration (which must be put into the SgIfStmt scope).
671
672 // SgIfStmt *ifstmt = new SgIfStmt(conditional, true_body, false_body);
673 ROSE_ASSERT(ifstmt);
674
675 if (ifstmt->get_conditional() == nullptr)
676 ifstmt->set_conditional(conditional);
677
678 if (ifstmt->get_true_body() == nullptr)
679 ifstmt->set_true_body(true_body);
680
681 if (ifstmt->get_false_body() == nullptr)
682 ifstmt->set_false_body(false_body);
683
684 // Rasmussen (3/22/2020): Fixed setting case insensitivity
686 ifstmt->setCaseInsensitive(true);
687
689 if (conditional) conditional->set_parent(ifstmt);
690 if (true_body) true_body->set_parent(ifstmt);
691 if (false_body) false_body->set_parent(ifstmt);
692 }
693
694
695void
697 {
698 ROSE_ASSERT(switchStatement != NULL);
699
700 // Rasmussen (3/22/2020): Fixed setting case insensitivity
702 switchStatement->setCaseInsensitive(true);
703
704 if (switchStatement->get_item_selector() == nullptr)
705 switchStatement->set_item_selector(item_selector);
706
707 if (switchStatement->get_body() == nullptr)
708 switchStatement->set_body(body);
709
711 if (item_selector != nullptr)
712 item_selector->set_parent(switchStatement);
713 if (body != nullptr)
714 body->set_parent(switchStatement);
715 }
716
717
718void
720 {
721 ROSE_ASSERT(whileStatement);
722
723 // Rasmussen (3/22/2020): Fixed setting case insensitivity
725 whileStatement->setCaseInsensitive(true);
726
727 if (whileStatement->get_condition() == nullptr)
728 whileStatement->set_condition(condition);
729 if (whileStatement->get_body() == nullptr)
730 whileStatement->set_body(body);
731
732 // Python support.
733 if (whileStatement->get_else_body() == nullptr)
734 whileStatement->set_else_body(else_body);
735
736 setOneSourcePositionNull(whileStatement);
737 if (condition) condition->set_parent(whileStatement);
738 if (body) body->set_parent(whileStatement);
739
740 // DQ (8/10/2011): This is added by Michael to support a Python specific feature.
741 if (else_body != nullptr)
742 {
743 whileStatement->set_else_body(else_body);
744 else_body->set_parent(whileStatement);
745 }
746 }
747
748
749
752 {
753 // DQ (11/4/2007): This function is used in the markTemplateInstantiationsForOutput.C
754
755 // This function returns the namespace associated with any declaration.
756 // If the declaration is nested inside of other scopes this function
757 // iterates through these scopes to get the the first namespace.
758 // This is important for details of template handling, namely making sure
759 // that the template specializations (generated by ROSE) are put into the
760 // correct location (namespace) since stricted rules in gnu now enforce
761 // these details. If the declaration is not in a namespace as computed
762 // in the chain of scopes then this function returns nullptr.
763
764 ROSE_ASSERT(declaration != NULL);
765 SgScopeStatement* tempScope = declaration->get_scope();
766
767 // Loop back to the first namespace or stop at global scope (stop on either a namespace or the global scope)
768 while ( isSgNamespaceDefinitionStatement(tempScope) == nullptr && isSgGlobal(tempScope) == nullptr )
769 {
770 tempScope = tempScope->get_scope();
771 ROSE_ASSERT(tempScope != NULL);
772#if 0
773 printf ("Iterating back through scopes: tempScope = %p = %s = %s \n",tempScope,tempScope->class_name().c_str(),SageInterface::get_name(tempScope).c_str());
774#endif
775 }
776
777 SgNamespaceDefinitionStatement* namespaceScope = isSgNamespaceDefinitionStatement(tempScope);
778 return namespaceScope;
779 }
780
781
784 {
785 // DQ (11/4/2007): This function is used in the markTemplateInstantiationsForOutput.C
786 // DQ (11/4/2007): Get the associated declaration that will be in the original source code,
787 // if it is part of a template instantiation then get the original template declaration.
788
789 SgDeclarationStatement* parentDeclaration = nullptr;
790
791 SgScopeStatement* defn = memberFunctionInstantiation->get_class_scope();
792 ASSERT_not_null(defn);
793
794 // SgTemplateDeclaration* templateDeclaration = memberFunctionInstantiation->get_templateDeclaration();
795 SgDeclarationStatement* templateDeclaration = memberFunctionInstantiation->get_templateDeclaration();
796 ASSERT_not_null(templateDeclaration);
797
798 // If it is a template instatiation, then we have to find the temple declaration (not the template instantiation declaration), else we want the class declaration.
799 SgClassDefinition* cdefn = isSgClassDefinition(defn);
800 SgDeclarationScope* nrscope = isSgDeclarationScope(defn);
801 SgTemplateInstantiationDefn* templateInstatiationClassDefinition = isSgTemplateInstantiationDefn(defn);
802 if (templateInstatiationClassDefinition != nullptr)
803 {
804 // This is the case of a template member function in a templated class (see test2005_172.C).
805 SgTemplateInstantiationDefn* parentTemplateInstantiationDefinition = isSgTemplateInstantiationDefn(templateDeclaration->get_scope());
806 ASSERT_not_null(parentTemplateInstantiationDefinition);
807 SgTemplateInstantiationDecl* parentTemplateInstantiationDeclaration = isSgTemplateInstantiationDecl(parentTemplateInstantiationDefinition->get_declaration());
808 ASSERT_not_null(parentTemplateInstantiationDeclaration);
809
810 parentDeclaration = parentTemplateInstantiationDeclaration->get_templateDeclaration();
811 ASSERT_not_null(parentDeclaration);
812 }
813 else if (cdefn != nullptr)
814 {
815 // This is the case of a template member function in a class definition (see test2005_168.C).
816 parentDeclaration = cdefn->get_declaration();
817 ASSERT_not_null(parentDeclaration);
818 }
819 else if (nrscope != nullptr)
820 {
821 parentDeclaration = isSgDeclarationStatement(nrscope->get_parent());
822 ASSERT_not_null(parentDeclaration);
823 }
824 else
825 {
826 ROSE_ABORT();
827 }
828
829 return parentDeclaration;
830 }
831
835void
837{
838 ASSERT_not_null(var_decl);
839 ASSERT_not_null(base_decl);
840
841 // There is a bug (see gitlab-issue-349.jov) that arises when base_decl has a comment and it is the
842 // first statement, because base_decl will be removed (causing comments to be moved, where? good question!).
843 // Consider moving comments to var_decl first to circumvent (by artfulness or deception) potential problems.
844 // [Rasmussen 2024.04.10]
845
846 // try to remove it from the scope's declaration list
847 // If the struct decl was previously inserted into its scope
848 if (base_decl->get_parent() != nullptr)
849 {
850 if (base_decl->get_scope() == base_decl->get_parent())
851 {
852 SgStatementPtrList stmt_list = base_decl->get_scope()->generateStatementList();
853 if (find(stmt_list.begin(), stmt_list.end(), base_decl) != stmt_list.end())
855 }
856 }
857 base_decl->set_parent(var_decl);
858 var_decl->set_baseTypeDefiningDeclaration(base_decl);
859
860 //Set an internal mangled name for the anonymous declaration, if necessary
861 // resetNamesInAST(); // this will trigger mangleNameMap.size() ==0 assertion.
862 // We call resetEmptyNames directly instead.
863 ResetEmptyNames t1;
864 t1.traverseMemoryPool();
865}
866
867// DQ (11/4/2007): This looks for a forward temple member function declaration of matching name exists in the specified scope.
868bool
870 {
871 // DQ (11/3/2007): Look for an existing previously inserted (or existing) template member function declaration and only add one if we can't find it.
872
873 bool foundExistingPrototype = false;
874
875 ROSE_ASSERT(scope != NULL);
876 ROSE_ASSERT(functionDeclaration != NULL);
877 ROSE_ASSERT(startingAtDeclaration != NULL);
878
879 // TV (09/17/2018): ROSE-1378
880 if (isSgDeclarationScope(scope)) {
881 printf("TODO: SgDeclarationScope handling in SageInterface::isPrototypeInScope see ROSE-1378\n");
882 return false;
883 }
884
885 // These are the scopes for which get_declarationList() is properly defined.
886 ROSE_ASSERT(scope->containsOnlyDeclarations() == true);
887
888 // Note that this is only defined for certain scopes, but we only want it for THOSE scopes
889 SgDeclarationStatementPtrList & declarationList = scope->getDeclarationList();
890
891 // This is a simple way to restrict the evaluation (still linear, but jumps to initial position to start search).
892 SgDeclarationStatementPtrList::iterator startingLocation = find(declarationList.begin(),declarationList.end(),startingAtDeclaration);
893
894 if (startingLocation != declarationList.end())
895 {
896#if 0
897 printf ("startingLocation = %p = %s = %s \n",*startingLocation,(*startingLocation)->class_name().c_str(),SageInterface::get_name(*startingLocation).c_str());
898#endif
899 // printf ("Found the startingLocation is the global scope, now check if we need to add a new declaration \n");
900 SgDeclarationStatementPtrList::iterator i = startingLocation;
901 SgScopeStatement* targetScope = functionDeclaration->get_scope();
902 SgName targetName = functionDeclaration->get_name();
903
904 while (i != declarationList.end())
905 {
906 // printf ("i = %p = %s = %s \n",*i,(*i)->class_name().c_str(),SageInterface::get_name(*i).c_str());
907
908 // Look for a prototype like what we want to insert, if we find it then we don't need to add a second one!
909 SgTemplateInstantiationMemberFunctionDecl* templateMemberFunction = isSgTemplateInstantiationMemberFunctionDecl(*i);
910 if (templateMemberFunction != nullptr)
911 {
912 // Check the name and the scope
913 if (targetScope == templateMemberFunction->get_scope())
914 {
915 if (targetName == templateMemberFunction->get_name())
916 {
917 // Don't count the defining declaration which may be at the end of the global scope.
918 if (templateMemberFunction->isForward() == true)
919 {
920 foundExistingPrototype = true;
921
922 // Exit the loop (optimization)
923 break;
924 }
925 }
926 }
927 }
928
929 i++;
930 }
931 }
932
933 return foundExistingPrototype;
934 }
935
936bool
938 {
939 ROSE_ASSERT(node1 && node2);
940
941 SgNode* curnode = node2;
942 if (node1==node2)
943 {
944 return false;
945 }
946
947 do {
948 curnode= curnode->get_parent();
949 } while( (curnode!=nullptr) && (curnode!=node1));
950
951 if (curnode==node1)
952 {
953 return true;
954 }
955 else
956 {
957 return false;
958 }
959 }
960
961bool
963 {
964 // DQ (12/7/2020): This is supporting the recognition of functions in header files from two different AST.
965
966#define DEBUG_HAS_SAME_SCOPE 0
967
968#if DEBUG_HAS_SAME_SCOPE
969 printf ("In SageInterface::hasSameGlobalScope(): \n");
970 printf (" --- statement_1 = %p = %s \n",statement_1,statement_1->class_name().c_str());
971 printf (" --- statement_2 = %p = %s \n",statement_2,statement_2->class_name().c_str());
972#endif
973
974 bool includingSelf = true;
975 SgGlobal* global_scope_1 = getEnclosingNode<SgGlobal>(statement_1,includingSelf);
976 SgGlobal* global_scope_2 = getEnclosingNode<SgGlobal>(statement_2,includingSelf);
977
978#if DEBUG_HAS_SAME_SCOPE
979 printf (" --- global_scope_1 = %p = %s \n",global_scope_1,global_scope_1->class_name().c_str());
980 SgSourceFile* sourcefile_1 = isSgSourceFile(global_scope_1->get_parent());
981 printf (" --- --- sourcefile_1 = %p filename = %s \n",sourcefile_1,sourcefile_1->getFileName().c_str());
982
983 printf (" --- global_scope_2 = %p = %s \n",global_scope_2,global_scope_2->class_name().c_str());
984 SgSourceFile* sourcefile_2 = isSgSourceFile(global_scope_2->get_parent());
985 printf (" --- --- sourcefile_2 = %p filename = %s \n",sourcefile_2,sourcefile_2->getFileName().c_str());
986#endif
987
988 bool returnResult = (global_scope_1 == global_scope_2);
989
990#if DEBUG_HAS_SAME_SCOPE
991 printf ("Leaving SageInterface::hasSameGlobalScope(): returning: %s \n",returnResult ? "true" : "false");
992#endif
993
994 return returnResult;
995 }
996
997
998std::vector<SgNode*>
1000 {
1001 std::vector<SgNode*> intersectionSet;
1002
1003 // Collect all the IR nodes for the original AST
1004 std::vector<SgNode*> AST_original = NodeQuery::querySubTree (original,V_SgNode);
1005 std::vector<SgNode*> AST_copy = NodeQuery::querySubTree (copy,V_SgNode);
1006
1007 int AST_original_size = AST_original.size();
1008 int AST_copy_size = AST_copy.size();
1009
1010 if (SgProject::get_verbose() > 0)
1011 {
1012 printf ("Original AST size = %d \n",AST_original_size);
1013 printf ("Copy of original AST size = %d \n",AST_copy_size);
1014 }
1015
1016 int differenceInSizes = AST_original_size - AST_copy_size;
1017 if (differenceInSizes == 0)
1018 {
1019 if (SgProject::get_verbose() > 0)
1020 printf ("Copied AST is the SAME size as the original (size = %d) \n",AST_original_size);
1021 }
1022 else
1023 {
1024 printf ("Warning: Copied AST and the original are DIFFERENT sizes (original size = %d copyied size = %d) \n",AST_original_size,AST_copy_size);
1025 }
1026
1027 // Compute the intersection (reference in the copy that point to the origal AST).
1028 // std::set<SgNode*> AST_set_original = AST_original;
1029 std::set<SgNode*> AST_set_original;
1030 for (int i = 0; i < AST_original_size; i++)
1031 {
1032 AST_set_original.insert(AST_original[i]);
1033 }
1034
1035 std::set<SgNode*> AST_set_copy;
1036 for (int i = 0; i < AST_copy_size; i++)
1037 {
1038 AST_set_copy.insert(AST_copy[i]);
1039 }
1040
1041 int size = AST_original_size;
1042 std::vector<SgNode*> intersectionList(size);
1043
1044 // Is there a better way to do this? Build scratch space and then use the different between begin() and end to build another vector.
1045 std::vector<SgNode*>::iterator end = set_intersection(AST_set_original.begin(),AST_set_original.end(),AST_set_copy.begin(),AST_set_copy.end(),intersectionList.begin());
1046
1047 // Build a new vector from the relevant elements of the intersectionList scratch space.
1048 std::vector<SgNode*> meaningIntersectionList = std::vector<SgNode*>(intersectionList.begin(),end);
1049 std::vector<SgNode*> deleteList;
1050 for (int i = 0; i < (int)meaningIntersectionList.size(); i++)
1051 {
1052 if (meaningIntersectionList[i] != nullptr && isSgType(meaningIntersectionList[i]) != nullptr)
1053 {
1054 deleteList.push_back(meaningIntersectionList[i]);
1055 }
1056 }
1057
1058 // Remove the types since they are allowed to be shared...
1059 if (SgProject::get_verbose() > 0)
1060 printf ("Remove the types that are allowed to be shared: deleteList.size() = %ld \n",(long)deleteList.size());
1061
1062 for (std::vector<SgNode*>::iterator i = deleteList.begin(); i != deleteList.end(); i++)
1063 {
1064 meaningIntersectionList.erase(find(meaningIntersectionList.begin(),meaningIntersectionList.end(),*i));
1065 }
1066
1067 if (SgProject::get_verbose() > 0)
1068 printf ("After removing the types there are meaningIntersectionList.size() = %ld \n",(long)meaningIntersectionList.size());
1069
1070 for (int i = 0; i < (int)meaningIntersectionList.size(); i++)
1071 {
1072 printf (" meaningIntersectionList[%d] = %p = %s = %s \n",i,meaningIntersectionList[i],meaningIntersectionList[i]->class_name().c_str(),get_name(meaningIntersectionList[i]).c_str());
1073 }
1074
1075 int unmatchedIRnodes = 0;
1076 if (help != nullptr)
1077 {
1078 std::vector<SgNode*> tmp_AST_original; // = AST_original;
1079 std::vector<SgNode*> tmp_AST_copy; // = AST_copy;
1080
1081 int AST_original_size = AST_original.size();
1082 for (int j = 0; j < AST_original_size; j++)
1083 {
1084 if (AST_original[j] != NULL && isSgType(AST_original[j]) == NULL)
1085 {
1086 tmp_AST_original.push_back(AST_original[j]);
1087 }
1088 }
1089
1090 int AST_copy_size = AST_copy.size();
1091 for (int j = 0; j < AST_copy_size; j++)
1092 {
1093 if (AST_copy[j] != NULL && isSgType(AST_copy[j]) == NULL)
1094 {
1095 tmp_AST_copy.push_back(AST_copy[j]);
1096 }
1097 }
1098
1099 std::vector<SgNode*> deleteList_original;
1100 std::vector<SgNode*> deleteList_copy;
1101 for (int j = 0; j < (int)tmp_AST_original.size(); j++)
1102 {
1103 // printf (" (before removing types) meaningIntersectionList[%d] = %p = %s \n",i,meaningIntersectionList[i],(meaningIntersectionList[i] != NULL) ? meaningIntersectionList[i]->class_name().c_str() : "NULL");
1104 SgCopyHelp::copiedNodeMapTypeIterator i = help->get_copiedNodeMap().find(tmp_AST_original[j]);
1105 // printf ("SgCopyHelp::copiedNodeMapTypeIterator i != help->get_copiedNodeMap().end() = %s \n",i != help->get_copiedNodeMap().end() ? "true" : "false");
1106 if (i != help->get_copiedNodeMap().end())
1107 {
1108 // Matched up an original IR node with it's copy
1109 SgNode* associated_node_copy = i->second;
1110 ROSE_ASSERT(associated_node_copy != NULL);
1111 deleteList_original.push_back(tmp_AST_original[j]);
1112 deleteList_copy.push_back(associated_node_copy);
1113#if 0
1114 // printf ("Original IR node = %p = %s copy = %p \n",tmp_AST_original[j],tmp_AST_original[j]->class_name().c_str(),associated_node_copy);
1115 SgTemplateInstantiationMemberFunctionDecl* templateMemberFunction = isSgTemplateInstantiationMemberFunctionDecl(tmp_AST_original[j]);
1116 SgTemplateInstantiationMemberFunctionDecl* templateMemberFunction_copy = isSgTemplateInstantiationMemberFunctionDecl(associated_node_copy);
1117 if (templateMemberFunction != NULL)
1118 {
1119 printf ("In SageInterface::astIntersection(): Found a SgTemplateInstantiationMemberFunctionDecl = %p copy = %p \n",templateMemberFunction,associated_node_copy);
1120 // templateMemberFunction->get_startOfConstruct()->display("original: debug");
1121 // templateMemberFunction_copy->get_startOfConstruct()->display("copy: debug");
1122 }
1123#endif
1124 }
1125 }
1126
1127 int deleteList_original_size = deleteList_original.size();
1128 for (int j = 0; j < deleteList_original_size; j++)
1129 {
1130 // tmp_AST_original.erase(find(tmp_AST_original.begin(),tmp_AST_original.end(),deleteList_original[j]));
1131 std::vector<SgNode*>::iterator k = find(tmp_AST_original.begin(),tmp_AST_original.end(),deleteList_original[j]);
1132 if (k != tmp_AST_original.end())
1133 {
1134 tmp_AST_original.erase(k);
1135 }
1136 }
1137
1138 if (SgProject::get_verbose() > 0)
1139 printf ("IR nodes different between the original AST and the copy of the AST = %" PRIuPTR " \n",tmp_AST_original.size());
1140
1141 for (int j = 0; j < (int)tmp_AST_original.size(); j++)
1142 {
1143 printf ("non matched IR node = %p = %s = %s \n",tmp_AST_original[j],tmp_AST_original[j]->class_name().c_str(),get_name(tmp_AST_original[j]).c_str());
1144 // tmp_AST_original[j]->get_startOfConstruct()->display("debug");
1145 }
1146
1147 unmatchedIRnodes = (int)tmp_AST_original.size();
1148 }
1149
1150 // DQ (11/2/2007): Make this an error now!
1151 if (differenceInSizes != 0)
1152 {
1153 SgProject* originalProject = isSgProject(original);
1154 if (originalProject != NULL)
1155 {
1156 printf ("In %s Copied AST and the original are DIFFERENT sizes (original size = %d copyied size = %d) IR nodes different = %d \n",
1157 (*originalProject)[0]->get_sourceFileNameWithoutPath().c_str(),AST_original_size,AST_copy_size,unmatchedIRnodes);
1158 }
1159
1160 if (unmatchedIRnodes > 0)
1161 {
1162 printf ("Make this an error under stricter testing \n");
1163 ROSE_ABORT();
1164 }
1165 }
1166
1167 return intersectionSet;
1168 }
1169
1170// AJ (10/21/2004): Added support for changing the symbol name associated with an SgInitializedName
1171// by updating the symbol table
1172int
1173SageInterface::set_name ( SgInitializedName *initializedNameNode, SgName new_name )
1174 {
1175 // find the appropriate symbol table, delete the symbol
1176 // with the old name and add a symbol with the new name.
1177 ROSE_ASSERT(initializedNameNode != NULL);
1178
1179#define DEBUG_SET_NAME 0
1180
1181 // SgNode * node = this;
1182#if DEBUG_SET_NAME
1183 printf ("In SageInterface::set_name(): initializedNameNode = %p name = %s new_name = %s \n",initializedNameNode,initializedNameNode->get_name().str(),new_name.str());
1184#endif
1185
1186#if 0
1187 // DQ (12/9/2004): This should likely call the get_scope function (which is more robust than traversing
1188 // parents, there is a reason why we are forced to include the scope explicitly on some IR nodes,
1189 // see test2004_133.C for details).
1190 while((node!=NULL) && ( isSgScopeStatement(node)==NULL))
1191 node = node->get_parent();
1192
1193 ROSE_ASSERT(node!=NULL);
1194
1195 SgScopeStatement * scope_stmt = isSgScopeStatement(node);
1196#else
1197 SgScopeStatement *scope_stmt = initializedNameNode->get_scope();
1198#endif
1199
1200 // DQ (2/4/2021): Adding support for enum values (in SgEnumDeclarations).
1201 if (isSgEnumDeclaration(initializedNameNode->get_parent()) != NULL)
1202 {
1203 ROSE_ASSERT(scope_stmt != NULL);
1204 printf ("scope_stmt = %p = %s \n",scope_stmt,scope_stmt->class_name().c_str());
1205#if 0
1206 printf ("Detected isSgEnumDeclaration as parent: exiting as a test in SageInterface::set_name() \n");
1207 ROSE_ASSERT(false);
1208#endif
1209 }
1210
1211 ROSE_ASSERT(scope_stmt != NULL);
1212 ROSE_ASSERT(scope_stmt->get_symbol_table() != NULL);
1213 ROSE_ASSERT(scope_stmt->get_symbol_table()->get_table() != NULL);
1214
1215 SgDeclarationStatement * parent_declaration = initializedNameNode->get_declaration();
1216
1217 ROSE_ASSERT(parent_declaration != NULL);
1218
1219 // Find the symbols associated with p_name
1220 std::pair<SgSymbolTable::hash_iterator,SgSymbolTable::hash_iterator> pair_it = scope_stmt->get_symbol_table()->get_table()->equal_range(initializedNameNode->get_name());
1221
1222 SgSymbolTable::hash_iterator found_it = scope_stmt->get_symbol_table()->get_table()->end();
1223
1224 for (SgSymbolTable::hash_iterator it = pair_it.first; it != pair_it.second; ++it)
1225 {
1226#if DEBUG_SET_NAME
1227 printf ("Looking for symbol in scope = %p = %s \n",scope_stmt,scope_stmt->class_name().c_str());
1228 printf (" --- *it = %p = %s \n",(*it).second,(*it).second->class_name().c_str());
1229#endif
1230 switch(parent_declaration->variantT())
1231 {
1232 case V_SgFunctionParameterList:
1233 case V_SgVariableDeclaration:
1234 {
1235 if (isSgVariableSymbol((*it).second) != NULL)
1236 found_it = it;
1237 break;
1238 }
1239
1240 case V_SgClassDeclaration:
1241 {
1242 if (isSgClassSymbol((*it).second) != NULL)
1243 found_it = it;
1244 break;
1245 }
1246
1247 case V_SgFunctionDeclaration:
1248 {
1249 if (isSgFunctionSymbol((*it).second) != NULL)
1250 found_it = it;
1251 break;
1252 }
1253
1254 // DQ (2/4/2021): Adding support for enum values (in SgEnumDeclarations).
1255 case V_SgEnumDeclaration:
1256 {
1257 if (isSgEnumFieldSymbol((*it).second) != NULL)
1258 found_it = it;
1259 break;
1260 }
1261
1262 default:
1263 {
1264 printf ("Default reached in switch in SageInterface::set_name() \n");
1265 }
1266 };
1267 }
1268
1269 // there is no Variable, Class or Function symbol associated with p_name
1270 if (found_it == scope_stmt->get_symbol_table()->get_table()->end())
1271 {
1272 printf ("Warning: There is no Variable, Class, Function, or EnumValue symbol associated with p_name \n");
1273 return 0;
1274 }
1275
1276 // DQ (11/12/2018): In general, this can't be tested if we permit it to be transformed.
1277 if (statementCanBeTransformed(parent_declaration) == false)
1278 {
1279 printf ("WARNING: SageInterface::set_name(): This statement can not be transformed because it is part of a header file specific more then once with different include file syntax \n");
1280 return 0;
1281 }
1282 else
1283 {
1284#if DEBUG_SET_NAME
1285 printf ("In SageInterface::set_name(): This statement can be transformed! parent_declaration = %p = %s \n",parent_declaration,get_name(parent_declaration).c_str());
1286#endif
1287
1288#if 0
1289 // DQ (11/12/2018): Initial test problem should not permit a transformation!
1290 printf ("Exiting as a test! \n");
1291 ROSE_ABORT();
1292#endif
1293 }
1294
1295 SgSymbol * associated_symbol = (*found_it).second;
1296
1297 // erase the name from there
1298 scope_stmt->get_symbol_table()->get_table()->erase(found_it);
1299
1300 // insert the new_name in the symbol table
1301// CH (4/9/2010): Use boost::unordered instead
1302//#ifdef _MSCx_VER
1303#if 0
1304 // DQ (11/28/2009): Unclear if this code is a problem (testing).
1305
1306// CH (4/7/2010): It seems that the following code can be compiled under MSVC 9.0
1307//#pragma message ("WARNING: this code does not apprear to compile with MSVC.")
1308// printf ("ERROR: this code does not apprear to compile with MSVC. \n");
1309// ROSE_ASSERT(false);
1310 found_it = scope_stmt->get_symbol_table()->get_table()->insert(pair<SgName,SgSymbol*> ( new_name,associated_symbol));
1311#else
1312 found_it = scope_stmt->get_symbol_table()->get_table()->insert(pair<SgName,SgSymbol*> ( new_name,associated_symbol));
1313#endif
1314 // if insertion failed
1315 if (found_it == scope_stmt->get_symbol_table()->get_table()->end())
1316 {
1317 printf ("Warning: insertion of new symbol failed \n");
1318 return 0;
1319 }
1320
1321#if DEBUG_SET_NAME
1322 // Set the p_name to the new_name
1323 printf ("Reset initializedNameNode->get_name() = %s to new_name = %s \n",initializedNameNode->get_name().str(),new_name.str());
1324#endif
1325
1326 // p_name = new_name;
1327 initializedNameNode->set_name(new_name);
1328
1329 // DQ (11/30/2018): Mark the enclosing statement as modified, so that it will be recognized
1330 // in the header file unparsing as being a header file that should be unparsed.
1331 SgStatement* enclosingStatement = getEnclosingStatement(initializedNameNode);
1332 ROSE_ASSERT(enclosingStatement != NULL);
1333 enclosingStatement->set_isModified(true);
1334 enclosingStatement->setTransformation();
1335
1336 // Invalidate the p_iterator, p_no_name and p_name data members in the Symbol table
1337
1338#if 1
1339 // Search the AST for references to this SgInitializedName (SgVarRefExp), check if the symbol matches
1340 // (we can do this since we only reused the exisitng symbol), and mark those expressions as modified.
1341 class RoseVisitor : public ROSE_VisitTraversal
1342 {
1343 public:
1344 int counter;
1345 SgSymbol* symbol;
1346
1348 void visit (SgNode* node)
1349 {
1350 SgVarRefExp* varRefExp = isSgVarRefExp(node);
1351 SgVariableSymbol* variableSymbol = isSgVariableSymbol(symbol);
1352
1353 ROSE_ASSERT(varRefExp != NULL);
1354 ROSE_ASSERT(variableSymbol != NULL);
1355
1356 if (varRefExp->get_symbol() == variableSymbol)
1357 {
1358#if DEBUG_SET_NAME
1359 printf ("In SageInterface::set_name(): Found associated SgVarRefExp varRefExp = %p to symbol associated_symbol = %p \n",varRefExp,variableSymbol);
1360#endif
1361#if 0
1362 printf ("Exiting as a test! \n");
1363 ROSE_ABORT();
1364#endif
1365 varRefExp->set_isModified(true);
1366 varRefExp->setTransformation();
1367#if 1
1368 // DQ (5/2/2021): The traversal over the file will identify the nesting of and transformations in outer (enclosing) IR nodes.
1369 // DQ (5/1/2021): I think that we may have to set the physical node id and maybe make it to be output. This is
1370 // special to the case of using the header file unparsing (any maybe the token-based unparsing with the header
1371 // file unparsing, but I think just the header file unparsing).
1372#if 0
1373 printf ("In SageInterface::set_name(): When unparsing header files, we need to set the physical file id to the correct file \n");
1374#endif
1375 // DQ (4/23/2021): I think it is a problem that the statement is not marked as a transformation so that we
1376 // know how to handle it with the token-based unparsing.
1377 SgStatement* associatedStatement = getEnclosingStatement(varRefExp);
1378 ROSE_ASSERT(associatedStatement != NULL);
1379 associatedStatement->setTransformation();
1380#endif
1381#if 0
1382 // DQ (11/13/2018): Mark the statement associated with this SgVarRefExp (see test9 in UnparseHeaders_tests).
1383 SgStatement* associatedStatement = getEnclosingStatement(varRefExp);
1384 ROSE_ASSERT(associatedStatement != NULL);
1385 // associatedStatement->set_isModified(true);
1386 // associatedStatement->set_containsTransformation(true);
1387 associatedStatement->setTransformation();
1388#endif
1389 }
1390 }
1391
1392 RoseVisitor(SgSymbol* symbol_parmeter) : counter(0), symbol(symbol_parmeter)
1393 {
1394#if 0
1395 printf ("roseVisitor::visit: counter %4d node = %s \n",counter,symbol_parmeter->class_name().c_str());
1396#endif
1397 counter++;
1398 }
1399 };
1400
1401 // RoseVisitor visitor;
1402 // visitor.traverseMemoryPool();
1403 RoseVisitor t1(associated_symbol);
1405#endif
1406
1407#if DEBUG_SET_NAME
1408 printf ("Leaving SageInterface::set_name(): initializedNameNode = %p name = %s new_name = %s (return 1) \n",initializedNameNode,initializedNameNode->get_name().str(),new_name.str());
1409#endif
1410
1411 // DQ (4/23/2021): I think that we should be returning zero for no error
1412 // and one for an error, this function appears to have this detail reversed.
1413 return 1;
1414 }
1415
1416
1417void
1419 {
1420 printf ("In SageInterface::listHeaderFiles(): includeFile filename = %s \n",includeFile->get_filename().str());
1421
1422 // Preorder traversal to uniquely name specific declarations (SgClassDeclaration and SgFunctionDeclaration IR nodes).
1423 class PrefixTraversal : public AstSimpleProcessing
1424 {
1425 public:
1426 void visit (SgNode* node)
1427 {
1428 printf ("In listHeaderFiles visit(): node = %p = %s \n",node,node->class_name().c_str());
1429 SgIncludeFile* includeFile = isSgIncludeFile(node);
1430 if (includeFile != NULL)
1431 {
1432 printf ("include file: filename = %s \n",includeFile->get_filename().str());
1433 }
1434 }
1435 };
1436
1437 // Now buid the traveral object and call the traversal (preorder) on the function definition.
1438 PrefixTraversal traversal;
1439 traversal.traverse(includeFile, preorder);
1440
1441 }
1442
1443
1444bool
1446 {
1447 // DQ (5/9/2021): Adding support for detection of statements in a scope that must be unparsed.
1448 // This function supports the token-based unparsing when used with unparsing of header files
1449 // to know when the scope can be unparsed via it's token stream, even though a statement from
1450 // a header file may contain a transformation.
1451 // returns true if there is a statement in the scope that has to be unparsed (is from the same file as the scope).
1452 // returns false if the scope is empty or contains only statements associated with one or more header files.
1453 // When the scope has statements from the same file, then if there is a transformation contained in any of
1454 // those statements then we have to unparse the scope one statement at a time when using the token-based
1455 // unparsing. If the scope has no statements from the same file, then the existance of any statement that
1456 // contains a transformation does not case the statements to be unparsed individually.
1457
1458 ROSE_ASSERT(scope != NULL);
1459 int scope_file_id = scope->get_file_info()->get_physical_file_id();
1460
1461 bool return_value = false;
1462
1463 if (scope->containsOnlyDeclarations() == true)
1464 {
1465 SgDeclarationStatementPtrList & declarationStatementList = scope->getDeclarationList();
1466#if 1
1467 printf ("In scopeHasStatementsFromSameFile(): DeclarationStatementList not implemented \n");
1468#endif
1469#if 1
1470 printf ("declarationStatementList.size() = %zu \n",declarationStatementList.size());
1471#endif
1472 SgDeclarationStatementPtrList::iterator i = declarationStatementList.begin();
1473
1474 while (i != declarationStatementList.end() && return_value == false)
1475 {
1476 SgDeclarationStatement* statement = *i;
1477 int statement_file_id = statement->get_file_info()->get_physical_file_id();
1478
1479 if (statement_file_id == scope_file_id)
1480 {
1481 return_value = true;
1482 }
1483
1484 i++;
1485 }
1486#if 0
1487 printf ("Exiting as a test! \n");
1488 ROSE_ASSERT(false);
1489#endif
1490 }
1491 else
1492 {
1493 SgStatementPtrList & statementList = scope->getStatementList();
1494#if 1
1495 printf ("In scopeHasStatementsFromSameFile(): StatementList not implemented \n");
1496#endif
1497 SgStatementPtrList::iterator i = statementList.begin();
1498
1499 while (i != statementList.end() && return_value == false)
1500 {
1501 SgStatement* statement = *i;
1502 int statement_file_id = statement->get_file_info()->get_physical_file_id();
1503
1504 if (statement_file_id == scope_file_id)
1505 {
1506 return_value = true;
1507 }
1508
1509 i++;
1510 }
1511 }
1512
1513 return return_value;
1514 }
1515
1516
1517namespace
1518{
1519 template <class SageDecl>
1520 std::string genericGetName(SageDecl* dcl)
1521 {
1522 ROSE_ASSERT(dcl);
1523 return dcl->get_name();
1524 }
1525}
1526
1527
1528
1529
1530string
1532 {
1533 string name = "undefined_name";
1534
1535 ROSE_ASSERT(directive != NULL);
1536
1537 name = directive->class_name();
1538
1539#if 1
1540 // I don't think we need this code now!
1541 switch (directive->variantT())
1542 {
1543 // Separate out these cases...
1544 case V_SgIncludeDirectiveStatement:
1545 case V_SgDefineDirectiveStatement:
1546 case V_SgUndefDirectiveStatement:
1547 case V_SgIfdefDirectiveStatement:
1548 case V_SgIfndefDirectiveStatement:
1549 case V_SgDeadIfDirectiveStatement:
1550 case V_SgIfDirectiveStatement:
1551 case V_SgElseDirectiveStatement:
1552 case V_SgElseifDirectiveStatement:
1553 case V_SgLineDirectiveStatement:
1554 case V_SgWarningDirectiveStatement:
1555 case V_SgErrorDirectiveStatement:
1556 case V_SgEmptyDirectiveStatement:
1557 {
1558 name = directive->class_name();
1559 break;
1560 }
1561
1562 // case ClinkageDeclarationStatement:
1563 case V_SgClinkageStartStatement:
1564 case V_SgClinkageEndStatement:
1565 {
1566 name = directive->class_name();
1567 break;
1568 }
1569
1570 case V_SgFortranIncludeLine:
1571 {
1572 name = directive->class_name();
1573 break;
1574 }
1575
1576 default:
1577 // name = "default name (default case reached: not handled)";
1578 printf ("Warning: default case reached in SageInterface::get_name ( const SgC_PreprocessorDirectiveStatement* directive ), directive = %p = %s \n",
1579 directive,directive->class_name().c_str());
1580 ROSE_ABORT();
1581#if 0 // [Robb Matzke 2021-03-24]: unreachable
1582 name = "directive_default_name_case_reached_not_handled";
1583 break;
1584#endif
1585 }
1586#endif
1587
1588 return name;
1589 }
1590
1591string
1593 {
1594 string name = "undefined_name";
1595
1596 ROSE_ASSERT(declaration != NULL);
1597
1598 // DQ (11/23/2008): Handle the case of a Cpp directive...
1599 const SgC_PreprocessorDirectiveStatement* directive = isSgC_PreprocessorDirectiveStatement(declaration);
1600 if (directive != NULL)
1601 {
1602 return SageInterface::get_name (directive);
1603 }
1604
1605 switch (declaration->variantT())
1606 {
1607 case V_SgTemplateMemberFunctionDeclaration:
1608 name = isSgTemplateMemberFunctionDeclaration(declaration)->get_name().str();
1609 break;
1610
1611 case V_SgTemplateFunctionDeclaration:
1612 name = isSgTemplateFunctionDeclaration(declaration)->get_name().str();
1613 break;
1614
1615 case V_SgTemplateClassDeclaration:
1616 name = isSgTemplateClassDeclaration(declaration)->get_name().str();
1617 break;
1618
1619 case V_SgTemplateDeclaration:
1620 name = isSgTemplateDeclaration(declaration)->get_name().str();
1621 break;
1622
1623 case V_SgTemplateInstantiationDecl:
1624 name = isSgTemplateInstantiationDecl(declaration)->get_templateName().str();
1625 break;
1626
1627 case V_SgClassDeclaration:
1628 case V_SgDerivedTypeStatement:
1629 case V_SgJovialTableStatement:
1630 name = isSgClassDeclaration(declaration)->get_name().str();
1631 break;
1632
1633 // Rasmussen (8/2/2019): Added SgJovialDefineDeclaration and SgJovialDirectiveStatement
1634 // I'm not sure class_name() is correct. Probably get_name() should be fixed.
1635 case V_SgJovialDefineDeclaration:
1636 case V_SgJovialDirectiveStatement:
1637 case V_SgJovialCompoolStatement:
1638 name = "__" + declaration->class_name() + "_";
1639 name += StringUtility::numberToString(declaration);
1640 break;
1641
1642 case V_SgJovialLabelDeclaration:
1643 name = isSgJovialLabelDeclaration(declaration)->get_label();
1644 break;
1645
1646 case V_SgEnumDeclaration:
1647 name = isSgEnumDeclaration(declaration)->get_name().str();
1648 break;
1649
1650 // DQ (11/5/2014): Adding support for template typedef declarations (C++11 feature).
1651 case V_SgTemplateInstantiationTypedefDeclaration:
1652 // DQ (11/3/2014): Adding support for template typedef declarations (C++11 feature).
1653 case V_SgTemplateTypedefDeclaration:
1654 case V_SgTypedefDeclaration:
1655 name = isSgTypedefDeclaration(declaration)->get_name().str();
1656 break;
1657
1658 case V_SgFunctionDeclaration:
1659 case V_SgProgramHeaderStatement:
1660 case V_SgProcedureHeaderStatement:
1661 case V_SgMemberFunctionDeclaration:
1662 case V_SgTemplateInstantiationFunctionDecl:
1663 case V_SgTemplateInstantiationMemberFunctionDecl:
1664 case V_SgAdaFunctionRenamingDecl:
1665 case V_SgAdaEntryDecl:
1666 name = isSgFunctionDeclaration(declaration)->get_name().str();
1667 break;
1668
1669 case V_SgNamespaceDeclarationStatement:
1670 name = isSgNamespaceDeclarationStatement(declaration)->get_name().str();
1671 break;
1672
1673 // DQ (2/12/2006): Added support to get name of SgFunctionParameterList
1674 case V_SgFunctionParameterList:
1675 {
1676 // Parents should be set prior to calling these functions (if not we might have to implement that case)
1677 ROSE_ASSERT(declaration->get_parent() != NULL);
1678
1679 if (SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(declaration->get_parent()))
1680 {
1681 name = get_name(functionDeclaration);
1682 }
1683 else if (SgScopeStatement* scopeStmt = isSgScopeStatement(declaration->get_parent()))
1684 {
1685 name = get_name(scopeStmt);
1686 }
1687 else ROSE_ABORT();
1688
1689 name += "_parameter_list_";
1690 break;
1691 }
1692
1693 // DQ (2/10/2012): Added support for template variable declarations (using base class support).
1694 case V_SgTemplateVariableDeclaration:
1695
1696 // DQ (3/8/2006): Implemented case for variable declaration (forgot this case)
1697 case V_SgVariableDeclaration:
1698 {
1699 // DQ (2/11/2007): Modified to return names that can be used as variables (required
1700 // because we use this mechanism to generate names for unnamed structs and enums).
1701 name = "_variable_declaration_";
1702 const SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(declaration);
1703 ROSE_ASSERT(variableDeclaration != NULL);
1704 SgInitializedNamePtrList::const_iterator i = variableDeclaration->get_variables().begin();
1705
1706 // Make sure that we have at least one variable in the list
1707 ROSE_ASSERT(i != variableDeclaration->get_variables().end());
1708 do {
1709 // name += string(" ") + string((*i)->get_name().str());
1710 name += string((*i)->get_name().str());
1711 i++;
1712 }
1713 while (i != variableDeclaration->get_variables().end());
1714 break;
1715 }
1716
1717
1718 // DQ (3/8/2006): Implemented case for variable declaration (forgot this case)
1719 case V_SgVariableDefinition:
1720 {
1721 // DQ (2/11/2007): Modified to return names that can be used as variables (required
1722 // because we use this mechanism to generate names for unnamed structs and enums).
1723 name = "_variable_definition_";
1724 const SgVariableDefinition* variableDefinition = isSgVariableDefinition(declaration);
1725 ROSE_ASSERT(variableDefinition != NULL);
1726
1727 // define this in terms of the associated SgInitializedName
1728 ROSE_ASSERT(variableDefinition->get_vardefn() != NULL);
1729 name += get_name(variableDefinition->get_vardefn());
1730 break;
1731 }
1732
1733 // DQ (3/17/2006): Implemented case for pragma declaration (forgot this case)
1734 case V_SgPragmaDeclaration:
1735 {
1736 name = "_pragma_declaration_";
1737 const SgPragmaDeclaration* pragmaDeclaration = isSgPragmaDeclaration(declaration);
1738 ROSE_ASSERT(pragmaDeclaration != NULL);
1739 ROSE_ASSERT(pragmaDeclaration->get_pragma() != NULL);
1740 name += get_name(pragmaDeclaration->get_pragma());
1741 break;
1742 }
1743
1744 // DQ (4/15/2007): Implemented case for using directive statement (forgot this case)
1745 case V_SgUsingDirectiveStatement:
1746 {
1747 name = "_using_directive_statement_";
1748 const SgUsingDirectiveStatement* usingDeclaration = isSgUsingDirectiveStatement(declaration);
1749 ROSE_ASSERT(usingDeclaration != NULL);
1750 ROSE_ASSERT(usingDeclaration->get_namespaceDeclaration() != NULL);
1751 name += get_name(usingDeclaration->get_namespaceDeclaration());
1752 break;
1753 }
1754
1755 // DQ (6/20/2007): Added new case!
1756 case V_SgNamespaceAliasDeclarationStatement:
1757 {
1758 name = "_namespace_alias_directive_statement_";
1759 const SgNamespaceAliasDeclarationStatement* namespaceAliasDeclaration = isSgNamespaceAliasDeclarationStatement(declaration);
1760 ROSE_ASSERT(namespaceAliasDeclaration != NULL);
1761 ROSE_ASSERT(namespaceAliasDeclaration->get_name().is_null() == false);
1762 name += namespaceAliasDeclaration->get_name();
1763 break;
1764 }
1765
1766 // DQ (6/20/2007): Added new case!
1767 case V_SgUsingDeclarationStatement:
1768 {
1769 name = "_using_declaration_statement_";
1770 const SgUsingDeclarationStatement* usingDeclaration = isSgUsingDeclarationStatement(declaration);
1771 ROSE_ASSERT(usingDeclaration != NULL);
1772 if (usingDeclaration->get_declaration() != NULL)
1773 {
1774 name += get_name(usingDeclaration->get_declaration());
1775 }
1776 else
1777 {
1778 ROSE_ASSERT(usingDeclaration->get_initializedName() != NULL);
1779 name += get_name(usingDeclaration->get_initializedName());
1780 }
1781 break;
1782 }
1783
1784 // DQ (6/20/2007): Added new case!
1785 case V_SgTemplateInstantiationDirectiveStatement:
1786 {
1787 name = "_template_instantiation_directive_statement_";
1788 ROSE_ASSERT(declaration != NULL);
1789 const SgTemplateInstantiationDirectiveStatement* templateInstantiationDirective = isSgTemplateInstantiationDirectiveStatement(declaration);
1790 ROSE_ASSERT(templateInstantiationDirective != NULL);
1791 ROSE_ASSERT(templateInstantiationDirective->get_declaration() != NULL);
1792#if 0
1793 printf ("declaration->get_declaration() = %p = %s \n",templateInstantiationDirective->get_declaration(),templateInstantiationDirective->get_declaration()->class_name().c_str());
1794#endif
1795 name += get_name(templateInstantiationDirective->get_declaration());
1796 break;
1797 }
1798
1799 case V_SgCtorInitializerList:
1800 {
1801 name = "_ctor_list_";
1802 const SgCtorInitializerList* ctorDeclaration = isSgCtorInitializerList(declaration);
1803 ROSE_ASSERT(ctorDeclaration != NULL);
1804 ROSE_ASSERT(ctorDeclaration->get_parent() != NULL);
1805 name += get_name(ctorDeclaration->get_parent());
1806 break;
1807 }
1808
1809 // DQ (8/9/2007): Added case for SgAsmStmt
1810 case V_SgAsmStmt:
1811 {
1812 name = "_asm_stmt_";
1813 const SgAsmStmt* asmStatement = isSgAsmStmt(declaration);
1814 ROSE_ASSERT(asmStatement != NULL);
1815 ROSE_ASSERT(asmStatement->get_parent() != NULL);
1816 name += StringUtility::numberToString(const_cast<SgAsmStmt*>(asmStatement));
1817 break;
1818 }
1819
1820 // DQ (8/22/2007): Added case for SgImplicitStatement
1821 case V_SgImplicitStatement:
1822 {
1823 name = "_fortran_implicit_";
1824 const SgImplicitStatement* implicitStatement = isSgImplicitStatement(declaration);
1825 ROSE_ASSERT(implicitStatement != NULL);
1826 ROSE_ASSERT(implicitStatement->get_parent() != NULL);
1827 name += StringUtility::numberToString(const_cast<SgImplicitStatement*>(implicitStatement));
1828 break;
1829 }
1830
1831 // DQ (8/22/2007): Added case for SgNamelistStatement
1832 case V_SgNamelistStatement:
1833 {
1834 name = "_fortran_namelist_";
1835 const SgNamelistStatement* namelistStatement = isSgNamelistStatement(declaration);
1836 ROSE_ASSERT(namelistStatement != NULL);
1837 ROSE_ASSERT(namelistStatement->get_parent() != NULL);
1838 name += StringUtility::numberToString(const_cast<SgNamelistStatement*>(namelistStatement));
1839 break;
1840 }
1841
1842 // DQ (11/21/2007): Added case for SgEquivalenceStatement
1843 case V_SgEquivalenceStatement:
1844 {
1845 name = "_fortran_equivalence_";
1846 const SgEquivalenceStatement* equivalenceStatement = isSgEquivalenceStatement(declaration);
1847 ROSE_ASSERT(equivalenceStatement != NULL);
1848 ROSE_ASSERT(equivalenceStatement->get_parent() != NULL);
1849 name += StringUtility::numberToString(const_cast<SgEquivalenceStatement*>(equivalenceStatement));
1850 break;
1851 }
1852
1853
1854 // DQ (11/21/2007): Added case for SgCommonBlock
1855 case V_SgCommonBlock:
1856 {
1857 name = "_fortran_common_block_";
1858 const SgCommonBlock* commonBlockStatement = isSgCommonBlock(declaration);
1859 ROSE_ASSERT(commonBlockStatement != NULL);
1860 ROSE_ASSERT(commonBlockStatement->get_parent() != NULL);
1861 name += StringUtility::numberToString(const_cast<SgCommonBlock*>(commonBlockStatement));
1862 break;
1863 }
1864
1865 // DQ (11/21/2007): Added case for SgImportStatement
1866 case V_SgImportStatement:
1867 {
1868 name = "_fortran_import_stmt_";
1869 const SgImportStatement* importStatement = isSgImportStatement(declaration);
1870 ROSE_ASSERT(importStatement != NULL);
1871 ROSE_ASSERT(importStatement->get_parent() != NULL);
1872 name += StringUtility::numberToString(const_cast<SgImportStatement*>(importStatement));
1873 break;
1874 }
1875
1876 // DQ (11/21/2007): Added case for SgFormatStatement
1877 case V_SgFormatStatement:
1878 {
1879 name = "_fortran_format_stmt_";
1880 const SgFormatStatement* formatStatement = isSgFormatStatement(declaration);
1881 ROSE_ASSERT(formatStatement != NULL);
1882 ROSE_ASSERT(formatStatement->get_parent() != NULL);
1883 name += StringUtility::numberToString(const_cast<SgFormatStatement*>(formatStatement));
1884 break;
1885 }
1886
1887 // DQ (12/27/2007): Added case for SgModuleStatement
1888 case V_SgModuleStatement:
1889 {
1890 name = "_fortran_module_stmt_";
1891 const SgModuleStatement* moduleStatement = isSgModuleStatement(declaration);
1892 ROSE_ASSERT(moduleStatement != NULL);
1893 ROSE_ASSERT(moduleStatement->get_parent() != NULL);
1894 name += StringUtility::numberToString(const_cast<SgModuleStatement*>(moduleStatement));
1895 break;
1896 }
1897
1898 // DQ (12/27/2007): Added case for SgUseStatement
1899 case V_SgUseStatement:
1900 {
1901 name = "_fortran_use_stmt_";
1902 const SgUseStatement* useStatement = isSgUseStatement(declaration);
1903 ROSE_ASSERT(useStatement != NULL);
1904 ROSE_ASSERT(useStatement->get_parent() != NULL);
1905 name += StringUtility::numberToString(const_cast<SgUseStatement*>(useStatement));
1906 break;
1907 }
1908
1909 // DQ (12/28/2007): Added case for SgContainsStatement
1910 case V_SgContainsStatement:
1911 {
1912 name = "_fortran_contains_stmt_";
1913 const SgContainsStatement* containsStatement = isSgContainsStatement(declaration);
1914 ROSE_ASSERT(containsStatement != NULL);
1915 ROSE_ASSERT(containsStatement->get_parent() != NULL);
1916 name += StringUtility::numberToString(const_cast<SgContainsStatement*>(containsStatement));
1917 break;
1918 }
1919
1920 // DQ (1/20/2008): Added case for SgEntryStatement
1921 case V_SgEntryStatement:
1922 {
1923 name = "_fortran_entry_stmt_";
1924 const SgEntryStatement* entryStatement = isSgEntryStatement(declaration);
1925 ROSE_ASSERT(entryStatement != NULL);
1926 ROSE_ASSERT(entryStatement->get_parent() != NULL);
1927 name += StringUtility::numberToString(const_cast<SgEntryStatement*>(entryStatement));
1928 break;
1929 }
1930
1931 // DQ (1/23/2008): Added case for SgAttributeSpecificationStatement
1932 case V_SgAttributeSpecificationStatement:
1933 {
1934 name = "_fortran_attribute_specification_stmt_";
1935 const SgAttributeSpecificationStatement* statement = isSgAttributeSpecificationStatement(declaration);
1936 ROSE_ASSERT(statement != NULL);
1937 ROSE_ASSERT(statement->get_parent() != NULL);
1939 break;
1940 }
1941
1942 case V_SgInterfaceStatement:
1943 {
1944 name = "_fortran_interface_stmt_";
1945 const SgInterfaceStatement* statement = isSgInterfaceStatement(declaration);
1946 ROSE_ASSERT(statement != NULL);
1947 ROSE_ASSERT(statement->get_parent() != NULL);
1948 name += StringUtility::numberToString(const_cast<SgInterfaceStatement*>(statement));
1949 break;
1950 }
1951
1952 case V_SgFortranIncludeLine:
1953 {
1954 name = "_fortran_include_line_stmt_";
1955 const SgFortranIncludeLine* statement = isSgFortranIncludeLine(declaration);
1956 ROSE_ASSERT(statement != NULL);
1957 ROSE_ASSERT(statement->get_parent() != NULL);
1958 name += StringUtility::numberToString(const_cast<SgFortranIncludeLine*>(statement));
1959 break;
1960 }
1961
1962 // DQ (4/16/2011): Added Java import statment support.
1963 case V_SgJavaImportStatement:
1964 {
1965 name = "_java_import_stmt_";
1966 const SgJavaImportStatement* statement = isSgJavaImportStatement(declaration);
1967 ROSE_ASSERT(statement != NULL);
1968 ROSE_ASSERT(statement->get_parent() != NULL);
1969 name += StringUtility::numberToString(const_cast<SgJavaImportStatement*>(statement));
1970 break;
1971 }
1972
1973 case V_SgJavaPackageDeclaration:
1974 {
1975 name = "_java_package_declaration_";
1976 const SgJavaPackageDeclaration* package_declaration = isSgJavaPackageDeclaration(declaration);
1977 ROSE_ASSERT(package_declaration != NULL);
1978 ROSE_ASSERT(package_declaration->get_parent() != NULL);
1979 name += StringUtility::numberToString(const_cast<SgJavaPackageDeclaration*>(package_declaration));
1980 break;
1981 }
1982
1983 case V_SgJavaPackageStatement:
1984 {
1985 name = "_java_package_stmt_";
1986 const SgJavaPackageStatement* statement = isSgJavaPackageStatement(declaration);
1987 ROSE_ASSERT(statement != NULL);
1988 ROSE_ASSERT(statement->get_parent() != NULL);
1989 name += StringUtility::numberToString(const_cast<SgJavaPackageStatement*>(statement));
1990 break;
1991 }
1992
1993 // DQ (1/21/2018): Added case for C++11 SgStaticAssertionDeclaration
1994 case V_SgStaticAssertionDeclaration:
1995 {
1996 name = "_static_assertion_declaration_stmt_";
1997 const SgStaticAssertionDeclaration* statement = isSgStaticAssertionDeclaration(declaration);
1998 ROSE_ASSERT(statement != NULL);
1999 ROSE_ASSERT(statement->get_parent() != NULL);
2000 name += StringUtility::numberToString(const_cast<SgStaticAssertionDeclaration*>(statement));
2001 break;
2002 }
2003
2004 case V_SgNonrealDecl:
2005 {
2006 const SgNonrealDecl * nrdecl = isSgNonrealDecl(declaration);
2007 ROSE_ASSERT(nrdecl != NULL);
2008 name = nrdecl->get_name();
2009 break;
2010 }
2011
2012 // DQ (3/26/2019): Adding support for new declaration.
2013 case V_SgEmptyDeclaration:
2014 {
2015 const SgEmptyDeclaration * emptyDeclaration = isSgEmptyDeclaration(declaration);
2016 ROSE_ASSERT(emptyDeclaration != NULL);
2017 name = string("emptyDeclaration") + StringUtility::numberToString(const_cast<SgDeclarationStatement*>(declaration));
2018 break;
2019 }
2020
2021 case V_SgAdaPackageSpecDecl:
2022 {
2023 name = genericGetName(isSgAdaPackageSpecDecl(declaration));
2024 break;
2025 }
2026
2027 case V_SgAdaPackageBodyDecl:
2028 {
2029 name = genericGetName(isSgAdaPackageBodyDecl(declaration));
2030 break;
2031 }
2032
2033 case V_SgAdaFormalTypeDecl:
2034 {
2035 name = genericGetName(isSgAdaFormalTypeDecl(declaration));
2036 break;
2037 }
2038
2039 case V_SgAdaGenericDecl:
2040 {
2041 // need to look inside the declaration wrapped by the generic.
2042 const SgAdaGenericDecl* gendcl = isSgAdaGenericDecl(declaration);
2043 name = get_name(gendcl->get_declaration());
2044 break;
2045#if OBSOLETE_CODE
2046 if (isSgFunctionDeclaration(dcl->get_declaration())) {
2047 name = "_ada_generic_decl_" + genericGetName(isSgFunctionDeclaration(dcl->get_declaration()));
2048 break;
2049 }
2050 if (isSgAdaPackageSpecDecl(dcl->get_declaration())) {
2051 name = "_ada_generic_decl_" + genericGetName(isSgAdaPackageSpecDecl(dcl->get_declaration()));
2052 break;
2053 }
2054
2055 // something malformed in the tree if we get here
2056 ROSE_ABORT();
2057 break;
2058#endif /* OBSOLETE_CODE */
2059 }
2060
2061 case V_SgAdaDiscriminatedTypeDecl:
2062 {
2063 const SgAdaDiscriminatedTypeDecl* dcl = isSgAdaDiscriminatedTypeDecl(declaration);
2064 ROSE_ASSERT(dcl);
2065
2066 if (const SgDeclarationStatement* discrDcl = dcl->get_discriminatedDecl())
2067 {
2068 name = get_name(discrDcl);
2069 }
2070 else
2071 {
2072 name = "_incomplete_Ada_discriminated_type_";
2073 }
2074
2075 break;
2076 }
2077
2078 case V_SgAdaVariantDecl:
2079 {
2080 name = "_ada_variant_decl_";
2081 break;
2082 }
2083
2084 case V_SgAdaAttributeClause:
2085 {
2086 name = "_ada_attribute_clause_";
2087 break;
2088 }
2089
2090 case V_SgAdaRepresentationClause:
2091 {
2092 name = "_ada_representation_clause_";
2093 break;
2094 }
2095
2096 case V_SgAdaEnumRepresentationClause:
2097 {
2098 name = "_ada_enum_representation_clause_";
2099 break;
2100 }
2101
2102 case V_SgAdaComponentClause:
2103 {
2104 name = "_ada_component_clause_";
2105 break;
2106 }
2107
2108 case V_SgAdaTaskTypeDecl:
2109 {
2110 name = genericGetName(isSgAdaTaskTypeDecl(declaration));
2111 break;
2112 }
2113
2114 case V_SgAdaProtectedTypeDecl:
2115 {
2116 name = genericGetName(isSgAdaProtectedTypeDecl(declaration));
2117 break;
2118 }
2119
2120 case V_SgAdaTaskBodyDecl:
2121 {
2122 name = genericGetName(isSgAdaTaskBodyDecl(declaration));
2123 break;
2124 }
2125
2126 case V_SgAdaProtectedBodyDecl:
2127 {
2128 name = genericGetName(isSgAdaProtectedBodyDecl(declaration));
2129 break;
2130 }
2131
2132 case V_SgAdaRenamingDecl:
2133 {
2134 name = genericGetName(isSgAdaRenamingDecl(declaration));
2135 break;
2136 }
2137
2138 case V_SgAdaTaskSpecDecl:
2139 {
2140 name = genericGetName(isSgAdaTaskSpecDecl(declaration));
2141 break;
2142 }
2143
2144 case V_SgAdaProtectedSpecDecl:
2145 {
2146 name = genericGetName(isSgAdaProtectedSpecDecl(declaration));
2147 break;
2148 }
2149
2150 case V_SgAdaGenericInstanceDecl:
2151 {
2152 name = genericGetName(isSgAdaGenericInstanceDecl(declaration));
2153 break;
2154 }
2155
2156 case V_SgAdaFormalPackageDecl:
2157 {
2158 name = genericGetName(isSgAdaFormalPackageDecl(declaration));
2159 break;
2160 }
2161
2162 case V_SgAdaParameterList:
2163 {
2164 const SgAdaParameterList* plst = isSgAdaParameterList(declaration);
2165 ROSE_ASSERT(plst);
2166
2167 name = std::accumulate( plst->get_parameters().begin(), plst->get_parameters().end(),
2168 std::string{"_ada_parameter_list_"},
2169 [](std::string n, SgDeclarationStatement* rhs) -> std::string
2170 {
2171 n += SageInterface::get_name(rhs);
2172 return n;
2173 }
2174 );
2175 break;
2176 }
2177
2178 // Note that the case for SgVariableDeclaration is not implemented
2179 default:
2180 printf ("Warning: default case reached in SageInterface::get_name ( const SgDeclarationStatement* declaration ), declaration = %p = %s \n",
2181 declaration,declaration->class_name().c_str());
2182 ROSE_ABORT();
2183 }
2184
2185 return name;
2186 }
2187
2188string
2190 {
2191 string name = "undefined_name";
2192
2193 ROSE_ASSERT(scope != NULL);
2194
2195 switch (scope->variantT())
2196 {
2197 // DQ (6/11/2011): Added support for new template IR nodes.
2198 case V_SgTemplateClassDefinition:
2199 name = get_name(isSgTemplateClassDefinition(scope)->get_declaration());
2200 break;
2201
2202 case V_SgClassDefinition:
2203 case V_SgTemplateInstantiationDefn:
2204 name = get_name(isSgClassDefinition(scope)->get_declaration());
2205 break;
2206
2207 // DQ (9/8/2012): Added missing case for SgTemplateFunctionDefinition.
2208 case V_SgTemplateFunctionDefinition:
2209 case V_SgFunctionDefinition:
2210 name = get_name(isSgFunctionDefinition(scope)->get_declaration());
2211 break;
2212
2213 case V_SgNamespaceDefinitionStatement:
2214 name = get_name(isSgNamespaceDefinitionStatement(scope)->get_namespaceDeclaration());
2215 break;
2216 case V_SgJavaLabelStatement:
2217 name = (isSgJavaLabelStatement(scope)->get_label()).getString();
2218 break;
2219
2220 // DQ (7/18/2017): Added support for the new declaration scope.
2221 case V_SgDeclarationScope:
2222
2223 // DQ (11/30/2007): Added more fortran support.
2224 case V_SgAssociateStatement:
2225 case V_SgJavaForEachStatement:
2226
2227 case V_SgFunctionParameterScope:
2228 case V_SgAdaPackageSpec:
2229 case V_SgAdaPackageBody:
2230 case V_SgAdaTaskSpec:
2231 case V_SgAdaTaskBody:
2232 case V_SgAdaProtectedSpec:
2233 case V_SgAdaProtectedBody:
2234 case V_SgAdaGenericDefn:
2235 case V_SgAdaAcceptStmt:
2236 case V_SgJovialForThenStatement: //Rasmussen: Jovial for statement
2237 case V_SgMatlabForStatement: //SK: Matlab for statement
2238 case V_SgBasicBlock:
2239 case V_SgCatchOptionStmt:
2240 case V_SgDoWhileStmt:
2241 case V_SgForStatement:
2242 case V_SgGlobal:
2243 case V_SgIfStmt:
2244 case V_SgSwitchStatement:
2245 case V_SgWhileStmt:
2246 case V_SgFortranDo:
2247 case V_SgForAllStatement:
2248 case V_SgRangeBasedForStatement:
2249 name = StringUtility::numberToString(const_cast<SgScopeStatement*>(scope));
2250 break;
2251
2252 default:
2253 printf ("Error: undefined case (SgScopeStatement) in SageInterface::get_name(): node = %s \n",scope->class_name().c_str());
2254 ROSE_ABORT();
2255 }
2256
2257 return name;
2258 }
2259
2260string
2262 {
2263 string name = "undefined_name";
2264
2265 ROSE_ASSERT(stmt != NULL);
2266
2267 const SgDeclarationStatement* declaration = isSgDeclarationStatement(stmt);
2268 if (declaration != NULL)
2269 {
2270 name = get_name(declaration);
2271 }
2272 else
2273 {
2274 const SgScopeStatement* scope = isSgScopeStatement(stmt);
2275 if (scope != NULL)
2276 {
2277 name = get_name(scope);
2278 }
2279 else
2280 {
2281 // DQ (10/25/2007): This is better since it names the SgLabelStatement case
2282 switch (stmt->variantT())
2283 {
2284#if 0
2285 case V_SgBreakStmt:
2286 case V_SgCaseOptionStmt:
2287 case V_SgCatchStatementSeq:
2288 case V_SgClinkageStartStatement:
2289 case V_SgContinueStmt:
2290 case V_SgDefaultOptionStmt:
2291 case V_SgExprStmt:
2292 case V_SgForInitStmt:
2293 case V_SgFunctionTypeTable:
2294 case V_SgGotoStatement:
2295 case V_SgReturnStmt:
2296 case V_SgSpawnStmt:
2297 case V_SgTryStmt:
2298 name = stmt->class_name();
2299 break;
2300#endif
2301 case V_SgLabelStatement:
2302 {
2303 const SgLabelStatement* labelStatement = isSgLabelStatement(stmt);
2304 name = labelStatement->get_label().str();
2305 break;
2306 }
2307
2308 default:
2309 {
2310 // printf ("Default reached in switch \n");
2311 // name = "default name";
2312 name = stmt->class_name();
2313 break;
2314 }
2315 }
2316 }
2317 }
2318
2319 return name;
2320 }
2321
2322string
2324 {
2325 // This function is useful for debugging
2326 // This is the most general case of a function to return a name for an IR node.
2327 ROSE_ASSERT(node != NULL);
2328
2329 string name = "undefined_name";
2330
2331 ROSE_ASSERT(node != NULL);
2332
2333 switch (node->variantT())
2334 {
2335 case V_SgInitializedName:
2336 {
2337 const SgInitializedName* initializedName = isSgInitializedName(node);
2338 if (initializedName != NULL)
2339 {
2340 name = initializedName->get_name().str();
2341 }
2342 break;
2343 }
2344#if 1
2345 // DQ (3/17/2006): Implemented case for pragma declaration (forgot this case)
2346 case V_SgPragma:
2347 {
2348 name = "_pragma_string_";
2349 const SgPragma* pragma = isSgPragma(node);
2350 ROSE_ASSERT(pragma != NULL);
2351 name += pragma->get_pragma();
2352 break;
2353 }
2354#endif
2355
2356 // DQ (5/31/2007): Implemented case for SgProject
2357 case V_SgProject:
2358 {
2359 name = "_project_";
2360 break;
2361 }
2362
2363 // DQ (5/31/2007): Implemented case for SgFile
2364 // case V_SgFile:
2365 case V_SgSourceFile:
2366#ifdef ROSE_ENABLE_BINARY_ANALYSIS
2367 case V_SgBinaryComposite:
2368#endif
2369 {
2370 name = "_file_";
2371
2372 // DQ (3/1/2009): Added support to include the file name.
2373 const SgFile* file = isSgFile(node);
2374 ROSE_ASSERT(file != NULL);
2375
2376 name += file->getFileName();
2377 break;
2378 }
2379
2380 // DQ (5/31/2007): Implemented case for SgSymbolTable
2381 case V_SgSymbolTable:
2382 {
2383 name = "_symbol_table_";
2384 break;
2385 }
2386
2387 // DQ (5/31/2007): Implemented case for SgStorageModifier
2388 case V_SgStorageModifier:
2389 {
2390 name = "_storage_modifier_";
2391 break;
2392 }
2393
2394
2395 // DQ (5/31/2007): Implemented case for Sg_File_Info
2396 case V_Sg_File_Info:
2397 {
2398 name = "_file_info_";
2399 break;
2400 }
2401
2402 // DQ (8/7/2007): Implemented case for SgTemplateArgument
2403 case V_SgTemplateArgument:
2404 {
2405 name = "_template_argument_";
2406 const SgTemplateArgument* templateArgument = isSgTemplateArgument(node);
2407 ROSE_ASSERT(templateArgument != NULL);
2408 switch(templateArgument->get_argumentType())
2409 {
2411 {
2412 SgType* t = templateArgument->get_type();
2413 ROSE_ASSERT(t != NULL);
2414 name += get_name(t);
2415 break;
2416 }
2417
2419 {
2420 SgExpression* t = templateArgument->get_expression();
2421
2422 // DQ (8/11/2013): Adding support for including an initializedName instead of an expression (for template parameters used as expressions).
2423 // ROSE_ASSERT(t != NULL);
2424 // name += get_name(t);
2425 if (t != NULL)
2426 {
2427 ROSE_ASSERT(templateArgument->get_initializedName() == NULL);
2428 name += get_name(t);
2429 }
2430 else
2431 {
2432 ROSE_ASSERT(t == NULL);
2433 SgInitializedName* initializedName = templateArgument->get_initializedName();
2434 ROSE_ASSERT(initializedName != NULL);
2435
2436 name += get_name(initializedName);
2437 }
2438 break;
2439 }
2440
2442 {
2443 // SgTemplateDeclaration* t = templateArgument->get_templateDeclaration();
2444 SgDeclarationStatement* t = templateArgument->get_templateDeclaration();
2445 ROSE_ASSERT(t != NULL);
2446 name += get_name(t);
2447 break;
2448 }
2449
2450 default:
2451 {
2452 printf ("Error: default case reached in switch on templateArgument->get_argumentType() \n");
2453 ROSE_ABORT();
2454 }
2455 }
2456 break;
2457 }
2458
2459
2460 // DQ (8/7/2007): Implemented case for SgTemplateArgument
2461 case V_SgTypeModifier:
2462 {
2463 const SgTypeModifier* typeModifier = isSgTypeModifier(node);
2464 ROSE_ASSERT(typeModifier != NULL);
2465 name = "_type_modifier_" + typeModifier->displayString();
2466 break;
2467 }
2468
2469 // DQ (11/19/2007): Implemented case for SgNameGroup
2470 case V_SgNameGroup:
2471 {
2472 const SgNameGroup* nameGroup = isSgNameGroup(node);
2473 ROSE_ASSERT(nameGroup != NULL);
2474 name = "_name_group_" + nameGroup->get_group_name();
2475 break;
2476 }
2477
2478 // DQ (11/20/2007): Implemented case for Fortran data statement support
2479 case V_SgDataStatementGroup:
2480 {
2481 const SgDataStatementGroup* dataGroup = isSgDataStatementGroup(node);
2482 ROSE_ASSERT(dataGroup != NULL);
2483 name = "_data_statement_group_";
2484 break;
2485 }
2486
2487 // DQ (11/20/2007): Implemented case for Fortran data statement support
2488 case V_SgDataStatementObject:
2489 {
2490 const SgDataStatementObject* dataObject = isSgDataStatementObject(node);
2491 ROSE_ASSERT(dataObject != NULL);
2492 name = "_data_statement_object_";
2493 break;
2494 }
2495
2496 // DQ (11/20/2007): Implemented case for Fortran data statement support
2497 case V_SgDataStatementValue:
2498 {
2499 const SgDataStatementValue* dataValue = isSgDataStatementValue(node);
2500 ROSE_ASSERT(dataValue != NULL);
2501 name = "_data_statement_value_";
2502 break;
2503 }
2504
2505 // DQ (11/19/2007): Implemented case for SgCommonBlock
2506 case V_SgCommonBlockObject:
2507 {
2508 const SgCommonBlockObject* commonBlockObject = isSgCommonBlockObject(node);
2509 ROSE_ASSERT(commonBlockObject != NULL);
2510 name = "_common_block_object_" + commonBlockObject->get_block_name();
2511 break;
2512 }
2513
2514 // DQ (12/23/2007): Added support for repeat_specification
2515 case V_SgFormatItem:
2516 {
2517 const SgFormatItem* formatItem = isSgFormatItem(node);
2518 ROSE_ASSERT(formatItem != NULL);
2519 name = "_format_item_";
2520 break;
2521 }
2522
2523 // DQ (12/23/2007): Added support for repeat_specification
2524 case V_SgFormatItemList:
2525 {
2526 const SgFormatItemList* formatItemList = isSgFormatItemList(node);
2527 ROSE_ASSERT(formatItemList != NULL);
2528 name = "_format_item_list_";
2529 break;
2530 }
2531
2532 // DQ (12/23/2007): Added support for repeat_specification
2533 case V_SgRenamePair:
2534 {
2535 const SgRenamePair* renamePair = isSgRenamePair(node);
2536 ROSE_ASSERT(renamePair != NULL);
2537 name = renamePair->get_local_name() + "__" + renamePair->get_use_name() + "_rename_pair_";
2538 break;
2539 }
2540
2541 // DQ (12/2/2010): Implemented case for SgName
2542 case V_SgName:
2543 {
2544 const SgName* name_node = isSgName(node);
2545 ROSE_ASSERT(name_node != NULL);
2546 name = "_name_" + name_node->getString();
2547 break;
2548 }
2549
2550 // DQ (8/8/2013): Implemented case for SgTemplateParameter
2551 case V_SgTemplateParameter:
2552 {
2553 const SgTemplateParameter* template_parameter_node = isSgTemplateParameter(node);
2554 ROSE_ASSERT(template_parameter_node != NULL);
2555 name = "_template_parameter_";
2556
2557 switch(template_parameter_node->get_parameterType())
2558 {
2560 {
2561 name += "type_parameter_";
2562 break;
2563 }
2564
2566 {
2567 name += "nontype_parameter_";
2568#if 1
2569 name += template_parameter_node->unparseToString();
2570#else
2571 if (template_parameter_node->get_expression() != NULL)
2572 {
2573 name += template_parameter_node->get_expression()->unparseToString();
2574 }
2575 else
2576 {
2577 ROSE_ASSERT(template_parameter_node->get_initializedName() != NULL);
2578
2579 // DQ (8/8/2013): This does not handle the case of "template <void (foo::*M)()> void test() {}"
2580 // since what is unparsed is: "_template_parameter_nontype_parameter_M"
2581 // instead of a string to represent what is in "void (foo::*M)()"
2582 // and differentiate it from: "int foo::*M" in: "template <void (foo::*M)()> void test() {}"
2583 name += template_parameter_node->get_initializedName()->unparseToString();
2584 }
2585#endif
2586 break;
2587 }
2588
2590 {
2591 name += "template_parameter_";
2592 break;
2593 }
2594
2595 default:
2596 {
2597 printf ("Error: default reached \n");
2598 ROSE_ABORT();
2599 }
2600 }
2601 break;
2602 }
2603
2604 // DQ (1/21/2019): Implemented case for SgBaseClass
2605 case V_SgBaseClass:
2606 {
2607 const SgBaseClass* base_class_node = isSgBaseClass(node);
2608 ROSE_ASSERT(base_class_node != NULL);
2609 ROSE_ASSERT(base_class_node->get_base_class() != NULL);
2610
2611 // Add the access modifier to the output.
2612 string access = "";
2613 const SgBaseClassModifier* baseClassModifier = base_class_node->get_baseClassModifier();
2614 ROSE_ASSERT(baseClassModifier != NULL);
2615 access = baseClassModifier->displayString();
2616
2617 name = "_base_class_" + access + "_" + get_name(base_class_node->get_base_class());
2618 break;
2619 }
2620
2621 default:
2622 {
2623 printf ("Default reached in switch for SgSupport IR node = %s \n",node->class_name().c_str());
2624 name = "default name";
2625 // ROSE_ASSERT(false);
2626 break;
2627 }
2628 }
2629
2630 return name;
2631 }
2632
2633
2634string
2636 {
2637 // This function is useful for debugging
2638 // This is the most general case of a function to return a name for an IR node.
2639 ROSE_ASSERT(symbol != NULL);
2640
2641 string aliasSymbolPrefix = "";
2642 if (isSgAliasSymbol(symbol) != NULL)
2643 {
2644 aliasSymbolPrefix = "_ALIAS";
2645 }
2646
2647 // printf ("In SageInterface::get_name(): symbol->get_symbol_basis() = %p = %s \n",symbol->get_symbol_basis(),symbol->get_symbol_basis()->class_name().c_str());
2648 // printf ("In SageInterface::get_name(): symbol->get_declaration() = %p = %s \n",symbol->get_declaration(),symbol->get_declaration()->class_name().c_str());
2649
2650 // This is a call to the "get_name()" virtual function
2651 return symbol->get_name() + aliasSymbolPrefix + "_symbol_";
2652 }
2653
2654string
2656 {
2657 // This function is useful for debugging
2658 // This is the most general case of a function to return a name for an IR node.
2659 ROSE_ASSERT(type != NULL);
2660
2661 string returnName;
2662
2663 const SgNamedType* namedType = isSgNamedType(type);
2664 if (namedType != NULL)
2665 {
2666 returnName = "named_type_";
2667 returnName = namedType->get_name().getString();
2668 }
2669 else
2670 {
2671 switch(type->variantT())
2672 {
2673 case V_SgPointerType:
2674 {
2675 const SgPointerType* pointerType = isSgPointerType(type);
2676 returnName = "pointer_to_";
2677 returnName += get_name(pointerType->get_base_type());
2678 break;
2679 }
2680
2681 case V_SgReferenceType:
2682 {
2683 const SgReferenceType* referenceType = isSgReferenceType(type);
2684 returnName = "reference_to_";
2685 returnName += get_name(referenceType->get_base_type());
2686 break;
2687 }
2688
2689 case V_SgArrayType:
2690 {
2691 const SgArrayType* arrayType = isSgArrayType(type);
2692 returnName = "array_of_";
2693 returnName += get_name(arrayType->get_base_type());
2694 break;
2695 }
2696
2697 case V_SgModifierType:
2698 {
2699 const SgModifierType* modifierType = isSgModifierType(type);
2700 returnName = get_name(&(modifierType->get_typeModifier()));
2701 returnName += get_name(modifierType->get_base_type());
2702 break;
2703 }
2704
2705 // DQ (8/26/2012): Added case to support template declaration work.
2706 case V_SgTemplateType:
2707 {
2708 const SgTemplateType* templateType = isSgTemplateType(type);
2709 returnName = "templateType_";
2710 returnName += templateType->get_name();
2711 break;
2712 }
2713
2714 default:
2715 {
2716 returnName = type->class_name();
2717 }
2718 }
2719 }
2720
2721 return returnName;
2722 }
2723
2724string
2726 {
2727 string name = "undefined_name";
2728
2729 // ROSE_ASSERT(expr != NULL);
2730 switch(expr->variantT())
2731 {
2732 case V_SgVarRefExp:
2733 {
2734 const SgVarRefExp* varRef = isSgVarRefExp(expr);
2735 name = "var_ref_of_";
2736 ROSE_ASSERT(varRef != NULL);
2737 ROSE_ASSERT(varRef->get_symbol() != NULL);
2738 name += varRef->get_symbol()->get_name();
2739 break;
2740 }
2741
2742 // DQ (2/2/2011): Added case to support fortran use of label references in alternate return parameters.
2743 case V_SgLabelRefExp:
2744 {
2745 const SgLabelRefExp* labelRef = isSgLabelRefExp(expr);
2746 name = "label_ref_of_";
2747 ROSE_ASSERT(labelRef != NULL);
2748 ROSE_ASSERT(labelRef->get_symbol() != NULL);
2749 name += labelRef->get_symbol()->get_name();
2750 break;
2751 }
2752
2753 case V_SgPntrArrRefExp:
2754 {
2755 const SgPntrArrRefExp* arrayRef = isSgPntrArrRefExp(expr);
2756 name = "array_ref_of_";
2757 name += get_name(arrayRef->get_lhs_operand());
2758 name += "_at_";
2759 name += get_name(arrayRef->get_rhs_operand());
2760 break;
2761 }
2762
2763 case V_SgFunctionCallExp:
2764 {
2765 const SgFunctionCallExp* functionCall = isSgFunctionCallExp(expr);
2766 name = "function_call_";
2767 name += get_name(functionCall->get_function());
2768 break;
2769 }
2770
2771 case V_SgFunctionRefExp:
2772 {
2773 const SgFunctionRefExp* functionRefExp = isSgFunctionRefExp(expr);
2774 name = "function_ref_";
2775 name += functionRefExp->get_symbol()->get_name();
2776 break;
2777 }
2778
2779 // DQ (4/19/2013): Added support for SgMemberFunctionRefExp.
2780 case V_SgMemberFunctionRefExp:
2781 {
2782 const SgMemberFunctionRefExp* memberFunctionRefExp = isSgMemberFunctionRefExp(expr);
2783 name = "member_function_ref_";
2784 name += memberFunctionRefExp->get_symbol()->get_name();
2785 break;
2786 }
2787
2788 case V_SgIntVal:
2789 {
2790 const SgIntVal* valueExp = isSgIntVal(expr);
2791 name = "integer_value_exp_";
2792 name += StringUtility::numberToString(valueExp->get_value());
2793 break;
2794 }
2795
2796 case V_SgStringVal:
2797 {
2798 const SgStringVal* valueExp = isSgStringVal(expr);
2799 name = "string_value_exp_";
2800 name += valueExp->get_value();
2801 break;
2802 }
2803
2804 case V_SgSubscriptExpression:
2805 {
2806 const SgSubscriptExpression* subscriptExpression = isSgSubscriptExpression(expr);
2807 name = "subscript_exp_";
2808 // name += StringUtility::numberToString(subscriptExpression->get_lowerBound());
2809 name += get_name(subscriptExpression->get_lowerBound());
2810 name += "_";
2811 // name += StringUtility::numberToString(subscriptExpression->get_upperBound());
2812 name += get_name(subscriptExpression->get_upperBound());
2813 name += "_";
2814 // name += StringUtility::numberToString(subscriptExpression->get_stride());
2815 name += get_name(subscriptExpression->get_stride());
2816 break;
2817 }
2818
2819 case V_SgNullExpression:
2820 {
2821 name = "null_expression";
2822 break;
2823 }
2824
2825 // DQ (1/17/2011): Added support for SgExprListExp (to support debugging).
2826 case V_SgExprListExp:
2827 {
2828 const SgExprListExp* exprListExp = isSgExprListExp(expr);
2829 name = "expr_list_exp_";
2830 for (size_t i = 0; i < exprListExp->get_expressions().size(); i++)
2831 {
2832 name += get_name(exprListExp->get_expressions()[i]);
2833 }
2834 break;
2835 }
2836
2837 // DQ (1/31/2011): Added to support Fortran debugging.
2838 case V_SgActualArgumentExpression:
2839 {
2840 const SgActualArgumentExpression* actualArgExp = isSgActualArgumentExpression(expr);
2841 name = "actual_arg_exp_name_";
2842 name += actualArgExp->get_argument_name();
2843 name = "_exp_";
2844 name += get_name(actualArgExp->get_expression());
2845 break;
2846 }
2847
2848 // DQ (7/25/2012): Added support for new template IR nodes.
2849 case V_SgTemplateParameterVal:
2850 {
2851 const SgTemplateParameterVal* valueExp = isSgTemplateParameterVal(expr);
2852 name = "template_parameter_value_expression_number_";
2853 // name += valueExp->get_value();
2854 // name += get_name(valueExp);
2855 name += StringUtility::numberToString(valueExp->get_template_parameter_position());
2856 break;
2857 }
2858
2859 // DQ (4/19/2013): Added support for SgDotExp.
2860 case V_SgDotExp:
2861 {
2862 const SgDotExp* dotExp = isSgDotExp(expr);
2863 ROSE_ASSERT(dotExp != NULL);
2864
2865 name = "_dot_exp_lhs_";
2866 name += get_name(dotExp->get_lhs_operand());
2867 name += "_dot_exp_rhs_";
2868 name += get_name(dotExp->get_rhs_operand());
2869 // name += StringUtility::numberToString(valueExp->get_template_parameter_position());
2870 break;
2871 }
2872
2873 // DQ (9/3/2014): Added support for C++11 lambda expressions.
2874 case V_SgLambdaExp:
2875 {
2876 const SgLambdaExp* lambdaExp = isSgLambdaExp(expr);
2877 ROSE_ASSERT (lambdaExp != NULL);
2878 name = "lambda_expression_";
2879 break;
2880 }
2881
2882 // DQ (1/3/2020): Added support for SgThisExp.
2883 case V_SgThisExp:
2884 {
2885 const SgThisExp* thisExp = isSgThisExp(expr);
2886 ROSE_ASSERT(thisExp != NULL);
2887
2888 name = "_this_exp_for_";
2889
2890 SgClassSymbol* classSymbol = thisExp->get_class_symbol();
2891 ROSE_ASSERT(classSymbol != NULL);
2892 // name += get_name(classSymbol->get_name());
2893 // string class_name = classSymbol->get_name();
2894 // name += class_name;
2895 name += classSymbol->get_name();
2896 break;
2897 }
2898
2899 default:
2900 {
2901 // Nothing to do for other IR nodes
2902#if 0
2903 // DQ (7/25/2012): Make this an error.
2904 printf ("Note: default reached in get_name() expr = %p = %s \n",expr,expr->class_name().c_str());
2905 ROSE_ABORT();
2906#endif
2907 // DQ (4/8/2010): define something specific to this function to make debugging more clear.
2908 // printf ("Note: default reached in get_name() expr = %p = %s \n",expr,expr->class_name().c_str());
2909 // name = "undefined_expression_name";
2910 name = expr->class_name() + "_undef_name";
2911 break;
2912 }
2913 }
2914
2915 return name;
2916 }
2917
2918string
2920 {
2921 // This function is useful for debugging
2922 // This is the most general case of a function to return a name for an IR node.
2923 ROSE_ASSERT(node != NULL);
2924
2925 string returnName;
2926
2927 switch(node->variantT())
2928 {
2929 case V_SgRenamePair:
2930 {
2931 const SgRenamePair* n = isSgRenamePair(node);
2932 returnName = "rename_pair_";
2933 returnName += n->get_local_name().str();
2934 returnName += "_from_";
2935 returnName += n->get_use_name().str();
2936 break;
2937 }
2938
2939 case V_SgInitializedName:
2940 {
2941 const SgInitializedName* n = isSgInitializedName(node);
2942 ROSE_ASSERT (n != NULL);
2943 returnName = "initialized_name_";
2944 returnName += n->get_name().str();
2945 break;
2946 }
2947
2948 // DQ (9/3/2014): Added support for C++11 lambda expressions.
2949 case V_SgLambdaCapture:
2950 {
2951 const SgLambdaCapture* n = isSgLambdaCapture(node);
2952 ROSE_ASSERT (n != NULL);
2953 returnName = "lambda_capture_";
2954 // returnName += n->get_name().str();
2955 break;
2956 }
2957
2958#if 0
2959 case V_SgInterfaceBody:
2960 {
2961 const SgInterfaceBody* n = isSgInterfaceBody(node);
2962 returnName = "interface_body";
2963 break;
2964 }
2965#endif
2966 default:
2967 {
2968 returnName = node->class_name();
2969 }
2970 }
2971
2972 return returnName;
2973 }
2974
2975string
2977 {
2978 // This function is useful for debugging
2979 // This is the most general case of a function to return a name for an IR node.
2980 // Later this function will handle expressions, etc.
2981
2982 string name = "undefined_name";
2983
2984 ROSE_ASSERT(node != NULL);
2985
2986 const SgLocatedNode* locatedNode = isSgLocatedNode(node);
2987 if (locatedNode != NULL)
2988 {
2989 const SgStatement* statement = isSgStatement(node);
2990 if (statement != NULL)
2991 {
2992 name = get_name(statement);
2993 }
2994 else
2995 {
2996 const SgExpression* expression = isSgExpression(node);
2997 if (expression != NULL)
2998 {
2999 name = get_name(expression);
3000 }
3001 else
3002 {
3003 const SgLocatedNodeSupport* locatedNodeSupport = isSgLocatedNodeSupport(node);
3004 if (locatedNodeSupport != NULL)
3005 {
3006 name = get_name(locatedNodeSupport);
3007 }
3008 else
3009 {
3010 const SgToken* token = isSgToken(node);
3011 if (token != NULL)
3012 {
3013 name = get_name(token);
3014 }
3015 else
3016 {
3017 printf ("Unknown SgLocatedNode = %p = %s \n",node,node->class_name().c_str());
3018 ROSE_ABORT();
3019 }
3020 }
3021 }
3022 }
3023 }
3024 else
3025 {
3026 const SgSupport* supportNode = isSgSupport(node);
3027 if (supportNode != NULL)
3028 {
3029 name = get_name(supportNode);
3030 }
3031 else
3032 {
3033 // DQ (9/21/2005): I think this is good enough for the more general case (for now)
3034 const SgSymbol* symbol = isSgSymbol(node);
3035 if (symbol != NULL)
3036 {
3037 name = get_name(symbol);
3038 }
3039 else
3040 {
3041 // DQ (8/7/2007): Added support to get names of types (usefult for SgNamedType objects).
3042 const SgType* type = isSgType(node);
3043 if (type != NULL)
3044 {
3045 name = get_name(type);
3046 }
3047 else
3048 {
3049 name = node->class_name();
3050 }
3051 }
3052 }
3053 }
3054
3055 return name;
3056 }
3057
3058
3059string
3061 {
3062 // This function is useful for debugging
3063 string name = "undefined_name";
3064
3065 ROSE_ASSERT(token != NULL);
3066 name = token->get_lexeme_string();
3067
3068 // Handle special cases
3069 if (name == " ")
3070 name = "<space>";
3071 else if (name == "\n")
3072 name = "<eol>";
3073 else if (name == "\t")
3074 name = "<tab>";
3075
3076 return name;
3077 }
3078
3079
3080void
3087
3088
3089string
3091 {
3092 // DQ (3/20/2016): Adding support for generating a unique name from a declaration that
3093 // can be used as an identifier. This functionality is used in the DSL infrastructure
3094 // support (refactored to this location in ROSE). The point of this mechanism is that
3095 // unlike mangled names that are compressed in a way that allows them to only be used
3096 // within a single translation unit, names generated by this function can be used across
3097 // multiple translation units. These names are also easier to interprete in debugging
3098 // (since they explicitly contain the scope, function name, and coding to interprete
3099 // function overloading.
3100
3101 // At present it only supports class declarations, and function declarations (all others
3102 // are trapped as errors).
3103
3104 // Name collision testing, it might be that this should be external to this function.
3105 // static std::map<std::string,int> dsl_attribute_name_collision_map;
3106 // static std::map<std::string,int> local_name_collision_map;
3107
3108 string s;
3109
3110 // string scope = SageInterface::get_name(classDeclaration->get_scope());
3111 string scope = isSgGlobal(declaration->get_scope()) == NULL ? SageInterface::get_name(declaration->get_scope()) : "global";
3112
3113 switch (declaration->variantT())
3114 {
3115 case V_SgClassDeclaration:
3116 case V_SgTemplateClassDeclaration:
3117 // case V_SgTemplateInstantiationDecl:
3118 {
3119 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
3120 ROSE_ASSERT(classDeclaration != NULL);
3121
3122 string type_name = classDeclaration->get_name();
3123#if 0
3124 printf ("In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case class or template type: type_name = %s \n",type_name.c_str());
3125#endif
3126 string className = string("scope_") + scope + "_type_name_" + type_name;
3127#if 0
3128 printf ("classDeclaration->get_scope() = %p = %s scope = %s \n",classDeclaration->get_scope(),classDeclaration->get_scope()->class_name().c_str(),scope.c_str());
3129#endif
3130 s = className;
3131 break;
3132 }
3133
3134 // DQ (3/29/2016): Seperate out the case of the SgTemplateInstantiationDecl.
3135 case V_SgTemplateInstantiationDecl:
3136 {
3137 SgTemplateInstantiationDecl* templateInstantiationDeclaration = isSgTemplateInstantiationDecl(declaration);
3138 ROSE_ASSERT(templateInstantiationDeclaration != NULL);
3139
3140 // Note that we can't use the mangled name because they might not be unique across multiple translation units if seperately compiled).
3141 // string type_name = templateInstantiationDeclaration->get_name();
3142 // string type_name = templateInstantiationDeclaration->get_mangled_name();
3143 // string type_name = templateInstantiationDeclaration->get_templateName();
3144 string type_name = templateInstantiationDeclaration->get_name();
3145#if 0
3146 printf ("In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case SgTemplateInstantiationDecl: type_name = %s \n",type_name.c_str());
3147#endif
3148 string className = string("scope_") + scope + "_type_name_" + type_name;
3149
3150 // Note that trimSpaces is defined in the name mangling support.
3151 // string compressedClassName = trimSpaces(className);
3152 // string compressedClassName = SageInterface::get_name(templateInstantiationDeclaration);
3153 // ROSE_UTIL_API std::string copyEdit(const std::string& inputString, const std::string & oldToken, const std::string & newToken);
3154
3155 // We need to turn this template instatiation name into a name that can be used as a C++ identifier.
3156 string compressedClassName = StringUtility::copyEdit(className," ","");
3157 compressedClassName = StringUtility::copyEdit(compressedClassName,"<","_abs_");
3158 compressedClassName = StringUtility::copyEdit(compressedClassName,">","_abe_");
3159 compressedClassName = StringUtility::copyEdit(compressedClassName,",","_comma_");
3160 compressedClassName = StringUtility::copyEdit(compressedClassName,"*","_star_");
3161 compressedClassName = StringUtility::copyEdit(compressedClassName,"&","_ref_");
3162#if 0
3163 printf ("className = %s compressedClassName = %s \n",className.c_str(),compressedClassName.c_str());
3164#endif
3165#if 0
3166 printf ("templateInstantiationDeclaration->get_scope() = %p = %s scope = %s \n",
3167 templateInstantiationDeclaration->get_scope(),templateInstantiationDeclaration->get_scope()->class_name().c_str(),scope.c_str());
3168#endif
3169 // s = className;
3170 s = compressedClassName;
3171#if 0
3172 printf ("Exiting as a test! \n");
3173 ROSE_ABORT();
3174#endif
3175 break;
3176 }
3177
3178 case V_SgFunctionDeclaration:
3179 case V_SgTemplateFunctionDeclaration:
3180 case V_SgTemplateInstantiationFunctionDecl:
3181 {
3182 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(declaration);
3183 ROSE_ASSERT(functionDeclaration != NULL);
3184#if 0
3185 printf ("In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case SgFunctionDeclaration: not implemented \n");
3186#endif
3187 // We might at some point want the qualified name.
3188 string original_name = functionDeclaration->get_name();
3189
3190 string function_name_part = mangleFunctionName(original_name,"return_type");
3191 string function_name = string("scope_") + scope + "_function_name_" + function_name_part;
3192
3193 // DQ (3/16/2016): Detect name collisions so that we can
3194 // std::map<std::string,int> dsl_attribute_name_collision_map;
3195 if (local_name_collision_map.find(function_name) == local_name_collision_map.end())
3196 {
3197 local_name_collision_map.insert(pair<string,int>(function_name,0));
3198 }
3199 else
3200 {
3201 local_name_collision_map[function_name]++;
3202
3203 int count = local_name_collision_map[function_name];
3204#if 0
3205 printf ("In SageInterface::generateUniqueNameForUseAsIdentifier(): Collision count = %d \n",count);
3206#endif
3207 function_name += StringUtility::numberToString(count);
3208 }
3209
3210 s = function_name;
3211#if 0
3212 printf ("In SageInterface::generateUniqueNameForUseAsIdentifier(): case SgFunctionDeclaration: Exiting as a test! \n");
3213 ROSE_ABORT();
3214#endif
3215 break;
3216 }
3217
3218 case V_SgMemberFunctionDeclaration:
3219 case V_SgTemplateMemberFunctionDeclaration:
3220 case V_SgTemplateInstantiationMemberFunctionDecl:
3221 {
3222 SgMemberFunctionDeclaration* memberFunctionDeclaration = isSgMemberFunctionDeclaration(declaration);
3223 ROSE_ASSERT(memberFunctionDeclaration != NULL);
3224#if 0
3225 printf ("In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case SgMemberFunctionDeclaration: not implemented \n");
3226#endif
3227 // We might at some point want the qualified name.
3228 string original_name = memberFunctionDeclaration->get_name();
3229
3230 // string member_function_name = memberFunctionDeclaration->get_mangled_name();
3231 // string member_function_name = memberFunctionDeclaration->get_qualified_name();
3232 // string member_function_name = SageInterface::get_name(memberFunctionDeclaration);
3233 // string member_function_scope = SageInterface::get_name(memberFunctionDeclaration->get_scope());
3234 string member_function_name_part = mangleFunctionName(original_name,"return_type");
3235 // string member_function_name = string("scope_") + member_function_scope + "_function_name_" + member_function_name_part;
3236 string member_function_name = string("scope_") + scope + "_member_function_name_" + member_function_name_part;
3237
3238 // DQ (3/16/2016): Detect name collisions so that we can
3239 // std::map<std::string,int> dsl_attribute_name_collision_map;
3240 if (local_name_collision_map.find(member_function_name) == local_name_collision_map.end())
3241 {
3242 local_name_collision_map.insert(pair<string,int>(member_function_name,0));
3243 }
3244 else
3245 {
3246 local_name_collision_map[member_function_name]++;
3247
3248 int count = local_name_collision_map[member_function_name];
3249#if 0
3250 printf ("In SageInterface::generateUniqueNameForUseAsIdentifier(): Collision count = %d \n",count);
3251#endif
3252 member_function_name += StringUtility::numberToString(count);
3253 }
3254
3255 s = member_function_name;
3256#if 0
3257 printf ("In SageInterface::generateUniqueNameForUseAsIdentifier(): case SgMemberFunctionDeclaration: Exiting as a test! \n");
3258 ROSE_ABORT();
3259#endif
3260 break;
3261 }
3262
3263 default:
3264 {
3265 printf ("In SageInterface::generateUniqueNameForUseAsIdentifier(): Unsupported declaration = %p = %s \n",declaration,declaration->class_name().c_str());
3266// ROSE_ASSERT(false);
3267 }
3268 }
3269
3270#if 0
3271 printf ("In SageInterface::generateUniqueNameForUseAsIdentifier(): s = %s \n",s.c_str());
3272#endif
3273#if 0
3274 if (s != "")
3275 {
3276 printf ("In SageInterface::generateUniqueNameForUseAsIdentifier(): s = %s \n",s.c_str());
3277 }
3278#endif
3279
3280#if 0
3281 printf ("Exiting as a test! \n");
3282 ROSE_ABORT();
3283#endif
3284
3285 return s;
3286 }
3287
3288// Generate unique name for use as a class name for the generated attribute classes.
3289// std::string AttributeGeneratorTraversal::generateUniqueNameForUseAsIdentifier ( SgDeclarationStatement* declaration )
3290// std::string AttributeGeneratorTraversal::generateUniqueName ( SgDeclarationStatement* declaration )
3291std::string
3293 {
3294 // DQ (3/21/2016): The support for unique name generation for use across translation
3295 // units is not refactored into the SageInterface.
3296 // string s = SageInterface::generateUniqueNameForUseAsIdentifier(declaration);
3297 string s;
3298
3299#if 0
3300 printf ("In generateUniqueNameForUseAsIdentifier(): evaluating declaration = %p = %s \n",declaration,declaration->class_name().c_str());
3301#endif
3302
3303 ROSE_ASSERT(local_node_to_name_map.empty() == false);
3304 ROSE_ASSERT(local_name_to_node_map.empty() == false);
3305
3307 {
3309 }
3310 else
3311 {
3312 SgDeclarationStatement* definingDeclaration = declaration->get_definingDeclaration();
3313 if (definingDeclaration != NULL)
3314 {
3315#if 0
3316 printf ("In generateUniqueName(): Using the defining declaration = %p since %p was not in the map \n",definingDeclaration,declaration);
3317#endif
3318 // s = generateUniqueName(definingDeclaration);
3319 s = generateUniqueNameForUseAsIdentifier_support(definingDeclaration);
3320 }
3321 else
3322 {
3323 // Note that builtin functions will not have a defining declaration.
3324 printf ("Warning: defining declaration not in SageInterface::local_node_to_name_map: declaration = %p = %s using name = %s \n",
3325 declaration,declaration->class_name().c_str(),SageInterface::get_name(declaration).c_str());
3326 // ROSE_ASSERT(false);
3327
3328 // If there is no defining declaration then go ahead and use the non-defining one.
3329 // s = SageInterface::get_name(declaration);
3330 SgDeclarationStatement* nondefiningDeclaration = declaration->get_firstNondefiningDeclaration();
3331 ROSE_ASSERT(nondefiningDeclaration != NULL);
3332 s = generateUniqueNameForUseAsIdentifier_support(nondefiningDeclaration);
3333 }
3334 }
3335
3336#if 0
3337 printf ("Exiting as a test! \n");
3338 ROSE_ABORT();
3339#endif
3340
3341 return s;
3342 }
3343
3344
3345void
3347 {
3348 ROSE_ASSERT(astNode != NULL);
3349
3350 ROSE_ASSERT(local_name_collision_map.empty() == true);
3351 ROSE_ASSERT(local_name_to_node_map.empty() == true);
3352 ROSE_ASSERT(local_node_to_name_map.empty() == true);
3353
3354 // Preorder traversal to uniquely name specific declarations (SgClassDeclaration and SgFunctionDeclaration IR nodes).
3355 class UniqueNameTraversal : public AstSimpleProcessing
3356 {
3357 public:
3358 void visit (SgNode* node)
3359 {
3360 SgDeclarationStatement* decl = isSgDeclarationStatement(node);
3361 if (decl != NULL)
3362 {
3363 SgClassDeclaration* classDeclaration = isSgClassDeclaration(decl);
3364 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(decl);
3365 if (classDeclaration != NULL || functionDeclaration != NULL)
3366 {
3368 local_name_to_node_map.insert(pair<string,SgNode*>(s,decl));
3369 local_node_to_name_map.insert(pair<SgNode*,string>(decl,s));
3370 }
3371 }
3372 }
3373 };
3374
3375 // Now buid the traveral object and call the traversal (preorder) on the function definition.
3376 UniqueNameTraversal traversal;
3377 traversal.traverse(astNode, preorder);
3378 }
3379
3380
3381
3384 {
3385 SgMemberFunctionDeclaration* defaultConstructor = NULL;
3386
3387 ROSE_ASSERT(classDeclaration != NULL);
3388 SgDeclarationStatement* definingDeclaration = classDeclaration->get_definingDeclaration();
3389 ROSE_ASSERT(definingDeclaration != NULL);
3390 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(definingDeclaration);
3391
3392 // Note that not all class declarations have to have a defining declaration (e.g. "~int()"
3393 // would be associated with a class declaration but no definition would exist).
3394 if (definingClassDeclaration != NULL)
3395 {
3396 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
3397 ROSE_ASSERT(classDefinition != NULL);
3398
3399 SgDeclarationStatementPtrList::iterator i = classDefinition->get_members().begin();
3400 while ( i != classDefinition->get_members().end() )
3401 {
3402 // Check the parent pointer to make sure it is properly set
3403 ROSE_ASSERT( (*i)->get_parent() != NULL);
3404 ROSE_ASSERT( (*i)->get_parent() == classDefinition);
3405
3406 SgMemberFunctionDeclaration* memberFunction = isSgMemberFunctionDeclaration(*i);
3407 if (memberFunction != NULL)
3408 {
3409 // printf ("memberFunction = %p = %s \n",memberFunction,memberFunction->get_name().str());
3410 if ( memberFunction->get_specialFunctionModifier().isConstructor() == true )
3411 defaultConstructor = memberFunction;
3412 }
3413
3414 // iterate through the class members
3415 i++;
3416 }
3417 }
3418
3419 // This should be true for the specific case that we are currently debugging!
3420 // ROSE_ASSERT(defaultConstructor != NULL);
3421
3422 return defaultConstructor;
3423 }
3424
3427 {
3428 SgMemberFunctionDeclaration* defaultDestructor = NULL;
3429
3430 ROSE_ASSERT(classDeclaration != NULL);
3431 SgDeclarationStatement* definingDeclaration = classDeclaration->get_definingDeclaration();
3432 if (definingDeclaration != NULL)
3433 {
3434 ROSE_ASSERT(definingDeclaration != NULL);
3435 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(definingDeclaration);
3436
3437 // Note that not all class declarations have to have a defining declaration (e.g. "~int()"
3438 // would be associated with a class declaration but no definition would exist).
3439 if (definingClassDeclaration != NULL)
3440 {
3441 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
3442 ROSE_ASSERT(classDefinition != NULL);
3443
3444 SgDeclarationStatementPtrList::iterator i = classDefinition->get_members().begin();
3445 while ( i != classDefinition->get_members().end() )
3446 {
3447 // Check the parent pointer to make sure it is properly set
3448 SgNode* i_parent = (*i)->get_parent();
3449 ROSE_ASSERT(i_parent != NULL);
3450
3451 // DQ (11/1/2005): Note that a template instantiation can have a parent which is the
3452 // variable which forced it's instantiation. Since it does not really exist in the
3453 // source code explicitly (it is compiler generated) this is as reasonable as anything else.
3454 if ( i_parent != classDefinition )
3455 {
3456 printf ("Error: (*i)->get_parent() = %p = %s \n",i_parent,i_parent->class_name().c_str());
3457 printf ("(*i) = %p = %s = %s \n",*i,(*i)->class_name().c_str(),(*i)->unparseToString().c_str());
3458 (*i)->get_file_info()->display("Called from SageInterface::getDefaultDestructor: debug");
3459 }
3460 ROSE_ASSERT( i_parent == classDefinition);
3461
3462 SgMemberFunctionDeclaration* memberFunction = isSgMemberFunctionDeclaration(*i);
3463 if (memberFunction != NULL)
3464 {
3465 if ( memberFunction->get_specialFunctionModifier().isDestructor() == true )
3466 defaultDestructor = memberFunction;
3467 }
3468
3469 // iterate through the class members
3470 i++;
3471 }
3472 }
3473 }
3474
3475 return defaultDestructor;
3476 }
3477
3478
3479
3480bool
3481SageInterface::addDefaultConstructorIfRequired ( SgClassType* classType, int physical_file_id /* = Sg_File_Info::TRANSFORMATION_FILE_ID */ )
3482 {
3483 // DQ (11/9/2020): Added function to support adding a default constructor definition to a class
3484 // if it does not have a default constructor, but has any other constructor that would prevent
3485 // a compiler generated default constructor from being generated by the compiler.
3486
3487#define DEBUG_ADD_DEFAULT_CONSTRUCTOR 0
3488
3489 // Note the physical_file_id is so that it can be marked to be unparsed when header file unparsing is active.
3490
3491 ASSERT_not_null(classType);
3492
3493 bool returnValue = false;
3494
3495 // To setup this transformation we need to see if there is a default constructor in the associated class.
3496 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
3497 ROSE_ASSERT(classDeclaration != NULL);
3498 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(classDeclaration->get_definingDeclaration());
3499 ROSE_ASSERT(definingClassDeclaration != NULL);
3500 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
3501 ROSE_ASSERT(classDefinition != NULL);
3502
3503 SgDeclarationStatementPtrList & declarationList = classDefinition->get_members();
3504
3505 bool foundConstructor = false;
3506 bool foundDefaultConstructor = false;
3507
3508#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3509 printf ("In addDefaultConstructorIfRequired(): class name = %s \n",classDeclaration->get_name().str());
3510#endif
3511
3512 SgDeclarationStatementPtrList::iterator i = declarationList.begin();
3513 while (i != declarationList.end())
3514 {
3515 SgMemberFunctionDeclaration* memberFunctionDeclaration = isSgMemberFunctionDeclaration(*i);
3516 if (memberFunctionDeclaration != NULL)
3517 {
3518 bool isConstructor = memberFunctionDeclaration->get_specialFunctionModifier().isConstructor();
3519 if (isConstructor == true)
3520 {
3521 foundConstructor = true;
3522
3523#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3524 printf ("Found a constructor! \n");
3525#endif
3526 SgFunctionParameterList* functionParameterList = memberFunctionDeclaration->get_parameterList();
3527 ROSE_ASSERT(functionParameterList != NULL);
3528
3529 // DQ (7/19/2021): Fixed to allow for previously found default constructor to be registered as found.
3530 // foundDefaultConstructor = (functionParameterList->get_args().size() == 0);
3531 foundDefaultConstructor = ((foundDefaultConstructor == true) || (functionParameterList->get_args().size() == 0));
3532
3533#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3534 if (foundDefaultConstructor == true)
3535 {
3536 printf ("Found a default constructor! \n");
3537 }
3538 else
3539 {
3540 printf ("This is not a default constructor: functionParameterList->get_args().size() = %zu \n",functionParameterList->get_args().size());
3541 }
3542#endif
3543 }
3544 else
3545 {
3546#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3547 printf ("This is not a constructor \n");
3548#endif
3549 }
3550 }
3551
3552 i++;
3553 }
3554
3555#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3556 printf ("foundConstructor = %s \n",foundConstructor ? "true" : "false");
3557 printf ("foundDefaultConstructor = %s \n",foundDefaultConstructor ? "true" : "false");
3558#endif
3559
3560 if (foundConstructor == true)
3561 {
3562 // Since there is at least one constructor, we can't rely on compiler generated constructors.
3563#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3564 printf ("Since there is at least one constructor, we can't rely on compiler generated constructors \n");
3565#endif
3566 if (foundDefaultConstructor == true)
3567 {
3568 // We can use the existing default constructor.
3569#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3570 printf ("We can use the existing default constructor (no need to build one) \n");
3571#endif
3572 }
3573 else
3574 {
3575 // We don't have a default constructor, so we need to build one explicitly, and insert it into the class definition.
3576
3577#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3578 printf ("########################################################### \n");
3579 printf ("Need to build a default constructor in the associated class \n");
3580#endif
3581 SgMemberFunctionDeclaration* constructorDeclaration = SageBuilder::buildDefaultConstructor(classType);
3582 ROSE_ASSERT(constructorDeclaration != NULL);
3583
3584#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3585 printf (" --- constructorDeclaration = %p = %s name = %s \n",constructorDeclaration,constructorDeclaration->class_name().c_str(),constructorDeclaration->get_name().str());
3586#endif
3587 ROSE_ASSERT (constructorDeclaration->get_declarationModifier().get_accessModifier().isPublic() == true);
3588
3589 classDefinition->prepend_statement(constructorDeclaration);
3590
3591 // constructorDeclaration->set_parent(classDefinition);
3592 ROSE_ASSERT(constructorDeclaration->get_parent() != NULL);
3593
3594 // int physical_file_id = variableDeclaration->get_startOfConstruct()->get_physical_file_id();
3595 markSubtreeToBeUnparsed(constructorDeclaration,physical_file_id);
3596
3597 returnValue = true;
3598#if 0
3599 constructorDeclaration->get_startOfConstruct()->set_physical_file_id(physical_file_id);
3600 constructorDeclaration->get_endOfConstruct ()->set_physical_file_id(physical_file_id);
3601
3602 // We also need to set the source position of the function definition, else the
3603 // function declaration will not be output.
3604 ROSE_ASSERT(constructorDeclaration->get_definition() != NULL);
3605 ROSE_ASSERT(constructorDeclaration->get_definition()->get_startOfConstruct() != NULL);
3606 ROSE_ASSERT(constructorDeclaration->get_definition()->get_endOfConstruct() != NULL);
3607 constructorDeclaration->get_definition()->get_startOfConstruct()->set_physical_file_id(physical_file_id);
3608 constructorDeclaration->get_definition()->get_endOfConstruct ()->set_physical_file_id(physical_file_id);
3609#endif
3610
3611#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3612 printf ("DONE: Need to build a default constructor in the associated class \n");
3613 printf ("################################################################# \n");
3614#endif
3615#if 0
3616 printf ("Exiting as a test! \n");
3617 ROSE_ABORT();
3618#endif
3619 }
3620 }
3621 else
3622 {
3623 // No constructors found, so we don't need to add an explicit default constructor.
3624
3625#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3626 printf ("No constructors found, so we don't need to add an explicit default constructor \n");
3627#endif
3628 }
3629
3630#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3631 printf ("Leaving addDefaultConstructorIfRequired(): returnValue = %s \n",returnValue ? "true" : "false");
3632#endif
3633
3634 return returnValue;
3635 }
3636
3637
3638
3639
3640void
3642 {
3643 // DQ (6/27/2005): This function outputs the global table of function type symbols
3644 // it is built during the EDG/Sage translation phase, and it built initially with
3645 // the EDG names of all instantiated templates. At a later phase (incomplete at
3646 // the moment) the AST fixup rebuilds the table to use the modified template names
3647 // (that is mangled names built from the modified template names used in Sage III).
3648
3649 // DQ (1/31/2006): Modified to build all types in the memory pools
3650 // extern SgFunctionTypeTable Sgfunc_type_table;
3651 // Sgfunc_type_table.print_functypetable();
3652 ROSE_ASSERT(SgNode::get_globalFunctionTypeTable() != NULL);
3653 SgNode::get_globalFunctionTypeTable()->print_functypetable();
3654 }
3655
3656void
3658 {
3659 // This simplifies how the traversal is called!
3660 OutputLocalSymbolTables astTraversal;
3661
3662 // I think the default should be preorder so that the interfaces would be more uniform
3663 astTraversal.traverse(node,preorder);
3664 }
3665
3666void
3668 {
3669 // DQ (6/27/2005): Output the local symbol table from each scope.
3670 // printf ("node = %s \n",node->sage_class_name());
3671
3672#if 0
3673 printf ("Exiting as a test! \n");
3674 ROSE_ABORT();
3675#endif
3676
3677 SgScopeStatement* scope = isSgScopeStatement(node);
3678 if (scope != NULL)
3679 {
3680 // SgSymbolTable* symbolTable = scope->get_symbol_table();
3681 // ROSE_ASSERT(symbolTable != NULL);
3682
3683 printf ("Symbol Table from %p = %s at: \n",scope,scope->sage_class_name());
3684 scope->get_file_info()->display("Symbol Table Location (Called from SageInterface::OutputLocalSymbolTables::visit())");
3685 // symbolTable->print("Called from SageInterface::OutputLocalSymbolTables::visit()");
3686 scope->print_symboltable("Called from SageInterface::OutputLocalSymbolTables::visit()");
3687 }
3688 }
3689
3690#if 0
3691// DQ (8/28/2005): This is already a member function of the SgFunctionDeclaration
3692// (so that it can handle template functions and member functions)
3693
3694// DQ (8/27/2005):
3695bool
3696SageInterface::isTemplateMemberFunction( SgTemplateInstantiationMemberFunctionDecl* memberFunctionDeclaration )
3697 {
3698 // This function determines if the member function is associated with a template
3699 // or just a template class (where it is a normal non-template member function).
3700
3701 bool result = false;
3702
3703 result = memberFunctionDeclaration->isTemplateFunction();
3704
3705 return result;
3706 }
3707#endif
3708
3709// DQ (8/27/2005):
3710bool
3712 {
3713 // This function determines if the template declaration associated withthis member function instantiation is
3714 // defined in the class or outside of the class.
3715
3716 bool result = false;
3717
3718#if 0
3719 // Check if this is a template or non-template member function
3720 if (isTemplateMemberFunction(memberFunctionDeclaration) == true)
3721 {
3722 SgTemplateDeclaration* templateDeclaration = memberFunctionDeclaration->get_templateDeclaration();
3723 printf ("templateDeclaration = %p parent of templateDeclaration = %p \n",templateDeclaration,templateDeclaration->get_parent());
3724
3725 // SgTemplateInstantiationDecl* classTemplateInstantiation = memberFunctionDeclaration->get_class_scope()->get_declaration();
3726 SgClassDeclaration* classDeclaration = memberFunctionDeclaration->get_class_scope()->get_declaration();
3727 ROSE_ASSERT(classDeclaration != NULL);
3728 SgTemplateInstantiationDecl* classTemplateInstantiation = isSgTemplateInstantiationDecl(classDeclaration);
3729
3730 if (classTemplateInstantiation != NULL)
3731 {
3732 SgTemplateDeclaration* classTemplateDeclaration = classTemplateInstantiation->get_templateDeclaration();
3733 if (classTemplateDeclaration != NULL && classTemplateDeclaration != templateDeclaration)
3734 {
3735 result = true;
3736 }
3737 }
3738 }
3739#endif
3740
3741 // Alternative approach
3742 // SgTemplateDeclaration* templateDeclaration = memberFunctionDeclaration->get_templateDeclaration();
3743 SgDeclarationStatement* templateDeclaration = memberFunctionDeclaration->get_templateDeclaration();
3744// printf ("In templateDefinitionIsInClass(): templateDeclaration = %p parent of templateDeclaration = %p = %s \n",templateDeclaration,
3745// templateDeclaration->get_parent(),templateDeclaration->get_parent()->class_name().c_str());
3746
3747 if (templateDeclaration != NULL && templateDeclaration->get_parent() != NULL)
3748 {
3749 SgScopeStatement* parentScope = isSgScopeStatement(templateDeclaration->get_parent());
3750 if (isSgClassDefinition(parentScope) != NULL)
3751 {
3752 result = true;
3753 }
3754 }
3755
3756 return result;
3757 }
3758#if 0
3760generateUniqueDeclaration ( SgDeclarationStatement* declaration )
3761 {
3762 // DQ (10/11/2007): This is no longer used.
3763 printf ("Error: This is no longer used. \n");
3764 ROSE_ABORT();
3765
3766 // Get the defining or first non-defining declaration so that we can use it as a key to know
3767 // when we have found the same function. So we don't count a redundant forward declaration
3768 // found outside of the class as matching the first non-defining declaration or the defining
3769 // declaration in the class by mistake. All declarations share the same firstNondefining
3770 // declaration and defining declaration so either could be a key declaration, but there are
3771 // times when either one of then (but not both) can be NULL (function defined withouth forward
3772 // declaration or not defined at all).
3773 SgDeclarationStatement* firstNondefiningDeclaration = declaration->get_firstNondefiningDeclaration();
3774 SgDeclarationStatement* definingDeclaration = declaration->get_definingDeclaration();
3775 SgDeclarationStatement* keyDeclaration = NULL;
3776 if (firstNondefiningDeclaration != NULL)
3777 keyDeclaration = firstNondefiningDeclaration;
3778 else
3779 keyDeclaration = definingDeclaration;
3780 ROSE_ASSERT(keyDeclaration != NULL);
3781
3782 return keyDeclaration;
3783 }
3784#endif
3787{
3788 string pragmaString = pragmaDeclaration->get_pragma()->get_pragma();
3789 istringstream istr(pragmaString);
3790 std::string key;
3791 istr >> key;
3792 return key;
3793}
3794
3796// TODO: move all Omp*statement under a parent SgOmpStatement
3798{
3799 ROSE_ASSERT (n != NULL);
3800 bool result = false;
3801 if (isSgOmpBarrierStatement(n)||
3802 isSgOmpBodyStatement(n)||
3803 isSgOmpDeclareSimdStatement(n) ||
3804 isSgOmpFlushStatement(n)||
3805 isSgOmpThreadprivateStatement(n)||
3806 isSgOmpTaskwaitStatement(n) )
3807 result = true;
3808
3809 return result;
3810
3811}
3812// DQ (8/28/2005):
3813bool
3815 {
3816 // This function looks for any other function that might overload the input function.
3817 // for member functions we only look in the scope where the member function is defined.
3818 // for non-member functions we look only in the scope where the function is declared.
3819
3820 // Note that there are scenarios where this approach of searching only these locations
3821 // might not catch an overloaded function.
3822 // * member functions:
3823 // - overloaded functions might be declared in base classes
3824 // * non-member functions:
3825 // - function declarations might be friend functions in classes
3826 // - functions might be declared in differen namespace definitions
3827 // (SgNamespaceDefinitionStatement), since a namespace in re-entrant
3828 // and can have many namespace declarations and definitions.
3829
3830 // bool result = false;
3831 int counter = 0;
3832
3833 SgMemberFunctionDeclaration* memberFunctionDeclaration = isSgMemberFunctionDeclaration(functionDeclaration);
3834 if (memberFunctionDeclaration != NULL)
3835 {
3836 // This is a member function declaration
3837
3838 // DQ (10/11/2007): Fix this to NOT use the generateUniqueDeclaration() function.
3839 // Generate a key to use for comparision (avoids false positives)
3840 // SgMemberFunctionDeclaration* keyDeclaration = isSgMemberFunctionDeclaration(generateUniqueDeclaration(functionDeclaration));
3841 // ROSE_ASSERT(keyDeclaration != NULL);
3842
3843 SgScopeStatement * scope = memberFunctionDeclaration->get_scope();
3844 ROSE_ASSERT(scope != NULL);
3845
3846 // TV (09/17/2018): ROSE-1378
3847 if (isSgDeclarationScope(scope)) {
3848 printf("TODO SageInterface::isOverloaded case when scope is SgDeclarationScope. See ROSE-1378.\n");
3849 return false;
3850 }
3851
3852 // Get the class definition
3853 SgClassDefinition* classDefinition =
3854 isSgClassDefinition(memberFunctionDeclaration->get_scope());
3855 ROSE_ASSERT(classDefinition != NULL);
3856
3857 // Get the class declaration associated with the class definition
3858 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classDefinition->get_declaration());
3859 ROSE_ASSERT(classDeclaration != NULL);
3860
3861 // Get the list of member declarations in the class
3862 SgDeclarationStatementPtrList & memberList = classDefinition->get_members();
3863#if 0
3864 // DQ (10/11/2007): Fix this function better by checking for more than one member function declaration in the class definition.
3865 printf (" memberList.size() = %" PRIuPTR " \n",memberList.size());
3866#endif
3867 for (SgDeclarationStatementPtrList::iterator i = memberList.begin(); i != memberList.end(); i++)
3868 {
3869#if 0
3870 printf (" counter = %d declaration = %p = %s \n",counter,*i,(*i)->class_name().c_str());
3871#endif
3872 SgMemberFunctionDeclaration* tempMemberFunction = isSgMemberFunctionDeclaration(*i);
3873 SgTemplateDeclaration* tempTemplateDeclaration = isSgTemplateDeclaration(*i);
3874
3875 // Member functions could be overloaded
3876 if (tempMemberFunction != NULL)
3877 {
3878#if 0
3879 // DQ (10/11/2007): This is a problem for where s member function prototype from outside the class is checked to be an ovverloaded function.
3880 // Check using the key declaration
3881 if ( keyDeclaration == generateUniqueDeclaration(tempMemberFunction) )
3882 {
3883#if 0
3884 printf ("Skipping the case of keyDeclaration == generateUniqueDeclaration(tempMemberFunction) = %p \n",keyDeclaration);
3885#endif
3886 continue;
3887 }
3888#endif
3889 ROSE_ASSERT(tempMemberFunction->get_name() != "");
3890#if 0
3891 printf (" tempMemberFunction = (name) %s = (qualified) %s \n",
3892 tempMemberFunction->get_name().str(),
3893 tempMemberFunction->get_qualified_name().str());
3894#endif
3895 if (tempMemberFunction->get_name() == memberFunctionDeclaration->get_name())
3896 {
3897#if 0
3898 printf (" Found a matching overloaded member function! \n");
3899#endif
3900 // result = true;
3901 counter++;
3902 }
3903 }
3904 else
3905 {
3906 // Or templates could be overloaded, but nothing else.
3907 if (tempTemplateDeclaration != NULL)
3908 {
3909 // If this is a template declaration, it could be a template
3910 // declaration for an overloaded member function of the same name.
3911#if 0
3912 // printf ("keyDeclaration->get_name() = %s \n",keyDeclaration->get_name().str());
3913 printf ("tempTemplateDeclaration->get_name() = %s \n",tempTemplateDeclaration->get_name().str());
3914#endif
3915 if (memberFunctionDeclaration->get_name() == tempTemplateDeclaration->get_name())
3916 {
3917#if 0
3918 printf (" Found a matching overloaded member function! \n");
3919#endif
3920 // result = true;
3921 counter++;
3922 }
3923 }
3924 else
3925 {
3926 // DQ (10/12/2007): Could friend functions defined in a class be overloaded? Need to check this!
3927 if (functionDeclaration->variantT() == V_SgFunctionDeclaration)
3928 {
3929 printf ("In SageInterface::isOverloaded(): could friend functions be overloaded in a class? \n");
3930 }
3931 }
3932 }
3933
3934 // If we have detected two, so we have an overloaded function.
3935 if (counter > 1)
3936 break;
3937 }
3938 }
3939 else
3940 {
3941 // This is a non-member function declaration
3942 printf ("In SageInterface::isOverloaded(): case of non-member function not yet implemented! \n");
3943 ROSE_ABORT();
3944 }
3945
3946 // DQ (10/11/2007): Fixup to use the counter and consider more than 1 function with the same name an overloaded member function.
3947 // This might be a problem for friend functions, so test this separately.
3948 // return result;
3949 return (counter > 1);
3950 }
3951
3952
3953
3954
3957 {
3958 // DQ (9/6/2005): This function builds a copy of the input function for the
3959 // construction of a forward declaration of the function. Required in the
3960 // instantiated functions definition is to be output as a specialization by ROSE.
3961 // Since the shallow copy mechanism will cause IR nodes to be shared, we have
3962 // to fix it up with deep copies of the parameter list and the CtorInitializerList.
3963
3964 ROSE_ASSERT(memberFunctionInstantiation != NULL);
3965
3966#if 0
3967 printf ("buildForwardFunctionDeclaration: Member function = %p = %s = definition = %p \n",
3968 memberFunctionInstantiation,
3969 memberFunctionInstantiation->get_name().str(),
3970 memberFunctionInstantiation->get_definition());
3971 memberFunctionInstantiation->get_file_info()->display("memberFunctionInstantiation: debug");
3972#endif
3973
3974 // This is a better implementation using a derived class from SgCopyHelp to control the
3975 // copying process (skipping the copy of any function definition). This is a variable
3976 // declaration with an explicitly declared class type.
3977 class NondefiningFunctionDeclarationCopyType : public SgCopyHelp
3978 {
3979 // DQ (9/26/2005): This class demonstrates the use of the copy mechanism
3980 // within Sage III (originally designed and implemented by Qing Yi).
3981 // One problem with it is that there is no context information permitted.
3982
3983 public:
3984 virtual SgNode *copyAst(const SgNode *n)
3985 {
3986 // If still NULL after switch then make the copy
3987 SgNode* returnValue = NULL;
3988
3989 switch(n->variantT())
3990 {
3991 // DQ (10/21/2007): Now that s bug is fixed in the SgDeclarationStatement::fixupCopy()
3992 // member function, I think we might not need this case.
3993
3994 // Don't copy the associated non-defining declaration when building a function prototype!
3995 case V_SgFunctionDeclaration:
3996 case V_SgMemberFunctionDeclaration:
3997 case V_SgTemplateInstantiationFunctionDecl:
3998 case V_SgTemplateInstantiationMemberFunctionDecl:
3999 {
4000 // printf ("Skip copying an associated non-defining declaration if it is present \n");
4001 const SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(n);
4002 ROSE_ASSERT(functionDeclaration != NULL);
4003 if (functionDeclaration == functionDeclaration->get_definingDeclaration())
4004 {
4005 // This is the defining declaration (make a shallow copy)
4006 // printf ("In NondefiningFunctionDeclarationCopyType::copyAst(): This is the DEFINING declaration! \n");
4007 // return const_cast<SgNode *>(n);
4008 returnValue = const_cast<SgNode *>(n);
4009 }
4010 else
4011 {
4012 // This is the non-defining declaration where we want to make a deep copy.
4013 // printf ("In NondefiningFunctionDeclarationCopyType::copyAst(): This is the NONDEFINING declaration! \n");
4014 }
4015
4016 break;
4017 }
4018
4019 // Don't copy the function definitions (roughly the body of the function)
4020 case V_SgFunctionDefinition:
4021 {
4022 printf ("Skip copying the function definition if it is present \n");
4023 // return const_cast<SgNode *>(n);
4024 returnValue = const_cast<SgNode *>(n);
4025 break;
4026 }
4027
4028 default:
4029 {
4030 // Nothing to do here
4031 break;
4032 }
4033 }
4034
4035 // return n->copy(*this);
4036
4037 // If not set at this point then make the copy!
4038 if (returnValue == NULL)
4039 returnValue = n->copy(*this);
4040
4041 ROSE_ASSERT(returnValue != NULL);
4042 return returnValue;
4043 }
4044 } nondefiningFunctionDeclarationCopy;
4045
4046 // DQ (10/20/2007): The more accurate copy mechanism now builds us a defining declaration to go with the non-defining declaration!
4047 // This is because we have to remove the pointers from non-defining declaration to the definition (which should be pointed to ONLY by the defining declaration!
4048 // delete copyOfMemberFunction->get_definingDeclaration();
4049 if (memberFunctionInstantiation->get_definition() != NULL)
4050 {
4051 printf ("\n\nNEED TO REMOVE POINTERS IN THE NON-DEFINING DECLARATION TO THE SgClassDefinition objects. \n");
4052 ROSE_ABORT();
4053
4054 // If we see the assertion above fail then we might want to use this code:
4055 ROSE_ASSERT( memberFunctionInstantiation != memberFunctionInstantiation->get_definingDeclaration() );
4056 memberFunctionInstantiation->set_definition(NULL);
4057 }
4058 SgNode* copyOfMemberFunctionNode = memberFunctionInstantiation->copy(nondefiningFunctionDeclarationCopy);
4059 SgTemplateInstantiationMemberFunctionDecl* copyOfMemberFunction = static_cast<SgTemplateInstantiationMemberFunctionDecl*>(copyOfMemberFunctionNode);
4060
4061 // printf ("\n\nHOW DO WE KNOW WHEN TO NOT COPY THE DEFINING DECLARATION SO THAT WE CAN JUST BUILD A FUNCTION PROTOTYPE! \n");
4062 // ROSE_ASSERT(false);
4063
4064#if 0
4065 printf ("copyOfMemberFunction->get_firstNondefiningDeclaration() = %p \n",copyOfMemberFunction->get_firstNondefiningDeclaration());
4066#endif
4067 // DQ (10/11/2007): The copy function sets the firstNondefiningDeclaration to itself if in the original declaration it had the
4068 // firstNondefiningDeclaration set to itself, this is incorrect in the case where we only make a copy of function declaration,
4069 // and causes the symbol table tests for get_declaration_associated_with_symbol() to fail because it uses the
4070 // firstNondefiningDeclaration which is not the one associated with the symbol in the parent scope. So reset the
4071 // firstNondefiningDeclaration in the copy of the member function.
4072 copyOfMemberFunction->set_firstNondefiningDeclaration(memberFunctionInstantiation->get_firstNondefiningDeclaration());
4073
4074#if 0
4075 printf ("memberFunctionInstantiation->get_firstNondefiningDeclaration() = %p \n",memberFunctionInstantiation->get_firstNondefiningDeclaration());
4076
4077 printf ("copyOfMemberFunction->isForward() = %s \n",copyOfMemberFunction->isForward() ? "true" : "false");
4078 printf ("memberFunctionInstantiation->isForward() = %s \n",memberFunctionInstantiation->isForward() ? "true" : "false");
4079#endif
4080#if 0
4081 printf ("memberFunctionInstantiation->isSpecialization() = %s \n",memberFunctionInstantiation->isSpecialization() ? "true" : "false");
4082 printf ("copyOfMemberFunctionNode = %p = %s = %s memberFunctionInstantiation->isSpecialization() = %s \n",
4083 copyOfMemberFunction,copyOfMemberFunction->class_name().c_str(),SageInterface::get_name(copyOfMemberFunction).c_str(),copyOfMemberFunction->isSpecialization() ? "true" : "false");
4084 copyOfMemberFunction->get_file_info()->display("copyOfMemberFunction: debug");
4085#endif
4086
4087 // Make sure that we have the same number of arguments on the copy that we build
4088 ROSE_ASSERT(memberFunctionInstantiation->get_args().size() == copyOfMemberFunction->get_args().size());
4089
4090 // DQ (11/5/2007): Additional tests
4091 ROSE_ASSERT(memberFunctionInstantiation->get_startOfConstruct()->isOutputInCodeGeneration() == copyOfMemberFunction->get_startOfConstruct()->isOutputInCodeGeneration());
4092 ROSE_ASSERT(memberFunctionInstantiation->get_startOfConstruct()->isCompilerGenerated() == copyOfMemberFunction->get_startOfConstruct()->isCompilerGenerated());
4093
4094 ROSE_ASSERT(copyOfMemberFunction != NULL);
4095 return copyOfMemberFunction;
4096 }
4097
4098
4099void
4100supportForBaseTypeDefiningDeclaration ( SgSymbolTable* symbolTable, SgDeclarationStatement* declarationForType )
4101 {
4102 // DQ (10/14/2007): Supporting function for
4103
4104 ROSE_ASSERT(declarationForType != NULL);
4105
4106 // DQ (11/7/2007): Added more cases...
4107 switch(declarationForType->variantT())
4108 {
4109 // DQ (12/26/2012): Added support for templates.
4110 case V_SgTemplateInstantiationDecl:
4111 case V_SgTemplateClassDeclaration:
4112
4113 case V_SgClassDeclaration:
4114 {
4115 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declarationForType);
4116 // SgSymbol* symbol = new SgClassSymbol(classDeclaration);
4117 SgSymbol* symbol = NULL;
4118 if (isSgTemplateClassDeclaration(declarationForType) != NULL)
4119 {
4120 symbol = new SgTemplateClassSymbol(classDeclaration);
4121 }
4122 else
4123 {
4124 symbol = new SgClassSymbol(classDeclaration);
4125 }
4126
4127 ROSE_ASSERT(symbol != NULL);
4128 SgName name = classDeclaration->get_name();
4129 symbolTable->insert(name,symbol);
4130 break;
4131 }
4132
4133 case V_SgEnumDeclaration:
4134 {
4135 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(declarationForType);
4136 SgSymbol* symbol = new SgEnumSymbol(enumDeclaration);
4137 ROSE_ASSERT(symbol != NULL);
4138 SgName name = enumDeclaration->get_name();
4139 symbolTable->insert(name,symbol);
4140 break;
4141 }
4142
4143 case V_SgFunctionDeclaration:
4144 {
4145 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(declarationForType);
4146 SgSymbol* symbol = new SgFunctionSymbol(functionDeclaration);
4147 ROSE_ASSERT(symbol != NULL);
4148 SgName name = functionDeclaration->get_name();
4149 symbolTable->insert(name,symbol);
4150 break;
4151 }
4152
4153 case V_SgMemberFunctionDeclaration:
4154 {
4155 SgMemberFunctionDeclaration* functionDeclaration = isSgMemberFunctionDeclaration(declarationForType);
4156 SgSymbol* symbol = new SgMemberFunctionSymbol(functionDeclaration);
4157 ROSE_ASSERT(symbol != NULL);
4158
4159 // printf ("In supportForBaseTypeDefiningDeclaration(): symbol = %p = %s = %s \n",symbol,symbol->class_name().c_str(),SageInterface::get_name(symbol).c_str());
4160
4161 SgName name = functionDeclaration->get_name();
4162 symbolTable->insert(name,symbol);
4163 break;
4164 }
4165
4166 default:
4167 {
4168 printf ("Default reached in evaluation of typedef inner definition = %p = %s and building a symbol for it for the symbol table \n",declarationForType,declarationForType->class_name().c_str());
4169 ROSE_ABORT();
4170 }
4171 }
4172 }
4173
4174
4175void
4176supportForVariableLists ( SgScopeStatement* scope, SgSymbolTable* symbolTable, SgInitializedNamePtrList & variableList )
4177 {
4178 // DQ (11/1/2007): Added supporting function to refactor code.
4179 SgInitializedNamePtrList::iterator i = variableList.begin();
4180 while (i != variableList.end())
4181 {
4183 ROSE_ASSERT(variable != NULL);
4184 if (variable->get_scope() == scope)
4185 {
4186 // printf ("Scopes match, OK! \n");
4187 }
4188 else
4189 {
4190 if (SgProject::get_verbose() > 0)
4191 {
4192 printf ("WARNING: Scopes do NOT match! variable = %p = %s (could this be a static variable, or has the symbol table been setup before the scopes have been set?) \n",variable,variable->get_name().str());
4193 }
4194 }
4195
4196 SgSymbol* symbol = new SgVariableSymbol(variable);
4197 ROSE_ASSERT(symbol != NULL);
4198 SgName name = variable->get_name();
4199 symbolTable->insert(name,symbol);
4200
4201 i++;
4202 }
4203 }
4204#if 0
4205// DQ (3/2/2014): Added a new interface function (used in the snippet insertion support).
4206void
4207SageInterface::supportForInitializedNameLists ( SgScopeStatement* scope, SgInitializedNamePtrList & variableList )
4208 {
4209 SgSymbolTable* symbolTable = scope->get_symbol_table();
4210 ROSE_ASSERT(symbolTable != NULL);
4211
4212 supportForVariableLists(scope,symbolTable,variableList);
4213 }
4214#endif
4215
4216void
4217supportForVariableDeclarations ( SgScopeStatement* scope, SgSymbolTable* symbolTable, SgVariableDeclaration* variableDeclaration )
4218 {
4219 // DQ (10/24/2007): Added supporting function to refactor code.
4220 SgInitializedNamePtrList & variableList = variableDeclaration->get_variables();
4221 supportForVariableLists(scope,symbolTable,variableList);
4222
4223 // DQ (10/13/2007): Need to look into variable declarations to see if there are defining declaration
4224 // that also force symbols to be built in the current scope!
4225 // ROSE_ASSERT(derivedDeclaration->get_variableDeclarationContainsBaseTypeDefiningDeclaration() == false);
4226 if (variableDeclaration->get_variableDeclarationContainsBaseTypeDefiningDeclaration() == true)
4227 {
4228 // Build a SgClassDeclaration, SgEnumDeclaration associated symbol and add it to the symbol table.
4229 ROSE_ASSERT(symbolTable != NULL);
4230 ROSE_ASSERT(variableDeclaration->get_baseTypeDefiningDeclaration() != NULL);
4231 supportForBaseTypeDefiningDeclaration ( symbolTable, variableDeclaration->get_baseTypeDefiningDeclaration() );
4232 }
4233 }
4234
4235void
4236supportForLabelStatements ( SgScopeStatement* scope, SgSymbolTable* symbolTable )
4237 {
4238 // Update the symbol table in SgFunctionDefinition with all the labels in the function.
4239
4240 std::vector<SgNode*> labelList = NodeQuery::querySubTree (scope,V_SgLabelStatement);
4241
4242 int numberOfLabels = labelList.size();
4243 for (int i=0; i < numberOfLabels; i++)
4244 {
4245 SgLabelStatement* labelStatement = isSgLabelStatement(labelList[i]);
4246
4247 ROSE_ASSERT(labelStatement != NULL);
4248 ROSE_ASSERT(labelStatement->get_scope() == scope);
4249
4250 SgSymbol* symbol = new SgLabelSymbol(labelStatement);
4251 ROSE_ASSERT(symbol != NULL);
4252
4253 // printf ("In SageInterface::rebuildSymbolTable() labelStatement = %p building a new SgLabelSymbol = %p \n",labelStatement,symbol);
4254
4255 SgName name = labelStatement->get_name();
4256 symbolTable->insert(name,symbol);
4257 }
4258 }
4259
4260
4261void
4263 {
4264 // This function is called from the implementation of the copy member functions.
4265
4266 ROSE_ASSERT(scope != NULL);
4267#if 0
4268 printf ("In SageInterface::rebuildSymbolTable(): Symbol Table from %p = %s \n",scope,scope->class_name().c_str());
4269#endif
4270#if 0
4271 printf ("Exiting as a test \n");
4272 ROSE_ABORT();
4273#endif
4274
4275 SgSymbolTable* symbolTable = scope->get_symbol_table();
4276
4277 if (symbolTable != NULL)
4278 {
4279 // This must be an empty symbol table!
4280 if (symbolTable->size() != 0)
4281 {
4282 printf ("symbolTable->size() = %d \n",symbolTable->size());
4283 }
4284 ROSE_ASSERT(symbolTable->size() == 0);
4285#if 0
4286 printf ("Symbol Table from %p = %s of size = %" PRIuPTR " \n",scope,scope->class_name().c_str(),symbolTable->size());
4287 symbolTable->print("Called from SageInterface::rebuildSymbolTable()");
4288#endif
4289 }
4290 else
4291 {
4292#if 0
4293 printf ("In SageInterface::rebuildSymbolTable(): No symbol table found \n");
4294#endif
4295 ROSE_ASSERT(symbolTable == NULL);
4296
4297 // DQ (10/8/2007): Build a new symbol table if there was not already one built.
4298 symbolTable = new SgSymbolTable();
4299
4300 ROSE_ASSERT(symbolTable != NULL);
4301 ROSE_ASSERT(symbolTable->get_table() != NULL);
4302
4303 // DQ (2/16/2006): Set this parent directly (now tested)
4304 symbolTable->set_parent(scope);
4305 ROSE_ASSERT(symbolTable->get_parent() != NULL);
4306
4307 scope->set_symbol_table(symbolTable);
4308 }
4309
4310 // DQ (10/8/2007): If there is already a symbol table then don't over write it. This fixes copies generated with more than one symbol table.
4311 ROSE_ASSERT(scope->get_symbol_table() != NULL);
4312 ROSE_ASSERT(scope->get_symbol_table()->get_table() != NULL);
4313
4314 // This implements SgScopeStatement specific details (e.g function declarations have parameters and their declaration causes variable
4315 // symbols to be placed into the SgFunctionDefinition scope (but only for defining declarations).
4316 switch(scope->variantT())
4317 {
4318 case V_SgForStatement:
4319 {
4320 // These scopes have their symbols split between the attached symbol table and the symbol tables in the SgBasicBlock data member(s).
4321 // printf ("Symbol tables could contain symbols outside of the inclosed body scope = %p = %s \n",scope,scope->class_name().c_str());
4322
4323 SgForStatement* forStatement = isSgForStatement(scope);
4324
4325 SgStatementPtrList::iterator i = forStatement->get_init_stmt().begin();
4326
4327 // printf ("i != forStatement->get_init_stmt().end() = %s \n",i != forStatement->get_init_stmt().end() ? "true" : "false");
4328
4329 while (i != forStatement->get_init_stmt().end())
4330 {
4331 // printf ("For statement initialization list: *i = %p = %s \n",*i,(*i)->class_name().c_str());
4332 SgVariableDeclaration* variableDeclarationInitializer = isSgVariableDeclaration(*i);
4333 if (variableDeclarationInitializer != NULL)
4334 {
4335 // There is a variable declaration in the conditional, it needs to be added to the symbol table.
4336 // printf ("There is a variable declaration in the for statement initializer, it needs to be added to the symbol table scope = %p = %s \n",scope,scope->class_name().c_str());
4337 // ROSE_ASSERT(false);
4338 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationInitializer );
4339 }
4340
4341 i++;
4342 }
4343
4344 SgVariableDeclaration* variableDeclarationCondition = isSgVariableDeclaration(forStatement->get_test());
4345 if (variableDeclarationCondition != NULL)
4346 {
4347 // There is a variable declaration in the conditional, it needs to be added to the symbol table.
4348 // printf ("There is a variable declaration in the for statement test, it needs to be added to the symbol table scope = %p = %s \n",scope,scope->class_name().c_str());
4349 // ROSE_ASSERT(false);
4350 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4351 }
4352
4353 return;
4354 break;
4355 }
4356
4357 case V_SgJovialForThenStatement:
4358 case V_SgMatlabForStatement:
4359 {
4360 return;
4361 break;
4362 }
4363
4364
4365 // DQ (12/23/2012): Added support for templates.
4366 case V_SgTemplateFunctionDefinition:
4367
4368 case V_SgFunctionDefinition:
4369 {
4370 // These scopes have their symbols split between the attached symbol table and the symbol tables in the SgBasicBlock data member(s).
4371 // printf ("Symbol tables could contain symbols outside of the enclosed body scope = %p = %s \n",scope,scope->class_name().c_str());
4372
4373 // DQ (10/8/2007): If this is a SgFunctionDefinition, then include the parameters in the SgFunctionDeclaration.
4374 SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(scope);
4375 if (functionDefinition != NULL)
4376 {
4377 SgFunctionDeclaration* functionDeclaration = functionDefinition->get_declaration();
4378 // printf ("In SageInterface::rebuildSymbolTable(): functionDefinition = %p functionDeclaration = %p \n",functionDefinition,functionDeclaration);
4379
4380 // DQ (10/8/2007): It turns out that this is always NULL, because the parent of the functionDeclaration has not yet been set in the copy mechanism!
4381 if (functionDeclaration != NULL)
4382 {
4383 // DQ (3/28/2014): After a call with Philippe, this Java specific issues is fixed and we don't seem to see this problem any more.
4384 if (functionDeclaration->isForward() == true)
4385 {
4386 printf ("ERROR: functionDeclaration = %p = %s = %s \n",functionDeclaration,functionDeclaration->class_name().c_str(),functionDeclaration->get_name().str());
4387 printf (" --- functionDeclaration (get_name()) = %s \n",get_name(functionDeclaration).c_str());
4388 printf (" --- functionDeclaration (mangled name) = %s \n",functionDeclaration->get_mangled_name().str());
4389 SgMemberFunctionDeclaration* memberFunctionDeclaration = isSgMemberFunctionDeclaration(functionDeclaration);
4390 if (memberFunctionDeclaration != NULL)
4391 {
4392 printf ("memberFunctionDeclaration != NULL \n");
4393 }
4394 }
4395 ROSE_ASSERT(functionDeclaration->isForward() == false);
4396 SgInitializedNamePtrList & argumentList = functionDeclaration->get_args();
4397 supportForVariableLists(scope,symbolTable,argumentList);
4398 }
4399 else
4400 {
4401 // This happens in the copy function because the function definition is copied from the SgFunctionDeclaration
4402 // and only after the copy is made is the parent of the definition set to be the function declaration. Thus
4403 // the get_declaration() member function returns NULL.
4404 // printf ("There is no function declaration associated with this function definition! \n");
4405 // ROSE_ASSERT(functionDeclaration->isForward() == true);
4406 }
4407 }
4408
4409 // DQ (10/25/2007): Label symbols are now places into the SgFunctionDefinition (they have to be collected from the function).
4410 supportForLabelStatements(scope,symbolTable);
4411
4412 return;
4413 break;
4414 }
4415
4416 case V_SgIfStmt:
4417 {
4418 // These scopes have their sysmbols split between the attached symbol table and the symbol tables in the SgBasicBlock data member(s).
4419 // printf ("Symbol tables could contain symbols outside of the enclosed body scope = %p = %s \n",scope,scope->class_name().c_str());
4420
4421 SgIfStmt* ifStatement = isSgIfStmt(scope);
4422 SgVariableDeclaration* variableDeclarationCondition = isSgVariableDeclaration(ifStatement->get_conditional());
4423 if (variableDeclarationCondition != NULL)
4424 {
4425 // There is a variable declaration in the conditional, it needs to be added to the symbol table.
4426 // printf ("There is a variable declaration in the conditional, it needs to be added to the symbol table \n");
4427 // ROSE_ASSERT(false);
4428 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4429 }
4430 return;
4431 break;
4432 }
4433
4434 case V_SgSwitchStatement:
4435 {
4436 // These scopes have their sysmbols split between the attached symbol table and the symbol tables in the SgBasicBlock data member(s).
4437 // printf ("Symbol tables could contain symbols outside of the enclosed body scope = %p = %s \n",scope,scope->class_name().c_str());
4438
4439 SgSwitchStatement* switchStatement = isSgSwitchStatement(scope);
4440 SgVariableDeclaration* variableDeclarationSelector = isSgVariableDeclaration(switchStatement->get_item_selector());
4441 if (variableDeclarationSelector != NULL)
4442 {
4443 // There is a variable declaration in the conditional, it needs to be added to the symbol table.
4444 // printf ("There is a variable declaration in the item selector of the switch statement, it needs to be added to the symbol table \n");
4445
4446 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationSelector );
4447 }
4448 return;
4449 break;
4450 }
4451
4452 case V_SgWhileStmt:
4453 {
4454 // These scopes have their sysmbols split between the attached symbol table and the symbol tables in the SgBasicBlock data member(s).
4455 // commented out like for others, otherwise show up each time a While is being copied. Liao, 1/31/2008
4456 // printf ("Symbol tables could contain symbols outside of the enclosed body scope = %p = %s \n",scope,scope->class_name().c_str());
4457
4458 SgWhileStmt* whileStatement = isSgWhileStmt(scope);
4459 SgVariableDeclaration* variableDeclarationCondition = isSgVariableDeclaration(whileStatement->get_condition());
4460 if (variableDeclarationCondition != NULL)
4461 {
4462 // There is a variable declaration in the conditional, it needs to be added to the symbol table.
4463 // printf ("There is a variable declaration in the while statement condition, it needs to be added to the symbol table \n");
4464 // ROSE_ASSERT(false);
4465
4466 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4467 }
4468 return;
4469 break;
4470 }
4471
4472 case V_SgCatchOptionStmt:
4473 case V_SgDoWhileStmt:
4474 {
4475 // These scopes contain a SgBasicBlock as a data member and the scope is held there.
4476 // printf ("Symbol tables can must be computed by the enclosed body scope = %p = %s \n",scope,scope->class_name().c_str());
4477 return;
4478 break;
4479 }
4480
4481 // DQ (12/24/2012): Added support for templates.
4482 case V_SgTemplateClassDefinition:
4483
4484 case V_SgBasicBlock:
4485 case V_SgClassDefinition:
4486 case V_SgTemplateInstantiationDefn:
4487 case V_SgGlobal:
4488 case V_SgNamespaceDefinitionStatement:
4489 case V_SgFortranDo: // Liao 12/19/2008, My understanding is that Fortran do loop header does not introduce new symbols like a C/C++ for loop does
4490 {
4491 // printf ("Used the list of statements/declarations that are held deirectly by this scope \n");
4492 break;
4493 }
4494
4495 // DQ (3/29/2014): Added support for SgJavaForEachStatement.
4496 case V_SgJavaForEachStatement:
4497 {
4498 SgJavaForEachStatement* javaForEachStatement = isSgJavaForEachStatement(scope);
4499 SgVariableDeclaration* variableDeclarationCondition = isSgVariableDeclaration(javaForEachStatement->get_element());
4500 if (variableDeclarationCondition != NULL)
4501 {
4502 // There is a variable declaration in the conditional, it needs to be added to the symbol table.
4503 // printf ("There is a variable declaration in the while statement condition, it needs to be added to the symbol table \n");
4504 // ROSE_ASSERT(false);
4505
4506 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4507 }
4508 return;
4509 break;
4510 }
4511
4512 default:
4513 {
4514 printf ("Default reached in SageInterface::rebuildSymbolTable() scope = %p = %s \n",scope,scope->class_name().c_str());
4515 ROSE_ABORT();
4516 }
4517 }
4518
4519#if 0
4520 printf ("In SageInterface::rebuildSymbolTable(): fixup declarations in Symbol Table from %p = %s \n",scope,scope->class_name().c_str());
4521#endif
4522
4523 // Generate a copy of the statement list (this is simpler than handling the cases of a
4524 // declaration list and a statement list separately for the scopes that contain one or the other.
4525 SgStatementPtrList statementList = scope->generateStatementList();
4526
4527 // Loop through the statements and for each declaration build a symbol and add it to the symbol table
4528 for (SgStatementPtrList::iterator i = statementList.begin(); i != statementList.end(); i++)
4529 {
4530 // At some point we should move this mechanism in to a factory patterns for SgSymbol
4531
4532 // printf ("Iterating through the declaration in this scope ... %p = %s = %s \n",*i,(*i)->class_name().c_str(),get_name(*i).c_str());
4533
4534 SgDeclarationStatement* declaration = isSgDeclarationStatement(*i);
4535 if (declaration != NULL)
4536 {
4537 // DQ (11/7/2007): Where there can be multiple declaration (e.g. function declarations with prototypes) only use one of them.
4538 bool useThisDeclaration = (declaration->get_firstNondefiningDeclaration() == declaration) ||
4539 ( (declaration->get_firstNondefiningDeclaration() == NULL) && (declaration->get_definingDeclaration() == declaration) );
4540
4541 list<SgSymbol*> symbolList;
4542 switch(declaration->variantT())
4543 {
4544 case V_SgTemplateInstantiationMemberFunctionDecl:
4545 {
4546 SgTemplateInstantiationMemberFunctionDecl* derivedDeclaration = isSgTemplateInstantiationMemberFunctionDecl(declaration);
4547 // DQ (11/6/2007): Don't build a symbol for the defining declaration defined in another scope and put the resulting symbol into the wrong scope
4548 if (scope == derivedDeclaration->get_scope())
4549 {
4550 SgSymbol* symbol = new SgMemberFunctionSymbol(derivedDeclaration);
4551 ROSE_ASSERT(symbol != NULL);
4552
4553 // printf ("In rebuildSymbolTable: symbol = %p = %s = %s \n",symbol,symbol->class_name().c_str(),SageInterface::get_name(symbol).c_str());
4554
4555 // printf ("SgTemplateInstantiationMemberFunctionDecl: scope = %p derivedDeclaration = %p = %s inserting a symbol = %p \n",scope,derivedDeclaration,get_name(derivedDeclaration).c_str(),symbol);
4556
4557 SgName name = derivedDeclaration->get_name();
4558 symbolTable->insert(name,symbol);
4559 }
4560 else
4561 {
4562 // printf ("SgTemplateInstantiationMemberFunctionDecl: scope = %p derivedDeclaration = %p = %s didn't match the scope \n",scope,derivedDeclaration,get_name(derivedDeclaration).c_str());
4563
4564 // These IR nodes might only exist as a template declaration and thus not be structureally present in their scope.
4565 // So we would never traverse them in the correct scope and so never build sysmbols for them and add the symbols
4566 // to the correct symbol table. This is a fundamental problem. So we have to try to add these sorts of symbols
4567 // to the scope were they belong.
4568 SgScopeStatement* derivedDeclarationScope = derivedDeclaration->get_scope();
4569 ROSE_ASSERT(derivedDeclarationScope != NULL);
4570
4571 // If this is a copy then it would be nice to make sure that the scope has been properly set.
4572 // Check this by looking for the associated template declaration in the scope.
4573 // SgTemplateDeclaration* templateDeclaration = derivedDeclaration->get_templateDeclaration();
4574 // SgDeclarationStatement* templateDeclaration = derivedDeclaration->get_templateDeclaration();
4575 SgTemplateMemberFunctionDeclaration* templateDeclaration = derivedDeclaration->get_templateDeclaration();
4576 ROSE_ASSERT(templateDeclaration != NULL);
4577 // SgTemplateSymbol* templateSymbol = derivedDeclarationScope->lookup_template_symbol(templateDeclaration->get_name());
4578
4579 // DQ (8/13/2013): Fixed the interface to avoid use of lookup_template_symbol() (removed).
4580 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
4581 // In this case these are unavailable from this point.
4582 // SgTemplateSymbol* templateSymbol = derivedDeclarationScope->lookup_template_symbol(templateDeclaration->get_template_name());
4583 // SgTemplateSymbol* templateSymbol = derivedDeclarationScope->lookup_template_symbol(templateDeclaration->get_template_name(),NULL,NULL);
4584 SgType* functionType = templateDeclaration->get_type();
4585 SgTemplateParameterPtrList & templateParameterList = templateDeclaration->get_templateParameters();
4586 // SgTemplateMemberFunctionSymbol* templateSymbol = derivedDeclarationScope->lookup_template_symbol(templateDeclaration->get_template_name(),NULL,NULL);
4587 SgTemplateMemberFunctionSymbol* templateSymbol = derivedDeclarationScope->lookup_template_member_function_symbol(templateDeclaration->get_template_name(),functionType,&templateParameterList);
4588 if (templateSymbol != NULL)
4589 {
4590 // The symbol is not present, so we have to build one and add it.
4591#if 0
4592 printf ("Building a symbol for derivedDeclaration = %p = %s to an alternative symbol table in derivedDeclarationScope = %p \n",
4593 derivedDeclaration,get_name(derivedDeclaration).c_str(),derivedDeclarationScope);
4594#endif
4595 SgSymbol* symbol = new SgMemberFunctionSymbol(derivedDeclaration);
4596 ROSE_ASSERT(symbol != NULL);
4597 SgName name = derivedDeclaration->get_name();
4598 derivedDeclarationScope->insert_symbol(name,symbol);
4599 }
4600 else
4601 {
4602 // printf ("The symbol was already present in the derivedDeclarationScope = %p \n",derivedDeclarationScope);
4603 }
4604 }
4605 break;
4606 }
4607
4608 // DQ (12/26/2012): Added support for templates.
4609 case V_SgTemplateMemberFunctionDeclaration:
4610
4611 case V_SgMemberFunctionDeclaration:
4612 {
4613 SgMemberFunctionDeclaration* derivedDeclaration = isSgMemberFunctionDeclaration(declaration);
4614
4615 // DQ (11/6/2007): Don't build a symbol for the defining declaration defined in another scope and put the resulting symbol into the wrong scope
4616 if (scope == derivedDeclaration->get_scope())
4617 {
4618 // SgSymbol* symbol = new SgMemberFunctionSymbol(derivedDeclaration);
4619 SgSymbol* symbol = NULL;
4620 if (isSgTemplateFunctionDeclaration(declaration) != NULL)
4621 symbol = new SgTemplateMemberFunctionSymbol(derivedDeclaration);
4622 else
4623 symbol = new SgMemberFunctionSymbol(derivedDeclaration);
4624
4625 ROSE_ASSERT(symbol != NULL);
4626
4627 // printf ("In rebuildSymbolTable: symbol = %p = %s = %s \n",symbol,symbol->class_name().c_str(),SageInterface::get_name(symbol).c_str());
4628
4629 SgName name = derivedDeclaration->get_name();
4630 symbolTable->insert(name,symbol);
4631 }
4632 else
4633 {
4634 // This happens when a defining declaration is located outside of the class where it is associated.
4635 // printf ("SgMemberFunctionDeclaration: scope = %p derivedDeclaration = %p = %s didn't match the scope \n",scope,derivedDeclaration,get_name(derivedDeclaration).c_str());
4636 }
4637 break;
4638 }
4639
4640 // DQ (2/26/2009): These have to be reformatted from where someone removed the formatting previously.
4641 case V_SgTemplateInstantiationFunctionDecl:
4642 {
4643 SgTemplateInstantiationFunctionDecl* derivedDeclaration = isSgTemplateInstantiationFunctionDecl(declaration);
4644 // DQ (10/21/2007): If this is a friend function in a class then we have to skip insertion of the symbol into this scope (this symbol table)
4645 if (scope == derivedDeclaration->get_scope())
4646 {
4647 SgSymbol* symbol = new SgFunctionSymbol(derivedDeclaration);
4648 ROSE_ASSERT(symbol != NULL);
4649 SgName name = derivedDeclaration->get_name();
4650 symbolTable->insert(name,symbol);
4651 }
4652 else
4653 {
4654 if (derivedDeclaration->get_declarationModifier().isFriend() == false)
4655 {
4656#if PRINT_DEVELOPER_WARNINGS
4657 printf ("Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->class_name().c_str());
4658#endif
4659 }
4660 }
4661
4662 break;
4663 }
4664
4665 // DQ (12/24/2012): Added support for templates.
4666 case V_SgTemplateFunctionDeclaration:
4667
4668 case V_SgFunctionDeclaration:
4669 {
4670 SgFunctionDeclaration* derivedDeclaration = isSgFunctionDeclaration(declaration);
4671
4672 // DQ (10/20/2007): If this is a friend function in a class then we have to skip insertion of the symbol into this scope (this symbol table)
4673
4674 if (useThisDeclaration == true)
4675 {
4676 if (scope == derivedDeclaration->get_scope())
4677 {
4678 // DQ (12/24/2012): Added support for templates.
4679 // SgSymbol* symbol = new SgFunctionSymbol(derivedDeclaration);
4680 SgSymbol* symbol = NULL;
4681 if (isSgTemplateFunctionDeclaration(declaration) != NULL)
4682 symbol = new SgTemplateFunctionSymbol(derivedDeclaration);
4683 else
4684 symbol = new SgFunctionSymbol(derivedDeclaration);
4685
4686 ROSE_ASSERT(symbol != NULL);
4687 SgName name = derivedDeclaration->get_name();
4688 symbolTable->insert(name,symbol);
4689 }
4690 else
4691 {
4692 if (derivedDeclaration->get_declarationModifier().isFriend() == false)
4693 {
4694#if PRINT_DEVELOPER_WARNINGS
4695 printf ("Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->class_name().c_str());
4696#endif
4697 }
4698 }
4699 }
4700 break;
4701 }
4702
4703 // DQ (12/28/2012): Adding support for templates.
4704 case V_SgTemplateVariableDeclaration:
4705
4706 case V_SgVariableDeclaration:
4707 {
4708 SgVariableDeclaration* derivedDeclaration = isSgVariableDeclaration(declaration);
4709 SgInitializedNamePtrList & variableList = derivedDeclaration->get_variables();
4710 SgInitializedNamePtrList::iterator i = variableList.begin();
4711 while ( i != variableList.end() )
4712 {
4714 ROSE_ASSERT(variable != NULL);
4715
4716 // DQ (10/20/2007): static data members declared outside the class scope don't generate symbols.
4717 if (variable->get_scope() == scope)
4718 {
4719 SgSymbol* symbol = new SgVariableSymbol(variable);
4720 ROSE_ASSERT(symbol != NULL);
4721
4722 // printf ("In SageInterface::rebuildSymbolTable() variable = %p building a new SgVariableSymbol = %p \n",variable,symbol);
4723
4724 SgName name = variable->get_name();
4725 symbolTable->insert(name,symbol);
4726 }
4727 else
4728 {
4729 // I think there is nothing to do in this case
4730 // printf ("In SageInterface::rebuildSymbolTable() This variable has a scope inconsistant with the symbol table: variable->get_scope() = %p scope = %p \n",variable->get_scope(),scope);
4731 }
4732
4733 i++;
4734 }
4735
4736 // DQ (10/13/2007): Need to look into variable declarations to see if there are defining declaration
4737 // that also force symbols to be built in the current scope!
4738 // ROSE_ASSERT(derivedDeclaration->get_variableDeclarationContainsBaseTypeDefiningDeclaration() == false);
4739 if (derivedDeclaration->get_variableDeclarationContainsBaseTypeDefiningDeclaration() == true)
4740 {
4741 // Build a SgClassDeclaration, SgEnumDeclaration associated symbol and add it to the symbol table.
4742 ROSE_ASSERT(symbolTable != NULL);
4743 ROSE_ASSERT(derivedDeclaration->get_baseTypeDefiningDeclaration() != NULL);
4744 supportForBaseTypeDefiningDeclaration ( symbolTable, derivedDeclaration->get_baseTypeDefiningDeclaration() );
4745 }
4746
4747 // ROSE_ASSERT(symbolList.empty() == false);
4748 break;
4749 }
4750
4751 case V_SgTemplateInstantiationDecl:
4752 {
4753 SgTemplateInstantiationDecl* derivedDeclaration = isSgTemplateInstantiationDecl(declaration);
4754#if 1
4755 // printf ("case SgTemplateInstantiationDecl: derivedDeclaration name = %s derivedDeclaration->get_declarationModifier().isFriend() = %s \n",
4756 // derivedDeclaration->get_name().str(),derivedDeclaration->get_declarationModifier().isFriend() ? "true" : "false");
4757
4758 if (scope == derivedDeclaration->get_scope())
4759 {
4760 SgSymbol* symbol = new SgClassSymbol(derivedDeclaration);
4761 // printf ("Inserting SgClassSymbol = %p into scope = %p = %s \n",symbol,scope,scope->class_name().c_str());
4762 ROSE_ASSERT(symbol != NULL);
4763 SgName name = derivedDeclaration->get_name();
4764#if 0
4765 // DQ (10/21/2007): The scopes should match
4766 if (scope != derivedDeclaration->get_scope())
4767 {
4768 printf ("Error: scopes don't match for derivedDeclaration = %p = %s \n",derivedDeclaration,derivedDeclaration->class_name().c_str());
4769 }
4770 ROSE_ASSERT(scope == derivedDeclaration->get_scope());
4771#endif
4772 symbolTable->insert(name,symbol);
4773 }
4774 else
4775 {
4776 // printf ("SgTemplateInstantiationDecl: scope = %p derivedDeclaration = %p = %s didn't match the scope \n",scope,derivedDeclaration,get_name(derivedDeclaration).c_str());
4777
4778 if (derivedDeclaration->get_declarationModifier().isFriend() == false)
4779 {
4780#if PRINT_DEVELOPER_WARNINGS
4781 printf ("Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->class_name().c_str());
4782#endif
4783 }
4784 }
4785#else
4786 SgSymbol* symbol = new SgClassSymbol(derivedDeclaration);
4787 ROSE_ASSERT(symbol != NULL);
4788 SgName name = derivedDeclaration->get_name();
4789 symbolTable->insert(name,symbol);
4790#endif
4791 break;
4792 }
4793
4794
4795 // DQ (12/24/2012): Added support for templates.
4796 case V_SgTemplateClassDeclaration:
4797
4798 case V_SgClassDeclaration:
4799 {
4800 SgClassDeclaration* derivedDeclaration = isSgClassDeclaration(declaration);
4801#if 1
4802 if (scope == derivedDeclaration->get_scope())
4803 {
4804 SgSymbol* symbol = NULL;
4805 if (isSgTemplateClassDeclaration(declaration) != NULL)
4806 symbol = new SgTemplateClassSymbol(derivedDeclaration);
4807 else
4808 symbol = new SgClassSymbol(derivedDeclaration);
4809
4810 ROSE_ASSERT(symbol != NULL);
4811 SgName name = derivedDeclaration->get_name();
4812 symbolTable->insert(name,symbol);
4813 }
4814 else
4815 {
4816 if (derivedDeclaration->get_declarationModifier().isFriend() == false)
4817 {
4818#if PRINT_DEVELOPER_WARNINGS
4819 printf ("Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->class_name().c_str());
4820#endif
4821 }
4822 }
4823#else
4824 SgSymbol* symbol = new SgClassSymbol(derivedDeclaration);
4825 ROSE_ASSERT(symbol != NULL);
4826 SgName name = derivedDeclaration->get_name();
4827 symbolTable->insert(name,symbol);
4828#endif
4829 break;
4830 }
4831
4832 case V_SgEnumDeclaration:
4833 {
4834 SgEnumDeclaration* derivedDeclaration = isSgEnumDeclaration(declaration);
4835 ROSE_ASSERT(derivedDeclaration != NULL);
4836 SgSymbol* symbol = new SgEnumSymbol(derivedDeclaration);
4837 ROSE_ASSERT(symbol != NULL);
4838 SgName name = derivedDeclaration->get_name();
4839 symbolTable->insert(name,symbol);
4840
4841 // DQ (10/18/2007): Fixed construction of symbol tabel to include enum fields.
4842 SgInitializedNamePtrList & enumFieldList = derivedDeclaration->get_enumerators();
4843 SgInitializedNamePtrList::iterator i = enumFieldList.begin();
4844
4845 // Iterate over enum fields and add each one to the symbol table.
4846 while (i != enumFieldList.end())
4847 {
4848 SgSymbol* enum_field_symbol = new SgEnumFieldSymbol(*i);
4849 ROSE_ASSERT(enum_field_symbol != NULL);
4850 SgName enum_field_name = (*i)->get_name();
4851 symbolTable->insert(enum_field_name,enum_field_symbol);
4852
4853 i++;
4854 }
4855
4856 break;
4857 }
4858
4859
4860 // DQ (2/18/2017): Added support for C++11 SgTemplateTypedefDeclaration.
4861 case V_SgTemplateTypedefDeclaration:
4862
4863 case V_SgTypedefDeclaration:
4864 {
4865 SgTypedefDeclaration* derivedDeclaration = isSgTypedefDeclaration(declaration);
4866 SgSymbol* symbol = new SgTypedefSymbol(derivedDeclaration);
4867 ROSE_ASSERT(symbol != NULL);
4868 SgName name = derivedDeclaration->get_name();
4869 symbolTable->insert(name,symbol);
4870#if 0
4871 printf ("In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration \n");
4872#endif
4873 // DQ (10/13/2007): Need to look into typedefs to see if there are defining declaration
4874 // that also force symbols to be built in the current scope!
4875 // ROSE_ASSERT(derivedDeclaration->get_typedefBaseTypeContainsDefiningDeclaration() == false);
4876 if (derivedDeclaration->get_typedefBaseTypeContainsDefiningDeclaration() == true)
4877 {
4878 // Build a SgClassDeclaration, SgEnumDeclaration associated symbol and add it to the symbol table.
4879 ROSE_ASSERT(symbolTable != NULL);
4880 ROSE_ASSERT(derivedDeclaration->get_baseTypeDefiningDeclaration() != NULL);
4881#if 0
4882 printf ("In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration: typedefBaseTypeContainsDefiningDeclaration == true calling supportForBaseTypeDefiningDeclaration() \n");
4883#endif
4884 supportForBaseTypeDefiningDeclaration ( symbolTable, derivedDeclaration->get_baseTypeDefiningDeclaration() );
4885 }
4886 else
4887 {
4888 // DQ (11/7/2007): If the typedef has a definition (e.g. function pointer) then build a symbol.
4889 SgDeclarationStatement* declaration = derivedDeclaration->get_declaration();
4890 if (declaration != NULL)
4891 {
4892#if 0
4893 printf ("In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration: typedefBaseTypeContainsDefiningDeclaration == false calling supportForBaseTypeDefiningDeclaration() \n");
4894#endif
4895 // DQ (12/27/2012): Debugging the support for copytest_2007_40_cpp.C (we don't want to build this symbol since it is associated with an outer scope).
4896 // supportForBaseTypeDefiningDeclaration ( symbolTable, derivedDeclaration->get_declaration() );
4897
4898 printf ("In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration: typedefBaseTypeContainsDefiningDeclaration == false: skipping call to supportForBaseTypeDefiningDeclaration() \n");
4899 }
4900 }
4901#if 0
4902 printf ("In SageInterface::rebuildSymbolTable(): Leaving case of SgTypedefDeclaration \n");
4903#endif
4904 break;
4905 }
4906
4907 case V_SgTemplateDeclaration:
4908 {
4909 SgTemplateDeclaration* derivedDeclaration = isSgTemplateDeclaration(declaration);
4910#if 1
4911 // DQ (10/21/2007): If this is a friend function in a class then we have to skip insertion of the symbol into this scope (this symbol table)
4912#if 0
4913 printf ("case V_SgTemplateDeclaration: derivedDeclaration = %p \n",derivedDeclaration);
4914 printf ("case V_SgTemplateDeclaration: derivedDeclaration->get_declarationModifier().isFriend() = %s \n",derivedDeclaration->get_declarationModifier().isFriend() ? "true" : "false");
4915 printf ("case V_SgTemplateDeclaration: derivedDeclaration->get_name() = %s \n",derivedDeclaration->get_name().str());
4916 printf ("case V_SgTemplateDeclaration: derivedDeclaration->get_string() = %s \n",derivedDeclaration->get_string().str());
4917#endif
4918 if (scope == derivedDeclaration->get_scope())
4919 {
4920 SgSymbol* symbol = new SgTemplateSymbol(derivedDeclaration);
4921 ROSE_ASSERT(symbol != NULL);
4922 SgName name = derivedDeclaration->get_name();
4923 symbolTable->insert(name,symbol);
4924 }
4925 else
4926 {
4927 if (derivedDeclaration->get_declarationModifier().isFriend() == false)
4928 {
4929#if PRINT_DEVELOPER_WARNINGS
4930 printf ("Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->class_name().c_str());
4931#endif
4932 }
4933 }
4934#else
4935 SgTemplateDeclaration* derivedDeclaration = isSgTemplateDeclaration(declaration);
4936 SgSymbol* symbol = new SgTemplateSymbol(derivedDeclaration);
4937 ROSE_ASSERT(symbol != NULL);
4938 SgName name = derivedDeclaration->get_name();
4939 symbolTable->insert(name,symbol);
4940#endif
4941 break;
4942 }
4943
4944 // Does this cause a symbol to be built? Seems that it should,
4945 // unless we always reference the non-aliased symbol (reuse it)!
4946 case V_SgNamespaceAliasDeclarationStatement:
4947 {
4948 SgNamespaceAliasDeclarationStatement* aliasDeclaration = isSgNamespaceAliasDeclarationStatement(declaration);
4949 ROSE_ASSERT(aliasDeclaration != NULL);
4950 ROSE_ASSERT(aliasDeclaration->get_namespaceDeclaration() != NULL);
4951
4952 SgNamespaceDeclarationStatement* derivedDeclaration = isSgNamespaceDeclarationStatement(aliasDeclaration->get_namespaceDeclaration());
4953 ROSE_ASSERT(derivedDeclaration != NULL);
4954
4955 // The constructor for the SgNamespaceSymbol is disturbingly different from the rest of the constructors.
4956 SgSymbol* symbol = new SgNamespaceSymbol(derivedDeclaration->get_name(),derivedDeclaration);
4957 ROSE_ASSERT(symbol != NULL);
4958 SgName name = derivedDeclaration->get_name();
4959 symbolTable->insert(name,symbol);
4960 // symbolList.push_back(symbol);
4961 // ROSE_ASSERT(symbolList.empty() == false);
4962 break;
4963 }
4964
4965 // Does this cause a symbol to be built? Seems that it should,
4966 // unless we always reference the non-aliased symbol (reuse it)!
4967 case V_SgNamespaceDeclarationStatement:
4968 {
4969 SgNamespaceDeclarationStatement* derivedDeclaration = isSgNamespaceDeclarationStatement(declaration);
4970 ROSE_ASSERT(derivedDeclaration != NULL);
4971
4972 // The constructor for the SgNamespaceSymbol is disturbingly different from the rest of the constructors.
4973 SgSymbol* symbol = new SgNamespaceSymbol(derivedDeclaration->get_name(),derivedDeclaration);
4974 ROSE_ASSERT(symbol != NULL);
4975 SgName name = derivedDeclaration->get_name();
4976 symbolTable->insert(name,symbol);
4977 // symbolList.push_back(symbol);
4978 // ROSE_ASSERT(symbolList.empty() == false);
4979 break;
4980 }
4981
4982 case V_SgUsingDirectiveStatement:
4983 case V_SgPragmaDeclaration:
4984 case V_SgTemplateInstantiationDirectiveStatement:
4985 case V_SgUsingDeclarationStatement:
4986 {
4987 // DQ (10/22/2005): Not sure if we have to worry about this declaration's appearance in the symbol table!
4988#if 0
4989 printf ("This declaration is ignored in rebuilding symbol table %p = %s = %s \n",*i,(*i)->class_name().c_str(),get_name(*i).c_str());
4990#endif
4991 break;
4992 }
4993
4994 case V_SgAsmStmt:
4995 {
4996 // DQ (8/13/2006): This is not really a declaration (I think). This will be fixed later.
4997#if 0
4998 printf ("An ASM statement (SgAsmStmt) declaration is not really a declaration %p = %s = %s \n",*i,(*i)->class_name().c_str(),get_name(*i).c_str());
4999#endif
5000 break;
5001 }
5002
5003 // Cases where declations are not used or referenced and so symbols are not required!
5004 case V_SgVariableDefinition:
5005 case V_SgFunctionParameterList:
5006 case V_SgCtorInitializerList:
5007 // These are not referenced so they don't need a symbol!
5008 {
5009 printf ("Special cases not handled %p = %s = %s \n",*i,(*i)->class_name().c_str(),get_name(*i).c_str());
5010 ROSE_ABORT();
5011 }
5012
5013 case V_SgStaticAssertionDeclaration:
5014 {
5015 // DQ (2/18/2017): This is not really a declaration (I think). This will be fixed later.
5016#if 0
5017 printf ("A static assertion statement (SgStaticAssertionDeclaration) declaration is not really a declaration %p = %s = %s \n",*i,(*i)->class_name().c_str(),get_name(*i).c_str());
5018#endif
5019 break;
5020 }
5021
5022 default:
5023 {
5024 printf ("Error: Default reached in rebuildSymbolTable declaration = %p = %s \n",declaration,declaration->class_name().c_str());
5025 ROSE_ABORT();
5026 }
5027 }
5028
5029 ROSE_ASSERT(symbolTable != NULL);
5030 ROSE_ASSERT(symbolTable->get_table() != NULL);
5031 }
5032 // printf ("DONE: Iterating through the declaration in this scope ... %p = %s = %s \n",*i,(*i)->class_name().c_str(),get_name(*i).c_str());
5033
5034 }
5035
5036 ROSE_ASSERT(symbolTable != NULL);
5037 ROSE_ASSERT(symbolTable->get_table() != NULL);
5038
5039#if 0
5040 printf ("Leaving SageInterface::rebuildSymbolTable(): fixup declarations in Symbol Table from %p = %s \n",scope,scope->class_name().c_str());
5041#endif
5042
5043#if 0
5044 printf ("Symbol Table from %p = %s at: \n",scope,scope->class_name().c_str());
5045 scope->get_file_info()->display("Symbol Table Location");
5046 symbolTable->print("Called from SageInterface::rebuildSymbolTable()");
5047#endif
5048 }
5049
5050
5051// #ifndef USE_ROSE
5052
5053void
5055 {
5056 // This function is called by the SageInterface::rebuildSymbolTable().
5057 // It resets references to old symbols to the new symbols (just built).
5058 // All pairs of old/new symbols are also saved in the object:
5059 // SgCopyHelp::copiedNodeMapType copiedNodeMap
5060
5061#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
5062 ROSE_ASSERT(this_scope != NULL);
5063 ROSE_ASSERT(copy_scope != NULL);
5064
5065#if 0
5066 printf ("In fixupReferencesToSymbols(this_scope = %p = %s = %s, copy_scope = %p = %s = %s) \n",
5067 this_scope,this_scope->class_name().c_str(),get_name(this_scope).c_str(),
5068 copy_scope,copy_scope->class_name().c_str(),get_name(copy_scope).c_str());
5069#endif
5070
5071 SgSymbolTable* this_symbolTable = this_scope->get_symbol_table();
5072 SgSymbolTable* copy_symbolTable = copy_scope->get_symbol_table();
5073#if 0
5074 printf ("Before fixup: this scope = %p = %s this_symbolTable->get_table()->size() = %" PRIuPTR " \n",this_scope,this_scope->class_name().c_str(),this_symbolTable->get_table()->size());
5075 printf ("Before fixup: copy scope = %p = %s copy_symbolTable->get_table()->size() = %" PRIuPTR " \n",copy_scope,copy_scope->class_name().c_str(),copy_symbolTable->get_table()->size());
5076#endif
5077
5078 // DQ (3/4/2009): For now just output a warning, but this might be a more serious problem.
5079 // Since the symbol table size of the copy is larger than that of the original it might
5080 // be that a symbol is enterted twice by the copy mechanism. If so I want to fix this.
5081 if (this_symbolTable->get_table()->size() != copy_symbolTable->get_table()->size())
5082 {
5083 if (SgProject::get_verbose() > 0)
5084 {
5085 printf ("Before fixup: this scope = %p = %s this_symbolTable->get_table()->size() = %" PRIuPTR " \n",this_scope,this_scope->class_name().c_str(),this_symbolTable->get_table()->size());
5086 printf ("Before fixup: copy scope = %p = %s copy_symbolTable->get_table()->size() = %" PRIuPTR " \n",copy_scope,copy_scope->class_name().c_str(),copy_symbolTable->get_table()->size());
5087 printf ("Warning the symbols tables in these different scopes are different sizes \n");
5088 }
5089 }
5090 // ROSE_ASSERT(this_symbolTable->get_table()->size() <= copy_symbolTable->get_table()->size());
5091
5092 SgSymbolTable::hash_iterator i = this_symbolTable->get_table()->begin();
5093
5094 // This is used to fixup the AST by resetting references to IR nodes (leveraged from AST merge).
5095 std::map<SgNode*, SgNode*> replacementMap;
5096 int counter = 0;
5097 while (i != this_symbolTable->get_table()->end())
5098 {
5099 ROSE_ASSERT ( isSgSymbol( (*i).second ) != NULL );
5100
5101 SgName name = (*i).first;
5102 // SgSymbol* symbol = isSgSymbol((*i).second);
5103 SgSymbol* symbol = (*i).second;
5104 ROSE_ASSERT ( symbol != NULL );
5105
5106 SgSymbol* associated_symbol = NULL;
5107#if 0
5108 printf ("Symbol number: %d (pair.first (SgName) = %s) pair.second (SgSymbol) = %p sage_class_name() = %s \n",counter,i->first.str(),i->second,i->second->class_name().c_str());
5109#endif
5110 // Look for the associated symbol in the copy_scope's symbol table.
5111 SgSymbolTable::hash_iterator associated_symbol_iterator = copy_symbolTable->get_table()->find(name);
5112
5113 // Note that this is a multi-map and for C++ a number of symbols can have the same name
5114 // (though not the same type of symbol) so we have to iterator over the symbols of the
5115 // same name so that we can identify the associated symbol.
5116 while (associated_symbol_iterator != copy_symbolTable->get_table()->end() && associated_symbol_iterator->first == name)
5117 {
5118 if ( associated_symbol_iterator->second->variantT() == symbol->variantT() )
5119 {
5120 associated_symbol = associated_symbol_iterator->second;
5121 }
5122
5123 associated_symbol_iterator++;
5124 }
5125
5126 if (associated_symbol != NULL)
5127 {
5128 ROSE_ASSERT ( associated_symbol != NULL );
5129
5130 // Check to make sure that this is correct
5131 ROSE_ASSERT(copy_scope->symbol_exists(associated_symbol) == true);
5132
5133 // Add the SgGlobal referenece to the replacementMap
5134 // replacementMap.insert(pair<SgNode*,SgNode*>(originalFileGlobalScope,scope));
5135 // DQ (23/1/2009): Find the reference to symbol and replace it with associated_symbol.
5136 replacementMap.insert(pair<SgNode*,SgNode*>(symbol,associated_symbol));
5137
5138 // DQ (3/1/2009): This is backwards
5139 // replacementMap.insert(pair<SgNode*,SgNode*>(associated_symbol,symbol));
5140
5141 // DQ (3/2/2009): accumulate the symbol pair into the SgCopyHelp object (to support the outliner).
5142 // Actually this should also improve the robustness of the outliner.
5143 help.get_copiedNodeMap().insert(pair<const SgNode*,SgNode*>(symbol,associated_symbol));
5144 }
5145 else
5146 {
5147 // DQ (3/4/2009): This case was broken out because copytest2007_14.C fails here.
5148 if (SgProject::get_verbose() > 0)
5149 {
5150 printf ("Warning: Symbol number: %d (pair.first (SgName) = %s) pair.second (SgSymbol) = %p sage_class_name() = %s \n",counter,i->first.str(),i->second,i->second->class_name().c_str());
5151 printf ("Warning: associated_symbol == NULL, need to investigate this (ignoring for now) \n");
5152 }
5153 }
5154
5155 counter++;
5156
5157 i++;
5158 }
5159
5160#if 0
5161 printf ("\n\n************************************************************\n");
5162 printf ("fixupReferencesToSymbols(this_scope = %p copy_scope = %p = %s = %s): calling Utils::edgePointerReplacement() \n",this_scope,copy_scope,copy_scope->class_name().c_str(),get_name(copy_scope).c_str());
5163#endif
5164
5165 Rose::AST::Utility::edgePointerReplacement(copy_scope,replacementMap);
5166
5167#if 0
5168 printf ("fixupReferencesToSymbols(): calling Utils::edgePointerReplacement(): DONE \n");
5169 printf ("************************************************************\n\n");
5170
5171 printf ("\n\n After replacementMapTraversal(): intermediateDeleteSet: \n");
5172 displaySet(intermediateDeleteSet,"After Utils::edgePointerReplacement");
5173
5174 printf ("After fixup: this_symbolTable->get_table()->size() = %" PRIuPTR " \n",this_symbolTable->get_table()->size());
5175 printf ("After fixup: copy_symbolTable->get_table()->size() = %" PRIuPTR " \n",copy_symbolTable->get_table()->size());
5176#endif
5177
5178 // DQ (3/1/2009): find a case where this code is tested.
5179 // ROSE_ASSERT(this_symbolTable->get_table()->size() == 0);
5180 // ROSE_ASSERT(isSgClassDefinition(copy_scope) == NULL);
5181#endif
5182
5183#if 0
5184 printf ("Exiting as a test in fixupReferencesToSymbols() \n");
5185 ROSE_ABORT();
5186#endif
5187 }
5188
5189// #endif
5190
5191#ifndef USE_ROSE
5192
5193std::vector<SgFile*>
5195 {
5196 // This function uses a memory pool traversal specific to the SgFile IR nodes
5197 class FileTraversal : public ROSE_VisitTraversal
5198 {
5199 public:
5200 vector<SgFile*> fileList;
5201 void visit ( SgNode* node)
5202 {
5203 SgFile* file = isSgFile(node);
5204 ROSE_ASSERT(file != NULL);
5205 if (file != NULL)
5206 {
5207 fileList.push_back(file);
5208 }
5209 };
5210
5211 virtual ~FileTraversal() {}
5212 };
5213
5214 FileTraversal fileTraversal;
5215
5216 // traverse just the SgFile nodes (both the SgSourceFile and SgBinaryComposite IR nodes)!
5217 // SgFile::visitRepresentativeNode(fileTraversal);
5219#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5221#endif
5222
5223 // This would alternatively traverse all IR nodes in thememory pool!
5224 // fileTraversal.traverseMemoryPool();
5225
5226 // TV (06/24/2013): This fail when calling SageBuilder::buildVariableDeclaration(...) without any file created.
5227 // DQ (10/11/2014): This is allowed to be empty (required for new aterm support).
5228 // ROSE_ASSERT(fileTraversal.fileList.empty() == false);
5229
5230 return fileTraversal.fileList;
5231 }
5232
5233#endif
5234
5235// #ifndef USE_ROSE
5236
5237// DQ (4/17/2015): I think this function should be removed since it interferes
5238// with the concept of having more than one SgProject node.
5239// This function uses a memory pool traversal specific to the SgProject IR nodes
5240SgProject*
5242{
5243#if 0
5244 class ProjectTraversal : public ROSE_VisitTraversal
5245 {
5246 public:
5247 SgProject * project;
5248 void visit ( SgNode* node)
5249 {
5250 project = isSgProject(node);
5251 ROSE_ASSERT(project!= NULL);
5252 };
5253 virtual ~ProjectTraversal() {}
5254 };
5255
5256 ProjectTraversal projectTraversal;
5257 SgProject::visitRepresentativeNode(projectTraversal);
5258 return projectTraversal.project;
5259#endif
5260 std::vector<SgProject* > resultlist = getSgNodeListFromMemoryPool<SgProject>();
5261 if (resultlist.empty())
5262 return NULL;
5263 ROSE_ASSERT(resultlist.size()==1);
5264 return resultlist[0];
5265}
5266
5267SgProject*
5269 return getEnclosingNode<SgProject>(node, true /*includingSelf*/);
5270}
5271
5273 SgFunctionDeclaration * ret = NULL;
5274 if (isSgFunctionRefExp(func))
5275 {
5276 return isSgFunctionRefExp(func)->get_symbol()->get_declaration();
5277 }
5278 else if (isSgDotExp(func) || isSgArrowExp(func))
5279 {
5280 SgExpression* func2 = isSgBinaryOp(func)->get_rhs_operand();
5281 if (isSgMemberFunctionRefExp(func2))
5282 return isSgMemberFunctionRefExp(func2)->get_symbol()->get_declaration();
5283 else
5284 {
5285 cerr<<"Warning in SageInterface::getDeclarationOfNamedFunction(): rhs operand of dot or arrow operations is not a member function, but a "<<func2->class_name()<<endl;
5286 }
5287 }
5288
5289 return ret;
5290}
5291
5293 SgExprListExp* el = stmt->get_forall_header();
5294 const SgExpressionPtrList& ls = el->get_expressions();
5295 if (ls.empty()) return 0;
5296 if (isSgAssignOp(ls.back())) return 0;
5297 return ls.back();
5298}
5299
5300//Find all SgPntrArrRefExp under astNode, add the referenced dim_info SgVarRefExp (if any) into NodeList_t
5301void SageInterface::addVarRefExpFromArrayDimInfo(SgNode * astNode, Rose_STL_Container<SgNode *>& NodeList_t)
5302{
5303 ASSERT_not_null(astNode);
5304 Rose_STL_Container<SgNode*> arr_exp_list = NodeQuery::querySubTree(astNode,V_SgPntrArrRefExp);
5305 for (SgNode* expr : arr_exp_list)
5306 {
5307 SgPntrArrRefExp* arr_exp = isSgPntrArrRefExp(expr);
5308 ASSERT_not_null(arr_exp);
5309 Rose_STL_Container<SgNode*> refList = NodeQuery::querySubTree(arr_exp->get_lhs_operand(),V_SgVarRefExp);
5310 for (SgNode* ref : refList)
5311 {
5312 SgVarRefExp* cur_ref = isSgVarRefExp(ref);
5313 ASSERT_not_null(cur_ref);
5314 SgVariableSymbol * sym = cur_ref->get_symbol();
5315 ASSERT_not_null(sym);
5316 SgInitializedName * iname = sym->get_declaration();
5317 ASSERT_not_null(iname);
5318 SgArrayType * a_type = isSgArrayType(iname->get_typeptr());
5319 if (a_type && a_type->get_dim_info())
5320 {
5321 Rose_STL_Container<SgNode*> dim_ref_list = NodeQuery::querySubTree(a_type->get_dim_info(),V_SgVarRefExp);
5322 for (Rose_STL_Container<SgNode*>::iterator iter2 = dim_ref_list.begin(); iter2 != dim_ref_list.end(); iter2++)
5323 {
5324 SgVarRefExp* dim_ref = isSgVarRefExp(*iter2);
5325 NodeList_t.push_back(dim_ref);
5326 }
5327 }
5328 }
5329 } // end for
5330}
5331
5332
5333// DQ (11/25/2020): This disables these non-inlined functions in favor of
5334// inlined versions of the functions in the sageInterface.h (header file).
5335#if (INLINE_OPTIMIZED_IS_LANGUAGE_KIND_FUNCTIONS == 0)
5336bool
5338 {
5339#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5340 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5341 return Rose::is_Ada_language;
5342#else
5343 bool returnValue = false;
5344
5345 vector<SgFile*> fileList = generateFileList();
5346
5347 int size = (int)fileList.size();
5348 for (int i = 0; i < size; i++)
5349 {
5350 if (fileList[i]->get_Ada_only() == true)
5351 returnValue = true;
5352 }
5353
5354 return returnValue;
5355#endif
5356 }
5357
5358bool
5360 {
5361#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5362 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5363 return Rose::is_C_language;
5364#else
5365 bool returnValue = false;
5366
5367 vector<SgFile*> fileList = generateFileList();
5368
5369 int size = (int)fileList.size();
5370 for (int i = 0; i < size; i++)
5371 {
5372 if (fileList[i]->get_C_only() == true)
5373 returnValue = true;
5374 }
5375
5376 return returnValue;
5377#endif
5378 }
5379
5380bool
5382 {
5383#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5384 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5385 return Rose::is_OpenMP_language;
5386#else
5387 bool returnValue = false;
5388
5389 vector<SgFile*> fileList = generateFileList();
5390
5391 int size = (int)fileList.size();
5392 for (int i = 0; i < size; i++)
5393 {
5394 if (fileList[i]->get_openmp() == true)
5395 returnValue = true;
5396 }
5397
5398 return returnValue;
5399#endif
5400 }
5401
5402bool
5404 {
5405#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5406 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5407 return Rose::is_UPC_language;
5408#else
5409 bool returnValue = false;
5410
5411 vector<SgFile*> fileList = generateFileList();
5412
5413 int size = (int)fileList.size();
5414 for (int i = 0; i < size; i++)
5415 {
5416 if (fileList[i]->get_UPC_only() == true)
5417 returnValue = true;
5418 }
5419
5420 return returnValue;
5421#endif
5422 }
5423
5424//FMZ
5425bool
5427 {
5428#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5429 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5430 return Rose::is_CAF_language;
5431#else
5432 bool returnValue = false;
5433
5434 vector<SgFile*> fileList = generateFileList();
5435
5436 int size = (int)fileList.size();
5437 for (int i = 0; i < size; i++)
5438 {
5439 if (fileList[i]->get_CoArrayFortran_only()==true)
5440 returnValue = true;
5441 }
5442
5443 return returnValue;
5444#endif
5445 }
5446
5447
5448// true if any of upc_threads is set to >0 via command line: -rose:upc_threads n
5449bool
5451 {
5452#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5453 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5454 return Rose::is_UPC_dynamic_threads;
5455#else
5456 bool returnValue = false;
5457
5458 vector<SgFile*> fileList = generateFileList();
5459
5460 int size = (int)fileList.size();
5461 for (int i = 0; i < size; i++)
5462 {
5463 if (fileList[i]->get_upc_threads() > 0)
5464 returnValue = true;
5465 }
5466
5467 return returnValue;
5468#endif
5469 }
5470
5471
5472
5473bool
5475 {
5476#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5477 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5478 return Rose::is_C99_language;
5479#else
5480 bool returnValue = false;
5481
5482 vector<SgFile*> fileList = generateFileList();
5483
5484 int size = (int)fileList.size();
5485 for (int i = 0; i < size; i++)
5486 {
5487 if (fileList[i]->get_C99_only() == true)
5488 returnValue = true;
5489 }
5490
5491 return returnValue;
5492#endif
5493 }
5494
5495bool
5497 {
5498#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5499 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5500 return Rose::is_Cxx_language;
5501#else
5502 bool returnValue = false;
5503
5504 vector<SgFile*> fileList = generateFileList();
5505
5506 int size = (int)fileList.size();
5507 for (int i = 0; i < size; i++)
5508 {
5509 // DQ (8/19/2007): Make sure this is not a Fortran code!
5510 if (fileList[i]->get_Cxx_only() == true)
5511 {
5512 ROSE_ASSERT(fileList[i]->get_Fortran_only() == false && fileList[i]->get_C99_only() == false && fileList[i]->get_C_only() == false && fileList[i]->get_binary_only() == false);
5513
5514 returnValue = true;
5515 }
5516 }
5517
5518 return returnValue;
5519#endif
5520 }
5521
5522bool
5524 {
5525#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5526 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5527 return Rose::is_Java_language;
5528#else
5529 bool returnValue = false;
5530
5531 vector<SgFile*> fileList = generateFileList();
5532
5533 int size = (int)fileList.size();
5534 for (int i = 0; i < size; i++)
5535 {
5536 if (fileList[i]->get_Java_only() == true)
5537 returnValue = true;
5538 }
5539
5540 return returnValue;
5541#endif
5542 }
5543
5544bool
5546 {
5547#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5548 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5549 return Rose::is_Jvm_language;
5550#else
5551 bool returnValue = false;
5552
5553 vector<SgFile*> fileList = generateFileList();
5554
5555 int size = (int)fileList.size();
5556 for (int i = 0; i < size; i++)
5557 {
5558 if (fileList[i]->get_Jvm_only() == true)
5559 returnValue = true;
5560 }
5561
5562 return returnValue;
5563#endif
5564 }
5565
5566// Rasmussen (4/4/2018): Added Jovial
5567bool
5569 {
5570#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5571 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5572 return Rose::is_Jovial_language;
5573#else
5574 bool returnValue = false;
5575
5576 vector<SgFile*> fileList = generateFileList();
5577
5578 int size = (int)fileList.size();
5579 for (int i = 0; i < size; i++)
5580 {
5581 if (fileList[i]->get_Jovial_only() == true)
5582 returnValue = true;
5583 }
5584
5585 return returnValue;
5586#endif
5587 }
5588
5589
5590bool
5592 {
5593#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5594 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5595 return Rose::is_Fortran_language;
5596#else
5597 bool returnValue = false;
5598
5599 vector<SgFile*> fileList = generateFileList();
5600
5601 int size = (int)fileList.size();
5602 for (int i = 0; i < size; i++)
5603 {
5604 if (fileList[i]->get_Fortran_only() == true)
5605 returnValue = true;
5606 }
5607
5608 return returnValue;
5609#endif
5610 }
5611
5612
5613bool
5615 {
5616#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5617 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5618 return Rose::is_binary_executable;
5619#else
5620 bool returnValue = false;
5621
5622 vector<SgFile*> fileList = generateFileList();
5623
5624 int size = (int)fileList.size();
5625 for (int i = 0; i < size; i++)
5626 {
5627 if (fileList[i]->get_binary_only() == true)
5628 returnValue = true;
5629 }
5630
5631 return returnValue;
5632#endif
5633 }
5634
5635bool
5637 {
5638#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5639 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5640 return Rose::is_PHP_language;
5641#else
5642 bool returnValue = false;
5643
5644 vector<SgFile*> fileList = generateFileList();
5645
5646 int size = (int)fileList.size();
5647 for (int i = 0; i < size; i++)
5648 {
5649 if (fileList[i]->get_PHP_only() == true)
5650 returnValue = true;
5651 }
5652
5653 return returnValue;
5654#endif
5655 }
5656
5657bool
5659 {
5660#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5661 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5662 return Rose::is_Python_language;
5663#else
5664 bool returnValue = false;
5665
5666 vector<SgFile*> fileList = generateFileList();
5667
5668 int size = (int)fileList.size();
5669 for (int i = 0; i < size; i++)
5670 {
5671 if (fileList[i]->get_Python_only() == true)
5672 returnValue = true;
5673 }
5674
5675 return returnValue;
5676#endif
5677 }
5678
5679bool
5681 {
5682#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5683 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5684 return Rose::is_Cuda_language;
5685#else
5686 bool returnValue = false;
5687
5688 vector<SgFile*> fileList = generateFileList();
5689
5690 int size = (int)fileList.size();
5691 for (int i = 0; i < size; i++)
5692 {
5693 if (fileList[i]->get_Cuda_only() == true)
5694 returnValue = true;
5695 }
5696
5697 return returnValue;
5698#endif
5699 }
5700
5701bool
5703 {
5704#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5705 // DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
5706 return Rose::is_OpenCL_language;
5707#else
5708 bool returnValue = false;
5709
5710 vector<SgFile*> fileList = generateFileList();
5711
5712 int size = (int)fileList.size();
5713 for (int i = 0; i < size; i++)
5714 {
5715 if (fileList[i]->get_OpenCL_only() == true)
5716 returnValue = true;
5717 }
5718
5719 return returnValue;
5720#endif
5721 }
5722
5723// for if (INLINE_OPTIMIZED_IS_LANGUAGE_KIND_FUNCTIONS == 0)
5724#endif
5725
5730
5735
5740
5745
5750
5751// Languages that may have scopes that contain statements that are not only declarations.
5752// For Fortran and Jovial (at least), function definitions may be declared at the end of procedures.
5757
5758// DQ (10/5/2006): Added support for faster (non-quadratic) computation of unique
5759// labels for scopes in a function (as required for name mangling).
5760void
5762 {
5763 ASSERT_not_null(functionDefinition);
5764 std::map<SgNode*,int> & scopeMap = functionDefinition->get_scope_number_list();
5765
5766 // Clear the cache of stored (scope,integer) pairs
5767 scopeMap.erase(scopeMap.begin(),scopeMap.end());
5768
5769 ASSERT_require(scopeMap.empty() == true);
5770 ASSERT_require(functionDefinition->get_scope_number_list().empty() == true);
5771 }
5772
5773#ifndef USE_ROSE
5774
5775// DQ (10/5/2006): Added support for faster (non-quadratic) computation of unique
5776// labels for scopes in a function (as required for name mangling).
5777void
5779 {
5780 ROSE_ASSERT(functionDefinition != NULL);
5781 // std::map<SgNode*,int> & scopeMap = functionDefinition->get_scope_number_list();
5782 // ROSE_ASSERT(scopeMap.empty() == true);
5783 ROSE_ASSERT(functionDefinition->get_scope_number_list().empty() == true);
5784
5785 // Preorder traversal to uniquely label the scopes (SgScopeStatements)
5786 class ScopeNumberingTraversal : public AstSimpleProcessing
5787 {
5788 public:
5789 ScopeNumberingTraversal() : count (0), storedFunctionDefinition(NULL) {}
5790 void visit (SgNode* node)
5791 {
5792 SgScopeStatement* scope = isSgScopeStatement (node);
5793 if (scope != NULL)
5794 {
5795 // Set the function definition
5796 SgFunctionDefinition* testFunctionDefinition = isSgFunctionDefinition(scope);
5797 if (testFunctionDefinition != NULL && storedFunctionDefinition == NULL)
5798 {
5799 ROSE_ASSERT(storedFunctionDefinition == NULL);
5800 storedFunctionDefinition = testFunctionDefinition;
5801 }
5802
5803 // This should now be set (since the root of each traversal is a SgFunctionDefinition).
5804 ROSE_ASSERT(storedFunctionDefinition != NULL);
5805
5806 count++;
5807
5808 std::map<SgNode*,int> & scopeMap = storedFunctionDefinition->get_scope_number_list();
5809 scopeMap.insert(pair<SgNode*,int>(scope,count));
5810#if 0
5811 string functionName = storedFunctionDefinition->get_declaration()->get_name().str();
5812 printf ("In function = %s insert scope = %p = %s with count = %d into local map (size = %d) \n",
5813 functionName.c_str(),scope,scope->class_name().c_str(),count,scopeMap.size());
5814#endif
5815 }
5816 }
5817
5818 private:
5819 int count; // running total of scopes found in the input function
5820 SgFunctionDefinition* storedFunctionDefinition;
5821 };
5822
5823 // Now buid the traveral object and call the traversal (preorder) on the function definition.
5824 ScopeNumberingTraversal traversal;
5825 traversal.traverse(functionDefinition, preorder);
5826 }
5827
5828#endif
5829
5830#ifndef USE_ROSE
5831
5832#if 0
5833// DQ (6/26/2007): These are removed and the support is added to SgNode to support a single mangled name cache.
5834// DQ (10/5/2006): Added support for faster (non-quadratic) computation of unique
5835// labels for scopes in a function (as required for name mangling).
5836void
5838 {
5839 ROSE_ASSERT(globalScope != NULL);
5840 std::map<SgNode*,std::string> & mangledNameCache = globalScope->get_mangledNameCache();
5841
5842 // Clear the cache of stored (scope,integer) pairs
5843 mangledNameCache.erase(mangledNameCache.begin(),mangledNameCache.end());
5844
5845 ROSE_ASSERT(mangledNameCache.empty() == true);
5846 ROSE_ASSERT(globalScope->get_mangledNameCache().empty() == true);
5847 }
5848
5849// DQ (10/5/2006): Added support for faster (non-quadratic) computation of unique
5850// labels for scopes in a function (as required for name mangling).
5851void
5853 {
5854 ROSE_ASSERT(globalScope != NULL);
5855 ROSE_ASSERT(globalScope->get_mangledNameCache().empty() == true);
5856
5857 // Preorder traversal to uniquely label the scopes (SgScopeStatements)
5858 class MangledNameTraversal : public AstSimpleProcessing
5859 {
5860 public:
5861 MangledNameTraversal() : storedGlobalScope(NULL) {}
5862 void visit (SgNode* node)
5863 {
5864 SgFunctionDeclaration* mangleableNode = isSgFunctionDeclaration(node);
5865 if ( (mangleableNode != NULL) || (isSgGlobal(node) != NULL) )
5866 {
5867 // Set the global scope
5868 SgGlobal* testGlobalScope = isSgGlobal(mangleableNode);
5869 if (testGlobalScope != NULL && storedGlobalScope == NULL)
5870 {
5871 ROSE_ASSERT(storedGlobalScope == NULL);
5872 storedGlobalScope = testGlobalScope;
5873 }
5874
5875 // This should now be set (since the root of each traversal is a SgFunctionDefinition).
5876 ROSE_ASSERT(storedGlobalScope != NULL);
5877
5878 string mangledName = mangleableNode->get_mangled_name();
5879 // printf ("mangledName = %s \n",mangledName.c_str());
5880
5881 std::map<SgNode*,std::string> & mangledNameCache = storedGlobalScope->get_mangledNameCache();
5882 mangledNameCache.insert(pair<SgNode*,std::string>(mangleableNode,mangledName));
5883#if 0
5884 string nodeName = get_name(mangleableNode);
5885 printf ("At node = %p = %s = %s in local map (size = %d) \n",
5886 mangleableNode,mangleableNode->class_name().c_str(),nodeName.c_str(),mangledNameCache.size());
5887#endif
5888 }
5889 }
5890
5891 private:
5892 SgGlobal* storedGlobalScope;
5893 };
5894
5895 // Now buid the traveral object and call the traversal (preorder) on the function definition.
5896 MangledNameTraversal traversal;
5897 traversal.traverse(globalScope, preorder);
5898 }
5899#endif
5900
5901
5902string
5904 {
5905 // The TransformationSupport is not defined yet (I forget the
5906 // details but I recall that there is a reason why this is this way).
5907 // SgGlobal* globalScope = TransformationSupport::getGlobalScope(astNode);
5908#if 0
5909 SgGlobal* globalScope = isSgGlobal(astNode);
5910
5911 if (globalScope == NULL && isSgFile(astNode) != NULL)
5912 {
5913 globalScope = isSgFile(astNode)->get_globalScope();
5914 ROSE_ASSERT(globalScope != NULL);
5915 }
5916
5917 if (globalScope == NULL && isSgProject(astNode) != NULL)
5918 {
5919 // Check to make sure that the SgFile can be uniquely determined
5920 ROSE_ASSERT( isSgProject(astNode)->get_fileList()->size() == 1 );
5921 globalScope = isSgProject(astNode)->get_fileList()->operator[](0)->get_globalScope();
5922 ROSE_ASSERT(globalScope != NULL);
5923 }
5924
5925 SgNode* temp = astNode;
5926 while (temp->get_parent() != NULL && globalScope == NULL)
5927 {
5928 temp = temp->get_parent();
5929 globalScope = isSgGlobal(temp);
5930 }
5931 ROSE_ASSERT(globalScope != NULL);
5932#endif
5933
5934 // std::map<SgNode*,std::string> & mangledNameCache = globalScope->get_mangledNameCache();
5935 std::map<SgNode*,std::string> & mangledNameCache = SgNode::get_globalMangledNameMap();
5936
5937 // Build an iterator
5938 std::map<SgNode*,std::string>::iterator i = mangledNameCache.find(astNode);
5939
5940 string mangledName;
5941 if (i != mangledNameCache.end())
5942 {
5943 // get the precomputed mangled name!
5944 //~ printf ("Mangled name IS found in cache (node = %p = %s) \n",astNode,astNode->class_name().c_str());
5945 mangledName = i->second;
5946 }
5947 else
5948 {
5949 // mangled name not found in cache!
5950 //~ printf ("Mangled name NOT found in cache (node = %p = %s) \n",astNode,astNode->class_name().c_str());
5951 }
5952
5953 return mangledName;
5954 }
5955
5956#define DEBUG_SAGE_INTERFACE_ADD_MANGLED_TO_CACHE 0
5957#define DEBUG_MANGLED_SHORTNAME 1
5958
5959//#ifdef DEBUG_MANGLED_SHORTNAME
5960//std::unordered_map<uint64_t, std::string> SageInterface::mangledNameHashCollisionCheckMap;
5961//#endif
5962
5963std::string
5964SageInterface::addMangledNameToCache( SgNode* astNode, const std::string & oldMangledName)
5965 {
5966#if DEBUG_SAGE_INTERFACE_ADD_MANGLED_TO_CACHE
5967 printf ("In SageInterface::addMangledNameToCache(): TOP: astNode = %p = %s oldMangledName = %s \n",astNode,astNode->class_name().c_str(),oldMangledName.c_str());
5968#endif
5969
5970//#define DEBUG_MANGLED_SHORTNAME 1
5971#ifdef DEBUG_MANGLED_SHORTNAME
5972 static std::unordered_map<uint64_t, std::string> mangledNameHashCollisionCheckMap;
5973#endif
5974
5975
5976#if 0
5977 SgGlobal* globalScope = isSgGlobal(astNode);
5978
5979 if (globalScope == NULL && isSgFile(astNode) != NULL)
5980 {
5981 globalScope = isSgFile(astNode)->get_globalScope();
5982 ROSE_ASSERT(globalScope != NULL);
5983 }
5984
5985 if (globalScope == NULL && isSgProject(astNode) != NULL)
5986 {
5987 // Check to make sure that the SgFile can be uniquely determined
5988 ROSE_ASSERT( isSgProject(astNode)->get_fileList()->size() == 1 );
5989 globalScope = isSgProject(astNode)->get_fileList()->operator[](0)->get_globalScope();
5990 ROSE_ASSERT(globalScope != NULL);
5991 }
5992
5993 SgNode* temp = astNode;
5994 while (temp->get_parent() != NULL && globalScope == NULL)
5995 {
5996 temp = temp->get_parent();
5997 globalScope = isSgGlobal(temp);
5998 }
5999 ROSE_ASSERT(globalScope != NULL);
6000#endif
6001
6002 std::map<SgNode*,std::string> & mangledNameCache = SgNode::get_globalMangledNameMap();
6003
6004 std::string mangledName;
6005
6006 if (SgProject::get_mangled_noshortname() == false) {
6007 std::map<std::string, uint64_t> & shortMangledNameCache = SgNode::get_shortMangledNameCache();
6008
6009 if (oldMangledName.size() > 40) {
6010 std::map<std::string, uint64_t>::const_iterator shortMNIter = shortMangledNameCache.find(oldMangledName);
6011 uint64_t idNumber = 0;
6012 if (shortMNIter != shortMangledNameCache.end())
6013 {
6014 idNumber = shortMNIter->second;
6015
6016#ifdef DEBUG_MANGLED_SHORTNAME
6017 //Check for hash colisions, if we found an idNumber, but the long mangled name is different, we have a problem
6018 auto collisionIt = mangledNameHashCollisionCheckMap.find(idNumber);
6019 if(collisionIt != mangledNameHashCollisionCheckMap.end() &&
6020 oldMangledName != shortMNIter->first)
6021 {
6022 mlog[Sawyer::Message::Common::ERROR] <<" Got a short mangled name collision. \n "<<
6023 oldMangledName << " and \n " << shortMNIter->first << " \n" <<
6024 "have the same idNumber of: " << Combinatorics::toBase62String(idNumber) << " " << shortMNIter->second << endl;
6025 exit(12);
6026 } else {
6027 mangledNameHashCollisionCheckMap[idNumber] = oldMangledName;
6028 }
6029#endif //DEBUG_MANGLED_SHORTNAME
6030
6031 }
6032 else
6033 {
6035 hasher.insert(oldMangledName);
6036 hasher.digest();
6037 idNumber = hasher.make64Bits();
6038 shortMangledNameCache.insert(std::pair<std::string, uint64_t>(oldMangledName, idNumber));
6039 }
6040
6041 std::ostringstream mn;
6042 mn << 'L' << Combinatorics::toBase62String(idNumber) << 'R';
6043 mangledName = mn.str();
6044 } else {
6045 mangledName = oldMangledName;
6046 }
6047 } else {
6048
6049 // DQ (7/24/2012): Note that using this option can cause some test codes using operators that have
6050 // difficult names (conversion operators to user-defined types) to fail. See test2004_141.C for example.
6051 // The conversion operator "operator T&() const;" will fail because the character "&" will remain in
6052 // mangled name. The substring coding changes the strings for the mangled names and this effectively
6053 // removes the special characters, but there could be cases where they might remain.
6054
6055 // DQ (3/27/2012): Use this as a mechanism to limit the I/O but still output a warning infrequently.
6056 static unsigned long counter = 0;
6057
6058 // DQ (3/27/2012): Use this as a mechanism to limit the I/O but still output a warning infrequently.
6059 // This supports debugging the new EDG 4.x interface...
6060 if (counter++ % 500 == 0)
6061 {
6062 printf ("WARNING: In SageInterface::addMangledNameToCache(): Using longer forms of mangled names (can cause some function names with embedded special characters to fail; test2004_141.C) \n");
6063 }
6064 mangledName = oldMangledName;
6065}
6066
6067 // DQ (6/26/2007): Output information useful for understanding Jeremiah's shortended name merge caching.
6068 // std::cerr << "Changed MN " << oldMangledName << " to " << mangledName << std::endl;
6069
6070#if 0
6071 printf ("Updating mangled name cache for node = %p = %s with mangledName = %s \n",astNode,astNode->class_name().c_str(),mangledName.c_str());
6072#endif
6073
6074#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
6075 SgStatement* statement = isSgStatement(astNode);
6076 if (statement != NULL && statement->hasExplicitScope() == true)
6077 {
6078 if (statement->get_scope() == NULL)
6079 {
6080 printf ("Warning: SageInterface::addMangledNameToCache(): In it might be premature to add this IR node and name to the mangledNameCache: statement = %p = %s oldMangledName = %s \n",
6081 statement,statement->class_name().c_str(),oldMangledName.c_str());
6082 }
6083 }
6084#endif
6085
6086 mangledNameCache.insert(pair<SgNode*,string>(astNode,mangledName));
6087
6088#if DEBUG_SAGE_INTERFACE_ADD_MANGLED_TO_CACHE
6089 printf ("In SageInterface::addMangledNameToCache(): returning mangledName = %s \n",mangledName.c_str());
6090#endif
6091
6092 return mangledName;
6093 }
6094
6095
6096// #endif
6097
6098#ifndef USE_ROSE
6099
6100bool
6102 {
6103 // This function is used in the unparser, but might be more generally useful. Since it is
6104 // related to general AST tests, I have put it here. It might be alternatively put in the
6105 // src/backend/unparser or related utility directory.
6106
6107 // Preorder traversal to test the order of declaration of non-defining vs. defining class
6108 // declarations in the preorder traversal of the AST.
6109 class DeclarationOrderTraversal : public AstSimpleProcessing
6110 {
6111 public:
6112 DeclarationOrderTraversal( SgDeclarationStatement* nonDefiningDeclaration, SgDeclarationStatement* definingDeclaration )
6113 : storedNondefiningDeclaration(nonDefiningDeclaration),
6114 storedDefiningDeclaration(definingDeclaration)
6115 {
6116 storedDeclarationFound = false;
6117 nonDefiningDeclarationPreceedsDefiningDeclaration = false;
6118 }
6119
6120 void visit (SgNode* node)
6121 {
6122 ROSE_ASSERT(storedNondefiningDeclaration != NULL);
6123 ROSE_ASSERT(storedDefiningDeclaration != NULL);
6124 ROSE_ASSERT(storedNondefiningDeclaration != storedDefiningDeclaration);
6125 // ROSE_ASSERT(storedNondefiningDeclaration->get_definingDeclaration() == storedDefiningDeclaration);
6126
6127 // Even though we only care about the SgClassDeclaration IR nodes we have to traverse them
6128 // in the AST in the order defined by the traversal (order of apprearance in the AST). We
6129 // also can't just search the declarations of a single scope (since the nondefining declaration
6130 // can appear in a different scope than the defining declaration).
6131 SgDeclarationStatement* declaration = isSgDeclarationStatement(node);
6132 if ( declaration != NULL )
6133 {
6134 if (storedDeclarationFound == false)
6135 {
6136 if (declaration == storedDefiningDeclaration)
6137 {
6138 storedDeclarationFound = true;
6139 nonDefiningDeclarationPreceedsDefiningDeclaration = false;
6140 }
6141 if (declaration == storedNondefiningDeclaration)
6142 {
6143 storedDeclarationFound = true;
6144 nonDefiningDeclarationPreceedsDefiningDeclaration = true;
6145 }
6146 }
6147 }
6148 }
6149
6150 public:
6151 bool storedDeclarationFound;
6152 bool nonDefiningDeclarationPreceedsDefiningDeclaration;
6153
6154 private:
6155 SgDeclarationStatement* storedNondefiningDeclaration;
6156 SgDeclarationStatement* storedDefiningDeclaration;
6157 };
6158
6159 ROSE_ASSERT(nonDefiningDeclaration != NULL);
6160#if 0
6161 printf ("In SageInterface::declarationPreceedsDefinition(): \n");
6162 printf (" nondefiningDeclaration = %p = %s \n",nonDefiningDeclaration,nonDefiningDeclaration->class_name().c_str());
6163 nonDefiningDeclaration->get_file_info()->display("nonDefiningDeclaration");
6164 printf (" nondefiningDeclaration->get_definingDeclaration() = %p \n",nonDefiningDeclaration->get_definingDeclaration());
6165 printf (" definingDeclaration = %p = %s \n",definingDeclaration,definingDeclaration->