ROSE 0.11.145.210
sageBuilder.C
1// tps (01/14/2010) : Switching from rose.h to sage3
2// test cases are put into tests/nonsmoke/functional/roseTests/astInterfaceTests
3// Last modified, by Liao, Jan 10, 2008
4
5// includes "sageBuilder.h"
6#include "sage3basic.h"
7
8#include <rose_config.h>
9
10#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
11 #include "roseAdapter.h"
12 #include "markLhsValues.h"
13 #include <fstream>
14 #include "Outliner.hh"
15#else
16 #include <fstream>
17 #include "transformationSupport.h"
18#endif
19
20#include <boost/algorithm/string/trim.hpp>
21
22// DQ (4/3/2012): Added so that I can enforce some rules as the AST is constructed.
23#include "AstConsistencyTests.h"
24
25// DQ (2/27/2014): We need this feature to support the function: fixupCopyOfAstFromSeparateFileInNewTargetAst()
26#include "RoseAst.h"
27
28// DQ (2/17/2013): This is a operation on the global AST that we don't need to do too often
29// depending on the grainularity sought for the debugging information. It is done on the
30// whole AST once after construction (in edgRose.C), but is not needed more than that
31// since it is a performance issue.
32#define BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS 0
33#define BUILDER_MAKE_REDUNDANT_CALLS_TO_SYMBOL_TABLE_LOOKUP 0
34
35using namespace std;
36using namespace Rose;
37using namespace SageInterface;
38using namespace Rose::Diagnostics;
39
40namespace EDG_ROSE_Translation
41 {
42 // DQ (6/3/2019): The case of outlining to a seperate file will have transformations
43 // that this checking will fail on because it is for the typical case of checking the
44 // AST for transformations after construction of the AST from an typical input file.
45#if defined(ROSE_BUILD_CXX_LANGUAGE_SUPPORT) && !defined(ROSE_USE_CLANG_FRONTEND)
46 // DQ (6/3/2019): Use the definition in the EDG edgRose.C file if C/C++ support IS defined.
47 extern bool suppress_detection_of_transformations;
48#else
49 // DQ (6/3/2019): Allow this to be the definition if C/C++ support is NOT defined.
50 bool suppress_detection_of_transformations;
51#endif
52 }
53
54// MS 2015: utility functions used in the implementation of SageBuilder functions, but are not exposed in the SageBuilder-Interface.
55namespace SageBuilder {
56
57// DQ (3/24/2016): Adding Robb's message mechanism (data member and function).
59void
60initDiagnostics()
61 {
62 static bool initialized = false;
63 if (!initialized)
64 {
65 initialized = true;
66 Rose::Diagnostics::initAndRegister(&mlog, "Rose::SageBuilder");
67 mlog.comment("building abstract syntax trees");
68 }
69 }
70
71
72template <class actualFunction>
73actualFunction*
74buildNondefiningFunctionDeclaration_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);
75
76// DQ (8/11/2013): Note that the specification of the SgTemplateArgumentPtrList is somewhat redundant with the required parameter first_nondefinng_declaration (I think).
78template <class actualFunction>
79actualFunction*
80buildDefiningFunctionDeclaration_T (const SgName & name, SgType* return_type, SgFunctionParameterList * parlist, bool isMemberFunction, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, actualFunction* first_nondefinng_declaration, SgTemplateArgumentPtrList* templateArgumentsList);
81
83template <class T> ROSE_DLL_API void resetDeclaration(T* classDeclaration_copy, T* classDeclaration_original, SgScopeStatement* targetScope);
84
85}; // SageBuilder namespace
86
87//---------------------------------------------
88// scope stack interfaces
89// hide actual implementation of the stack
90//---------------------------------------------
91
92// DQ (1/18/2008): Added declaration in source file with Liao.
93// std::list<SgScopeStatement*> SageBuilder::ScopeStack;
94std::list<SgScopeStatement*> SageBuilder::ScopeStack(0);
95
96
97// DQ (11/30/2010): Added support for building Fortran case insensitive symbol table handling.
98// Support for construction of case sensitive/insensitive symbol table handling in scopes.
99// Rasmussen (3/22/2020): Setting this variable to properly reflect language properties
100// was removed in 2017. I would like to remove it from SageBuilder.
102
103
105// (used to control how the source code positon is defined for IR nodes built within the SageBuilder interface).
106// Set the default to be to mark everything as a transformation.
108
109
112 {
113 ASSERT_not_null(classType);
114
115 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
116 ASSERT_not_null(classDeclaration);
117
118 SgName className = classDeclaration->get_name();
119
120#if 0
121 printf ("In SageBuilder::buildDefaultConstructor(): building default constructor for class = %s \n",className.str());
122#endif
123
124 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(classDeclaration->get_definingDeclaration());
125 ASSERT_not_null(definingClassDeclaration);
126 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
127 ASSERT_not_null(classDefinition);
128
130 ASSERT_not_null(functionParameterList);
131
132 // Constructors are specified with type void internally, though the type name is not output.
133 SgType* return_type = SageBuilder::buildVoidType();
134 ASSERT_not_null(return_type);
135
136 SgExprListExp* decoratorList = nullptr;
137 bool buildTemplateInstantiation = false;
138
139 // These are zero for a constructor.
140 unsigned int functionConstVolatileFlags = 0;
141
142 SgTemplateArgumentPtrList templateArgumentsList;
143
144 SgMemberFunctionDeclaration* first_nondefining_declaration = buildNondefiningMemberFunctionDeclaration (className, return_type, functionParameterList,
145 classDefinition, decoratorList, functionConstVolatileFlags, buildTemplateInstantiation, &templateArgumentsList);
146 ASSERT_not_null(first_nondefining_declaration);
147
148 first_nondefining_declaration->get_specialFunctionModifier().setConstructor();
149 ROSE_ASSERT(first_nondefining_declaration->get_specialFunctionModifier().isConstructor() == true);
150
151 // DQ (11/10/2020): Need to make sure that the firstNondefiningDeclaration is being used (reset is needed).
152 if (first_nondefining_declaration->get_firstNondefiningDeclaration() != first_nondefining_declaration)
153 {
154 first_nondefining_declaration = isSgMemberFunctionDeclaration(first_nondefining_declaration->get_firstNondefiningDeclaration());
155 }
156 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
157
158 SgMemberFunctionDeclaration* memberFunctionDeclaration = SageBuilder::buildDefiningMemberFunctionDeclaration (className, return_type, functionParameterList,
159 classDefinition, decoratorList, buildTemplateInstantiation, functionConstVolatileFlags, first_nondefining_declaration, &templateArgumentsList);
160 ASSERT_not_null(memberFunctionDeclaration);
161
162 memberFunctionDeclaration->get_specialFunctionModifier().setConstructor();
163 ROSE_ASSERT(memberFunctionDeclaration->get_specialFunctionModifier().isConstructor() == true);
164
165 // We return the default constructor and the use should insert it, I think.
166 // classDefinition->prepend_statement(memberFunctionDeclaration);
167
168 // Mark the constructor as public.
169 memberFunctionDeclaration->get_declarationModifier().get_accessModifier().setPublic();
170
171 ROSE_ASSERT (memberFunctionDeclaration->get_declarationModifier().get_accessModifier().isPublic() == true);
172
173#if 0
174 // DQ (6/27/2021): Added debugging information. It appears that when we build the prototype for a default
175 // constructor we also build the defining declaration, which might not always exist in the original source
176 // file. So this seems like a potential subtle error.
177 printf ("In SageBuilder::buildDefaultConstructor(): building default constructor for class = %s \n",className.str());
178 printf (" --- memberFunctionDeclaration = %p \n",memberFunctionDeclaration);
179 printf (" --- first_nondefining_declaration = %p \n",first_nondefining_declaration);
180 printf (" --- memberFunctionDeclaration->get_firstNondefiningDeclaration() = %p \n",memberFunctionDeclaration->get_firstNondefiningDeclaration());
181 printf (" --- memberFunctionDeclaration->get_definingDeclaration() = %p \n",memberFunctionDeclaration->get_definingDeclaration());
182#endif
183
184 return memberFunctionDeclaration;
185 }
186
187
194
196void
201
202string
204 {
205 // DQ (11/19/2012): This function is build to support debugging the value of the statically defined mode.
206
207 string s;
208 switch(scp)
209 {
210 case e_sourcePositionError: s = "e_sourcePositionError"; break;
211 case e_sourcePositionDefault: s = "e_sourcePositionDefault"; break;
212 case e_sourcePositionTransformation: s = "e_sourcePositionTransformation"; break;
213 case e_sourcePositionCompilerGenerated: s = "e_sourcePositionCompilerGenerated"; break;
214 case e_sourcePositionNullPointers: s = "e_sourcePositionNullPointers"; break;
215 case e_sourcePositionFrontendConstruction: s = "e_sourcePositionFrontendConstruction"; break;
216 case e_sourcePosition_last: s = "e_sourcePosition_last"; break;
217
218 default:
219 {
220 printf ("Error: default reached in SageBuilder::display(SourcePositionClassification & scp): scp = %d \n",scp);
221 ROSE_ABORT();
222 }
223
224 }
225
226 return s;
227 }
228
229
230// DQ (5/21/2013): Added function to support hidding the implementation in the SgScopeStatement API.
231// template <class T> SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function (const SgName & name, const SgType* func_type)
232template <class T>
234SgScopeStatement::find_symbol_by_type_of_function (const SgName & name, const SgType* func_type, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateArgumentsList)
235 {
236 // DQ (3/13/2012): This is to address the fact that there are 6 different types of functions in ROSE:
237 // 1) SgFunctionDeclaration
238 // 2) SgMemberFunctionDeclaration
239 // 3) SgTemplateFunctionDeclaration
240 // 4) SgTemplateMemberFunctionDeclaration
241 // 5) SgTemplateFunctionInstntiationDeclaration
242 // 6) SgTemplateMemberFunctionInstntiationDeclaration
243 // And 4 different types of function symbols:
244 // 1) SgFunctionSymbol
245 // 2) SgMemberFunctionSymbol
246 // 3) SgTemplateFunctionSymbol
247 // 4) SgTemplateMemberFunctionSymbol
248 // Note that both:
249 // SgTemplateFunctionInstntiationDeclaration
250 // SgTemplateMemberFunctionInstntiationDeclaration
251 // map to
252 // SgFunctionSymbol
253 // SgMemberFunctionSymbol
254 // respectively.
255
256 // Check if there is a function symbol of any kind, then narrow the selection.
257 SgFunctionSymbol* func_symbol = nullptr;
258
259 {
260 // Use the static variant as a selector.
261 switch((VariantT)T::static_variant)
262 {
263 case V_SgFunctionDeclaration:
264 case V_SgProcedureHeaderStatement:
265 case V_SgTemplateInstantiationFunctionDecl:
266 {
267 // DQ (8/11/2013): Verify that the template arguments are provided for the correct cases and not for the incorrect cases.
268 if ((VariantT)T::static_variant == V_SgTemplateInstantiationFunctionDecl)
269 {
270 ROSE_ASSERT(templateArgumentsList != NULL);
271 }
272 else
273 {
274 ROSE_ASSERT(templateArgumentsList == NULL);
275 }
276
277 // DQ (5/21/2013): Calling the SgScopeStatement API.
278 func_symbol = lookup_nontemplate_function_symbol(name,func_type,templateArgumentsList);
279 // DQ (5/22/2013): This function symbol should not be a SgTemplateFunctionSymbol (associated with a template function. It should be an instantiated template.
280 ROSE_ASSERT(isSgTemplateFunctionSymbol(func_symbol) == NULL);
281 break;
282 }
283
284 case V_SgMemberFunctionDeclaration:
285 case V_SgTemplateInstantiationMemberFunctionDecl:
286 {
287 // DQ (5/21/2013): there is no SgScopeStatement API that calls this function.
288 // DQ (8/11/2013): Verify that the template arguments are provided for the correct cases and not for the incorrect cases.
289 if ((VariantT)T::static_variant == V_SgTemplateInstantiationMemberFunctionDecl)
290 {
291 ROSE_ASSERT(templateArgumentsList != NULL);
292 }
293 else
294 {
295 ROSE_ASSERT(templateArgumentsList == NULL);
296 }
297 func_symbol = lookup_nontemplate_member_function_symbol(name,func_type,templateArgumentsList);
298 break;
299 }
300
301 case V_SgTemplateFunctionDeclaration:
302 {
303 // DQ (8/11/2013): I think this should fail in cases were we should be handing the templateArgumentsList
304 // to the lookup_template_function_symbol() function.
305 ROSE_ASSERT(templateArgumentsList == NULL);
306
307 // DQ (8/11/2013): I think this should always be non-null.
308 ROSE_ASSERT(templateParameterList != NULL);
309
310 // DQ (8/7/2013): Adding support to permit template function overloading on template parameters.
311 // Note that the template arguments are being handed in as templateSpecializationArgumentList since this is the matching list.
312 // However, we might expect template parameter.
313
314 // DQ (8/7/2013): Adding support for template function overloading using template parameters (info passed as template arguments for specialization).
315 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
316 // In this case these are unavailable from this point.
317 // DQ (5/21/2013): Calling the SgScopeStatement API.
318 func_symbol = lookup_template_function_symbol(name,func_type,templateParameterList);
319
320 break;
321 }
322
323 case V_SgTemplateMemberFunctionDeclaration:
324 {
325 // DQ (8/11/2013): I think this should fail in cases were we should be handing the templateArgumentsList
326 // to the lookup_template_member_function_symbol() function.
327 ROSE_ASSERT(templateArgumentsList == NULL);
328
329 // DQ (8/11/2013): I think this sould always be non-null.
330 ROSE_ASSERT(templateParameterList != NULL);
331
332 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
333 // In this case these are unavailable from this point.
334 // DQ (5/21/2013): Calling the SgScopeStatement API.
335 func_symbol = lookup_template_member_function_symbol(name,func_type,templateParameterList);
336 break;
337 }
338
339 default:
340 {
341 printf ("In SgScopeStatement::find_symbol_by_type_of_function(): default reached --- variantT(T::static_variant) = %d \n",T::static_variant);
342 ROSE_ABORT();
343 }
344 }
345 }
346 return func_symbol;
347 }
348
349
350// explicit instantiation of find_symbol_by_type_of_function
351template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgTemplateFunctionDeclaration>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
352template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgTemplateInstantiationMemberFunctionDecl>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
353template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgTemplateInstantiationFunctionDecl>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
354template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgMemberFunctionDeclaration>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
355template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgTemplateMemberFunctionDeclaration>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
356template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgFunctionDeclaration>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
357
358void
360 {
361 ASSERT_not_null(stmt);
362 ScopeStack.push_back(stmt);
363 }
364
366 {
367 ASSERT_require(ScopeStack.empty() == false);
368 ScopeStack.pop_back();
369 }
370
372 {
373 // If this is an empty stack, return nullptr (ScopeStack.back() should be undefined for this case).
374 if (ScopeStack.empty()) {
375 return nullptr;
376 }
377
378 // DQ (9/28/2009): This is part of testing for GNU 4.0.x (other versions of g++ work fine).
379 SgScopeStatement* tempScope = ScopeStack.back();
380 if (tempScope) {
381 tempScope->class_name();
382 }
383
384 return tempScope;
385 }
386
387
390 {
391 // This function adds new support within the internal scope stack mechanism.
392
393 // DQ (3/20/2017): This branch is never taken and can be reported as an error (this improves code coverage).
394 // DQ (3/11/2012): Test if this is an empty stack, and if so return NULL (ScopeStack.back() should be undefined for this case).
395 ROSE_ASSERT(ScopeStack.empty() == false);
396
397 // The SgGlobal scope should be the first (front) element in the list (the current scope at the end (back) of the list).
398 SgScopeStatement* tempScope = ScopeStack.front();
399 ASSERT_not_null(isSgGlobal(tempScope));
400
401 return tempScope;
402 }
403
405 {
406 return ScopeStack.empty();
407 }
408
410 {
411 ScopeStack.clear();
412 }
413
415 {
416 // DQ (11/26/2012): This is used to turn off some pragma processing which is a problem in switch statements.
417 bool returnVar = false;
418 std::list<SgScopeStatement*>::iterator i;
419 for (i = ScopeStack.begin(); i != ScopeStack.end(); i++)
420 {
421 if (isSgSwitchStatement(*i) != nullptr)
422 returnVar = true;
423 }
424
425 return returnVar;
426 }
427
428// *******************************************************************************
429// ******************************* Build Functions *****************************
430// *******************************************************************************
431SgName
432SageBuilder::appendTemplateArgumentsToName( const SgName & name, const SgTemplateArgumentPtrList & templateArgumentsList)
433 {
434 // DQ (7/23/2012): This function is somewhat redundant with the SgDeclarationStatement::resetTemplateNameSupport() in that
435 // they both have to generate identical names. this was a problem and thus this code is seneitive to " ," instead of ","
436 // below.
437
438 // DQ (7/23/2012): This is one of three locations where the template arguments are assembled and where
439 // the name generated identically (in each case) is critical. Not clear how to best refactor this code.
440 // The other two are:
441 // Unparse_ExprStmt::unparseTemplateArgumentList()
442 // and in:
443 // void SgDeclarationStatement::resetTemplateNameSupport ( bool & nameResetFromMangledForm, SgName & name )
444 // It is less clear how to refactor this code.
445
446#define DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST 0
447
448#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST
449 printf ("In SageBuilder::appendTemplateArgumentsToName(): CRITICAL FUNCTION TO BE REFACTORED (name = %s) \n",name.str());
450#endif
451
452 // DQ (3/10/2018): This is now partially redundant with SgTemplateArgumentList::unparseToStringSupport().
453 SgUnparse_Info *info = new SgUnparse_Info();
454 ASSERT_not_null(info);
455
456 info->set_language(SgFile::e_Cxx_language);
457 info->set_requiresGlobalNameQualification();
458
459 // DQ (4/28/2017): For template arguments we never want to output the definitions of classes, and enums.
460 info->set_SkipClassDefinition();
461 info->set_SkipEnumDefinition();
462 info->set_use_generated_name_for_template_arguments(true);
463
464 bool emptyArgumentList = templateArgumentsList.empty();
465
466 // DQ (9/24/2012): Don't add "< >" if there are no template arguments (see test2012_221.C).
467 // SgName returnName = name + " < ";
468 SgName returnName = name;
469 if (emptyArgumentList == false)
470 returnName += " < ";
471
472 SgTemplateArgumentPtrList::const_iterator i = templateArgumentsList.begin();
473 bool need_separator = false;
474
475 bool exit_after_name_is_generated = false;
476
477 while (i != templateArgumentsList.end())
478 {
479 if ((*i)->get_argumentType() == SgTemplateArgument::start_of_pack_expansion_argument)
480 {
481 i++;
482 continue;
483 }
484
485 if (need_separator)
486 {
487 returnName += " , ";
488 }
489
490#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST
491 printf ("In SageBuilder::appendTemplateArgumentsToName(): (top of loop) templateArgumentsList element *i = %p = %s returnName = %s \n",*i,(*i)->class_name().c_str(),returnName.str());
492#endif
493
494 // DQ (2/5/2022): We need to use a fully qualified name as demonstrated by test2022_05.C.
495 // Where there are two different template arguments with the same name (e.g. in different
496 // namespaces) the generated names will be the same and the symbols will collide in the
497 // symbol table for the scope where they are both constructed.
498 // So a fix is to add the fully qualified name of the scope of the expression used as a template argument.
499
500 // DQ (2/6/2022): Newer version of code (still refactoring this section).
501 bool used_fully_qualified_name = false;
502
503#define DEBUG_TEMPLATE_ARGUMENT_NAMES 0
504
505 // DQ (2/6/2022): This is the newly refactored implementation to add name qualification to
506 // the template arguments in the used in symbol tables key for template instantiations.
507 SgTemplateArgument* templateArgument = *i;
508 ASSERT_not_null(templateArgument);
509
510 switch (templateArgument->get_argumentType())
511 {
513 {
514 SgType* type = templateArgument->get_type();
515 ASSERT_not_null(type);
516
517#if DEBUG_TEMPLATE_ARGUMENT_NAMES
518 printf ("In SageBuilder::appendTemplateArgumentsToName(): case SgTemplateArgument::type_argument: BEFORE stripType: type = %p = %s \n",type,type->class_name().c_str());
519#endif
520 // I think that we need to strip off any pointer or reference modifier types.
521 // 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 | SgType::STRIP_POINTER_MEMBER_TYPE);
522 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_POINTER_MEMBER_TYPE);
523 type = type->stripType(bit_array);
524
525#if DEBUG_TEMPLATE_ARGUMENT_NAMES
526 printf ("In SageBuilder::appendTemplateArgumentsToName(): case SgTemplateArgument::type_argument: AFTER stripType: type = %p = %s \n",type,type->class_name().c_str());
527#endif
528 // DQ (2/6/2022): We need to find an example of the case where the template argument is a pointer type.
529 if (isSgPointerType(templateArgument->get_type()) != nullptr)
530 {
531
532#if DEBUG_TEMPLATE_ARGUMENT_NAMES
533 printf ("Found a templateArgument->get_type() that is SgPointerType: name = %s \n",name.str());
534#endif
535 }
536
537 SgNamedType* namedType = isSgNamedType(type);
538 if (namedType != nullptr)
539 {
540 // DQ (2/5/2022): Since SgNonrealType is a SgNamedType, is this sufficiant to handle those cases?
541 SgDeclarationStatement* declaration = namedType->get_declaration();
542 ASSERT_not_null(declaration);
543
544 switch (declaration->variantT())
545 {
546 case V_SgTemplateInstantiationDecl:
547 case V_SgTemplateClassDeclaration:
548 case V_SgClassDeclaration:
549 {
550 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
551 string fully_qualified_name = classDeclaration->get_qualified_name();
552#if DEBUG_TEMPLATE_ARGUMENT_NAMES
553 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
554#endif
555 returnName += fully_qualified_name;
556 used_fully_qualified_name = true;
557 break;
558 }
559
560 case V_SgTemplateInstantiationTypedefDeclaration:
561 case V_SgTemplateTypedefDeclaration:
562 case V_SgTypedefDeclaration:
563 {
564 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(declaration);
565 string fully_qualified_name = typedefDeclaration->get_qualified_name();
566#if DEBUG_TEMPLATE_ARGUMENT_NAMES
567 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
568#endif
569 returnName += fully_qualified_name;
570 used_fully_qualified_name = true;
571 break;
572 }
573
574 case V_SgEnumDeclaration:
575 {
576 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(declaration);
577 string fully_qualified_name = enumDeclaration->get_qualified_name();
578#if DEBUG_TEMPLATE_ARGUMENT_NAMES
579 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
580#endif
581 returnName += fully_qualified_name;
582 used_fully_qualified_name = true;
583 break;
584 }
585
586 // DQ (2/5/2022): Is this implementation correct for SgNonrealDecl?
587 case V_SgNonrealDecl:
588 {
589 SgNonrealDecl* nonrealDeclaration = isSgNonrealDecl(declaration);
590 string fully_qualified_name = nonrealDeclaration->get_qualified_name();
591#if DEBUG_TEMPLATE_ARGUMENT_NAMES
592 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
593#endif
594 returnName += fully_qualified_name;
595 used_fully_qualified_name = true;
596 break;
597 }
598
599 default:
600 {
601 // I'm not clear if we need to support any other cases, so this default case is an error.
602 printf ("In SageBuilder::appendTemplateArgumentsToName(): default reached: get_type() != NULL: declaration = %s \n",declaration->class_name().c_str());
603 ROSE_ASSERT(false);
604 }
605 }
606 }
607 else
608 {
609#if DEBUG_TEMPLATE_ARGUMENT_NAMES
610 printf ("In SageBuilder::appendTemplateArgumentsToName(): not a SgNamedType: get_type() != NULL: type = %s \n",type->class_name().c_str());
611#endif
612 }
613
614 break;
615 }
616
618 {
619 // DQ (8/12/2013): This can be either an SgExpression or SgInitializedName.
620 ROSE_ASSERT (templateArgument->get_expression() != NULL || templateArgument->get_initializedName() != NULL);
621 ROSE_ASSERT (templateArgument->get_expression() == NULL || templateArgument->get_initializedName() == NULL);
622 if (templateArgument->get_expression() != NULL)
623 {
624 SgExpression* expression = templateArgument->get_expression();
625 ASSERT_not_null(expression);
626
627 // Now we care about types of expression that could require name qualification.
628 // Is there anything more than SgVarRefExp that we need to worry about?
629 SgVarRefExp* varRefExp = isSgVarRefExp(expression);
630 if (varRefExp != NULL)
631 {
632 // SgVariableSymbol* variableSymbol = isSgVariableSymbol(varRefExp->get_symbol());
633 SgVariableSymbol* variableSymbol = varRefExp->get_symbol();
634 ROSE_ASSERT(variableSymbol != NULL);
635 SgInitializedName* initializedName = variableSymbol->get_declaration();
636 ROSE_ASSERT(initializedName != NULL);
637 string fully_qualified_name = initializedName->get_qualified_name();
638#if DEBUG_TEMPLATE_ARGUMENT_NAMES
639 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
640#endif
641 returnName += fully_qualified_name;
642 used_fully_qualified_name = true;
643 }
644 else
645 {
646 // Unclear if we have cases here to support (need more examples of different types of template arguments in use).
647#if DEBUG_TEMPLATE_ARGUMENT_NAMES
648 printf ("In SageBuilder::appendTemplateArgumentsToName(): Case of template argument varRefExp == NULL: expression = %p = %s \n",
649 expression,expression->class_name().c_str());
650#endif
651#if 0
652 printf ("In SageBuilder::appendTemplateArgumentsToName(): Case of template argument varRefExp == NULL is not yet supported! \n");
653 ROSE_ASSERT(false);
654#endif
655 }
656 }
657 else
658 {
659 // SgType* type = templateArgument->get_initializedName()->get_type();
660 // ROSE_ASSERT(type != NULL);
661
662 SgInitializedName* initializedName = templateArgument->get_initializedName();
663 ROSE_ASSERT(initializedName != NULL);
664 printf ("initializedName = %p = %s \n",initializedName,initializedName->get_name().str());
665
666 printf ("In SageBuilder::appendTemplateArgumentsToName(): Case of template argument initializedName != NULL: Unclear what do do in this case \n");
667 ROSE_ASSERT(false);
668 }
669
670 break;
671 }
672
674 {
675 SgDeclarationStatement* decl = templateArgument->get_templateDeclaration();
676 ASSERT_not_null(decl);
677#if DEBUG_TEMPLATE_ARGUMENT_NAMES
678 printf ("In SageBuilder::appendTemplateArgumentsToName(): case SgTemplateArgument::template_template_argument: decl = %p = %s \n",decl,decl->class_name().c_str());
679#endif
680 exit_after_name_is_generated = true;
681#if 0
682 printf ("Exiting as a test! \n");
683 ROSE_ASSERT(false);
684#endif
685 SgTemplateDeclaration* tpl_decl = isSgTemplateDeclaration(decl);
686 ROSE_ASSERT(tpl_decl == NULL);
687
688 break;
689 }
690
692 {
693#if DEBUG_TEMPLATE_ARGUMENT_NAMES
694 printf("WARNING: start_of_pack_expansion_argument in evaluateNameQualificationForTemplateArgumentList (can happen from some debug output)\n");
695#endif
696 break;
697 }
698
700 {
701 // mfprintf(mlog [ WARN ] ) ("Error argument_undefined in evaluateNameQualificationForTemplateArgumentList \n");
702 printf("Error argument_undefined in evaluateNameQualificationForTemplateArgumentList \n");
703 ROSE_ABORT();
704 break;
705 }
706
707 default:
708 {
709 // mfprintf(mlog [ WARN ] ) ("Error default reached in evaluateNameQualificationForTemplateArgumentList \n");
710 printf("Error default reached in evaluateNameQualificationForTemplateArgumentList \n");
711 ROSE_ABORT();
712 }
713 }
714
715 // DQ (2/5/2022): if it is not set above then use the old way without name qualification (debugging test2022_05.C).
716 // 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).
717 // Calling the unparseToString (SgUnparse_Info *info) function instead of the version not taking an argument.
718 // returnName += (*i)->unparseToString(info);
719 if (used_fully_qualified_name == false)
720 {
721 returnName += (*i)->unparseToString(info);
722 }
723
724#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST
725 printf ("In SageBuilder::appendTemplateArgumentsToName(): (after appending template name) *i = %p returnName = %s \n",*i,returnName.str());
726#endif
727 need_separator = true;
728 i++;
729
730#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST
731 printf ("In SageBuilder::appendTemplateArgumentsToName(): (bottom of loop) returnName = %s \n",returnName.str());
732#endif
733 }
734
735 if (emptyArgumentList == false)
736 returnName += " > ";
737
738#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST || DEBUG_TEMPLATE_ARGUMENT_NAMES
739 printf ("Leaving SageBuilder::appendTemplateArgumentsToName(): returnName = %s \n",returnName.str());
740#endif
741
742 if (false) // was: #if 0
743 {
744 // This allows me to test a large number of input codes and identify ones that are using specific features (e.g. template template parameters).
745 if (exit_after_name_is_generated == true)
746 {
747 printf ("Exiting as a test! \n");
748 ROSE_ASSERT(false);
749 }
750 } // #endif
751
752 delete info;
753 info = NULL;
754
755 return returnName;
756 }
757
758
759SgName
761 {
762 // DQ (3/10/2018): This is now redundant with SgTemplateArgument::unparseToStringSupport().
763 // DQ (3/9/2018): Added function to support debugging.
764
765 ROSE_ASSERT(templateArgument != NULL);
766
767 SgUnparse_Info *info = new SgUnparse_Info();
768 ROSE_ASSERT(info != NULL);
769
770 info->set_language(SgFile::e_Cxx_language);
771
772 // DQ (4/28/2017): For template arguments we never want to output the definitions of classes, and enums.
773 info->set_SkipClassDefinition();
774 info->set_SkipEnumDefinition();
775 info->set_use_generated_name_for_template_arguments(true);
776
777 SgName returnName = templateArgument->unparseToString(info);
778
779 delete info;
780 info = NULL;
781
782 return returnName;
783 }
784
785
786SgTemplateArgumentPtrList*
788 {
789 // DQ (9/13/2012): This function returns the SgTemplateArgumentPtrList. Both template declarations and template instanatiations have them.
790 // In a template instantiation it is the templateArguments field and from template declarations it is the templateSpecializationArguments field.
791
792 ROSE_ASSERT(decl != NULL);
793
794 SgTemplateArgumentPtrList* templateArgumentsList = NULL;
795
796 switch(decl->variantT())
797 {
798 // DQ (4/9/2018): Added support for namespace alias.
799 case V_SgNamespaceAliasDeclarationStatement:
800 // DQ (8/17/2013): These cases do not use templates.
801 // This function has to handle these cases because it is called in a general context
802 // on many types of declarations as part of the name qualification support.
803 case V_SgNamespaceDeclarationStatement:
804 case V_SgEnumDeclaration:
805 case V_SgVariableDeclaration:
806 case V_SgTypedefDeclaration:
807 {
808 templateArgumentsList = NULL;
809 break;
810 }
811
812 // PC (10/11/13): Added case of SgJavaPackageDeclaration
813 // DQ (8/11/2013): Added cases for SgFunctionDeclaration and SgMemberFunctionDeclaration
814 // I forget why we needed this case...
815 case V_SgProcedureHeaderStatement:
816 case V_SgJovialTableStatement:
817 case V_SgJavaPackageDeclaration:
818 case V_SgFunctionDeclaration:
819 case V_SgMemberFunctionDeclaration:
820 case V_SgClassDeclaration:
821 {
822 templateArgumentsList = NULL;
823 break;
824 }
825
826 case V_SgTemplateInstantiationDecl:
827 {
828 templateArgumentsList = &(isSgTemplateInstantiationDecl(decl)->get_templateArguments());
829 break;
830 }
831
832 case V_SgTemplateClassDeclaration:
833 {
834 templateArgumentsList = &(isSgTemplateClassDeclaration(decl)->get_templateSpecializationArguments());
835 break;
836 }
837
838 case V_SgTemplateInstantiationFunctionDecl:
839 {
840 templateArgumentsList = &(isSgTemplateInstantiationFunctionDecl(decl)->get_templateArguments());
841 break;
842 }
843
844 case V_SgTemplateFunctionDeclaration:
845 {
846 templateArgumentsList = &(isSgTemplateFunctionDeclaration(decl)->get_templateSpecializationArguments());
847 break;
848 }
849
850 case V_SgTemplateInstantiationMemberFunctionDecl:
851 {
852 templateArgumentsList = &(isSgTemplateInstantiationMemberFunctionDecl(decl)->get_templateArguments());
853 break;
854 }
855
856 case V_SgTemplateMemberFunctionDeclaration:
857 {
858 templateArgumentsList = &(isSgTemplateMemberFunctionDeclaration(decl)->get_templateSpecializationArguments());
859 break;
860 }
861
862 case V_SgTemplateVariableDeclaration:
863 {
864 templateArgumentsList = &(isSgTemplateVariableDeclaration(decl)->get_templateSpecializationArguments());
865 break;
866 }
867
868 // DQ (11/10/2014): Added support for template typedef declarations.
869 case V_SgTemplateTypedefDeclaration:
870 {
871 templateArgumentsList = &(isSgTemplateTypedefDeclaration(decl)->get_templateSpecializationArguments());
872 break;
873 }
874
875 // DQ (11/10/2014): Added support for template typedef declarations.
876 case V_SgTemplateInstantiationTypedefDeclaration:
877 {
878 templateArgumentsList = &(isSgTemplateInstantiationTypedefDeclaration(decl)->get_templateArguments());
879 break;
880 }
881
882 case V_SgTemplateDeclaration:
883 {
884 templateArgumentsList = NULL;
885 break;
886 }
887
888 case V_SgNonrealDecl:
889 {
890 templateArgumentsList = &(isSgNonrealDecl(decl)->get_tpl_args());
891 break;
892 }
893
894 default:
895 {
896 printf ("getTemplateArgumentList(): Default reached in switch: decl = %p = %s \n",decl,decl->class_name().c_str());
897 ROSE_ABORT();
898 }
899 }
900
901 return templateArgumentsList;
902 }
903
904
905
906SgTemplateParameterPtrList*
908 {
909 // DQ (9/16/2012): This function returns the SgTemplateParameterPtrList that is associated with template declarations.
910 // For all other cases it returns NULL (or is an error).
911
912 ROSE_ASSERT(decl != NULL);
913
914 SgTemplateParameterPtrList* templateParameterList = NULL;
915
916 switch(decl->variantT())
917 {
918 // DQ (4/9/2018): Added support for namespace alias.
919 case V_SgNamespaceAliasDeclarationStatement:
920 // DQ (8/17/2013): These cases do not use templates.
921 // This function has to handle these cases because it is called in a general context
922 // on many types of declarations as part of the name qualification support.
923 case V_SgNamespaceDeclarationStatement:
924 case V_SgEnumDeclaration:
925 case V_SgVariableDeclaration:
926 case V_SgTypedefDeclaration:
927 {
928 templateParameterList = NULL;
929 break;
930 }
931
932 // PC (10/11/13): Added case of SgJavaPackageDeclaration
933 // DQ (8/12/2013): This function has to be supported when called using any kind of declaration (at least SgFunctionDeclaration and SgClassDeclaration).
934 // DQ (9/16/2012): I think it should be an error to call this function for a SgClassDeclaration.
935 case V_SgProcedureHeaderStatement:
936 case V_SgJovialTableStatement:
937 case V_SgJavaPackageDeclaration:
938 case V_SgFunctionDeclaration:
939 case V_SgMemberFunctionDeclaration:
940 case V_SgClassDeclaration:
941 {
942 templateParameterList = NULL;
943 break;
944 }
945
946 // DQ (11/10/2014): Added support for template typedef declarations.
947 case V_SgTemplateInstantiationTypedefDeclaration:
948
949 // DQ (8/12/2013): This function has to be supported when called using any kind of declaration (at least SgFunctionDeclaration and SgClassDeclaration).
950 // DQ (9/16/2012): I think it should be an error to call this function for these types of declarations.
951 case V_SgTemplateInstantiationDecl:
952 case V_SgTemplateInstantiationFunctionDecl:
953 case V_SgTemplateInstantiationMemberFunctionDecl:
954 {
955 templateParameterList = NULL;
956 break;
957 }
958
959 case V_SgTemplateClassDeclaration:
960 {
961 templateParameterList = &(isSgTemplateClassDeclaration(decl)->get_templateParameters());
962 break;
963 }
964
965 case V_SgTemplateFunctionDeclaration:
966 {
967 templateParameterList = &(isSgTemplateFunctionDeclaration(decl)->get_templateParameters());
968 break;
969 }
970
971 case V_SgTemplateMemberFunctionDeclaration:
972 {
973 templateParameterList = &(isSgTemplateMemberFunctionDeclaration(decl)->get_templateParameters());
974 break;
975 }
976
977 case V_SgTemplateVariableDeclaration:
978 {
979 templateParameterList = &(isSgTemplateVariableDeclaration(decl)->get_templateParameters());
980 break;
981 }
982
983 // DQ (11/10/2014): Added support for template typedef declarations.
984 case V_SgTemplateTypedefDeclaration:
985 {
986 templateParameterList = &(isSgTemplateTypedefDeclaration(decl)->get_templateParameters());
987 break;
988 }
989
990 case V_SgNonrealDecl:
991 {
992 templateParameterList = &(isSgNonrealDecl(decl)->get_tpl_params());
993 break;
994 }
995
996 case V_SgTemplateDeclaration:
997 {
998 templateParameterList = &(isSgTemplateDeclaration(decl)->get_templateParameters());
999 break;
1000 }
1001
1002 default:
1003 {
1004 printf ("getTemplateParameterList(): Default reached in switch: decl = %p = %s \n",decl,decl->class_name().c_str());
1005 ROSE_ABORT();
1006 }
1007 }
1008
1009 return templateParameterList;
1010 }
1011
1012
1013
1014void
1016 {
1017 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1018
1019 ROSE_ASSERT(decl != NULL);
1020
1021 SgTemplateArgumentPtrList* templateArgumentsList = getTemplateArgumentList(decl);
1022
1023 if (templateArgumentsList != NULL)
1024 {
1026 ROSE_ASSERT(first_decl != NULL);
1027
1028 SgTemplateArgumentPtrList::iterator i = templateArgumentsList->begin();
1029 while (i != templateArgumentsList->end())
1030 {
1031 SgNode* parent = (*i)->get_parent();
1032 if (parent== NULL)
1033 {
1034 // (*i)->set_parent(decl);
1035 (*i)->set_parent(first_decl);
1036 }
1037 else
1038 {
1039 SgScopeStatement* scope = isSgScopeStatement(parent);
1040 if (scope != NULL)
1041 {
1042 // Template Arguments should have had there parents set to a scope when they were build, we want
1043 // to refine that now that the declaration which we want them to be specified in has been build.
1044 (*i)->set_parent(first_decl);
1045 }
1046 else
1047 {
1048 SgDeclarationStatement* declaration = isSgDeclarationStatement(parent);
1049 if (declaration != NULL)
1050 {
1051#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
1052 printf ("In setTemplateArgumentParents(): Template argument already set to declaration = %p = %s \n",declaration,declaration->class_name().c_str());
1053#endif
1054 }
1055 else
1056 {
1057#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
1058 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());
1059#endif
1060 }
1061 }
1062 }
1063
1064 i++;
1065 }
1066 }
1067
1069 }
1070
1071
1072void
1074 {
1075 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1076 ROSE_ASSERT(decl != NULL);
1077
1078 SgTemplateParameterPtrList* templateParameterList = getTemplateParameterList(decl);
1079
1080 if (templateParameterList != NULL)
1081 {
1083 ROSE_ASSERT(first_decl != NULL);
1084
1085 SgTemplateParameterPtrList::iterator i = templateParameterList->begin();
1086 while (i != templateParameterList->end())
1087 {
1088 SgNode* parent = (*i)->get_parent();
1089 if (parent == NULL)
1090 {
1091 (*i)->set_parent(first_decl);
1092 }
1093 else
1094 {
1095 SgScopeStatement* scope = isSgScopeStatement(parent);
1096 if (scope != NULL)
1097 {
1098 // Template Arguments should have had their parents set to a scope when they were build, we want
1099 // to refine that now that the declaration which we want them to be specified in has been build.
1100 (*i)->set_parent(first_decl);
1101 }
1102 }
1103
1104 i++;
1105 }
1106 }
1107
1109 }
1110
1111
1112void
1114 {
1115 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1116
1117 ROSE_ASSERT(decl != NULL);
1118
1119 SgTemplateArgumentPtrList* templateArgumentsList = getTemplateArgumentList(decl);
1120
1121 if (templateArgumentsList != NULL)
1122 {
1123 SgTemplateArgumentPtrList::iterator i = templateArgumentsList->begin();
1124 while (i != templateArgumentsList->end())
1125 {
1126 SgNode* parent = (*i)->get_parent();
1127 if (parent == NULL)
1128 {
1129 printf ("Error: In testTemplateArgumentParents(): decl = %p = %s has template argument = %p with null parent \n",decl,decl->class_name().c_str(),*i);
1130 }
1131 ROSE_ASSERT(parent != NULL);
1132
1133 // DQ (9/16/2012): Adding new test.
1134 ROSE_ASSERT(decl->get_firstNondefiningDeclaration() != NULL);
1135 // DQ (1/30/2013): Commented this test out so that we could reuse SgTemplateArguments and
1136 // assure that the mapping from EDG a_template_arg_ptr's to SgTemplateArgument's was 1-to-1.
1137 // It is not clear if we can relax this constraint in the future.
1138
1139 i++;
1140 }
1141 }
1142 }
1143
1144
1145void
1147 {
1148 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1149
1150 ROSE_ASSERT(decl != NULL);
1151
1152 SgTemplateParameterPtrList* templateParameterList = getTemplateParameterList(decl);
1153
1154 if (templateParameterList != NULL)
1155 {
1156 SgTemplateParameterPtrList::iterator i = templateParameterList->begin();
1157 while (i != templateParameterList->end())
1158 {
1159 SgNode* parent = (*i)->get_parent();
1160 if (parent == NULL)
1161 {
1162 printf ("Error: In testTemplateParameterParents(): decl = %p = %s has template argument = %p with null parent \n",decl,decl->class_name().c_str(),*i);
1163 }
1164 ROSE_ASSERT(parent != NULL);
1165
1166 // DQ (9/16/2012): Adding new test.
1167 ROSE_ASSERT(decl->get_firstNondefiningDeclaration() != NULL);
1168 if (parent != decl->get_firstNondefiningDeclaration())
1169 {
1170#if 0
1171 // DQ (2/7/2015): This message is output a lot for C++11 test projects/ShiftCalculus/simpleCNS.cpp (also test2014_83.C and test2014_84.C).
1172 printf ("Error: In testTemplateParameterParents(): decl = %p = %s has template argument = %p with parent = %p = %s \n",decl,decl->class_name().c_str(),*i,parent,parent->class_name().c_str());
1173#endif
1174 }
1175
1176 // DQ (8/22/2013): Since these are now shared, it makes less sense to expect these to have such simple parent relationships.
1177 // This commit of work on ROSE added caching to template parameters so that we could support pointer equality for tests
1178 // of template parameter equality in the symbol table handling (this was a technique previously used for template arguments).
1179 // 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).
1180
1181 i++;
1182 }
1183 }
1184 }
1185
1186
1187void
1188SageBuilder::setTemplateArgumentsInDeclaration( SgDeclarationStatement* decl, SgTemplateArgumentPtrList* templateArgumentsList_input )
1189 {
1190 // DQ (9/16/2012): Setup the template arguments for any type of template instantiation.
1191
1192 ROSE_ASSERT(templateArgumentsList_input != NULL);
1193
1194 ROSE_ASSERT(decl->variantT() == V_SgTemplateInstantiationDecl ||
1195 decl->variantT() == V_SgTemplateInstantiationFunctionDecl ||
1196 decl->variantT() == V_SgTemplateInstantiationMemberFunctionDecl ||
1197 decl->variantT() == V_SgTemplateInstantiationTypedefDeclaration);
1198
1199 SgTemplateArgumentPtrList* templateArgumentsList_from_declaration = getTemplateArgumentList(decl);
1200
1201 if (templateArgumentsList_from_declaration != NULL)
1202 {
1203 *templateArgumentsList_from_declaration = *templateArgumentsList_input;
1204
1205 // Set the parents.
1207 }
1208
1210 }
1211
1212
1213void
1214SageBuilder::setTemplateSpecializationArgumentsInDeclaration( SgDeclarationStatement* decl, SgTemplateArgumentPtrList* templateSpecializationArgumentsList_input )
1215 {
1216 // DQ (9/16/2012): Setup the template arguments for any type of template declaration
1217
1218 ROSE_ASSERT(templateSpecializationArgumentsList_input != NULL);
1219
1220 ROSE_ASSERT(decl->variantT() == V_SgTemplateClassDeclaration || decl->variantT() == V_SgTemplateFunctionDeclaration ||
1221 decl->variantT() == V_SgTemplateMemberFunctionDeclaration || decl->variantT() == V_SgTemplateVariableDeclaration );
1222
1223 SgTemplateArgumentPtrList* templateSpecializationArgumentsList_from_declaration = getTemplateArgumentList(decl);
1224
1225 if (templateSpecializationArgumentsList_from_declaration != NULL)
1226 {
1227 *templateSpecializationArgumentsList_from_declaration = *templateSpecializationArgumentsList_input;
1228
1229 // Set the parents.
1231 }
1232
1234 }
1235
1236void
1237SageBuilder::setTemplateParametersInDeclaration( SgDeclarationStatement* decl, SgTemplateParameterPtrList* templateParameterList_input )
1238 {
1239 // DQ (9/16/2012): Setup the template parameters for any type of template declaration.
1240
1241 ROSE_ASSERT(templateParameterList_input != NULL);
1242
1243 ROSE_ASSERT(decl->variantT() == V_SgTemplateClassDeclaration || decl->variantT() == V_SgTemplateFunctionDeclaration ||
1244 decl->variantT() == V_SgTemplateMemberFunctionDeclaration || decl->variantT() == V_SgTemplateVariableDeclaration );
1245
1246 SgTemplateParameterPtrList* templateParameterList_from_declaration = getTemplateParameterList(decl);
1247
1248 if (templateParameterList_from_declaration != NULL)
1249 {
1250 *templateParameterList_from_declaration = *templateParameterList_input;
1251
1252 // Set the parents.
1254 }
1255
1257 }
1258
1259// Only used to build parameter arguments for function ??
1260// should be transparently generated for most variable declaration builder
1261// deferred symbol insertion, scope setting , etc
1262// do them when it is actually used with the parameterList!!
1264SageBuilder::buildInitializedName (const SgName & name, SgType* type, SgInitializer* init /*= NULL*/)
1265{
1266 ASSERT_not_null(type);
1267
1268 SgInitializedName* initializedName = new SgInitializedName(name,type,init);
1269 ASSERT_not_null(initializedName);
1270
1272 return initializedName;
1273}
1274
1276SageBuilder::buildInitializedName ( const std::string & name, SgType* type)
1277 {
1278 SgName var_name(name);
1279 return buildInitializedName(var_name,type);
1280 }
1281
1284 {
1285 // DQ (3/20/2017): Call the version of the function that takes a string as part of migration away from this function that takes a const char*.
1286 // This also provides a test of the string based version of this function (for code coverage).
1287 string var_name(name);
1288 return buildInitializedName(var_name,type);
1289 }
1290
1293 {
1294 ASSERT_not_null(type);
1295
1296 SgInitializedName* initializedName = new SgInitializedName(name,type,init);
1297 ASSERT_not_null(initializedName);
1298 ASSERT_require(init == nullptr || init->get_parent() == initializedName);
1299
1300 setOneSourcePositionNull(initializedName);
1301
1302 return initializedName;
1303 }
1304
1305//-----------------------------------------------
1306// could have two declarations for a same variable
1307// extern int i;
1308// int i;
1311 //(const SgName & name, SgType* type, SgInitializer * varInit= NULL, SgScopeStatement* scope = NULL)
1312{
1313 if (scope == NULL)
1315 ROSE_ASSERT(name.is_null() == false);
1316 ROSE_ASSERT(type != NULL);
1317
1318 SgVariableDeclaration * varDecl = new SgVariableDeclaration(name, type, varInit);
1319 ROSE_ASSERT(varDecl);
1320
1321// DQ (8/21/2011): Note that the default is to set the declaration modifier's access modifier to be
1322// default (which is the same as public). So the effect it to set it to be public. This is ignored
1323// by the unparser for most languguages in ROSE.
1324 varDecl->set_firstNondefiningDeclaration(varDecl);
1325
1326 if (scope!=NULL)
1327 {
1328 // Liao 12/13/2010
1329 // Fortran subroutine/function parameters have corresponding variable declarations in the body
1330 // For this declaration, it should use the initialized names of the parameters instead of creating new ones
1331 // The symbol of the init name should be under SgFunctionDefinition, instead of the function body block
1332 bool isFortranParameter = false;
1334 {
1336 if (f_def != NULL)
1337 {
1338 // DQ (5/21/2013): Removed direct reference to symbol table (namespace handling is only supported at the SgScopeStatement level).
1339 SgVariableSymbol * v_symbol = f_def->lookup_variable_symbol(name);
1340 if (v_symbol != NULL) // find a function parameter with the same name
1341 {
1342 // replace the default one with the one from parameter
1343 SgInitializedName *default_initName = varDecl->get_decl_item (name);
1344 ROSE_ASSERT (default_initName != NULL);
1345 SgInitializedName * new_initName = v_symbol->get_declaration();
1346 ROSE_ASSERT (new_initName != NULL);
1347 ROSE_ASSERT (default_initName != new_initName);
1348
1349 SgInitializedNamePtrList& n_list= varDecl->get_variables();
1350 std::replace (n_list.begin(), n_list.end(),default_initName, new_initName );
1351 ROSE_ASSERT (varDecl->get_decl_item (name)==new_initName); //ensure the new one can be found
1352
1353 // change the function argument's old parent to the variable declaration
1354 SgNode * old_parent = new_initName->get_parent();
1355 ROSE_ASSERT (old_parent != NULL);
1356 ROSE_ASSERT (isSgFunctionParameterList(old_parent) != NULL);
1357 new_initName->set_parent(varDecl); // adjust parent from SgFunctionParameterList to SgVariableDeclaration
1358
1359 // DQ (1/25/2011): Deleting these causes problems if I use this function in the Fortran support...
1360 // delete (default_initName->get_declptr()); // delete the var definition
1361 // delete (default_initName->get_declptr()); // relink the var definition
1362
1363 SgVariableDefinition * var_def = isSgVariableDefinition(default_initName->get_declptr()) ;
1364 ROSE_ASSERT (var_def != NULL);
1365 var_def->set_parent(new_initName);
1366 var_def->set_vardefn(new_initName);
1367 new_initName->set_declptr(var_def); // it was set to SgProcedureHeaderStatement as a function argument
1368
1369 delete (default_initName); // must delete the old one to pass AST consistency test
1370
1371 // DQ (12/13/2011): Is this executed...
1372 //printf ("Is this executed \n");
1373 //ROSE_ASSERT(false);
1374
1375 isFortranParameter = true;
1376 }
1377 }
1378 }
1379 if (! isFortranParameter) // No need to add symbol to the function body if it is a Fortran parameter
1380 // The symbol should already exist under function definition for the parameter
1381 fixVariableDeclaration(varDecl,scope);
1382 }
1383
1384 SgInitializedName *initName = varDecl->get_decl_item (name);
1385 ROSE_ASSERT(initName != NULL);
1386 ROSE_ASSERT((initName->get_declptr())!=NULL);
1387
1388 //bug 119, SgVariableDefintion's File_info is needed for deep copy to work
1389 // AstQuery based setSourcePositionForTransformation() cannot access all child nodes
1390 // have to set SgVariableDefintion explicitly
1391 SgDeclarationStatement* variableDefinition_original = initName->get_declptr();
1392 setOneSourcePositionForTransformation(variableDefinition_original);
1393 ROSE_ASSERT((variableDefinition_original->get_startOfConstruct()) !=NULL);
1394 ROSE_ASSERT((variableDefinition_original->get_endOfConstruct())!=NULL);
1395
1397 //ROSE_ASSERT (isSgVariableDefinition(initName->get_declptr())->get_startOfConstruct()!=NULL);
1398
1399
1400 // DQ (4/16/2015): This is replaced with a better implementation.
1401 // DQ (4/15/2015): We should reset the isModified flags as part of the transforamtion
1402 // because we have added statements explicitly marked as transformations.
1403 // checkIsModifiedFlag(varDecl);
1404 unsetNodesMarkedAsModified(varDecl);
1405
1406// ROSE_ASSERT(findFirstSgCastExpMarkedAsTransformation(varDecl,"testing buildVariableDeclaration(): 9") == false);
1407// ROSE_ASSERT(findFirstSgCastExpMarkedAsTransformation(scope,"testing buildVariableDeclaration(): 9-scope") == false);
1408
1409 return varDecl;
1410}
1411
1412//-----------------------------------------------
1413// could have two declarations for a same variable
1414// extern int i;
1415// int i;
1418 {
1419
1420#define DEBUG_BUILD_VARIABLE_DECLARATION 0
1421
1422#if DEBUG_BUILD_VARIABLE_DECLARATION
1423 printf ("In SageBuilder::buildVariableDeclaration_nfi(): name = %s scope = %p varInit = %p \n",name.str(),scope,varInit);
1424 if (scope != NULL)
1425 {
1426 printf (" --- scope = %p = %s \n",scope,scope->class_name().c_str());
1427 }
1428#endif
1429
1430 if (scope == NULL)
1431 {
1432#if DEBUG_BUILD_VARIABLE_DECLARATION
1433 printf ("Scope determined from the SageBuilder::topScopeStack() \n");
1434#endif
1436 }
1437
1438 ROSE_ASSERT (scope != NULL);
1439 ROSE_ASSERT(type != NULL);
1440
1441 // DQ (7/18/2012): Added debugging code (should fail for test2011_75.C).
1442 SgVariableSymbol* variableSymbol = scope->lookup_variable_symbol(name);
1443
1444#if DEBUG_BUILD_VARIABLE_DECLARATION
1445 printf ("In SageBuilder::buildVariableDeclaration_nfi(): variableSymbol = %p \n",variableSymbol);
1446#endif
1447
1448 // 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.
1449 SgVariableDeclaration * varDecl = NULL;
1450 if (variableSymbol == NULL)
1451 {
1452 varDecl = new SgVariableDeclaration(name, type, varInit);
1453#if DEBUG_BUILD_VARIABLE_DECLARATION
1454 SgInitializedName* tmp_initializedName = getFirstInitializedName(varDecl);
1455 ROSE_ASSERT(tmp_initializedName != NULL);
1456 printf ("In SageBuilder::buildVariableDeclaration_nfi(): variableSymbol == NULL: varDecl = %p: initializedName = %p = %s \n",varDecl,tmp_initializedName,tmp_initializedName->get_name().str());
1457 printf (" --- tmp_initializedName->get_initptr() = %p \n",tmp_initializedName->get_initptr());
1458#endif
1459 // DQ (6/25/2019): This is a new feature to input the builtFromUseOnly function optional parameter.
1460 if (builtFromUseOnly == true)
1461 {
1462#if DEBUG_BUILD_VARIABLE_DECLARATION
1463 printf ("In buildVariableDeclaration_nfi(): this is the first reference to this variable: building a new SgVariableDeclaration: varDecl = %p name = %s \n",varDecl,name.str());
1464#endif
1465 varDecl->set_builtFromUseOnly(true);
1466 }
1467 }
1468 else
1469 {
1470 SgInitializedName* initializedName = variableSymbol->get_declaration();
1471 ROSE_ASSERT(initializedName != NULL);
1472
1473 SgVariableDeclaration* associatedVariableDeclaration = isSgVariableDeclaration(initializedName->get_parent());
1474
1475#if DEBUG_BUILD_VARIABLE_DECLARATION
1476 printf ("In SageBuilder::buildVariableDeclaration_nfi(): initializedName->get_parent() = %p \n",initializedName->get_parent());
1477 if (initializedName->get_parent() != NULL)
1478 {
1479 printf ("In SageBuilder::buildVariableDeclaration_nfi(): initializedName->get_parent() = %p = %s \n",initializedName->get_parent(),initializedName->get_parent()->class_name().c_str());
1480 }
1481 printf ("In SageBuilder::buildVariableDeclaration_nfi(): associatedVariableDeclaration = %p \n",associatedVariableDeclaration);
1482#endif
1483#if DEBUG_BUILD_VARIABLE_DECLARATION
1484 // DQ (6/24/2019): If this has been previously built as part of a variable use (in a class declaration),
1485 // then it should not be attached to the class definition as a variable declaration yet, and we should reuse it.
1486 if (associatedVariableDeclaration != NULL && associatedVariableDeclaration->get_parent() != NULL)
1487 {
1488 printf ("In SageBuilder::buildVariableDeclaration_nfi(): associatedVariableDeclaration->get_parent() = %p = %s \n",
1489 associatedVariableDeclaration->get_parent(),associatedVariableDeclaration->get_parent()->class_name().c_str());
1490 }
1491#endif
1492
1493#if DEBUG_BUILD_VARIABLE_DECLARATION
1494 printf ("associatedVariableDeclaration = %p \n",associatedVariableDeclaration);
1495 if (associatedVariableDeclaration != NULL)
1496 {
1497 printf ("associatedVariableDeclaration->get_builtFromUseOnly() = %s \n",associatedVariableDeclaration->get_builtFromUseOnly() ? "true" : "false");
1498 }
1499#endif
1500
1501 // DQ (6/25/2019): Trigger the reuse of the available variable declaration.
1502 bool reuseTheAssociatedVariableDeclaration = ((associatedVariableDeclaration != NULL) && (associatedVariableDeclaration->get_builtFromUseOnly() == true));
1503 if (reuseTheAssociatedVariableDeclaration == true)
1504 {
1505 // Build a seperate SgVariableDeclaration so that we can avoid sharing the SgInitializedName
1506 // (and it's possible initializer which would be an error for the secondary declaration
1507 // (the declaration in the class for the case of a static declaration))
1508
1509 ROSE_ASSERT(associatedVariableDeclaration != NULL);
1510
1511 // DQ (6/24/2019): Fix this to use the associatedVariableDeclaration.
1512 varDecl = associatedVariableDeclaration;
1513
1514 // DQ (6/25/2019): Mark this variable declaration so that it will not be reused again.
1515 varDecl->set_builtFromUseOnly(false);
1516
1517 // 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.
1518 varDecl->set_parent(NULL);
1519
1520 // DQ (6/24/2019): this veriable declaration that is being reused, should not have had an initializer (check this).
1522 ROSE_ASSERT(variable != NULL);
1523
1524 // DQ (6/25/2019): See Cxx11_tests/test2019_121.C and Cxx11_tests/test2019_482.C.
1525 // ROSE_ASSERT(variable->get_initptr() == NULL);
1526#if DEBUG_BUILD_VARIABLE_DECLARATION
1527 if (variable->get_initptr() != NULL)
1528 {
1529 printf ("Found initializer associated with variable declaration being reused: variable = %p name = %s \n",variable,variable->get_name().str());
1530 }
1531#endif
1532 // DQ (7/3/2019): Reuse in a conditional will have a valid initializer.
1533 }
1534 else
1535 {
1536 // DQ (6/25/2019): We can't reuse the existing SgInitializedName, because it could have been initialized in the other SgVariableDeclaration.
1537 // DQ (6/26/2019): Added assertion.
1538 ROSE_ASSERT(reuseTheAssociatedVariableDeclaration == false);
1539
1540 // DQ (6/27/2019): If the SgInitializedName was generated from the convert_variable_use() function in the
1541 // EDG/ROSE translation, then where was not associated SgVariableDeclaration built (an inconsistancy).
1542 // So we want to check for the parent being a scope statement (e.g. SgIfStmt or other statement that can
1543 // accept a conditional expression where in C++ it can alternatively declare a variable.
1544 if (associatedVariableDeclaration == NULL)
1545 {
1546 ROSE_ASSERT(initializedName->get_parent() != NULL);
1547 SgScopeStatement* scopeStatement = isSgScopeStatement(initializedName->get_parent());
1548 if (scopeStatement != NULL)
1549 {
1550#if DEBUG_BUILD_VARIABLE_DECLARATION
1551 printf ("scopeStatement = %p = %s \n",scopeStatement,scopeStatement->class_name().c_str());
1552#endif
1553 }
1554 else
1555 {
1556#if DEBUG_BUILD_VARIABLE_DECLARATION
1557 printf ("initializedName->get_parent() = %p = %s \n",initializedName->get_parent(),initializedName->get_parent()->class_name().c_str());
1558#endif
1559 }
1560 }
1561
1562 // DQ (6/27/2019): In some case we want to reuse the associated SgInitializedName node.
1563 // For example: variable declarations in conditionals (e.g. SgIfStmt, and other scope statements).
1564 // DQ (6/26/2019): Build an additional variable to support another reference to the original variable.
1565 // Note: we need another one because either one can have an initializer that cannot be shared in the AST.
1566 SgInitializedName* additional_variable = NULL;
1567
1568#if DEBUG_BUILD_VARIABLE_DECLARATION
1569 printf ("In SageBuilder::buildVariableDeclaration_nfi(): initializedName->get_scope() = %p = %s \n",initializedName->get_scope(),initializedName->get_scope()->class_name().c_str());
1570#endif
1571 SgScopeStatement* scopeStatement = isSgScopeStatement(initializedName->get_parent());
1572 if (scopeStatement != NULL)
1573 {
1574 additional_variable = initializedName;
1575
1576 // DQ (6/28/2019): Support case when the borrowed SgInitializedName has a valid initializer.
1577 // DQ (6/26/2019): Adding the initializer.
1578 if (additional_variable->get_initptr() != NULL)
1579 {
1580#if DEBUG_BUILD_VARIABLE_DECLARATION
1581 printf ("In SageBuilder::buildVariableDeclaration_nfi(): borrowed SgInitializedName is alread initialized \n");
1582 printf (" --- additional_variable->get_initptr() = %p \n",additional_variable->get_initptr());
1583 printf (" --- varInit = %p \n",varInit);
1584#endif
1585 // DQ (6/28/2019): when this is assertion is false, we have constructed a redundant initializer (debugging this).
1586 // PP (7/22/2019) faults in CUDA code
1587 }
1588 else
1589 {
1590 additional_variable->set_initptr(varInit);
1591 }
1592
1593#if DEBUG_BUILD_VARIABLE_DECLARATION || 0
1594 printf (" --- additional_variable->get_scope() = %p = %s \n",additional_variable->get_scope(),additional_variable->get_scope()->class_name().c_str());
1595 printf (" --- Reusing the SgInitializedName (not associated with a previous SgVariableDeclaration where the parent is a SgScopeStatement) \n");
1596#endif
1597 }
1598 else
1599 {
1600#if DEBUG_BUILD_VARIABLE_DECLARATION
1601 printf (" --- Building a new SgInitializedName \n");
1602#endif
1603 additional_variable = buildInitializedName_nfi(name,type,varInit);
1604 }
1605
1606#if DEBUG_BUILD_VARIABLE_DECLARATION
1607 ROSE_ASSERT(initializedName->get_scope() != NULL);
1608#endif
1609 // DQ (6/26/2019): Set the scopes to be the same (a symbol already exists at this point).
1610 // DQ (6/26/2019): Set the pointer to the original version of this variable (unless we reused the SgInitializedName above).
1611 if (additional_variable != initializedName)
1612 {
1613 additional_variable->set_prev_decl_item(initializedName);
1614 }
1615
1616 // If there is not an associated SgVariableDeclaration then reuse the existing SgInitializedName.
1617 varDecl = new SgVariableDeclaration(additional_variable);
1618#if DEBUG_BUILD_VARIABLE_DECLARATION
1619 ROSE_ASSERT(initializedName->get_parent() != NULL);
1620 printf ("initializedName->get_parent() = %p = %s \n",initializedName->get_parent(),initializedName->get_parent()->class_name().c_str());
1621 ROSE_ASSERT(additional_variable->get_parent() != NULL);
1622 printf ("additional_variable->get_parent() = %p = %s \n",additional_variable->get_parent(),additional_variable->get_parent()->class_name().c_str());
1623#endif
1624 // DQ (6/26/2019): Set the parent of the first SgInitializedName to that of the second SgInitializedName.
1625 // This is an issue for the range for initialization: see test2019_483.C.
1626
1627 ASSERT_not_null(initializedName->get_scope());
1628
1629 // DQ (6/26/2019): Set the pointer to the original version of this variable (unless we reused the SgInitializedName above).
1630 if (additional_variable != initializedName)
1631 {
1632 additional_variable->set_scope(initializedName->get_scope());
1633 }
1634 // DQ (7/14/2014): Set the variable initialized (see test2014_107.C, also required for boost for_each support)).
1635 // initializedName->set_initptr(varInit);
1636#if DEBUG_BUILD_VARIABLE_DECLARATION
1637 printf ("In SageBuilder::buildVariableDeclaration_nfi(): After sharing the exisitng SgInitializedName: initializedName = %p = %s \n",initializedName,initializedName->get_name().str());
1638 printf (" --- initializedName->get_initptr() = %p \n",initializedName->get_initptr());
1639 printf (" --- additional_variable->get_initptr() = %p \n",additional_variable->get_initptr());
1640#endif
1641 }
1642 }
1643
1644 // DQ (11/3/2012): The SgInitializedName inside the SgVariableDeclaration must have valid source position object (even if default initialized).
1646 ASSERT_not_null(variable);
1648
1649 ASSERT_not_null(varDecl);
1650 varDecl->set_firstNondefiningDeclaration(varDecl);
1651 varDecl->get_declarationModifier().get_storageModifier().set_modifier(sm);
1652
1653 // DQ (7/9/2012): Added test (parent should not be set yet; set in parse_statement).
1654 ROSE_ASSERT(varDecl->get_parent() == NULL);
1655
1656 if (name != "")
1657 {
1658 // Anonymous bit fields should not have symbols
1659 fixVariableDeclaration(varDecl,scope);
1660
1661 // DQ (7/9/2012): Added test (parent should not be set yet; set in parse_statement).
1662 }
1663 else
1664 {
1665 // 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).
1666 // 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...
1667 varDecl->set_parent(topScopeStack());
1668 ASSERT_not_null(varDecl->get_parent());
1669 }
1670
1671 SgInitializedName *initName = varDecl->get_decl_item (name);
1672 ASSERT_not_null(initName);
1673 ASSERT_not_null(initName->get_declptr());
1674
1675 if (initName->get_scope())
1676 {
1677 // Make this a warning for the few places where this fails.
1678#if DEBUG_BUILD_VARIABLE_DECLARATION
1679 printf ("WARNING: Note in buildVariableDeclaration_nfi(): initName->get_scope() == NULL \n");
1680#endif
1681 }
1682
1683 // DQ (7/9/2012): Added test (parent should not be set yet; set in parse_statement).
1684 // bug 119, SgVariableDefintion's File_info is needed for deep copy to work
1685 // AstQuery based setSourcePositionForTransformation() cannot access all child nodes
1686 // have to set SgVariableDefintion explicitly
1687 SgVariableDefinition* variableDefinition_original = isSgVariableDefinition(initName->get_declptr());
1688 ASSERT_not_null(variableDefinition_original);
1689 setOneSourcePositionNull(variableDefinition_original);
1690 setOneSourcePositionNull(varDecl);
1691
1692 // DQ (7/12/2012): The parent should be set to the current scope (not the same as that specified
1693 // in the scope (since that applies to the variable (SgInitializedName) not the SgVariableDeclaration).
1694 // Liao, 1/23/2013, quick fix for now, this condition is a mirror to the code setting parent in SageInterface::fixVariableDeclaration()
1695 if (topScopeStack())
1696 {
1697 ASSERT_not_null(varDecl->get_parent());
1698 }
1699
1700 // DQ (4/16/2015): This is replaced with a better implementation.
1701 // DQ (4/15/2015): We should reset the isModified flags as part of the transforamtion
1702 // because we have added statements explicitly marked as transformations.
1703 unsetNodesMarkedAsModified(varDecl);
1704
1705 ASSERT_not_null(varDecl);
1706
1707#if DEBUG_BUILD_VARIABLE_DECLARATION
1708 printf ("Leaving buildVariableDeclaration_nfi(): varDecl = %p varDecl->get_parent() = %p \n",varDecl,varDecl->get_parent());
1709#endif
1710
1711 return varDecl;
1712 }
1713
1714
1717{
1718// refactored from ROSETTA/Grammar/Statement.code SgVariableDeclaration::append_variable ()
1719
1720 ROSE_ASSERT (decl!=NULL);
1721 ROSE_ASSERT (init_name !=NULL);
1722 // init can be NULL
1723
1724 SgVariableDefinition *defn_stmt = NULL;
1725 if (!isSgFunctionType(init_name->get_type()))
1726 {
1727 Sg_File_Info* copyOfFileInfo = NULL;
1728 if (decl->get_file_info() != NULL)
1729 {
1730 copyOfFileInfo = new Sg_File_Info(*(decl->get_file_info()));
1731 ROSE_ASSERT (copyOfFileInfo != NULL);
1732
1733 // Note that the SgVariableDefinition will connect the new IR node into the AST.
1734 defn_stmt = new SgVariableDefinition(copyOfFileInfo, init_name, init);
1735 ROSE_ASSERT (defn_stmt != NULL);
1736
1737 copyOfFileInfo->set_parent(defn_stmt);
1738
1739 // DQ (3/13/2007): We can't enforce that the endOfConstruct is set (if the interface using the startOfConstruct is used.
1740 // DQ (2/3/2007): Need to build the endOfConstruct position as well.
1741 if (decl->get_endOfConstruct() != NULL)
1742 {
1743 Sg_File_Info* copyOfEndOfConstruct = new Sg_File_Info(*(decl->get_endOfConstruct()));
1744 defn_stmt->set_endOfConstruct(copyOfEndOfConstruct);
1745 copyOfEndOfConstruct->set_parent(defn_stmt);
1746 }
1747 }
1748 else
1749 {
1750 // Note that the SgVariableDefinition will connect the new IR node into the AST.
1751 defn_stmt = new SgVariableDefinition(init_name, init);
1752 }
1753 ROSE_ASSERT(defn_stmt != NULL);
1754 }
1755 else
1756 defn_stmt = NULL;
1757 return defn_stmt ;
1758}
1759
1760
1763{
1766 return res;
1767}
1768
1769// DQ (12/6/2011): Adding support for template declarations into the AST.
1770// SgTemplateDeclaration*
1771// SgVariableDeclaration*
1772// SgTemplateVariableDeclaration* buildTemplateVariableDeclaration_nfi(const SgName & name, SgType *type, SgInitializer *varInit, SgScopeStatement* scope);
1775 {
1776 ROSE_ASSERT (scope != NULL);
1777 ROSE_ASSERT(type != NULL);
1778
1779 SgTemplateVariableDeclaration * varDecl = new SgTemplateVariableDeclaration(name, type, varInit);
1780 ROSE_ASSERT(varDecl);
1781
1782 varDecl->set_firstNondefiningDeclaration(varDecl);
1783
1784 // DQ (11/3/2012): The SgInitializedName inside the SgVariableDeclaration must have valid source position object (even if default initialized).
1786 ROSE_ASSERT(variable != NULL);
1788
1789 if (name != "")
1790 {
1791 // Anonymous bit fields should not have symbols
1792 fixVariableDeclaration(varDecl,scope);
1793 }
1794
1795 SgInitializedName *initName = varDecl->get_decl_item (name);
1796 ROSE_ASSERT(initName);
1797 ROSE_ASSERT((initName->get_declptr())!=NULL);
1798
1799 // bug 119, SgVariableDefintion's File_info is needed for deep copy to work
1800 // AstQuery based setSourcePositionForTransformation() cannot access all child nodes
1801 // have to set SgVariableDefintion explicitly
1802 SgVariableDefinition* variableDefinition_original = isSgVariableDefinition(initName->get_declptr());
1803 ROSE_ASSERT(variableDefinition_original != NULL);
1804 setOneSourcePositionNull(variableDefinition_original);
1805
1806 setOneSourcePositionNull(varDecl);
1807
1808 return varDecl;
1809 }
1810
1812SageBuilder::buildVariableDeclaration(const std::string & name, SgType* type, SgInitializer * varInit, SgScopeStatement* scope)
1813{
1814 SgName name2(name);
1815 return buildVariableDeclaration(name2,type, varInit,scope);
1816}
1817
1820{
1821 SgName name2(name);
1822 return buildVariableDeclaration(name2,type, varInit,scope);
1823}
1824
1827SageBuilder::buildTypedefDeclaration(const std::string& name, SgType* base_type, SgScopeStatement* scope /*= NULL*/, bool has_defining_base/*= false*/)
1828{
1829 SgTypedefDeclaration* type_decl = buildTypedefDeclaration_nfi(name, base_type, scope, has_defining_base);
1831
1832 return type_decl;
1833}
1834
1836// The side effects include: creating SgTypedefType, SgTypedefSymbol, and add SgTypedefType to the base type
1838SageBuilder::buildTypedefDeclaration_nfi(const std::string& name, SgType* base_type, SgScopeStatement* scope /*= NULL*/, bool has_defining_base/*=false*/)
1839 {
1840 ROSE_ASSERT (base_type != NULL);
1841
1842 if (scope == NULL )
1843 {
1845 }
1846
1847 // We don't yet support bottom up construction for this node yet
1848 ASSERT_not_null(scope);
1849
1850 SgDeclarationStatement* base_decl = nullptr;
1851
1852 // Handle the case where this is a pointer, reference, or typedef to another type.
1853 SgType* stripedBaseType = base_type->stripType();
1854 ASSERT_not_null(stripedBaseType);
1855
1856 SgNamedType* namedType = isSgNamedType(stripedBaseType);
1857 if (namedType)
1858 {
1859 // DQ (12/28/2019): the problem with getting the base declaration from the type is that it forces sharing
1860 // of the base declaration when the typedef has a defining declaration for a base type in multiple files.
1861
1862 // DQ (3/20/2012): Use this to set the value of base_decl (which was previously unset).
1863 // isSgNamedType(base_type)->get_declaration();
1864 // base_decl = isSgNamedType(base_type)->get_declaration();
1865 base_decl = namedType->get_declaration();
1866
1867 // DQ (3/20/2012): All named types should have a valid declaration!
1868 ROSE_ASSERT(base_decl != NULL);
1869 }
1870
1871 // DQ (3/20/2012): I don't remember why we need to provide the symbol for the scope of the
1872 // parent rather then the scope. But as I recall there was a special corner of C++ that
1873 // required this sort of support.
1874 SgSymbol* parent_scope = NULL;
1875#ifndef ROSE_USE_CLANG_FRONTEND
1876 if (scope != NULL)
1877 {
1878 ROSE_ASSERT(scope->get_parent() != NULL);
1879 SgDeclarationStatement* declaration = isSgDeclarationStatement(scope->get_parent());
1880
1881 // PP (3/9/22)
1882 // In Ada, discriminated type may not have been fully built yet.
1883 // this is because a the discriminated type obtains the name of the underlying
1884 // declaration.
1885 // PP (5/9/22)
1886 // Unsure if declaration link should be set at all for Ada.
1887 // The AstConsistencyTest flags typedefdecls with declaration link set...
1888 if (declaration && !isSgAdaDiscriminatedTypeDecl(declaration))
1889 {
1890 mprintf ("Found a valid declaration = %p = %s \n",declaration,declaration->class_name().c_str());
1891
1892 ROSE_ASSERT(SageInterface::is_Ada_language() || declaration->get_firstNondefiningDeclaration() != NULL);
1893
1894 parent_scope = declaration->search_for_symbol_from_symbol_table();
1895
1896 ROSE_ASSERT(parent_scope != NULL);
1897 }
1898 }
1899#endif
1900
1901 // Create the first nondefining declaration (note that the typedef type is always a NULL input value).
1902 SgTypedefDeclaration* type_decl = new SgTypedefDeclaration(SgName(name), base_type, NULL, base_decl, parent_scope);
1903 ROSE_ASSERT(type_decl != NULL);
1904
1905 // 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)
1906 type_decl->set_scope(scope);
1907 type_decl->set_parent(scope);
1908
1909 // DQ (2/27/2018): Add this call here to reflect change to the constructor semantics.
1910 type_decl->set_type(SgTypedefType::createType(type_decl));
1911
1912 // 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)).
1913 type_decl->set_firstNondefiningDeclaration (type_decl);
1914 type_decl->set_definingDeclaration(NULL);
1915
1916 // Set the source code position information.
1917 setOneSourcePositionNull(type_decl);
1918
1919 // Liao 11/29/2012, for typedef struct Frame {int x;} st_frame; We have to set parent for the struct.
1920 // AstPostProcessing() has resetParentPointers(). But it is kind of too late.
1921 if (SgClassDeclaration* base_class = isSgClassDeclaration(base_decl))
1922 {
1923 SgClassDeclaration* def_class = isSgClassDeclaration(base_class->get_definingDeclaration());
1924 SgClassDeclaration* nondef_class = isSgClassDeclaration(base_class->get_firstNondefiningDeclaration());
1925 // Dan and Liao, 12/3/2012, handle test2003_08.C nested typedef
1926 if (has_defining_base)
1927 {
1928 if (def_class != NULL)
1929 if (def_class->get_parent() == NULL)
1930 def_class->set_parent(type_decl);
1931 }
1932 else
1933 {
1934 if (nondef_class != NULL)
1935 if (nondef_class->get_parent() == NULL)
1936 {
1937 nondef_class->set_parent(type_decl);
1938 }
1939 }
1940 }
1941
1942 SgTypedefSymbol* typedef_symbol = new SgTypedefSymbol(type_decl);
1943 ROSE_ASSERT(typedef_symbol);
1944
1945 scope->insert_symbol(SgName(name),typedef_symbol);
1946
1947 return type_decl;
1948 }
1949
1950
1952SageBuilder::buildTemplateTypedefDeclaration_nfi(const SgName & name, SgType* base_type, SgScopeStatement* scope, bool has_defining_base )
1953 {
1954 // DQ (11/2/2014): Adding support for templated typedef.
1955
1956 ROSE_ASSERT (base_type != NULL);
1957
1958 if (scope == NULL )
1959 {
1961 }
1962
1963 // We don't yet support bottom up construction for this node yet
1964 ROSE_ASSERT(scope != NULL);
1965
1966 SgDeclarationStatement* base_decl = NULL;
1967
1968 // DQ (3/20/2012): I don't remember why we need to provide the symbol for the scope of the
1969 // parent rather then the scope. But as I recall there was a special corner of C++ that
1970 // required this sort of support.
1971 SgSymbol* parent_scope = NULL;
1972 if (scope != NULL)
1973 {
1974 ROSE_ASSERT(scope->get_parent() != NULL);
1975 SgDeclarationStatement* declaration = isSgDeclarationStatement(scope->get_parent());
1976
1977 if (declaration != NULL)
1978 {
1979 ROSE_ASSERT(declaration->get_firstNondefiningDeclaration() != NULL);
1980 parent_scope = declaration->search_for_symbol_from_symbol_table();
1981
1982 ROSE_ASSERT(parent_scope != NULL);
1983 }
1984 // 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.
1985 SgNamedType* namedType = isSgNamedType(base_type);
1986
1987 // DQ (3/4/2018): This might not always be true (sure enough it fails for Cxx11_tests/test2014_58.C).
1988
1989 if (namedType != NULL)
1990 {
1991 SgDeclarationStatement* declarationStatement = namedType->get_declaration();
1992
1993 // This might not always be true.
1994 ROSE_ASSERT(declarationStatement != NULL);
1995 if (declarationStatement != NULL)
1996 {
1997 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(declarationStatement);
1998 if (templateInstantiationDecl != NULL)
1999 {
2000 SgName name = templateInstantiationDecl->get_name();
2001 // DQ (2/28/2018): Added debugging to track down redundnat symbol.
2002 if (scope->lookup_template_typedef_symbol(name) != NULL)
2003 {
2004 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());
2005 }
2006 ROSE_ASSERT(scope->lookup_template_typedef_symbol(name) == NULL);
2007 }
2008 }
2009 }
2010 }
2011
2012 // We need to add the template parameter and partial specialization support to the SgTemplateTypedefDeclaration IR node.
2013 SgTemplateTypedefDeclaration* type_decl = new SgTemplateTypedefDeclaration(name, base_type, NULL, base_decl, parent_scope);
2014 ROSE_ASSERT(type_decl != NULL);
2015
2016 // 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)
2017 type_decl->set_scope(scope);
2018 type_decl->set_parent(scope);
2019
2020 // DQ (2/27/2018): We now have to set the type explicitly.
2021 ROSE_ASSERT(type_decl->get_type() == NULL);
2022
2023 SgTypedefType* typedefType = SgTypedefType::createType(type_decl);
2024 ROSE_ASSERT(typedefType != NULL);
2025
2026 // DQ (2/27/2018): It is an inconsistancy for the type to be set here.
2027 type_decl->set_type(typedefType);
2028
2029 // DQ (2/27/2018): This should be non-null, since we just built the new type.
2030 ROSE_ASSERT(type_decl->get_type() != NULL);
2031
2032 // 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)).
2033 type_decl->set_firstNondefiningDeclaration (type_decl);
2034 type_decl->set_definingDeclaration(NULL);
2035
2036 // Set the source code position information.
2037 setOneSourcePositionNull(type_decl);
2038
2039 // 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.
2040 SgNamedType* namedType = isSgNamedType(base_type);
2041
2042 // DQ (3/4/2018): This might not always be true (sure enough it fails for Cxx11_tests/test2014_58.C).
2043
2044 if (namedType != NULL)
2045 {
2046 SgDeclarationStatement* declarationStatement = namedType->get_declaration();
2047
2048 // This might not always be true.
2049 ROSE_ASSERT(declarationStatement != NULL);
2050 if (declarationStatement != NULL)
2051 {
2052 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(declarationStatement);
2053 if (templateInstantiationDecl != NULL)
2054 {
2055 SgName name = templateInstantiationDecl->get_name();
2056 // DQ (2/28/2018): Added debugging to track down redundnat symbol.
2057 if (scope->lookup_template_typedef_symbol(name) != NULL)
2058 {
2059 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());
2060 }
2061 ROSE_ASSERT(scope->lookup_template_typedef_symbol(name) == NULL);
2062 }
2063 }
2064 }
2065
2066 SgTemplateTypedefSymbol* typedef_symbol = new SgTemplateTypedefSymbol(type_decl);
2067 ROSE_ASSERT(typedef_symbol);
2068
2069 // DQ (5/16/2013): This is the code we want now that we have implemented the namespace support behind the scope symbol bable interface.
2070 scope->insert_symbol(name, typedef_symbol);
2071
2072 ROSE_ASSERT(scope->lookup_template_typedef_symbol(name) != NULL);
2073
2074 return type_decl;
2075 }
2076
2077#define DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi 0
2078
2081 SgName & name, SgType* base_type, SgScopeStatement* scope, bool has_defining_base,
2082 SgTemplateTypedefDeclaration* templateTypedefDeclaration,
2083 SgTemplateArgumentPtrList & templateArgumentsList
2084) {
2085#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2086 std::cout << "SageBuilder::buildTemplateInstantiationTypedefDeclaration_nfi" << std::endl;
2087 std::cout << " name = " << name.getString() << std::endl;
2088 std::cout << " base_type = " << std::hex << base_type << " : " << ( base_type ? base_type->class_name() : "" ) << std::endl;
2089#endif
2090 ROSE_ASSERT (base_type != NULL);
2091
2092 SgName nameWithoutTemplateArguments = name;
2093 SgName nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,templateArgumentsList);
2094#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2095 std::cout << " nameWithoutTemplateArguments = " << nameWithoutTemplateArguments.getString() << std::endl;
2096 std::cout << " nameWithTemplateArguments = " << nameWithTemplateArguments.getString() << std::endl;
2097#endif
2098
2099 // We don't yet support bottom up construction for this node yet
2100 ROSE_ASSERT(scope != NULL);
2101
2102 SgDeclarationStatement* base_decl = NULL;
2103
2104 // DQ (3/20/2012): I don't remember why we need to provide the symbol for the scope of the
2105 // parent rather then the scope. But as I recall there was a special corner of C++ that
2106 // required this sort of support.
2107 SgSymbol* parent_scope = NULL;
2108 if (scope != NULL)
2109 {
2110 ROSE_ASSERT(scope->get_parent() != NULL);
2111 SgDeclarationStatement* declaration = isSgDeclarationStatement(scope->get_parent());
2112 if (declaration != NULL)
2113 {
2114 ROSE_ASSERT(declaration->get_firstNondefiningDeclaration() != NULL);
2115 parent_scope = declaration->search_for_symbol_from_symbol_table();
2116
2117 ROSE_ASSERT(parent_scope != NULL);
2118 }
2119 }
2120
2121 // DQ (11/5/2014): I think this might be set afterward.
2122 ROSE_ASSERT(templateTypedefDeclaration != NULL);
2123
2124 SgTemplateTypedefSymbol* prexisting_template_typedef_symbol = scope->lookup_template_typedef_symbol(nameWithTemplateArguments);
2125 if (prexisting_template_typedef_symbol != NULL)
2126 {
2127 SgDeclarationStatement* declarationStatement = prexisting_template_typedef_symbol->get_declaration();
2128 ROSE_ASSERT(declarationStatement != NULL);
2129 SgTemplateInstantiationTypedefDeclaration* return_declaration = isSgTemplateInstantiationTypedefDeclaration(declarationStatement);
2130 ROSE_ASSERT(return_declaration != NULL);
2131 return return_declaration;
2132 }
2133 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == NULL);
2134
2135 // DQ (2/25/2018): Not clear if we want to use the template name with arguments.
2136 // Calling: SgTemplateInstantiationTypedefDeclaration(SgName, SgType*, SgTypedefType*, SgDeclarationStatement*, SgSymbol*, SgTemplateTypedefDeclaration*, SgTemplateArgumentPtrList)
2137 SgTypedefType* typedefType = NULL;
2139 new SgTemplateInstantiationTypedefDeclaration(nameWithTemplateArguments, base_type, typedefType, base_decl, parent_scope, templateTypedefDeclaration, templateArgumentsList);
2140 ROSE_ASSERT(type_decl != NULL);
2141 ROSE_ASSERT(type_decl->get_base_type() == base_type);
2142
2143#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2144 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2145 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;
2146#endif
2147
2148 // DQ (2/27/2018): This is a change in the constructor semantics, we now have to build the type explicitly.
2149 // printf ("We now have to build the type explicitly \n");
2150 ROSE_ASSERT(type_decl->get_type() == NULL);
2151
2152
2153 // DQ (2/27/2018): Set the template name that this instantiation is using.
2154 type_decl->set_templateName(nameWithoutTemplateArguments);
2155
2156 ROSE_ASSERT(scope != NULL);
2157 type_decl->set_scope(scope);
2158
2159 // DQ (3/1/2018): A bug in the name of the template with arguments has been detected (extra spaces in
2160 // the name generated by type_decl->resetTemplateName()), make sure that we have a consistant naming.
2161 ROSE_ASSERT(type_decl->get_name() == nameWithTemplateArguments);
2162
2163 // DQ (2/28/2018): Added debugging to track down redundnat symbol.
2164 if (scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != NULL)
2165 {
2166 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());
2167 }
2168 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == NULL);
2169
2170
2171 // DQ (2/26/2018): Can we assert this?
2172 ROSE_ASSERT(type_decl->get_type() == NULL);
2173
2174 SgTypedefType* new_typedefType = SgTypedefType::createType(type_decl);
2175 ROSE_ASSERT(new_typedefType != NULL);
2176
2177 type_decl->set_type(new_typedefType);
2178 ROSE_ASSERT(type_decl->get_type() != NULL);
2179 ROSE_ASSERT(type_decl->get_scope() != NULL);
2180
2181 type_decl->set_firstNondefiningDeclaration (type_decl);
2182 type_decl->set_definingDeclaration(NULL);
2183
2184 setOneSourcePositionNull(type_decl);
2185
2186 SgName mangled_name = type_decl->get_mangled_name();
2187 setTemplateArgumentsInDeclaration(type_decl,&templateArgumentsList);
2188
2189 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() != NULL);
2190 ROSE_ASSERT(type_decl->get_definingDeclaration() == NULL);
2191 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() == type_decl);
2192
2193 ROSE_ASSERT(type_decl->get_type() != NULL);
2194 ROSE_ASSERT(scope != NULL);
2195
2196#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2197 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2198 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;
2199#endif
2200
2201 if (scope != NULL)
2202 {
2203 if (scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != NULL)
2204 {
2205 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());
2206 }
2207 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == NULL);
2208
2209 SgTemplateTypedefSymbol* typedef_symbol = new SgTemplateTypedefSymbol(type_decl);
2210 ROSE_ASSERT(typedef_symbol);
2211
2212 scope->insert_symbol(nameWithTemplateArguments,typedef_symbol);
2213 type_decl->set_scope(scope);
2214 type_decl->set_parent(scope);
2215 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != NULL);
2216 }
2217
2218#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2219 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2220 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;
2221#endif
2222
2223 return type_decl;
2224 }
2225
2226
2227
2228
2229
2230//-----------------------------------------------
2231// Assertion `definingDeclaration != NULL || firstNondefiningDeclaration != NULL'
2234{
2235 SgFunctionParameterList *parameterList = new SgFunctionParameterList();
2236 ROSE_ASSERT (parameterList);
2237
2238 parameterList->set_definingDeclaration (NULL);
2239 parameterList->set_firstNondefiningDeclaration (parameterList);
2240
2242
2243 if (in1) appendArg(parameterList, in1);
2244 if (in2) appendArg(parameterList, in2);
2245 if (in3) appendArg(parameterList, in3);
2246 if (in4) appendArg(parameterList, in4);
2247 if (in5) appendArg(parameterList, in5);
2248 if (in6) appendArg(parameterList, in6);
2249 if (in7) appendArg(parameterList, in7);
2250 if (in8) appendArg(parameterList, in8);
2251 if (in9) appendArg(parameterList, in9);
2252 if (in10) appendArg(parameterList, in10);
2253
2254 return parameterList;
2255}
2256
2259 SgFunctionParameterList *parameterList = new SgFunctionParameterList();
2260 ROSE_ASSERT (parameterList);
2261 parameterList->set_definingDeclaration (NULL);
2262 parameterList->set_firstNondefiningDeclaration (parameterList);
2263
2264 setOneSourcePositionNull(parameterList);
2265
2266 return parameterList;
2267}
2268
2269//-----------------------------------------------
2272 SgCtorInitializerList *ctorInitList = new SgCtorInitializerList();
2273 ROSE_ASSERT (ctorInitList);
2274 ctorInitList->set_definingDeclaration (NULL);
2275 ctorInitList->set_firstNondefiningDeclaration (ctorInitList);
2276
2277 setOneSourcePositionNull(ctorInitList);
2278
2279 return ctorInitList;
2280}
2281
2282//-----------------------------------------------
2283// no type vs. void type ?
2286 {
2287 // DQ (8/19/2012): I am not a fan of this sort of codeing style either (NULL pointers as inputs should be an error).
2288 if (paralist == NULL)
2289 {
2290 printf ("WARNING: In buildFunctionParameterTypeList(): Accepting NULL input and returning NULL pointer. \n");
2291
2292 return NULL;
2293 }
2294
2295 // 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).
2296 // if (paralist->get_args().size()==0)
2297 // return NULL;
2298
2300 ROSE_ASSERT(typePtrList != NULL);
2301
2302 SgInitializedNamePtrList args = paralist->get_args();
2303 SgInitializedNamePtrList::const_iterator i;
2304 for(i = args.begin(); i != args.end(); i++)
2305 (typePtrList->get_arguments()).push_back( (*i)->get_type() );
2306
2308
2309 return typePtrList;
2310 }
2311
2312
2315 {
2316 if (expList ==NULL) return NULL;
2317 SgExpressionPtrList expPtrList = expList->get_expressions();
2318
2320 ROSE_ASSERT(typePtrList);
2321
2322 SgExpressionPtrList::const_iterator i;
2323 for (i=expPtrList.begin();i!=expPtrList.end();i++)
2324 {
2325 typePtrList->get_arguments().push_back( (*i)->get_type() );
2326 }
2327
2329
2330 return typePtrList;
2331 }
2332
2335 SgType* type4, SgType* type5, SgType* type6, SgType* type7)
2336 {
2338 ROSE_ASSERT(typePtrList);
2339
2340 SgTypePtrList & types = typePtrList->get_arguments();
2341
2342 if (type0 != NULL) types.push_back(type0);
2343 if (type1 != NULL) types.push_back(type1);
2344 if (type2 != NULL) types.push_back(type2);
2345 if (type3 != NULL) types.push_back(type3);
2346 if (type4 != NULL) types.push_back(type4);
2347 if (type5 != NULL) types.push_back(type5);
2348 if (type6 != NULL) types.push_back(type6);
2349 if (type7 != NULL) types.push_back(type7);
2350
2351 return typePtrList;
2352 }
2353
2354//-----------------------------------------------
2355// build function type,
2356//
2357// insert into symbol table when not duplicated
2360 {
2361 ROSE_ASSERT(return_type != NULL);
2362
2363 // DQ (8/19/2012): Can we enforce this?
2364 ROSE_ASSERT(typeList != NULL);
2365
2367 ROSE_ASSERT(fTable);
2368
2369 // This function make clever use of a static member function which can't be built
2370 // for the case of a SgMemberFunctionType (or at least not without more work).
2371 SgName typeName = SgFunctionType::get_mangled(return_type, typeList);
2372
2373 SgFunctionType* funcType = isSgFunctionType(fTable->lookup_function_type(typeName));
2374
2375 if (funcType == NULL)
2376 {
2377 // Only build the new type if it can't be found in the global type table.
2378 funcType = new SgFunctionType(return_type, false);
2379 ROSE_ASSERT(funcType);
2380
2381 if (typeList != NULL)
2382 {
2383 // DQ (12/5/2012): We want to avoid overwriting an existing SgFunctionParameterTypeList. Could be related to failing tests for AST File I/O.
2384 if (funcType->get_argument_list() != NULL)
2385 {
2386 delete funcType->get_argument_list();
2387 funcType->set_argument_list(NULL);
2388 }
2389 ROSE_ASSERT(funcType->get_argument_list() == NULL);
2390
2391 funcType->set_argument_list(typeList);
2392 typeList->set_parent(funcType);
2393 }
2394
2395 fTable->insert_function_type(typeName,funcType);
2396 }
2397 else
2398 {
2399 // DQ (12/6/2012): Tracking down orphaned SgFunctionParameterTypeList objects.
2400 }
2401
2402 return funcType;
2403 }
2404
2405
2406
2408SageBuilder::buildMemberFunctionType(SgType* return_type, SgFunctionParameterTypeList* typeList, SgType *classType, unsigned int mfunc_specifier)
2409 {
2410 // DQ (8/19/2012): This is a refactored version of the buildMemberFunctionType() below so that we can
2411 // isolate out the part that uses a SgClassType from the version that uses the SgClassDefinition.
2412
2413 // Maintain the global type table
2415 ROSE_ASSERT(fTable != NULL);
2416
2417 // DQ (12/6/2012): Added assertion.
2418 // ROSE_ASSERT(classType != NULL);
2419
2420 // DQ (12/13/2012): Added assertion.
2421 ROSE_ASSERT(typeList != NULL);
2422
2423 // DQ (12/6/2012): Newer simpler code (using static function SgMemberFunctionType::get_mangled()).
2424 SgName typeName = SgMemberFunctionType::get_mangled(return_type,typeList,classType,mfunc_specifier);
2425 SgType* typeInTable = fTable->lookup_function_type(typeName);
2426
2427#if 0
2428 printf ("In buildMemberFunctionType(SgType*,SgFunctionParameterTypeList*,SgType*,int,int): fTable->lookup_function_type(typeName = %s) = %p \n",typeName.str(),typeInTable);
2429 printf (" --- mfunc_specifier = %d ref_qualifiers = %d \n",mfunc_specifier,ref_qualifiers);
2430#endif
2431
2432#if 0
2433 // DQ (1/10/2020): I think that these qualifiers are contained in the mfunc_specifier.
2434 if (ref_qualifiers > 0)
2435 {
2436 printf ("Exiting as a test! \n");
2437 ROSE_ABORT();
2438 }
2439#endif
2440
2441 SgMemberFunctionType* funcType = NULL;
2442 if (typeInTable == NULL)
2443 {
2444 bool has_ellipses = false;
2445 //~ SgPartialFunctionType* partialFunctionType = new SgPartialFunctionType(return_type, has_ellipses, classType, mfunc_specifier, ref_qualifiers);
2446 // PP (10/4/22): removing ref_qualifiers
2447 SgPartialFunctionType* partialFunctionType = new SgPartialFunctionType(return_type, has_ellipses, classType, mfunc_specifier);
2448 ROSE_ASSERT(partialFunctionType != NULL);
2449#if 0
2450 printf ("Building a SgPartialFunctionType: partialFunctionType = %p \n",partialFunctionType);
2451 printf (" --- partialFunctionType->isLvalueReferenceFunc() = %s \n",partialFunctionType->isLvalueReferenceFunc() ? "true" : "false");
2452 printf (" --- partialFunctionType->isRvalueReferenceFunc() = %s \n",partialFunctionType->isRvalueReferenceFunc() ? "true" : "false");
2453#endif
2454 // DQ (12/5/2012): We want to avoid overwriting an existing SgFunctionParameterTypeList. Could be related to failing tests for AST File I/O.
2455 if (partialFunctionType->get_argument_list() != NULL)
2456 {
2457 delete partialFunctionType->get_argument_list();
2458 partialFunctionType->set_argument_list(NULL);
2459 }
2460 ROSE_ASSERT(partialFunctionType->get_argument_list() == NULL);
2461
2462 typeList->set_parent(partialFunctionType);
2463
2464 // DQ (12/6/2012): Set the SgFunctionParameterTypeList in the SgPartialFunctionType before trying
2465 // to build a SgMemberFunctionType (not critical that it be set before, but might be in the future,
2466 // but it is important that it be set).
2467 partialFunctionType->set_argument_list(typeList);
2468
2469 ROSE_ASSERT(partialFunctionType->get_argument_list() != NULL);
2470
2471 // The optional_fortran_type_kind is only required for Fortran support.
2472 SgExpression* optional_fortran_type_kind = NULL;
2473 funcType = SgMemberFunctionType::createType(partialFunctionType, optional_fortran_type_kind);
2474
2475 // DQ (12/13/2012): Remove the SgPartialFunctionType after it has been used to build the SgMemberFunctionType.
2476 // I would rather modify the SgMemberFunctionType::createType() API so that we didn't use the SgPartialFunctionType IR nodes.
2477 // First we have to reset the pointer to the type argument list to NULL since it is shared with the SgMemberFunctionType.
2478 partialFunctionType->set_argument_list(NULL);
2479
2480 // Then we can delete the SgPartialFunctionType.
2481 delete partialFunctionType;
2482 partialFunctionType = NULL;
2483
2484 // This is perhaps redundant since it was set to a derived class (but might be an important distiction).
2485 typeList->set_parent(funcType);
2486
2487 ROSE_ASSERT(funcType->get_argument_list() != NULL);
2488 }
2489
2490 if (typeInTable == nullptr)
2491 {
2492 ASSERT_not_null(funcType);
2493 fTable->insert_function_type(typeName,funcType);
2494 }
2495 else
2496 {
2497 // DQ (12/3/2011): Added this case to support reuse of function types (not handled by the createType functions).
2498 // Delete the one generated so that we could form the mangled name.
2499 ASSERT_require(typeInTable != funcType);
2500 delete funcType;
2501
2502 // Return the one from the global type table.
2503 funcType = isSgMemberFunctionType(typeInTable);
2504 ASSERT_not_null(funcType);
2505 }
2506
2507 return funcType;
2508 }
2509
2510
2511// DQ (1/4/2009): Need to finish this!!!
2512//-----------------------------------------------
2513// build member function type,
2514//
2515// insert into symbol table when not duplicated
2517SageBuilder::buildMemberFunctionType(SgType* return_type, SgFunctionParameterTypeList* typeList, SgScopeStatement * struct_name, unsigned int mfunc_specifier)
2518 {
2519 // This function has to first build a version of the SgMemberFunctionType so that it can generate a mangled name.
2520 // If the mangled name can be use to lookup a SgMemberFunctionType then the "just built" SgMemberFunctionType
2521 // is deleted and the one from the global function type table is returned. This fixes a lot of subtle C++
2522 // specific issues with the build interface and it's use with the newer EDG 4.3 connection to ROSE.
2523
2524 ROSE_ASSERT(return_type != NULL);
2525
2526 // SgMemberFunctionType (SgType *return_type=NULL, bool has_ellipses=true, SgClassDefinition *struct_name=NULL, unsigned int mfunc_specifier=0)
2527 // SgMemberFunctionType * funcType = new SgMemberFunctionType(return_type, false);
2528
2529 ROSE_ASSERT(struct_name != NULL);
2530
2531#if 0
2532 printf("In buildMemberFunctionType():\n");
2533 printf(" - struct_name = %p (%s)\n", struct_name, struct_name->class_name().c_str());
2534#endif
2535
2536#if 0
2537 // DQ (1/9/2020): Unclear why this function is not using the ref_qualifiers.
2538 printf ("SageBuilder::buildMemberFunctionType(SgType*,SgFunctionParameterTypeList*,SgScopeStatement*,int,int): This function does not use the input ref_qualifiers = %x \n",ref_qualifiers);
2539 printf (" --- mfunc_specifier = %d ref_qualifiers = %d \n",mfunc_specifier,ref_qualifiers);
2540#endif
2541
2542#if 0
2543 printf ("Exiting as a test! \n");
2544 ROSE_ABORT();
2545#endif
2546
2547 ROSE_ASSERT(struct_name->get_parent() != NULL);
2548 // ROSE_ASSERT(struct_name->get_declaration() != NULL);
2549
2550#if 0
2551 printf("struct_name = %p ( %s )\n", struct_name, struct_name->class_name().c_str());
2552#endif
2553
2554 // SgDeclarationStatement* declaration = struct_name->get_declaration();
2555 SgClassDefinition* classDefinition = isSgClassDefinition(struct_name);
2556 SgDeclarationScope* decl_scope = isSgDeclarationScope(struct_name);
2557
2558 if (classDefinition == NULL && decl_scope == NULL)
2559 {
2560 printf ("Error: (classDefinition == NULL && decl_scope == NULL): struct_name = %p = %s name = %s \n",
2561 struct_name,struct_name->class_name().c_str(),SageInterface::get_name(struct_name).c_str());
2562 }
2563 ROSE_ASSERT(classDefinition != NULL || decl_scope != NULL);
2564
2565 SgDeclarationStatement* declaration = NULL;
2566 if (classDefinition != NULL)
2567 {
2568 declaration = classDefinition->get_declaration();
2569 }
2570 else if (decl_scope != NULL)
2571 {
2572 declaration = isSgDeclarationStatement(decl_scope->get_parent());
2573 }
2574 else
2575 {
2576 ROSE_ABORT();
2577 }
2578
2579 ROSE_ASSERT(declaration != NULL);
2580
2581 if (typeList != NULL)
2582 {
2583#if 0
2584 SgTypePtrList & typeListArgs = typeList->get_arguments();
2585 for (SgTypePtrList::iterator i = typeListArgs.begin(); i != typeListArgs.end(); i++)
2586 {
2587 printf (" --- type argument = %p = %s \n",*i,(*i)->class_name().c_str());
2588 }
2589#endif
2590 }
2591 else
2592 {
2593 printf ("WARNING: typeList == NULL \n");
2594 }
2595
2596 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
2597 // SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(declaration);
2598 SgNonrealDecl * nrdecl = isSgNonrealDecl(declaration);
2599
2600 ROSE_ASSERT(classDeclaration != NULL || nrdecl != NULL);
2601
2602 SgMemberFunctionType* funcType = NULL;
2603
2604 // DQ (12/4/2011): Modified SgClassType to support template declarations (SgTemplateClassDeclaration now contains a type set to SgClassType.
2605 // The SgClassType has been modified (browdened) to support a SgDeclarationStatement instead of a SgClassDeclaration.
2606 // SgClassType* classType = classDeclaration->get_type();
2607 SgType* classType = NULL;
2608 if (classDeclaration != NULL)
2609 {
2610 classType = classDeclaration->get_type();
2611 }
2612 else if (decl_scope != NULL)
2613 {
2614 classType = nrdecl->get_type();
2615 }
2616 else
2617 {
2618 ROSE_ABORT();
2619 }
2620
2621 ROSE_ASSERT(classType != NULL);
2622
2623#if 0
2624 printf ("In buildMemberFunctionType(): Calling refactored function: buildMemberFunctionType(...,classType = %p,...) \n",classType);
2625#endif
2626
2627 // DQ (8/19/2012): This code has been refactored.
2628 funcType = buildMemberFunctionType(return_type,typeList,classType,mfunc_specifier);
2629
2630#if 0
2631 printf ("In buildMemberFunctionType(): DONE: Calling refactored function: buildMemberFunctionType(...,classType = %p,...) \n",classType);
2632#endif
2633
2634 return funcType;
2635 }
2636
2637
2640 {
2641 ROSE_ASSERT(base_type != NULL);
2642
2643 ROSE_ASSERT(classType != NULL);
2644 SgPointerMemberType* pointerToMemberType = new SgPointerMemberType(base_type,classType);
2645 return pointerToMemberType;
2646
2647 }
2648
2649//----------------------------------------------------
2651SgType * SageBuilder::buildOpaqueType(std::string const name, SgScopeStatement * scope)
2652{
2653 // we require users to specify a target scope
2654 ROSE_ASSERT(scope);
2655 SgTypedefDeclaration* type_decl = NULL;
2656 SgTypedefType* result = NULL;
2657
2658 // Liao and Greg Bronevetsky , 8/27/2009
2659 // patch up the symbol
2660 // and avoid duplicated creation
2661 // TODO a function like fixTypeDeclaration() (similar to SageInterface::fixVariableDeclaration()) for this
2662 SgTypedefSymbol* type_symbol = scope->lookup_typedef_symbol(name);
2663 if (type_symbol == NULL)
2664 {
2665 type_decl = new SgTypedefDeclaration(name,buildIntType(),NULL, NULL, NULL);
2666 ROSE_ASSERT(type_decl);
2667
2668 // DQ (2/27/2018): Add this call here to reflect change to the constructor semantics.
2669 type_decl->set_type(SgTypedefType::createType(type_decl));
2670
2671 type_symbol = new SgTypedefSymbol(type_decl);
2672 ROSE_ASSERT(type_symbol);
2673 SgName n = name;
2674
2675 // DQ (5/21/2013): The symbol table should only be accessed through the SgScopeStatement interface.
2676 scope->insert_symbol(n,type_symbol);
2677
2678 type_decl->set_firstNondefiningDeclaration (type_decl);
2680 prependStatement(type_decl,scope);
2681 // Hide it from unparser
2682 Sg_File_Info* file_info = type_decl->get_file_info();
2683 file_info->unsetOutputInCodeGeneration ();
2684 result = new SgTypedefType(type_decl);
2685 }
2686 else
2687 {
2688 type_decl = type_symbol->get_declaration();
2689 result = type_decl->get_type();
2690 }
2691 ROSE_ASSERT(result);
2692 return result;
2693}
2694
2695
2696//----------------- function type------------
2697// same function declarations (defining or nondefining) should share the same function type!
2700 {
2701 ASSERT_not_null(argList);
2702
2704 SgFunctionType* func_type = buildFunctionType(return_type, typeList);
2705
2706 if (func_type->get_argument_list() != typeList)
2707 {
2708 delete typeList;
2709 typeList = NULL;
2710 }
2711
2712 return func_type;
2713 }
2714
2715void
2716checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope ( SgDeclarationStatement* func, SgScopeStatement* scope )
2717 {
2718 // DQ (12/14/2011): We need the parent to be set so that we can call some of the test functions
2719 // (e.g assert that get_class_scope() for member functions). So we set the parent to the scope
2720 // by default and see if this will work, else we could disable to assertion that the parent is
2721 // non-null in the get_class_scope() member function.
2722
2723 if (isSgMemberFunctionDeclaration(func) != NULL)
2724 {
2725#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
2726 printf ("WARNING: setting parent of function to match scope by default \n");
2727#endif
2728 func->set_parent(scope);
2729
2730 ROSE_ASSERT(scope != NULL);
2731
2732 if (isSgTemplateInstantiationMemberFunctionDecl(func) != NULL)
2733 {
2734 // DQ (12/14/2011): We should not have a member function template instantiation in a template class definition.
2735
2736 // DQ (8/25/2014): Un-Commented out to revert to previous working state.
2737 // DQ (8/25/2014): Commented out to test new logic at base of isTemplateDeclaration(a_routine_ptr).
2738 // DQ (8/25/2014): Un-Commented out to revert to previous working state.
2739 // DQ (8/25/2014): Allow non-template functions in a template class declaration (see test2014_161.C).
2740#if !ENFORCE_NO_FUNCTION_TEMPLATE_DECLARATIONS_IN_TEMPLATE_CLASS_INSTANTIATIONS
2741 // 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");
2742#endif
2743 }
2744 }
2745 else
2746 {
2747 if (isSgTemplateFunctionDeclaration(func) != NULL)
2748 {
2749 if (isSgTemplateInstantiationMemberFunctionDecl(func) != NULL)
2750 {
2751 ROSE_ASSERT(isSgTemplateClassDefinition(scope) != NULL);
2752 }
2753 }
2754 }
2755 }
2756
2757//----------------- function declaration------------
2758// considering
2759// 1. fresh building
2760// 2. secondary building after another nondefining functiondeclaration
2761// 3. secondary building after another defining function declaration
2762// 4. fortran ?
2763template <class actualFunction>
2764actualFunction*
2765SageBuilder::buildNondefiningFunctionDeclaration_T (
2766 const SgName & XXX_name, SgType* return_type, SgFunctionParameterList * paralist, bool isMemberFunction,
2767 SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags,
2768 SgTemplateArgumentPtrList* templateArgumentsList, SgTemplateParameterPtrList* templateParameterList,
2770) {
2771 // DQ (11/25/2011): This function has been modified to work when used with a SgTemplateFunctionDeclaration as a template argument.
2772 // It was originally designed to work with only SgFunctionDeclaration and SgMemberFunctionDeclaration, it now works with these
2773 // plus SgTemplateFunctionDeclaration and SgTemplateMemberonDeclaration IR nodes. This is part of providing new support for template
2774 // declarations in the AST and a general update of this function to support this expanded use.
2775
2776 // 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.
2777
2778 // argument verification
2779 if (scope == nullptr)
2780 {
2782 }
2783 ASSERT_not_null(scope);
2784
2785 if (XXX_name.is_null() == true)
2786 {
2787 // DQ (4/2/2013): This case is generated for test2013_86.C.
2788 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");
2789 }
2790
2791 SgName nameWithoutTemplateArguments = XXX_name;
2792 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
2793
2794 bool buildTemplateInstantiation = ((VariantT)actualFunction::static_variant == V_SgTemplateInstantiationFunctionDecl || (VariantT)actualFunction::static_variant == V_SgTemplateInstantiationMemberFunctionDecl);
2795
2796 // DQ (8/7/2013): Added support for template declarations.
2797 bool buildTemplateDeclaration = ((VariantT)actualFunction::static_variant == V_SgTemplateFunctionDeclaration || (VariantT)actualFunction::static_variant == V_SgTemplateMemberFunctionDeclaration);
2798
2799 // DQ (8/7/2013): Added support for template declarations (need to handle template names overloaded on template parameters).
2800 // We want to use the template arguments in the symbol table lookup, but not in the name generation.
2801 if (buildTemplateInstantiation == true)
2802 {
2803 ASSERT_not_null(templateArgumentsList);
2804 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
2805 }
2806
2807 // this function is also called when building a function reference before the function declaration exists. So, skip the check
2808 if (nameWithTemplateArguments.is_null() == true)
2809 {
2810 // DQ (3/25/2017): Modified to use message logging.
2811 // DQ (4/2/2013): This case is generated for test2013_86.C.
2812 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");
2813 }
2814
2815 if (nameWithoutTemplateArguments.is_null() == true)
2816 {
2817 // DQ (3/25/2017): Modified to use message logging.
2818 // DQ (4/2/2013): This case is generated for test2013_86.C.
2819 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");
2820 }
2821
2822 ASSERT_not_null(return_type);
2823 ASSERT_not_null(paralist);
2824
2825 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
2826 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
2827 if (SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == true)
2828 {
2829#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
2830 printf ("Warning: In buildNondefiningFunctionDeclaration_T(): nameWithoutTemplateArguments = %s nameWithTemplateArguments = %s \n",nameWithoutTemplateArguments.str(),nameWithTemplateArguments.str());
2831#endif
2832 }
2833 // DQ (7/27/2012): There are reasons why this can fail: e.g. for functions with names such as:
2834 // "operator std::auto_ptr_ref<_Tp1>" which is a user defined conversion operator to one class from another.
2835
2836 // tentatively build a function type, since it is shared
2837 // by all prototypes and defining declarations of a same function!
2838
2839 SgFunctionType* func_type = nullptr;
2840 if (isMemberFunction == true)
2841 {
2843 func_type = buildMemberFunctionType(return_type,typeList,scope, functionConstVolatileFlags);
2844 }
2845 else
2846 {
2847 func_type = buildFunctionType(return_type,paralist);
2848 }
2849
2850 ASSERT_not_null(func_type);
2851
2852 // function declaration
2853 actualFunction* func = nullptr;
2854
2855 // search before using the function type to create the function declaration
2856 // TODO only search current scope or all ancestor scope?? (DQ: Only current scope!)
2857 // We don't have lookup_member_function_symbol yet
2858
2859 // DQ (12/27/2011): Under the new design we can make the symbol type SgFunctionSymbol instead of the less specific SgSymbol.
2860 // DQ (11/25/2011): We want to add the support for template function declarations,
2861 // so this should be a SgSymbol so that we can have it be either a SgFunctionSymbol
2862 // or a SgTemplateSymbol.
2863 SgFunctionSymbol* func_symbol = NULL;
2864
2865 if (scope != NULL)
2866 {
2867 // DQ (3/13/2012): Experiment with new function to support only associating the right type of symbol with the
2868 // function being built. I don't think I like the design of this interface, but we might change that later.
2869
2870 // 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.
2871 func_symbol = scope->find_symbol_by_type_of_function<actualFunction>(nameWithTemplateArguments,func_type,templateParameterList,templateArgumentsList);
2872
2873#if 0 // DBG1
2874 printf ("In buildNondefiningFunctionDeclaration_T(): func_symbol from scope->find_symbol_by_type_of_function<actualFunction>(name = %s) = %p \n",nameWithTemplateArguments.str(),func_symbol);
2875 if (func_symbol != NULL) {
2876 printf ("In buildNondefiningFunctionDeclaration_T(): func_symbol->get_declaration() = %p \n", func_symbol->get_declaration());
2877 }
2878#endif /* DBG1 */
2879
2880 // If not a proper function (or instantiated template function), then check for a template function declaration.
2881 if (func_symbol == NULL)
2882 {
2883 // Note that a template function does not have a function type (just a name).
2884 ROSE_ASSERT(func_type != NULL);
2885 }
2886 }
2887
2888 // DQ (3/13/2012): I want to introduce error checking on the symbol matching the template parameter.
2889 if (func_symbol != NULL)
2890 {
2891 switch((VariantT)actualFunction::static_variant)
2892 {
2893 case V_SgFunctionDeclaration:
2894 case V_SgProcedureHeaderStatement:
2895 case V_SgTemplateInstantiationFunctionDecl:
2896 {
2897 ROSE_ASSERT(isSgFunctionSymbol(func_symbol) != NULL);
2898 break;
2899 }
2900 case V_SgMemberFunctionDeclaration:
2901 case V_SgTemplateInstantiationMemberFunctionDecl:
2902 {
2903 ROSE_ASSERT(isSgMemberFunctionSymbol(func_symbol) != NULL);
2904 break;
2905 }
2906 case V_SgTemplateFunctionDeclaration:
2907 {
2908 ROSE_ASSERT(isSgTemplateFunctionSymbol(func_symbol) != NULL);
2909 break;
2910 }
2911 case V_SgTemplateMemberFunctionDeclaration:
2912 {
2913 ROSE_ASSERT(isSgTemplateMemberFunctionSymbol(func_symbol) != NULL);
2914 break;
2915 }
2916
2917 default:
2918 {
2919 printf ("default reach in buildNondefiningFunctionDeclaration_T(): variantT(actualFunction::static_variant) = %d \n",actualFunction::static_variant);
2920 ROSE_ABORT();
2921 }
2922 }
2923
2924 // TV (2/5/14): Found symbol might come from another file, in this case we need to insert it in the current scope.
2925 // Can only happen when scope is a global scope
2926 ROSE_ASSERT(scope != NULL);
2927 if ( isSgGlobal(scope) != NULL
2928 && scope != func_symbol->get_scope()
2929 && !SageInterface::isAncestor(scope, func_symbol->get_scope())
2930 && !scope->symbol_exists(nameWithTemplateArguments, func_symbol) )
2931 {
2932 scope->insert_symbol(nameWithTemplateArguments, func_symbol);
2933 }
2934 }
2935
2936 if (func_symbol == NULL)
2937 {
2938 func = new actualFunction (nameWithTemplateArguments,func_type,NULL);
2939 ROSE_ASSERT(func != NULL);
2940
2941 // Storage modifier (esp. static) must be set before inserting symbol
2942 func->get_declarationModifier().get_storageModifier().set_modifier(sm);
2943
2944 // DQ (5/1/2012): This should always be true.
2945 ROSE_ASSERT(func->get_file_info() == NULL);
2946
2947 // DQ (12/14/2011): Moved this from lower in this function.
2948 func->set_scope(scope);
2949
2950 // DQ (12/15/2011): Added test.
2951 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(func,scope);
2952
2953 // This fails below for a SgTemplateFunctionDeclaration, so test it here.
2954 ROSE_ASSERT(func->get_parameterList() != NULL);
2955
2956 // NOTE: we want to allow the input scope to be NULL (and even the SageBuilder::topScopeStack() == NULL)
2957 // so that function can be built bottom up style. However this means that the symbol tables in the
2958 // scope of the returned function declaration will have to be setup separately.
2959 if (scope != NULL)
2960 {
2961 // function symbol table
2962 if (isSgMemberFunctionDeclaration(func))
2963 {
2964 // DQ (11/23/2011): This change allows this to compile for where SgTemplateFunctionDeclarations are used. I have
2965 // not decided if template declarations should cause symbols to be generated for functions and member functions.
2966 // func_symbol = new SgMemberFunctionSymbol(func);
2967 if (isSgTemplateMemberFunctionDeclaration(func) != NULL)
2968 func_symbol = new SgTemplateMemberFunctionSymbol(isSgTemplateMemberFunctionDeclaration(func));
2969 else
2970 {
2971 SgMemberFunctionDeclaration* memberFunctionDeclaration = isSgMemberFunctionDeclaration(func);
2972 ROSE_ASSERT(memberFunctionDeclaration != NULL);
2973 func_symbol = new SgMemberFunctionSymbol(memberFunctionDeclaration);
2974 }
2975
2976 ROSE_ASSERT(func_symbol != NULL);
2977 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
2978 }
2979 else
2980 {
2981 // if (isSgFunctionDeclaration(func))
2982 if (isSgTemplateFunctionDeclaration(func))
2983 {
2984 // How should we handled template functions in the symbol table???
2985 // DQ (11/24/2011): After some thought, I think that template declarations for function are more template declarations
2986 // than functions. So all template function declarations will be handled as SgTemplateSymbols and not SgFunctionSymbols.mplate function declarations.
2987 SgTemplateFunctionDeclaration* templatedeclaration = isSgTemplateFunctionDeclaration(func);
2988 ROSE_ASSERT(templatedeclaration != NULL);
2989 SgTemplateFunctionSymbol* template_symbol = new SgTemplateFunctionSymbol(templatedeclaration);
2990 ROSE_ASSERT(template_symbol != NULL);
2991 ROSE_ASSERT(template_symbol->get_symbol_basis() != NULL);
2992 func_symbol = template_symbol;
2993 }
2994 else
2995 {
2996 func_symbol = new SgFunctionSymbol(isSgFunctionDeclaration(func));
2997 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
2998 }
2999 }
3000
3001 ROSE_ASSERT(func_symbol != NULL);
3002 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
3003 scope->insert_symbol(nameWithTemplateArguments, func_symbol);
3004
3005 // DQ (3/8/2012): Added assertion.
3006 ROSE_ASSERT(func->get_symbol_from_symbol_table() != NULL);
3007
3008 if (isSgFunctionDeclaration(func) == NULL)
3009 {
3010 // DQ (12/18/2011): If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3011 // DQ (8/12/2013): Added template parameter list.
3012 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3013 // In this case these are unavailable from this point.
3014 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3015 }
3016
3017 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3018 // In this case these are unavailable from this point.
3019 // DQ (11/25/2011): Added support for template functions.
3020 // DQ (2/26/2009): uncommented assertion.
3021 // Did not pass for member function? Should we have used the mangled name?
3022 ROSE_ASSERT(buildTemplateDeclaration == false || templateParameterList != NULL);
3023
3024 // DQ (8/13/2013): We need to test for function symbols (which will include member function symbols),
3025 // template functions and template member functions. Each must be tested for seperately because template
3026 // functions and template member functions are not connected to derivation which non-template functions
3027 // and non-template member functions are connected through derivation.
3028 ROSE_ASSERT(scope->lookup_function_symbol(nameWithTemplateArguments) != NULL ||
3029 scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL ||
3030 scope->lookup_template_member_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3031
3032#if BUILDER_MAKE_REDUNDANT_CALLS_TO_SYMBOL_TABLE_LOOKUP
3033 // if (scope->lookup_function_symbol(name) == NULL || scope->lookup_template_symbol(name) != NULL)
3034 // if (scope->lookup_function_symbol(nameWithTemplateArguments) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments) != NULL)
3035 // if (scope->lookup_function_symbol(nameWithTemplateArguments) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments,NULL,NULL) != NULL)
3036 if (scope->lookup_function_symbol(nameWithTemplateArguments,templateArgumentList) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments,templateParameterList,NULL) != NULL)
3037 {
3038 // Make sure this is a template function declaration...
3039 printf ("Need to make sure this is a template function declaration... \n");
3040 }
3041#endif
3042 }
3043
3044 // DQ (12/14/2011): Added test.
3045 ROSE_ASSERT(func->get_scope() != NULL);
3046
3047 if (isSgFunctionDeclaration(func) == NULL)
3048 {
3049 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3050
3051 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3052 // In this case these are unavailable from this point.
3053 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3054 }
3055 func->set_firstNondefiningDeclaration(func);
3056 func->set_definingDeclaration(NULL);
3057
3058 // DQ (5/8/2016): We need to test the first defining declaration that we used.
3059 ROSE_ASSERT(func->get_firstNondefiningDeclaration() == func);
3060
3061 ROSE_ASSERT(func->get_definingDeclaration() == NULL);
3062
3063 // DQ (12/14/2011): Error checking
3064 SgTemplateInstantiationMemberFunctionDecl* testMemberDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
3065 if (testMemberDecl != NULL)
3066 {
3067 ROSE_ASSERT(testMemberDecl->get_scope() != NULL);
3068 ROSE_ASSERT(testMemberDecl->get_class_scope() != NULL);
3069 ROSE_ASSERT(testMemberDecl->get_associatedClassDeclaration() != NULL);
3070 }
3071 }
3072 else
3073 {
3074 ROSE_ASSERT(func_symbol != NULL);
3075
3076 ROSE_ASSERT(scope != NULL);
3077
3078 // 2nd, or 3rd... prototype declaration
3079 // reuse function type, function symbol of previous declaration
3080
3081 // std::cout<<"debug:SageBuilder.C: 267: "<<"found func_symbol!"<<std::endl;
3082 // delete (func_type-> get_argument_list ());
3083 // delete func_type; // bug 189
3084 SgNode* associatedSymbolBasis = func_symbol->get_symbol_basis();
3085 ROSE_ASSERT(associatedSymbolBasis != NULL);
3086
3087 SgDeclarationStatement* associatedDeclaration = isSgDeclarationStatement(associatedSymbolBasis);
3088 ROSE_ASSERT(associatedDeclaration != NULL);
3089 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(associatedDeclaration);
3090 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(associatedDeclaration);
3091
3092 if (functionDeclaration != NULL)
3093 {
3094 func_type = functionDeclaration->get_type();
3095 }
3096 else
3097 {
3098 if (templateFunctionDeclaration != NULL)
3099 {
3100 // DQ (5/8/2016): I think this code is never executed (because a templateFunctionDeclaration
3101 // is derived from a SgFunctionDeclaration, in the newer design (a few years ago)).
3102
3103 printf ("This code should not be reachable! \n");
3104 ROSE_ABORT();
3105
3106 func_type = templateFunctionDeclaration->get_type();
3107 }
3108 else
3109 {
3110 printf ("Error: associatedDeclaration = %p = %s \n",associatedDeclaration,associatedDeclaration->class_name().c_str());
3111 ROSE_ABORT();
3112 }
3113 }
3114 ROSE_ASSERT(func_type != NULL);
3115
3116 func = new actualFunction(nameWithTemplateArguments,func_type,NULL);
3117 ROSE_ASSERT(func != NULL);
3118
3119#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3120 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as translformations.
3121 // This is too early a point to test since the source position has not been set for func yet.
3122 // detectTransformations_local(func);
3123#endif
3124
3125 // DQ (12/14/2011): Moved this up from below.
3126 func->set_scope(scope);
3127
3128 // DQ (3/8/2012): Added assertion.
3129 ROSE_ASSERT(func->get_symbol_from_symbol_table() == NULL);
3130
3131 // DQ (12/15/2011): Added test.
3132 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(func,scope);
3133
3134 // we don't care if it is member function or function here for a pointer
3135 SgDeclarationStatement* prevDecl = NULL;
3136
3137 // This does not handle the case of a template function declaration.
3138 if (functionDeclaration != NULL)
3139 {
3140 prevDecl = functionDeclaration;
3141 }
3142 else
3143 {
3144 ROSE_ASSERT(templateFunctionDeclaration != NULL);
3145 prevDecl = templateFunctionDeclaration;
3146 }
3147
3148 ROSE_ASSERT(prevDecl != NULL);
3149
3150 SgFunctionSymbol *function_symbol = isSgFunctionSymbol(func_symbol);
3151 if (prevDecl == prevDecl->get_definingDeclaration())
3152 {
3153 // The symbol points to a defining declaration and now that we have added a non-defining
3154 // declaration we should have the symbol point to the new non-defining declaration.
3155 printf ("WARNING: Switching declaration in functionSymbol to point to the non-defining declaration \n");
3156 function_symbol->set_declaration(isSgFunctionDeclaration(func));
3157 ROSE_ASSERT(function_symbol->get_declaration() != NULL);
3158 }
3159
3160 // If this is the first non-defining declaration then set the associated data member.
3161 SgDeclarationStatement* nondefiningDeclaration = prevDecl->get_firstNondefiningDeclaration();
3162 if (nondefiningDeclaration == NULL)
3163 {
3164 nondefiningDeclaration = func;
3165 }
3166
3167 ROSE_ASSERT(nondefiningDeclaration != NULL);
3168 ROSE_ASSERT(func != NULL);
3169 ROSE_ASSERT(prevDecl != NULL);
3170
3171 func->set_firstNondefiningDeclaration(nondefiningDeclaration);
3172 func->set_definingDeclaration(prevDecl->get_definingDeclaration());
3173
3174 ROSE_ASSERT(nondefiningDeclaration->get_symbol_from_symbol_table() != NULL);
3175 ROSE_ASSERT(func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3176
3177 // DQ (3/8/2012): If this is the redundant function prototype then we have to look
3178 // at the first defining declaration since only it will have an associated symbol.
3179 if (func->get_symbol_from_symbol_table() == NULL)
3180 {
3181 ROSE_ASSERT(nondefiningDeclaration != NULL);
3182 ROSE_ASSERT(func->get_firstNondefiningDeclaration() == nondefiningDeclaration);
3183 }
3184
3185 // DQ (12/14/2011): Added test.
3186 ROSE_ASSERT(scope != NULL);
3187 ROSE_ASSERT(func->get_scope() != NULL);
3188 ROSE_ASSERT(func->get_scope() == scope);
3189
3190 // DQ (12/14/2011): Error checking
3191 SgTemplateInstantiationMemberFunctionDecl* testMemberDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
3192 if (testMemberDecl != NULL)
3193 {
3194 ROSE_ASSERT(testMemberDecl->get_scope() != NULL);
3195 ROSE_ASSERT(testMemberDecl->get_associatedClassDeclaration() != NULL);
3196 }
3197
3198 // DQ (12/18/2011): Testing to debug generation of wrong kind of declaration (symbol not found in correct scope or ...).
3199 if (isSgFunctionDeclaration(func) == NULL)
3200 {
3201 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3202 // DQ (8/12/2013): Added template parameter list.
3203 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3204 // In this case these are unavailable from this point.
3205 // DQ (12/18/2011): This fails because the first use of the function causes a non-defining function declaration
3206 // to be built and it is built as a template instantiation instead of a template declaration. So the symbol for
3207 // the non-defining declaration is put into the correct scope, but as a SgMemberFunctionSymbol instead of as a
3208 // SgTemplateSymbol (if it were built as a SgTemplateMemberFunctionDeclaration). So of course we can't find it
3209 // using lookup_template_symbol().
3210 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3211 }
3212 }
3213
3214 ROSE_ASSERT(func != NULL);
3215
3216 ROSE_ASSERT(func->get_file_info() == NULL);
3217
3218 // DQ (3/8/2012): Added assertion.
3219 ROSE_ASSERT(func->get_firstNondefiningDeclaration() != NULL);
3220 ROSE_ASSERT(func_symbol != NULL);
3221 ROSE_ASSERT(func_symbol->get_symbol_basis() == func->get_firstNondefiningDeclaration());
3222 ROSE_ASSERT(func->get_symbol_from_symbol_table() != NULL || func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3223
3224 // DQ (2/24/2009): Delete the old parameter list build by the actualFunction (template argument) constructor.
3225 ROSE_ASSERT(func->get_parameterList() != NULL);
3226 delete func->get_parameterList();
3227 func->set_parameterList(NULL);
3228
3229 // DQ (9/16/2012): Setup up the template arguments and the parents of the template arguments.
3230 if (buildTemplateInstantiation == true)
3231 {
3232 setTemplateArgumentsInDeclaration(func,templateArgumentsList);
3233 }
3234
3235 // DQ (8/10/2013): Setup the template parameters if this is a template declaration.
3236 if (buildTemplateDeclaration == true)
3237 {
3238 setTemplateParametersInDeclaration(func,templateParameterList);
3239
3240 // DQ (8/13/2013): Adding test of template parameter lists.
3241 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(func);
3242 ROSE_ASSERT(templateFunctionDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateFunctionDeclaration->get_templateParameters().size()));
3243
3244 SgTemplateMemberFunctionDeclaration* templateMemberFunctionDeclaration = isSgTemplateMemberFunctionDeclaration(func);
3245 ROSE_ASSERT(templateMemberFunctionDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateMemberFunctionDeclaration->get_templateParameters().size()));
3246 }
3247
3248 // parameter list
3249 // DQ (11/23/2011): This change allows this to compile for where SgTemplateFunctionDeclarations are used.
3250 setParameterList(func, paralist);
3251
3252 for (SgInitializedName* i_name : paralist->get_args())
3253 {
3254 i_name->set_scope(scope);
3255 }
3256
3257#if 0
3258 // DQ (7/12/2021): Debugging where nodes in the outliner are being marked as transformations (SgCastExpressions should not be marked as transformations).
3259 printf ("In buildNondefiningFunctionDeclaration_T(): setting the source position information (calling setTransformation()) \n");
3260#endif
3261
3262 // DQ (5/2/2012): Test this to make sure we have SgInitializedNames set properly.
3264
3265#if 0
3266 // DQ (7/12/2021): Debugging where nodes in the outliner are being marked as transformations (SgCastExpressions should not be marked as transformations).
3267 printf ("In buildNondefiningFunctionDeclaration_T(): DONE: setting the source position information (calling setTransformation()) \n");
3268#endif
3269
3270#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3271 // Liao 11/21/2012: we should assert no transformation only when the current model is NOT transformation
3272 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
3273 {
3274 detectTransformations_local(paralist);
3275 }
3276#endif
3277
3278 ASSERT_not_null(scope);
3279 ASSERT_not_null(func->get_scope());
3280 ASSERT_require(func->get_scope() == scope);
3281
3282 // DQ (1/5/2009): This is not always true (should likely use SageBuilder::topScopeStack() instead)
3283 if (SageBuilder::topScopeStack() != nullptr) // This comparison only makes sense when topScopeStack() returns non-NULL value
3284 {
3285 // since stack scope is totally optional in SageBuilder.
3286 if (scope != SageBuilder::topScopeStack())
3287 {
3288#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
3289 printf ("Warning: SageBuilder::buildNondefiningFunctionDeclaration_T(): scope parameter may not be the same as the topScopeStack() (e.g. for member functions) \n");
3290#endif
3291 }
3292 }
3293
3294 func->set_parent(scope);
3295 ASSERT_not_null(func->get_firstNondefiningDeclaration());
3296
3297 // mark as a forward declartion
3298 func->setForward();
3299
3300 ROSE_ASSERT(func->get_file_info() == NULL);
3301
3302 // set File_Info as transformation generated or front end generated
3304
3305 ROSE_ASSERT(func->get_file_info() != NULL);
3306
3307#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3308 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3309 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
3310 {
3311 detectTransformations_local(func);
3312 }
3313#endif
3314
3315 // printf ("In SageBuilder::buildNondefiningFunctionDeclaration_T(): generated function func = %p \n",func);
3316
3317 // Liao 12/2/2010, special handling for Fortran functions and subroutines
3318 if ((SageInterface::is_Fortran_language() == true) && (getEnclosingFileNode(scope)->get_outputLanguage() == SgFile::e_Fortran_language))
3319 {
3320 SgProcedureHeaderStatement * f_func = isSgProcedureHeaderStatement(func);
3321 ROSE_ASSERT (f_func != NULL);
3322 if (return_type == buildVoidType())
3324 else
3325 f_func->set_subprogram_kind(SgProcedureHeaderStatement::e_function_subprogram_kind);
3326
3327 // hide it from the unparser since fortran prototype func declaration is internally used by ROSE AST
3330 ROSE_ASSERT(f_func->get_startOfConstruct()->isOutputInCodeGeneration() == false);
3331 ROSE_ASSERT(f_func->get_endOfConstruct()->isOutputInCodeGeneration() == false);
3332 }
3333
3334 // DQ (12/11/2011): Added new test.
3335 ROSE_ASSERT(func->get_firstNondefiningDeclaration() != NULL);
3336 SgSymbol* symbol_from_first_nondefining_function = func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table();
3337 ROSE_ASSERT(symbol_from_first_nondefining_function != NULL);
3338
3339 // DQ (12/11/2011): Note that this may be false when func is not the first nondefining declaration.
3340 if (func != func->get_firstNondefiningDeclaration())
3341 {
3342 SgSymbol* symbol_from_nondefining_function = func->get_symbol_from_symbol_table();
3343 ROSE_ASSERT(symbol_from_nondefining_function == NULL);
3344 }
3345
3346 // DQ (12/18/2011): Testing to debug generation of wrong kind of declaration (symbol not found in correct scope or ...).
3347 if (isSgFunctionDeclaration(func) == NULL)
3348 {
3349 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3350 // DQ (8/12/2013): Make sure we use the template parameters and the template arguments that are available.
3351 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3352 // In this case these are unavailable from this point.
3353 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3354 }
3355
3356 // 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)).
3357 setTemplateNameInTemplateInstantiations(func,nameWithoutTemplateArguments);
3358
3359#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3360 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3361 if (SourcePositionClassificationMode !=e_sourcePositionTransformation)
3362 {
3363 detectTransformations_local(func);
3364 }
3365#endif
3366
3367 // DQ (12/11/2012): Force the two different ways that this can be set to match (we want consistancy).
3368 if (functionConstVolatileFlags & SgMemberFunctionType::e_restrict)
3369 {
3370 func->get_declarationModifier().get_typeModifier().setRestrict();
3371 }
3372
3373 // DQ (8/19/2013): Added assertion that is tested and which fails for test_3 of the RoseExample_tests directory (in edgRose.C).
3374 // This fails for everything.... not sure why...
3375
3376 // DQ (4/16/2015): This is replaced with a better implementation.
3377 // Make sure the isModified boolean is clear for all newly-parsed nodes.
3378 unsetNodesMarkedAsModified(func);
3379
3380 ROSE_ASSERT(paralist->get_parent() != NULL);
3381 return func;
3382 }
3383
3384
3388{
3389 ROSE_ASSERT(funcdecl!=NULL);
3390 SgName name=funcdecl->get_name();
3391 SgFunctionType * funcType = funcdecl->get_type();
3392 SgType* return_type = funcType->get_return_type();
3393 SgFunctionParameterList* paralist = deepCopy<SgFunctionParameterList>(funcdecl->get_parameterList());
3394
3395 // make sure the function has consistent function type based on its return type and parameter list
3396 SgFunctionType * ref_funcType= findFunctionType (return_type, funcType->get_argument_list());
3397 ROSE_ASSERT(funcType== ref_funcType);
3398
3399 // buildNondefiningFunctionDeclaration() will check if a same function is created before by looking up function symbols.
3400 SgFunctionDeclaration* returnFunction = buildNondefiningFunctionDeclaration (name, return_type, paralist, scope, decoratorList, false, NULL);
3401
3402 returnFunction->set_linkage(funcdecl->get_linkage());
3403 if (funcdecl->get_declarationModifier().get_storageModifier().isExtern() == true)
3404 {
3405 returnFunction->get_declarationModifier().get_storageModifier().setExtern();
3406 }
3407
3408 ROSE_ASSERT (returnFunction->get_linkage() == funcdecl->get_linkage());
3409 ROSE_ASSERT (returnFunction->get_declarationModifier().get_storageModifier().isExtern() ==
3410 funcdecl->get_declarationModifier().get_storageModifier().isExtern());
3411
3412 ROSE_ASSERT(returnFunction->get_firstNondefiningDeclaration() != NULL);
3413 // Make sure that internal references are to the same file (else the symbol table information will not be consistent).
3414 if (scope != NULL)
3415 {
3416 ROSE_ASSERT(returnFunction->get_firstNondefiningDeclaration() != NULL);
3417 }
3418
3419 return returnFunction;
3420}
3421
3423SageBuilder::buildNondefiningFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList, SgStorageModifier::storage_modifier_enum sm)
3424 {
3425 SgFunctionDeclaration * result = NULL;
3426 if ((SageInterface::is_Fortran_language() == true) && (getEnclosingFileNode(scope)->get_outputLanguage() == SgFile::e_Fortran_language))
3427 {
3428 result = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, NULL, sm);
3429 }
3430 else
3431 {
3432 // 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).
3433 if (buildTemplateInstantiation == true)
3434 {
3435 result = buildNondefiningFunctionDeclaration_T <SgTemplateInstantiationFunctionDecl> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, templateArgumentsList, NULL, sm);
3436 }
3437 else
3438 {
3439 result = buildNondefiningFunctionDeclaration_T <SgFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, NULL, sm);
3440 }
3441 }
3442
3443 return result;
3444 }
3445
3446
3447// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficent).
3448// We need to decide if the SageBuilder API should include these sorts of functions.
3451 {
3452 unsigned int memberFunctionModifiers = 0;
3453 return buildNondefiningMemberFunctionDeclaration (name,return_type,paralist,scope,NULL,memberFunctionModifiers,false,NULL);
3454 }
3455
3456// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficient).
3457// We need to decide if the SageBuilder API should include these sorts of functions.
3460 {
3461 if (scope == NULL)
3462 {
3464 }
3465
3466 unsigned int memberFunctionModifiers = 0;
3468 SgMemberFunctionDeclaration* nondefining_decl = NULL;
3469 SgMemberFunctionType* member_func_type = buildMemberFunctionType(return_type,param_type_list, scope, memberFunctionModifiers);
3470 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgMemberFunctionDeclaration>(name,member_func_type,NULL,NULL);
3471 SgMemberFunctionSymbol* member_func_symbol = isSgMemberFunctionSymbol(func_symbol);
3472
3473 if (member_func_symbol != NULL)
3474 {
3475 nondefining_decl = member_func_symbol->get_declaration();
3476 }
3477 else
3478 {
3479 // each defining member function decl must have a non-defining counter part now. 11/27/2012, Liao
3480 nondefining_decl = buildNondefiningMemberFunctionDeclaration (name, return_type, paralist, scope,NULL, memberFunctionModifiers, false, NULL);
3481 }
3482 return buildDefiningMemberFunctionDeclaration (name,return_type,paralist,scope,NULL,false,memberFunctionModifiers,nondefining_decl,NULL);
3483 }
3484
3485
3486// SgTemplateFunctionDeclaration* SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList)
3487// SgTemplateFunctionDeclaration* SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateArgumentPtrList* templateArgumentsList)
3489SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateParameterPtrList* templateParameterList)
3490 {
3491 // DQ (8/15/2013): Note that we don't need template arguments because teplate functions can't support partial specialization.
3492
3493 // DQ (11/25/2011): Adding support for template declarations in the AST.
3494
3495 // DQ (8/7/2013): Added support for template function overloading using template parameters.
3496 SgTemplateFunctionDeclaration* result = buildNondefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, templateParameterList, SgStorageModifier::e_default);
3497
3498 // DQ (12/12/2011): Added test.
3499 ROSE_ASSERT(result != NULL);
3500 if (result->get_symbol_from_symbol_table() == NULL)
3501 {
3502 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3503 ROSE_ASSERT(result != result->get_firstNondefiningDeclaration());
3504 ROSE_ASSERT(result->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3505 }
3506
3507 // DQ (2/12/2015): Added assertions earlier before calling buildDefiningFunctionDeclaration_T<>().
3508 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3509
3510 return result;
3511 }
3512
3514SageBuilder::buildDefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateFunctionDeclaration* first_nondefining_declaration)
3515 {
3516 // DQ (12/1/2011): Adding support for template declarations in the AST.
3517
3518 // DQ (7/31/2013): Added assertions earlier before calling buildDefiningFunctionDeclaration_T<>().
3519 ROSE_ASSERT(first_nondefining_declaration != NULL);
3520 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() != NULL);
3521 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3522
3523 // template <class actualFunction> actualFunction * buildDefiningFunctionDeclaration_T (const SgName & name, SgType* return_type, SgFunctionParameterList * parlist, SgScopeStatement* scope=NULL, SgExprListExp* decoratorList = NULL);
3524 // SgTemplateFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ false, scope, decoratorList,functionConstVolatileFlags);
3525 // SgTemplateFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ false, scope, decoratorList, 0, first_nondefining_declaration);
3526 SgTemplateFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ false, scope, decoratorList, 0, first_nondefining_declaration, NULL);
3527
3528 return result;
3529 }
3530
3532SageBuilder::buildDefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList *paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, SgTemplateMemberFunctionDeclaration* first_nondefining_declaration)
3533 {
3534 // DQ (12/1/2011): Adding support for template declarations in the AST.
3535
3536 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3537
3538 SgTemplateMemberFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true, scope, decoratorList, functionConstVolatileFlags, first_nondefining_declaration, NULL);
3539 ROSE_ASSERT(result != NULL);
3540
3541 ROSE_ASSERT(result->get_definition() != NULL);
3542
3543 return result;
3544 }
3545
3548 SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList)
3549 {
3550 // This function builds either a SgMemberFunctionDeclaration (non-template; normal member function) or a SgTemplateInstantiationMemberFunctionDecl (template instantiation).
3551
3552 // DQ (11/27/2011): Added support for instations of template member functions.
3553 SgMemberFunctionDeclaration * result = NULL;
3554
3555 if (buildTemplateInstantiation == true)
3556 {
3557 // This is how we build an instantiation of a template (SgTemplateInstantiationMemberFunctionDecl).
3558 result = buildNondefiningFunctionDeclaration_T <SgTemplateInstantiationMemberFunctionDecl> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,templateArgumentsList,NULL, SgStorageModifier::e_default);
3559 }
3560 else
3561 {
3562 // This is a non-template instatiation (normal member function).
3563 result = buildNondefiningFunctionDeclaration_T <SgMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,NULL,NULL, SgStorageModifier::e_default);
3564 }
3565 ROSE_ASSERT(result != NULL);
3566
3567 // set definingdecl for SgCtorInitializerList
3569 ROSE_ASSERT(ctor != NULL);
3570
3571 // required in AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3572 ctor->set_definingDeclaration(ctor);
3574
3575 // DQ (1/4/2009): Error checking
3576 ROSE_ASSERT(result->get_associatedClassDeclaration() != NULL);
3577
3578 if (result->get_associatedClassDeclaration() == NULL)
3579 {
3580 printf ("Warning, must set the SgMemberFunctionDeclaration::associatedClassDeclaration \n");
3581
3582 ROSE_ASSERT(scope != NULL);
3583 SgClassDefinition* classDefinition = isSgClassDefinition(scope);
3584 ROSE_ASSERT(classDefinition != NULL);
3585 SgDeclarationStatement* associatedDeclaration = classDefinition->get_declaration();
3586 ROSE_ASSERT(associatedDeclaration != NULL);
3587 SgClassDeclaration* associatedClassDeclaration = isSgClassDeclaration(associatedDeclaration);
3588
3589 // DQ (1/4/2009): This needs to be set, checked in AstConsistencyTests.C!
3590 result->set_associatedClassDeclaration(associatedClassDeclaration);
3591 }
3592
3593 return result;
3594 }
3595
3596
3597// DQ (8/12/2013): This function needs to handle the SgTemplateParameterPtrList (since it is generating a template).
3598// It need not take a SgTemplateArgumentPtrList because template functions (including template member functions) can not support partial specialization.
3599// SgTemplateMemberFunctionDeclaration* SageBuilder::buildNondefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags)
3601SageBuilder::buildNondefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, SgTemplateParameterPtrList* templateParameterList)
3602 {
3603 // This function only builds template member function declarations.
3604
3605 SgTemplateMemberFunctionDeclaration * result = buildNondefiningFunctionDeclaration_T <SgTemplateMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,NULL,templateParameterList, SgStorageModifier::e_default);
3606
3607 // set definingdecl for SgCtorInitializerList
3608 ROSE_ASSERT(result != NULL);
3609
3610#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3611 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as translformations.
3613 {
3614 detectTransformations_local(result);
3615 }
3616#endif
3617
3618 // DQ (8/12/2013): Added template paremter list to call to get the function template symbol.
3619 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3620 // In this case these are unavailable from this point.
3621 SgSymbol* associatedSymbol = scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList);
3622 if (associatedSymbol == NULL)
3623 {
3624 printf ("ERROR: associatedSymbol == NULL \n");
3625 printf (" --- result = %p = %s \n",result,result->class_name().c_str());
3626 printf (" --- scope = %p = %s \n",scope,scope->class_name().c_str());
3627 printf (" --- name = %s \n",name.str());
3628 printf (" --- result->get_type() = %p = %s \n",result->get_type(),result->get_type()->class_name().c_str());
3629 printf (" --- result->get_type()->get_mangled() = %s \n",result->get_type()->get_mangled().str());
3630 }
3631 ROSE_ASSERT(associatedSymbol != NULL);
3632
3634 ROSE_ASSERT(ctor != NULL);
3635 // required ty AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3636 ctor->set_definingDeclaration(ctor);
3638
3639 // DQ (12/11/2011): Added new test (also at the base of buildNondefiningFunctionDeclaration_T<>() function).
3640 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3641 SgSymbol* symbol_from_first_nondefining_function = result->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table();
3642 ROSE_ASSERT(symbol_from_first_nondefining_function != NULL);
3643
3644 // DQ (12/11/2011): Note that this may be false when func is not the first nondefining declaration.
3645 if (result != result->get_firstNondefiningDeclaration())
3646 {
3647 SgSymbol* symbol_from_nondefining_function = result->get_symbol_from_symbol_table();
3648 ROSE_ASSERT(symbol_from_nondefining_function == NULL);
3649 }
3650
3651#if BUILDER_MAKE_REDUNDANT_CALLS_TO_SYMBOL_TABLE_LOOKUP
3652 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3653 // In this case these are unavailable from this point.
3654 if (scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList) == NULL)
3655 {
3656 printf ("Error: scope->lookup_template_member_function_symbol(name,result->get_type()) == NULL (investigate this) \n");
3657 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());
3658 scope->get_symbol_table()->print("Error: scope->lookup_template_member_function_symbol(name,result->get_type()) == NULL (investigate this)");
3659 }
3660#endif
3661 ROSE_ASSERT(scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList) != NULL);
3662
3663#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3664 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3666 {
3667 detectTransformations_local(result);
3668 }
3669#endif
3670
3671 return result;
3672 }
3673
3675SageBuilder::buildDefiningMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, unsigned int functionConstVolatileFlags, SgMemberFunctionDeclaration* first_nondefining_declaration, SgTemplateArgumentPtrList* templateArgumentsList)
3676 {
3677 // DQ (12/18/2011): Need to build a SgTemplateInstantiationMemberFunctionDecl when buildTemplateInstantiation == true
3678 SgMemberFunctionDeclaration * result = NULL;
3679 if (buildTemplateInstantiation == true)
3680 {
3681 SgTemplateInstantiationMemberFunctionDecl* templateInstantiationMemberFunctionDecl = isSgTemplateInstantiationMemberFunctionDecl(first_nondefining_declaration);
3682 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
3683
3684 // DQ (1/26/2013): Added test failing in buildDefiningFunctionDeclaration_T().
3685 {
3686 ROSE_ASSERT(templateArgumentsList != NULL);
3687 string nameWithoutTemplateArguments = name;
3688 string nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
3689 SgMemberFunctionType* func_type = isSgMemberFunctionType(first_nondefining_declaration->get_type());
3690 ROSE_ASSERT(func_type != NULL);
3691
3692 // DQ (8/7/2013): API change due to added support for template function overloading using template parameters.
3693 SgSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgTemplateInstantiationMemberFunctionDecl>(nameWithTemplateArguments,func_type,NULL,templateArgumentsList);
3694 if (func_symbol == NULL)
3695 {
3696 printf ("ERROR caught in SageBuilder::buildDefiningMemberFunctionDeclaration(): nameWithTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithTemplateArguments.c_str(),buildTemplateInstantiation ? "true:" : "false");
3697 printf ("ERROR caught in SageBuilder::buildDefiningMemberFunctionDeclaration(): func_symbol == NULL for first_nondefining_declaration = %p = %s and func_type = %p = %s \n",
3698 templateInstantiationMemberFunctionDecl,templateInstantiationMemberFunctionDecl->class_name().c_str(),func_type,func_type->class_name().c_str());
3699 }
3700 }
3701
3702 result = buildDefiningFunctionDeclaration_T <SgTemplateInstantiationMemberFunctionDecl> (name, return_type, paralist, /* isMemberFunction = */ true, scope, decoratorList, functionConstVolatileFlags, templateInstantiationMemberFunctionDecl, templateArgumentsList);
3703 ROSE_ASSERT(isSgTemplateInstantiationMemberFunctionDecl(result) != NULL);
3704 ROSE_ASSERT(isSgTemplateInstantiationMemberFunctionDecl(result)->get_templateName().is_null() == false);
3705 }
3706 else
3707 {
3708 ROSE_ASSERT(first_nondefining_declaration != NULL);
3709
3710 // DQ (12/27/20134): Added these to permit testing earlier than in the buildDefiningFunctionDeclaration_T() function.
3711 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() != NULL);
3712 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3713
3714 result = buildDefiningFunctionDeclaration_T <SgMemberFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,first_nondefining_declaration, NULL);
3715 }
3716
3717 ROSE_ASSERT(result != NULL);
3718
3719 // set definingdecl for SgCtorInitializerList
3721 ROSE_ASSERT(ctor != NULL);
3722
3723 // required ty AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3724 ctor->set_definingDeclaration(ctor);
3726
3727 // DQ (1/4/2009): Error checking
3728 ROSE_ASSERT(result->get_associatedClassDeclaration() != NULL);
3729
3730 return result;
3731 }
3732
3733
3734//----------------- defining function declaration------------
3735// a template builder for all kinds of defining SgFunctionDeclaration
3736// handle common chores for function type, symbol, paramter etc.
3737
3738template <class actualFunction>
3739actualFunction*
3740SageBuilder::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)
3741 {
3742 // Note that the semantics of this function now differs from that of the buildDefiningClassDeclaration().
3743 // We want to have the non-defining declaration already exist before calling this function.
3744 // We could still build a higher level function that built both together. Or we could provide two versions
3745 // named differently (from this one) and depricate this function...which I like much better.
3746
3747#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
3748 printf ("WARNING: This function for building defining function declarations has different semantics from that of the function to build defining class declarations. \n");
3749#endif
3750
3751 ASSERT_not_null(first_nondefining_declaration);
3752 ASSERT_require(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3753
3754 if (scope == nullptr)
3755 {
3757 }
3758
3759 ASSERT_require(XXX_name.is_null() == false);
3760 ASSERT_not_null(scope);
3761 ASSERT_not_null(return_type);
3762
3763 SgName nameWithoutTemplateArguments = XXX_name;
3764 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
3765
3766 bool buildTemplateInstantiation = ((VariantT)actualFunction::static_variant == V_SgTemplateInstantiationFunctionDecl || (VariantT)actualFunction::static_variant == V_SgTemplateInstantiationMemberFunctionDecl);
3767
3768 // DQ (8/7/2013): Added support for template declarations.
3769 bool buildTemplateDeclaration = ((VariantT)actualFunction::static_variant == V_SgTemplateFunctionDeclaration || (VariantT)actualFunction::static_variant == V_SgTemplateMemberFunctionDeclaration);
3770
3771 // DQ (8/11/2013): Check that the template argument lists are consistant. The templateArgumentsList can then be considered redundant if this works.
3772 if (buildTemplateInstantiation == true)
3773 {
3774 ASSERT_not_null(templateArgumentsList);
3775
3776 SgTemplateArgumentPtrList & templateArgumentsList_from_first_nondefining_declaration = (isMemberFunction == false) ?
3777 isSgTemplateInstantiationFunctionDecl(first_nondefining_declaration)->get_templateArguments() :
3778 isSgTemplateInstantiationMemberFunctionDecl(first_nondefining_declaration)->get_templateArguments();
3779
3780 ASSERT_not_null(templateArgumentsList);
3781 bool templateArgumentListsAreEquivalent = SageInterface::templateArgumentListEquivalence(*templateArgumentsList, templateArgumentsList_from_first_nondefining_declaration);
3782 ASSERT_require(templateArgumentListsAreEquivalent == true);
3783 }
3784
3785 SgTemplateParameterPtrList* templateParameterList = nullptr;
3786 if (buildTemplateDeclaration == true)
3787 {
3788 // 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.
3789 templateParameterList = (isMemberFunction == false) ?
3790 &(isSgTemplateFunctionDeclaration(first_nondefining_declaration)->get_templateParameters()) :
3791 &(isSgTemplateMemberFunctionDeclaration(first_nondefining_declaration)->get_templateParameters());
3792
3793 ASSERT_require(templateArgumentsList == nullptr);
3794 ASSERT_not_null(templateParameterList);
3795 }
3796
3797 if (buildTemplateInstantiation == true)
3798 {
3799 ASSERT_not_null(templateArgumentsList);
3800 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
3801
3802 if (nameWithTemplateArguments == "insert < __normal_iterator< SgInitializedName ** , __type > > ")
3803 {
3804 printf ("In buildDefiningFunctionDeclaration_T(): Found function nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
3805 }
3806 }
3807
3808 ASSERT_require(nameWithoutTemplateArguments.is_null() == false);
3809 ASSERT_require(nameWithTemplateArguments.is_null() == false);
3810 ASSERT_not_null(paralist);
3811
3813 {
3814 ASSERT_require(scope->containsOnlyDeclarations());
3815 }
3816
3817 // build function type, manage function type symbol internally
3818 actualFunction* defining_func = nullptr;
3819 SgFunctionType* func_type = nullptr;
3820
3821 // 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).
3822 // This is a special problem for templates because the function parameters will evaluate different for different builds of the same template.
3823 // This is a problem for test2012_74.C (and a dozen other test codes that make use of STL).
3824 ASSERT_not_null(first_nondefining_declaration);
3825
3826 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
3827 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
3828 // DQ (7/27/2012): There are reasons why this can fail: e.g. for functions with names such as:
3829 // "operator std::auto_ptr_ref<_Tp1>" which is a user defined conversion operator to one class from another.
3830
3831 // DQ (5/12/2012): Use the newly added parameter to get the exact SgFunctionType used to build the symbol.
3832 // This should make the template handling more robust since we were sometimes using types that had different
3833 // levels of template instantiation between the non-definng and defining function declarations and this
3834 // caused symbols build to support the non-defining declaration to not be found when we searched for them
3835 // using the function type built for the defining declaration. We want the function types for all defining
3836 // and non-defining declarations to be identical. This define also means that we don't have to build a
3837 // SgFunctionType just to look up a symbol in the symbol table (which was always silly). However, only
3838 // the defining function declaration can use the existing function type because it is required that a
3839 // non-defining declaration exist prior to the construction of the defining declaration (built by this
3840 // function).
3841 func_type = first_nondefining_declaration->get_type();
3842 ASSERT_not_null(func_type);
3843
3844 // Make sure these are the same (this will fail until we generate the func_type directly from first_nondefining_declaration).
3845 ASSERT_require(func_type == first_nondefining_declaration->get_type());
3846
3847 SgDeclarationStatement* firstNondefiningFunctionDeclaration = nullptr;
3848
3849 // symbol table and non-defining
3850 SgSymbol* func_symbol = scope->find_symbol_by_type_of_function<actualFunction>(nameWithTemplateArguments,func_type,templateParameterList,templateArgumentsList);
3851
3852 // DQ (1/26/2013): This fails for ROSE compiling ROSE.
3853 ASSERT_not_null(func_symbol);
3854
3855 if (func_symbol == nullptr)
3856 {
3857 // DQ (12/2/2011): After discussion with Liao, we think this should be an error.
3858 // The defining declaration requires that the associated non-defining declaration should already exist.
3859 // If required, a higher level build function could build both of these and connect them as required.
3860 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");
3861 ROSE_ABORT();
3862 }
3863 else
3864 {
3865 // We will now build a reference to the non-defining declaration found in the symbol.
3866
3867 // defining declaration after nondefining declaration
3868 // reuse function type, function symbol
3869
3870 // Cong (10/25/2010): Make sure in this situation there is no defining declaration for this symbol.
3871
3872 SgFunctionSymbol* temp_function_sym = isSgFunctionSymbol(func_symbol);
3873 SgTemplateSymbol* temp_template_sym = isSgTemplateSymbol(func_symbol);
3874 if (temp_function_sym != nullptr)
3875 {
3876 func_type = temp_function_sym->get_declaration()->get_type();
3877 firstNondefiningFunctionDeclaration = temp_function_sym->get_declaration()->get_firstNondefiningDeclaration();
3878 }
3879 else
3880 {
3881 // There is no type for a template function declaration.
3882 ASSERT_not_null(temp_template_sym);
3883 firstNondefiningFunctionDeclaration = temp_template_sym->get_declaration()->get_firstNondefiningDeclaration();
3884 }
3885 ASSERT_not_null(firstNondefiningFunctionDeclaration);
3886 }
3887
3888 defining_func = new actualFunction(nameWithTemplateArguments,func_type,nullptr);
3889 ASSERT_not_null(defining_func);
3890
3891 ASSERT_not_null(firstNondefiningFunctionDeclaration);
3892 defining_func->set_firstNondefiningDeclaration(firstNondefiningFunctionDeclaration);
3893
3894 // fix up defining declarations before current statement
3895 firstNondefiningFunctionDeclaration->set_definingDeclaration(defining_func);
3896
3897 // Handle decorators (Python specific)
3898 if (decoratorList != nullptr)
3899 {
3900 defining_func->set_decoratorList(decoratorList);
3901 decoratorList->set_parent(defining_func);
3902 }
3903
3904 // definingDeclaration
3905 defining_func->set_definingDeclaration(defining_func);
3906
3907 // function body and definition are created before setting argument list
3908 SgBasicBlock * func_body = new SgBasicBlock();
3909 ASSERT_not_null(func_body);
3910
3911 SgFunctionDefinition* func_def = nullptr;
3912 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(defining_func);
3913
3914 // Build either a definition for a template or non-template function definition.
3915 if (templateFunctionDeclaration == nullptr)
3916 {
3917 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(defining_func);
3918 ASSERT_not_null(functionDeclaration);
3919 func_def = new SgFunctionDefinition(functionDeclaration,func_body);
3920 }
3921 else
3922 {
3923 ASSERT_not_null(templateFunctionDeclaration);
3924 func_def = new SgTemplateFunctionDefinition(templateFunctionDeclaration,func_body);
3925 }
3926 ASSERT_not_null(func_def);
3927
3929 {
3930 func_def->setCaseInsensitive(true);
3931 func_body->setCaseInsensitive(true);
3932 }
3933
3934 func_def->set_parent(defining_func);
3935 func_def->set_body(func_body);
3936 func_body->set_parent(func_def);
3937
3938 // parameter list,
3939 // TODO consider the difference between C++ and Fortran
3940 setParameterList(defining_func,paralist);
3941 // fixup the scope and symbol of arguments,
3942 for (SgInitializedName* i_name : paralist->get_args())
3943 {
3944 i_name->set_scope(func_def);
3945
3946 SgVariableSymbol* variableSymbol = new SgVariableSymbol(i_name);
3947 ASSERT_not_null(variableSymbol);
3948 func_def->insert_symbol(i_name->get_name(), variableSymbol);
3949
3950 // For variable length array types in the function parameter list
3951 SgArrayType* arrayType = isSgArrayType(i_name->get_type());
3952 if (arrayType != nullptr)
3953 {
3954 // Check if this is a VLA array type, if so look for the index expressions and check
3955 // if we need to add asociated symbols to the current function definition scope.
3956 SgExpression* indexExpression = arrayType->get_index();
3957
3958 if (indexExpression != nullptr)
3959 {
3960 // DQ (2/14/2016): Handle the case of an expression tree with any number of variable references.
3961 // Get the list of SgVarRef IR nodes and process each one as above.
3962 vector<SgVarRefExp* > varRefList;
3963 collectVarRefs(indexExpression,varRefList);
3964
3965 for (size_t i = 0; i < varRefList.size(); i++)
3966 {
3967 // Process each index subtree's SgVarRefExp.
3968 SgVariableSymbol* dimension_variableSymbol = varRefList[i]->get_symbol();
3969 ASSERT_not_null(dimension_variableSymbol);
3970 ASSERT_require(dimension_variableSymbol != variableSymbol);
3971
3972 // The symbol from the referenced variable for the array dimension expression shuld already by in the function definition's symbol table.
3973 SgSymbol* symbolFromLookup = func_def->lookup_symbol(dimension_variableSymbol->get_name());
3974 if (symbolFromLookup != nullptr)
3975 {
3976 SgVariableSymbol* variableSymbolFromLookup = isSgVariableSymbol(symbolFromLookup);
3977 ASSERT_not_null(variableSymbolFromLookup);
3978
3979 varRefList[i]->set_symbol(variableSymbolFromLookup);
3980 ASSERT_require(dimension_variableSymbol != variableSymbol);
3981 }
3982 else
3983 {
3984 // 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.
3985 }
3986 }
3987 }
3988 }
3989 }
3990
3991 defining_func->set_parent(scope);
3992 defining_func->set_scope(scope);
3993
3994 ASSERT_not_null(defining_func->get_scope());
3995
3996 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(defining_func,scope);
3997
3998 // set File_Info as transformation generated
4000
4001 // Enforce that the return type matches the specification to build a member function.
4002 if (isMemberFunction == true)
4003 {
4004 ASSERT_not_null(isSgMemberFunctionDeclaration(defining_func));
4005 }
4006
4007 // 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)).
4008 setTemplateNameInTemplateInstantiations(defining_func,nameWithoutTemplateArguments);
4009
4010 // DQ (9/16/2012): Setup up the template arguments and the parents of the template arguments.
4011 if (buildTemplateInstantiation == true)
4012 {
4013 setTemplateArgumentsInDeclaration(defining_func,templateArgumentsList);
4014 }
4015
4016 // DQ (8/13/2013): Added code to set the template parameters in the defining declaration (if it is a template declaration).
4017 if (buildTemplateDeclaration == true)
4018 {
4019 setTemplateParametersInDeclaration(defining_func,templateParameterList);
4020
4021 // DQ (8/13/2013): Adding test of template parameter lists.
4022 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(defining_func);
4023 ROSE_ASSERT(templateFunctionDeclaration == nullptr || (templateParameterList != nullptr && templateParameterList->size() == templateFunctionDeclaration->get_templateParameters().size()));
4024 SgTemplateMemberFunctionDeclaration* templateMemberFunctionDeclaration = isSgTemplateMemberFunctionDeclaration(defining_func);
4025 ROSE_ASSERT(templateMemberFunctionDeclaration == nullptr || (templateParameterList != nullptr && templateParameterList->size() == templateMemberFunctionDeclaration->get_templateParameters().size()));
4026 }
4027
4028 // DQ (12/12/2012): Force the two different ways that this can be set to match (we want consistancy).
4029 if (functionConstVolatileFlags & SgMemberFunctionType::e_restrict)
4030 {
4031 defining_func->get_declarationModifier().get_typeModifier().setRestrict();
4032 }
4033
4034 // DQ (4/16/2015): This is replaced with a better implementation.
4035 // DQ (4/15/2015): We should reset the isModified flags as part of the transforamtion
4036 // because we have added statements explicitly marked as transformations.
4037 // checkIsModifiedFlag(defining_func);
4038 unsetNodesMarkedAsModified(defining_func);
4039
4040 return defining_func;
4041 }
4042
4043void
4045 {
4046 // 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)).
4047
4048 SgTemplateInstantiationFunctionDecl* templateInstantiationFunctionDecl = isSgTemplateInstantiationFunctionDecl(func);
4049 SgTemplateInstantiationMemberFunctionDecl* templateInstantiationMemberFunctionDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
4050 bool isTemplateInstantition = (templateInstantiationFunctionDecl != NULL) || (templateInstantiationMemberFunctionDecl != NULL);
4051 if (isTemplateInstantition == true)
4052 {
4053 // If this is a template instantiation then we need to take care of a few more issues.
4054
4055 SgName templateNameWithoutArguments = name;
4056
4057 // DQ (7/27/2012): New semantics is that we want to have the input name be without template arguments and
4058 // we will add the template arguments instead of trying to remove then (which was problematic for examples
4059 // such as "X<Y<Z>> operator X&()" and "X<Y<Z>> operator>()".
4060
4061 bool isMemberFunction = (templateInstantiationMemberFunctionDecl != NULL);
4062 if (isMemberFunction == true)
4063 {
4064 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
4065 ROSE_ASSERT(templateInstantiationFunctionDecl == NULL);
4066
4067 if (templateInstantiationMemberFunctionDecl->get_templateName().is_null() == true)
4068 {
4069 // Set the template name for the member function template instantiation.
4070 // templateInstantiationMemberFunctionDecl->set_templateName(name);
4071 templateInstantiationMemberFunctionDecl->set_templateName(templateNameWithoutArguments);
4072
4073 // DQ (5/31/2012): Find locations where this is set and include template syntax.
4074 }
4075 ROSE_ASSERT(templateInstantiationMemberFunctionDecl->get_templateName().is_null() == false);
4076 }
4077 else
4078 {
4079 ROSE_ASSERT(templateInstantiationFunctionDecl != NULL);
4080 ROSE_ASSERT(templateInstantiationMemberFunctionDecl == NULL);
4081
4082 if (templateInstantiationFunctionDecl->get_templateName().is_null() == true)
4083 {
4084 // Set the template name for the function template instantiation.
4085 // templateInstantiationFunctionDecl->set_templateName(name);
4086 templateInstantiationFunctionDecl->set_templateName(templateNameWithoutArguments);
4087
4088 // DQ (5/31/2012): Find locations where this is set and include template syntax.
4089 ROSE_ASSERT(hasTemplateSyntax(templateNameWithoutArguments) == false);
4090 }
4091 ROSE_ASSERT(templateInstantiationFunctionDecl->get_templateName().is_null() == false);
4092 }
4093 }
4094 }
4095
4097SageBuilder::buildDefiningFunctionDeclaration(const SgName& name, SgType* return_type, SgFunctionParameterList* paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, SgFunctionDeclaration* first_nondefining_declaration, SgTemplateArgumentPtrList* templateArgumentsList)
4098 {
4099 // DQ (2/10/2012): Fixed to build either SgTemplateInstantiationFunctionDecl or SgFunctionDeclaration.
4100 SgFunctionDeclaration* func = NULL;
4101 if (buildTemplateInstantiation == true)
4102 {
4103 SgTemplateInstantiationFunctionDecl* templateInstantiationFunctionDecl = isSgTemplateInstantiationFunctionDecl(first_nondefining_declaration);
4104
4105 ROSE_ASSERT(first_nondefining_declaration != NULL);
4106
4107 func = buildDefiningFunctionDeclaration_T<SgTemplateInstantiationFunctionDecl>(name,return_type,paralist,/* isMemberFunction = */ false,scope,decoratorList,0,templateInstantiationFunctionDecl, templateArgumentsList);
4108
4109 ROSE_ASSERT(isSgTemplateInstantiationFunctionDecl(func) != NULL);
4110 ROSE_ASSERT(isSgTemplateInstantiationFunctionDecl(func)->get_templateName().is_null() == false);
4111 }
4112 else
4113 {
4114 ROSE_ASSERT(first_nondefining_declaration != NULL);
4115
4116 func = buildDefiningFunctionDeclaration_T<SgFunctionDeclaration>(name,return_type,paralist,/* isMemberFunction = */ false,scope,decoratorList,0,first_nondefining_declaration, NULL);
4117
4118 ROSE_ASSERT(isSgFunctionDeclaration(func) != NULL);
4119 }
4120
4121 return func;
4122 }
4123
4124
4125// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficent).
4126// We need to decide if the SageBuilder API should include these sorts of functions.
4129 {
4130 // DQ (11/12/2012): Note that this function is not used in the AST construction in the EDG/ROSE interface.
4131
4132 // DQ (8/23/2013): Added assertions.
4133 ROSE_ASSERT(return_type != NULL);
4134 ROSE_ASSERT(parameter_list != NULL);
4135
4136 // DQ (8/23/2013): We need to provide the buildDefiningFunctionDeclaration() function with a pointer to the first non-defining declaration.
4137 // So we need to find it, and if it does not exist we need to build one so that we have a simple API for building defining declarations.
4138 // DQ (11/12/2012): Building a defining declaration from scratch now requires a non-defining declaration to exist.
4139 // SgFunctionDeclaration* nondefininfDeclaration = buildNondefiningFunctionDeclaration(name,return_type,parameter_list,scope,NULL);
4140
4141 if (scope == NULL)
4142 {
4144 }
4145
4146 SgFunctionDeclaration* nondefiningDeclaration = NULL;
4147
4148 SgFunctionType* func_type = buildFunctionType(return_type,parameter_list);
4149 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgFunctionDeclaration>(name,func_type,NULL,NULL);
4150 if (func_symbol != NULL)
4151 {
4152 nondefiningDeclaration = func_symbol->get_declaration();
4153 }
4154 else
4155 {
4156 nondefiningDeclaration = buildNondefiningFunctionDeclaration(name,return_type,parameter_list,scope,NULL);
4157 }
4158
4159 ROSE_ASSERT(nondefiningDeclaration != NULL);
4160 ROSE_ASSERT(nondefiningDeclaration->get_firstNondefiningDeclaration() != NULL);
4161 ROSE_ASSERT(nondefiningDeclaration->get_firstNondefiningDeclaration() == nondefiningDeclaration);
4162
4163 return buildDefiningFunctionDeclaration (name,return_type,parameter_list,scope,NULL,false,nondefiningDeclaration,NULL);
4164 }
4165
4166// Build a nondefining SgProcedureHeaderStatement, handle function type, symbol etc transparently [Rasmussen 9/24/2020]
4170 {
4171 ASSERT_not_null(return_type);
4172 ASSERT_not_null(param_list);
4173
4174 SgProcedureHeaderStatement* nondef_decl = nullptr;
4175
4176 if (scope == nullptr) {
4178 }
4179
4180 // A new nondefing declaration is needed even if the function symbol already exists. The function symbol
4181 // should always contain the _first_ nondefining declaration (even though this may not be the first one).
4182 nondef_decl = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement>
4183 ( name, return_type, param_list, /*isMemberFunction*/false, scope, /*decoratorList*/nullptr,
4184 /*functionConstVolatileFlags*/0, nullptr, nullptr, SgStorageModifier::e_default );
4185
4186 ASSERT_not_null(isSgProcedureHeaderStatement(nondef_decl));
4187 ASSERT_not_null(nondef_decl->get_firstNondefiningDeclaration());
4188
4189 nondef_decl->set_subprogram_kind(kind);
4190
4191 return nondef_decl;
4192 }
4193
4195buildProcedureHeaderStatement(const SgName& name, SgType* return_type, SgFunctionParameterList* parameter_list,
4197 {
4198 ASSERT_not_null(return_type);
4199 ASSERT_not_null(parameter_list);
4200
4201 SgFunctionDeclaration* nondef_decl = nullptr;
4202
4203 if (scope == nullptr) {
4205 }
4206
4207 SgFunctionType* func_type = buildFunctionType(return_type,parameter_list);
4208 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgProcedureHeaderStatement>(name,func_type,nullptr,nullptr);
4209 if (func_symbol == nullptr)
4210 {
4211 nondef_decl = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement>
4212 ( name, return_type, parameter_list, /*isMemberFunction*/false, scope,
4213 /*decoratorList*/nullptr, /*functionConstVolatileFlags*/0, nullptr, nullptr, SgStorageModifier::e_default);
4214 }
4215 else
4216 {
4217 nondef_decl = func_symbol->get_declaration();
4218 }
4219
4220 SgProcedureHeaderStatement* proc_header_stmt = isSgProcedureHeaderStatement(nondef_decl);
4221 ASSERT_not_null(proc_header_stmt);
4222 ASSERT_require(nondef_decl->get_firstNondefiningDeclaration() == nondef_decl);
4223
4224 return buildProcedureHeaderStatement(name.str(), return_type, parameter_list, kind, scope, proc_header_stmt);
4225 }
4226
4227
4232 SgProcedureHeaderStatement* firstNondefDecl)
4233{
4234 ASSERT_not_null(firstNondefDecl);
4235 SgProcedureHeaderStatement* func{nullptr};
4236
4239 ASSERT_require(returnType == buildVoidType());
4240 }
4242 mlog[ERROR] << "unhandled subprogram kind for Fortran (or Jovial) function declaration:"
4243 << kind << endl;
4244 ROSE_ABORT();
4245 }
4246
4247 func = buildDefiningFunctionDeclaration_T<SgProcedureHeaderStatement>(SgName(name), returnType, params, /*isMemberFunction =*/false,
4248 scope, nullptr, 0U, firstNondefDecl, nullptr);
4249 ASSERT_not_null(func);
4250 func->set_subprogram_kind(kind);
4251
4252 return func;
4253}
4254
4255//------------------build value expressions -------------------
4256//-------------------------------------------------------------
4258{
4259 //TODO does valueString matter here?
4260 SgBoolValExp* boolValue= new SgBoolValExp(value);
4261 ROSE_ASSERT(boolValue);
4263 return boolValue;
4264}
4266{
4267 return buildBoolValExp(int(value));
4268}
4270{
4271 SgBoolValExp* boolValue= new SgBoolValExp(value);
4272 ROSE_ASSERT(boolValue);
4273 setOneSourcePositionNull(boolValue);
4274 return boolValue;
4275}
4276
4278 {
4279 SgNullptrValExp* nullptrValue = new SgNullptrValExp();
4280 ROSE_ASSERT(nullptrValue);
4282 return nullptrValue;
4283 }
4284
4286 {
4287 SgNullptrValExp* nullptrValue = new SgNullptrValExp();
4288 ROSE_ASSERT(nullptrValue);
4289 setOneSourcePositionNull(nullptrValue);
4290 return nullptrValue;
4291 }
4292
4294 {
4295 SgVoidVal* voidValue = new SgVoidVal();
4296 ROSE_ASSERT(voidValue);
4298 return voidValue;
4299 }
4300
4302 {
4303 SgVoidVal* voidValue = new SgVoidVal();
4304 ROSE_ASSERT(voidValue);
4305 setOneSourcePositionNull(voidValue);
4306 return voidValue;
4307 }
4308
4310{
4311 SgCharVal* result = new SgCharVal(value, "");
4312 ROSE_ASSERT(result);
4314 return result;
4315}
4316
4317SgCharVal* SageBuilder::buildCharVal_nfi(char value, const string& str)
4318{
4319 SgCharVal* result = new SgCharVal(value, str);
4320 ROSE_ASSERT(result);
4322 return result;
4323}
4324
4326{
4327 SgWcharVal* result = new SgWcharVal(value, "");
4328 ROSE_ASSERT(result);
4330 return result;
4331}
4332
4333SgWcharVal* SageBuilder::buildWcharVal_nfi(wchar_t value, const string& str)
4334{
4335 SgWcharVal* result = new SgWcharVal(value, str);
4336 ROSE_ASSERT(result);
4338 return result;
4339}
4340
4341// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
4342SgChar16Val* SageBuilder::buildChar16Val(unsigned short value /*= 0*/)
4343{
4344 SgChar16Val* result = new SgChar16Val(value, "");
4345 ROSE_ASSERT(result);
4347 return result;
4348}
4349
4350SgChar16Val* SageBuilder::buildChar16Val_nfi(unsigned short value, const string& str)
4351{
4352 SgChar16Val* result = new SgChar16Val(value, str);
4353 ROSE_ASSERT(result);
4355 return result;
4356}
4357
4358// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
4359SgChar32Val* SageBuilder::buildChar32Val(unsigned int value /*= 0*/)
4360{
4361 SgChar32Val* result = new SgChar32Val(value, "");
4362 ROSE_ASSERT(result);
4364 return result;
4365}
4366
4367SgChar32Val* SageBuilder::buildChar32Val_nfi(unsigned int value, const string& str)
4368{
4369 SgChar32Val* result = new SgChar32Val(value, str);
4370 ROSE_ASSERT(result);
4372 return result;
4373}
4374
4375
4377{
4378 SgComplexVal* result = new SgComplexVal(real_value,imaginary_value,imaginary_value->get_type(),"");
4379 ROSE_ASSERT(result);
4380
4381// DQ (12/31/2008): set and test the parents
4382 if (real_value != NULL)
4383 real_value->set_parent(result);
4384
4385 if (imaginary_value != NULL)
4386 imaginary_value->set_parent(result);
4387
4388 ROSE_ASSERT(real_value == NULL || real_value->get_parent() != NULL);
4389 ROSE_ASSERT(imaginary_value == NULL || imaginary_value->get_parent() != NULL);
4390
4392 return result;
4393}
4394
4395SgComplexVal* SageBuilder::buildComplexVal_nfi(SgValueExp* real_value, SgValueExp* imaginary_value, const std::string& str)
4396{
4397 ROSE_ASSERT(imaginary_value != NULL);
4398 SgComplexVal* result = new SgComplexVal(real_value,imaginary_value,imaginary_value->get_type(),str);
4399 ROSE_ASSERT(result != NULL);
4400
4401// DQ (12/31/2008): set and test the parents
4402 if (real_value != NULL)
4403 real_value->set_parent(result);
4404
4405 if (imaginary_value != NULL)
4406 imaginary_value->set_parent(result);
4407
4408 ROSE_ASSERT(real_value == NULL || real_value->get_parent() != NULL);
4409 ROSE_ASSERT(imaginary_value == NULL || imaginary_value->get_parent() != NULL);
4410
4412 return result;
4413}
4414
4415SgComplexVal* SageBuilder::buildImaginaryVal(long double imaginary_value /*= 0.0*/ )
4416{
4417 SgComplexVal* result = new SgComplexVal(NULL,buildLongDoubleVal(imaginary_value),SgTypeLongDouble::createType(),"");
4418 ROSE_ASSERT(result);
4419
4420// DQ (12/31/2008): set and test the parents
4421 result->get_imaginary_value()->set_parent(result);
4422 ROSE_ASSERT(result->get_imaginary_value()->get_parent() != NULL);
4423
4425 return result;
4426}
4427
4429{
4430 ROSE_ASSERT(imaginary_value != NULL);
4431
4432 SgComplexVal* result = new SgComplexVal(NULL,imaginary_value,imaginary_value->get_type(),"");
4433 ROSE_ASSERT(result);
4434
4435// DQ (12/31/2008): set and test the parents
4436 imaginary_value->set_parent(result);
4437 ROSE_ASSERT(imaginary_value->get_parent() != NULL);
4438
4440 return result;
4441}
4442
4443SgComplexVal* SageBuilder::buildImaginaryVal_nfi(SgValueExp* imaginary_value, const std::string& str)
4444{
4445 ROSE_ASSERT(imaginary_value != NULL);
4446
4447 SgComplexVal* result = new SgComplexVal(NULL,imaginary_value,imaginary_value->get_type(),str);
4448 imaginary_value->set_parent(result);
4449 ROSE_ASSERT(result);
4450
4451// DQ (12/31/2008): set and test the parents
4452 ROSE_ASSERT(imaginary_value->get_parent() != NULL);
4453
4455 return result;
4456}
4457
4459{
4460 SgDoubleVal* value = new SgDoubleVal(t,"");
4461 ROSE_ASSERT(value);
4463 return value;
4464}
4465
4467{
4468 SgDoubleVal* value = new SgDoubleVal(t,str);
4469 ROSE_ASSERT(value);
4471 return value;
4472}
4473
4475{
4476 SgFloatVal* result = new SgFloatVal(value,"");
4477 ROSE_ASSERT(result);
4479 return result;
4480}
4481
4483{
4484 SgFloatVal* result = new SgFloatVal(value,"");
4485 ROSE_ASSERT(result);
4487 return result;
4488}
4489
4490SgFloatVal* SageBuilder::buildFloatVal_nfi(float value, const string& str)
4491{
4492 SgFloatVal* result = new SgFloatVal(value,str);
4493 ROSE_ASSERT(result);
4495 return result;
4496}
4497
4499{
4500 // C++11 please [CR 2020.02.25]
4501 // return buildFloatVal_nfi(std::stof(str), str);
4502 return buildFloatVal_nfi(atof(str.c_str()), str);
4503}
4504
4506 {
4507 SgIntVal* intValue= new SgIntVal(value,"");
4508 ASSERT_not_null(intValue);
4510 return intValue;
4511 }
4512
4514 {
4515 SgIntVal* intValue= new SgIntVal(value, (value >= 0 ? StringUtility::intToHex((unsigned int)value) : "-" + StringUtility::intToHex((unsigned int)(-value))));
4516 ASSERT_not_null(intValue);
4518 return intValue;
4519 }
4520
4522 {
4523 SgIntVal* intValue = new SgIntVal(value,"");
4524 ASSERT_not_null(intValue);
4525 setOneSourcePositionNull(intValue);
4526 return intValue;
4527 }
4528
4529SgIntVal* SageBuilder::buildIntVal_nfi(int value, const string& str)
4530 {
4531 SgIntVal* intValue = new SgIntVal(value,str);
4532 ASSERT_not_null(intValue);
4533 setOneSourcePositionNull(intValue);
4534 return intValue;
4535 }
4536
4538 {
4539 return buildIntVal_nfi(std::stoi(str), str);
4540 }
4541
4543{
4544 SgLongIntVal* intValue= new SgLongIntVal(value,"");
4545 ASSERT_not_null(intValue);
4547 return intValue;
4548}
4549
4550SgLongIntVal* SageBuilder::buildLongIntVal_nfi(long value, const string& str)
4551{
4552 SgLongIntVal* intValue= new SgLongIntVal(value,str);
4553 ASSERT_not_null(intValue);
4554 setOneSourcePositionNull(intValue);
4555 return intValue;
4556}
4557
4559{
4560 SgLongLongIntVal* intValue= new SgLongLongIntVal(value,"");
4561 ASSERT_not_null(intValue);
4563 return intValue;
4564}
4565
4566SgLongLongIntVal* SageBuilder::buildLongLongIntVal_nfi(long long value, const string& str)
4567{
4568 SgLongLongIntVal* intValue= new SgLongLongIntVal(value,str);
4569 ASSERT_not_null(intValue);
4570 setOneSourcePositionNull(intValue);
4571 return intValue;
4572}
4573
4575 {
4576 SgEnumVal* enumVal= new SgEnumVal(value,decl,name);
4577 ASSERT_not_null(enumVal);
4579 return enumVal;
4580 }
4581
4582
4584 {
4585 SgEnumVal* enumVal= new SgEnumVal(value,decl,name);
4586 ASSERT_not_null(enumVal);
4587 setOneSourcePositionNull(enumVal);
4588 return enumVal;
4589 }
4590
4592 SgInitializedName * init_name = sym->get_declaration();
4593 ROSE_ASSERT(init_name != NULL);
4594 SgAssignInitializer * assign_init = isSgAssignInitializer(init_name->get_initptr());
4595 ROSE_ASSERT(assign_init != NULL);
4596 SgEnumVal * enum_val = isSgEnumVal(assign_init->get_operand_i());
4597 ROSE_ASSERT(enum_val != NULL);
4598 enum_val = isSgEnumVal(SageInterface::copyExpression(enum_val));
4599 return enum_val;
4600}
4601
4603{
4604 SgLongDoubleVal* result = new SgLongDoubleVal(value,"");
4605 ASSERT_not_null(result);
4607 return result;
4608}
4609
4610SgLongDoubleVal* SageBuilder::buildLongDoubleVal_nfi(long double value, const string& str)
4611{
4612 SgLongDoubleVal* result = new SgLongDoubleVal(value,str);
4613 ASSERT_not_null(result);
4615 return result;
4616}
4617
4618SgFloat80Val* SageBuilder::buildFloat80Val(long double value /*= 0.0*/)
4619{
4620 SgFloat80Val* result = new SgFloat80Val(value,"");
4621 ASSERT_not_null(result);
4623 return result;
4624}
4625
4626SgFloat80Val* SageBuilder::buildFloat80Val_nfi(long double value, const string& str)
4627{
4628 SgFloat80Val* result = new SgFloat80Val(value,str);
4629 ASSERT_not_null(result);
4631 return result;
4632}
4633
4635{
4636 SgFloat128Val* result = new SgFloat128Val(value,"");
4637 ASSERT_not_null(result);
4639 return result;
4640}
4641
4642SgFloat128Val* SageBuilder::buildFloat128Val_nfi(long double value, const string& str)
4643{
4644 SgFloat128Val* result = new SgFloat128Val(value,str);
4645 ASSERT_not_null(result);
4647 return result;
4648}
4649
4650SgStringVal* SageBuilder::buildStringVal(std::string value /*=""*/)
4651{
4652 SgStringVal* result = new SgStringVal(value);
4653 ASSERT_not_null(result);
4655 return result;
4656}
4657
4659{
4660 SgStringVal* result = new SgStringVal(value);
4661 ASSERT_not_null(result);
4663 return result;
4664}
4665
4667{
4668 SgUnsignedCharVal* result = new SgUnsignedCharVal(v,"");
4669 ASSERT_not_null(result);
4671 return result;
4672}
4673
4675{
4677 ASSERT_not_null(result);
4679 return result;
4680}
4681
4683{
4684 SgUnsignedCharVal* result = new SgUnsignedCharVal(v,str);
4685 ASSERT_not_null(result);
4687 return result;
4688}
4689
4691{
4692 SgShortVal* result = new SgShortVal(v,"");
4693 ASSERT_not_null(result);
4695 return result;
4696}
4697
4699{
4700 SgShortVal* result = new SgShortVal(v, (v >= 0 ? StringUtility::intToHex((unsigned int)v) : "-" + StringUtility::intToHex((unsigned int)(-v))));
4701 ASSERT_not_null(result);
4703 return result;
4704}
4705
4706SgShortVal* SageBuilder::buildShortVal_nfi(short v, const string& str)
4707{
4708 SgShortVal* result = new SgShortVal(v,str);
4709 ASSERT_not_null(result);
4711 return result;
4712}
4713
4715{
4716 SgUnsignedShortVal* result = new SgUnsignedShortVal(v,"");
4717 ASSERT_not_null(result);
4719 return result;
4720}
4721
4723{
4725 ASSERT_not_null(result);
4727 return result;
4728}
4729
4731{
4732 SgUnsignedShortVal* result = new SgUnsignedShortVal(v,str);
4733 ASSERT_not_null(result);
4735 return result;
4736}
4737
4739{
4740 SgUnsignedIntVal* result = new SgUnsignedIntVal(v,"");
4741 ASSERT_not_null(result);
4743 return result;
4744}
4745
4747{
4749 ASSERT_not_null(result);
4751 return result;
4752}
4753
4755{
4756 SgUnsignedIntVal* result = new SgUnsignedIntVal(v,str);
4757 ASSERT_not_null(result);
4759 return result;
4760}
4761
4763{
4764 SgUnsignedLongVal* result = new SgUnsignedLongVal(v,"");
4765 ASSERT_not_null(result);
4767 return result;
4768}
4769
4771{
4773 ASSERT_not_null(result);
4775 return result;
4776}
4777
4779{
4780 SgUnsignedLongVal* result = new SgUnsignedLongVal(v,str);
4781 ASSERT_not_null(result);
4783 return result;
4784}
4785
4787{
4789 ASSERT_not_null(result);
4791 return result;
4792}
4793
4795{
4797 ASSERT_not_null(result);
4799 return result;
4800}
4801
4803{
4805 ASSERT_not_null(result);
4807 return result;
4808}
4809
4810SgJovialBitVal* SageBuilder::buildJovialBitVal_nfi(const string& str)
4811{
4812 SgJovialBitVal* result = new SgJovialBitVal(str);
4813 ASSERT_not_null(result);
4815 return result;
4816}
4817
4819{
4820 SgTemplateType* result = new SgTemplateType (name);
4821 ASSERT_not_null (result);
4823 return result;
4824}
4825
4827{
4828 ROSE_ASSERT (t);
4829 SgTemplateParameter* result = new SgTemplateParameter(parameterType, t);
4830 ROSE_ASSERT (result);
4832 return result;
4833}
4834
4836{
4837 SgTemplateParameterVal* templateParameterValue = new SgTemplateParameterVal(template_parameter_position,"");
4838 ROSE_ASSERT(templateParameterValue);
4839 setOneSourcePositionForTransformation(templateParameterValue);
4840
4841// DQ (7/25/2012): Assert this (it will be set later).
4842 ROSE_ASSERT(templateParameterValue->get_parent() == NULL);
4843
4844 return templateParameterValue;
4845}
4846
4847SgTemplateParameterVal* SageBuilder::buildTemplateParameterVal_nfi(int template_parameter_position, const string& str)
4848{
4849 SgTemplateParameterVal* templateParameterValue= new SgTemplateParameterVal(template_parameter_position,str);
4850 ROSE_ASSERT(templateParameterValue);
4851 setOneSourcePositionNull(templateParameterValue);
4852
4853// DQ (7/25/2012): Assert this (it will be set later).
4854 ROSE_ASSERT(templateParameterValue->get_parent() == NULL);
4855
4856 return templateParameterValue;
4857}
4858
4859#define DEBUG_BUILD_NONREAL_DECL 0
4860
4862 ROSE_ASSERT(scope != NULL);
4863#if DEBUG_BUILD_NONREAL_DECL
4864 printf("ENTER SageBuilder::buildNonrealDecl\n");
4865 printf(" --- name = %s\n", name.str());
4866 printf(" --- scope = %p (%s)\n", scope, scope->class_name().c_str());
4867#endif
4868
4869 SgNonrealDecl * nrdecl = NULL;
4870
4871 nrdecl = new SgNonrealDecl(name);
4873 nrdecl->set_firstNondefiningDeclaration(nrdecl);
4874#if DEBUG_BUILD_NONREAL_DECL
4875 printf(" --- nrdecl = %p (%s)\n", nrdecl, nrdecl->class_name().c_str());
4876#endif
4877
4878 SgNonrealSymbol * symbol = new SgNonrealSymbol(nrdecl);
4879 scope->insert_symbol(name, symbol);
4880#if DEBUG_BUILD_NONREAL_DECL
4881 printf(" --- symbol = %p (%s)\n", symbol, symbol->class_name().c_str());
4882#endif
4883
4884 SgNonrealType * type = new SgNonrealType();
4885 type->set_declaration(nrdecl);
4886 type->set_parent(scope);
4887 nrdecl->set_type(type);
4888 // FIXME (???) insert `type` in `scope`
4889#if DEBUG_BUILD_NONREAL_DECL
4890 printf(" --- type = %p (%s)\n", type, type->class_name().c_str());
4891#endif
4892
4893 if (child_scope == NULL) {
4894 child_scope = new SgDeclarationScope();
4895#if DEBUG_BUILD_NONREAL_DECL
4896 printf(" --- child_scope = %p (new)\n", name.str(), child_scope);
4897#endif
4900 child_scope->get_endOfConstruct()->setCompilerGenerated();
4901 } else {
4902#if DEBUG_BUILD_NONREAL_DECL
4903 printf(" --- child_scope = %p (provided)\n", name.str(), child_scope);
4904#endif
4905
4906 }
4907 child_scope->set_parent(nrdecl);
4908 nrdecl->set_nonreal_decl_scope(child_scope);
4909
4910#if DEBUG_BUILD_NONREAL_DECL
4911 printf("LEAVE SageBuilder::buildNonrealDecl\n");
4912#endif
4913
4914 return nrdecl;
4915}
4916
4919{
4920 SgUpcThreads* result = new SgUpcThreads(0,"");
4921 ROSE_ASSERT(result);
4923 return result;
4924}
4925
4928{
4929 SgUpcThreads* result = new SgUpcThreads(0,"");
4930 ROSE_ASSERT(result);
4932 return result;
4933}
4934
4937{
4938 SgUpcMythread* result = new SgUpcMythread(0,"");
4939 ROSE_ASSERT(result);
4941 return result;
4942}
4943
4946{
4947 SgUpcMythread* result = new SgUpcMythread(0,"");
4948 ROSE_ASSERT(result);
4950 return result;
4951}
4952
4954{
4955 SgThisExp* result = new SgThisExp(isSgClassSymbol(sym), isSgNonrealSymbol(sym), 0);
4956 ROSE_ASSERT(result);
4958 return result;
4959}
4960
4962{
4963 SgThisExp* result = new SgThisExp(isSgClassSymbol(sym), isSgNonrealSymbol(sym), 0);
4964 ROSE_ASSERT(result);
4966 return result;
4967}
4968
4970{
4971 SgSuperExp* result = new SgSuperExp(sym, 0);
4972 ROSE_ASSERT(result);
4974 return result;
4975}
4976
4978{
4979 SgSuperExp* result = new SgSuperExp(sym, 0);
4980 ROSE_ASSERT(result);
4982 return result;
4983}
4984
4986{
4987 SgClassExp* result = new SgClassExp(sym, 0);
4988 ROSE_ASSERT(result);
4990 return result;
4991}
4992
4994{
4995 SgClassExp* result = new SgClassExp(sym, 0);
4996 ROSE_ASSERT(result);
4998 return result;
4999}
5000
5003{
5004 SgTupleExp* tuple = new SgTupleExp();
5005 ROSE_ASSERT(tuple);
5006 if (elt1) appendExpression(tuple, elt1);
5007 if (elt2) appendExpression(tuple, elt2);
5008 if (elt3) appendExpression(tuple, elt3);
5009 if (elt4) appendExpression(tuple, elt4);
5010 if (elt5) appendExpression(tuple, elt5);
5011 if (elt6) appendExpression(tuple, elt6);
5012 if (elt7) appendExpression(tuple, elt7);
5013 if (elt8) appendExpression(tuple, elt8);
5014 if (elt9) appendExpression(tuple, elt9);
5015 if (elt10) appendExpression(tuple, elt10);
5016
5018 return tuple;
5019}
5020
5022SageBuilder::buildTupleExp(const std::vector<SgExpression*>& elts)
5023{
5025 appendExpressionList(expList, elts);
5026 return expList;
5027}
5028
5031{
5032 SgTupleExp* tuple = new SgTupleExp();
5033 ROSE_ASSERT(tuple);
5035 return tuple;
5036}
5037
5039SageBuilder::buildTupleExp_nfi(const std::vector<SgExpression*>& elts)
5040{
5042 appendExpressionList(tuple, elts);
5043 return tuple;
5044}
5045
5046SgListExp*
5048{
5049 SgListExp* tuple = new SgListExp();
5050 ROSE_ASSERT(tuple);
5051 if (elt1) appendExpression(tuple, elt1);
5052 if (elt2) appendExpression(tuple, elt2);
5053 if (elt3) appendExpression(tuple, elt3);
5054 if (elt4) appendExpression(tuple, elt4);
5055 if (elt5) appendExpression(tuple, elt5);
5056 if (elt6) appendExpression(tuple, elt6);
5057 if (elt7) appendExpression(tuple, elt7);
5058 if (elt8) appendExpression(tuple, elt8);
5059 if (elt9) appendExpression(tuple, elt9);
5060 if (elt10) appendExpression(tuple, elt10);
5061
5063 return tuple;
5064}
5065
5066SgListExp*
5067SageBuilder::buildListExp(const std::vector<SgExpression*>& elts)
5068{
5070 appendExpressionList(expList, elts);
5071 return expList;
5072}
5073
5074SgListExp*
5076{
5077 SgListExp* tuple = new SgListExp();
5078 ROSE_ASSERT(tuple);
5080 return tuple;
5081}
5082
5083SgListExp*
5084SageBuilder::buildListExp_nfi(const std::vector<SgExpression*>& elts)
5085{
5087 appendExpressionList(tuple, elts);
5088 return tuple;
5089}
5090
5091
5092#define BUILD_UNARY_DEF(suffix) \
5093 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix##_nfi(SgExpression* op) \
5094 { \
5095 return SageBuilder::buildUnaryExpression_nfi<Sg##suffix>(op); \
5096 } \
5097 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix(SgExpression* op) \
5098 { \
5099 return SageBuilder::buildUnaryExpression<Sg##suffix>(op); \
5100 }
5101
5102BUILD_UNARY_DEF(AddressOfOp)
5103BUILD_UNARY_DEF(BitComplementOp)
5104BUILD_UNARY_DEF(MinusOp)
5105BUILD_UNARY_DEF(NotOp)
5106BUILD_UNARY_DEF(PointerDerefExp)
5107BUILD_UNARY_DEF(UnaryAddOp)
5108BUILD_UNARY_DEF(AbsOp)
5109BUILD_UNARY_DEF(MinusMinusOp)
5110BUILD_UNARY_DEF(PlusPlusOp)
5111BUILD_UNARY_DEF(RealPartOp)
5112BUILD_UNARY_DEF(ImagPartOp)
5113BUILD_UNARY_DEF(ConjugateOp)
5114BUILD_UNARY_DEF(VarArgStartOneOperandOp)
5115BUILD_UNARY_DEF(VarArgEndOp)
5116
5117BUILD_UNARY_DEF(MatrixTransposeOp) //SK(08/20/2015): Matlab matrix transpose operators
5118
5119#undef BUILD_UNARY_DEF
5120
5122 SgType * expression_type,
5123 SgCastExp::cast_type_enum cast_type)
5124{
5125 SgCastExp* result = new SgCastExp(operand_i, expression_type, cast_type);
5126 ROSE_ASSERT(result);
5127 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5129 return result;
5130}
5131
5132SgNewExp*
5134 SgExprListExp* placement_args,
5135 SgConstructorInitializer* constructor_args,
5136 SgExpression* builtin_args,
5137 // FIXME: Change this from "short int" to "bool".
5138 short int need_global_specifier,
5139 SgFunctionDeclaration* newOperatorDeclaration)
5140 {
5141 // DQ (11/18/2012): Modified parameter names to make this function more clear.
5142 SgNewExp* result = new SgNewExp(specified_type, placement_args, constructor_args, builtin_args, need_global_specifier, newOperatorDeclaration);
5143 ROSE_ASSERT(result);
5144
5146 return result;
5147 }
5148
5150 short is_array,
5151 short need_global_specifier,
5152 SgFunctionDeclaration* deleteOperatorDeclaration)
5153{
5154 SgDeleteExp* result = new SgDeleteExp(variable, is_array,
5155 need_global_specifier, deleteOperatorDeclaration);
5156 ROSE_ASSERT(result);
5158 return result;
5159}
5160
5163 {
5164 // DQ (1/25/2013): Added support for typeId operators.
5165 SgTypeIdOp* result = new SgTypeIdOp(operand_expr,operand_type);
5166 ROSE_ASSERT(result != NULL);
5168 return result;
5169 }
5170
5172{
5173 SgCastExp* result = new SgCastExp(operand_i, expression_type, cast_type);
5174 ROSE_ASSERT(result);
5175 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5177 return result;
5178}
5179
5181 SgVarArgOp* result = new SgVarArgOp(operand_i, expression_type);
5182 ROSE_ASSERT(result);
5183 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5185 return result;
5186}
5187
5189{
5190 SgMinusMinusOp* result = buildUnaryExpression<SgMinusMinusOp>(operand_i);
5191 ROSE_ASSERT(result);
5192 result->set_mode(a_mode);
5193 return result;
5194}
5195
5197{
5198 SgMinusMinusOp* result = buildUnaryExpression_nfi<SgMinusMinusOp>(operand_i);
5199 ROSE_ASSERT(result);
5200 result->set_mode(a_mode);
5201 return result;
5202}
5203
5205{
5206 SgMinusOp* result = buildUnaryExpression<SgMinusOp>(operand_i);
5207 ROSE_ASSERT(result);
5208 result->set_mode(a_mode);
5209 return result;
5210}
5211
5213{
5214 SgMinusOp* result = buildUnaryExpression_nfi<SgMinusOp>(operand_i);
5215 ROSE_ASSERT(result);
5216 result->set_mode(a_mode);
5217 return result;
5218}
5219
5221{
5222 SgPlusPlusOp* result = buildUnaryExpression<SgPlusPlusOp>(operand_i);
5223 ROSE_ASSERT(result);
5224 result->set_mode(a_mode);
5225 return result;
5226}
5227
5228
5230{
5231 SgPlusPlusOp* result = buildUnaryExpression_nfi<SgPlusPlusOp>(operand_i);
5232 ROSE_ASSERT(result);
5233 result->set_mode(a_mode);
5234 return result;
5235}
5236
5238 {
5239 // DQ (11/8/2011): operand_i is allowed to be NULL.
5240
5241 // SgThrowOp* result = new SgThrowOp(operand_i, operand_i -> get_type(), throwKind);
5242 SgThrowOp* result = new SgThrowOp(operand_i, (operand_i != NULL) ? operand_i->get_type() : NULL, throwKind);
5243
5244 if (operand_i)
5245 {
5246 markLhsValues(result);
5247 }
5248
5250
5251 if (operand_i)
5252 operand_i -> set_parent(result);
5253
5254 ROSE_ASSERT(result);
5255
5256 return result;
5257 }
5258
5259
5260
5261#define BUILD_BINARY_DEF(suffix) \
5262 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix##_nfi(SgExpression* lhs, SgExpression* rhs) \
5263 { \
5264 return buildBinaryExpression_nfi<Sg##suffix>(lhs, rhs); \
5265 } \
5266 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix(SgExpression* lhs, SgExpression* rhs) \
5267 { \
5268 return buildBinaryExpression<Sg##suffix>(lhs, rhs); \
5269 }
5270
5271BUILD_BINARY_DEF(AddOp)
5272BUILD_BINARY_DEF(AndAssignOp)
5273BUILD_BINARY_DEF(AndOp)
5274BUILD_BINARY_DEF(ArrowExp)
5275BUILD_BINARY_DEF(ArrowStarOp)
5276BUILD_BINARY_DEF(AssignOp)
5277BUILD_BINARY_DEF(AtOp)
5278BUILD_BINARY_DEF(BitAndOp)
5279BUILD_BINARY_DEF(BitOrOp)
5280BUILD_BINARY_DEF(BitXorOp)
5281
5282BUILD_BINARY_DEF(CommaOpExp)
5283BUILD_BINARY_DEF(ConcatenationOp)
5284BUILD_BINARY_DEF(DivAssignOp)
5285BUILD_BINARY_DEF(DivideOp)
5286BUILD_BINARY_DEF(DotExp)
5287BUILD_BINARY_DEF(DotStarOp)
5288BUILD_BINARY_DEF(EqualityOp)
5289
5290BUILD_BINARY_DEF(ExponentiationOp)
5291BUILD_BINARY_DEF(ExponentiationAssignOp)
5292BUILD_BINARY_DEF(GreaterOrEqualOp)
5293BUILD_BINARY_DEF(GreaterThanOp)
5294BUILD_BINARY_DEF(IntegerDivideOp)
5295BUILD_BINARY_DEF(IntegerDivideAssignOp)
5296BUILD_BINARY_DEF(IorAssignOp)
5297BUILD_BINARY_DEF(IsOp)
5298BUILD_BINARY_DEF(IsNotOp)
5299
5300BUILD_BINARY_DEF(LessOrEqualOp)
5301BUILD_BINARY_DEF(LessThanOp)
5302BUILD_BINARY_DEF(LshiftAssignOp)
5303BUILD_BINARY_DEF(LshiftOp)
5304
5305BUILD_BINARY_DEF(MembershipOp)
5306BUILD_BINARY_DEF(MinusAssignOp)
5307BUILD_BINARY_DEF(ModAssignOp)
5308BUILD_BINARY_DEF(ModOp)
5309BUILD_BINARY_DEF(MultAssignOp)
5310BUILD_BINARY_DEF(MultiplyOp)
5311
5312BUILD_BINARY_DEF(NotEqualOp)
5313BUILD_BINARY_DEF(NonMembershipOp)
5314BUILD_BINARY_DEF(OrOp)
5315BUILD_BINARY_DEF(PlusAssignOp)
5316BUILD_BINARY_DEF(PntrArrRefExp)
5317BUILD_BINARY_DEF(RemOp)
5318BUILD_BINARY_DEF(RshiftAssignOp)
5319BUILD_BINARY_DEF(JavaUnsignedRshiftAssignOp)
5320
5321BUILD_BINARY_DEF(RshiftOp)
5322BUILD_BINARY_DEF(JavaUnsignedRshiftOp)
5323BUILD_BINARY_DEF(ScopeOp)
5324BUILD_BINARY_DEF(SubtractOp)
5325BUILD_BINARY_DEF(XorAssignOp)
5326
5327BUILD_BINARY_DEF(VarArgCopyOp)
5328BUILD_BINARY_DEF(VarArgStartOp)
5329
5330// CR(07/26/2018): Jovial operators
5331BUILD_BINARY_DEF(ReplicationOp);
5332
5333//SK(08/20/2015): Matlab operators
5334BUILD_BINARY_DEF(PowerOp);
5335BUILD_BINARY_DEF(ElementwisePowerOp);
5336BUILD_BINARY_DEF(ElementwiseMultiplyOp);
5337BUILD_BINARY_DEF(ElementwiseDivideOp);
5338BUILD_BINARY_DEF(LeftDivideOp);
5339BUILD_BINARY_DEF(ElementwiseLeftDivideOp);
5340BUILD_BINARY_DEF(ElementwiseAddOp);
5341BUILD_BINARY_DEF(ElementwiseSubtractOp);
5342
5343// DQ (7/25/2020): Adding C++20 support
5344BUILD_BINARY_DEF(SpaceshipOp)
5345
5346#undef BUILD_BINARY_DEF
5347
5348
5349
5350// CR ( 1/25/2018):
5351// (10/30/2018): Fixed case when this function is called with NULL dim_info object.
5353 {
5354 ROSE_ASSERT(base_type != NULL);
5355
5356 // There must always be a dim_info object for this function. If not, the
5357 // overloaded function must be used to handle it.
5358 if (dim_info == NULL)
5359 {
5360 SgExpression* index = NULL;
5361 return buildArrayType(base_type, index);
5362 }
5363
5364 SgExpression* index = new SgNullExpression();
5365 ROSE_ASSERT(index);
5366 setSourcePosition(index);
5367
5368 SgArrayType* array_type = new SgArrayType(base_type, index);
5369 ROSE_ASSERT(array_type);
5370 ROSE_ASSERT(array_type->get_dim_info() == NULL);
5371
5372 index ->set_parent(array_type);
5373 dim_info->set_parent(array_type);
5374
5375 array_type->set_dim_info(dim_info);
5376 array_type->set_rank(dim_info->get_expressions().size());
5377
5378 return array_type;
5379 }
5380
5381SgArrayType* SageBuilder::buildArrayType(SgType* base_type/*=NULL*/, SgExpression* index/*=NULL*/)
5382{
5383 SgArrayType* result = new SgArrayType(base_type,index);
5384 ASSERT_not_null(result);
5385
5386 if (index != nullptr) {
5387 index->set_parent(result); // important!
5388 }
5389
5390 return result;
5391}
5392
5394{
5395 SgConditionalExp* result = new SgConditionalExp(test, a, b, NULL);
5396 if (test) test->set_parent(result);
5397 if (a) a->set_parent(result);
5398 if (b) b->set_parent(result);
5400 return result;
5401}
5402
5404{
5405 SgConditionalExp* result = new SgConditionalExp(test, a, b, t);
5406 if (test) test->set_parent(result);
5407 if (a) {a->set_parent(result); markLhsValues(a);}
5408 if (b) {b->set_parent(result); markLhsValues(b);}
5410 return result;
5411}
5412
5414{
5416 ROSE_ASSERT(result);
5418 return result;
5419}
5420
5423 ROSE_ASSERT(ne);
5425 return ne;
5426}
5427
5433
5435 SgColonShapeExp* expr = new SgColonShapeExp();
5436 ASSERT_not_null(expr);
5438 return expr;
5439}
5440
5446
5447SgAssignInitializer * SageBuilder::buildAssignInitializer(SgExpression * operand_i /*= NULL*/, SgType * expression_type /* = NULL */)
5448 {
5449 SgAssignInitializer* result = new SgAssignInitializer(operand_i, expression_type);
5450 ROSE_ASSERT(result);
5451 if (operand_i!=NULL)
5452 {
5453 operand_i->set_parent(result);
5454 // set lvalue, it asserts operand!=NULL
5455 markLhsValues(result);
5456 }
5458 return result;
5459 }
5460
5461SgAssignInitializer * SageBuilder::buildAssignInitializer_nfi(SgExpression * operand_i /*= nullptr*/, SgType * expression_type /*=nullptr*/)
5462 {
5463 SgAssignInitializer* result = new SgAssignInitializer(operand_i, expression_type);
5464 ASSERT_not_null(result);
5465 if (operand_i)
5466 {
5467 operand_i->set_parent(result);
5468 // set lvalue, it asserts operand!=NULL
5469 markLhsValues(result);
5470 }
5471
5472 setSourcePosition(result);
5473 result->set_need_paren(false);
5474
5475 return result;
5476 }
5477
5480{
5481 SgAggregateInitializer* result = new SgAggregateInitializer(initializers, type);
5482 ROSE_ASSERT(result);
5483 if (initializers!=NULL)
5484 {
5485 initializers->set_parent(result);
5486 }
5487 result->set_need_explicit_braces(true);
5489 return result;
5490}
5491
5494{
5495 SgAggregateInitializer* result = new SgAggregateInitializer(initializers, type);
5496 ROSE_ASSERT(result);
5497 if (initializers!=NULL)
5498 {
5499 initializers->set_parent(result);
5500 }
5501 result->set_need_explicit_braces(true);
5503 return result;
5504}
5505
5508{
5509 SgCompoundInitializer* result = new SgCompoundInitializer(initializers, type);
5510 ROSE_ASSERT(result);
5511 if (initializers!=NULL)
5512 {
5513 initializers->set_parent(result);
5514 }
5516 return result;
5517}
5518
5521{
5522 SgCompoundInitializer* result = new SgCompoundInitializer(initializers, type);
5523 ROSE_ASSERT(result);
5524 if (initializers!=NULL)
5525 {
5526 initializers->set_parent(result);
5527 }
5529 return result;
5530}
5531
5532// DQ (1/4/2009): Added support for SgConstructorInitializer
5535 SgMemberFunctionDeclaration *declaration/* = NULL*/,
5536 SgExprListExp *args/* = NULL*/,
5537 SgType *expression_type/* = NULL*/,
5538 bool need_name /*= false*/,
5539 bool need_qualifier /*= false*/,
5540 bool need_parenthesis_after_name /*= false*/,
5541 bool associated_class_unknown /*= false*/)
5542 {
5543 // Prototype:
5544 // SgConstructorInitializer (SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type,
5545 // bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown);
5546
5547 //George Vulov (05/24/2011) Modified this assertion to allow for a NULL declaration (in case of implicit constructors)
5548 ROSE_ASSERT(declaration == NULL || declaration->get_associatedClassDeclaration() != NULL);
5549
5550 SgConstructorInitializer* result = new SgConstructorInitializer( declaration, args, expression_type, need_name,
5551 need_qualifier, need_parenthesis_after_name, associated_class_unknown );
5552 ROSE_ASSERT(result != NULL);
5553 if (args != NULL)
5554 {
5555 args->set_parent(result);
5557 }
5558
5560
5561 return result;
5562 }
5563
5564// DQ (1/4/2009): Added support for SgConstructorInitializer
5567 SgMemberFunctionDeclaration *declaration/* = NULL*/,
5568 SgExprListExp *args/* = NULL*/,
5569 SgType *expression_type/* = NULL*/,
5570 bool need_name /*= false*/,
5571 bool need_qualifier /*= false*/,
5572 bool need_parenthesis_after_name /*= false*/,
5573 bool associated_class_unknown /*= false*/)
5574 {
5575 // Prototype:
5576 // SgConstructorInitializer (SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type, bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown);
5577
5578 // DQ (11/7/2011): Fix symetric to the way George did it above.
5579 ROSE_ASSERT(declaration == NULL || declaration->get_associatedClassDeclaration() != NULL);
5580
5581 SgConstructorInitializer* result = new SgConstructorInitializer( declaration, args, expression_type, need_name, need_qualifier, need_parenthesis_after_name, associated_class_unknown );
5582 ROSE_ASSERT(result != NULL);
5583
5585
5586 if (args != NULL)
5587 {
5588 args->set_parent(result);
5589 }
5590
5591 // DQ (11/4/2012): This is required and appears to work fine now.
5592 // DQ (11/23/2011): Fixup the expression list (but this does not appear to work...)
5593 if (result->get_args()->get_startOfConstruct() == NULL)
5594 {
5595 setOneSourcePositionNull(result->get_args());
5596 }
5597
5598 return result;
5599 }
5600
5601// DQ (11/15/2016):Adding support for braced initializer (required for template support).
5605 {
5606 SgBracedInitializer* result = new SgBracedInitializer(initializers, expression_type);
5607 ROSE_ASSERT(result);
5608 if (initializers!=NULL)
5609 {
5610 initializers->set_parent(result);
5611 }
5613 return result;
5614 }
5615
5617 {
5618 SgBracedInitializer* result = new SgBracedInitializer(initializers, expression_type);
5619 ROSE_ASSERT(result);
5620 if (initializers!=NULL)
5621 {
5622 initializers->set_parent(result);
5623 }
5625 return result;
5626 }
5627
5628
5631 {
5632 // SgType* exp_type = NULL;
5633 // if (exp) exp_type = exp->get_type();
5634
5635 SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, NULL);
5636 // SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, exp_type);
5637 ROSE_ASSERT(result);
5638 if (exp)
5639 {
5640 exp->set_parent(result);
5641 markLhsValues(result);
5642 }
5644 return result;
5645 }
5646
5649 {
5650 // SgType* exp_type =NULL;
5651 // if (exp) exp_type = exp->get_type();
5652
5653 SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, NULL);
5654 // SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, exp_type);
5655 ROSE_ASSERT(result);
5656 if (exp)
5657 {
5658 exp->set_parent(result);
5659 markLhsValues(result);
5660 }
5662 return result;
5663 }
5664
5667 {
5668 SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,NULL);
5669 // SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,type);
5670 ROSE_ASSERT(result);
5672 return result;
5673 }
5674
5677 {
5678 SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,NULL);
5679 // SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,type);
5680 ROSE_ASSERT(result);
5682 return result;
5683 }
5684
5687 {
5688 // SgType* exp_type =NULL;
5689 // if (exp) exp_type = exp->get_type();
5690
5691 SgAlignOfOp* result = new SgAlignOfOp(exp,NULL, NULL);
5692 ROSE_ASSERT(result);
5693 if (exp)
5694 {
5695 exp->set_parent(result);
5696 markLhsValues(result);
5697 }
5699 return result;
5700 }
5701
5704 {
5705 // SgType* exp_type =NULL;
5706 // if (exp) exp_type = exp->get_type();
5707
5708 SgAlignOfOp* result = new SgAlignOfOp(exp,NULL, NULL);
5709 ROSE_ASSERT(result);
5710 if (exp)
5711 {
5712 exp->set_parent(result);
5713 markLhsValues(result);
5714 }
5716 return result;
5717 }
5718