ROSE 0.11.145.380
sageBuilder.C
1#include "sage3basic.h"
2#include <rose_config.h>
3
4#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
5 #include "roseAdapter.h"
6 #include "markLhsValues.h"
7 #include <fstream>
8 #include "Outliner.hh"
9#else
10 #include <fstream>
11 #include "transformationSupport.h"
12#endif
13
14#include <boost/algorithm/string/trim.hpp>
15#include "AstConsistencyTests.h"
16
17// DQ (2/27/2014): We need this feature to support the function: fixupCopyOfAstFromSeparateFileInNewTargetAst()
18#include "RoseAst.h"
19
20// DQ (2/17/2013): This is a operation on the global AST that we don't need to do too often
21// depending on the grainularity sought for the debugging information. It is done on the
22// whole AST once after construction (in edgRose.C), but is not needed more than that
23// since it is a performance issue.
24#define BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS 0
25#define BUILDER_MAKE_REDUNDANT_CALLS_TO_SYMBOL_TABLE_LOOKUP 0
26
27using namespace std;
28using namespace Rose;
29using namespace SageInterface;
30using namespace Rose::Diagnostics;
31
32namespace EDG_ROSE_Translation
33 {
34 // DQ (6/3/2019): The case of outlining to a seperate file will have transformations
35 // that this checking will fail on because it is for the typical case of checking the
36 // AST for transformations after construction of the AST from an typical input file.
37#if defined(ROSE_BUILD_CXX_LANGUAGE_SUPPORT) && !defined(ROSE_USE_CLANG_FRONTEND)
38 // DQ (6/3/2019): Use the definition in the EDG edgRose.C file if C/C++ support IS defined.
39 extern bool suppress_detection_of_transformations;
40#else
41 // DQ (6/3/2019): Allow this to be the definition if C/C++ support is NOT defined.
42 bool suppress_detection_of_transformations;
43#endif
44 }
45
46// MS 2015: utility functions used in the implementation of SageBuilder functions, but are not exposed in the SageBuilder-Interface.
47namespace SageBuilder {
48
49// DQ (3/24/2016): Adding Robb's message mechanism (data member and function).
51void
52initDiagnostics()
53 {
54 static bool initialized = false;
55 if (!initialized)
56 {
57 initialized = true;
58 Rose::Diagnostics::initAndRegister(&mlog, "Rose::SageBuilder");
59 mlog.comment("building abstract syntax trees");
60 }
61 }
62
63
64template <class actualFunction>
65actualFunction*
66buildNondefiningFunctionDeclaration_T (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, bool isMemberFunction, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, SgTemplateArgumentPtrList* templateArgumentsList, SgTemplateParameterPtrList* templateParameterList, SgStorageModifier::storage_modifier_enum sm);
67
68// DQ (8/11/2013): Note that the specification of the SgTemplateArgumentPtrList is somewhat redundant with the required parameter first_nondefinng_declaration (I think).
70template <class actualFunction>
71actualFunction*
72buildDefiningFunctionDeclaration_T (const SgName & name, SgType* return_type, SgFunctionParameterList * parlist, bool isMemberFunction, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, actualFunction* first_nondefinng_declaration, SgTemplateArgumentPtrList* templateArgumentsList);
73
75template <class T> ROSE_DLL_API void resetDeclaration(T* classDeclaration_copy, T* classDeclaration_original, SgScopeStatement* targetScope);
76
77}; // SageBuilder namespace
78
79//---------------------------------------------
80// scope stack interfaces
81// hide actual implementation of the stack
82//---------------------------------------------
83
84// DQ (1/18/2008): Added declaration in source file with Liao.
85// std::list<SgScopeStatement*> SageBuilder::ScopeStack;
86std::list<SgScopeStatement*> SageBuilder::ScopeStack(0);
87
88
89// DQ (11/30/2010): Added support for building Fortran case insensitive symbol table handling.
90// Support for construction of case sensitive/insensitive symbol table handling in scopes.
91// Rasmussen (3/22/2020): Setting this variable to properly reflect language properties
92// was removed in 2017. I would like to remove it from SageBuilder.
94
95
97// (used to control how the source code positon is defined for IR nodes built within the SageBuilder interface).
98// Set the default to be to mark everything as a transformation.
100
101
104 {
105 ASSERT_not_null(classType);
106
107 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
108 ASSERT_not_null(classDeclaration);
109
110 SgName className = classDeclaration->get_name();
111
112 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(classDeclaration->get_definingDeclaration());
113 ASSERT_not_null(definingClassDeclaration);
114 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
115 ASSERT_not_null(classDefinition);
116
118 ASSERT_not_null(functionParameterList);
119
120 // Constructors are specified with type void internally, though the type name is not output.
121 SgType* return_type = SageBuilder::buildVoidType();
122 ASSERT_not_null(return_type);
123
124 SgExprListExp* decoratorList = nullptr;
125 bool buildTemplateInstantiation = false;
126
127 // These are zero for a constructor.
128 unsigned int functionConstVolatileFlags = 0;
129
130 SgTemplateArgumentPtrList templateArgumentsList;
131
132 SgMemberFunctionDeclaration* first_nondefining_declaration = buildNondefiningMemberFunctionDeclaration (className, return_type, functionParameterList,
133 classDefinition, decoratorList, functionConstVolatileFlags, buildTemplateInstantiation, &templateArgumentsList);
134 ASSERT_not_null(first_nondefining_declaration);
135
136 first_nondefining_declaration->get_specialFunctionModifier().setConstructor();
137 ROSE_ASSERT(first_nondefining_declaration->get_specialFunctionModifier().isConstructor() == true);
138
139 // DQ (11/10/2020): Need to make sure that the firstNondefiningDeclaration is being used (reset is needed).
140 if (first_nondefining_declaration->get_firstNondefiningDeclaration() != first_nondefining_declaration)
141 {
142 first_nondefining_declaration = isSgMemberFunctionDeclaration(first_nondefining_declaration->get_firstNondefiningDeclaration());
143 }
144 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
145
146 SgMemberFunctionDeclaration* memberFunctionDeclaration = SageBuilder::buildDefiningMemberFunctionDeclaration (className, return_type, functionParameterList,
147 classDefinition, decoratorList, buildTemplateInstantiation, functionConstVolatileFlags, first_nondefining_declaration, &templateArgumentsList);
148 ASSERT_not_null(memberFunctionDeclaration);
149
150 memberFunctionDeclaration->get_specialFunctionModifier().setConstructor();
151 ROSE_ASSERT(memberFunctionDeclaration->get_specialFunctionModifier().isConstructor() == true);
152
153 // We return the default constructor and the use should insert it, I think.
154 // classDefinition->prepend_statement(memberFunctionDeclaration);
155
156 // Mark the constructor as public.
157 memberFunctionDeclaration->get_declarationModifier().get_accessModifier().setPublic();
158
159 ROSE_ASSERT (memberFunctionDeclaration->get_declarationModifier().get_accessModifier().isPublic() == true);
160
161 return memberFunctionDeclaration;
162 }
163
170
172void
177
178string
180 {
181 // DQ (11/19/2012): This function is build to support debugging the value of the statically defined mode.
182
183 string s;
184 switch(scp)
185 {
186 case e_sourcePositionError: s = "e_sourcePositionError"; break;
187 case e_sourcePositionDefault: s = "e_sourcePositionDefault"; break;
188 case e_sourcePositionTransformation: s = "e_sourcePositionTransformation"; break;
189 case e_sourcePositionCompilerGenerated: s = "e_sourcePositionCompilerGenerated"; break;
190 case e_sourcePositionNullPointers: s = "e_sourcePositionNullPointers"; break;
191 case e_sourcePositionFrontendConstruction: s = "e_sourcePositionFrontendConstruction"; break;
192 case e_sourcePosition_last: s = "e_sourcePosition_last"; break;
193
194 default:
195 {
196 printf ("Error: default reached in SageBuilder::display(SourcePositionClassification & scp): scp = %d \n",scp);
197 ROSE_ABORT();
198 }
199
200 }
201
202 return s;
203 }
204
205
206// DQ (5/21/2013): Added function to support hidding the implementation in the SgScopeStatement API.
207// template <class T> SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function (const SgName & name, const SgType* func_type)
208template <class T>
210SgScopeStatement::find_symbol_by_type_of_function (const SgName & name, const SgType* func_type, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateArgumentsList)
211 {
212 // DQ (3/13/2012): This is to address the fact that there are 6 different types of functions in ROSE:
213 // 1) SgFunctionDeclaration
214 // 2) SgMemberFunctionDeclaration
215 // 3) SgTemplateFunctionDeclaration
216 // 4) SgTemplateMemberFunctionDeclaration
217 // 5) SgTemplateFunctionInstntiationDeclaration
218 // 6) SgTemplateMemberFunctionInstntiationDeclaration
219 // And 4 different types of function symbols:
220 // 1) SgFunctionSymbol
221 // 2) SgMemberFunctionSymbol
222 // 3) SgTemplateFunctionSymbol
223 // 4) SgTemplateMemberFunctionSymbol
224 // Note that both:
225 // SgTemplateFunctionInstntiationDeclaration
226 // SgTemplateMemberFunctionInstntiationDeclaration
227 // map to
228 // SgFunctionSymbol
229 // SgMemberFunctionSymbol
230 // respectively.
231
232 // Check if there is a function symbol of any kind, then narrow the selection.
233 SgFunctionSymbol* func_symbol = nullptr;
234
235 {
236 // Use the static variant as a selector.
237 switch((VariantT)T::static_variant)
238 {
239 case V_SgFunctionDeclaration:
240 case V_SgProcedureHeaderStatement:
241 case V_SgTemplateInstantiationFunctionDecl:
242 {
243 // DQ (8/11/2013): Verify that the template arguments are provided for the correct cases and not for the incorrect cases.
244 if ((VariantT)T::static_variant == V_SgTemplateInstantiationFunctionDecl)
245 {
246 ROSE_ASSERT(templateArgumentsList != NULL);
247 }
248 else
249 {
250 ROSE_ASSERT(templateArgumentsList == NULL);
251 }
252
253 // DQ (5/21/2013): Calling the SgScopeStatement API.
254 func_symbol = lookup_nontemplate_function_symbol(name,func_type,templateArgumentsList);
255 // DQ (5/22/2013): This function symbol should not be a SgTemplateFunctionSymbol (associated with a template function. It should be an instantiated template.
256 ROSE_ASSERT(isSgTemplateFunctionSymbol(func_symbol) == NULL);
257 break;
258 }
259
260 case V_SgMemberFunctionDeclaration:
261 case V_SgTemplateInstantiationMemberFunctionDecl:
262 {
263 // DQ (5/21/2013): there is no SgScopeStatement API that calls this function.
264 // DQ (8/11/2013): Verify that the template arguments are provided for the correct cases and not for the incorrect cases.
265 if ((VariantT)T::static_variant == V_SgTemplateInstantiationMemberFunctionDecl)
266 {
267 ROSE_ASSERT(templateArgumentsList != NULL);
268 }
269 else
270 {
271 ROSE_ASSERT(templateArgumentsList == NULL);
272 }
273 func_symbol = lookup_nontemplate_member_function_symbol(name,func_type,templateArgumentsList);
274 break;
275 }
276
277 case V_SgTemplateFunctionDeclaration:
278 {
279 // DQ (8/11/2013): I think this should fail in cases were we should be handing the templateArgumentsList
280 // to the lookup_template_function_symbol() function.
281 ROSE_ASSERT(templateArgumentsList == NULL);
282
283 // DQ (8/11/2013): I think this should always be non-null.
284 ROSE_ASSERT(templateParameterList != NULL);
285
286 // DQ (8/7/2013): Adding support to permit template function overloading on template parameters.
287 // Note that the template arguments are being handed in as templateSpecializationArgumentList since this is the matching list.
288 // However, we might expect template parameter.
289
290 // DQ (8/7/2013): Adding support for template function overloading using template parameters (info passed as template arguments for specialization).
291 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
292 // In this case these are unavailable from this point.
293 // DQ (5/21/2013): Calling the SgScopeStatement API.
294 func_symbol = lookup_template_function_symbol(name,func_type,templateParameterList);
295
296 break;
297 }
298
299 case V_SgTemplateMemberFunctionDeclaration:
300 {
301 // DQ (8/11/2013): I think this should fail in cases were we should be handing the templateArgumentsList
302 // to the lookup_template_member_function_symbol() function.
303 ROSE_ASSERT(templateArgumentsList == NULL);
304
305 // DQ (8/11/2013): I think this sould always be non-null.
306 ROSE_ASSERT(templateParameterList != NULL);
307
308 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
309 // In this case these are unavailable from this point.
310 // DQ (5/21/2013): Calling the SgScopeStatement API.
311 func_symbol = lookup_template_member_function_symbol(name,func_type,templateParameterList);
312 break;
313 }
314
315 default:
316 {
317 printf ("In SgScopeStatement::find_symbol_by_type_of_function(): default reached --- variantT(T::static_variant) = %d \n",T::static_variant);
318 ROSE_ABORT();
319 }
320 }
321 }
322 return func_symbol;
323 }
324
325
326// explicit instantiation of find_symbol_by_type_of_function
327template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgTemplateFunctionDeclaration>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
328template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgTemplateInstantiationMemberFunctionDecl>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
329template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgTemplateInstantiationFunctionDecl>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
330template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgMemberFunctionDeclaration>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
331template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgTemplateMemberFunctionDeclaration>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
332template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgFunctionDeclaration>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
333
334void
336 {
337 ASSERT_not_null(stmt);
338 ScopeStack.push_back(stmt);
339 }
340
342 {
343 ASSERT_require(ScopeStack.empty() == false);
344 ScopeStack.pop_back();
345 }
346
348 {
349 // If this is an empty stack, return nullptr (ScopeStack.back() should be undefined for this case).
350 if (ScopeStack.empty()) {
351 return nullptr;
352 }
353
354 // DQ (9/28/2009): This is part of testing for GNU 4.0.x (other versions of g++ work fine).
355 SgScopeStatement* tempScope = ScopeStack.back();
356 if (tempScope) {
357 tempScope->class_name();
358 }
359
360 return tempScope;
361 }
362
363
366 {
367 // This function adds new support within the internal scope stack mechanism.
368
369 // DQ (3/20/2017): This branch is never taken and can be reported as an error (this improves code coverage).
370 // DQ (3/11/2012): Test if this is an empty stack, and if so return NULL (ScopeStack.back() should be undefined for this case).
371 ROSE_ASSERT(ScopeStack.empty() == false);
372
373 // The SgGlobal scope should be the first (front) element in the list (the current scope at the end (back) of the list).
374 SgScopeStatement* tempScope = ScopeStack.front();
375 ASSERT_not_null(isSgGlobal(tempScope));
376
377 return tempScope;
378 }
379
381 {
382 return ScopeStack.empty();
383 }
384
386 {
387 ScopeStack.clear();
388 }
389
391 {
392 // DQ (11/26/2012): This is used to turn off some pragma processing which is a problem in switch statements.
393 bool returnVar = false;
394 std::list<SgScopeStatement*>::iterator i;
395 for (i = ScopeStack.begin(); i != ScopeStack.end(); i++)
396 {
397 if (isSgSwitchStatement(*i) != nullptr)
398 returnVar = true;
399 }
400
401 return returnVar;
402 }
403
404// *******************************************************************************
405// ******************************* Build Functions *****************************
406// *******************************************************************************
407SgName
408SageBuilder::appendTemplateArgumentsToName( const SgName & name, const SgTemplateArgumentPtrList & templateArgumentsList)
409 {
410 // DQ (7/23/2012): This function is somewhat redundant with the SgDeclarationStatement::resetTemplateNameSupport() in that
411 // they both have to generate identical names. this was a problem and thus this code is seneitive to " ," instead of ","
412 // below.
413
414 // DQ (7/23/2012): This is one of three locations where the template arguments are assembled and where
415 // the name generated identically (in each case) is critical. Not clear how to best refactor this code.
416 // The other two are:
417 // Unparse_ExprStmt::unparseTemplateArgumentList()
418 // and in:
419 // void SgDeclarationStatement::resetTemplateNameSupport ( bool & nameResetFromMangledForm, SgName & name )
420 // It is less clear how to refactor this code.
421
422#define DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST 0
423
424#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST
425 printf ("In SageBuilder::appendTemplateArgumentsToName(): CRITICAL FUNCTION TO BE REFACTORED (name = %s) \n",name.str());
426#endif
427
428 // DQ (3/10/2018): This is now partially redundant with SgTemplateArgumentList::unparseToStringSupport().
429 SgUnparse_Info *info = new SgUnparse_Info();
430 ASSERT_not_null(info);
431
432 info->set_language(SgFile::e_Cxx_language);
433 info->set_requiresGlobalNameQualification();
434
435 // DQ (4/28/2017): For template arguments we never want to output the definitions of classes, and enums.
436 info->set_SkipClassDefinition();
437 info->set_SkipEnumDefinition();
438 info->set_use_generated_name_for_template_arguments(true);
439
440 bool emptyArgumentList = templateArgumentsList.empty();
441
442 // DQ (9/24/2012): Don't add "< >" if there are no template arguments (see test2012_221.C).
443 // SgName returnName = name + " < ";
444 SgName returnName = name;
445 if (emptyArgumentList == false)
446 returnName += " < ";
447
448 SgTemplateArgumentPtrList::const_iterator i = templateArgumentsList.begin();
449 bool need_separator = false;
450
451 bool exit_after_name_is_generated = false;
452
453 while (i != templateArgumentsList.end())
454 {
455 if ((*i)->get_argumentType() == SgTemplateArgument::start_of_pack_expansion_argument)
456 {
457 i++;
458 continue;
459 }
460
461 if (need_separator)
462 {
463 returnName += " , ";
464 }
465
466#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST
467 printf ("In SageBuilder::appendTemplateArgumentsToName(): (top of loop) templateArgumentsList element *i = %p = %s returnName = %s \n",*i,(*i)->class_name().c_str(),returnName.str());
468#endif
469
470 // DQ (2/5/2022): We need to use a fully qualified name as demonstrated by test2022_05.C.
471 // Where there are two different template arguments with the same name (e.g. in different
472 // namespaces) the generated names will be the same and the symbols will collide in the
473 // symbol table for the scope where they are both constructed.
474 // So a fix is to add the fully qualified name of the scope of the expression used as a template argument.
475
476 // DQ (2/6/2022): Newer version of code (still refactoring this section).
477 bool used_fully_qualified_name = false;
478
479#define DEBUG_TEMPLATE_ARGUMENT_NAMES 0
480
481 // DQ (2/6/2022): This is the newly refactored implementation to add name qualification to
482 // the template arguments in the used in symbol tables key for template instantiations.
483 SgTemplateArgument* templateArgument = *i;
484 ASSERT_not_null(templateArgument);
485
486 switch (templateArgument->get_argumentType())
487 {
489 {
490 SgType* type = templateArgument->get_type();
491 ASSERT_not_null(type);
492
493#if DEBUG_TEMPLATE_ARGUMENT_NAMES
494 printf ("In SageBuilder::appendTemplateArgumentsToName(): case SgTemplateArgument::type_argument: BEFORE stripType: type = %p = %s \n",type,type->class_name().c_str());
495#endif
496
497#if DEBUG_TEMPLATE_ARGUMENT_NAMES
498 printf ("In SageBuilder::appendTemplateArgumentsToName(): case SgTemplateArgument::type_argument: AFTER stripType: type = %p = %s \n",type,type->class_name().c_str());
499#endif
500 // DQ (2/6/2022): We need to find an example of the case where the template argument is a pointer type.
501 if (isSgPointerType(templateArgument->get_type()) != nullptr)
502 {
503
504#if DEBUG_TEMPLATE_ARGUMENT_NAMES
505 printf ("Found a templateArgument->get_type() that is SgPointerType: name = %s \n",name.str());
506#endif
507 }
508
509 SgNamedType* namedType = isSgNamedType(type);
510 if (namedType != nullptr)
511 {
512 // DQ (2/5/2022): Since SgNonrealType is a SgNamedType, is this sufficiant to handle those cases?
513 SgDeclarationStatement* declaration = namedType->get_declaration();
514 ASSERT_not_null(declaration);
515
516 switch (declaration->variantT())
517 {
518 case V_SgTemplateInstantiationDecl:
519 case V_SgTemplateClassDeclaration:
520 case V_SgClassDeclaration:
521 {
522 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
523 string fully_qualified_name = classDeclaration->get_qualified_name();
524#if DEBUG_TEMPLATE_ARGUMENT_NAMES
525 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
526#endif
527 returnName += fully_qualified_name;
528 used_fully_qualified_name = true;
529 break;
530 }
531
532 case V_SgTemplateInstantiationTypedefDeclaration:
533 case V_SgTemplateTypedefDeclaration:
534 case V_SgTypedefDeclaration:
535 {
536 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(declaration);
537 string fully_qualified_name = typedefDeclaration->get_qualified_name();
538#if DEBUG_TEMPLATE_ARGUMENT_NAMES
539 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
540#endif
541 returnName += fully_qualified_name;
542 used_fully_qualified_name = true;
543 break;
544 }
545
546 case V_SgEnumDeclaration:
547 {
548 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(declaration);
549 string fully_qualified_name = enumDeclaration->get_qualified_name();
550#if DEBUG_TEMPLATE_ARGUMENT_NAMES
551 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
552#endif
553 returnName += fully_qualified_name;
554 used_fully_qualified_name = true;
555 break;
556 }
557
558 // DQ (2/5/2022): Is this implementation correct for SgNonrealDecl?
559 case V_SgNonrealDecl:
560 {
561 SgNonrealDecl* nonrealDeclaration = isSgNonrealDecl(declaration);
562 string fully_qualified_name = nonrealDeclaration->get_qualified_name();
563#if DEBUG_TEMPLATE_ARGUMENT_NAMES
564 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
565#endif
566 returnName += fully_qualified_name;
567 used_fully_qualified_name = true;
568 break;
569 }
570
571 default:
572 {
573 // I'm not clear if we need to support any other cases, so this default case is an error.
574 printf ("In SageBuilder::appendTemplateArgumentsToName(): default reached: get_type() != NULL: declaration = %s \n",declaration->class_name().c_str());
575 ROSE_ASSERT(false);
576 }
577 }
578 }
579 else
580 {
581#if DEBUG_TEMPLATE_ARGUMENT_NAMES
582 printf ("In SageBuilder::appendTemplateArgumentsToName(): not a SgNamedType: get_type() != NULL: type = %s \n",type->class_name().c_str());
583#endif
584 }
585
586 break;
587 }
588
590 {
591 // DQ (8/12/2013): This can be either an SgExpression or SgInitializedName.
592 ROSE_ASSERT (templateArgument->get_expression() != NULL || templateArgument->get_initializedName() != NULL);
593 ROSE_ASSERT (templateArgument->get_expression() == NULL || templateArgument->get_initializedName() == NULL);
594 if (templateArgument->get_expression() != nullptr)
595 {
596 SgExpression* expression = templateArgument->get_expression();
597 ASSERT_not_null(expression);
598
599 // Now we care about types of expression that could require name qualification.
600 // Is there anything more than SgVarRefExp that we need to worry about?
601 SgVarRefExp* varRefExp = isSgVarRefExp(expression);
602 if (varRefExp != nullptr)
603 {
604 // SgVariableSymbol* variableSymbol = isSgVariableSymbol(varRefExp->get_symbol());
605 SgVariableSymbol* variableSymbol = varRefExp->get_symbol();
606 ROSE_ASSERT(variableSymbol != NULL);
607 SgInitializedName* initializedName = variableSymbol->get_declaration();
608 ROSE_ASSERT(initializedName != NULL);
609 string fully_qualified_name = initializedName->get_qualified_name();
610#if DEBUG_TEMPLATE_ARGUMENT_NAMES
611 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
612#endif
613 returnName += fully_qualified_name;
614 used_fully_qualified_name = true;
615 }
616 else
617 {
618 // Unclear if we have cases here to support (need more examples of different types of template arguments in use).
619#if DEBUG_TEMPLATE_ARGUMENT_NAMES
620 printf ("In SageBuilder::appendTemplateArgumentsToName(): Case of template argument varRefExp == NULL: expression = %p = %s \n",
621 expression,expression->class_name().c_str());
622#endif
623 }
624 }
625 else
626 {
627 SgInitializedName* initializedName = templateArgument->get_initializedName();
628 ROSE_ASSERT(initializedName != NULL);
629 printf ("initializedName = %p = %s \n",initializedName,initializedName->get_name().str());
630
631 printf ("In SageBuilder::appendTemplateArgumentsToName(): Case of template argument initializedName != NULL: Unclear what do do in this case \n");
632 ROSE_ASSERT(false);
633 }
634
635 break;
636 }
637
639 {
640 SgDeclarationStatement* decl = templateArgument->get_templateDeclaration();
641 ASSERT_not_null(decl);
642#if DEBUG_TEMPLATE_ARGUMENT_NAMES
643 printf ("In SageBuilder::appendTemplateArgumentsToName(): case SgTemplateArgument::template_template_argument: decl = %p = %s \n",decl,decl->class_name().c_str());
644#endif
645 exit_after_name_is_generated = true;
646 SgTemplateDeclaration* tpl_decl = isSgTemplateDeclaration(decl);
647 ROSE_ASSERT(tpl_decl == NULL);
648
649 break;
650 }
651
653 {
654#if DEBUG_TEMPLATE_ARGUMENT_NAMES
655 printf("WARNING: start_of_pack_expansion_argument in evaluateNameQualificationForTemplateArgumentList (can happen from some debug output)\n");
656#endif
657 break;
658 }
659
661 {
662 // mfprintf(mlog [ WARN ] ) ("Error argument_undefined in evaluateNameQualificationForTemplateArgumentList \n");
663 printf("Error argument_undefined in evaluateNameQualificationForTemplateArgumentList \n");
664 ROSE_ABORT();
665 break;
666 }
667
668 default:
669 {
670 // mfprintf(mlog [ WARN ] ) ("Error default reached in evaluateNameQualificationForTemplateArgumentList \n");
671 printf("Error default reached in evaluateNameQualificationForTemplateArgumentList \n");
672 ROSE_ABORT();
673 }
674 }
675
676 // DQ (2/5/2022): if it is not set above then use the old way without name qualification (debugging test2022_05.C).
677 // DQ (9/15/2012): We need to communicate that the language so that SgBoolVal will not be unparsed to "1" instead of "true" (see test2012_215.C).
678 // Calling the unparseToString (SgUnparse_Info *info) function instead of the version not taking an argument.
679 // returnName += (*i)->unparseToString(info);
680 if (used_fully_qualified_name == false)
681 {
682 returnName += (*i)->unparseToString(info);
683 }
684
685#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST
686 printf ("In SageBuilder::appendTemplateArgumentsToName(): (after appending template name) *i = %p returnName = %s \n",*i,returnName.str());
687#endif
688 need_separator = true;
689 i++;
690
691#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST
692 printf ("In SageBuilder::appendTemplateArgumentsToName(): (bottom of loop) returnName = %s \n",returnName.str());
693#endif
694 }
695
696 if (emptyArgumentList == false)
697 returnName += " > ";
698
699#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST || DEBUG_TEMPLATE_ARGUMENT_NAMES
700 printf ("Leaving SageBuilder::appendTemplateArgumentsToName(): returnName = %s \n",returnName.str());
701#endif
702
703 if (false)
704 {
705 // This allows me to test a large number of input codes and identify ones that are using specific features (e.g. template template parameters).
706 if (exit_after_name_is_generated == true)
707 {
708 printf ("Exiting as a test! \n");
709 ROSE_ASSERT(false);
710 }
711 }
712
713 delete info;
714 info = nullptr;
715
716 return returnName;
717 }
718
719
720SgName
722 {
723 ROSE_ASSERT(templateArgument != NULL);
724
725 SgUnparse_Info *info = new SgUnparse_Info();
726 ROSE_ASSERT(info != NULL);
727
728 info->set_language(SgFile::e_Cxx_language);
729
730 // DQ (4/28/2017): For template arguments we never want to output the definitions of classes, and enums.
731 info->set_SkipClassDefinition();
732 info->set_SkipEnumDefinition();
733 info->set_use_generated_name_for_template_arguments(true);
734
735 SgName returnName = templateArgument->unparseToString(info);
736
737 delete info;
738 info = nullptr;
739
740 return returnName;
741 }
742
743
744SgTemplateArgumentPtrList*
746 {
747 // DQ (9/13/2012): This function returns the SgTemplateArgumentPtrList. Both template declarations and template instanatiations have them.
748 // In a template instantiation it is the templateArguments field and from template declarations it is the templateSpecializationArguments field.
749
750 ROSE_ASSERT(decl != NULL);
751
752 SgTemplateArgumentPtrList* templateArgumentsList = nullptr;
753
754 switch(decl->variantT())
755 {
756 case V_SgNamespaceAliasDeclarationStatement:
757 case V_SgNamespaceDeclarationStatement:
758 case V_SgEnumDeclaration:
759 case V_SgVariableDeclaration:
760 case V_SgTypedefDeclaration:
761 case V_SgProcedureHeaderStatement:
762 case V_SgJovialTableStatement:
763 case V_SgJavaPackageDeclaration:
764 case V_SgFunctionDeclaration:
765 case V_SgMemberFunctionDeclaration:
766 case V_SgClassDeclaration:
767 {
768 templateArgumentsList = nullptr;
769 break;
770 }
771
772 case V_SgTemplateInstantiationDecl:
773 {
774 templateArgumentsList = &(isSgTemplateInstantiationDecl(decl)->get_templateArguments());
775 break;
776 }
777
778 case V_SgTemplateClassDeclaration:
779 {
780 templateArgumentsList = &(isSgTemplateClassDeclaration(decl)->get_templateSpecializationArguments());
781 break;
782 }
783
784 case V_SgTemplateInstantiationFunctionDecl:
785 {
786 templateArgumentsList = &(isSgTemplateInstantiationFunctionDecl(decl)->get_templateArguments());
787 break;
788 }
789
790 case V_SgTemplateFunctionDeclaration:
791 {
792 templateArgumentsList = &(isSgTemplateFunctionDeclaration(decl)->get_templateSpecializationArguments());
793 break;
794 }
795
796 case V_SgTemplateInstantiationMemberFunctionDecl:
797 {
798 templateArgumentsList = &(isSgTemplateInstantiationMemberFunctionDecl(decl)->get_templateArguments());
799 break;
800 }
801
802 case V_SgTemplateMemberFunctionDeclaration:
803 {
804 templateArgumentsList = &(isSgTemplateMemberFunctionDeclaration(decl)->get_templateSpecializationArguments());
805 break;
806 }
807
808 case V_SgTemplateVariableDeclaration:
809 {
810 templateArgumentsList = &(isSgTemplateVariableDeclaration(decl)->get_templateSpecializationArguments());
811 break;
812 }
813
814 case V_SgTemplateVariableInstantiation:
815 {
816 templateArgumentsList = &(isSgTemplateVariableInstantiation(decl)->get_templateArguments());
817 break;
818 }
819
820 case V_SgTemplateTypedefDeclaration:
821 {
822 templateArgumentsList = &(isSgTemplateTypedefDeclaration(decl)->get_templateSpecializationArguments());
823 break;
824 }
825
826 case V_SgTemplateInstantiationTypedefDeclaration:
827 {
828 templateArgumentsList = &(isSgTemplateInstantiationTypedefDeclaration(decl)->get_templateArguments());
829 break;
830 }
831
832 case V_SgTemplateDeclaration:
833 {
834 templateArgumentsList = nullptr;
835 break;
836 }
837
838 case V_SgNonrealDecl:
839 {
840 templateArgumentsList = &(isSgNonrealDecl(decl)->get_tpl_args());
841 break;
842 }
843
844 default:
845 {
846 printf ("getTemplateArgumentList(): Default reached in switch: decl = %p = %s \n",decl,decl->class_name().c_str());
847 ROSE_ABORT();
848 }
849 }
850
851 return templateArgumentsList;
852 }
853
854
855
856SgTemplateParameterPtrList*
858 {
859 // DQ (9/16/2012): This function returns the SgTemplateParameterPtrList that is associated with template declarations.
860 // For all other cases it returns NULL (or is an error).
861
862 ROSE_ASSERT(decl != NULL);
863
864 SgTemplateParameterPtrList* templateParameterList = nullptr;
865
866 switch(decl->variantT())
867 {
868 case V_SgNamespaceAliasDeclarationStatement:
869 case V_SgNamespaceDeclarationStatement:
870 case V_SgEnumDeclaration:
871 case V_SgVariableDeclaration:
872 case V_SgTypedefDeclaration:
873 case V_SgProcedureHeaderStatement:
874 case V_SgJovialTableStatement:
875 case V_SgJavaPackageDeclaration:
876 case V_SgFunctionDeclaration:
877 case V_SgMemberFunctionDeclaration:
878 case V_SgClassDeclaration:
879 case V_SgTemplateInstantiationTypedefDeclaration:
880 case V_SgTemplateInstantiationFunctionDecl:
881 case V_SgTemplateInstantiationMemberFunctionDecl:
882 case V_SgTemplateVariableInstantiation:
883 case V_SgTemplateInstantiationDecl:
884 {
885 templateParameterList = nullptr;
886 break;
887 }
888
889 case V_SgTemplateClassDeclaration:
890 {
891 templateParameterList = &(isSgTemplateClassDeclaration(decl)->get_templateParameters());
892 break;
893 }
894
895 case V_SgTemplateFunctionDeclaration:
896 {
897 templateParameterList = &(isSgTemplateFunctionDeclaration(decl)->get_templateParameters());
898 break;
899 }
900
901 case V_SgTemplateMemberFunctionDeclaration:
902 {
903 templateParameterList = &(isSgTemplateMemberFunctionDeclaration(decl)->get_templateParameters());
904 break;
905 }
906
907 case V_SgTemplateVariableDeclaration:
908 {
909 templateParameterList = &(isSgTemplateVariableDeclaration(decl)->get_templateParameters());
910 break;
911 }
912
913 case V_SgTemplateTypedefDeclaration:
914 {
915 templateParameterList = &(isSgTemplateTypedefDeclaration(decl)->get_templateParameters());
916 break;
917 }
918
919 case V_SgNonrealDecl:
920 {
921 templateParameterList = &(isSgNonrealDecl(decl)->get_tpl_params());
922 break;
923 }
924
925 case V_SgTemplateDeclaration:
926 {
927 templateParameterList = &(isSgTemplateDeclaration(decl)->get_templateParameters());
928 break;
929 }
930
931 default:
932 {
933 printf ("getTemplateParameterList(): Default reached in switch: decl = %p = %s \n",decl,decl->class_name().c_str());
934 ROSE_ABORT();
935 }
936 }
937
938 return templateParameterList;
939 }
940
941
942
943void
945 {
946 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
947
948 ROSE_ASSERT(decl != NULL);
949
950 SgTemplateArgumentPtrList* templateArgumentsList = getTemplateArgumentList(decl);
951
952 if (templateArgumentsList != nullptr)
953 {
955 ROSE_ASSERT(first_decl != NULL);
956
957 SgTemplateArgumentPtrList::iterator i = templateArgumentsList->begin();
958 while (i != templateArgumentsList->end())
959 {
960 SgNode* parent = (*i)->get_parent();
961 if (parent == nullptr)
962 {
963 (*i)->set_parent(first_decl);
964 }
965 else
966 {
967 SgScopeStatement* scope = isSgScopeStatement(parent);
968 if (scope != nullptr)
969 {
970 // Template Arguments should have had there parents set to a scope when they were build, we want
971 // to refine that now that the declaration which we want them to be specified in has been build.
972 (*i)->set_parent(first_decl);
973 }
974 else
975 {
976 SgDeclarationStatement* declaration = isSgDeclarationStatement(parent);
977 if (declaration != nullptr)
978 {
979#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
980 printf ("In setTemplateArgumentParents(): Template argument already set to declaration = %p = %s \n",declaration,declaration->class_name().c_str());
981#endif
982 }
983 else
984 {
985#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
986 printf ("Error: In setTemplateArgumentParents(): I think it is an error for the template argument parent to be set to %p = %s \n",parent,parent->class_name().c_str());
987#endif
988 }
989 }
990 }
991
992 i++;
993 }
994 }
995
997 }
998
999
1000void
1002 {
1003 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1004 ROSE_ASSERT(decl != NULL);
1005
1006 SgTemplateParameterPtrList* templateParameterList = getTemplateParameterList(decl);
1007
1008 if (templateParameterList != nullptr)
1009 {
1011 ROSE_ASSERT(first_decl != NULL);
1012
1013 SgTemplateParameterPtrList::iterator i = templateParameterList->begin();
1014 while (i != templateParameterList->end())
1015 {
1016 SgNode* parent = (*i)->get_parent();
1017 if (parent == nullptr)
1018 {
1019 (*i)->set_parent(first_decl);
1020 }
1021 else
1022 {
1023 SgScopeStatement* scope = isSgScopeStatement(parent);
1024 if (scope != nullptr)
1025 {
1026 // Template Arguments should have had their parents set to a scope when they were build, we want
1027 // to refine that now that the declaration which we want them to be specified in has been build.
1028 (*i)->set_parent(first_decl);
1029 }
1030 }
1031
1032 i++;
1033 }
1034 }
1035
1037 }
1038
1039
1040void
1042 {
1043 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1044
1045 ROSE_ASSERT(decl != NULL);
1046
1047 SgTemplateArgumentPtrList* templateArgumentsList = getTemplateArgumentList(decl);
1048
1049 if (templateArgumentsList != nullptr)
1050 {
1051 SgTemplateArgumentPtrList::iterator i = templateArgumentsList->begin();
1052 while (i != templateArgumentsList->end())
1053 {
1054 SgNode* parent = (*i)->get_parent();
1055 if (parent == nullptr)
1056 {
1057 printf ("Error: In testTemplateArgumentParents(): decl = %p = %s has template argument = %p with null parent \n",decl,decl->class_name().c_str(),*i);
1058 }
1059 ROSE_ASSERT(parent != NULL);
1060
1061 // DQ (9/16/2012): Adding new test.
1062 ROSE_ASSERT(decl->get_firstNondefiningDeclaration() != NULL);
1063 // DQ (1/30/2013): Commented this test out so that we could reuse SgTemplateArguments and
1064 // assure that the mapping from EDG a_template_arg_ptr's to SgTemplateArgument's was 1-to-1.
1065 // It is not clear if we can relax this constraint in the future.
1066
1067 i++;
1068 }
1069 }
1070 }
1071
1072
1073void
1075 {
1076 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1077
1078 ROSE_ASSERT(decl != NULL);
1079
1080 SgTemplateParameterPtrList* templateParameterList = getTemplateParameterList(decl);
1081
1082 if (templateParameterList != nullptr)
1083 {
1084 SgTemplateParameterPtrList::iterator i = templateParameterList->begin();
1085 while (i != templateParameterList->end())
1086 {
1087 SgNode* parent = (*i)->get_parent();
1088 if (parent == nullptr)
1089 {
1090 printf ("Error: In testTemplateParameterParents(): decl = %p = %s has template argument = %p with null parent \n",decl,decl->class_name().c_str(),*i);
1091 }
1092 ROSE_ASSERT(parent != NULL);
1093 ROSE_ASSERT(decl->get_firstNondefiningDeclaration() != NULL);
1094
1095 // DQ (8/22/2013): Since these are now shared, it makes less sense to expect these to have such simple parent relationships.
1096 // This commit of work on ROSE added caching to template parameters so that we could support pointer equality for tests
1097 // of template parameter equality in the symbol table handling (this was a technique previously used for template arguments).
1098 // This test fails in the mergeTest_04.C test , but only on the GNU 4.4.x compiler (passes on the GNU 4.2.4 compiler).
1099
1100 i++;
1101 }
1102 }
1103 }
1104
1105
1106void
1107SageBuilder::setTemplateArgumentsInDeclaration( SgDeclarationStatement* decl, SgTemplateArgumentPtrList* templateArgumentsList_input )
1108 {
1109 // DQ (9/16/2012): Setup the template arguments for any type of template instantiation.
1110
1111 ROSE_ASSERT(templateArgumentsList_input != NULL);
1112
1113 ROSE_ASSERT(decl->variantT() == V_SgTemplateInstantiationDecl ||
1114 decl->variantT() == V_SgTemplateInstantiationFunctionDecl ||
1115 decl->variantT() == V_SgTemplateInstantiationMemberFunctionDecl ||
1116 decl->variantT() == V_SgTemplateInstantiationTypedefDeclaration);
1117
1118 SgTemplateArgumentPtrList* templateArgumentsList_from_declaration = getTemplateArgumentList(decl);
1119
1120 if (templateArgumentsList_from_declaration != nullptr)
1121 {
1122 *templateArgumentsList_from_declaration = *templateArgumentsList_input;
1123
1124 // Set the parents.
1126 }
1127
1129 }
1130
1131
1132void
1133SageBuilder::setTemplateSpecializationArgumentsInDeclaration( SgDeclarationStatement* decl, SgTemplateArgumentPtrList* templateSpecializationArgumentsList_input )
1134 {
1135 // DQ (9/16/2012): Setup the template arguments for any type of template declaration
1136
1137 ROSE_ASSERT(templateSpecializationArgumentsList_input != NULL);
1138
1139 ROSE_ASSERT(decl->variantT() == V_SgTemplateClassDeclaration || decl->variantT() == V_SgTemplateFunctionDeclaration ||
1140 decl->variantT() == V_SgTemplateMemberFunctionDeclaration || decl->variantT() == V_SgTemplateVariableDeclaration );
1141
1142 SgTemplateArgumentPtrList* templateSpecializationArgumentsList_from_declaration = getTemplateArgumentList(decl);
1143
1144 if (templateSpecializationArgumentsList_from_declaration != nullptr)
1145 {
1146 *templateSpecializationArgumentsList_from_declaration = *templateSpecializationArgumentsList_input;
1147
1148 // Set the parents.
1150 }
1151
1153 }
1154
1155void
1156SageBuilder::setTemplateParametersInDeclaration( SgDeclarationStatement* decl, SgTemplateParameterPtrList* templateParameterList_input )
1157 {
1158 // DQ (9/16/2012): Setup the template parameters for any type of template declaration.
1159
1160 ROSE_ASSERT(templateParameterList_input != NULL);
1161
1162 ROSE_ASSERT(decl->variantT() == V_SgTemplateClassDeclaration || decl->variantT() == V_SgTemplateFunctionDeclaration ||
1163 decl->variantT() == V_SgTemplateMemberFunctionDeclaration || decl->variantT() == V_SgTemplateVariableDeclaration );
1164
1165 SgTemplateParameterPtrList* templateParameterList_from_declaration = getTemplateParameterList(decl);
1166
1167 if (templateParameterList_from_declaration != nullptr)
1168 {
1169 *templateParameterList_from_declaration = *templateParameterList_input;
1170
1171 // Set the parents.
1173 }
1174
1176 }
1177
1178#define DEBUG__buildInitializedName 0
1179// Only used to build parameter arguments for function ??
1180// should be transparently generated for most variable declaration builder
1181// deferred symbol insertion, scope setting , etc
1182// do them when it is actually used with the parameterList!!
1184#if DEBUG__buildInitializedName
1185 std::cout << "SageBuilder::buildInitializedName" << std::endl;
1186 std::cout << " name = " << name << std::endl;
1187#endif
1188 ASSERT_not_null(type);
1189
1190 SgInitializedName* initializedName = new SgInitializedName(name,type,init);
1191 ROSE_ASSERT(initializedName);
1192
1194 return initializedName;
1195}
1196
1197SgInitializedName * SageBuilder::buildInitializedName ( const std::string & name, SgType* type) {
1198 SgName var_name(name);
1199 return buildInitializedName(var_name,type);
1200}
1201
1203 string var_name(name);
1204 return buildInitializedName(var_name,type);
1205}
1206
1208#if DEBUG__buildInitializedName
1209 std::cout << "SageBuilder::buildInitializedName_nfi" << std::endl;
1210 std::cout << " name = " << name << std::endl;
1211#endif
1212 ROSE_ASSERT(type != NULL);
1213
1214 SgInitializedName* initializedName = new SgInitializedName(name,type,init);
1215 ROSE_ASSERT(initializedName != NULL);
1216
1217 if (declptr)
1218 {
1219 initializedName->set_parent(declptr);
1220 initializedName->set_declptr(declptr);
1221 }
1222
1223 setOneSourcePositionNull(initializedName);
1224
1225 return initializedName;
1226}
1227
1228//-----------------------------------------------
1229// could have two declarations for a same variable
1230// extern int i;
1231// int i;
1234{
1235 if (scope == nullptr)
1237 ROSE_ASSERT(name.is_null() == false);
1238 ROSE_ASSERT(type != NULL);
1239
1240 SgVariableDeclaration* varDecl = new SgVariableDeclaration(name, type, varInit);
1241 ROSE_ASSERT(varDecl);
1242
1243// DQ (8/21/2011): Note that the default is to set the declaration modifier's access modifier to be
1244// default (which is the same as public). So the effect it to set it to be public. This is ignored
1245// by the unparser for most languguages in ROSE.
1246 varDecl->set_firstNondefiningDeclaration(varDecl);
1247
1248 if (scope != nullptr)
1249 {
1250 // Liao 12/13/2010
1251 // Fortran subroutine/function parameters have corresponding variable declarations in the body
1252 // For this declaration, it should use the initialized names of the parameters instead of creating new ones
1253 // The symbol of the init name should be under SgFunctionDefinition, instead of the function body block
1254 bool isFortranParameter = false;
1256 {
1258 if (f_def != nullptr)
1259 {
1260 // DQ (5/21/2013): Removed direct reference to symbol table (namespace handling is only supported at the SgScopeStatement level).
1261 SgVariableSymbol * v_symbol = f_def->lookup_variable_symbol(name);
1262 if (v_symbol != nullptr) // find a function parameter with the same name
1263 {
1264 // replace the default one with the one from parameter
1265 SgInitializedName *default_initName = varDecl->get_decl_item (name);
1266 ROSE_ASSERT (default_initName != NULL);
1267 SgInitializedName * new_initName = v_symbol->get_declaration();
1268 ROSE_ASSERT (new_initName != NULL);
1269 ROSE_ASSERT (default_initName != new_initName);
1270
1271 SgInitializedNamePtrList& n_list= varDecl->get_variables();
1272 std::replace (n_list.begin(), n_list.end(),default_initName, new_initName );
1273 ROSE_ASSERT (varDecl->get_decl_item (name)==new_initName); //ensure the new one can be found
1274
1275 // change the function argument's old parent to the variable declaration
1276 SgNode * old_parent = new_initName->get_parent();
1277 ROSE_ASSERT (old_parent != NULL);
1278 ROSE_ASSERT (isSgFunctionParameterList(old_parent) != NULL);
1279 new_initName->set_parent(varDecl); // adjust parent from SgFunctionParameterList to SgVariableDeclaration
1280
1281 // DQ (1/25/2011): Deleting these causes problems if I use this function in the Fortran support...
1282 // delete (default_initName->get_declptr()); // delete the var definition
1283 // delete (default_initName->get_declptr()); // relink the var definition
1284
1285 SgVariableDefinition * var_def = isSgVariableDefinition(default_initName->get_declptr()) ;
1286 ROSE_ASSERT (var_def != NULL);
1287 var_def->set_parent(new_initName);
1288 var_def->set_vardefn(new_initName);
1289 new_initName->set_declptr(var_def); // it was set to SgProcedureHeaderStatement as a function argument
1290
1291 delete (default_initName); // must delete the old one to pass AST consistency test
1292
1293 // DQ (12/13/2011): Is this executed...
1294 //printf ("Is this executed \n");
1295 //ROSE_ASSERT(false);
1296
1297 isFortranParameter = true;
1298 }
1299 }
1300 }
1301 if (! isFortranParameter) // No need to add symbol to the function body if it is a Fortran parameter
1302 // The symbol should already exist under function definition for the parameter
1303 fixVariableDeclaration(varDecl,scope);
1304 }
1305
1306 SgInitializedName *initName = varDecl->get_decl_item (name);
1307 ROSE_ASSERT(initName != NULL);
1308 ROSE_ASSERT((initName->get_declptr())!=NULL);
1309
1310 //bug 119, SgVariableDefintion's File_info is needed for deep copy to work
1311 // AstQuery based setSourcePositionForTransformation() cannot access all child nodes
1312 // have to set SgVariableDefintion explicitly
1313 SgDeclarationStatement* variableDefinition_original = initName->get_declptr();
1314 setOneSourcePositionForTransformation(variableDefinition_original);
1315 ROSE_ASSERT((variableDefinition_original->get_startOfConstruct()) !=NULL);
1316 ROSE_ASSERT((variableDefinition_original->get_endOfConstruct())!=NULL);
1317
1319 unsetNodesMarkedAsModified(varDecl);
1320
1321 return varDecl;
1322}
1323
1324//-----------------------------------------------
1325// could have two declarations for a same variable
1326// extern int i;
1327// int i;
1330 {
1331
1332#define DEBUG_BUILD_VARIABLE_DECLARATION 0
1333
1334#if DEBUG_BUILD_VARIABLE_DECLARATION
1335 printf ("In SageBuilder::buildVariableDeclaration_nfi(): name = %s scope = %p varInit = %p \n",name.str(),scope,varInit);
1336 if (scope != nullptr)
1337 {
1338 printf (" --- scope = %p = %s \n",scope,scope->class_name().c_str());
1339 }
1340#endif
1341
1342 if (scope == nullptr)
1343 {
1344#if DEBUG_BUILD_VARIABLE_DECLARATION
1345 printf ("Scope determined from the SageBuilder::topScopeStack() \n");
1346#endif
1348 }
1349
1350 ROSE_ASSERT (scope != NULL);
1351 ROSE_ASSERT(type != NULL);
1352
1353 // DQ (7/18/2012): Added debugging code (should fail for test2011_75.C).
1354 SgVariableSymbol* variableSymbol = scope->lookup_variable_symbol(name);
1355
1356#if DEBUG_BUILD_VARIABLE_DECLARATION
1357 printf ("In SageBuilder::buildVariableDeclaration_nfi(): variableSymbol = %p \n",variableSymbol);
1358#endif
1359
1360 // If there was a previous use of the variable, then there will be an existing symbol with it's declaration pointing to the SgInitializedName object.
1361 SgVariableDeclaration* varDecl = nullptr;
1362 if (variableSymbol == nullptr)
1363 {
1364 varDecl = new SgVariableDeclaration(name, type, varInit);
1365#if DEBUG_BUILD_VARIABLE_DECLARATION
1366 SgInitializedName* tmp_initializedName = getFirstInitializedName(varDecl);
1367 ROSE_ASSERT(tmp_initializedName != NULL);
1368 printf ("In SageBuilder::buildVariableDeclaration_nfi(): variableSymbol == NULL: varDecl = %p: initializedName = %p = %s \n",varDecl,tmp_initializedName,tmp_initializedName->get_name().str());
1369 printf (" --- tmp_initializedName->get_initptr() = %p \n",tmp_initializedName->get_initptr());
1370#endif
1371 // DQ (6/25/2019): This is a new feature to input the builtFromUseOnly function optional parameter.
1372 if (builtFromUseOnly == true)
1373 {
1374#if DEBUG_BUILD_VARIABLE_DECLARATION
1375 printf ("In buildVariableDeclaration_nfi(): this is the first reference to this variable: building a new SgVariableDeclaration: varDecl = %p name = %s \n",varDecl,name.str());
1376#endif
1377 varDecl->set_builtFromUseOnly(true);
1378 }
1379 }
1380 else
1381 {
1382 SgInitializedName* initializedName = variableSymbol->get_declaration();
1383 ROSE_ASSERT(initializedName != NULL);
1384
1385 SgVariableDeclaration* associatedVariableDeclaration = isSgVariableDeclaration(initializedName->get_parent());
1386
1387#if DEBUG_BUILD_VARIABLE_DECLARATION
1388 printf ("In SageBuilder::buildVariableDeclaration_nfi(): initializedName->get_parent() = %p \n",initializedName->get_parent());
1389 if (initializedName->get_parent() != nullptr)
1390 {
1391 printf ("In SageBuilder::buildVariableDeclaration_nfi(): initializedName->get_parent() = %p = %s \n",initializedName->get_parent(),initializedName->get_parent()->class_name().c_str());
1392 }
1393 printf ("In SageBuilder::buildVariableDeclaration_nfi(): associatedVariableDeclaration = %p \n",associatedVariableDeclaration);
1394#endif
1395#if DEBUG_BUILD_VARIABLE_DECLARATION
1396 // DQ (6/24/2019): If this has been previously built as part of a variable use (in a class declaration),
1397 // then it should not be attached to the class definition as a variable declaration yet, and we should reuse it.
1398 if (associatedVariableDeclaration != nullptr && associatedVariableDeclaration->get_parent() != nullptr)
1399 {
1400 printf ("In SageBuilder::buildVariableDeclaration_nfi(): associatedVariableDeclaration->get_parent() = %p = %s \n",
1401 associatedVariableDeclaration->get_parent(),associatedVariableDeclaration->get_parent()->class_name().c_str());
1402 }
1403#endif
1404
1405#if DEBUG_BUILD_VARIABLE_DECLARATION
1406 printf ("associatedVariableDeclaration = %p \n",associatedVariableDeclaration);
1407 if (associatedVariableDeclaration != nullptr)
1408 {
1409 printf ("associatedVariableDeclaration->get_builtFromUseOnly() = %s \n",associatedVariableDeclaration->get_builtFromUseOnly() ? "true" : "false");
1410 }
1411#endif
1412
1413 // DQ (6/25/2019): Trigger the reuse of the available variable declaration.
1414 bool reuseTheAssociatedVariableDeclaration = ((associatedVariableDeclaration != nullptr) && (associatedVariableDeclaration->get_builtFromUseOnly() == true));
1415 if (reuseTheAssociatedVariableDeclaration == true)
1416 {
1417 // Build a seperate SgVariableDeclaration so that we can avoid sharing the SgInitializedName
1418 // (and it's possible initializer which would be an error for the secondary declaration
1419 // (the declaration in the class for the case of a static declaration))
1420
1421 ROSE_ASSERT(associatedVariableDeclaration != NULL);
1422
1423 // DQ (6/24/2019): Fix this to use the associatedVariableDeclaration.
1424 varDecl = associatedVariableDeclaration;
1425
1426 // DQ (6/25/2019): Mark this variable declaration so that it will not be reused again.
1427 varDecl->set_builtFromUseOnly(false);
1428
1429 // DQ (6/24/2019): Set the parent to NULL, since we are reusing this variable declaration and it would not have been set correctly before.
1430 varDecl->set_parent(nullptr);
1431
1432 // DQ (6/24/2019): this veriable declaration that is being reused, should not have had an initializer (check this).
1434 ROSE_ASSERT(variable != NULL);
1435
1436#if DEBUG_BUILD_VARIABLE_DECLARATION
1437 if (variable->get_initptr() != nullptr)
1438 {
1439 printf ("Found initializer associated with variable declaration being reused: variable = %p name = %s \n",variable,variable->get_name().str());
1440 }
1441#endif
1442 // DQ (7/3/2019): Reuse in a conditional will have a valid initializer.
1443 }
1444 else
1445 {
1446 // DQ (6/25/2019): We can't reuse the existing SgInitializedName, because it could have been initialized in the other SgVariableDeclaration.
1447 ROSE_ASSERT(reuseTheAssociatedVariableDeclaration == false);
1448
1449 // DQ (6/27/2019): If the SgInitializedName was generated from the convert_variable_use() function in the
1450 // EDG/ROSE translation, then where was not associated SgVariableDeclaration built (an inconsistancy).
1451 // So we want to check for the parent being a scope statement (e.g. SgIfStmt or other statement that can
1452 // accept a conditional expression where in C++ it can alternatively declare a variable.
1453 if (associatedVariableDeclaration == nullptr)
1454 {
1455 ROSE_ASSERT(initializedName->get_parent() != NULL);
1456 SgScopeStatement* scopeStatement = isSgScopeStatement(initializedName->get_parent());
1457 if (scopeStatement != nullptr)
1458 {
1459#if DEBUG_BUILD_VARIABLE_DECLARATION
1460 printf ("scopeStatement = %p = %s \n",scopeStatement,scopeStatement->class_name().c_str());
1461#endif
1462 }
1463 else
1464 {
1465#if DEBUG_BUILD_VARIABLE_DECLARATION
1466 printf ("initializedName->get_parent() = %p = %s \n",initializedName->get_parent(),initializedName->get_parent()->class_name().c_str());
1467#endif
1468 }
1469 }
1470
1471 // DQ (6/27/2019): In some case we want to reuse the associated SgInitializedName node.
1472 // For example: variable declarations in conditionals (e.g. SgIfStmt, and other scope statements).
1473 // DQ (6/26/2019): Build an additional variable to support another reference to the original variable.
1474 // Note: we need another one because either one can have an initializer that cannot be shared in the AST.
1475 SgInitializedName* additional_variable = nullptr;
1476
1477#if DEBUG_BUILD_VARIABLE_DECLARATION
1478 printf ("In SageBuilder::buildVariableDeclaration_nfi(): initializedName->get_scope() = %p = %s \n",initializedName->get_scope(),initializedName->get_scope()->class_name().c_str());
1479#endif
1480 SgScopeStatement* scopeStatement = isSgScopeStatement(initializedName->get_parent());
1481 if (scopeStatement != nullptr)
1482 {
1483 additional_variable = initializedName;
1484 if (additional_variable->get_initptr() != nullptr)
1485 {
1486#if DEBUG_BUILD_VARIABLE_DECLARATION
1487 printf ("In SageBuilder::buildVariableDeclaration_nfi(): borrowed SgInitializedName is alread initialized \n");
1488 printf (" --- additional_variable->get_initptr() = %p \n",additional_variable->get_initptr());
1489 printf (" --- varInit = %p \n",varInit);
1490#endif
1491 // DQ (6/28/2019): when this is assertion is false, we have constructed a redundant initializer (debugging this).
1492 // PP (7/22/2019) faults in CUDA code
1493 }
1494 else
1495 {
1496 additional_variable->set_initptr(varInit);
1497 }
1498
1499#if DEBUG_BUILD_VARIABLE_DECLARATION || 0
1500 printf (" --- additional_variable->get_scope() = %p = %s \n",additional_variable->get_scope(),additional_variable->get_scope()->class_name().c_str());
1501 printf (" --- Reusing the SgInitializedName (not associated with a previous SgVariableDeclaration where the parent is a SgScopeStatement) \n");
1502#endif
1503 }
1504 else
1505 {
1506#if DEBUG_BUILD_VARIABLE_DECLARATION
1507 printf (" --- Building a new SgInitializedName \n");
1508#endif
1509 additional_variable = buildInitializedName_nfi(name,type,varInit);
1510 }
1511
1512#if DEBUG_BUILD_VARIABLE_DECLARATION
1513 ROSE_ASSERT(initializedName->get_scope() != NULL);
1514#endif
1515 // DQ (6/26/2019): Set the scopes to be the same (a symbol already exists at this point).
1516 // DQ (6/26/2019): Set the pointer to the original version of this variable (unless we reused the SgInitializedName above).
1517 if (additional_variable != initializedName)
1518 {
1519 additional_variable->set_prev_decl_item(initializedName);
1520 }
1521
1522 // If there is not an associated SgVariableDeclaration then reuse the existing SgInitializedName.
1523 varDecl = new SgVariableDeclaration(additional_variable);
1524#if DEBUG_BUILD_VARIABLE_DECLARATION
1525 ROSE_ASSERT(initializedName->get_parent() != NULL);
1526 printf ("initializedName->get_parent() = %p = %s \n",initializedName->get_parent(),initializedName->get_parent()->class_name().c_str());
1527 ROSE_ASSERT(additional_variable->get_parent() != NULL);
1528 printf ("additional_variable->get_parent() = %p = %s \n",additional_variable->get_parent(),additional_variable->get_parent()->class_name().c_str());
1529#endif
1530 // DQ (6/26/2019): Set the parent of the first SgInitializedName to that of the second SgInitializedName.
1531 // This is an issue for the range for initialization: see test2019_483.C.
1532
1533 ASSERT_not_null(initializedName->get_scope());
1534
1535 // DQ (6/26/2019): Set the pointer to the original version of this variable (unless we reused the SgInitializedName above).
1536 if (additional_variable != initializedName)
1537 {
1538 additional_variable->set_scope(initializedName->get_scope());
1539 }
1540 // DQ (7/14/2014): Set the variable initialized (see test2014_107.C, also required for boost for_each support)).
1541 // initializedName->set_initptr(varInit);
1542#if DEBUG_BUILD_VARIABLE_DECLARATION
1543 printf ("In SageBuilder::buildVariableDeclaration_nfi(): After sharing the exisitng SgInitializedName: initializedName = %p = %s \n",initializedName,initializedName->get_name().str());
1544 printf (" --- initializedName->get_initptr() = %p \n",initializedName->get_initptr());
1545 printf (" --- additional_variable->get_initptr() = %p \n",additional_variable->get_initptr());
1546#endif
1547 }
1548 }
1549
1550 // DQ (11/3/2012): The SgInitializedName inside the SgVariableDeclaration must have valid source position object (even if default initialized).
1552 ASSERT_not_null(variable);
1554
1555 ASSERT_not_null(varDecl);
1556 varDecl->set_firstNondefiningDeclaration(varDecl);
1557 varDecl->get_declarationModifier().get_storageModifier().set_modifier(sm);
1558
1559 // DQ (7/9/2012): Added test (parent should not be set yet; set in parse_statement).
1560 ROSE_ASSERT(varDecl->get_parent() == NULL);
1561
1562 if (name != "")
1563 {
1564 // Anonymous bit fields should not have symbols
1565 fixVariableDeclaration(varDecl,scope);
1566
1567 // DQ (7/9/2012): Added test (parent should not be set yet; set in parse_statement).
1568 }
1569 else
1570 {
1571 // DQ (7/12/2012): This is not correct for C++ (to use the input scope), so don't set it here (unless we use the current scope instead of scope).
1572 // Yes, let's set it to the current top of the scope stack. This might be a problem if the scope stack is not being used...
1573 varDecl->set_parent(topScopeStack());
1574 ASSERT_not_null(varDecl->get_parent());
1575 }
1576
1577 SgInitializedName *initName = varDecl->get_decl_item (name);
1578 ASSERT_not_null(initName);
1579 ASSERT_not_null(initName->get_declptr());
1580
1581 if (initName->get_scope())
1582 {
1583 // Make this a warning for the few places where this fails.
1584#if DEBUG_BUILD_VARIABLE_DECLARATION
1585 printf ("WARNING: Note in buildVariableDeclaration_nfi(): initName->get_scope() == NULL \n");
1586#endif
1587 }
1588
1589 // DQ (7/9/2012): Added test (parent should not be set yet; set in parse_statement).
1590 // bug 119, SgVariableDefintion's File_info is needed for deep copy to work
1591 // AstQuery based setSourcePositionForTransformation() cannot access all child nodes
1592 // have to set SgVariableDefintion explicitly
1593 SgVariableDefinition* variableDefinition_original = isSgVariableDefinition(initName->get_declptr());
1594 ASSERT_not_null(variableDefinition_original);
1595 setOneSourcePositionNull(variableDefinition_original);
1596 setOneSourcePositionNull(varDecl);
1597
1598 // DQ (7/12/2012): The parent should be set to the current scope (not the same as that specified
1599 // in the scope (since that applies to the variable (SgInitializedName) not the SgVariableDeclaration).
1600 // Liao, 1/23/2013, quick fix for now, this condition is a mirror to the code setting parent in SageInterface::fixVariableDeclaration()
1601 if (topScopeStack())
1602 {
1603 ASSERT_not_null(varDecl->get_parent());
1604 }
1605
1606 // DQ (4/16/2015): This is replaced with a better implementation.
1607 // DQ (4/15/2015): We should reset the isModified flags as part of the transforamtion
1608 // because we have added statements explicitly marked as transformations.
1609 unsetNodesMarkedAsModified(varDecl);
1610
1611 ASSERT_not_null(varDecl);
1612
1613#if DEBUG_BUILD_VARIABLE_DECLARATION
1614 printf ("Leaving buildVariableDeclaration_nfi(): varDecl = %p varDecl->get_parent() = %p \n",varDecl,varDecl->get_parent());
1615#endif
1616
1617 return varDecl;
1618 }
1619
1620
1623{
1624// refactored from ROSETTA/Grammar/Statement.code SgVariableDeclaration::append_variable ()
1625
1626 ASSERT_not_null(decl);
1627 ASSERT_not_null(init_name);
1628 // init can be NULL
1629
1630 SgVariableDefinition* defn_stmt = nullptr;
1631 if (!isSgFunctionType(init_name->get_type()))
1632 {
1633 Sg_File_Info* copyOfFileInfo = nullptr;
1634 if (decl->get_file_info() != nullptr)
1635 {
1636 copyOfFileInfo = new Sg_File_Info(*(decl->get_file_info()));
1637 ROSE_ASSERT (copyOfFileInfo != NULL);
1638
1639 // Note that the SgVariableDefinition will connect the new IR node into the AST.
1640 defn_stmt = new SgVariableDefinition(copyOfFileInfo, init_name, init);
1641 ROSE_ASSERT (defn_stmt != NULL);
1642
1643 copyOfFileInfo->set_parent(defn_stmt);
1644
1645 // DQ (3/13/2007): We can't enforce that the endOfConstruct is set (if the interface using the startOfConstruct is used.
1646 // DQ (2/3/2007): Need to build the endOfConstruct position as well.
1647 if (decl->get_endOfConstruct() != nullptr)
1648 {
1649 Sg_File_Info* copyOfEndOfConstruct = new Sg_File_Info(*(decl->get_endOfConstruct()));
1650 defn_stmt->set_endOfConstruct(copyOfEndOfConstruct);
1651 copyOfEndOfConstruct->set_parent(defn_stmt);
1652 }
1653 }
1654 else
1655 {
1656 // Note that the SgVariableDefinition will connect the new IR node into the AST.
1657 defn_stmt = new SgVariableDefinition(init_name, init);
1658 }
1659 ROSE_ASSERT(defn_stmt != NULL);
1660 }
1661 else
1662 defn_stmt = nullptr;
1663 return defn_stmt ;
1664}
1665
1666
1669{
1672 return res;
1673}
1674
1677 {
1678 ROSE_ASSERT (scope != NULL);
1679 ROSE_ASSERT(type != NULL);
1680
1681 SgTemplateVariableDeclaration * varDecl = new SgTemplateVariableDeclaration(name, type, varInit);
1682 ROSE_ASSERT(varDecl);
1683
1684 varDecl->set_firstNondefiningDeclaration(varDecl);
1685
1686 // DQ (11/3/2012): The SgInitializedName inside the SgVariableDeclaration must have valid source position object (even if default initialized).
1688 ROSE_ASSERT(variable != NULL);
1690
1691 if (name != "")
1692 {
1693 // Anonymous bit fields should not have symbols
1694 fixVariableDeclaration(varDecl,scope);
1695 }
1696
1697 SgInitializedName *initName = varDecl->get_decl_item (name);
1698 ROSE_ASSERT(initName);
1699 ROSE_ASSERT((initName->get_declptr())!=NULL);
1700
1701 // bug 119, SgVariableDefintion's File_info is needed for deep copy to work
1702 // AstQuery based setSourcePositionForTransformation() cannot access all child nodes
1703 // have to set SgVariableDefintion explicitly
1704 SgVariableDefinition* variableDefinition_original = isSgVariableDefinition(initName->get_declptr());
1705 ROSE_ASSERT(variableDefinition_original != NULL);
1706 setOneSourcePositionNull(variableDefinition_original);
1707
1708 setOneSourcePositionNull(varDecl);
1709
1710 return varDecl;
1711 }
1712
1715 const SgName & name, SgType *type, SgInitializer *varInit, SgScopeStatement* scope,
1717 SgTemplateArgumentPtrList & tpl_args
1718) {
1719 SgTemplateVariableInstantiation* res = buildTemplateVariableInstantiation_nfi(name, type, varInit, scope, tpl_decl, tpl_args);
1721 return res;
1722}
1723
1724#define DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi 0
1725
1728 const SgName& name, SgType* type, SgInitializer* varInit, SgScopeStatement* scope,
1729 SgTemplateVariableDeclaration* /*tpl_decl*/, SgTemplateArgumentPtrList& tpl_args) {
1730#if DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi
1731 std::cout << "SageBuilder::buildTemplateVariableInstantiation_nfi" << std::endl;
1732 std::cout << " name = " << name.getString() << std::endl;
1733 std::cout << " type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
1734 std::cout << " scope = " << std::hex << scope << " : " << ( scope ? scope->class_name() : "" ) << std::endl;
1735#endif
1736 ASSERT_not_null(type);
1737
1738 SgName nameWithoutTemplateArguments = name;
1739 SgName nameWithTemplateArguments = appendTemplateArgumentsToName(name,tpl_args);
1740#if DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi
1741 std::cout << " nameWithoutTemplateArguments = " << nameWithoutTemplateArguments.getString() << std::endl;
1742 std::cout << " nameWithTemplateArguments = " << nameWithTemplateArguments.getString() << std::endl;
1743#endif
1744
1745 ASSERT_not_null(scope);
1746 ASSERT_not_null(type);
1747
1748 SgTemplateVariableInstantiation * varDecl = new SgTemplateVariableInstantiation(name, type, varInit);
1749 ROSE_ASSERT(varDecl);
1750#if DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi
1751 std::cout << " varDecl = " << std::hex << varDecl << " : " << ( varDecl ? varDecl->class_name() : "" ) << std::endl;
1752#endif
1753
1754 varDecl->set_firstNondefiningDeclaration(varDecl);
1755 varDecl->get_templateArguments() = tpl_args;
1756
1758 ROSE_ASSERT(variable != NULL);
1760
1761 if (name != "") {
1762 fixVariableDeclaration(varDecl, scope);
1763 }
1764
1765 SgInitializedName* initName = varDecl->get_decl_item(name);
1766 ASSERT_not_null(initName);
1767 ASSERT_not_null((initName->get_declptr()));
1768#if DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi
1769 std::cout << " initName = " << std::hex << initName << " : " << ( initName ? initName->class_name() : "" ) << std::endl;
1770#endif
1771
1772 SgVariableDefinition* variableDefinition_original = isSgVariableDefinition(initName->get_declptr());
1773 ASSERT_not_null(variableDefinition_original);
1774 setOneSourcePositionNull(variableDefinition_original);
1775 setOneSourcePositionNull(varDecl);
1776
1777 return varDecl;
1778 }
1779
1781SageBuilder::buildVariableDeclaration(const std::string & name, SgType* type, SgInitializer * varInit, SgScopeStatement* scope)
1782{
1783 SgName name2(name);
1784 return buildVariableDeclaration(name2,type, varInit,scope);
1785}
1786
1789{
1790 SgName name2(name);
1791 return buildVariableDeclaration(name2,type, varInit,scope);
1792}
1793
1796SageBuilder::buildTypedefDeclaration(const std::string& name, SgType* base_type, SgScopeStatement* scope /*= NULL*/, bool has_defining_base/*= false*/)
1797{
1798 SgTypedefDeclaration* type_decl = buildTypedefDeclaration_nfi(name, base_type, scope, has_defining_base);
1800
1801 return type_decl;
1802}
1803
1805// The side effects include: creating SgTypedefType, SgTypedefSymbol, and add SgTypedefType to the base type
1807SageBuilder::buildTypedefDeclaration_nfi(const std::string& name, SgType* base_type, SgScopeStatement* scope /*= NULL*/, bool has_defining_base/*=false*/)
1808 {
1809 ROSE_ASSERT (base_type != NULL);
1810
1811 if (scope == NULL )
1812 {
1814 }
1815
1816 // We don't yet support bottom up construction for this node yet
1817 ASSERT_not_null(scope);
1818
1819 SgDeclarationStatement* base_decl = nullptr;
1820
1821 // Handle the case where this is a pointer, reference, or typedef to another type.
1822 SgType* stripedBaseType = base_type->stripType();
1823 ASSERT_not_null(stripedBaseType);
1824
1825 SgNamedType* namedType = isSgNamedType(stripedBaseType);
1826 if (namedType)
1827 {
1828 // DQ (12/28/2019): the problem with getting the base declaration from the type is that it forces sharing
1829 // of the base declaration when the typedef has a defining declaration for a base type in multiple files.
1830
1831 // DQ (3/20/2012): Use this to set the value of base_decl (which was previously unset).
1832 // isSgNamedType(base_type)->get_declaration();
1833 // base_decl = isSgNamedType(base_type)->get_declaration();
1834 base_decl = namedType->get_declaration();
1835
1836 // DQ (3/20/2012): All named types should have a valid declaration!
1837 ROSE_ASSERT(base_decl != NULL);
1838 }
1839
1840 // DQ (3/20/2012): I don't remember why we need to provide the symbol for the scope of the
1841 // parent rather then the scope. But as I recall there was a special corner of C++ that
1842 // required this sort of support.
1843 SgSymbol* parent_scope = NULL;
1844#ifndef ROSE_USE_CLANG_FRONTEND
1845 if (scope != NULL)
1846 {
1847 ROSE_ASSERT(scope->get_parent() != NULL);
1848 SgDeclarationStatement* declaration = isSgDeclarationStatement(scope->get_parent());
1849
1850 // PP (3/9/22)
1851 // In Ada, discriminated type may not have been fully built yet.
1852 // this is because a the discriminated type obtains the name of the underlying
1853 // declaration.
1854 // PP (5/9/22)
1855 // Unsure if declaration link should be set at all for Ada.
1856 // The AstConsistencyTest flags typedefdecls with declaration link set...
1857 if (declaration && !isSgAdaDiscriminatedTypeDecl(declaration))
1858 {
1859 mprintf ("Found a valid declaration = %p = %s \n",declaration,declaration->class_name().c_str());
1860
1861 ROSE_ASSERT(SageInterface::is_Ada_language() || declaration->get_firstNondefiningDeclaration() != NULL);
1862
1863 parent_scope = declaration->search_for_symbol_from_symbol_table();
1864
1865 ROSE_ASSERT(parent_scope != NULL);
1866 }
1867 }
1868#endif
1869
1870 // Create the first nondefining declaration (note that the typedef type is always a NULL input value).
1871 SgTypedefDeclaration* type_decl = new SgTypedefDeclaration(SgName(name), base_type, NULL, base_decl, parent_scope);
1872 ROSE_ASSERT(type_decl != NULL);
1873
1874 // TV (08/17/2018): moved it before building type as SgTypedefType::createType uses SgTemplateTypedefDeclaration::get_mangled_name which requires the scope to be set (else name of the associated type might not be unique)
1875 type_decl->set_scope(scope);
1876 type_decl->set_parent(scope);
1877
1878 // DQ (2/27/2018): Add this call here to reflect change to the constructor semantics.
1879 type_decl->set_type(SgTypedefType::createType(type_decl));
1880
1881 // DQ (3/20/2012): Comment ouly, these are always set this way. first defining is a self reference, and defining is always NULL (required for AST consistancy)).
1882 type_decl->set_firstNondefiningDeclaration (type_decl);
1883 type_decl->set_definingDeclaration(NULL);
1884
1885 // Set the source code position information.
1886 setOneSourcePositionNull(type_decl);
1887
1888 // Liao 11/29/2012, for typedef struct Frame {int x;} st_frame; We have to set parent for the struct.
1889 // AstPostProcessing() has resetParentPointers(). But it is kind of too late.
1890 if (SgClassDeclaration* base_class = isSgClassDeclaration(base_decl))
1891 {
1892 SgClassDeclaration* def_class = isSgClassDeclaration(base_class->get_definingDeclaration());
1893 SgClassDeclaration* nondef_class = isSgClassDeclaration(base_class->get_firstNondefiningDeclaration());
1894 // Dan and Liao, 12/3/2012, handle test2003_08.C nested typedef
1895 if (has_defining_base)
1896 {
1897 if (def_class != NULL)
1898 if (def_class->get_parent() == NULL)
1899 def_class->set_parent(type_decl);
1900 }
1901 else
1902 {
1903 if (nondef_class != NULL)
1904 if (nondef_class->get_parent() == NULL)
1905 {
1906 nondef_class->set_parent(type_decl);
1907 }
1908 }
1909 }
1910
1911 SgTypedefSymbol* typedef_symbol = new SgTypedefSymbol(type_decl);
1912 ROSE_ASSERT(typedef_symbol);
1913
1914 scope->insert_symbol(SgName(name),typedef_symbol);
1915
1916 return type_decl;
1917 }
1918
1919
1921SageBuilder::buildTemplateTypedefDeclaration_nfi(const SgName& name, SgType* base_type, SgScopeStatement* scope, bool /*has_defining_base*/)
1922{
1923 ASSERT_not_null(base_type);
1924
1925 if (scope == nullptr) {
1927 }
1928
1929 // We don't yet support bottom up construction for this node yet
1930 ASSERT_not_null(scope);
1931
1932 SgDeclarationStatement* base_decl = nullptr;
1933
1934 // DQ (3/20/2012): I don't remember why we need to provide the symbol for the scope of the
1935 // parent rather then the scope. But as I recall there was a special corner of C++ that
1936 // required this sort of support.
1937 SgSymbol* parent_scope = NULL;
1938 if (scope != NULL)
1939 {
1940 ROSE_ASSERT(scope->get_parent() != NULL);
1941 SgDeclarationStatement* declaration = isSgDeclarationStatement(scope->get_parent());
1942
1943 if (declaration != NULL)
1944 {
1945 ROSE_ASSERT(declaration->get_firstNondefiningDeclaration() != NULL);
1946 parent_scope = declaration->search_for_symbol_from_symbol_table();
1947
1948 ROSE_ASSERT(parent_scope != NULL);
1949 }
1950 // DQ (2/28/2018): check out if the symbol associated with the declaration used for the base type used in this typedef has a symbol.
1951 SgNamedType* namedType = isSgNamedType(base_type);
1952
1953 // DQ (3/4/2018): This might not always be true (sure enough it fails for Cxx11_tests/test2014_58.C).
1954
1955 if (namedType != NULL)
1956 {
1957 SgDeclarationStatement* declarationStatement = namedType->get_declaration();
1958
1959 // This might not always be true.
1960 ROSE_ASSERT(declarationStatement != NULL);
1961 if (declarationStatement != NULL)
1962 {
1963 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(declarationStatement);
1964 if (templateInstantiationDecl != NULL)
1965 {
1966 SgName name = templateInstantiationDecl->get_name();
1967 // DQ (2/28/2018): Added debugging to track down redundnat symbol.
1968 if (scope->lookup_template_typedef_symbol(name) != NULL)
1969 {
1970 printf ("Error: it appears that there is already a symbol in scope = %p = %s for name = %s \n",scope,scope->class_name().c_str(),name.str());
1971 }
1972 ROSE_ASSERT(scope->lookup_template_typedef_symbol(name) == NULL);
1973 }
1974 }
1975 }
1976 }
1977
1978 // We need to add the template parameter and partial specialization support to the SgTemplateTypedefDeclaration IR node.
1979 SgTemplateTypedefDeclaration* type_decl = new SgTemplateTypedefDeclaration(name, base_type, NULL, base_decl, parent_scope);
1980 ROSE_ASSERT(type_decl != NULL);
1981
1982 // TV (08/17/2018): moved it before building type as SgTypedefType::createType uses SgTemplateTypedefDeclaration::get_mangled_name which requires the scope to be set (else name of the associated type might not be unique)
1983 type_decl->set_scope(scope);
1984 type_decl->set_parent(scope);
1985
1986 // DQ (2/27/2018): We now have to set the type explicitly.
1987 ROSE_ASSERT(type_decl->get_type() == NULL);
1988
1989 SgTypedefType* typedefType = SgTypedefType::createType(type_decl);
1990 ROSE_ASSERT(typedefType != NULL);
1991
1992 // DQ (2/27/2018): It is an inconsistancy for the type to be set here.
1993 type_decl->set_type(typedefType);
1994
1995 // DQ (2/27/2018): This should be non-null, since we just built the new type.
1996 ROSE_ASSERT(type_decl->get_type() != NULL);
1997
1998 // DQ (3/20/2012): Comment ouly, these are always set this way. first defining is a self reference, and defining is always NULL (required for AST consistancy)).
1999 type_decl->set_firstNondefiningDeclaration (type_decl);
2000 type_decl->set_definingDeclaration(NULL);
2001
2002 // Set the source code position information.
2003 setOneSourcePositionNull(type_decl);
2004
2005 // DQ (2/28/2018): check out if the symbol associated with the declaration used for the base type used in this typedef has a symbol.
2006 SgNamedType* namedType = isSgNamedType(base_type);
2007
2008 // DQ (3/4/2018): This might not always be true (sure enough it fails for Cxx11_tests/test2014_58.C).
2009
2010 if (namedType != NULL)
2011 {
2012 SgDeclarationStatement* declarationStatement = namedType->get_declaration();
2013
2014 // This might not always be true.
2015 ROSE_ASSERT(declarationStatement != NULL);
2016 if (declarationStatement != NULL)
2017 {
2018 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(declarationStatement);
2019 if (templateInstantiationDecl != NULL)
2020 {
2021 SgName name = templateInstantiationDecl->get_name();
2022 // DQ (2/28/2018): Added debugging to track down redundnat symbol.
2023 if (scope->lookup_template_typedef_symbol(name) != NULL)
2024 {
2025 printf ("Error: it appears that there is already a symbol in scope = %p = %s for name = %s \n",scope,scope->class_name().c_str(),name.str());
2026 }
2027 ROSE_ASSERT(scope->lookup_template_typedef_symbol(name) == NULL);
2028 }
2029 }
2030 }
2031
2032 SgTemplateTypedefSymbol* typedef_symbol = new SgTemplateTypedefSymbol(type_decl);
2033 ROSE_ASSERT(typedef_symbol);
2034
2035 // DQ (5/16/2013): This is the code we want now that we have implemented the namespace support behind the scope symbol bable interface.
2036 scope->insert_symbol(name, typedef_symbol);
2037
2038 ROSE_ASSERT(scope->lookup_template_typedef_symbol(name) != NULL);
2039
2040 return type_decl;
2041 }
2042
2043#define DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi 0
2044
2047 SgName& name, SgType* base_type, SgScopeStatement* scope, bool /*has_defining_base*/,
2048 SgTemplateTypedefDeclaration* templateTypedefDeclaration,
2049 SgTemplateArgumentPtrList & templateArgumentsList
2050) {
2051#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2052 std::cout << "SageBuilder::buildTemplateInstantiationTypedefDeclaration_nfi" << std::endl;
2053 std::cout << " name = " << name.getString() << std::endl;
2054 std::cout << " base_type = " << std::hex << base_type << " : " << ( base_type ? base_type->class_name() : "" ) << std::endl;
2055#endif
2056 ASSERT_not_null(base_type);
2057
2058 SgName nameWithoutTemplateArguments = name;
2059 SgName nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,templateArgumentsList);
2060#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2061 std::cout << " nameWithoutTemplateArguments = " << nameWithoutTemplateArguments.getString() << std::endl;
2062 std::cout << " nameWithTemplateArguments = " << nameWithTemplateArguments.getString() << std::endl;
2063#endif
2064
2065 // We don't yet support bottom up construction for this node yet
2066 ASSERT_not_null(scope);
2067 SgDeclarationStatement* base_decl = nullptr;
2068
2069 // DQ (3/20/2012): I don't remember why we need to provide the symbol for the scope of the
2070 // parent rather then the scope. But as I recall there was a special corner of C++ that
2071 // required this sort of support.
2072 SgSymbol* parent_scope = nullptr;
2073 if (scope != nullptr)
2074 {
2075 ASSERT_not_null(scope->get_parent());
2076 SgDeclarationStatement* declaration = isSgDeclarationStatement(scope->get_parent());
2077 if (declaration != nullptr)
2078 {
2079 ASSERT_not_null(declaration->get_firstNondefiningDeclaration());
2080 parent_scope = declaration->search_for_symbol_from_symbol_table();
2081 ASSERT_not_null(parent_scope);
2082 }
2083 }
2084 ASSERT_not_null(templateTypedefDeclaration);
2085
2086 SgTemplateTypedefSymbol* prexisting_template_typedef_symbol = scope->lookup_template_typedef_symbol(nameWithTemplateArguments);
2087 if (prexisting_template_typedef_symbol != nullptr)
2088 {
2089 SgDeclarationStatement* declarationStatement = prexisting_template_typedef_symbol->get_declaration();
2090 ASSERT_not_null(declarationStatement);
2091#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2092 std::cout << " declarationStatement = " << declarationStatement << " : " << declarationStatement->class_name() << std::endl;
2093#endif
2094 SgTemplateInstantiationTypedefDeclaration* return_declaration = isSgTemplateInstantiationTypedefDeclaration(declarationStatement);
2095 ASSERT_not_null(return_declaration);
2096 return return_declaration;
2097 }
2098 ASSERT_require(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == nullptr);
2099
2100 SgTypedefType* typedefType = nullptr;
2102 new SgTemplateInstantiationTypedefDeclaration(nameWithTemplateArguments, base_type, typedefType, base_decl, parent_scope, templateTypedefDeclaration, templateArgumentsList);
2103 ASSERT_not_null(type_decl);
2104 ASSERT_require(type_decl->get_base_type() == base_type);
2105
2106#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2107 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2108 std::cout << " ->get_base_type() = " << std::hex << type_decl->get_base_type() << " : " << ( type_decl->get_base_type() ? type_decl->get_base_type()->class_name() : "" ) << std::endl;
2109#endif
2110
2111 // DQ (2/27/2018): This is a change in the constructor semantics, we now have to build the type explicitly.
2112 ASSERT_require(type_decl->get_type() == nullptr);
2113
2114 // DQ (2/27/2018): Set the template name that this instantiation is using.
2115 type_decl->set_templateName(nameWithoutTemplateArguments);
2116
2117 ASSERT_not_null(scope);
2118 type_decl->set_scope(scope);
2119
2120 // DQ (3/1/2018): A bug in the name of the template with arguments has been detected (extra spaces in
2121 // the name generated by type_decl->resetTemplateName()), make sure that we have a consistant naming.
2122 ASSERT_require(type_decl->get_name() == nameWithTemplateArguments);
2123
2124 if (scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != nullptr)
2125 {
2126 printf ("Error: it appears that there is already a symbol in scope = %p = %s for name = %s \n",scope,scope->class_name().c_str(),name.str());
2127 }
2128 ASSERT_require(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == nullptr);
2129 ASSERT_require(type_decl->get_type() == nullptr);
2130
2131 SgTypedefType* new_typedefType = SgTypedefType::createType(type_decl);
2132 ASSERT_not_null(new_typedefType);
2133
2134 type_decl->set_type(new_typedefType);
2135 ASSERT_not_null(type_decl->get_type());
2136 ASSERT_not_null(type_decl->get_scope());
2137
2138 type_decl->set_firstNondefiningDeclaration(type_decl);
2139 type_decl->set_definingDeclaration(nullptr);
2140
2141 setOneSourcePositionNull(type_decl);
2142 setTemplateArgumentsInDeclaration(type_decl,&templateArgumentsList);
2143
2144 ASSERT_not_null(type_decl->get_firstNondefiningDeclaration());
2145 ASSERT_require(type_decl->get_definingDeclaration() == nullptr);
2146 ASSERT_require(type_decl->get_firstNondefiningDeclaration() == type_decl);
2147
2148 ASSERT_not_null(type_decl->get_type());
2149 ASSERT_not_null(scope);
2150
2151#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2152 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2153 std::cout << " ->get_base_type() = " << std::hex << type_decl->get_base_type() << " : " << ( type_decl->get_base_type() ? type_decl->get_base_type()->class_name() : "" ) << std::endl;
2154#endif
2155
2156 if (scope != nullptr)
2157 {
2158 if (scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != nullptr)
2159 {
2160 printf ("Error: it appears that there is already a symbol in scope = %p = %s for nameWithTemplateArguments = %s \n",scope,scope->class_name().c_str(),nameWithTemplateArguments.str());
2161 }
2162 ASSERT_require(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == nullptr);
2163
2164 SgTemplateTypedefSymbol* typedef_symbol = new SgTemplateTypedefSymbol(type_decl);
2165 ASSERT_not_null(typedef_symbol);
2166
2167 scope->insert_symbol(nameWithTemplateArguments,typedef_symbol);
2168 type_decl->set_scope(scope);
2169 type_decl->set_parent(scope);
2170 ASSERT_not_null(scope->lookup_template_typedef_symbol(nameWithTemplateArguments));
2171 }
2172
2173#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2174 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2175 std::cout << " ->get_base_type() = " << std::hex << type_decl->get_base_type() << " : " << ( type_decl->get_base_type() ? type_decl->get_base_type()->class_name() : "" ) << std::endl;
2176#endif
2177
2178 return type_decl;
2179 }
2180
2181//-----------------------------------------------
2182// Assertion `definingDeclaration != NULL || firstNondefiningDeclaration != NULL'
2185{
2186 SgFunctionParameterList *parameterList = new SgFunctionParameterList();
2187 ROSE_ASSERT (parameterList);
2188
2189 parameterList->set_definingDeclaration (NULL);
2190 parameterList->set_firstNondefiningDeclaration (parameterList);
2191
2193
2194 if (in1) appendArg(parameterList, in1);
2195 if (in2) appendArg(parameterList, in2);
2196 if (in3) appendArg(parameterList, in3);
2197 if (in4) appendArg(parameterList, in4);
2198 if (in5) appendArg(parameterList, in5);
2199 if (in6) appendArg(parameterList, in6);
2200 if (in7) appendArg(parameterList, in7);
2201 if (in8) appendArg(parameterList, in8);
2202 if (in9) appendArg(parameterList, in9);
2203 if (in10) appendArg(parameterList, in10);
2204
2205 return parameterList;
2206}
2207
2210 SgFunctionParameterList *parameterList = new SgFunctionParameterList();
2211 ROSE_ASSERT (parameterList);
2212 parameterList->set_definingDeclaration (NULL);
2213 parameterList->set_firstNondefiningDeclaration (parameterList);
2214
2215 setOneSourcePositionNull(parameterList);
2216
2217 return parameterList;
2218}
2219
2220//-----------------------------------------------
2223 SgCtorInitializerList *ctorInitList = new SgCtorInitializerList();
2224 ROSE_ASSERT (ctorInitList);
2225 ctorInitList->set_definingDeclaration (NULL);
2226 ctorInitList->set_firstNondefiningDeclaration (ctorInitList);
2227
2228 setOneSourcePositionNull(ctorInitList);
2229
2230 return ctorInitList;
2231}
2232
2233//-----------------------------------------------
2234// no type vs. void type ?
2237 {
2238 // DQ (8/19/2012): I am not a fan of this sort of codeing style either (NULL pointers as inputs should be an error).
2239 if (paralist == NULL)
2240 {
2241 printf ("WARNING: In buildFunctionParameterTypeList(): Accepting NULL input and returning NULL pointer. \n");
2242
2243 return NULL;
2244 }
2245
2246 // DQ (8/18/2012): This is a problem, any valid list (even zero length) should result in a valid return list of types (even zero length).
2247 // if (paralist->get_args().size()==0)
2248 // return NULL;
2249
2251 ROSE_ASSERT(typePtrList != NULL);
2252
2253 SgInitializedNamePtrList args = paralist->get_args();
2254 SgInitializedNamePtrList::const_iterator i;
2255 for(i = args.begin(); i != args.end(); i++)
2256 (typePtrList->get_arguments()).push_back( (*i)->get_type() );
2257
2259
2260 return typePtrList;
2261 }
2262
2263
2266 {
2267 if (expList ==NULL) return NULL;
2268 SgExpressionPtrList expPtrList = expList->get_expressions();
2269
2271 ROSE_ASSERT(typePtrList);
2272
2273 SgExpressionPtrList::const_iterator i;
2274 for (i=expPtrList.begin();i!=expPtrList.end();i++)
2275 {
2276 typePtrList->get_arguments().push_back( (*i)->get_type() );
2277 }
2278
2280
2281 return typePtrList;
2282 }
2283
2286 SgType* type4, SgType* type5, SgType* type6, SgType* type7)
2287 {
2289 ROSE_ASSERT(typePtrList);
2290
2291 SgTypePtrList & types = typePtrList->get_arguments();
2292
2293 if (type0 != NULL) types.push_back(type0);
2294 if (type1 != NULL) types.push_back(type1);
2295 if (type2 != NULL) types.push_back(type2);
2296 if (type3 != NULL) types.push_back(type3);
2297 if (type4 != NULL) types.push_back(type4);
2298 if (type5 != NULL) types.push_back(type5);
2299 if (type6 != NULL) types.push_back(type6);
2300 if (type7 != NULL) types.push_back(type7);
2301
2302 return typePtrList;
2303 }
2304
2305//-----------------------------------------------
2306// build function type,
2307//
2308// insert into symbol table when not duplicated
2311 {
2312 ROSE_ASSERT(return_type != NULL);
2313
2314 // DQ (8/19/2012): Can we enforce this?
2315 ROSE_ASSERT(typeList != NULL);
2316
2318 ROSE_ASSERT(fTable);
2319
2320 // This function make clever use of a static member function which can't be built
2321 // for the case of a SgMemberFunctionType (or at least not without more work).
2322 SgName typeName = SgFunctionType::get_mangled(return_type, typeList);
2323
2324 SgFunctionType* funcType = isSgFunctionType(fTable->lookup_function_type(typeName));
2325
2326 if (funcType == NULL)
2327 {
2328 // Only build the new type if it can't be found in the global type table.
2329 funcType = new SgFunctionType(return_type, false);
2330 ROSE_ASSERT(funcType);
2331
2332 if (typeList != NULL)
2333 {
2334 // DQ (12/5/2012): We want to avoid overwriting an existing SgFunctionParameterTypeList. Could be related to failing tests for AST File I/O.
2335 if (funcType->get_argument_list() != NULL)
2336 {
2337 delete funcType->get_argument_list();
2338 funcType->set_argument_list(NULL);
2339 }
2340 ROSE_ASSERT(funcType->get_argument_list() == NULL);
2341
2342 funcType->set_argument_list(typeList);
2343 typeList->set_parent(funcType);
2344 }
2345
2346 fTable->insert_function_type(typeName,funcType);
2347 }
2348 else
2349 {
2350 // DQ (12/6/2012): Tracking down orphaned SgFunctionParameterTypeList objects.
2351 }
2352
2353 return funcType;
2354 }
2355
2357SageBuilder::buildMemberFunctionType(SgType* return_type, SgFunctionParameterTypeList* typeList, SgType *classType, unsigned int mfunc_specifier)
2358 {
2359 // DQ (8/19/2012): This is a refactored version of the buildMemberFunctionType() below so that we can
2360 // isolate out the part that uses a SgClassType from the version that uses the SgClassDefinition.
2361
2362 // Maintain the global type table
2364 ROSE_ASSERT(fTable != NULL);
2365 ROSE_ASSERT(typeList != NULL);
2366
2367 SgName typeName = SgMemberFunctionType::get_mangled(return_type,typeList,classType,mfunc_specifier);
2368 SgType* typeInTable = fTable->lookup_function_type(typeName);
2369
2370 SgMemberFunctionType* funcType = NULL;
2371 if (typeInTable == NULL)
2372 {
2373 bool has_ellipses = false;
2374 // PP (10/4/22): removing ref_qualifiers
2375 SgPartialFunctionType* partialFunctionType = new SgPartialFunctionType(return_type, has_ellipses, classType, mfunc_specifier);
2376 ROSE_ASSERT(partialFunctionType != NULL);
2377
2378 // DQ (12/5/2012): We want to avoid overwriting an existing SgFunctionParameterTypeList. Could be related to failing tests for AST File I/O.
2379 if (partialFunctionType->get_argument_list() != NULL)
2380 {
2381 delete partialFunctionType->get_argument_list();
2382 partialFunctionType->set_argument_list(NULL);
2383 }
2384 ROSE_ASSERT(partialFunctionType->get_argument_list() == NULL);
2385
2386 typeList->set_parent(partialFunctionType);
2387
2388 // DQ (12/6/2012): Set the SgFunctionParameterTypeList in the SgPartialFunctionType before trying
2389 // to build a SgMemberFunctionType (not critical that it be set before, but might be in the future,
2390 // but it is important that it be set).
2391 partialFunctionType->set_argument_list(typeList);
2392
2393 ROSE_ASSERT(partialFunctionType->get_argument_list() != NULL);
2394
2395 // The optional_fortran_type_kind is only required for Fortran support.
2396 SgExpression* optional_fortran_type_kind = NULL;
2397 funcType = SgMemberFunctionType::createType(partialFunctionType, optional_fortran_type_kind);
2398
2399 // DQ (12/13/2012): Remove the SgPartialFunctionType after it has been used to build the SgMemberFunctionType.
2400 // I would rather modify the SgMemberFunctionType::createType() API so that we didn't use the SgPartialFunctionType IR nodes.
2401 // First we have to reset the pointer to the type argument list to NULL since it is shared with the SgMemberFunctionType.
2402 partialFunctionType->set_argument_list(NULL);
2403
2404 // Then we can delete the SgPartialFunctionType.
2405 delete partialFunctionType;
2406 partialFunctionType = NULL;
2407
2408 // This is perhaps redundant since it was set to a derived class (but might be an important distiction).
2409 typeList->set_parent(funcType);
2410
2411 ROSE_ASSERT(funcType->get_argument_list() != NULL);
2412 }
2413
2414 if (typeInTable == nullptr)
2415 {
2416 ASSERT_not_null(funcType);
2417 fTable->insert_function_type(typeName,funcType);
2418 }
2419 else
2420 {
2421 // DQ (12/3/2011): Added this case to support reuse of function types (not handled by the createType functions).
2422 // Delete the one generated so that we could form the mangled name.
2423 ASSERT_require(typeInTable != funcType);
2424 delete funcType;
2425
2426 // Return the one from the global type table.
2427 funcType = isSgMemberFunctionType(typeInTable);
2428 ASSERT_not_null(funcType);
2429 }
2430
2431 return funcType;
2432 }
2433
2434
2435// DQ (1/4/2009): Need to finish this!!!
2436//-----------------------------------------------
2437// build member function type,
2438//
2439// insert into symbol table when not duplicated
2441SageBuilder::buildMemberFunctionType(SgType* return_type, SgFunctionParameterTypeList* typeList, SgScopeStatement * struct_name, unsigned int mfunc_specifier)
2442 {
2443 // This function has to first build a version of the SgMemberFunctionType so that it can generate a mangled name.
2444 // If the mangled name can be use to lookup a SgMemberFunctionType then the "just built" SgMemberFunctionType
2445 // is deleted and the one from the global function type table is returned. This fixes a lot of subtle C++
2446 // specific issues with the build interface and it's use with the newer EDG 4.3 connection to ROSE.
2447
2448 ROSE_ASSERT(return_type != NULL);
2449 ROSE_ASSERT(struct_name != NULL);
2450 ROSE_ASSERT(struct_name->get_parent() != NULL);
2451
2452 SgClassDefinition* classDefinition = isSgClassDefinition(struct_name);
2453 SgDeclarationScope* decl_scope = isSgDeclarationScope(struct_name);
2454
2455 if (classDefinition == NULL && decl_scope == NULL)
2456 {
2457 printf ("Error: (classDefinition == NULL && decl_scope == NULL): struct_name = %p = %s name = %s \n",
2458 struct_name,struct_name->class_name().c_str(),SageInterface::get_name(struct_name).c_str());
2459 }
2460 ROSE_ASSERT(classDefinition != NULL || decl_scope != NULL);
2461
2462 SgDeclarationStatement* declaration = NULL;
2463 if (classDefinition != NULL)
2464 {
2465 declaration = classDefinition->get_declaration();
2466 }
2467 else if (decl_scope != NULL)
2468 {
2469 declaration = isSgDeclarationStatement(decl_scope->get_parent());
2470 }
2471 else
2472 {
2473 ROSE_ABORT();
2474 }
2475
2476 ROSE_ASSERT(declaration != NULL);
2477
2478 if (typeList == nullptr) {
2479 printf ("WARNING: typeList == NULL \n");
2480 }
2481
2482 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
2483 SgNonrealDecl * nrdecl = isSgNonrealDecl(declaration);
2484
2485 ROSE_ASSERT(classDeclaration != NULL || nrdecl != NULL);
2486
2487 SgType* classType = NULL;
2488 if (classDeclaration != NULL)
2489 {
2490 classType = classDeclaration->get_type();
2491 }
2492 else if (decl_scope != NULL)
2493 {
2494 classType = nrdecl->get_type();
2495 }
2496 else
2497 {
2498 ROSE_ABORT();
2499 }
2500 ROSE_ASSERT(classType != NULL);
2501
2502 return buildMemberFunctionType(return_type,typeList,classType,mfunc_specifier);
2503 }
2504
2507 {
2508 ROSE_ASSERT(base_type != NULL);
2509
2510 ROSE_ASSERT(classType != NULL);
2511 SgPointerMemberType* pointerToMemberType = new SgPointerMemberType(base_type,classType);
2512 return pointerToMemberType;
2513 }
2514
2515//----------------------------------------------------
2517SgType * SageBuilder::buildOpaqueType(std::string const name, SgScopeStatement * scope)
2518{
2519 // we require users to specify a target scope
2520 ASSERT_not_null(scope);
2521 SgTypedefDeclaration* type_decl = NULL;
2522 SgTypedefType* result = NULL;
2523
2524 // Liao and Greg Bronevetsky , 8/27/2009
2525 // patch up the symbol
2526 // and avoid duplicated creation
2527 // TODO a function like fixTypeDeclaration() (similar to SageInterface::fixVariableDeclaration()) for this
2528 SgTypedefSymbol* type_symbol = scope->lookup_typedef_symbol(name);
2529 if (type_symbol == NULL)
2530 {
2531 type_decl = new SgTypedefDeclaration(name,buildIntType(),NULL, NULL, NULL);
2532 ASSERT_not_null(type_decl);
2533
2534 type_decl->set_scope(scope); // PP (05/29/25): set the scope of the decl
2535
2536 // DQ (2/27/2018): Add this call here to reflect change to the constructor semantics.
2537 type_decl->set_type(SgTypedefType::createType(type_decl));
2538
2539 type_symbol = new SgTypedefSymbol(type_decl);
2540 ROSE_ASSERT(type_symbol);
2541 SgName n = name;
2542
2543 // DQ (5/21/2013): The symbol table should only be accessed through the SgScopeStatement interface.
2544 scope->insert_symbol(n,type_symbol);
2545
2546 type_decl->set_firstNondefiningDeclaration (type_decl);
2548 prependStatement(type_decl,scope);
2549 // Hide it from unparser
2550 Sg_File_Info* file_info = type_decl->get_file_info();
2551 file_info->unsetOutputInCodeGeneration ();
2552 result = new SgTypedefType(type_decl); // QUESTION: PP: why do not we return type_decl->get_type()?
2553 }
2554 else
2555 {
2556 type_decl = type_symbol->get_declaration();
2557 result = type_decl->get_type();
2558 }
2559 ASSERT_not_null(result);
2560 return result;
2561}
2562
2563
2564//----------------- function type------------
2565// same function declarations (defining or nondefining) should share the same function type!
2568 {
2569 ASSERT_not_null(argList);
2570
2572 SgFunctionType* func_type = buildFunctionType(return_type, typeList);
2573
2574 if (func_type->get_argument_list() != typeList)
2575 {
2576 delete typeList;
2577 typeList = NULL;
2578 }
2579
2580 return func_type;
2581 }
2582
2583void
2584checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope ( SgDeclarationStatement* func, SgScopeStatement* scope )
2585 {
2586 // DQ (12/14/2011): We need the parent to be set so that we can call some of the test functions
2587 // (e.g assert that get_class_scope() for member functions). So we set the parent to the scope
2588 // by default and see if this will work, else we could disable to assertion that the parent is
2589 // non-null in the get_class_scope() member function.
2590
2591 if (isSgMemberFunctionDeclaration(func) != NULL)
2592 {
2593#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
2594 printf ("WARNING: setting parent of function to match scope by default \n");
2595#endif
2596 func->set_parent(scope);
2597
2598 ROSE_ASSERT(scope != NULL);
2599
2600 if (isSgTemplateInstantiationMemberFunctionDecl(func) != NULL)
2601 {
2602 // DQ (12/14/2011): We should not have a member function template instantiation in a template class definition.
2603
2604 // DQ (8/25/2014): Un-Commented out to revert to previous working state.
2605 // DQ (8/25/2014): Commented out to test new logic at base of isTemplateDeclaration(a_routine_ptr).
2606 // DQ (8/25/2014): Un-Commented out to revert to previous working state.
2607 // DQ (8/25/2014): Allow non-template functions in a template class declaration (see test2014_161.C).
2608#if !ENFORCE_NO_FUNCTION_TEMPLATE_DECLARATIONS_IN_TEMPLATE_CLASS_INSTANTIATIONS
2609 // printf ("In checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(): This is the wrong scope that is associated with this function (because EDG uses a single pointeer for a scope that maps to two different scopes in ROSE (and the scope_cache is not reset) \n");
2610#endif
2611 }
2612 }
2613 else
2614 {
2615 if (isSgTemplateFunctionDeclaration(func) != NULL)
2616 {
2617 if (isSgTemplateInstantiationMemberFunctionDecl(func) != NULL)
2618 {
2619 ROSE_ASSERT(isSgTemplateClassDefinition(scope) != NULL);
2620 }
2621 }
2622 }
2623 }
2624
2625//----------------- function declaration------------
2626// considering
2627// 1. fresh building
2628// 2. secondary building after another nondefining functiondeclaration
2629// 3. secondary building after another defining function declaration
2630// 4. fortran ?
2631template <class actualFunction>
2632actualFunction*
2633SageBuilder::buildNondefiningFunctionDeclaration_T (
2634 const SgName & XXX_name, SgType* return_type, SgFunctionParameterList * paralist, bool isMemberFunction,
2635 SgScopeStatement* scope, SgExprListExp* /*decoratorList*/, unsigned int functionConstVolatileFlags,
2636 SgTemplateArgumentPtrList* templateArgumentsList, SgTemplateParameterPtrList* templateParameterList,
2638) {
2639 // DQ (11/25/2011): This function has been modified to work when used with a SgTemplateFunctionDeclaration as a template argument.
2640 // It was originally designed to work with only SgFunctionDeclaration and SgMemberFunctionDeclaration, it now works with these
2641 // plus SgTemplateFunctionDeclaration and SgTemplateMemberonDeclaration IR nodes. This is part of providing new support for template
2642 // declarations in the AST and a general update of this function to support this expanded use.
2643
2644 // DQ (11/27/2011) Note: it is not clear if we need the newly added input paramter: buildTemplateInstantiation; since this is represented in the template parameter.
2645
2646 // argument verification
2647 if (scope == nullptr)
2648 {
2650 }
2651 ASSERT_not_null(scope);
2652
2653 if (XXX_name.is_null() == true)
2654 {
2655 // DQ (4/2/2013): This case is generated for test2013_86.C.
2656 mprintf ("NOTE: In buildNondefiningFunctionDeclaration_T(): XXX_name.is_null() == true: This is a function with an empty name (allowed as compiler generated initializing constructors to un-named classes, structs, and unions in C++ \n");
2657 }
2658
2659 SgName nameWithoutTemplateArguments = XXX_name;
2660 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
2661
2662 bool buildTemplateInstantiation = ((VariantT)actualFunction::static_variant == V_SgTemplateInstantiationFunctionDecl || (VariantT)actualFunction::static_variant == V_SgTemplateInstantiationMemberFunctionDecl);
2663
2664 // DQ (8/7/2013): Added support for template declarations.
2665 bool buildTemplateDeclaration = ((VariantT)actualFunction::static_variant == V_SgTemplateFunctionDeclaration || (VariantT)actualFunction::static_variant == V_SgTemplateMemberFunctionDeclaration);
2666
2667 // DQ (8/7/2013): Added support for template declarations (need to handle template names overloaded on template parameters).
2668 // We want to use the template arguments in the symbol table lookup, but not in the name generation.
2669 if (buildTemplateInstantiation == true)
2670 {
2671 ASSERT_not_null(templateArgumentsList);
2672 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
2673 }
2674
2675 // this function is also called when building a function reference before the function declaration exists. So, skip the check
2676 if (nameWithTemplateArguments.is_null() == true)
2677 {
2678 // DQ (3/25/2017): Modified to use message logging.
2679 // DQ (4/2/2013): This case is generated for test2013_86.C.
2680 mprintf ("NOTE: In buildNondefiningFunctionDeclaration_T(): nameWithTemplateArguments.is_null() == true: This is a function with an empty name (allowed as compiler generated initializing constructors to un-named classes, structs, and unions in C++ \n");
2681 }
2682
2683 if (nameWithoutTemplateArguments.is_null() == true)
2684 {
2685 // DQ (3/25/2017): Modified to use message logging.
2686 // DQ (4/2/2013): This case is generated for test2013_86.C.
2687 mprintf ("NOTE: In buildNondefiningFunctionDeclaration_T(): nameWithoutTemplateArguments.is_null() == true: This is a function with an empty name (allowed as compiler generated initializing constructors to un-named classes, structs, and unions in C++ \n");
2688 }
2689
2690 ASSERT_not_null(return_type);
2691 ASSERT_not_null(paralist);
2692
2693 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
2694 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
2695 if (SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == true)
2696 {
2697#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
2698 printf ("Warning: In buildNondefiningFunctionDeclaration_T(): nameWithoutTemplateArguments = %s nameWithTemplateArguments = %s \n",nameWithoutTemplateArguments.str(),nameWithTemplateArguments.str());
2699#endif
2700 }
2701 // DQ (7/27/2012): There are reasons why this can fail: e.g. for functions with names such as:
2702 // "operator std::auto_ptr_ref<_Tp1>" which is a user defined conversion operator to one class from another.
2703
2704 // tentatively build a function type, since it is shared
2705 // by all prototypes and defining declarations of a same function!
2706
2707 SgFunctionType* func_type = nullptr;
2708 if (isMemberFunction == true)
2709 {
2711 func_type = buildMemberFunctionType(return_type,typeList,scope, functionConstVolatileFlags);
2712 }
2713 else
2714 {
2715 func_type = buildFunctionType(return_type,paralist);
2716 }
2717
2718 ASSERT_not_null(func_type);
2719
2720 // function declaration
2721 actualFunction* func = nullptr;
2722
2723 // search before using the function type to create the function declaration
2724 // TODO only search current scope or all ancestor scope?? (DQ: Only current scope!)
2725 // We don't have lookup_member_function_symbol yet
2726
2727 // DQ (12/27/2011): Under the new design we can make the symbol type SgFunctionSymbol instead of the less specific SgSymbol.
2728 // DQ (11/25/2011): We want to add the support for template function declarations,
2729 // so this should be a SgSymbol so that we can have it be either a SgFunctionSymbol
2730 // or a SgTemplateSymbol.
2731 SgFunctionSymbol* func_symbol = NULL;
2732
2733 if (scope != NULL)
2734 {
2735 // DQ (3/13/2012): Experiment with new function to support only associating the right type of symbol with the
2736 // function being built. I don't think I like the design of this interface, but we might change that later.
2737
2738 // DQ (8/7/2013): We need to use the template arguments in the symbol table lookup for template functions to permit template function overloading on template perameters.
2739 func_symbol = scope->find_symbol_by_type_of_function<actualFunction>(nameWithTemplateArguments,func_type,templateParameterList,templateArgumentsList);
2740
2741 // If not a proper function (or instantiated template function), then check for a template function declaration.
2742 if (func_symbol == NULL)
2743 {
2744 // Note that a template function does not have a function type (just a name).
2745 ROSE_ASSERT(func_type != NULL);
2746 }
2747 }
2748
2749 if (func_symbol != NULL)
2750 {
2751 switch((VariantT)actualFunction::static_variant)
2752 {
2753 case V_SgFunctionDeclaration:
2754 case V_SgProcedureHeaderStatement:
2755 case V_SgTemplateInstantiationFunctionDecl:
2756 {
2757 ROSE_ASSERT(isSgFunctionSymbol(func_symbol) != NULL);
2758 break;
2759 }
2760 case V_SgMemberFunctionDeclaration:
2761 case V_SgTemplateInstantiationMemberFunctionDecl:
2762 {
2763 ROSE_ASSERT(isSgMemberFunctionSymbol(func_symbol) != NULL);
2764 break;
2765 }
2766 case V_SgTemplateFunctionDeclaration:
2767 {
2768 ROSE_ASSERT(isSgTemplateFunctionSymbol(func_symbol) != NULL);
2769 break;
2770 }
2771 case V_SgTemplateMemberFunctionDeclaration:
2772 {
2773 ROSE_ASSERT(isSgTemplateMemberFunctionSymbol(func_symbol) != NULL);
2774 break;
2775 }
2776
2777 default:
2778 {
2779 printf ("default reach in buildNondefiningFunctionDeclaration_T(): variantT(actualFunction::static_variant) = %d \n",actualFunction::static_variant);
2780 ROSE_ABORT();
2781 }
2782 }
2783
2784 // TV (2/5/14): Found symbol might come from another file, in this case we need to insert it in the current scope.
2785 // Can only happen when scope is a global scope
2786 ROSE_ASSERT(scope != NULL);
2787 if ( isSgGlobal(scope) != NULL
2788 && scope != func_symbol->get_scope()
2789 && !SageInterface::isAncestor(scope, func_symbol->get_scope())
2790 && !scope->symbol_exists(nameWithTemplateArguments, func_symbol) )
2791 {
2792 scope->insert_symbol(nameWithTemplateArguments, func_symbol);
2793 }
2794 }
2795
2796 if (func_symbol == NULL)
2797 {
2798 func = new actualFunction (nameWithTemplateArguments,func_type,NULL);
2799 ROSE_ASSERT(func != NULL);
2800
2801 // Storage modifier (esp. static) must be set before inserting symbol
2802 func->get_declarationModifier().get_storageModifier().set_modifier(sm);
2803
2804 // DQ (5/1/2012): This should always be true.
2805 ROSE_ASSERT(func->get_file_info() == NULL);
2806
2807 // DQ (12/14/2011): Moved this from lower in this function.
2808 func->set_scope(scope);
2809
2810 // DQ (12/15/2011): Added test.
2811 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(func,scope);
2812
2813 // This fails below for a SgTemplateFunctionDeclaration, so test it here.
2814 ROSE_ASSERT(func->get_parameterList() != NULL);
2815
2816 // NOTE: we want to allow the input scope to be NULL (and even the SageBuilder::topScopeStack() == NULL)
2817 // so that function can be built bottom up style. However this means that the symbol tables in the
2818 // scope of the returned function declaration will have to be setup separately.
2819 if (scope != NULL)
2820 {
2821 // function symbol table
2822 if (isSgMemberFunctionDeclaration(func))
2823 {
2824 // DQ (11/23/2011): This change allows this to compile for where SgTemplateFunctionDeclarations are used. I have
2825 // not decided if template declarations should cause symbols to be generated for functions and member functions.
2826 // func_symbol = new SgMemberFunctionSymbol(func);
2827 if (isSgTemplateMemberFunctionDeclaration(func) != NULL)
2828 func_symbol = new SgTemplateMemberFunctionSymbol(isSgTemplateMemberFunctionDeclaration(func));
2829 else
2830 {
2831 SgMemberFunctionDeclaration* memberFunctionDeclaration = isSgMemberFunctionDeclaration(func);
2832 ROSE_ASSERT(memberFunctionDeclaration != NULL);
2833 func_symbol = new SgMemberFunctionSymbol(memberFunctionDeclaration);
2834 }
2835
2836 ROSE_ASSERT(func_symbol != NULL);
2837 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
2838 }
2839 else
2840 {
2841 // if (isSgFunctionDeclaration(func))
2842 if (isSgTemplateFunctionDeclaration(func))
2843 {
2844 // How should we handled template functions in the symbol table???
2845 // DQ (11/24/2011): After some thought, I think that template declarations for function are more template declarations
2846 // than functions. So all template function declarations will be handled as SgTemplateSymbols and not SgFunctionSymbols.mplate function declarations.
2847 SgTemplateFunctionDeclaration* templatedeclaration = isSgTemplateFunctionDeclaration(func);
2848 ROSE_ASSERT(templatedeclaration != NULL);
2849 SgTemplateFunctionSymbol* template_symbol = new SgTemplateFunctionSymbol(templatedeclaration);
2850 ROSE_ASSERT(template_symbol != NULL);
2851 ROSE_ASSERT(template_symbol->get_symbol_basis() != NULL);
2852 func_symbol = template_symbol;
2853 }
2854 else
2855 {
2856 func_symbol = new SgFunctionSymbol(isSgFunctionDeclaration(func));
2857 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
2858 }
2859 }
2860
2861 ROSE_ASSERT(func_symbol != NULL);
2862 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
2863 scope->insert_symbol(nameWithTemplateArguments, func_symbol);
2864
2865 ROSE_ASSERT(func->get_symbol_from_symbol_table() != NULL);
2866
2867 if (isSgFunctionDeclaration(func) == NULL)
2868 {
2869 // DQ (12/18/2011): If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
2870 // DQ (8/12/2013): Added template parameter list.
2871 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
2872 // In this case these are unavailable from this point.
2873 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
2874 }
2875
2876 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
2877 // In this case these are unavailable from this point.
2878 // DQ (11/25/2011): Added support for template functions.
2879 // DQ (2/26/2009): uncommented assertion.
2880 // Did not pass for member function? Should we have used the mangled name?
2881 ROSE_ASSERT(buildTemplateDeclaration == false || templateParameterList != NULL);
2882
2883 // DQ (8/13/2013): We need to test for function symbols (which will include member function symbols),
2884 // template functions and template member functions. Each must be tested for seperately because template
2885 // functions and template member functions are not connected to derivation which non-template functions
2886 // and non-template member functions are connected through derivation.
2887 ROSE_ASSERT(scope->lookup_function_symbol(nameWithTemplateArguments) != NULL ||
2888 scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL ||
2889 scope->lookup_template_member_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
2890
2891#if BUILDER_MAKE_REDUNDANT_CALLS_TO_SYMBOL_TABLE_LOOKUP
2892 // if (scope->lookup_function_symbol(name) == NULL || scope->lookup_template_symbol(name) != NULL)
2893 // if (scope->lookup_function_symbol(nameWithTemplateArguments) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments) != NULL)
2894 // if (scope->lookup_function_symbol(nameWithTemplateArguments) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments,NULL,NULL) != NULL)
2895 if (scope->lookup_function_symbol(nameWithTemplateArguments,templateArgumentList) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments,templateParameterList,NULL) != NULL)
2896 {
2897 // Make sure this is a template function declaration...
2898 printf ("Need to make sure this is a template function declaration... \n");
2899 }
2900#endif
2901 }
2902
2903 // DQ (12/14/2011): Added test.
2904 ROSE_ASSERT(func->get_scope() != NULL);
2905
2906 if (isSgFunctionDeclaration(func) == NULL)
2907 {
2908 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
2909
2910 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
2911 // In this case these are unavailable from this point.
2912 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
2913 }
2914 func->set_firstNondefiningDeclaration(func);
2915 func->set_definingDeclaration(NULL);
2916
2917 // DQ (5/8/2016): We need to test the first defining declaration that we used.
2918 ROSE_ASSERT(func->get_firstNondefiningDeclaration() == func);
2919
2920 ROSE_ASSERT(func->get_definingDeclaration() == NULL);
2921
2922 // DQ (12/14/2011): Error checking
2923 SgTemplateInstantiationMemberFunctionDecl* testMemberDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
2924 if (testMemberDecl != NULL)
2925 {
2926 ROSE_ASSERT(testMemberDecl->get_scope() != NULL);
2927 ROSE_ASSERT(testMemberDecl->get_class_scope() != NULL);
2928 ROSE_ASSERT(testMemberDecl->get_associatedClassDeclaration() != NULL);
2929 }
2930 }
2931 else
2932 {
2933 ROSE_ASSERT(func_symbol != NULL);
2934
2935 ROSE_ASSERT(scope != NULL);
2936
2937 // 2nd, or 3rd... prototype declaration
2938 // reuse function type, function symbol of previous declaration
2939
2940 // std::cout<<"debug:SageBuilder.C: 267: "<<"found func_symbol!"<<std::endl;
2941 // delete (func_type-> get_argument_list ());
2942 // delete func_type; // bug 189
2943 SgNode* associatedSymbolBasis = func_symbol->get_symbol_basis();
2944 ROSE_ASSERT(associatedSymbolBasis != NULL);
2945
2946 SgDeclarationStatement* associatedDeclaration = isSgDeclarationStatement(associatedSymbolBasis);
2947 ROSE_ASSERT(associatedDeclaration != NULL);
2948 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(associatedDeclaration);
2949 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(associatedDeclaration);
2950
2951 if (functionDeclaration != NULL)
2952 {
2953 func_type = functionDeclaration->get_type();
2954 }
2955 else
2956 {
2957 if (templateFunctionDeclaration != NULL)
2958 {
2959 // DQ (5/8/2016): I think this code is never executed (because a templateFunctionDeclaration
2960 // is derived from a SgFunctionDeclaration, in the newer design (a few years ago)).
2961
2962 printf ("This code should not be reachable! \n");
2963 ROSE_ABORT();
2964
2965 func_type = templateFunctionDeclaration->get_type();
2966 }
2967 else
2968 {
2969 printf ("Error: associatedDeclaration = %p = %s \n",associatedDeclaration,associatedDeclaration->class_name().c_str());
2970 ROSE_ABORT();
2971 }
2972 }
2973 ROSE_ASSERT(func_type != NULL);
2974
2975 func = new actualFunction(nameWithTemplateArguments,func_type,NULL);
2976 ROSE_ASSERT(func != NULL);
2977
2978#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
2979 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as translformations.
2980 // This is too early a point to test since the source position has not been set for func yet.
2981 // detectTransformations_local(func);
2982#endif
2983
2984 // DQ (12/14/2011): Moved this up from below.
2985 func->set_scope(scope);
2986
2987 ROSE_ASSERT(func->get_symbol_from_symbol_table() == NULL);
2988
2989 // DQ (12/15/2011): Added test.
2990 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(func,scope);
2991
2992 // we don't care if it is member function or function here for a pointer
2993 SgDeclarationStatement* prevDecl = NULL;
2994
2995 // This does not handle the case of a template function declaration.
2996 if (functionDeclaration != NULL)
2997 {
2998 prevDecl = functionDeclaration;
2999 }
3000 else
3001 {
3002 ROSE_ASSERT(templateFunctionDeclaration != NULL);
3003 prevDecl = templateFunctionDeclaration;
3004 }
3005
3006 ROSE_ASSERT(prevDecl != NULL);
3007
3008 SgFunctionSymbol *function_symbol = isSgFunctionSymbol(func_symbol);
3009 if (prevDecl == prevDecl->get_definingDeclaration())
3010 {
3011 // The symbol points to a defining declaration and now that we have added a non-defining
3012 // declaration we should have the symbol point to the new non-defining declaration.
3013 printf ("WARNING: Switching declaration in functionSymbol to point to the non-defining declaration \n");
3014 function_symbol->set_declaration(isSgFunctionDeclaration(func));
3015 ROSE_ASSERT(function_symbol->get_declaration() != NULL);
3016 }
3017
3018 // If this is the first non-defining declaration then set the associated data member.
3019 SgDeclarationStatement* nondefiningDeclaration = prevDecl->get_firstNondefiningDeclaration();
3020 if (nondefiningDeclaration == NULL)
3021 {
3022 nondefiningDeclaration = func;
3023 }
3024
3025 ROSE_ASSERT(nondefiningDeclaration != NULL);
3026 ROSE_ASSERT(func != NULL);
3027 ROSE_ASSERT(prevDecl != NULL);
3028
3029 func->set_firstNondefiningDeclaration(nondefiningDeclaration);
3030 func->set_definingDeclaration(prevDecl->get_definingDeclaration());
3031
3032 ROSE_ASSERT(nondefiningDeclaration->get_symbol_from_symbol_table() != NULL);
3033 ROSE_ASSERT(func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3034
3035 // DQ (3/8/2012): If this is the redundant function prototype then we have to look
3036 // at the first defining declaration since only it will have an associated symbol.
3037 if (func->get_symbol_from_symbol_table() == NULL)
3038 {
3039 ROSE_ASSERT(nondefiningDeclaration != NULL);
3040 ROSE_ASSERT(func->get_firstNondefiningDeclaration() == nondefiningDeclaration);
3041 }
3042
3043 // DQ (12/14/2011): Added test.
3044 ROSE_ASSERT(scope != NULL);
3045 ROSE_ASSERT(func->get_scope() != NULL);
3046 ROSE_ASSERT(func->get_scope() == scope);
3047
3048 // DQ (12/14/2011): Error checking
3049 SgTemplateInstantiationMemberFunctionDecl* testMemberDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
3050 if (testMemberDecl != NULL)
3051 {
3052 ROSE_ASSERT(testMemberDecl->get_scope() != NULL);
3053 ROSE_ASSERT(testMemberDecl->get_associatedClassDeclaration() != NULL);
3054 }
3055
3056 // DQ (12/18/2011): Testing to debug generation of wrong kind of declaration (symbol not found in correct scope or ...).
3057 if (isSgFunctionDeclaration(func) == NULL)
3058 {
3059 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3060 // DQ (8/12/2013): Added template parameter list.
3061 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3062 // In this case these are unavailable from this point.
3063 // DQ (12/18/2011): This fails because the first use of the function causes a non-defining function declaration
3064 // to be built and it is built as a template instantiation instead of a template declaration. So the symbol for
3065 // the non-defining declaration is put into the correct scope, but as a SgMemberFunctionSymbol instead of as a
3066 // SgTemplateSymbol (if it were built as a SgTemplateMemberFunctionDeclaration). So of course we can't find it
3067 // using lookup_template_symbol().
3068 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3069 }
3070 }
3071
3072 ROSE_ASSERT(func != NULL);
3073
3074 ROSE_ASSERT(func->get_file_info() == NULL);
3075
3076 ROSE_ASSERT(func->get_firstNondefiningDeclaration() != NULL);
3077 ROSE_ASSERT(func_symbol != NULL);
3078 ROSE_ASSERT(func_symbol->get_symbol_basis() == func->get_firstNondefiningDeclaration());
3079 ROSE_ASSERT(func->get_symbol_from_symbol_table() != NULL || func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3080
3081 // DQ (2/24/2009): Delete the old parameter list build by the actualFunction (template argument) constructor.
3082 ROSE_ASSERT(func->get_parameterList() != NULL);
3083 delete func->get_parameterList();
3084 func->set_parameterList(NULL);
3085
3086 // DQ (9/16/2012): Setup up the template arguments and the parents of the template arguments.
3087 if (buildTemplateInstantiation == true)
3088 {
3089 setTemplateArgumentsInDeclaration(func,templateArgumentsList);
3090 }
3091
3092 // DQ (8/10/2013): Setup the template parameters if this is a template declaration.
3093 if (buildTemplateDeclaration == true)
3094 {
3095 setTemplateParametersInDeclaration(func,templateParameterList);
3096
3097 // DQ (8/13/2013): Adding test of template parameter lists.
3098 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(func);
3099 ROSE_ASSERT(templateFunctionDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateFunctionDeclaration->get_templateParameters().size()));
3100
3101 SgTemplateMemberFunctionDeclaration* templateMemberFunctionDeclaration = isSgTemplateMemberFunctionDeclaration(func);
3102 ROSE_ASSERT(templateMemberFunctionDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateMemberFunctionDeclaration->get_templateParameters().size()));
3103 }
3104
3105 // parameter list
3106 // DQ (11/23/2011): This change allows this to compile for where SgTemplateFunctionDeclarations are used.
3107 setParameterList(func, paralist);
3108
3109 for (SgInitializedName* i_name : paralist->get_args())
3110 {
3111 i_name->set_scope(scope);
3112 }
3113
3114 // DQ (5/2/2012): Test this to make sure we have SgInitializedNames set properly.
3116
3117#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3118 // Liao 11/21/2012: we should assert no transformation only when the current model is NOT transformation
3119 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
3120 {
3121 detectTransformations_local(paralist);
3122 }
3123#endif
3124
3125 ASSERT_not_null(scope);
3126 ASSERT_not_null(func->get_scope());
3127 ASSERT_require(func->get_scope() == scope);
3128
3129 if (SageBuilder::topScopeStack() != nullptr) // This comparison only makes sense when topScopeStack() returns non-NULL value
3130 {
3131 // since stack scope is totally optional in SageBuilder.
3132 if (scope != SageBuilder::topScopeStack())
3133 {
3134#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
3135 printf ("Warning: SageBuilder::buildNondefiningFunctionDeclaration_T(): scope parameter may not be the same as the topScopeStack() (e.g. for member functions) \n");
3136#endif
3137 }
3138 }
3139
3140 func->set_parent(scope);
3141 ASSERT_not_null(func->get_firstNondefiningDeclaration());
3142
3143 // mark as a forward declartion
3144 func->setForward();
3145
3146 ROSE_ASSERT(func->get_file_info() == NULL);
3147
3148 // set File_Info as transformation generated or front end generated
3150
3151 ROSE_ASSERT(func->get_file_info() != NULL);
3152
3153#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3154 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3155 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
3156 {
3157 detectTransformations_local(func);
3158 }
3159#endif
3160
3161 // printf ("In SageBuilder::buildNondefiningFunctionDeclaration_T(): generated function func = %p \n",func);
3162
3163 // Liao 12/2/2010, special handling for Fortran functions and subroutines
3164 if ((SageInterface::is_Fortran_language() == true) && (getEnclosingFileNode(scope)->get_outputLanguage() == SgFile::e_Fortran_language))
3165 {
3166 SgProcedureHeaderStatement * f_func = isSgProcedureHeaderStatement(func);
3167 ROSE_ASSERT (f_func != NULL);
3168 if (return_type == buildVoidType())
3170 else
3171 f_func->set_subprogram_kind(SgProcedureHeaderStatement::e_function_subprogram_kind);
3172
3173 // hide it from the unparser since fortran prototype func declaration is internally used by ROSE AST
3176 ROSE_ASSERT(f_func->get_startOfConstruct()->isOutputInCodeGeneration() == false);
3177 ROSE_ASSERT(f_func->get_endOfConstruct()->isOutputInCodeGeneration() == false);
3178 }
3179
3180 // DQ (12/11/2011): Added new test.
3181 ROSE_ASSERT(func->get_firstNondefiningDeclaration() != NULL);
3182 SgSymbol* symbol_from_first_nondefining_function = func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table();
3183 ROSE_ASSERT(symbol_from_first_nondefining_function != NULL);
3184
3185 // DQ (12/11/2011): Note that this may be false when func is not the first nondefining declaration.
3186 if (func != func->get_firstNondefiningDeclaration())
3187 {
3188 SgSymbol* symbol_from_nondefining_function = func->get_symbol_from_symbol_table();
3189 ROSE_ASSERT(symbol_from_nondefining_function == NULL);
3190 }
3191
3192 // DQ (12/18/2011): Testing to debug generation of wrong kind of declaration (symbol not found in correct scope or ...).
3193 if (isSgFunctionDeclaration(func) == NULL)
3194 {
3195 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3196 // DQ (8/12/2013): Make sure we use the template parameters and the template arguments that are available.
3197 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3198 // In this case these are unavailable from this point.
3199 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3200 }
3201
3202 // DQ (2/11/2012): If this is a template instantiation then we have to set the template name (seperate from the name of the function which can include template parameters)).
3203 setTemplateNameInTemplateInstantiations(func,nameWithoutTemplateArguments);
3204
3205#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3206 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3207 if (SourcePositionClassificationMode !=e_sourcePositionTransformation)
3208 {
3209 detectTransformations_local(func);
3210 }
3211#endif
3212
3213 // DQ (12/11/2012): Force the two different ways that this can be set to match (we want consistancy).
3214 if (functionConstVolatileFlags & SgMemberFunctionType::e_restrict)
3215 {
3216 func->get_declarationModifier().get_typeModifier().setRestrict();
3217 }
3218
3219 unsetNodesMarkedAsModified(func);
3220
3221 ROSE_ASSERT(paralist->get_parent() != NULL);
3222 return func;
3223 }
3224
3225
3229{
3230 ROSE_ASSERT(funcdecl!=NULL);
3231 SgName name=funcdecl->get_name();
3232 SgFunctionType * funcType = funcdecl->get_type();
3233 SgType* return_type = funcType->get_return_type();
3234 SgFunctionParameterList* paralist = deepCopy<SgFunctionParameterList>(funcdecl->get_parameterList());
3235
3236 // make sure the function has consistent function type based on its return type and parameter list
3237 SgFunctionType * ref_funcType= findFunctionType (return_type, funcType->get_argument_list());
3238 ROSE_ASSERT(funcType== ref_funcType);
3239
3240 // buildNondefiningFunctionDeclaration() will check if a same function is created before by looking up function symbols.
3241 SgFunctionDeclaration* returnFunction = buildNondefiningFunctionDeclaration (name, return_type, paralist, scope, decoratorList, false, NULL);
3242
3243 returnFunction->set_linkage(funcdecl->get_linkage());
3244 if (funcdecl->get_declarationModifier().get_storageModifier().isExtern() == true)
3245 {
3246 returnFunction->get_declarationModifier().get_storageModifier().setExtern();
3247 }
3248
3249 ROSE_ASSERT (returnFunction->get_linkage() == funcdecl->get_linkage());
3250 ROSE_ASSERT (returnFunction->get_declarationModifier().get_storageModifier().isExtern() ==
3251 funcdecl->get_declarationModifier().get_storageModifier().isExtern());
3252
3253 ROSE_ASSERT(returnFunction->get_firstNondefiningDeclaration() != NULL);
3254 // Make sure that internal references are to the same file (else the symbol table information will not be consistent).
3255 if (scope != NULL)
3256 {
3257 ROSE_ASSERT(returnFunction->get_firstNondefiningDeclaration() != NULL);
3258 }
3259
3260 return returnFunction;
3261}
3262
3264SageBuilder::buildNondefiningFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList, SgStorageModifier::storage_modifier_enum sm)
3265 {
3266 SgFunctionDeclaration * result = NULL;
3267 if ((SageInterface::is_Fortran_language() == true) && (getEnclosingFileNode(scope)->get_outputLanguage() == SgFile::e_Fortran_language))
3268 {
3269 result = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, NULL, sm);
3270 }
3271 else
3272 {
3273 // DQ (11/27/2011): Added support to generate template declarations in the AST (this is part of a common API to make the build functions support more uniform).
3274 if (buildTemplateInstantiation == true)
3275 {
3276 result = buildNondefiningFunctionDeclaration_T <SgTemplateInstantiationFunctionDecl> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, templateArgumentsList, NULL, sm);
3277 }
3278 else
3279 {
3280 result = buildNondefiningFunctionDeclaration_T <SgFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, NULL, sm);
3281 }
3282 }
3283
3284 return result;
3285 }
3286
3287
3288// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficent).
3289// We need to decide if the SageBuilder API should include these sorts of functions.
3292 {
3293 unsigned int memberFunctionModifiers = 0;
3294 return buildNondefiningMemberFunctionDeclaration (name,return_type,paralist,scope,NULL,memberFunctionModifiers,false,NULL);
3295 }
3296
3297// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficient).
3298// We need to decide if the SageBuilder API should include these sorts of functions.
3301 {
3302 if (scope == NULL)
3303 {
3305 }
3306
3307 unsigned int memberFunctionModifiers = 0;
3309 SgMemberFunctionDeclaration* nondefining_decl = NULL;
3310 SgMemberFunctionType* member_func_type = buildMemberFunctionType(return_type,param_type_list, scope, memberFunctionModifiers);
3311 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgMemberFunctionDeclaration>(name,member_func_type,NULL,NULL);
3312 SgMemberFunctionSymbol* member_func_symbol = isSgMemberFunctionSymbol(func_symbol);
3313
3314 if (member_func_symbol != NULL)
3315 {
3316 nondefining_decl = member_func_symbol->get_declaration();
3317 }
3318 else
3319 {
3320 // each defining member function decl must have a non-defining counter part now. 11/27/2012, Liao
3321 nondefining_decl = buildNondefiningMemberFunctionDeclaration (name, return_type, paralist, scope,NULL, memberFunctionModifiers, false, NULL);
3322 }
3323 return buildDefiningMemberFunctionDeclaration (name,return_type,paralist,scope,NULL,false,memberFunctionModifiers,nondefining_decl,NULL);
3324 }
3325
3326
3327// SgTemplateFunctionDeclaration* SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList)
3328// SgTemplateFunctionDeclaration* SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateArgumentPtrList* templateArgumentsList)
3330SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateParameterPtrList* templateParameterList)
3331 {
3332 // DQ (8/15/2013): Note that we don't need template arguments because teplate functions can't support partial specialization.
3333
3334 // DQ (11/25/2011): Adding support for template declarations in the AST.
3335
3336 // DQ (8/7/2013): Added support for template function overloading using template parameters.
3337 SgTemplateFunctionDeclaration* result = buildNondefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, templateParameterList, SgStorageModifier::e_default);
3338
3339 // DQ (12/12/2011): Added test.
3340 ROSE_ASSERT(result != NULL);
3341 if (result->get_symbol_from_symbol_table() == NULL)
3342 {
3343 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3344 ROSE_ASSERT(result != result->get_firstNondefiningDeclaration());
3345 ROSE_ASSERT(result->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3346 }
3347 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3348
3349 return result;
3350 }
3351
3353SageBuilder::buildDefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateFunctionDeclaration* first_nondefining_declaration)
3354 {
3355 // DQ (12/1/2011): Adding support for template declarations in the AST.
3356 ROSE_ASSERT(first_nondefining_declaration != NULL);
3357 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() != NULL);
3358 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3359
3360 SgTemplateFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ false, scope, decoratorList, 0, first_nondefining_declaration, NULL);
3361
3362 return result;
3363 }
3364
3366SageBuilder::buildDefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList *paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, SgTemplateMemberFunctionDeclaration* first_nondefining_declaration)
3367 {
3368 // DQ (12/1/2011): Adding support for template declarations in the AST.
3369
3370 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3371
3372 SgTemplateMemberFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true, scope, decoratorList, functionConstVolatileFlags, first_nondefining_declaration, NULL);
3373 ROSE_ASSERT(result != NULL);
3374
3375 ROSE_ASSERT(result->get_definition() != NULL);
3376
3377 return result;
3378 }
3379
3382 SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList)
3383 {
3384 // This function builds either a SgMemberFunctionDeclaration (non-template; normal member function) or a SgTemplateInstantiationMemberFunctionDecl (template instantiation).
3385
3386 // DQ (11/27/2011): Added support for instations of template member functions.
3387 SgMemberFunctionDeclaration * result = NULL;
3388
3389 if (buildTemplateInstantiation == true)
3390 {
3391 // This is how we build an instantiation of a template (SgTemplateInstantiationMemberFunctionDecl).
3392 result = buildNondefiningFunctionDeclaration_T <SgTemplateInstantiationMemberFunctionDecl> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,templateArgumentsList,NULL, SgStorageModifier::e_default);
3393 }
3394 else
3395 {
3396 // This is a non-template instatiation (normal member function).
3397 result = buildNondefiningFunctionDeclaration_T <SgMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,NULL,NULL, SgStorageModifier::e_default);
3398 }
3399 ROSE_ASSERT(result != NULL);
3400
3401 // set definingdecl for SgCtorInitializerList
3403 ROSE_ASSERT(ctor != NULL);
3404
3405 // required in AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3406 ctor->set_definingDeclaration(ctor);
3408
3409 // DQ (1/4/2009): Error checking
3410 ROSE_ASSERT(result->get_associatedClassDeclaration() != NULL);
3411
3412 if (result->get_associatedClassDeclaration() == NULL)
3413 {
3414 printf ("Warning, must set the SgMemberFunctionDeclaration::associatedClassDeclaration \n");
3415
3416 ROSE_ASSERT(scope != NULL);
3417 SgClassDefinition* classDefinition = isSgClassDefinition(scope);
3418 ROSE_ASSERT(classDefinition != NULL);
3419 SgDeclarationStatement* associatedDeclaration = classDefinition->get_declaration();
3420 ROSE_ASSERT(associatedDeclaration != NULL);
3421 SgClassDeclaration* associatedClassDeclaration = isSgClassDeclaration(associatedDeclaration);
3422
3423 // DQ (1/4/2009): This needs to be set, checked in AstConsistencyTests.C!
3424 result->set_associatedClassDeclaration(associatedClassDeclaration);
3425 }
3426
3427 return result;
3428 }
3429
3430
3431// DQ (8/12/2013): This function needs to handle the SgTemplateParameterPtrList (since it is generating a template).
3432// It need not take a SgTemplateArgumentPtrList because template functions (including template member functions) can not support partial specialization.
3433// SgTemplateMemberFunctionDeclaration* SageBuilder::buildNondefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags)
3435SageBuilder::buildNondefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, SgTemplateParameterPtrList* templateParameterList)
3436 {
3437 // This function only builds template member function declarations.
3438
3439 SgTemplateMemberFunctionDeclaration * result = buildNondefiningFunctionDeclaration_T <SgTemplateMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,NULL,templateParameterList, SgStorageModifier::e_default);
3440
3441 // set definingdecl for SgCtorInitializerList
3442 ROSE_ASSERT(result != NULL);
3443
3444#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3445 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as translformations.
3447 {
3448 detectTransformations_local(result);
3449 }
3450#endif
3451
3452 // DQ (8/12/2013): Added template paremter list to call to get the function template symbol.
3453 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3454 // In this case these are unavailable from this point.
3455 SgSymbol* associatedSymbol = scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList);
3456 if (associatedSymbol == NULL)
3457 {
3458 printf ("ERROR: associatedSymbol == NULL \n");
3459 printf (" --- result = %p = %s \n",result,result->class_name().c_str());
3460 printf (" --- scope = %p = %s \n",scope,scope->class_name().c_str());
3461 printf (" --- name = %s \n",name.str());
3462 printf (" --- result->get_type() = %p = %s \n",result->get_type(),result->get_type()->class_name().c_str());
3463 printf (" --- result->get_type()->get_mangled() = %s \n",result->get_type()->get_mangled().str());
3464 }
3465 ROSE_ASSERT(associatedSymbol != NULL);
3466
3468 ROSE_ASSERT(ctor != NULL);
3469 // required ty AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3470 ctor->set_definingDeclaration(ctor);
3472
3473 // DQ (12/11/2011): Added new test (also at the base of buildNondefiningFunctionDeclaration_T<>() function).
3474 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3475 SgSymbol* symbol_from_first_nondefining_function = result->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table();
3476 ROSE_ASSERT(symbol_from_first_nondefining_function != NULL);
3477
3478 // DQ (12/11/2011): Note that this may be false when func is not the first nondefining declaration.
3479 if (result != result->get_firstNondefiningDeclaration())
3480 {
3481 SgSymbol* symbol_from_nondefining_function = result->get_symbol_from_symbol_table();
3482 ROSE_ASSERT(symbol_from_nondefining_function == NULL);
3483 }
3484
3485#if BUILDER_MAKE_REDUNDANT_CALLS_TO_SYMBOL_TABLE_LOOKUP
3486 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3487 // In this case these are unavailable from this point.
3488 if (scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList) == NULL)
3489 {
3490 printf ("Error: scope->lookup_template_member_function_symbol(name,result->get_type()) == NULL (investigate this) \n");
3491 printf ("--- function name = %s in scope = %p = %s result->get_type() = %p = %s \n",name.str(),scope,scope->class_name().c_str(),result->get_type(),result->get_type()->class_name().c_str());
3492 scope->get_symbol_table()->print("Error: scope->lookup_template_member_function_symbol(name,result->get_type()) == NULL (investigate this)");
3493 }
3494#endif
3495 ROSE_ASSERT(scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList) != NULL);
3496
3497#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3498 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3500 {
3501 detectTransformations_local(result);
3502 }
3503#endif
3504
3505 return result;
3506 }
3507
3509SageBuilder::buildDefiningMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, unsigned int functionConstVolatileFlags, SgMemberFunctionDeclaration* first_nondefining_declaration, SgTemplateArgumentPtrList* templateArgumentsList)
3510 {
3511 // DQ (12/18/2011): Need to build a SgTemplateInstantiationMemberFunctionDecl when buildTemplateInstantiation == true
3512 SgMemberFunctionDeclaration * result = NULL;
3513 if (buildTemplateInstantiation == true)
3514 {
3515 SgTemplateInstantiationMemberFunctionDecl* templateInstantiationMemberFunctionDecl = isSgTemplateInstantiationMemberFunctionDecl(first_nondefining_declaration);
3516 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
3517
3518 // DQ (1/26/2013): Added test failing in buildDefiningFunctionDeclaration_T().
3519 {
3520 ROSE_ASSERT(templateArgumentsList != NULL);
3521 string nameWithoutTemplateArguments = name;
3522 string nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
3523 SgMemberFunctionType* func_type = isSgMemberFunctionType(first_nondefining_declaration->get_type());
3524 ROSE_ASSERT(func_type != NULL);
3525
3526 // DQ (8/7/2013): API change due to added support for template function overloading using template parameters.
3527 SgSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgTemplateInstantiationMemberFunctionDecl>(nameWithTemplateArguments,func_type,NULL,templateArgumentsList);
3528 if (func_symbol == NULL)
3529 {
3530 printf ("ERROR caught in SageBuilder::buildDefiningMemberFunctionDeclaration(): nameWithTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithTemplateArguments.c_str(),buildTemplateInstantiation ? "true:" : "false");
3531 printf ("ERROR caught in SageBuilder::buildDefiningMemberFunctionDeclaration(): func_symbol == NULL for first_nondefining_declaration = %p = %s and func_type = %p = %s \n",
3532 templateInstantiationMemberFunctionDecl,templateInstantiationMemberFunctionDecl->class_name().c_str(),func_type,func_type->class_name().c_str());
3533 }
3534 }
3535
3536 result = buildDefiningFunctionDeclaration_T <SgTemplateInstantiationMemberFunctionDecl> (name, return_type, paralist, /* isMemberFunction = */ true, scope, decoratorList, functionConstVolatileFlags, templateInstantiationMemberFunctionDecl, templateArgumentsList);
3537 ROSE_ASSERT(isSgTemplateInstantiationMemberFunctionDecl(result) != NULL);
3538 ROSE_ASSERT(isSgTemplateInstantiationMemberFunctionDecl(result)->get_templateName().is_null() == false);
3539 }
3540 else
3541 {
3542 ROSE_ASSERT(first_nondefining_declaration != NULL);
3543
3544 // DQ (12/27/20134): Added these to permit testing earlier than in the buildDefiningFunctionDeclaration_T() function.
3545 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() != NULL);
3546 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3547
3548 result = buildDefiningFunctionDeclaration_T <SgMemberFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,first_nondefining_declaration, NULL);
3549 }
3550
3551 ROSE_ASSERT(result != NULL);
3552
3553 // set definingdecl for SgCtorInitializerList
3555 ROSE_ASSERT(ctor != NULL);
3556
3557 // required ty AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3558 ctor->set_definingDeclaration(ctor);
3560
3561 // DQ (1/4/2009): Error checking
3562 ROSE_ASSERT(result->get_associatedClassDeclaration() != NULL);
3563
3564 return result;
3565 }
3566
3567
3568//----------------- defining function declaration------------
3569// a template builder for all kinds of defining SgFunctionDeclaration
3570// handle common chores for function type, symbol, paramter etc.
3571
3572template <class actualFunction>
3573actualFunction*
3574SageBuilder::buildDefiningFunctionDeclaration_T(const SgName & XXX_name, SgType* return_type, SgFunctionParameterList* paralist, bool isMemberFunction, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, actualFunction* first_nondefining_declaration, SgTemplateArgumentPtrList* templateArgumentsList)
3575 {
3576 // Note that the semantics of this function now differs from that of the buildDefiningClassDeclaration().
3577 // We want to have the non-defining declaration already exist before calling this function.
3578 // We could still build a higher level function that built both together. Or we could provide two versions
3579 // named differently (from this one) and depricate this function...which I like much better.
3580
3581#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
3582 printf ("WARNING: This function for building defining function declarations has different semantics from that of the function to build defining class declarations. \n");
3583#endif
3584
3585 ASSERT_not_null(first_nondefining_declaration);
3586 ASSERT_require(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3587
3588 if (scope == nullptr)
3589 {
3591 }
3592
3593 ASSERT_require(XXX_name.is_null() == false);
3594 ASSERT_not_null(scope);
3595 ASSERT_not_null(return_type);
3596
3597 SgName nameWithoutTemplateArguments = XXX_name;
3598 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
3599
3600 bool buildTemplateInstantiation = ((VariantT)actualFunction::static_variant == V_SgTemplateInstantiationFunctionDecl || (VariantT)actualFunction::static_variant == V_SgTemplateInstantiationMemberFunctionDecl);
3601
3602 // DQ (8/7/2013): Added support for template declarations.
3603 bool buildTemplateDeclaration = ((VariantT)actualFunction::static_variant == V_SgTemplateFunctionDeclaration || (VariantT)actualFunction::static_variant == V_SgTemplateMemberFunctionDeclaration);
3604
3605 // DQ (8/11/2013): Check that the template argument lists are consistant. The templateArgumentsList can then be considered redundant if this works.
3606 if (buildTemplateInstantiation == true)
3607 {
3608 ASSERT_not_null(templateArgumentsList);
3609
3610 SgTemplateArgumentPtrList & templateArgumentsList_from_first_nondefining_declaration = (isMemberFunction == false) ?
3611 isSgTemplateInstantiationFunctionDecl(first_nondefining_declaration)->get_templateArguments() :
3612 isSgTemplateInstantiationMemberFunctionDecl(first_nondefining_declaration)->get_templateArguments();
3613
3614 ASSERT_not_null(templateArgumentsList);
3615 bool templateArgumentListsAreEquivalent = SageInterface::templateArgumentListEquivalence(*templateArgumentsList, templateArgumentsList_from_first_nondefining_declaration);
3616 ASSERT_require(templateArgumentListsAreEquivalent == true);
3617 }
3618
3619 SgTemplateParameterPtrList* templateParameterList = nullptr;
3620 if (buildTemplateDeclaration == true)
3621 {
3622 // DQ (8/11/2013): Since this is not passed in so we can access it but not assert its equivalence with a redundant input parameter.
3623 templateParameterList = (isMemberFunction == false) ?
3624 &(isSgTemplateFunctionDeclaration(first_nondefining_declaration)->get_templateParameters()) :
3625 &(isSgTemplateMemberFunctionDeclaration(first_nondefining_declaration)->get_templateParameters());
3626
3627 ASSERT_require(templateArgumentsList == nullptr);
3628 ASSERT_not_null(templateParameterList);
3629 }
3630
3631 if (buildTemplateInstantiation == true)
3632 {
3633 ASSERT_not_null(templateArgumentsList);
3634 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
3635
3636 if (nameWithTemplateArguments == "insert < __normal_iterator< SgInitializedName ** , __type > > ")
3637 {
3638 printf ("In buildDefiningFunctionDeclaration_T(): Found function nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
3639 }
3640 }
3641
3642 ASSERT_require(nameWithoutTemplateArguments.is_null() == false);
3643 ASSERT_require(nameWithTemplateArguments.is_null() == false);
3644 ASSERT_not_null(paralist);
3645
3647 {
3648 ASSERT_require(scope->containsOnlyDeclarations());
3649 }
3650
3651 // build function type, manage function type symbol internally
3652 actualFunction* defining_func = nullptr;
3653 SgFunctionType* func_type = nullptr;
3654
3655 // DQ (5/11/2012): Enforce this so that we can avoid building the function type (be reusing the function type of the first non-defining declaration).
3656 // This is a special problem for templates because the function parameters will evaluate different for different builds of the same template.
3657 // This is a problem for test2012_74.C (and a dozen other test codes that make use of STL).
3658 ASSERT_not_null(first_nondefining_declaration);
3659
3660 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
3661 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
3662 // DQ (7/27/2012): There are reasons why this can fail: e.g. for functions with names such as:
3663 // "operator std::auto_ptr_ref<_Tp1>" which is a user defined conversion operator to one class from another.
3664
3665 // DQ (5/12/2012): Use the newly added parameter to get the exact SgFunctionType used to build the symbol.
3666 // This should make the template handling more robust since we were sometimes using types that had different
3667 // levels of template instantiation between the non-definng and defining function declarations and this
3668 // caused symbols build to support the non-defining declaration to not be found when we searched for them
3669 // using the function type built for the defining declaration. We want the function types for all defining
3670 // and non-defining declarations to be identical. This define also means that we don't have to build a
3671 // SgFunctionType just to look up a symbol in the symbol table (which was always silly). However, only
3672 // the defining function declaration can use the existing function type because it is required that a
3673 // non-defining declaration exist prior to the construction of the defining declaration (built by this
3674 // function).
3675 func_type = first_nondefining_declaration->get_type();
3676 ASSERT_not_null(func_type);
3677
3678 // Make sure these are the same (this will fail until we generate the func_type directly from first_nondefining_declaration).
3679 ASSERT_require(func_type == first_nondefining_declaration->get_type());
3680
3681 SgDeclarationStatement* firstNondefiningFunctionDeclaration = nullptr;
3682
3683 // symbol table and non-defining
3684 SgSymbol* func_symbol = scope->find_symbol_by_type_of_function<actualFunction>(nameWithTemplateArguments,func_type,templateParameterList,templateArgumentsList);
3685
3686 // DQ (1/26/2013): This fails for ROSE compiling ROSE.
3687 ASSERT_not_null(func_symbol);
3688
3689 if (func_symbol == nullptr)
3690 {
3691 // DQ (12/2/2011): After discussion with Liao, we think this should be an error.
3692 // The defining declaration requires that the associated non-defining declaration should already exist.
3693 // If required, a higher level build function could build both of these and connect them as required.
3694 printf ("Error: building a defining declaration requires that the associated non-defining declaration already exists and it's symbol found the the same scope's symbol table! \n");
3695 ROSE_ABORT();
3696 }
3697 else
3698 {
3699 // We will now build a reference to the non-defining declaration found in the symbol.
3700
3701 // defining declaration after nondefining declaration
3702 // reuse function type, function symbol
3703
3704 // Cong (10/25/2010): Make sure in this situation there is no defining declaration for this symbol.
3705
3706 SgFunctionSymbol* temp_function_sym = isSgFunctionSymbol(func_symbol);
3707 SgTemplateSymbol* temp_template_sym = isSgTemplateSymbol(func_symbol);
3708 if (temp_function_sym != nullptr)
3709 {
3710 func_type = temp_function_sym->get_declaration()->get_type();
3711 firstNondefiningFunctionDeclaration = temp_function_sym->get_declaration()->get_firstNondefiningDeclaration();
3712 }
3713 else
3714 {
3715 // There is no type for a template function declaration.
3716 ASSERT_not_null(temp_template_sym);
3717 firstNondefiningFunctionDeclaration = temp_template_sym->get_declaration()->get_firstNondefiningDeclaration();
3718 }
3719 ASSERT_not_null(firstNondefiningFunctionDeclaration);
3720 }
3721
3722 defining_func = new actualFunction(nameWithTemplateArguments,func_type,nullptr);
3723 ASSERT_not_null(defining_func);
3724
3725 ASSERT_not_null(firstNondefiningFunctionDeclaration);
3726 defining_func->set_firstNondefiningDeclaration(firstNondefiningFunctionDeclaration);
3727
3728 // fix up defining declarations before current statement
3729 firstNondefiningFunctionDeclaration->set_definingDeclaration(defining_func);
3730
3731 // Handle decorators (Python specific)
3732 if (decoratorList != nullptr)
3733 {
3734 defining_func->set_decoratorList(decoratorList);
3735 decoratorList->set_parent(defining_func);
3736 }
3737
3738 // definingDeclaration
3739 defining_func->set_definingDeclaration(defining_func);
3740
3741 // function body and definition are created before setting argument list
3742 SgBasicBlock * func_body = new SgBasicBlock();
3743 ASSERT_not_null(func_body);
3744
3745 SgFunctionDefinition* func_def = nullptr;
3746 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(defining_func);
3747
3748 // Build either a definition for a template or non-template function definition.
3749 if (templateFunctionDeclaration == nullptr)
3750 {
3751 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(defining_func);
3752 ASSERT_not_null(functionDeclaration);
3753 func_def = new SgFunctionDefinition(functionDeclaration,func_body);
3754 }
3755 else
3756 {
3757 ASSERT_not_null(templateFunctionDeclaration);
3758 func_def = new SgTemplateFunctionDefinition(templateFunctionDeclaration,func_body);
3759 }
3760 ASSERT_not_null(func_def);
3761
3763 {
3764 func_def->setCaseInsensitive(true);
3765 func_body->setCaseInsensitive(true);
3766 }
3767
3768 func_def->set_parent(defining_func);
3769 func_def->set_body(func_body);
3770 func_body->set_parent(func_def);
3771
3772 // parameter list,
3773 // TODO consider the difference between C++ and Fortran
3774 setParameterList(defining_func,paralist);
3775 // fixup the scope and symbol of arguments,
3776 for (SgInitializedName* i_name : paralist->get_args())
3777 {
3778 i_name->set_scope(func_def);
3779
3780 SgVariableSymbol* variableSymbol = new SgVariableSymbol(i_name);
3781 ASSERT_not_null(variableSymbol);
3782 func_def->insert_symbol(i_name->get_name(), variableSymbol);
3783
3784 // For variable length array types in the function parameter list
3785 SgArrayType* arrayType = isSgArrayType(i_name->get_type());
3786 if (arrayType != nullptr)
3787 {
3788 // Check if this is a VLA array type, if so look for the index expressions and check
3789 // if we need to add asociated symbols to the current function definition scope.
3790 SgExpression* indexExpression = arrayType->get_index();
3791
3792 if (indexExpression != nullptr)
3793 {
3794 // DQ (2/14/2016): Handle the case of an expression tree with any number of variable references.
3795 // Get the list of SgVarRef IR nodes and process each one as above.
3796 vector<SgVarRefExp* > varRefList;
3797 collectVarRefs(indexExpression,varRefList);
3798
3799 for (size_t i = 0; i < varRefList.size(); i++)
3800 {
3801 // Process each index subtree's SgVarRefExp.
3802 SgVariableSymbol* dimension_variableSymbol = varRefList[i]->get_symbol();
3803 ASSERT_not_null(dimension_variableSymbol);
3804 ASSERT_require(dimension_variableSymbol != variableSymbol);
3805
3806 // The symbol from the referenced variable for the array dimension expression shuld already by in the function definition's symbol table.
3807 SgSymbol* symbolFromLookup = func_def->lookup_symbol(dimension_variableSymbol->get_name());
3808 if (symbolFromLookup != nullptr)
3809 {
3810 SgVariableSymbol* variableSymbolFromLookup = isSgVariableSymbol(symbolFromLookup);
3811 ASSERT_not_null(variableSymbolFromLookup);
3812
3813 varRefList[i]->set_symbol(variableSymbolFromLookup);
3814 ASSERT_require(dimension_variableSymbol != variableSymbol);
3815 }
3816 else
3817 {
3818 // This is not a reference to a variable from the current function's paramter lists, so we can ignore processing it within the VLA handling.
3819 }
3820 }
3821 }
3822 }
3823 }
3824
3825 defining_func->set_parent(scope);
3826 defining_func->set_scope(scope);
3827
3828 ASSERT_not_null(defining_func->get_scope());
3829
3830 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(defining_func,scope);
3831
3832 // set File_Info as transformation generated
3834
3835 // Enforce that the return type matches the specification to build a member function.
3836 if (isMemberFunction == true)
3837 {
3838 ASSERT_not_null(isSgMemberFunctionDeclaration(defining_func));
3839 }
3840
3841 // DQ (2/11/2012): If this is a template instantiation then we have to set the template name (seperate from the name of the function which can include template parameters)).
3842 setTemplateNameInTemplateInstantiations(defining_func,nameWithoutTemplateArguments);
3843
3844 // DQ (9/16/2012): Setup up the template arguments and the parents of the template arguments.
3845 if (buildTemplateInstantiation == true)
3846 {
3847 setTemplateArgumentsInDeclaration(defining_func,templateArgumentsList);
3848 }
3849
3850 // DQ (8/13/2013): Added code to set the template parameters in the defining declaration (if it is a template declaration).
3851 if (buildTemplateDeclaration == true)
3852 {
3853 setTemplateParametersInDeclaration(defining_func,templateParameterList);
3854
3855 // DQ (8/13/2013): Adding test of template parameter lists.
3856 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(defining_func);
3857 ROSE_ASSERT(templateFunctionDeclaration == nullptr || (templateParameterList != nullptr && templateParameterList->size() == templateFunctionDeclaration->get_templateParameters().size()));
3858 SgTemplateMemberFunctionDeclaration* templateMemberFunctionDeclaration = isSgTemplateMemberFunctionDeclaration(defining_func);
3859 ROSE_ASSERT(templateMemberFunctionDeclaration == nullptr || (templateParameterList != nullptr && templateParameterList->size() == templateMemberFunctionDeclaration->get_templateParameters().size()));
3860 }
3861
3862 // DQ (12/12/2012): Force the two different ways that this can be set to match (we want consistancy).
3863 if (functionConstVolatileFlags & SgMemberFunctionType::e_restrict)
3864 {
3865 defining_func->get_declarationModifier().get_typeModifier().setRestrict();
3866 }
3867
3868 // DQ (4/16/2015): This is replaced with a better implementation.
3869 // DQ (4/15/2015): We should reset the isModified flags as part of the transforamtion
3870 // because we have added statements explicitly marked as transformations.
3871 // checkIsModifiedFlag(defining_func);
3872 unsetNodesMarkedAsModified(defining_func);
3873
3874 return defining_func;
3875 }
3876
3877void
3879 {
3880 // DQ (2/11/2012): If this is a template instantiation then we have to set the template name (seperate from the name of the function which can include template parameters)).
3881
3882 SgTemplateInstantiationFunctionDecl* templateInstantiationFunctionDecl = isSgTemplateInstantiationFunctionDecl(func);
3883 SgTemplateInstantiationMemberFunctionDecl* templateInstantiationMemberFunctionDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
3884 bool isTemplateInstantition = (templateInstantiationFunctionDecl != NULL) || (templateInstantiationMemberFunctionDecl != NULL);
3885 if (isTemplateInstantition == true)
3886 {
3887 // If this is a template instantiation then we need to take care of a few more issues.
3888
3889 SgName templateNameWithoutArguments = name;
3890
3891 // DQ (7/27/2012): New semantics is that we want to have the input name be without template arguments and
3892 // we will add the template arguments instead of trying to remove then (which was problematic for examples
3893 // such as "X<Y<Z>> operator X&()" and "X<Y<Z>> operator>()".
3894
3895 bool isMemberFunction = (templateInstantiationMemberFunctionDecl != NULL);
3896 if (isMemberFunction == true)
3897 {
3898 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
3899 ROSE_ASSERT(templateInstantiationFunctionDecl == NULL);
3900
3901 if (templateInstantiationMemberFunctionDecl->get_templateName().is_null() == true)
3902 {
3903 // Set the template name for the member function template instantiation.
3904 // templateInstantiationMemberFunctionDecl->set_templateName(name);
3905 templateInstantiationMemberFunctionDecl->set_templateName(templateNameWithoutArguments);
3906
3907 // DQ (5/31/2012): Find locations where this is set and include template syntax.
3908 }
3909 ROSE_ASSERT(templateInstantiationMemberFunctionDecl->get_templateName().is_null() == false);
3910 }
3911 else
3912 {
3913 ROSE_ASSERT(templateInstantiationFunctionDecl != NULL);
3914 ROSE_ASSERT(templateInstantiationMemberFunctionDecl == NULL);
3915
3916 if (templateInstantiationFunctionDecl->get_templateName().is_null() == true)
3917 {
3918 // Set the template name for the function template instantiation.
3919 // templateInstantiationFunctionDecl->set_templateName(name);
3920 templateInstantiationFunctionDecl->set_templateName(templateNameWithoutArguments);
3921
3922 // DQ (5/31/2012): Find locations where this is set and include template syntax.
3923 ROSE_ASSERT(hasTemplateSyntax(templateNameWithoutArguments) == false);
3924 }
3925 ROSE_ASSERT(templateInstantiationFunctionDecl->get_templateName().is_null() == false);
3926 }
3927 }
3928 }
3929
3931SageBuilder::buildDefiningFunctionDeclaration(const SgName& name, SgType* return_type, SgFunctionParameterList* paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, SgFunctionDeclaration* first_nondefining_declaration, SgTemplateArgumentPtrList* templateArgumentsList)
3932 {
3933 // DQ (2/10/2012): Fixed to build either SgTemplateInstantiationFunctionDecl or SgFunctionDeclaration.
3934 SgFunctionDeclaration* func = NULL;
3935 if (buildTemplateInstantiation == true)
3936 {
3937 SgTemplateInstantiationFunctionDecl* templateInstantiationFunctionDecl = isSgTemplateInstantiationFunctionDecl(first_nondefining_declaration);
3938
3939 ROSE_ASSERT(first_nondefining_declaration != NULL);
3940
3941 func = buildDefiningFunctionDeclaration_T<SgTemplateInstantiationFunctionDecl>(name,return_type,paralist,/* isMemberFunction = */ false,scope,decoratorList,0,templateInstantiationFunctionDecl, templateArgumentsList);
3942
3943 ROSE_ASSERT(isSgTemplateInstantiationFunctionDecl(func) != NULL);
3944 ROSE_ASSERT(isSgTemplateInstantiationFunctionDecl(func)->get_templateName().is_null() == false);
3945 }
3946 else
3947 {
3948 ROSE_ASSERT(first_nondefining_declaration != NULL);
3949
3950 func = buildDefiningFunctionDeclaration_T<SgFunctionDeclaration>(name,return_type,paralist,/* isMemberFunction = */ false,scope,decoratorList,0,first_nondefining_declaration, NULL);
3951
3952 ROSE_ASSERT(isSgFunctionDeclaration(func) != NULL);
3953 }
3954
3955 return func;
3956 }
3957
3958
3959// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficent).
3960// We need to decide if the SageBuilder API should include these sorts of functions.
3963 {
3964 // DQ (11/12/2012): Note that this function is not used in the AST construction in the EDG/ROSE interface.
3965 ROSE_ASSERT(return_type != NULL);
3966 ROSE_ASSERT(parameter_list != NULL);
3967
3968 if (scope == NULL)
3969 {
3971 }
3972
3973 SgFunctionDeclaration* nondefiningDeclaration = NULL;
3974
3975 SgFunctionType* func_type = buildFunctionType(return_type,parameter_list);
3976 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgFunctionDeclaration>(name,func_type,NULL,NULL);
3977 if (func_symbol != NULL)
3978 {
3979 nondefiningDeclaration = func_symbol->get_declaration();
3980 }
3981 else
3982 {
3983 nondefiningDeclaration = buildNondefiningFunctionDeclaration(name,return_type,parameter_list,scope,NULL);
3984 }
3985
3986 ROSE_ASSERT(nondefiningDeclaration != NULL);
3987 ROSE_ASSERT(nondefiningDeclaration->get_firstNondefiningDeclaration() != NULL);
3988 ROSE_ASSERT(nondefiningDeclaration->get_firstNondefiningDeclaration() == nondefiningDeclaration);
3989
3990 return buildDefiningFunctionDeclaration (name,return_type,parameter_list,scope,NULL,false,nondefiningDeclaration,NULL);
3991 }
3992
3993// Build a nondefining SgProcedureHeaderStatement, handle function type, symbol etc transparently [Rasmussen 9/24/2020]
3997 {
3998 ASSERT_not_null(return_type);
3999 ASSERT_not_null(param_list);
4000
4001 SgProcedureHeaderStatement* nondef_decl = nullptr;
4002
4003 if (scope == nullptr) {
4005 }
4006
4007 // A new nondefing declaration is needed even if the function symbol already exists. The function symbol
4008 // should always contain the _first_ nondefining declaration (even though this may not be the first one).
4009 nondef_decl = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement>
4010 ( name, return_type, param_list, /*isMemberFunction*/false, scope, /*decoratorList*/nullptr,
4011 /*functionConstVolatileFlags*/0, nullptr, nullptr, SgStorageModifier::e_default );
4012
4013 ASSERT_not_null(isSgProcedureHeaderStatement(nondef_decl));
4014 ASSERT_not_null(nondef_decl->get_firstNondefiningDeclaration());
4015
4016 nondef_decl->set_subprogram_kind(kind);
4017
4018 return nondef_decl;
4019 }
4020
4022buildProcedureHeaderStatement(const SgName& name, SgType* return_type, SgFunctionParameterList* parameter_list,
4024 {
4025 ASSERT_not_null(return_type);
4026 ASSERT_not_null(parameter_list);
4027
4028 SgFunctionDeclaration* nondef_decl = nullptr;
4029
4030 if (scope == nullptr) {
4032 }
4033
4034 SgFunctionType* func_type = buildFunctionType(return_type,parameter_list);
4035 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgProcedureHeaderStatement>(name,func_type,nullptr,nullptr);
4036 if (func_symbol == nullptr)
4037 {
4038 nondef_decl = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement>
4039 ( name, return_type, parameter_list, /*isMemberFunction*/false, scope,
4040 /*decoratorList*/nullptr, /*functionConstVolatileFlags*/0, nullptr, nullptr, SgStorageModifier::e_default);
4041 }
4042 else
4043 {
4044 nondef_decl = func_symbol->get_declaration();
4045 }
4046
4047 SgProcedureHeaderStatement* proc_header_stmt = isSgProcedureHeaderStatement(nondef_decl);
4048 ASSERT_not_null(proc_header_stmt);
4049 ASSERT_require(nondef_decl->get_firstNondefiningDeclaration() == nondef_decl);
4050
4051 return buildProcedureHeaderStatement(name.str(), return_type, parameter_list, kind, scope, proc_header_stmt);
4052 }
4053
4054
4059 SgProcedureHeaderStatement* firstNondefDecl)
4060{
4061 ASSERT_not_null(firstNondefDecl);
4062 SgProcedureHeaderStatement* func{nullptr};
4063
4066 ASSERT_require(returnType == buildVoidType());
4067 }
4069 mlog[ERROR] << "unhandled subprogram kind for Fortran (or Jovial) function declaration:"
4070 << kind << endl;
4071 ROSE_ABORT();
4072 }
4073
4074 func = buildDefiningFunctionDeclaration_T<SgProcedureHeaderStatement>(SgName(name), returnType, params, /*isMemberFunction =*/false,
4075 scope, nullptr, 0U, firstNondefDecl, nullptr);
4076 ASSERT_not_null(func);
4077 func->set_subprogram_kind(kind);
4078
4079 return func;
4080}
4081
4082//------------------build value expressions -------------------
4083//-------------------------------------------------------------
4085{
4086 //TODO does valueString matter here?
4087 SgBoolValExp* boolValue= new SgBoolValExp(value);
4088 ROSE_ASSERT(boolValue);
4090 return boolValue;
4091}
4093{
4094 return buildBoolValExp(int(value));
4095}
4097{
4098 SgBoolValExp* boolValue= new SgBoolValExp(value);
4099 ROSE_ASSERT(boolValue);
4100 setOneSourcePositionNull(boolValue);
4101 return boolValue;
4102}
4103
4105 {
4106 SgNullptrValExp* nullptrValue = new SgNullptrValExp();
4107 ROSE_ASSERT(nullptrValue);
4109 return nullptrValue;
4110 }
4111
4113 {
4114 SgNullptrValExp* nullptrValue = new SgNullptrValExp();
4115 ROSE_ASSERT(nullptrValue);
4116 setOneSourcePositionNull(nullptrValue);
4117 return nullptrValue;
4118 }
4119
4121 {
4122 SgVoidVal* voidValue = new SgVoidVal();
4123 ROSE_ASSERT(voidValue);
4125 return voidValue;
4126 }
4127
4129 {
4130 SgVoidVal* voidValue = new SgVoidVal();
4131 ROSE_ASSERT(voidValue);
4132 setOneSourcePositionNull(voidValue);
4133 return voidValue;
4134 }
4135
4137{
4138 SgCharVal* result = new SgCharVal(value, "");
4139 ROSE_ASSERT(result);
4141 return result;
4142}
4143
4144SgCharVal* SageBuilder::buildCharVal_nfi(char value, const string& str)
4145{
4146 SgCharVal* result = new SgCharVal(value, str);
4147 ROSE_ASSERT(result);
4149 return result;
4150}
4151
4153{
4154 SgWcharVal* result = new SgWcharVal(value, "");
4155 ROSE_ASSERT(result);
4157 return result;
4158}
4159
4160SgWcharVal* SageBuilder::buildWcharVal_nfi(wchar_t value, const string& str)
4161{
4162 SgWcharVal* result = new SgWcharVal(value, str);
4163 ROSE_ASSERT(result);
4165 return result;
4166}
4167
4168// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
4169SgChar16Val* SageBuilder::buildChar16Val(unsigned short value /*= 0*/)
4170{
4171 SgChar16Val* result = new SgChar16Val(value, "");
4172 ROSE_ASSERT(result);
4174 return result;
4175}
4176
4177SgChar16Val* SageBuilder::buildChar16Val_nfi(unsigned short value, const string& str)
4178{
4179 SgChar16Val* result = new SgChar16Val(value, str);
4180 ROSE_ASSERT(result);
4182 return result;
4183}
4184
4185// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
4186SgChar32Val* SageBuilder::buildChar32Val(unsigned int value /*= 0*/)
4187{
4188 SgChar32Val* result = new SgChar32Val(value, "");
4189 ROSE_ASSERT(result);
4191 return result;
4192}
4193
4194SgChar32Val* SageBuilder::buildChar32Val_nfi(unsigned int value, const string& str)
4195{
4196 SgChar32Val* result = new SgChar32Val(value, str);
4197 ROSE_ASSERT(result);
4199 return result;
4200}
4201
4202
4204{
4205 SgComplexVal* result = new SgComplexVal(real_value,imaginary_value,imaginary_value->get_type(),"");
4206 ROSE_ASSERT(result);
4207
4208// DQ (12/31/2008): set and test the parents
4209 if (real_value != NULL)
4210 real_value->set_parent(result);
4211
4212 if (imaginary_value != NULL)
4213 imaginary_value->set_parent(result);
4214
4215 ROSE_ASSERT(real_value == NULL || real_value->get_parent() != NULL);
4216 ROSE_ASSERT(imaginary_value == NULL || imaginary_value->get_parent() != NULL);
4217
4219 return result;
4220}
4221
4222SgComplexVal* SageBuilder::buildComplexVal_nfi(SgValueExp* real_value, SgValueExp* imaginary_value, const std::string& str)
4223{
4224 ROSE_ASSERT(imaginary_value != NULL);
4225 SgComplexVal* result = new SgComplexVal(real_value,imaginary_value,imaginary_value->get_type(),str);
4226 ROSE_ASSERT(result != NULL);
4227
4228// DQ (12/31/2008): set and test the parents
4229 if (real_value != NULL)
4230 real_value->set_parent(result);
4231
4232 if (imaginary_value != NULL)
4233 imaginary_value->set_parent(result);
4234
4235 ROSE_ASSERT(real_value == NULL || real_value->get_parent() != NULL);
4236 ROSE_ASSERT(imaginary_value == NULL || imaginary_value->get_parent() != NULL);
4237
4239 return result;
4240}
4241
4242SgComplexVal* SageBuilder::buildImaginaryVal(long double imaginary_value /*= 0.0*/ )
4243{
4244 SgComplexVal* result = new SgComplexVal(NULL,buildLongDoubleVal(imaginary_value),SgTypeLongDouble::createType(),"");
4245 ROSE_ASSERT(result);
4246
4247// DQ (12/31/2008): set and test the parents
4248 result->get_imaginary_value()->set_parent(result);
4249 ROSE_ASSERT(result->get_imaginary_value()->get_parent() != NULL);
4250
4252 return result;
4253}
4254
4256{
4257 ROSE_ASSERT(imaginary_value != NULL);
4258
4259 SgComplexVal* result = new SgComplexVal(NULL,imaginary_value,imaginary_value->get_type(),"");
4260 ROSE_ASSERT(result);
4261
4262// DQ (12/31/2008): set and test the parents
4263 imaginary_value->set_parent(result);
4264 ROSE_ASSERT(imaginary_value->get_parent() != NULL);
4265
4267 return result;
4268}
4269
4270SgComplexVal* SageBuilder::buildImaginaryVal_nfi(SgValueExp* imaginary_value, const std::string& str)
4271{
4272 ROSE_ASSERT(imaginary_value != NULL);
4273
4274 SgComplexVal* result = new SgComplexVal(NULL,imaginary_value,imaginary_value->get_type(),str);
4275 imaginary_value->set_parent(result);
4276 ROSE_ASSERT(result);
4277
4278// DQ (12/31/2008): set and test the parents
4279 ROSE_ASSERT(imaginary_value->get_parent() != NULL);
4280
4282 return result;
4283}
4284
4286{
4287 SgDoubleVal* value = new SgDoubleVal(t,"");
4288 ROSE_ASSERT(value);
4290 return value;
4291}
4292
4294{
4295 SgDoubleVal* value = new SgDoubleVal(t,str);
4296 ROSE_ASSERT(value);
4298 return value;
4299}
4300
4302{
4303 SgFloatVal* result = new SgFloatVal(value,"");
4304 ROSE_ASSERT(result);
4306 return result;
4307}
4308
4310{
4311 SgFloatVal* result = new SgFloatVal(value,"");
4312 ROSE_ASSERT(result);
4314 return result;
4315}
4316
4317SgFloatVal* SageBuilder::buildFloatVal_nfi(float value, const string& str)
4318{
4319 SgFloatVal* result = new SgFloatVal(value,str);
4320 ROSE_ASSERT(result);
4322 return result;
4323}
4324
4326{
4327 // C++11 please [CR 2020.02.25]
4328 // return buildFloatVal_nfi(std::stof(str), str);
4329 return buildFloatVal_nfi(atof(str.c_str()), str);
4330}
4331
4333 {
4334 SgIntVal* intValue= new SgIntVal(value,"");
4335 ASSERT_not_null(intValue);
4337 return intValue;
4338 }
4339
4341 {
4342 SgIntVal* intValue= new SgIntVal(value, (value >= 0 ? StringUtility::intToHex((unsigned int)value) : "-" + StringUtility::intToHex((unsigned int)(-value))));
4343 ASSERT_not_null(intValue);
4345 return intValue;
4346 }
4347
4349 {
4350 SgIntVal* intValue = new SgIntVal(value,"");
4351 ASSERT_not_null(intValue);
4352 setOneSourcePositionNull(intValue);
4353 return intValue;
4354 }
4355
4356SgIntVal* SageBuilder::buildIntVal_nfi(int value, const string& str)
4357 {
4358 SgIntVal* intValue = new SgIntVal(value,str);
4359 ASSERT_not_null(intValue);
4360 setOneSourcePositionNull(intValue);
4361 return intValue;
4362 }
4363
4365 {
4366 return buildIntVal_nfi(std::stoi(str), str);
4367 }
4368
4370{
4371 SgLongIntVal* intValue= new SgLongIntVal(value,"");
4372 ASSERT_not_null(intValue);
4374 return intValue;
4375}
4376
4377SgLongIntVal* SageBuilder::buildLongIntVal_nfi(long value, const string& str)
4378{
4379 SgLongIntVal* intValue= new SgLongIntVal(value,str);
4380 ASSERT_not_null(intValue);
4381 setOneSourcePositionNull(intValue);
4382 return intValue;
4383}
4384
4386{
4387 SgLongLongIntVal* intValue= new SgLongLongIntVal(value,"");
4388 ASSERT_not_null(intValue);
4390 return intValue;
4391}
4392
4393SgLongLongIntVal* SageBuilder::buildLongLongIntVal_nfi(long long value, const string& str)
4394{
4395 SgLongLongIntVal* intValue= new SgLongLongIntVal(value,str);
4396 ASSERT_not_null(intValue);
4397 setOneSourcePositionNull(intValue);
4398 return intValue;
4399}
4400
4402 {
4403 SgEnumVal* enumVal= new SgEnumVal(value,decl,name);
4404 ASSERT_not_null(enumVal);
4406 return enumVal;
4407 }
4408
4409
4411 {
4412 SgEnumVal* enumVal= new SgEnumVal(value,decl,name);
4413 ASSERT_not_null(enumVal);
4414 setOneSourcePositionNull(enumVal);
4415 return enumVal;
4416 }
4417
4419 SgInitializedName * init_name = sym->get_declaration();
4420 ROSE_ASSERT(init_name != NULL);
4421 SgAssignInitializer * assign_init = isSgAssignInitializer(init_name->get_initptr());
4422 ROSE_ASSERT(assign_init != NULL);
4423 SgEnumVal * enum_val = isSgEnumVal(assign_init->get_operand_i());
4424 ROSE_ASSERT(enum_val != NULL);
4425 enum_val = isSgEnumVal(SageInterface::copyExpression(enum_val));
4426 return enum_val;
4427}
4428
4430{
4431 SgLongDoubleVal* result = new SgLongDoubleVal(value,"");
4432 ASSERT_not_null(result);
4434 return result;
4435}
4436
4437SgLongDoubleVal* SageBuilder::buildLongDoubleVal_nfi(long double value, const string& str)
4438{
4439 SgLongDoubleVal* result = new SgLongDoubleVal(value,str);
4440 ASSERT_not_null(result);
4442 return result;
4443}
4444
4445SgFloat80Val* SageBuilder::buildFloat80Val(long double value /*= 0.0*/)
4446{
4447 SgFloat80Val* result = new SgFloat80Val(value,"");
4448 ASSERT_not_null(result);
4450 return result;
4451}
4452
4453SgFloat80Val* SageBuilder::buildFloat80Val_nfi(long double value, const string& str)
4454{
4455 SgFloat80Val* result = new SgFloat80Val(value,str);
4456 ASSERT_not_null(result);
4458 return result;
4459}
4460
4462{
4463 SgBFloat16Val* result = new SgBFloat16Val(value,"");
4464 ASSERT_not_null(result);
4466 return result;
4467}
4468
4469SgBFloat16Val* SageBuilder::buildBFloat16Val_nfi(float value, const string& str)
4470{
4471 SgBFloat16Val* result = new SgBFloat16Val(value,str);
4472 ASSERT_not_null(result);
4474 return result;
4475}
4476
4478{
4479 SgFloat16Val* result = new SgFloat16Val(value,"");
4480 ASSERT_not_null(result);
4482 return result;
4483}
4484
4485SgFloat16Val* SageBuilder::buildFloat16Val_nfi(float value, const string& str)
4486{
4487 SgFloat16Val* result = new SgFloat16Val(value,str);
4488 ASSERT_not_null(result);
4490 return result;
4491}
4492
4494{
4495 SgFloat32Val* result = new SgFloat32Val(value,"");
4496 ASSERT_not_null(result);
4498 return result;
4499}
4500
4501SgFloat32Val* SageBuilder::buildFloat32Val_nfi(float value, const string& str)
4502{
4503 SgFloat32Val* result = new SgFloat32Val(value,str);
4504 ASSERT_not_null(result);
4506 return result;
4507}
4508
4510{
4511 SgFloat64Val* result = new SgFloat64Val(value,"");
4512 ASSERT_not_null(result);
4514 return result;
4515}
4516
4517SgFloat64Val* SageBuilder::buildFloat64Val_nfi(double value, const string& str)
4518{
4519 SgFloat64Val* result = new SgFloat64Val(value,str);
4520 ASSERT_not_null(result);
4522 return result;
4523}
4524
4526{
4527 SgFloat128Val* result = new SgFloat128Val(value,"");
4528 ASSERT_not_null(result);
4530 return result;
4531}
4532
4533SgFloat128Val* SageBuilder::buildFloat128Val_nfi(long double value, const string& str)
4534{
4535 SgFloat128Val* result = new SgFloat128Val(value,str);
4536 ASSERT_not_null(result);
4538 return result;
4539}
4540
4541SgStringVal* SageBuilder::buildStringVal(std::string value /*=""*/)
4542{
4543 SgStringVal* result = new SgStringVal(value);
4544 ASSERT_not_null(result);
4546 return result;
4547}
4548
4550{
4551 SgStringVal* result = new SgStringVal(value);
4552 ASSERT_not_null(result);
4554 return result;
4555}
4556
4558{
4559 SgUnsignedCharVal* result = new SgUnsignedCharVal(v,"");
4560 ASSERT_not_null(result);
4562 return result;
4563}
4564
4566{
4568 ASSERT_not_null(result);
4570 return result;
4571}
4572
4574{
4575 SgUnsignedCharVal* result = new SgUnsignedCharVal(v,str);
4576 ASSERT_not_null(result);
4578 return result;
4579}
4580
4582{
4583 SgSignedCharVal* result = new SgSignedCharVal(v,"");
4584 ASSERT_not_null(result);
4586 return result;
4587}
4588
4590{
4592 ASSERT_not_null(result);
4594 return result;
4595}
4596
4598{
4599 SgSignedCharVal* result = new SgSignedCharVal(v,str);
4600 ASSERT_not_null(result);
4602 return result;
4603}
4604
4606{
4607 SgShortVal* result = new SgShortVal(v,"");
4608 ASSERT_not_null(result);
4610 return result;
4611}
4612
4614{
4615 SgShortVal* result = new SgShortVal(v, (v >= 0 ? StringUtility::intToHex((unsigned int)v) : "-" + StringUtility::intToHex((unsigned int)(-v))));
4616 ASSERT_not_null(result);
4618 return result;
4619}
4620
4621SgShortVal* SageBuilder::buildShortVal_nfi(short v, const string& str)
4622{
4623 SgShortVal* result = new SgShortVal(v,str);
4624 ASSERT_not_null(result);
4626 return result;
4627}
4628
4630{
4631 SgUnsignedShortVal* result = new SgUnsignedShortVal(v,"");
4632 ASSERT_not_null(result);
4634 return result;
4635}
4636
4638{
4640 ASSERT_not_null(result);
4642 return result;
4643}
4644
4646{
4647 SgUnsignedShortVal* result = new SgUnsignedShortVal(v,str);
4648 ASSERT_not_null(result);
4650 return result;
4651}
4652
4654{
4655 SgUnsignedIntVal* result = new SgUnsignedIntVal(v,"");
4656 ASSERT_not_null(result);
4658 return result;
4659}
4660
4662{
4664 ASSERT_not_null(result);
4666 return result;
4667}
4668
4670{
4671 SgUnsignedIntVal* result = new SgUnsignedIntVal(v,str);
4672 ASSERT_not_null(result);
4674 return result;
4675}
4676
4678{
4679 SgUnsignedLongVal* result = new SgUnsignedLongVal(v,"");
4680 ASSERT_not_null(result);
4682 return result;
4683}
4684
4686{
4688 ASSERT_not_null(result);
4690 return result;
4691}
4692
4694{
4695 SgUnsignedLongVal* result = new SgUnsignedLongVal(v,str);
4696 ASSERT_not_null(result);
4698 return result;
4699}
4700
4702{
4704 ASSERT_not_null(result);
4706 return result;
4707}
4708
4710{
4712 ASSERT_not_null(result);
4714 return result;
4715}
4716
4718{
4720 ASSERT_not_null(result);
4722 return result;
4723}
4724
4725SgJovialBitVal* SageBuilder::buildJovialBitVal_nfi(const string& str)
4726{
4727 SgJovialBitVal* result = new SgJovialBitVal(str);
4728 ASSERT_not_null(result);
4730 return result;
4731}
4732
4734{
4735 SgTemplateType* result = new SgTemplateType (name);
4736 ASSERT_not_null (result);
4738 return result;
4739}
4740
4742{
4743 ROSE_ASSERT (t);
4744 SgTemplateParameter* result = new SgTemplateParameter(parameterType, t);
4745 ROSE_ASSERT (result);
4747 return result;
4748}
4749
4751{
4752 SgTemplateParameterVal* templateParameterValue = new SgTemplateParameterVal(template_parameter_position,"");
4753 ROSE_ASSERT(templateParameterValue);
4754 setOneSourcePositionForTransformation(templateParameterValue);
4755
4756// DQ (7/25/2012): Assert this (it will be set later).
4757 ROSE_ASSERT(templateParameterValue->get_parent() == NULL);
4758
4759 return templateParameterValue;
4760}
4761
4762SgTemplateParameterVal* SageBuilder::buildTemplateParameterVal_nfi(int template_parameter_position, const string& str)
4763{
4764 SgTemplateParameterVal* templateParameterValue= new SgTemplateParameterVal(template_parameter_position,str);
4765 ROSE_ASSERT(templateParameterValue);
4766 setOneSourcePositionNull(templateParameterValue);
4767
4768// DQ (7/25/2012): Assert this (it will be set later).
4769 ROSE_ASSERT(templateParameterValue->get_parent() == NULL);
4770
4771 return templateParameterValue;
4772}
4773
4774#define DEBUG_BUILD_NONREAL_DECL 0
4775
4777 ROSE_ASSERT(scope != NULL);
4778#if DEBUG_BUILD_NONREAL_DECL
4779 printf("ENTER SageBuilder::buildNonrealDecl\n");
4780 printf(" --- name = %s\n", name.str());
4781 printf(" --- scope = %p (%s)\n", scope, scope->class_name().c_str());
4782#endif
4783
4784 SgNonrealDecl * nrdecl = NULL;
4785
4786 nrdecl = new SgNonrealDecl(name);
4788 nrdecl->set_firstNondefiningDeclaration(nrdecl);
4789#if DEBUG_BUILD_NONREAL_DECL
4790 printf(" --- nrdecl = %p (%s)\n", nrdecl, nrdecl->class_name().c_str());
4791#endif
4792
4793 SgNonrealSymbol * symbol = new SgNonrealSymbol(nrdecl);
4794 scope->insert_symbol(name, symbol);
4795#if DEBUG_BUILD_NONREAL_DECL
4796 printf(" --- symbol = %p (%s)\n", symbol, symbol->class_name().c_str());
4797#endif
4798
4799 SgNonrealType * type = new SgNonrealType();
4800 type->set_declaration(nrdecl);
4801 type->set_parent(scope);
4802 nrdecl->set_type(type);
4803 // FIXME (???) insert `type` in `scope`
4804#if DEBUG_BUILD_NONREAL_DECL
4805 printf(" --- type = %p (%s)\n", type, type->class_name().c_str());
4806#endif
4807
4808 if (child_scope == NULL) {
4809 child_scope = new SgDeclarationScope();
4810#if DEBUG_BUILD_NONREAL_DECL
4811 printf(" --- child_scope = %p (new)\n", name.str(), child_scope);
4812#endif
4815 child_scope->get_endOfConstruct()->setCompilerGenerated();
4816 } else {
4817#if DEBUG_BUILD_NONREAL_DECL
4818 printf(" --- child_scope = %p (provided)\n", name.str(), child_scope);
4819#endif
4820
4821 }
4822 child_scope->set_parent(nrdecl);
4823 nrdecl->set_nonreal_decl_scope(child_scope);
4824
4825#if DEBUG_BUILD_NONREAL_DECL
4826 printf("LEAVE SageBuilder::buildNonrealDecl\n");
4827#endif
4828
4829 return nrdecl;
4830}
4831
4834{
4835 SgUpcThreads* result = new SgUpcThreads(0,"");
4836 ROSE_ASSERT(result);
4838 return result;
4839}
4840
4843{
4844 SgUpcThreads* result = new SgUpcThreads(0,"");
4845 ROSE_ASSERT(result);
4847 return result;
4848}
4849
4852{
4853 SgUpcMythread* result = new SgUpcMythread(0,"");
4854 ROSE_ASSERT(result);
4856 return result;
4857}
4858
4861{
4862 SgUpcMythread* result = new SgUpcMythread(0,"");
4863 ROSE_ASSERT(result);
4865 return result;
4866}
4867
4869{
4870 SgThisExp* result = new SgThisExp(isSgClassSymbol(sym), isSgNonrealSymbol(sym), 0);
4871 ROSE_ASSERT(result);
4873 return result;
4874}
4875
4877{
4878 SgThisExp* result = new SgThisExp(isSgClassSymbol(sym), isSgNonrealSymbol(sym), 0);
4879 ROSE_ASSERT(result);
4881 return result;
4882}
4883
4885{
4886 SgSuperExp* result = new SgSuperExp(sym, 0);
4887 ROSE_ASSERT(result);
4889 return result;
4890}
4891
4893{
4894 SgSuperExp* result = new SgSuperExp(sym, 0);
4895 ROSE_ASSERT(result);
4897 return result;
4898}
4899
4901{
4902 SgClassExp* result = new SgClassExp(sym, 0);
4903 ROSE_ASSERT(result);
4905 return result;
4906}
4907
4909{
4910 SgClassExp* result = new SgClassExp(sym, 0);
4911 ROSE_ASSERT(result);
4913 return result;
4914}
4915
4918{
4919 SgTupleExp* tuple = new SgTupleExp();
4920 ROSE_ASSERT(tuple);
4921 if (elt1) appendExpression(tuple, elt1);
4922 if (elt2) appendExpression(tuple, elt2);
4923 if (elt3) appendExpression(tuple, elt3);
4924 if (elt4) appendExpression(tuple, elt4);
4925 if (elt5) appendExpression(tuple, elt5);
4926 if (elt6) appendExpression(tuple, elt6);
4927 if (elt7) appendExpression(tuple, elt7);
4928 if (elt8) appendExpression(tuple, elt8);
4929 if (elt9) appendExpression(tuple, elt9);
4930 if (elt10) appendExpression(tuple, elt10);
4931
4933 return tuple;
4934}
4935
4937SageBuilder::buildTupleExp(const std::vector<SgExpression*>& elts)
4938{
4940 appendExpressionList(expList, elts);
4941 return expList;
4942}
4943
4946{
4947 SgTupleExp* tuple = new SgTupleExp();
4948 ROSE_ASSERT(tuple);
4950 return tuple;
4951}
4952
4954SageBuilder::buildTupleExp_nfi(const std::vector<SgExpression*>& elts)
4955{
4957 appendExpressionList(tuple, elts);
4958 return tuple;
4959}
4960
4961SgListExp*
4963{
4964 SgListExp* tuple = new SgListExp();
4965 ROSE_ASSERT(tuple);
4966 if (elt1) appendExpression(tuple, elt1);
4967 if (elt2) appendExpression(tuple, elt2);
4968 if (elt3) appendExpression(tuple, elt3);
4969 if (elt4) appendExpression(tuple, elt4);
4970 if (elt5) appendExpression(tuple, elt5);
4971 if (elt6) appendExpression(tuple, elt6);
4972 if (elt7) appendExpression(tuple, elt7);
4973 if (elt8) appendExpression(tuple, elt8);
4974 if (elt9) appendExpression(tuple, elt9);
4975 if (elt10) appendExpression(tuple, elt10);
4976
4978 return tuple;
4979}
4980
4981SgListExp*
4982SageBuilder::buildListExp(const std::vector<SgExpression*>& elts)
4983{
4985 appendExpressionList(expList, elts);
4986 return expList;
4987}
4988
4989SgListExp*
4991{
4992 SgListExp* tuple = new SgListExp();
4993 ROSE_ASSERT(tuple);
4995 return tuple;
4996}
4997
4998SgListExp*
4999SageBuilder::buildListExp_nfi(const std::vector<SgExpression*>& elts)
5000{
5002 appendExpressionList(tuple, elts);
5003 return tuple;
5004}
5005
5006
5007#define BUILD_UNARY_DEF(suffix) \
5008 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix##_nfi(SgExpression* op) \
5009 { \
5010 return SageBuilder::buildUnaryExpression_nfi<Sg##suffix>(op); \
5011 } \
5012 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix(SgExpression* op) \
5013 { \
5014 return SageBuilder::buildUnaryExpression<Sg##suffix>(op); \
5015 }
5016
5017BUILD_UNARY_DEF(AddressOfOp)
5018BUILD_UNARY_DEF(BitComplementOp)
5019BUILD_UNARY_DEF(MinusOp)
5020BUILD_UNARY_DEF(NotOp)
5021BUILD_UNARY_DEF(PointerDerefExp)
5022BUILD_UNARY_DEF(UnaryAddOp)
5023BUILD_UNARY_DEF(AbsOp)
5024BUILD_UNARY_DEF(MinusMinusOp)
5025BUILD_UNARY_DEF(PlusPlusOp)
5026BUILD_UNARY_DEF(RealPartOp)
5027BUILD_UNARY_DEF(ImagPartOp)
5028BUILD_UNARY_DEF(ConjugateOp)
5029BUILD_UNARY_DEF(VarArgStartOneOperandOp)
5030BUILD_UNARY_DEF(VarArgEndOp)
5031
5032BUILD_UNARY_DEF(MatrixTransposeOp) //SK(08/20/2015): Matlab matrix transpose operators
5033
5034#undef BUILD_UNARY_DEF
5035
5037 SgType * expression_type,
5038 SgCastExp::cast_type_enum cast_type)
5039{
5040 SgCastExp* result = new SgCastExp(operand_i, expression_type, cast_type);
5041 ROSE_ASSERT(result);
5042 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5044 return result;
5045}
5046
5047SgNewExp*
5049 SgExprListExp* placement_args,
5050 SgConstructorInitializer* constructor_args,
5051 SgExpression* builtin_args,
5052 // FIXME: Change this from "short int" to "bool".
5053 short int need_global_specifier,
5054 SgFunctionDeclaration* newOperatorDeclaration)
5055 {
5056 // DQ (11/18/2012): Modified parameter names to make this function more clear.
5057 SgNewExp* result = new SgNewExp(specified_type, placement_args, constructor_args, builtin_args, need_global_specifier, newOperatorDeclaration);
5058 ROSE_ASSERT(result);
5059
5061 return result;
5062 }
5063
5065 short is_array,
5066 short need_global_specifier,
5067 SgFunctionDeclaration* deleteOperatorDeclaration)
5068{
5069 SgDeleteExp* result = new SgDeleteExp(variable, is_array,
5070 need_global_specifier, deleteOperatorDeclaration);
5071 ROSE_ASSERT(result);
5073 return result;
5074}
5075
5078 {
5079 // DQ (1/25/2013): Added support for typeId operators.
5080 SgTypeIdOp* result = new SgTypeIdOp(operand_expr,operand_type);
5081 ROSE_ASSERT(result != NULL);
5083 return result;
5084 }
5085
5087{
5088 SgCastExp* result = new SgCastExp(operand_i, expression_type, cast_type);
5089 ROSE_ASSERT(result);
5090 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5092 return result;
5093}
5094
5096 SgVarArgOp* result = new SgVarArgOp(operand_i, expression_type);
5097 ROSE_ASSERT(result);
5098 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5100 return result;
5101}
5102
5104{
5105 SgMinusMinusOp* result = buildUnaryExpression<SgMinusMinusOp>(operand_i);
5106 ROSE_ASSERT(result);
5107 result->set_mode(a_mode);
5108 return result;
5109}
5110
5112{
5113 SgMinusMinusOp* result = buildUnaryExpression_nfi<SgMinusMinusOp>(operand_i);
5114 ROSE_ASSERT(result);
5115 result->set_mode(a_mode);
5116 return result;
5117}
5118
5120{
5121 SgMinusOp* result = buildUnaryExpression<SgMinusOp>(operand_i);
5122 ROSE_ASSERT(result);
5123 result->set_mode(a_mode);
5124 return result;
5125}
5126
5128{
5129 SgMinusOp* result = buildUnaryExpression_nfi<SgMinusOp>(operand_i);
5130 ROSE_ASSERT(result);
5131 result->set_mode(a_mode);
5132 return result;
5133}
5134
5136{
5137 SgPlusPlusOp* result = buildUnaryExpression<SgPlusPlusOp>(operand_i);
5138 ROSE_ASSERT(result);
5139 result->set_mode(a_mode);
5140 return result;
5141}
5142
5143
5145{
5146 SgPlusPlusOp* result = buildUnaryExpression_nfi<SgPlusPlusOp>(operand_i);
5147 ROSE_ASSERT(result);
5148 result->set_mode(a_mode);
5149 return result;
5150}
5151
5153 {
5154 // DQ (11/8/2011): operand_i is allowed to be NULL.
5155
5156 // SgThrowOp* result = new SgThrowOp(operand_i, operand_i -> get_type(), throwKind);
5157 SgThrowOp* result = new SgThrowOp(operand_i, (operand_i != NULL) ? operand_i->get_type() : NULL, throwKind);
5158
5159 if (operand_i)
5160 {
5161 markLhsValues(result);
5162 }
5163
5165
5166 if (operand_i)
5167 operand_i -> set_parent(result);
5168
5169 ROSE_ASSERT(result);
5170
5171 return result;
5172 }
5173
5174
5175
5176#define BUILD_BINARY_DEF(suffix) \
5177 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix##_nfi(SgExpression* lhs, SgExpression* rhs) \
5178 { \
5179 return buildBinaryExpression_nfi<Sg##suffix>(lhs, rhs); \
5180 } \
5181 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix(SgExpression* lhs, SgExpression* rhs) \
5182 { \
5183 return buildBinaryExpression<Sg##suffix>(lhs, rhs); \
5184 }
5185
5186BUILD_BINARY_DEF(AddOp)
5187BUILD_BINARY_DEF(AndAssignOp)
5188BUILD_BINARY_DEF(AndOp)
5189BUILD_BINARY_DEF(ArrowExp)
5190BUILD_BINARY_DEF(ArrowStarOp)
5191BUILD_BINARY_DEF(AssignOp)
5192BUILD_BINARY_DEF(AtOp)
5193BUILD_BINARY_DEF(BitAndOp)
5194BUILD_BINARY_DEF(BitOrOp)
5195BUILD_BINARY_DEF(BitXorOp)
5196
5197BUILD_BINARY_DEF(CommaOpExp)
5198BUILD_BINARY_DEF(ConcatenationOp)
5199BUILD_BINARY_DEF(DivAssignOp)
5200BUILD_BINARY_DEF(DivideOp)
5201BUILD_BINARY_DEF(DotExp)
5202BUILD_BINARY_DEF(DotStarOp)
5203BUILD_BINARY_DEF(EqualityOp)
5204
5205BUILD_BINARY_DEF(ExponentiationOp)
5206BUILD_BINARY_DEF(ExponentiationAssignOp)
5207BUILD_BINARY_DEF(GreaterOrEqualOp)
5208BUILD_BINARY_DEF(GreaterThanOp)
5209BUILD_BINARY_DEF(IntegerDivideOp)
5210BUILD_BINARY_DEF(IntegerDivideAssignOp)
5211BUILD_BINARY_DEF(IorAssignOp)
5212BUILD_BINARY_DEF(IsOp)
5213BUILD_BINARY_DEF(IsNotOp)
5214
5215BUILD_BINARY_DEF(LessOrEqualOp)
5216BUILD_BINARY_DEF(LessThanOp)
5217BUILD_BINARY_DEF(LshiftAssignOp)
5218BUILD_BINARY_DEF(LshiftOp)
5219
5220BUILD_BINARY_DEF(MembershipOp)
5221BUILD_BINARY_DEF(MinusAssignOp)
5222BUILD_BINARY_DEF(ModAssignOp)
5223BUILD_BINARY_DEF(ModOp)
5224BUILD_BINARY_DEF(MultAssignOp)
5225BUILD_BINARY_DEF(MultiplyOp)
5226
5227BUILD_BINARY_DEF(NotEqualOp)
5228BUILD_BINARY_DEF(NonMembershipOp)
5229BUILD_BINARY_DEF(OrOp)
5230BUILD_BINARY_DEF(PlusAssignOp)
5231BUILD_BINARY_DEF(PntrArrRefExp)
5232BUILD_BINARY_DEF(RemOp)
5233BUILD_BINARY_DEF(RshiftAssignOp)
5234BUILD_BINARY_DEF(JavaUnsignedRshiftAssignOp)
5235
5236BUILD_BINARY_DEF(RshiftOp)
5237BUILD_BINARY_DEF(JavaUnsignedRshiftOp)
5238BUILD_BINARY_DEF(ScopeOp)
5239BUILD_BINARY_DEF(SubtractOp)
5240BUILD_BINARY_DEF(XorAssignOp)
5241
5242BUILD_BINARY_DEF(VarArgCopyOp)
5243BUILD_BINARY_DEF(VarArgStartOp)
5244
5245// CR(07/26/2018): Jovial operators
5246BUILD_BINARY_DEF(ReplicationOp);
5247
5248//SK(08/20/2015): Matlab operators
5249BUILD_BINARY_DEF(PowerOp);
5250BUILD_BINARY_DEF(ElementwisePowerOp);
5251BUILD_BINARY_DEF(ElementwiseMultiplyOp);
5252BUILD_BINARY_DEF(ElementwiseDivideOp);
5253BUILD_BINARY_DEF(LeftDivideOp);
5254BUILD_BINARY_DEF(ElementwiseLeftDivideOp);
5255BUILD_BINARY_DEF(ElementwiseAddOp);
5256BUILD_BINARY_DEF(ElementwiseSubtractOp);
5257
5258// DQ (7/25/2020): Adding C++20 support
5259BUILD_BINARY_DEF(SpaceshipOp)
5260
5261#undef BUILD_BINARY_DEF
5262
5263
5264
5265// CR ( 1/25/2018):
5266// (10/30/2018): Fixed case when this function is called with NULL dim_info object.
5268 {
5269 ROSE_ASSERT(base_type != NULL);
5270
5271 // There must always be a dim_info object for this function. If not, the
5272 // overloaded function must be used to handle it.
5273 if (dim_info == NULL)
5274 {
5275 SgExpression* index = NULL;
5276 return buildArrayType(base_type, index);
5277 }
5278
5279 SgExpression* index = new SgNullExpression();
5280 ROSE_ASSERT(index);
5281 setSourcePosition(index);
5282
5283 SgArrayType* array_type = new SgArrayType(base_type, index);
5284 ROSE_ASSERT(array_type);
5285 ROSE_ASSERT(array_type->get_dim_info() == NULL);
5286
5287 index ->set_parent(array_type);
5288 dim_info->set_parent(array_type);
5289
5290 array_type->set_dim_info(dim_info);
5291 array_type->set_rank(dim_info->get_expressions().size());
5292
5293 return array_type;
5294 }
5295
5296SgArrayType* SageBuilder::buildArrayType(SgType* base_type/*=NULL*/, SgExpression* index/*=NULL*/)
5297{
5298 SgArrayType* result = new SgArrayType(base_type,index);
5299 ASSERT_not_null(result);
5300
5301 if (index != nullptr) {
5302 index->set_parent(result); // important!
5303 }
5304
5305 return result;
5306}
5307
5309{
5310 SgConditionalExp* result = new SgConditionalExp(test, a, b, NULL);
5311 if (test) test->set_parent(result);
5312 if (a) a->set_parent(result);
5313 if (b) b->set_parent(result);
5315 return result;
5316}
5317
5319{
5320 SgConditionalExp* result = new SgConditionalExp(test, a, b, t);
5321 if (test) test->set_parent(result);
5322 if (a) {a->set_parent(result); markLhsValues(a);}
5323 if (b) {b->set_parent(result); markLhsValues(b);}
5325 return result;
5326}
5327
5329{
5331 ROSE_ASSERT(result);
5333 return result;
5334}
5335
5338 ROSE_ASSERT(ne);
5340 return ne;
5341}
5342
5348
5350 SgColonShapeExp* expr = new SgColonShapeExp();
5351 ASSERT_not_null(expr);
5353 return expr;
5354}
5355
5361
5362SgAssignInitializer * SageBuilder::buildAssignInitializer(SgExpression * operand_i /*= NULL*/, SgType * expression_type /* = NULL */)
5363 {
5364 SgAssignInitializer* result = new SgAssignInitializer(operand_i, expression_type);
5365 ROSE_ASSERT(result);
5366 if (operand_i!=NULL)
5367 {
5368 operand_i->set_parent(result);
5369 // set lvalue, it asserts operand!=NULL
5370 markLhsValues(result);
5371 }
5373 return result;
5374 }
5375
5376SgAssignInitializer * SageBuilder::buildAssignInitializer_nfi(SgExpression * operand_i /*= nullptr*/, SgType * expression_type /*=nullptr*/)
5377 {
5378 SgAssignInitializer* result = new SgAssignInitializer(operand_i, expression_type);
5379 ASSERT_not_null(result);
5380 if (operand_i)
5381 {
5382 operand_i->set_parent(result);
5383 // set lvalue, it asserts operand!=NULL
5384 markLhsValues(result);
5385 }
5386
5387 setSourcePosition(result);
5388 result->set_need_paren(false);
5389
5390 return result;
5391 }
5392
5395{
5396 SgAggregateInitializer* result = new SgAggregateInitializer(initializers, type);
5397 ROSE_ASSERT(result);
5398 if (initializers!=NULL)
5399 {
5400 initializers->set_parent(result);
5401 }
5402 result->set_need_explicit_braces(true);
5404 return result;
5405}
5406
5409{
5410 SgAggregateInitializer* result = new SgAggregateInitializer(initializers, type);
5411 ROSE_ASSERT(result);
5412 if (initializers!=NULL)
5413 {
5414 initializers->set_parent(result);
5415 }
5416 result->set_need_explicit_braces(true);
5418 return result;
5419}
5420
5423{
5424 SgCompoundInitializer* result = new SgCompoundInitializer(initializers, type);
5425 ROSE_ASSERT(result);
5426 if (initializers!=NULL)
5427 {
5428 initializers->set_parent(result);
5429 }
5431 return result;
5432}
5433
5436{
5437 SgCompoundInitializer* result = new SgCompoundInitializer(initializers, type);
5438 ROSE_ASSERT(result);
5439 if (initializers!=NULL)
5440 {
5441 initializers->set_parent(result);
5442 }
5444 return result;
5445}
5446
5447// DQ (1/4/2009): Added support for SgConstructorInitializer
5450 SgMemberFunctionDeclaration *declaration/* = NULL*/,
5451 SgExprListExp *args/* = NULL*/,
5452 SgType *expression_type/* = NULL*/,
5453 bool need_name /*= false*/,
5454 bool need_qualifier /*= false*/,
5455 bool need_parenthesis_after_name /*= false*/,
5456 bool associated_class_unknown /*= false*/)
5457 {
5458 // Prototype:
5459 // SgConstructorInitializer (SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type,
5460 // bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown);
5461
5462 //George Vulov (05/24/2011) Modified this assertion to allow for a NULL declaration (in case of implicit constructors)
5463 ROSE_ASSERT(declaration == NULL || declaration->get_associatedClassDeclaration() != NULL);
5464
5465 SgConstructorInitializer* result = new SgConstructorInitializer( declaration, args, expression_type, need_name,
5466 need_qualifier, need_parenthesis_after_name, associated_class_unknown );
5467 ROSE_ASSERT(result != NULL);
5468 if (args != NULL)
5469 {
5470 args->set_parent(result);
5472 }
5473
5475
5476 return result;
5477 }
5478
5479// DQ (1/4/2009): Added support for SgConstructorInitializer
5482 SgMemberFunctionDeclaration *declaration/* = NULL*/,
5483 SgExprListExp *args/* = NULL*/,
5484 SgType *expression_type/* = NULL*/,
5485 bool need_name /*= false*/,
5486 bool need_qualifier /*= false*/,
5487 bool need_parenthesis_after_name /*= false*/,
5488 bool associated_class_unknown /*= false*/)
5489 {
5490 // Prototype:
5491 // SgConstructorInitializer (SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type, bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown);
5492
5493 // DQ (11/7/2011): Fix symetric to the way George did it above.
5494 ROSE_ASSERT(declaration == NULL || declaration->get_associatedClassDeclaration() != NULL);
5495
5496 SgConstructorInitializer* result = new SgConstructorInitializer( declaration, args, expression_type, need_name, need_qualifier, need_parenthesis_after_name, associated_class_unknown );
5497 ROSE_ASSERT(result != NULL);
5498
5500
5501 if (args != NULL)
5502 {
5503 args->set_parent(result);
5504 }
5505
5506 // DQ (11/4/2012): This is required and appears to work fine now.
5507 // DQ (11/23/2011): Fixup the expression list (but this does not appear to work...)
5508 if (result->get_args()->get_startOfConstruct() == NULL)
5509 {
5510 setOneSourcePositionNull(result->get_args());
5511 }
5512
5513 return result;
5514 }
5515
5516// DQ (11/15/2016):Adding support for braced initializer (required for template support).
5520 {
5521 SgBracedInitializer* result = new SgBracedInitializer(initializers, expression_type);
5522 ROSE_ASSERT(result);
5523 if (initializers!=NULL)
5524 {
5525 initializers->set_parent(result);
5526 }
5528 return result;
5529 }
5530
5532 {
5533 SgBracedInitializer* result = new SgBracedInitializer(initializers, expression_type);
5534 ROSE_ASSERT(result);
5535 if (initializers!=NULL)
5536 {
5537 initializers->set_parent(result);
5538 }
5540 return result;
5541 }
5542
5543
5546 {
5547 // SgType* exp_type = NULL;
5548 // if (exp) exp_type = exp->get_type();
5549
5550 SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, NULL);
5551 // SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, exp_type);
5552 ROSE_ASSERT(result);
5553 if (exp)
5554 {
5555 exp->set_parent(result);
5556 markLhsValues(result);
5557 }
5559 return result;
5560 }
5561
5564 {
5565 // SgType* exp_type =NULL;
5566 // if (exp) exp_type = exp->get_type();
5567
5568 SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, NULL);
5569 // SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, exp_type);
5570 ROSE_ASSERT(result);
5571 if (exp)
5572 {
5573 exp->set_parent(result);
5574 markLhsValues(result);
5575 }
5577 return result;
5578 }
5579
5582 {
5583 SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,NULL);
5584 // SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,type);
5585 ROSE_ASSERT(result);
5587 return result;
5588 }
5589
5592 {
5593 SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,NULL);
5594 // SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,type);
5595 ROSE_ASSERT(result);
5597 return result;
5598 }
5599
5602 {
5603 // SgType* exp_type =NULL;
5604 // if (exp) exp_type = exp->get_type();
5605
5606 SgAlignOfOp* result = new SgAlignOfOp(exp,NULL, NULL);
5607 ROSE_ASSERT(result);
5608 if (exp)
5609 {
5610 exp->set_parent(result);
5611 markLhsValues(result);
5612 }
5614 return result;
5615 }
5616
5619 {
5620 // SgType* exp_type =NULL;
5621 // if (exp) exp_type = exp->get_type();
5622
5623 SgAlignOfOp* result = new SgAlignOfOp(exp,NULL, NULL);
5624 ROSE_ASSERT(result);
5625 if (exp)
5626 {
5627 exp->set_parent(result);
5628 markLhsValues(result);
5629 }
5631 return result;
5632 }
5633
5636 {
5637 // SgType* exp_type =NULL;
5638 // if (exp) exp_type = exp->get_type();
5639
5640 SgNoexceptOp* result = new SgNoexceptOp(exp);
5641 ROSE_ASSERT(result);
5642 if (exp)
5643 {
5644 exp->set_parent(result);
5645 markLhsValues(result);
5646 }
5647
5649 return result;
5650 }
5651
5654 {
5655 // SgType* exp_type =NULL;
5656 // if (exp) exp_type = exp->get_type();
5657
5658 SgNoexceptOp* result = new SgNoexceptOp(exp);
5659 ROSE_ASSERT(result);
5660 if (exp)
5661 {
5662 exp->set_parent(result);
5663 markLhsValues(result);
5664 }
5665
5667 return result;
5668 }
5669
5672 {
5673 SgAlignOfOp* result = new SgAlignOfOp((SgExpression*)NULL,type,NULL);
5674 ROSE_ASSERT(result);
5676 return result;
5677 }
5678
5681 {
5682 SgAlignOfOp* result = new SgAlignOfOp((SgExpression*)NULL,type,NULL);
5683 ROSE_ASSERT(result);
5685 return result;
5686 }
5687
5688
5690{
5691 SgExprListExp* expList = new SgExprListExp();
5692 ROSE_ASSERT(expList);
5693
5694// printf ("In SageBuilder::buildExprListExp(SgExpression * expr1, SgExpression* expr2, ...): SgExprListExp* expList = %p \n",expList);
5695
5697 if (expr1) appendExpression(expList, expr1);
5698 if (expr2) appendExpression(expList, expr2);
5699 if (expr3) appendExpression(expList, expr3);
5700 if (expr4) appendExpression(expList, expr4);
5701 if (expr5) appendExpression(expList, expr5);
5702 if (expr6) appendExpression(expList, expr6);
5703 if (expr7) appendExpression(expList, expr7);
5704 if (expr8) appendExpression(expList, expr8);
5705 if (expr9) appendExpression(expList, expr9);
5706 if (expr10) appendExpression(expList, expr10);
5707 return expList;
5708}
5709
5710// CH (5/11/2010): Seems that this function is useful.
5711SgExprListExp * SageBuilder::buildExprListExp(const std::vector<SgExpression*>& exprs)
5712{
5713 SgExprListExp* expList = new SgExprListExp();
5714 ROSE_ASSERT(expList);
5715
5717 for (size_t i = 0; i < exprs.size(); ++i) {
5718 appendExpression(expList, exprs[i]);
5719 }
5720 return expList;
5721}
5722
5724 {
5725 SgExprListExp* expList = new SgExprListExp();
5726 ROSE_ASSERT(expList);
5727
5728 setOneSourcePositionNull(expList);
5729 return expList;
5730 }
5731
5732SgExprListExp * SageBuilder::buildExprListExp_nfi(const std::vector<SgExpression*>& exprs)
5733 {
5734 SgExprListExp* expList = new SgExprListExp();
5735 ROSE_ASSERT(expList != NULL);
5736
5737 setOneSourcePositionNull(expList);
5738 for (size_t i = 0; i < exprs.size(); ++i)
5739 {
5740 appendExpression(expList, exprs[i]);
5741 }
5742
5743 // DQ (4/3/2012): Added test to make sure that the pointers are unique.
5744 testAstForUniqueNodes(expList);
5745
5746 return expList;
5747 }
5748
5751 {
5752 if (lower_bound == NULL)
5753 {
5755 }
5756 if (stride == NULL)
5757 {
5759 }
5760
5761 ROSE_ASSERT(lower_bound);
5762 ROSE_ASSERT(upper_bound);
5763 ROSE_ASSERT(stride);
5764
5765 SgSubscriptExpression* subscript = new SgSubscriptExpression(lower_bound, upper_bound, stride);
5766 ROSE_ASSERT(subscript);
5768
5769 // Set the parents of all the parts of the SgSubscriptExpression
5770 lower_bound->set_parent(subscript);
5771 upper_bound->set_parent(subscript);
5772 stride ->set_parent(subscript);
5773
5774 return subscript;
5775 }
5776
5779 {
5780 ROSE_ASSERT(initname);
5781 if (scope == NULL)
5783
5784 SgVarRefExp *varRef = NULL;
5785 // there is assertion for get_scope() != NULL in get_symbol_from_symbol_table()
5786 SgSymbol* symbol = NULL;
5787 if (initname->get_scope()!=NULL)
5788 symbol = initname->get_symbol_from_symbol_table ();
5789
5790 if (symbol != NULL)
5791 {
5792 varRef = new SgVarRefExp(isSgVariableSymbol(symbol));
5794 ROSE_ASSERT(varRef);
5795 }
5796 else
5797 {
5798 varRef = buildVarRefExp(initname->get_name(), scope);
5799 }
5800
5801 return varRef;
5802 }
5803
5806{
5807 SgName name(varName);
5808 return buildVarRefExp(name,scope);
5809}
5810
5812SageBuilder::buildVarRefExp(const std::string& varName, SgScopeStatement* scope)
5813{
5814 SgName name(varName);
5815 return buildVarRefExp(name,scope);
5816}
5817
5820 {
5821 if (scope == NULL)
5823
5824 SgSymbol* symbol = NULL;
5825 SgVariableSymbol* varSymbol = NULL;
5826
5827 if (scope != NULL)
5828 {
5829 // DQ (12/30/2011): This is a bad idea for C++ since qualified names might indicate different scopes.
5830 // If the scope has been provided then is should be the correct scope.
5831
5832 // DQ (8/16/2013): Modified to use the new API supporting template parameters and template arguments, however
5833 // this should more likely be using lookupVariableSymbolInParentScopes() instead of lookupSymbolInParentScopes().
5834 symbol = lookupVariableSymbolInParentScopes(name,scope);
5835 }
5836
5837 if (symbol != NULL)
5838 {
5839 varSymbol = isSgVariableSymbol(symbol);
5840 }
5841 else
5842 {
5843 // if not found: put fake init name and symbol here and
5844 // waiting for a postProcessing phase to clean it up
5845 // two features: no scope and unknown type for initializedName
5847 name1->set_scope(scope); // buildInitializedName() does not set scope for various reasons
5848 name1->set_parent(scope);
5849 varSymbol = new SgVariableSymbol(name1);
5850 varSymbol->set_parent(scope);
5851 }
5852
5853 if (varSymbol == NULL)
5854 {
5855 printf ("Error: varSymbol == NULL for name = %s \n",name.str());
5856 }
5857 ROSE_ASSERT(varSymbol != NULL);
5858
5859 SgVarRefExp *varRef = new SgVarRefExp(varSymbol);
5861 ROSE_ASSERT(varRef != NULL);
5862
5863 ROSE_ASSERT (isSgVariableSymbol(varRef->get_symbol())->get_declaration()!=NULL);
5864
5865 return varRef;
5866 }
5867
5871 {
5872 SgVariableSymbol* symbol = getFirstVarSym(vardecl);
5873 ROSE_ASSERT(symbol);
5874
5875 return buildVarRefExp(symbol);
5876 }
5877
5878
5881 {
5882 SgVarRefExp *varRef = new SgVarRefExp(sym);
5883 ROSE_ASSERT(varRef);
5884
5886
5887 return varRef;
5888 }
5889
5892 {
5893 SgVarRefExp *varRef = new SgVarRefExp(sym);
5894 ROSE_ASSERT(varRef);
5895
5897
5898 return varRef;
5899 }
5900
5903 {
5904 SgNonrealRefExp * refexp = new SgNonrealRefExp(sym);
5905 ROSE_ASSERT(refexp != NULL);
5907 return refexp;
5908 }
5909
5911
5914SageBuilder::buildOpaqueVarRefExp(const std::string& name,SgScopeStatement* scope/* =NULL */)
5915 {
5916 SgVarRefExp *result = NULL;
5917
5918 if (scope == NULL)
5920 ROSE_ASSERT(scope != NULL);
5921
5922 // DQ (8/16/2013): Modified to use the new API supporting template parameters and template arguments, however
5923 // this should more likely be using lookupVariableSymbolInParentScopes() instead of lookupSymbolInParentScopes().
5924 // SgSymbol * symbol = lookupSymbolInParentScopes(name,scope);
5925 SgSymbol * symbol = lookupVariableSymbolInParentScopes(name,scope);
5926
5927 if (symbol)
5928 {
5929 // Can be the same opaque var ref built before
5930 // cerr<<"Error: trying to build an opaque var ref when the variable is actual explicit!"<<endl;
5931 ROSE_ASSERT(isSgVariableSymbol(symbol));
5932 result = buildVarRefExp(isSgVariableSymbol(symbol));
5933 }
5934 else
5935 {
5936 SgVariableDeclaration* fakeVar = buildVariableDeclaration(name, buildIntType(),NULL, scope);
5937 Sg_File_Info* file_info = fakeVar->get_file_info();
5938
5939 // TGWE (7/16/2014): on the advice of DQ who doesn't like the function at all
5940 fakeVar->set_parent(scope);
5941
5942 file_info->unsetOutputInCodeGeneration ();
5943 SgVariableSymbol* fakeSymbol = getFirstVarSym (fakeVar);
5944 result = buildVarRefExp(fakeSymbol);
5945 }
5946
5947 return result;
5948 } // buildOpaqueVarRefExp()
5949
5950
5951// DQ (9/4/2013): Added support for building compound literals (similar to a SgVarRefExp).
5955 {
5956 SgCompoundLiteralExp *compoundLiteral = new SgCompoundLiteralExp(varSymbol);
5957 ROSE_ASSERT(compoundLiteral != NULL);
5958
5959 setOneSourcePositionNull(compoundLiteral);
5960
5961 return compoundLiteral;
5962 }
5963
5964// DQ (9/4/2013): Added support for building compound literals (similar to a SgVarRefExp).
5968 {
5969 SgCompoundLiteralExp *compoundLiteral = new SgCompoundLiteralExp(varSymbol);
5970 ROSE_ASSERT(compoundLiteral != NULL);
5971
5973
5974 return compoundLiteral;
5975 }
5976
5977
5980{
5981 SgLabelRefExp * result= NULL;
5982 ROSE_ASSERT (s!= NULL);
5983 result = new SgLabelRefExp(s);
5984 ROSE_ASSERT (result != NULL);
5986 return result;
5987}
5988
5991{
5993 if (paraTypeList==NULL) return paraList;
5994
5995 SgTypePtrList typeList = paraTypeList->get_arguments();
5996 SgTypePtrList::iterator i;
5997 for (i=typeList.begin();i!=typeList.end();i++)
5998 {
6000 appendArg(paraList,arg);
6001 }
6002
6003 return paraList;
6004}
6005
6008{
6010 ROSE_ASSERT (paraList);
6011 SgTypePtrList typeList = paraTypeList->get_arguments();
6012 SgTypePtrList::iterator i;
6013 for (i=typeList.begin();i!=typeList.end();i++)
6014 {
6016 appendArg(paraList,arg);
6017 }
6018 return paraList;
6019}
6020
6021// lookup function symbol to create a reference to it
6023SageBuilder::buildFunctionRefExp(const SgName& name,const SgType* funcType, SgScopeStatement* scope /*=NULL*/)
6024{
6025 ASSERT_not_null(funcType); // function type cannot be NULL
6026 SgFunctionType* func_type = isSgFunctionType(const_cast<SgType*>(funcType));
6027 ASSERT_not_null(func_type);
6028
6029 bool isMemberFunc = isSgMemberFunctionType(func_type);
6030
6031 if (scope == nullptr) {
6033 }
6034 ASSERT_not_null(scope);
6035 SgFunctionSymbol* symbol = lookupFunctionSymbolInParentScopes(name,func_type,scope);
6036 if (symbol == nullptr)
6037 // in rare cases when function calls are inserted before any prototypes exist
6038 {
6039 SgType* return_type = func_type->get_return_type();
6040 SgFunctionParameterTypeList * paraTypeList = func_type->get_argument_list();
6041 SgFunctionParameterList *parList = buildFunctionParameterList(paraTypeList);
6042
6043 SgGlobal* globalscope = getGlobalScope(scope);
6044
6045 ASSERT_require(isMemberFunc == false); // Liao, 11/21/2012. We assume only regular functions can go into this if-body so we can insert them into global scope by default
6046
6047 // TODO: consider C++ template functions
6048 SgFunctionDeclaration * funcDecl = nullptr;
6050 {
6051 funcDecl = buildNondefiningFunctionDeclaration_T
6052 <SgProcedureHeaderStatement>(name,return_type,parList,false,globalscope,nullptr,false,nullptr,nullptr,SgStorageModifier::e_default);
6053 }
6054 else
6055 {
6056 funcDecl = buildNondefiningFunctionDeclaration_T
6057 <SgFunctionDeclaration>(name,return_type,parList,false,globalscope,nullptr,false,nullptr,nullptr,SgStorageModifier::e_default);
6058 }
6059
6060 funcDecl->get_declarationModifier().get_storageModifier().setExtern();
6061
6062 symbol = lookupFunctionSymbolInParentScopes(name,func_type,scope);
6063 ASSERT_not_null(symbol);
6064 }
6065 SgFunctionRefExp* func_ref = new SgFunctionRefExp(symbol,func_type);
6067
6068 ASSERT_not_null(func_ref);
6069 return func_ref;
6070}
6071
6073SageBuilder::buildFunctionRefExp(const char* name,const SgType* funcType, SgScopeStatement* scope /*=NULL*/)
6074{
6075 SgName name2(name);
6076 return buildFunctionRefExp(name2,funcType,scope);
6077}
6078
6079// lookup function symbol to create a reference to it
6082{
6083 ROSE_ASSERT(func_decl != NULL);
6084 SgDeclarationStatement* nondef_func = func_decl->get_firstNondefiningDeclaration ();
6085 SgDeclarationStatement* def_func = func_decl->get_definingDeclaration ();
6086 SgSymbol* symbol = NULL;
6087 if (nondef_func != NULL)
6088 {
6089 ROSE_ASSERT(nondef_func!= NULL);
6090 symbol = nondef_func->get_symbol_from_symbol_table();
6091 ROSE_ASSERT( symbol != NULL);
6092 }
6093 // Liao 12/1/2010. It is possible that there is no prototype declarations at all
6094 else if (def_func != NULL)
6095 {
6096 symbol = def_func->get_symbol_from_symbol_table();
6097 }
6098 else
6099 {
6100 std::cerr<<"Fatal error: SageBuilder::buildFunctionRefExp():defining and nondefining declarations for a function cannot be both NULL"<<std::endl;
6101 ROSE_ABORT ();
6102 }
6103 ROSE_ASSERT( symbol != NULL);
6104 return buildFunctionRefExp( isSgFunctionSymbol (symbol));
6105}
6106
6107
6108// lookup function symbol to create a reference to it
6111{
6112 SgFunctionRefExp* func_ref = new SgFunctionRefExp(sym, NULL);
6114 ROSE_ASSERT(func_ref);
6115 return func_ref;
6116}
6117
6118// lookup function symbol to create a reference to it
6121{
6122 SgFunctionRefExp* func_ref = new SgFunctionRefExp(sym, NULL);
6123 setOneSourcePositionNull(func_ref);
6124 ROSE_ASSERT(func_ref);
6125 return func_ref;
6126}
6127
6128// DQ (12/15/2011): Adding template declaration support to the AST.
6131 {
6132 ROSE_ASSERT(sym != NULL);
6133
6135 ROSE_ASSERT(func_ref != NULL);
6136
6137 setOneSourcePositionNull(func_ref);
6138 ROSE_ASSERT(func_ref->get_symbol() != NULL);
6139
6140 return func_ref;
6141 }
6142
6143// DQ (12/29/2011): Adding template declaration support to the AST.
6146 {
6147 SgTemplateMemberFunctionRefExp* func_ref = new SgTemplateMemberFunctionRefExp(sym, virtual_call, need_qualifier);
6148 setOneSourcePositionNull(func_ref);
6149 ROSE_ASSERT(func_ref);
6150 return func_ref;
6151 }
6152
6153// lookup member function symbol to create a reference to it
6155SageBuilder::buildMemberFunctionRefExp_nfi(SgMemberFunctionSymbol* sym, bool virtual_call, bool need_qualifier)
6156{
6157 SgMemberFunctionRefExp* func_ref = new SgMemberFunctionRefExp(sym, virtual_call, NULL, need_qualifier);
6158 setOneSourcePositionNull(func_ref);
6159 ROSE_ASSERT(func_ref);
6160 return func_ref;
6161}
6162
6163// lookup member function symbol to create a reference to it
6165SageBuilder::buildMemberFunctionRefExp(SgMemberFunctionSymbol* sym, bool virtual_call, bool need_qualifier)
6166{
6167 SgMemberFunctionRefExp* func_ref = new SgMemberFunctionRefExp(sym, virtual_call, NULL, need_qualifier);
6169 ROSE_ASSERT(func_ref);
6170 return func_ref;
6171}
6172
6173// lookup class symbol to create a reference to it
6176{
6177 SgClassNameRefExp* class_ref = new SgClassNameRefExp(sym);
6178 setOneSourcePositionNull(class_ref);
6179 ROSE_ASSERT(class_ref);
6180 return class_ref;
6181}
6182
6185{
6186 SgClassNameRefExp* class_ref = new SgClassNameRefExp(sym);
6188 ROSE_ASSERT(class_ref);
6189 return class_ref;
6190}
6191
6195{
6196 if (scope == NULL)
6198 ROSE_ASSERT(scope != NULL);
6200
6201 if (symbol==NULL)
6202// in rare cases when function calls are inserted before any prototypes exist
6203 {
6204// assume int return type, and empty parameter list
6205
6206#if 1
6207// DQ (7/26/2012): I am at least temporarily removing this function from the API.
6208// Later if we need it, we can update it to reflect that passing of the new
6209// SgTemplateArgumentPtrList function parameter (part of the new API design).
6210
6211 SgFunctionDeclaration* funcDecl = NULL;
6212 printf ("Error: buildFunctionRefExp(): This function should not be used! \n");
6213 ROSE_ABORT();
6214#else
6215 SgType* return_type = buildIntType();
6217
6218 SgGlobal* globalscope = getGlobalScope(scope);
6219
6220 SgFunctionDeclaration * funcDecl = buildNondefiningFunctionDeclaration(name,return_type,parList,globalscope);
6221#endif
6222
6223 funcDecl->get_declarationModifier().get_storageModifier().setExtern();
6224
6225 symbol = lookupFunctionSymbolInParentScopes(name,scope);
6226 ROSE_ASSERT(symbol);
6227 }
6228
6229 SgFunctionRefExp* func_ref = buildFunctionRefExp(symbol);
6231
6232 ROSE_ASSERT(func_ref);
6233 return func_ref;
6234}
6235
6237SageBuilder::buildFunctionRefExp(const char* name, SgScopeStatement* scope /*=NULL*/)
6238{
6239 SgName name2(name);
6240 return buildFunctionRefExp(name2,scope);
6241}
6242
6243
6246{
6247 SgExprStatement* expStmt = new SgExprStatement(exp);
6248 ROSE_ASSERT(expStmt);
6249 if (exp) exp->set_parent(expStmt);
6251 return expStmt;
6252}
6253
6256{
6257 SgExprStatement* expStmt = new SgExprStatement(exp);
6258 ROSE_ASSERT(expStmt);
6259 if (exp) exp->set_parent(expStmt);
6260 setOneSourcePositionNull(expStmt);
6261 return expStmt;
6262}
6263
6264// DQ (3/27/2015): Added support for SgStatementExpression.
6267{
6268 SgStatementExpression* expStmt = new SgStatementExpression(exp);
6269 ROSE_ASSERT(expStmt);
6270 if (exp) exp->set_parent(expStmt);
6272
6273 return expStmt;
6274}
6275
6276// DQ (3/27/2015): Added support for SgStatementExpression.
6279{
6280 SgStatementExpression* expStmt = new SgStatementExpression(exp);
6281 ROSE_ASSERT(expStmt);
6282 if (exp) exp->set_parent(expStmt);
6283 setOneSourcePositionNull(expStmt);
6284
6285 return expStmt;
6286}
6287
6289SageBuilder::buildFunctionCallExp(const SgName& name, SgType* return_type, SgExprListExp* parameters/*=NULL*/, SgScopeStatement* scope/*=NULL*/)
6290 {
6291 if (scope == nullptr) {
6293 }
6294 ASSERT_not_null(scope);
6295
6296 if (parameters == nullptr) {
6297 parameters = buildExprListExp();
6298 }
6299
6301 SgFunctionType * func_type = buildFunctionType(return_type,typeList);
6302 SgFunctionRefExp* func_ref = buildFunctionRefExp(name,func_type,scope);
6303 SgFunctionCallExp * func_call_expr = new SgFunctionCallExp(func_ref,parameters,func_ref->get_type());
6304 parameters->set_parent(func_call_expr);
6305
6307 ASSERT_not_null(func_call_expr);
6308
6309 return func_call_expr;
6310 }
6311
6312
6315 SgExprListExp* parameters/*=NULL*/)
6316 {
6317 ROSE_ASSERT (sym != NULL);
6318 if (parameters == NULL)
6319 parameters = buildExprListExp();
6320 ROSE_ASSERT (parameters != NULL);
6321
6322 // DQ (8/21/2011): We want to preserve the support for member functions to be built as SgMemberFunctionRefExp.
6323 // This is important for the Java support and the C++ support else we will be lowering all mmember function calls
6324 // to function calls which will be a proble for eht analysis of object oriented languages.
6325 SgFunctionCallExp * func_call_expr = NULL;
6326 SgMemberFunctionSymbol* memberFunctionSymbol = isSgMemberFunctionSymbol(sym);
6327 if (memberFunctionSymbol != NULL)
6328 {
6329 // Note that we can't at this point be sure this is not a virtual function.
6330 bool virtual_call = false;
6331
6332 // Name qualificaiton is handled separately from the setting of this variable (old API).
6333 bool need_qualifier = false;
6334
6335 SgMemberFunctionRefExp* member_func_ref = buildMemberFunctionRefExp(memberFunctionSymbol,virtual_call,need_qualifier);
6336 func_call_expr = new SgFunctionCallExp(member_func_ref,parameters,member_func_ref->get_type());
6337 member_func_ref->set_parent(func_call_expr);
6338 }
6339 else
6340 {
6341 SgFunctionRefExp * func_ref = buildFunctionRefExp(sym);
6342 func_call_expr = new SgFunctionCallExp(func_ref,parameters,func_ref->get_type());
6343 func_ref->set_parent(func_call_expr);
6344 }
6345
6346
6347 parameters->set_parent(func_call_expr);
6348
6350
6351 ROSE_ASSERT(func_call_expr);
6352 return func_call_expr;
6353 }
6354
6357 {
6358 ROSE_ASSERT(f != NULL);
6359 SgFunctionCallExp* func_call_expr = new SgFunctionCallExp(f,parameters,f->get_type());
6360 ROSE_ASSERT(func_call_expr != NULL);
6361
6362 if (f != NULL) {
6363 f->set_parent(func_call_expr);
6364 }
6365 if (parameters != NULL) {
6366 parameters->set_parent(func_call_expr);
6367 }
6368 setOneSourcePositionNull(func_call_expr);
6369
6370 return func_call_expr;
6371 }
6372
6375 {
6376 ROSE_ASSERT(f != NULL);
6377 SgFunctionCallExp * func_call_expr = new SgFunctionCallExp(f,parameters,f->get_type());
6378 ROSE_ASSERT(func_call_expr != NULL);
6379
6380 if (f) f->set_parent(func_call_expr);
6381 if (parameters) parameters->set_parent(func_call_expr);
6383
6384 return func_call_expr;
6385 }
6386
6389 SgType* return_type,
6390 SgExprListExp* parameters /*= NULL*/,
6391 SgScopeStatement* scope /*=NULL*/)
6392{
6393 if (scope == NULL)
6395 ROSE_ASSERT(scope != NULL);
6396 SgFunctionCallExp* func_call_expr = buildFunctionCallExp(name,return_type,parameters,scope);
6397 SgExprStatement * expStmt = buildExprStatement(func_call_expr);
6398 return expStmt;
6399}
6400
6404{
6405 SgFunctionCallExp* func_call_expr = buildFunctionCallExp(function_exp, parameters);
6406 SgExprStatement * expStmt = buildExprStatement(func_call_expr);
6407 return expStmt;
6408}
6409
6410
6412
6420 SgExpression* objectExpression,
6421 std::string functionName,
6422 SgExprListExp* params,
6423 SgScopeStatement* scope
6424 )
6425{
6426 SgClassSymbol* classSymbol = SageInterface::lookupClassSymbolInParentScopes(className, scope);
6427 ROSE_ASSERT(classSymbol);
6428
6429 SgDeclarationStatement* classDecl = classSymbol->get_declaration()->get_definingDeclaration();
6430 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classDecl);
6431 ROSE_ASSERT(classDeclaration != NULL);
6432
6433 SgClassDefinition* classDefinition = classDeclaration->get_definition();
6434 ROSE_ASSERT(classDefinition);
6435
6436 SgSymbol* funsy = lookupFunctionSymbolInParentScopes(functionName, classDefinition);
6437 SgMemberFunctionSymbol* functionSymbol = isSgMemberFunctionSymbol(funsy);
6438 ROSE_ASSERT(functionSymbol);
6439
6440 SgMemberFunctionRefExp* memref = buildMemberFunctionRefExp(functionSymbol, false, false);
6441
6442 return buildFunctionCallExp(buildDotExp(objectExpression, memref), params);
6443}
6444
6445// with known varRef and mem function symbol : a.size()
6447 SgExprListExp* params)
6448{
6449 SgMemberFunctionRefExp* memref = SageBuilder::buildMemberFunctionRefExp(functionSymbol, false, false);
6450 return SageBuilder::buildFunctionCallExp(SageBuilder::buildDotExp(objectExpression, memref), params);
6451}
6452
6454SageBuilder::buildTypeTraitBuiltinOperator(SgName functionName, SgNodePtrList parameters)
6455 {
6456 // DQ (7/14/2013): This is supporting compiler extensions that are required to support type traits in C++.
6457 // These operators are used increasingly in newer versions of GNU and other compilers. They are builtin
6458 // compiler extensions that typically take types as arguments.
6459
6460 SgTypeTraitBuiltinOperator * builtin_func_call_expr = new SgTypeTraitBuiltinOperator(functionName);
6461 ROSE_ASSERT(builtin_func_call_expr != NULL);
6462
6463 SgNodePtrList & args = builtin_func_call_expr->get_args();
6464 for (SgNodePtrList::iterator it = parameters.begin(); it != parameters.end(); ++it) {
6465 args.push_back(*it);
6466 (*it)->set_parent(builtin_func_call_expr);
6467 }
6468
6469 return builtin_func_call_expr;
6470 }
6471
6472
6475 {
6476 ROSE_ASSERT(kernel);
6477 ROSE_ASSERT(parameters);
6478 ROSE_ASSERT(config);
6479
6480 // DQ (1/19/2016): Adding template function ref support.
6481 SgFunctionRefExp * func_ref_exp = isSgFunctionRefExp(kernel);
6482 SgTemplateFunctionRefExp * template_func_ref_exp = isSgTemplateFunctionRefExp(kernel);
6483 if (func_ref_exp == NULL && template_func_ref_exp == NULL)
6484 {
6485 std::cerr << "SgCudaKernelCallExp accept only direct reference to a function. Got, " << typeid(*kernel).name()
6486 << " with, " << kernel->unparseToString() << std::endl;
6487
6488 // PP (7/1/19): experimental support for RAJA/CUDA Lulesh codes (producing SgNonrealRefExp) **1
6489 // was: ROSE_ASSERT(false);
6490 }
6491 // DQ (1/19/2016): Adding template function ref support.
6492 else if ( (func_ref_exp != NULL && func_ref_exp->get_symbol_i()->get_declaration()->get_functionModifier().isCudaKernel() == false) &&
6493 (template_func_ref_exp != NULL && template_func_ref_exp->get_symbol_i()->get_declaration()->get_functionModifier().isCudaKernel() == false) )
6494 {
6495 std::cerr << "To build a SgCudaKernelCallExp the callee needs to be a kernel (having \"__global__\" attribute)." << std::endl;
6496 ROSE_ABORT();
6497 }
6498
6499 SgCudaKernelCallExp * kernel_call_expr = new SgCudaKernelCallExp(kernel, parameters, kernel->get_type(), config);
6500
6501 kernel->set_parent(kernel_call_expr);
6502 parameters->set_parent(kernel_call_expr);
6503 config->set_parent(kernel_call_expr);
6504
6505 setOneSourcePositionNull(kernel_call_expr);
6506
6507 ROSE_ASSERT(kernel_call_expr);
6508
6509 return kernel_call_expr;
6510 }
6511
6514 if (!grid || !blocks) {
6515 std::cerr << "SgCudaKernelExecConfig need fields 'grid' and 'blocks' to be set." << std::endl;
6516 ROSE_ABORT();
6517 }
6518
6519 // TODO-CUDA check types
6520
6521 SgCudaKernelExecConfig * config = new SgCudaKernelExecConfig (grid, blocks, shared, stream);
6522
6523 grid->set_parent(config);
6524 blocks->set_parent(config);
6525 if (shared)
6526 shared->set_parent(config);
6527 if (stream)
6528 stream->set_parent(config);
6529
6531
6532 ROSE_ASSERT(config);
6533
6534 return config;
6535}
6536
6539//SageBuilder::buildAssignStatement(SgExpression* lhs,SgExpression* rhs, SgScopeStatement* scope=NULL)
6540{
6541 ROSE_ASSERT(lhs != NULL);
6542 ROSE_ASSERT(rhs != NULL);
6543
6544 //SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,lhs->get_type());
6545// SgBinaryOp::get_type() assume p_expression_type is not set
6546 SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,NULL);
6547 ROSE_ASSERT(assignOp);
6549 lhs->set_parent(assignOp);
6550 rhs->set_parent(assignOp);
6551
6552 lhs->set_lvalue (true);
6553 SgExprStatement* exp = new SgExprStatement(assignOp);
6554 ROSE_ASSERT(exp);
6555 // some child nodes are transparently generated, using recursive setting is safer
6557 //setOneSourcePositionForTransformation(exp);
6558 assignOp->set_parent(exp);
6559 return exp;
6560}
6561
6562// DQ (8/16/2011): This is an AST translate specific version (see note below).
6563// We would like to phase out the version above if possible (but we want to
6564// test this later).
6567{
6568 ROSE_ASSERT(lhs != NULL);
6569 ROSE_ASSERT(rhs != NULL);
6570
6571 //SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,lhs->get_type());
6572// SgBinaryOp::get_type() assume p_expression_type is not set
6573 SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,NULL);
6574 ROSE_ASSERT(assignOp);
6576 lhs->set_parent(assignOp);
6577 rhs->set_parent(assignOp);
6578
6579 lhs->set_lvalue (true);
6580 SgExprStatement* exp = new SgExprStatement(assignOp);
6581 ROSE_ASSERT(exp);
6582
6583// DQ (8/16/2011): Modified to avoid recursive call to reset source position information
6584// (this version is required for the Java support where we have set source code position
6585// information on the lhs and rhs and we don't want it to be reset as a transformation.
6586// some child nodes are transparently generated, using recursive setting is safer
6588 assignOp->set_parent(exp);
6589 return exp;
6590}
6591
6592
6594{
6595 if (scope == NULL)
6597
6598 // should including current scope when searching for the function definition
6599 // since users can only pass FunctionDefinition when the function body is not yet attached
6600 SgLabelStatement * labelstmt = new SgLabelStatement(name,stmt);
6601 ROSE_ASSERT(labelstmt);
6603
6604 if(stmt!=NULL)
6605 stmt->set_parent(labelstmt);
6606
6607 // Liao 1/7/2010
6608 // SgLabelStatement is used for CONTINUE statement in Fortran
6609 // In this case , it has no inherent association with a Label symbol.
6610 // It is up to the SageInterface::setNumericalLabel(SgStatement*) to handle label symbol
6612 fixLabelStatement(labelstmt,scope);
6613 // we don't want to set parent here yet
6614 // delay it until append_statement() or alike
6615 return labelstmt;
6616}
6617
6619{
6620 SgLabelStatement* labelStmt = new SgLabelStatement(name,stmt);
6621 ASSERT_not_null(labelStmt);
6623
6624 if (stmt != nullptr) {
6625 stmt->set_parent(labelStmt);
6626 }
6627 if (scope) {
6628 fixLabelStatement(labelStmt,scope);
6629 }
6630
6631 // we don't want to set parent here yet
6632 // delay it until append_statement() or alike
6633 return labelStmt;
6634}
6635
6636SgIfStmt * SageBuilder::buildIfStmt(SgStatement* conditional, SgStatement * true_body, SgStatement * false_body)
6637{
6638 ROSE_ASSERT(conditional);
6639 ROSE_ASSERT(true_body);
6640 SgIfStmt *ifstmt = new SgIfStmt(conditional, true_body, false_body);
6641 ROSE_ASSERT(ifstmt);
6642
6643 // CR (3/22/2020): Fixed setting case insensitivity
6644 // if (symbol_table_case_insensitive_semantics == true)
6646 ifstmt->setCaseInsensitive(true);
6647
6649 conditional->set_parent(ifstmt);
6650 true_body->set_parent(ifstmt);
6651 if (false_body != NULL) false_body->set_parent(ifstmt);
6652
6654 {
6655 // Liao 1/20/2010
6656 // According to Fortran 77 standard Chapter 11.5 to 11.9,
6657 // this is a Fortran Block IF statement, if the true body is:
6658 // 1. A block of statement under SgBasicBlock
6659 // 2. DO, block if, or another logical if
6660 // Otherwise it is a logical if statement
6661 if (isSgBasicBlock(true_body)|| isSgFortranDo(true_body)|| isSgIfStmt(true_body))
6662 {
6663 ifstmt->set_use_then_keyword(true);
6664 ifstmt->set_has_end_statement(true);
6665 }
6666 }
6667
6668 return ifstmt;
6669}
6670
6672 {
6673 SgIfStmt *ifstmt = new SgIfStmt(conditional, true_body, false_body);
6674 ROSE_ASSERT(ifstmt);
6675 // DQ (2/13/2012): This allows us to separate the construction from the initialization (see note below).
6676 initializeIfStmt(ifstmt,conditional,true_body,false_body);
6677 return ifstmt;
6678 }
6679
6680// Rasmussen (9/3/2018): Added build function for a Fortran do construct
6682{
6683 if (initialization == nullptr) initialization = buildNullExpression();
6684 if (bound == nullptr) bound = buildNullExpression();
6685 if (increment == nullptr) increment = buildNullExpression();
6686 if (loopBody == nullptr) loopBody = buildBasicBlock();
6687
6688 SgFortranDo* result = new SgFortranDo(initialization, bound, increment, loopBody);
6689 ASSERT_not_null(result);
6690
6692 result->setCaseInsensitive(true);
6693 }
6694
6696
6697 initialization->set_parent(result);
6698 bound->set_parent(result);
6699 increment->set_parent(result);
6700 loopBody->set_parent(result);
6701
6702 return result;
6703}
6704
6706{
6707 if (initialization == nullptr) initialization = buildNullExpression_nfi();
6708 if (bound == nullptr) bound = buildNullExpression_nfi();
6709 if (increment == nullptr) increment = buildNullExpression_nfi();
6710 if (loopBody == nullptr) loopBody = buildBasicBlock_nfi();
6711
6712 SgFortranDo* result = new SgFortranDo(initialization, bound, increment, loopBody);
6713 ASSERT_not_null(result);
6714
6716 result->setCaseInsensitive(true);
6717 }
6718
6720
6721 initialization->set_parent(result);
6722 bound->set_parent(result);
6723 increment->set_parent(result);
6724 loopBody->set_parent(result);
6725
6726 return result;
6727}
6728
6729// charles4 10/14/2011: Vanilla allocation. Use prepend_init_stmt and append_init_stmt to populate afterward.
6731 {
6732 // return new SgForInitStatement();
6733 SgForInitStatement* result = new SgForInitStatement();
6734
6735 // DQ (11/3/2012): Added call to set file info to default settings.
6736 setSourcePosition(result);
6737
6738 return result;
6739 }
6740
6741// DQ (10/12/2012): Added specific API to handle simple (single) statement.
6744 {
6745 SgForInitStatement* forInit = new SgForInitStatement();
6746 ROSE_ASSERT(forInit != NULL);
6747
6748 ROSE_ASSERT(statement != NULL);
6749 forInit->append_init_stmt(statement);
6750
6751 // DQ (11/3/2012): Added call to set file info to default settings.
6752 setSourcePosition(forInit);
6753
6754 return forInit;
6755 }
6756
6757SgForInitStatement * SageBuilder::buildForInitStatement(const SgStatementPtrList & statements)
6758{
6759 SgForInitStatement * result = new SgForInitStatement();
6760 result->get_init_stmt() = statements;
6761
6762 for (SgStatementPtrList::iterator it = result->get_init_stmt().begin(); it != result->get_init_stmt().end(); it++)
6763 (*it)->set_parent(result);
6764
6766 return result;
6767}
6768
6770SageBuilder::buildForInitStatement_nfi(SgStatementPtrList & statements)
6771 {
6772 SgForInitStatement * result = new SgForInitStatement();
6773
6774 result->get_init_stmt() = statements;
6775
6776 for (SgStatementPtrList::iterator it = result->get_init_stmt().begin(); it != result->get_init_stmt().end(); it++)
6777 {
6778 (*it)->set_parent(result);
6779 }
6780
6781 // DQ (11/3/2012): Added call to set file info to default settings.
6782 setSourcePosition(result);
6783
6784 return result;
6785 }
6786
6788//Liao, 8/27/2008
6789SgForStatement * SageBuilder::buildForStatement(SgStatement* initialize_stmt, SgStatement * test, SgExpression * increment, SgStatement * loop_body, SgStatement * else_body)
6790{
6791 SgForStatement * result = new SgForStatement(test,increment, loop_body);
6792 ROSE_ASSERT(result);
6793
6795 result->setCaseInsensitive(true);
6796
6798 if (test)
6799 test->set_parent(result);
6800 if (loop_body)
6801 loop_body->set_parent(result);
6802 if (increment)
6803 increment->set_parent(result);
6804
6805 if (else_body)
6806 else_body->set_parent(result);
6807 result->set_else_body(else_body);
6808
6809 // CH (5/13/2010): If the initialize_stmt is an object of SgForInitStatement, we can directly put it
6810 // into for statement. Or else, there will be two semicolons after unparsing.
6811 if (SgForInitStatement* for_init_stmt = isSgForInitStatement(initialize_stmt))
6812 {
6813 // DQ (7/30/2011): We have to delete the the SgForInitStatement build within the SgForStatement::post_constructor_initialization()
6814 // to avoid causing errors in the AST consistancy checking later.
6815 if (result->get_for_init_stmt() != NULL)
6816 {
6817 delete result->get_for_init_stmt();
6818 result->set_for_init_stmt(NULL);
6819 }
6820
6821 result->set_for_init_stmt(for_init_stmt);
6822 for_init_stmt->set_parent(result);
6823 return result;
6824 }
6825
6826 SgForInitStatement* init_stmt = new SgForInitStatement();
6827 ROSE_ASSERT(init_stmt);
6829
6830 // DQ (7/30/2011): We have to delete the the SgForInitStatement build within the SgForStatement::post_constructor_initialization().
6831 // to avoid causeing errors in the AST consistancy checking later.
6832 if (result->get_for_init_stmt() != NULL)
6833 {
6834 delete result->get_for_init_stmt();
6835 result->set_for_init_stmt(NULL);
6836 }
6837
6838 result->set_for_init_stmt(init_stmt);
6839 init_stmt->set_parent(result);
6840
6841 if (initialize_stmt)
6842 {
6843 init_stmt->append_init_stmt(initialize_stmt);
6844 // Support for "for (int i=0; )", Liao, 3/11/2009
6845 // The symbols are inserted into the symbol table attached to SgForStatement
6846 if (isSgVariableDeclaration(initialize_stmt))
6847 {
6848 fixVariableDeclaration(isSgVariableDeclaration(initialize_stmt),result);
6849 // fix varRefExp to the index variable used in increment, conditional expressions
6850 fixVariableReferences(result);
6851 }
6852 }
6853
6854 return result;
6855 }
6856
6857
6859//Liao, 8/27/2008
6861SageBuilder::buildForStatement_nfi(SgStatement* initialize_stmt, SgStatement * test, SgExpression * increment, SgStatement * loop_body, SgStatement * else_body)
6862 {
6863 SgForStatement * result = new SgForStatement(test, increment, loop_body);
6864 ROSE_ASSERT(result);
6865
6866 // Rasmussen (3/22/2020): Fixed setting case insensitivity
6867 // if (symbol_table_case_insensitive_semantics == true)
6869 result->setCaseInsensitive(true);
6870
6872 if (test) test->set_parent(result);
6873 if (loop_body) loop_body->set_parent(result);
6874 if (increment) increment->set_parent(result);
6875 if (else_body) else_body->set_parent(result);
6876
6877 result->set_else_body(else_body);
6878
6879 if (initialize_stmt != NULL)
6880 {
6881 SgForInitStatement* init_stmt = result->get_for_init_stmt();
6882 ROSE_ASSERT(init_stmt);
6883 setOneSourcePositionNull(init_stmt);
6884 init_stmt->append_init_stmt(initialize_stmt);
6885 initialize_stmt->set_parent(init_stmt);
6886 }
6887
6888 return result;
6889 }
6890
6891
6894 {
6895 SgForStatement * result = new SgForStatement(init_stmt, test, increment, loop_body);
6896 ROSE_ASSERT(result != NULL);
6897
6898 // DQ (9/26/2012): Refactored this function to allow for where the SgForStatement had to be
6899 // constructed early to define the scope for types that can be defined in the SgForInitStatement.
6900 buildForStatement_nfi(result,init_stmt,test,increment,loop_body,else_body);
6901
6902 return result;
6903 }
6904
6905
6906void
6908 {
6909 // DQ (9/26/2012): Refactored this function to allow for where the SgForStatement had to be
6910 // constructed early to define the scope for types that can be defined in the SgForInitStatement.
6911
6912 ROSE_ASSERT(result != NULL);
6913
6914 // DQ (11/4/2012): I have added support for remove existing subtrees if they are different from what is provided as input.
6915 if (result->get_for_init_stmt() != NULL && init_stmt != result->get_for_init_stmt())
6916 {
6917 delete result->get_for_init_stmt();
6918 result->set_for_init_stmt(NULL);
6919 }
6920
6921 if (result->get_test() != NULL && test != result->get_test())
6922 {
6923 delete result->get_test();
6924 result->set_test(NULL);
6925 }
6926
6927 if (result->get_increment() != NULL && increment != result->get_increment())
6928 {
6929 delete result->get_increment();
6930 result->set_increment(NULL);
6931 }
6932
6933 if (result->get_loop_body() != NULL && loop_body != result->get_loop_body())
6934 {
6935 delete result->get_loop_body();
6936 result->set_loop_body(NULL);
6937 }
6938
6939 if (result->get_else_body() != NULL && else_body != result->get_else_body())
6940 {
6941 delete result->get_else_body();
6942 result->set_else_body(NULL);
6943 }
6944
6945 result->set_for_init_stmt(init_stmt);
6946 result->set_test(test);
6947 result->set_increment(increment);
6948 result->set_loop_body(loop_body);
6949
6951 result->setCaseInsensitive(true);
6952
6954 if (test) test->set_parent(result);
6955 if (loop_body) loop_body->set_parent(result);
6956 if (increment) increment->set_parent(result);
6957 if (init_stmt) init_stmt->set_parent(result);
6958 if (else_body) else_body->set_parent(result);
6959
6960 result->set_else_body(else_body);
6961
6962 ROSE_ASSERT(result->get_for_init_stmt() != NULL);
6963 ROSE_ASSERT(result->get_test() != NULL);
6964 ROSE_ASSERT(result->get_increment() != NULL);
6965 ROSE_ASSERT(result->get_loop_body() != NULL);
6966 }
6967
6968
6969// DQ (3/26/2018): Adding support for range based for statement.
6970// SgRangeBasedForStatement* SageBuilder::buildRangeBasedForStatement_nfi(SgVariableDeclaration* initializer, SgExpression* range, SgStatement* body)
6973 SgVariableDeclaration* initializer, SgVariableDeclaration* range,
6974 SgVariableDeclaration* begin_declaration, SgVariableDeclaration* end_declaration,
6975 SgExpression* not_equal_expression, SgExpression* increment_expression,
6976 SgStatement* body)
6977 {
6978 // DQ (6/26/2019): Commented these out so that we could build the SgRangeBasedForStatement before
6979 // building the children, since the scope of the chldren will be the SgRangeBasedForStatement and
6980 // it must exist before the children are constructed.
6981 // ROSE_ASSERT(initializer != NULL);
6982 // ROSE_ASSERT(range != NULL);
6983
6984 // DQ (6/26/2019): This was already commented out.
6985 // ROSE_ASSERT(body != NULL);
6986
6987 SgRangeBasedForStatement* result = new SgRangeBasedForStatement(initializer, range, begin_declaration, end_declaration, not_equal_expression, increment_expression, body);
6988 ROSE_ASSERT(result != NULL);
6989
6991
6992 if (initializer != NULL) initializer->set_parent(result);
6993 if (range != NULL) range->set_parent(result);
6994
6995 if (begin_declaration != NULL) begin_declaration->set_parent(result);
6996 if (end_declaration != NULL) end_declaration->set_parent(result);
6997
6998 if (not_equal_expression != NULL) not_equal_expression->set_parent(result);
6999 if (increment_expression != NULL) increment_expression->set_parent(result);
7000
7001 if (body != NULL) body->set_parent(result);
7002
7003 return result;
7004 }
7005
7006
7007void
7009 {
7010 // DQ (3/22/2014): This function has been built to support reusing an existing SgDoWhileStatement
7011 // that may have been built and pushed onto the stack as part of a top-down construction of the AST.
7012 // It is required in the EDG 4.8 useage because of a change from EDG 4.7 to 4.8 in how blocks are
7013 // handled (end-of-construct entries).
7014
7015 ASSERT_not_null(result);
7016 ASSERT_not_null(body);
7017 ASSERT_not_null(condition);
7018
7019 ASSERT_require(result->get_body() == nullptr);
7020 ASSERT_require(result->get_condition() == nullptr);
7021
7022 result->set_body(body);
7023 result->set_condition(condition);
7024
7025 body->set_parent(result);
7026 condition->set_parent(result);
7027
7029
7030 ASSERT_not_null(result->get_body());
7031 ASSERT_not_null(result->get_condition());
7032
7033 ASSERT_require(result->get_body()->get_parent() == result);
7034 ASSERT_require(result->get_condition()->get_parent() == result);
7035 }
7036
7037
7038
7040//Liao, 8/27/2008
7042{
7043 SgUpcForAllStatement * result = new SgUpcForAllStatement(test,increment, affinity, loop_body);
7044 ROSE_ASSERT(result);
7046 if (test) test->set_parent(result);
7047 if (loop_body) loop_body->set_parent(result);
7048 if (increment) increment->set_parent(result);
7049 if (affinity) affinity->set_parent(result);
7050
7051 if (initialize_stmt != NULL) {
7052 SgForInitStatement* init_stmt = result->get_for_init_stmt();
7053 ROSE_ASSERT(init_stmt);
7054 setOneSourcePositionNull(init_stmt);
7055 init_stmt->append_init_stmt(initialize_stmt);
7056 initialize_stmt->set_parent(init_stmt);
7057 }
7058
7059 return result;
7060}
7061
7062
7064{
7065 SgUpcForAllStatement * result = new SgUpcForAllStatement(init_stmt, test, increment, affinity, loop_body);
7066 ROSE_ASSERT(result);
7067
7068 // CR (3/22/2020): Fixed setting case insensitivity
7069 // if (symbol_table_case_insensitive_semantics == true)
7071 result->setCaseInsensitive(true);
7072
7074 if (test) test->set_parent(result);
7075 if (loop_body) loop_body->set_parent(result);
7076 if (increment) increment->set_parent(result);
7077 if (affinity) affinity->set_parent(result);
7078 if (init_stmt) init_stmt->set_parent(result);
7079
7080 return result;
7081}
7082
7083// DQ (3/3/2013): Added UPC specific build functions.
7086 {
7087 SgUpcNotifyStatement* result = new SgUpcNotifyStatement(exp);
7088
7090
7091 exp->set_parent(result);
7092
7093 ROSE_ASSERT(exp->get_parent() != NULL);
7094
7095 return result;
7096 }
7097
7100 {
7101 SgUpcWaitStatement* result = new SgUpcWaitStatement(exp);
7102
7104
7105 exp->set_parent(result);
7106
7107 ROSE_ASSERT(exp->get_parent() != NULL);
7108
7109 return result;
7110 }
7111
7114 {
7116
7118
7119 exp->set_parent(result);
7120
7121 ROSE_ASSERT(exp->get_parent() != NULL);
7122
7123 return result;
7124 }
7125
7128 {
7130
7132
7133 return result;
7134 }
7135
7136
7137
7138
7140{
7141 ROSE_ASSERT(condition);
7142 ROSE_ASSERT(body);
7143 SgWhileStmt * result = new SgWhileStmt(condition,body);
7144 ROSE_ASSERT(result);
7145
7146 // CR (3/22/2020): Fixed setting case insensitivity
7147 // if (symbol_table_case_insensitive_semantics == true)
7149 result->setCaseInsensitive(true);
7150
7152 condition->set_parent(result);
7153 body->set_parent(result);
7154
7155// DQ (8/10/2011): This is added by Michael to support a Python specific feature.
7156 if (else_body != NULL) {
7157 result->set_else_body(else_body);
7158 else_body->set_parent(result);
7159 }
7160
7161 return result;
7162}
7163
7166{
7167 SgWhileStmt* result = new SgWhileStmt(condition,body);
7168 ROSE_ASSERT(result);
7169
7170 // DQ (2/15/2012): This function supports the case where in C++ the condition can include a variable declaration.
7171 initializeWhileStatement(result,condition,body,else_body);
7172 return result;
7173}
7174
7176{
7177 ROSE_ASSERT(expr != NULL && body != NULL);
7178 SgWithStatement* result = new SgWithStatement(expr, body);
7179 expr->set_parent(result);
7180 body->set_parent(result);
7181
7183 return result;
7184}
7185
7187{
7188 ROSE_ASSERT(expr != NULL && body != NULL);
7189 SgWithStatement* result = new SgWithStatement(expr, body);
7190 expr->set_parent(result);
7191 body->set_parent(result);
7192
7194 return result;
7195}
7196
7198{
7199 ROSE_ASSERT(condition);
7200 ROSE_ASSERT(body);
7201 SgDoWhileStmt* result = new SgDoWhileStmt(body, condition);
7202 ROSE_ASSERT(result);
7204 condition->set_parent(result);
7205 body->set_parent(result);
7206 return result;
7207}
7208
7210{
7211 SgDoWhileStmt* result = new SgDoWhileStmt(body, condition);
7212 ROSE_ASSERT(result);
7214 if (condition) condition->set_parent(result);
7215 if (body) body->set_parent(result);
7216 return result;
7217}
7218
7220{
7221 SgMatlabForStatement* result = new SgMatlabForStatement(loop_index, loop_range, loop_body);
7223
7224 ROSE_ASSERT(result != NULL);
7225
7226 loop_index->set_parent(result);
7227 loop_range->set_parent(result);
7228 loop_body->set_parent(result);
7229 return result;
7230}
7231
7233{
7234 SgBreakStmt* result = new SgBreakStmt();
7235 ROSE_ASSERT(result);
7237 return result;
7238}
7239
7241{
7242 SgBreakStmt* result = new SgBreakStmt();
7243 ROSE_ASSERT(result);
7245 return result;
7246}
7247
7249{
7250 SgContinueStmt* result = new SgContinueStmt();
7251 ASSERT_not_null(result);
7253 return result;
7254}
7255
7257{
7258 SgContinueStmt* result = new SgContinueStmt();
7259 ASSERT_not_null(result);
7261 return result;
7262}
7263
7265{
7267 ASSERT_not_null(result);
7269 return result;
7270}
7271
7273{
7275 ASSERT_not_null(result);
7277 return result;
7278}
7279
7281{
7282 SgPassStatement* result = new SgPassStatement();
7283 ROSE_ASSERT(result);
7285 return result;
7286}
7287
7289{
7290 SgPassStatement* result = new SgPassStatement();
7291 ROSE_ASSERT(result);
7293 return result;
7294}
7295
7296SgDeleteExp* SageBuilder::buildDeleteExp(SgExpression *target, bool is_array, bool need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
7297{
7298 SgDeleteExp *result = new SgDeleteExp(target, is_array, need_global_specifier, deleteOperatorDeclaration);
7299 target->set_parent(result);
7301 return result;
7302}
7303
7304SgDeleteExp* SageBuilder::buildDeleteExp_nfi(SgExpression *target, bool is_array, bool need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
7305{
7306 SgDeleteExp *result = new SgDeleteExp(target, is_array, need_global_specifier, deleteOperatorDeclaration);
7307 target->set_parent(result);
7309 return result;
7310}
7311
7313{
7314 SgAssertStmt* result = new SgAssertStmt(test);
7315 ROSE_ASSERT(test != NULL);
7316 test->set_parent(result);
7318 return result;
7319}
7320
7321// DQ (7/18/2011): Added support for SgJavaInstanceOfOp
7324 {
7325 SgType* exp_type = SgTypeBool::createType();
7326
7327 SgJavaInstanceOfOp* result = new SgJavaInstanceOfOp(exp, type, exp_type);
7328 ROSE_ASSERT(result);
7329 if (exp != NULL)
7330 {
7331 exp->set_parent(result);
7332 markLhsValues(result);
7333 }
7334
7336 return result;
7337 }
7338
7340{
7341 SgAssertStmt* result = new SgAssertStmt(test);
7342 ROSE_ASSERT(test != NULL);
7343 test->set_parent(result);
7344 if (exceptionArgument != NULL) {
7345 result -> set_exception_argument(exceptionArgument);
7346 exceptionArgument->set_parent(result);
7347 }
7349 return result;
7350}
7351
7353{
7354 SgAssertStmt* result = new SgAssertStmt(test);
7355 ROSE_ASSERT(test != NULL);
7356 test->set_parent(result);
7358 return result;
7359}
7360
7362{
7363 ROSE_ASSERT(value != NULL);
7364 SgYieldExpression* result = new SgYieldExpression(value);
7365 value->set_parent(result);
7367 return result;
7368}
7369
7371{
7372 ROSE_ASSERT(value != NULL);
7373 SgYieldExpression* result = new SgYieldExpression(value);
7374 value->set_parent(result);
7376 return result;
7377}
7378
7380{
7381 ROSE_ASSERT(key != NULL && datum != NULL);
7382 SgKeyDatumPair *result = new SgKeyDatumPair(key, datum);
7383 key->set_parent(result);
7384 datum->set_parent(result);
7386 return result;
7387}
7388
7390{
7391 ROSE_ASSERT(key != NULL && datum != NULL);
7392 SgKeyDatumPair *result = new SgKeyDatumPair(key, datum);
7393 key->set_parent(result);
7394 datum->set_parent(result);
7396 return result;
7397}
7398
7399SgDictionaryExp* SageBuilder::buildDictionaryExp(std::vector<SgKeyDatumPair*> pairs)
7400{
7401 SgDictionaryExp *result = new SgDictionaryExp();
7402 ROSE_ASSERT(result);
7403 for (size_t i = 0; i < pairs.size(); ++i)
7404 result->append_pair(pairs[i]);
7406 return result;
7407}
7408
7409SgDictionaryExp* SageBuilder::buildDictionaryExp_nfi(std::vector<SgKeyDatumPair*> pairs)
7410{
7411 SgDictionaryExp *result = new SgDictionaryExp();
7412 ROSE_ASSERT(result);
7413 for (size_t i = 0; i < pairs.size(); ++i)
7414 result->append_pair(pairs[i]);
7416 return result;
7417}
7418
7421{
7422 ROSE_ASSERT(target != NULL);
7423 ROSE_ASSERT(iter != NULL);
7424 SgComprehension *result = new SgComprehension(target, iter, ifs);
7425 ROSE_ASSERT(result);
7426
7427 target->set_parent(result);
7428 iter->set_parent(result);
7429 if (ifs != NULL) ifs->set_parent(result);
7430
7432 return result;
7433}
7434
7437{
7438 ROSE_ASSERT(target != NULL);
7439 ROSE_ASSERT(iter != NULL);
7440 SgComprehension *result = new SgComprehension(target, iter, ifs);
7441 ROSE_ASSERT(result);
7442 target->set_parent(result);
7443 iter->set_parent(result);
7444 if (ifs != NULL) ifs->set_parent(result);
7446 return result;
7447}
7448
7451{
7452 ROSE_ASSERT(elt != NULL);
7453 ROSE_ASSERT(generators != NULL);
7454 SgListComprehension* result = new SgListComprehension(elt, generators);
7455 elt->set_parent(result);
7456 generators->set_parent(result);
7458 return result;
7459}
7460
7463{
7464 ROSE_ASSERT(elt != NULL);
7465 ROSE_ASSERT(generators != NULL);
7466 SgListComprehension* result = new SgListComprehension(elt, generators);
7467 elt->set_parent(result);
7468 generators->set_parent(result);
7470 return result;
7471}
7472
7475{
7476 ROSE_ASSERT(elt != NULL);
7477 ROSE_ASSERT(generators != NULL);
7478 SgSetComprehension* result = new SgSetComprehension(elt, generators);
7479 elt->set_parent(result);
7480 generators->set_parent(result);
7482 return result;
7483}
7484
7487{
7488 ROSE_ASSERT(elt != NULL);
7489 ROSE_ASSERT(generators != NULL);
7490 SgSetComprehension* result = new SgSetComprehension(elt, generators);
7491 elt->set_parent(result);
7492 generators->set_parent(result);
7494 return result;
7495}
7496
7499{
7500 ROSE_ASSERT(kd_pair != NULL);
7501 ROSE_ASSERT(generators != NULL);
7502 SgDictionaryComprehension* result = new SgDictionaryComprehension(kd_pair, generators);
7503 kd_pair->set_parent(result);
7504 generators->set_parent(result);
7506 return result;
7507}
7508
7511{
7512 ROSE_ASSERT(kd_pair != NULL);
7513 ROSE_ASSERT(generators != NULL);
7514 SgDictionaryComprehension* result = new SgDictionaryComprehension(kd_pair, generators);
7515 kd_pair->set_parent(result);
7516 generators->set_parent(result);
7518 return result;
7519}
7520
7523 ROSE_ASSERT(arg != NULL);
7524 SgActualArgumentExpression* result = new SgActualArgumentExpression(arg_name, arg);
7525 arg->set_parent(result);
7527 return result;
7528}
7529
7532 ROSE_ASSERT(arg != NULL);
7533 SgActualArgumentExpression* result = new SgActualArgumentExpression(arg_name, arg);
7534 arg->set_parent(result);
7536 return result;
7537}
7538
7541 {
7542 if (scope == NULL)
7544
7545 SgPragma* pragma = new SgPragma(name);
7546 ROSE_ASSERT(pragma);
7547
7549
7550 SgPragmaDeclaration* result = new SgPragmaDeclaration(pragma);
7551 ROSE_ASSERT(result);
7552
7554
7555 result->set_definingDeclaration (result);
7556 result->set_firstNondefiningDeclaration(result);
7557 pragma->set_parent(result);
7558
7559 // DQ (7/14/2012): Set the parent so that we can be consistent where possible (class declarations and
7560 // enum declaration can't have there parent set since they could be non-autonomous declarations).
7561 result->set_parent(scope);
7562
7563 if (scope || topScopeStack())
7564 ROSE_ASSERT(result->get_parent() != NULL);
7565
7566 return result;
7567 }
7568
7570SgPragma* SageBuilder::buildPragma(const std::string & name)
7571{
7572 SgPragma* result= new SgPragma(name);
7573 ROSE_ASSERT(result);
7575 return result;
7576}
7577
7578
7580 {
7581 // Build an empty declaration (useful for adding precission to comments and CPP handling under token-based unparsing).
7582 SgEmptyDeclaration* emptyDeclaration = new SgEmptyDeclaration();
7583 ROSE_ASSERT(emptyDeclaration != NULL);
7584
7585 setOneSourcePositionForTransformation(emptyDeclaration);
7586
7587 emptyDeclaration->set_definingDeclaration (emptyDeclaration);
7588 emptyDeclaration->set_firstNondefiningDeclaration(emptyDeclaration);
7589
7590 // DQ (7/14/2012): Set the parent so that we can be consistent where possible (class declarations and
7591 // enum declaration can't have there parent set since they could be non-autonomous declarations).
7592 emptyDeclaration->set_parent(topScopeStack());
7593
7594 if (topScopeStack() != NULL)
7595 {
7596 ROSE_ASSERT(emptyDeclaration->get_parent() != NULL);
7597 }
7598
7599 return emptyDeclaration;
7600 }
7601
7602
7604{
7605 SgBasicBlock* result = new SgBasicBlock();
7606 ROSE_ASSERT(result);
7607
7608 // CR (3/22/2020): Fixed setting case insensitivity
7609 // if (symbol_table_case_insensitive_semantics == true)
7611 result->setCaseInsensitive(true);
7612
7614 if (stmt1) SageInterface::appendStatement(stmt1, result);
7615 if (stmt2) SageInterface::appendStatement(stmt2, result);
7616 if (stmt3) SageInterface::appendStatement(stmt3, result);
7617 if (stmt4) SageInterface::appendStatement(stmt4, result);
7618 if (stmt5) SageInterface::appendStatement(stmt5, result);
7619 if (stmt6) SageInterface::appendStatement(stmt6, result);
7620 if (stmt7) SageInterface::appendStatement(stmt7, result);
7621 if (stmt8) SageInterface::appendStatement(stmt8, result);
7622 if (stmt9) SageInterface::appendStatement(stmt9, result);
7623 if (stmt10) SageInterface::appendStatement(stmt10, result);
7624
7625 return result;
7626}
7627
7629 {
7630 SgBasicBlock* result = new SgBasicBlock();
7631 ROSE_ASSERT(result);
7632
7634 {
7635 result->setCaseInsensitive(true);
7636 }
7637
7639 return result;
7640 }
7641
7642SgBasicBlock* SageBuilder::buildBasicBlock_nfi(const vector<SgStatement*>& stmts)
7643 {
7645 appendStatementList(stmts, result);
7646 return result;
7647 }
7648
7649// Build a SgBasicBlock and set its parent. This function does NOT link the parent scope to the block.
7652{
7654 block->set_parent(parent);
7655
7656 return block;
7657}
7658
7661{
7662 SgGotoStatement* result = new SgGotoStatement(label);
7663 ROSE_ASSERT(result);
7665 return result;
7666}
7667
7670{
7671 SgGotoStatement* result = NULL;
7672 ROSE_ASSERT (symbol != NULL);
7674 { // Fortran case
7675 result = buildGotoStatement((SgLabelStatement *)NULL);
7676 SgLabelRefExp* l_exp = buildLabelRefExp(symbol);
7677 l_exp->set_parent(result);
7678 result->set_label_expression(l_exp);
7679 }
7680 else // C/C++ case
7681 {
7682 SgLabelStatement* l_stmt = isSgLabelStatement(symbol->get_declaration());
7683 ROSE_ASSERT (l_stmt != NULL);
7684 result = buildGotoStatement(l_stmt);
7685 }
7686 ROSE_ASSERT(result);
7687 return result;
7688}
7689
7692{
7693 SgGotoStatement* result = new SgGotoStatement(label);
7694 ROSE_ASSERT(result);
7696 return result;
7697}
7698
7699// DQ (11/22/2017): Added support for computed code goto as defined by GNU C/C++ extension.
7702 {
7703 SgLabelStatement* label = NULL;
7704 SgGotoStatement* result = new SgGotoStatement(label);
7705 result->set_selector_expression(label_expression);
7706 ROSE_ASSERT(result);
7708 return result;
7709 }
7710
7713{
7714 // Liao 2/6/2013. We no longer allow NULL express pointer. Use SgNullExpression instead.
7715 // CR (4/27/18): The expression argument to the builder function is optional
7716 // (NULL is allowed). What is not allowed is constructing an SgReturnStmt with a NULL
7717 // expression argument.
7718 if (expression == NULL)
7719 {
7720 expression = buildNullExpression();
7721 }
7722 SgReturnStmt* result = new SgReturnStmt(expression);
7723 ROSE_ASSERT(result);
7724 if (expression != NULL) expression->set_parent(result);
7726 return result;
7727}
7728
7731{
7732 SgReturnStmt* result = new SgReturnStmt(expression);
7733 ROSE_ASSERT(result);
7734 if (expression != NULL) expression->set_parent(result);
7736 return result;
7737}
7738
7740{
7741 SgCaseOptionStmt* result = new SgCaseOptionStmt(key,body);
7742 ROSE_ASSERT(result);
7744 if (key) key->set_parent(result);
7745 if (body) body->set_parent(result);
7746 return result;
7747}
7748
7750{
7751 SgCaseOptionStmt* result = new SgCaseOptionStmt(key,body);
7752 ROSE_ASSERT(result);
7754 if (key) key->set_parent(result);
7755 if (body) body->set_parent(result);
7756 return result;
7757}
7758
7760{
7761 SgDefaultOptionStmt* result = new SgDefaultOptionStmt(body);
7762 ROSE_ASSERT(result);
7764 if (body) body->set_parent(result);
7765 return result;
7766}
7767
7769{
7770 SgDefaultOptionStmt* result = new SgDefaultOptionStmt(body);
7771 ROSE_ASSERT(result);
7773 if (body) body->set_parent(result);
7774 return result;
7775}
7776
7778{
7779 SgSwitchStatement* result = new SgSwitchStatement(item_selector,body);
7780 ROSE_ASSERT(result);
7781
7783 result->setCaseInsensitive(true);
7784
7786 if (item_selector) item_selector->set_parent(result);
7787 if (body) body->set_parent(result);
7788 return result;
7789}
7790
7793{
7794 SgSwitchStatement* result = new SgSwitchStatement(item_selector,body);
7795 ROSE_ASSERT(result);
7796
7797 // DQ (2/15/2012): Modified to handle C++ case where variable declarations are allowed in the condition.
7798 initializeSwitchStatement(result,item_selector,body);
7799 return result;
7800}
7801
7804{
7805 SgNullStatement* result = NULL;
7806 result = new SgNullStatement();
7807 ROSE_ASSERT(result);
7809 return result;
7810}
7811
7814{
7815 SgNullStatement* result = NULL;
7816 result = new SgNullStatement();
7817 ROSE_ASSERT(result);
7819 return result;
7820}
7821
7824 SgExpression* globals,
7825 SgExpression* locals) {
7826 if (locals != NULL && globals == NULL)
7827 ROSE_ASSERT(!"buildExecStatement with non-NULL locals requires non-NULL globals");
7828 ROSE_ASSERT(executable != NULL);
7829
7830 SgExecStatement* result = new SgExecStatement(executable, globals, locals);
7831 executable->set_parent(result);
7832 if (globals != NULL) globals->set_parent(result);
7833 if (locals != NULL) locals->set_parent(result);
7834
7836 return result;
7837}
7838
7841 SgExpression* globals,
7842 SgExpression* locals) {
7843 if (locals != NULL && globals == NULL)
7844 ROSE_ASSERT(!"buildExecStatement with non-NULL locals requires non-NULL globals");
7845 ROSE_ASSERT(executable != NULL);
7846
7847 SgExecStatement* result = new SgExecStatement(executable, globals, locals);
7848 executable->set_parent(result);
7849 if (globals != NULL) globals->set_parent(result);
7850 if (locals != NULL) locals->set_parent(result);
7851
7853 return result;
7854}
7855
7856// MH (6/10/2014): Added async support
7858{
7859 ROSE_ASSERT(body != NULL);
7860 SgAsyncStmt *async_stmt = new SgAsyncStmt(body);
7861 ROSE_ASSERT(async_stmt);
7862 body->set_parent(async_stmt);
7864
7865 return async_stmt;
7866}
7867
7868// MH (6/11/2014): Added finish support
7870{
7871 ROSE_ASSERT(body != NULL);
7872 SgFinishStmt *finish_stmt = new SgFinishStmt(body);
7873 ROSE_ASSERT(finish_stmt);
7874 body->set_parent(finish_stmt);
7876
7877 return finish_stmt;
7878}
7879
7880// MH (6/11/2014): Added at support
7882{
7883 ROSE_ASSERT(expression);
7884 ROSE_ASSERT(body);
7885 SgAtStmt *at_stmt = new SgAtStmt(expression, body);
7887 expression->set_parent(at_stmt);
7888 body->set_parent(at_stmt);
7889
7890 return at_stmt;
7891}
7892
7893// MH (11/12/2014): Added atomic support
7895{
7896 ROSE_ASSERT(body != NULL);
7897 SgAtomicStmt *atomic_stmt = new SgAtomicStmt(body);
7898 ROSE_ASSERT(atomic_stmt);
7899 body->set_parent(atomic_stmt);
7901
7902 return atomic_stmt;
7903}
7904
7905
7907{
7908 ROSE_ASSERT(expression);
7909 ROSE_ASSERT(body);
7910 SgWhenStmt *when_stmt = new SgWhenStmt(expression, body);
7912 expression->set_parent(when_stmt);
7913 body->set_parent(when_stmt);
7914
7915 return when_stmt;
7916}
7917
7918// MH (9/14/2014): Added atexpr support
7920{
7921 ROSE_ASSERT(expression);
7922 ROSE_ASSERT(body);
7923 SgAtExp *at_exp = new SgAtExp(expression, body);
7925 expression->set_parent(at_exp);
7926 body->set_parent(at_exp);
7927
7928 return at_exp;
7929}
7930
7931// MH (11/7/2014): Added finish expression support
7933{
7934 ROSE_ASSERT(expression);
7935 ROSE_ASSERT(body);
7936 SgFinishExp *finish_exp = new SgFinishExp(expression, body);
7938 expression->set_parent(finish_exp);
7939 body->set_parent(finish_exp);
7940
7941 return finish_exp;
7942}
7943
7945{
7946 SgHereExp *here = new SgHereExp(NULL);
7947 return here;
7948}
7949
7951{
7952 SgDotDotExp *dotdot = new SgDotDotExp(NULL);
7953 return dotdot;
7954}
7955
7956
7959 SgCatchOptionStmt* catch0,
7960 SgCatchOptionStmt* catch1,
7961 SgCatchOptionStmt* catch2,
7962 SgCatchOptionStmt* catch3,
7963 SgCatchOptionStmt* catch4
7964 )
7965 {
7966 ROSE_ASSERT(body != NULL);
7967 SgTryStmt* try_stmt = new SgTryStmt(body);
7968 body->set_parent(try_stmt);
7969
7970 // DQ (11/3/2012): Added setting default source position info.
7971 setSourcePosition(try_stmt);
7972
7973 if (try_stmt->get_catch_statement_seq_root() != NULL)
7974 {
7975 if (try_stmt->get_catch_statement_seq_root()->get_startOfConstruct() == NULL)
7976 {
7977 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_endOfConstruct() == NULL);
7979 }
7980
7981 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_startOfConstruct() != NULL);
7982 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_endOfConstruct() != NULL);
7983 }
7984
7985 if (catch0 != NULL) try_stmt->append_catch_statement(catch0);
7986 if (catch1 != NULL) try_stmt->append_catch_statement(catch1);
7987 if (catch2 != NULL) try_stmt->append_catch_statement(catch2);
7988 if (catch3 != NULL) try_stmt->append_catch_statement(catch3);
7989 if (catch4 != NULL) try_stmt->append_catch_statement(catch4);
7990
7991 return try_stmt;
7992 }
7993
7994
7995// charles4 09/16/2011
7998 {
7999 //
8000 // charles4 09/23/2011 - Note that when an SgTryStmt is allocated, its constructor
8001 // preallocates a SgCatchStementSeq for the field p_catch_statement_sequence_root.
8002 // So, although the method set_catch_statement_seq_root(catch_statement_sequence) is
8003 // available, it should not be used to set the catch_statement_sequence_root as that
8004 // would leave the one that was allocated by the constructor dangling!
8005 //
8006 ROSE_ASSERT(try_body != NULL);
8007 SgTryStmt* try_stmt = new SgTryStmt(try_body);
8008 try_body -> set_parent(try_stmt);
8009
8010 // DQ (11/3/2012): Added setting default source position info.
8011 setSourcePosition(try_stmt);
8012
8013 if (finally_body) {
8014 try_stmt -> set_finally_body(finally_body);
8015 finally_body -> set_parent(try_stmt);
8016 }
8017
8018 return try_stmt;
8019}
8020
8021// charles4 09/16/2011
8022// ! Build an initial sequence of Catch blocks containing 0 or 1 element.
8024 SgCatchStatementSeq *catch_statement_sequence = new SgCatchStatementSeq();
8025
8026 // DQ (11/3/2012): Added setting default source position info.
8027 setSourcePosition(catch_statement_sequence);
8028
8029 if (catch_option_stmt) {
8030 catch_statement_sequence -> append_catch_statement(catch_option_stmt);
8031 catch_option_stmt -> set_parent(catch_statement_sequence);
8032 }
8033
8034 return catch_statement_sequence;
8035}
8036
8037// charles4 09/21/2011 - Make condition and body arguments optional.
8040 SgCatchOptionStmt* result = new SgCatchOptionStmt(condition, body, /* SgTryStmt*= */ NULL);
8041 if (condition) condition->set_parent(result);
8042 if (body) body->set_parent(result);
8044 return result;
8045}
8046
8048{
8049 ROSE_ASSERT(expression);
8050 ROSE_ASSERT(body);
8051 SgJavaSynchronizedStatement *sync_stmt = new SgJavaSynchronizedStatement(expression, body);
8053
8054 expression->set_parent(sync_stmt);
8055 body->set_parent(sync_stmt);
8056
8057 return sync_stmt;
8058}
8059
8061{
8062 ROSE_ASSERT(op);
8063 SgJavaThrowStatement *throw_stmt = new SgJavaThrowStatement(op);
8064 ROSE_ASSERT(throw_stmt);
8065
8066 op->set_parent(throw_stmt);
8067
8068 return throw_stmt;
8069}
8070
8072{
8073 SgJavaForEachStatement *foreach_stmt = new SgJavaForEachStatement(variable, collection, body);
8074 ROSE_ASSERT(foreach_stmt);
8075 if (variable) variable -> set_parent(foreach_stmt);
8076 if (collection) collection -> set_parent(foreach_stmt);
8077 if (body) body -> set_parent(foreach_stmt);
8078
8079 return foreach_stmt;
8080}
8081
8083{
8084 SgJavaLabelStatement *label_stmt = new SgJavaLabelStatement(name, stmt);
8085 ROSE_ASSERT(label_stmt);
8087
8088 if (stmt != NULL)
8089 stmt -> set_parent(label_stmt);
8090
8091 SgJavaLabelSymbol *lsymbol = label_stmt -> lookup_java_label_symbol(name);
8092 if (! lsymbol) // Should be an Assertion - always true!
8093 {
8094 lsymbol= new SgJavaLabelSymbol(label_stmt);
8095 ROSE_ASSERT(lsymbol);
8096 label_stmt -> insert_symbol(lsymbol -> get_name(), lsymbol);
8097 }
8098
8099 return label_stmt;
8100}
8101
8104 SgPythonPrintStmt* result = new SgPythonPrintStmt(dest, values);
8105 if (dest) dest->set_parent(result);
8106 if (values) values->set_parent(result);
8108 return result;
8109}
8110
8113 SgPythonPrintStmt* result = new SgPythonPrintStmt(dest, values);
8114 if (dest) dest->set_parent(result);
8115 if (values) values->set_parent(result);
8117 return result;
8118}
8119
8121SageBuilder::buildPythonGlobalStmt(SgInitializedNamePtrList& names) {
8122 SgPythonGlobalStmt* result = new SgPythonGlobalStmt();
8123 for (SgInitializedName* name: names) {
8124 result->append_name(name);
8125 }
8127 return result;
8128}
8129
8131SageBuilder::buildPythonGlobalStmt_nfi(SgInitializedNamePtrList& names) {
8132 SgPythonGlobalStmt* result = new SgPythonGlobalStmt();
8133 for (SgInitializedName* name: names) {
8134 result->append_name(name);
8135 }
8137 return result;
8138}
8139
8140// DQ (4/30/2010): Added support for building asm statements.
8143{
8144 SgAsmStmt* result = NULL;
8145 result = new SgAsmStmt();
8146 ROSE_ASSERT(result);
8147 result->set_assemblyCode(s);
8149 return result;
8150}
8151
8152// DQ (4/30/2010): Added support for building asm statements.
8155{
8156 SgAsmStmt* result = NULL;
8157 result = new SgAsmStmt();
8158 ROSE_ASSERT(result);
8159 result->set_assemblyCode(s);
8161 return result;
8162}
8163
8164SgAsmStmt*
8166 {
8167// Multi-byte NOP instructions.
8168// Note: I can't seem to get the memonic versions to work properly
8169#define NOP_1_BYTE_STRING "nop"
8170#define NOP_2_BYTE_STRING ".byte 0x66,0x90"
8171#define NOP_3_BYTE_STRING "nopl (%eax)"
8172#define NOP_4_BYTE_STRING "nopl 0x01(%eax)"
8173#define NOP_5_BYTE_STRING ".byte 0x0f,0x1f,0x44,0x00,0x00"
8174#define NOP_6_BYTE_STRING ".byte 0x66,0x0f,0x1f,0x44,0x00,0x00"
8175#define NOP_7_BYTE_STRING ".byte 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00"
8176#define NOP_8_BYTE_STRING ".byte 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00"
8177#define NOP_9_BYTE_STRING ".byte 0x66,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00"
8178
8179 ROSE_ASSERT(n > 0);
8180
8181 SgAsmStmt* nopStatement = NULL;
8182
8183 switch (n)
8184 {
8185 case 1: nopStatement = buildAsmStatement(NOP_1_BYTE_STRING); break;
8186 case 2: nopStatement = buildAsmStatement(NOP_2_BYTE_STRING); break;
8187 case 3: nopStatement = buildAsmStatement(NOP_3_BYTE_STRING); break;
8188 case 4: nopStatement = buildAsmStatement(NOP_4_BYTE_STRING); break;
8189 case 5: nopStatement = buildAsmStatement(NOP_5_BYTE_STRING); break;
8190 case 6: nopStatement = buildAsmStatement(NOP_6_BYTE_STRING); break;
8191 case 7: nopStatement = buildAsmStatement(NOP_7_BYTE_STRING); break;
8192 case 8: nopStatement = buildAsmStatement(NOP_8_BYTE_STRING); break;
8193 case 9: nopStatement = buildAsmStatement(NOP_9_BYTE_STRING); break;
8194
8195 default:
8196 {
8197 printf ("Only supporting values of multi-byte nop's up to 9 bytes long. \n");
8198 ROSE_ABORT();
8199 }
8200 }
8201
8202 return nopStatement;
8203 }
8204
8206 {
8207 // DQ (7/25/2014): Adding support for C11 static assertions.
8208
8209 ROSE_ASSERT(condition != NULL);
8210
8211 SgStaticAssertionDeclaration* result = new SgStaticAssertionDeclaration(condition,string_literal);
8212 ROSE_ASSERT(result != NULL);
8213
8214 // DQ (7/25/2014): It is enforced that at least the firstNondefiningDeclaration be set.
8215 ROSE_ASSERT(result->get_firstNondefiningDeclaration() == NULL);
8216 result->set_firstNondefiningDeclaration(result);
8217 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
8218
8220
8221 return result;
8222 }
8223
8224
8225// DQ (8/17/2014): Adding support for Microsoft MSVC specific attributes.
8227 {
8229 ROSE_ASSERT(result != NULL);
8230
8231 // DQ (8/17/2014): It is enforced that at least the firstNondefiningDeclaration be set.
8232 ROSE_ASSERT(result->get_firstNondefiningDeclaration() == NULL);
8233 result->set_firstNondefiningDeclaration(result);
8234 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
8235
8237
8238 return result;
8239 }
8240
8242 {
8243 if (isSgReferenceType (base_type))
8244 {
8245 cerr<<"Error in SageBuilder::buildPointerType(): trying to build a pointer to a reference type! This is not allowed in C++."<<endl;
8246 ROSE_ABORT ();
8247 }
8248
8249 SgPointerType* result = SgPointerType::createType(base_type);
8250 ROSE_ASSERT(result != NULL);
8251
8252 return result;
8253 }
8254
8256 {
8257 SgReferenceType* result = SgReferenceType::createType(base_type);
8258 ROSE_ASSERT(result != NULL);
8259 return result;
8260 }
8261
8263 {
8264 ROSE_ASSERT(base_type != NULL);
8266 ROSE_ASSERT(result != NULL);
8267
8268 return result;
8269 }
8270
8272 {
8273 ROSE_ASSERT(base_expression != NULL);
8274
8275 // SgDeclType* result = SgDeclType::createType(base_expression);
8276 SgDeclType* result = NULL;
8277 if (isSgFunctionParameterRefExp(base_expression) != NULL)
8278 {
8279 result = new SgDeclType(base_expression);
8280 result->set_base_type(base_type);
8281 }
8282 else
8283 {
8284 result = SgDeclType::createType(base_expression);
8285 }
8286
8287 ROSE_ASSERT(result != NULL);
8288
8289 // DQ (8/12/2014): Set the parent in the expression.
8290 base_expression->set_parent(result);
8291
8292 return result;
8293 }
8294
8297 {
8298 // ROSE_ASSERT(base_expression != NULL);
8299
8300#define DEBUG_TYPEOF_TYPE 0
8301
8302#if DEBUG_TYPEOF_TYPE
8303 printf ("In SageBuilder::buildTypeOfType(): base_expression = %p = %s \n",base_expression,base_expression != NULL ? base_expression->class_name().c_str() : "NULL");
8304 printf (" ------------------------------- base_type = %p = %s \n",base_type,base_type != NULL ? base_type->class_name().c_str() : "NULL");
8305#endif
8306
8307 SgTypeOfType* result = NULL;
8308 if (isSgFunctionParameterRefExp(base_expression) != NULL)
8309 {
8310#if DEBUG_TYPEOF_TYPE
8311 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) != NULL: calling new SgTypeOfType(base_expression,NULL) \n");
8312#endif
8313 result = new SgTypeOfType(base_expression,NULL);
8314
8315 // DQ (3/28/2015): Testing for corruption in return value.
8316 ROSE_ASSERT(result != NULL);
8317#if DEBUG_TYPEOF_TYPE
8318 printf ("In buildTypeOfType(): test 1: result = %p = %s \n",result,result->class_name().c_str());
8319#endif
8320 result->set_base_type(base_type);
8321 }
8322 else
8323 {
8324 if (base_expression != NULL)
8325 {
8326#if DEBUG_TYPEOF_TYPE
8327 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) == NULL: base_expression != NULL: calling SgTypeOfType::createType(base_expression,NULL) \n");
8328#endif
8329 result = SgTypeOfType::createType(base_expression,NULL);
8330
8331 // DQ (3/28/2015): Testing for corruption in return value.
8332 ROSE_ASSERT(result != NULL);
8333#if DEBUG_TYPEOF_TYPE
8334 printf ("In buildTypeOfType(): test 2: result = %p = %s \n",result,result->class_name().c_str());
8335#endif
8336 }
8337 else
8338 {
8339 ROSE_ASSERT(base_type != NULL);
8340
8341#if DEBUG_TYPEOF_TYPE
8342 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) == NULL: base_expression == NULL: calling SgTypeOfType::createType(base_type,NULL) \n");
8343#endif
8344 result = SgTypeOfType::createType(base_type,NULL);
8345
8346 // DQ (3/28/2015): Testing for corruption in return value.
8347 ROSE_ASSERT(result != NULL);
8348
8349#if DEBUG_TYPEOF_TYPE
8350 printf ("In buildTypeOfType(): test 3: result = %p = %s \n",result,result->class_name().c_str());
8351#endif
8352 // result->set_base_type(base_type);
8353 if (result->get_base_type() != base_type)
8354 {
8355 ROSE_ASSERT(result->get_base_type() != NULL);
8356#if DEBUG_TYPEOF_TYPE
8357 printf ("result->get_base_type() = %p = %s \n",result->get_base_type(),result->get_base_type()->class_name().c_str());
8358#endif
8359 ROSE_ASSERT(base_type != NULL);
8360#if DEBUG_TYPEOF_TYPE
8361 printf ("base_type = %p = %s \n",base_type,base_type->class_name().c_str());
8362#endif
8363 }
8364 }
8365 }
8366
8367 ROSE_ASSERT(result != NULL);
8368
8369 if (base_expression != NULL)
8370 {
8371 base_expression->set_parent(result);
8372 }
8373
8374 // DQ (3/28/2015): Testing for corruption in return value.
8375 ROSE_ASSERT(result != NULL);
8376
8377#if DEBUG_TYPEOF_TYPE
8378 printf ("In buildTypeOfType(): test 4: result = %p = %s \n",result,result->class_name().c_str());
8379#endif
8380
8381 return result;
8382 }
8383
8384// Builder functions for type size (kind) expressions for Fortran and Jovial
8386 SgTypeBool* result = SgTypeBool::createType(kind_expr);
8387 ROSE_ASSERT(result);
8388 if (kind_expr != NULL) kind_expr->set_parent(result);
8389 return result;
8390}
8394
8396{
8398 ROSE_ASSERT(result);
8399 return result;
8400}
8401
8403{
8405 ROSE_ASSERT(result);
8406 return result;
8407}
8408
8410{
8412 ROSE_ASSERT(result);
8413 return result;
8414}
8415
8417{
8419 ROSE_ASSERT(result);
8420 return result;
8421}
8422
8424{
8426 ROSE_ASSERT(result);
8427 return result;
8428}
8429
8431{
8433 ROSE_ASSERT(result);
8434 return result;
8435}
8436
8437// Builder functions for type size (kind) expressions for Fortran and Jovial
8439{
8441 ROSE_ASSERT(result);
8442 if (kind_expr != NULL) kind_expr->set_parent(result);
8443 return result;
8444}
8449
8451{
8453 ROSE_ASSERT(result);
8454 return result;
8455}
8456
8459 ROSE_ASSERT(result);
8460 return result;
8461}
8462
8465 ROSE_ASSERT(result);
8466 return result;
8467}
8468
8471 ROSE_ASSERT(result);
8472 return result;
8473}
8474
8477 ROSE_ASSERT(result);
8478 return result;
8479}
8480
8483 ROSE_ASSERT(result);
8484 return result;
8485}
8486
8489 ROSE_ASSERT(result);
8490 return result;
8491}
8492
8495 ROSE_ASSERT(result);
8496 return result;
8497}
8498
8501 ROSE_ASSERT(result);
8502 return result;
8503}
8504
8507 ROSE_ASSERT(result);
8508 return result;
8509}
8510
8512{
8514 ROSE_ASSERT(result);
8515 return result;
8516}
8517
8519{
8521 ROSE_ASSERT(result);
8522 return result;
8523}
8524
8526{
8528 ROSE_ASSERT(result);
8529 return result;
8530}
8531
8533{
8535 ROSE_ASSERT(result);
8536 return result;
8537}
8538
8545
8552
8554{
8556 ROSE_ASSERT(result);
8557 return result;
8558}
8559
8561{
8563 ROSE_ASSERT(result);
8564 return result;
8565}
8566
8568{
8570 ROSE_ASSERT(result);
8571 return result;
8572}
8573
8575{
8577 ROSE_ASSERT(result);
8578 return result;
8579}
8580
8582{
8584 ROSE_ASSERT(result);
8585 return result;
8586}
8587
8589{
8591 ROSE_ASSERT(result);
8592 return result;
8593}
8594
8596{
8597 SgAutoType * result =new SgAutoType();
8598 ROSE_ASSERT(result);
8599 return result;
8600}
8601
8603{
8605 ROSE_ASSERT(result);
8606 return result;
8607}
8608
8610{
8612 ROSE_ASSERT(result);
8613 return result;
8614}
8615
8617{
8619 ROSE_ASSERT(result);
8620 return result;
8621}
8622
8624 {
8625 // DQ (8/17/2010): This function needs to use a different API to handle a literal
8626 // value for the string size (typical) or an expression for the string size (rare).
8627 // For now we will make it an error to call this function.
8628
8629 // SgTypeString * result =SgTypeString::createType();
8630 SgTypeString * result = NULL;
8631 ROSE_ASSERT(result != NULL);
8632 return result;
8633 }
8634
8636 {
8637 // DQ (8/21/2010): This is a new API for this function. This type is specific to Fortran use,
8638 // in C/C++ a string is just an array of char. We could have a consistant handling between
8639 // C/C++ and Fortrna, but we have just corrected the implementation in Fortran to use this IR
8640 // node and we would have to add such support to C/C++. The current implementation reflects
8641 // the grammar of the two languages.
8642
8643 // This function needs to use a different API to handle a literal
8644 // value for the string size (typical) or an expression for the string size (rare).
8645
8646 SgTypeString* result = SgTypeString::createType(stringLengthExpression);
8647 ASSERT_not_null(result);
8648 return result;
8649 }
8650
8651// Rasmussen (2/20/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8653{
8654 SgTypeInt * result;
8655 if (kind_expr != NULL)
8656 {
8657 result = SgTypeInt::createType(0, kind_expr);
8658 kind_expr->set_parent(result);
8659 }
8660 else
8661 {
8662 result = SgTypeInt::createType();
8663 }
8664 ASSERT_not_null(result);
8665 return result;
8666}
8668{
8669 return buildIntType(NULL);
8670}
8671
8673{
8675 ROSE_ASSERT(result);
8676 return result;
8677}
8678
8679// Rasmussen (3/6/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8681{
8682 SgTypeFloat * result;
8683 if (kind_expr != NULL)
8684 {
8685 result = SgTypeFloat::createType(kind_expr);
8686 kind_expr->set_parent(result);
8687 }
8688 else
8689 {
8690 result = SgTypeFloat::createType();
8691 }
8692 ASSERT_not_null(result);
8693 return result;
8694}
8696{
8698 ASSERT_not_null(result);
8699 return result;
8700}
8701
8702// Rasmussen (2/20/2020): Added builder for Jovial fixed type
8704{
8705 SgTypeFixed * result = SgTypeFixed::createType(scale, fraction);
8706 ROSE_ASSERT(result);
8707
8708 if (scale) scale->set_parent(result);
8709 if (fraction) fraction->set_parent(result);
8710
8711 return result;
8712}
8713
8714// Rasmussen (5/5/2020): Added builder for Jovial bit type
8716{
8717 SgJovialBitType * result = SgJovialBitType::createType(size, NULL);
8718
8719 if (size) size->set_parent(result);
8720
8721 return result;
8722}
8723
8724// DQ (7/29/2010): Changed return type from SgType to SgModifierType
8727 {
8728 ROSE_ASSERT(base_type != NULL);
8729
8730 // DQ (7/28/2010): New (similar) approach using type table support.
8731 SgModifierType* result = new SgModifierType(base_type);
8732 ROSE_ASSERT(result != NULL);
8733
8734 // DQ (3/10/2018): Adding assertion.
8735 ROSE_ASSERT(result != base_type);
8736
8737 // DQ (7/28/2010): Insert result type into type table and return it, or
8738 // replace the result type, if already available in the type table, with
8739 // the type from type table.
8740 SgModifierType* result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8741
8742 if (result != result2)
8743 {
8744 // DQ (10/27/2015): This is the cause of a bug in the test2015_97.C (boost template problem).
8745 printf ("WARNING: In SageBuilder::buildModifierType(): using previously build SgModifierType from global type table: result2 = %p = %s \n",result2,result2->class_name().c_str());
8746 delete result;
8747 }
8748
8749 // DQ (3/10/2018): Adding assertion.
8750 ROSE_ASSERT(result2 != base_type);
8751
8752 return result2;
8753 }
8754
8757 {
8758 ROSE_ASSERT(base_type != NULL);
8759
8760 // DQ (7/28/2010): New (similar) approach using type table support.
8761 SgModifierType *result = new SgModifierType(base_type);
8762 ROSE_ASSERT(result!=NULL);
8763 result->get_typeModifier().get_constVolatileModifier().setConst();
8764
8765 // DQ (7/28/2010): Insert result type into type table and return it, or
8766 // replace the result type, if already available in the type table, with
8767 // the type from type table.
8768 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8769
8770 if (result != result2)
8771 {
8772 delete result;
8773 }
8774
8775 // DQ (3/10/2018): Adding assertion.
8776 ROSE_ASSERT(result2 != base_type);
8777
8778 return result2;
8779 }
8780
8781// DQ (8/27/2010): Added Fortran specific support for types based on kind expressions.
8784 {
8785 ROSE_ASSERT(base_type != NULL);
8786
8787 SgModifierType *result = new SgModifierType(base_type);
8788 ROSE_ASSERT(result != NULL);
8789
8790 result->set_type_kind(kindExpression);
8791
8792 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8793 if (result != result2)
8794 {
8795 delete result;
8796 }
8797
8798 return result2;
8799 }
8800
8801// DQ (7/29/2010): Changed return type from SgType to SgModifierType
8804 {
8805 ROSE_ASSERT(base_type != NULL);
8806 SgModifierType *result = new SgModifierType(base_type);
8807 ROSE_ASSERT(result!=NULL);
8808
8809 result->get_typeModifier().get_constVolatileModifier().setVolatile();
8810
8811 // DQ (7/29/2010): Insert result type into type table and return it, or
8812 // replace the result type, if already available in the type table, with
8813 // the type from type table.
8814 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8815 if (result != result2)
8816 {
8817 delete result;
8818 }
8819
8820 return result2;
8821 }
8822
8823// DQ (1/19/2019): Adding support for const volatile type (both together as another value).
8826 {
8827 ROSE_ASSERT(base_type != NULL);
8828
8829 SgModifierType *result = new SgModifierType(base_type);
8830 ROSE_ASSERT(result!=NULL);
8831
8832 result->get_typeModifier().get_constVolatileModifier().setConst();
8833 result->get_typeModifier().get_constVolatileModifier().setVolatile();
8834
8835 printf ("In SageBuilder::buildConstVolatileType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
8836
8837 // DQ (7/29/2010): Insert result type into type table and return it, or
8838 // replace the result type, if already available in the type table, with
8839 // the type from type table.
8840 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8841 if (result != result2) {
8842 delete result;
8843 }
8844
8845 return result2;
8846 }
8847
8848string
8849generate_type_list (SgType* type)
8850 {
8851 // This function generates a list of types for each level of the type structure.
8852 string returnString;
8853
8854 unsigned char bit_array = (SgType::STRIP_MODIFIER_TYPE | SgType::STRIP_REFERENCE_TYPE | SgType::STRIP_RVALUE_REFERENCE_TYPE | SgType::STRIP_POINTER_TYPE | SgType::STRIP_ARRAY_TYPE | SgType::STRIP_TYPEDEF_TYPE);
8855
8856 SgType* currentType = type;
8857
8858 SgModifierType* modType = NULL;
8859 SgPointerType* pointType = NULL;
8860 SgReferenceType* refType = NULL;
8861 SgRvalueReferenceType* rRefType = NULL;
8862 SgArrayType* arrayType = NULL;
8863 SgTypedefType* typedefType = NULL;
8864
8865 while (currentType != NULL)
8866 {
8867 returnString += currentType->class_name();
8868 if ( (bit_array & SgType::STRIP_MODIFIER_TYPE) && (modType = isSgModifierType(currentType)) )
8869 {
8870 currentType = modType->get_base_type();
8871 }
8872 else if ( (bit_array & SgType::STRIP_REFERENCE_TYPE) && (refType = isSgReferenceType(currentType)) )
8873 {
8874 currentType = refType->get_base_type();
8875 }
8876 else if ( (bit_array & SgType::STRIP_RVALUE_REFERENCE_TYPE) && (rRefType = isSgRvalueReferenceType(currentType)) )
8877 {
8878 currentType = rRefType->get_base_type();
8879 }
8880 else if ( (bit_array & SgType::STRIP_POINTER_TYPE) && (pointType = isSgPointerType(currentType)) )
8881 {
8882 currentType = pointType->get_base_type();
8883 }
8884 else if ( (bit_array & SgType::STRIP_ARRAY_TYPE) && (arrayType = isSgArrayType(currentType)) )
8885 {
8886 currentType = arrayType->get_base_type();
8887 }
8888 else if ( (bit_array & SgType::STRIP_TYPEDEF_TYPE) && (typedefType = isSgTypedefType(currentType)) )
8889 {
8890 currentType = typedefType->get_base_type();
8891 }
8892 else
8893 {
8894 break;
8895 }
8896
8897 if (type != NULL)
8898 returnString += " , ";
8899 }
8900
8901 return returnString;
8902 }
8903
8904// DQ (7/29/2010): Changed return type from SgType to SgModifierType
8907 {
8908 ROSE_ASSERT(base_type != NULL);
8909
8910 // DQ (1/30/2014): We need to include typedefs here as well (see test2014_77.c).
8911 // DQ (9/28/2012): Added that the base type could be an array (see test2012_03.c (C test code)).
8912 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type))
8913 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type))
8914 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type) && !isSgTypedefType(base_type))
8915 if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type) && !isSgTypedefType(base_type) && !isSgModifierType(base_type))
8916 {
8917 printf("ERROR: Base type of restrict type must be on a pointer or reference or array or typedef type: base_type = %p = %s \n",base_type,base_type->class_name().c_str());
8918 printf (" --- generate_type_list() = %s \n",generate_type_list(base_type).c_str());
8919 ROSE_ABORT();
8920 }
8921
8922 SgModifierType* result = new SgModifierType(base_type);
8923 ASSERT_not_null(result);
8924 result->get_typeModifier().setRestrict();
8925
8926 // DQ (7/29/2010): Insert result type into type table and return it, or
8927 // replace the result type, if already available in the type table, with
8928 // the type from type table.
8929 SgModifierType* result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8930 if (result != result2) {
8931 delete result;
8932 }
8933 return result2;
8934 }
8935
8936namespace
8937{
8938 // PP (2/16/24): model builder function after buildRestrictType
8940 _buildModifierType(SgType* base_type, std::function<void(SgModifierType*)> setModifiers)
8941 {
8942 ASSERT_not_null(base_type);
8943
8944 SgModifierType* result = new SgModifierType(base_type);
8945 setModifiers(result);
8946
8947 SgModifierType* result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8948 if (result != result2) delete result;
8949
8950 return result2;
8951 }
8952}
8953
8955 {
8956 auto op = [](SgModifierType* ty) { ty->get_typeModifier().setAliased(); };
8957
8958 return _buildModifierType(base_type, op);
8959 }
8960
8962 {
8963 auto op = [](SgModifierType* ty) { ty->get_typeModifier().setNotNull(); };
8964
8965 return _buildModifierType(base_type, op);
8966 }
8967
8968
8969// DQ (7/29/2010): Changed return type from SgType to SgModifierType
8972 {
8973 ROSE_ASSERT(base_type != NULL);
8974
8975 SgModifierType *result = new SgModifierType(base_type);
8976 ROSE_ASSERT(result!=NULL);
8977 result->get_typeModifier().get_upcModifier().set_modifier(SgUPC_AccessModifier::e_upc_strict);
8978
8979 // DQ (7/29/2010): Insert result type into type table and return it, or
8980 // replace the result type, if already available in the type table, with
8981 // the type from type table.
8982 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8983 if (result != result2) {
8984 delete result;
8985 }
8986 return result2;
8987 }
8988
8989// DQ (7/29/2010): Changed return type from SgType to SgModifierType
8992 {
8993 ROSE_ASSERT(base_type != NULL);
8994
8995 SgModifierType *result = new SgModifierType(base_type);
8996 ROSE_ASSERT(result!=NULL);
8997 result->get_typeModifier().get_upcModifier().set_modifier(SgUPC_AccessModifier::e_upc_relaxed);
8998
8999 // DQ (7/29/2010): Insert result type into type table and return it, or
9000 // replace the result type, if already available in the type table, with
9001 // the type from type table.
9002 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9003 if (result != result2) {
9004 delete result;
9005 }
9006 return result2;
9007 }
9008
9009// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9011SgModifierType* SageBuilder::buildUpcSharedType(SgType* base_type /*=NULL*/, long layout /*= -1*/)
9012 {
9013 ROSE_ASSERT(base_type != NULL);
9014
9015 SgModifierType *result = new SgModifierType(base_type);
9016 ROSE_ASSERT(result!=NULL);
9017
9018 result->get_typeModifier().get_upcModifier().set_isShared(true);
9019 result->get_typeModifier().get_upcModifier().set_layout(layout); // No layout ("shared" without a block size)
9020
9021 // DQ (7/29/2010): Insert result type into type table and return it, or
9022 // replace the result type, if already available in the type table, with
9023 // the type from type table.
9024 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9025 if (result != result2) {
9026 delete result;
9027 }
9028 return result2;
9029 }
9030
9031// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9034 {
9035 ROSE_ASSERT(base_type != NULL);
9036
9037 SgModifierType* result = isSgModifierType(buildUpcSharedType(base_type));
9038 ROSE_ASSERT(result != NULL);
9039 result->get_typeModifier().get_upcModifier().set_layout(0); // [] layout
9040
9041 // DQ (7/29/2010): Insert result type into type table and return it, or
9042 // replace the result type, if already available in the type table, with
9043 // the type from type table.
9044 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9045 return result;
9046 }
9047
9048// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9051 {
9052 ROSE_ASSERT(base_type != NULL);
9053
9054 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9055 ROSE_ASSERT(result!=NULL);
9056 result->get_typeModifier().get_upcModifier().set_layout(-2); // [*] layout
9057
9058 // DQ (7/29/2010): Insert result type into type table and return it, or
9059 // replace the result type, if already available in the type table, with
9060 // the type from type table.
9061 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9062 return result;
9063 }
9064
9065// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9068 {
9069 ROSE_ASSERT(base_type != NULL);
9070
9071 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9072 ROSE_ASSERT(result!=NULL);
9073 result->get_typeModifier().get_upcModifier().set_layout(block_factor); // [block_factor] layout
9074
9075 // DQ (7/29/2010): Insert result type into type table and return it, or
9076 // replace the result type, if already available in the type table, with
9077 // the type from type table.
9078 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9079 return result;
9080 }
9081
9084{
9085 ROSE_ASSERT(base_type != NULL);
9086 SgTypeComplex *result = new SgTypeComplex(base_type);
9087 ROSE_ASSERT(result!=NULL);
9088 return result;
9089}
9090
9093{
9094 ROSE_ASSERT(base_type != NULL);
9095 SgTypeImaginary *result = new SgTypeImaginary(base_type);
9096 ROSE_ASSERT(result!=NULL);
9097 return result;
9098}
9099
9102{
9103 SgTypeMatrix *result = new SgTypeMatrix();
9104 ROSE_ASSERT(result != NULL);
9105 return result;
9106}
9107
9110{
9111 SgTypeTuple *result = new SgTypeTuple();
9112 ROSE_ASSERT(result != NULL);
9113
9114 if(t1) result->append_type(t1);
9115 if(t2) result->append_type(t2);
9116 if(t3) result->append_type(t3);
9117 if(t4) result->append_type(t4);
9118 if(t5) result->append_type(t5);
9119 if(t6) result->append_type(t6);
9120 if(t7) result->append_type(t7);
9121 if(t8) result->append_type(t8);
9122 if(t9) result->append_type(t9);
9123 if(t10) result->append_type(t10);
9124
9126
9127 return result;
9128}
9129
9132 SgNonrealDecl * nrdecl = buildNonrealDecl(name, scope);
9133 nrdecl->set_parent(scope);
9134 nrdecl->set_is_template_param (true);
9135 return nrdecl->get_type();
9136}
9137
9139{
9140 SgRangeExp *result = new SgRangeExp();
9142 ROSE_ASSERT(result != NULL);
9143
9144 result->append(start);
9145 return result;
9146}
9147
9149{
9150 SgRangeExp *result = new SgRangeExp();
9152 ROSE_ASSERT(result != NULL);
9153
9154 result->set_start(start);
9155 start->set_parent(result);
9156
9157 result->set_end(end);
9158 end->set_parent(result);
9159
9160 result->set_stride(stride);
9161 stride->set_parent(result);
9162 return result;
9163}
9164
9165
9167{
9168 SgMatrixExp *result = new SgMatrixExp();
9170
9171 result->append_expression(firstRow);
9172 ROSE_ASSERT(result != NULL);
9173
9174 return result;
9175}
9176
9178{
9179 SgMagicColonExp *result = new SgMagicColonExp();
9181
9182 ROSE_ASSERT(result != NULL);
9183
9184 return result;
9185}
9186
9189{
9190 SgConstVolatileModifier * result = NULL;
9191 result = new SgConstVolatileModifier();
9192 ROSE_ASSERT (result != NULL);
9193 result->set_modifier (mtype);
9194
9195 return result;
9196}
9197
9201 {
9202 // SgFunctionDeclaration* func_decl = buildDefiningFunctionDeclaration("__rose__lambda__",return_type,params,scope,NULL,NULL);
9203 SgFunctionDeclaration* func_decl = buildDefiningFunctionDeclaration("__rose__lambda__",return_type,params,scope,NULL,false,NULL,NULL);
9204
9205 SgLambdaRefExp* result = new SgLambdaRefExp(func_decl);
9206 func_decl->set_parent(result);
9207
9209
9210 return result;
9211 }
9212
9215 {
9216 SgTypeExpression *expr = new SgTypeExpression(type);
9218 return expr;
9219 }
9220
9221// DQ (8/11/2014): Added support for C++11 decltype used in new function return syntax.
9223SageBuilder::buildFunctionParameterRefExp(int parameter_number, int parameter_level )
9224 {
9225 SgFunctionParameterRefExp *expr = new SgFunctionParameterRefExp(NULL,parameter_number,parameter_level);
9226 ROSE_ASSERT(expr != NULL);
9227
9228 setSourcePosition(expr);
9229 return expr;
9230 }
9231
9232
9233// DQ (8/11/2014): Added support for C++11 decltype used in new function return syntax.
9235SageBuilder::buildFunctionParameterRefExp_nfi(int parameter_number, int parameter_level )
9236 {
9237 SgFunctionParameterRefExp *expr = new SgFunctionParameterRefExp(NULL,parameter_number,parameter_level);
9238 ROSE_ASSERT(expr != NULL);
9239
9241 return expr;
9242 }
9243
9244// DQ (9/3/2014): Adding support for C++11 Lambda expressions
9246SageBuilder::buildLambdaExp(SgLambdaCaptureList* lambda_capture_list, SgClassDeclaration* lambda_closure_class, SgFunctionDeclaration* lambda_function)
9247 {
9248 SgLambdaExp *expr = new SgLambdaExp(lambda_capture_list,lambda_closure_class,lambda_function);
9249 ROSE_ASSERT(expr != NULL);
9250
9251 // Set the parents
9252 if (lambda_capture_list != NULL)
9253 {
9254 lambda_capture_list->set_parent(expr);
9255 }
9256
9257 if (lambda_closure_class != NULL)
9258 {
9259 lambda_closure_class->set_parent(expr);
9260 }
9261
9262 if (lambda_function != NULL)
9263 {
9264#if 1
9265 lambda_function->set_parent(expr);
9266#else
9267 if (lambda_closure_class != NULL)
9268 {
9269 lambda_function->set_parent(lambda_closure_class);
9270 }
9271 else
9272 {
9273 printf ("Warning: In SageBuilder::buildLambdaExp(): lambda_closure_class == NULL: lambda_function parent not set! \n");
9274 }
9275#endif
9276 }
9277
9278 setSourcePosition(expr);
9279 return expr;
9280 }
9281
9283SageBuilder::buildLambdaExp_nfi(SgLambdaCaptureList* lambda_capture_list, SgClassDeclaration* lambda_closure_class, SgFunctionDeclaration* lambda_function)
9284 {
9285 SgLambdaExp *expr = new SgLambdaExp(lambda_capture_list,lambda_closure_class,lambda_function);
9286 ROSE_ASSERT(expr != NULL);
9287
9288 // Set the parents
9289 if (lambda_capture_list != NULL)
9290 {
9291 lambda_capture_list->set_parent(expr);
9292 }
9293
9294 if (lambda_closure_class != NULL)
9295 {
9296 lambda_closure_class->set_parent(expr);
9297 }
9298
9299 if (lambda_function != NULL)
9300 {
9301#if 1
9302 lambda_function->set_parent(expr);
9303#else
9304#endif
9305 }
9306
9308 return expr;
9309 }
9310
9312SageBuilder::buildLambdaCapture(SgExpression* capture_variable, SgExpression* source_closure_variable, SgExpression* closure_variable)
9313 {
9314 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9315 ROSE_ASSERT(lambdaCapture != NULL);
9316
9317 setSourcePosition(lambdaCapture);
9318 return lambdaCapture;
9319 }
9320
9322SageBuilder::buildLambdaCapture_nfi(SgExpression* capture_variable, SgExpression* source_closure_variable, SgExpression* closure_variable)
9323 {
9324 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9325 ROSE_ASSERT(lambdaCapture != NULL);
9326
9327 setOneSourcePositionNull(lambdaCapture);
9328 return lambdaCapture;
9329 }
9330
9333 {
9334 SgLambdaCaptureList *lambdaCaptureList = new SgLambdaCaptureList(NULL);
9335 ROSE_ASSERT(lambdaCaptureList != NULL);
9336
9337 setSourcePosition(lambdaCaptureList);
9338 return lambdaCaptureList;
9339 }
9340
9343 {
9344 SgLambdaCaptureList *lambdaCaptureList = new SgLambdaCaptureList(NULL);
9345 ROSE_ASSERT(lambdaCaptureList != NULL);
9346
9347 setOneSourcePositionNull(lambdaCaptureList);
9348 return lambdaCaptureList;
9349 }
9350
9351// DQ (7/25/2020): Adding C++17 support
9353SageBuilder::buildFoldExpression(SgExpression* operands, string operator_token_string, bool is_left_associative)
9354 {
9355 SgFoldExpression* result = new SgFoldExpression(NULL,operands,operator_token_string,is_left_associative);
9356 ROSE_ASSERT(result != NULL);
9357
9359 return result;
9360 }
9361
9363SageBuilder::buildFoldExpression_nfi(SgExpression* operands, string operator_token_string, bool is_left_associative)
9364 {
9365 SgFoldExpression* result = new SgFoldExpression(NULL,operands,operator_token_string,is_left_associative);
9366 ROSE_ASSERT(result != NULL);
9367
9369 return result;
9370 }
9371
9372// DQ (7/25/2020): Adding C++20 support
9375 {
9376 SgAwaitExpression* result = new SgAwaitExpression(NULL,NULL);
9377 ROSE_ASSERT(result != NULL);
9378
9380 return result;
9381 }
9384 {
9385 SgAwaitExpression* result = new SgAwaitExpression(NULL,NULL);
9386 ROSE_ASSERT(result != NULL);
9387
9389 return result;
9390 }
9391
9392// DQ (7/25/2020): Adding C++20 support
9395 {
9396 SgChooseExpression* result = new SgChooseExpression(NULL,NULL);
9397 ROSE_ASSERT(result != NULL);
9398
9400 return result;
9401 }
9402
9405 {
9406 SgChooseExpression* result = new SgChooseExpression(NULL,NULL);
9407 ROSE_ASSERT(result != NULL);
9408
9410 return result;
9411 }
9412
9413
9414
9417 {
9418 SgNamespaceDefinitionStatement* result = NULL;
9419 if (d!=NULL) // the constructor does not check for NULL d, causing segmentation fault
9420 {
9421 result = new SgNamespaceDefinitionStatement(d);
9422 result->set_parent(d); // set_declaration() == set_parent() in this case
9423 }
9424 else
9425 {
9426 result = new SgNamespaceDefinitionStatement(d);
9427 }
9428
9429 ROSE_ASSERT(result);
9430
9432 return result;
9433 }
9434
9437{
9438 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
9439 SageInterface::setSourcePosition(nonreal_decl_scope);
9440 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
9441 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
9442 return nonreal_decl_scope;
9443}
9444
9446SageBuilder::buildClassDefinition(SgClassDeclaration *d/*= NULL*/, bool buildTemplateInstantiation )
9447 {
9448 SgClassDefinition* result = NULL;
9449 if (d != NULL) // the constructor does not check for NULL d, causing segmentation fault
9450 {
9451 // result->set_parent(d); // set_declaration() == set_parent() in this case
9452 // result = new SgClassDefinition(d);
9453 ROSE_ASSERT(buildTemplateInstantiation == false || isSgTemplateInstantiationDecl(d) != NULL);
9454 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn(isSgTemplateInstantiationDecl(d)) : new SgClassDefinition(d);
9455 }
9456 else
9457 {
9458 // result = new SgClassDefinition();
9459 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn() : new SgClassDefinition();
9460 }
9461
9462 ROSE_ASSERT(result);
9463
9464 // CR (3/22/2020): Fixed setting case insensitivity
9465 // if (symbol_table_case_insensitive_semantics == true)
9467 {
9468 result->setCaseInsensitive(true);
9469 }
9470
9472
9473 return result;
9474 }
9475
9476
9477
9479SageBuilder::buildClassDefinition_nfi(SgClassDeclaration *d/*= NULL*/, bool buildTemplateInstantiation )
9480 {
9481 SgClassDefinition* result = NULL;
9482 if (d!=NULL) // the constructor does not check for NULL d, causing segmentation fault
9483 {
9484 // result->set_parent(d); // set_declaration() == set_parent() in this case
9485 // result = new SgClassDefinition(d);
9486 ROSE_ASSERT(buildTemplateInstantiation == false || isSgTemplateInstantiationDecl(d) != NULL);
9487 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn(isSgTemplateInstantiationDecl(d)) : new SgClassDefinition(d);
9488 }
9489 else
9490 {
9491 // result = new SgClassDefinition();
9492 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn() : new SgClassDefinition();
9493 }
9494
9495 ROSE_ASSERT(result);
9496
9497 // CR (3/22/2020): Fixed setting case insensitivity
9498 // if (symbol_table_case_insensitive_semantics == true)
9500 result->setCaseInsensitive(true);
9501
9503 return result;
9504 }
9505
9506
9508SageBuilder::buildNondefiningClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList)
9509 {
9510 SgName nameWithoutTemplateArguments = XXX_name;
9511
9512 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
9513
9514 // SgClassDeclaration* nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
9515 SgClassDeclaration* nondefdecl = NULL;
9516
9517#define DEBUG_NONDEFINING_CLASS_DECLARATION 0
9518
9519 // DQ (11/26/2011): Debugging EDG 3.3 use of templateArguments.
9520#if DEBUG_NONDEFINING_CLASS_DECLARATION
9521 printf ("Building a SgClassDeclaration: buildNondefiningClassDeclaration_nfi() nameWithoutTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithoutTemplateArguments.str(),buildTemplateInstantiation ? "true:" : "false");
9522 printf (" --- scope = %p = %s \n",scope,(scope != NULL) ? scope->class_name().c_str() : "null");
9523#endif
9524
9525 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
9526 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
9527 ROSE_ASSERT(SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == false);
9528
9529 if (buildTemplateInstantiation == true)
9530 {
9531 ROSE_ASSERT(templateArgumentsList != NULL);
9532 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
9533
9534#if DEBUG_NONDEFINING_CLASS_DECLARATION
9535 printf ("Building a SgClassDeclaration: buildNondefiningClassDeclaration_nfi() nameWithTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithTemplateArguments.str(),buildTemplateInstantiation ? "true:" : "false");
9536#endif
9537
9538 // SgTemplateInstantiationDecl (SgName name, SgClassDeclaration::class_types class_type, SgClassType *type, SgClassDefinition *definition, SgTemplateDeclaration *templateDeclaration, SgTemplateArgumentPtrList templateArguments)
9539 SgTemplateArgumentPtrList emptyList;
9540 // nondefdecl = new SgTemplateInstantiationDecl(name,kind,NULL,NULL,NULL,emptyList);
9541 nondefdecl = new SgTemplateInstantiationDecl(nameWithTemplateArguments,kind,NULL,NULL,NULL,emptyList);
9542#if DEBUG_NONDEFINING_CLASS_DECLARATION
9543 printf ("In buildNondefiningClassDeclaration_nfi(): built new SgTemplateInstantiationDecl: nondefdecl = %p \n",nondefdecl);
9544#endif
9545 ROSE_ASSERT(nondefdecl->get_type() == NULL);
9546 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl) != NULL);
9547#if DEBUG_NONDEFINING_CLASS_DECLARATION
9548 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_name() = %s nondefdecl->get_templateName() = %s \n",
9549 nondefdecl->get_name().str(),isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().str());
9550#endif
9551 // DQ (6/6/2012): Added support for template arguments so that they can be a part of any generated type.
9552 ROSE_ASSERT(templateArgumentsList != NULL);
9553
9554#if DEBUG_NONDEFINING_CLASS_DECLARATION
9555 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
9556 printf ("nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
9557 printf ("Output templateArgumentsList: \n");
9558 for (size_t i = 0; i < templateArgumentsList->size(); i++)
9559 {
9560 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
9561 printf (" --- --- name = %s \n",unparseTemplateArgumentToString(templateArgumentsList->operator[](i)).str());
9562 }
9563#endif
9564
9565 ROSE_ASSERT(nondefdecl->get_name() == nameWithTemplateArguments);
9566 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == true);
9567 isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(nameWithoutTemplateArguments);
9568 }
9569 else
9570 {
9571 nondefdecl = new SgClassDeclaration(nameWithoutTemplateArguments,kind,NULL,NULL);
9572#if DEBUG_NONDEFINING_CLASS_DECLARATION
9573 printf ("In buildNondefiningClassDeclaration_nfi(): built new SgClassDeclaration: nondefdecl = %p \n",nondefdecl);
9574#endif
9575 // The default name for nameWithTemplateArguments is nameWithoutTemplateArguments so that we can use
9576 // nameWithTemplateArguments uniformally as the name of the function and it will work from non-template
9577 // instantiations.
9578 ROSE_ASSERT(nameWithoutTemplateArguments == nameWithTemplateArguments);
9579 }
9580
9581 ROSE_ASSERT(nondefdecl != NULL);
9582 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
9583 ROSE_ASSERT(nondefdecl->get_type() == NULL);
9584
9585 // The non-defining declaration asociated with a declaration does not have a
9586 // source position...unless it is the position of the defining declaration.
9587 // setOneSourcePositionNull(nondefdecl);
9588 setSourcePosition(nondefdecl);
9589
9590 // This is find for now, but a little later in this function (if we can find a symbol)
9591 // we want to find the first non-defining declaration (using the symbol table) and use
9592 // that as a paramter to "nondefdecl->set_firstNondefiningDeclaration()".
9593 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
9594 nondefdecl->set_definingDeclaration(NULL);
9595 nondefdecl->setForward();
9596
9597 // This is the structural parent (the logical scope can be different than the parent).
9598 // TPS (09/18/2009) added a condition to be able to build this properly
9599 if (scope == NULL)
9600 nondefdecl->set_parent(topScopeStack());
9601 else
9602 nondefdecl->set_parent(scope);
9603
9604 // This is the logical scope...
9605 nondefdecl->set_scope(scope);
9606
9607 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
9608
9609 SgClassDeclaration* firstNondefdecl = NULL;
9610 if (scope != NULL)
9611 {
9612#if 0
9613#error "DEAD CODE"
9614#else
9615 SgClassSymbol* mysymbol = scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
9616
9617#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
9618 printf ("In SageBuilder::buildNondefiningClassDeclaration(): mysymbol = %p = %s \n",mysymbol,(mysymbol != NULL) ? mysymbol->class_name().c_str() : "null");
9619#endif
9620 if (mysymbol != NULL)
9621 {
9622 firstNondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
9623 ROSE_ASSERT(firstNondefdecl != NULL);
9624
9625 ROSE_ASSERT(firstNondefdecl->get_type() != NULL);
9626
9627 // DQ (3/22/2012): Now we can built the type and have it use the same nondefining declaration as from the symbol (required to match).
9628 ROSE_ASSERT(nondefdecl->get_type() == NULL);
9629
9630 if (nondefdecl->get_type() == NULL)
9631 {
9632#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
9633 printf ("In SageBuilder::buildNondefiningClassDeclaration(): Why are we creating a new type instead of reusing the type (firstNondefdecl->get_type() = %p) from the firstNondefdecl = %p \n",firstNondefdecl->get_type(),firstNondefdecl);
9634#endif
9635 // Note: It would be better to just call: "nondefdecl->set_type(firstNondefdecl->get_type());"
9636#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
9637 printf ("NOTE: Call nondefdecl->set_type(firstNondefdecl->get_type()); instead of nondefdecl->set_type(SgClassType::createType(firstNondefdecl)); \n");
9638#endif
9639 nondefdecl->set_type(SgClassType::createType(firstNondefdecl));
9640 ROSE_ASSERT(nondefdecl->get_type() != NULL);
9641
9642#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
9643 printf ("In SageBuilder::buildNondefiningClassDeclaration(): nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
9644#endif
9645 ROSE_ASSERT(nondefdecl->get_type() == firstNondefdecl->get_type());
9646 }
9647
9648#if (REUSE_CLASS_DECLARATION_FROM_SYMBOL == 0)
9649 ROSE_ASSERT(nondefdecl != NULL);
9650 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
9651
9652 // DQ (5/18/2014): Added test to match that in set_firstNondefiningDeclaration().
9653 // This is a problem for the Boost code after the fix to detec templates vs. template instantiation declarations.
9654 if (nondefdecl->variantT() != firstNondefdecl->variantT())
9655 {
9656 printf ("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): nondefdecl = %p = %s IS NOT THE SAME AS firstNondefiningDeclaration = %p = %s \n",
9657 nondefdecl,nondefdecl->class_name().c_str(),firstNondefdecl,firstNondefdecl->class_name().c_str());
9658 ROSE_ASSERT(nondefdecl->get_file_info() != NULL);
9659 nondefdecl->get_file_info()->display("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): nondefdecl: debug");
9660 ROSE_ASSERT(firstNondefdecl->get_file_info() != NULL);
9661 firstNondefdecl->get_file_info()->display("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): firstNondefdecl: debug");
9662 }
9663
9664 // DQ (5/18/2014): Added test to match that in set_firstNondefiningDeclaration().
9665 ROSE_ASSERT(nondefdecl->variantT() == firstNondefdecl->variantT());
9666
9667 nondefdecl->set_firstNondefiningDeclaration(firstNondefdecl);
9668
9669 // This might be NULL if the defining declaration has not been seen yet!
9670 nondefdecl->set_definingDeclaration(firstNondefdecl->get_definingDeclaration());
9671
9672 // DQ (3/22/2012): New assertions.
9673 ROSE_ASSERT(firstNondefdecl != NULL);
9674 ROSE_ASSERT(firstNondefdecl->get_type() != NULL);
9675
9676 // DQ (9/16/2012): This is a newly refactored function (call this after we know the firstNondefiningDeclaration is set correctly).
9677 // This is called in the other branch (mysymbol == NULL), but there is must be called before the symbol table is appended with
9678 // the new symbol for this declaration. So we have to call this in this brach and re can't refactor this be be called one before
9679 // both branches or once after both branches.
9680 if (buildTemplateInstantiation == true)
9681 {
9682 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
9683 }
9684
9685 // DQ (9/4/2012): We can now assert this because of how the type is constructed above.
9686 ROSE_ASSERT (nondefdecl->get_type() == firstNondefdecl->get_type());
9687
9688 // Share the type!
9689 if (nondefdecl->get_type() != firstNondefdecl->get_type())
9690 {
9691 // Remove the type from the new SgClassDeclaration and set the reference to the type in the firstNondefiningDeclaration.
9692 printf ("Deleting type in associated non-defining declaration (sharing type) nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
9693 printf ("Skipping delete of %p so we can maintain unique type pointers \n",nondefdecl->get_type());
9694 // delete nondefdecl->get_type();
9695 printf ("Setting the new type to be from firstNondefdecl = %p (sharing type) firstNondefdecl->get_type() = %p = %s \n",firstNondefdecl,firstNondefdecl->get_type(),firstNondefdecl->get_type()->class_name().c_str());
9696 nondefdecl->set_type(firstNondefdecl->get_type());
9697#if 1
9698 // DQ (12/13/2011): Is this executed!
9699 printf ("Unclear if this code is executed \n");
9700 ROSE_ABORT();
9701#endif
9702 }
9703#else
9704#error "DEAD CODE"
9705
9706 ROSE_ASSERT(nondefdecl == NULL);
9707#endif
9708 // This function should return a new nondefining declaration each time (to support multile class prototypes!).
9709 // nondefdecl = firstNondefdecl;
9710 }
9711 else
9712 {
9713#if REUSE_CLASS_DECLARATION_FROM_SYMBOL
9714 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
9715
9716#error "DEAD CODE"
9717
9718 nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
9719
9720#error "DEAD CODE"
9721
9722 ROSE_ASSERT(nondefdecl != NULL);
9723 if (nondefdecl->get_type() == NULL)
9724 nondefdel->set_type(SgClassType::createType(nondefdecl));
9725
9726 printf ("SageBuilder::buildNondefiningClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
9727
9728 setOneSourcePositionNull(nondefdecl);
9729
9730#error "DEAD CODE"
9731
9732 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
9733 nondefdecl->set_definingDeclaration(NULL);
9734 nondefdecl->setForward();
9735#endif
9736
9737 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
9738
9739 mysymbol = new SgClassSymbol(nondefdecl);
9740 firstNondefdecl = nondefdecl;
9741
9742 // DQ (6/9/2013): Adding assertions to make sure that symbols only reference non-defining declarations.
9743 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
9744 ROSE_ASSERT(mysymbol->get_declaration()->get_definition() == NULL);
9745
9746 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
9747 // Note that since the symbol tables use the template arguments associated with the declaration it is best to
9748 // fixup the template arguments before the symbol table is fixup to have a symbol for this declaration. So we
9749 // fixup the template arguments here (just after we know that the firstNondefiningDeclaration is set correctly
9750 // and just before the symbol is inserted into the symbol table.
9751 if (buildTemplateInstantiation == true)
9752 {
9753 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
9754 }
9755#if DEBUG_NONDEFINING_CLASS_DECLARATION
9756 printf ("BEFORE scope->insert_symbol(): scope = %p = %s nameWithTemplateArguments = %s mysymbol = %p = %s \n",
9757 scope,scope->class_name().c_str(),nameWithTemplateArguments.str(),mysymbol,mysymbol->class_name().c_str());
9758#endif
9759
9760 // scope->insert_symbol(name, mysymbol);
9761 scope->insert_symbol(nameWithTemplateArguments, mysymbol);
9762
9763 // DQ (3/22/2012): Now we can built the type and have it use the same nondefining declaration as from the symbol (required to match).
9764 ROSE_ASSERT(nondefdecl->get_type() == NULL);
9765 if (nondefdecl->get_type() == NULL)
9766 {
9767 nondefdecl->set_type(SgClassType::createType(nondefdecl));
9768 }
9769
9770#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
9771 printf ("NOTE: In buildNondefiningClassDeclaration_nfi(): 2nd time this is a performance issue (maybe) to call the lookup_nontemplate_class_symbol() again \n");
9772#endif
9773 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would
9774 // not include name qualification on template arguments.
9775 // DQ (12/27/2011): Added new test.
9776 // ROSE_ASSERT(scope->lookup_nontemplate_class_symbol(name) != NULL);
9777 // TV (07/01/2013): this assertion fail when building basic class (buildTemplateInstantiation = false , templateArgumentsList = NULL)
9778 // ROSE_ASSERT(scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
9779
9780 // DQ (6/9/2013): Added test to make sure that symbols only reference non-defining declarations.
9781 SgClassSymbol* temp_classSymbol = nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
9782#if DEBUG_NONDEFINING_CLASS_DECLARATION
9783 // DQ (12/28/2018): When can this be NULL?
9784 printf ("In buildNondefiningClassDeclaration_nfi(): temp_classSymbol = %p \n",temp_classSymbol);
9785 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_scope() = %p = %s scope = %p \n",nondefdecl->get_scope(),nondefdecl->get_scope()->class_name().c_str(),scope);
9786
9787 printf ("In buildNondefiningClassDeclaration_nfi(): nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
9788 if (templateArgumentsList != NULL)
9789 {
9790 printf (" --- templateArgumentsList elements: \n");
9791 for (size_t i = 0; i < templateArgumentsList->size(); i++)
9792 {
9793 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
9794 printf (" --- --- templateArgumentsList->[%zu] = %s \n",i,templateArgumentsList->operator[](i)->class_name().c_str());
9795 templateArgumentsList->operator[](i)->display("In SageBuilder::buildNondefiningClassDeclaration_nfi()");
9796 }
9797 }
9798#endif
9799 // DQ (12/28/2018): When can this be NULL? When we call lookup_class_symbol() later it is NULL, so test it here.
9800 ROSE_ASSERT(nondefdecl->get_scope()->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
9801 ROSE_ASSERT(nondefdecl->get_scope() == scope);
9802
9803 // TV (07/01/2013): temp_classSymbol can be NULL, but lookup_class_symbol return a symbol
9804 // ROSE_ASSERT(temp_classSymbol->get_declaration()->get_definition() == NULL);
9805 ROSE_ASSERT(temp_classSymbol == NULL || temp_classSymbol->get_declaration()->get_definition() == NULL);
9806 }
9807
9808 ROSE_ASSERT(mysymbol != NULL);
9809 ROSE_ASSERT(firstNondefdecl != NULL);
9810#endif
9811 nondefdecl->set_scope(scope);
9812
9813 // DQ (1/25/2009): The scope is not the same as the parent, since the scope is logical, and the parent is structural (note that topScopeStack() is structural).
9814 // TPS (09/18/2009) added a condition to be able to build this properly
9815 if (scope==NULL)
9816 nondefdecl->set_parent(topScopeStack());
9817 else
9818 nondefdecl->set_parent(scope);
9819 }
9820
9821 // The support for SgEnumDeclaration handles the type, but why not for SgClassDeclaration?
9822 ROSE_ASSERT(nondefdecl->get_type() != NULL);
9823
9824 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
9825
9826#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
9827 printf ("NOTE: In buildNondefiningClassDeclaration_nfi(): 3rd time this is a performance issue (maybe) to call the lookup_nontemplate_class_symbol() again \n");
9828#endif
9829
9830 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would not include name qualification on template arguments.
9831 // DQ (12/27/2011): Added new test.
9832 // ROSE_ASSERT(nondefdecl->get_scope()->lookup_nontemplate_class_symbol(name) != NULL);
9833 // TV (07/01/2013): this assertion fail when building basic class (buildTemplateInstantiation = false , templateArgumentsList = NULL)
9834 // ROSE_ASSERT(nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
9835
9836 // DQ (6/9/2013): Added test to make sure that symbols only reference non-defining declarations.
9837 SgClassSymbol* temp_classSymbol = nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
9838 // TV (07/01/2013): temp_classSymbol can be NULL, but lookup_class_symbol return a symbol
9839 ROSE_ASSERT(temp_classSymbol == NULL || temp_classSymbol->get_declaration()->get_definition() == NULL);
9840
9841 ROSE_ASSERT(nondefdecl != NULL);
9842 ROSE_ASSERT(nondefdecl->get_name() == nameWithTemplateArguments);
9843
9844 // DQ (3/9/2018): Test the consistancy of the template instantiation name.
9845 if (isSgTemplateInstantiationDecl(nondefdecl) != NULL)
9846 {
9847 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(nondefdecl);
9848 SgName finalName = appendTemplateArgumentsToName(templateInstantiationDecl->get_templateName(),templateInstantiationDecl->get_templateArguments());
9849 ROSE_ASSERT(finalName == nameWithTemplateArguments);
9850 ROSE_ASSERT(finalName == nondefdecl->get_name());
9851 }
9852
9853#if DEBUG_NONDEFINING_CLASS_DECLARATION
9854 printf ("Leaving buildNondefiningClassDeclaration_nfi(): nondefdecl = %p nondefdecl->unparseNameToString() = %s \n",nondefdecl,nondefdecl->unparseNameToString().c_str());
9855 printf (" --- nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
9856#endif
9857
9858#if DEBUG_NONDEFINING_CLASS_DECLARATION
9859 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
9860 printf ("Leaving buildNondefiningClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
9861 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
9862
9863 printf ("test_symbol = %p \n",test_symbol);
9864
9865 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
9866 printf ("Leaving buildNondefiningClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
9867 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
9868#endif
9869
9870 return nondefdecl;
9871 }
9872
9875 ROSE_ASSERT(stmt != NULL);
9876
9878 stmt->set_parent(result);
9879
9880 result->set_definingDeclaration(result);
9882 return result;
9883}
9884
9887 ROSE_ASSERT(stmt != NULL);
9888
9890 stmt->set_parent(result);
9891
9892 result->set_definingDeclaration(result);
9894 return result;
9895}
9896
9898SageBuilder::buildJovialDefineDeclaration_nfi(const SgName& name, const std::string& params,
9899 const std::string& def_string, SgScopeStatement* scope)
9900 {
9901 std::string directive_string(name);
9902
9903 if (scope == NULL)
9905 ROSE_ASSERT(scope);
9906
9907 if (params.length() > 0)
9908 directive_string += " " + params;
9909
9910 directive_string += " " + def_string;
9911
9912 SgJovialDefineDeclaration* define_decl = new SgJovialDefineDeclaration(directive_string);
9913 ROSE_ASSERT(define_decl);
9915
9916 // The first nondefining declaration must be set
9917 define_decl->set_firstNondefiningDeclaration(define_decl);
9918 define_decl->set_parent(scope);
9919
9920 return define_decl;
9921 }
9922
9923// Build a Jovial loop statement. Two variants are FOR and WHILE.
9924// A loop body will be created and its parent set to the loop statement.
9927{
9928 SgJovialForThenStatement* forStmt{nullptr};
9929
9931
9932 forStmt = new SgJovialForThenStatement(nullptr, nullptr, nullptr, body);
9933 ASSERT_not_null(forStmt);
9934 setOneSourcePositionNull(forStmt);
9935
9936 body->set_parent(forStmt);
9937
9939 forStmt->setCaseInsensitive(true);
9940 }
9941
9942 return forStmt;
9943}
9944
9945// This should take a SgClassDeclaration::class_types kind parameter!
9947 {
9948 bool buildTemplateInstantiation = false;
9949 SgClassDeclaration* defdecl = buildClassDeclaration_nfi(name,SgClassDeclaration::e_struct,scope,NULL,buildTemplateInstantiation,NULL);
9950
9952 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
9954
9955 return defdecl;
9956 }
9957
9960 {
9962 SgDerivedTypeStatement* type_decl = buildClassDeclarationStatement_nfi <SgDerivedTypeStatement> (name, kind, scope);
9963
9965 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() != NULL);
9967
9968 return type_decl;
9969 }
9970
9973 {
9975 SgModuleStatement* module_stmt = buildClassDeclarationStatement_nfi <SgModuleStatement> (name, kind, scope);
9976
9978 ROSE_ASSERT(module_stmt->get_firstNondefiningDeclaration() != NULL);
9980
9981 return module_stmt;
9982 }
9983
9987 SgScopeStatement* scope /*=NULL*/)
9988 {
9989 SgJovialTableStatement* table_decl = buildClassDeclarationStatement_nfi <SgJovialTableStatement> (name, kind, scope);
9990
9992 ROSE_ASSERT(table_decl->get_firstNondefiningDeclaration() != NULL);
9994
9995 return table_decl;
9996 }
9997
10000 {
10001 std::string type_name(name);
10002 if (base_type) {
10003 // Mangle the name to make sure the table type and the base type don't have the same name
10004 type_name = "_table_of_" + type_name;
10005 // Add dim_info address if there are subscripts to ensure type is unique
10006 if (dim_info->get_expressions().size() > 0) {
10007 std::ostringstream address;
10008 address << (void const *)dim_info;
10009 type_name += "_" + address.str();
10010 }
10011 }
10012
10014 SgJovialTableStatement* table_decl = buildClassDeclarationStatement_nfi <SgJovialTableStatement> (type_name, kind, scope);
10015
10017 ROSE_ASSERT(table_decl->get_firstNondefiningDeclaration() != NULL);
10019
10020 // For a type declaration the parent of the nondefining declaration is the defining declaration
10021 SgClassDeclaration* nondef_decl = isSgClassDeclaration(table_decl->get_firstNondefiningDeclaration());
10022 ROSE_ASSERT(nondef_decl != NULL);
10023 nondef_decl->set_parent(table_decl);
10024
10025 SgJovialTableType* table_type = isSgJovialTableType(table_decl->get_type());
10026 ROSE_ASSERT(table_type != NULL);
10027
10028 table_type->set_base_type(base_type);
10029 table_type->set_dim_info(dim_info);
10030 table_type->set_rank(dim_info->get_expressions().size());
10031
10032 dim_info->set_parent(table_type);
10033 nondef_decl->set_type(table_type);
10034
10035 return table_type;
10036 }
10037
10039template <class DeclClass> DeclClass *
10041 SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl)
10042 {
10043 // DQ (3/15/2012): Added function to build C++ class (builds both the non-defining and defining declarations; in that order).
10044 // The implementation of this function could be simplified to directly call both:
10045 // SgClassDeclaration* buildNondefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10046 // and
10047 // SgClassDeclaration* buildDefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10048 // This might refactor the implementation nicely.
10049
10050 if (scope == NULL)
10051 {
10053 }
10054
10055 // Step 1. Build the nondefining declaration (but only if the input nonDefiningDecl pointer was NULL and it does not exist)
10056 // -----------------------------------------
10057 //
10058
10059 // Get the nondefining declaration from the symbol if it has been built (if this works,
10060 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
10061
10062 SgClassDeclaration* nondefdecl = NULL;
10063 SgClassSymbol* mysymbol = NULL;
10064
10065 if (scope != NULL)
10066 {
10067 // DQ (10/10/2015): look up the correct type of symbol.
10068 mysymbol = scope->lookup_class_symbol(name);
10069
10070 if (mysymbol == NULL)
10071 {
10072 // Note: this is an input parameter (could/should go away?) [CR]
10073 if (nonDefiningDecl != NULL)
10074 {
10075 // DQ (3/4/2018): I think this is the correct API to use (internal use only).
10076 SgSymbol* temp_mysymbol = nonDefiningDecl->get_symbol_from_symbol_table();
10077 ROSE_ASSERT(temp_mysymbol != NULL);
10078
10079 mysymbol = isSgClassSymbol(temp_mysymbol);
10080 ROSE_ASSERT(mysymbol != NULL);
10081
10082 // check that the scopes are the same.
10083 ROSE_ASSERT(scope == nonDefiningDecl->get_scope());
10084 }
10085 }
10086 }
10087
10088 if (mysymbol != NULL) // set links for existing nondefining declaration
10089 {
10090 nondefdecl = (mysymbol->get_declaration() == NULL)
10091 ? NULL : dynamic_cast<DeclClass*>(mysymbol->get_declaration());
10092 ROSE_ASSERT(nondefdecl != NULL);
10093
10094 // DQ (6/8/2013): This should not be true (see test2013_198.C).
10095 // Fundamentally the symbol should always only have a pointer to a non-defining
10096 // declaration, where by definition (get_definition() == NULL).
10097 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10098
10099 // DQ (9/16/2012): This should be true by definition (verify).
10100 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
10101
10102 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10103 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10104
10105 // DQ (9/7/2012): I think this might be the root of a problem in the haskell tests (ROSE compiling ROSE).
10106 if (nondefdecl->get_definingDeclaration() != NULL)
10107 {
10108 DeclClass* nondefining_classDeclaration = (nondefdecl == NULL) ? NULL : dynamic_cast<DeclClass*>(nondefdecl);
10109 ROSE_ASSERT(nondefining_classDeclaration != NULL);
10110 DeclClass* defining_classDeclaration = (nondefdecl->get_definingDeclaration() == NULL)
10111 ? NULL : dynamic_cast<DeclClass*>(nondefdecl->get_definingDeclaration());
10112 ROSE_ASSERT(defining_classDeclaration != NULL);
10113
10114 return defining_classDeclaration;
10115 }
10116 }
10117 else // build a nondefining declaration since it does not exist
10118 {
10119 ROSE_ASSERT(nondefdecl == NULL);
10120
10121 // DeclClass is the template type parameter
10122 nondefdecl = new DeclClass(name, kind, NULL, NULL);
10123 ROSE_ASSERT(nondefdecl != NULL);
10124
10125 // The first nondefining declaration has to be set before we generate the type.
10126 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10127
10128 // DQ (7/25/2017): This will be true, but it might not be what we want since it can be caught as an error in the code below.
10129 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
10130
10131 // DQ (3/14/2012): For C++ we need the scope set so that types will have proper locations to resolve them
10132 // from being ambiguous or not properly defined. Basically, we need a handle from which to generate something
10133 // that amounts to a kind of name qualification internally (maybe even exactly name qualification, but I would
10134 // have to think about that a bit more).
10135 ROSE_ASSERT(scope != NULL);
10136
10137 // Set the parent before calling the SgClassType::createType() as the name mangling will require it.
10138 // This is true for Fortran SgDerivedTypeStatement at least.
10139 nondefdecl->set_parent(scope);
10140 nondefdecl->set_scope(scope);
10141
10142 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
10143 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10144
10145 if (nondefdecl->get_type() == NULL)
10146 {
10147 SgClassType* class_type = NULL;
10148 switch (kind)
10149 {
10151 class_type = SgJavaParameterType::createType(nondefdecl);
10152 break;
10155 class_type = SgJovialTableType::createType(nondefdecl);
10156 break;
10157 default:
10158 class_type = SgClassType::createType(nondefdecl);
10159 break;
10160 }
10161 ROSE_ASSERT(class_type != NULL);
10162
10163 nondefdecl->set_type(class_type);
10164
10165 SgClassDeclaration* tmp_classDeclarationFromType = isSgClassDeclaration(class_type->get_declaration());
10166 ROSE_ASSERT(tmp_classDeclarationFromType != NULL);
10167 }
10168
10169 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10170 if (nondefdecl->get_type()->get_declaration() != nondefdecl)
10171 {
10172 printf ("ERROR: nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
10173 printf ("ERROR: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
10174 printf ("ERROR: nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
10175
10176 SgClassDeclaration* classDeclarationFromType = isSgClassDeclaration(nondefdecl->get_type()->get_declaration());
10177 ROSE_ASSERT(classDeclarationFromType != NULL);
10178
10179 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
10180 printf ("nondefdecl->get_type()->get_name() = %s \n",nondefdecl->get_type()->get_name().str());
10181 printf ("nondefdecl->get_type()->get_declaration()->get_name() = %s \n",classDeclarationFromType->get_name().str());
10182
10183 printf ("nondefdecl->get_mangled_name() = %s \n",nondefdecl->get_mangled_name().getString().c_str());
10184 printf ("nondefdecl->get_type()->get_mangled() = %s \n",nondefdecl->get_type()->get_mangled().getString().c_str());
10185 printf ("nondefdecl->get_type()->get_declaration()->get_mangled_name() = %s \n",classDeclarationFromType->get_mangled_name().getString().c_str());
10186
10187 // DQ (12/27/2018): Added additional debugging support.
10188 printf ("nondefdecl->get_type()->get_declaration()->get_firstNondefiningDeclaration() = %s \n",classDeclarationFromType->get_firstNondefiningDeclaration() ? "true" : "false");
10189 printf ("nondefdecl->get_firstNondefiningDeclaration() = %s \n",nondefdecl->get_firstNondefiningDeclaration() ? "true" : "false");
10190
10191 // DQ (12/27/2018): I think that if this is a base class declaration then it is OK for the type's declaration to not match.
10192 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10193 if (nondefdecl->get_parent() != NULL)
10194 {
10195 printf ("nondefdecl->get_parent() = %p = %s \n",nondefdecl->get_parent(),nondefdecl->get_parent()->class_name().c_str());
10196 }
10197 }
10198 ROSE_ASSERT(nondefdecl->get_type()->get_declaration() == nondefdecl);
10199
10200 // The nondefining declaration will not appear in the source code, but is compiler
10201 // generated (so we have something about the class that we can reference; e.g in
10202 // types). At the moment we make it a transformation, there might be another kind
10203 // of source position that would be more precise. FIXME.
10204 // setOneSourcePositionNull(nondefdecl);
10206 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
10207
10208#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
10209 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
10210 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
10211 {
10212 detectTransformations(nondefdecl);
10213 }
10214#endif
10215
10216 nondefdecl->setForward();
10217
10218 if (scope != NULL)
10219 {
10220 mysymbol = new SgClassSymbol(nondefdecl);
10221 scope->insert_symbol(name, mysymbol);
10222
10223 ROSE_ASSERT(nondefdecl->get_scope() == scope);
10224 }
10225 }
10226
10227 // DQ (3/15/2012): I have moved construction of defining declaration to be AFTER the nondefining declaration!
10228 // This is a better organization ans also should make sure that the declaration in the SgClassType will
10229 // properly reference the firstNondefiningDeclaration (instead of the defining declaration).
10230
10231 // Step 2. Build the defining declaration
10232 // --------------------------------------
10233 //
10235
10236 DeclClass* defdecl = new DeclClass(name,kind,NULL,classDef);
10237 ROSE_ASSERT(defdecl != NULL);
10238 ROSE_ASSERT(defdecl->get_type() == NULL);
10239
10240 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
10241 ROSE_ASSERT(defdecl->get_definition() != NULL);
10242 ROSE_ASSERT(defdecl != NULL);
10243
10244 // DQ (3/15/2012): Moved from original location above...
10245 nondefdecl->set_definingDeclaration(defdecl);
10246
10247 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
10248 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
10249
10251 // constructor is side-effect free
10252 classDef->set_declaration(defdecl);
10253 defdecl->set_definingDeclaration(defdecl);
10254
10255 defdecl->set_firstNondefiningDeclaration(nondefdecl);
10256
10257 // DQ (3/22/2012): I think we can assert this.
10258 ROSE_ASSERT(defdecl->get_type() == NULL);
10259
10260 // Liao, 10/30/2009
10261 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
10262 // This is not desired when building a defining declaration and an inefficience in the constructor
10263 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
10264 // the defining class declaration (and other nondefining declaration) just share that SgClassType.
10265 if (defdecl->get_type() != NULL)
10266 {
10267 // Removed several lines of dead code because of the assertion just above
10268 }
10269 else
10270 {
10271 // DQ (3/15/2012): Make sure that both the defining and non-defining declarations use the same type.
10272 ROSE_ASSERT (nondefdecl->get_type() != NULL);
10273 defdecl->set_type(nondefdecl->get_type());
10274
10275 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
10276 }
10277
10278 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10279
10280 // patch up the SgClassType for the defining class declaration
10281 ROSE_ASSERT (nondefdecl->get_type() != NULL);
10282 ROSE_ASSERT (defdecl->get_type() != NULL);
10283 ROSE_ASSERT (defdecl->get_type()->get_declaration() != NULL);
10284 ROSE_ASSERT (defdecl->get_type()->get_declaration() != isSgDeclarationStatement(defdecl));
10285 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
10286 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
10287
10288 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10289
10290 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
10291 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
10292 // used in a defining declaration).
10293 nondefdecl->setForward();
10294
10295 if (scope != NULL) // put into fixStructDeclaration() or alike later on
10296 {
10297 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10298
10299 // Note, this function sets the parent to be the scope if it is not already set.
10300 fixStructDeclaration(defdecl,scope);
10301
10302 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10303
10304 fixStructDeclaration(nondefdecl,scope);
10305
10306 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10307 }
10308
10309 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
10310 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
10311 // ROSE_ASSERT(defdecl->get_parent() != NULL);
10312
10313 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
10314
10315 // DQ (2/27/2012): Tracking down where parents are not set correctly (class declaration in typedef is incorrectly set to SgGlobal).
10316 ROSE_ASSERT(defdecl->get_parent() == NULL);
10317
10318 // DQ (2/29/2012): We can't assert this (fails for test2012_09.C).
10319 // ROSE_ASSERT(nondefdecl->get_parent() == NULL);
10320
10321 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
10322 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
10323
10324 // DQ (3/8/2018): Added for debugging.
10325 SgClassDeclaration* temp_firstNondefiningDeclaration = isSgClassDeclaration(defdecl->get_firstNondefiningDeclaration());
10326 SgClassDeclaration* temp_definingDeclaration = isSgClassDeclaration(defdecl->get_definingDeclaration());
10327 ROSE_ASSERT(temp_firstNondefiningDeclaration != NULL);
10328 ROSE_ASSERT(temp_definingDeclaration != NULL);
10329 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_name() == temp_definingDeclaration->get_name());
10330 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_type() == temp_definingDeclaration->get_type());
10331
10332 return defdecl;
10333 }
10334
10337 {
10338 SgNamespaceAliasDeclarationStatement* aliasdecl = new SgNamespaceAliasDeclarationStatement(name,namespaceDeclaration);
10341 return aliasdecl;
10342 }
10343
10346 {
10348
10350 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
10352
10353 return defdecl;
10354 }
10355
10357SageBuilder::buildNamespaceDeclaration_nfi(const SgName& name, bool unnamednamespace, SgScopeStatement* scope)
10358 {
10359 if (scope == NULL)
10361
10362 ROSE_ASSERT(scope != NULL);
10363
10364 // TODO How about class type??
10365 // build defining declaration
10367
10368 SgNamespaceDeclarationStatement* defdecl = new SgNamespaceDeclarationStatement(name,namespaceDef,unnamednamespace);
10369 ROSE_ASSERT(defdecl != NULL);
10370 namespaceDef->set_parent(defdecl);
10371 setOneSourcePositionNull(defdecl);
10372
10373 // constructor is side-effect free
10374 namespaceDef->set_namespaceDeclaration(defdecl);
10375 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
10376
10377 // Get the nondefining declaration from the symbol if it has been built (if this works,
10378 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
10379 SgNamespaceDeclarationStatement* nondefdecl = NULL;
10380 SgNamespaceSymbol* mysymbol = NULL;
10381 if (scope != NULL)
10382 {
10383 mysymbol = scope->lookup_namespace_symbol(name);
10384 }
10385 else
10386 {
10387 // DQ (1/26/2009): I think this should be an error, but that appears it would
10388 // break the existing interface. Need to discuss this with Liao.
10389 printf ("Warning: In SageBuilder::buildNamespaceDeclaration_nfi(): scope == NULL \n");
10390 }
10391
10392 if (mysymbol != NULL)
10393 {
10394 SgNamespaceDeclarationStatement* namespaceDeclaration = mysymbol->get_declaration();
10395 ROSE_ASSERT(namespaceDeclaration != NULL);
10396 nondefdecl = isSgNamespaceDeclarationStatement(namespaceDeclaration);
10397
10398 ROSE_ASSERT(nondefdecl != NULL);
10399 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10400 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == NULL);
10401 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
10402
10403 // DQ (5/16/2013): Set the global definition for the new namespace definition.
10404 ROSE_ASSERT(namespaceDeclaration->get_definition() != NULL);
10405 if (namespaceDeclaration->get_definition()->get_global_definition() == NULL)
10406 {
10407 printf ("ERROR: namespaceDeclaration->get_definition()->get_global_definition() == NULL: namespaceDeclaration = %p = %s namespaceDeclaration->get_definition() = %p \n",
10408 namespaceDeclaration,namespaceDeclaration->get_name().str(),namespaceDeclaration->get_definition());
10409 }
10410 ROSE_ASSERT(namespaceDeclaration->get_definition()->get_global_definition() != NULL);
10411 namespaceDef->set_global_definition(namespaceDeclaration->get_definition()->get_global_definition());
10412 ROSE_ASSERT(namespaceDef->get_global_definition() != NULL);
10413
10414 // DQ (5/19/2013): Make the global_definition point to itself.
10415 ROSE_ASSERT(namespaceDef->get_global_definition() == namespaceDef->get_global_definition()->get_global_definition());
10416
10417 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
10418
10419 ROSE_ASSERT(nondefdecl->get_definition()->get_previousNamespaceDefinition() == NULL);
10420 // ROSE_ASSERT(nondefdecl->get_definition()->get_nextNamespaceDefinition() == NULL);
10421
10422 SgNamespaceDefinitionStatement* i = namespaceDeclaration->get_definition();
10423 ROSE_ASSERT(i != NULL);
10424 while (i != NULL && i->get_nextNamespaceDefinition() != NULL)
10425 {
10426 i = i->get_nextNamespaceDefinition();
10427 ROSE_ASSERT(i->get_previousNamespaceDefinition() != NULL);
10428 }
10429
10430 ROSE_ASSERT(i != NULL);
10431 i->set_nextNamespaceDefinition(namespaceDef);
10432 namespaceDef->set_previousNamespaceDefinition(i);
10433 }
10434 else
10435 {
10436 // DQ (5/16/2013): Note that since we don't build a SgNamespaceDefinition for the declaration we can't
10437 // build the global_definition. This is a potential problem.
10438
10439 nondefdecl = defdecl;
10440 ROSE_ASSERT(nondefdecl != NULL);
10441 namespaceDef = nondefdecl->get_definition();
10442 ROSE_ASSERT(namespaceDef->get_namespaceDeclaration() != NULL);
10443
10444 // DQ (5/16/2013): Now add the global definition where we will accumulate all of the symbols for the logical namespace.
10445 SgNamespaceDefinitionStatement* global_definition_namespaceDef = buildNamespaceDefinition();
10446 namespaceDef->set_global_definition(global_definition_namespaceDef);
10447 ROSE_ASSERT(namespaceDef->get_global_definition() != NULL);
10448
10449 // DQ (5/19/2013): Make the global_definition point to itself.
10450 global_definition_namespaceDef->set_global_definition(global_definition_namespaceDef);
10451
10452 global_definition_namespaceDef->set_isUnionOfReentrantNamespaceDefinitions(true);
10453
10454 // DQ (8/23/2013): Set the parent of the global_definition_namespaceDef.
10455 ROSE_ASSERT(global_definition_namespaceDef->get_parent() == NULL);
10456 global_definition_namespaceDef->set_parent(defdecl);
10457 ROSE_ASSERT(global_definition_namespaceDef->get_parent() != NULL);
10458
10459 // DQ (5/16/2013): Added tests and setting of the associated declaration.
10460 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() == NULL);
10461 global_definition_namespaceDef->set_namespaceDeclaration(nondefdecl);
10462 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() != NULL);
10463
10464 // DQ (5/16/2013): Set the associated declaration to be the nondefdecl.
10465 global_definition_namespaceDef->set_namespaceDeclaration(nondefdecl);
10466 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() != NULL);
10467
10468 if (defdecl->get_definition()->get_global_definition() == NULL)
10469 {
10470 defdecl->get_definition()->set_global_definition(global_definition_namespaceDef);
10471 }
10472
10473 // DQ (5/19/2013): Make the global_definition point to itself.
10474 ROSE_ASSERT(global_definition_namespaceDef == global_definition_namespaceDef->get_global_definition());
10475 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
10476 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() == namespaceDef->get_global_definition());
10477 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10478
10479 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == NULL);
10480 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
10481
10482 nondefdecl->setForward();
10483 nondefdecl->set_parent(scope);
10484 ROSE_ASSERT(nondefdecl->get_parent());
10485
10486 if (scope != NULL)
10487 {
10488 mysymbol = new SgNamespaceSymbol(name,nondefdecl); // tps: added name to constructor
10489 scope->insert_symbol(name, mysymbol);
10490 }
10491 else
10492 {
10493 // DQ (1/26/2009): I think this should be an error, but that appears it would
10494 // break the existing interface. Need to discuss this with Liao.
10495 printf ("Warning: no scope provided to support symbol table entry! \n");
10496 }
10497
10498 ROSE_ASSERT(defdecl->get_definition() != NULL);
10499 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
10500
10501 ROSE_ASSERT(nondefdecl->get_definition()->get_previousNamespaceDefinition() == NULL);
10502 ROSE_ASSERT(nondefdecl->get_definition()->get_nextNamespaceDefinition() == NULL);
10503 }
10504
10505 ROSE_ASSERT(nondefdecl != NULL);
10506 defdecl->set_firstNondefiningDeclaration(nondefdecl);
10507
10508 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
10509 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
10510 // used in a defining declaration).
10511 nondefdecl->setForward();
10512
10513 if (scope != NULL) // put into fixStructDeclaration() or alike later on
10514 {
10515 fixNamespaceDeclaration(nondefdecl,scope);
10516 fixNamespaceDeclaration(defdecl,scope);
10517 }
10518
10519 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
10520
10521 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
10522 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
10523 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
10524 ROSE_ASSERT(defdecl->get_definition() != NULL);
10525 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
10526
10527 return defdecl;
10528 }
10529
10530// driscoll6 (7/20/11) : Support n-ary operators for python
10533 SgNaryComparisonOp* result = new SgNaryComparisonOp();
10534
10535 result->get_operands().push_back(lhs);
10536 lhs->set_parent(result);
10537
10539 return result;
10540}
10541
10544 SgNaryComparisonOp* result = new SgNaryComparisonOp();
10545
10546 result->get_operands().push_back(lhs);
10547 lhs->set_parent(result);
10548
10550 return result;
10551}
10552
10555 SgNaryBooleanOp* result = new SgNaryBooleanOp();
10556
10557 result->get_operands().push_back(lhs);
10558 lhs->set_parent(result);
10559
10561 return result;
10562}
10563
10566 SgNaryBooleanOp* result = new SgNaryBooleanOp();
10567
10568 result->get_operands().push_back(lhs);
10569 lhs->set_parent(result);
10570
10572 return result;
10573}
10574
10577 ROSE_ASSERT(exp);
10578 SgStringConversion* result = new SgStringConversion(exp);
10579 exp->set_parent(result);
10580
10582 return result;
10583}
10584
10585
10588 ROSE_ASSERT(exp);
10589 SgStringConversion* result = new SgStringConversion(exp);
10590 exp->set_parent(result);
10591
10593 return result;
10594}
10595
10596// DQ (11/7/2009): Added more uniform support for building class declarations.
10599 {
10600 SgClassDeclaration* defdecl = NULL;
10601 SgClassDeclaration* nondefdecl = NULL;
10602
10603 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
10604 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
10605 ROSE_ASSERT(SageInterface::hasTemplateSyntax(name) == false);
10606
10607#if 1
10608 printf ("In buildNondefiningClassDeclaration(): name = %s scope = %p = %s \n",name.str(),scope,scope != NULL ? scope->class_name().c_str() : "NULL");
10609
10610 // DQ (8/12/2013): If this function were to be called then we would have to
10611 // support a template argument list for the call to lookup_class_symbol().
10612
10613 // DQ (6/9/2013): I want to know that I'm not debugging this function.
10614 ROSE_ABORT();
10615#endif
10616
10617 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
10618 // ROSE_ASSERT(scope != NULL);
10619 SgClassSymbol* mysymbol = NULL;
10620 if (scope != NULL)
10621 {
10622 // mysymbol = scope->lookup_class_symbol(name);
10623 mysymbol = scope->lookup_class_symbol(name,NULL);
10624 }
10625 else
10626 {
10627 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unkown.
10628 // DQ (1/26/2009): I think this should be an error, but that appears it would
10629 // break the existing interface. Need to discuss this with Liao.
10630 // printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): scope == NULL \n");
10631 }
10632
10633#if 0
10634 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
10635#endif
10636
10637 if (mysymbol != NULL) // set links if nondefining declaration already exists.
10638 {
10639 nondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
10640
10641 ROSE_ASSERT(nondefdecl != NULL);
10642 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10643
10644 nondefdecl->set_definingDeclaration(defdecl);
10645
10646 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
10647 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
10648
10649 // DQ (10/30/2010): There should be a properly defined type at this point!
10650 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10651
10652 // DQ (7/31/2019): Check that this is true.
10653 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10654 }
10655 else // build a nondefnining declaration if it does not exist
10656 {
10657 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
10658
10660 nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
10661 ROSE_ASSERT(nondefdecl != NULL);
10662 if (nondefdecl->get_type() == NULL)
10663 {
10664 nondefdecl->set_type(SgClassType::createType(nondefdecl));
10665#if 0
10666 printf ("In SageBuilder::buildNondefiningClassDeclaration(): built class type: part 3: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
10667#endif
10668 }
10669
10670 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
10671
10672 // The nondefining declaration will not appear in the source code, but is compiler
10673 // generated (so we have something about the class that we can reference; e.g in
10674 // types). At the moment we make it a transformation, there might be another kind
10675 // of source position that would be more precise. FIXME.
10676 // setOneSourcePositionNull(nondefdecl);
10678
10679 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10680 nondefdecl->set_definingDeclaration(defdecl);
10681 nondefdecl->setForward();
10682 // Liao, 9/2/2009. scope stack is optional, it can be empty
10683 // nondefdecl->set_parent(topScopeStack());
10684 // nondefdecl->set_parent(scope);
10685
10686 // DQ (7/31/2019): Check that this is true.
10687 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10688
10689 // DQ (3/24/2011): This should be NULL before we set it (if the scope is known).
10690 ROSE_ASSERT(nondefdecl->get_scope() == NULL);
10691 if (scope != NULL)
10692 {
10693 // DQ (3/24/2011): Decided with Liao that we should set the scope where possible. The AST consistancy test will make sure it is consistant with where it is inserted into the AST.
10694 nondefdecl->set_scope(scope);
10695 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
10696
10697 mysymbol = new SgClassSymbol(nondefdecl);
10698#if 0
10699 printf ("In buildNondefiningClassDeclaration(): Adding SgClassSymbol: mysymbol = %p from nondefdecl = %p = %s to scope = %p = %s \n",mysymbol,nondefdecl,nondefdecl->class_name().c_str(),scope,scope->class_name().c_str());
10700#endif
10701 scope->insert_symbol(name, mysymbol);
10702 }
10703 else
10704 {
10705 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknown.
10706 // DQ (1/26/2009): I think this should be an error, but that appears it would
10707 // break the existing interface. Need to discuss this with Liao.
10708 // printf ("Warning: no scope provided to support symbol table entry! \n");
10709 }
10710
10711 // DQ (10/30/2010): There should be a properly defined type at this point!
10712 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10713
10714 // DQ (3/24/2011): The scope should be set if the scope was available.
10715 ROSE_ASSERT(scope == NULL || (scope != NULL && nondefdecl->get_scope() != NULL));
10716 }
10717
10718 ROSE_ASSERT(nondefdecl != NULL);
10719
10720 return nondefdecl;
10721 }
10722
10723// DQ (11/7/2009): Added more uniform support for building class declarations.
10726 {
10727 // Note that the semantics of this function now differs from that of the buildDefiningFunctionDeclaration().
10728 // We want to have the non-defining declaration already exist before calling this function.
10729 // We could still build a higher level function that built both together. Or we could provide two versions
10730 // named differently (from this one) and deprecate this function...which I like much better.
10731 printf ("WARNING: This function for building defining class declarations has different semantics from that of the function to build defining function declarations. \n");
10732
10733#if 1
10734 printf ("In buildDefiningClassDeclaration(): name = %s scope = %p = %s \n",name.str(),scope,scope != NULL ? scope->class_name().c_str() : "NULL");
10735
10736 // DQ (6/9/2013): I want to know that I'm not debugging this function.
10737 ROSE_ABORT();
10738#endif
10739
10740 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
10741 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
10742 ROSE_ASSERT(SageInterface::hasTemplateSyntax(name) == false);
10743
10744 SgClassDeclaration* nondefiningClassDeclaration = buildNondefiningClassDeclaration(name,scope);
10745 ROSE_ASSERT(nondefiningClassDeclaration != NULL);
10746
10747 SgClassDefinition* definingClassDefinition = buildClassDefinition();
10748 ROSE_ASSERT(definingClassDefinition != NULL);
10749
10750 // DQ (10/30/2010): There should be a properly defined type at this point!
10751 SgClassType* classType = nondefiningClassDeclaration->get_type();
10752 ROSE_ASSERT(classType != NULL);
10753
10755
10756 // DQ (10/30/2010): We need to make sure that there is a type defined.
10757 // SgClassDeclaration* definingClassDeclaration = new SgClassDeclaration (name,kind,NULL,definingClassDefinition);
10758 SgClassDeclaration* definingClassDeclaration = new SgClassDeclaration (name,kind,classType,definingClassDefinition);
10759 ROSE_ASSERT(definingClassDeclaration != NULL);
10760
10761 // printf ("SageBuilder::buildDefiningClassDeclaration(): definingClassDeclaration = %p \n",definingClassDeclaration);
10762
10763 setOneSourcePositionForTransformation(definingClassDeclaration);
10764
10765 // constructor is side-effect free
10766 definingClassDefinition->set_declaration(definingClassDeclaration);
10767 definingClassDeclaration->set_definingDeclaration(definingClassDeclaration);
10768 definingClassDeclaration->set_firstNondefiningDeclaration(nondefiningClassDeclaration);
10769
10770 nondefiningClassDeclaration->set_definingDeclaration(definingClassDeclaration);
10771
10772 // some error checking
10773 ROSE_ASSERT(nondefiningClassDeclaration->get_definingDeclaration() != NULL);
10774 ROSE_ASSERT(nondefiningClassDeclaration->get_firstNondefiningDeclaration() != NULL);
10775 ROSE_ASSERT(definingClassDeclaration->get_firstNondefiningDeclaration() != NULL);
10776 ROSE_ASSERT(definingClassDeclaration->get_definition() != NULL);
10777
10778 ROSE_ASSERT(definingClassDeclaration->get_scope() == NULL);
10779 if (scope != NULL)
10780 {
10781 definingClassDeclaration->set_scope(scope);
10782 ROSE_ASSERT(definingClassDeclaration->get_scope() != NULL);
10783 ROSE_ASSERT(nondefiningClassDeclaration->get_scope() != NULL);
10784 }
10785
10786 ROSE_ASSERT(definingClassDeclaration->get_definition()->get_parent() != NULL);
10787
10788 // DQ (10/30/2010): There should be a properly defined type at this point!
10789 ROSE_ASSERT(definingClassDeclaration->get_type() != NULL);
10790
10791 return definingClassDeclaration;
10792 }
10793
10794// DQ (11/7/2009): Added more uniform support for building class declarations.
10797 {
10798 ROSE_ASSERT(scope != NULL);
10799 SgClassDeclaration* definingClassDeclaration = buildDefiningClassDeclaration(name,scope);
10800 ROSE_ASSERT(definingClassDeclaration != NULL);
10801
10802 return definingClassDeclaration;
10803 }
10804
10805
10806// DQ (6/6/2012): Added support for template arguments (so that the type could be computing using the template arguments when building a template instantiation).
10807// DQ (1/24/2009): Built this "nfi" version but factored the code.
10808// SgClassDeclaration* SageBuilder::buildClassDeclaration_nfi(const SgName& name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl , bool buildTemplateInstantiation )
10810SageBuilder::buildClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl , bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList )
10811 {
10812 // DQ (3/15/2012): Added function to build C++ class (builds both the non-defining and defining declarations; in that order).
10813 // The implementation of this function could be simplified to directly call both:
10814 // SgClassDeclaration* buildNondefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10815 // and
10816 // SgClassDeclaration* buildDefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10817 // This might refactor the implementation nicely.
10818
10819#define DEBUG_CLASS_DECLARATION 0
10820
10821 // Note that the nonDefiningDecl pointer does not appear to be used.
10822#if 0
10823 printf ("WARNING: In SageBuilder::buildClassDeclaration_nfi(): the nonDefiningDecl pointer = %p (input parameter) does not appear to be used. \n",nonDefiningDecl);
10824#endif
10825
10826#if 0
10827 // DQ (3/4/2018): Adding testing.
10828 // ROSE_ASSERT(nonDefiningDecl != NULL);
10829 if (nonDefiningDecl != NULL)
10830 {
10831 ROSE_ASSERT(nonDefiningDecl->get_type() != NULL);
10832 ROSE_ASSERT(nonDefiningDecl->get_type()->get_declaration() != NULL);
10833 printf ("nonDefiningDecl->get_type() = %p = %s \n",nonDefiningDecl->get_type(),nonDefiningDecl->get_type()->class_name().c_str());
10834 printf ("nonDefiningDecl->get_type()->get_declaration() = %p = %s \n",nonDefiningDecl->get_type()->get_declaration(),nonDefiningDecl->get_type()->get_declaration()->class_name().c_str());
10835#if 0
10836 printf ("In buildClassDeclaration_nfi(): nonDefiningDecl: unparseNameToString() = %s \n",nonDefiningDecl->unparseNameToString().c_str());
10837#endif
10838
10839 }
10840#endif
10841
10842
10843 // DQ (10/10/2015): I think we can assert this! NO we can't (see test2015_87.C).
10844 // ROSE_ASSERT(nonDefiningDecl != NULL);
10845
10846 // DQ (10/10/2015): OK, now we have a valid use on the input non-defining declaration.
10847 bool buildTemplateDeclaration = (isSgTemplateClassDeclaration(nonDefiningDecl) != NULL);
10848
10849 // DQ (10/10/2015): If this is true, then we should have called a different function to build the associated SgTemplateClassDeclaration.
10850 if (buildTemplateDeclaration == true)
10851 {
10852 // Error checking.
10853 printf ("ERROR: If buildTemplateDeclaration == true, then we should have called a different function to build the associated SgTemplateClassDeclaration \n");
10854 }
10855 ROSE_ASSERT(buildTemplateDeclaration == false);
10856
10857#if 0
10858 printf ("In SageBuilder::buildClassDeclaration_nfi(): XXX_name = %s \n",XXX_name.str());
10859 printf ("In SageBuilder::buildClassDeclaration_nfi(): the nonDefiningDecl pointer = %p = %s \n",nonDefiningDecl,nonDefiningDecl != NULL ? nonDefiningDecl->class_name().c_str() : "null");
10860 printf ("In SageBuilder::buildClassDeclaration_nfi(): buildTemplateDeclaration = %s \n",buildTemplateDeclaration ? "true" : "false");
10861 printf (" --- templateArgumentsList = %p \n",templateArgumentsList);
10862 if (templateArgumentsList != NULL)
10863 {
10864 printf (" --- templateArgumentsList.size() = %zu \n",templateArgumentsList->size());
10865 for (size_t i = 0; i < templateArgumentsList->size(); i++)
10866 {
10867 printf (" --- --- argument pointer: templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
10868 }
10869 }
10870#endif
10871
10872 if (scope == NULL)
10873 {
10875#if 0
10876 printf ("In SageBuilder::buildClassDeclaration_nfi(): no scope was provided so using the SageBuilder::topScopeStack() = %p = %s \n",scope,scope->class_name().c_str());
10877#endif
10878 }
10879 else
10880 {
10881#if 0
10882 printf ("In SageBuilder::buildClassDeclaration_nfi(): scope was provided scope = %p = %s \n",scope,scope->class_name().c_str());
10883#endif
10884 }
10885
10886#if 0
10887 printf ("Building a SgClassDeclaration: buildClassDeclaration_nfi() XXX_name = %s buildTemplateInstantiation = %s \n",XXX_name.str(),buildTemplateInstantiation ? "true" : "false");
10888#endif
10889
10890 // Step 2 (now step 1). build the nondefining declaration,
10891 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
10892
10893 // Get the nondefining declaration from the symbol if it has been built (if this works,
10894 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
10895 SgClassDeclaration* nondefdecl = NULL;
10896
10897 SgName nameWithoutTemplateArguments = XXX_name;
10898 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
10899 if (buildTemplateInstantiation == true)
10900 {
10901 ROSE_ASSERT(templateArgumentsList != NULL);
10902 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
10903 }
10904
10905#if DEBUG_CLASS_DECLARATION
10906 printf ("In SageBuilder::buildClassDeclaration_nfi():\n");
10907 printf (" -- nameWithoutTemplateArguments = %s\n", nameWithoutTemplateArguments.str());
10908 printf (" -- nameWithTemplateArguments = %s\n", nameWithTemplateArguments.str());
10909#endif
10910
10911 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
10912 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
10913 // This fails for test2005_35.C
10914 // ROSE_ASSERT(SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == false);
10915
10916 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
10917 // ROSE_ASSERT(scope != NULL);
10918 SgClassSymbol* mysymbol = NULL;
10919 if (scope != NULL)
10920 {
10921#if DEBUG_CLASS_DECLARATION
10922 printf ("Looking up the SgClassSymbol in scope = %p = %s nameWithTemplateArguments = %s \n",scope,scope->class_name().c_str(),nameWithTemplateArguments.str());
10923#endif
10924
10925 // DQ (8/22/2012): We need to provide more information ofr the symbol table lookup to correctly resolve
10926 // (and disambiguate template instantations where the name qualification of the template arguments would
10927 // be significant).
10928 // mysymbol = scope->lookup_class_symbol(name);
10929 // mysymbol = scope->lookup_class_symbol(name);
10930 // mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments);
10931#if 0
10932 // DQ (7/25/2017): Since this is overwritten below, for both branches, we don't need to call this here.
10933 printf ("This was a redundant call to lookup_class_symbol \n");
10934 // mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList);
10935#endif
10936
10937 // DQ (10/10/2015): look up the correct type of symbol.
10938 if (buildTemplateDeclaration == true)
10939 {
10940#if DEBUG_CLASS_DECLARATION
10941 printf ("Note: In SageBuilder::buildClassDeclaration_nfi(): Need to look up a template symbol \n");
10942#endif
10943 ROSE_ASSERT(nonDefiningDecl != NULL);
10944
10945 SgTemplateParameterPtrList templateParameterList;
10946 SgTemplateArgumentPtrList templateSpecializationArgumentList;
10947
10948 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateArguments,&templateParameterList,&templateSpecializationArgumentList) != NULL);
10949
10950 mysymbol = scope->lookup_template_class_symbol(nameWithTemplateArguments,&templateParameterList,&templateSpecializationArgumentList);
10951
10952 ROSE_ASSERT(mysymbol != NULL);
10953#if 0
10954 printf ("ERROR: Need to look up a template symbol \n");
10955 ROSE_ABORT();
10956#endif
10957 }
10958 else
10959 {
10960#if DEBUG_CLASS_DECLARATION
10961 printf ("In SageBuilder::buildClassDeclaration_nfi(): calling lookup_class_symbol(nameWithTemplateArguments = %s,templateArgumentsList->size() = %zu \n",
10962 nameWithTemplateArguments.str(),(templateArgumentsList != NULL) ? templateArgumentsList->size() : 999);
10963 if (templateArgumentsList != NULL)
10964 {
10965 printf (" --- templateArgumentsList elements: \n");
10966 for (size_t i = 0; i < templateArgumentsList->size(); i++)
10967 {
10968 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
10969 printf (" --- --- templateArgumentsList->[%zu] = %s \n",i,templateArgumentsList->operator[](i)->class_name().c_str());
10970 templateArgumentsList->operator[](i)->display("In SageBuilder::buildClassDeclaration_nfi()");
10971 }
10972 }
10973#endif
10974 mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList);
10975#if DEBUG_CLASS_DECLARATION
10976 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
10977#endif
10978 // DQ (3/4/2018): The only time I see this failing is when we should have used the nonDefiningDecl (see Cxx11_tests/test2015_08.C).
10979 if (mysymbol == NULL)
10980 {
10981#if DEBUG_CLASS_DECLARATION
10982 printf ("WARNING: scope->lookup_class_symbol(nameWithTemplateArguments = %s,templateArgumentsList->size() = %zu) == NULL \n",nameWithTemplateArguments.str(),templateArgumentsList->size());
10983#endif
10984 // ROSE_ASSERT(nonDefiningDecl != NULL);
10985
10986 // DQ (12/28/2018): Could it be that we wanted to use the name without template arguments.
10987#if DEBUG_CLASS_DECLARATION
10988 printf ("Checking lookup_class_symbol() using nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
10989#endif
10990 ROSE_ASSERT(scope->lookup_class_symbol(nameWithoutTemplateArguments,templateArgumentsList) == NULL);
10991
10992#if DEBUG_CLASS_DECLARATION
10993 printf ("nonDefiningDecl = %p \n",nonDefiningDecl);
10994#endif
10995 if (nonDefiningDecl != NULL)
10996 {
10997#if DEBUG_CLASS_DECLARATION
10998 printf ("nonDefiningDecl = %p = %s \n",nonDefiningDecl,nonDefiningDecl->class_name().c_str());
10999#endif
11000 // DQ (3/4/2018): I think this is the correct API to use (internal use only).
11001 SgSymbol* temp_mysymbol = nonDefiningDecl->get_symbol_from_symbol_table();
11002 ROSE_ASSERT(temp_mysymbol != NULL);
11003
11004 mysymbol = isSgClassSymbol(temp_mysymbol);
11005 ROSE_ASSERT(mysymbol != NULL);
11006
11007 // DQ (3/4/2018): check that the scopes are the same.
11008 ROSE_ASSERT(scope == nonDefiningDecl->get_scope());
11009 }
11010 }
11011 }
11012
11013#if 0
11014 // DQ (11/21/2013): Added test based on debugging session with Philippe.
11015 // This test is not a test for a bug, since we require that symbols in base classes be aliased in the derived classes.
11016 if (mysymbol != NULL)
11017 {
11018 SgClassDeclaration* symbol_declaration = isSgClassDeclaration(mysymbol->get_declaration());
11019 ROSE_ASSERT(symbol_declaration != NULL);
11020 ROSE_ASSERT(symbol_declaration->get_scope() == scope);
11021
11022 printf ("In SageBuilder::buildClassDeclaration_nfi(): Testing scope->get_symbol_table()->exists(mysymbol) == true (expensive) \n");
11023
11024 ROSE_ASSERT(scope->get_symbol_table()->exists(mysymbol) == true);
11025 }
11026#endif
11027 }
11028 else
11029 {
11030 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknow.
11031 // DQ (1/26/2009): I think this should be an error, but that appears it would
11032 // break the existing interface. Need to discuss this with Liao.
11033 // printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): scope == NULL \n");
11034 }
11035
11036#if DEBUG_CLASS_DECLARATION
11037 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
11038#endif
11039
11040 if (mysymbol != NULL) // set links if nondefining declaration already exists.
11041 {
11042 nondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
11043
11044 ROSE_ASSERT(nondefdecl != NULL);
11045
11046#if DEBUG_CLASS_DECLARATION
11047 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol->get_declaration(): nondefdecl = %p = %s nondefdecl->get_definition() = %p = %s \n",
11048 nondefdecl,nondefdecl->class_name().c_str(),nondefdecl->get_definition(),
11049 nondefdecl->get_definition() != NULL ? nondefdecl->get_definition()->class_name().c_str() : "NULL");
11050#endif
11051 // DQ (6/8/2013): This should not be true (see test2013_198.C).
11052 // Fundamentally the symbol should always only have a pointer to a non-defining
11053 // declaration, where by definition (get_definition() == NULL).
11054 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
11055
11056 // DQ (9/16/2012): This should be true by definition (verify).
11057 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
11058
11059 // DQ (9/16/2012): The declaration was build previously, but test it to make sure the template arguments were setup properly.
11060 testTemplateArgumentParents(nondefdecl);
11061
11062#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11063 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11064 detectTransformations(nondefdecl);
11065#endif
11066
11067 // DQ (3/22/2012): I think we can assert this.
11068 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11069
11070 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11071 if (nondefdecl->get_parent() == NULL)
11072 {
11073#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11074 printf ("In SageBuilder::buildClassDeclaration_nfi(): Note that nondefdecl->get_parent() == NULL, this might be OK. \n");
11075#endif
11076 }
11077
11078#if 0
11079 // DQ (12/22/2019): This is the code that causes the class declarations between defining
11080 // class declarations across multiple translation units to be shared.
11081
11082 // DQ (9/7/2012): I think this might be the root of a problem in the haskell tests (ROSE compiling ROSE).
11083 if (nondefdecl->get_definingDeclaration() != NULL)
11084 {
11085#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11086 printf ("ERROR: In SageBuilder::buildClassDeclaration_nfi(): Non defining declaration nondefdecl = %p = %s already has a defining declaration, so we would be build another nondefdecl->get_definingDeclaration() = %p = %s \n",
11087 nondefdecl,nondefdecl->class_name().c_str(),nondefdecl->get_definingDeclaration(),nondefdecl->get_definingDeclaration()->class_name().c_str());
11088#endif
11089 SgClassDeclaration* nondefining_classDeclaration = isSgClassDeclaration(nondefdecl);
11090 ROSE_ASSERT(nondefining_classDeclaration != NULL);
11091 SgClassDeclaration* defining_classDeclaration = isSgClassDeclaration(nondefdecl->get_definingDeclaration());
11092 ROSE_ASSERT(defining_classDeclaration != NULL);
11093
11094#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11095 printf ("In SageBuilder::buildClassDeclaration_nfi(): nondefining_classDeclaration: scope = %p = %s name = %s \n",
11096 nondefining_classDeclaration->get_scope(),nondefining_classDeclaration->get_scope()->class_name().c_str(),nondefining_classDeclaration->get_name().str());
11097 printf ("In SageBuilder::buildClassDeclaration_nfi(): defining_classDeclaration: scope = %p = %s name = %s \n",
11098 defining_classDeclaration->get_scope(),defining_classDeclaration->get_scope()->class_name().c_str(),defining_classDeclaration->get_name().str());
11099 defining_classDeclaration->get_file_info()->display("already has a defining declaration");
11100#endif
11101#if 0
11102 printf ("Error: In SageBuilder::buildClassDeclaration_nfi(): exiting as part of test \n");
11103 ROSE_ABORT();
11104#endif
11105 // DQ (9/24/2012): This only appears to happen for large tests (e.g. ROSE compiling ROSE), alow it for the moment and look into this later.
11106#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11107 printf ("WARNING: In SageBuilder::buildClassDeclaration_nfi(): but a defining declaration was found to have already been built (might be an error), so returning it defining_classDeclaration = %p \n",defining_classDeclaration);
11108#endif
11109
11110#if 0
11111 // DQ (2/26/2019): Debugging support for multiple files on the command line.
11112 printf ("Exiting as a test! \n");
11113 ROSE_ABORT();
11114#endif
11115 return defining_classDeclaration;
11116 }
11117#endif
11118
11119#if 0
11120 nondefdecl->set_definingDeclaration(defdecl);
11121
11122 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
11123 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
11124#endif
11125 }
11126 else // build a nondefnining declaration if it does not exist
11127 {
11128#if DEBUG_CLASS_DECLARATION
11129 printf ("In SageBuilder::buildClassDeclaration_nfi(): building a nondefining declaration since it does not exist \n");
11130#endif
11131 // DQ (10/10/2015): This should be true.
11132 ROSE_ASSERT(nondefdecl == NULL);
11133
11134 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
11135 // DQ (1/1/2012): Fixed to force matching types or IR nodes for defining and non-defining declarations.
11136 if (buildTemplateInstantiation == true)
11137 {
11138 // This adds: SgTemplateDeclaration *templateDeclaration and SgTemplateArgumentPtrList templateArguments
11139#if DEBUG_CLASS_DECLARATION
11140 printf ("************************************************************************* \n");
11141 printf ("Building SgTemplateInstantiationDecl with empty SgTemplateArgumentPtrList \n");
11142 printf (" --- using nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
11143 printf ("************************************************************************* \n");
11144#endif
11145 SgTemplateArgumentPtrList emptyList;
11146 // nondefdecl = new SgTemplateInstantiationDecl (name,kind,NULL,NULL,NULL,emptyList);
11147 nondefdecl = new SgTemplateInstantiationDecl (nameWithTemplateArguments,kind,NULL,NULL,NULL,emptyList);
11148 ROSE_ASSERT(nondefdecl != NULL);
11149#if DEBUG_CLASS_DECLARATION
11150 printf ("In SageBuilder::buildClassDeclaration_nfi(): Build SgTemplateInstantiationDecl: nondefdecl = %p \n",nondefdecl);
11151#endif
11152 // DQ (2/27/2018): Added assertion now that we have implemented more consistant semantics
11153 // for template instantiations (types are not generated in the constructor calls).
11154 ROSE_ASSERT(nondefdecl->get_type() == NULL);
11155 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl) != NULL);
11156#if 0
11157 printf ("In buildClassDeclaration_nfi(): nondefdecl->get_name() = %s nondefdecl->get_templateName() = %s \n",nondefdecl->get_name().str(),isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().str());
11158#endif
11159#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11160 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11161 // detectTransformations(nondefdecl);
11162#endif
11163 // DQ (6/6/2012): Set the first non-defining declaration to be itself.
11164 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11165
11166 // DQ (1/1/2012): Added support for setting the template name (I think this should be fixed in the constructor).
11167 // It can't be fixed in the constructor since it has to be set after construction (or passed in explicitly).
11168 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == true);
11169
11170 // DQ (6/6/2012): Added support for template arguments so that types would be computed with the template arguments.
11171 ROSE_ASSERT(templateArgumentsList != NULL);
11172
11173#if 0
11174 // DQ (5/30/2014): Removing output spew.
11175 // DQ (5/17/2014): This must be allowed for some template instantiations (see test2014_77.C).
11176 // This occurs now under some revised rules for when to interpret a class or struct as a template
11177 // declaration or template instantiation declaration. This revisions is required for test2014_56.C
11178 // but has had a small cascading effect on other parts of ROSE (all fixed on 5/17/2014, if I can
11179 // finish this work today).
11180 // ROSE_ASSERT(templateArgumentsList->size() > 0);
11181 if (templateArgumentsList->size() == 0)
11182 {
11183 printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): templateArgumentsList->size() == 0 \n");
11184 }
11185#endif
11186 // DQ (9/16/2012): Set the firstNondefiningDeclaration so that we can set the template parameters.
11187 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11188#if 1
11189 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
11190 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
11191#else
11192 isSgTemplateInstantiationDecl(nondefdecl)->get_templateArguments() = *templateArgumentsList;
11193
11194#error "DEAD CODE!"
11195
11196 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
11197 // printf ("Calling setTemplateArgumentParents(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11198 setTemplateArgumentParents(nondefdecl);
11199 // printf ("DONE: Calling setTemplateArgumentParents(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11200
11201 testTemplateArgumentParents(nondefdecl);
11202#endif
11203 // DQ (6/6/2012): Generate the name without the template arguments.
11204#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11205 printf ("Warning: In buildClassDeclaration_nfi(): calling set_templateName(nameWithTemplateArguments = %s) for nondefining declaration \n",nameWithTemplateArguments.str());
11206#endif
11207 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(name);
11208 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName("SETME_NONDEFINING_DECL<>");
11209 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(name);
11210 isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(nameWithoutTemplateArguments);
11211
11212 // DQ (6/6/2012): I don't think we want this test any more (should apply only to the result of get_templateName()).
11213 // DQ (5/31/2012): Find locations where this is set and include template syntax.
11214 // ROSE_ASSERT(name.getString().find('<') == string::npos);
11215 // printf ("Commented out test for: name.getString().find('<') == string::npos (should apply only to the result of get_templateName() \n");
11216
11217 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == false);
11218
11219 // DQ (3/25/2017): Fixed Clang warning: warning: if statement has empty body [-Wempty-body]
11220 // DQ (3/22/2012): Make sure there is template syntax present.
11221 // if (isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().getString().find('>') == string::npos)
11222 // if (hasTemplateSyntax(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName()) == false);
11223 if (hasTemplateSyntax(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName()) == false)
11224 {
11225#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11226 printf ("WARNING: No template syntax present in name of template class instantiation (nondefdecl) \n");
11227#endif
11228 }
11229 // ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().getString().find('>') != string::npos);
11230
11231#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11232 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11233 // detectTransformations(nondefdecl);
11234#endif
11235 // DQ (7/25/2017): This will be true, but it might not be what we want since it can be caught as an error in the code below.
11236 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
11237 }
11238 else
11239 {
11240 // We know that the name without template arguments should be used here (but they are the same).
11241#if DEBUG_CLASS_DECLARATION
11242 printf ("WARNING: In buildClassDeclaration_nfi(): Are we building a new SgClassDeclaration as a nondefining declaration when we should be using the nonDefiningDecl = %p \n",nonDefiningDecl);
11243 printf (" --- nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11244#endif
11245 // nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
11246 nondefdecl = new SgClassDeclaration(nameWithoutTemplateArguments,kind,NULL,NULL);
11247
11248 ROSE_ASSERT(nondefdecl != NULL);
11249#if DEBUG_CLASS_DECLARATION
11250 printf ("In buildClassDeclaration_nfi(): (no file info set): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11251#endif
11252 ROSE_ASSERT(nameWithoutTemplateArguments == nameWithTemplateArguments);
11253
11254#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11255 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11256 // detectTransformations(nondefdecl);
11257#endif
11258 // DQ (9/16/2012): Set the firstNondefiningDeclaration because this is the one branch left were it
11259 // was not set (required in the true branch so that we could set the template parameters).
11260 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11261
11262 testTemplateArgumentParents(nondefdecl);
11263
11264 // DQ (7/25/2017): This will be true, but it might not be what we want since it can be caught as an error in the code below.
11265 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
11266 }
11267
11268 ROSE_ASSERT(nondefdecl != NULL);
11269
11270 // DQ (6/6/2012): This has to be set before we generate the type.
11271 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11272 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
11273
11274 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
11275 // setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
11276
11277 // DQ (3/14/2012): For C++ we need the scope set so that types will have proper locations to revolve them
11278 // from being ambiguous or not properly defined. Basically, we need a handle from which to generate something
11279 // that amounts to a kind of name qualification internally (maybe even exactly name qualification, but I would
11280 // have to think about that a bit more).
11281 ROSE_ASSERT(scope != NULL);
11282
11283#if DEBUG_CLASS_DECLARATION
11284 printf ("In SageBuilder::buildClassDeclaration_nfi(): Set the scope of the new non-defining declaration to %p = %s \n",scope,scope->class_name().c_str());
11285#endif
11286 nondefdecl->set_scope(scope);
11287 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
11288
11289 // DQ (8/2/2019): The was required becuase the parent pointers were not being set when reading a file from the SageBuilder::buildFil() API.
11290 // However the bug was that the astPostprocessing's call to resetParentPointersInMemoryPool() was not properly working to find the global
11291 // scope in anyother case but when it was called usign a SgProject node. This is not fixed to permit caloling using a SgSourceFile node
11292 // and it is now an error to call it using any other kind of IR node.
11293 // DQ (8/1/2019): Set the parent for the non defining declaration to be the same as the scope by default.
11294 // nondefdecl->set_parent(scope);
11295#if 0
11296 printf ("In buildClassDeclaration_nfi(): setting the parent of the non defining declaration to be the scope by default) \n");
11297#endif
11298 // DQ (7/31/2019): Check that the parent is set if this was used a the declaration referenced by a symbol.
11299 // ROSE_ASSERT (nondefdecl->get_parent() != NULL);
11300
11301 // DQ (3/22/2012): I think we can assert this.
11302 // ROSE_ASSERT(nondefdecl->get_type() != NULL);
11303 ROSE_ASSERT(nondefdecl->get_type() == NULL);
11304
11305 if (nondefdecl->get_type() == NULL)
11306 {
11307#if DEBUG_CLASS_DECLARATION
11308 // DQ (12/27/2018): If we have already built a type, then why did we need to build a nondefining declaration?
11309 printf ("Calling scope->get_type_table()->lookup_type(): nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
11310
11311 printf ("WE NEED THE MANGLED NAME FOR THIS TO BE RELEVANT! \n");
11312
11313 // SgType* existingType = scope->get_type_table()->lookup_type(nameWithTemplateArguments);
11314 // ROSE_ASSERT(existingType == NULL);
11315#endif
11316
11317#if DEBUG_CLASS_DECLARATION
11318 printf ("In SageBuilder::buildClassDeclaration_nfi(): kind == SgClassDeclaration::e_java_parameter = %s \n",(kind == SgClassDeclaration::e_java_parameter) ? "true" : "false");
11319#endif
11322 : (SgClassType *) SgClassType::createType(nondefdecl));
11323#if DEBUG_CLASS_DECLARATION
11324 printf ("In SageBuilder::buildClassDeclaration_nfi(): nondefdecl->get_type() == NULL: building a new class_type = %p = %s \n",class_type,class_type->class_name().c_str());
11325#endif
11326 nondefdecl->set_type(class_type);
11327#if DEBUG_CLASS_DECLARATION
11328 printf ("In SageBuilder::buildNondefiningClassDeclaration(): built class type: part 4: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11329#endif
11330 SgClassDeclaration* tmp_classDeclarationFromType = isSgClassDeclaration(class_type->get_declaration());
11331 ROSE_ASSERT(tmp_classDeclarationFromType != NULL);
11332#if DEBUG_CLASS_DECLARATION
11333 SgScopeStatement* scope = tmp_classDeclarationFromType->get_scope();
11334 printf ("tmp_classDeclarationFromType: scope = %p = %s \n",scope,scope->class_name().c_str());
11335 printf ("tmp_classDeclarationFromType = %p = %s \n",tmp_classDeclarationFromType,tmp_classDeclarationFromType->class_name().c_str());
11336 printf ("tmp_classDeclarationFromType name = %s \n",tmp_classDeclarationFromType->get_name().str());
11337 if (tmp_classDeclarationFromType->get_file_info() != NULL)
11338 {
11339 tmp_classDeclarationFromType->get_file_info()->display("tmp_classDeclarationFromType: debug");
11340 }
11341#endif
11342 }
11343
11344 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11345 if (nondefdecl->get_type()->get_declaration() != nondefdecl)
11346 {
11347 printf ("ERROR: nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11348 printf ("ERROR: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11349 printf ("ERROR: nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
11350
11351 SgClassDeclaration* classDeclarationFromType = isSgClassDeclaration(nondefdecl->get_type()->get_declaration());
11352 ROSE_ASSERT(classDeclarationFromType != NULL);
11353
11354 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
11355 printf ("nondefdecl->get_type()->get_name() = %s \n",nondefdecl->get_type()->get_name().str());
11356 printf ("nondefdecl->get_type()->get_declaration()->get_name() = %s \n",classDeclarationFromType->get_name().str());
11357
11358 printf ("nondefdecl->get_mangled_name() = %s \n",nondefdecl->get_mangled_name().getString().c_str());
11359 printf ("nondefdecl->get_type()->get_mangled() = %s \n",nondefdecl->get_type()->get_mangled().getString().c_str());
11360 printf ("nondefdecl->get_type()->get_declaration()->get_mangled_name() = %s \n",classDeclarationFromType->get_mangled_name().getString().c_str());
11361
11362 // DQ (12/27/2018): Added additional debugging support.
11363 printf ("nondefdecl->get_type()->get_declaration()->get_firstNondefiningDeclaration() = %s \n",classDeclarationFromType->get_firstNondefiningDeclaration() ? "true" : "false");
11364 printf ("nondefdecl->get_firstNondefiningDeclaration() = %s \n",nondefdecl->get_firstNondefiningDeclaration() ? "true" : "false");
11365
11366 // DQ (12/27/2018): I think that if this is a base class declaration then it is OK for the type's declaration to not match.
11367 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11368 {
11369 SgNode* parent = nondefdecl->get_parent();
11370 if (parent != NULL)
11371 {
11372 printf ("nondefdecl->get_parent() = %p = %s \n",parent,parent->class_name().c_str());
11373 }
11374 }
11375
11376 // DQ (12/27/2018): Activate this debugging support.
11377#if DEBUG_CLASS_DECLARATION
11378 nondefdecl->get_type()->get_declaration()->get_file_info()->display("nondefdecl->get_type()->get_declaration()");
11379
11380 // DQ (7/24/2017): Added more debug information to support debugging test2014_187.C.
11381 // Note that this can be caught as an error if the class declaration was built in the code above when
11382 // the symbol was not found. But if the nondefdecl->get_type()->get_declaration() == nondefdecl,
11383 // then this branch will not be taken (which is simply debugging information to assert that
11384 // nondefdecl->get_type()->get_declaration() == nondefdecl is true (below).
11385 if (nondefdecl->get_file_info() == NULL)
11386 {
11387 printf ("ERROR: In SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p = %s does not have its source position information setup \n",nondefdecl,nondefdecl->class_name().c_str());
11388 printf (" --- nondefdecl = %s \n",nondefdecl->get_name().str());
11389 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p \n",nondefdecl->get_firstNondefiningDeclaration());
11390 printf (" --- nondefdecl->get_definingDeclaration() = %p \n",nondefdecl->get_definingDeclaration());
11391 printf (" --- nondefdecl->get_type() = %p \n",nondefdecl->get_type());
11392 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
11393 printf ("The real error is: (nondefdecl->get_type()->get_declaration() != nondefdecl) \n");
11394 }
11395 else
11396 {
11397 ROSE_ASSERT(nondefdecl->get_file_info() != NULL);
11398 nondefdecl->get_file_info()->display("nondefdecl");
11399 }
11400#endif
11401 }
11402 ROSE_ASSERT(nondefdecl->get_type()->get_declaration() == nondefdecl);
11403
11404#if 0
11405 printf ("In buildClassDeclaration_nfi(): after set_type(): nondefdecl = %p = %s nondefdecl->get_type() = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str(),nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11406#endif
11407
11408 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11409
11410 // The nondefining declaration will not appear in the source code, but is compiler
11411 // generated (so we have something about the class that we can reference; e.g in
11412 // types). At the moment we make it a transformation, there might be another kind
11413 // of source position that would be more precise. FIXME.
11414 // setOneSourcePositionNull(nondefdecl);
11416 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
11417
11418#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11419 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11421 {
11422 detectTransformations(nondefdecl);
11423 }
11424#endif
11425 // DQ (6/6/2012): This has to be set before we generate the type.
11426 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11427
11428 // DQ (3/15/2012): This is now set below.
11429 // nondefdecl->set_definingDeclaration(defdecl);
11430 nondefdecl->setForward();
11431
11432 // DQ (2/27/2012): I don't like that this is setting the parent to be a scope (not a bad default, but must be reset later if required).
11433 // Liao, 9/2/2009. scope stack is optional, it can be empty
11434 // nondefdecl->set_parent(topScopeStack());
11435#if 0
11436 printf ("WARNING: In buildClassDeclaration_nfi(): Skipping the setting of the parents (for both defining and nondefining declaration) to be the same as the scope \n");
11437#endif
11438 // nondefdecl->set_parent(scope);
11439 // defdecl->set_parent(scope);
11440
11441 if (scope != NULL)
11442 {
11443 mysymbol = new SgClassSymbol(nondefdecl);
11444#if 0
11445 printf ("In buildClassDeclaration_nfi(): Insert the new SgClassSymbol = %p from nondefdecl = %p = %s into the scope = %p = %s \n",mysymbol,nondefdecl,nondefdecl->class_name().c_str(),scope,scope->class_name().c_str());
11446#endif
11447 // scope->insert_symbol(name, mysymbol);
11448 scope->insert_symbol(nameWithTemplateArguments, mysymbol);
11449
11450 // DQ (11/21/2013): Added test based on debugging session with Philippe.
11451 ROSE_ASSERT(nondefdecl->get_scope() == scope);
11452 }
11453 else
11454 {
11455 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unkown.
11456 // DQ (1/26/2009): I think this should be an error, but that appears it would
11457 // break the existing interface. Need to discuss this with Liao.
11458 printf ("Warning: no scope provided to support symbol table entry! \n");
11459 }
11460
11461 // DQ (7/31/2019): Check that the parent is set if this was used a the declaration referenced by a symbol.
11462 // ROSE_ASSERT (nondefdecl->get_parent() != NULL);
11463 }
11464
11465 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11466
11467#if 1
11468 // Refactored this code.
11469 testTemplateArgumentParents(nondefdecl);
11470#else
11471 if (buildTemplateInstantiation == true)
11472 {
11473 // DQ (7/25/2012): Added this code here to reset the parents of the template arguments.
11474 for (size_t i = 0; i < templateArgumentsList->size(); i++)
11475 {
11476 // DQ (7/25/2012): This should be true because the template argument was set to the functions
11477 // scope so that the name with template arguments could be computed (with name qualification).
11478 ROSE_ASSERT((*templateArgumentsList)[i]->get_parent() != NULL);
11479
11480#error "DEAD CODE!"
11481
11482 // ROSE_ASSERT(isSgGlobal(templateArgumentsList[i]->get_parent()) == NULL);
11483 // ROSE_ASSERT(templateArgumentsList[i]->get_parent() == nondefining_templateInstantiation);
11484
11485 // Be we want to reset it to be the function (now that it is available, because this is more precise).
11486 // All qualified names should compute to the same qualified name (if not then it is a bug in the name
11487 // qualification mechanism).
11488 (*templateArgumentsList)[i]->set_parent(nondefdecl);
11489 }
11490 }
11491#endif
11492
11493 // DQ (3/15/2012): I hhava moved construction of defining declaration to be AFTER the nondefining declaration!
11494 // This is a better organization ans also should make sure that the declaration in the SgClassType will
11495 // properly reference the firstNondefiningDeclaration (instead of the defining declaration).
11496
11497 // step 1 (now step 2). Build defining declaration
11498 // SgClassDefinition* classDef = buildClassDefinition();
11499 SgClassDefinition* classDef = buildClassDefinition(NULL,buildTemplateInstantiation);
11500
11501 // DQ (11/26/2011): Debugging EDG 3.3 use of templateArguments.
11502#if 0
11503 printf ("Building a SgClassDeclaration: buildClassDeclaration_nfi() buildTemplateInstantiation = %s \n",buildTemplateInstantiation ? "true:" : "false");
11504#endif
11505
11506 // SgClassDeclaration* defdecl = new SgClassDeclaration (name,kind,NULL,classDef);
11507 SgClassDeclaration* defdecl = NULL;
11508 if (buildTemplateInstantiation == true)
11509 {
11510 // This adds: SgTemplateDeclaration *templateDeclaration and SgTemplateArgumentPtrList templateArguments
11511 SgTemplateArgumentPtrList emptyList;
11512 // defdecl = new SgTemplateInstantiationDecl (name,kind,NULL,classDef,NULL,emptyList);
11513 defdecl = new SgTemplateInstantiationDecl (nameWithTemplateArguments,kind,NULL,classDef,NULL,emptyList);
11514
11515 // DQ (2/27/2018): Added assertion now that we have implemented more consistant semantics
11516 // for template instantiations (types are not generated in the constructor calls).
11517 ROSE_ASSERT(defdecl->get_type() == NULL);
11518 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl) != NULL);
11519#if 0
11520 printf ("In buildClassDeclaration_nfi(): defdecl->get_name() = %s defdecl->get_templateName() = %s \n",defdecl->get_name().str(),isSgTemplateInstantiationDecl(defdecl)->get_templateName().str());
11521#endif
11522 // DQ (1/1/2012): Added support for setting the template name (I think this should be fixed in the constructor).
11523 // It can't be fixed in the constructor since it has to be set after construction (or passed in explicitly).
11524 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().is_null() == true);
11525
11526#if 0
11527 printf ("Warning: In buildClassDeclaration_nfi(): calling set_templateName(name = %s) for defining declaration \n",name.str());
11528#if 0
11529 // isSgTemplateInstantiationDecl(defdecl)->set_templateName(name);
11530 // isSgTemplateInstantiationDecl(defdecl)->set_templateName("SETME_DEFINING_DECL<>");
11531 isSgTemplateInstantiationDecl(defdecl)->set_templateName(name);
11532
11533#error "DEAD CODE!"
11534
11535 // DQ (5/31/2012): Find locations where this is set and include template syntax.
11536 ROSE_ASSERT(name.getString().find('<') == string::npos);
11537#else
11538 // DQ (6/1/2012): Make sure that the templateName is set and they it does not include the template syntax.
11539 SgName templateName = generateTemplateNameFromTemplateNameWithTemplateArguments(name);
11540 printf ("In buildClassDeclaration_nfi(): templateName = %s \n",templateName.str());
11541 isSgTemplateInstantiationDecl(defdecl)->set_templateName(templateName);
11542
11543#error "DEAD CODE!"
11544
11545 // DQ (5/31/2012): Find locations where this is set and include template syntax.
11546 // ROSE_ASSERT(templateName.getString().find('<') == string::npos);
11547 ROSE_ASSERT(hasTemplateSyntax(templateName) == false);
11548
11549 // DQ (6/1/2012): Not clear if this is always true (for all template instantations).
11550 // ROSE_ASSERT(name.getString().find('<') != string::npos);
11551 ROSE_ASSERT(hasTemplateSyntax(name) == true);
11552#endif
11553#else
11554#if 0
11555 printf ("In buildClassDeclaration_nfi(): nameWithoutTemplateArguments = %s nameWithTemplateArguments = %s \n",nameWithoutTemplateArguments.str(),nameWithTemplateArguments.str());
11556#endif
11557 isSgTemplateInstantiationDecl(defdecl)->set_templateName(nameWithoutTemplateArguments);
11558
11559#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11560 // DQ (5/8/2013): This fails for test2013_159.C, and it appears that we have been overly restrictive here.
11561 if (hasTemplateSyntax(nameWithTemplateArguments) == false)
11562 {
11563 printf ("WARNING: In buildClassDeclaration_nfi(): nameWithTemplateArguments = %s is not using template syntax \n",nameWithTemplateArguments.str());
11564 }
11565#endif
11566 // ROSE_ASSERT(hasTemplateSyntax(nameWithTemplateArguments) == true);
11567
11568 // DQ (7/27/2012): This fails for test2005_35.C where conversion operators are seen.
11569 // ROSE_ASSERT(hasTemplateSyntax(nameWithoutTemplateArguments) == false);
11570#endif
11571
11572 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().is_null() == false);
11573
11574 // DQ (3/22/2012): Make sure there is template syntax present.
11575 if (isSgTemplateInstantiationDecl(defdecl)->get_templateName().getString().find('>') == string::npos)
11576 {
11577#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11578 printf ("WARNING: No template syntax present in name of template class instantiation (defdecl) \n");
11579#endif
11580 }
11581 // ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().getString().find('>') != string::npos);
11582#if 0
11583 printf ("Should we have set the template instantiation name at this point? \n");
11584 ROSE_ABORT();
11585#endif
11586 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
11587 ROSE_ASSERT(defdecl->get_definition() != NULL);
11588 ROSE_ASSERT(isSgTemplateInstantiationDefn(defdecl->get_definition()) != NULL);
11589 }
11590 else
11591 {
11592#if 0
11593 printf ("Building a SgClassDeclaration, but we might require a SgTemplateClassDeclaration \n");
11594#endif
11595 // defdecl = new SgClassDeclaration (name,kind,NULL,classDef);
11596 // defdecl = new SgClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
11597
11598 // DQ (10/11/2015): Try to build a matching SgTemplateClassDeclaration. The problem with this fix is that
11599 // I would prefer that the other function be called instead. We might still want to implementat that instead.
11600 if (buildTemplateDeclaration == true)
11601 {
11602 printf ("In buildClassDeclaration_nfi(): I think we also want template specialization arguments to be more general: using nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11603
11604 // = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,classType,(SgClassDefinition*)NULL);
11605 defdecl = new SgTemplateClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
11606
11607 // DQ (2/27/2018): We should be able to enforce this, it should have always been true.
11608 ROSE_ASSERT(defdecl->get_type() == NULL);
11609#if 0
11610 printf ("Exiting afte test! \n");
11611 ROSE_ABORT();
11612#endif
11613 }
11614 else
11615 {
11616 defdecl = new SgClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
11617
11618#if 0
11619 // DQ (12/22/2019): Debugging the case of shared class declarations between multiple files referencing the same defining declaration.
11620 printf ("In SageBuilder::buildClassDeclaration_nfi(): build a SgClassDeclaration: defdecl = %p \n",defdecl);
11621#endif
11622
11623 // DQ (2/27/2018): We should be able to enforce this, it should have always been true.
11624 ROSE_ASSERT(defdecl->get_type() == NULL);
11625 }
11626
11627 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
11628 ROSE_ASSERT(defdecl->get_definition() != NULL);
11629 ROSE_ASSERT(isSgTemplateInstantiationDefn(defdecl->get_definition()) == NULL);
11630 }
11631 ROSE_ASSERT(defdecl != NULL);
11632
11633#if 0
11634 printf ("In buildClassDeclaration_nfi(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11635#endif
11636
11637 // DQ (3/15/2012): Moved from original location above...
11638 nondefdecl->set_definingDeclaration(defdecl);
11639
11640 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
11641 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
11642
11643 // printf ("SageBuilder::buildClassDeclaration_nfi(): defdecl = %p \n",defdecl);
11644
11646 // constructor is side-effect free
11647 classDef->set_declaration(defdecl);
11648 defdecl->set_definingDeclaration(defdecl);
11649
11650 testTemplateArgumentParents(nondefdecl);
11652
11653 // setOneSourcePositionForTransformation(nondefdecl);
11654 //
11655 // Liao 1/18/2011, I changed the semantics of setOneSourcePositionNull to set file_info to null regardless the existence of
11656 // file_info of the input node.
11657 // We do want to keep the file_info of nodefdecl if it is set already as compiler generated.
11658 // setOneSourcePositionNull(nondefdecl);
11659
11660 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11661 // nondefdecl->set_definingDeclaration(defdecl);
11662 defdecl->set_firstNondefiningDeclaration(nondefdecl);
11663
11664 if (buildTemplateInstantiation == true)
11665 {
11666 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
11667 setTemplateArgumentsInDeclaration(defdecl,templateArgumentsList);
11668 }
11669
11670 // DQ (3/22/2012): I think we can assert this.
11671 ROSE_ASSERT(defdecl->get_type() == NULL);
11672
11673 // Liao, 10/30/2009
11674 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
11675 // This is not desired when building a defining declaration and an inefficience in the constructor
11676 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
11677 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
11678 if (defdecl->get_type() != NULL)
11679 {
11680 // if a defining class declaration's type is associated with a defining class.
11681 // This is a wrong SgClassType and has to be reset
11682 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl))
11683 {
11684 // DQ (3/21/2012): Added this test.
11685 ROSE_ASSERT (nondefdecl->get_type() != NULL);
11686
11687 // DQ (3/15/2012): Make this conditional upon the types not already being equal.
11688 if (nondefdecl->get_type() != defdecl->get_type())
11689 {
11690#if 0
11691 printf ("Deleting defdecl->get_type() = %p = %s (using type from nondefdecl = %p) \n",defdecl->get_type(),defdecl->get_type()->class_name().c_str(),nondefdecl);
11692 printf ("Skipping delete of %p to maintain unique type pointers \n",defdecl->get_type());
11693#else
11694 delete defdecl->get_type();
11695#endif
11696 // DQ (3/15/2012): This will be reset below.
11697 defdecl->set_type(NULL);
11698#if 0
11699 printf ("In SageBuilder::buildClassDeclaration(): built class type: part 5: defdecl->get_type() = %p = %s \n",defdecl->get_type(),defdecl->get_type()->class_name().c_str());
11700#endif
11701#if 0
11702 // DQ (12/13/2011): Is this executed...
11703 printf ("Is this executed! \n");
11704 ROSE_ABORT();
11705#endif
11706 // DQ (3/21/2012): set the types to be the same type.
11707 ROSE_ASSERT (nondefdecl->get_type() != NULL);
11708 defdecl->set_type(nondefdecl->get_type());
11709#if 0
11710 printf ("In SageBuilder::buildClassDeclaration(): built class type: part 6: nondefdecl->get_type() = %p = %s \n",defdecl->get_type(),defdecl->get_type()->class_name().c_str());
11711#endif
11712 // DQ (3/21/2012): Added these checks...
11713 SgClassType* classType = nondefdecl->get_type();
11714 ROSE_ASSERT(classType != NULL);
11715 SgClassDeclaration* local_classDeclaration = isSgClassDeclaration(classType->get_declaration());
11716 ROSE_ASSERT (local_classDeclaration != NULL);
11717 printf ("In buildClassDeclaration_nfi(): classType = %p local_classDeclaration = %p \n",classType,local_classDeclaration);
11718 ROSE_ASSERT (local_classDeclaration->get_firstNondefiningDeclaration() != NULL);
11719 ROSE_ASSERT (local_classDeclaration->get_firstNondefiningDeclaration() == local_classDeclaration);
11720 }
11721 }
11722 }
11723 else
11724 {
11725 // DQ (3/15/2012): Make sure that both the defining and non-defining declarations use the same type.
11726 ROSE_ASSERT (nondefdecl->get_type() != NULL);
11727 defdecl->set_type(nondefdecl->get_type());
11728#if 0
11729 printf ("In buildClassDeclaration_nfi(): defdecl = %p = %s defdecl->get_type() = %p = %s \n",defdecl,defdecl->class_name().c_str(),defdecl->get_type(),defdecl->get_type()->class_name().c_str());
11730#endif
11731
11732 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
11733#if 0
11734 // DQ (11/20/2017): Commented out output spew.
11735 // DQ (2/28/2015): This test is failing in the new application support for templates within the testRoseHeaders_01.C.
11736 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()))
11737 {
11738 printf ("WARNING: In buildClassDeclaration_nfi(): inner test: commented out test for equality between the declaration asociated with the type and that associated with the firstNondefiningDeclaration \n");
11739 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11740 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
11741 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
11742 }
11743 // DQ (7/22/2017): Uncomment this test to better understand why this is a new issue (after two years).
11744 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
11745#endif
11746#if 0
11747 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
11748#endif
11749 }
11750
11751 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
11752
11753 // patch up the SgClassType for the defining class declaration
11754 ROSE_ASSERT (nondefdecl->get_type() != NULL);
11755 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
11756#if 0
11757 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl))
11758 {
11759 printf ("nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11760 printf ("nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11761 printf ("nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
11762 printf ("nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
11763 }
11764#endif
11765 // ROSE_ASSERT (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl));
11766 ROSE_ASSERT (defdecl->get_type() != NULL);
11767 ROSE_ASSERT (defdecl->get_type()->get_declaration() != NULL);
11768 ROSE_ASSERT (defdecl->get_type()->get_declaration() != isSgDeclarationStatement(defdecl));
11769 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
11770 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
11771#if 0
11772 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
11773#else
11774
11775#if 0
11776 // DQ (11/20/2017): Commented out output spew.
11777 // DQ (2/28/2015): This test is failing in the new application support for templates within the testRoseHeaders_01.C.
11778 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()))
11779 {
11780 printf ("WARNING: In buildClassDeclaration_nfi(): outer test (test 1): commented out test for equality between the declaration asociated with the type and that associated with the firstNondefiningDeclaration \n");
11781 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11782 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
11783 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
11784 }
11785 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
11786 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl))
11787 {
11788 printf ("WARNING: In buildClassDeclaration_nfi(): outer test (test 2): commented out test for equality between the declaration asociated with the type and that associated with the firstNondefiningDeclaration \n");
11789 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11790 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
11791 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11792 }
11793 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
11794#endif
11795
11796#endif
11797
11798 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
11799
11800 // This appears to be redundant...is it?
11801 defdecl->set_type(nondefdecl->get_type());
11802
11803#if 0
11804 printf ("In buildClassDeclaration_nfi(): after calling set_type() again: defdecl = %p = %s defdecl->get_type() = %p = %s \n",
11805 defdecl,defdecl->class_name().c_str(),defdecl->get_type(),defdecl->get_type()->class_name().c_str());
11806#endif
11807
11808 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
11809
11810 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
11811 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
11812 // used in a defining declaration).
11813 nondefdecl->setForward();
11814
11815 if (scope != NULL) // put into fixStructDeclaration() or alike later on
11816 {
11817 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
11818
11819 // Note, this function sets the parent to be the scope if it is not already set.
11820 fixStructDeclaration(defdecl,scope);
11821
11822 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
11823
11824 fixStructDeclaration(nondefdecl,scope);
11825
11826 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
11827
11828#if 0
11829 SgClassSymbol* mysymbol = new SgClassSymbol(nondefdecl);
11830 ROSE_ASSERT(mysymbol);
11831 scope->insert_symbol(name, mysymbol);
11832 printf ("@@@@@@@@@@@@@@ In buildClassDeclaration_nfi(): setting scope of defining and non-defining declaration to scope = %s \n",scope->class_name().c_str());
11833 defdecl->set_scope(scope);
11834 nondefdecl->set_scope(scope);
11835
11836 // defdecl->set_parent(scope);
11837
11838 // Liao, 9/2/2009. merged into fixStructDeclaration
11839 // DQ (1/25/2009): The scope is not the same as the parent, since the scope is logical, and the parent is structural (note that topScopeStack() is structural).
11840 nondefdecl->set_parent(scope);
11841 // nondefdecl->set_parent(topScopeStack());
11842 // Liao, 9/2/2009. scope stack is optional, it can be empty
11843 defdecl->set_parent(scope);
11844 // defdecl->set_parent(topScopeStack());
11845#endif
11846 }
11847
11848 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
11849 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
11850 // ROSE_ASSERT(defdecl->get_parent() != NULL);
11851
11852 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
11853
11854 // DQ (2/27/2012): Tracking down where parents are not set correctly (class declaration in typedef is incorrectly set to SgGlobal).
11855 ROSE_ASSERT(defdecl->get_parent() == NULL);
11856
11857 // DQ (2/29/2012): We can't assert this (fails for test2012_09.C).
11858 // ROSE_ASSERT(nondefdecl->get_parent() == NULL);
11859
11860 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
11861 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
11862
11863 testTemplateArgumentParents(nondefdecl);
11865
11866 // DQ (3/8/2018): Added for debugging.
11867 SgClassDeclaration* temp_firstNondefiningDeclaration = isSgClassDeclaration(defdecl->get_firstNondefiningDeclaration());
11868 SgClassDeclaration* temp_definingDeclaration = isSgClassDeclaration(defdecl->get_definingDeclaration());
11869 ROSE_ASSERT(temp_firstNondefiningDeclaration != NULL);
11870 ROSE_ASSERT(temp_definingDeclaration != NULL);
11871
11872#if 0
11873 printf ("Leaving buildClassDeclaration_nfi(): defdecl = %p = %s = %s \n",defdecl,defdecl->class_name().c_str(),defdecl->get_name().str());
11874 printf (" --- defdecl->get_firstNondefiningDeclaration() = %p \n",defdecl->get_firstNondefiningDeclaration());
11875 printf (" --- defdecl->get_definingDeclaration() = %p \n",defdecl->get_definingDeclaration());
11876
11877 printf (" --- defdecl->get_firstNondefiningDeclaration()->get_name() = %s \n",temp_firstNondefiningDeclaration->get_name().str());
11878 printf (" --- defdecl->get_definingDeclaration()->get_name() = %s \n",temp_definingDeclaration->get_name().str());
11879
11880 printf (" --- defdecl->get_firstNondefiningDeclaration()->get_type() = %p = %s \n",
11881 temp_firstNondefiningDeclaration->get_type(),temp_firstNondefiningDeclaration->get_type()->unparseToString().c_str());
11882 printf (" --- defdecl->get_definingDeclaration()->get_type() = %p = %s \n",
11883 temp_definingDeclaration->get_type(),temp_definingDeclaration->get_type()->unparseToString().c_str());
11884
11885 printf (" --- nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11886 printf (" --- nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
11887
11888#if 0
11889 printf ("Leaving buildClassDeclaration_nfi(): defdecl: unparseNameToString() = %s \n",defdecl->unparseNameToString().c_str());
11890#endif
11891#endif
11892
11893 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_name() == temp_definingDeclaration->get_name());
11894 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_type() == temp_definingDeclaration->get_type());
11895
11896 // DQ (3/7/2015): Only in EDG 4.7 does the defining declaration not have a valid templateDeclaration pointer (sometimes).
11897 SgTemplateInstantiationDecl* nondefiningDeclaration = isSgTemplateInstantiationDecl(defdecl->get_firstNondefiningDeclaration());
11898 SgTemplateInstantiationDecl* definingDeclaration = isSgTemplateInstantiationDecl(defdecl->get_definingDeclaration());
11899 if (definingDeclaration != NULL && nondefiningDeclaration != NULL)
11900 {
11901 SgTemplateClassDeclaration* templateDeclaration = nondefiningDeclaration->get_templateDeclaration();
11902 if (templateDeclaration != NULL && definingDeclaration->get_templateDeclaration() == NULL)
11903 {
11904#if 0
11905 printf ("NOTE: buildClassDeclaration_nfi(): Setting the templateDeclaration for the defining declaration = %p using the value = %p from the nondefiningDeclaration = %p \n",
11906 definingDeclaration,templateDeclaration,nondefiningDeclaration);
11907#endif
11908 definingDeclaration->set_templateDeclaration(templateDeclaration);
11909
11910 ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
11911 }
11912 // ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
11913 }
11914
11915 // DQ (3/7/2015): Only in EDG 4.7 does the defining declaration not have a valid templateDeclaration pointer (sometimes).
11916 if (definingDeclaration != NULL)
11917 {
11918 if (definingDeclaration->get_templateDeclaration() == NULL)
11919 {
11920#if 0
11921 printf ("NOTE: buildClassDeclaration_nfi(): definingDeclaration->get_templateDeclaration() == NULL \n");
11922#endif
11923 }
11924 // ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
11925 }
11926
11927#if 0
11928 printf ("Leaving buildClassDeclaration_nfi(): defdecl = %p defdecl->unparseNameToString() = %s \n",defdecl,defdecl->unparseNameToString().c_str());
11929#endif
11930
11931#if 0
11932 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
11933 printf ("Leaving buildClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
11934 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
11935
11936 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
11937 printf ("Leaving buildClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
11938 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
11939#endif
11940
11941 return defdecl;
11942 }
11943
11944
11946 {
11947 SgName myname(name);
11948 return buildStructDeclaration(myname, scope);
11949 }
11950
11952 {
11953 SgName myname(name);
11954 return buildStructDeclaration(myname, scope);
11955 }
11956
11957
11958#if 0
11959// DQ (11/19/2011): Added more uniform support for building class declarations.
11962 {
11963 ROSE_ASSERT(scope != NULL);
11964 SgTemplateClassDeclaration* definingClassDeclaration = buildDefiningTemplateClassDeclaration(name,scope);
11965 ROSE_ASSERT(definingClassDeclaration != NULL);
11966
11967 return definingClassDeclaration;
11968 }
11969#endif
11970
11971
11974 {
11975 SgTemplateClassDefinition* result = NULL;
11976 if (d != NULL) // the constructor does not check for NULL d, causing segmentation fault
11977 {
11978 result = new SgTemplateClassDefinition(d);
11979 // result->set_parent(d); // set_declaration() == set_parent() in this case
11980 }
11981 else
11982 {
11983 result = new SgTemplateClassDefinition();
11984 }
11985
11986 ROSE_ASSERT(result);
11987
11988 // CR (3/22/2020): Fixed setting case insensitivity
11989 // if (symbol_table_case_insensitive_semantics == true)
11991 result->setCaseInsensitive(true);
11992
11994 return result;
11995 }
11996
11998SageBuilder::buildNondefiningTemplateClassDeclaration(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
11999{
12000 SgTemplateClassDeclaration* res = buildNondefiningTemplateClassDeclaration_nfi (XXX_name, kind, scope, templateParameterList, templateSpecializationArgumentList);
12002 return res;
12003}
12004
12005// SgTemplateClassDeclaration * SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(const SgName& name, SgClassDeclaration::class_types kind, SgScopeStatement* scope )
12007SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12008 {
12009#if 0
12010 printf("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(XXX_name = %p):\n", XXX_name.str());
12011#endif
12012
12013 if (scope == NULL)
12015
12016 // DQ (11/20/2011): This is for initial debugging only.
12017 ROSE_ASSERT(scope != NULL);
12018
12019#if 0
12020 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): XXX_name = %s scope = %p = %s \n",XXX_name.str(),scope,scope->class_name().c_str());
12021#endif
12022
12023 // DQ (9/12/2012): We want to add the template arguments of any specialization to the template name and keep track of the name with and without template specialization arguments.
12024 SgName nameWithoutTemplateArguments = XXX_name;
12025 SgName nameWithTemplateSpecializationArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateSpecializationArgumentList);
12026
12027#if 0
12028 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
12029#endif
12030
12031 // SgTemplateClassDeclaration::class_types template_class_kind = SgTemplateClassDeclaration::e_class;
12032
12033 // Step 2. build the nondefining declaration,
12034 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
12035
12036 // Get the nondefining declaration from the symbol if it has been built (if this works,
12037 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
12038 SgTemplateClassDeclaration* nondefdecl = NULL;
12039
12040 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
12041 // ROSE_ASSERT(scope != NULL);
12042
12043 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12044 // SgTemplateSymbol* mysymbol = NULL;
12045 SgClassSymbol* mysymbol = NULL;
12046
12047 if (scope != NULL)
12048 {
12049 // DQ (9/12/2012): We want to include the template specialization into the name where it is required (this handling
12050 // is similar to normal template arguments for non-template declaration, but different than template parameters).
12051 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12052 // mysymbol = scope->lookup_template_symbol(name);
12053 // mysymbol = scope->lookup_class_symbol(name);
12054 // mysymbol = scope->lookup_template_class_symbol(name);
12055 // mysymbol = scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList);
12056 mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
12057 }
12058 else
12059 {
12060 // Liao 9/2/2009: This is not an error. We support bottom-up AST construction and scope can be unknown.
12061 // DQ (1/26/2009): I think this should be an error, but that appears it would
12062 // break the existing interface. Need to discuss this with Liao.
12063 printf ("Warning: In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): scope == NULL \n");
12064 }
12065#if 0
12066 printf ("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
12067#endif
12068
12069 if (mysymbol != NULL) // set links if nondefining declaration already exists.
12070 {
12071 // DQ (3/7/2012): Build a seperate non-defining declaration (reusing the existing one will cause the test for unique statements to fail).
12072 // printf ("WARNING: Even if the first non-defining SgTemplateClassDeclaration is found in the symbol table then likely we still might want to build a 2nd one. \n");
12073 // nondefdecl = isSgTemplateClassDeclaration(mysymbol->get_declaration());
12074 SgClassType* classType = isSgClassType(mysymbol->get_type());
12075 ROSE_ASSERT(classType != NULL);
12076
12077 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12078 // nondefdecl = new SgTemplateClassDeclaration(name,kind,classType,(SgClassDefinition*)NULL);
12079 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,classType,(SgClassDefinition*)NULL);
12080
12081#if 0
12082 // DQ (3/4/2018): relax this requirement for SgTemplateInstantiationClassDeclaration.
12083 // DQ (2/27/2018): Enforce that this is not already set (should be set after the constructor to
12084 // simplify how derived classes (e.g. SgTemplateInstantiationClassDeclaration statements) work.
12085 if (nondefdecl->get_type() != NULL)
12086 {
12087 printf ("Note: SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): nondefdecl->get_type() != NULL: name = %s \n",nondefdecl->get_name().str());
12088 }
12089 // ROSE_ASSERT(nondefdecl->get_type() == NULL);
12090#endif
12091
12092 ROSE_ASSERT(nondefdecl != NULL);
12093
12094 // DQ (9/10/2012): Initialize the template parameter list.
12095 ROSE_ASSERT(templateParameterList != NULL);
12096 nondefdecl->get_templateParameters() = *templateParameterList;
12097
12098 // DQ (9/16/2012): Moved this initialization of firstNondefiningDeclaration from farther down in this branch (and added assertion).
12099 nondefdecl->set_firstNondefiningDeclaration(mysymbol->get_declaration());
12100 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
12101
12102 // TV (04/12/2018): Add a scope for nonreal classes (and their member) on the first non-defining declaration of template classes
12103 if (nondefdecl == nondefdecl->get_firstNondefiningDeclaration()) {
12104 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
12105
12106 nonreal_decl_scope->set_parent(nondefdecl);
12107 nondefdecl->set_nonreal_decl_scope(nonreal_decl_scope);
12108
12109 SageInterface::setSourcePosition(nonreal_decl_scope);
12110 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
12111 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
12112#if 0
12113 printf("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(XXX_name = %p): nrscope = %p (new)\n", XXX_name.str(), nonreal_decl_scope);
12114#endif
12115 }
12116
12117#if 1
12118 // DQ (9/16/2012): This newly refactored function can only be called after firstNondefiningDeclaration is set.
12119 // This also sets the template argument parents to the firstNondefiningDeclaration.
12120 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
12121#else
12122 // DQ (9/12/2012): Adding support for template specialization.
12123 ROSE_ASSERT(templateSpecializationArgumentList != NULL);
12124 nondefdecl->get_templateSpecializationArguments() = *templateSpecializationArgumentList;
12125#endif
12126 // DQ (9/10/2012): Test the just built template with its template parameters.
12127 if (nondefdecl->get_templateParameters().size() == 0)
12128 {
12129#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12130 printf ("WARNING: In buildNondefiningTemplateClassDeclaration_nfi(): (part 1) nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
12131#endif
12132 }
12133 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12134
12135 // DQ (3/7/2012): We want this to be set later, so we can't test it here.
12136 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
12137#if 0
12138 nondefdecl->set_definingDeclaration(defdecl);
12139
12140 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
12141 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
12142#endif
12143 // DQ (3/7/2012): But always refer to the first non-defining declaration so it will be unique (and set the scope).
12144 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
12145 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != nondefdecl);
12146 nondefdecl->set_scope(scope);
12147 nondefdecl->setForward();
12148
12149 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12150 nondefdecl->set_templateName(nameWithoutTemplateArguments);
12151
12152 testTemplateArgumentParents(nondefdecl);
12153 }
12154 else // build a nondefnining declaration if it does not exist
12155 {
12156 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,(SgClassType*)NULL,(SgClassDefinition*)NULL);
12157 ROSE_ASSERT(nondefdecl != NULL);
12158
12159 // DQ (9/10/2012): Initialize the template parameter list.
12160 ROSE_ASSERT(templateParameterList != NULL);
12161 nondefdecl->get_templateParameters() = *templateParameterList;
12162
12163 // DQ (9/16/2012): Moved this initialization of firstNondefiningDeclaration from farther down in this branch.
12164 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12165
12166 // DQ (9/16/2012): This newly refactored function can only be called after firstNondefiningDeclaration is set.
12167 // This also sets the template argument parents to the firstNondefiningDeclaration.
12168 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
12169
12170 // DQ (9/10/2012): Test the just built template with its template parameters.
12171 if (nondefdecl->get_templateParameters().size() == 0)
12172 {
12173#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12174 printf ("WARNING: In buildNondefiningTemplateClassDeclaration_nfi(): (part 2) nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
12175#endif
12176 }
12177 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12178
12179 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12180 nondefdecl->set_templateName(nameWithoutTemplateArguments);
12181
12182#if 0
12183 // DQ (12/4/2011): Now we want to enable this so that the SgClassType will be available from a SgTemplateClassDeclaration.
12184 if (nondefdecl->get_type() == NULL)
12185 {
12186 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
12187 // nondefdecl->set_type(NULL);
12188 // nondefdecl->set_type(SgTemplateType::createType(nondefdecl));
12189 // nondefdecl->set_type(SgTemplateType::createType());
12190 nondefdecl->set_type(SgClassType::createType(nondefdecl));
12191 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12192 }
12193#endif
12194 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
12195
12196 // The nondefining declaration will not appear in the source code, but is compiler
12197 // generated (so we have something about the class that we can reference; e.g in
12198 // types). At the moment we make it a transformation, there might be another kind
12199 // of source position that would be more precise. FIXME.
12200 // setOneSourcePositionNull(nondefdecl);
12202 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
12203
12204 // nondefdecl->set_definingDeclaration(defdecl);
12205 nondefdecl->setForward();
12206
12207 // Liao, 9/2/2009. scope stack is optional, it can be empty
12208 // nondefdecl->set_parent(topScopeStack());
12209#if 0
12210 printf ("In buildNondefiningTemplateClassDeclaration_nfi(): Commented out setting the parent to the scope. \n");
12211#endif
12212 // printf ("Note that for C++, the parent may not be the same as the scope (dangerous code). \n");
12213 // nondefdecl->set_parent(scope);
12214
12215 nondefdecl->set_scope(scope);
12216
12217#if 1
12218 // DQ (12/4/2011): Set the scope first and then set the type (scope is required to compute the type (name mangling)).
12219 // DQ (12/4/2011): Now we want to enable this so that the SgClassType will be available from a SgTemplateClassDeclaration.
12220 if (nondefdecl->get_type() == NULL)
12221 {
12222 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
12223 // nondefdecl->set_type(NULL);
12224 // nondefdecl->set_type(SgTemplateType::createType(nondefdecl));
12225 // nondefdecl->set_type(SgTemplateType::createType());
12226 nondefdecl->set_type(SgClassType::createType(nondefdecl));
12227 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12228#if 0
12229 printf ("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): built class type: part 1: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12230#endif
12231 }
12232#endif
12233
12234 // Build a SgTemplateClassSymbol and put it into the specified scope.
12235 if (scope != NULL)
12236 {
12237#if 0
12238 printf ("Building a SgTemplateSymbol using nameWithTemplateSpecializationArguments = %s and nondefdecl = %p = %s \n",nameWithTemplateSpecializationArguments.str(),nondefdecl,nondefdecl->class_name().c_str());
12239#endif
12240 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12241 // mysymbol = new SgTemplateSymbol(nondefdecl);
12242 // mysymbol = new SgClassSymbol(nondefdecl);
12243 mysymbol = new SgTemplateClassSymbol(nondefdecl);
12244 ROSE_ASSERT(mysymbol != NULL);
12245
12246 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12247 // DQ (3/6/2012): Added test for existing symbol (see test2012_18.C).
12248 // ROSE_ASSERT(scope->lookup_template_class_symbol(name) == NULL);
12249 // ROSE_ASSERT(scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList) == NULL);
12250 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList) == NULL);
12251
12252 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12253 // scope->insert_symbol(name, mysymbol);
12254 scope->insert_symbol(nameWithTemplateSpecializationArguments, mysymbol);
12255#if 0
12256 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi() (after building symbol): scope = %p = %s \n",scope,scope->class_name().c_str());
12257#endif
12258 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
12259
12260 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
12261
12262 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12263 // ROSE_ASSERT(scope->lookup_template_class_symbol(name) != NULL);
12264 // ROSE_ASSERT(scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList) != NULL);
12265 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList) != NULL);
12266 }
12267 else
12268 {
12269 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknown.
12270 }
12271
12272 testTemplateArgumentParents(nondefdecl);
12273
12274#if 1
12275 // DQ (7/16/2017): Added code to set the template parameters in the just build declaration (if it is a template declaration).
12276 // We want to set the parents of the template paremters to the frst nondefining template class declaration, and we want to reset
12277 // the scope of the declarations associated with any previously marked SgClassType objects associated with any template parameters.
12278 // printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): Calling setTemplateParametersInDeclaration(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
12279
12280 setTemplateParametersInDeclaration(nondefdecl,templateParameterList);
12281
12282 // DQ (8/13/2013): Adding test of template parameter lists.
12283 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(nondefdecl);
12284 ROSE_ASSERT(templateClassDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateClassDeclaration->get_templateParameters().size()));
12285#endif
12286 }
12287
12288 // defdecl->set_firstNondefiningDeclaration(nondefdecl);
12289
12290 // DQ (11/3/2012): Setup the default source position information.
12291 setSourcePosition(nondefdecl);
12292
12293#if 0
12294 // DQ (11/20/2011): SgTemplateClassDeclaration IR nodes don't have a SgType associated with them (template declarations don't have a type in C++, I think).
12295
12296 // Liao, 10/30/2009
12297 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
12298 // This is not desired when building a defining declaration and an inefficience in the constructor
12299 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
12300 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
12301 if (defdecl->get_type() != NULL)
12302 {
12303 // if a defining class declaration's type is associated with a defining class.
12304 // This is a wrong SgClassType and has to be reset
12305 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
12306 {
12307 delete defdecl->get_type();
12308 }
12309 }
12310
12311 // patch up the SgClassType for the defining class declaration
12312 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12313 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
12314 defdecl->set_type(nondefdecl->get_type());
12315#else
12316 // printf ("We might need to force the types used for defining and non-defining SgTemplateClassDeclaration to be the same! \n");
12317 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12318#endif
12319
12320 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
12321 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
12322 // used in a defining declaration).
12323 nondefdecl->setForward();
12324
12325 if (scope != NULL) // put into fixStructDeclaration() or alike later on
12326 {
12327 // fixStructDeclaration(defdecl,scope);
12328 // fixStructDeclaration(nondefdecl,scope);
12329
12330 // printf ("***** WARNING *****: Commented out call to fixStructDeclaration() \n");
12331 // ROSE_ASSERT(false);
12332 }
12333
12334#if 0
12335 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
12336 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
12337
12338 ROSE_ASSERT(defdecl->get_scope() != NULL);
12339#endif
12340
12341 // DQ (7/15/2012): We want to enforce this to not be set yet (might be part of non-autonomous declaration (e.g. nested in a typedef).
12342 ROSE_ASSERT(nondefdecl->get_parent() == NULL);
12343
12344 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
12345 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
12346
12347 testTemplateArgumentParents(nondefdecl);
12348
12349#if 0
12350 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12351 printf ("Leaving buildNondefiningTemplateClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
12352 SgClassDeclaration* tmp_classDeclaration = nondefdecl;
12353 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(tmp_classDeclaration);
12354
12355 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12356 printf ("Leaving buildNondefiningTemplateClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
12357 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
12358#endif
12359
12360 return nondefdecl;
12361 }
12362
12365 SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12366{
12367 SgTemplateClassDeclaration * res = buildTemplateClassDeclaration_nfi (XXX_name, kind, scope, nonDefiningDecl, templateParameterList, templateSpecializationArgumentList);
12369 return res;
12370}
12371
12374 SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12375 {
12376 // DQ (12/26/2011): Notes that the input nonDefiningDecl is not used...this is a confusing point.
12377 // The specification of the scope appears to be enough.
12378
12379 if (scope == NULL)
12381
12382#if 0
12383 printf ("In buildTemplateClassDeclaration_nfi(): nonDefiningDecl = %p \n",nonDefiningDecl);
12384 if (nonDefiningDecl != NULL)
12385 {
12386 printf ("--- nonDefiningDecl->get_firstNondefiningDeclaration() = %p \n",nonDefiningDecl->get_firstNondefiningDeclaration());
12387 printf ("--- nonDefiningDecl->get_definingDeclaration() = %p \n",nonDefiningDecl->get_definingDeclaration());
12388 }
12389#endif
12390
12391 // DQ (11/20/2011): This is for initial debugging only.
12392 ROSE_ASSERT(scope != NULL);
12393
12394 // DQ (9/12/2012): We want to add the template arguments of any specialization to the template name and keep track of the name with and without template specialization arguments.
12395 SgName nameWithoutTemplateArguments = XXX_name;
12396 SgName nameWithTemplateSpecializationArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateSpecializationArgumentList);
12397
12398 // step 1. Build defining declaration
12399 // Note that even the SgTemplateClassDeclaration uses a regular SgClassDefinition instead of the currently unused SgTemplateClassDefinition.
12400 // SgClassDefinition* classDef = buildClassDefinition();
12401 // SgTemplateClassDefinition* classDef = buildTemplateClassDefinition(name,);
12402
12403 // DQ (11/29/2011): Added checks...
12404 if (nonDefiningDecl != NULL)
12405 {
12406 ROSE_ASSERT(nonDefiningDecl->get_firstNondefiningDeclaration() == nonDefiningDecl);
12407 }
12408
12409 SgName templateString = "template string";
12410 // SgTemplateDeclaration::template_type_enum template_kind = SgTemplateDeclaration::e_template_class;
12411 SgTemplateParameterPtrList templateParameters;
12412
12413 // SgTemplateDeclaration (SgName name, SgName string, SgTemplateDeclaration::template_type_enum template_kind, SgTemplateParameterPtrList templateParameters)
12414 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,kind,NULL,classDef);
12415 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters);
12416
12417 // SgTemplateClassDeclaration::class_types template_class_kind = SgTemplateClassDeclaration::e_class;
12418 // SgTemplateType* classType = NULL;
12419 // SgTemplateClassDefinition* classDef = NULL;
12421
12422 // Constructure arguments: SgName, SgName, SgTemplateDeclaration::template_type_enum, SgTemplateParameterPtrList, SgTemplateClassDeclaration::class_types, SgClassType*, SgTemplateClassDefinition*
12423 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters);
12424 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,template_class_kind,classType,classDef);
12425 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,template_class_kind,classDef);
12426
12427#if 0
12428 printf ("In buildTemplateClassDeclaration_nfi(): calling new SgTemplateClassDeclaration() name = %s \n",nameWithTemplateSpecializationArguments.str());
12429#endif
12430
12431 // DQ (9/12/2012): We want to include the template specialization into the name where it is required (this handling
12432 // is similar to normal template arguments for non-template declaration, but different than template parameters).
12433 // This copy of SgName is required to support passing it to the SgTemplateClassDeclaration constructor.
12434 // SgName localName = name;
12435 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,template_class_kind,classDef);
12436 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,kind,NULL,classDef);
12437
12438 // DQ (1/13/2013): This is causing two defining declarations to be built for test2012_278.C (and the parent for the second defining
12439 // declaration is not being set, though the larger issue is that we have two defining declarations, however this might be acceptable
12440 // if this is a specialization).
12441 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (nameWithTemplateSpecializationArguments,kind,NULL,classDef);
12442 SgTemplateClassDeclaration* defdecl = NULL;
12443 if (nonDefiningDecl != NULL)
12444 {
12445 // If we have a non-defining declaration specified, try to use any existing defining declaration withouth building a 2nd one
12446 // (which would be an error, unless maybe if this is a specialization).
12447 if (nonDefiningDecl->get_definingDeclaration() != NULL)
12448 {
12449 // This must be a valid SgTemplateClassDefinition.
12450 defdecl = isSgTemplateClassDeclaration(nonDefiningDecl->get_definingDeclaration());
12451 ROSE_ASSERT(defdecl != NULL);
12452#if 0
12453 printf ("In buildTemplateClassDeclaration_nfi(): Reusing the defining declaration previously build: defdecl = %p = %s \n",defdecl,defdecl->get_name().str());
12454#endif
12455 }
12456 else
12457 {
12458#if 0
12459 printf ("In buildTemplateClassDeclaration_nfi(): No defining declaration found, so we have to build one. \n");
12460#endif
12461 }
12462 }
12463
12464 if (defdecl == NULL)
12465 {
12466#if 0
12467 printf ("Building a defining declaration \n");
12468#endif
12469 defdecl = new SgTemplateClassDeclaration (nameWithTemplateSpecializationArguments,kind,NULL,classDef);
12470 }
12471
12472 ROSE_ASSERT(defdecl != NULL);
12473
12474#if 0
12475 printf ("In buildTemplateClassDeclaration_nfi(): defdecl = %p = %s \n",defdecl,defdecl->class_name().c_str());
12476#endif
12477
12478 // DQ (9/10/2012): Initialize the template parameter list.
12479 ROSE_ASSERT(templateParameterList != NULL);
12480 defdecl->get_templateParameters() = *templateParameterList;
12481
12482 // DQ (9/12/2012): Adding support for template specialization.
12483 ROSE_ASSERT(templateSpecializationArgumentList != NULL);
12484 defdecl->get_templateSpecializationArguments() = *templateSpecializationArgumentList;
12485
12486 // DQ (9/16/2012): We can't test this yet, since the firstNondefiningDeclaration has not be set.
12487 // testTemplateArgumentParents(defdecl);
12488
12489 // DQ (9/10/2012): Test the just built template with its template parameters.
12490 if (defdecl->get_templateParameters().size() == 0)
12491 {
12492#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12493 printf ("WARNING: In buildTemplateClassDeclaration_nfi(): defdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations defdecl = %p \n",defdecl);
12494#endif
12495 }
12496 // ROSE_ASSERT(defdecl->get_templateParameters().size() > 0);
12497
12498 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12499 defdecl->set_templateName(nameWithoutTemplateArguments);
12500
12501#if 0
12502 printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): scope = %p = %s \n",scope,scope->class_name().c_str());
12503#endif
12504
12505 defdecl->set_scope(scope);
12506
12507 // DQ (7/15/2012): To support non-autonomous declarations (declarations nested in types) we don't want to set the parent here. It will be set later.
12508 // DQ (11/20/2011): Can name qualification make this incorrect?
12509 // defdecl->set_parent(scope);
12510
12511 ROSE_ASSERT(classDef != NULL);
12512
12513 // printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): defdecl = %p \n",defdecl);
12514
12516
12517 // constructor is side-effect free
12518 classDef->set_declaration(defdecl);
12519 defdecl->set_definingDeclaration(defdecl);
12520
12521 // Step 2. build the nondefining declaration,
12522 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
12523
12524 // Get the nondefining declaration from the symbol if it has been built (if this works,
12525 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
12526 SgTemplateClassDeclaration* nondefdecl = nonDefiningDecl;
12527 if (nondefdecl == NULL) {
12528 ROSE_ASSERT(scope != NULL);
12529
12530 SgClassSymbol* mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
12531#if 0
12532 printf ("In buildTemplateClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
12533#endif
12534
12535 if (mysymbol != NULL) {
12536 nondefdecl = isSgTemplateClassDeclaration(mysymbol->get_declaration());
12537 ROSE_ASSERT(nondefdecl != NULL);
12538
12539 nondefdecl->set_definingDeclaration(defdecl);
12540 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
12541 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
12542
12543 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
12544 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
12545
12546 // DQ (9/16/2012): Test this previously setup firstNondefiningDeclaration.
12547 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
12548 testTemplateArgumentParents(nondefdecl);
12549 } else {
12550#if 0
12551 printf(" start build non-defn decl for %p\n",defdecl);
12552#endif
12553 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
12554 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,NULL,NULL);
12555 ROSE_ASSERT(nondefdecl != NULL);
12556
12557 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12558 nondefdecl->set_definingDeclaration(defdecl);
12559#if 0
12560 printf(" nondefdecl = %p\n",nondefdecl);
12561#endif
12562#if 0
12563 // TV (04/12/2018): Add a scope for nonreal classes (and their member) on the first non-defining declaration of template classes
12564 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
12565
12566 nonreal_decl_scope->set_parent(nondefdecl);
12567 nondefdecl->set_nonreal_decl_scope(nonreal_decl_scope);
12568
12569 SageInterface::setSourcePosition(nonreal_decl_scope);
12570 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
12571 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
12572#if 1
12573 printf("In buildTemplateClassDeclaration_nfi(): nrscope = %p\n", nonreal_decl_scope);
12574#endif
12575#endif
12576 // DQ (9/10/2012): Initialize the template parameter list.
12577 ROSE_ASSERT(templateParameterList != NULL);
12578 nondefdecl->get_templateParameters() = *templateParameterList;
12579
12580 // DQ (9/16/2012): Newly refactored code.
12581 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
12582 testTemplateArgumentParents(nondefdecl);
12583
12584 // DQ (9/10/2012): Test the just built template with its template parameters.
12585 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12586 if (nondefdecl->get_templateParameters().size() == 0)
12587 {
12588#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12589 printf ("WARNING: In buildTemplateClassDeclaration_nfi(): nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
12590#endif
12591 }
12592 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12593#if 0
12594 printf(" next 1\n");
12595#endif
12596
12597 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12598 nondefdecl->set_templateName(nameWithoutTemplateArguments);
12599
12600 // DQ (12/26/2011): The non defining declaration should not have a valid pointer to the class definition.
12601 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
12602
12603 // The nondefining declaration will not appear in the source code, but is compiler
12604 // generated (so we have something about the class that we can reference; e.g in
12605 // types). At the moment we make it a transformation, there might be another kind
12606 // of source position that would be more precise. FIXME.
12608 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
12609
12610 nondefdecl->setForward();
12611
12612 // Liao, 9/2/2009. scope stack is optional, it can be empty
12613 nondefdecl->set_parent(scope);
12614 nondefdecl->set_scope(scope);
12615#if 0
12616 printf(" next 2\n");
12617#endif
12618
12619 if (nondefdecl->get_type() == NULL)
12620 {
12621 nondefdecl->set_type(SgClassType::createType(nondefdecl));
12622#if 0
12623 printf ("In SageBuilder::buildTemplateClassDeclaration_nfi(): built class type: part 1: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12624#endif
12625 }
12626#if 0
12627 printf(" next 3\n");
12628#endif
12629
12630 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
12631 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
12632
12633 // DQ (7/16/2017): Added code to set the template parameters in the just build declaration (if it is a template declaration).
12634 // We want to set the parents of the template paremters to the frst nondefining template class declaration, and we want to reset
12635 // the scope of the declarations associated with any previously marked SgClassType objects associated with any template parameters.
12636 // printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): Calling setTemplateParametersInDeclaration(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
12637
12638 setTemplateParametersInDeclaration(nondefdecl,templateParameterList);
12639
12640 // DQ (8/13/2013): Adding test of template parameter lists.
12641 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(nondefdecl);
12642 ROSE_ASSERT(templateClassDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateClassDeclaration->get_templateParameters().size()));
12643
12644 mysymbol = new SgTemplateClassSymbol(nondefdecl);
12645 scope->insert_symbol(nameWithTemplateSpecializationArguments, mysymbol);
12646#if 0
12647 printf(" end build non-defn decl\n");
12648#endif
12649 }
12650 } else {
12651 SgClassSymbol* mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
12652 if (mysymbol == NULL) {
12653 printf("WARNING: In buildTemplateClassDeclaration_nfi(): non-defining declaration was provided but cannot be located in the associated scope.\n");
12654 }
12655 }
12656
12657#if 0
12658 printf ("In buildTemplateClassDeclaration_nfi(): Setting the firstNondefiningDeclaration to be nondefdecl = %p \n",nondefdecl);
12659#endif
12660
12661 defdecl->set_firstNondefiningDeclaration(nondefdecl);
12662
12663 // DQ (9/16/2012): Setup the template specialization arguments on the defining declaration (tested below at base of function).
12664 setTemplateSpecializationArgumentsInDeclaration(defdecl,templateSpecializationArgumentList);
12665
12666#if 1
12667 // DQ (11/20/2011): SgTemplateClassDeclaration IR nodes don't have a SgType associated with them (template declarations don't have a type in C++, I think).
12668
12669 // Liao, 10/30/2009
12670 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
12671 // This is not desired when building a defining declaration and an inefficience in the constructor
12672 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
12673 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
12674 if (defdecl->get_type() != NULL)
12675 {
12676 // if a defining class declaration's type is associated with a defining class.
12677 // This is a wrong SgClassType and has to be reset
12678#if 0
12679 // if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
12680 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
12681 {
12682 delete defdecl->get_type();
12683 }
12684#else
12685 // DQ (1/13/2013): I am not clear what this means... if (defdecl->get_type() != NULL) then it makes
12686 // no sense to assert that (defdecl->get_type() == NULL). This is related to the reuse of the defining
12687 // declaration when it is available (instead of building a new one, which still might be required for a
12688 // template specialization (or template partial specialization)).
12689 // ROSE_ASSERT(defdecl->get_type() == NULL);
12690#endif
12691 }
12692
12693 // patch up the SgClassType for the defining class declaration
12694 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12695 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
12696
12697 // DQ (1/22/2013): This assertion is a problem for boost code represented by ROSE compiling ROSE (see testRoseHeaders_01.C)
12698 if (isSgClassType(nondefdecl->get_type())->get_declaration() != isSgDeclarationStatement(nondefdecl))
12699 {
12700#if 0
12701 printf ("In buildTemplateClassDeclaration_nfi(): detected isSgClassType(nondefdecl->get_type())->get_declaration() != isSgDeclarationStatement(nondefdecl) (problem with Boost code in ROSE compiling ROSE) \n");
12702#endif
12703 }
12704 // ROSE_ASSERT (isSgClassType(nondefdecl->get_type())->get_declaration() == isSgDeclarationStatement(nondefdecl));
12705
12706 defdecl->set_type(nondefdecl->get_type());
12707
12708#if 0
12709 printf ("In SageBuilder::buildTemplateClassDeclaration_nfi(): built class type: part 2: defdecl->get_type() = %p = %s \n",defdecl->get_type(),defdecl->get_type()->class_name().c_str());
12710#endif
12711#endif
12712
12713 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
12714 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
12715 // used in a defining declaration).
12716 nondefdecl->setForward();
12717
12718#if 0
12719 if (scope != NULL) // put into fixStructDeclaration() or alike later on
12720 {
12721 // fixStructDeclaration(defdecl,scope);
12722 // fixStructDeclaration(nondefdecl,scope);
12723
12724 printf ("***** WARNING *****: Commented out call to fixStructDeclaration() \n");
12725 // ROSE_ASSERT(false);
12726 }
12727#endif
12728
12729 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
12730 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
12731
12732 ROSE_ASSERT(defdecl->get_scope() != NULL);
12733
12734 // DQ (12/4/2011): We need a concept for type for SgTemplateClassDeclaration so that we can construct SgMemberFunctionType nodes for template member functions.
12735 // We use a SgClassType which has been fixed to permit it to hold either a SgClassDeclaration or an SgTemplateClassDeclaration.
12736 ROSE_ASSERT(defdecl->get_type() != NULL);
12737
12738 // DQ (12/26/2011): The non defining declaration should not have a valid pointer to the class definition.
12739 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
12740
12741 // DQ (7/15/2012): We want to inforce this.
12742 // ROSE_ASSERT(defdecl->get_parent() == NULL);
12743 if (defdecl->get_parent() != NULL)
12744 {
12745#if PRINT_DEVELOPER_WARNINGS
12746 printf ("WARNING: the parent will have been set if the defining declaration was found and reused! defdecl = %p = %s \n",defdecl,defdecl->class_name().c_str());
12747#endif
12748 }
12749
12750 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
12751 ROSE_ASSERT(defdecl->get_templateName().is_null() == false);
12752
12753 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
12754 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
12755
12757 testTemplateArgumentParents(nondefdecl);
12758
12759#if 0
12760 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12761 printf ("Leaving buildTemplateClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
12762 SgClassDeclaration* tmp_classDeclaration = defdecl;
12763 SgSymbol* test_symbol = defdecl->get_scope()->find_symbol_from_declaration(tmp_classDeclaration);
12764
12765 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12766 printf ("Leaving buildTemplateClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
12767 ROSE_ASSERT(defdecl->get_symbol_from_symbol_table() != NULL);
12768#endif
12769
12770 return defdecl;
12771 }
12772
12774 {
12775 // DQ (1/11/2009): This function has semantics very different from the buildEnumDeclaration_nfi() function!
12776
12777 if (scope == NULL)
12779
12780 SgEnumDeclaration* decl = buildEnumDeclaration_nfi(name, scope);
12784
12785 // DQ (7/15/2012): We want to inforce this.
12786 ROSE_ASSERT(decl->get_parent() == NULL);
12787
12788 return decl;
12789 } //buildEnumDeclaration()
12790
12791
12794 {
12795 // The support for SgEnumDeclaration is identical to that for SgClassDeclaration (except for the type handling, why is that?).
12796 ASSERT_not_null(scope);
12797
12798 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
12799 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
12800 ASSERT_require(SageInterface::hasTemplateSyntax(name) == false);
12801
12802 SgEnumType* enumType = nullptr;
12803 SgEnumDeclaration* first_nondefdecl = nullptr;
12804
12805 if (scope)
12806 {
12807 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
12808 if (existing_symbol != NULL)
12809 {
12810 enumType = isSgEnumType(existing_symbol->get_type());
12811 first_nondefdecl = existing_symbol->get_declaration();
12812 ROSE_ASSERT(first_nondefdecl != NULL);
12813 }
12814 }
12815
12816 // DQ (5/8/2013): We do want to build a new SgEnumDeclaration (to avoid sharing).
12817 // This forces each call to buildNondefiningEnumDeclaration_nfi() to build a unique declaration
12818 // required to avoid sharing declaration in examples such as test2007_29.C.
12819 SgEnumDeclaration* nondefdecl = new SgEnumDeclaration(name, enumType);
12820
12821 ROSE_ASSERT(nondefdecl);
12822 setOneSourcePositionNull(nondefdecl);
12823
12824 // Set the defining and first non-defining declarations.
12825 if (first_nondefdecl)
12826 {
12827 nondefdecl->set_firstNondefiningDeclaration(first_nondefdecl);
12828 nondefdecl->set_definingDeclaration(first_nondefdecl->get_definingDeclaration());
12829 }
12830 else
12831 {
12832 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12833 nondefdecl->set_definingDeclaration(nullptr);
12834 }
12835
12836 // Any non-defining declaration is not always a forward declaration.
12837 nondefdecl->setForward();
12838
12839 SgType* type = nondefdecl->get_type();
12840 ASSERT_not_null(type);
12841
12842 if (scope)
12843 {
12844 // Check for an existing symbol (reuse it if it is found).
12845 SgEnumSymbol* mysymbol = nullptr;
12846 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
12847
12848 if (existing_symbol)
12849 {
12850 mysymbol = existing_symbol;
12851 first_nondefdecl = mysymbol->get_declaration();
12852 }
12853 else
12854 {
12855 first_nondefdecl = nondefdecl;
12856
12857 mysymbol = new SgEnumSymbol(nondefdecl);
12858 ASSERT_not_null(mysymbol);
12859 scope->insert_symbol(name, mysymbol);
12860 }
12861
12862 nondefdecl->set_scope(scope);
12863
12864 // Can this be defined in C++ so that it is in a logical scope different from its structural scope?
12865 nondefdecl->set_parent(scope);
12866 }
12867
12868 if (first_nondefdecl != nondefdecl)
12869 {
12870 nondefdecl->set_firstNondefiningDeclaration(first_nondefdecl);
12871
12872 if (first_nondefdecl->get_definingDeclaration() != NULL)
12873 {
12874 nondefdecl->set_definingDeclaration(first_nondefdecl->get_definingDeclaration());
12875 }
12876 }
12877
12878 ASSERT_not_null(nondefdecl->get_type());
12879 ASSERT_not_null(scope->lookup_enum_symbol(name));
12880
12881 return nondefdecl;
12882 }
12883
12884
12887 {
12888 ROSE_ASSERT(scope != NULL);
12889
12890#if 0
12891 printf ("In buildEnumDeclaration_nfi(): name = %s scope = %p = %s \n",name.str(),scope,scope->class_name().c_str());
12892#endif
12893
12894 // DQ (5/8/2013): I think if we searched for the type it might exist and this would allow the types to be shared.
12895 SgEnumType* enumType = NULL;
12896
12897 if (scope != NULL)
12898 {
12899 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
12900 if (existing_symbol != NULL)
12901 {
12902 enumType = isSgEnumType(existing_symbol->get_type());
12903 }
12904 }
12905
12906#if 0
12907 printf ("In buildEnumDeclaration_nfi(): name = %s building using enumType = %p \n",name.str(),enumType);
12908#endif
12909
12910 // SgEnumDeclaration* defdecl = new SgEnumDeclaration (name,NULL);
12911 SgEnumDeclaration* defdecl = new SgEnumDeclaration (name,enumType);
12912 ROSE_ASSERT(defdecl);
12913
12914#if 0
12915 printf ("In buildEnumDeclaration_nfi(): built defining declaration = %p name = %s scope = %p = %s \n",defdecl,name.str(),scope,scope->class_name().c_str());
12916#endif
12917
12918 // DQ (5/8/2013): Make sure that the enum type is available.
12919 SgType* type = defdecl->get_type();
12920 ROSE_ASSERT(type != NULL);
12921
12922 setOneSourcePositionNull(defdecl);
12923 // constructor is side-effect free
12924 defdecl->set_definingDeclaration(defdecl);
12925
12926#if 0
12927 printf ("In buildEnumDeclaration_nfi(): name = %s \n",name.str());
12928#endif
12929
12930#if 1
12931 // DQ (4/3/2017): Check for an existing non-defining declaration before building one (to avoid multiple versions). See test2017_13.C.
12932 ROSE_ASSERT(scope != NULL);
12933 SgEnumSymbol* enumSymbol = scope->lookup_enum_symbol(name);
12934 // ROSE_ASSERT(enumSymbol != NULL);
12935 SgEnumDeclaration* nondefdecl = NULL;
12936 if (enumSymbol != NULL)
12937 {
12938 ROSE_ASSERT(enumSymbol->get_declaration() != NULL);
12939 nondefdecl = enumSymbol->get_declaration();
12940 ROSE_ASSERT(nondefdecl != NULL);
12941 }
12942 else
12943 {
12944 // build the nondefining declaration
12945 nondefdecl = buildNondefiningEnumDeclaration_nfi(name, scope);
12946#if 0
12947 printf ("###### In buildEnumDeclaration_nfi(): built a non-defining declaration to support the symbol table: name = %s nondefdecl = %p \n",name.str(),nondefdecl);
12948#endif
12949 }
12950#else
12951 // build the nondefining declaration
12952 SgEnumDeclaration* nondefdecl = buildNondefiningEnumDeclaration_nfi(name, scope);
12953#endif
12954
12955 nondefdecl->set_definingDeclaration(defdecl);
12956 // defdecl->set_firstNondefiningDeclaration(nondefdecl);
12958
12959 // DQ (4/22/2013): We need to set the defining declaration on the first non-defining declaration.
12960 if (nondefdecl->get_firstNondefiningDeclaration() != NULL && nondefdecl->get_firstNondefiningDeclaration() != nondefdecl)
12961 {
12963 }
12964
12965 // DQ (4/22/2013): Thing that should be true at this point.
12966 ROSE_ASSERT(nondefdecl->get_definingDeclaration() != NULL);
12967 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
12968 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration()->get_definingDeclaration() != NULL);
12969 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration()->get_firstNondefiningDeclaration() != NULL);
12970 ROSE_ASSERT(defdecl->get_definingDeclaration() != NULL);
12971 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
12972
12973 // DQ (1/11/2009): The buildNondefiningEnumDeclaration function builds an entry in the symbol table, and so we don't want a second one!
12974#if 0
12975 SgEnumSymbol* mysymbol = new SgEnumSymbol(nondefdecl);
12976 ROSE_ASSERT(mysymbol);
12977 // scope->print_symboltable("buildEnumDeclaration_nfi(): before inserting new SgEnumSymbol");
12978 scope->insert_symbol(name, mysymbol);
12979#endif
12980
12981 defdecl->set_scope(scope);
12982 nondefdecl->set_scope(scope);
12983
12984#if 0
12985 // DQ (7/12/2012): We can't set the parent here because if this is a non-autonomous declaration then it must be set later (to the outer declaration where this declaration is nested).
12986 defdecl->set_parent(scope);
12987 nondefdecl->set_parent(scope);
12988#endif
12989
12990 // DQ (7/12/2012): When this is an unnamed enum declaration, this it is NON-AUTONIMOUS
12991 // (and will have it's parent set in the associated variable or typedef declaration.
12992 // In the case of a class declaration this is always NULL (this should be similar).
12993 ROSE_ASSERT(defdecl->get_parent() == NULL);
12994
12995#if 0
12996 printf ("In buildEnumDeclaration_nfi(): name = %s defdecl = %p \n",name.str(),defdecl);
12997#endif
12998
12999 // DQ (5/8/2013): Check that the symbol is present.
13000 ROSE_ASSERT(scope->lookup_enum_symbol(name) != NULL);
13001
13002 return defdecl;
13003 } //buildEnumDeclaration_nfi()
13004
13005
13007SageBuilder::buildBaseClass ( SgClassDeclaration* classDeclaration, SgClassDefinition* classDefinition, bool isVirtual, bool isDirect )
13008 {
13009 // DQ (5/6/2013): Refactored the construction of the SgBaseClass support to the builder API.
13010
13011 // Note: classDeclaration should be the first non-defining class declaration, not required to be the the declaration associated with the SgClassDefinition.
13012 ROSE_ASSERT(classDeclaration != NULL);
13013 ROSE_ASSERT(classDefinition != NULL);
13014
13015 // DQ (5/6/2013): This is not always true (see test2013_63.C).
13016 // ROSE_ASSERT(classDeclaration == classDeclaration->get_firstNondefiningDeclaration());
13017
13018 ROSE_ASSERT(classDefinition->get_declaration() != NULL);
13019
13020 // DQ (5/6/2013): This is not always true (see test2004_30.C).
13021 // ROSE_ASSERT(classDefinition->get_declaration() == classDeclaration->get_firstNondefiningDeclaration());
13022
13023 SgBaseClass* baseclass = new SgBaseClass ( classDeclaration, isDirect );
13024 ROSE_ASSERT(baseclass != NULL);
13025
13026 if (isVirtual == true)
13027 {
13028 // DQ (1/21/2019): get_baseClassModifier() uses ROSETTA generated access functions which return a pointer.
13029 // baseclass->get_baseClassModifier().setVirtual();
13030 ROSE_ASSERT(baseclass->get_baseClassModifier() != NULL);
13031 baseclass->get_baseClassModifier()->setVirtual();
13032 }
13033
13034 // DQ (4/29/2004): add support to set access specifier
13035 // baseclass->get_baseClassModifier().get_accessModifier() = set_access_modifiers(bcdp->access);
13036 // baseclass->get_baseClassModifier().get_accessModifier() = buildAccessModifier(accessModifiers);
13037
13038 // DQ (6/21/2005): Set the parent of the base class to the class definition
13039 // (these are not traversed in ROSE currently, so their parents are not set).
13040 baseclass->set_parent(classDefinition);
13041
13042 // DQ (6/21/2005): Notice that this is copied by value (the base class list should be a list of pointers to SgBaseClass (later)
13043 classDefinition->append_inheritance(baseclass);
13044
13045 return baseclass;
13046 }
13047
13048
13050SageBuilder::buildNonrealBaseClass ( SgNonrealDecl* nrdecl, SgClassDefinition* classDefinition, bool isVirtual, bool isDirect )
13051 {
13052 ROSE_ASSERT(nrdecl != NULL);
13053 ROSE_ASSERT(classDefinition != NULL);
13054
13055 SgNonrealBaseClass * baseclass = new SgNonrealBaseClass ( NULL , isDirect , nrdecl );
13056 ROSE_ASSERT(baseclass != NULL);
13057
13058 if (isVirtual == true)
13059 {
13060 baseclass->get_baseClassModifier()->setVirtual();
13061 }
13062
13063 baseclass->set_parent(classDefinition);
13064
13065 classDefinition->append_inheritance(baseclass);
13066
13067 return baseclass;
13068 }
13069
13070
13071#if 0
13072// This function would be more complex that I want to support at present since the mapping of
13073// edg modifier values to ROSE modifier values is offset and backwards (reversed in numerical order).
13075SageBuilder::buildAccessModifier ( unsigned int access )
13076 {
13078
13079 switch (access)
13080 {
13081 case as_public:
13082#if 0
13083 printf ("In SageBuilder::set_access_modifiers(): Mark as public \n");
13084#endif
13085 a.setPublic();
13086 break;
13087
13088 case as_protected:
13089#if 0
13090 printf ("In SageBuilder::set_access_modifiers(): Mark as protected \n");
13091#endif
13092 a.setProtected();
13093 break;
13094
13095 case as_private:
13096#if 0
13097 printf ("In SageBuilder::set_access_modifiers(): Mark as private \n");
13098#endif
13099 a.setPrivate();
13100 break;
13101
13102 default:
13103 printf ("Error: default reached in SageBuilder::set_access_modifiers() \n");
13104 ROSE_ABORT ();
13105 }
13106
13107 return a;
13108 }
13109#endif
13110
13111
13112void
13113SageBuilder::fixupSourcePositionFileSpecification(SgNode* subtreeRoot, const std::string& newFileName)
13114 {
13115 // DQ (11/8/2019): This function changes the filename designation in all of the Sg_File_Info objects
13116 // associated with the designated AST subtree.
13117
13118 ROSE_ASSERT(subtreeRoot != NULL);
13119 ROSE_ASSERT(newFileName != "");
13120
13121#define DEBUG_FIXUP 0
13122
13123#if DEBUG_FIXUP
13124 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): newFileName = %s \n",newFileName.c_str());
13125 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13126#endif
13127
13128 class Traversal : public AstSimpleProcessing
13129 {
13130 public:
13131
13132 Traversal(const std::string& tmp_newFileName, int tmp_new_file_id, int tmp_originalFileId)
13133 {
13134 newFileName = tmp_newFileName;
13135 new_file_id = tmp_new_file_id;
13136 originalFileId = tmp_originalFileId;
13137#if DEBUG_FIXUP
13138 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): newFileName = %s new_file_id = %d originalFileId = %d \n",newFileName.c_str(),new_file_id,originalFileId);
13139#endif
13140 }
13141
13142 void visit (SgNode* node)
13143 {
13144#if DEBUG_FIXUP
13145 printf ("In fixupSourcePositionFileSpecification visit(): node = %p = %s \n",node,node->class_name().c_str());
13146#endif
13147
13148 SgLocatedNode* locatedNode = isSgLocatedNode(node);
13149 if (locatedNode != NULL)
13150 {
13151 // if (locatedNode->get_startOfConstruct()->get_file_id() == originalFileId)
13152 if (locatedNode->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13153 {
13154 ROSE_ASSERT(locatedNode->get_startOfConstruct() != NULL);
13155 ROSE_ASSERT(locatedNode->get_endOfConstruct() != NULL);
13156
13157 if (locatedNode->get_startOfConstruct()->isShared() == true)
13158 {
13159#if DEBUG_FIXUP
13160 printf ("Found SgLocatedNode marked as isShared() == true: locatedNode = %p = %s \n",locatedNode,locatedNode->class_name().c_str());
13161#endif
13162#if 0
13163 printf ("Exiting as a test! \n");
13164 ROSE_ABORT();
13165#endif
13166 }
13167 locatedNode->get_startOfConstruct()->set_file_id(new_file_id);
13168 locatedNode->get_endOfConstruct ()->set_file_id(new_file_id);
13169
13170 locatedNode->get_startOfConstruct()->set_physical_file_id(new_file_id);
13171 locatedNode->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13172
13173#if DEBUG_FIXUP
13174 printf ("locatedNode->get_startOfConstruct()->get_filename() = %s locatedNode->get_startOfConstruct()->get_physical_filename() = %s \n",
13175 locatedNode->get_startOfConstruct()->get_filenameString().c_str(),locatedNode->get_startOfConstruct()->get_physical_filename().c_str());
13176 printf ("locatedNode->get_startOfConstruct()->get_file_id() = %d locatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",
13177 locatedNode->get_startOfConstruct()->get_file_id(),locatedNode->get_startOfConstruct()->get_physical_file_id());
13178 printf ("locatedNode->get_startOfConstruct()->isShared() = %s \n",locatedNode->get_startOfConstruct()->isShared() ? "true" : "false");
13179#endif
13180 }
13181 else
13182 {
13183#if DEBUG_FIXUP
13184 printf ("NOT MATCHING: originalFileId = %d locatedNode->get_startOfConstruct()->get_file_id() = %d locatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",
13185 originalFileId,locatedNode->get_startOfConstruct()->get_file_id(),locatedNode->get_startOfConstruct()->get_physical_file_id());
13186 printf (" ------------ originalFileId = %d locatedNode->get_endOfConstruct()->get_file_id() = %d locatedNode->get_endOfConstruct()->get_physical_file_id() = %d \n",
13187 originalFileId,locatedNode->get_endOfConstruct()->get_file_id(),locatedNode->get_endOfConstruct()->get_physical_file_id());
13188#endif
13189 }
13190 }
13191 else
13192 {
13193 SgInitializedName* initializedName = isSgInitializedName(node);
13194 if (initializedName != NULL)
13195 {
13196 // if (initializedName->get_startOfConstruct()->get_file_id() == originalFileId)
13197 if (initializedName->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13198 {
13199 ROSE_ASSERT(initializedName->get_startOfConstruct() != NULL);
13200 ROSE_ASSERT(initializedName->get_endOfConstruct() != NULL);
13201
13202 initializedName->get_startOfConstruct()->set_file_id(new_file_id);
13203 initializedName->get_endOfConstruct ()->set_file_id(new_file_id);
13204
13205 initializedName->get_startOfConstruct()->set_physical_file_id(new_file_id);
13206 initializedName->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13207 }
13208 }
13209 else
13210 {
13211 SgSourceFile* sourceFile = isSgSourceFile(node);
13212 if (sourceFile != NULL)
13213 {
13214 ROSE_ASSERT(sourceFile->get_startOfConstruct() != NULL);
13215#if 0
13216 // A SgSourceFile has no endOfConstruct.
13217 if (sourceFile->get_endOfConstruct() == NULL)
13218 {
13219#if 0
13220 printf ("sourceFile->get_endOfConstruct() == NULL: fixup endOfConstruct \n");
13221#endif
13222 sourceFile->set_endOfConstruct(new Sg_File_Info());
13223 *(sourceFile->get_endOfConstruct()) = *(sourceFile->get_startOfConstruct());
13224 }
13225 ROSE_ASSERT(sourceFile->get_endOfConstruct() != NULL);
13226#endif
13227 // Need to test the physical_file_id because we already set the regular file_id (as part of seeding the process).
13228 // if (sourceFile->get_startOfConstruct()->get_file_id() == originalFileId)
13229 if (sourceFile->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13230 {
13231 sourceFile->get_startOfConstruct()->set_file_id(new_file_id);
13232 sourceFile->get_startOfConstruct()->set_physical_file_id(new_file_id);
13233#if DEBUG_FIXUP
13234 printf ("sourceFile->get_startOfConstruct()->get_file_id() = %d \n",sourceFile->get_startOfConstruct()->get_file_id());
13235 printf ("sourceFile->get_startOfConstruct()->get_physical_file_id() = %d \n",sourceFile->get_startOfConstruct()->get_physical_file_id());
13236#endif
13237 // sourceFile->get_endOfConstruct ()->set_file_id(new_file_id);
13238 // sourceFile->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13239 }
13240 }
13241 else
13242 {
13243#if DEBUG_FIXUP
13244 printf ("Unhandled: node = %p = %s \n",node,node->class_name().c_str());
13245#endif
13246 }
13247 }
13248 }
13249
13250 SgExpression* expression = isSgExpression(node);
13251 if (expression != NULL)
13252 {
13253 if (expression->get_operatorPosition()->get_physical_file_id() == originalFileId)
13254 {
13255 expression->get_operatorPosition()->set_file_id(new_file_id);
13256 expression->get_operatorPosition()->set_physical_file_id(new_file_id);
13257 }
13258 }
13259 }
13260
13261 // Data members.
13262 int new_file_id;
13263 int originalFileId;
13264 string newFileName;
13265 };
13266
13267
13268 SgFile* file = isSgFile(subtreeRoot);
13269 int new_file_id = -1;
13270 int originalFileId = -1;
13271
13272 if (file != NULL)
13273 {
13274 // We need to set the filename in at least one Sg_File_Info object so that we can have
13275 // the file_id be computed ans saved into the file_id to filename maps.
13276
13277 originalFileId = file->get_startOfConstruct()->get_file_id();
13278#if DEBUG_FIXUP
13279 printf ("originalFileId = %d \n",originalFileId);
13280#endif
13281 file->get_startOfConstruct()->set_filenameString(newFileName);
13282 new_file_id = Sg_File_Info::get_nametofileid_map()[newFileName];
13283
13284
13285#if 0
13286 file->get_endOfConstruct()->set_physical_file_id(new_file_id);
13287
13288 file->get_startOfConstruct()->set_physical_file_id(new_file_id);
13289 file->get_endOfConstruct()->set_physical_file_id(new_file_id);
13290
13291 // getFilenameFromID
13292 int new_file_id_2 = Sg_File_Info::getIDFromFilename(newFileName);
13293#if 0
13294 printf ("new_file_id = %d new_file_id_2 = %d \n",new_file_id,new_file_id_2);
13295#endif
13296 ROSE_ASSERT(new_file_id == new_file_id_2);
13297
13298 string new_filename_2 = Sg_File_Info::getFilenameFromID(new_file_id);
13299#if 0
13300 printf ("newFileName = %s new_filename_2 = %s \n",newFileName.c_str(),new_filename_2.c_str());
13301#endif
13302 ROSE_ASSERT(newFileName == new_filename_2);
13303#endif
13304
13305#if DEBUG_FIXUP
13306 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): file != NULL: newFileName = %s new_file_id = %d \n",newFileName.c_str(),new_file_id);
13307#endif
13308 }
13309 else
13310 {
13311 SgLocatedNode* subtreeLocatedNode = isSgLocatedNode(subtreeRoot);
13312 if (subtreeLocatedNode != NULL)
13313 {
13314#if DEBUG_FIXUP
13315 printf ("subtreeLocatedNode->get_startOfConstruct()->get_file_id() = %d \n",subtreeLocatedNode->get_startOfConstruct()->get_file_id());
13316 printf ("subtreeLocatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",subtreeLocatedNode->get_startOfConstruct()->get_physical_file_id());
13317#endif
13318 originalFileId = subtreeLocatedNode->get_startOfConstruct()->get_file_id();
13319 new_file_id = Sg_File_Info::getIDFromFilename(newFileName);
13320#if DEBUG_FIXUP
13321 printf ("originalFileId = %d \n",originalFileId);
13322 printf ("new_file_id = %d \n",new_file_id);
13323#endif
13324#if DEBUG_FIXUP
13325 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): subtreeLocatedNode = %s : originalFileId = %d newFileName = %s new_file_id = %d \n",
13326 subtreeLocatedNode->class_name().c_str(),originalFileId,newFileName.c_str(),new_file_id);
13327#endif
13328 }
13329 else
13330 {
13331 printf ("Error: In SageBuilder::fixupSourcePositionFileSpecification(): subtree should be a SgFile or SgLocatedNode: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13332 ROSE_ABORT();
13333 }
13334
13335#if 0
13336 printf ("Error: In SageBuilder::fixupSourcePositionFileSpecification(): subtree should be a SgFile: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13337 ROSE_ABORT();
13338#endif
13339 }
13340
13341 ROSE_ASSERT(new_file_id >= 0);
13342
13343 // Now build the traveral object and call the traversal (preorder) on the function definition.
13344 Traversal traversal (newFileName,new_file_id,originalFileId);
13345
13346 // traversal.traverse(subtreeRoot, preorder);
13347 // traversal.traverseInputFiles(subtreeRoot, preorder);
13348 // traversal.traverseWithinFile(subtreeRoot, preorder);
13349 traversal.traverse(subtreeRoot, preorder);
13350
13351#if 0
13352 printf ("Exiting as a test in SageBuilder::fixupSourcePositionFileSpecification() \n");
13353 ROSE_ABORT();
13354#endif
13355 }
13356
13357
13358
13359
13360
13361
13362
13363
13364void
13366 {
13367 // DQ (11/8/2019): This function changes the filename designation in all of the Sg_File_Info objects
13368 // associated with the designated AST subtree.
13369
13370 ROSE_ASSERT(subtreeRoot != NULL);
13371 ROSE_ASSERT(new_file_id >= 0);
13372
13373#if 0
13374 printf ("In SageBuilder::fixupSharingSourcePosition(): subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13375 printf ("In SageBuilder::fixupSharingSourcePosition(): new_file_id = %d \n",new_file_id);
13376#endif
13377
13378 class Traversal : public AstSimpleProcessing
13379 {
13380 public:
13381
13382 Traversal(int tmp_new_file_id)
13383 {
13384 new_file_id = tmp_new_file_id;
13385#if 0
13386 printf ("In SageBuilder::fixupSharingSourcePosition(): new_file_id = %d \n",new_file_id);
13387#endif
13388 }
13389
13390 void visit (SgNode* node)
13391 {
13392#if 0
13393 printf ("In fixupSharingSourcePosition visit(): node = %p = %s new_file_id = %d \n",node,node->class_name().c_str(),new_file_id);
13394#endif
13395
13396 SgStatement* statement = isSgStatement(node);
13397 if (statement != NULL)
13398 {
13399 Sg_File_Info* startOfConstruct = statement->get_startOfConstruct();
13400 Sg_File_Info* endOfConstruct = statement->get_endOfConstruct();
13401#if 0
13402 printf ("new_file_id = %d startOfConstruct->get_physical_file_id() = %d \n",new_file_id,startOfConstruct->get_physical_file_id());
13403#endif
13404 // Only mark the files from the associated file (not statements in header files, for example).
13405 if (startOfConstruct->get_physical_file_id() == new_file_id)
13406 {
13407 // Mark this IR node as being shared
13408 startOfConstruct->setShared();
13409 endOfConstruct->setShared();
13410
13411 // Add this file_id to those file_id that will trigger this IR node to be unparsed.
13412#if 0
13413 printf (" --- adding entries for file_id and line number to support sharing: new_file_id = %d line = %d end line = %d \n",
13414 new_file_id,startOfConstruct->get_line(),endOfConstruct->get_line());
13415#endif
13416 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == startOfConstruct->get_fileLineNumbersToUnparse().size());
13417 ROSE_ASSERT(endOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
13418 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
13419
13420 // Add this existing_fi->get_file_id() to the list of file id's that will permit the assocated language construct to be unparsed.
13421 startOfConstruct->get_fileIDsToUnparse().push_back(new_file_id);
13422 startOfConstruct->get_fileLineNumbersToUnparse().push_back(startOfConstruct->get_line());
13423
13424 endOfConstruct->get_fileIDsToUnparse().push_back(new_file_id);
13425 endOfConstruct->get_fileLineNumbersToUnparse().push_back(endOfConstruct->get_line());
13426
13427 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == startOfConstruct->get_fileLineNumbersToUnparse().size());
13428 ROSE_ASSERT(endOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
13429 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
13430 }
13431 }
13432 else
13433 {
13434#if 0
13435 printf ("Unhandled: node = %p = %s \n",node,node->class_name().c_str());
13436#endif
13437 }
13438 }
13439
13440 // Data members.
13441 int new_file_id;
13442 };
13443
13444
13445 SgStatement* statement = isSgStatement(subtreeRoot);
13446 if (statement != NULL)
13447 {
13448#if 0
13449 printf ("statement->get_startOfConstruct()->get_file_id() = %d \n",statement->get_startOfConstruct()->get_file_id());
13450 printf ("statement->get_startOfConstruct()->get_physical_file_id() = %d \n",statement->get_startOfConstruct()->get_physical_file_id());
13451#endif
13452#if 0
13453 printf ("new_file_id = %d \n",new_file_id);
13454#endif
13455#if 0
13456 printf ("In SageBuilder::fixupSharingSourcePosition(): statement = %s : new_file_id = %d \n",statement->class_name().c_str(),new_file_id);
13457#endif
13458 }
13459 else
13460 {
13461 printf ("Error: In SageBuilder::fixupSharingSourcePosition(): subtree should be a SgFile or SgLocatedNode: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13462 ROSE_ABORT();
13463 }
13464
13465 ROSE_ASSERT(new_file_id >= 0);
13466
13467 // Now buid the traveral object and call the traversal (preorder) on the function definition.
13468 Traversal traversal (new_file_id);
13469
13470 // traversal.traverse(subtreeRoot, preorder);
13471 // traversal.traverseInputFiles(subtreeRoot, preorder);
13472 // traversal.traverseWithinFile(subtreeRoot, preorder);
13473 traversal.traverse(subtreeRoot, preorder);
13474
13475#if 0
13476 printf ("Exiting as a test in SageBuilder::fixupSharingSourcePosition() \n");
13477 ROSE_ABORT();
13478#endif
13479 }
13480
13481
13482
13483
13484
13486SgFile*
13487SageBuilder::buildFile(const std::string& inputFileName, const std::string& outputFileName, SgProject* project/*=NULL*/, bool clear_globalScopeAcrossFiles /*=false*/)
13488 {
13489// Note that ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT defines a reduced set of ROSE to support front-end specific development.
13490// It is mostly used by quinlan to support laptop development where the smaller set of files permits one to do limited
13491// development work on a Mac (even with OSX's poor performance with large numbers of debug symbols). This is an
13492// infrequently used option.
13493#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
13494
13495#if 0
13496 printf ("In SageBuilder::buildFile(inputFileName = %s, outputFileName = %s, project = %p) \n",inputFileName.c_str(),outputFileName.c_str(),project);
13497 // printf (" --- fullname = %s \n",fullname.c_str());
13498#endif
13499
13500#if 0
13501 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13502 ROSE_ASSERT(project != NULL);
13503 std::set<SgLocatedNode*> tmp1_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
13504
13505 if (tmp1_collectionOfModifiedLocatedNodes.size() > 0)
13506 {
13507 printf ("In Traversal::evaluateInheritedAttribute(): tmp1_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp1_collectionOfModifiedLocatedNodes.size());
13508#if 1
13509 printf ("Exiting as a test! \n");
13510 ROSE_ASSERT(false);
13511#endif
13512 }
13513#endif
13514
13515 ROSE_ASSERT(inputFileName.size() != 0); // empty file name is not allowed.
13516
13517 // DQ (9/18/2019): I am unclear what the use of fullname is below.
13518 // string sourceFilename = inputFileName, fullname;
13519 // string sourceFilename_fullname = inputFileName, fullname;
13520 string sourceFilename = inputFileName;
13521
13522#if 0
13523 // printf ("sourceFilename_fullname = %s \n",sourceFilename_fullname.c_str());
13524 printf ("sourceFilename = %s \n",sourceFilename.c_str());
13525#endif
13526
13527
13528 // DQ (11/5/2020): Experiment with clearing the global scope that is supporting multiple translation
13529 // units, since it is the cause of some problem when a tool is designed to read an input file twice.
13530 if (project != NULL)
13531 {
13532 SgGlobal* globalScopeAcrossFiles = project->get_globalScopeAcrossFiles();
13533 ROSE_ASSERT(globalScopeAcrossFiles != NULL);
13534
13535 ROSE_ASSERT(globalScopeAcrossFiles->get_symbol_table() != NULL);
13536 ROSE_ASSERT(globalScopeAcrossFiles->get_symbol_table()->get_table() != NULL);
13537
13538#if 0
13539 printf ("In SageBuilder::buildFile(): globalScopeAcrossFiles = %p \n",globalScopeAcrossFiles);
13540 printf (" --- globalScopeAcrossFiles->get_declarations().size() = %zu \n",globalScopeAcrossFiles->get_declarations().size());
13541 printf (" --- globalScopeAcrossFiles->get_symbol_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->size());
13542 printf (" --- globalScopeAcrossFiles->get_symbol_table()->get_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->get_table()->size());
13543#endif
13544#if 0
13545 printf ("Removing all elements from the globalScopeAcrossFiles->get_symbol_table() \n");
13546#endif
13547
13548 // DQ (11/5/2020): Clear the symbol table used to support multifile handling.
13549 // This breaks only one of the test codes in the codeSegregation tool, but it is a name
13550 // qualification that should likely be handled better so I think this is a good fix.
13551 if (clear_globalScopeAcrossFiles == true)
13552 {
13553 globalScopeAcrossFiles->get_symbol_table()->get_table()->delete_elements();
13554 }
13555
13556#if 0
13557 printf ("After removing all symbols (alias symbols): globalScopeAcrossFiles->get_symbol_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->size());
13558 printf ("After removing all symbols (alias symbols): globalScopeAcrossFiles->get_symbol_table()->get_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->get_table()->size());
13559#endif
13560 }
13561
13562 // DQ (9/18/2019): Test that the use of fullname has no effect.
13563 // ROSE_ASSERT(sourceFilename == sourceFilename_fullname);
13564
13565 Rose_STL_Container<std::string> arglist;
13566 int nextErrorCode = 0;
13567
13568#if 0
13569 bool set_header_file_unparsing_optimization = false;
13570#endif
13571
13572 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
13573 bool isCopyOfExistingFile_testForSharedNodes = false;
13574 SgFile* fileBeingCopied = NULL;
13575
13576 if (project == NULL)
13577 // SgProject is created on the fly
13578 // Make up an arglist in order to reuse the code inside SgFile::setupSourceFilename()
13579 {
13580#if 0
13581 printf ("In SageBuilder::buildFile(): build the SgProject \n");
13582#endif
13583 project = new SgProject();
13584 ROSE_ASSERT(project);
13585 project->get_fileList().clear();
13586
13587 arglist.push_back("cc");
13588 arglist.push_back("-c");
13589 project->set_originalCommandLineArgumentList (arglist);
13590 }
13591 else
13592 {
13593 // If project exists, then find the original source file if it exists and check the header file optimization setting for consistancy.
13594
13595 // DQ (9/18/2019): Adding debugging support to header file optimization support.
13596 SgFilePtrList & files = project->get_fileList();
13597 for (SgFilePtrList::iterator i = files.begin(); i != files.end(); i++)
13598 {
13599 SgFile* file = *i;
13600#if 0
13601 printf ("file = %p = %s name = %s \n",file,file->class_name().c_str(), file->getFileName().c_str());
13602
13603 printf ("file->get_header_file_unparsing_optimization() = %s \n",file->get_header_file_unparsing_optimization() ? "true" : "false");
13604 printf ("file->get_header_file_unparsing_optimization_source_file() = %s \n",file->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
13605 printf ("file->get_header_file_unparsing_optimization_header_file() = %s \n",file->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
13606#endif
13607 if (sourceFilename == file->getFileName())
13608 {
13609#if 0
13610 printf ("This is a copy of an existing file in the project: sourceFilename = %s \n",sourceFilename.c_str());
13611#endif
13612 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
13613 isCopyOfExistingFile_testForSharedNodes = true;
13614 fileBeingCopied = file;
13615
13616#if 0
13617 // DQ (4/24/2021): This data member header_file_unparsing_optimization is now static.
13618 // We are building a second copy of an originally specified file (so we need to set the optimization setting similarly).
13619 if (file->get_header_file_unparsing_optimization() == true)
13620 {
13621 set_header_file_unparsing_optimization = true;
13622 }
13623#endif
13624 }
13625 }
13626
13627#if 0
13628 printf ("Exiting as a test! \n");
13629 ROSE_ABORT();
13630#endif
13631 }
13632
13633 ifstream testfile(inputFileName.c_str());
13634 if (!testfile.is_open())
13635 {
13636 // create a temporary file if the file does not exist.
13637 // have to do this, otherwise StringUtility::getAbsolutePathFromRelativePath() complains
13638 // which is called by result->setupSourceFilename(arglist);
13639 testfile.close();
13640 ofstream outputfile(inputFileName.c_str(),ios::out);
13641 // DQ (2/6/2009): I think this comment is helpful to put into the file (helps explain why the file exists).
13642 outputfile<<"// Output file generated so that StringUtility::getAbsolutePathFromRelativePath() will see a vaild file ... unparsed file will have rose_ prefix "<<endl;
13643 outputfile.close();
13644 }
13645 else // file already exists , load and parse it
13646 {
13647 // should not reparse all files in case their ASTs have unsaved changes,
13648 // just parse the newly loaded file only.
13649 // use argv here, change non-existing input file later on
13650 // TODO add error code handling
13651
13652 // DQ (2/6/2009): Avoid closing this file twice (so put this here, instead of below).
13653 testfile.close();
13654 // should remove the old one here, Liao, 5/1/2009
13655 }
13656
13657 // DQ (2/6/2009): Avoid closing this file twice (moved to false branch above).
13658 // testfile.close();
13659
13660 // DQ (2/6/2009): Need to add the inputFileName to the source file list in the project,
13661 // because this list will be used to subtract off the source files as required to build
13662 // the commandline for the backend compiler.
13663 project->get_sourceFileNameList().push_back(inputFileName);
13664
13665 Rose_STL_Container<string> sourceFilenames = project->get_sourceFileNameList();
13666 // printf ("In SageBuilder::buildFile(): sourceFilenames.size() = %" PRIuPTR " sourceFilenames = %s \n",sourceFilenames.size(),StringUtility::listToString(sourceFilenames).c_str());
13667
13668 arglist = project->get_originalCommandLineArgumentList();
13669
13670 // DQ (2/6/2009): We will be compiling the source code generated in the
13671 // "rose_<inputFileName>" file, so we don't want this on the argument stack.
13672 // TV (09/19/2018): only add if not already present
13673 if (std::find(arglist.begin(), arglist.end(), sourceFilename) == arglist.end())
13674 {
13675 arglist.push_back(sourceFilename);
13676 }
13677
13678 // DQ (2/6/2009): Modified.
13679 // There is output file name specified for rose translators
13680 if (outputFileName.empty() == false)
13681 {
13682 arglist.push_back("-rose:o");
13683 // arglist.push_back("-o");
13684 arglist.push_back(outputFileName);
13685 }
13686
13687 // DQ (4/15/2010): Turn on verbose mode
13688 // arglist.push_back("-rose:verbose 2");
13689
13690 // This handles the case where the original command line may have referenced multiple files.
13691 Rose_STL_Container<string> fileList = CommandlineProcessing::generateSourceFilenames(arglist,/* binaryMode = */ false);
13692 CommandlineProcessing::removeAllFileNamesExcept(arglist,fileList,sourceFilename);
13693
13694 // DQ (9/3/2008): Added support for SgSourceFile IR node
13695 // SgFile* result = new SgFile (arglist, nextErrorCode, 0, project);
13696 // AS(10/04/08) Because of refactoring we require the determineFileType function to be called
13697 // to construct the node.
13698 // SgSourceFile* result = new SgSourceFile (arglist, nextErrorCode, 0, project);
13699 // SgSourceFile* result = isSgSourceFile(determineFileType(arglist, nextErrorCode, project));
13700 // TH (2009-07-15): changed to more generig isSgFile, this also supports SgBinaryComposite
13701 SgFile* result = determineFileType(arglist, nextErrorCode, project);
13702 ROSE_ASSERT(result != NULL);
13703
13704#if 0
13705 printf ("In SageBuilder::buildFile(): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",project,project->get_fileList_ptr()->get_listOfFiles().size());
13706#endif
13707
13708 SgSourceFile* sourceFile = isSgSourceFile(result);
13709 if (sourceFile != NULL)
13710 {
13711 SgGlobal* globalScope = sourceFile->get_globalScope();
13712 ROSE_ASSERT(globalScope != NULL);
13713
13714 // DQ (6/24/2021): We need to end this function with the isModified flag set to false. This is
13715 // important for the support of the token based unparsing when building a dynamic library.
13716 // This is important in permitting the simpleFrontierDetectionForTokenStreamMapping() function
13717 // to generate the correct settings for nodes in the second file constructed from the original file.
13718 if (globalScope->get_isModified() == true)
13719 {
13720#if 0
13721 printf ("In SageBuilder::buildFile(): globalScope->get_isModified() == true: reset to false \n");
13722#endif
13723 globalScope->set_isModified(false);
13724#if 0
13725 printf ("In SageBuilder::buildFile(): Verify false setting: globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
13726#endif
13727 }
13728 }
13729
13730#if 0
13731 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
13732 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
13733
13734 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
13735 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
13736#endif
13737
13738#if 0
13739 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13740 ROSE_ASSERT(project != NULL);
13741 std::set<SgLocatedNode*> tmp2_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
13742
13743 if (tmp2_collectionOfModifiedLocatedNodes.size() > 0)
13744 {
13745 printf ("In Traversal::evaluateInheritedAttribute(): tmp2_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp2_collectionOfModifiedLocatedNodes.size());
13746#if 1
13747 printf ("Exiting as a test! \n");
13748 ROSE_ASSERT(false);
13749#endif
13750 }
13751#endif
13752
13753#if 0
13754 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13755 ROSE_ASSERT(project != NULL);
13756 std::set<SgLocatedNode*> tmp22_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(result);
13757
13758 if (tmp22_collectionOfModifiedLocatedNodes.size() > 0)
13759 {
13760 printf ("In Traversal::evaluateInheritedAttribute(): tmp22_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp22_collectionOfModifiedLocatedNodes.size());
13761#if 1
13762 printf ("Exiting as a test! \n");
13763 ROSE_ASSERT(false);
13764#endif
13765 }
13766#endif
13767
13768#if 0
13769 printf ("Calling outputFileIds() \n");
13770
13772
13773 printf ("DONE: Calling outputFileIds() \n");
13774#endif
13775
13776#if 0
13777 // DQ (9/18/2019): Adding debugging support.
13778 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization() = %s \n",
13779 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization() ? "true" : "false");
13780#endif
13781
13782#if 0
13783 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization_source_file() = %s \n",
13784 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
13785 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization_header_file() = %s \n",
13786 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
13787#endif
13788
13789 // DQ (9/18/2019): Adding debugging support.
13790 // ROSE_ASSERT(result->get_header_file_unparsing_optimization() == false);
13791 // ROSE_ASSERT(result->get_header_file_unparsing_optimization_source_file() == false);
13792 // ROSE_ASSERT(result->get_header_file_unparsing_optimization_header_file() == false);
13793
13794 // ROSE_ASSERT(result->get_header_file_unparsing_optimization() == true);
13795
13796#if 0
13797 // DQ (4/24/2021): This data member header_file_unparsing_optimization is now static (so we don't need this code).
13798 if (set_header_file_unparsing_optimization == true)
13799 {
13800 result->set_header_file_unparsing_optimization(true);
13801
13802 // DQ (9/18/2019): Also set the values for the source file and header files.
13803 // I think we only want to set the source file version to true and the header file version to false.
13804 // This is enforced in the attachPreprocessingInfo() function.
13805
13806 // DQ (4/24/2021): Debugging header file optimization.
13807 // result->set_header_file_unparsing_optimization_source_file(true);
13808
13809 // result->set_header_file_unparsing_optimization_header_file(true);
13810 result->set_header_file_unparsing_optimization_header_file(false);
13811
13812#if 0
13813 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization() = %s \n",
13814 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization() ? "true" : "false");
13815 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization_source_file() = %s \n",
13816 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
13817 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization_header_file() = %s \n",
13818 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
13819#endif
13820 }
13821#endif
13822
13823#if 0
13824 // DQ (3/4/2014): This fix is only for Java and for C will cause a second SgFile to be redundently added to the file list.
13825 // For now I will provide a temporary fix and check is this is for a Java project so that we can continue. But the longer
13826 // term fix would be to make the semantics for Java the same as that of C/C++ (or the other way around, whatever is the
13827 // cleaner semantics.
13828 // This just adds the new file to the list of files stored internally (note: this sets the parent of the newFile).
13829 // TOO1 (2/28/2014): This is definitely required for Java (ECJ frontend), though C passes without it (I think only
13830 // by luck :-).
13831 // The ECJ frontend uses the SgProject internally (via a global SgProject*). Therefore, the
13832 // SgProject must contain this newly created SgFile, otherwise ECJ won't be able to find it.
13833 // project->set_file ( *result );
13834 if (project->get_Java_only() == true)
13835 {
13836 // DQ (3/4/2014): For now we want to output a message and clean this up afterward (likely in the Java language support).
13837 printf ("WARNING: Java specific action to add new file to SgProject (using set_file()) (more uniform language handling symantics would avoid this problem) \n");
13838 project->set_file ( *result );
13839 }
13840#else
13841 // DQ (3/6/2014): The code below adresses the specific bug faced in the use of the outliner (so we use it directly).
13842 // This code was moved ahead of the call to "result->runFrontend(nextErrorCode);" because in the case of Java
13843 // the file must be set to be a part of the SgProject before calling the runFrontend() function.
13844 // project->set_file ( *result );
13845
13846 result->set_parent(project);
13847
13848#if 0
13849 printf ("In SageBuilder::buildFile(): Outliner::use_dlopen = %s \n",Outliner::use_dlopen ? "true" : "false");
13850#endif
13851
13852#if 0
13853 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13854 ROSE_ASSERT(project != NULL);
13855 std::set<SgLocatedNode*> tmp23_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(result);
13856
13857 if (tmp23_collectionOfModifiedLocatedNodes.size() > 0)
13858 {
13859 printf ("In Traversal::evaluateInheritedAttribute(): tmp23_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp23_collectionOfModifiedLocatedNodes.size());
13860#if 1
13861 printf ("Exiting as a test! \n");
13862 ROSE_ASSERT(false);
13863#endif
13864 }
13865#endif
13866
13867#if 0
13868 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13869 ROSE_ASSERT(project != NULL);
13870 std::set<SgLocatedNode*> tmp24_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
13871
13872 if (tmp24_collectionOfModifiedLocatedNodes.size() > 0)
13873 {
13874 printf ("In Traversal::evaluateInheritedAttribute(): tmp24_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp24_collectionOfModifiedLocatedNodes.size());
13875#if 1
13876 printf ("Exiting as a test! \n");
13877 ROSE_ASSERT(false);
13878#endif
13879 }
13880#endif
13881
13882 // DQ (3/5/2014): I need to check with Liao to understand this part of the code better.
13883 // I think that the default value for Outliner::use_dlopen is false, so that when the
13884 // Java support is used the true branch is taken. However, if might be the we need
13885 // to support the outliner using the code below and so this would be a bug for the
13886 // outliner.
13887 if (!Outliner::use_dlopen)
13888 {
13889#if 0
13890 printf ("In SageBuilder::buildFile(): (after test for (!Outliner::use_dlopen) == true: project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
13891 project,project->get_fileList_ptr()->get_listOfFiles().size());
13892#endif
13893 // DQ (3/5/2014): If we added the file above, then don't add it here since it is redundant.
13894 project->set_file(*result); // equal to push_back()
13895#if 0
13896 printf ("In SageBuilder::buildFile(): (after 2nd project->set_file()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
13897 project,project->get_fileList_ptr()->get_listOfFiles().size());
13898#endif
13899 }
13900 else
13901 {
13902#if 0
13903 printf ("In SageBuilder::buildFile(): (after test for (!Outliner::use_dlopen) == false: project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
13904 project,project->get_fileList_ptr()->get_listOfFiles().size());
13905#endif
13906
13907 // Liao, 5/1/2009,
13908 // if the original command line is: gcc -c -o my.o my.c and we want to
13909 // add a new file(mynew.c), the command line for the new file would become "gcc -c -o my.o mynew.c "
13910 // which overwrites the object file my.o from my.c and causes linking error.
13911 // To avoid this problem, I insert the file at the beginning and let the right object file to be the last generated one
13912 //
13913 // TODO This is not an elegant fix and it causes some strange assertion failure in addAssociatedNodes(): default case node
13914 // So we only turn this on if Outliner:: use_dlopen is used for now
13915 // The semantics of adding a new source file can cause changes to linking phase (new object files etc.)
13916 // But ROSE has a long-time bug in handling combined compiling and linking command like "translator -o a.out a.c b.c"
13917 // It will generated two command lines: "translator -o a.out a.c" and "translator -o a.out b.c", which are totally wrong.
13918 // This problem is very relevant to the bug.
13919 SgFilePtrList& flist = project->get_fileList();
13920 flist.insert(flist.begin(),result);
13921#if 0
13922 printf ("In SageBuilder::buildFile(): (after flist.insert(flist.begin(),result)): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
13923 project,project->get_fileList_ptr()->get_listOfFiles().size());
13924#endif
13925 }
13926#endif
13927
13928#if 0
13929 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13930 ROSE_ASSERT(project != NULL);
13931 std::set<SgLocatedNode*> tmp25_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
13932
13933 if (tmp25_collectionOfModifiedLocatedNodes.size() > 0)
13934 {
13935 printf ("In Traversal::evaluateInheritedAttribute(): tmp25_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp25_collectionOfModifiedLocatedNodes.size());
13936#if 1
13937 printf ("Exiting as a test! \n");
13938 ROSE_ASSERT(false);
13939#endif
13940 }
13941#endif
13942
13943 // DQ (6/3/2019): The case of outlining to a seperate file will have transformations
13944 // that this checking will fail on because it is for the typical case of checking the
13945 // AST for transformations after construction of the AST from an typical input file.
13946 EDG_ROSE_Translation::suppress_detection_of_transformations = true;
13947
13948#if 0
13949 printf ("In SageBuilder::buildFile(): EDG_ROSE_Translation::suppress_detection_of_transformations = %s \n",EDG_ROSE_Translation::suppress_detection_of_transformations ? "true" : "false");
13950#endif
13951
13952#if 0
13953 printf ("In SageBuilder::buildFile(): (after project->set_file()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",project,project->get_fileList_ptr()->get_listOfFiles().size());
13954#endif
13955
13956
13957 // DQ (6/5/2019): Record what is marked as isModified() and then reset these IR nodes to be isModified after the new file has been processed.
13958 // This is required because the modified IR nodes will be reset in this AST associated with the new file, and IR nodes that are common
13959 // across the two AST's will be reset (shared IR nodes, which are also not marked as shared). The solution is to compute the list of IR nodes
13960 // which are marked as isModified, and then build the new file (which will reset them for the new file's AST (plus any shared nodes visited in
13961 // the traversal) and then afterward reset the set of isModified IR nodes to isModified. By isolating the fix in this function we can eliminate
13962 // the complexity of it being seen from the outside (outside of this abstraction). Note that the function:
13963 // SageInterface::collectModifiedLocatedNodes() has previously been implemented and used for debugging.
13964 std::set<SgLocatedNode*> modifiedNodeSet = collectModifiedLocatedNodes(project);
13965
13966#if 0
13967 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
13968 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
13969
13970 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
13971 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
13972#endif
13973
13974#if 0
13975 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13976 ROSE_ASSERT(project != NULL);
13977 std::set<SgLocatedNode*> tmp251_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
13978
13979 if (tmp251_collectionOfModifiedLocatedNodes.size() > 0)
13980 {
13981 printf ("In Traversal::evaluateInheritedAttribute(): tmp251_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp251_collectionOfModifiedLocatedNodes.size());
13982#if 1
13983 printf ("Exiting as a test! \n");
13984 ROSE_ASSERT(false);
13985#endif
13986 }
13987#endif
13988
13989 // DQ (3/6/2014): For Java, this function can only be called AFTER the SgFile has been added to the file list in the SgProject.
13990 // For C/C++ it does not appear to matter if the call is made before the SgFile has been added to the file list in the SgProject.
13991 // DQ (6/14/2013): Since we seperated the construction of the SgFile IR nodes from the invocation of the frontend, we have to call the frontend explicitly.
13992 result->runFrontend(nextErrorCode);
13993
13994#if 0
13995 printf ("In SageBuilder::buildFile(): (after result->runFrontend()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",project,project->get_fileList_ptr()->get_listOfFiles().size());
13996#endif
13997
13998#if 0
13999 printf ("After result->runFrontend(): calling outputFileIds() \n");
14000
14002
14003 printf ("DONE: After result->runFrontend(): calling outputFileIds() \n");
14004#endif
14005
14006#if 0
14007 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14008 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14009
14010 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14011 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14012#endif
14013
14014#if 0
14015 // DQ (6/24/2021): This can be expected to fail, because the new AST has been build and all of the
14016 // nodes are marked as isModified until rest in the AstPostProcessing() step (below).
14017 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14018 ROSE_ASSERT(project != NULL);
14019 std::set<SgLocatedNode*> tmp26_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14020
14021 if (tmp26_collectionOfModifiedLocatedNodes.size() > 0)
14022 {
14023 printf ("In Traversal::evaluateInheritedAttribute(): tmp26_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp26_collectionOfModifiedLocatedNodes.size());
14024#if 0
14025 printf ("Exiting as a test! \n");
14026 ROSE_ASSERT(false);
14027#endif
14028 }
14029#endif
14030
14031#if 0
14032 // Output an optional graph of the AST (just the tree, when active)
14033 printf ("Generating a dot file... (SgFile only) \n");
14034 generateDOT ( *project );
14035 // generateAstGraph(project, 2000);
14036#endif
14037
14038#if 0
14039 printf ("In SageBuilder::buildFile(): Generate the dot output for multiple files (ROSE AST) \n");
14040 // generateDOT ( *project );
14041 generateDOTforMultipleFile ( *project );
14042 printf ("DONE: Generate the dot output of the SAGE III AST \n");
14043#endif
14044
14045#if 0
14046 // DQ (7/18/2019): Output a graph of the AST for debugging.
14047 // Output an optional graph of the AST (the whole graph, of bounded complexity, when active)
14048 const int MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH = 8000;
14049 generateAstGraph(project,MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH);
14050#endif
14051
14052 // DQ (7/14/2019): I think we need to call the astPostProcessing at this point.
14053#if 0
14054 printf ("In SageBuilder::buildFile(): calling astPostProcessing() \n");
14055#endif
14056
14057 if (!project->get_skip_post_processing()) AstPostProcessing(result);
14058
14059#if 0
14060 printf ("In SageBuilder::buildFile(): DONE: calling astPostProcessing() \n");
14061#endif
14062
14063#if 0
14064 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14065 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14066
14067 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14068 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14069#endif
14070
14071#if 0
14072 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14073 ROSE_ASSERT(project != NULL);
14074 std::set<SgLocatedNode*> tmp265_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14075
14076 if (tmp265_collectionOfModifiedLocatedNodes.size() > 0)
14077 {
14078 printf ("In Traversal::evaluateInheritedAttribute(): tmp265_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp265_collectionOfModifiedLocatedNodes.size());
14079#if 1
14080 printf ("Exiting as a test! \n");
14081 ROSE_ASSERT(false);
14082#endif
14083 }
14084#endif
14085
14086#if 0
14087 result->display("SageBuilder::buildFile()");
14088#endif
14089
14090 ROSE_ASSERT(project != NULL);
14091 project->set_frontendErrorCode(max(project->get_frontendErrorCode(), nextErrorCode));
14092
14093 // Not sure why a warning shows up from astPostProcessing.C
14094 // SgNode::get_globalMangledNameMap().size() != 0 size = %" PRIuPTR " (clearing mangled name cache)
14095 if (result->get_globalMangledNameMap().size() != 0)
14096 {
14097 result->clearGlobalMangledNameMap();
14098 }
14099
14100 // DQ (6/5/2019): Use the previously constructed set (above) to reset the IR nodes to be marked as isModified.
14101 // std::set<SgLocatedNode*> modifiedNodeSet = collectModifiedLocatedNodes(project);
14102 // void resetModifiedLocatedNodes(const std::set<SgLocatedNode*> & modifiedNodeSet);
14103 resetModifiedLocatedNodes(modifiedNodeSet);
14104
14105#if 0
14106 printf ("Exiting as a test! \n");
14107 ROSE_ABORT();
14108#endif
14109
14110#if 0
14111 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14112 ROSE_ASSERT(project != NULL);
14113 std::set<SgLocatedNode*> tmp27_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14114
14115 if (tmp27_collectionOfModifiedLocatedNodes.size() > 0)
14116 {
14117 printf ("In Traversal::evaluateInheritedAttribute(): tmp27_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp27_collectionOfModifiedLocatedNodes.size());
14118#if 1
14119 printf ("Exiting as a test! \n");
14120 ROSE_ASSERT(false);
14121#endif
14122 }
14123#endif
14124
14125 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
14126 if (isCopyOfExistingFile_testForSharedNodes == true)
14127 {
14128 // Sharing of IR nodes happens in the AST when the same file is read twice.
14129 // Also in the case where two declarations in the global scope match in two different ASTs (typically in header files of different translation units).
14130
14131#if 0
14132 printf ("Found isCopyOfExistingFile_testForSharedNodes == true \n");
14133 printf ("fileBeingCopied = %p = %s \n",fileBeingCopied,fileBeingCopied->getFileName().c_str());
14134#endif
14135
14136 SgSourceFile* sourceFileBeingCopied = isSgSourceFile(fileBeingCopied);
14137 ROSE_ASSERT(sourceFileBeingCopied != NULL);
14138
14139 SgSourceFile* sourceResult = isSgSourceFile(result);
14140 ROSE_ASSERT(sourceResult != NULL);
14141
14142 SgGlobal* fileBeingCopied_globalScope = sourceFileBeingCopied->get_globalScope();
14143 SgGlobal* result_globalScope = sourceResult->get_globalScope();
14144#if 0
14145 printf ("fileBeingCopied_globalScope = %p \n",fileBeingCopied_globalScope);
14146 printf ("result_globalScope = %p \n",result_globalScope);
14147#endif
14148 ROSE_ASSERT(fileBeingCopied_globalScope != NULL);
14149 ROSE_ASSERT(result_globalScope != NULL);
14150
14151 SgDeclarationStatementPtrList fileBeingCopied_declarationList = fileBeingCopied_globalScope->get_declarations();
14152 SgDeclarationStatementPtrList result_declarationList = result_globalScope->get_declarations();
14153
14154#if 1
14155 // DQ (11/22/2019): Use set intersection to compute the list to make be shared (this is a better implementation).
14156 // This implementation is insensitive to transforamtions in the original AST for the file.
14157 vector<SgDeclarationStatement*>::iterator it;
14158 SgDeclarationStatementPtrList v(fileBeingCopied_declarationList.size());
14159
14160 // This is n log n in complexity, but likely OK.
14161 std::sort(fileBeingCopied_declarationList.begin(),fileBeingCopied_declarationList.end());
14162 std::sort(result_declarationList.begin(),result_declarationList.end());
14163
14164 // printf ("v.size() = %zu \n",v.size());
14165
14166 it = std::set_intersection(fileBeingCopied_declarationList.begin(),fileBeingCopied_declarationList.end(),result_declarationList.begin(),result_declarationList.end(),v.begin());
14167
14168 v.resize(it-v.begin());
14169
14170 int fileBeingCopied_file_id = fileBeingCopied->get_startOfConstruct()->get_physical_file_id();
14171
14172 // printf ("v.size() = %zu \n",v.size());
14173 for (size_t i = 0; i < v.size(); i++)
14174 {
14175 SgDeclarationStatement* intersection_element = v[i];
14176 // printf ("intersection_element = %p = %s \n",intersection_element,intersection_element->class_name().c_str());
14177#if 0
14178 printf (" --- SageBuilder::buildFile() is sharing this node: %p %s \n",intersection_element,intersection_element->class_name().c_str());
14179#endif
14180 // DQ (11/10/2019): Need to recursively mark this as shared so that the unparser will be able to test each line?
14181
14182 fixupSharingSourcePosition(intersection_element,fileBeingCopied_file_id);
14183#if 0
14184 printf ("Exiting as a test! \n");
14185 ROSE_ABORT();
14186#endif
14187 }
14188
14189#if 0
14190 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14191 ROSE_ASSERT(project != NULL);
14192 std::set<SgLocatedNode*> tmp28_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14193
14194 if (tmp28_collectionOfModifiedLocatedNodes.size() > 0)
14195 {
14196 printf ("In Traversal::evaluateInheritedAttribute(): tmp28_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp28_collectionOfModifiedLocatedNodes.size());
14197#if 1
14198 printf ("Exiting as a test! \n");
14199 ROSE_ASSERT(false);
14200#endif
14201 }
14202#endif
14203
14204#else
14205
14206#error "DEAD CODE!"
14207
14208 // This is the older implementation that is sensitive to transforamtions in the original AST from the file.
14209 // DQ (11/21/2019): Remove elements in the vector that are SgEmptyDeclarations which
14210 // are associated with some transformations (include header, for example).
14211 std::vector<SgDeclarationStatementPtrList::iterator> removeList;
14212 SgDeclarationStatementPtrList::iterator i = fileBeingCopied_declarationList.begin();
14213 while (i != fileBeingCopied_declarationList.end())
14214 {
14215 SgEmptyDeclaration* emptyDeclaration = isSgEmptyDeclaration(*i);
14216 if (emptyDeclaration != NULL)
14217 {
14218 removeList.push_back(i);
14219 }
14220
14221 i++;
14222 }
14223
14224#error "DEAD CODE!"
14225
14226 // Need seperate list to avoid iterator invalidation.
14227 // for (SgDeclarationStatementPtrList::iterator i = removeList.begin(); i != removeList.end(); i++)
14228 for (std::vector<SgDeclarationStatementPtrList::iterator>::iterator i = removeList.begin(); i != removeList.end(); i++)
14229 {
14230 fileBeingCopied_declarationList.erase(*i);
14231 }
14232
14233 // DQ (11/21/2019): These might be a different size if for example the file being
14234 // copied is being copied after some transformations to the AST from the original file.
14235 if (fileBeingCopied_declarationList.size() != result_declarationList.size())
14236 {
14237 printf ("fileBeingCopied_declarationList.size() = %zu \n",fileBeingCopied_declarationList.size());
14238 printf ("result_declarationList.size() = %zu \n",result_declarationList.size());
14239 }
14240 ROSE_ASSERT(fileBeingCopied_declarationList.size() == result_declarationList.size());
14241
14242#error "DEAD CODE!"
14243
14244#if 0
14245 printf ("Statements from global scope (size = %zu): \n",fileBeingCopied_declarationList.size());
14246#endif
14247 for (size_t i = 0; i < fileBeingCopied_declarationList.size(); i++)
14248 {
14249 SgDeclarationStatement* fileBeingCopied_decl = fileBeingCopied_declarationList[i];
14250 SgDeclarationStatement* result_decl = result_declarationList[i];
14251#if 0
14252 printf (" #%zu global scope entry: fileBeingCopied: %p %s result %p %s \n",i,fileBeingCopied_decl,fileBeingCopied_decl->class_name().c_str(),result_decl,result_decl->class_name().c_str());
14253#endif
14254 if (fileBeingCopied_decl == result_decl)
14255 {
14256#if 0
14257 printf (" --- SageBuilder::buildFile() is sharing this node: %p %s \n",fileBeingCopied_decl,fileBeingCopied_decl->class_name().c_str());
14258#endif
14259 // DQ (11/10/2019): Need to recursively mark this as shared so that the unparser will be able to test each line?
14260
14261#error "DEAD CODE!"
14262
14263 int fileBeingCopied_file_id = fileBeingCopied->get_startOfConstruct()->get_physical_file_id();
14264 fixupSharingSourcePosition(fileBeingCopied_decl,fileBeingCopied_file_id);
14265#if 0
14266 printf ("Exiting as a test! \n");
14267 ROSE_ABORT();
14268#endif
14269 }
14270 }
14271
14272#error "DEAD CODE!"
14273
14274#endif
14275
14276#if 0
14277 printf ("exiting as a test! \n");
14278 ROSE_ABORT();
14279#endif
14280 }
14281
14282#if 0
14283 reportModifiedStatements("Leaving SageBuilder::buildFile(): calling reportModifiedStatements()",project);
14284#endif
14285
14286#if 0
14287 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14288 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14289 printf ("Leaving SageBuilder::buildFile(): (after result->runFrontend()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14290 project,project->get_fileList_ptr()->get_listOfFiles().size());
14291 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14292 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14293#endif
14294
14295#if 0
14296 // DQ (11/8/2019): This is not working and breaks the current work at present.
14297 // DQ (11/8/2019): Support function to change the name in each of the IR node's source position info objects.
14298 fixupSourcePositionFileSpecification(result,outputFileName);
14299#endif
14300
14301 ROSE_ASSERT(result->get_preprocessorDirectivesAndCommentsList() != NULL);
14302
14303#if 0
14304 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14305 ROSE_ASSERT(project != NULL);
14306 std::set<SgLocatedNode*> tmp3_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14307
14308 if (tmp3_collectionOfModifiedLocatedNodes.size() > 0)
14309 {
14310 printf ("In Traversal::evaluateInheritedAttribute(): tmp3_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp3_collectionOfModifiedLocatedNodes.size());
14311#if 1
14312 printf ("Exiting as a test! \n");
14313 ROSE_ASSERT(false);
14314#endif
14315 }
14316#endif
14317
14318 return result;
14319#else
14320
14321 // false branch of #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT (at top of function.
14322
14323 return NULL;
14324#endif
14325 }
14326
14327
14330SageBuilder::buildSourceFile(const std::string& outputFileName, SgProject* project, bool clear_globalScopeAcrossFiles /*=false*/)
14331 {
14332 // DQ (2/9/2013): Adding support to build a SgSourceFile with an empty global scope.
14333 // This function calls the buildFile(string,string,SgProject*) function and provides
14334 // a simple API where one wants to create a new SgSourceFile that will then have
14335 // statements added to it and then unparsed.
14336
14337 // This function needs a way to specify the associated language for the generated file.
14338 // Currently this is taken from the input file (generated from a prefix on the output filename.
14339
14340#if 1
14341 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
14342 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
14343 printf ("In SageBuilder::buildSourceFile(outputFileName = %s, project = %p) \n",outputFileName.c_str(),project);
14344 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
14345 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
14346#endif
14347
14348 // Call the supporting function to build a file.
14349 string inputFilePrefix = "temp_dummy_file_";
14350
14351#if 0
14352 printf ("In SageBuilder::buildSourceFile(const std::string& outputFileName, SgProject* project): calling buildFile() \n");
14353#endif
14354
14355 SgFile* file = buildFile(inputFilePrefix+outputFileName,outputFileName,project,clear_globalScopeAcrossFiles);
14356 ROSE_ASSERT(file != NULL);
14357
14358#if 0
14359 printf ("DONE: In SageBuilder::buildSourceFile(): calling buildFile() \n");
14360#endif
14361
14362 SgSourceFile* sourceFile = isSgSourceFile(file);
14363 ROSE_ASSERT(sourceFile != NULL);
14364
14365 ROSE_ASSERT(sourceFile->get_globalScope() != NULL);
14366
14367#if 0
14368 printf ("call the unparser on the just built file \n");
14369#endif
14370
14371#if 0
14372 printf ("Exiting as a test! \n");
14373 ROSE_ABORT();
14374#endif
14375
14376 return sourceFile;
14377
14378 }
14379
14380SgSourceFile* SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project, bool clear_globalScopeAcrossFiles /*=false*/)
14381 {
14382#if 0
14383 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
14384 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
14385 printf ("In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling buildFile() \n");
14386 // printf (" --- inputFileName = %s outputFileName = %s \n",inputFileName.c_str(),outputFileName.c_str());
14387 printf (" --- inputFileName = %s \n",inputFileName.c_str());
14388 printf (" --- outputFileName = %s \n",outputFileName.c_str());
14389 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
14390 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
14391#endif
14392
14393#if 0
14394 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14395 ROSE_ASSERT(project != NULL);
14396 std::set<SgLocatedNode*> tmp1_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14397
14398 if (tmp1_collectionOfModifiedLocatedNodes.size() > 0)
14399 {
14400 printf ("In Traversal::evaluateInheritedAttribute(): tmp1_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp1_collectionOfModifiedLocatedNodes.size());
14401#if 1
14402 printf ("Exiting as a test! \n");
14403 ROSE_ASSERT(false);
14404#endif
14405 }
14406#endif
14407
14408 SgFile* file = buildFile(inputFileName, outputFileName,project,clear_globalScopeAcrossFiles);
14409 ROSE_ASSERT(file != NULL);
14410
14411#if 0
14412 printf ("DONE: In SageBuilder::buildSourceFile(): calling buildFile() \n");
14413#endif
14414
14415#if 0
14416 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14417 ROSE_ASSERT(project != NULL);
14418 std::set<SgLocatedNode*> tmp2_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14419
14420 if (tmp2_collectionOfModifiedLocatedNodes.size() > 0)
14421 {
14422 printf ("In Traversal::evaluateInheritedAttribute(): tmp2_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp2_collectionOfModifiedLocatedNodes.size());
14423#if 1
14424 printf ("Exiting as a test! \n");
14425 ROSE_ASSERT(false);
14426#endif
14427 }
14428#endif
14429
14430 SgSourceFile* sourceFile = isSgSourceFile(file);
14431 ROSE_ASSERT(sourceFile != NULL);
14432
14433 ROSE_ASSERT(sourceFile->get_globalScope() != NULL);
14434
14435#if 0
14436 // DQ (9/18/2019): Adding support for debugging the header file optimization.
14437 printf ("Debugging the unparsing header file optimization \n");
14438
14439 printf ("sourceFile->get_header_file_unparsing_optimization() = %s \n",sourceFile->get_header_file_unparsing_optimization() ? "true" : "false");
14440 printf ("sourceFile->get_header_file_unparsing_optimization_source_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14441 printf ("sourceFile->get_header_file_unparsing_optimization_header_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14442#endif
14443
14444#if 0
14445 // ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == false);
14446
14447 // DQ (9/18/2019): These are now set to true when the inputFileName matches a previously read file for which the optimizaton was turned on.
14448 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization() == true);
14449 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_source_file() == true);
14450 // ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == true);
14451 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == false);
14452#endif
14453
14454 // DQ (9/18/2019): Adding support for the header file optimization.
14455 // Check is this file matches an existing file and if so avoid regathering the CPP directives and comments (if posible).
14456 // If the original file was specified as being optimized for unparsing header files, then make this one similarly.
14457 SgFilePtrList & fileList = project->get_fileList();
14458
14459#if 0
14460 printf ("Looking for file = %s \n",inputFileName.c_str());
14461#endif
14462
14463 for (SgFilePtrList::iterator i = fileList.begin(); i != fileList.end(); i++)
14464 {
14465 SgFile* temp_file = *i;
14466#if 0
14467 printf ("temp_file = %p = %s name = %s \n",temp_file,temp_file->class_name().c_str(),temp_file->getFileName().c_str());
14468#endif
14469 if (temp_file != file)
14470 {
14471 if (temp_file->getFileName() == file->getFileName())
14472 {
14473 // Then the temp_file is the original version of the file we are building for a second time
14474 // (usually as a part of the outlining to a seperate file). and we need to mark at least the
14475 // unparsing headr file optimizations to be the same across thje two file.
14476
14477 // DQ (6/12/2021): The header_file_unparsing_optimization is now a static data member and the
14478 // header_file_unparsing_optimization_source_file and header_file_unparsing_optimization_header_file
14479 // data members have been removed.
14480 // temp_file->set_header_file_unparsing_optimization(sourceFile->get_header_file_unparsing_optimization());
14481 // temp_file->set_header_file_unparsing_optimization_source_file(sourceFile->get_header_file_unparsing_optimization_source_file());
14482 // temp_file->set_header_file_unparsing_optimization_header_file(sourceFile->get_header_file_unparsing_optimization_header_file());
14483#if 0
14484 printf ("sourceFile = %p = %s \n",sourceFile,sourceFile->class_name().c_str());
14485 printf ("sourceFile->get_header_file_unparsing_optimization() = %s \n",sourceFile->get_header_file_unparsing_optimization() ? "true" : "false");
14486 printf ("sourceFile->get_header_file_unparsing_optimization_source_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14487 printf ("sourceFile->get_header_file_unparsing_optimization_header_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14488
14489 printf ("temp_file = %p = %s \n",temp_file,temp_file->class_name().c_str());
14490 printf ("temp_file->get_header_file_unparsing_optimization() = %s \n",temp_file->get_header_file_unparsing_optimization() ? "true" : "false");
14491 printf ("temp_file->get_header_file_unparsing_optimization_source_file() = %s \n",temp_file->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14492 printf ("temp_file->get_header_file_unparsing_optimization_header_file() = %s \n",temp_file->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14493#endif
14494 }
14495 else
14496 {
14497 // This is a different file.
14498 }
14499 }
14500 else
14501 {
14502 // This is the same file, already added to the SgProject file list (as it should be).
14503 }
14504 }
14505
14506
14507#if 0
14508 printf ("sourceFile->get_file_info()->get_filename() = %s \n",sourceFile->get_file_info()->get_filename());
14509 int filename_id = Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()];
14510 int filename_physical_id = Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()];
14511 printf ("Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()] = %d \n",filename_id);
14512 printf ("Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()] = %d \n",filename_physical_id);
14513 sourceFile->get_file_info()->set_physical_file_id(filename_physical_id);
14514
14515 printf ("sourceFile->get_file_info()->get_physical_filename() = %s \n",sourceFile->get_file_info()->get_physical_filename().c_str());
14516 printf ("sourceFile->get_file_info()->get_physical_file_id() = %d \n",sourceFile->get_file_info()->get_physical_file_id());
14517#endif
14518
14519#if 0
14520 printf ("Exiting as a test! \n");
14521 ROSE_ABORT();
14522#endif
14523
14524 // DQ (1/11/2021): I think we should be calling secondaryPassOverSourceFile() instead of attachPreprocessingInfo() because we need to support the token-based unparsing.
14525#if 0
14526
14527#error "DEAD CODE!"
14528
14529#if 1
14530 // DQ (11/4/2019): I need to add this when I went back to testing tool_G.
14531 // It is required in the functions to attach CPP directives and comments.
14532 if (sourceFile->get_preprocessorDirectivesAndCommentsList() == NULL)
14533 {
14534#if 1
14535 printf ("Initialize NULL p_preprocessorDirectivesAndCommentsList to empty ROSEAttributesListContainer \n");
14536#endif
14537 ROSEAttributesListContainer* tmp_preprocessorDirectivesAndCommentsList = new ROSEAttributesListContainer();
14538 sourceFile->set_preprocessorDirectivesAndCommentsList(tmp_preprocessorDirectivesAndCommentsList);
14539 }
14540 else
14541 {
14542#if 1
14543 printf ("NOTE: p_preprocessorDirectivesAndCommentsList is already defined! \n");
14544 printf (" --- inputFileName = %s \n",inputFileName.c_str());
14545 printf (" --- outputFileName = %s \n",outputFileName.c_str());
14546 printf (" --- sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size() = %zu \n",sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size());
14547#endif
14548 }
14549 ROSE_ASSERT (sourceFile->get_preprocessorDirectivesAndCommentsList() != NULL);
14550
14551#if 0
14552 // DQ (5/22/2020): If this is processing a previously processed file, then this
14553 // will cause comments and CPP directives to be collected twice. This happens
14554 // in the case where we build a copy of the source file to support construction
14555 // of a dynamic library.
14556 printf ("NOTE: SageBuilder::buildSourceFile(): If this is processing a previously processed source file then this will cause the source file comments and CPP directives to be collected redundently \n");
14557#endif
14558
14559 // DQ (11/4/2019): This is a test that is use in attaching CPP directives and comments to the AST.
14560 ROSEAttributesListContainerPtr filePreprocInfo = sourceFile->get_preprocessorDirectivesAndCommentsList();
14561 ROSE_ASSERT(filePreprocInfo != NULL);
14562#endif
14563
14564#error "DEAD CODE!"
14565
14566#if 0
14567 printf ("In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling attachPreprocessingInfo() \n");
14568 printf (" --- sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size() = %zu \n",sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size());
14569#endif
14570
14571#if 0
14572 // DQ (12/3/2020): This is the root of the problem, the comments are built for the outputFileName, but the comments are marked with the inputFileName.
14573 printf ("We read the comments in filename inputFileName, and build outputFileName, and this is a problem since the comments are marked with the inputFileName \n");
14574 printf (" --- inputFileName = %s \n",inputFileName.c_str());
14575 printf (" --- outputFileName = %s \n",outputFileName.c_str());
14576 printf ("sourceFile = %p \n",sourceFile);
14577 printf ("sourceFile->get_token_list.size() = %zu \n",sourceFile->get_token_list().size());
14578 printf ("sourceFile->get_tokenSubsequenceMap().size() = %zu \n",sourceFile->get_tokenSubsequenceMap().size());
14579#endif
14580
14581#error "DEAD CODE!"
14582
14583 // DQ (1/4/2020): Adding support to permit comments and CPP directives and token stream to be defined using the outputFileName.
14584 // Liao, 2019, 1/31: We often need the preprocessing info. (e.g. #include ..) attached to make the new file compilable.
14585 // attachPreprocessingInfo (sourceFile);
14586 attachPreprocessingInfo (sourceFile,outputFileName);
14587#else
14588 // DQ (1/11/2021): Call the secondaryPassOverSourceFile() instead of attachPreprocessingInfo() because we need to support the token-based unparsing.
14590#endif
14591
14592#if 0
14593 printf ("Exiting after test! processed first phase of collecting comments and CPP directives for source file) \n");
14594 ROSE_ASSERT(false);
14595#endif
14596
14597#if 0
14598 printf ("DONE: In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling attachPreprocessingInfo() \n");
14599#endif
14600
14601#if 0
14602 printf ("call the unparser on the just built file \n");
14603#endif
14604
14605#if 0
14606 printf ("In buildSourceFile(): AS A TEST: calling unparseFile(): filename = %s \n",sourceFile->getFileName().c_str());
14607 backend(project);
14608#endif
14609
14610#if 1
14611 // DQ (11/8/2019): This is not working and breaks the current work at present.
14612 // DQ (11/8/2019): Support function to change the name in each of the IR node's source position info objects.
14613 fixupSourcePositionFileSpecification(sourceFile,outputFileName);
14614#endif
14615
14616 // DQ (1/8/2021): Set the filename used in the generated SgSourceFile to be the output file.
14617 // This appears to be important so that we can get either key correct for the comments and CPP
14618 // directives and or the comments and CPP directives to be consistant as well as the token stream,
14619 // I think this might be less about the comments and CPP directives than the key for the token stream.
14620 // Either that or I need to have an extra field for the SgSourceFile name when it is read from one
14621 // file, but trying to be another file.
14622 // sourceFile->setFileName(outputFileName);
14623
14624#if 0
14625 printf ("In SageBuilder::buildSourceFile(): changing the name of the file represented in sourceFile: \n");
14626 printf ("inputFileName = %s \n",inputFileName.c_str());
14627 printf ("outputFileName = %s \n",outputFileName.c_str());
14628 printf ("sourceFile->getFileName() = %s \n",sourceFile->getFileName().c_str());
14629#endif
14630
14631 SgGlobal* globalScope = sourceFile->get_globalScope();
14632
14633#if 0
14634 printf ("Leaving SageBuilder::buildSourceFile() sourceFile = %p globalScope = %p \n",sourceFile,sourceFile->get_globalScope());
14635 printf ("sourceFile->get_file_info()->get_file_id() = %d \n",sourceFile->get_file_info()->get_file_id());
14636 printf ("sourceFile->get_file_info()->get_physical_file_id() = %d \n",sourceFile->get_file_info()->get_physical_file_id());
14637 printf ("sourceFile->get_token_list.size() = %zu \n",sourceFile->get_token_list().size());
14638 printf ("sourceFile->get_tokenSubsequenceMap().size() = %zu \n",sourceFile->get_tokenSubsequenceMap().size());
14639 printf ("inputFileName = %s \n",inputFileName.c_str());
14640 printf ("outputFileName = %s \n",outputFileName.c_str());
14641 printf ("sourceFile->getFileName() = %s \n",sourceFile->getFileName().c_str());
14642
14643 printf ("sourceFile->get_globalScope() = %p \n",globalScope);
14644 printf ("globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
14645#endif
14646
14647 // DQ (6/1/2021): We need to end this function with the isModified flag set to false. This is
14648 // important for the support of the token based unparsing when building a dynamic library.
14649 // This is important in permitting the simpleFrontierDetectionForTokenStreamMapping() function
14650 // to generate the correct settings for nodes in the second file constructed from the original file.
14651 if (globalScope->get_isModified() == true)
14652 {
14653#if 0
14654 printf ("globalScope->get_isModified() == true: reset to false \n");
14655#endif
14656 globalScope->set_isModified(false);
14657#if 0
14658 printf ("Verify false setting: globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
14659#endif
14660 }
14661
14662#if 0
14663 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14664 ROSE_ASSERT(project != NULL);
14665 std::set<SgLocatedNode*> tmp3_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14666
14667 if (tmp3_collectionOfModifiedLocatedNodes.size() > 0)
14668 {
14669 printf ("In Traversal::evaluateInheritedAttribute(): tmp3_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp3_collectionOfModifiedLocatedNodes.size());
14670#if 1
14671 printf ("Exiting as a test! \n");
14672 ROSE_ASSERT(false);
14673#endif
14674 }
14675#endif
14676
14677#if 0
14678 printf ("Exiting as a test! \n");
14679 ROSE_ABORT();
14680#endif
14681
14682 return sourceFile;
14683 }
14684
14685
14686PreprocessingInfo* SageBuilder::buildComment(SgLocatedNode* target, const std::string & content,PreprocessingInfo::RelativePositionType position/*=PreprocessingInfo::before*/,PreprocessingInfo::DirectiveType dtype/* = PreprocessingInfo::CpreprocessorUnknownDeclaration*/)
14687 {
14688 return SageInterface::attachComment(target,content, position, dtype);
14689 }
14690
14692PreprocessingInfo* SageBuilder::buildHeader(const std::string& header_filename,
14693 PreprocessingInfo::RelativePositionType position/*=PreprocessingInfo::before*/,
14694 bool isSystemHeader/* =false*/)
14695{
14696 std::string content;
14697 if (isSystemHeader)
14698 content = "#include <" + header_filename + "> \n";
14699 else
14700 content = "#include \"" + header_filename + "\" \n";
14701 PreprocessingInfo* result = new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration,
14702 content, "Transformation generated",0, 0, 0, position);
14703 ROSE_ASSERT(result);
14704
14705 result->get_file_info()->setTransformation();
14706 return result;
14707}
14708
14710PreprocessingInfo* SageBuilder::buildCpreprocessorDefineDeclaration(SgLocatedNode* target,const std::string & content,PreprocessingInfo::RelativePositionType position /* =PreprocessingInfo::before*/)
14711 {
14712 ROSE_ASSERT(target != NULL); //dangling #define xxx is not allowed in the ROSE AST
14713 // simple input verification
14714 std::string content2 = content;
14715 boost::algorithm::trim(content2);
14716 string prefix = "#define";
14717 string::size_type pos = content2.find(prefix, 0);
14718 ROSE_ASSERT (pos == 0);
14719
14720 PreprocessingInfo* result = NULL;
14721
14722 PreprocessingInfo::DirectiveType mytype = PreprocessingInfo::CpreprocessorDefineDeclaration;
14723
14724 // DQ (7/19/2008): Modified interface to PreprocessingInfo
14725 // result = new PreprocessingInfo (mytype,content, "transformation-generated", 0, 0, 0, position, false, true);
14726 result = new PreprocessingInfo (mytype,content, "transformation-generated", 0, 0, 0, position);
14727 ROSE_ASSERT(result);
14728 target->addToAttachedPreprocessingInfo(result);
14729 return result;
14730
14731 }
14732
14733
14734#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
14737{
14738 // avoid duplicated creation
14739 static std::map<SgNode*, AbstractHandle::abstract_handle *> handleMap;
14740
14741 ROSE_ASSERT(n != NULL);
14742 AbstractHandle::abstract_handle * ahandle =handleMap[n];
14743 if (ahandle==NULL)
14744 {
14746 ROSE_ASSERT(anode !=NULL );
14747 ahandle = new AbstractHandle::abstract_handle(anode);
14748 //TODO do we allow NULL handle to be returned?
14749 ROSE_ASSERT(ahandle != NULL);
14750 }
14751 return ahandle;
14752}
14753#endif
14754
14757{
14758 ROSE_ASSERT(exp1 != NULL);
14759 ROSE_ASSERT(exp2 != NULL);
14760
14761 SgExprListExp* tuple = buildExprListExp(exp1,exp2);
14762 SgExprListExp* setList = buildExprListExp(tuple);
14763 SgEquivalenceStatement* equivalenceStatement = new SgEquivalenceStatement();
14764 ROSE_ASSERT(equivalenceStatement->get_equivalence_set_list() == NULL);
14765 equivalenceStatement->set_equivalence_set_list(setList);
14766 ROSE_ASSERT(equivalenceStatement->get_equivalence_set_list() != NULL);
14767 equivalenceStatement->set_firstNondefiningDeclaration(equivalenceStatement);
14768 setOneSourcePositionForTransformation(equivalenceStatement);
14769 return equivalenceStatement;
14770}
14771
14772SgSymbol*
14774 {
14775 // Starting at the snippet_declaration, record the associated scope list to the global scope.
14776 // The do a reverse traversal on the list starting with the global scope of the target AST.
14777 // Lookup each declaration as we proceed deeper into the target AST to find the associated
14778 // symbol in the target AST (associated with the input declaration from the snippet AST).
14779
14780 SgSymbol* returnSymbol = NULL;
14781
14782 typedef Rose_STL_Container<SgScopeStatement*> SgScopeStatementPtrList;
14783 SgScopeStatementPtrList snippet_scope_list;
14784
14785 // Starting at the snippet_declaration, record the associated scope list to the global scope.
14786 // SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
14787 SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
14788#if 1
14789 printf ("First scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
14790 SgClassDefinition* temp_classDefinition = isSgClassDefinition(snippet_scope);
14791 if (temp_classDefinition != NULL)
14792 {
14793 SgClassDeclaration* temp_classDeclaration = temp_classDefinition->get_declaration();
14794 SgName className = temp_classDeclaration->get_name();
14795#if 1
14796 printf ("Input snippet declaration's class name = %s \n",className.str());
14797#endif
14798 }
14799 SgNamespaceDefinitionStatement* namespaceDefinitionStatement = isSgNamespaceDefinitionStatement(snippet_scope);
14800 if (namespaceDefinitionStatement != NULL)
14801 {
14802
14803 }
14804#endif
14805 snippet_scope_list.push_back(snippet_scope);
14806 while (snippet_scope != NULL && isSgGlobal(snippet_scope) == NULL)
14807 {
14808 // The scopes between the snippet declaration and the global scope should be named scopes,
14809 // else we will not be able to identify the associated scope in the target AST.
14810 ROSE_ASSERT(snippet_scope->isNamedScope() == true);
14811
14812 snippet_scope = snippet_scope->get_scope();
14813#if 1
14814 printf ("snippet_scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
14815#endif
14816 snippet_scope_list.push_back(snippet_scope);
14817 }
14818
14819#if 1
14820 printf ("snippet_scope_list.size() = %" PRIuPTR " \n",snippet_scope_list.size());
14821#endif
14822
14823 SgGlobal* global_scope_in_target_ast = TransformationSupport::getGlobalScope(targetScope);
14824 SgScopeStatementPtrList::reverse_iterator i = snippet_scope_list.rbegin();
14825
14826 SgScopeStatement* target_AST_scope = global_scope_in_target_ast;
14827 SgScopeStatement* snippet_AST_scope = *i;
14828
14829 ROSE_ASSERT(isSgGlobal(snippet_AST_scope) != NULL);
14830 // Iterate past the global scope
14831 i++;
14832
14833 // Traverse the snippet scopes in the reverse order from global scope to the associated scope in the target AST.
14834 while (i != snippet_scope_list.rend())
14835 {
14836 // This loop has to handle different types of names scopes (for C this only means structs, I think).
14837#if 1
14838 printf ("snippet_AST_scope list *i = %p = %s \n",*i,(*i)->class_name().c_str());
14839#endif
14840 // printf ("target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope ->class_name().c_str());
14841 // printf ("snippet_AST_scope = %p = %s \n",snippet_AST_scope,snippet_AST_scope ->class_name().c_str());
14842
14843 // DQ (12/5/2020): I think this should be a switch statement.
14844 SgClassDefinition* classDefinition = isSgClassDefinition(*i);
14845 if (classDefinition != NULL)
14846 {
14847 SgClassDeclaration* classDeclaration = classDefinition->get_declaration();
14848 SgName className = classDeclaration->get_name();
14849#if 1
14850 printf ("Found snippet class name = %s \n",className.str());
14851#endif
14852 SgClassSymbol* classSymbol = target_AST_scope->lookup_class_symbol(className);
14853 ROSE_ASSERT(classSymbol != NULL);
14854 ROSE_ASSERT(classSymbol->get_declaration() != NULL);
14855#if 1
14856 printf ("Associated symbol in taget AST: declaration = %p name = %s \n",classSymbol->get_declaration(),classSymbol->get_declaration()->get_name().str());
14857#endif
14858 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
14859 returnSymbol = classSymbol;
14860
14861 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
14862 target_AST_scope = classDefinition;
14863 }
14864
14865 // Not clear if we can have this case for C or C++.
14866 SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(*i);
14867 if (functionDefinition != NULL)
14868 {
14869 printf ("ERROR: Found an unusual case of SgFunctionDefinition in list of scopes holding a declaration for a type \n");
14870 ROSE_ABORT();
14871 }
14872
14873 SgNamespaceDefinitionStatement* namespaceDefinition = isSgNamespaceDefinitionStatement(*i);
14874 if (namespaceDefinition != NULL)
14875 {
14876 SgNamespaceDeclarationStatement* namespaceDeclaration = namespaceDefinition->get_namespaceDeclaration();
14877 SgName namespaceName = namespaceDeclaration->get_name();
14878#if 1
14879 printf ("Found snippet namespace name = %s \n",namespaceName.str());
14880#endif
14881 SgNamespaceSymbol* namespaceSymbol = target_AST_scope->lookup_namespace_symbol(namespaceName);
14882 ROSE_ASSERT(namespaceSymbol != NULL);
14883 ROSE_ASSERT(namespaceSymbol->get_declaration() != NULL);
14884#if 1
14885 printf ("Associated symbol in taget AST: declaration = %p name = %s \n",namespaceSymbol->get_declaration(),namespaceSymbol->get_declaration()->get_name().str());
14886#endif
14887 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
14888 returnSymbol = namespaceSymbol;
14889
14890 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
14891 target_AST_scope = namespaceDefinition;
14892 }
14893
14894 // Increment the reverse iterator.
14895 i++;
14896 }
14897
14898 // Handle the different cases using a switch (there are only a few cases).
14899 switch (snippet_declaration->variantT())
14900 {
14901 case V_SgClassDeclaration:
14902 {
14903 SgClassDeclaration* snippet_classDeclaration = isSgClassDeclaration(snippet_declaration);
14904 ROSE_ASSERT(snippet_classDeclaration != NULL);
14905
14906 SgName snippet_className = snippet_classDeclaration->get_name();
14907#if 0
14908 printf ("snippet snippet declaration's class name = %s \n",snippet_className.str());
14909#endif
14910 SgClassSymbol* target_symbol = target_AST_scope->lookup_class_symbol(snippet_className);
14911 ROSE_ASSERT(target_symbol != NULL);
14912 returnSymbol = target_symbol;
14913
14914 SgClassSymbol* classSymbolInTargetAST = isSgClassSymbol(returnSymbol);
14915 ROSE_ASSERT(classSymbolInTargetAST != NULL);
14916 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
14917 ROSE_ASSERT(target_classDeclaration != NULL);
14918#if 0
14919 printf ("snippet: classDeclaration = %p = %s \n",snippet_classDeclaration,snippet_classDeclaration->get_name().str());
14920 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
14921#endif
14922 ROSE_ASSERT(snippet_classDeclaration->get_name() == target_classDeclaration->get_name());
14923 break;
14924 }
14925
14926 case V_SgTypedefDeclaration:
14927 {
14928 SgTypedefDeclaration* snippet_typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
14929 ROSE_ASSERT(snippet_typedefDeclaration != NULL);
14930
14931 SgName snippet_typedefName = snippet_typedefDeclaration->get_name();
14932#if 0
14933 printf ("snippet snippet declaration's typedef name = %s \n",snippet_typedefName.str());
14934#endif
14935 SgTypedefSymbol* target_symbol = target_AST_scope->lookup_typedef_symbol(snippet_typedefName);
14936 ROSE_ASSERT(target_symbol != NULL);
14937 returnSymbol = target_symbol;
14938
14939 SgTypedefSymbol* typedefSymbolInTargetAST = isSgTypedefSymbol(returnSymbol);
14940 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
14941 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
14942 ROSE_ASSERT(target_typedefDeclaration != NULL);
14943#if 0
14944 printf ("snippet: typedefDeclaration = %p = %s \n",snippet_typedefDeclaration,snippet_typedefDeclaration->get_name().str());
14945 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
14946#endif
14947 ROSE_ASSERT(snippet_typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
14948 break;
14949 }
14950
14951 case V_SgEnumDeclaration:
14952 {
14953 SgEnumDeclaration* snippet_enumDeclaration = isSgEnumDeclaration(snippet_declaration);
14954 ROSE_ASSERT(snippet_enumDeclaration != NULL);
14955
14956 SgName snippet_enumName = snippet_enumDeclaration->get_name();
14957#if 0
14958 printf ("snippet snippet declaration's enum name = %s \n",snippet_enumName.str());
14959#endif
14960 // DQ (4/13/2014): check if this is an un-named enum beclaration.
14961 bool isUnNamed = snippet_enumDeclaration->get_isUnNamed();
14962 if (isUnNamed == false)
14963 {
14964 // SgEnumSymbol* target_symbol = target_AST_scope->lookup_enum_symbol(snippet_enumName);
14965 SgEnumSymbol* target_symbol = lookupEnumSymbolInParentScopes(snippet_enumName,target_AST_scope);
14966 if (target_symbol == NULL)
14967 {
14968 // Debug this case.
14969 SgScopeStatement* scope = snippet_enumDeclaration->get_scope();
14970 printf ("scope = %p = %s \n",scope,scope->class_name().c_str());
14971 scope->get_file_info()->display("case V_SgEnumDeclaration: target_symbol == NULL: scope: debug");
14972 }
14973 ROSE_ASSERT(target_symbol != NULL);
14974 returnSymbol = target_symbol;
14975
14976 SgEnumSymbol* enumSymbolInTargetAST = isSgEnumSymbol(returnSymbol);
14977 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
14978 SgEnumDeclaration* target_enumDeclaration = isSgEnumDeclaration(enumSymbolInTargetAST->get_declaration());
14979 ROSE_ASSERT(target_enumDeclaration != NULL);
14980#if 0
14981 printf ("snippet: enumDeclaration = %p = %s \n",snippet_enumDeclaration,snippet_enumDeclaration->get_name().str());
14982 printf ("target: enumDeclaration = %p = %s \n",target_enumDeclaration,target_enumDeclaration->get_name().str());
14983#endif
14984 ROSE_ASSERT(snippet_enumDeclaration->get_name() == target_enumDeclaration->get_name());
14985 }
14986 else
14987 {
14988 // DQ (4/13/2014): I think we all agreed these would not have to be handled.
14989 printf ("Warning: can't handle unnamed enum declarations \n");
14990 ROSE_ASSERT(returnSymbol == NULL);
14991 }
14992 break;
14993 }
14994
14995 // DQ (12/5/2020): Adding support for codeSegregation tool.
14996 case V_SgMemberFunctionDeclaration:
14997 case V_SgFunctionDeclaration:
14998 {
14999 SgFunctionDeclaration* snippet_functionDeclaration = isSgFunctionDeclaration(snippet_declaration);
15000 ROSE_ASSERT(snippet_functionDeclaration != NULL);
15001#if 1
15002 printf ("snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15003#endif
15004 SgName snippet_functionName = snippet_functionDeclaration->get_name();
15005#if 1
15006 printf ("snippet snippet declaration's function name = %s \n",snippet_functionName.str());
15007 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope->class_name().c_str());
15008#endif
15009 SgFunctionSymbol* target_symbol = target_AST_scope->lookup_function_symbol(snippet_functionName);
15010 ROSE_ASSERT(target_symbol != NULL);
15011 returnSymbol = target_symbol;
15012
15013 SgFunctionSymbol* functionSymbolInTargetAST = isSgFunctionSymbol(returnSymbol);
15014 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
15015 SgFunctionDeclaration* target_functionDeclaration = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
15016 ROSE_ASSERT(target_functionDeclaration != NULL);
15017#if 1
15018 printf ("snippet: functionDeclaration = %p = %s \n",snippet_functionDeclaration,snippet_functionDeclaration->get_name().str());
15019 printf ("target: functionDeclaration = %p = %s \n",target_functionDeclaration,target_functionDeclaration->get_name().str());
15020#endif
15021 ROSE_ASSERT(snippet_functionDeclaration->get_name() == target_functionDeclaration->get_name());
15022 break;
15023 }
15024
15025 default:
15026 {
15027 printf ("Error: default reached in switch: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15028 ROSE_ABORT();
15029 }
15030 }
15031
15032 // return the last found symbol.
15033 return returnSymbol;
15034 }
15035
15036
15039 {
15040 // DQ (12/6/2020): This is a similar function to findAssociatedSymbolInTargetAST() but since
15041 // I need to modify it to support the requirements of the codeSegregation, it was useful to not
15042 // modify the existing findAssociatedSymbolInTargetAST() function too much so as to avoid
15043 // compromizing the snippet transformation support.
15044
15045#define DEBUG_FIND_ASSOCIATED_DECLARATION 0
15046
15047 SgSymbol* returnSymbol = NULL;
15048 SgDeclarationStatement* returnDeclaration = NULL;
15049
15050 bool isDefiningDeclaration = (snippet_declaration == snippet_declaration->get_definingDeclaration());
15051
15052#if DEBUG_FIND_ASSOCIATED_DECLARATION
15053 printf ("isDefiningDeclaration = %s \n",isDefiningDeclaration ? "true" : "false");
15054#endif
15055
15056 // DQ (12/7/2020): This should be true.
15057 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,targetScope) == false);
15058
15059 typedef Rose_STL_Container<SgScopeStatement*> SgScopeStatementPtrList;
15060 SgScopeStatementPtrList snippet_scope_list;
15061
15062 // Starting at the snippet_declaration, record the associated scope list to the global scope.
15063 // SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15064 SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15065#if DEBUG_FIND_ASSOCIATED_DECLARATION
15066 printf ("First scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15067 SgClassDefinition* temp_classDefinition = isSgClassDefinition(snippet_scope);
15068 if (temp_classDefinition != NULL)
15069 {
15070 SgClassDeclaration* temp_classDeclaration = temp_classDefinition->get_declaration();
15071 SgName className = temp_classDeclaration->get_name();
15072 printf ("Input declaration's class name = %s \n",className.str());
15073 }
15074
15075 SgNamespaceDefinitionStatement* namespaceDefinitionStatement = isSgNamespaceDefinitionStatement(snippet_scope);
15076 if (namespaceDefinitionStatement != NULL)
15077 {
15078 SgNamespaceDeclarationStatement* temp_namespaceDeclaration = namespaceDefinitionStatement->get_namespaceDeclaration();
15079 SgName namespaceName = temp_namespaceDeclaration->get_name();
15080 printf ("Input declaration's namespace name = %s \n",namespaceName.str());
15081 }
15082#endif
15083
15084 snippet_scope_list.push_back(snippet_scope);
15085 while (snippet_scope != NULL && isSgGlobal(snippet_scope) == NULL)
15086 {
15087 // The scopes between the snippet declaration and the global scope should be named scopes,
15088 // else we will not be able to identify the associated scope in the target AST.
15089 ROSE_ASSERT(snippet_scope->isNamedScope() == true);
15090
15091 snippet_scope = snippet_scope->get_scope();
15092
15093#if DEBUG_FIND_ASSOCIATED_DECLARATION
15094 printf ("snippet_scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15095#endif
15096 snippet_scope_list.push_back(snippet_scope);
15097
15098 // DQ (12/7/2020): At this point the scopes that we are traversing to the global scope should
15099 // have the same global scope as the input declaration.
15100 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_scope) == true);
15101 }
15102
15103#if DEBUG_FIND_ASSOCIATED_DECLARATION
15104 printf ("snippet_scope_list.size() = %" PRIuPTR " \n",snippet_scope_list.size());
15105 for (SgScopeStatementPtrList::iterator i = snippet_scope_list.begin(); i != snippet_scope_list.end(); i++)
15106 {
15107 SgScopeStatement* scope = *i;
15108 printf (" --- *i = %p = %s name = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
15109 SgGlobal* global_scope_from_declarations_scope = TransformationSupport::getGlobalScope(scope);
15110 printf (" --- --- global_scope_from_declarations_scope = %p \n",global_scope_from_declarations_scope);
15111 }
15112#endif
15113
15114 // DQ (12/7/2020): At this point the scopes that we are traversing to the global scope should
15115 // have the same global scope as the input declaration.
15116 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_scope) == true);
15117
15118 SgGlobal* global_scope_in_target_ast = TransformationSupport::getGlobalScope(targetScope);
15119 SgScopeStatementPtrList::reverse_iterator i = snippet_scope_list.rbegin();
15120
15121#if DEBUG_FIND_ASSOCIATED_DECLARATION
15122 printf ("global_scope_in_target_ast = %p = %s \n",global_scope_in_target_ast,global_scope_in_target_ast->class_name().c_str());
15123#endif
15124
15125 SgScopeStatement* target_AST_scope = global_scope_in_target_ast;
15126 SgScopeStatement* snippet_AST_scope = *i;
15127
15128 // DQ (12/7/2020): This should be true.
15129 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_AST_scope) == true);
15130
15131 ROSE_ASSERT(isSgGlobal(snippet_AST_scope) != NULL);
15132 // Iterate past the global scope
15133 i++;
15134
15135#if DEBUG_FIND_ASSOCIATED_DECLARATION
15136 string otherASTnameFromGlobalScope = global_scope_in_target_ast->get_file_info()->get_filenameString();
15137 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(targetScope,true);
15138 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15139 printf ("Now traverse the list of scopes in reverse to find the declaration in the other AST: \n");
15140 printf ("otherASTnameFromGlobalScope = %s \n",otherASTnameFromGlobalScope.c_str());
15141 printf ("otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15142#endif
15143
15144 // DQ (12/7/2020): This should be true.
15145 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15146
15147 // Traverse the snippet scopes in the reverse order from global scope to the associated scope in the target AST.
15148 while (i != snippet_scope_list.rend())
15149 {
15150 // This loop has to handle different types of names scopes (for C this only means structs, I think).
15151
15152 SgScopeStatement* scope = *i;
15153
15154#if DEBUG_FIND_ASSOCIATED_DECLARATION
15155 printf ("snippet_AST_scope list *i = %p = %s \n",*i,(*i)->class_name().c_str());
15156 printf (" --- *i = %p = %s name = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
15157 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope ->class_name().c_str());
15158 // printf ("snippet_AST_scope = %p = %s \n",snippet_AST_scope,snippet_AST_scope ->class_name().c_str());
15159#endif
15160
15161 // DQ (12/7/2020): This should still be true.
15162 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,scope) == true);
15163
15164#if DEBUG_FIND_ASSOCIATED_DECLARATION
15165 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(targetScope,true);
15166 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15167 printf (" --- otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15168#endif
15169
15170 // DQ (12/5/2020): I think this should be a switch statement.
15171 SgClassDefinition* classDefinition = isSgClassDefinition(*i);
15172 if (classDefinition != NULL)
15173 {
15174 SgClassDeclaration* classDeclaration = classDefinition->get_declaration();
15175 SgName className = classDeclaration->get_name();
15176#if DEBUG_FIND_ASSOCIATED_DECLARATION
15177 printf (" --- Found snippet class name = %s \n",className.str());
15178#endif
15179 SgClassSymbol* classSymbol = target_AST_scope->lookup_class_symbol(className);
15180 ROSE_ASSERT(classSymbol != NULL);
15181 ROSE_ASSERT(classSymbol->get_declaration() != NULL);
15182#if DEBUG_FIND_ASSOCIATED_DECLARATION
15183 printf (" --- Associated symbol in taget AST: declaration = %p name = %s \n",classSymbol->get_declaration(),classSymbol->get_declaration()->get_name().str());
15184#endif
15185 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15186 returnSymbol = classSymbol;
15187
15188 // DQ (12/8/2020): Need to get the associated class definition from the symbol in the target scope.
15189 SgClassDeclaration* temp_classDeclaration_in_target_ast = classSymbol->get_declaration();
15190 ROSE_ASSERT(temp_classDeclaration_in_target_ast != NULL);
15191 SgClassDeclaration* classDeclaration_in_target_ast = isSgClassDeclaration(temp_classDeclaration_in_target_ast->get_definingDeclaration());
15192 ROSE_ASSERT(classDeclaration_in_target_ast != NULL);
15193 SgClassDefinition* classDefinition_in_target_ast = classDeclaration_in_target_ast->get_definition();
15194 ROSE_ASSERT(classDefinition_in_target_ast != NULL);
15195
15196 // DQ (12/7/2020): This should be true.
15197 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15198
15199 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15200 // target_AST_scope = classDefinition;
15201 target_AST_scope = classDefinition_in_target_ast;
15202
15203 // DQ (12/7/2020): This should be true.
15204 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15205 }
15206
15207 // Not clear if we can have this case for C or C++.
15208 SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(*i);
15209 if (functionDefinition != NULL)
15210 {
15211 printf ("ERROR: Found an unusual case of SgFunctionDefinition in list of scopes holding a declaration for a type \n");
15212 ROSE_ABORT();
15213 }
15214
15215 SgNamespaceDefinitionStatement* namespaceDefinition = isSgNamespaceDefinitionStatement(*i);
15216 if (namespaceDefinition != NULL)
15217 {
15218 SgNamespaceDeclarationStatement* namespaceDeclaration = namespaceDefinition->get_namespaceDeclaration();
15219 SgName namespaceName = namespaceDeclaration->get_name();
15220#if DEBUG_FIND_ASSOCIATED_DECLARATION
15221 printf (" --- Found snippet namespace name = %s \n",namespaceName.str());
15222#endif
15223 SgNamespaceSymbol* namespaceSymbol = target_AST_scope->lookup_namespace_symbol(namespaceName);
15224 ROSE_ASSERT(namespaceSymbol != NULL);
15225 ROSE_ASSERT(namespaceSymbol->get_declaration() != NULL);
15226 SgNamespaceDeclarationStatement* otherASTnamespaceDeclaration = namespaceSymbol->get_declaration();
15227#if DEBUG_FIND_ASSOCIATED_DECLARATION
15228 printf (" --- Associated symbol in taget AST: declaration = %p name = %s \n",namespaceSymbol->get_declaration(),namespaceSymbol->get_declaration()->get_name().str());
15229#endif
15230 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15231 returnSymbol = namespaceSymbol;
15232
15233 // DQ (12/7/2020): This should be true.
15234 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15235
15236 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15237 // target_AST_scope = namespaceDefinition;
15238 target_AST_scope = otherASTnamespaceDeclaration->get_definition();
15239
15240 // DQ (12/7/2020): This should be true.
15241 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15242 }
15243
15244 // DQ (12/7/2020): This should be true.
15245 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15246
15247#if DEBUG_FIND_ASSOCIATED_DECLARATION
15248 printf (" --- At base of loop of the list of scopes in top to bottom: target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope->class_name().c_str());
15249
15250 {
15251 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(target_AST_scope,true);
15252 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15253 printf (" --- At base of loop: otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15254 }
15255#endif
15256 // Increment the reverse iterator.
15257 i++;
15258 }
15259
15260#if DEBUG_FIND_ASSOCIATED_DECLARATION
15261 printf ("##### Now based on the kind of declaration, search for that same named declaration in the target_AST_scope = %p = %s \n",
15262 target_AST_scope,target_AST_scope->class_name().c_str());
15263#endif
15264
15265 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15266
15267 // Handle the different cases using a switch (there are only a few cases).
15268 switch (snippet_declaration->variantT())
15269 {
15270 case V_SgClassDeclaration:
15271 {
15272 SgClassDeclaration* snippet_classDeclaration = isSgClassDeclaration(snippet_declaration);
15273 ROSE_ASSERT(snippet_classDeclaration != NULL);
15274
15275 SgName snippet_className = snippet_classDeclaration->get_name();
15276
15277#if DEBUG_FIND_ASSOCIATED_DECLARATION
15278 printf ("snippet snippet declaration's class name = %s \n",snippet_className.str());
15279#endif
15280 SgClassSymbol* target_symbol = target_AST_scope->lookup_class_symbol(snippet_className);
15281 ROSE_ASSERT(target_symbol != NULL);
15282 returnSymbol = target_symbol;
15283
15284 SgClassSymbol* classSymbolInTargetAST = isSgClassSymbol(returnSymbol);
15285 ROSE_ASSERT(classSymbolInTargetAST != NULL);
15286 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
15287 ROSE_ASSERT(target_classDeclaration != NULL);
15288
15289#if DEBUG_FIND_ASSOCIATED_DECLARATION
15290 printf ("snippet: classDeclaration = %p = %s \n",snippet_classDeclaration,snippet_classDeclaration->get_name().str());
15291 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
15292#endif
15293 ROSE_ASSERT(snippet_classDeclaration->get_name() == target_classDeclaration->get_name());
15294 break;
15295 }
15296
15297 case V_SgTypedefDeclaration:
15298 {
15299 SgTypedefDeclaration* snippet_typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
15300 ROSE_ASSERT(snippet_typedefDeclaration != NULL);
15301
15302 SgName snippet_typedefName = snippet_typedefDeclaration->get_name();
15303
15304#if DEBUG_FIND_ASSOCIATED_DECLARATION
15305 printf ("snippet snippet declaration's typedef name = %s \n",snippet_typedefName.str());
15306#endif
15307 SgTypedefSymbol* target_symbol = target_AST_scope->lookup_typedef_symbol(snippet_typedefName);
15308 ROSE_ASSERT(target_symbol != NULL);
15309 returnSymbol = target_symbol;
15310
15311 SgTypedefSymbol* typedefSymbolInTargetAST = isSgTypedefSymbol(returnSymbol);
15312 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15313 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
15314 ROSE_ASSERT(target_typedefDeclaration != NULL);
15315
15316#if DEBUG_FIND_ASSOCIATED_DECLARATION
15317 printf ("snippet: typedefDeclaration = %p = %s \n",snippet_typedefDeclaration,snippet_typedefDeclaration->get_name().str());
15318 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
15319#endif
15320 ROSE_ASSERT(snippet_typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
15321 break;
15322 }
15323
15324 case V_SgEnumDeclaration:
15325 {
15326 SgEnumDeclaration* snippet_enumDeclaration = isSgEnumDeclaration(snippet_declaration);
15327 ROSE_ASSERT(snippet_enumDeclaration != NULL);
15328
15329 SgName snippet_enumName = snippet_enumDeclaration->get_name();
15330
15331#if DEBUG_FIND_ASSOCIATED_DECLARATION
15332 printf ("snippet snippet declaration's enum name = %s \n",snippet_enumName.str());
15333#endif
15334 // DQ (4/13/2014): check if this is an un-named enum beclaration.
15335 bool isUnNamed = snippet_enumDeclaration->get_isUnNamed();
15336 if (isUnNamed == false)
15337 {
15338 // SgEnumSymbol* target_symbol = target_AST_scope->lookup_enum_symbol(snippet_enumName);
15339 SgEnumSymbol* target_symbol = lookupEnumSymbolInParentScopes(snippet_enumName,target_AST_scope);
15340 if (target_symbol == NULL)
15341 {
15342 // Debug this case.
15343 SgScopeStatement* scope = snippet_enumDeclaration->get_scope();
15344 printf ("scope = %p = %s \n",scope,scope->class_name().c_str());
15345 scope->get_file_info()->display("case V_SgEnumDeclaration: target_symbol == NULL: scope: debug");
15346 }
15347 ROSE_ASSERT(target_symbol != NULL);
15348 returnSymbol = target_symbol;
15349
15350 SgEnumSymbol* enumSymbolInTargetAST = isSgEnumSymbol(returnSymbol);
15351 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
15352 SgEnumDeclaration* target_enumDeclaration = isSgEnumDeclaration(enumSymbolInTargetAST->get_declaration());
15353 ROSE_ASSERT(target_enumDeclaration != NULL);
15354
15355#if DEBUG_FIND_ASSOCIATED_DECLARATION
15356 printf ("snippet: enumDeclaration = %p = %s \n",snippet_enumDeclaration,snippet_enumDeclaration->get_name().str());
15357 printf ("target: enumDeclaration = %p = %s \n",target_enumDeclaration,target_enumDeclaration->get_name().str());
15358#endif
15359 ROSE_ASSERT(snippet_enumDeclaration->get_name() == target_enumDeclaration->get_name());
15360 }
15361 else
15362 {
15363 // DQ (4/13/2014): I think we all agreed these would not have to be handled.
15364 printf ("Warning: can't handle unnamed enum declarations \n");
15365 ROSE_ASSERT(returnSymbol == NULL);
15366 }
15367 break;
15368 }
15369
15370 // DQ (12/11/2020): Adding support for codeSegregation tool.
15371 case V_SgTemplateMemberFunctionDeclaration:
15372 // DQ (12/8/2020): Adding support for codeSegregation tool.
15373 case V_SgTemplateFunctionDeclaration:
15374 // DQ (12/5/2020): Adding support for codeSegregation tool.
15375 case V_SgMemberFunctionDeclaration:
15376 case V_SgFunctionDeclaration:
15377 {
15378 SgFunctionDeclaration* snippet_functionDeclaration = isSgFunctionDeclaration(snippet_declaration);
15379 ROSE_ASSERT(snippet_functionDeclaration != NULL);
15380
15381#if DEBUG_FIND_ASSOCIATED_DECLARATION
15382 printf ("snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15383#endif
15384 SgName snippet_functionName = snippet_functionDeclaration->get_name();
15385
15386#if DEBUG_FIND_ASSOCIATED_DECLARATION
15387 printf ("snippet snippet declaration's function name = %s \n",snippet_functionName.str());
15388 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope->class_name().c_str());
15389#endif
15390 SgFunctionSymbol* target_symbol = target_AST_scope->lookup_function_symbol(snippet_functionName);
15391 ROSE_ASSERT(target_symbol != NULL);
15392 returnSymbol = target_symbol;
15393
15394 SgFunctionSymbol* functionSymbolInTargetAST = isSgFunctionSymbol(returnSymbol);
15395 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
15396 SgFunctionDeclaration* target_functionDeclaration = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
15397 ROSE_ASSERT(target_functionDeclaration != NULL);
15398
15399#if DEBUG_FIND_ASSOCIATED_DECLARATION
15400 printf ("snippet: functionDeclaration = %p = %s \n",snippet_functionDeclaration,snippet_functionDeclaration->get_name().str());
15401 printf ("target: functionDeclaration = %p = %s \n",target_functionDeclaration,target_functionDeclaration->get_name().str());
15402 printf ("isDefiningDeclaration = %s \n",isDefiningDeclaration ? "true" : "false");
15403#endif
15404 if (isDefiningDeclaration == true)
15405 {
15406#if DEBUG_FIND_ASSOCIATED_DECLARATION
15407 printf ("get the defining declaration instead of the firstNondefining declaration from the function symbol \n");
15408#endif
15409 returnDeclaration = target_functionDeclaration->get_definingDeclaration();
15410 }
15411
15412 ROSE_ASSERT(snippet_functionDeclaration->get_name() == target_functionDeclaration->get_name());
15413 break;
15414 }
15415
15416 default:
15417 {
15418 printf ("Error: default reached in switch: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15419 ROSE_ABORT();
15420 }
15421 }
15422
15423 ROSE_ASSERT(returnDeclaration != NULL);
15424
15425 // These should have different global scopes, because they are from different ASTs.
15426 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,returnDeclaration) == false);
15427
15428 // return the last found symbol.
15429 // return returnSymbol;
15430 return returnDeclaration;
15431 }
15432
15433
15434SgType*
15436 {
15437 // This is the inner function to getTargetFileType()
15438 SgType* returnType = NULL;
15439
15440 ROSE_ASSERT(snippet_type != NULL);
15441 ROSE_ASSERT(targetScope != NULL);
15442
15443 // DQ (3/17/2014): Refactored code.
15444 // See if the type might be asociated with the snippet file.
15445 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
15446 // SgType* type_copy = snippet_type;
15447
15448#if 0
15449 SgType* type_copy = snippet_type;
15450 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
15451#endif
15452
15453 SgNamedType* namedType = isSgNamedType(snippet_type);
15454 if (namedType != NULL)
15455 {
15456 // Find the associated declaration and it's corresponding declaration in the target AST.
15457 SgDeclarationStatement* snippet_declaration = namedType->get_declaration();
15458 ROSE_ASSERT(snippet_declaration != NULL);
15459#if 0
15460 printf ("Need to find the declaration in the target AST that is associated with the snippet_declaration in the snippet AST \n");
15461 printf (" --- snippet_declaration = %p = %s = %s \n",snippet_declaration,snippet_declaration->class_name().c_str(),SageInterface::get_name(snippet_declaration).c_str());
15462#endif
15463 // There are only a few cases here!
15464 switch (namedType->variantT())
15465 {
15466 case V_SgClassType:
15467 {
15468 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
15469 if (classDeclaration != NULL)
15470 {
15471 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
15472 if (classSymbolInTargetAST == NULL)
15473 {
15474 // For Java or C++ this could be a name qualified type and so we need a better mechanism
15475 // to identify it thorugh it's parent scopes. Build a list of parent scope back to the
15476 // global scope and then traverse the list backwards to identify each scope in the target
15477 // AST's global scope until we each the associated declaration in the target AST.
15478#if 0
15479 printf ("This is likely a name qualified scope (which can't be seen in a simple traversal of the parent scope (case of C++ or Java) \n");
15480 printf (" --- Looking for target AST match for class name = %s \n",classDeclaration->get_name().str());
15481#endif
15482 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
15483 ROSE_ASSERT(symbol != NULL);
15484
15485 classSymbolInTargetAST = isSgClassSymbol(symbol);
15486 }
15487
15488 ROSE_ASSERT(classSymbolInTargetAST != NULL);
15489 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
15490 ROSE_ASSERT(target_classDeclaration != NULL);
15491#if 0
15492 printf ("snippet: classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
15493 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
15494#endif
15495 ROSE_ASSERT(classDeclaration->get_name() == target_classDeclaration->get_name());
15496
15497 returnType = classSymbolInTargetAST->get_type();
15498 }
15499 break;
15500 }
15501
15502 case V_SgTypedefType:
15503 {
15504 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
15505 if (typedefDeclaration != NULL)
15506 {
15507 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(typedefDeclaration->get_name(),targetScope);
15508
15509 // Not clear if we have to handle a more general case here.
15510 // ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15511 // returnType = typedefSymbolInTargetAST->get_type();
15512 if (typedefSymbolInTargetAST == NULL)
15513 {
15514#if 0
15515 printf ("Error: It is an error to not have a typedef type defined in the target AST (this is an old rule, we have to support more general rules now)! \n");
15516 printf (" --- The target AST must have a valid typedef type (and associated declaration) to support resetting the SgTypedefType: %p \n",typedefDeclaration->get_type());
15517#endif
15518 // DQ (3/16/2014): Find the associated typedef declaration (from the target AST)
15519 // for the input type associated with its declaration in the snippet AST.
15520 SgSymbol* symbol = findAssociatedSymbolInTargetAST(typedefDeclaration,targetScope);
15521 ROSE_ASSERT(symbol != NULL);
15522
15523 typedefSymbolInTargetAST = isSgTypedefSymbol(symbol);
15524
15525 // Note that test5d demonstrates this problem.
15526 // ROSE_ASSERT(false);
15527 }
15528
15529 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15530 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
15531 ROSE_ASSERT(target_typedefDeclaration != NULL);
15532#if 0
15533 printf ("snippet: typedefDeclaration = %p = %s \n",typedefDeclaration,typedefDeclaration->get_name().str());
15534 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
15535#endif
15536 ROSE_ASSERT(typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
15537
15538 returnType = typedefSymbolInTargetAST->get_type();
15539 }
15540 break;
15541 }
15542
15543 case V_SgEnumType:
15544 {
15545 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(snippet_declaration);
15546 if (enumDeclaration != NULL)
15547 {
15548 ROSE_ASSERT(enumDeclaration->get_name().is_null() == false);
15549 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(enumDeclaration->get_name(),targetScope);
15550
15551 // Not clear if we have to handle a more general case here.
15552 // ROSE_ASSERT(enumSymbolInTargetAST != NULL);
15553 // returnType = enumSymbolInTargetAST->get_type();
15554 if (enumSymbolInTargetAST == NULL)
15555 {
15556 printf ("Error: It is an error to not have a enum type defined in the target AST! \n");
15557 printf (" --- The target AST must have a valid enum type (and associated declaration) to support resetting the SgEnumType: %p \n",enumDeclaration->get_type());
15558
15559 // We will allow this to pass for now, since it is a violation of the target AST, and not the snippet mechanism (I think).
15560 returnType = snippet_type;
15561
15562 // Note that test5d demonstrates this problem.
15563 // ROSE_ASSERT(false);
15564 }
15565 else
15566 {
15567 returnType = enumSymbolInTargetAST->get_type();
15568 }
15569 }
15570
15571 break;
15572 }
15573
15574 case V_SgJavaParameterizedType:
15575 {
15576 // DQ (3/10/2014): This type is a view of a generic class with dynamic type checking (e.g. T).
15577 // This acts more like a class with reference to the template instead of the template instantiation.
15578 // So reset the declaration.
15579#if 0
15580 printf ("In getTargetFileTypeSupport(): case V_SgJavaParameterizedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15581#endif
15582#if 1
15583 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
15584 if (classDeclaration != NULL)
15585 {
15586#if 0
15587 printf ("Looking for classDeclaration = %s \n",classDeclaration->get_name().str());
15588#endif
15589 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
15590 ROSE_ASSERT(javaParameterizedType != NULL);
15591#if 0
15592 // SgTemplateParameterPtrList* templateParameterList = javaParameterizedType->get_type_list();
15593 SgTemplateParameterList* templateParameterListNode = javaParameterizedType->get_type_list();
15594 ROSE_ASSERT(templateParameterListNode != NULL);
15595 SgTemplateParameterPtrList* templateParameterList = &templateParameterListNode->get_args();
15596#else
15597 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
15598 // SgTemplateParameterPtrList* templateParameterList = NULL;
15599#endif
15600 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
15601 // SgTemplateArgumentPtrList* templateSpecializationArgumentList = NULL;
15602#if 0
15603 printf ("Calling lookupTemplateClassSymbolInParentScopes() name = %s \n",classDeclaration->get_name().str());
15604#endif
15605 // SgTemplateClassSymbol* templateClassSymbolInTargetAST = lookupTemplateClassSymbolInParentScopes(classDeclaration->get_name(),templateParameterList,templateSpecializationArgumentList,targetScope);
15606 SgClassSymbol* templateClassSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
15607#if 0
15608 printf ("DONE: Calling lookupTemplateClassSymbolInParentScopes() \n");
15609#endif
15610#if 0
15611 printf ("targetScope->get_symbol_table()->size() = %d \n",targetScope->get_symbol_table()->size());
15612 if (templateClassSymbolInTargetAST == NULL)
15613 {
15614 targetScope->get_symbol_table()->print("ERROR: templateClassSymbolInTargetAST == NULL");
15615 }
15616#endif
15617 // DQ (3/30/2014): Add this approach.
15618 if (templateClassSymbolInTargetAST == NULL)
15619 {
15620#if 0
15621 printf ("Calling findAssociatedSymbolInTargetAST \n");
15622#endif
15623 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
15624 ROSE_ASSERT(symbol != NULL);
15625
15626 templateClassSymbolInTargetAST = isSgClassSymbol(symbol);
15627
15628 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
15629 }
15630
15631 // Not clear if we have to handle a more general case here.
15632 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
15633
15634 returnType = templateClassSymbolInTargetAST->get_type();
15635 }
15636#else
15637 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
15638 if (javaParameterizedType != NULL)
15639 {
15640#error "DEAD CODE!"
15641 // Not clear how to lookup this type in the target AST.
15642 returnType = javaParameterizedType;
15643
15644 SgType* internal_type = javaParameterizedType->get_raw_type();
15645 ROSE_ASSERT(internal_type != NULL);
15646 }
15647#endif
15648#if 0
15649 printf ("SgJavaParameterizedType not yet tested! \n");
15650 ROSE_ABORT();
15651#endif
15652 break;
15653 }
15654
15655 case V_SgJavaQualifiedType:
15656 {
15657 // DQ (3/10/2014): This type acts like a binary operator on types to define aggregate
15658 // types to represent what in C++ would be name qualification. I need only set the
15659 // declarations in each SgJavaQualifiedType to refer to a declaration in the target AST.
15660 // So reset the declaration.
15661
15662 // This case is demonstrated by test code:
15663 // SS_JAVA_CWES/src/Error_Handling/CWE_248/CWE_248_0.java,Error_Handling.CWE_248.CWE_248_0.cwe_248_0
15664 // printf ("***** SgJavaQualifiedType not yet tested! *** \n");
15665
15666 printf ("In getTargetFileTypeSupport(): case V_SgJavaQualifiedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15667
15668 SgJavaQualifiedType* javaQualifiedType = isSgJavaQualifiedType(namedType);
15669 if (javaQualifiedType != NULL)
15670 {
15671 // Not clear how to lookup this type in the target AST.
15672 returnType = javaQualifiedType;
15673
15674 SgType* internal_type_1 = javaQualifiedType->get_parent_type();
15675 ROSE_ASSERT(internal_type_1 != NULL);
15676 SgType* internal_type_2 = javaQualifiedType->get_type();
15677 ROSE_ASSERT(internal_type_2 != NULL);
15678 }
15679
15680 printf ("Case of SgJavaQualifiedType: not yet handled: commented out assertion! \n");
15681 // ROSE_ASSERT(false);
15682 break;
15683 }
15684
15685 case V_SgJavaWildcardType:
15686 {
15687 // DQ (3/10/2014): This type expressed constraints on an input type.
15688 // if (?) then it is associated with the Java object type.
15689 // It can be constraint with an upper bound or lower bound.
15690 // if (?extends List) would be an upper bound for List.
15691 // if (?super Integer) would be an lower bound for List.
15692 // So reset the declaration.
15693
15694 printf ("In getTargetFileTypeSupport(): case V_SgJavaWildcardType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15695
15696 SgJavaWildcardType* javaWildcardType = isSgJavaWildcardType(namedType);
15697 if (javaWildcardType != NULL)
15698 {
15699 // Not clear how to lookup this type in the target AST.
15700 returnType = javaWildcardType;
15701 }
15702
15703 printf ("SgJavaWildcardType not yet tested! \n");
15704 ROSE_ABORT();
15705 }
15706
15707 default:
15708 {
15709 printf ("Error: In getTargetFileTypeSupport(): default reached in switch: namedType = %p = %s \n",namedType,namedType->class_name().c_str());
15710 ROSE_ABORT();
15711 }
15712 }
15713
15714 ROSE_ASSERT(returnType != NULL);
15715#if 0
15716 printf ("Exiting as a test! \n");
15717 ROSE_ABORT();
15718#endif
15719 }
15720 else
15721 {
15722 // Non-named types are shared, so we need not reset them.
15723
15724 // If this was not a named type then return NULL (which is checked at the
15725 // calling point, so that the type will not be reset).
15726 }
15727
15728 return returnType;
15729 }
15730
15731
15732SgType*
15734 {
15735 SgType* returnType = NULL;
15736
15737 ROSE_ASSERT(snippet_type != NULL);
15738 ROSE_ASSERT(targetScope != NULL);
15739
15740 // DQ (3/17/2014): Refactored code.
15741 // See if the type might be asociated with the snippet file.
15742 SgType* type_copy = snippet_type;
15743
15744#if 0
15745 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
15746#endif
15747
15748 // We need to be able to reproduce the pointer types to class types, etc.
15749 Rose_STL_Container<SgType*> typeList = type_copy->getInternalTypes();
15750
15751#if 0
15752 for (size_t i = 0; i < typeList.size(); i++)
15753 {
15754 printf ("Input type: typeList[i=%" PRIuPTR "] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
15755 }
15756#endif
15757
15758#if 1
15759 // This is the unwrapped version of the getTargetFileType() function.
15760 returnType = getTargetFileTypeSupport(snippet_type,targetScope);
15761#else
15762 SgNamedType* namedType = isSgNamedType(snippet_type);
15763
15764#error "DEAD CODE!"
15765
15766 if (namedType != NULL)
15767 {
15768 // Find the associated declaration and it's corresponding declaration in the target AST.
15769 SgDeclarationStatement* snippet_declaration = namedType->get_declaration();
15770 ROSE_ASSERT(snippet_declaration != NULL);
15771#if 0
15772 printf ("Need to find the declaration in the target AST that is associated with the snippet_declaration in the snippet AST \n");
15773 printf (" --- snippet_declaration = %p = %s = %s \n",snippet_declaration,snippet_declaration->class_name().c_str(),SageInterface::get_name(snippet_declaration).c_str());
15774#endif
15775 // There are only a few cases here!
15776 switch (namedType->variantT())
15777 {
15778 case V_SgClassType:
15779 {
15780 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
15781 if (classDeclaration != NULL)
15782 {
15783 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
15784 if (classSymbolInTargetAST == NULL)
15785 {
15786 // For Java or C++ this could be a name qualified type and so we need a better mechanism
15787 // to identify it thorugh it's parent scopes. Build a list of parent scope back to the
15788 // global scope and then traverse the list backwards to identify each scope in the target
15789 // AST's global scope until we each the associated declaration in the target AST.
15790#if 0
15791 printf ("This is likely a name qualified scope (which can't be seen in a simple traversal of the parent scope (case of C++ or Java) \n");
15792 printf (" --- Looking for target AST match for class name = %s \n",classDeclaration->get_name().str());
15793#endif
15794 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
15795 ROSE_ASSERT(symbol != NULL);
15796
15797 classSymbolInTargetAST = isSgClassSymbol(symbol);
15798 }
15799
15800 ROSE_ASSERT(classSymbolInTargetAST != NULL);
15801 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
15802 ROSE_ASSERT(target_classDeclaration != NULL);
15803#if 0
15804 printf ("snippet: classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
15805 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
15806#endif
15807 ROSE_ASSERT(classDeclaration->get_name() == target_classDeclaration->get_name());
15808
15809 returnType = classSymbolInTargetAST->get_type();
15810 }
15811 break;
15812 }
15813
15814 case V_SgTypedefType:
15815 {
15816 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
15817 if (typedefDeclaration != NULL)
15818 {
15819 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(typedefDeclaration->get_name(),targetScope);
15820
15821 // Not clear if we have to handle a more general case here.
15822 // ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15823 // returnType = typedefSymbolInTargetAST->get_type();
15824 if (typedefSymbolInTargetAST == NULL)
15825 {
15826#if 0
15827 printf ("Error: It is an error to not have a typedef type defined in the target AST (this is an old rule, we have to support more general rules now)! \n");
15828 printf (" --- The target AST must have a valid typedef type (and associated declaration) to support resetting the SgTypedefType: %p \n",typedefDeclaration->get_type());
15829#endif
15830 // DQ (3/16/2014): Find the associated typedef declaration (from the target AST)
15831 // for the input type associated with its declaration in the snippet AST.
15832 SgSymbol* symbol = findAssociatedSymbolInTargetAST(typedefDeclaration,targetScope);
15833 ROSE_ASSERT(symbol != NULL);
15834
15835 typedefSymbolInTargetAST = isSgTypedefSymbol(symbol);
15836
15837 // Note that test5d demonstrates this problem.
15838 // ROSE_ASSERT(false);
15839 }
15840
15841 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15842 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
15843 ROSE_ASSERT(target_typedefDeclaration != NULL);
15844#if 0
15845 printf ("snippet: typedefDeclaration = %p = %s \n",typedefDeclaration,typedefDeclaration->get_name().str());
15846 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
15847#endif
15848 ROSE_ASSERT(typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
15849
15850 returnType = typedefSymbolInTargetAST->get_type();
15851 }
15852 break;
15853 }
15854
15855 case V_SgEnumType:
15856 {
15857 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(snippet_declaration);
15858 if (enumDeclaration != NULL)
15859 {
15860 ROSE_ASSERT(enumDeclaration->get_name().is_null() == false);
15861 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(enumDeclaration->get_name(),targetScope);
15862
15863 // Not clear if we have to handle a more general case here.
15864 // ROSE_ASSERT(enumSymbolInTargetAST != NULL);
15865 // returnType = enumSymbolInTargetAST->get_type();
15866 if (enumSymbolInTargetAST == NULL)
15867 {
15868 printf ("Error: It is an error to not have a enum type defined in the target AST! \n");
15869 printf (" --- The target AST must have a valid enum type (and associated declaration) to support resetting the SgEnumType: %p \n",enumDeclaration->get_type());
15870
15871 // We will allow this to pass for now, since it is a violation of the target AST, and not the snippet mechanism (I think).
15872 returnType = snippet_type;
15873
15874 // Note that test5d demonstrates this problem.
15875 // ROSE_ASSERT(false);
15876 }
15877 else
15878 {
15879 returnType = enumSymbolInTargetAST->get_type();
15880 }
15881 }
15882
15883 break;
15884 }
15885
15886 case V_SgJavaParameterizedType:
15887 {
15888 // DQ (3/10/2014): This type is a view of a generic class with dynamic type checking (e.g. T).
15889 // This acts more like a class with reference to the template instead of the template instantiation.
15890 // So reset the declaration.
15891
15892 printf ("In getTargetFileType(): case V_SgJavaParameterizedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15893#if 1
15894 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
15895 if (classDeclaration != NULL)
15896 {
15897 SgTemplateParameterPtrList* templateParameterList = NULL;
15898 SgTemplateArgumentPtrList* templateSpecializationArgumentList = NULL;
15899 SgTemplateClassSymbol* templateClassSymbolInTargetAST = lookupTemplateClassSymbolInParentScopes(classDeclaration->get_name(),templateParameterList,templateSpecializationArgumentList,targetScope);
15900
15901 // Not clear if we have to handle a more general case here.
15902 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
15903
15904 returnType = templateClassSymbolInTargetAST->get_type();
15905 }
15906#else
15907 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
15908 if (javaParameterizedType != NULL)
15909 {
15910 // Not clear how to lookup this type in the target AST.
15911 returnType = javaParameterizedType;
15912
15913 SgType* internal_type = javaParameterizedType->get_raw_type();
15914 ROSE_ASSERT(internal_type != NULL);
15915 }
15916#endif
15917 printf ("SgJavaParameterizedType not yet tested! \n");
15918 ROSE_ABORT();
15919 }
15920
15921 case V_SgJavaQualifiedType:
15922 {
15923 // DQ (3/10/2014): This type acts like a binary operator on types to define aggregate
15924 // types to represent what in C++ would be name qualification. I need only set the
15925 // declarations in each SgJavaQualifiedType to refer to a declaration in the target AST.
15926 // So reset the declaration.
15927
15928 printf ("In getTargetFileType(): case V_SgJavaQualifiedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15929
15930 SgJavaQualifiedType* javaQualifiedType = isSgJavaQualifiedType(namedType);
15931 if (javaQualifiedType != NULL)
15932 {
15933 // Not clear how to lookup this type in the target AST.
15934 returnType = javaQualifiedType;
15935
15936 SgType* internal_type_1 = javaQualifiedType->get_parent_type();
15937 ROSE_ASSERT(internal_type_1 != NULL);
15938 SgType* internal_type_2 = javaQualifiedType->get_type();
15939 ROSE_ASSERT(internal_type_2 != NULL);
15940 }
15941
15942 printf ("SgJavaQualifiedType not yet tested! \n");
15943 ROSE_ABORT();
15944 }
15945
15946 case V_SgJavaWildcardType:
15947 {
15948 // DQ (3/10/2014): This type expressed constraints on an input type.
15949 // if (?) then it is associated with the Java object type.
15950 // It can be constraint with an upper bound or lower bound.
15951 // if (?extends List) would be an upper bound for List.
15952 // if (?super Integer) would be an lower bound for List.
15953 // So reset the declaration.
15954
15955 printf ("In getTargetFileType(): case V_SgJavaWildcardType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15956
15957 SgJavaWildcardType* javaWildcardType = isSgJavaWildcardType(namedType);
15958 if (javaWildcardType != NULL)
15959 {
15960 // Not clear how to lookup this type in the target AST.
15961 returnType = javaWildcardType;
15962
15963 SgType* internal_type_1 = javaWildcardType->get_bound_type();
15964 // ROSE_ASSERT(internal_type_1 != NULL); // PC: 03/15/2014 - Dan, this cannot be asserted as the bound_type CAN BE NULL.
15965 }
15966
15967 printf ("SgJavaWildcardType not yet tested! \n");
15968 ROSE_ABORT();
15969 }
15970
15971 default:
15972 {
15973 printf ("Error: In getTargetFileType(): default reached in switch: namedType = %p = %s \n",namedType,namedType->class_name().c_str());
15974 ROSE_ABORT();
15975 }
15976 }
15977
15978 ROSE_ASSERT(returnType != NULL);
15979#if 0
15980 printf ("Exiting as a test! \n");
15981 ROSE_ABORT();
15982#endif
15983 }
15984 else
15985 {
15986 // Non-named types are shared, so we need not reset them.
15987
15988 // If this was not a named type then return NULL (which is checked at the
15989 // calling point, so that the type will not be reset).
15990 }
15991#endif
15992
15993 SgType* new_type = returnType;
15994
15995 // DQ (3/17/2014): Refactored code.
15996 // Now rebuild the type_copy as required to represent associated modifiers, typedef wrappers, pointers and references.
15997 if (new_type != NULL && typeList.size() > 1)
15998 {
15999 int size = (int)typeList.size();
16000 for (int i = size - 2; i >= 0; i--)
16001 {
16002#if 0
16003 printf ("Rebuild type: typeList[i=%d] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
16004#endif
16005 // SgModifierType* SgModifierType::createType(SgType* base_type, unsigned int f, SgExpression* optional_fortran_type_kind )
16006 switch(typeList[i]->variantT())
16007 {
16008 case V_SgModifierType:
16009 {
16010 SgModifierType* modifierType = isSgModifierType(typeList[i]);
16011 ROSE_ASSERT(modifierType != NULL);
16012 if (modifierType->get_typeModifier().get_constVolatileModifier().isConst() == true)
16013 {
16014 ROSE_ASSERT(new_type != NULL);
16015#if 0
16016 printf ("Building a SgModifierType: calling buildConstType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16017#endif
16018 new_type = buildConstType(new_type);
16019 }
16020 else
16021 {
16022 // Flag any additional modifiers that we might require (make anything not supported an error).
16023 printf ("Modifier kind not handled (not implemented) check what sort of modifier this is: \n");
16024 modifierType->get_typeModifier().display("Modifier kind not handled");
16025 ROSE_ABORT();
16026 }
16027 break;
16028 }
16029
16030 case V_SgTypedefType:
16031 {
16032 SgTypedefType* typedefType = isSgTypedefType(typeList[i]);
16033 ROSE_ASSERT(typedefType != NULL);
16034
16035 // DQ (3/17/2014): Call the associated support function instead.
16036 // SgType* SageBuilder::getTargetFileType(SgType* snippet_type, SgScopeStatement* targetScope)
16037 // SgType* new_typedefType = getTargetFileType(typedefType,targetScope);
16038 SgType* new_typedefType = getTargetFileTypeSupport(typedefType,targetScope);
16039 ROSE_ASSERT(new_typedefType != NULL);
16040 ROSE_ASSERT(isSgTypedefType(new_typedefType) != NULL);
16041
16042 new_type = new_typedefType;
16043#if 0
16044 printf ("ERROSE: SgTypedefType kind not handled (not implemented) \n");
16045 ROSE_ABORT();
16046#endif
16047 break;
16048 }
16049
16050 case V_SgPointerType:
16051 {
16052 SgPointerType* pointerType = isSgPointerType(typeList[i]);
16053 ROSE_ASSERT(pointerType != NULL);
16054#if 0
16055 printf ("Building a SgPointerType: calling buildPointerType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16056#endif
16057 ROSE_ASSERT(new_type != NULL);
16058 new_type = buildPointerType(new_type);
16059#if 0
16060 printf ("ERROSE: SgPointerType kind not handled (not implemented) \n");
16061 ROSE_ABORT();
16062#endif
16063 break;
16064 }
16065
16066 default:
16067 {
16068 printf ("Error: default reached in evaluation of typelist: typeList[i] = %p = %s \n",typeList[i],typeList[i]->class_name().c_str());
16069 ROSE_ABORT();
16070 }
16071 }
16072 }
16073
16074 returnType = new_type;
16075 }
16076
16077#if 0
16078 if (typeList.size() > 1)
16079 {
16080 printf ("Exiting as a test! \n");
16081 ROSE_ABORT();
16082 }
16083#endif
16084
16085
16086 return returnType;
16087 }
16088
16089
16090
16091void
16092SageBuilder::errorCheckingTargetAST (SgNode* node_copy, SgNode* node_original, SgFile* targetFile, bool failOnWarning )
16093 {
16094#if 0
16095 printf ("In errorCheckingTargetAST(): node_copy = %p = %s node_original = %p = %s \n",node_copy,node_copy->class_name().c_str(),node_original,node_original->class_name().c_str());
16096#endif
16097
16098 // Handle what is the same about all statements before getting to the switch.
16099 SgStatement* statement_copy = isSgStatement(node_copy);
16100 SgStatement* statement_original = isSgStatement(node_original);
16101 if (statement_copy != NULL)
16102 {
16103 // Check the scope if it is stored explicitly.
16104 if (statement_copy->hasExplicitScope() == true)
16105 {
16106 // Handle the scope for all statements.
16107 SgScopeStatement* scope_copy = statement_copy->get_scope();
16108 ROSE_ASSERT(statement_original != NULL);
16109 SgScopeStatement* scope_original = statement_original->get_scope();
16110 ROSE_ASSERT(scope_copy != NULL);
16111 ROSE_ASSERT(scope_original != NULL);
16112
16113 // if (TransformationSupport::getFile(scope_original) != targetFile)
16114 // if (getEnclosingFileNode(scope_original) != targetFile)
16115 if (getEnclosingFileNode(scope_copy) != targetFile)
16116 {
16117#if 0
16118 printf ("Warning: SgStatement: scope = %p = %s \n",scope_original,scope_original->class_name().c_str());
16119#endif
16120 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
16121 // SgFile* snippetFile = getEnclosingFileNode(scope_original);
16122 SgFile* snippetFile = getEnclosingFileNode(scope_copy);
16123 ROSE_ASSERT(snippetFile != NULL);
16124 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16125#if 1
16126 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16127 // ROSE_ASSERT(false);
16128#endif
16129 if (failOnWarning == true)
16130 {
16131 printf ("Exit on warning! \n");
16132 ROSE_ABORT();
16133 }
16134 }
16135#if 0
16136 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
16137 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
16138
16139 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
16140 // ROSE_ASSERT(targetScope != NULL);
16141
16142 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16143 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16144 // SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol->get_name(),targetScope);
16145 // ROSE_ASSERT(variableSymbolInTargetAST != NULL);
16146
16147 // Unless we know that this is a declaration we can't set the scope here using the information about this being a definng declaration.
16148 // If this is a defining declaration then we want to set it's scope to targetScope, else we want to lookup
16149 // the symbol through the parent scope and set the scope using the symbol's first non-defining declaration.
16150 // statement_copy->set_scope(targetScope);
16151
16152 // SgSymbol* symbol = statement_copy->search_for_symbol_from_symbol_table();
16153 // ROSE_ASSERT(symbol != NULL);
16154#endif
16155#if 0
16156 printf ("SgClassDeclaration: Exiting as a test! \n");
16157 ROSE_ABORT();
16158#endif
16159#if 0
16160 if (TransformationSupport::getFile(scope) != targetFile)
16161 {
16162 printf ("Warning: SgStatement: scope = %p = %s \n",scope,scope->class_name().c_str());
16163 SgFile* snippetFile = TransformationSupport::getFile(scope);
16164 ROSE_ASSERT(snippetFile != NULL);
16165 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16166
16167 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16168 // ROSE_ASSERT(false);
16169 }
16170#endif
16171 }
16172 }
16173
16174 // Handle what is the same about all declaration before getting to the switch.
16175 SgDeclarationStatement* declarationStatement_copy = isSgDeclarationStatement(node_copy);
16176 SgDeclarationStatement* declarationStatement_original = isSgDeclarationStatement(node_original);
16177 if (declarationStatement_copy != NULL)
16178 {
16179 // Check the firstnondefiningDeclaration and definingDeclaration
16180 SgDeclarationStatement* firstNondefiningDeclaration_copy = declarationStatement_copy->get_firstNondefiningDeclaration();
16181 SgDeclarationStatement* firstNondefiningDeclaration_original = declarationStatement_original->get_firstNondefiningDeclaration();
16182
16183 // DQ (3/17/2014): Bugfix, we want to use the firstNondefiningDeclaration_copy instead of firstNondefiningDeclaration_original.
16184 // DQ (3/10/2014): We want to allow for NULL return values from getEnclosingFileNode() for Java classes that are in java.lang (for example).
16185 // SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_original);
16186 SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_copy);
16187 if (snippetFile != NULL && snippetFile != targetFile)
16188 {
16189 // I think we want to allow this because it is a common occurence in any merged AST.
16190 // However, if might be worth fixing for other reasons. This needs to be discussed.
16191#if 0
16192 printf ("Note: SgDeclarationStatement: firstNondefiningDeclaration_original is not in target file (allowed for merged ASTs) \n");
16193#endif
16194 // ROSE_ASSERT(false);
16195 if (failOnWarning == true)
16196 {
16197 printf ("Exit on warning! \n");
16198 ROSE_ABORT();
16199 }
16200 }
16201 else
16202 {
16203 // Warn about this if snippetFile == NULL.
16204 if (snippetFile == NULL)
16205 {
16206 printf ("Note: firstNondefiningDeclaration_original = %p getEnclosingFileNode() returned NULL \n",firstNondefiningDeclaration_original);
16207
16208 if (failOnWarning == true)
16209 {
16210 printf ("Exit on warning! \n");
16211 ROSE_ABORT();
16212 }
16213 }
16214 }
16215
16216 SgDeclarationStatement* definingDeclaration_copy = declarationStatement_copy->get_definingDeclaration();
16217 SgDeclarationStatement* definingDeclaration_original = declarationStatement_original->get_definingDeclaration();
16218 if (definingDeclaration_original != NULL)
16219 {
16220 // DQ (3/17/2014): Bugfix, we want to use the definingDeclaration_copy instead of definingDeclaration_original.
16221 // if (TransformationSupport::getFile(definingDeclaration_original) != targetFile)
16222 // if (getEnclosingFileNode(definingDeclaration_original) != targetFile)
16223 // SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_original);
16224 SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_copy);
16225 if (snippetFile != NULL && snippetFile != targetFile)
16226 {
16227#if 1
16228 printf ("Warning: SgDeclarationStatement: definingDeclaration is not in target file \n");
16229 // ROSE_ASSERT(false);
16230#endif
16231 if (failOnWarning == true)
16232 {
16233 printf ("Exit on warning! \n");
16234 ROSE_ABORT();
16235 }
16236
16237 if (declarationStatement_original == definingDeclaration_original)
16238 {
16239 // This is a defining declaration, so we can set the scope (or can we?)
16240 // I guess we could if the translation map were complete, but it is not complete yet.
16241 }
16242 }
16243 else
16244 {
16245 // Warn about this if snippetFile == NULL.
16246 if (snippetFile == NULL)
16247 {
16248 printf ("Note: definingDeclaration_original = %p getEnclosingFileNode() returned NULL \n",definingDeclaration_original);
16249
16250 if (failOnWarning == true)
16251 {
16252 printf ("Exit on warning! \n");
16253 ROSE_ABORT();
16254 }
16255 }
16256 }
16257 }
16258 }
16259
16260 // Handle what is the same about all expressions before getting to the switch.
16261 SgExpression* expression = isSgExpression(node_copy);
16262 if (expression != NULL)
16263 {
16264 // Check the scope if it is stored explicitly.
16265
16266 // printf ("WARNING: Need to check if the type is explicitly stored in this expression! \n");
16267
16268 if (expression->hasExplicitType() == true)
16269 {
16270 // Handle the type for all expressions.
16271 SgType* type = expression->get_type();
16272 ROSE_ASSERT(type != NULL);
16273 }
16274 }
16275
16276#if 0
16277 printf ("Leaving errorCheckingTargetAST() \n");
16278#endif
16279 }
16280
16281
16282template <class T>
16283void
16284SageBuilder::resetDeclaration(T* classDeclaration_copy, T* classDeclaration_original, SgScopeStatement* targetScope)
16285 {
16286 // I'm not sure if this function is a good idea since we can't call set_scope() easily from any
16287 // SgDeclarationStatement and I don't want to make set_scope() a virtual function because it would
16288 // not make sense everywhere.
16289
16290 // DQ (3/17/2014): This code is similar to the case for SgEnumDeclaration (later we can refactor this if this works well).
16291 T* classDeclaration_copy_defining = dynamic_cast<T*>(classDeclaration_copy->get_definingDeclaration());
16292 T* classDeclaration_copy_nondefining = dynamic_cast<T*>(classDeclaration_copy->get_firstNondefiningDeclaration());
16293 T* classDeclaration_original_defining = dynamic_cast<T*>(classDeclaration_original->get_definingDeclaration());
16294 T* classDeclaration_original_nondefining = dynamic_cast<T*>(classDeclaration_original->get_firstNondefiningDeclaration());
16295
16296 // Set the scope if it is still set to the scope of the snippet AST.
16297 if (classDeclaration_copy_defining != NULL && classDeclaration_copy_defining->get_scope() == classDeclaration_original_defining->get_scope())
16298 {
16299#if 0
16300 printf ("reset the scope of classDeclaration_copy_defining \n");
16301#endif
16302 classDeclaration_copy_defining->set_scope(targetScope);
16303 }
16304
16305 // Set the scope if it is still set to the scope of the snippet AST.
16306 if (classDeclaration_copy_nondefining != NULL && classDeclaration_copy_nondefining->get_scope() == classDeclaration_original_nondefining->get_scope())
16307 {
16308#if 0
16309 printf ("reset the scope of classDeclaration_copy_nondefining \n");
16310#endif
16311 classDeclaration_copy_nondefining->set_scope(targetScope);
16312 }
16313
16314 // Set the parent if it is still set to a node of the snippet AST.
16315 if (classDeclaration_copy_nondefining != NULL && classDeclaration_copy_nondefining->get_parent() == classDeclaration_original_nondefining->get_parent())
16316 {
16317#if 0
16318 printf ("reset the parent of classDeclaration_copy_nondefining \n");
16319#endif
16320 classDeclaration_copy_nondefining->set_parent(classDeclaration_copy->get_parent());
16321 }
16322 }
16323
16324
16325void
16327 SgNode* node_copy, SgNode* node_original)
16328 {
16329 // This function fixes up invidual IR nodes to be consistant in the context of the target AST
16330 // where the node is inserted and at the point specified by insertionPoint. In this function,
16331 // node_copy is the copy that was made of node_original by the AST copy function. The node_original
16332 // is assumed to be the node that is in the AST snippet (it is still connected in the snippet's
16333 // AST (from compilation of the snippet file).
16334
16335 // This function hides the details of handling each different type of IR node.
16336 // It is assume that the node_copy is from an AST sub-tree generated by the AST copy mechanism,
16337 // and that the insertionPoint is a location in the target AST where the snippet AST has already
16338 // been inserted, this function makes each IR node internally consistant with the target AST.
16339
16340 // BTW, the translationMap should only be required to support references to things that are name
16341 // qualified (which are C++ specific). These are a performance option to simplify tacking back
16342 // through scopes with code similarly complex as to what is supported in the name qualification
16343 // support.
16344#if 0
16345 printf ("In fixupCopyOfNodeFromSeperateFileInNewTargetAst: node_copy = %p = %s \n",node_copy,node_copy->class_name().c_str());
16346#endif
16347
16348#if 0
16349 printf ("Disabled fixupCopyOfNodeFromSeperateFileInNewTargetAst() \n");
16350 return;
16351#endif
16352
16353 // SgFile* targetFile = TransformationSupport::getFile(insertionPoint);
16354 SgFile* targetFile = getEnclosingFileNode(insertionPoint);
16355
16356#if 0
16357 printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
16358 printf (" --- insertionPointIsScope = %s \n",insertionPointIsScope ? "true" : "false");
16359#endif
16360
16361 // DQ (3/4/2014): As I recall there is a reason why we can't setup the scope here.
16362
16363 // We also need to handle the symbol (move it from the body (SgBaicBlock) that was
16364 // a copy to the scope in the target AST where the SgInitializedName was inserted).
16365 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
16366#if 0
16367 printf ("insertionPointScope = %p = %s \n",insertionPointScope,insertionPointScope->class_name().c_str());
16368#endif
16369 SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
16370 ROSE_ASSERT(targetScope != NULL);
16371
16372#if 1
16373 // Refactored code (error checking done after AST fixup).
16374#if 0
16375 errorCheckingTargetAST(node_copy,node_original,targetFile, false);
16376#endif
16377#else
16378
16379#error "DEAD CODE!"
16380
16381 // Handle what is the same about all statements before getting to the switch.
16382 SgStatement* statement_copy = isSgStatement(node_copy);
16383 SgStatement* statement_original = isSgStatement(node_original);
16384 if (statement_copy != NULL)
16385 {
16386 // Check the scope if it is stored explicitly.
16387 if (statement_copy->hasExplicitScope() == true)
16388 {
16389 // Handle the scope for all statements.
16390 SgScopeStatement* scope_copy = statement_copy->get_scope();
16391 SgScopeStatement* scope_original = statement_original->get_scope();
16392 ROSE_ASSERT(scope_copy != NULL);
16393 ROSE_ASSERT(scope_original != NULL);
16394
16395 // if (TransformationSupport::getFile(scope_original) != targetFile)
16396 if (getEnclosingFileNode(scope_original) != targetFile)
16397 {
16398#if 0
16399 printf ("Warning: SgStatement: scope = %p = %s \n",scope_original,scope_original->class_name().c_str());
16400#endif
16401 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
16402 SgFile* snippetFile = getEnclosingFileNode(scope_original);
16403 ROSE_ASSERT(snippetFile != NULL);
16404 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16405#if 0
16406 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16407 // ROSE_ASSERT(false);
16408#endif
16409 }
16410#if 0
16411 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
16412 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
16413
16414 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
16415 // ROSE_ASSERT(targetScope != NULL);
16416
16417 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16418 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16419 // SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol->get_name(),targetScope);
16420 // ROSE_ASSERT(variableSymbolInTargetAST != NULL);
16421
16422 // Unless we know that this is a declaration we can't set the scope here using the information about this being a definng declaration.
16423 // If this is a defining declaration then we want to set it's scope to targetScope, else we want to lookup
16424 // the symbol through the parent scope and set the scope using the symbol's first non-defining declaration.
16425 // statement_copy->set_scope(targetScope);
16426
16427 // SgSymbol* symbol = statement_copy->search_for_symbol_from_symbol_table();
16428 // ROSE_ASSERT(symbol != NULL);
16429#endif
16430#if 0
16431 printf ("SgClassDeclaration: Exiting as a test! \n");
16432 ROSE_ABORT();
16433#endif
16434#if 0
16435 if (TransformationSupport::getFile(scope) != targetFile)
16436 {
16437 printf ("Warning: SgStatement: scope = %p = %s \n",scope,scope->class_name().c_str());
16438 SgFile* snippetFile = TransformationSupport::getFile(scope);
16439 ROSE_ASSERT(snippetFile != NULL);
16440 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16441
16442 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16443 // ROSE_ASSERT(false);
16444 }
16445#endif
16446 }
16447 }
16448
16449#error "DEAD CODE!"
16450
16451 // Handle what is the same about all declaration before getting to the switch.
16452 SgDeclarationStatement* declarationStatement_copy = isSgDeclarationStatement(node_copy);
16453 SgDeclarationStatement* declarationStatement_original = isSgDeclarationStatement(node_original);
16454 if (declarationStatement_copy != NULL)
16455 {
16456 // Check the firstnondefiningDeclaration and definingDeclaration
16457 SgDeclarationStatement* firstNondefiningDeclaration_original = declarationStatement_original->get_firstNondefiningDeclaration();
16458
16459 // DQ (3/10/2014): We want to allow for NULL return values from getEnclosingFileNode() for Java classes that are in java.lang (for example).
16460 SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_original);
16461 if (snippetFile != NULL && snippetFile != targetFile)
16462 {
16463 // I think we want to allow this because it is a common occurence in any merged AST.
16464 // However, if might be worth fixing for other reasons. This needs to be discussed.
16465#if 0
16466 printf ("Note: SgDeclarationStatement: firstNondefiningDeclaration_original is not in target file (allowed for merged ASTs) \n");
16467#endif
16468 // ROSE_ASSERT(false);
16469 }
16470 else
16471 {
16472 // Warn about this if snippetFile == NULL.
16473 if (snippetFile == NULL)
16474 {
16475 printf ("Note: firstNondefiningDeclaration_original = %p getEnclosingFileNode() returned NULL \n",firstNondefiningDeclaration_original);
16476 }
16477 }
16478
16479#error "DEAD CODE!"
16480
16481 SgDeclarationStatement* definingDeclaration_original = declarationStatement_original->get_definingDeclaration();
16482 if (definingDeclaration_original != NULL)
16483 {
16484 // if (TransformationSupport::getFile(definingDeclaration_original) != targetFile)
16485 // if (getEnclosingFileNode(definingDeclaration_original) != targetFile)
16486 SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_original);
16487 if (snippetFile != NULL && snippetFile != targetFile)
16488 {
16489#if 0
16490 printf ("Warning: SgDeclarationStatement: definingDeclaration is not in target file \n");
16491 // ROSE_ASSERT(false);
16492#endif
16493 if (declarationStatement_original == definingDeclaration_original)
16494 {
16495 // This is a defining declaration, so we can set the scope (or can we?)
16496 // I guess we could if the translation map were complete, but it is not complete yet.
16497 }
16498 }
16499 else
16500 {
16501 // Warn about this if snippetFile == NULL.
16502 if (snippetFile == NULL)
16503 {
16504 printf ("Note: definingDeclaration_original = %p getEnclosingFileNode() returned NULL \n",definingDeclaration_original);
16505 }
16506 }
16507 }
16508 }
16509
16510#error "DEAD CODE!"
16511
16512#endif
16513
16514 // Handle what is the same about all expressions before getting to the switch.
16515 SgExpression* expression = isSgExpression(node_copy);
16516 if (expression != NULL)
16517 {
16518 // Check the scope if it is stored explicitly.
16519
16520 // printf ("WARNING: Need to check if the type is explicitly stored in this expression! \n");
16521
16522 if (expression->hasExplicitType() == true)
16523 {
16524 // Handle the type for all expressions.
16525 SgType* type = expression->get_type();
16526 ROSE_ASSERT(type != NULL);
16527
16528 // DQ (3/17/2014): Avoid calling stripType with the newly refactored getTargetFileType() function.
16529 // SgType* new_type = getTargetFileType(type->stripType(),targetScope);
16530 SgType* new_type = getTargetFileType(type,targetScope);
16531 if (new_type != NULL)
16532 {
16533 // Reset the base type to be the one associated with the target file.
16534 expression->set_explicitly_stored_type(new_type);
16535 }
16536 }
16537 }
16538
16539 switch (node_copy->variantT())
16540 {
16541 case V_SgInitializedName:
16542 {
16543 SgInitializedName* initializedName_copy = isSgInitializedName(node_copy);
16544 SgInitializedName* initializedName_original = isSgInitializedName(node_original);
16545
16546 // See if the scope might be associated with the snippet file.
16547
16548 // Since we don't want the scope that is stored in the SgInitializedName we
16549 // have to get the associated statement and the scope of that statement.
16550 // SgScopeStatement* scope_copy = initializedName_copy->get_scope();
16551 SgStatement* enclosingStatement_copy = TransformationSupport::getStatement(initializedName_copy);
16552#if 0
16553 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
16554#endif
16555 SgScopeStatement* scope_copy = enclosingStatement_copy->get_scope();
16556
16557 SgScopeStatement* scope_original = initializedName_original->get_scope();
16558
16559 ROSE_ASSERT(scope_copy != NULL);
16560 ROSE_ASSERT(scope_original != NULL);
16561
16562 // if (TransformationSupport::getFile(scope_original) != targetFile)
16563 if (getEnclosingFileNode(scope_original) != targetFile)
16564 {
16565#if 0
16566 ROSE_ASSERT(initializedName_copy != NULL);
16567 printf ("initializedName_copy = %p = %s \n",initializedName_copy,initializedName_copy->get_name().str());
16568 ROSE_ASSERT(initializedName_original != NULL);
16569 printf ("initializedName_original = %p = %s \n",initializedName_original,initializedName_original->get_name().str());
16570 SgType* initializedName_original_type = initializedName_original->get_type();
16571 printf ("initializedName_original_type = %p = %s \n",initializedName_original_type,initializedName_original_type->class_name().c_str());
16572 SgClassType* classType = isSgClassType(initializedName_original_type);
16573 // ROSE_ASSERT(classType != NULL);
16574 if (classType != NULL)
16575 {
16576 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
16577 ROSE_ASSERT(classDeclaration != NULL);
16578 printf ("classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
16579 }
16580#endif
16581#if 0
16582 printf ("Warning: case V_SgInitializedName: scope_copy = %p = %s \n",scope_copy,scope_copy->class_name().c_str());
16583 printf ("Warning: case V_SgInitializedName: scope_original = %p = %s \n",scope_original,scope_original->class_name().c_str());
16584
16585 printf ("Warning: case V_SgInitializedName: initializedName_copy->get_parent() = %p \n",initializedName_copy->get_parent());
16586 printf ("Warning: case V_SgInitializedName: initializedName_original->get_parent() = %p \n",initializedName_original->get_parent());
16587#endif
16588 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
16589 SgFile* snippetFile = getEnclosingFileNode(scope_original);
16590
16591 ROSE_ASSERT(snippetFile != NULL);
16592 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16593#if 0
16594 printf ("Warning: case V_SgInitializedName: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16595 // ROSE_ASSERT(false);
16596#endif
16597 }
16598
16599 // See if the type might be asociated with the snippet file.
16600 SgType* type_copy = initializedName_copy->get_type();
16601#if 0
16602 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
16603#endif
16604
16605#if 0
16606
16607#error "DEAD CODE!"
16608
16609 // We need to be able to reproduce the pointer types to class types, etc.
16610 Rose_STL_Container<SgType*> typeList = type_copy->getInternalTypes();
16611#if 0
16612 for (size_t i = 0; i < typeList.size(); i++)
16613 {
16614 printf ("Input type: typeList[i=%" PRIuPTR "] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
16615 }
16616#endif
16617 // Note that the semantics of this function is that it can return a NULL pointer (e.g. for primative types).
16618 SgType* new_type = getTargetFileType(type_copy->stripType(),targetScope);
16619
16620#error "DEAD CODE!"
16621
16622 // Now rebuild the type_copy as required to represent associated modifiers, typedef wrappers, pointers and references.
16623 if (new_type != NULL && typeList.size() > 1)
16624 {
16625 int size = (int)typeList.size();
16626 for (int i = size - 2; i >= 0; i--)
16627 {
16628#if 0
16629 printf ("Rebuild type: typeList[i=%d] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
16630#endif
16631 // SgModifierType* SgModifierType::createType(SgType* base_type, unsigned int f, SgExpression* optional_fortran_type_kind )
16632 switch(typeList[i]->variantT())
16633 {
16634 case V_SgModifierType:
16635 {
16636 SgModifierType* modifierType = isSgModifierType(typeList[i]);
16637 ROSE_ASSERT(modifierType != NULL);
16638 if (modifierType->get_typeModifier().get_constVolatileModifier().isConst() == true)
16639 {
16640 ROSE_ASSERT(new_type != NULL);
16641#if 0
16642 printf ("Building a SgModifierType: calling buildConstType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16643#endif
16644 new_type = buildConstType(new_type);
16645 }
16646 else
16647 {
16648 // Flag any additional modifiers that we might require (make anything not supported an error).
16649 printf ("Modifier kind not handled (not implemented) check what sort of modifier this is: \n");
16650 modifierType->get_typeModifier().display("Modifier kind not handled");
16651 ROSE_ABORT();
16652 }
16653 break;
16654 }
16655
16656#error "DEAD CODE!"
16657
16658 case V_SgTypedefType:
16659 {
16660 SgTypedefType* typedefType = isSgTypedefType(typeList[i]);
16661 ROSE_ASSERT(typedefType != NULL);
16662
16663 // SgType* SageBuilder::getTargetFileType(SgType* snippet_type, SgScopeStatement* targetScope)
16664 SgType* new_typedefType = getTargetFileType(typedefType,targetScope);
16665 ROSE_ASSERT(new_typedefType != NULL);
16666 ROSE_ASSERT(isSgTypedefType(new_typedefType) != NULL);
16667
16668 new_type = new_typedefType;
16669#if 0
16670 printf ("ERROSE: SgTypedefType kind not handled (not implemented) \n");
16671 ROSE_ABORT();
16672#endif
16673 break;
16674 }
16675
16676#error "DEAD CODE!"
16677
16678 case V_SgPointerType:
16679 {
16680 SgPointerType* pointerType = isSgPointerType(typeList[i]);
16681 ROSE_ASSERT(pointerType != NULL);
16682#if 0
16683 printf ("Building a SgPointerType: calling buildPointerType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16684#endif
16685 ROSE_ASSERT(new_type != NULL);
16686 new_type = buildPointerType(new_type);
16687#if 0
16688 printf ("ERROSE: SgPointerType kind not handled (not implemented) \n");
16689 ROSE_ABORT();
16690#endif
16691 break;
16692 }
16693
16694#error "DEAD CODE!"
16695
16696 default:
16697 {
16698 printf ("Error: default reached in evaluation of typelist: typeList[i] = %p = %s \n",typeList[i],typeList[i]->class_name().c_str());
16699 ROSE_ABORT();
16700 }
16701 }
16702 }
16703 }
16704#if 0
16705 if (typeList.size() > 1)
16706 {
16707 printf ("Exiting as a test! \n");
16708 ROSE_ABORT();
16709 }
16710#endif
16711
16712#error "DEAD CODE!"
16713
16714#else
16715 // Refactored the above code to be a part of getTargetFileType() function.
16716 // Note that the semantics of this function is that it can return a NULL pointer (e.g. for primative types).
16717 // SgType* new_type = getTargetFileType(type_copy->stripType(),targetScope);
16718 SgType* new_type = getTargetFileType(type_copy,targetScope);
16719#endif
16720#if 0
16721 printf ("new_type = %p \n",new_type);
16722#endif
16723 if (new_type != NULL)
16724 {
16725 // Reset the base type to be the one associated with the target file.
16726#if 0
16727 printf ("Reset type for initializedName_copy = %p from type = %p to type = %p \n",initializedName_copy,initializedName_copy->get_type(),new_type);
16728#endif
16729 SgType* original_type = initializedName_copy->get_type();
16730 SgNamedType* original_named_type = isSgNamedType(original_type);
16731 SgNamedType* new_named_type = isSgNamedType(new_type);
16732 if (original_named_type != NULL)
16733 {
16734 ROSE_ASSERT(new_named_type != NULL);
16735 SgClassDeclaration* original_classDeclaration = isSgClassDeclaration(original_named_type->get_declaration());
16736 SgClassDeclaration* new_classDeclaration = isSgClassDeclaration(new_named_type->get_declaration());
16737 if (original_classDeclaration != NULL)
16738 {
16739 ROSE_ASSERT(new_classDeclaration != NULL);
16740#if 0
16741 printf ("original_classDeclaration = %p = %s \n",original_classDeclaration,original_classDeclaration->get_name().str());
16742 printf ("new_classDeclaration = %p = %s \n",new_classDeclaration,new_classDeclaration->get_name().str());
16743#endif
16744 // Make sure that the type names are the same.
16745 ROSE_ASSERT(new_classDeclaration->get_name() == original_classDeclaration->get_name());
16746 }
16747 }
16748#if 0
16749 SgType* old_type = initializedName_copy->get_type();
16750 printf ("Reset the type: initializedName_copy->set_type(new_type): old type = %p = %s new_type = %p = %s \n",old_type,old_type->class_name().c_str(),new_type,new_type->class_name().c_str());
16751#endif
16752 initializedName_copy->set_type(new_type);
16753 }
16754#if 0
16755 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
16756#endif
16757 SgFunctionParameterList* functionParameterList = isSgFunctionParameterList(enclosingStatement_copy);
16758 if (functionParameterList != NULL)
16759 {
16760 // The use of SgInitializedName in function parametes is handled differently then in other
16761 // locations in the AST (e.g. how the scope is set).
16762 // This is a function parameter and the scope is set to the SgFunctionDefinition if
16763 // this is for a defining function and the SgGlobal if it is a function prototype.
16764 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(functionParameterList->get_parent());
16765 ROSE_ASSERT(functionDeclaration != NULL);
16766 SgFunctionDefinition* functionDefinition = functionDeclaration->get_definition();
16767 if (functionDefinition != NULL)
16768 {
16769 ROSE_ASSERT(initializedName_copy->get_scope() == functionDefinition);
16770 // initializedName_copy->set_scope(functionDefinition);
16771 }
16772 else
16773 {
16774 SgGlobal* globalScope = isSgGlobal(functionDeclaration->get_scope());
16775 ROSE_ASSERT(globalScope != NULL);
16776 if (initializedName_copy->get_scope() != globalScope)
16777 {
16778#if 0
16779 printf ("Reset scope for initializedName_copy = %p = %s \n",initializedName_copy,initializedName_copy->get_name().str());
16780#endif
16781 initializedName_copy->set_scope(globalScope);
16782 }
16783 ROSE_ASSERT(initializedName_copy->get_scope() == globalScope);
16784 }
16785 }
16786 else
16787 {
16788#if 0
16789 printf ("initializedName_copy->get_scope() = %p = %s \n",initializedName_copy->get_scope(),initializedName_copy->get_scope()->class_name().c_str());
16790#endif
16791 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(enclosingStatement_copy);
16792 if (enumDeclaration != NULL)
16793 {
16794 // The case of enum declarations is special because the associated SgInitializedName IR nodes has a scope
16795 // that is external to the SgEnumDeclaration (in the scope of the SgEnumDeclaration). The typical case in C
16796 // is that the enum declaration is in global scope and then the enum fields (represented by SgInitializedName
16797 // objects) are have their associated symbol in the global scope.
16798
16799 // We have to use the name to search for the symbol instead of the pointer value of the initializedName_copy
16800 // (since the original symbol was associated with initializedName_original).
16801 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16802 SgName name = initializedName_copy->get_name();
16803 SgSymbol* symbol = initializedName_copy->get_scope()->lookup_enum_field_symbol(name);
16804 ROSE_ASSERT(symbol != NULL);
16805
16806 SgEnumFieldSymbol* enumFieldSymbol = isSgEnumFieldSymbol(symbol);
16807 ROSE_ASSERT(enumFieldSymbol != NULL);
16808
16809 // DQ (3/17/2014): Build a new sysmbol to for the initializedName_copy instead of reusing the existing symbol
16810 // from the snippet AST.
16811 SgEnumFieldSymbol* new_enumFieldSymbol = new SgEnumFieldSymbol(initializedName_copy);
16812 ROSE_ASSERT(new_enumFieldSymbol != NULL);
16813
16814 // targetScope->insert_symbol(name,enumFieldSymbol);
16815 targetScope->insert_symbol(name,new_enumFieldSymbol);
16816
16817 // DQ (3/6/2014): Set the scope of the SgInitializedName IR node.
16818 initializedName_copy->set_scope(targetScope);
16819#if 0
16820 printf ("Exiting as a test! \n");
16821 ROSE_ABORT();
16822#endif
16823 }
16824 else
16825 {
16826#if 0
16827 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
16828#endif
16829 SgCatchOptionStmt* catchOptionStatement = isSgCatchOptionStmt(enclosingStatement_copy->get_parent());
16830 if (catchOptionStatement != NULL)
16831 {
16832 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(enclosingStatement_copy);
16833 ROSE_ASSERT(variableDeclaration != NULL);
16834
16835 // SgSymbol* symbol = targetScope->lookup_variable_symbol(initializedName_copy->get_name());
16836 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(initializedName_original);
16837 ROSE_ASSERT(enclosingStatement_original != NULL);
16838 SgCatchOptionStmt* catchOptionStatement_original = isSgCatchOptionStmt(enclosingStatement_original->get_parent());
16839
16840 // SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),targetScope);
16841 SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),catchOptionStatement_original);
16842 if (symbol == NULL)
16843 {
16844 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
16845 // initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
16846 }
16847 ROSE_ASSERT(symbol != NULL);
16848
16849 initializedName_copy->set_scope(targetScope);
16850
16851 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
16852 ROSE_ASSERT(new_variableSymbol != NULL);
16853
16854 // DQ (3/19/2014): I am not certain this is the correct location to insert this symbol.
16855 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
16856 }
16857 else
16858 {
16859 // DQ (3/29/2014): Adding support for SgInitializedName IR nodes found in a SgJavaForEachStatement.
16860 SgJavaForEachStatement* javaForEachStatement = isSgJavaForEachStatement(enclosingStatement_copy->get_parent());
16861 if (javaForEachStatement != NULL)
16862 {
16863 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(enclosingStatement_copy);
16864 ROSE_ASSERT(variableDeclaration != NULL);
16865
16866 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(initializedName_original);
16867 ROSE_ASSERT(enclosingStatement_original != NULL);
16868 SgJavaForEachStatement* javaForEachStatement_original = isSgJavaForEachStatement(enclosingStatement_original->get_parent());
16869
16870 SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),javaForEachStatement_original);
16871 if (symbol == NULL)
16872 {
16873 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
16874 // initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
16875 }
16876 ROSE_ASSERT(symbol != NULL);
16877
16878 initializedName_copy->set_scope(targetScope);
16879
16880 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
16881 ROSE_ASSERT(new_variableSymbol != NULL);
16882
16883 // DQ (3/29/2014): I am not certain this is the correct location to insert this symbol.
16884 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
16885#if 0
16886 printf ("Need to handle case of SgJavaForEachStatement \n");
16887 ROSE_ABORT();
16888#endif
16889 }
16890 else
16891 {
16892 // Case of non-SgFunctionParameterList and non-SgEnumDeclaration use of SgInitializedName in AST.
16893 SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16894 if (symbol == NULL)
16895 {
16896 printf ("ERROR: enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
16897 ROSE_ASSERT(enclosingStatement_copy->get_parent() != NULL);
16898 printf ("ERROR: enclosingStatement_copy->get_parent() = %p = %s \n",enclosingStatement_copy->get_parent(),enclosingStatement_copy->get_parent()->class_name().c_str());
16899 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
16900 initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
16901
16902 // DQ (3/30/2014): Add this appraoch to find the symbol.
16903 SgScopeStatement* initializedName_copy_scope = isSgScopeStatement(initializedName_copy->get_scope());
16904 ROSE_ASSERT(initializedName_copy_scope != NULL);
16905 SgVariableSymbol* variableSymbol = initializedName_copy_scope->lookup_variable_symbol(initializedName_copy->get_name());
16906 ROSE_ASSERT(variableSymbol != NULL);
16907
16908 symbol = variableSymbol;
16909 }
16910 ROSE_ASSERT(symbol != NULL);
16911
16912 SgVariableSymbol* variableSymbol = isSgVariableSymbol(symbol);
16913 ROSE_ASSERT(variableSymbol != NULL);
16914#if 0
16915 printf ("Insert symbol = %p for initializedName_copy = %p = %s into targetScope = %p = %s \n",variableSymbol,initializedName_copy,initializedName_copy->get_name().str(),targetScope,targetScope->class_name().c_str());
16916#endif
16917 // DQ (3/17/2014): Build a new sysmbol to for the initializedName_copy instead of reusing the existing symbol
16918 // from the snippet AST.
16919 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
16920 ROSE_ASSERT(new_variableSymbol != NULL);
16921
16922 // targetScope->insert_symbol(initializedName_copy->get_name(),variableSymbol);
16923 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
16924
16925 // DQ (3/6/2014): Set the scope of the SgInitializedName IR node.
16926 initializedName_copy->set_scope(targetScope);
16927
16928#if 0
16929 SgName mangledName = variableSymbol->get_mangled_name();
16930 printf ("initializedName_copy: mangledName = %s \n",mangledName.str());
16931#endif
16932 // DQ (3/2/2014): Make sure this is true (I think it should be, but I don't see that it was explicitly set).
16933 // ROSE_ASSERT(initializedName_copy->get_scope() == targetScope);
16934 if (initializedName_copy->get_scope() != targetScope)
16935 {
16936 printf ("WARNING: initializedName_copy->get_scope() != targetScope: initializedName_copy->get_scope() = %p = %s \n",initializedName_copy->get_scope(),initializedName_copy->get_scope()->class_name().c_str());
16937
16938 printf ("I think this should be an error! \n");
16939 ROSE_ABORT();
16940 }
16941 }
16942 }
16943 }
16944 }
16945
16946 break;
16947 }
16948
16949 case V_SgVariableDeclaration:
16950 {
16951 // I think there is nothing to handle for this case (there is no type accessbile here
16952 // since they are in the SgInitializedName IR nodes).
16953 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(node_copy);
16954 ROSE_ASSERT(variableDeclaration != NULL);
16955
16956 break;
16957 }
16958
16959#define DEBUG_FUNCTION_DECLARATION 0
16960
16961 case V_SgFunctionDeclaration:
16962 {
16963 // SgFunctionDeclaration is handled directly in the snippet support (insertRelatedThingsForC() function).
16964
16965 // Note that function types are stored in global type tables so they need not be fixed up.
16966
16967 // DQ (3/13/2014): As of today, this assumption is no longer true, we need to be able to insert
16968 // any function declaration in insertRelatedThingsForC() and use this function to fixup the AST.
16969 // The target AST should have a prototype (non-defining declaration) of the function defined
16970 // so that all internal types of the SgFunctionType are defined in the target AST.
16971 SgFunctionDeclaration* functionDeclaration_copy = isSgFunctionDeclaration(node_copy);
16972 SgFunctionDeclaration* functionDeclaration_original = isSgFunctionDeclaration(node_original);
16973 SgFunctionType* functionType_copy = functionDeclaration_copy->get_type();
16974 SgFunctionType* functionType_original = functionDeclaration_original->get_type();
16975 ROSE_ASSERT(functionType_copy != NULL);
16976 ROSE_ASSERT(functionType_original != NULL);
16977 ROSE_ASSERT(functionType_copy == functionType_original);
16978#if DEBUG_FUNCTION_DECLARATION
16979 printf ("case SgFunctionDeclaration: part 1: Calling functionDeclaration_copy->search_for_symbol_from_symbol_table() \n");
16980#endif
16981 // SgSymbol* symbol_copy = functionDeclaration_copy->search_for_symbol_from_symbol_table();
16982 SgSymbol* symbol_original = functionDeclaration_original->search_for_symbol_from_symbol_table();
16983 ROSE_ASSERT(symbol_original != NULL);
16984 SgFunctionSymbol* functionSymbol_original = isSgFunctionSymbol(symbol_original);
16985 ROSE_ASSERT(functionSymbol_original != NULL);
16986
16987 SgFile* snippetFile = getEnclosingFileNode(functionSymbol_original);
16988 ROSE_ASSERT(snippetFile != NULL);
16989 if (snippetFile != targetFile)
16990 {
16991#if DEBUG_FUNCTION_DECLARATION
16992 printf ("Warning: case V_SgFunctionDeclaration: functionSymbol_original not in target file \n");
16993#endif
16994 // DQ (3/13/2014): Handle the case of a member function seperately (I think this can't appear in Java, only in C++).
16995 // ROSE_ASSERT(isSgMemberFunctionSymbol(symbol_copy) == NULL);
16996 ROSE_ASSERT(isSgMemberFunctionSymbol(symbol_original) == NULL);
16997
16998 // printf ("case SgFunctionDeclaration: part 2: Calling functionDeclaration_copy->search_for_symbol_from_symbol_table() \n");
16999 // SgFunctionSymbol* functionSymbol_copy = isSgFunctionSymbol(functionDeclaration_copy->search_for_symbol_from_symbol_table());
17000 // ROSE_ASSERT(functionSymbol_copy != NULL);
17001
17002 SgName name = functionDeclaration_copy->get_name();
17003 SgType* functionType = functionDeclaration_copy->get_type();
17004 ROSE_ASSERT(functionType != NULL);
17005#if DEBUG_FUNCTION_DECLARATION
17006 printf ("case V_SgFunctionDeclaration: name = %s \n",name.str());
17007 printf ("case V_SgFunctionDeclaration: functionType = %p \n",functionType);
17008 printf ("case V_SgFunctionDeclaration: functionType_original = %p \n",functionType_original);
17009 printf ("case V_SgFunctionDeclaration: functionType_copy = %p \n",functionType_copy);
17010#endif
17011 SgFunctionSymbol* functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,functionType,targetScope);
17012
17013 ROSE_ASSERT(targetScope != NULL);
17014 functionDeclaration_copy->set_scope(targetScope);
17015
17016 // Set the scope of the non-defining declaration.
17017 functionDeclaration_copy->get_firstNondefiningDeclaration()->set_scope(targetScope);
17018
17019 SgFunctionDeclaration* functionDeclaration_copy_firstNondefining = NULL;
17020
17021 if (functionSymbolInTargetAST == NULL)
17022 {
17023#if DEBUG_FUNCTION_DECLARATION
17024 printf ("functionSymbolInTargetAST not found in targetScope = %p = %s \n",targetScope,targetScope->class_name().c_str());
17025#endif
17026 // If could be that the symbol is in the local scope of the snippet AST.
17027 SgScopeStatement* otherPossibleScope = isSgScopeStatement(functionDeclaration_original->get_parent());
17028 ROSE_ASSERT(otherPossibleScope != NULL);
17029#if DEBUG_FUNCTION_DECLARATION
17030 printf ("case V_SgFunctionDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope,otherPossibleScope->class_name().c_str());
17031#endif
17032 // We want to out serch the additional other scope and not it's parent scope.
17033 // functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,functionType,otherPossibleScope);
17034 functionSymbolInTargetAST = otherPossibleScope->lookup_function_symbol(name,functionType);
17035
17036 if (functionSymbolInTargetAST == NULL)
17037 {
17038 printf ("function symbol not found in otherPossibleScope = %p = %s \n",otherPossibleScope,otherPossibleScope->class_name().c_str());
17039 }
17040
17041 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17042#if DEBUG_FUNCTION_DECLARATION
17043 printf ("(building a new SgFunctionSymbol): functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17044#endif
17045 // DQ (3/15/2014): We need to insert a new symbol into the targetScope instead of reusing
17046 // the existing symbol (because it points to the declaration in the snippet file).
17047 // Insert the symbol into the targetScope.
17048 // targetScope->insert_symbol(name,functionSymbolInTargetAST);
17049 functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionDeclaration_copy->get_firstNondefiningDeclaration());
17050 SgFunctionSymbol* new_symbol = new SgFunctionSymbol(functionDeclaration_copy_firstNondefining);
17051 ROSE_ASSERT(new_symbol != NULL);
17052
17053 targetScope->insert_symbol(name,new_symbol);
17054
17055 functionSymbolInTargetAST = new_symbol;
17056
17057 ROSE_ASSERT(lookupFunctionSymbolInParentScopes(name,functionType,targetScope) != NULL);
17058 }
17059 else
17060 {
17061 // If we happend to find an associated symbol in the target scope then we nave to use it and
17062 // set the first nondefining declaration pointer to the symbol's associate declaration.
17063 // This is the case of the test3a test code (because the snippet functions declaration is
17064 // in the target AST file (likely a mistake, but we should handle it properly).
17065#if DEBUG_FUNCTION_DECLARATION
17066 printf ("(using existing symbol found in target scope): functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17067#endif
17068 functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
17069 }
17070
17071 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17072
17073 ROSE_ASSERT(functionDeclaration_copy->get_firstNondefiningDeclaration() != NULL);
17074 ROSE_ASSERT(functionDeclaration_copy_firstNondefining != NULL);
17075
17076 // SgFunctionDeclaration* functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionDeclaration_copy->get_firstNondefiningDeclaration());
17077 SgFunctionDeclaration* functionDeclaration_original_firstNondefining = isSgFunctionDeclaration(functionDeclaration_original->get_firstNondefiningDeclaration());
17078 SgFunctionDeclaration* functionDeclaration_copy_defining = isSgFunctionDeclaration(functionDeclaration_copy->get_definingDeclaration());
17079 SgFunctionDeclaration* functionDeclaration_original_defining = isSgFunctionDeclaration(functionDeclaration_original->get_definingDeclaration());
17080 if (functionDeclaration_copy_firstNondefining->get_symbol_from_symbol_table() == NULL)
17081 {
17082 // Check what might be wrong here!
17083 ROSE_ASSERT(functionDeclaration_original_firstNondefining != NULL);
17084 printf ("functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17085
17086 printf ("functionDeclaration_original = %p = %s \n",functionDeclaration_original,functionDeclaration_original->class_name().c_str());
17087 printf ("functionDeclaration_copy = %p = %s \n",functionDeclaration_copy,functionDeclaration_copy->class_name().c_str());
17088 printf ("functionDeclaration_original_firstNondefining = %p \n",functionDeclaration_original_firstNondefining);
17089 printf ("functionDeclaration_copy_firstNondefining = %p \n",functionDeclaration_copy_firstNondefining);
17090 printf ("functionDeclaration_original_defining = %p \n",functionDeclaration_original_defining);
17091 printf ("functionDeclaration_copy_defining = %p \n",functionDeclaration_copy_defining);
17092
17093 printf ("functionDeclaration_original->get_scope() = %p = %s \n",functionDeclaration_original->get_scope(),functionDeclaration_original->get_scope()->class_name().c_str());
17094 printf ("functionDeclaration_copy->get_scope() = %p = %s \n",functionDeclaration_copy->get_scope(),functionDeclaration_copy->get_scope()->class_name().c_str());
17095 printf ("functionDeclaration_original_firstNondefining->get_scope() = %p = %s \n",functionDeclaration_original_firstNondefining->get_scope(),functionDeclaration_original_firstNondefining->get_scope()->class_name().c_str());
17096 printf ("functionDeclaration_copy_firstNondefining->get_scope() = %p = %s \n",functionDeclaration_copy_firstNondefining->get_scope(),functionDeclaration_copy_firstNondefining->get_scope()->class_name().c_str());
17097 printf ("functionDeclaration_original_defining->get_scope() = %p = %s \n",functionDeclaration_original_defining->get_scope(),functionDeclaration_original_defining->get_scope()->class_name().c_str());
17098 printf ("functionDeclaration_copy_defining->get_scope() = %p = %s \n",functionDeclaration_copy_defining->get_scope(),functionDeclaration_copy_defining->get_scope()->class_name().c_str());
17099 printf ("functionSymbolInTargetAST = %p = %s \n",functionSymbolInTargetAST,functionSymbolInTargetAST->class_name().c_str());
17100 }
17101
17102 ROSE_ASSERT(targetScope->lookup_function_symbol(name,functionType) != NULL);
17103
17104 // TV (10/22/2014): Might not be the case as we now have a project wide global scope
17105 // ROSE_ASSERT(functionDeclaration_copy_firstNondefining->get_scope() == targetScope);
17106
17107 ROSE_ASSERT(functionDeclaration_copy_firstNondefining == functionDeclaration_copy_firstNondefining->get_firstNondefiningDeclaration());
17108
17109 // This is what is called internal to the get_symbol_from_symbol_table() function below.
17110 // Use this function, SgFunctionDeclaration::get_symbol_from_symbol_table(), but not the template function: find_symbol_from_declaration().
17111 // ROSE_ASSERT(targetScope->find_symbol_from_declaration(functionDeclaration_copy_firstNondefining) != NULL);
17112
17113 ROSE_ASSERT(functionDeclaration_copy_firstNondefining->get_symbol_from_symbol_table() != NULL);
17114
17115#if 0
17116 bool isDefiningDeclaration (functionDeclaration_original->get_declaration() != NULL);
17117 if (isDefiningDeclaration == true)
17118 {
17119 // We may have to build a non-defining declaration.
17120 SgFunctionDeclaration* nondefiningFunctionDeclaration_original = functionDeclaration_original->get_firstNondefiningDeclaration();
17121 SgFile* nondefiningDeclarationFile = getEnclosingFileNode(functionSymbol_original);
17122 ROSE_ASSERT(nondefiningDeclarationFile != NULL);
17123 if (nondefiningDeclarationFile == targetFile)
17124 {
17125 // Use this nondefining declaration.
17126 }
17127 else
17128 {
17129 // Make a copy of the non-defining declaration for use in the symbol.
17130 }
17131
17132 }
17133 else
17134 {
17135 // Use this as non-defining declaration.
17136 }
17137
17138 SgFile* snippetFile = getEnclosingFileNode(functionSymbol_original);
17139 SgFunctionSymbol* new_function_symbol = new SgFunctionSymbol(isSgFunctionDeclaration(func));
17140 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
17141 targetScope->insert_symbol(name,symbol_original);
17142
17143 ROSE_ABORT();
17144#endif
17145 }
17146
17147 // DQ (3/17/2014): Refactored code to support resetting the scopes in the SgDeclarationStatement IR nodes.
17148 resetDeclaration(functionDeclaration_copy,functionDeclaration_original,targetScope);
17149#if 0
17150 printf ("SageBuilder::fixupCopyOfNodeFromSeperateFileInNewTargetAst(): Need to be able to fixup the SgFunctionDeclaration \n");
17151 ROSE_ABORT();
17152#endif
17153 break;
17154 }
17155
17156 case V_SgClassDeclaration:
17157 {
17158 // Need to handle the referenced types
17159 SgClassDeclaration* classDeclaration_copy = isSgClassDeclaration(node_copy);
17160 SgClassDeclaration* classDeclaration_original = isSgClassDeclaration(node_original);
17161 SgClassType* classType = classDeclaration_copy->get_type();
17162 ROSE_ASSERT(classType != NULL);
17163#if 0
17164 printf ("Need to handle named types from class declarations \n");
17165#endif
17166 // SgClassSymbol* classSymbol_copy = isSgClassSymbol(classDeclaration_copy->search_for_symbol_from_symbol_table());
17167 // ROSE_ASSERT(classSymbol_copy != NULL);
17168
17169 // if (TransformationSupport::getFile(classSymbol_copy) != targetFile)
17170 // if (getEnclosingFileNode(classSymbol_copy) != targetFile)
17171 // if (getEnclosingFileNode(classDeclaration_copy) != targetFile)
17172 {
17173 // printf ("Warning: case V_SgClassDeclaration: classSymbol_copy not in target file \n");
17174#if 0
17175 printf ("Warning: case V_SgClassDeclaration: assume getEnclosingFileNode(classDeclaration_copy) != targetFile \n");
17176#endif
17177 // Find the symbol in the target scope.
17178 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17179#if 0
17180 // printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
17181#endif
17182 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
17183
17184 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17185 // ROSE_ASSERT(targetScope != NULL);
17186
17187 SgName name = classDeclaration_copy->get_name();
17188#if 0
17189 // If we randomize the names then we need to handle this case...
17190 printf ("case V_SgClassDeclaration: targetScope = %p classSymbol_copy->get_name() = %s \n",targetScope,classSymbol_copy->get_name().str());
17191#endif
17192 // SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classSymbol_copy->get_name(),targetScope);
17193 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(name,targetScope);
17194
17195 if (classSymbolInTargetAST == NULL)
17196 {
17197 // If could be that the symbol is in the local scope of the snippet AST.
17198 SgScopeStatement* otherPossibleScope = isSgScopeStatement(classDeclaration_original->get_parent());
17199 ROSE_ASSERT(otherPossibleScope != NULL);
17200#if 0
17201 printf ("case V_SgClassDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
17202#endif
17203 // classSymbolInTargetAST = lookupClassSymbolInParentScopes(classSymbol_copy->get_name(),otherPossibleScope);
17204 classSymbolInTargetAST = lookupClassSymbolInParentScopes(name,otherPossibleScope);
17205 ROSE_ASSERT(classSymbolInTargetAST != NULL);
17206#if 0
17207 // I think this is the wrong code.
17208 SgClassDeclaration* classDeclaration = classSymbolInTargetAST->get_declaration();
17209 ROSE_ASSERT(classDeclaration != NULL);
17210 SgScopeStatement* scope = classDeclaration->get_scope();
17211 ROSE_ASSERT(scope != NULL);
17212 classDeclaration_copy->set_scope(scope);
17213#else
17214 // DQ (3/17/2014): The scope must be set to be the targetScope (at least for C, but maybe not C++).
17215 classDeclaration_copy->set_scope(targetScope);
17216#endif
17217 // DQ (3/17/2014): Build a new SgClassSymbol using the classDeclaration_copy.
17218 SgClassSymbol* classSymbol = new SgClassSymbol(classDeclaration_copy);
17219 ROSE_ASSERT(classSymbol != NULL);
17220 classSymbolInTargetAST = classSymbol;
17221
17222 // Insert the symbol into the targetScope.
17223 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
17224 targetScope->insert_symbol(name,classSymbolInTargetAST);
17225 }
17226 else
17227 {
17228 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
17229 SgClassDeclaration* classDeclaration = classSymbolInTargetAST->get_declaration();
17230 ROSE_ASSERT(classDeclaration != NULL);
17231 SgScopeStatement* scope = classDeclaration->get_scope();
17232 ROSE_ASSERT(scope != NULL);
17233 classDeclaration_copy->set_scope(scope);
17234 }
17235
17236 ROSE_ASSERT(classSymbolInTargetAST != NULL);
17237 }
17238
17239 // DQ (3/17/2014): Avoid calling strip type now that we have refactored the getTargetFileType() function.
17240 // DQ (3/10/2014): Added remaining type for this case.
17241 // SgType* new_type = getTargetFileType(classType->stripType(),targetScope);
17242 SgType* new_type = getTargetFileType(classType,targetScope);
17243 SgClassType* new_class_type = isSgClassType(new_type);
17244 if (new_class_type != NULL)
17245 {
17246 // Reset the base type to be the one associated with the target file.
17247 classDeclaration_copy->set_type(new_class_type);
17248#if 0
17249 printf ("case V_SgClassDeclaration: built class type: part 1: classDeclaration_copy->get_type() = %p = %s \n",
17250 classDeclaration_copy->get_type(),classDeclaration_copy->get_type()->class_name().c_str());
17251#endif
17252 }
17253
17254 resetDeclaration(classDeclaration_copy,classDeclaration_original,targetScope);
17255#if 0
17256 printf ("SgClassDeclaration: Exiting as a test! \n");
17257 ROSE_ABORT();
17258#endif
17259 break;
17260 }
17261
17262 case V_SgEnumDeclaration:
17263 {
17264 // Need to handle the referenced types
17265 SgEnumDeclaration* enumDeclaration_copy = isSgEnumDeclaration(node_copy);
17266 SgEnumDeclaration* enumDeclaration_original = isSgEnumDeclaration(node_original);
17267
17268 // SgEnumType* enumType = enumDeclaration_copy->get_type();
17269 // ROSE_ASSERT(enumType != NULL);
17270
17271 // I don't think we have to test for this being a part of the snippet file.
17272 {
17273 SgName name = enumDeclaration_copy->get_name();
17274#if 0
17275 // If we randomize the names then we need to handle this case...
17276 printf ("case V_SgEnumDeclaration: targetScope = %p enumSymbol_copy->get_name() = %s \n",targetScope,name.str());
17277#endif
17278 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(name,targetScope);
17279
17280 if (enumSymbolInTargetAST == NULL)
17281 {
17282 // If could be that the symbol is in the local scope of the snippet AST.
17283 SgScopeStatement* otherPossibleScope = isSgScopeStatement(enumDeclaration_original->get_parent());
17284 ROSE_ASSERT(otherPossibleScope != NULL);
17285#if 0
17286 printf ("case V_SgEnumDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
17287#endif
17288 // I think we are not looking in the correct scope! Or else we need to also look in the target global scope.
17289#if 0
17290 printf ("Since the symbol has not been inserted yet, what symbol are we looking for? \n");
17291#endif
17292 enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(name,otherPossibleScope);
17293
17294 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
17295 SgEnumDeclaration* enumDeclaration = enumSymbolInTargetAST->get_declaration();
17296 ROSE_ASSERT(enumDeclaration != NULL);
17297
17298 ROSE_ASSERT(enumDeclaration != enumDeclaration_original);
17299
17300 // This is true, so we need to build a new sysmbol.
17301 ROSE_ASSERT(enumSymbolInTargetAST->get_declaration() == enumDeclaration_original->get_firstNondefiningDeclaration());
17302
17303 // Build a new SgEnumSymbol using the enumDeclaration_copy.
17304 SgEnumSymbol* enumSymbol = new SgEnumSymbol(enumDeclaration_copy);
17305 ROSE_ASSERT(enumSymbol != NULL);
17306 enumSymbolInTargetAST = enumSymbol;
17307
17308 // If this is false then we need to build a new SgEnumSymbol rather than reusing the existing one.
17309 ROSE_ASSERT(enumSymbolInTargetAST->get_declaration() != enumDeclaration_original->get_firstNondefiningDeclaration());
17310
17311 // SgScopeStatement* scope = enumDeclaration->get_scope();
17312 SgScopeStatement* scope = targetScope;
17313 ROSE_ASSERT(scope != NULL);
17314 enumDeclaration_copy->set_scope(scope);
17315#if 0
17316 printf ("case V_SgEnumDeclaration: insert_symbol(): name = %s enumSymbolInTargetAST = %p \n",name.str(),enumSymbolInTargetAST);
17317#endif
17318 // Insert the symbol into the targetScope.
17319 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
17320 targetScope->insert_symbol(name,enumSymbolInTargetAST);
17321 }
17322 else
17323 {
17324#if 0
17325 printf ("Found an existing enum declaration: name = %s enumSymbolInTargetAST = %p \n",name.str(),enumSymbolInTargetAST);
17326#endif
17327 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
17328 SgEnumDeclaration* enumDeclaration = enumSymbolInTargetAST->get_declaration();
17329 ROSE_ASSERT(enumDeclaration != NULL);
17330#if 0
17331 SgScopeStatement* scope = enumDeclaration->get_scope();
17332 ROSE_ASSERT(scope != NULL);
17333 ROSE_ASSERT(scope == targetScope);
17334 // enumDeclaration_copy->set_scope(scope);
17335#else
17336 // TV (10/22/2014): Might not be the case as we now have a project wide global scope
17337 // ROSE_ASSERT(enumDeclaration->get_scope() == targetScope);
17338#endif
17339 }
17340
17341 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
17342 }
17343#if 0
17344 printf ("Exiting as a test 1! \n");
17345 ROSE_ABORT();
17346#endif
17347 SgEnumType* enumType = enumDeclaration_copy->get_type();
17348 ROSE_ASSERT(enumType != NULL);
17349 SgType* new_type = getTargetFileType(enumType,targetScope);
17350#if 0
17351 printf ("Return type from getTargetFileType(): original enumType = %p new_type = %p \n",enumType,new_type);
17352#endif
17353 SgEnumType* new_enum_type = isSgEnumType(new_type);
17354 if (new_enum_type != NULL)
17355 {
17356 // Reset the base type to be the one associated with the target file.
17357#if 0
17358 printf ("reset the type using the new enum type from the target AST \n");
17359#endif
17360 enumDeclaration_copy->set_type(new_enum_type);
17361 }
17362#if 0
17363 printf ("Exiting as a test 2! \n");
17364 ROSE_ABORT();
17365#endif
17366
17367 resetDeclaration(enumDeclaration_copy,enumDeclaration_original,targetScope);
17368 break;
17369 }
17370
17371 // This is not a required declaration of C.
17372 case V_SgTemplateClassDeclaration:
17373 {
17374 // Need to handle the referenced types
17375 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(node_copy);
17376 SgClassType* templateClassType = templateClassDeclaration->get_type();
17377 ROSE_ASSERT(templateClassType != NULL);
17378
17379 // DQ (3/10/2014): Added support for enum types.
17380 SgType* new_type = getTargetFileType(templateClassType,targetScope);
17381 SgClassType* new_templateClass_type = isSgClassType(new_type);
17382 if (new_templateClass_type != NULL)
17383 {
17384 // Reset the base type to be the one associated with the target file.
17385 templateClassDeclaration->set_type(new_templateClass_type);
17386#if 0
17387 printf ("case V_SgTemplateClassDeclaration: built class type: part 1: templateClassDeclaration->get_type() = %p = %s \n",
17388 templateClassDeclaration->get_type(),templateClassDeclaration->get_type()->class_name().c_str());
17389#endif
17390 }
17391
17392 break;
17393 }
17394
17395 case V_SgTypedefDeclaration:
17396 {
17397 // Need to handle the referenced types (there are two for the case of a SgTypedefDeclaration).
17398 SgTypedefDeclaration* typedefDeclaration_copy = isSgTypedefDeclaration(node_copy);
17399 SgTypedefDeclaration* typedefDeclaration_original = isSgTypedefDeclaration(node_original);
17400
17401 SgType* base_type = typedefDeclaration_copy->get_base_type();
17402 ROSE_ASSERT(base_type != NULL);
17403 SgType* new_base_type = getTargetFileType(base_type,targetScope);
17404 if (new_base_type != NULL)
17405 {
17406 // Reset the base type to be the one associated with the target file.
17407 typedefDeclaration_copy->set_base_type(new_base_type);
17408 }
17409
17410 // I don't think we have to test for this being a part of the snippet file.
17411 {
17412 SgName name = typedefDeclaration_copy->get_name();
17413#if 0
17414 // If we randomize the names then we need to handle this case...
17415 printf ("case V_SgTypedefDeclaration: targetScope = %p typedefSymbol_copy->get_name() = %s \n",targetScope,name.str());
17416#endif
17417 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(name,targetScope);
17418
17419 if (typedefSymbolInTargetAST == NULL)
17420 {
17421 // If could be that the symbol is in the local scope of the snippet AST.
17422 SgScopeStatement* otherPossibleScope = isSgScopeStatement(typedefDeclaration_original->get_parent());
17423 ROSE_ASSERT(otherPossibleScope != NULL);
17424#if 0
17425 printf ("case V_SgTypedefDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
17426#endif
17427 typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(name,otherPossibleScope);
17428
17429 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
17430 SgTypedefDeclaration* typedefDeclaration = typedefSymbolInTargetAST->get_declaration();
17431 ROSE_ASSERT(typedefDeclaration != NULL);
17432 // SgScopeStatement* scope = typedefDeclaration->get_scope();
17433 SgScopeStatement* scope = targetScope;
17434 ROSE_ASSERT(scope != NULL);
17435 typedefDeclaration_copy->set_scope(scope);
17436
17437 // DQ (3/17/2014): Build a new SgTypedefSymbol using the typedefDeclaration_copy.
17438 SgTypedefSymbol* typedefSymbol = new SgTypedefSymbol(typedefDeclaration_copy);
17439 ROSE_ASSERT(typedefSymbol != NULL);
17440 typedefSymbolInTargetAST = typedefSymbol;
17441#if 0
17442 printf ("case V_SgTypedefDeclaration: insert_symbol(): name = %s typedefSymbolInTargetAST = %p \n",name.str(),typedefSymbolInTargetAST);
17443#endif
17444 // Insert the symbol into the targetScope.
17445 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
17446 targetScope->insert_symbol(name,typedefSymbolInTargetAST);
17447 }
17448 else
17449 {
17450#if 0
17451 printf ("Found an existing typedef declaration: name = %s typedefSymbolInTargetAST = %p \n",name.str(),typedefSymbolInTargetAST);
17452#endif
17453 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
17454 SgTypedefDeclaration* typedefDeclaration = typedefSymbolInTargetAST->get_declaration();
17455 ROSE_ASSERT(typedefDeclaration != NULL);
17456 SgScopeStatement* scope = typedefDeclaration->get_scope();
17457 ROSE_ASSERT(scope != NULL);
17458 typedefDeclaration_copy->set_scope(scope);
17459 }
17460
17461 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
17462 }
17463#if 0
17464 printf ("Exiting as a test 1! \n");
17465 ROSE_ABORT();
17466#endif
17467 SgTypedefType* typedefType = typedefDeclaration_copy->get_type();
17468 ROSE_ASSERT(typedefType != NULL);
17469 SgType* new_type = getTargetFileType(typedefType,targetScope);
17470 SgTypedefType* new_typedef_type = isSgTypedefType(new_type);
17471 if (new_typedef_type != NULL)
17472 {
17473 // Reset the base type to be the one associated with the target file.
17474#if 0
17475 printf ("reset the type using the new typedef type from the target AST \n");
17476#endif
17477 typedefDeclaration_copy->set_type(new_typedef_type);
17478#if 0
17479 printf ("case V_SgTypedefDeclaration: built class type: part 1: typedefDeclaration_copy->get_type() = %p = %s \n",
17480 typedefDeclaration_copy->get_type(),typedefDeclaration_copy->get_type()->class_name().c_str());
17481#endif
17482 }
17483
17484 resetDeclaration(typedefDeclaration_copy,typedefDeclaration_original,targetScope);
17485#if 0
17486 printf ("Exiting as a test 2! \n");
17487 ROSE_ABORT();
17488#endif
17489 break;
17490 }
17491
17492 case V_SgVarRefExp:
17493 {
17494 // Need to handle the referenced symbol.
17495 // but if we have handle this in the declaration for the variable (case V_SgInitializedName)
17496 // then we don't have to do anything here. However, we have only handled this variable
17497 // declaration if the variable declaration was a part of the snippet. If the variable
17498 // declaration is not a part of the original snippet (the copy of the snippet's AST that
17499 // we are inserting (not the snippet program where it would have to be defined for the
17500 // snippet to compile) then we have to find the associated variable sysmbol in the target
17501 // AST and reset the SgVarRefExp to use that symbol.
17502
17503 SgVarRefExp* varRefExp_copy = isSgVarRefExp(node_copy);
17504 SgVarRefExp* varRefExp_original = isSgVarRefExp(node_original);
17505 SgVariableSymbol* variableSymbol_copy = isSgVariableSymbol(varRefExp_copy->get_symbol());
17506 ROSE_ASSERT(variableSymbol_copy != NULL);
17507 // if (TransformationSupport::getFile(variableSymbol_copy) != targetFile)
17508 if (getEnclosingFileNode(variableSymbol_copy) != targetFile)
17509 {
17510#if 0
17511 printf ("Warning: case V_SgVarRefExp: variableSymbol not in target file: name = %s \n",variableSymbol_copy->get_name().str());
17512#endif
17513#if 0
17514 printf ("insertionPoint = %p = %s \n",insertionPoint,insertionPoint->class_name().c_str());
17515#endif
17516 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17517#if 0
17518 // printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
17519#endif
17520 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
17521
17522 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17523 // ROSE_ASSERT(targetScope != NULL);
17524
17525 SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),targetScope);
17526
17527 if (variableSymbolInTargetAST == NULL)
17528 {
17529 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
17530 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
17531 // previously added snippet.
17532#if 0
17533 printf ("Error: The associated variable = %s should have been found in a parent scope of the target AST \n",variableSymbol_copy->get_name().str());
17534#endif
17535 // We need to look into the scope of the block used to define the statments as seperate snippets (same issue as for functions).
17536
17537 // If could be that the symbol is in the local scope of the snippet AST.
17538 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(varRefExp_original);
17539 ROSE_ASSERT(enclosingStatement_original != NULL);
17540#if 0
17541 printf ("case V_SgVarRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
17542#endif
17543 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
17544 ROSE_ASSERT(otherPossibleScope_original != NULL);
17545 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
17546 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
17547 ROSE_ASSERT(file != NULL);
17548#if 0
17549 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
17550 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
17551
17552 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
17553 printf ("case V_SgClassDeclaration: variableSymbol_copy->get_name() = %s \n",variableSymbol_copy->get_name().str());
17554#endif
17555 variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),otherPossibleScope_original);
17556 if (variableSymbolInTargetAST == NULL)
17557 {
17558#if 0
17559 targetScope->get_symbol_table()->print("targetScope: symbol table");
17560 otherPossibleScope_original->get_symbol_table()->print("otherPossibleScope_original: symbol table");
17561#endif
17562
17563 // Check for the case of a record reference (member of data structure).
17564 SgExpression* parentExpression = isSgExpression(varRefExp_copy->get_parent());
17565 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
17566 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
17567 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
17568 if (parentDotExp != NULL || parentArrowExp != NULL)
17569 {
17570 // This is a data member reference, so it's scope is the associated data structure.
17571 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
17572 ROSE_ASSERT(lhs != NULL);
17573 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == varRefExp_copy);
17574
17575 SgType* type = lhs->get_type();
17576 ROSE_ASSERT(type != NULL);
17577#if 0
17578 printf ("type = %p = %s \n",type,type->class_name().c_str());
17579#endif
17580 SgNamedType* namedType = isSgNamedType(type);
17581 ROSE_ASSERT(namedType != NULL);
17582 SgDeclarationStatement* declaration = namedType->get_declaration();
17583 ROSE_ASSERT(declaration != NULL);
17584 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
17585 ROSE_ASSERT(classDeclaration != NULL);
17586 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
17587 ROSE_ASSERT(definingClassDeclaration != NULL);
17588 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
17589 ROSE_ASSERT(classDefinition != NULL);
17590#if 0
17591 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
17592#endif
17593 // I think we want the copy.
17594 otherPossibleScope_original = classDefinition;
17595
17596 variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),otherPossibleScope_original);
17597 }
17598
17599 }
17600 ROSE_ASSERT(variableSymbolInTargetAST != NULL);
17601 SgInitializedName* initializedName = variableSymbolInTargetAST->get_declaration();
17602 ROSE_ASSERT(initializedName != NULL);
17603 SgScopeStatement* scope = initializedName->get_scope();
17604 ROSE_ASSERT(scope != NULL);
17605
17606 // Is this the correct scope?
17607 initializedName->set_scope(scope);
17608
17609 // Insert the symbol into the targetScope.
17610 targetScope->insert_symbol(variableSymbol_copy->get_name(),variableSymbolInTargetAST);
17611 }
17612 ROSE_ASSERT(variableSymbolInTargetAST != NULL);
17613
17614 // Reset the symbol associated with this variable reference.
17615 varRefExp_copy->set_symbol(variableSymbolInTargetAST);
17616
17617 // printf ("Exiting as a test! \n");
17618 // ROSE_ASSERT(false);
17619 }
17620
17621 break;
17622 }
17623
17624 case V_SgFunctionRefExp:
17625 {
17626 // Need to handle the referenced symbol
17627 SgFunctionRefExp* functionRefExp_copy = isSgFunctionRefExp(node_copy);
17628 // SgFunctionRefExp* functionRefExp_original = isSgFunctionRefExp(node_original);
17629 SgFunctionSymbol* functionSymbol_copy = isSgFunctionSymbol(functionRefExp_copy->get_symbol());
17630 ROSE_ASSERT(functionSymbol_copy != NULL);
17631 // if (TransformationSupport::getFile(functionSymbol) != targetFile)
17632 if (getEnclosingFileNode(functionSymbol_copy) != targetFile)
17633 {
17634#if 0
17635 printf ("Warning: case V_SgFunctionRefExp: functionSymbol_copy not in target file (find function = %s) \n",functionSymbol_copy->get_name().str());
17636#endif
17637 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17638#if 0
17639 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
17640#endif
17641 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
17642
17643 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17644 // ROSE_ASSERT(targetScope != NULL);
17645
17646 SgName name = functionSymbol_copy->get_name();
17647
17648 // I think we need the function's mangled name to support this lookup.
17649 SgFunctionSymbol* functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,targetScope);
17650
17651 if (functionSymbolInTargetAST == NULL)
17652 {
17653 // DQ (3/17/2014): Revised as of further discussion about how the snippet mechanism will copy required
17654 // declaration from the snippet file to the target AST.
17655 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
17656 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
17657 // previously added snippet.
17658 // DQ (3/17/2014): After some revision of the specification for the snippet injection, this is still
17659 // an error since this is the case where a declaration should have been visible from having already been
17660 // inserted into the target AST and this visible from this injection point in the target AST.
17661
17662 fprintf (stderr, "Error: The associated function = \"%s\" should have been found in a parent scope"
17663 " of the target AST\n", name.str());
17664
17665 fprintf (stderr, " targetScope = %p = %s \n",targetScope,targetScope->class_name().c_str());
17666 SgGlobal* globalScope = TransformationSupport::getGlobalScope(targetScope);
17667 ROSE_ASSERT(globalScope != NULL);
17668 fprintf (stderr, " globalScope = %p = %s \n",globalScope,globalScope->class_name().c_str());
17669#if 0
17670 targetScope->get_file_info()->display("case V_SgFunctionRefExp: targetScope: debug");
17671 node_original->get_file_info()->display("case V_SgFunctionRefExp: node_original: debug");
17672#endif
17673#if 0
17674 // DQ (3/10/2014): This might be important for friend functions in C++ (but we can ignore it for now).
17675#error "DEAD CODE!"
17676 // If could be that the symbol is in the local scope of the snippet AST.
17677 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(functionRefExp_original);
17678 ROSE_ASSERT(enclosingStatement_original != NULL);
17679#if 0
17680 printf ("case V_SgFunctionRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
17681#endif
17682 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
17683 ROSE_ASSERT(otherPossibleScope_original != NULL);
17684 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
17685 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
17686 ROSE_ASSERT(file != NULL);
17687#if 0
17688 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
17689 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
17690
17691 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
17692 printf ("case V_SgClassDeclaration: functionSymbol_copy->get_name() = %s \n",functionSymbol_copy->get_name().str());
17693#endif
17694 functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(functionSymbol_copy->get_name(),otherPossibleScope_original);
17695#error "DEAD CODE!"
17696 if (functionSymbolInTargetAST == NULL)
17697 {
17698 // Check for the case of a record reference (member function of class declaration).
17699 SgExpression* parentExpression = isSgExpression(functionRefExp_copy->get_parent());
17700 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
17701 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
17702 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
17703 if (parentDotExp != NULL || parentArrowExp != NULL)
17704 {
17705 // This is a data member reference, so it's scope is the associated data structure.
17706 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
17707 ROSE_ASSERT(lhs != NULL);
17708 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == functionRefExp_copy);
17709#error "DEAD CODE!"
17710 SgType* type = lhs->get_type();
17711 ROSE_ASSERT(type != NULL);
17712#if 0
17713 printf ("type = %p = %s \n",type,type->class_name().c_str());
17714#endif
17715 SgNamedType* namedType = isSgNamedType(type);
17716 ROSE_ASSERT(namedType != NULL);
17717 SgDeclarationStatement* declaration = namedType->get_declaration();
17718 ROSE_ASSERT(declaration != NULL);
17719 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
17720 ROSE_ASSERT(classDeclaration != NULL);
17721 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
17722 ROSE_ASSERT(definingClassDeclaration != NULL);
17723 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
17724 ROSE_ASSERT(classDefinition != NULL);
17725#if 0
17726 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
17727#endif
17728 // I think we want the copy.
17729 otherPossibleScope_original = classDefinition;
17730
17731 functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(functionSymbol_copy->get_name(),otherPossibleScope_original);
17732 }
17733 }
17734
17735#error "DEAD CODE!"
17736 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17737 SgFunctionDeclaration* functionDeclaration = functionSymbolInTargetAST->get_declaration();
17738 ROSE_ASSERT(functionDeclaration != NULL);
17739 SgScopeStatement* scope = functionDeclaration->get_scope();
17740 ROSE_ASSERT(scope != NULL);
17741
17742 // Is this the correct scope?
17743 functionDeclaration->set_scope(scope);
17744#endif
17745 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17746
17747 // Insert the symbol into the targetScope.
17748 targetScope->insert_symbol(functionSymbol_copy->get_name(),functionSymbolInTargetAST);
17749 }
17750 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17751
17752 // Reset the symbol associated with this function reference.
17753 functionRefExp_copy->set_symbol(functionSymbolInTargetAST);
17754#if 0
17755 printf ("Exiting as a test! \n");
17756 ROSE_ABORT();
17757#endif
17758 }
17759
17760 break;
17761 }
17762
17763#define DEBUG_MEMBER_FUNCTION_REF_EXP 0
17764
17765 case V_SgMemberFunctionRefExp:
17766 {
17767 // Need to handle the referenced symbol
17768 SgMemberFunctionRefExp* memberFunctionRefExp_copy = isSgMemberFunctionRefExp(node_copy);
17769 SgMemberFunctionRefExp* memberFunctionRefExp_original = isSgMemberFunctionRefExp(node_original);
17770 SgMemberFunctionSymbol* memberFunctionSymbol_copy = isSgMemberFunctionSymbol(memberFunctionRefExp_copy->get_symbol());
17771 ROSE_ASSERT(memberFunctionSymbol_copy != NULL);
17772 // if (TransformationSupport::getFile(memberFunctionSymbol) != targetFile)
17773 if (getEnclosingFileNode(memberFunctionSymbol_copy) != targetFile)
17774 {
17775 // Not implemented (initial work is focused on C, then Java, then C++.
17776#if DEBUG_MEMBER_FUNCTION_REF_EXP
17777 printf ("Warning: case V_SgMemberFunctionRefExp: memberFunctionSymbol_copy not in target file (find member function = %s) \n",memberFunctionSymbol_copy->get_name().str());
17778#endif
17779 SgMemberFunctionSymbol* memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),targetScope));
17780
17781 if (memberFunctionSymbolInTargetAST == NULL)
17782 {
17783 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
17784 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
17785 // previously added snippet.
17786#if DEBUG_MEMBER_FUNCTION_REF_EXP
17787 printf ("Error: The associated memberFunction_copy = %s should have been found in a parent scope of the target AST \n",memberFunctionSymbol_copy->get_name().str());
17788#endif
17789 // DQ (3/10/2014): This is important for member functions in Java and C++.
17790
17791 // If could be that the symbol is in the local scope of the snippet AST.
17792 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(memberFunctionRefExp_original);
17793 ROSE_ASSERT(enclosingStatement_original != NULL);
17794#if DEBUG_MEMBER_FUNCTION_REF_EXP
17795 printf ("case V_SgMemberFunctionRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
17796#endif
17797 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
17798 ROSE_ASSERT(otherPossibleScope_original != NULL);
17799 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
17800 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
17801 ROSE_ASSERT(file != NULL);
17802#if DEBUG_MEMBER_FUNCTION_REF_EXP
17803 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
17804 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
17805
17806 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
17807 printf ("case V_SgClassDeclaration: memberFunctionSymbol_copy->get_name() = %s \n",memberFunctionSymbol_copy->get_name().str());
17808#endif
17809 memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original));
17810 if (memberFunctionSymbolInTargetAST == NULL)
17811 {
17812#if DEBUG_MEMBER_FUNCTION_REF_EXP
17813 printf ("Backup and look for the associated class and then look for the member function in the class (assume non-friend function or Java member function) \n");
17814#endif
17815 // Check for the case of a record reference (member function of class declaration).
17816 SgExpression* parentExpression = isSgExpression(memberFunctionRefExp_copy->get_parent());
17817
17818 ROSE_ASSERT(parentExpression != NULL);
17819#if DEBUG_MEMBER_FUNCTION_REF_EXP
17820 printf ("parentExpression = %p = %s \n",parentExpression,parentExpression->class_name().c_str());
17821#endif
17822 bool handle_as_java = false;
17823 SgFunctionCallExp* functionCallExp = isSgFunctionCallExp(parentExpression);
17824 if (functionCallExp != NULL)
17825 {
17826 // Note that this is a Java specific organization of the SgMemberFunctionRefExp and the SgFunctionCallExp.
17827 // We might want to make this more uniform between C++ and Java later.
17828 handle_as_java = true;
17829
17830 SgExpression* parentOfFunctionCallExpression = isSgExpression(functionCallExp->get_parent());
17831
17832 ROSE_ASSERT(parentOfFunctionCallExpression != NULL);
17833#if DEBUG_MEMBER_FUNCTION_REF_EXP
17834 printf ("parentOfFunctionCallExpression = %p = %s \n",parentOfFunctionCallExpression,parentOfFunctionCallExpression->class_name().c_str());
17835#endif
17836 parentExpression = parentOfFunctionCallExpression;
17837 }
17838
17839 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
17840 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
17841 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
17842#if DEBUG_MEMBER_FUNCTION_REF_EXP
17843 printf ("parentBinaryOp = %p \n",parentBinaryOp);
17844 printf ("parentDotExp = %p \n",parentDotExp);
17845 printf ("parentArrowExp = %p \n",parentArrowExp);
17846#endif
17847 if (parentDotExp != NULL || parentArrowExp != NULL)
17848 {
17849 // This is a data member reference, so it's scope is the associated data structure.
17850 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
17851 ROSE_ASSERT(lhs != NULL);
17852
17853 // This will be true for C++, but not Java (a little odd).
17854 if (handle_as_java == true)
17855 {
17856 // The rhs is the SgFunctionCallExp for Java.
17857 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == functionCallExp);
17858 }
17859 else
17860 {
17861 // This is what we expect to be true for C++.
17862 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == memberFunctionRefExp_copy);
17863 }
17864#if DEBUG_MEMBER_FUNCTION_REF_EXP
17865 printf ("lhs = %p = %s \n",lhs,lhs->class_name().c_str());
17866#endif
17867 SgVarRefExp* varRefExp = isSgVarRefExp(lhs);
17868
17869 // DQ (3/15/2014): This can be a SgJavaTypeExpression (see testJava3a).
17870 // ROSE_ASSERT(varRefExp != NULL);
17871 if (varRefExp != NULL)
17872 {
17873 SgVariableSymbol* variableSymbol = isSgVariableSymbol(varRefExp->get_symbol());
17874 ROSE_ASSERT(variableSymbol != NULL);
17875 SgInitializedName* initializedName = variableSymbol->get_declaration();
17876 ROSE_ASSERT(initializedName != NULL);
17877
17878 SgType* initializedName_type = initializedName->get_type();
17879#if DEBUG_MEMBER_FUNCTION_REF_EXP
17880 printf ("initializedName = %p = %s \n",initializedName,initializedName->get_name().str());
17881 printf ("initializedName_type = %p \n",initializedName_type);
17882#endif
17883 SgClassType* classType = isSgClassType(initializedName_type);
17884 if (classType != NULL)
17885 {
17886 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
17887 ROSE_ASSERT(classDeclaration != NULL);
17888 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(classDeclaration->get_definingDeclaration());
17889 ROSE_ASSERT(definingClassDeclaration != NULL);
17890 printf ("definingClassDeclaration->get_name() = %s \n",definingClassDeclaration->get_name().str());
17891
17892 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
17893 ROSE_ASSERT(classDefinition != NULL);
17894 SgType* memberFunctionType = memberFunctionSymbol_copy->get_type();
17895 SgName memberFunctionName = memberFunctionSymbol_copy->get_name();
17896 ROSE_ASSERT(memberFunctionType != NULL);
17897 SgFunctionSymbol *functionSymbol = classDefinition->lookup_function_symbol(memberFunctionName,memberFunctionType);
17898 if (functionSymbol == NULL)
17899 {
17900 printf ("Symbol not found: output symbol table (size = %d): \n",classDefinition->get_symbol_table()->size());
17901#if DEBUG_MEMBER_FUNCTION_REF_EXP
17902 classDefinition->get_symbol_table()->print("Symbol not found: output symbol table: SgClassDefinition");
17903#endif
17904 // DQ (3/30/2014): If functionSymbol is not found then I think it is because the class was not availalbe
17905 // in the target where the snippet is being copied. This is an error in the constrains for how the target
17906 // must be prepared for the snippet to be copied into it.
17907 printf ("\n*************************************************************** \n");
17908 printf ("ERROR: target has not be properly setup to receive the snippet. \n");
17909 printf ("*************************************************************** \n");
17910 }
17911 ROSE_ASSERT(functionSymbol != NULL);
17912 SgMemberFunctionSymbol *memberFunctionSymbol = isSgMemberFunctionSymbol(functionSymbol);
17913 ROSE_ASSERT(memberFunctionSymbol != NULL);
17914
17915 memberFunctionSymbolInTargetAST = memberFunctionSymbol;
17916#if 0
17917 printf ("Exiting as a test! \n");
17918 ROSE_ABORT();
17919#endif
17920 }
17921 }
17922
17923 // DQ (3/30/2014): If this is a value expression then calling the member function uses a shared
17924 // symbol from the global scope (or a type defined deep in the global scope, but common to the
17925 // snippet AST and the target AST).
17926 SgValueExp* valueExp = isSgValueExp(lhs);
17927 if (valueExp != NULL)
17928 {
17929 memberFunctionSymbolInTargetAST = memberFunctionSymbol_copy;
17930 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
17931 }
17932
17933 if (memberFunctionSymbolInTargetAST == NULL)
17934 {
17935#if 1
17936 SgType* type = lhs->get_type();
17937 ROSE_ASSERT(type != NULL);
17938#if DEBUG_MEMBER_FUNCTION_REF_EXP
17939 printf ("type = %p = %s \n",type,type->class_name().c_str());
17940#endif
17941 SgNamedType* namedType = isSgNamedType(type);
17942 ROSE_ASSERT(namedType != NULL);
17943 SgDeclarationStatement* declaration = namedType->get_declaration();
17944 ROSE_ASSERT(declaration != NULL);
17945 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
17946 ROSE_ASSERT(classDeclaration != NULL);
17947 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
17948 ROSE_ASSERT(definingClassDeclaration != NULL);
17949 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
17950 ROSE_ASSERT(classDefinition != NULL);
17951#if DEBUG_MEMBER_FUNCTION_REF_EXP
17952 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
17953#endif
17954 // I think we want the copy.
17955 otherPossibleScope_original = classDefinition;
17956#if DEBUG_MEMBER_FUNCTION_REF_EXP
17957 classDefinition->get_symbol_table()->print("Java classDefinition");
17958#endif
17959#if DEBUG_MEMBER_FUNCTION_REF_EXP
17960 SgClassDeclaration* associated_classDeclaration = classDefinition->get_declaration();
17961 SgFunctionSymbol* functionSymbol = lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original);
17962 printf ("associated_classDeclaration = %p name = %s \n",associated_classDeclaration,associated_classDeclaration->get_name().str());
17963 printf ("functionSymbol = %p \n",functionSymbol);
17964#endif
17965 memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original));
17966 if (memberFunctionSymbolInTargetAST == NULL)
17967 {
17968 // Output debugging info (16 of the CWE injection test codes fail here: see test_results.txt file for details).
17969 printf ("Error: (memberFunctionSymbolInTargetAST == NULL): memberFunctionSymbol_copy->get_name() = %s \n",memberFunctionSymbol_copy->get_name().str());
17970 }
17971#endif
17972 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
17973 }
17974 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
17975 }
17976 }
17977
17978 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
17979 SgFunctionDeclaration* functionDeclaration = memberFunctionSymbolInTargetAST->get_declaration();
17980 ROSE_ASSERT(functionDeclaration != NULL);
17981 SgScopeStatement* scope = functionDeclaration->get_scope();
17982 ROSE_ASSERT(scope != NULL);
17983
17984 // Is this the correct scope?
17985 functionDeclaration->set_scope(scope);
17986 }
17987 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
17988
17989 // Reset the symbol associated with this function reference.
17990 memberFunctionRefExp_copy->set_symbol(memberFunctionSymbolInTargetAST);
17991 }
17992
17993 break;
17994 }
17995
17996 // DQ (3/21/2014): I think we need this.
17997 case V_SgTryStmt:
17998 {
17999#if 0
18000 printf ("Exiting as a test! (SgTryStmt) \n");
18001 ROSE_ABORT();
18002#endif
18003 break;
18004 }
18005
18006 // DQ (3/19/2014): Just found this case in a few of the CWE Java snippet tests.
18007 case V_SgCatchStatementSeq:
18008 {
18009 // DQ (3/19/2014): Note sure that we need to handle this specific case.
18010
18011#if 0
18012 printf ("Exiting as a test! (SgCatchStatementSeq) \n");
18013 ROSE_ABORT();
18014#endif
18015 break;
18016 }
18017
18018 // DQ (3/19/2014): Just found this case in a few of the CWE Java snippet tests.
18019 case V_SgCatchOptionStmt:
18020 {
18021 // DQ (3/19/2014): Note sure that we need to handle this specific case.
18022 // Decide if we need to implement this newly identified case tomorrow (note that this is a SgScopeStatement).
18023 SgCatchOptionStmt* catchOptionStatement_copy = isSgCatchOptionStmt(node_copy);
18024 ROSE_ASSERT(catchOptionStatement_copy);
18025
18026 printf ("Need to check the symbol table of the SgCatchOptionStmt (which is a SgScopeStatement) \n");
18027
18028#if 0
18029 printf ("Exiting as a test! (SgCatchOptionStmt) \n");
18030 ROSE_ABORT();
18031#endif
18032 break;
18033 }
18034
18035 // DQ (3/21/2014): I think we need this.
18036 case V_SgJavaPackageStatement:
18037 {
18038#if 1
18039 printf ("Exiting as a test! (SgJavaPackageStatement) \n");
18040 ROSE_ABORT();
18041#endif
18042 break;
18043 }
18044
18045 case V_SgEnumVal:
18046 {
18047 // SgEnumVal expressions contain a reference to the associated SgEnumDeclaration, so this may have to be updated.
18048#if 0
18049 printf ("enum values contain a reference to the associated SgEnumDeclaration \n");
18050#endif
18051 SgEnumVal* enumVal_copy = isSgEnumVal(node_copy);
18052 SgEnumVal* enumVal_original = isSgEnumVal(node_original);
18053#if 0
18054 printf (" --- enumVal_original = %p = %d name = %s \n",enumVal_original,enumVal_original->get_value(),enumVal_original->get_name().str());
18055#endif
18056 SgEnumDeclaration* associatedEnumDeclaration_copy = isSgEnumDeclaration(enumVal_copy->get_declaration());
18057 SgEnumDeclaration* associatedEnumDeclaration_original = isSgEnumDeclaration(enumVal_original->get_declaration());
18058
18059 // DQ (4/13/2014): check if this is an un-named enum beclaration.
18060 bool isUnNamed = associatedEnumDeclaration_original->get_isUnNamed();
18061 if (isUnNamed == false)
18062 {
18063 if (associatedEnumDeclaration_copy == associatedEnumDeclaration_original)
18064 {
18065#if 0
18066 printf (" --- The stored reference to the enum declaration in the SgEnumVal must be reset \n");
18067#endif
18068 // SgSymbol* SageBuilder::findAssociatedSymbolInTargetAST(SgDeclarationStatement* snippet_declaration, SgScopeStatement* targetScope)
18069 SgSymbol* symbol = findAssociatedSymbolInTargetAST(associatedEnumDeclaration_original,targetScope);
18070 if (symbol == NULL)
18071 {
18072 // debug this case.
18073 enumVal_original->get_file_info()->display("case V_SgEnumVal: symbol == NULL: debug");
18074 }
18075 ROSE_ASSERT(symbol != NULL);
18076 SgEnumSymbol* enumSymbol = isSgEnumSymbol(symbol);
18077 ROSE_ASSERT(enumSymbol != NULL);
18078 SgEnumDeclaration* new_associatedEnumDeclaration_copy = enumSymbol->get_declaration();
18079 ROSE_ASSERT(new_associatedEnumDeclaration_copy != NULL);
18080
18081 // If this is false then in means that we should have built a new SgEnumSymbol instead of reusing the existing one from the snippet.
18082 ROSE_ASSERT(new_associatedEnumDeclaration_copy != associatedEnumDeclaration_original);// TV (10/22/2014): with project wide global scope this will always be false because 'symbol' is resolve to the first-non-defn-decl in original scope
18083 // ROSE_ASSERT(new_associatedEnumDeclaration_copy != associatedEnumDeclaration_original->get_firstNondefiningDeclaration());
18084 ROSE_ASSERT(new_associatedEnumDeclaration_copy != associatedEnumDeclaration_original->get_definingDeclaration());
18085
18086 enumVal_copy->set_declaration(new_associatedEnumDeclaration_copy);
18087#if 0
18088 printf ("Exiting as a test! \n");
18089 ROSE_ABORT();
18090#endif
18091 }
18092 }
18093 else
18094 {
18095 // DQ (4/13/2014): I think we all agreed these would not have to be handled, so issue a warning.
18096 // It still is likely that I can allow this, but permit this intermediate fix.
18097 printf ("Warning: can't handle enum values from unnamed enum declarations \n");
18098 printf (" --- enumVal_original = %p = %lld name = %s \n",enumVal_original,enumVal_original->get_value(),enumVal_original->get_name().str());
18099 }
18100
18101 break;
18102 }
18103
18104 default:
18105 {
18106 // Most IR nodes do not require specialized fixup (are not processed).
18107 }
18108 }
18109
18110#if 1
18111 // DQ (3/17/2014): Cause failure on warnings about any constructs referencing the snippet AST.
18112#if 0
18113 // Assert fail on warnings.
18114 errorCheckingTargetAST(node_copy,node_original,targetFile, true);
18115#else
18116 // Cause only warnings.
18117 errorCheckingTargetAST(node_copy,node_original,targetFile, false);
18118#endif
18119#endif
18120 }
18121
18122
18123void
18125 SgStatement *toInsert, SgStatement* original_before_copy)
18126 {
18127 // The semantics of the copy is that it will have been disconnected from the snippet AST in a few ways,
18128 // Namely the root of the copy of the snippet's AST will have been set with a NULL parent, and then
18129 // the parent would have been reset when the copy of the snippet was inserted into the target AST.
18130 // So a simple traversal of parents back to the SgFile will return the target AST's SgFile (confirmed below).
18131
18132 ROSE_ASSERT(insertionPoint != NULL);
18133 ROSE_ASSERT(toInsert != NULL);
18134 ROSE_ASSERT(original_before_copy != NULL);
18135
18136 // DQ (3/30/2014): Turn this on to support finding symbols in base classes (in Java).
18137 // Will be turned off at the base of this function (since we only only want to use it for the AST fixup, currently).
18138 SgSymbolTable::set_force_search_of_base_classes(true);
18139
18140 // DQ (3/4/2014): Switch to using the SageInterface function.
18141 // SgFile* targetFile = TransformationSupport::getFile(insertionPoint);
18142 SgFile* targetFile = getEnclosingFileNode(insertionPoint);
18143
18144 // For Java support this might be NULL, if the insertion point was in global scope.
18145 ROSE_ASSERT(targetFile != NULL);
18146
18147 // SgFile* snippetFile_of_copy = TransformationSupport::getFile(toInsert);
18148 SgFile* snippetFile_of_copy = getEnclosingFileNode(toInsert);
18149
18150 // At this point the parent pointers are set so that the same SgFile is found via a traversal back to the SgProject.
18151 // Confirm that the SgFile found by a traversal of parents in the copy of rthe snippet's AST will return that of the
18152 // SgFile for the target AST. This also confirms that the copy of the snippet has already been inserted into the
18153 // target AST.
18154 ROSE_ASSERT(snippetFile_of_copy == targetFile);
18155
18156 // SgFile* snippetFile_of_original = TransformationSupport::getFile(original_before_copy);
18157 SgFile* snippetFile_of_original = getEnclosingFileNode(original_before_copy);
18158
18159 ROSE_ASSERT(snippetFile_of_original != targetFile);
18160
18161#if 0
18162 printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18163 printf (" --- snippetFile_of_copy = %p = %s \n",snippetFile_of_copy,snippetFile_of_copy->get_sourceFileNameWithPath().c_str());
18164 printf (" --- snippetFile_of_original = %p = %s \n",snippetFile_of_original,snippetFile_of_original->get_sourceFileNameWithPath().c_str());
18165#endif
18166
18167 // Any node that has entries not referenced in the target file needs to be fixed up.
18168 // We can assume that any referenced variable or function that is referenced in the
18169 // snippet will exist in either the snippet or the target file.
18170
18171 // DQ (3/4/2014): This is a test of the structural equality of the original snippet and it's copy.
18172 // If they are different then we can't support fixing up the AST. Transformations on the snippet
18173 // should have been made after insertion into the AST. The complexity of this test is a traversal
18174 // of the copy of the snippet to be inserted (typically very small compared to the target application).
18175 bool isStructurallyEquivalent = isStructurallyEquivalentAST(toInsert,original_before_copy);
18176 if (isStructurallyEquivalent == false)
18177 {
18178 printf ("WARNING: The copy of the snippet is a different size than the original snippet (don't do transformations on the copy before inserting into the target AST). \n");
18179 return;
18180 }
18181 ROSE_ASSERT(isStructurallyEquivalent == true);
18182
18183#ifndef USE_CMAKEx
18184 // DQ (3/8/2014): Make this conditionally compiled based on when CMake is not used because the libraries are not configured yet.
18185
18186 // This is AST container for the ROSE AST that will provide an iterator.
18187 // We want two iterators (one for the copy of the snippet and one for the
18188 // original snippet so that we can query the original snippet's AST
18189 // as we process each IR node of the AST for the copy of the snippet.
18190 // Only the copy of the snippet is inserted into the target AST.
18191 RoseAst ast_of_copy(toInsert);
18192 RoseAst ast_of_original(original_before_copy);
18193
18194 // printf ("ast_of_copy.size() = %" PRIuPTR " \n",ast_of_copy.size());
18195
18196 // Build the iterators so that we can increment thorugh both ASTs one IR node at a time.
18197 RoseAst::iterator i_copy = ast_of_copy.begin();
18198 RoseAst::iterator i_original = ast_of_original.begin();
18199
18200 // Iterate of the copy of the snippet's AST.
18201 while (i_copy != ast_of_copy.end())
18202 {
18203 // DQ (2/28/2014): This is a problem for some of the test codes (TEST store/load heap string [test7a] and [test7a])
18204 // ROSE_ASSERT((*i_copy)->variantT() == (*i_original)->variantT());
18205 if ((*i_copy)->variantT() != (*i_original)->variantT())
18206 {
18207 printf ("ERROR: return from fixupCopyOfAstFromSeparateFileInNewTargetAst(): "
18208 "(*i_copy)->variantT() != (*i_original)->variantT() \n");
18209#if 1
18210 printf ("Making this an error! \n");
18211 ROSE_ABORT();
18212#endif
18213 return;
18214 }
18215
18216 // Operate on individual IR nodes.
18217 fixupCopyOfNodeFromSeparateFileInNewTargetAst(insertionPoint, insertionPointIsScope, *i_copy, *i_original);
18218
18219 i_copy++;
18220
18221 // Verify that we have not reached the end of the ast for the original (both the
18222 // copy and the original are the same structurally, and thus the same size).
18223 ROSE_ASSERT(i_original != ast_of_original.end());
18224 i_original++;
18225 }
18226
18227 // We have reached the end of both ASTs.
18228 ROSE_ASSERT(i_copy == ast_of_copy.end() && i_original == ast_of_original.end());
18229
18230 // DQ (3/8/2014): ENDIF: Make this conditionally compiled based on when CMake is not used because the libraries are not configured yet.
18231#endif
18232
18233#if 0
18234 if (functionDeclaration != NULL)
18235 {
18236 printf ("functionDeclaration = %s \n",functionDeclaration->get_name().str());
18237#if 0
18238 printf ("Exiting as a test! \n");
18239 ROSE_ABORT();
18240#endif
18241 }
18242#endif
18243
18244 // DQ (3/30/2014): Turn this off (since we only only want to use it for the AST fixup, currently).
18245 SgSymbolTable::set_force_search_of_base_classes(false);
18246 }
18247
18248// Liao 9/18/2015
18249// The parser is implemented in
18250// src/frontend/SageIII/astFromString/AstFromString.h .C
18252{
18253
18254 SgStatement* result = NULL;
18255 ROSE_ASSERT (scope != NULL);
18256 // set input and context for the parser
18257 AstFromString::c_char = s.c_str();
18258 ROSE_ASSERT(AstFromString::c_char== s.c_str());
18261
18263 {
18264 result = isSgStatement(AstFromString::c_parsed_node); // grab the result
18265 ROSE_ASSERT(result != NULL);
18266 }
18267 else
18268 {
18269 cerr<<"Error. buildStatementFromString() cannot parse the input string:"<<s
18270 <<"\n\t within the given scope:"<<scope->class_name() <<endl;
18271 ROSE_ABORT();
18272 }
18273 return result;
18274}
18275
18285
18286//
18287// pp (07/16/16)
18288// initial support for creating template instantiations
18289// from template declarations
18290
18291namespace {
18292 // internal functions
18293
18294 template <class SgAstNode>
18295 SgTemplateArgument* createTemplateArg_(SgAstNode& n)
18296 {
18297 static const bool explicitlySpecified = true;
18298
18299 return new SgTemplateArgument(&n, explicitlySpecified);
18300 }
18301
18302 SgTemplateArgument* createTemplateArg_(SgExpression& n)
18303 {
18304 SgTemplateArgument* res = createTemplateArg_<SgExpression>(n);
18305
18306 n.set_parent(res);
18307 return res;
18308 }
18309
18310 SgTemplateArgument* createTemplateArg(SgNode& n)
18311 {
18312 SgTemplateArgument* res = NULL;
18313
18314 if (isSgType(&n))
18315 res = createTemplateArg_(*isSgType(&n));
18316 else if (isSgExpression(&n))
18317 res = createTemplateArg_(*isSgExpression(&n));
18318 else
18319 {
18320 ROSE_ASSERT(isSgTemplateDeclaration(&n));
18321 res = createTemplateArg_(*isSgTemplateDeclaration(&n));
18322 }
18323
18324 ROSE_ASSERT(res);
18325 return res;
18326 }
18327#if 0
18328 SgName genTemplateName(SgName base, Rose_STL_Container<SgNode*>& targs)
18329 {
18330 Rose_STL_Container<SgNode*>::iterator aa = targs.begin();
18331 Rose_STL_Container<SgNode*>::iterator zz = targs.begin();
18332 std::string name(base.getString());
18333
18334 name.append("<");
18335 for ( ; aa != zz; ++aa) name.append((*aa)->unparseToString());
18336 name.append(">");
18337
18338 return SgName(name);
18339 }
18340#endif
18341 SgTemplateArgumentPtrList genTemplateArgumentList(Rose_STL_Container<SgNode*>& targs)
18342 {
18343 Rose_STL_Container<SgNode*>::iterator aa = targs.begin();
18344 Rose_STL_Container<SgNode*>::iterator zz = targs.begin();
18345 SgTemplateArgumentPtrList lst;
18346
18347 for ( ; aa != zz; ++aa)
18348 {
18349 lst.push_back(createTemplateArg(**aa));
18350 }
18351
18352 return lst;
18353 }
18354
18355 SgTemplateClassDeclaration* getCanonicalTemplateDecl(SgTemplateClassDeclaration* main_decl)
18356 {
18357 ROSE_ASSERT(main_decl);
18358 SgClassType* ct = main_decl->get_type();
18359 ROSE_ASSERT(ct);
18360 SgDeclarationStatement* decl = ct->get_declaration();
18361 SgTemplateClassDeclaration* tdecl = isSgTemplateClassDeclaration(decl);
18362
18363 ROSE_ASSERT(tdecl);
18364 return tdecl;
18365 }
18366
18367 SgTemplateInstantiationDecl* genTemplateInstantiationDecl(SgName tname, SgTemplateClassDeclaration* tclassdecl, SgTemplateArgumentPtrList targs)
18368 {
18369 ROSE_ASSERT(tclassdecl);
18370
18371 SgTemplateInstantiationDecl* res = NULL;
18372
18373 res = new SgTemplateInstantiationDecl( tname,
18375 NULL /* SgClassType* type -- to be set later */,
18376 NULL /* SgClassDefinition* def -- to be set later */,
18377 tclassdecl,
18378 targs
18379 );
18380
18381 res->set_scope(tclassdecl->get_scope());
18382 res->set_templateName(tname); // \todo \pp create mangled name from tname
18384 res->setForward(); // \pp set forward, since this is not a proper declaration
18385 return res;
18386 }
18387
18388 SgClassType* genTemplateClass(SgTemplateInstantiationDecl* tdecl)
18389 {
18390 ROSE_ASSERT(tdecl);
18391
18392 return SgClassType::createType(tdecl);
18393 }
18394
18395 struct TemplateArgumentParentSetter
18396 {
18398
18399 TemplateArgumentParentSetter(SgTemplateInstantiationDecl* p)
18400 : parent(p)
18401 {}
18402
18403 void operator()(SgTemplateArgument* targ)
18404 {
18405 targ->set_parent(parent);
18406 }
18407 };
18408} /* anonymous namespace */
18409
18410
18413Rose_STL_Container<SgNode *>& template_args)
18414{
18415 return buildClassTemplateType (template_decl,template_args);
18416}
18417
18420Rose_STL_Container<SgNode *>& template_args)
18421{
18422 ROSE_ASSERT(template_decl);
18423
18424 // create a template instantiation decl
18425 SgName name = template_decl->get_name();
18426 // SgName tname = genTemplateName(, template_args);
18427 SgTemplateArgumentPtrList targs = genTemplateArgumentList(template_args);
18428 SgTemplateClassDeclaration* tdecl = getCanonicalTemplateDecl(template_decl);
18429 SgTemplateInstantiationDecl* tinst = genTemplateInstantiationDecl(name, tdecl, targs);
18430 ROSE_ASSERT(tinst);
18431
18432 // create class type
18433 SgClassType* tclass = genTemplateClass(tinst);
18434 ROSE_ASSERT(tclass);
18435
18436 // set remaining fields in the template instantiation decl
18437 tinst->set_type(tclass);
18438 tinst->set_definition(static_cast<SgTemplateInstantiationDefn*>(0)); /* \pp not sure what to set this to .. */
18439
18440 // set parent of template arguments
18441 std::for_each(targs.begin(), targs.end(), TemplateArgumentParentSetter(tinst)); //
18442
18443 return tclass;
18444}
18445
18446//-----------------------------------------------------------------------------
18447#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
18448//-----------------------------------------------------------------------------
18449
18454 ROSE_ASSERT(Rose::Frontend::Java::lengthSymbol);
18455 SgVarRefExp *var_ref = SageBuilder::buildVarRefExp(Rose::Frontend::Java::lengthSymbol);
18457 return var_ref;
18458}
18459
18464 SgScopeStatement *scope = new SgScopeStatement();
18466 if (parent_scope != NULL) {
18467 scope -> set_parent(parent_scope);
18468 }
18469 return scope;
18470}
18471
18478 return expr;
18479}
18480
18485 SgJavaMarkerAnnotation *annotation = new SgJavaMarkerAnnotation(type);
18487 return annotation;
18488}
18489
18496 pair -> set_name(name);
18497 pair -> set_value(value);
18498 value -> set_parent(pair);
18499 return pair;
18500}
18501
18506 SgJavaSingleMemberAnnotation *annotation = new SgJavaSingleMemberAnnotation(type, value);
18508 return annotation;
18509}
18510
18515 SgJavaNormalAnnotation *annotation = new SgJavaNormalAnnotation(type);
18517 return annotation;
18518}
18519
18523SgJavaNormalAnnotation *SageBuilder::buildJavaNormalAnnotation(SgType *type, list<SgJavaMemberValuePair *>& pair_list) {
18525 for (std::list<SgJavaMemberValuePair *>::iterator i = pair_list.begin(); i != pair_list.end(); i++) {
18526 SgJavaMemberValuePair *member_value_pair = *i;
18527 member_value_pair -> set_parent(annotation);
18528 annotation -> append_value_pair(member_value_pair);
18529 }
18530 return annotation;
18531}
18532
18533
18537SgInitializedName *SageBuilder::buildJavaFormalParameter(SgType *argument_type, const SgName &argument_name, bool is_var_args, bool is_final) {
18538 SgInitializedName *initialized_name = NULL;
18539 if (is_var_args) {
18540 initialized_name = SageBuilder::buildInitializedName(argument_name, SageBuilder::getUniqueJavaArrayType(argument_type, 1), NULL);
18541 initialized_name -> setAttribute("var_args", new AstRegExAttribute(""));
18542 }
18543 else {
18544 initialized_name = SageBuilder::buildInitializedName(argument_name, argument_type, NULL);
18545 }
18546 SageInterface::setSourcePosition(initialized_name);
18547 if (is_final) {
18548 initialized_name -> setAttribute("final", new AstRegExAttribute(""));
18549 }
18550
18551 return initialized_name;
18552}
18553
18558 SgJavaPackageStatement *package_statement = new SgJavaPackageStatement(package_name);
18559 SageInterface::setSourcePosition(package_statement);
18560 package_statement -> set_firstNondefiningDeclaration(package_statement);
18561 package_statement -> set_definingDeclaration(package_statement);
18562 return package_statement;
18563}
18564
18568SgJavaImportStatement *SageBuilder::buildJavaImportStatement(string import_info, bool contains_wildcard) {
18569 SgJavaImportStatement *import_statement = new SgJavaImportStatement(import_info, contains_wildcard);
18570 SageInterface::setSourcePosition(import_statement);
18571 import_statement -> set_firstNondefiningDeclaration(import_statement);
18572 import_statement -> set_definingDeclaration(import_statement);
18573 return import_statement;
18574}
18575
18580 ROSE_ASSERT(scope);
18581 SgName class_name = name;
18582 ROSE_ASSERT(scope -> lookup_class_symbol(class_name) == NULL);
18583
18584 SgClassDeclaration* nonDefiningDecl = NULL;
18585 bool buildTemplateInstantiation = false;
18586 SgTemplateArgumentPtrList* templateArgumentsList = NULL;
18587 SgClassDeclaration *class_declaration = SageBuilder::buildClassDeclaration_nfi(class_name, kind, scope, nonDefiningDecl, buildTemplateInstantiation, templateArgumentsList);
18588 ROSE_ASSERT(class_declaration);
18589 class_declaration -> set_parent(scope);
18590 class_declaration -> set_scope(scope);
18591 SageInterface::setSourcePosition(class_declaration);
18592 SgClassDefinition *class_definition = class_declaration -> get_definition();
18593 ROSE_ASSERT(class_definition);
18594 SageInterface::setSourcePosition(class_definition);
18595
18596 class_definition -> setAttribute("extensions", new AstSgNodeListAttribute());
18597 class_definition -> setAttribute("extension_type_names", new AstRegExAttribute());
18598
18599 SgScopeStatement *type_space = new SgScopeStatement();
18600 type_space -> set_parent(class_definition);
18602 class_declaration -> setAttribute("type_space", new AstSgNodeAttribute(type_space));
18603
18604 return class_declaration;
18605}
18606
18607
18612SgSourceFile *SageBuilder::buildJavaSourceFile(SgProject *project, string directory_name, SgClassDefinition *package_definition, string type_name) {
18613 string filename = directory_name + "/" + type_name + ".java";
18614 ROSE_ASSERT((*project)[filename] == NULL); // does not already exist!
18615
18616 string command = string("touch ") + filename; // create the file
18617 int status = system(command.c_str());
18618 ROSE_ASSERT(status == 0);
18619 project -> get_sourceFileNameList().push_back(filename);
18620 Rose_STL_Container<std::string> arg_list = project -> get_originalCommandLineArgumentList();
18621 arg_list.push_back(filename);
18622 Rose_STL_Container<string> fileList = CommandlineProcessing::generateSourceFilenames(arg_list, // binaryMode
18623 false);
18624 CommandlineProcessing::removeAllFileNamesExcept(arg_list, fileList, filename);
18625 int error_code = 0;
18626 SgFile *file = determineFileType(arg_list, error_code, project);
18627 SgSourceFile *sourcefile = isSgSourceFile(file);
18628 ROSE_ASSERT(sourcefile);
18629 sourcefile -> set_parent(project);
18630 project -> get_fileList_ptr() -> get_listOfFiles().push_back(sourcefile);
18631 ROSE_ASSERT(sourcefile == isSgSourceFile((*project)[filename]));
18632
18633 //
18634 // Create a package statement and add it to the source file
18635 //
18636 SgClassDeclaration* pkgDefDecl = package_definition->get_declaration();
18637 ROSE_ASSERT(pkgDefDecl != NULL);
18638 SgJavaPackageStatement *package_statement = SageBuilder::buildJavaPackageStatement(pkgDefDecl->get_qualified_name().getString());
18639 package_statement->set_parent(package_definition);
18640 sourcefile->set_package(package_statement);
18641
18642 //
18643 // Initialize an import-list for the sourcefile
18644 //
18645 SgJavaImportStatementList *import_statement_list = new SgJavaImportStatementList();
18646 import_statement_list -> set_parent(sourcefile);
18647 sourcefile -> set_import_list(import_statement_list);
18648
18649 //
18650 // Initialize a class-declaration-list for the sourcefile
18651 //
18652 SgJavaClassDeclarationList *class_declaration_list = new SgJavaClassDeclarationList();
18653 class_declaration_list -> set_parent(package_definition);
18654 sourcefile -> set_class_list(class_declaration_list);
18655
18656 return sourcefile;
18657}
18658
18659
18663SgArrayType *SageBuilder::getUniqueJavaArrayType(SgType *base_type, int num_dimensions) {
18664 ROSE_ASSERT(num_dimensions > 0);
18665 if (num_dimensions > 1) {
18666 base_type = getUniqueJavaArrayType(base_type, num_dimensions - 1);
18667 }
18668
18669 ROSE_ASSERT(base_type != NULL);
18670 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) base_type -> getAttribute("array");
18671 if (attribute == NULL) {
18672 SgArrayType *array_type = SageBuilder::buildArrayType(base_type);
18673 array_type -> set_rank(num_dimensions);
18674 attribute = new AstSgNodeAttribute(array_type);
18675 base_type -> setAttribute("array", attribute);
18676 }
18677
18678 return isSgArrayType(attribute -> getNode());
18679}
18680
18681
18685SgJavaParameterizedType *SageBuilder::getUniqueJavaParameterizedType(SgNamedType *generic_type, SgTemplateParameterPtrList *new_args) {
18686 AstParameterizedTypeAttribute *attribute = (AstParameterizedTypeAttribute *) generic_type -> getAttribute("parameterized types");
18687 if (! attribute) {
18688 attribute = new AstParameterizedTypeAttribute(generic_type);
18689 generic_type -> setAttribute("parameterized types", attribute);
18690 }
18691 ROSE_ASSERT(attribute);
18692
18693 return attribute -> findOrInsertParameterizedType(new_args);
18694}
18695
18696
18701 AstSgNodeListAttribute *attribute = (AstSgNodeListAttribute *) type -> getAttribute("qualified types");
18702 if (! attribute) {
18703 attribute = new AstSgNodeListAttribute();
18704 type -> setAttribute("qualified types", attribute);
18705 }
18706 ROSE_ASSERT(attribute);
18707
18708 for (int i = 0; i < attribute -> size(); i++) {
18709 SgJavaQualifiedType *qualified_type = isSgJavaQualifiedType(attribute -> getNode(i));
18710 ROSE_ASSERT(qualified_type);
18711 if (qualified_type -> get_parent_type() == parent_type && qualified_type -> get_type() == type) {
18712 return qualified_type;
18713 }
18714 }
18715
18716 SgJavaQualifiedType *qualified_type = new SgJavaQualifiedType(class_declaration);
18717 qualified_type -> set_parent_type(parent_type);
18718 qualified_type -> set_type(type);
18719
18720 attribute -> addNode(qualified_type);
18721
18722 return qualified_type;
18723}
18724
18725
18731 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) Rose::Frontend::Java::ObjectClassType -> getAttribute("unbound");
18732 if (! attribute) {
18733 SgClassDeclaration *class_declaration = isSgClassDeclaration(Rose::Frontend::Java::ObjectClassType -> get_declaration());
18734 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration());
18735 attribute = new AstSgNodeAttribute(wildcard);
18736 Rose::Frontend::Java::ObjectClassType -> setAttribute("unbound", attribute);
18737 }
18738
18739 return isSgJavaWildcardType(attribute -> getNode());
18740}
18741
18742
18747 ROSE_ASSERT(type);
18748 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) type -> getAttribute("extends");
18749 if (! attribute) {
18750 SgArrayType *array_type = isSgArrayType(type);
18751 SgNamedType *named_type = isSgNamedType(type);
18752 ROSE_ASSERT(array_type || named_type);
18753 SgClassDeclaration *class_declaration = isSgClassDeclaration((array_type ? (SgNamedType *) Rose::Frontend::Java::ObjectClassType : named_type) -> get_declaration());
18754 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration(), type);
18755
18756 wildcard -> set_has_extends(true);
18757
18758 attribute = new AstSgNodeAttribute(wildcard);
18759 type -> setAttribute("extends", attribute);
18760 }
18761
18762 return isSgJavaWildcardType(attribute -> getNode());
18763}
18764
18765
18770 ROSE_ASSERT(type);
18771 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) type -> getAttribute("super");
18772 if (! attribute) {
18773 SgArrayType *array_type = isSgArrayType(type);
18774 SgNamedType *named_type = isSgNamedType(type);
18775 ROSE_ASSERT(array_type || named_type);
18776 SgClassDeclaration *class_declaration = isSgClassDeclaration((array_type ? (SgNamedType *) Rose::Frontend::Java::ObjectClassType : named_type) -> get_declaration());
18777 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration(), type);
18778
18779 wildcard -> set_has_super(true);
18780
18781 attribute = new AstSgNodeAttribute(wildcard);
18782 type -> setAttribute("super", attribute);
18783 }
18784
18785 return isSgJavaWildcardType(attribute -> getNode());
18786}
18787
18788
18789//-----------------------------------------------------------------------------
18790#endif // ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
18791//-----------------------------------------------------------------------------
18792
18793
18794namespace Rose {
18795 namespace Builder {
18796 namespace Templates {
18797
18798SgTemplateArgument * buildTemplateArgument(SgType * t) {
18799 if (t == nullptr) return nullptr;
18800 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::type_argument, false, t, nullptr, nullptr);
18801 return r;
18802}
18803
18804SgTemplateArgument * buildTemplateArgument(SgExpression * e) {
18805 if (e == nullptr) return nullptr;
18806 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
18807 e->set_parent(r);
18808 return r;
18809}
18810
18811SgTemplateArgument * buildTemplateArgument(int v) {
18813 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
18814 e->set_parent(r);
18815 return r;
18816}
18817
18818SgTemplateArgument * buildTemplateArgument(bool v) {
18820 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
18821 e->set_parent(r);
18822 return r;
18823}
18824
18825std::string strTemplateArgument(int v) {
18826 std::ostringstream oss;
18827 oss << v;
18828 return oss.str();
18829}
18830
18831std::string strTemplateArgument(bool v) {
18832 std::ostringstream oss;
18833 if (v) oss << "true";
18834 else oss << "false";
18835 return oss.str();
18836}
18837
18838std::string strTemplateArgument(SgNamedType * nt) {
18839 std::ostringstream oss;
18840 oss << nt->get_qualified_name().getString();
18841 return oss.str();
18842}
18843
18844std::string strTemplateArgument(SgType * t) {
18845 std::ostringstream oss;
18846 oss << t->unparseToString();
18847 return oss.str();
18848}
18849
18850std::string strTemplateArgument(SgExpression * e) {
18851 std::ostringstream oss;
18852 oss << e->unparseToString();
18853 return oss.str();
18854}
18855
18856#define DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps 0
18857
18858SgExpression * instantiateNonrealRefExps(
18859 SgExpression * expr,
18860 std::vector<std::vector<SgTemplateParameter *>> & tpl_params,
18861 std::vector<std::vector<SgTemplateArgument *>> & tpl_args
18862) {
18863#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18864 std::cout << "Rose::Builder::Templates::instantiateNonrealRefExps" << std::endl;
18865 std::cout << " expr = " << std::hex << expr << " : " << ( expr ? expr->class_name() : "" ) << std::endl;
18866 std::cout << " = " << ( expr ? expr->unparseToString() : "" ) << std::endl;
18867#endif
18868 if (!expr) {
18869 return nullptr;
18870 } else if (isSgNonrealRefExp(expr)) {
18871#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18872 std::cerr << "Error: In instantiateNonrealRefExps: case of a SgNonrealRefExp!!!" << std::endl;
18873#endif
18874 return nullptr;
18875 } else if (isSgVarRefExp(expr)) {
18876 SgVarRefExp * vref = (SgVarRefExp*)expr;
18877 SgInitializedName * iname = vref->get_symbol()->get_declaration();
18878 ROSE_ASSERT(iname);
18879#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18880 std::cout << " iname = " << std::hex << iname << " : " << ( iname ? iname->class_name() : "" ) << std::endl;
18881 std::cout << " iname->get_name() = " << iname->get_name() << std::endl;
18882 std::cout << " iname->get_initializer() = " << std::hex << iname->get_initializer() << " : " << ( iname->get_initializer() ? iname->get_initializer()->class_name() : "" ) << std::endl;
18883 std::cout << " iname->get_parent() = " << std::hex << iname->get_parent() << " : " << ( iname->get_parent() ? iname->get_parent()->class_name() : "" ) << std::endl;
18884#endif
18885
18886 unsigned depth = 0;
18887 unsigned pos = 0;
18888 for (auto tpl_params_: tpl_params) {
18889 pos = 0;
18890 for (auto tpl_param: tpl_params_) {
18891 if (tpl_param->get_initializedName()) {
18892#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18893 std::cout << " tpl_param->get_initializedName() = " << std::hex << tpl_param->get_initializedName() << std::endl;
18894 std::cout << " tpl_param->get_initializedName()->get_name() = " << tpl_param->get_initializedName()->get_name() << std::endl;
18895#endif
18896 if (tpl_param->get_initializedName()->get_name() == iname->get_name()) {
18897 iname = tpl_param->get_initializedName();
18898 break;
18899 }
18900 }
18901 pos++;
18902 }
18903 depth++;
18904 }
18905
18906 if (depth < tpl_args.size() && pos < tpl_args[depth].size()) {
18907 SgExpression * res = tpl_args[depth][pos]->get_expression();
18908 ROSE_ASSERT(res);
18909 return res;
18910 } else if (depth < tpl_params.size() && pos < tpl_params[depth].size()) {
18911 SgExpression * dft = tpl_params[depth][pos]->get_defaultExpressionParameter();
18912 ROSE_ASSERT(dft);
18913 dft = instantiateNonrealRefExps(dft, tpl_params, tpl_args);
18914 ROSE_ASSERT(dft);
18915 return dft;
18916 }
18917#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18918 std::cerr << "Error: In instantiateNonrealRefExps: this should not be reached!!!" << std::endl;
18919#endif
18920 return vref;
18921 } else if (isSgValueExp(expr)) {
18922 return expr;
18923 } else if (isSgConditionalExp(expr)) {
18924 SgConditionalExp * cond = (SgConditionalExp*)expr;
18925 cond->set_conditional_exp(instantiateNonrealRefExps(cond->get_conditional_exp(), tpl_params, tpl_args));
18926 cond->set_true_exp(instantiateNonrealRefExps(cond->get_true_exp(), tpl_params, tpl_args));
18927 cond->set_false_exp(instantiateNonrealRefExps(cond->get_false_exp(), tpl_params, tpl_args));
18928 return cond;
18929 } else if (isSgSizeOfOp(expr)) {
18930 SgSizeOfOp * szo = (SgSizeOfOp*)expr;
18931#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18932 std::cout << " szo->get_operand_expr() = " << std::hex << szo->get_operand_expr() << " : " << ( szo->get_operand_expr() ? szo->get_operand_expr()->class_name() : "" ) << std::endl;
18933 std::cout << " szo->get_operand_type() = " << std::hex << szo->get_operand_type() << " : " << ( szo->get_operand_type() ? szo->get_operand_type()->class_name() : "" ) << std::endl;
18934#endif
18935 SgExpression * eres = instantiateNonrealRefExps(szo->get_operand_expr(), tpl_params, tpl_args);
18936 ROSE_ASSERT(szo->get_operand_expr() == nullptr || eres != nullptr);
18937 szo->set_operand_expr(eres);
18938
18939 SgType * tres = instantiateNonrealTypes(szo->get_operand_type(), tpl_params, tpl_args);
18940 ROSE_ASSERT(szo->get_operand_type() == nullptr || tres != nullptr);
18941 szo->set_operand_type(tres);
18942
18943#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18944 std::cout << " szo->get_operand_expr() = " << std::hex << szo->get_operand_expr() << " : " << ( szo->get_operand_expr() ? szo->get_operand_expr()->class_name() : "" ) << std::endl;
18945 std::cout << " szo->get_operand_type() = " << std::hex << szo->get_operand_type() << " : " << ( szo->get_operand_type() ? szo->get_operand_type()->class_name() : "" ) << std::endl;
18946#endif
18947 return szo;
18948 } else if (isSgCastExp(expr)) {
18949 SgCastExp * cast = (SgCastExp*)expr;
18950 auto operand = instantiateNonrealRefExps(cast->get_operand_i(), tpl_params, tpl_args);
18951 if (operand == nullptr) return nullptr;
18952 auto type = instantiateNonrealTypes(cast->get_type(), tpl_params, tpl_args);
18953 if (type == nullptr) return operand;
18954 cast->set_operand_i(operand);
18955 cast->set_type(type);
18956 return cast;
18957 } else if (isSgUnaryOp(expr)) {
18958 SgUnaryOp * uop = (SgUnaryOp*)expr;
18959 uop->set_operand_i(instantiateNonrealRefExps(uop->get_operand_i(), tpl_params, tpl_args));
18960 return uop;
18961 } else if (isSgBinaryOp(expr)) {
18962 SgBinaryOp * bop = (SgBinaryOp*)expr;
18963 bop->set_lhs_operand_i(instantiateNonrealRefExps(bop->get_lhs_operand_i(), tpl_params, tpl_args));
18964 bop->set_rhs_operand_i(instantiateNonrealRefExps(bop->get_rhs_operand_i(), tpl_params, tpl_args));
18965 return bop;
18966 } else {
18967 std::cerr << "!!! expr = " << std::hex << expr << " : " << ( expr ? expr->class_name() : "" ) << std::endl;
18968 ROSE_ABORT();
18969 }
18970}
18971
18972SgExpression * instantiateNonrealRefExps(
18973 SgExpression * expr,
18974 std::vector<SgTemplateParameter *> & tpl_params,
18975 std::vector<SgTemplateArgument *> & tpl_args
18976) {
18977 std::vector<std::vector<SgTemplateParameter *>> tpl_params_{tpl_params};
18978 std::vector<std::vector<SgTemplateArgument *>> tpl_args_{tpl_args};
18979 return instantiateNonrealRefExps(expr, tpl_params_, tpl_args_);
18980}
18981
18982#define DEBUG_Rose_Builder_Templates_instantiateNonrealTypes 0
18983
18984SgType * instantiateNonrealTypes(
18985 SgType * type,
18986 std::vector<std::vector<SgTemplateParameter *>> & tpl_params,
18987 std::vector<std::vector<SgTemplateArgument *>> & tpl_args
18988) {
18989#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
18990 std::cout << "Rose::Builder::Templates::instantiateNonrealTypes" << std::endl;
18991 std::cout << " type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
18992 std::cout << " = " << ( type ? type->unparseToString() : "" ) << std::endl;
18993#endif
18994 if (!type) {
18995 return nullptr;
18996 } else if (isSgNonrealType(type)) {
18997 SgNonrealType * nrtype = (SgNonrealType*)type;
18998 SgNonrealDecl * nrdecl = isSgNonrealDecl(nrtype->get_declaration());
18999 ROSE_ASSERT(nrdecl != nullptr);
19000#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19001 std::cout << " nrdecl = " << std::hex << nrdecl << " : " << nrdecl->class_name() << std::endl;
19002 std::cout << " ->get_qualified_name() = " << nrdecl->get_qualified_name().getString() << std::endl;
19003// std::cout << " ->unparseToString() = " << nrdecl->unparseToString() << std::endl;
19004 std::cout << " ->get_tpl_args() = " << std::dec << nrdecl->get_tpl_args().size() << std::endl;
19005 std::cout << " ->get_tpl_params() = " << std::dec << nrdecl->get_tpl_params().size() << std::endl;
19006 std::cout << " ->get_is_class_member() = " << ( nrdecl->get_is_class_member() ? "true" : "false" ) << std::endl;
19007 std::cout << " ->get_is_template_param() = " << ( nrdecl->get_is_template_param() ? "true" : "false" ) << std::endl;
19008 std::cout << " ->get_is_template_template_param() = " << ( nrdecl->get_is_template_template_param() ? "true" : "false" ) << std::endl;
19009 std::cout << " ->get_is_nonreal_template() = " << ( nrdecl->get_is_nonreal_template() ? "true" : "false" ) << std::endl;
19010 std::cout << " ->get_is_nonreal_function() = " << ( nrdecl->get_is_nonreal_function() ? "true" : "false" ) << std::endl;
19011#endif
19012 SgDeclarationStatement * tpldecl = nrdecl->get_templateDeclaration();
19013 if (tpldecl != nullptr) {
19014#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19015 std::cout << " tpldecl = " << std::hex << tpldecl << " : " << tpldecl->class_name() << std::endl;
19016#endif
19017
19018 SgTemplateClassDeclaration * xtpldecl = isSgTemplateClassDeclaration(tpldecl);
19019 if (xtpldecl != nullptr) {
19020#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19021 std::cout << " xtpldecl->get_name() = " << xtpldecl->get_name() << std::endl;
19022#endif
19023 std::vector<SgTemplateArgument *> inst_tpl_args;
19024 for (SgTemplateArgument * tplarg: nrdecl->get_tpl_args()) {
19025#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19026 std::cout << " tplarg = " << std::hex << tplarg << " : " << ( tplarg ? tplarg->class_name() : "" ) << std::endl;
19027 std::cout << " ->get_argumentType() = " << tplarg->get_argumentType() << std::endl;
19028#endif
19029 switch (tplarg->get_argumentType()) {
19031#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19032 std::cout << " tplarg->get_type() = " << std::hex << tplarg->get_type() << " : " << ( tplarg->get_type() ? tplarg->get_type()->class_name() : "" ) << std::endl;
19033#endif
19034 auto inst_tplarg = instantiateNonrealTypes(tplarg->get_type(), tpl_params, tpl_args);
19035 if (inst_tplarg)
19036 inst_tpl_args.push_back(buildTemplateArgument(inst_tplarg));
19037 break;
19038 }
19040#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19041 std::cout << " tplarg->get_expression() = " << std::hex << tplarg->get_expression() << " : " << ( tplarg->get_expression() ? tplarg->get_expression()->class_name() : "" ) << std::endl;
19042 std::cout << " ->unparseToString() = " << tplarg->get_expression()->unparseToString() << std::endl;
19043#endif
19044 auto inst_tplarg = instantiateNonrealRefExps(SageInterface::copyExpression(tplarg->get_expression()), tpl_params, tpl_args);
19045#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19046 std::cout << " inst_tplarg = " << std::hex << inst_tplarg << " : " << ( inst_tplarg ? inst_tplarg->class_name() : "" ) << std::endl;
19047 std::cout << " inst_tplarg->unparseToString() = " << ( inst_tplarg ? inst_tplarg->unparseToString() : "" ) << std::endl;
19048#endif
19049 if (inst_tplarg)
19050 inst_tpl_args.push_back(buildTemplateArgument(inst_tplarg));
19051 break;
19052 }
19054#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19055 std::cout << " tplarg->get_templateDeclaration() = " << std::hex << tplarg->get_templateDeclaration() << " : " << ( tplarg->get_templateDeclaration() ? tplarg->get_templateDeclaration()->class_name() : "" ) << std::endl;
19056#endif
19057 ROSE_ABORT(); // TODO
19058 }
19060#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19061 std::cout << " start_of_pack_expansion_argument" << std::endl;
19062#endif
19063 break; // NOP
19064 }
19065 default: ROSE_ABORT();
19066 }
19067 }
19068 SgTemplateInstantiationDecl * inst_decl = isSgTemplateInstantiationDecl(SageBuilder::buildClassDeclaration_nfi(
19069 xtpldecl->get_name(), SgClassDeclaration::e_struct, xtpldecl->get_scope(), nullptr, true, &inst_tpl_args
19070 ));
19071 ROSE_ASSERT(inst_decl);
19072#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19073 std::cout << " inst_decl = " << std::hex << inst_decl << " : " << inst_decl->class_name() << std::endl;
19074 std::cout << " inst_decl->get_firstNondefiningDeclaration() = " << std::hex << inst_decl->get_firstNondefiningDeclaration() << std::endl;
19075 std::cout << " inst_decl->get_definingDeclaration() = " << std::hex << inst_decl->get_definingDeclaration() << std::endl;
19076#endif
19077 ROSE_ASSERT(inst_decl->get_definingDeclaration());
19078 ROSE_ASSERT(inst_decl->get_definingDeclaration() == inst_decl);
19079 inst_decl->set_templateDeclaration(xtpldecl);
19080 ((SgTemplateInstantiationDecl *)(inst_decl->get_firstNondefiningDeclaration()))->set_templateDeclaration(xtpldecl);
19081
19082 for (auto inst_tpl_arg: inst_tpl_args) {
19083 inst_tpl_arg->set_parent(inst_decl);
19084 }
19085
19086 xtpldecl->get_scope()->append_statement(inst_decl);
19087 return inst_decl->get_type();
19088 } else {
19089 ROSE_ABORT(); // TODO probably typedef
19090 }
19091 } else if (nrdecl->get_is_template_param()) {
19092 auto depth = nrdecl->get_template_parameter_depth();
19093 auto position = nrdecl->get_template_parameter_position();
19094#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19095 std::cout << " ->get_template_parameter_position() = " << std::dec << position << std::endl;
19096 std::cout << " ->get_template_parameter_depth() = " << std::dec << depth << std::endl;
19097#endif
19098 ROSE_ASSERT(depth > 0);
19099 ROSE_ASSERT(position > 0);
19100 if (std::size_t(depth) <= tpl_args.size() && std::size_t(position) <= tpl_args[depth-1].size()) {
19101 SgType * res = tpl_args[depth-1][position-1]->get_type();
19102#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19103 std::cout << " tpl_args[" << std::dec << depth-1 << "][" << std::dec << position-1 << "]->get_type() = " << std::dec << res << std::endl;
19104#endif
19105 return res;
19106 } else if (std::size_t(depth) <= tpl_params.size() && std::size_t(position) <= tpl_params[depth-1].size()) {
19107 SgType * dft_tpl_arg = tpl_params[depth-1][position-1]->get_defaultTypeParameter();
19108#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19109 std::cout << " tpl_params[" << std::dec << depth-1 << "][" << std::dec << position-1 << "]->get_type() = " << std::dec << dft_tpl_arg << std::endl;
19110#endif
19111 dft_tpl_arg = instantiateNonrealTypes(dft_tpl_arg, tpl_params, tpl_args);
19112#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19113 std::cout << " dft_tpl_arg = " << std::dec << dft_tpl_arg << std::endl;
19114#endif
19115 return dft_tpl_arg;
19116 } else {
19117 return nullptr;
19118 }
19119 } else if (nrdecl->get_is_class_member()) {
19120#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19121 std::cout << " Case of a non-real class member will return INT." << std::endl;
19122#endif
19123 // TODO case such as "template <unsigned depth=0> static constexpr typename range_at_depth_t<depth>::Base ub;"
19124 // -> retrieve parent type
19125 // -> instantiate parent type
19126 // -> lookup member(s) in original parent type
19127 // -> instantiate (matching) member inside instantiated parent type
19128
19130 } else {
19131 ROSE_ABORT();
19132 }
19133 } else if (isSgTypeVoid(type) || isSgTypeUnsignedLong(type) || isSgTypeInt(type) || isSgTypeLong(type) || isSgTypeUnsignedInt(type) || isSgTypedefType(type) || isSgClassType(type)) {
19134 return type;
19135 } else if (isSgModifierType(type)) {
19136 SgModifierType * mtype = (SgModifierType *)type;
19137 SgType * btype = mtype->get_base_type();
19138 ROSE_ASSERT(btype != nullptr);
19140 ROSE_ASSERT(rtype != nullptr);
19141 rtype->get_typeModifier() = mtype->get_typeModifier();
19142 return rtype;
19143 } else {
19144 std::cerr << "!!! type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
19145 ROSE_ABORT(); // TODO maybe pointer/reference
19146 }
19147 return nullptr;
19148}
19149
19150SgType * instantiateNonrealTypes(
19151 SgType * type,
19152 std::vector<SgTemplateParameter *> & tpl_params,
19153 std::vector<SgTemplateArgument *> & tpl_args
19154) {
19155 std::vector<std::vector<SgTemplateParameter *>> tpl_params_{tpl_params};
19156 std::vector<std::vector<SgTemplateArgument *>> tpl_args_{tpl_args};
19157 return instantiateNonrealTypes(type, tpl_params_, tpl_args_);
19158}
19159
19160} } }
to specify a construct using a specifier Can be used alone or with parent handles when relative speci...
Users should provide a concrete node implementation especially a constructor/builder to avoid duplica...
Attribute containing a regex expression as a string.
Attribute storing an SgNode.
Class for traversing the AST.
virtual void visit(SgNode *astNode)=0
this method is called at every traversed node.
For preprocessing information including source comments, include , if, define, etc.
RelativePositionType
MK: Enum type to store if the directive goes before or after the corresponding line of source code.
AST iterator.
Definition RoseAst.h:54
Interface for iterating over an AST.
Definition RoseAst.h:26
iterator begin()
Iterator positioned at root of subtree.
iterator end()
Iterator positioned at the end of the traversal.
Collection of streams.
Definition Message.h:1606
std::string comment() const
Property: Comment associated with facility.
This class represents the concept of a C Assembler statement.
This class represents the rhs of a variable declaration which includes an optional assignment (e....
This class represents the concept of a block (not a basic block from control flow analysis).
This class represents the notion of a binary operator. It is derived from a SgExpression because oper...
void set_rhs_operand_i(SgExpression *rhs_operand_i)
This function allows the p_rhs_operand_i pointer to be set (used internally).
SgExpression * get_lhs_operand() const
returns SgExpression pointer to the lhs operand associated with this binary operator.
SgExpression * get_rhs_operand_i() const
returns SgExpression pointer to the operand associated with this binary operator.
SgExpression * get_lhs_operand_i() const
returns SgExpression pointer to the operand associated with this binary operator.
void set_lhs_operand_i(SgExpression *lhs_operand_i)
This function allows the p_lhs_operand_i pointer to be set (used internally).
SgExpression * get_rhs_operand() const
returns SgExpression pointer to the rhs operand associated with this binary operator.
This class represents a boolean value (expression value).
This class represents the notion of a break statement (typically used in a switch statment).
This class represents the concept of a C and C++ case option (used within a switch statement).
This class represents a cast of one type to another.
cast_type_enum
Classification of Casts.
SgType * get_type() const override
unparsing support for pragmas
This class represents the concept of a catch within a try-catch construct used in C++ exception handl...
This class represents the concept of a C++ sequence of catch statements.
This class represents the concept of a class declaration statement. It includes the concept of an ins...
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
virtual std::string class_name() const override
returns a string representing the class name
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
SgScopeStatement * get_scope() const override
Returns scope of current statement.
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the concept of a class definition in C++.
SgClassDeclaration * get_declaration() const
returns the class declaration associated with this class decinition.
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a C++ expression built from a class name.
This class represents the concept of a class name within the compiler.
virtual std::string class_name() const override
returns a string representing the class name
SgType * get_type() const override
This function returns the type associated with the named entity.
virtual std::string class_name() const override
returns a string representing the class name
virtual SgName get_mangled(void) const override
Mangled name support for unparser support.
SgName get_name() const override
Support for some classes which have pure virtual function in base classes.
static SgClassType * createType(SgDeclarationStatement *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgClassType (types whose constructors take par...
This class represents the concept of a C trinary conditional expression (e.g. "test ?...
SgExpression * get_true_exp() const
Access function for p_true_exp.
void set_false_exp(SgExpression *false_exp)
Access function for p_false_exp.
SgExpression * get_conditional_exp() const
Access function for p_conditional_exp.
SgExpression * get_false_exp() const
Access function for p_false_exp.
void set_true_exp(SgExpression *true_exp)
Access function for p_true_exp.
void set_conditional_exp(SgExpression *conditional_exp)
Access function for p_conditional_exp.
cv_modifier_enum
Const Volatile Modifier.
This class represents the call of a class constructor to initialize a variable. For example "Foo foo;...
This class represents the concept of a C or C++ continue statement.
This class represents the concept of a contructor initializer list (used in constructor (member funct...
static SgDeclType * createType(SgExpression *expr=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgDeclType (types whose constructors take para...
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a declaration statement.
SgSymbol * search_for_symbol_from_symbol_table() const
User interface for retrieving the associated symbol from the declaration.
void set_definingDeclaration(SgDeclarationStatement *definingDeclaration)
This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see tha...
void set_firstNondefiningDeclaration(SgDeclarationStatement *firstNondefiningDeclaration)
This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member ...
SgDeclarationStatement * get_definingDeclaration() const
This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see tha...
virtual VariantT variantT() const override
returns new style SageIII enum values
virtual std::string class_name() const override
returns a string representing the class name
SgDeclarationStatement * get_firstNondefiningDeclaration() const
This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member ...
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
void setForward()
Marks a declaration as a forward declaration.
This class represents the concept of a C or C++ default case within a switch statement.
This class represents the concept of a C++ call to the delete operator.
This class represents the concept of a do-while statement.
SgStatement * get_condition() const
Access function for p_condition.
SgStatement * get_body() const
Access function for p_body.
void set_condition(SgStatement *condition)
Access function for p_condition.
void set_body(SgStatement *body)
Access function for p_body.
This class represents the notion of an value (expression value).
This class represents the concept of an enum declaration.
void set_type(SgEnumType *type)
Access function for p_type.
SgScopeStatement * get_scope() const override
Access function for p_scope.
SgName get_name() const
Access function for p_name.
void set_scope(SgScopeStatement *scope) override
Access function for p_scope.
SgEnumType * get_type() const
Access function for p_type.
SgType * get_type() const override
This function returns the type associated with the named entity.
This class represents the concept of the dynamic execution of a string, file, or code object....
This class represents the concept of a C and C++ expression list.
This class represents the concept of a C or C++ statement which contains a expression.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes,...
virtual std::string class_name() const override
returns a string representing the class name
void set_need_paren(bool need_paren)
This function allows the p_need_paren flag to be set (used internally).
virtual SgType * get_type() const
unparsing support for pragmas
bool hasExplicitType()
Some expressions store internal SgType pointers explicitly while others compute them from other expre...
virtual Sg_File_Info * get_file_info(void) const override
Interface function to implement original SAGE interface to SgFile_Info objects.
void set_lvalue(bool lvalue)
This function allows the p_lvalue flag to be set (used internally).
void set_explicitly_stored_type(SgType *type)
Some expressions store internal SgType pointers explicitly, this allows these IR nodes to be reset wi...
This class represents a source file for a project (which may contian many source files and or directo...
Sg_File_Info * get_startOfConstruct() const override
New function interface for Sg_File_Info data stores starting location of contruct (typically the open...
void secondaryPassOverSourceFile()
Fixups to be run when the whole project has been created (this attaches preprocessing information).
@ e_Fortran_language
std::string getFileName() const
associated filename
virtual std::string class_name() const override
returns a string representing the class name
Sg_File_Info * get_file_info() const override
Access function calling get_startOfConstruct(), provided to support older interface.
This class represents the notion of an value (expression value).
This class represents the variable declaration or variable initialization withn a for loop.
const SgStatementPtrList & get_init_stmt() const
Returns const reference to a SgStatementPtrList (typedef to a STL list).
This class represents the concept of a for loop.
SgForInitStatement * get_for_init_stmt() const
Access function for p_for_init_stmt.
void set_loop_body(SgStatement *loop_body)
Access function for p_loop_body.
SgStatement * get_loop_body() const
Access function for p_loop_body.
void set_for_init_stmt(SgForInitStatement *for_init_stmt)
Access function for p_for_init_stmt.
This class represents the concept of a C++ function call (which is an expression).
This class represents the concept of a function declaration statement.
SgScopeStatement * get_scope() const override
Returns scope of current statement.
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
void set_body(SgBasicBlock *body)
Access function for p_body.
This class represents the concept of a declaration list.
const SgInitializedNamePtrList & get_args() const
Access function for p_args.
const SgTypePtrList & get_arguments() const
Get a const list of input types (types of the parameters list) to this function type (from a cost fun...
This class represents the function being called and must be assembled in the SgFunctionCall with the ...
SgType * get_type() const override
Get the type associated with this expression.
virtual std::string class_name() const override
returns a string representing the class name
SgName get_name() const override
Access function for getting name from declarations or types internally.
This class represents the function type table (stores all function types so that they can be shared i...
This class represents a type for all functions.
virtual std::string class_name() const override
returns a string representing the class name
virtual SgName get_mangled(void) const override
Mangled name support for unparser support.
This class represents the concept of a namespace definition.
virtual std::string class_name() const override
returns a string representing the class name
const SgDeclarationStatementPtrList & get_declarations() const
Returns a const list to the global scope declarations.
This class represents the concept of a C or C++ goto statement.
This class represents the concept of an "if" construct.
void set_use_then_keyword(bool use_then_keyword)
Fortran specific function to indicate if the Fortran "if" statement uses the "then" construct (C/C++ ...
void set_has_end_statement(bool has_end_statement)
Fortran specific function to indicate if the Fortran "if" statement has an "end" construct (C/C++ use...
This class represents the notion of a declared variable.
SgName get_qualified_name() const
Returns the name with appropriate qualified names representing nested scopes.
SgSymbol * get_symbol_from_symbol_table() const
Get the associated SgSymbol from the symbol table located in the scope, without considering possible ...
virtual std::string class_name() const override
returns a string representing the class name
SgSymbol * search_for_symbol_from_symbol_table() const
User interface for retrieving the associated symbol. It searches through the possible chain of prev_d...
This class represents the notion of an initializer for a variable declaration or expression in a func...
virtual std::string class_name() const override
returns a string representing the class name
static SgJavaParameterType * createType(SgClassDeclaration *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgJavaParameterType (types whose constructors ...
static SgJovialBitType * createType(SgExpression *size=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgJovialBitType (types whose constructors take...
static SgJovialTableType * createType(SgClassDeclaration *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgJovialTableType (types whose constructors ta...
This class represents the concept of a C or C++ label statement.
This class represents a lambda expression.
This class represents a list display.
This class represents the notion of an expression or statement which has a position within the source...
virtual std::string class_name() const override
returns a string representing the class name
Sg_File_Info * get_endOfConstruct() const override
New function interface for Sg_File_Info data stores ending location of contruct (typically the closin...
void set_endOfConstruct(Sg_File_Info *endOfConstruct)
This function sets the current source location position of the end of the current construct.
Sg_File_Info * get_startOfConstruct() const override
New function interface for Sg_File_Info data stores starting location of contruct (typically the open...
virtual Sg_File_Info * get_file_info() const override
Interface function to implement original SAGE interface to SgFile_Info objects.
This class represents the notion of an value (expression value).
This class represents the concept of a member function declaration statement.
SgCtorInitializerList * get_CtorInitializerList() const
Access function for p_CtorInitializerList.
void set_associatedClassDeclaration(SgDeclarationStatement *associatedClassDeclaration)
This is an access function for the p_associatedClassDeclaration data member.
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
This class represents the member function being called and must be assembled in the SgFunctionCall wi...
SgType * get_type() const override
Get the type associated with this expression.
SgName get_name() const override
Access function for getting name from declarations or types internally.
SgType * get_type() const override
This function returns the type associated with the named entity.
virtual std::string class_name() const override
returns a string representing the class name
virtual SgName get_mangled(void) const override
Mangled name support for unparser support.
static SgMemberFunctionType * createType(SgPartialFunctionType *type=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgMemberFunctionType (types whose constructors...
This class represents the numeric negation of a value. Not to be confused with SgSubtractOp.
SgTypeModifier & get_typeModifier()
Access function for modifier.
virtual std::string class_name() const override
returns a string representing the class name
This class represents strings within the IR nodes.
virtual std::string class_name() const override
returns a string representing the class name
SgName get_qualified_name() const
Used for the SgNamedType object (base class for the SgClassType, SgTypedefType and the SgEnumType obj...
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the concept of a C++ namespace alias declaration statement.
This class represents the concept of a C++ namespace declaration.
SgName get_name() const
Access function for p_name.
SgNamespaceDefinitionStatement * get_definition() const
Returns pointer to SgNamespaceDefinitionStatement.
This class represents the concept of a namespace definition.
This class represents the concept of a namespace name within the compiler.
SgNamespaceDeclarationStatement * get_declaration() const
Access function for getting the declaration of the original namespace.
This class represents the notion of an n-ary boolean operation. This node is intended for use with Py...
This class represents the notion of an n-ary comparison operation. This node is intended for use with...
This class represents the concept of a C++ call to the new operator.
This class represents the base class for all IR nodes within Sage III.
static void clearGlobalMangledNameMap()
Support to clear the performance optimizing global mangled name map.
virtual Sg_File_Info * get_endOfConstruct(void) const
New function interface for Sg_File_Info data stores ending location of contruct (typically the closin...
SgNode * get_parent() const
Access function for parent node.
void set_isModified(bool isModified)
All nodes in the AST contain a isModified flag used to track changes to the AST.
virtual VariantT variantT() const
returns new style SageIII enum values
void set_parent(SgNode *parent)
All nodes in the AST contain a reference to a parent node.
virtual std::string unparseToString(SgUnparse_Info *info) const
This function unparses the AST node (excluding comments and unnecessary white space)
virtual std::string class_name() const
returns a string representing the class name
static std::map< SgNode *, std::string > & get_globalMangledNameMap()
Access function for performance optimizing global mangled name map.
static SgFunctionTypeTable * get_globalFunctionTypeTable()
Access function for symbol table specific to function types.
virtual Sg_File_Info * get_file_info(void) const
File information containing filename, line number, column number, and if the SgNode is a part of a ne...
bool get_isModified() const
Acess function for isModified flag.
virtual std::string class_name() const override
returns a string representing the class name
virtual std::string class_name() const override
returns a string representing the class name
virtual std::string class_name() const override
returns a string representing the class name
static SgPointerType * createType(SgType *type=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgPointerType (types whose constructors take p...
This class represents the concept of a C Assembler statement (untested).
subprogram_kind_enum
Classification for different types of Fortran subprograms.
This class represents a source project, with a list of SgFile objects and global information about th...
void set_originalCommandLineArgumentList(SgStringList originalCommandLineArgumentList)
Sets the list of strings representing the original command-line.
SgStringList get_originalCommandLineArgumentList() const
Returns a list of strings representing the original command-line.
void set_file(SgFile &)
Access function for putting a new SgFile object into the list stored internally This function is depr...
This class represents the concept of a 'global' stmt in Python.
virtual void append_name(SgInitializedName *element)
Append a name to the list of identifiers imported into the inner scope.
static SgReferenceType * createType(SgType *type=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgReferenceType (types whose constructors take...
This class represents the concept of a C Assembler statement (untested).
static SgRvalueReferenceType * createType(SgType *type=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgRvalueReferenceType (types whose constructor...
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
bool isNamedScope()
Some scopes have associated names for purposed of name qualification. This returns true if the scope ...
SgSymbolTable * get_symbol_table() const
Returns a pointer to the locally strored SgSymbolTable.
void append_statement(SgStatement *stmt)
Higher level function to handle statements and declarations is scopes.
virtual std::string class_name() const override
returns a string representing the class name
bool containsOnlyDeclarations() const
This function is used to indicate if either the getDeclarationList() or getStatementList() can be cal...
void insert_symbol(const SgName &n, SgSymbol *s)
Puts a SgSymbol object into the local symbol table.
This class represents the "sizeof()" operator (applied to any type).
virtual std::string class_name() const override
returns a string representing the class name
This class represents the GNU extension "statement expression" (thus is non-standard C and C++).
This class represents the notion of a statement.
virtual std::string class_name() const override
returns a string representing the class name
virtual void set_scope(SgScopeStatement *newScope)
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
virtual bool hasExplicitScope() const
Support for where the scope is explicitly required.
virtual SgScopeStatement * get_scope(void) const
Returns scope of current statement.
This class is intended to be a wrapper around SgStatements, allowing them to exist in scopes that onl...
void setExtern()
Set storage.
bool isExtern() const
Storage modifier is extern (not the same as extern "C").
storage_modifier_enum
Storage Modifiers (only one value can be specified)
This class represents the conversion of an arbitrary expression to a string. This node is intended fo...
This class represents the concept of a switch.
void print(std::string label, VariantT nodeType=V_SgSymbol)
Outputs symbol table information (useful for debugging)
int size() const
Computes the number of symbols in the symbol table (forced to count them, I think,...
This class represents the concept of a name within the compiler.
This class represents template argument within the use of a template to build an instantiation.
SgExpression * get_expression() const
This function returns argumentExpression.
SgType * get_type() const
This function returns argumentType.
SgTemplateArgument::template_argument_enum get_argumentType() const
This function returns argumentType.
virtual std::string class_name() const override
returns a string representing the class name
SgType * get_type() const override
This function returns the type associated with the named entity.
This class represents the concept of a template declaration.
This class represents the concept of an instantiated class template.
virtual std::string class_name() const override
returns a string representing the class name
void set_templateDeclaration(SgTemplateClassDeclaration *templateDeclaration)
Access function for p_templateDeclaration.
SgName get_templateName() const
Returns name of class template, the name excludes template arguments.
void set_templateName(SgName templateName)
sets name of instantiated class template, name excludes template arguments.
const SgTemplateArgumentPtrList & get_templateArguments() const
Returns pointer to STL list of pointers to SgTemplateArgument objects.
SgTemplateClassDeclaration * get_templateDeclaration() const
Returns pointer to SgTemplateDeclaration from which instantiation is generated.
This class represents the concept of a class definition in C++.
This class represents the concept of an instantiation of function template.
const SgTemplateArgumentPtrList & get_templateArguments() const
Returns pointer to STL list of pointers to SgTemplateArgument objects.
SgName get_templateName() const
Returns name of instantiated function template, name includes template arguments.
void set_templateName(SgName templateName)
sets name of instantiated function template, name includes template arguments.
This class represents the concept of an instantiation of member function template or a member functio...
void set_templateName(SgName templateName)
sets name of instantiated function template, name includes template arguments.
virtual std::string class_name() const override
returns a string representing the class name
const SgTemplateArgumentPtrList & get_templateArguments() const
Returns pointer to STL list of pointers to SgTemplateArgument objects.
SgName get_templateName() const
Returns name of instantiated function template, name includes template arguments.
virtual std::string class_name() const override
returns a string representing the class name
virtual std::string class_name() const override
returns a string representing the class name
virtual std::string class_name() const override
returns a string representing the class name
This class represents the "this" operator (can be applied to any member data).
This class represents the C++ throw expression (handled as a unary operator).
e_throw_kind
Throw IR node can be used in three different ways.
This class represents the concept of try statement within the try-catch support for exception handlin...
SgCatchStatementSeq * get_catch_statement_seq_root() const
Returns pointer to SgCatchStatementSeq.
This class represents a tuple display.
static SgTypeBFloat16 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeBool * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeChar16 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeChar32 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeChar * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents a C99 complex type.
static SgTypeDouble * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFixed * createType(SgExpression *scale=NULL, SgExpression *fraction=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypeFixed (types whose constructors take par...
static SgTypeFloat128 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat16 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat32 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat32x * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat64 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat64x * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat80 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFp16 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents a C99 complex type.
static SgTypeInt * createType(int sz=0, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypeInt (types whose constructors take param...
static SgTypeLongDouble * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeLongLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeNullptr * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeOfType * createType(SgExpression *expr=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypeOfType (types whose constructors take pa...
static SgTypeShort * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSigned128bitInteger * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedChar * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedInt * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedLongLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedShort * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents a string type used for SgStringVal IR node.
static SgTypeUnknown * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsigned128bitInteger * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedChar * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedInt * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedLongLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedShort * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeVoid * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeWchar * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents the base class for all types.
std::vector< SgType * > getInternalTypes() const
Generate a container of types hidden in the input type.
SgType * stripType(unsigned char bit_array=STRIP_MODIFIER_TYPE|STRIP_REFERENCE_TYPE|STRIP_RVALUE_REFERENCE_TYPE|STRIP_POINTER_TYPE|STRIP_ARRAY_TYPE|STRIP_TYPEDEF_TYPE|STRIP_POINTER_MEMBER_TYPE) const
Returns hidden type beneath layers of typedefs, pointers, references, modifiers, array representation...
virtual std::string class_name() const override
returns a string representing the class name
This class represents the notion of a typedef declaration.
SgScopeStatement * get_scope() const override
Returns scope of current statement.
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
SgType * get_type() const override
This function returns the type associated with the named entity.
virtual std::string class_name() const override
returns a string representing the class name
SgType * get_base_type() const
This is used in the SgTypedefType object (is not associated with a base_type data field)
static SgTypedefType * createType(SgTypedefDeclaration *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypedefType (types whose constructors take p...
This class represents the notion of a unary operator. It is derived from a SgExpression because opera...
void set_mode(SgUnaryOp::Sgop_mode mode)
Set the mode (prefix/postfix) associated with this operator.
SgExpression * get_operand_i() const
returns SgExpression pointer to the operand associated with this unary operator.
Sgop_mode
Enum value defines operators as prefix or postfix, as appropriate, e.g. operator++().
void set_operand_i(SgExpression *operand_i)
This function allows the p_operand_i pointer to be set (used internally).
This class represents the concept of a C++ using directive.
This class represents the notion of an value (expression value).
This class represents the variable refernece in expressions.
This class represents the concept of a C or C++ variable declaration.
const SgInitializedNamePtrList & get_variables() const
Access function for p_variables.
This class represents the definition (initialization) of a variable.
void set_vardefn(SgInitializedName *vardefn)
Access function for SgInitializedName in p_vardefn.
This class represents the concept of a variable name within the compiler (a shared container for the ...
SgName get_name() const override
Access function for getting name from declarations or types internally.
This class represents the concept of a do-while statement.
This class represents the location of the code associated with the IR node in the original source cod...
static std::map< std::string, int > & get_nametofileid_map()
Access function for static datamember nametofileid_map.
void setTransformation()
Marks an IR node to be a transformation if it is not one already.
const char * get_filename() const
Returns filename of source code associated with IR node.
bool isOutputInCodeGeneration() const
Returns true only if required to be unparsed in generated code.
void unsetOutputInCodeGeneration()
Mark as to be output by the unparser (code generator)
int get_line() const
Returns the line number of the associated code for this IR node.
void setShared()
Marks IR node as shared.
void setCompilerGenerated()
Marks IR node as compiler generated.
bool isShared() const
Returns true only if shared internally (either by the front-end or by ROSE).
ROSE_DLL_API roseNode * buildroseNode(SgNode *snode)
A builder function to avoid duplicated building.
ROSE_DLL_API const char * c_char
A namespace scope char* to avoid passing and returning a target c string for every and each function ...
ROSE_DLL_API SgNode * c_sgnode
current anchor SgNode associated with parsing. It will serve as a start point to find enclosing scope...
ROSE_DLL_API SgNode * c_parsed_node
Store the AST substree (expression, statement) generated from a helper function.
ROSE_DLL_API bool afs_match_statement()
match any statement, not complete yet. Don't use it yet . : labeled_statement | compound_statement | ...
ROSE_DLL_API std::vector< std::string > generateSourceFilenames(std::vector< std::string > argList, bool binaryMode)
Build the list of isolated file names from the command line.
ROSE_UTIL_API void removeAllFileNamesExcept(std::vector< std::string > &argv, std::vector< std::string > filenameList, std::string exceptFilename)
Remove file names specified in filenameList from argv, except for 'exceptFilename'.
Unsigned position(size_t i)
Generate a single-bit mask.
Definition BitOps.h:159
Controls diagnostic messages from ROSE.
ROSE_DLL_API void initAndRegister(Facility *mlog, const std::string &name)
Initialize and register a logging facility.
ROSE_DLL_API Sawyer::Message::Facility mlog
Diagnostic facility for the ROSE library as a whole.
Definition sageBuilder.C:50
ROSE_UTIL_API std::string intToHex(uint64_t)
Convert an integer to a hexadecimal string.
The ROSE library.
Functions that build an AST.
Definition sageBuilder.h:32
ROSE_DLL_API SgTypeFloat16 * buildFloat16Type()
Built in simple types.
ROSE_DLL_API SgTemplateInstantiationTypedefDeclaration * buildTemplateInstantiationTypedefDeclaration_nfi(SgName &name, SgType *base_type, SgScopeStatement *scope, bool has_defining_base, SgTemplateTypedefDeclaration *templateTypedefDeclaration, SgTemplateArgumentPtrList &templateArgumentsList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgJavaMemberValuePair * buildJavaMemberValuePair(const SgName &, SgExpression *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgCastExp * buildCastExp_nfi(SgExpression *operand_i, SgType *expression_type, SgCastExp::cast_type_enum cast_type)
ROSE_DLL_API SgUpcBarrierStatement * buildUpcBarrierStatement_nfi(SgExpression *exp)
Build a UPC barrier statement.
ROSE_DLL_API SgAtomicStmt * buildAtomicStmt(SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAtStmt * buildAtStmt(SgExpression *expression, SgBasicBlock *body)
MH (6/11/2014): Added at support.
ROSE_DLL_API SgJovialBitType * buildJovialBitType(SgExpression *size)
Build a Jovial bit type of a given size.
ROSE_DLL_API SgColonShapeExp * buildColonShapeExp()
Build a Fortran colon-shape expression, set file info as the default one.
ROSE_DLL_API SgJovialTableType * buildJovialTableType(const SgName &name, SgType *base_type, SgExprListExp *dim_info, SgScopeStatement *scope=NULL)
Build a Jovial table type with required class definition and defining and nondefining declarations.
ROSE_DLL_API SgFunctionDeclaration * buildNondefiningFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope=NULL, SgExprListExp *decoratorList=NULL, bool buildTemplateInstantiation=false, SgTemplateArgumentPtrList *templateArgumentsList=NULL, SgStorageModifier::storage_modifier_enum sm=SgStorageModifier::e_default)
Build a prototype for a function, handle function type, symbol etc transparently.
ROSE_DLL_API SgFloat32Val * buildFloat32Val(float v=0)
Build a float32.
ROSE_DLL_API SgTemplateArgumentPtrList * getTemplateArgumentList(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgSwitchStatement * buildSwitchStatement_nfi(SgStatement *item_selector, SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgBaseClass * buildBaseClass(SgClassDeclaration *classDeclaration, SgClassDefinition *classDefinition, bool isVirtual, bool isDirect)
DQ (5/6/2013): Added build functions to support SgBaseClass construction.
SourcePositionClassification
intended to be a private member, don't access it directly. could be changed any time
@ e_sourcePosition_last
Specify as source position to be filled in as part of AST construction in the front-end.
@ e_sourcePositionNullPointers
Classify as compiler generated code (e.g. template instantiation).
@ e_sourcePositionCompilerGenerated
Classify as a transformation.
@ e_sourcePositionFrontendConstruction
Set pointers to Sg_File_Info objects to NULL.
@ e_sourcePositionDefault
Error value for enum.
@ e_sourcePositionTransformation
Default source position.
ROSE_DLL_API SgFunctionParameterRefExp * buildFunctionParameterRefExp_nfi(int parameter_number, int parameter_level)
ROSE_DLL_API SgThrowOp * buildThrowOp(SgExpression *, SgThrowOp::e_throw_kind)
Build a ThrowOp expression.
ROSE_DLL_API SgPointerMemberType * buildPointerMemberType(SgType *base_type, SgType *classType)
Pei-Hung (06/30/2023): support for SgPointerMemberType.
ROSE_DLL_API SgPragma * buildPragma(const std::string &name)
Build SgPragma.
ROSE_DLL_API void testTemplateParameterParents(SgDeclarationStatement *decl)
DQ (9/16/2012): Added function to support setting the template parameters and setting their parents (...
ROSE_DLL_API SgStringConversion * buildStringConversion(SgExpression *exp)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgChooseExpression * buildChooseExpression_nfi()
ROSE_DLL_API SgJavaWildcardType * getUniqueJavaWildcardExtends(SgType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgUpcForAllStatement * buildUpcForAllStatement_nfi(SgStatement *initialize_stmt, SgStatement *test, SgExpression *increment, SgExpression *affinity, SgStatement *loop_body)
Build a UPC forall statement.
ROSE_DLL_API SgBFloat16Val * buildBFloat16Val_nfi(float v, const std::string &str)
ROSE_DLL_API SgUnsignedLongVal * buildUnsignedLongValHex(unsigned long v=0)
ROSE_DLL_API SgClassType * buildClassTemplateType(SgTemplateClassDeclaration *template_decl, std::vector< SgNode * > &template_args)
Some support for building class template instantiation declarations.
ROSE_DLL_API SgNullptrValExp * buildNullptrValExp_nfi()
ROSE_DLL_API SgDerivedTypeStatement * buildDerivedTypeStatement(const SgName &name, SgScopeStatement *scope=NULL)
Build an SgDerivedTypeStatement Fortran derived type declaration with a class declaration and definit...
ROSE_DLL_API SgExprStatement * buildFunctionCallStmt(const SgName &name, SgType *return_type, SgExprListExp *parameters=NULL, SgScopeStatement *scope=NULL)
Build a regular function call statement.
ROSE_DLL_API SgExecStatement * buildExecStatement(SgExpression *executable, SgExpression *globals=NULL, SgExpression *locals=NULL)
Build an exec statement.
ROSE_DLL_API SgShortVal * buildShortValHex(short value=0)
ROSE_DLL_API SgClassDeclaration * buildClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgClassDeclaration *nonDefiningDecl, bool buildTemplateInstantiation, SgTemplateArgumentPtrList *templateArgumentsList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeSignedLongLong * buildSignedLongLongType()
Built in simple types.
ROSE_DLL_API SgNewExp * buildNewExp(SgType *type, SgExprListExp *exprListExp, SgConstructorInitializer *constInit, SgExpression *expr, short int val, SgFunctionDeclaration *funcDecl)
SgPythonGlobalStmt * buildPythonGlobalStmt_nfi(SgInitializedNamePtrList &names)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SourcePositionClassification getSourcePositionClassificationMode()
Get the current source position classification (defines how IR nodes built by the SageBuilder interfa...
SgNullStatement * buildNullStatement_nfi()
Build a NULL statement.
ROSE_DLL_API SgForStatement * buildForStatement_nfi(SgStatement *initialize_stmt, SgStatement *test, SgExpression *increment, SgStatement *loop_body, SgStatement *else_body=NULL)
Based on the contribution from Pradeep Srinivasa@ LANL.
ROSE_DLL_API SgTypeUnsignedLongLong * buildUnsignedLongLongType()
Built in simple types.
ROSE_DLL_API SgCompoundInitializer * buildCompoundInitializer(SgExprListExp *initializers=NULL, SgType *type=NULL)
Build a compound initializer, for vector type initialization.
ROSE_DLL_API SgTypeString * buildStringType()
DQ (8/21/2010): We want to move to the new buildStringType( SgExpression*,size_t) function over the o...
ROSE_DLL_API SgUpcThreads * buildUpcThreads_nfi()
Build UPC THREADS (integer expression)
ROSE_DLL_API SgModifierType * buildModifierType(SgType *base_type=nullptr)
Build a modifier type.
ROSE_DLL_API SgCaseOptionStmt * buildCaseOptionStmt(SgExpression *key=NULL, SgStatement *body=NULL)
Build a case option statement.
ROSE_DLL_API SgTemplateFunctionDeclaration * buildDefiningTemplateFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, SgTemplateFunctionDeclaration *first_nondefining_declaration)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgCatchOptionStmt * buildCatchOptionStmt(SgVariableDeclaration *condition=NULL, SgStatement *body=NULL)
Build a catch statement.
ROSE_DLL_API SgLongLongIntVal * buildLongLongIntVal_nfi(long long value, const std::string &str)
ROSE_DLL_API SgClassType * buildTemplateClassType(SgTemplateClassDeclaration *template_decl, std::vector< SgNode * > &template_args)
Same as buildClassTemplateType(), just better name.
SgFortranContinueStmt * buildFortranContinueStmt_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTemplateMemberFunctionDeclaration * buildNondefiningTemplateMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, SgTemplateParameterPtrList *templateParameterList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgLabelStatement * buildLabelStatement(const SgName &name, SgStatement *stmt=NULL, SgScopeStatement *scope=NULL)
Build a label statement, name is the label's name. Handling label symbol and scope internally.
ROSE_DLL_API SgFortranDo * buildFortranDo_nfi(SgExpression *initialization, SgExpression *bound, SgExpression *increment, SgBasicBlock *)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUpcThreads * buildUpcThreads()
Build UPC THREADS (integer expression)
ROSE_DLL_API SgModifierType * buildRestrictType(SgType *base_type)
Build a restrict type.
ROSE_DLL_API SgIntVal * buildIntVal_nfi(int value=0)
ROSE_DLL_API SgLongDoubleVal * buildLongDoubleVal(long double value=0.0)
SgFunctionParameterList * buildFunctionParameterList_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API AbstractHandle::abstract_handle * buildAbstractHandle(SgNode *n)
Build an abstract handle from a SgNode.
ROSE_DLL_API SgClassDeclaration * buildClassDeclaration(SgName name, SgScopeStatement *scope)
Build C++ class (builds both the non-defining and defining declarations; in that order).
ROSE_DLL_API SgMinusOp * buildMinusOp_nfi(SgExpression *op)
ROSE_DLL_API SgTemplateFunctionDeclaration * buildNondefiningTemplateFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope=NULL, SgExprListExp *decoratorList=NULL, SgTemplateParameterPtrList *templateParameterList=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAsmStmt * buildMultibyteNopStatement(int n)
DQ (4/30/2010): Added support for building nop statement using asm statement Building nop statement u...
ROSE_DLL_API SgKeyDatumPair * buildKeyDatumPair(SgExpression *key, SgExpression *datum)
Build a key-datum pair.
ROSE_DLL_API SgComprehension * buildComprehension(SgExpression *target, SgExpression *iter, SgExprListExp *ifs)
ROSE_DLL_API SgJavaParameterizedType * getUniqueJavaParameterizedType(SgNamedType *, SgTemplateParameterPtrList *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgComplexVal * buildImaginaryVal_nfi(SgValueExp *imaginary_value, const std::string &str)
ROSE_DLL_API SgFunctionCallExp * buildFunctionCallExp(SgFunctionSymbol *sym, SgExprListExp *parameters=NULL)
Build a function call expression.
ROSE_DLL_API SgType * getTargetFileType(SgType *snippet_type, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgTemplateParameter * buildTemplateParameter(SgTemplateParameter::template_parameter_enum parameterType, SgType *)
Build a template parameter, passing enum kind and SgTemplateType template_parameter_enum { parameter_...
ROSE_DLL_API SgNoexceptOp * buildNoexceptOp(SgExpression *exp=NULL)
Build noexcept operator expression with an expression parameter.
ROSE_DLL_API SgSignedCharVal * buildSignedCharVal_nfi(signed char v, const std::string &str)
ROSE_DLL_API SgClassDeclaration * buildNondefiningClassDeclaration(SgName name, SgScopeStatement *scope)
DQ (11/7/2009): Added functions to build C++ class.
SgMemberFunctionRefExp * buildMemberFunctionRefExp_nfi(SgMemberFunctionSymbol *sym, bool virtual_call, bool need_qualifier)
ROSE_DLL_API SgFunctionDeclaration * buildDefiningFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, bool buildTemplateInstantiation=false, SgFunctionDeclaration *first_nondefinng_declaration=NULL, SgTemplateArgumentPtrList *templateArgumentsList=NULL)
Build a function declaration with a function body.
ROSE_DLL_API SgModifierType * buildUpcSharedType(SgType *base_type=nullptr, long layout=-1)
Build a UPC shared type.
ROSE_DLL_API SgGotoStatement * buildGotoStatement(SgLabelStatement *label=NULL)
Build a goto statement.
ROSE_DLL_API std::string display(SourcePositionClassification &scp)
display function for debugging
ROSE_DLL_API SgUnsignedLongVal * buildUnsignedLongVal_nfi(unsigned long v, const std::string &str)
ROSE_DLL_API SgLabelRefExp * buildLabelRefExp(SgLabelSymbol *s)
Build a Fortran numeric label ref exp.
ROSE_DLL_API SgCompoundInitializer * buildCompoundInitializer_nfi(SgExprListExp *initializers, SgType *type=NULL)
Build a compound initializer, for vector type initialization.
ROSE_DLL_API SgSourceFile * buildJavaSourceFile(SgProject *, std::string, SgClassDefinition *, std::string)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgCatchStatementSeq * buildCatchStatementSeq(SgCatchOptionStmt *=NULL)
Build an initial sequence of Catch blocks containing 0 or 1 element.
ROSE_DLL_API SgInitializedName * buildInitializedName(const SgName &name, SgType *type, SgInitializer *init=NULL)
Initialized names are tricky, their scope vary depending on context, so scope and symbol information ...
ROSE_DLL_API SgTryStmt * buildTryStmt(SgStatement *body, SgCatchOptionStmt *catch0=NULL, SgCatchOptionStmt *catch1=NULL, SgCatchOptionStmt *catch2=NULL, SgCatchOptionStmt *catch3=NULL, SgCatchOptionStmt *catch4=NULL)
Build a try statement.
ROSE_DLL_API SgJavaImportStatement * buildJavaImportStatement(std::string, bool)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgThisExp * buildThisExp_nfi(SgSymbol *sym)
ROSE_DLL_API SgEnumDeclaration * buildEnumDeclaration_nfi(const SgName &name, SgScopeStatement *scope=NULL)
Build an enum, It is also a declaration statement in SAGE III.
ROSE_DLL_API SgNonrealDecl * buildNonrealDecl(const SgName &name, SgDeclarationScope *scope, SgDeclarationScope *child_scope=NULL)
Build a declaration of a non-real class or class-member representing template parameters and their me...
SgAssertStmt * buildAssertStmt_nfi(SgExpression *test)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgThisExp * buildThisExp(SgSymbol *sym)
Build this pointer.
ROSE_DLL_API SgSymbol * findAssociatedSymbolInTargetAST(SgDeclarationStatement *snippet_declaration, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgListComprehension * buildListComprehension(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgMinusMinusOp * buildMinusMinusOp_nfi(SgExpression *op)
ROSE_DLL_API SgModifierType * buildUpcBlockStarType(SgType *base_type=nullptr)
Build a UPC shared[*] type.
ROSE_DLL_API SgStringConversion * buildStringConversion_nfi(SgExpression *exp)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgFloat16Val * buildFloat16Val_nfi(float v, const std::string &str)
SgTupleExp * buildTupleExp_nfi()
ROSE_DLL_API SgIntVal * buildIntValHex(int value=0)
ROSE_DLL_API SgTemplateClassDeclaration * buildNondefiningTemplateClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateSpecializationArgumentList)
DQ (11/29/2011): Adding template declaration support to the AST.
ROSE_DLL_API void setTemplateParametersInDeclaration(SgDeclarationStatement *decl, SgTemplateParameterPtrList *templateParametersList_input)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDeclType * buildDeclType(SgExpression *base_expression, SgType *base_type)
Build a decltype reference type.
ROSE_DLL_API SgUnsignedShortVal * buildUnsignedShortVal_nfi(unsigned short v, const std::string &str)
ROSE_DLL_API SgJavaWildcardType * getUniqueJavaWildcardUnbound()
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgIfStmt * buildIfStmt_nfi(SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDictionaryComprehension * buildDictionaryComprehension(SgKeyDatumPair *kd_pair, SgExprListExp *generators)
ROSE_DLL_API SgShortVal * buildShortVal_nfi(short value, const std::string &str)
ROSE_DLL_API void clearScopeStack()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgLongIntVal * buildLongIntVal(long value=0)
Build a long integer value expression.
ROSE_DLL_API SgJavaTypeExpression * buildJavaTypeExpression(SgType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgChar16Val * buildChar16Val(unsigned short value=0)
ROSE_DLL_API SgAwaitExpression * buildAwaitExpression()
SgDeleteExp * buildDeleteExp_nfi(SgExpression *target, bool is_array=false, bool need_global_specifier=false, SgFunctionDeclaration *deleteOperatorDeclaration=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgFoldExpression * buildFoldExpression_nfi(SgExpression *operands, std::string operator_token_string, bool is_left_associative)
ROSE_DLL_API SgBracedInitializer * buildBracedInitializer_nfi(SgExprListExp *initializers=NULL, SgType *expression_type=NULL)
ROSE_DLL_API SgMemberFunctionType * buildMemberFunctionType(SgType *return_type, SgFunctionParameterTypeList *typeList, SgScopeStatement *struct_name, unsigned int mfunc_specifier)
Built in simple types.
ROSE_DLL_API SgVariableDefinition * buildVariableDefinition_nfi(SgVariableDeclaration *decl, SgInitializedName *init_name, SgInitializer *init)
Build variable definition.
ROSE_DLL_API SgBasicBlock * buildBasicBlock_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUpcMythread * buildUpcMythread_nfi()
Build UPC MYTHREAD (integer expression)
ROSE_DLL_API SgWhileStmt * buildWhileStmt(SgStatement *condition, SgStatement *body, SgStatement *else_body=NULL)
Build while statement.
ROSE_DLL_API SgTypeFloat32 * buildFloat32Type()
Built in simple types.
ROSE_DLL_API SgTemplateClassDeclaration * buildNondefiningTemplateClassDeclaration(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateSpecializationArgumentList)
buildNondefiningTemplateClassDeclaration()
ROSE_DLL_API void setSourcePositionClassificationMode(SourcePositionClassification X)
Set the current source position classification (defines how IR nodes built by the SageBuilder interfa...
ROSE_DLL_API SgClassDeclaration * buildStructDeclaration(const SgName &name, SgScopeStatement *scope=NULL)
Build a structure, It is also a declaration statement in SAGE III.
SgCtorInitializerList * buildCtorInitializerList_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgNamespaceAliasDeclarationStatement * buildNamespaceAliasDeclarationStatement(const SgName &name, SgNamespaceDeclarationStatement *namespaceDeclaration)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgClassDefinition * buildClassDefinition(SgClassDeclaration *d=NULL, bool buildTemplateInstantiation=false)
Build a class definition scope statement.
ROSE_DLL_API SgJovialBitVal * buildJovialBitVal_nfi(const std::string &str)
Build a Jovial bit value expression.
ROSE_DLL_API SgCharVal * buildCharVal_nfi(char value, const std::string &str)
ROSE_DLL_API SgJavaThrowStatement * buildJavaThrowStatement(SgThrowOp *)
Build a Java Throw statement.
ROSE_DLL_API SgJavaSynchronizedStatement * buildJavaSynchronizedStatement(SgExpression *, SgBasicBlock *)
Build a Java Synchronized statement.
ROSE_DLL_API PreprocessingInfo * buildComment(SgLocatedNode *target, const std::string &content, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before, PreprocessingInfo::DirectiveType dtype=PreprocessingInfo::CpreprocessorUnknownDeclaration)
Build and attach a comment, comment style is inferred from the language type of the target node if no...
SgConditionalExp * buildConditionalExp_nfi(SgExpression *test, SgExpression *a, SgExpression *b, SgType *t)
ROSE_DLL_API SgNamespaceDefinitionStatement * buildNamespaceDefinition(SgNamespaceDeclarationStatement *d=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDefaultOptionStmt * buildDefaultOptionStmt(SgStatement *body=NULL)
Build a default option statement.
SgCudaKernelExecConfig * buildCudaKernelExecConfig_nfi(SgExpression *grid=NULL, SgExpression *blocks=NULL, SgExpression *shared=NULL, SgExpression *stream=NULL)
Build a CUDA kernel execution configuration (<<<grid, blocks, shared, stream>>>)
ROSE_DLL_API SgJavaSingleMemberAnnotation * buildJavaSingleMemberAnnotation(SgType *, SgExpression *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgForStatement * buildForStatement(SgStatement *initialize_stmt, SgStatement *test, SgExpression *increment, SgStatement *loop_body, SgStatement *else_body=NULL)
Build a for statement, assume none of the arguments is NULL.
ROSE_DLL_API SgTypeMatrix * buildMatrixType()
Build a Matlab Matrix Type.
ROSE_DLL_API SgModuleStatement * buildModuleStatement(const SgName &name, SgScopeStatement *scope)
Build a Fortran module declaration.
ROSE_DLL_API SgContinueStmt * buildContinueStmt()
Build a continue statement.
ROSE_DLL_API SgEmptyDeclaration * buildEmptyDeclaration()
Build an empty declaration (useful for adding precission to comments and CPP handling under token-bas...
ROSE_DLL_API SgUnsignedIntVal * buildUnsignedIntValHex(unsigned int v=0)
ROSE_DLL_API SgTemplateType * buildTemplateType(SgName name="")
Build a template type, used for template parameter and later argument.
ROSE_DLL_API SgLambdaRefExp * buildLambdaRefExp(SgType *return_type, SgFunctionParameterList *params, SgScopeStatement *scope)
Build lambda expression.
ROSE_DLL_API SgFloatVal * buildFloatVal_nfi(float value=0.0)
ROSE_DLL_API SgConditionalExp * buildConditionalExp(SgExpression *test=NULL, SgExpression *a=NULL, SgExpression *b=NULL)
Build a conditional expression ?:
ROSE_DLL_API SgUnsignedLongVal * buildUnsignedLongVal(unsigned long v=0)
Build a unsigned long integer.
ROSE_DLL_API SgTypeInt * buildIntType()
Built in simple types.
SgDictionaryComprehension * buildDictionaryComprehension_nfi(SgKeyDatumPair *kd_pair, SgExprListExp *generators)
ROSE_DLL_API SgTemplateClassDeclaration * buildTemplateClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgTemplateClassDeclaration *nonDefiningDecl, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateSpecializationArgumentList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeUnsignedInt * buildUnsignedIntType()
Built in simple types.
ROSE_DLL_API SgFloat80Val * buildFloat80Val(long double value=0.0)
SgSubscriptExpression * buildSubscriptExpression_nfi(SgExpression *lower_bound, SgExpression *upper_bound, SgExpression *stride)
Build a SgSubscriptExpression, used for array shape expressions. The lower bound and stride may be nu...
ROSE_DLL_API SgDotDotExp * buildDotDotExp()
Build a variable declaration, handle symbol table transparently.
SourcePositionClassification SourcePositionClassificationMode
C++ SageBuilder namespace specific state for storage of the source code position state (used to contr...
ROSE_DLL_API SgTypeBFloat16 * buildBFloat16Type()
Built in simple types.
ROSE_DLL_API SgMinusOp * buildMinusOp(SgExpression *op=NULL)
std::list< SgScopeStatement * > ScopeStack
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgModifierType * buildUpcBlockIndefiniteType(SgType *base_type=nullptr)
Build a UPC shared[] type.
SgSetComprehension * buildSetComprehension_nfi(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgTypeFp16 * buildFp16Type()
Built in simple types.
SgName unparseTemplateArgumentToString(SgTemplateArgument *templateArgument)
DQ (3/9/2018): Added to support debugging.
ROSE_DLL_API SgSuperExp * buildSuperExp(SgClassSymbol *sym)
Build super pointer.
ROSE_DLL_API SgExprListExp * buildExprListExp(SgExpression *expr1=NULL, SgExpression *expr2=NULL, SgExpression *expr3=NULL, SgExpression *expr4=NULL, SgExpression *expr5=NULL, SgExpression *expr6=NULL, SgExpression *expr7=NULL, SgExpression *expr8=NULL, SgExpression *expr9=NULL, SgExpression *expr10=NULL)
Build a SgExprListExp, used for function call parameter list etc.
ROSE_DLL_API void resetDeclaration(T *classDeclaration_copy, T *classDeclaration_original, SgScopeStatement *targetScope)
Function to reset scopes in SgDeclarationStatement IR nodes.
ROSE_DLL_API SgRangeBasedForStatement * buildRangeBasedForStatement_nfi(SgVariableDeclaration *initializer, SgVariableDeclaration *range, SgVariableDeclaration *begin_declaration, SgVariableDeclaration *end_declaration, SgExpression *not_equal_expression, SgExpression *increment_expression, SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgJavaPackageStatement * buildJavaPackageStatement(std::string)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgJavaLabelStatement * buildJavaLabelStatement(const SgName &, SgStatement *=NULL)
Build a Java Label statement.
ROSE_DLL_API SgEquivalenceStatement * buildEquivalenceStatement(SgExpression *lhs, SgExpression *rhs)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgListExp * buildListExp(SgExpression *expr1=NULL, SgExpression *expr2=NULL, SgExpression *expr3=NULL, SgExpression *expr4=NULL, SgExpression *expr5=NULL, SgExpression *expr6=NULL, SgExpression *expr7=NULL, SgExpression *expr8=NULL, SgExpression *expr9=NULL, SgExpression *expr10=NULL)
Build a SgListExp.
ROSE_DLL_API SgUnsignedCharVal * buildUnsignedCharValHex(unsigned char v=0)
ROSE_DLL_API SgModifierType * buildNotNullType(SgType *base_type)
Build a not null type for Ada.
ROSE_DLL_API SgLambdaExp * buildLambdaExp_nfi(SgLambdaCaptureList *lambda_capture_list, SgClassDeclaration *lambda_closure_class, SgFunctionDeclaration *lambda_function)
ROSE_DLL_API SgTemplateClassDeclaration * buildTemplateClassDeclaration(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgTemplateClassDeclaration *nonDefiningDecl, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateSpecializationArgumentList)
Build tempplate class declaration.
ROSE_DLL_API SgSourceFile * buildSourceFile(const std::string &outputFileName, SgProject *project=NULL, bool clear_globalScopeAcrossFiles=false)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API void setTemplateSpecializationArgumentsInDeclaration(SgDeclarationStatement *decl, SgTemplateArgumentPtrList *templateSpecializationArgumentsList_input)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgArrayType * buildArrayType(SgType *base_type=nullptr, SgExpression *index=nullptr)
Build ArrayType.
ROSE_DLL_API SgTypeFloat32x * buildFloat32xType()
Built in simple types.
ROSE_DLL_API SgEnumDeclaration * buildNondefiningEnumDeclaration_nfi(const SgName &name, SgScopeStatement *scope)
Build an enum first nondefining declaration, without file info.
ROSE_DLL_API SgComplexVal * buildImaginaryVal(long double imaginary_value)
ROSE_DLL_API SgLambdaCapture * buildLambdaCapture_nfi(SgExpression *capture_variable, SgExpression *source_closure_variable, SgExpression *closure_variable)
ROSE_DLL_API SgNullptrValExp * buildNullptrValExp()
DQ (7/31/2014): Adding support for C++11 nullptr const value expressions.
ROSE_DLL_API void fixupCopyOfAstFromSeparateFileInNewTargetAst(SgStatement *insertionPoint, bool insertionPointIsScope, SgStatement *toInsert, SgStatement *original_before_copy)
Fixup any AST moved from one file two another (references to symbols, types, etc.).
SgExprStatement * buildExprStatement_nfi(SgExpression *exp)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeExpression * buildTypeExpression(SgType *type)
DQ (7/24/2014): Adding support for c11 generic operands.
ROSE_DLL_API SgTypeFixed * buildFixedType(SgExpression *fraction, SgExpression *scale)
Build a Jovial fixed type with a fraction specifier and a scale specifier.
SgPythonPrintStmt * buildPythonPrintStmt_nfi(SgExpression *dest=NULL, SgExprListExp *values=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTemplateVariableDeclaration * buildTemplateVariableDeclaration_nfi(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgNaryComparisonOp * buildNaryComparisonOp_nfi(SgExpression *lhs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgReturnStmt * buildReturnStmt(SgExpression *expression=NULL)
Build a return statement.
SgCaseOptionStmt * buildCaseOptionStmt_nfi(SgExpression *key, SgStatement *body)
Build a variable declaration, handle symbol table transparently.
SgWithStatement * buildWithStatement_nfi(SgExpression *expr, SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUpcFenceStatement * buildUpcFenceStatement_nfi()
Build a UPC fence statement.
ROSE_DLL_API SgComplexVal * buildComplexVal_nfi(SgValueExp *real_value, SgValueExp *imaginary_value, const std::string &str)
SgCudaKernelCallExp * buildCudaKernelCallExp_nfi(SgExpression *kernel, SgExprListExp *parameters=NULL, SgCudaKernelExecConfig *config=NULL)
Build a CUDA kernel call expression (kernel<<<config>>>(parameters))
ROSE_DLL_API SgTypeFloat64x * buildFloat64xType()
Built in simple types.
SgCompoundLiteralExp * buildCompoundLiteralExp_nfi(SgVariableSymbol *varSymbol)
Build function for compound literals (uses a SgVariableSymbol and is similar to buildVarRefExp_nfi())...
actualFunction * buildDefiningFunctionDeclaration_T(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, bool isMemberFunction, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, actualFunction *first_nondefinng_declaration, SgTemplateArgumentPtrList *templateArgumentsList)
A template function for function declaration builders.
ROSE_DLL_API SgChar16Val * buildChar16Val_nfi(unsigned short value, const std::string &str)
ROSE_DLL_API SgTypeLongLong * buildLongLongType()
Built in simple types.
ROSE_DLL_API SgTypeFloat128 * buildFloat128Type()
Built in simple types.
ROSE_DLL_API SgProcedureHeaderStatement * buildNondefiningProcedureHeaderStatement(const SgName &name, SgType *return_type, SgFunctionParameterList *param_list, SgProcedureHeaderStatement::subprogram_kind_enum, SgScopeStatement *scope=NULL)
Build a nondefining SgProcedureHeaderStatement, handle function type, symbol etc transparently.
ROSE_DLL_API SgFloat32Val * buildFloat32Val_nfi(float v, const std::string &str)
ROSE_DLL_API SgVarRefExp * buildVarRefExp(const SgName &name, SgScopeStatement *scope=NULL)
Build SgVarRefExp based on a variable's Sage name. It will lookup the name in the symbol table intern...
SgComprehension * buildComprehension_nfi(SgExpression *target, SgExpression *iter, SgExprListExp *ifs)
ROSE_DLL_API SgJovialTableStatement * buildJovialTableStatement(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope=NULL)
Build a Jovial table declaration statement.
ROSE_DLL_API SgLongLongIntVal * buildLongLongIntVal(long long value=0)
Build a long long integer value expression.
ROSE_DLL_API SgUnsignedLongLongIntVal * buildUnsignedLongLongIntVal(unsigned long long v=0)
Build an unsigned long long integer.
ROSE_DLL_API SgVarRefExp * buildJavaArrayLengthVarRefExp()
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgSuperExp * buildSuperExp_nfi(SgClassSymbol *sym)
SgKeyDatumPair * buildKeyDatumPair_nfi(SgExpression *key, SgExpression *datum)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgNamespaceDeclarationStatement * buildNamespaceDeclaration(const SgName &name, SgScopeStatement *scope=NULL)
tps (09/02/2009) : Added support for building namespaces
ROSE_DLL_API SgAggregateInitializer * buildAggregateInitializer_nfi(SgExprListExp *initializers, SgType *type=NULL)
Build an aggregate initializer.
ROSE_DLL_API SgTypeUnsignedShort * buildUnsignedShortType()
Built in simple types.
ROSE_DLL_API SgTypedefDeclaration * buildTypedefDeclaration_nfi(const std::string &name, SgType *base_type, SgScopeStatement *scope=NULL, bool has_defining_base=false)
Build a typedef declaration, such as: typedef int myint;.
ROSE_DLL_API SgTemplateVariableDeclaration * buildTemplateVariableDeclaration(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope)
Build template variable declarations.
ROSE_DLL_API SgMinusMinusOp * buildMinusMinusOp(SgExpression *op=NULL)
ROSE_DLL_API void buildDoWhileStatement_nfi(SgDoWhileStmt *result, SgStatement *body, SgStatement *condition)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeSigned128bitInteger * buildSigned128bitIntegerType()
Built in simple types.
ROSE_DLL_API SgUnsignedCharVal * buildUnsignedCharVal_nfi(unsigned char v, const std::string &str)
bool symbol_table_case_insensitive_semantics
Support for construction of case sensitive/insensitive symbol table handling in scopes.
Definition sageBuilder.C:93
SgListExp * buildListExp_nfi()
ROSE_DLL_API SgPythonPrintStmt * buildPythonPrintStmt(SgExpression *dest=NULL, SgExprListExp *values=NULL)
Build a python print statement.
ROSE_DLL_API SgConstructorInitializer * buildConstructorInitializer(SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type, bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown)
ROSE_DLL_API SgDoWhileStmt * buildDoWhileStmt(SgStatement *body, SgStatement *condition)
Build do-while statement.
ROSE_DLL_API void errorCheckingTargetAST(SgNode *node_copy, SgNode *node_original, SgFile *targetFile, bool failOnWarning)
Error checking the inserted snippet AST.
ROSE_DLL_API SgDotExp * buildDotExp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgFortranDo * buildFortranDo(SgExpression *initialization, SgExpression *bound, SgExpression *increment, SgBasicBlock *)
Build a Fortran do construct.
ROSE_DLL_API SgPythonGlobalStmt * buildPythonGlobalStmt(SgInitializedNamePtrList &names)
Build a python global statement.
ROSE_DLL_API SgUnsignedLongLongIntVal * buildUnsignedLongLongIntValHex(unsigned long long v=0)
ROSE_DLL_API SgBoolValExp * buildBoolValExp_nfi(int value)
ROSE_DLL_API SgReturnStmt * buildReturnStmt_nfi(SgExpression *expression)
Build a return statement.
ROSE_DLL_API SgClassExp * buildClassExp(SgClassSymbol *sym)
Build class pointer.
ROSE_DLL_API SgTypeChar16 * buildChar16Type()
Built in simple types.
ROSE_DLL_API SgLambdaExp * buildLambdaExp(SgLambdaCaptureList *lambda_capture_list, SgClassDeclaration *lambda_closure_class, SgFunctionDeclaration *lambda_function)
DQ (9/3/2014): Adding support for C++11 Lambda expressions.
ROSE_DLL_API SgWhenStmt * buildWhenStmt(SgExpression *expression, SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
SgAsmStmt * buildAsmStatement_nfi(std::string s)
Build an asm statement.
SgListComprehension * buildListComprehension_nfi(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgClassDeclaration * buildJavaDefiningClassDeclaration(SgScopeStatement *, std::string, SgClassDeclaration::class_types kind=SgClassDeclaration::e_class)
Build a SgFile node and attach it to SgProject.
SgContinueStmt * buildContinueStmt_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAssignInitializer * buildAssignInitializer(SgExpression *operand_i=NULL, SgType *expression_type=NULL)
Build the rhs of a variable declaration which includes an assignment.
ROSE_DLL_API SgArrayType * getUniqueJavaArrayType(SgType *, int)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgLambdaCapture * buildLambdaCapture(SgExpression *capture_variable, SgExpression *source_closure_variable, SgExpression *closure_variable)
ROSE_DLL_API SgRangeExp * buildRangeExp(SgExpression *start)
Build a Matlab range expression like start:end or start:stride:end.
ROSE_DLL_API SgEnumDeclaration * buildEnumDeclaration(const SgName &name, SgScopeStatement *scope=NULL)
Build an enum, It is also a declaration statement in SAGE III.
ROSE_DLL_API SgModifierType * buildConstVolatileType(SgType *base_type=nullptr)
Build a const volatile type.
ROSE_DLL_API SgEnumVal * buildEnumVal(long long int value, SgEnumDeclaration *decl, SgName name)
ROSE_DLL_API SgEnumVal * buildEnumVal_nfi(long long int value, SgEnumDeclaration *decl, SgName name)
ROSE_DLL_API void setTemplateNameInTemplateInstantiations(SgFunctionDeclaration *func, const SgName &name)
DQ (2/11/2012): Added support to set the template name in function template instantiations (member an...
ROSE_DLL_API SgVariableDeclaration * buildVariableDeclaration(const SgName &name, SgType *type, SgInitializer *varInit=NULL, SgScopeStatement *scope=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgFloat128Val * buildFloat128Val(long double value=0.0)
ROSE_DLL_API SgJovialDefineDeclaration * buildJovialDefineDeclaration_nfi(const SgName &name, const std::string &params, const std::string &def_string, SgScopeStatement *scope=NULL)
Build a Jovial define directive declaration statement.
ROSE_DLL_API SgTypeFloat80 * buildFloat80Type()
Built in simple types.
SgBreakStmt * buildBreakStmt_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgWcharVal * buildWcharVal_nfi(wchar_t value, const std::string &str)
ROSE_DLL_API SgFloatVal * buildFloatVal(float value=0.0)
ROSE_DLL_API SgFinishStmt * buildFinishStmt(SgBasicBlock *body)
MH (6/11/2014): Added finish support.
ROSE_DLL_API SgScopeStatement * topScopeStack()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgModifierType * buildUpcRelaxedType(SgType *base_type=nullptr)
Build a UPC relaxed type.
SgScopeStatement * getGlobalScopeFromScopeStack()
Support to retrive the SgGlobal from the internal scope stack (error if not present in a non-empty li...
ROSE_DLL_API SgChooseExpression * buildChooseExpression()
SgClassDefinition * buildClassDefinition_nfi(SgClassDeclaration *d=NULL, bool buildTemplateInstantiation=false)
Build a class definition scope statement.
ROSE_DLL_API SgClassNameRefExp * buildClassNameRefExp(SgClassSymbol *sym)
ROSE_DLL_API SgWithStatement * buildWithStatement(SgExpression *expr, SgStatement *body)
Build a with statement.
SgTemplateClassDefinition * buildTemplateClassDefinition(SgTemplateClassDeclaration *d=NULL)
Build a template class definition statement.
ROSE_DLL_API SgNullExpression * buildNullExpression()
Build a null expression, set file info as the default one.
ROSE_DLL_API SgNaryBooleanOp * buildNaryBooleanOp_nfi(SgExpression *lhs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgModifierType * buildAliasedType(SgType *base_type)
Build an aliased type for Ada.
ROSE_DLL_API SgTupleExp * buildTupleExp(SgExpression *expr1=NULL, SgExpression *expr2=NULL, SgExpression *expr3=NULL, SgExpression *expr4=NULL, SgExpression *expr5=NULL, SgExpression *expr6=NULL, SgExpression *expr7=NULL, SgExpression *expr8=NULL, SgExpression *expr9=NULL, SgExpression *expr10=NULL)
Build a SgTupleExp.
ROSE_DLL_API SgTypeImaginary * buildImaginaryType(SgType *base_type=nullptr)
Build an imaginary type.
ROSE_DLL_API SgStringVal * buildStringVal_nfi(std::string value)
ROSE_DLL_API SgStatementExpression * buildStatementExpression_nfi(SgStatement *exp)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void setTemplateArgumentParents(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgStmtDeclarationStatement * buildStmtDeclarationStatement(SgStatement *stmt)
Build a StmtDeclarationStmt.
ROSE_DLL_API SgAwaitExpression * buildAwaitExpression_nfi()
ROSE_DLL_API SgTemplateParameterVal * buildTemplateParameterVal_nfi(int template_parameter_position, const std::string &str)
ROSE_DLL_API SgJavaQualifiedType * getUniqueJavaQualifiedType(SgClassDeclaration *, SgNamedType *, SgNamedType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgFinishExp * buildFinishExp(SgExpression *expression, SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgYieldExpression * buildYieldExpression(SgExpression *value)
Build a yield statement.
ROSE_DLL_API SgJavaInstanceOfOp * buildJavaInstanceOfOp(SgExpression *exp=NULL, SgType *type=NULL)
This is part of Java specific operator support.
ROSE_DLL_API SgLambdaCaptureList * buildLambdaCaptureList_nfi()
ROSE_DLL_API SgShortVal * buildShortVal(short value=0)
ROSE_DLL_API SgAsmStmt * buildAsmStatement(std::string s)
Build a NULL statement.
ROSE_DLL_API SgModifierType * buildConstType(SgType *base_type=nullptr)
Build a const type.
ROSE_DLL_API void setTemplateArgumentsInDeclaration(SgDeclarationStatement *decl, SgTemplateArgumentPtrList *templateArgumentsList_input)
DQ (9/16/2012): Added function to support setting the template arguments and setting their parents (a...
ROSE_DLL_API SgJavaNormalAnnotation * buildJavaNormalAnnotation(SgType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgDoubleVal * buildDoubleVal_nfi(double value, const std::string &str)
ROSE_DLL_API SgUnsignedShortVal * buildUnsignedShortVal(unsigned short v=0)
Build an unsigned short integer.
ROSE_DLL_API SgInitializedName * buildInitializedName_nfi(const SgName &name, SgType *type, SgInitializer *init, SgVariableDeclaration *declptr=NULL)
Initialized names are tricky, their scope vary depending on context, so scope and symbol information ...
ROSE_DLL_API PreprocessingInfo * buildCpreprocessorDefineDeclaration(SgLocatedNode *target, const std::string &content, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before)
Build and attach #define XX directives, pass "#define xxx xxx" as content.
ROSE_DLL_API SgTypeDouble * buildDoubleType()
Built in simple types.
ROSE_DLL_API SgReferenceType * buildReferenceType(SgType *base_type=nullptr)
Build a reference type.
SgExecStatement * buildExecStatement_nfi(SgExpression *executable, SgExpression *globals=NULL, SgExpression *locals=NULL)
Build an exec stmt.
ROSE_DLL_API SgTypeLongDouble * buildLongDoubleType()
Built in simple types.
ROSE_DLL_API SgTypeLong * buildLongType()
Built in simple types.
ROSE_DLL_API SgExprStatement * buildExprStatement(SgExpression *exp=NULL)
Build a SgExprStatement, set File_Info automatically.
ROSE_DLL_API SgLongIntVal * buildLongIntVal_nfi(long value, const std::string &str)
ROSE_DLL_API SgFunctionParameterRefExp * buildFunctionParameterRefExp(int parameter_number, int parameter_level)
ROSE_DLL_API SgTemplateTypedefDeclaration * buildTemplateTypedefDeclaration_nfi(const SgName &name, SgType *base_type, SgScopeStatement *scope=NULL, bool has_defining_base=false)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void fixupSourcePositionFileSpecification(SgNode *subtreeRoot, const std::string &newFileName)
Change the source file associated with the source position information in the AST.
ROSE_DLL_API SgAssertStmt * buildAssertStmt(SgExpression *test)
Build a Assert statement.
ROSE_DLL_API SgAtExp * buildAtExp(SgExpression *expression, SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgChar32Val * buildChar32Val(unsigned int value=0)
ROSE_DLL_API SgSizeOfOp * buildSizeOfOp_nfi(SgExpression *exp)
Build sizeof() expression with an expression parameter.
ROSE_DLL_API SgIfStmt * buildIfStmt(SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Build if statement.
ROSE_DLL_API SgAsyncStmt * buildAsyncStmt(SgBasicBlock *body)
MH (6/10/2014): Added async support.
ROSE_DLL_API SgFunctionParameterList * buildFunctionParameterList(SgInitializedName *in1=NULL, SgInitializedName *in2=NULL, SgInitializedName *in3=NULL, SgInitializedName *in4=NULL, SgInitializedName *in5=NULL, SgInitializedName *in6=NULL, SgInitializedName *in7=NULL, SgInitializedName *in8=NULL, SgInitializedName *in9=NULL, SgInitializedName *in10=NULL)
Build an empty SgFunctionParameterList, possibly with some initialized names filled in.
ROSE_DLL_API SgModifierType * buildFortranKindType(SgType *base_type, SgExpression *kindExpression)
Build a type based on the Fortran kind mechanism.
ROSE_DLL_API SgPragmaDeclaration * buildPragmaDeclaration(const std::string &name, SgScopeStatement *scope=NULL)
Build pragma declaration, handle SgPragma and defining/nondefining pointers internally.
ROSE_DLL_API SgUnsignedCharVal * buildUnsignedCharVal(unsigned char v=0)
Build an unsigned char.
SgLabelStatement * buildLabelStatement_nfi(const SgName &name, SgStatement *stmt, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAlignOfOp * buildAlignOfOp(SgExpression *exp=NULL)
Build alignof() expression with an expression parameter.
ROSE_DLL_API SgMatlabForStatement * buildMatlabForStatement(SgExpression *loop_index, SgExpression *loop_range, SgBasicBlock *loop_body)
Build a For-loop statement for matlab.
bool inSwitchScope()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgFloat64Val * buildFloat64Val_nfi(double v, const std::string &str)
ROSE_DLL_API SgUpcMythread * buildUpcMythread()
Build UPC MYTHREAD (integer expression)
ROSE_DLL_API SgTypeUnsignedLong * buildUnsignedLongType()
Built in simple types.
ROSE_DLL_API SgPlusPlusOp * buildPlusPlusOp_nfi(SgExpression *op)
ROSE_DLL_API SgSignedCharVal * buildSignedCharValHex(signed char v=0)
ROSE_DLL_API SgTypeShort * buildShortType()
Built in simple types.
ROSE_DLL_API SgNonrealRefExp * buildNonrealRefExp_nfi(SgNonrealSymbol *sym)
Build a reference to the non-real declaration of a member of a non-real class.
SgFunctionCallExp * buildFunctionCallExp_nfi(SgExpression *f, SgExprListExp *parameters=NULL)
ROSE_DLL_API SgTypeVoid * buildVoidType()
Built in simple types.
ROSE_DLL_API void fixupSharingSourcePosition(SgNode *subtreeRoot, int new_file_id)
Sharing IR nodes requires that the file id be added to the fileIDsToUnparse held in the Sg_File_Info ...
ROSE_DLL_API SgAssignInitializer * buildAssignInitializer_nfi(SgExpression *operand_i=NULL, SgType *expression_type=NULL)
ROSE_DLL_API SgTypeBool * buildBoolType()
Built in simple types.
ROSE_DLL_API SgMicrosoftAttributeDeclaration * buildMicrosoftAttributeDeclaration(const SgName &name)
DQ (8/17/2014): Adding support for Microsoft MSVC specific attributes.
ROSE_DLL_API SgStatement * buildStatementFromString(const std::string &stmt_str, SgScopeStatement *scope)
Liao (9/18/2015): experimental support of building a statement from a string.
ROSE_DLL_API SgFile * buildFile(const std::string &inputFileName, const std::string &outputFileName, SgProject *project=NULL, bool clear_globalScopeAcrossFiles=false)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgMemberFunctionDeclaration * buildDefiningMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, bool buildTemplateInstantiation, unsigned int functionConstVolatileFlags, SgMemberFunctionDeclaration *first_nondefinng_declaration, SgTemplateArgumentPtrList *templateArgumentsList)
Build a defining ( non-prototype) member function declaration.
ROSE_DLL_API SgVarRefExp * buildVarRefExp_nfi(SgVariableSymbol *varSymbol)
ROSE_DLL_API SgPointerType * buildPointerType(SgType *base_type=nullptr)
Build a pointer type.
ROSE_DLL_API SgLongDoubleVal * buildLongDoubleVal_nfi(long double value, const std::string &str)
ROSE_DLL_API SgMagicColonExp * buildMagicColonExp()
Build a Matlab colon expression :
ROSE_DLL_API SgTypedefDeclaration * buildTypedefDeclaration(const std::string &name, SgType *base_type, SgScopeStatement *scope=NULL, bool has_defining_base=false)
Build a typedef declaration, such as: typedef int myint; typedef struct A {..} s_A;.
ROSE_DLL_API SgTemplateParameterVal * buildTemplateParameterVal(int template_parameter_position=-1)
Build an template parameter value expression.
ROSE_DLL_API SgFortranContinueStmt * buildFortranContinueStmt()
Build a Fortran continue statement.
ROSE_DLL_API SgFloat128Val * buildFloat128Val_nfi(long double value, const std::string &str)
ROSE_DLL_API SgBoolValExp * buildBoolValExp(int value=0)
Build a bool value expression, the name convention of SgBoolValExp is little different from others fo...
ROSE_DLL_API SgSwitchStatement * buildSwitchStatement(SgStatement *item_selector=NULL, SgStatement *body=NULL)
Build a switch statement.
ROSE_DLL_API SgType * buildOpaqueType(std::string const type_name, SgScopeStatement *scope)
Build an opaque type with a name, useful when a type's details are unknown during transformation,...
ROSE_DLL_API SgTypeChar32 * buildChar32Type()
Built in simple types.
ROSE_DLL_API SgConstructorInitializer * buildConstructorInitializer_nfi(SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type, bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown)
ROSE_DLL_API SgMatrixExp * buildMatrixExp(SgExprListExp *firstRow)
Build a Matlab Matrix.
ROSE_DLL_API SgPassStatement * buildPassStatement()
Build a pass statement.
ROSE_DLL_API SgTypeComplex * buildComplexType(SgType *base_type=nullptr)
Build a complex type.
ROSE_DLL_API SgProcedureHeaderStatement * buildProcedureHeaderStatement(const SgName &name, SgType *return_type, SgFunctionParameterList *parameter_list, SgProcedureHeaderStatement::subprogram_kind_enum, SgScopeStatement *scope=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDeclarationStatement * findAssociatedDeclarationInTargetAST(SgDeclarationStatement *snippet_declaration, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgTypeTuple * buildTupleType(SgType *t1=NULL, SgType *t2=NULL, SgType *t3=NULL, SgType *t4=NULL, SgType *t5=NULL, SgType *t6=NULL, SgType *t7=NULL, SgType *t8=NULL, SgType *t9=NULL, SgType *t10=NULL)
Build a tuple of types. Useful for a function returning multiple variables of different types.
ROSE_DLL_API SgNaryComparisonOp * buildNaryComparisonOp(SgExpression *lhs)
driscoll6 (7/20/11) : Support n-ary operators for python
ROSE_DLL_API SgNonrealType * buildNonrealType(const SgName &name, SgDeclarationScope *scope)
Build a non real type used for template parameter. Internally a SgNorealDecl is also built.
ROSE_DLL_API SgDeclarationScope * buildDeclarationScope()
Build a scope statement. Used to build SgNonrealDecl and SgNonrealType.
ROSE_DLL_API SgName appendTemplateArgumentsToName(const SgName &name, const SgTemplateArgumentPtrList &templateArgumentsList)
DQ (7/27/2012): changed semantics from removing the template arguments in names to adding the templat...
ROSE_DLL_API SgStaticAssertionDeclaration * buildStaticAssertionDeclaration(SgExpression *condition, const SgName &string_literal)
DQ (7/25/2014): Adding support for C11 static assertions.
ROSE_DLL_API SgNullExpression * buildNullExpression_nfi()
No file info version of buildNullExpression(). File info is to be set later on.
ROSE_DLL_API SgFunctionParameterTypeList * buildFunctionParameterTypeList(SgFunctionParameterList *paralist)
Build SgFunctionParameterTypeList from SgFunctionParameterList.
ROSE_DLL_API SgFunctionCallExp * buildMemberFunctionCall(std::string className, SgExpression *objectExpression, std::string functionName, SgExprListExp *params, SgScopeStatement *scope)
Build member function calls.
SgDefaultOptionStmt * buildDefaultOptionStmt_nfi(SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgFloat64Val * buildFloat64Val(double v=0)
Build a float64.
ROSE_DLL_API SgActualArgumentExpression * buildActualArgumentExpression(SgName arg_name, SgExpression *arg)
Build an Actual Argument Expression.
ROSE_DLL_API PreprocessingInfo * buildHeader(const std::string &header_filename, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before, bool isSystemHeader=false)
Build a dangling #include "x.h" header, insertHeader() is needed to actually insert it.
SgPassStatement * buildPassStatement_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgStringVal * buildStringVal(std::string value="")
ROSE_DLL_API SgTypeSignedLong * buildSignedLongType()
Built in simple types.
ROSE_DLL_API SgClassDeclaration * buildDefiningClassDeclaration(SgName name, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
SgGotoStatement * buildGotoStatement_nfi(SgLabelStatement *label)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeChar * buildCharType()
Built in simple types.
ROSE_DLL_API SgTemplateParameterPtrList * getTemplateParameterList(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgClassExp * buildClassExp_nfi(SgClassSymbol *sym)
ROSE_DLL_API SgBreakStmt * buildBreakStmt()
Build a break statement.
ROSE_DLL_API SgForInitStatement * buildForInitStatement_nfi(SgStatementPtrList &statements)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void setTemplateParameterParents(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void pushScopeStack(SgScopeStatement *stmt)
Public interfaces of the scope stack, should be stable.
ROSE_DLL_API SgTypeSignedShort * buildSignedShortType()
Built in simple types.
ROSE_DLL_API SgUsingDirectiveStatement * buildUsingDirectiveStatement(SgNamespaceDeclarationStatement *ns_decl)
Build a using directive statement.
SgDictionaryExp * buildDictionaryExp_nfi(std::vector< SgKeyDatumPair * > pairs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgCastExp * buildCastExp(SgExpression *operand_i=NULL, SgType *expression_type=NULL, SgCastExp::cast_type_enum cast_type=SgCastExp::e_C_style_cast)
Build a type casting expression.
SgTemplateMemberFunctionRefExp * buildTemplateMemberFunctionRefExp_nfi(SgTemplateMemberFunctionSymbol *sym, bool virtual_call, bool need_qualifier)
DQ (12/29/2011): Adding template declaration support to the AST.
ROSE_DLL_API SgRvalueReferenceType * buildRvalueReferenceType(SgType *base_type)
Build a rvalue reference type.
ROSE_DLL_API SgClassDeclaration * buildNondefiningClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, bool buildTemplateInstantiation, SgTemplateArgumentPtrList *templateArgumentsList)
Build a structure first nondefining declaration, without file info.
ROSE_DLL_API SgStmtDeclarationStatement * buildStmtDeclarationStatement_nfi(SgStatement *stmt)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgForInitStatement * buildForInitStatement()
Build a for init statement.
SgDoWhileStmt * buildDoWhileStmt_nfi(SgStatement *body, SgStatement *condition)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void popScopeStack()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgSignedCharVal * buildSignedCharVal(signed char v=0)
Build a signed char.
ROSE_DLL_API SgAlignOfOp * buildAlignOfOp_nfi(SgExpression *exp)
Build alignof() expression with an expression parameter.
ROSE_DLL_API SgVarArgOp * buildVarArgOp_nfi(SgExpression *operand_i, SgType *expression_type)
Build vararg op expression.
ROSE_DLL_API void testTemplateArgumentParents(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeNullptr * buildNullptrType()
Built in simple types.
ROSE_DLL_API SgModifierType * buildUpcStrictType(SgType *base_type=nullptr)
Build a UPC strict type.
ROSE_DLL_API SgExprStatement * buildAssignStatement_ast_translate(SgExpression *lhs, SgExpression *rhs)
This version does not recursively reset the file info as a transformation.
ROSE_DLL_API SgTypeFloat * buildFloatType()
Built in simple types.
ROSE_DLL_API SgDeleteExp * buildDeleteExp(SgExpression *variable, short is_array, short need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
ROSE_DLL_API SgTypeOfType * buildTypeOfType(SgExpression *base_expression, SgType *base_type)
Build a GNU typeof operator.
ROSE_DLL_API SgVoidVal * buildVoidVal()
DQ (2/14/2019): Adding support for C++14 void value expressions.
SgWhileStmt * buildWhileStmt_nfi(SgStatement *condition, SgStatement *body, SgStatement *else_body=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API bool emptyScopeStack()
intended to be a private member, don't access it directly. could be changed any time
SgClassNameRefExp * buildClassNameRefExp_nfi(SgClassSymbol *sym)
ROSE_DLL_API SgFloat80Val * buildFloat80Val_nfi(long double value, const std::string &str)
ROSE_DLL_API SgSetComprehension * buildSetComprehension(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgTypeFloat64 * buildFloat64Type()
Built in simple types.
ROSE_DLL_API SgColonShapeExp * buildColonShapeExp_nfi()
No file info version of buildColonShapeExp(). File info is to be set later on.
ROSE_DLL_API SgVoidVal * buildVoidVal_nfi()
ROSE_DLL_API SgModifierType * buildVolatileType(SgType *base_type=nullptr)
Build a volatile type.
ROSE_DLL_API SgFunctionRefExp * buildFunctionRefExp(const SgName &name, const SgType *func_type, SgScopeStatement *scope=NULL)
Build SgFunctionRefExp based on a C++ function's name and function type. It will lookup symbol table ...
ROSE_DLL_API SgTemplateVariableInstantiation * buildTemplateVariableInstantiation(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope, SgTemplateVariableDeclaration *tpl_decl, SgTemplateArgumentPtrList &tpl_args)
Build template variable declarations.
ROSE_DLL_API SgTypeWchar * buildWcharType()
Built in simple types.
ROSE_DLL_API SgBasicBlock * buildBasicBlock(SgStatement *stmt1=NULL, SgStatement *stmt2=NULL, SgStatement *stmt3=NULL, SgStatement *stmt4=NULL, SgStatement *stmt5=NULL, SgStatement *stmt6=NULL, SgStatement *stmt7=NULL, SgStatement *stmt8=NULL, SgStatement *stmt9=NULL, SgStatement *stmt10=NULL)
Build a SgBasicBlock, setting file info internally.
ROSE_DLL_API SgAggregateInitializer * buildAggregateInitializer(SgExprListExp *initializers=NULL, SgType *type=NULL)
Build an aggregate initializer.
ROSE_DLL_API SgNoexceptOp * buildNoexceptOp_nfi(SgExpression *exp)
Build noexcept operator expression with an expression parameter.
ROSE_DLL_API SgTypeUnknown * buildUnknownType()
Built in simple types.
ROSE_DLL_API SgFoldExpression * buildFoldExpression(SgExpression *operands, std::string operator_token_string, bool is_left_associative)
ROSE_DLL_API SgVariableDeclaration * buildVariableDeclaration_nfi(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope, bool builtFromUseOnly=false, SgStorageModifier::storage_modifier_enum sm=SgStorageModifier::e_default)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeIdOp * buildTypeIdOp(SgExpression *operand_expr, SgType *operand_type)
DQ (1/25/2013): Added support for typeId operators.
ROSE_DLL_API SgExprStatement * buildAssignStatement(SgExpression *lhs, SgExpression *rhs)
Build an assignment statement from lefthand operand and right hand operand.
ROSE_DLL_API SgTypeUnsigned128bitInteger * buildUnsigned128bitIntegerType()
Built in simple types.
ROSE_DLL_API SgUnsignedIntVal * buildUnsignedIntVal(unsigned int v=0)
Build an unsigned integer.
SgFunctionRefExp * buildFunctionRefExp_nfi(SgFunctionSymbol *sym)
ROSE_DLL_API SgCharVal * buildCharVal(char value=0)
SgActualArgumentExpression * buildActualArgumentExpression_nfi(SgName arg_name, SgExpression *arg)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgSizeOfOp * buildSizeOfOp(SgExpression *exp=NULL)
Build sizeof() expression with an expression parameter.
ROSE_DLL_API SgMemberFunctionDeclaration * buildNondefiningMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, bool buildTemplateInstantiation, SgTemplateArgumentPtrList *templateArgumentsList)
Build a prototype member function declaration.
ROSE_DLL_API SgJavaWildcardType * getUniqueJavaWildcardSuper(SgType *)
Build a SgFile node and attach it to SgProject.
SgTypeTraitBuiltinOperator * buildTypeTraitBuiltinOperator(SgName functionName, SgNodePtrList parameters)
SgCompoundLiteralExp * buildCompoundLiteralExp(SgVariableSymbol *varSymbol)
Build function for compound literals (uses a SgVariableSymbol and is similar to buildVarRefExp()).
ROSE_DLL_API SgTemplateVariableInstantiation * buildTemplateVariableInstantiation_nfi(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope, SgTemplateVariableDeclaration *tpl_decl, SgTemplateArgumentPtrList &tpl_args)
Build a variable declaration, handle symbol table transparently.
SgExprListExp * buildExprListExp_nfi()
ROSE_DLL_API SgType * getTargetFileTypeSupport(SgType *snippet_type, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgVariantExpression * buildVariantExpression()
ROSE_DLL_API SgNonrealBaseClass * buildNonrealBaseClass(SgNonrealDecl *classDeclaration, SgClassDefinition *classDefinition, bool isVirtual, bool isDirect)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeSignedInt * buildSignedIntType()
Built in simple types.
ROSE_DLL_API SgBFloat16Val * buildBFloat16Val(float v=0)
Build a bfloat16.
ROSE_DLL_API void fixupCopyOfNodeFromSeparateFileInNewTargetAst(SgStatement *insertionPoint, bool insertionPointIsScope, SgNode *node_copy, SgNode *node_original)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgWcharVal * buildWcharVal(wchar_t value=0)
ROSE_DLL_API SgUnsignedShortVal * buildUnsignedShortValHex(unsigned short v=0)
ROSE_DLL_API SgTemplateMemberFunctionDeclaration * buildDefiningTemplateMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, SgTemplateMemberFunctionDeclaration *first_nondefing_declaration)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgVarRefExp * buildOpaqueVarRefExp(const std::string &varName, SgScopeStatement *scope=NULL)
Build a variable reference expression at scope to an opaque variable which has unknown information ex...
ROSE_DLL_API SgTypeUnsignedChar * buildUnsignedCharType()
Built in simple types.
ROSE_DLL_API SgJavaMarkerAnnotation * buildJavaMarkerAnnotation(SgType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgUnsignedIntVal * buildUnsignedIntVal_nfi(unsigned int v, const std::string &str)
ROSE_DLL_API SgNaryBooleanOp * buildNaryBooleanOp(SgExpression *lhs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgModifierType * buildUpcBlockNumberType(SgType *base_type, long block_factor)
Build a UPC shared[n] type.
ROSE_DLL_API SgStatementExpression * buildStatementExpression(SgStatement *exp)
Build a GNU statement expression.
ROSE_DLL_API SgTypeSignedChar * buildSignedCharType()
Built in simple types.
ROSE_DLL_API SgUpcWaitStatement * buildUpcWaitStatement_nfi(SgExpression *exp)
Build a UPC wait statement.
ROSE_DLL_API SgDoubleVal * buildDoubleVal(double value=0.0)
Build a double value expression.
ROSE_DLL_API SgMemberFunctionDeclaration * buildDefaultConstructor(SgClassType *classType)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUnsignedLongLongIntVal * buildUnsignedLongLongIntVal_nfi(unsigned long long v, const std::string &str)
ROSE_DLL_API SgAutoType * buildAutoType()
Built in simple types.
ROSE_DLL_API SgMemberFunctionRefExp * buildMemberFunctionRefExp(SgMemberFunctionSymbol *sym, bool virtual_call, bool need_qualifier)
ROSE_DLL_API SgFloat16Val * buildFloat16Val(float v=0)
Build a float16.
ROSE_DLL_API SgHereExp * buildHereExpression()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgPlusPlusOp * buildPlusPlusOp(SgExpression *op=NULL)
ROSE_DLL_API SgComplexVal * buildComplexVal(SgValueExp *real_value, SgValueExp *imaginary_value)
ROSE_DLL_API SgNamespaceDeclarationStatement * buildNamespaceDeclaration_nfi(const SgName &name, bool unnamednamespace, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgIntVal * buildIntVal(int value=0)
Build an integer value expression.
SgYieldExpression * buildYieldExpression_nfi(SgExpression *value)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgChar32Val * buildChar32Val_nfi(unsigned int value, const std::string &str)
ROSE_DLL_API DeclClass * buildClassDeclarationStatement_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope=NULL, SgClassDeclaration *nonDefiningDecl=NULL)
Build a generic class declaration statement (SgClassDeclaration or subclass) with a class declaration...
SgTemplateFunctionRefExp * buildTemplateFunctionRefExp_nfi(SgTemplateFunctionSymbol *sym)
DQ (12/15/2011): Adding template declaration support to the AST.
ROSE_DLL_API SgNullStatement * buildNullStatement()
Build a NULL statement.
ROSE_DLL_API SgUpcNotifyStatement * buildUpcNotifyStatement_nfi(SgExpression *exp)
Build a UPC notify statement.
ROSE_DLL_API SgConstVolatileModifier * buildConstVolatileModifier(SgConstVolatileModifier::cv_modifier_enum mtype=SgConstVolatileModifier::e_unknown)
Build a const/volatile type qualifier.
ROSE_DLL_API SgJavaForEachStatement * buildJavaForEachStatement(SgVariableDeclaration *=NULL, SgExpression *=NULL, SgStatement *=NULL)
Build a Java Foreach statement.
ROSE_DLL_API SgBracedInitializer * buildBracedInitializer(SgExprListExp *initializers=NULL, SgType *expression_type=NULL)
Build an braced initializer.
ROSE_DLL_API SgFunctionType * buildFunctionType(SgType *return_type, SgFunctionParameterTypeList *typeList=nullptr)
Build function type from return type and parameter type list.
ROSE_DLL_API SgScopeStatement * buildScopeStatement(SgClassDefinition *=NULL)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgDictionaryExp * buildDictionaryExp(std::vector< SgKeyDatumPair * > pairs)
Build a list of key-datum pairs.
ROSE_DLL_API SgLambdaCaptureList * buildLambdaCaptureList()
ROSE_DLL_API SgJovialForThenStatement * buildJovialForThenStatement_nfi()
Build a Jovial loop statement.
ROSE_DLL_API SgInitializedName * buildJavaFormalParameter(SgType *, const SgName &, bool is_var_args=false, bool is_final=false)
Build a SgFile node and attach it to SgProject.
SgDeclarationStatement * associatedDeclaration(const SgSymbol &n)
returns the associated declaration for symbol n or nullptr if there is none.
Functions that are useful when operating on the AST.
Definition sageBuilder.h:25
void initializeIfStmt(SgIfStmt *ifstmt, SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void fixNamespaceDeclaration(SgNamespaceDeclarationStatement *structDecl, SgScopeStatement *scope)
Fix symbols, parent and scope pointers. Used internally within appendStatment(), insertStatement() et...
ROSE_DLL_API bool is_Jovial_language()
ROSE_DLL_API bool hasSameGlobalScope(SgStatement *statement_1, SgStatement *statement_2)
This is supporting the recognition of functions in header files from two different ASTs.
ROSE_DLL_API bool language_may_contain_nondeclarations_in_scope()
ROSE_DLL_API void fixStructDeclaration(SgClassDeclaration *structDecl, SgScopeStatement *scope)
Fix symbols, parent and scope pointers. Used internally within appendStatment(), insertStatement() et...
ROSE_DLL_API void appendExpressionList(SgExprListExp *, const std::vector< SgExpression * > &)
Append an expression list to a SgExprListExp, set the parent pointers also.
ROSE_DLL_API int set_name(SgInitializedName *initializedNameNode, SgName new_name)
set_name of symbol in symbol table.
ROSE_DLL_API SgVariableSymbol * getFirstVarSym(SgVariableDeclaration *decl)
Get the variable symbol for the first initialized name of a declaration stmt.
void initializeSwitchStatement(SgSwitchStatement *switchStatement, SgStatement *item_selector, SgStatement *body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void setOneSourcePositionForTransformation(SgNode *root)
Set current node's source position as transformation generated.
PreprocessingInfo * attachComment(SgSourceFile *source_file, const std::string &content, PreprocessingInfo::DirectiveType directive_type=PreprocessingInfo::C_StyleComment, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before)
Build and attach comment onto the global scope of a source file.
ROSE_DLL_API SgInitializedName * getFirstInitializedName(SgVariableDeclaration *decl)
Get the first initialized name of a declaration statement.
ROSE_DLL_API void reportModifiedStatements(const std::string &label, SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API void setSourcePositionForTransformation(SgNode *root)
Recursively set source position info(Sg_File_Info) as transformation generated.
ROSE_DLL_API SgGlobal * getGlobalScope(const SgNode *astNode)
Traverse back through a node's parents to find the enclosing global scope.
ROSE_DLL_API bool templateArgumentListEquivalence(const SgTemplateArgumentPtrList &list1, const SgTemplateArgumentPtrList &list2)
Verify that 2 SgTemplateArgumentPtrList are equivalent.
ROSE_DLL_API void reportModifiedLocatedNodes(const std::string &label, SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
void initializeWhileStatement(SgWhileStmt *whileStatement, SgStatement *condition, SgStatement *body, SgStatement *else_body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void setSourcePosition(SgNode *node)
Set the source code positon for the current (input) node.
bool isStructurallyEquivalentAST(SgNode *tree1, SgNode *tree2)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API bool is_language_case_insensitive()
ROSE_DLL_API SgFunctionSymbol * lookupFunctionSymbolInParentScopes(const SgName &functionName, SgScopeStatement *currentScope=NULL)
look up the first matched function symbol in parent scopes given only a function name,...
ROSE_DLL_API SgFile * getEnclosingFileNode(SgNode *astNode)
get the SgFile node from current node
bool ROSE_DLL_API isAncestor(SgNode *node1, SgNode *node2)
check if node1 is a strict ancestor of node 2. (a node is not considered its own ancestor)
ROSE_DLL_API void resetModifiedLocatedNodes(const std::set< SgLocatedNode * > &modifiedNodeSet)
Use the set of IR nodes and set the isModified flag in each IR node to true.
ROSE_DLL_API SgEnumSymbol * lookupEnumSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API SgTypedefSymbol * lookupTypedefSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API bool is_Fortran_language()
ROSE_DLL_API SgVariableSymbol * lookupVariableSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API void outputFileIds(SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API SgTemplateClassSymbol * lookupTemplateClassSymbolInParentScopes(const SgName &name, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateArgumentList, SgScopeStatement *cscope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
void collectVarRefs(SgLocatedNode *root, std::vector< SgVarRefExp * > &result)
Collect all variable references in a subtree.
ROSE_DLL_API SgVariableSymbol * appendArg(SgFunctionParameterList *, SgInitializedName *)
Append an argument to SgFunctionParameterList, transparently set parent,scope, and symbols for argume...
ROSE_DLL_API int fixVariableReferences(SgNode *root, bool cleanUnusedSymbol=true)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API void appendStatement(SgStatement *stmt, SgScopeStatement *scope=NULL)
Append a statement to the end of the current scope, handle side effect of appending statements,...
ROSE_DLL_API void setOneSourcePositionNull(SgNode *node)
Set current node's source position as NULL.
ROSE_DLL_API void fixVariableDeclaration(SgVariableDeclaration *varDecl, SgScopeStatement *scope)
Patch up symbol, scope, and parent information when a SgVariableDeclaration's scope is known.
ROSE_DLL_API SgFunctionDefinition * getEnclosingProcedure(SgNode *n, const bool includingSelf=false)
Find the function definition.
std::string get_name(const SgNode *node)
Generate a useful name to describe the SgNode.
ROSE_DLL_API bool is_Ada_language()
ROSE_DLL_API std::set< SgLocatedNode * > collectModifiedLocatedNodes(SgNode *node)
This collects the SgLocatedNodes that are marked as modified (a flag automatically set by all set_* g...
ROSE_DLL_API void fixLabelStatement(SgLabelStatement *label_stmt, SgScopeStatement *scope)
Fix symbol table for SgLabelStatement. Used Internally when the label is built without knowing its ta...
ROSE_DLL_API void appendStatementList(const std::vector< SgStatement * > &stmt, SgScopeStatement *scope=NULL)
Append a list of statements to the end of the current scope, handle side effect of appending statemen...
bool hasTemplateSyntax(const SgName &name)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API SgClassSymbol * lookupClassSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL, SgTemplateArgumentPtrList *templateArgumentList=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API void appendExpression(SgExprListExp *, SgExpression *)
Append an expression to a SgExprListExp, set the parent pointer also.
ROSE_DLL_API void prependStatement(SgStatement *stmt, SgScopeStatement *scope=NULL)
Prepend a statement to the beginning of the current scope, handling side effects as appropriate.
ROSE_DLL_API void setSourcePositionAtRootAndAllChildren(SgNode *root)
Set the source code positon for the subtree (including the root).
ROSE_DLL_API SgExpression * copyExpression(SgExpression *e)
Deep copy an expression.
void setParameterList(actualFunction *func, SgFunctionParameterList *paralist)
Set parameter list for a function declaration, considering existing parameter list etc.
ROSE_DLL_API SgFunctionType * findFunctionType(SgType *return_type, SgFunctionParameterTypeList *typeList)
Find the function type matching a function signature plus a given return type.