ROSE 0.11.145.192
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
5721 {
5722 // SgType* exp_type =NULL;
5723 // if (exp) exp_type = exp->get_type();
5724
5725 SgNoexceptOp* result = new SgNoexceptOp(exp);
5726 ROSE_ASSERT(result);
5727 if (exp)
5728 {
5729 exp->set_parent(result);
5730 markLhsValues(result);
5731 }
5732
5734 return result;
5735 }
5736
5739 {
5740 // SgType* exp_type =NULL;
5741 // if (exp) exp_type = exp->get_type();
5742
5743 SgNoexceptOp* result = new SgNoexceptOp(exp);
5744 ROSE_ASSERT(result);
5745 if (exp)
5746 {
5747 exp->set_parent(result);
5748 markLhsValues(result);
5749 }
5750
5752 return result;
5753 }
5754
5757 {
5758 SgAlignOfOp* result = new SgAlignOfOp((SgExpression*)NULL,type,NULL);
5759 ROSE_ASSERT(result);
5761 return result;
5762 }
5763
5766 {
5767 SgAlignOfOp* result = new SgAlignOfOp((SgExpression*)NULL,type,NULL);
5768 ROSE_ASSERT(result);
5770 return result;
5771 }
5772
5773
5775{
5776 SgExprListExp* expList = new SgExprListExp();
5777 ROSE_ASSERT(expList);
5778
5779// printf ("In SageBuilder::buildExprListExp(SgExpression * expr1, SgExpression* expr2, ...): SgExprListExp* expList = %p \n",expList);
5780
5782 if (expr1) appendExpression(expList, expr1);
5783 if (expr2) appendExpression(expList, expr2);
5784 if (expr3) appendExpression(expList, expr3);
5785 if (expr4) appendExpression(expList, expr4);
5786 if (expr5) appendExpression(expList, expr5);
5787 if (expr6) appendExpression(expList, expr6);
5788 if (expr7) appendExpression(expList, expr7);
5789 if (expr8) appendExpression(expList, expr8);
5790 if (expr9) appendExpression(expList, expr9);
5791 if (expr10) appendExpression(expList, expr10);
5792 return expList;
5793}
5794
5795// CH (5/11/2010): Seems that this function is useful.
5796SgExprListExp * SageBuilder::buildExprListExp(const std::vector<SgExpression*>& exprs)
5797{
5798 SgExprListExp* expList = new SgExprListExp();
5799 ROSE_ASSERT(expList);
5800
5802 for (size_t i = 0; i < exprs.size(); ++i) {
5803 appendExpression(expList, exprs[i]);
5804 }
5805 return expList;
5806}
5807
5809 {
5810 SgExprListExp* expList = new SgExprListExp();
5811 ROSE_ASSERT(expList);
5812
5813 setOneSourcePositionNull(expList);
5814 return expList;
5815 }
5816
5817SgExprListExp * SageBuilder::buildExprListExp_nfi(const std::vector<SgExpression*>& exprs)
5818 {
5819 SgExprListExp* expList = new SgExprListExp();
5820 ROSE_ASSERT(expList != NULL);
5821
5822 setOneSourcePositionNull(expList);
5823 for (size_t i = 0; i < exprs.size(); ++i)
5824 {
5825 appendExpression(expList, exprs[i]);
5826 }
5827
5828 // DQ (4/3/2012): Added test to make sure that the pointers are unique.
5829 testAstForUniqueNodes(expList);
5830
5831 return expList;
5832 }
5833
5836 {
5837 if (lower_bound == NULL)
5838 {
5840 }
5841 if (stride == NULL)
5842 {
5844 }
5845
5846 ROSE_ASSERT(lower_bound);
5847 ROSE_ASSERT(upper_bound);
5848 ROSE_ASSERT(stride);
5849
5850 SgSubscriptExpression* subscript = new SgSubscriptExpression(lower_bound, upper_bound, stride);
5851 ROSE_ASSERT(subscript);
5853
5854 // Set the parents of all the parts of the SgSubscriptExpression
5855 lower_bound->set_parent(subscript);
5856 upper_bound->set_parent(subscript);
5857 stride ->set_parent(subscript);
5858
5859 return subscript;
5860 }
5861
5864 {
5865 ROSE_ASSERT(initname);
5866 if (scope == NULL)
5868
5869 SgVarRefExp *varRef = NULL;
5870 // there is assertion for get_scope() != NULL in get_symbol_from_symbol_table()
5871 SgSymbol* symbol = NULL;
5872 if (initname->get_scope()!=NULL)
5873 symbol = initname->get_symbol_from_symbol_table ();
5874
5875 if (symbol != NULL)
5876 {
5877 varRef = new SgVarRefExp(isSgVariableSymbol(symbol));
5879 ROSE_ASSERT(varRef);
5880 }
5881 else
5882 {
5883 varRef = buildVarRefExp(initname->get_name(), scope);
5884 }
5885
5886 return varRef;
5887 }
5888
5891{
5892 SgName name(varName);
5893 return buildVarRefExp(name,scope);
5894}
5895
5897SageBuilder::buildVarRefExp(const std::string& varName, SgScopeStatement* scope)
5898{
5899 SgName name(varName);
5900 return buildVarRefExp(name,scope);
5901}
5902
5905 {
5906 if (scope == NULL)
5908
5909 SgSymbol* symbol = NULL;
5910 SgVariableSymbol* varSymbol = NULL;
5911
5912 if (scope != NULL)
5913 {
5914 // DQ (12/30/2011): This is a bad idea for C++ since qualified names might indicate different scopes.
5915 // If the scope has been provided then is should be the correct scope.
5916
5917 // DQ (8/16/2013): Modified to use the new API supporting template parameters and template arguments, however
5918 // this should more likely be using lookupVariableSymbolInParentScopes() instead of lookupSymbolInParentScopes().
5919 symbol = lookupVariableSymbolInParentScopes(name,scope);
5920 }
5921
5922 if (symbol != NULL)
5923 {
5924 varSymbol = isSgVariableSymbol(symbol);
5925 }
5926 else
5927 {
5928 // if not found: put fake init name and symbol here and
5929 // waiting for a postProcessing phase to clean it up
5930 // two features: no scope and unknown type for initializedName
5932 name1->set_scope(scope); // buildInitializedName() does not set scope for various reasons
5933 name1->set_parent(scope);
5934 varSymbol = new SgVariableSymbol(name1);
5935 varSymbol->set_parent(scope);
5936 }
5937
5938 if (varSymbol == NULL)
5939 {
5940 printf ("Error: varSymbol == NULL for name = %s \n",name.str());
5941 }
5942 ROSE_ASSERT(varSymbol != NULL);
5943
5944 SgVarRefExp *varRef = new SgVarRefExp(varSymbol);
5946 ROSE_ASSERT(varRef != NULL);
5947
5948 ROSE_ASSERT (isSgVariableSymbol(varRef->get_symbol())->get_declaration()!=NULL);
5949
5950 return varRef;
5951 }
5952
5956 {
5957 SgVariableSymbol* symbol = getFirstVarSym(vardecl);
5958 ROSE_ASSERT(symbol);
5959
5960 return buildVarRefExp(symbol);
5961 }
5962
5963
5966 {
5967 SgVarRefExp *varRef = new SgVarRefExp(sym);
5968 ROSE_ASSERT(varRef);
5969
5971
5972 return varRef;
5973 }
5974
5977 {
5978 SgVarRefExp *varRef = new SgVarRefExp(sym);
5979 ROSE_ASSERT(varRef);
5980
5982
5983 return varRef;
5984 }
5985
5988 {
5989 SgNonrealRefExp * refexp = new SgNonrealRefExp(sym);
5990 ROSE_ASSERT(refexp != NULL);
5992 return refexp;
5993 }
5994
5996
5999SageBuilder::buildOpaqueVarRefExp(const std::string& name,SgScopeStatement* scope/* =NULL */)
6000 {
6001 SgVarRefExp *result = NULL;
6002
6003 if (scope == NULL)
6005 ROSE_ASSERT(scope != NULL);
6006
6007 // DQ (8/16/2013): Modified to use the new API supporting template parameters and template arguments, however
6008 // this should more likely be using lookupVariableSymbolInParentScopes() instead of lookupSymbolInParentScopes().
6009 // SgSymbol * symbol = lookupSymbolInParentScopes(name,scope);
6010 SgSymbol * symbol = lookupVariableSymbolInParentScopes(name,scope);
6011
6012 if (symbol)
6013 {
6014 // Can be the same opaque var ref built before
6015 // cerr<<"Error: trying to build an opaque var ref when the variable is actual explicit!"<<endl;
6016 ROSE_ASSERT(isSgVariableSymbol(symbol));
6017 result = buildVarRefExp(isSgVariableSymbol(symbol));
6018 }
6019 else
6020 {
6021 SgVariableDeclaration* fakeVar = buildVariableDeclaration(name, buildIntType(),NULL, scope);
6022 Sg_File_Info* file_info = fakeVar->get_file_info();
6023
6024 // TGWE (7/16/2014): on the advice of DQ who doesn't like the function at all
6025 fakeVar->set_parent(scope);
6026
6027 file_info->unsetOutputInCodeGeneration ();
6028 SgVariableSymbol* fakeSymbol = getFirstVarSym (fakeVar);
6029 result = buildVarRefExp(fakeSymbol);
6030 }
6031
6032 return result;
6033 } // buildOpaqueVarRefExp()
6034
6035
6036// DQ (9/4/2013): Added support for building compound literals (similar to a SgVarRefExp).
6040 {
6041 SgCompoundLiteralExp *compoundLiteral = new SgCompoundLiteralExp(varSymbol);
6042 ROSE_ASSERT(compoundLiteral != NULL);
6043
6044 setOneSourcePositionNull(compoundLiteral);
6045
6046 return compoundLiteral;
6047 }
6048
6049// DQ (9/4/2013): Added support for building compound literals (similar to a SgVarRefExp).
6053 {
6054 SgCompoundLiteralExp *compoundLiteral = new SgCompoundLiteralExp(varSymbol);
6055 ROSE_ASSERT(compoundLiteral != NULL);
6056
6058
6059 return compoundLiteral;
6060 }
6061
6062
6065{
6066 SgLabelRefExp * result= NULL;
6067 ROSE_ASSERT (s!= NULL);
6068 result = new SgLabelRefExp(s);
6069 ROSE_ASSERT (result != NULL);
6071 return result;
6072}
6073
6076{
6078 if (paraTypeList==NULL) return paraList;
6079
6080 SgTypePtrList typeList = paraTypeList->get_arguments();
6081 SgTypePtrList::iterator i;
6082 for (i=typeList.begin();i!=typeList.end();i++)
6083 {
6085 appendArg(paraList,arg);
6086 }
6087
6088 return paraList;
6089}
6090
6093{
6095 ROSE_ASSERT (paraList);
6096 SgTypePtrList typeList = paraTypeList->get_arguments();
6097 SgTypePtrList::iterator i;
6098 for (i=typeList.begin();i!=typeList.end();i++)
6099 {
6101 appendArg(paraList,arg);
6102 }
6103 return paraList;
6104}
6105
6106// lookup function symbol to create a reference to it
6108SageBuilder::buildFunctionRefExp(const SgName& name,const SgType* funcType, SgScopeStatement* scope /*=NULL*/)
6109{
6110 ASSERT_not_null(funcType); // function type cannot be NULL
6111 SgFunctionType* func_type = isSgFunctionType(const_cast<SgType*>(funcType));
6112 ASSERT_not_null(func_type);
6113
6114 bool isMemberFunc = isSgMemberFunctionType(func_type);
6115
6116 if (scope == nullptr) {
6118 }
6119 ASSERT_not_null(scope);
6120 SgFunctionSymbol* symbol = lookupFunctionSymbolInParentScopes(name,func_type,scope);
6121 if (symbol == nullptr)
6122 // in rare cases when function calls are inserted before any prototypes exist
6123 {
6124 SgType* return_type = func_type->get_return_type();
6125 SgFunctionParameterTypeList * paraTypeList = func_type->get_argument_list();
6126 SgFunctionParameterList *parList = buildFunctionParameterList(paraTypeList);
6127
6128 SgGlobal* globalscope = getGlobalScope(scope);
6129
6130 ASSERT_require(isMemberFunc == false); // Liao, 11/21/2012. We assume only regular functions can go into this if-body so we can insert them into global scope by default
6131
6132 // TODO: consider C++ template functions
6133 SgFunctionDeclaration * funcDecl = nullptr;
6135 {
6136 funcDecl = buildNondefiningFunctionDeclaration_T
6137 <SgProcedureHeaderStatement>(name,return_type,parList,false,globalscope,nullptr,false,nullptr,nullptr,SgStorageModifier::e_default);
6138 }
6139 else
6140 {
6141 funcDecl = buildNondefiningFunctionDeclaration_T
6142 <SgFunctionDeclaration>(name,return_type,parList,false,globalscope,nullptr,false,nullptr,nullptr,SgStorageModifier::e_default);
6143 }
6144
6145 funcDecl->get_declarationModifier().get_storageModifier().setExtern();
6146
6147 symbol = lookupFunctionSymbolInParentScopes(name,func_type,scope);
6148 ASSERT_not_null(symbol);
6149 }
6150 SgFunctionRefExp* func_ref = new SgFunctionRefExp(symbol,func_type);
6152
6153 ASSERT_not_null(func_ref);
6154 return func_ref;
6155}
6156
6158SageBuilder::buildFunctionRefExp(const char* name,const SgType* funcType, SgScopeStatement* scope /*=NULL*/)
6159{
6160 SgName name2(name);
6161 return buildFunctionRefExp(name2,funcType,scope);
6162}
6163
6164// lookup function symbol to create a reference to it
6167{
6168 ROSE_ASSERT(func_decl != NULL);
6169 SgDeclarationStatement* nondef_func = func_decl->get_firstNondefiningDeclaration ();
6170 SgDeclarationStatement* def_func = func_decl->get_definingDeclaration ();
6171 SgSymbol* symbol = NULL;
6172 if (nondef_func != NULL)
6173 {
6174 ROSE_ASSERT(nondef_func!= NULL);
6175 symbol = nondef_func->get_symbol_from_symbol_table();
6176 ROSE_ASSERT( symbol != NULL);
6177 }
6178 // Liao 12/1/2010. It is possible that there is no prototype declarations at all
6179 else if (def_func != NULL)
6180 {
6181 symbol = def_func->get_symbol_from_symbol_table();
6182 }
6183 else
6184 {
6185 std::cerr<<"Fatal error: SageBuilder::buildFunctionRefExp():defining and nondefining declarations for a function cannot be both NULL"<<std::endl;
6186 ROSE_ABORT ();
6187 }
6188 ROSE_ASSERT( symbol != NULL);
6189 return buildFunctionRefExp( isSgFunctionSymbol (symbol));
6190}
6191
6192
6193// lookup function symbol to create a reference to it
6196{
6197 SgFunctionRefExp* func_ref = new SgFunctionRefExp(sym, NULL);
6199 ROSE_ASSERT(func_ref);
6200 return func_ref;
6201}
6202
6203// lookup function symbol to create a reference to it
6206{
6207 SgFunctionRefExp* func_ref = new SgFunctionRefExp(sym, NULL);
6208 setOneSourcePositionNull(func_ref);
6209 ROSE_ASSERT(func_ref);
6210 return func_ref;
6211}
6212
6213// DQ (12/15/2011): Adding template declaration support to the AST.
6216 {
6217 // DQ (2/23/2013): Added assertion.
6218 ROSE_ASSERT(sym != NULL);
6219
6221 ROSE_ASSERT(func_ref != NULL);
6222
6223 setOneSourcePositionNull(func_ref);
6224
6225 // DQ (2/23/2013): Added assertion.
6226 ROSE_ASSERT(func_ref->get_symbol() != NULL);
6227
6228 return func_ref;
6229 }
6230
6231// DQ (12/29/2011): Adding template declaration support to the AST.
6234 {
6235 SgTemplateMemberFunctionRefExp* func_ref = new SgTemplateMemberFunctionRefExp(sym, virtual_call, need_qualifier);
6236 setOneSourcePositionNull(func_ref);
6237 ROSE_ASSERT(func_ref);
6238 return func_ref;
6239 }
6240
6241// lookup member function symbol to create a reference to it
6243SageBuilder::buildMemberFunctionRefExp_nfi(SgMemberFunctionSymbol* sym, bool virtual_call, bool need_qualifier)
6244{
6245 SgMemberFunctionRefExp* func_ref = new SgMemberFunctionRefExp(sym, virtual_call, NULL, need_qualifier);
6246 setOneSourcePositionNull(func_ref);
6247 ROSE_ASSERT(func_ref);
6248 return func_ref;
6249}
6250
6251// lookup member function symbol to create a reference to it
6253SageBuilder::buildMemberFunctionRefExp(SgMemberFunctionSymbol* sym, bool virtual_call, bool need_qualifier)
6254{
6255 SgMemberFunctionRefExp* func_ref = new SgMemberFunctionRefExp(sym, virtual_call, NULL, need_qualifier);
6257 ROSE_ASSERT(func_ref);
6258 return func_ref;
6259}
6260
6261// lookup class symbol to create a reference to it
6264{
6265 SgClassNameRefExp* class_ref = new SgClassNameRefExp(sym);
6266 setOneSourcePositionNull(class_ref);
6267 ROSE_ASSERT(class_ref);
6268 return class_ref;
6269}
6270
6273{
6274 SgClassNameRefExp* class_ref = new SgClassNameRefExp(sym);
6276 ROSE_ASSERT(class_ref);
6277 return class_ref;
6278}
6279
6283{
6284 if (scope == NULL)
6286 ROSE_ASSERT(scope != NULL);
6288
6289 if (symbol==NULL)
6290// in rare cases when function calls are inserted before any prototypes exist
6291 {
6292// assume int return type, and empty parameter list
6293
6294#if 1
6295// DQ (7/26/2012): I am at least temporarily removing this function from the API.
6296// Later if we need it, we can update it to reflect that passing of the new
6297// SgTemplateArgumentPtrList function parameter (part of the new API design).
6298
6299 SgFunctionDeclaration* funcDecl = NULL;
6300 printf ("Error: buildFunctionRefExp(): This function should not be used! \n");
6301 ROSE_ABORT();
6302#else
6303 SgType* return_type = buildIntType();
6305
6306 SgGlobal* globalscope = getGlobalScope(scope);
6307
6308 SgFunctionDeclaration * funcDecl = buildNondefiningFunctionDeclaration(name,return_type,parList,globalscope);
6309#endif
6310
6311 funcDecl->get_declarationModifier().get_storageModifier().setExtern();
6312
6313 symbol = lookupFunctionSymbolInParentScopes(name,scope);
6314 ROSE_ASSERT(symbol);
6315 }
6316
6317 SgFunctionRefExp* func_ref = buildFunctionRefExp(symbol);
6319
6320 ROSE_ASSERT(func_ref);
6321 return func_ref;
6322}
6323
6325SageBuilder::buildFunctionRefExp(const char* name, SgScopeStatement* scope /*=NULL*/)
6326{
6327 SgName name2(name);
6328 return buildFunctionRefExp(name2,scope);
6329}
6330
6331
6334{
6335 SgExprStatement* expStmt = new SgExprStatement(exp);
6336 ROSE_ASSERT(expStmt);
6337 if (exp) exp->set_parent(expStmt);
6339 return expStmt;
6340}
6341
6344{
6345 SgExprStatement* expStmt = new SgExprStatement(exp);
6346 ROSE_ASSERT(expStmt);
6347 if (exp) exp->set_parent(expStmt);
6348 setOneSourcePositionNull(expStmt);
6349 return expStmt;
6350}
6351
6352// DQ (3/27/2015): Added support for SgStatementExpression.
6355{
6356 SgStatementExpression* expStmt = new SgStatementExpression(exp);
6357 ROSE_ASSERT(expStmt);
6358 if (exp) exp->set_parent(expStmt);
6360
6361 return expStmt;
6362}
6363
6364// DQ (3/27/2015): Added support for SgStatementExpression.
6367{
6368 SgStatementExpression* expStmt = new SgStatementExpression(exp);
6369 ROSE_ASSERT(expStmt);
6370 if (exp) exp->set_parent(expStmt);
6371 setOneSourcePositionNull(expStmt);
6372
6373 return expStmt;
6374}
6375
6377SageBuilder::buildFunctionCallExp(const SgName& name, SgType* return_type, SgExprListExp* parameters/*=NULL*/, SgScopeStatement* scope/*=NULL*/)
6378 {
6379 if (scope == nullptr) {
6381 }
6382 ASSERT_not_null(scope);
6383
6384 if (parameters == nullptr) {
6385 parameters = buildExprListExp();
6386 }
6387
6389 SgFunctionType * func_type = buildFunctionType(return_type,typeList);
6390 SgFunctionRefExp* func_ref = buildFunctionRefExp(name,func_type,scope);
6391 SgFunctionCallExp * func_call_expr = new SgFunctionCallExp(func_ref,parameters,func_ref->get_type());
6392 parameters->set_parent(func_call_expr);
6393
6395 ASSERT_not_null(func_call_expr);
6396
6397 return func_call_expr;
6398 }
6399
6400
6403 SgExprListExp* parameters/*=NULL*/)
6404 {
6405 ROSE_ASSERT (sym != NULL);
6406 if (parameters == NULL)
6407 parameters = buildExprListExp();
6408 ROSE_ASSERT (parameters != NULL);
6409
6410 // DQ (8/21/2011): We want to preserve the support for member functions to be built as SgMemberFunctionRefExp.
6411 // This is important for the Java support and the C++ support else we will be lowering all mmember function calls
6412 // to function calls which will be a proble for eht analysis of object oriented languages.
6413 SgFunctionCallExp * func_call_expr = NULL;
6414 SgMemberFunctionSymbol* memberFunctionSymbol = isSgMemberFunctionSymbol(sym);
6415 if (memberFunctionSymbol != NULL)
6416 {
6417 // Note that we can't at this point be sure this is not a virtual function.
6418 bool virtual_call = false;
6419
6420 // Name qualificaiton is handled separately from the setting of this variable (old API).
6421 bool need_qualifier = false;
6422
6423 SgMemberFunctionRefExp* member_func_ref = buildMemberFunctionRefExp(memberFunctionSymbol,virtual_call,need_qualifier);
6424 func_call_expr = new SgFunctionCallExp(member_func_ref,parameters,member_func_ref->get_type());
6425 member_func_ref->set_parent(func_call_expr);
6426 }
6427 else
6428 {
6429 SgFunctionRefExp * func_ref = buildFunctionRefExp(sym);
6430 func_call_expr = new SgFunctionCallExp(func_ref,parameters,func_ref->get_type());
6431 func_ref->set_parent(func_call_expr);
6432 }
6433
6434
6435 parameters->set_parent(func_call_expr);
6436
6438
6439 ROSE_ASSERT(func_call_expr);
6440 return func_call_expr;
6441 }
6442
6445 {
6446 ROSE_ASSERT(f != NULL);
6447 SgFunctionCallExp* func_call_expr = new SgFunctionCallExp(f,parameters,f->get_type());
6448 ROSE_ASSERT(func_call_expr != NULL);
6449
6450 if (f != NULL) {
6451 f->set_parent(func_call_expr);
6452 }
6453 if (parameters != NULL) {
6454 parameters->set_parent(func_call_expr);
6455 }
6456 setOneSourcePositionNull(func_call_expr);
6457
6458 return func_call_expr;
6459 }
6460
6463 {
6464 ROSE_ASSERT(f != NULL);
6465 SgFunctionCallExp * func_call_expr = new SgFunctionCallExp(f,parameters,f->get_type());
6466 ROSE_ASSERT(func_call_expr != NULL);
6467
6468 if (f) f->set_parent(func_call_expr);
6469 if (parameters) parameters->set_parent(func_call_expr);
6471
6472 return func_call_expr;
6473 }
6474
6477 SgType* return_type,
6478 SgExprListExp* parameters /*= NULL*/,
6479 SgScopeStatement* scope /*=NULL*/)
6480{
6481 if (scope == NULL)
6483 ROSE_ASSERT(scope != NULL);
6484 SgFunctionCallExp* func_call_expr = buildFunctionCallExp(name,return_type,parameters,scope);
6485 SgExprStatement * expStmt = buildExprStatement(func_call_expr);
6486 return expStmt;
6487}
6488
6492{
6493 SgFunctionCallExp* func_call_expr = buildFunctionCallExp(function_exp, parameters);
6494 SgExprStatement * expStmt = buildExprStatement(func_call_expr);
6495 return expStmt;
6496}
6497
6498
6500
6508 SgExpression* objectExpression,
6509 std::string functionName,
6510 SgExprListExp* params,
6511 SgScopeStatement* scope
6512 )
6513{
6514 SgClassSymbol* classSymbol = SageInterface::lookupClassSymbolInParentScopes(className, scope);
6515 ROSE_ASSERT(classSymbol);
6516
6517 SgDeclarationStatement* classDecl = classSymbol->get_declaration()->get_definingDeclaration();
6518 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classDecl);
6519 ROSE_ASSERT(classDeclaration != NULL);
6520
6521 SgClassDefinition* classDefinition = classDeclaration->get_definition();
6522 ROSE_ASSERT(classDefinition);
6523
6524 SgSymbol* funsy = lookupFunctionSymbolInParentScopes(functionName, classDefinition);
6525 SgMemberFunctionSymbol* functionSymbol = isSgMemberFunctionSymbol(funsy);
6526 ROSE_ASSERT(functionSymbol);
6527
6528 SgMemberFunctionRefExp* memref = buildMemberFunctionRefExp(functionSymbol, false, false);
6529
6530 return buildFunctionCallExp(buildDotExp(objectExpression, memref), params);
6531}
6532
6533// with known varRef and mem function symbol : a.size()
6535 SgExprListExp* params)
6536{
6537 SgMemberFunctionRefExp* memref = SageBuilder::buildMemberFunctionRefExp(functionSymbol, false, false);
6538 return SageBuilder::buildFunctionCallExp(SageBuilder::buildDotExp(objectExpression, memref), params);
6539}
6540
6542SageBuilder::buildTypeTraitBuiltinOperator(SgName functionName, SgNodePtrList parameters)
6543 {
6544 // DQ (7/14/2013): This is supporting compiler extensions that are required to support type traits in C++.
6545 // These operators are used increasingly in newer versions of GNU and other compilers. They are builtin
6546 // compiler extensions that typically take types as arguments.
6547
6548 SgTypeTraitBuiltinOperator * builtin_func_call_expr = new SgTypeTraitBuiltinOperator(functionName);
6549 ROSE_ASSERT(builtin_func_call_expr != NULL);
6550
6551 SgNodePtrList & args = builtin_func_call_expr->get_args();
6552 for (SgNodePtrList::iterator it = parameters.begin(); it != parameters.end(); ++it) {
6553 args.push_back(*it);
6554 (*it)->set_parent(builtin_func_call_expr);
6555 }
6556
6557 return builtin_func_call_expr;
6558 }
6559
6560
6563 {
6564 ROSE_ASSERT(kernel);
6565 ROSE_ASSERT(parameters);
6566 ROSE_ASSERT(config);
6567
6568 // DQ (1/19/2016): Adding template function ref support.
6569 SgFunctionRefExp * func_ref_exp = isSgFunctionRefExp(kernel);
6570 SgTemplateFunctionRefExp * template_func_ref_exp = isSgTemplateFunctionRefExp(kernel);
6571 if (func_ref_exp == NULL && template_func_ref_exp == NULL)
6572 {
6573 std::cerr << "SgCudaKernelCallExp accept only direct reference to a function. Got, " << typeid(*kernel).name()
6574 << " with, " << kernel->unparseToString() << std::endl;
6575
6576 // PP (7/1/19): experimental support for RAJA/CUDA Lulesh codes (producing SgNonrealRefExp) **1
6577 // was: ROSE_ASSERT(false);
6578 }
6579 // DQ (1/19/2016): Adding template function ref support.
6580 else if ( (func_ref_exp != NULL && func_ref_exp->get_symbol_i()->get_declaration()->get_functionModifier().isCudaKernel() == false) &&
6581 (template_func_ref_exp != NULL && template_func_ref_exp->get_symbol_i()->get_declaration()->get_functionModifier().isCudaKernel() == false) )
6582 {
6583 std::cerr << "To build a SgCudaKernelCallExp the callee needs to be a kernel (having \"__global__\" attribute)." << std::endl;
6584 ROSE_ABORT();
6585 }
6586
6587 SgCudaKernelCallExp * kernel_call_expr = new SgCudaKernelCallExp(kernel, parameters, kernel->get_type(), config);
6588
6589 kernel->set_parent(kernel_call_expr);
6590 parameters->set_parent(kernel_call_expr);
6591 config->set_parent(kernel_call_expr);
6592
6593 setOneSourcePositionNull(kernel_call_expr);
6594
6595 ROSE_ASSERT(kernel_call_expr);
6596
6597 return kernel_call_expr;
6598 }
6599
6602 if (!grid || !blocks) {
6603 std::cerr << "SgCudaKernelExecConfig need fields 'grid' and 'blocks' to be set." << std::endl;
6604 ROSE_ABORT();
6605 }
6606
6607 // TODO-CUDA check types
6608
6609 SgCudaKernelExecConfig * config = new SgCudaKernelExecConfig (grid, blocks, shared, stream);
6610
6611 grid->set_parent(config);
6612 blocks->set_parent(config);
6613 if (shared)
6614 shared->set_parent(config);
6615 if (stream)
6616 stream->set_parent(config);
6617
6619
6620 ROSE_ASSERT(config);
6621
6622 return config;
6623}
6624
6627//SageBuilder::buildAssignStatement(SgExpression* lhs,SgExpression* rhs, SgScopeStatement* scope=NULL)
6628{
6629 ROSE_ASSERT(lhs != NULL);
6630 ROSE_ASSERT(rhs != NULL);
6631
6632 //SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,lhs->get_type());
6633// SgBinaryOp::get_type() assume p_expression_type is not set
6634 SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,NULL);
6635 ROSE_ASSERT(assignOp);
6637 lhs->set_parent(assignOp);
6638 rhs->set_parent(assignOp);
6639
6640 lhs->set_lvalue (true);
6641 SgExprStatement* exp = new SgExprStatement(assignOp);
6642 ROSE_ASSERT(exp);
6643 // some child nodes are transparently generated, using recursive setting is safer
6645 //setOneSourcePositionForTransformation(exp);
6646 assignOp->set_parent(exp);
6647 return exp;
6648}
6649
6650// DQ (8/16/2011): This is an AST translate specific version (see note below).
6651// We would like to phase out the version above if possible (but we want to
6652// test this later).
6655{
6656 ROSE_ASSERT(lhs != NULL);
6657 ROSE_ASSERT(rhs != NULL);
6658
6659 //SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,lhs->get_type());
6660// SgBinaryOp::get_type() assume p_expression_type is not set
6661 SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,NULL);
6662 ROSE_ASSERT(assignOp);
6664 lhs->set_parent(assignOp);
6665 rhs->set_parent(assignOp);
6666
6667 lhs->set_lvalue (true);
6668 SgExprStatement* exp = new SgExprStatement(assignOp);
6669 ROSE_ASSERT(exp);
6670
6671// DQ (8/16/2011): Modified to avoid recursive call to reset source position information
6672// (this version is required for the Java support where we have set source code position
6673// information on the lhs and rhs and we don't want it to be reset as a transformation.
6674// some child nodes are transparently generated, using recursive setting is safer
6676 assignOp->set_parent(exp);
6677 return exp;
6678}
6679
6680
6682{
6683 if (scope == NULL)
6685
6686 // should including current scope when searching for the function definition
6687 // since users can only pass FunctionDefinition when the function body is not yet attached
6688 SgLabelStatement * labelstmt = new SgLabelStatement(name,stmt);
6689 ROSE_ASSERT(labelstmt);
6691
6692 if(stmt!=NULL)
6693 stmt->set_parent(labelstmt);
6694
6695 // Liao 1/7/2010
6696 // SgLabelStatement is used for CONTINUE statement in Fortran
6697 // In this case , it has no inherent association with a Label symbol.
6698 // It is up to the SageInterface::setNumericalLabel(SgStatement*) to handle label symbol
6700 fixLabelStatement(labelstmt,scope);
6701 // we don't want to set parent here yet
6702 // delay it until append_statement() or alike
6703 return labelstmt;
6704}
6705
6707{
6708 SgLabelStatement* labelStmt = new SgLabelStatement(name,stmt);
6709 ASSERT_not_null(labelStmt);
6711
6712 if (stmt != nullptr) {
6713 stmt->set_parent(labelStmt);
6714 }
6715 if (scope) {
6716 fixLabelStatement(labelStmt,scope);
6717 }
6718
6719 // we don't want to set parent here yet
6720 // delay it until append_statement() or alike
6721 return labelStmt;
6722}
6723
6724SgIfStmt * SageBuilder::buildIfStmt(SgStatement* conditional, SgStatement * true_body, SgStatement * false_body)
6725{
6726 ROSE_ASSERT(conditional);
6727 ROSE_ASSERT(true_body);
6728 SgIfStmt *ifstmt = new SgIfStmt(conditional, true_body, false_body);
6729 ROSE_ASSERT(ifstmt);
6730
6731 // CR (3/22/2020): Fixed setting case insensitivity
6732 // if (symbol_table_case_insensitive_semantics == true)
6734 ifstmt->setCaseInsensitive(true);
6735
6737 conditional->set_parent(ifstmt);
6738 true_body->set_parent(ifstmt);
6739 if (false_body != NULL) false_body->set_parent(ifstmt);
6740
6742 {
6743 // Liao 1/20/2010
6744 // According to Fortran 77 standard Chapter 11.5 to 11.9,
6745 // this is a Fortran Block IF statement, if the true body is:
6746 // 1. A block of statement under SgBasicBlock
6747 // 2. DO, block if, or another logical if
6748 // Otherwise it is a logical if statement
6749 if (isSgBasicBlock(true_body)|| isSgFortranDo(true_body)|| isSgIfStmt(true_body))
6750 {
6751 ifstmt->set_use_then_keyword(true);
6752 ifstmt->set_has_end_statement(true);
6753 }
6754 }
6755
6756 return ifstmt;
6757}
6758
6760 {
6761 SgIfStmt *ifstmt = new SgIfStmt(conditional, true_body, false_body);
6762 ROSE_ASSERT(ifstmt);
6763 // DQ (2/13/2012): This allows us to separate the construction from the initialization (see note below).
6764 initializeIfStmt(ifstmt,conditional,true_body,false_body);
6765 return ifstmt;
6766 }
6767
6768// Rasmussen (9/3/2018): Added build function for a Fortran do construct
6770{
6771 if (initialization == nullptr) initialization = buildNullExpression();
6772 if (bound == nullptr) bound = buildNullExpression();
6773 if (increment == nullptr) increment = buildNullExpression();
6774 if (loopBody == nullptr) loopBody = buildBasicBlock();
6775
6776 SgFortranDo* result = new SgFortranDo(initialization, bound, increment, loopBody);
6777 ASSERT_not_null(result);
6778
6780 result->setCaseInsensitive(true);
6781 }
6782
6784
6785 initialization->set_parent(result);
6786 bound->set_parent(result);
6787 increment->set_parent(result);
6788 loopBody->set_parent(result);
6789
6790 return result;
6791}
6792
6794{
6795 if (initialization == nullptr) initialization = buildNullExpression_nfi();
6796 if (bound == nullptr) bound = buildNullExpression_nfi();
6797 if (increment == nullptr) increment = buildNullExpression_nfi();
6798 if (loopBody == nullptr) loopBody = buildBasicBlock_nfi();
6799
6800 SgFortranDo* result = new SgFortranDo(initialization, bound, increment, loopBody);
6801 ASSERT_not_null(result);
6802
6804 result->setCaseInsensitive(true);
6805 }
6806
6808
6809 initialization->set_parent(result);
6810 bound->set_parent(result);
6811 increment->set_parent(result);
6812 loopBody->set_parent(result);
6813
6814 return result;
6815}
6816
6817// charles4 10/14/2011: Vanilla allocation. Use prepend_init_stmt and append_init_stmt to populate afterward.
6819 {
6820 // return new SgForInitStatement();
6821 SgForInitStatement* result = new SgForInitStatement();
6822
6823 // DQ (11/3/2012): Added call to set file info to default settings.
6824 setSourcePosition(result);
6825
6826 return result;
6827 }
6828
6829// DQ (10/12/2012): Added specific API to handle simple (single) statement.
6832 {
6833 SgForInitStatement* forInit = new SgForInitStatement();
6834 ROSE_ASSERT(forInit != NULL);
6835
6836 ROSE_ASSERT(statement != NULL);
6837 forInit->append_init_stmt(statement);
6838
6839 // DQ (11/3/2012): Added call to set file info to default settings.
6840 setSourcePosition(forInit);
6841
6842 return forInit;
6843 }
6844
6845SgForInitStatement * SageBuilder::buildForInitStatement(const SgStatementPtrList & statements)
6846{
6847 SgForInitStatement * result = new SgForInitStatement();
6848 result->get_init_stmt() = statements;
6849
6850 for (SgStatementPtrList::iterator it = result->get_init_stmt().begin(); it != result->get_init_stmt().end(); it++)
6851 (*it)->set_parent(result);
6852
6854 return result;
6855}
6856
6858SageBuilder::buildForInitStatement_nfi(SgStatementPtrList & statements)
6859 {
6860 SgForInitStatement * result = new SgForInitStatement();
6861
6862 result->get_init_stmt() = statements;
6863
6864 for (SgStatementPtrList::iterator it = result->get_init_stmt().begin(); it != result->get_init_stmt().end(); it++)
6865 {
6866 (*it)->set_parent(result);
6867 }
6868
6869 // DQ (11/3/2012): Added call to set file info to default settings.
6870 setSourcePosition(result);
6871
6872 return result;
6873 }
6874
6876//Liao, 8/27/2008
6877SgForStatement * SageBuilder::buildForStatement(SgStatement* initialize_stmt, SgStatement * test, SgExpression * increment, SgStatement * loop_body, SgStatement * else_body)
6878{
6879 SgForStatement * result = new SgForStatement(test,increment, loop_body);
6880 ROSE_ASSERT(result);
6881
6883 result->setCaseInsensitive(true);
6884
6886 if (test)
6887 test->set_parent(result);
6888 if (loop_body)
6889 loop_body->set_parent(result);
6890 if (increment)
6891 increment->set_parent(result);
6892
6893 if (else_body)
6894 else_body->set_parent(result);
6895 result->set_else_body(else_body);
6896
6897 // CH (5/13/2010): If the initialize_stmt is an object of SgForInitStatement, we can directly put it
6898 // into for statement. Or else, there will be two semicolons after unparsing.
6899 if (SgForInitStatement* for_init_stmt = isSgForInitStatement(initialize_stmt))
6900 {
6901 // DQ (7/30/2011): We have to delete the the SgForInitStatement build within the SgForStatement::post_constructor_initialization()
6902 // to avoid causing errors in the AST consistancy checking later.
6903 if (result->get_for_init_stmt() != NULL)
6904 {
6905 delete result->get_for_init_stmt();
6906 result->set_for_init_stmt(NULL);
6907 }
6908
6909 result->set_for_init_stmt(for_init_stmt);
6910 for_init_stmt->set_parent(result);
6911 return result;
6912 }
6913
6914 SgForInitStatement* init_stmt = new SgForInitStatement();
6915 ROSE_ASSERT(init_stmt);
6917
6918 // DQ (7/30/2011): We have to delete the the SgForInitStatement build within the SgForStatement::post_constructor_initialization().
6919 // to avoid causeing errors in the AST consistancy checking later.
6920 if (result->get_for_init_stmt() != NULL)
6921 {
6922 delete result->get_for_init_stmt();
6923 result->set_for_init_stmt(NULL);
6924 }
6925
6926 result->set_for_init_stmt(init_stmt);
6927 init_stmt->set_parent(result);
6928
6929 if (initialize_stmt)
6930 {
6931 init_stmt->append_init_stmt(initialize_stmt);
6932 // Support for "for (int i=0; )", Liao, 3/11/2009
6933 // The symbols are inserted into the symbol table attached to SgForStatement
6934 if (isSgVariableDeclaration(initialize_stmt))
6935 {
6936 fixVariableDeclaration(isSgVariableDeclaration(initialize_stmt),result);
6937 // fix varRefExp to the index variable used in increment, conditional expressions
6938 fixVariableReferences(result);
6939 }
6940 }
6941
6942 return result;
6943 }
6944
6945
6947//Liao, 8/27/2008
6949SageBuilder::buildForStatement_nfi(SgStatement* initialize_stmt, SgStatement * test, SgExpression * increment, SgStatement * loop_body, SgStatement * else_body)
6950 {
6951 SgForStatement * result = new SgForStatement(test, increment, loop_body);
6952 ROSE_ASSERT(result);
6953
6954 // Rasmussen (3/22/2020): Fixed setting case insensitivity
6955 // if (symbol_table_case_insensitive_semantics == true)
6957 result->setCaseInsensitive(true);
6958
6960 if (test) test->set_parent(result);
6961 if (loop_body) loop_body->set_parent(result);
6962 if (increment) increment->set_parent(result);
6963 if (else_body) else_body->set_parent(result);
6964
6965 result->set_else_body(else_body);
6966
6967 if (initialize_stmt != NULL)
6968 {
6969 SgForInitStatement* init_stmt = result->get_for_init_stmt();
6970 ROSE_ASSERT(init_stmt);
6971 setOneSourcePositionNull(init_stmt);
6972 init_stmt->append_init_stmt(initialize_stmt);
6973 initialize_stmt->set_parent(init_stmt);
6974 }
6975
6976 return result;
6977 }
6978
6979
6982 {
6983 SgForStatement * result = new SgForStatement(init_stmt, test, increment, loop_body);
6984 ROSE_ASSERT(result != NULL);
6985
6986 // DQ (9/26/2012): Refactored this function to allow for where the SgForStatement had to be
6987 // constructed early to define the scope for types that can be defined in the SgForInitStatement.
6988 buildForStatement_nfi(result,init_stmt,test,increment,loop_body,else_body);
6989
6990 return result;
6991 }
6992
6993
6994void
6996 {
6997 // DQ (9/26/2012): Refactored this function to allow for where the SgForStatement had to be
6998 // constructed early to define the scope for types that can be defined in the SgForInitStatement.
6999
7000 ROSE_ASSERT(result != NULL);
7001
7002 // DQ (11/4/2012): I have added support for remove existing subtrees if they are different from what is provided as input.
7003 if (result->get_for_init_stmt() != NULL && init_stmt != result->get_for_init_stmt())
7004 {
7005 delete result->get_for_init_stmt();
7006 result->set_for_init_stmt(NULL);
7007 }
7008
7009 if (result->get_test() != NULL && test != result->get_test())
7010 {
7011 delete result->get_test();
7012 result->set_test(NULL);
7013 }
7014
7015 if (result->get_increment() != NULL && increment != result->get_increment())
7016 {
7017 delete result->get_increment();
7018 result->set_increment(NULL);
7019 }
7020
7021 if (result->get_loop_body() != NULL && loop_body != result->get_loop_body())
7022 {
7023 delete result->get_loop_body();
7024 result->set_loop_body(NULL);
7025 }
7026
7027 if (result->get_else_body() != NULL && else_body != result->get_else_body())
7028 {
7029 delete result->get_else_body();
7030 result->set_else_body(NULL);
7031 }
7032
7033 result->set_for_init_stmt(init_stmt);
7034 result->set_test(test);
7035 result->set_increment(increment);
7036 result->set_loop_body(loop_body);
7037
7039 result->setCaseInsensitive(true);
7040
7042 if (test) test->set_parent(result);
7043 if (loop_body) loop_body->set_parent(result);
7044 if (increment) increment->set_parent(result);
7045 if (init_stmt) init_stmt->set_parent(result);
7046 if (else_body) else_body->set_parent(result);
7047
7048 result->set_else_body(else_body);
7049
7050 ROSE_ASSERT(result->get_for_init_stmt() != NULL);
7051 ROSE_ASSERT(result->get_test() != NULL);
7052 ROSE_ASSERT(result->get_increment() != NULL);
7053 ROSE_ASSERT(result->get_loop_body() != NULL);
7054 }
7055
7056
7057// DQ (3/26/2018): Adding support for range based for statement.
7058// SgRangeBasedForStatement* SageBuilder::buildRangeBasedForStatement_nfi(SgVariableDeclaration* initializer, SgExpression* range, SgStatement* body)
7061 SgVariableDeclaration* initializer, SgVariableDeclaration* range,
7062 SgVariableDeclaration* begin_declaration, SgVariableDeclaration* end_declaration,
7063 SgExpression* not_equal_expression, SgExpression* increment_expression,
7064 SgStatement* body)
7065 {
7066 // DQ (6/26/2019): Commented these out so that we could build the SgRangeBasedForStatement before
7067 // building the children, since the scope of the chldren will be the SgRangeBasedForStatement and
7068 // it must exist before the children are constructed.
7069 // ROSE_ASSERT(initializer != NULL);
7070 // ROSE_ASSERT(range != NULL);
7071
7072 // DQ (6/26/2019): This was already commented out.
7073 // ROSE_ASSERT(body != NULL);
7074
7075 SgRangeBasedForStatement* result = new SgRangeBasedForStatement(initializer, range, begin_declaration, end_declaration, not_equal_expression, increment_expression, body);
7076 ROSE_ASSERT(result != NULL);
7077
7079
7080 if (initializer != NULL) initializer->set_parent(result);
7081 if (range != NULL) range->set_parent(result);
7082
7083 if (begin_declaration != NULL) begin_declaration->set_parent(result);
7084 if (end_declaration != NULL) end_declaration->set_parent(result);
7085
7086 if (not_equal_expression != NULL) not_equal_expression->set_parent(result);
7087 if (increment_expression != NULL) increment_expression->set_parent(result);
7088
7089 if (body != NULL) body->set_parent(result);
7090
7091 return result;
7092 }
7093
7094
7095void
7097 {
7098 // DQ (3/22/2014): This function has been built to support reusing an existing SgDoWhileStatement
7099 // that may have been built and pushed onto the stack as part of a top-down construction of the AST.
7100 // It is required in the EDG 4.8 useage because of a change from EDG 4.7 to 4.8 in how blocks are
7101 // handled (end-of-construct entries).
7102
7103 ASSERT_not_null(result);
7104 ASSERT_not_null(body);
7105 ASSERT_not_null(condition);
7106
7107 ASSERT_require(result->get_body() == nullptr);
7108 ASSERT_require(result->get_condition() == nullptr);
7109
7110 result->set_body(body);
7111 result->set_condition(condition);
7112
7113 body->set_parent(result);
7114 condition->set_parent(result);
7115
7117
7118 ASSERT_not_null(result->get_body());
7119 ASSERT_not_null(result->get_condition());
7120
7121 ASSERT_require(result->get_body()->get_parent() == result);
7122 ASSERT_require(result->get_condition()->get_parent() == result);
7123 }
7124
7125
7126
7128//Liao, 8/27/2008
7130{
7131 SgUpcForAllStatement * result = new SgUpcForAllStatement(test,increment, affinity, loop_body);
7132 ROSE_ASSERT(result);
7134 if (test) test->set_parent(result);
7135 if (loop_body) loop_body->set_parent(result);
7136 if (increment) increment->set_parent(result);
7137 if (affinity) affinity->set_parent(result);
7138
7139 if (initialize_stmt != NULL) {
7140 SgForInitStatement* init_stmt = result->get_for_init_stmt();
7141 ROSE_ASSERT(init_stmt);
7142 setOneSourcePositionNull(init_stmt);
7143 init_stmt->append_init_stmt(initialize_stmt);
7144 initialize_stmt->set_parent(init_stmt);
7145 }
7146
7147 return result;
7148}
7149
7150
7152{
7153 SgUpcForAllStatement * result = new SgUpcForAllStatement(init_stmt, test, increment, affinity, loop_body);
7154 ROSE_ASSERT(result);
7155
7156 // CR (3/22/2020): Fixed setting case insensitivity
7157 // if (symbol_table_case_insensitive_semantics == true)
7159 result->setCaseInsensitive(true);
7160
7162 if (test) test->set_parent(result);
7163 if (loop_body) loop_body->set_parent(result);
7164 if (increment) increment->set_parent(result);
7165 if (affinity) affinity->set_parent(result);
7166 if (init_stmt) init_stmt->set_parent(result);
7167
7168 return result;
7169}
7170
7171// DQ (3/3/2013): Added UPC specific build functions.
7174 {
7175 SgUpcNotifyStatement* result = new SgUpcNotifyStatement(exp);
7176
7178
7179 exp->set_parent(result);
7180
7181 ROSE_ASSERT(exp->get_parent() != NULL);
7182
7183 return result;
7184 }
7185
7188 {
7189 SgUpcWaitStatement* result = new SgUpcWaitStatement(exp);
7190
7192
7193 exp->set_parent(result);
7194
7195 ROSE_ASSERT(exp->get_parent() != NULL);
7196
7197 return result;
7198 }
7199
7202 {
7204
7206
7207 exp->set_parent(result);
7208
7209 ROSE_ASSERT(exp->get_parent() != NULL);
7210
7211 return result;
7212 }
7213
7216 {
7218
7220
7221 return result;
7222 }
7223
7224
7225
7226
7228{
7229 ROSE_ASSERT(condition);
7230 ROSE_ASSERT(body);
7231 SgWhileStmt * result = new SgWhileStmt(condition,body);
7232 ROSE_ASSERT(result);
7233
7234 // CR (3/22/2020): Fixed setting case insensitivity
7235 // if (symbol_table_case_insensitive_semantics == true)
7237 result->setCaseInsensitive(true);
7238
7240 condition->set_parent(result);
7241 body->set_parent(result);
7242
7243// DQ (8/10/2011): This is added by Michael to support a Python specific feature.
7244 if (else_body != NULL) {
7245 result->set_else_body(else_body);
7246 else_body->set_parent(result);
7247 }
7248
7249 return result;
7250}
7251
7252
7255 {
7256 SgWhileStmt * result = new SgWhileStmt(condition,body);
7257 ROSE_ASSERT(result);
7258
7259#if 0
7260 // DQ (11/28/2010): Added specification of case insensitivity for Fortran.
7262 result->setCaseInsensitive(true);
7263
7265 if (condition) condition->set_parent(result);
7266 if (body) body->set_parent(result);
7267
7268 // DQ (8/10/2011): This is added by Michael to support a Python specific feature.
7269 if (else_body != NULL)
7270 {
7271 result->set_else_body(else_body);
7272 else_body->set_parent(result);
7273 }
7274#else
7275 // DQ (2/15/2012): This function supports the case where in C++ the condition can include a variable declaration.
7276 initializeWhileStatement(result,condition,body,else_body);
7277#endif
7278
7279 return result;
7280 }
7281
7282
7284{
7285 ROSE_ASSERT(expr != NULL && body != NULL);
7286 SgWithStatement* result = new SgWithStatement(expr, body);
7287 expr->set_parent(result);
7288 body->set_parent(result);
7289
7291 return result;
7292}
7293
7295{
7296 ROSE_ASSERT(expr != NULL && body != NULL);
7297 SgWithStatement* result = new SgWithStatement(expr, body);
7298 expr->set_parent(result);
7299 body->set_parent(result);
7300
7302 return result;
7303}
7304
7306{
7307 ROSE_ASSERT(condition);
7308 ROSE_ASSERT(body);
7309 SgDoWhileStmt * result = new SgDoWhileStmt(body, condition);
7310 ROSE_ASSERT(result);
7312 condition->set_parent(result);
7313 body->set_parent(result);
7314 return result;
7315}
7316
7318{
7319 SgDoWhileStmt * result = new SgDoWhileStmt(body, condition);
7320 ROSE_ASSERT(result);
7322 if (condition) condition->set_parent(result);
7323 if (body) body->set_parent(result);
7324 return result;
7325}
7326
7328{
7329 SgMatlabForStatement* result = new SgMatlabForStatement(loop_index, loop_range, loop_body);
7331
7332 ROSE_ASSERT(result != NULL);
7333
7334 loop_index->set_parent(result);
7335 loop_range->set_parent(result);
7336 loop_body->set_parent(result);
7337 return result;
7338}
7339
7341{
7342 SgBreakStmt* result = new SgBreakStmt();
7343 ROSE_ASSERT(result);
7345 return result;
7346}
7347
7349{
7350 SgBreakStmt* result = new SgBreakStmt();
7351 ROSE_ASSERT(result);
7353 return result;
7354}
7355
7357{
7358 SgContinueStmt* result = new SgContinueStmt();
7359 ASSERT_not_null(result);
7361 return result;
7362}
7363
7365{
7366 SgContinueStmt* result = new SgContinueStmt();
7367 ASSERT_not_null(result);
7369 return result;
7370}
7371
7373{
7375 ASSERT_not_null(result);
7377 return result;
7378}
7379
7381{
7383 ASSERT_not_null(result);
7385 return result;
7386}
7387
7389{
7390 SgPassStatement* result = new SgPassStatement();
7391 ROSE_ASSERT(result);
7393 return result;
7394}
7395
7397{
7398 SgPassStatement* result = new SgPassStatement();
7399 ROSE_ASSERT(result);
7401 return result;
7402}
7403
7404SgDeleteExp* SageBuilder::buildDeleteExp(SgExpression *target, bool is_array, bool need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
7405{
7406 SgDeleteExp *result = new SgDeleteExp(target, is_array, need_global_specifier, deleteOperatorDeclaration);
7407 target->set_parent(result);
7409 return result;
7410}
7411
7412SgDeleteExp* SageBuilder::buildDeleteExp_nfi(SgExpression *target, bool is_array, bool need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
7413{
7414 SgDeleteExp *result = new SgDeleteExp(target, is_array, need_global_specifier, deleteOperatorDeclaration);
7415 target->set_parent(result);
7417 return result;
7418}
7419
7421{
7422 SgAssertStmt* result = new SgAssertStmt(test);
7423 ROSE_ASSERT(test != NULL);
7424 test->set_parent(result);
7426 return result;
7427}
7428
7429// DQ (7/18/2011): Added support for SgJavaInstanceOfOp
7432 {
7433 SgType* exp_type = SgTypeBool::createType();
7434
7435 SgJavaInstanceOfOp* result = new SgJavaInstanceOfOp(exp, type, exp_type);
7436 ROSE_ASSERT(result);
7437 if (exp != NULL)
7438 {
7439 exp->set_parent(result);
7440 markLhsValues(result);
7441 }
7442
7444 return result;
7445 }
7446
7448{
7449 SgAssertStmt* result = new SgAssertStmt(test);
7450 ROSE_ASSERT(test != NULL);
7451 test->set_parent(result);
7452 if (exceptionArgument != NULL) {
7453 result -> set_exception_argument(exceptionArgument);
7454 exceptionArgument->set_parent(result);
7455 }
7457 return result;
7458}
7459
7461{
7462 SgAssertStmt* result = new SgAssertStmt(test);
7463 ROSE_ASSERT(test != NULL);
7464 test->set_parent(result);
7466 return result;
7467}
7468
7470{
7471 ROSE_ASSERT(value != NULL);
7472 SgYieldExpression* result = new SgYieldExpression(value);
7473 value->set_parent(result);
7475 return result;
7476}
7477
7479{
7480 ROSE_ASSERT(value != NULL);
7481 SgYieldExpression* result = new SgYieldExpression(value);
7482 value->set_parent(result);
7484 return result;
7485}
7486
7488{
7489 ROSE_ASSERT(key != NULL && datum != NULL);
7490 SgKeyDatumPair *result = new SgKeyDatumPair(key, datum);
7491 key->set_parent(result);
7492 datum->set_parent(result);
7494 return result;
7495}
7496
7498{
7499 ROSE_ASSERT(key != NULL && datum != NULL);
7500 SgKeyDatumPair *result = new SgKeyDatumPair(key, datum);
7501 key->set_parent(result);
7502 datum->set_parent(result);
7504 return result;
7505}
7506
7507SgDictionaryExp* SageBuilder::buildDictionaryExp(std::vector<SgKeyDatumPair*> pairs)
7508{
7509 SgDictionaryExp *result = new SgDictionaryExp();
7510 ROSE_ASSERT(result);
7511 for (size_t i = 0; i < pairs.size(); ++i)
7512 result->append_pair(pairs[i]);
7514 return result;
7515}
7516
7517SgDictionaryExp* SageBuilder::buildDictionaryExp_nfi(std::vector<SgKeyDatumPair*> pairs)
7518{
7519 SgDictionaryExp *result = new SgDictionaryExp();
7520 ROSE_ASSERT(result);
7521 for (size_t i = 0; i < pairs.size(); ++i)
7522 result->append_pair(pairs[i]);
7524 return result;
7525}
7526
7529{
7530 ROSE_ASSERT(target != NULL);
7531 ROSE_ASSERT(iter != NULL);
7532 SgComprehension *result = new SgComprehension(target, iter, ifs);
7533 ROSE_ASSERT(result);
7534
7535 target->set_parent(result);
7536 iter->set_parent(result);
7537 if (ifs != NULL) ifs->set_parent(result);
7538
7540 return result;
7541}
7542
7545{
7546 ROSE_ASSERT(target != NULL);
7547 ROSE_ASSERT(iter != NULL);
7548 SgComprehension *result = new SgComprehension(target, iter, ifs);
7549 ROSE_ASSERT(result);
7550 target->set_parent(result);
7551 iter->set_parent(result);
7552 if (ifs != NULL) ifs->set_parent(result);
7554 return result;
7555}
7556
7559{
7560 ROSE_ASSERT(elt != NULL);
7561 ROSE_ASSERT(generators != NULL);
7562 SgListComprehension* result = new SgListComprehension(elt, generators);
7563 elt->set_parent(result);
7564 generators->set_parent(result);
7566 return result;
7567}
7568
7571{
7572 ROSE_ASSERT(elt != NULL);
7573 ROSE_ASSERT(generators != NULL);
7574 SgListComprehension* result = new SgListComprehension(elt, generators);
7575 elt->set_parent(result);
7576 generators->set_parent(result);
7578 return result;
7579}
7580
7583{
7584 ROSE_ASSERT(elt != NULL);
7585 ROSE_ASSERT(generators != NULL);
7586 SgSetComprehension* result = new SgSetComprehension(elt, generators);
7587 elt->set_parent(result);
7588 generators->set_parent(result);
7590 return result;
7591}
7592
7595{
7596 ROSE_ASSERT(elt != NULL);
7597 ROSE_ASSERT(generators != NULL);
7598 SgSetComprehension* result = new SgSetComprehension(elt, generators);
7599 elt->set_parent(result);
7600 generators->set_parent(result);
7602 return result;
7603}
7604
7607{
7608 ROSE_ASSERT(kd_pair != NULL);
7609 ROSE_ASSERT(generators != NULL);
7610 SgDictionaryComprehension* result = new SgDictionaryComprehension(kd_pair, generators);
7611 kd_pair->set_parent(result);
7612 generators->set_parent(result);
7614 return result;
7615}
7616
7619{
7620 ROSE_ASSERT(kd_pair != NULL);
7621 ROSE_ASSERT(generators != NULL);
7622 SgDictionaryComprehension* result = new SgDictionaryComprehension(kd_pair, generators);
7623 kd_pair->set_parent(result);
7624 generators->set_parent(result);
7626 return result;
7627}
7628
7631 ROSE_ASSERT(arg != NULL);
7632 SgActualArgumentExpression* result = new SgActualArgumentExpression(arg_name, arg);
7633 arg->set_parent(result);
7635 return result;
7636}
7637
7640 ROSE_ASSERT(arg != NULL);
7641 SgActualArgumentExpression* result = new SgActualArgumentExpression(arg_name, arg);
7642 arg->set_parent(result);
7644 return result;
7645}
7646
7649 {
7650 if (scope == NULL)
7652
7653 SgPragma* pragma = new SgPragma(name);
7654 ROSE_ASSERT(pragma);
7655
7657
7658 SgPragmaDeclaration* result = new SgPragmaDeclaration(pragma);
7659 ROSE_ASSERT(result);
7660
7662
7663 result->set_definingDeclaration (result);
7664 result->set_firstNondefiningDeclaration(result);
7665 pragma->set_parent(result);
7666
7667 // DQ (7/14/2012): Set the parent so that we can be consistent where possible (class declarations and
7668 // enum declaration can't have there parent set since they could be non-autonomous declarations).
7669 result->set_parent(scope);
7670
7671 if (scope || topScopeStack())
7672 ROSE_ASSERT(result->get_parent() != NULL);
7673
7674 return result;
7675 }
7676
7678SgPragma* SageBuilder::buildPragma(const std::string & name)
7679{
7680 SgPragma* result= new SgPragma(name);
7681 ROSE_ASSERT(result);
7683 return result;
7684}
7685
7686
7688 {
7689 // Build an empty declaration (useful for adding precission to comments and CPP handling under token-based unparsing).
7690 SgEmptyDeclaration* emptyDeclaration = new SgEmptyDeclaration();
7691 ROSE_ASSERT(emptyDeclaration != NULL);
7692
7693 setOneSourcePositionForTransformation(emptyDeclaration);
7694
7695 emptyDeclaration->set_definingDeclaration (emptyDeclaration);
7696 emptyDeclaration->set_firstNondefiningDeclaration(emptyDeclaration);
7697
7698 // DQ (7/14/2012): Set the parent so that we can be consistent where possible (class declarations and
7699 // enum declaration can't have there parent set since they could be non-autonomous declarations).
7700 emptyDeclaration->set_parent(topScopeStack());
7701
7702 if (topScopeStack() != NULL)
7703 {
7704 ROSE_ASSERT(emptyDeclaration->get_parent() != NULL);
7705 }
7706
7707 return emptyDeclaration;
7708 }
7709
7710
7712{
7713 SgBasicBlock* result = new SgBasicBlock();
7714 ROSE_ASSERT(result);
7715
7716 // CR (3/22/2020): Fixed setting case insensitivity
7717 // if (symbol_table_case_insensitive_semantics == true)
7719 result->setCaseInsensitive(true);
7720
7722 if (stmt1) SageInterface::appendStatement(stmt1, result);
7723 if (stmt2) SageInterface::appendStatement(stmt2, result);
7724 if (stmt3) SageInterface::appendStatement(stmt3, result);
7725 if (stmt4) SageInterface::appendStatement(stmt4, result);
7726 if (stmt5) SageInterface::appendStatement(stmt5, result);
7727 if (stmt6) SageInterface::appendStatement(stmt6, result);
7728 if (stmt7) SageInterface::appendStatement(stmt7, result);
7729 if (stmt8) SageInterface::appendStatement(stmt8, result);
7730 if (stmt9) SageInterface::appendStatement(stmt9, result);
7731 if (stmt10) SageInterface::appendStatement(stmt10, result);
7732
7733 return result;
7734}
7735
7737 {
7738 SgBasicBlock* result = new SgBasicBlock();
7739 ROSE_ASSERT(result);
7740
7741 // CR (3/22/2020): Fixed setting case insensitivity
7742 // if (symbol_table_case_insensitive_semantics == true)
7744 {
7745 result->setCaseInsensitive(true);
7746 }
7747
7749
7750#if 0
7751 printf ("In buildBasicBlock_nfi(): returning result = %p \n",result);
7752#endif
7753
7754 return result;
7755 }
7756
7757SgBasicBlock* SageBuilder::buildBasicBlock_nfi(const vector<SgStatement*>& stmts)
7758 {
7760 appendStatementList(stmts, result);
7761
7762#if 0
7763 printf ("In buildBasicBlock_nfi(const vector<SgStatement*>& stmts): returning result = %p \n",result);
7764#endif
7765
7766#if 0
7767 printf ("Exiting as a test! \n");
7768 ROSE_ABORT();
7769#endif
7770
7771 return result;
7772 }
7773
7774// CR (7/24/2020): Added additional functionality.
7775// Build a SgBasicBlock and set its parent. This function does NOT link the parent scope to the block.
7778{
7780 block->set_parent(parent);
7781
7782 return block;
7783}
7784
7785
7788{
7789 SgGotoStatement* result = new SgGotoStatement(label);
7790 ROSE_ASSERT(result);
7792 return result;
7793}
7794
7797{
7798 SgGotoStatement* result = NULL;
7799 ROSE_ASSERT (symbol != NULL);
7801 { // Fortran case
7802 result = buildGotoStatement((SgLabelStatement *)NULL);
7803 SgLabelRefExp* l_exp = buildLabelRefExp(symbol);
7804 l_exp->set_parent(result);
7805 result->set_label_expression(l_exp);
7806 }
7807 else // C/C++ case
7808 {
7809 SgLabelStatement* l_stmt = isSgLabelStatement(symbol->get_declaration());
7810 ROSE_ASSERT (l_stmt != NULL);
7811 result = buildGotoStatement(l_stmt);
7812 }
7813 ROSE_ASSERT(result);
7814 return result;
7815}
7816
7819{
7820 SgGotoStatement* result = new SgGotoStatement(label);
7821 ROSE_ASSERT(result);
7823 return result;
7824}
7825
7826// DQ (11/22/2017): Added support for computed code goto as defined by GNU C/C++ extension.
7829 {
7830 SgLabelStatement* label = NULL;
7831 SgGotoStatement* result = new SgGotoStatement(label);
7832 result->set_selector_expression(label_expression);
7833 ROSE_ASSERT(result);
7835 return result;
7836 }
7837
7840{
7841 // Liao 2/6/2013. We no longer allow NULL express pointer. Use SgNullExpression instead.
7842 // CR (4/27/18): The expression argument to the builder function is optional
7843 // (NULL is allowed). What is not allowed is constructing an SgReturnStmt with a NULL
7844 // expression argument.
7845 if (expression == NULL)
7846 {
7847 expression = buildNullExpression();
7848 }
7849 SgReturnStmt * result = new SgReturnStmt(expression);
7850 ROSE_ASSERT(result);
7851 if (expression != NULL) expression->set_parent(result);
7853 return result;
7854}
7855
7858{
7859 SgReturnStmt * result = new SgReturnStmt(expression);
7860 ROSE_ASSERT(result);
7861 if (expression != NULL) expression->set_parent(result);
7863 return result;
7864}
7865
7867{
7868 SgCaseOptionStmt* result = new SgCaseOptionStmt(key,body);
7869 ROSE_ASSERT(result);
7871 if (key) key->set_parent(result);
7872 if (body) body->set_parent(result);
7873 return result;
7874}
7875
7877{
7878 SgCaseOptionStmt* result = new SgCaseOptionStmt(key,body);
7879 ROSE_ASSERT(result);
7881 if (key) key->set_parent(result);
7882 if (body) body->set_parent(result);
7883 return result;
7884}
7885
7887{
7888 SgDefaultOptionStmt* result = new SgDefaultOptionStmt(body);
7889 ROSE_ASSERT(result);
7891 if (body) body->set_parent(result);
7892
7893#if 0
7894 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7895 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7896 printf ("SageBuilder::buildDefaultOptionStmt() body = %p \n",body);
7897 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7898 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7899#endif
7900
7901 return result;
7902}
7903
7905{
7906 SgDefaultOptionStmt* result = new SgDefaultOptionStmt(body);
7907 ROSE_ASSERT(result);
7909 if (body) body->set_parent(result);
7910
7911#if 0
7912 static int count = 0;
7913
7914 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7915 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7916 printf ("SageBuilder::buildDefaultOptionStmt_nfi() body = %p \n",body);
7917 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7918 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7919
7920 if (count >= 1)
7921 {
7922 printf ("Exiting as a test! \n");
7923 ROSE_ASSERT(false);
7924 }
7925 count++;
7926#endif
7927
7928 return result;
7929}
7930
7932{
7933 SgSwitchStatement* result = new SgSwitchStatement(item_selector,body);
7934 ROSE_ASSERT(result);
7935
7936 // CR (3/22/2020): Fixed setting case insensitivity
7937 // if (symbol_table_case_insensitive_semantics == true)
7939 result->setCaseInsensitive(true);
7940
7942 if (item_selector) item_selector->set_parent(result);
7943 if (body) body->set_parent(result);
7944 return result;
7945}
7946
7949 {
7950 SgSwitchStatement* result = new SgSwitchStatement(item_selector,body);
7951 ROSE_ASSERT(result);
7952
7953#if 0
7954 // DQ (11/28/2010): Added specification of case insensitivity for Fortran.
7956 result->setCaseInsensitive(true);
7957
7959 if (item_selector) item_selector->set_parent(result);
7960 if (body) body->set_parent(result);
7961#else
7962 // DQ (2/15/2012): Modified to handle C++ case where variable declarations are allowed in the condition.
7963 initializeSwitchStatement(result,item_selector,body);
7964#endif
7965
7966 return result;
7967 }
7968
7971{
7972 SgNullStatement* result = NULL;
7973 result = new SgNullStatement();
7974 ROSE_ASSERT(result);
7976 return result;
7977}
7978
7981{
7982 SgNullStatement* result = NULL;
7983 result = new SgNullStatement();
7984 ROSE_ASSERT(result);
7986 return result;
7987}
7988
7991 SgExpression* globals,
7992 SgExpression* locals) {
7993 if (locals != NULL && globals == NULL)
7994 ROSE_ASSERT(!"buildExecStatement with non-NULL locals requires non-NULL globals");
7995 ROSE_ASSERT(executable != NULL);
7996
7997 SgExecStatement* result = new SgExecStatement(executable, globals, locals);
7998 executable->set_parent(result);
7999 if (globals != NULL) globals->set_parent(result);
8000 if (locals != NULL) locals->set_parent(result);
8001
8003 return result;
8004}
8005
8008 SgExpression* globals,
8009 SgExpression* locals) {
8010 if (locals != NULL && globals == NULL)
8011 ROSE_ASSERT(!"buildExecStatement with non-NULL locals requires non-NULL globals");
8012 ROSE_ASSERT(executable != NULL);
8013
8014 SgExecStatement* result = new SgExecStatement(executable, globals, locals);
8015 executable->set_parent(result);
8016 if (globals != NULL) globals->set_parent(result);
8017 if (locals != NULL) locals->set_parent(result);
8018
8020 return result;
8021}
8022
8023// MH (6/10/2014): Added async support
8025{
8026 ROSE_ASSERT(body != NULL);
8027 SgAsyncStmt *async_stmt = new SgAsyncStmt(body);
8028 ROSE_ASSERT(async_stmt);
8029 body->set_parent(async_stmt);
8031
8032 return async_stmt;
8033}
8034
8035// MH (6/11/2014): Added finish support
8037{
8038 ROSE_ASSERT(body != NULL);
8039 SgFinishStmt *finish_stmt = new SgFinishStmt(body);
8040 ROSE_ASSERT(finish_stmt);
8041 body->set_parent(finish_stmt);
8043
8044 return finish_stmt;
8045}
8046
8047// MH (6/11/2014): Added at support
8049{
8050 ROSE_ASSERT(expression);
8051 ROSE_ASSERT(body);
8052 SgAtStmt *at_stmt = new SgAtStmt(expression, body);
8054 expression->set_parent(at_stmt);
8055 body->set_parent(at_stmt);
8056
8057 return at_stmt;
8058}
8059
8060// MH (11/12/2014): Added atomic support
8062{
8063 ROSE_ASSERT(body != NULL);
8064 SgAtomicStmt *atomic_stmt = new SgAtomicStmt(body);
8065 ROSE_ASSERT(atomic_stmt);
8066 body->set_parent(atomic_stmt);
8068
8069 return atomic_stmt;
8070}
8071
8072
8074{
8075 ROSE_ASSERT(expression);
8076 ROSE_ASSERT(body);
8077 SgWhenStmt *when_stmt = new SgWhenStmt(expression, body);
8079 expression->set_parent(when_stmt);
8080 body->set_parent(when_stmt);
8081
8082 return when_stmt;
8083}
8084
8085// MH (9/14/2014): Added atexpr support
8087{
8088 ROSE_ASSERT(expression);
8089 ROSE_ASSERT(body);
8090 SgAtExp *at_exp = new SgAtExp(expression, body);
8092 expression->set_parent(at_exp);
8093 body->set_parent(at_exp);
8094
8095 return at_exp;
8096}
8097
8098// MH (11/7/2014): Added finish expression support
8100{
8101 ROSE_ASSERT(expression);
8102 ROSE_ASSERT(body);
8103 SgFinishExp *finish_exp = new SgFinishExp(expression, body);
8105 expression->set_parent(finish_exp);
8106 body->set_parent(finish_exp);
8107
8108 return finish_exp;
8109}
8110
8112{
8113 SgHereExp *here = new SgHereExp(NULL);
8114 return here;
8115}
8116
8118{
8119 SgDotDotExp *dotdot = new SgDotDotExp(NULL);
8120 return dotdot;
8121}
8122
8123
8126 SgCatchOptionStmt* catch0,
8127 SgCatchOptionStmt* catch1,
8128 SgCatchOptionStmt* catch2,
8129 SgCatchOptionStmt* catch3,
8130 SgCatchOptionStmt* catch4
8131 )
8132 {
8133 ROSE_ASSERT(body != NULL);
8134 SgTryStmt* try_stmt = new SgTryStmt(body);
8135 body->set_parent(try_stmt);
8136
8137 // DQ (11/3/2012): Added setting default source position info.
8138 setSourcePosition(try_stmt);
8139
8140 if (try_stmt->get_catch_statement_seq_root() != NULL)
8141 {
8142 if (try_stmt->get_catch_statement_seq_root()->get_startOfConstruct() == NULL)
8143 {
8144 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_endOfConstruct() == NULL);
8146 }
8147
8148 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_startOfConstruct() != NULL);
8149 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_endOfConstruct() != NULL);
8150 }
8151
8152 if (catch0 != NULL) try_stmt->append_catch_statement(catch0);
8153 if (catch1 != NULL) try_stmt->append_catch_statement(catch1);
8154 if (catch2 != NULL) try_stmt->append_catch_statement(catch2);
8155 if (catch3 != NULL) try_stmt->append_catch_statement(catch3);
8156 if (catch4 != NULL) try_stmt->append_catch_statement(catch4);
8157
8158 return try_stmt;
8159 }
8160
8161
8162// charles4 09/16/2011
8165 {
8166 //
8167 // charles4 09/23/2011 - Note that when an SgTryStmt is allocated, its constructor
8168 // preallocates a SgCatchStementSeq for the field p_catch_statement_sequence_root.
8169 // So, although the method set_catch_statement_seq_root(catch_statement_sequence) is
8170 // available, it should not be used to set the catch_statement_sequence_root as that
8171 // would leave the one that was allocated by the constructor dangling!
8172 //
8173 ROSE_ASSERT(try_body != NULL);
8174 SgTryStmt* try_stmt = new SgTryStmt(try_body);
8175 try_body -> set_parent(try_stmt);
8176
8177 // DQ (11/3/2012): Added setting default source position info.
8178 setSourcePosition(try_stmt);
8179
8180 if (finally_body) {
8181 try_stmt -> set_finally_body(finally_body);
8182 finally_body -> set_parent(try_stmt);
8183 }
8184
8185 return try_stmt;
8186}
8187
8188// charles4 09/16/2011
8189// ! Build an initial sequence of Catch blocks containing 0 or 1 element.
8191 SgCatchStatementSeq *catch_statement_sequence = new SgCatchStatementSeq();
8192
8193 // DQ (11/3/2012): Added setting default source position info.
8194 setSourcePosition(catch_statement_sequence);
8195
8196 if (catch_option_stmt) {
8197 catch_statement_sequence -> append_catch_statement(catch_option_stmt);
8198 catch_option_stmt -> set_parent(catch_statement_sequence);
8199 }
8200
8201 return catch_statement_sequence;
8202}
8203
8204// charles4 09/21/2011 - Make condition and body arguments optional.
8207 SgCatchOptionStmt* result = new SgCatchOptionStmt(condition, body, /* SgTryStmt*= */ NULL);
8208 if (condition) condition->set_parent(result);
8209 if (body) body->set_parent(result);
8211 return result;
8212}
8213
8215{
8216 ROSE_ASSERT(expression);
8217 ROSE_ASSERT(body);
8218 SgJavaSynchronizedStatement *sync_stmt = new SgJavaSynchronizedStatement(expression, body);
8220
8221 expression->set_parent(sync_stmt);
8222 body->set_parent(sync_stmt);
8223
8224 return sync_stmt;
8225}
8226
8228{
8229 ROSE_ASSERT(op);
8230 SgJavaThrowStatement *throw_stmt = new SgJavaThrowStatement(op);
8231 ROSE_ASSERT(throw_stmt);
8232
8233 op->set_parent(throw_stmt);
8234
8235 return throw_stmt;
8236}
8237
8238// DQ (9/3/2011): Changed the API to conform to the Java grammar.
8239// SgJavaForEachStatement *SageBuilder::buildJavaForEachStatement(SgInitializedName *variable, SgExpression *collection, SgStatement *body)
8241{
8242 SgJavaForEachStatement *foreach_stmt = new SgJavaForEachStatement(variable, collection, body);
8243 ROSE_ASSERT(foreach_stmt);
8244 if (variable) variable -> set_parent(foreach_stmt);
8245 if (collection) collection -> set_parent(foreach_stmt);
8246 if (body) body -> set_parent(foreach_stmt);
8247
8248 return foreach_stmt;
8249}
8250
8252{
8253 SgJavaLabelStatement *label_stmt = new SgJavaLabelStatement(name, stmt);
8254 ROSE_ASSERT(label_stmt);
8256
8257 if (stmt != NULL)
8258 stmt -> set_parent(label_stmt);
8259
8260 SgJavaLabelSymbol *lsymbol = label_stmt -> lookup_java_label_symbol(name);
8261 if (! lsymbol) // Should be an Assertion - always true!
8262 {
8263 lsymbol= new SgJavaLabelSymbol(label_stmt);
8264 ROSE_ASSERT(lsymbol);
8265 label_stmt -> insert_symbol(lsymbol -> get_name(), lsymbol);
8266 }
8267
8268 return label_stmt;
8269}
8270
8273 SgPythonPrintStmt* result = new SgPythonPrintStmt(dest, values);
8274 if (dest) dest->set_parent(result);
8275 if (values) values->set_parent(result);
8277 return result;
8278}
8279
8282 SgPythonPrintStmt* result = new SgPythonPrintStmt(dest, values);
8283 if (dest) dest->set_parent(result);
8284 if (values) values->set_parent(result);
8286 return result;
8287}
8288
8290SageBuilder::buildPythonGlobalStmt(SgInitializedNamePtrList& names) {
8291 SgPythonGlobalStmt* result = new SgPythonGlobalStmt();
8292 for (SgInitializedName* name: names) {
8293 result->append_name(name);
8294 }
8296 return result;
8297}
8298
8300SageBuilder::buildPythonGlobalStmt_nfi(SgInitializedNamePtrList& names) {
8301 SgPythonGlobalStmt* result = new SgPythonGlobalStmt();
8302 for (SgInitializedName* name: names) {
8303 result->append_name(name);
8304 }
8306 return result;
8307}
8308
8309// DQ (4/30/2010): Added support for building asm statements.
8312{
8313 SgAsmStmt* result = NULL;
8314 result = new SgAsmStmt();
8315 ROSE_ASSERT(result);
8316 result->set_assemblyCode(s);
8318 return result;
8319}
8320
8321// DQ (4/30/2010): Added support for building asm statements.
8324{
8325 SgAsmStmt* result = NULL;
8326 result = new SgAsmStmt();
8327 ROSE_ASSERT(result);
8328 result->set_assemblyCode(s);
8330 return result;
8331}
8332
8333SgAsmStmt*
8335 {
8336// Multi-byte NOP instructions.
8337// Note: I can't seem to get the memonic versions to work properly
8338#define NOP_1_BYTE_STRING "nop"
8339#define NOP_2_BYTE_STRING ".byte 0x66,0x90"
8340#define NOP_3_BYTE_STRING "nopl (%eax)"
8341#define NOP_4_BYTE_STRING "nopl 0x01(%eax)"
8342#define NOP_5_BYTE_STRING ".byte 0x0f,0x1f,0x44,0x00,0x00"
8343#define NOP_6_BYTE_STRING ".byte 0x66,0x0f,0x1f,0x44,0x00,0x00"
8344#define NOP_7_BYTE_STRING ".byte 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00"
8345#define NOP_8_BYTE_STRING ".byte 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00"
8346#define NOP_9_BYTE_STRING ".byte 0x66,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00"
8347
8348 ROSE_ASSERT(n > 0);
8349
8350 SgAsmStmt* nopStatement = NULL;
8351
8352 switch (n)
8353 {
8354 case 1: nopStatement = buildAsmStatement(NOP_1_BYTE_STRING); break;
8355 case 2: nopStatement = buildAsmStatement(NOP_2_BYTE_STRING); break;
8356 case 3: nopStatement = buildAsmStatement(NOP_3_BYTE_STRING); break;
8357 case 4: nopStatement = buildAsmStatement(NOP_4_BYTE_STRING); break;
8358 case 5: nopStatement = buildAsmStatement(NOP_5_BYTE_STRING); break;
8359 case 6: nopStatement = buildAsmStatement(NOP_6_BYTE_STRING); break;
8360 case 7: nopStatement = buildAsmStatement(NOP_7_BYTE_STRING); break;
8361 case 8: nopStatement = buildAsmStatement(NOP_8_BYTE_STRING); break;
8362 case 9: nopStatement = buildAsmStatement(NOP_9_BYTE_STRING); break;
8363
8364 default:
8365 {
8366 printf ("Only supporting values of multi-byte nop's up to 9 bytes long. \n");
8367 ROSE_ABORT();
8368 }
8369 }
8370
8371 return nopStatement;
8372 }
8373
8375 {
8376 // DQ (7/25/2014): Adding support for C11 static assertions.
8377
8378 ROSE_ASSERT(condition != NULL);
8379
8380 SgStaticAssertionDeclaration* result = new SgStaticAssertionDeclaration(condition,string_literal);
8381 ROSE_ASSERT(result != NULL);
8382
8383 // DQ (7/25/2014): It is enforced that at least the firstNondefiningDeclaration be set.
8384 ROSE_ASSERT(result->get_firstNondefiningDeclaration() == NULL);
8385 result->set_firstNondefiningDeclaration(result);
8386 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
8387
8389
8390 return result;
8391 }
8392
8393
8394// DQ (8/17/2014): Adding support for Microsoft MSVC specific attributes.
8396 {
8398 ROSE_ASSERT(result != NULL);
8399
8400 // DQ (8/17/2014): It is enforced that at least the firstNondefiningDeclaration be set.
8401 ROSE_ASSERT(result->get_firstNondefiningDeclaration() == NULL);
8402 result->set_firstNondefiningDeclaration(result);
8403 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
8404
8406
8407 return result;
8408 }
8409
8411// This does not work properly since the global scope expects declaration statement, not just SgNullStatement
8412#if 0
8414{
8415 SgStatement* result = NULL;
8416
8417 return result;
8418
8419} //buildStatementFromString()
8420#endif
8421
8423 {
8424 // DQ (7/26/2010): This needs to call the SgPointerType::createType() function so that we can properly abstract the creation of types into the type table.
8425 // printf ("ERROR: This function needs to call the SgPointerType::createType() function so that we can properly abstract the creation of types into the type table. \n");
8426 // ROSE_ASSERT(false);
8427
8428 // DQ (7/29/2010): This function needs to call the SgPointerType::createType() function to support the new type table.
8429 // SgPointerType* result = new SgPointerType(base_type);
8430 if (isSgReferenceType (base_type))
8431 {
8432 cerr<<"Error in SageBuilder::buildPointerType(): trying to build a pointer to a reference type! This is not allowed in C++."<<endl;
8433 ROSE_ABORT ();
8434 }
8435
8436 SgPointerType* result = SgPointerType::createType(base_type);
8437 ROSE_ASSERT(result != NULL);
8438
8439 return result;
8440 }
8441
8443 {
8444 // DQ (7/26/2010): This needs to call the SgReferenceType::createType() function so that we can properly abstract the creation of types into the type table.
8445 // printf ("ERROR: This function needs to call the SgReferenceType::createType() function so that we can properly abstract the creation of types into the type table. \n");
8446 // ROSE_ASSERT(false);
8447
8448 // DQ (7/29/2010): This function needs to call the SgPointerType::createType() function to support the new type table.
8449 // SgReferenceType* result= new SgReferenceType(base_type);
8450 SgReferenceType* result = SgReferenceType::createType(base_type);
8451 ROSE_ASSERT(result != NULL);
8452
8453 return result;
8454 }
8455
8457 {
8458 ROSE_ASSERT(base_type != NULL);
8460 ROSE_ASSERT(result != NULL);
8461
8462 return result;
8463 }
8464
8466 {
8467 ROSE_ASSERT(base_expression != NULL);
8468
8469 // SgDeclType* result = SgDeclType::createType(base_expression);
8470 SgDeclType* result = NULL;
8471 if (isSgFunctionParameterRefExp(base_expression) != NULL)
8472 {
8473 result = new SgDeclType(base_expression);
8474 result->set_base_type(base_type);
8475 }
8476 else
8477 {
8478 result = SgDeclType::createType(base_expression);
8479 }
8480
8481 ROSE_ASSERT(result != NULL);
8482
8483 // DQ (8/12/2014): Set the parent in the expression.
8484 base_expression->set_parent(result);
8485
8486 return result;
8487 }
8488
8491 {
8492 // ROSE_ASSERT(base_expression != NULL);
8493
8494#define DEBUG_TYPEOF_TYPE 0
8495
8496#if DEBUG_TYPEOF_TYPE
8497 printf ("In SageBuilder::buildTypeOfType(): base_expression = %p = %s \n",base_expression,base_expression != NULL ? base_expression->class_name().c_str() : "NULL");
8498 printf (" ------------------------------- base_type = %p = %s \n",base_type,base_type != NULL ? base_type->class_name().c_str() : "NULL");
8499#endif
8500
8501 SgTypeOfType* result = NULL;
8502 if (isSgFunctionParameterRefExp(base_expression) != NULL)
8503 {
8504#if DEBUG_TYPEOF_TYPE
8505 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) != NULL: calling new SgTypeOfType(base_expression,NULL) \n");
8506#endif
8507 result = new SgTypeOfType(base_expression,NULL);
8508
8509 // DQ (3/28/2015): Testing for corruption in return value.
8510 ROSE_ASSERT(result != NULL);
8511#if DEBUG_TYPEOF_TYPE
8512 printf ("In buildTypeOfType(): test 1: result = %p = %s \n",result,result->class_name().c_str());
8513#endif
8514 result->set_base_type(base_type);
8515 }
8516 else
8517 {
8518 if (base_expression != NULL)
8519 {
8520#if DEBUG_TYPEOF_TYPE
8521 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) == NULL: base_expression != NULL: calling SgTypeOfType::createType(base_expression,NULL) \n");
8522#endif
8523 result = SgTypeOfType::createType(base_expression,NULL);
8524
8525 // DQ (3/28/2015): Testing for corruption in return value.
8526 ROSE_ASSERT(result != NULL);
8527#if DEBUG_TYPEOF_TYPE
8528 printf ("In buildTypeOfType(): test 2: result = %p = %s \n",result,result->class_name().c_str());
8529#endif
8530 }
8531 else
8532 {
8533 ROSE_ASSERT(base_type != NULL);
8534
8535#if DEBUG_TYPEOF_TYPE
8536 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) == NULL: base_expression == NULL: calling SgTypeOfType::createType(base_type,NULL) \n");
8537#endif
8538 result = SgTypeOfType::createType(base_type,NULL);
8539
8540 // DQ (3/28/2015): Testing for corruption in return value.
8541 ROSE_ASSERT(result != NULL);
8542
8543#if DEBUG_TYPEOF_TYPE
8544 printf ("In buildTypeOfType(): test 3: result = %p = %s \n",result,result->class_name().c_str());
8545#endif
8546 // result->set_base_type(base_type);
8547 if (result->get_base_type() != base_type)
8548 {
8549 ROSE_ASSERT(result->get_base_type() != NULL);
8550#if DEBUG_TYPEOF_TYPE
8551 printf ("result->get_base_type() = %p = %s \n",result->get_base_type(),result->get_base_type()->class_name().c_str());
8552#endif
8553 ROSE_ASSERT(base_type != NULL);
8554#if DEBUG_TYPEOF_TYPE
8555 printf ("base_type = %p = %s \n",base_type,base_type->class_name().c_str());
8556#endif
8557 }
8558 }
8559 }
8560
8561 ROSE_ASSERT(result != NULL);
8562
8563 if (base_expression != NULL)
8564 {
8565 base_expression->set_parent(result);
8566 }
8567
8568 // DQ (3/28/2015): Testing for corruption in return value.
8569 ROSE_ASSERT(result != NULL);
8570
8571#if DEBUG_TYPEOF_TYPE
8572 printf ("In buildTypeOfType(): test 4: result = %p = %s \n",result,result->class_name().c_str());
8573#endif
8574
8575 return result;
8576 }
8577
8578
8579
8580#if 0
8581// Liao, 8/16/2010, This function is being phased out. Please don't call this!!
8583 {
8584 // DQ (7/30/2010): Note that this is called by the outline test: tests/nonsmoke/functional/roseTests/astOutliningTests/moreTest3.cpp
8585 // DQ (7/28/2010): Now we want to make calling this function an error, the functions buildConst() will return SgModifierType objects instead.
8586 printf ("Error: this function SageBuilder::buildModifierType() should not be called! (call the buildConst() function (or whatever other function is required) directly \n");
8587 ROSE_ABORT();
8588 // Liao, 8/13/2010, This function is being phased out. Please don't call this!!
8589
8590 // DQ (7/26/2010): This needs to call the SgModifierType::createType() function so that we can properly abstract the creation of types into the type table.
8591 SgModifierType* result = new SgModifierType(base_type);
8592 // SgModifierType* result = SgModifierType::createType(base_type);
8593 ROSE_ASSERT(result != NULL);
8594
8595 // DQ (7/28/2010): Insert result type into type table and return it, or
8596 // replace the result type, if already available in the type table, with
8597 // the type from type table.
8598 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
8599
8600 return result;
8601 }
8602#endif
8603
8604// CR (2/20/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8606 SgTypeBool * result = SgTypeBool::createType(kind_expr);
8607 ROSE_ASSERT(result);
8608 if (kind_expr != NULL) kind_expr->set_parent(result);
8609 return result;
8610}
8614
8616 {
8618 ROSE_ASSERT(result);
8619 return result;
8620 }
8621
8623{
8625 ROSE_ASSERT(result);
8626 return result;
8627}
8628
8629#if 0 // did not work, build##itemType would be expanded correctly
8630#define BUILD_SGTYPE_DEF(item) \
8631 SgType##item * SageBuilder::build##itemType() { \
8632 SgType##item * result =SgType##item::createType(); \
8633 ROSE_ASSERT(result); \
8634 return result; \
8635 }
8636
8637 BUILD_SGTYPE_DEF(Bool)
8638 BUILD_SGTYPE_DEF(Char)
8639 BUILD_SGTYPE_DEF(Double)
8640 BUILD_SGTYPE_DEF(Float)
8641 BUILD_SGTYPE_DEF(Int)
8642 BUILD_SGTYPE_DEF(Long)
8643 BUILD_SGTYPE_DEF(LongDouble)
8644 BUILD_SGTYPE_DEF(LongLong)
8645 BUILD_SGTYPE_DEF(Short)
8646 BUILD_SGTYPE_DEF(Void)
8647
8648 BUILD_SGTYPE_DEF(Wchar)
8649
8650// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
8651 BUILD_SGTYPE_DEF(Char16)
8652 BUILD_SGTYPE_DEF(Char32)
8653
8654 BUILD_SGTYPE_DEF(SignedChar)
8655 BUILD_SGTYPE_DEF(SignedInt)
8656 BUILD_SGTYPE_DEF(SignedLong)
8657 BUILD_SGTYPE_DEF(SignedShort)
8658 BUILD_SGTYPE_DEF(UnsignedChar)
8659 BUILD_SGTYPE_DEF(UnsignedInt)
8660 BUILD_SGTYPE_DEF(UnsignedLong)
8661 BUILD_SGTYPE_DEF(UnsignedLongLong)
8662 BUILD_SGTYPE_DEF(UnsignedShort)
8663#undef BUILD_SGTYPE_DEF
8664#endif
8666{
8668 ROSE_ASSERT(result);
8669 return result;
8670}
8671
8673{
8675 ROSE_ASSERT(result);
8676 return result;
8677}
8678
8680{
8682 ROSE_ASSERT(result);
8683 return result;
8684}
8685
8687{
8689 ROSE_ASSERT(result);
8690 return result;
8691}
8692
8693// Rasmussen (2/20/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8695{
8697 ROSE_ASSERT(result);
8698 if (kind_expr != NULL) kind_expr->set_parent(result);
8699 return result;
8700}
8705
8707{
8709 ROSE_ASSERT(result);
8710 return result;
8711}
8712
8715 ROSE_ASSERT(result);
8716 return result;
8717}
8718
8721 ROSE_ASSERT(result);
8722 return result;
8723}
8724
8726{
8728 ROSE_ASSERT(result);
8729 return result;
8730}
8731
8733{
8735 ROSE_ASSERT(result);
8736 return result;
8737}
8738
8740{
8742 ROSE_ASSERT(result);
8743 return result;
8744}
8745
8747{
8749 ROSE_ASSERT(result);
8750 return result;
8751}
8752
8753#if 1
8760
8767#endif
8768
8769
8771{
8773 ROSE_ASSERT(result);
8774 return result;
8775}
8776
8777// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
8779{
8781 ROSE_ASSERT(result);
8782 return result;
8783}
8784
8785// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
8787{
8789 ROSE_ASSERT(result);
8790 return result;
8791}
8792
8793
8795{
8797 ROSE_ASSERT(result);
8798 return result;
8799}
8800
8802{
8804 ROSE_ASSERT(result);
8805 return result;
8806}
8807
8809{
8811 ROSE_ASSERT(result);
8812 return result;
8813}
8814
8816{
8817 SgAutoType * result =new SgAutoType();
8818 ROSE_ASSERT(result);
8819 return result;
8820}
8821
8823{
8825 ROSE_ASSERT(result);
8826 return result;
8827}
8828
8830{
8832 ROSE_ASSERT(result);
8833 return result;
8834}
8835
8837{
8839 ROSE_ASSERT(result);
8840 return result;
8841}
8842
8844 {
8845 // DQ (8/17/2010): This function needs to use a different API to handle a literal
8846 // value for the string size (typical) or an expression for the string size (rare).
8847 // For now we will make it an error to call this function.
8848
8849 // SgTypeString * result =SgTypeString::createType();
8850 SgTypeString * result = NULL;
8851 ROSE_ASSERT(result != NULL);
8852 return result;
8853 }
8854
8856 {
8857 // DQ (8/21/2010): This is a new API for this function. This type is specific to Fortran use,
8858 // in C/C++ a string is just an array of char. We could have a consistant handling between
8859 // C/C++ and Fortrna, but we have just corrected the implementation in Fortran to use this IR
8860 // node and we would have to add such support to C/C++. The current implementation reflects
8861 // the grammar of the two languages.
8862
8863 // This function needs to use a different API to handle a literal
8864 // value for the string size (typical) or an expression for the string size (rare).
8865
8866 SgTypeString* result = SgTypeString::createType(stringLengthExpression);
8867 ASSERT_not_null(result);
8868 return result;
8869 }
8870
8871// Rasmussen (2/20/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8873{
8874 SgTypeInt * result;
8875 if (kind_expr != NULL)
8876 {
8877 result = SgTypeInt::createType(0, kind_expr);
8878 kind_expr->set_parent(result);
8879 }
8880 else
8881 {
8882 result = SgTypeInt::createType();
8883 }
8884 ASSERT_not_null(result);
8885 return result;
8886}
8888{
8889 return buildIntType(NULL);
8890}
8891
8893{
8895 ROSE_ASSERT(result);
8896 return result;
8897}
8898
8899// Rasmussen (3/6/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8901{
8902 SgTypeFloat * result;
8903 if (kind_expr != NULL)
8904 {
8905 result = SgTypeFloat::createType(kind_expr);
8906 kind_expr->set_parent(result);
8907 }
8908 else
8909 {
8910 result = SgTypeFloat::createType();
8911 }
8912 ASSERT_not_null(result);
8913 return result;
8914}
8916{
8918 ASSERT_not_null(result);
8919 return result;
8920}
8921
8922// Rasmussen (2/20/2020): Added builder for Jovial fixed type
8924{
8925 SgTypeFixed * result = SgTypeFixed::createType(scale, fraction);
8926 ROSE_ASSERT(result);
8927
8928 if (scale) scale->set_parent(result);
8929 if (fraction) fraction->set_parent(result);
8930
8931 return result;
8932}
8933
8934// Rasmussen (5/5/2020): Added builder for Jovial bit type
8936{
8937 SgJovialBitType * result = SgJovialBitType::createType(size, NULL);
8938
8939 if (size) size->set_parent(result);
8940
8941 return result;
8942}
8943
8944// DQ (7/29/2010): Changed return type from SgType to SgModifierType
8947 {
8948 // DQ (9/3/2012): Added assertion.
8949 ROSE_ASSERT(base_type != NULL);
8950
8951 // DQ (7/28/2010): New (similar) approach using type table support.
8952 SgModifierType* result = new SgModifierType(base_type);
8953 ROSE_ASSERT(result != NULL);
8954
8955 // DQ (3/10/2018): Adding assertion.
8956 ROSE_ASSERT(result != base_type);
8957
8958 // DQ (7/28/2010): Insert result type into type table and return it, or
8959 // replace the result type, if already available in the type table, with
8960 // the type from type table.
8961 SgModifierType* result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8962
8963 if (result != result2)
8964 {
8965 // DQ (10/27/2015): This is the cause of a bug in the test2015_97.C (boost template problem).
8966 printf ("WARNING: In SageBuilder::buildModifierType(): using previously build SgModifierType from global type table: result2 = %p = %s \n",result2,result2->class_name().c_str());
8967 delete result;
8968 }
8969
8970 // DQ (3/10/2018): Adding assertion.
8971 ROSE_ASSERT(result2 != base_type);
8972
8973 return result2;
8974 }
8975
8978 {
8979 // DQ (9/3/2012): Added assertion.
8980 ROSE_ASSERT(base_type != NULL);
8981
8982 // DQ (7/28/2010): New (similar) approach using type table support.
8983 SgModifierType *result = new SgModifierType(base_type);
8984 ROSE_ASSERT(result!=NULL);
8985 result->get_typeModifier().get_constVolatileModifier().setConst();
8986
8987 // DQ (7/28/2010): Insert result type into type table and return it, or
8988 // replace the result type, if already available in the type table, with
8989 // the type from type table.
8990 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8991
8992 if (result != result2)
8993 {
8994 delete result;
8995 }
8996
8997 // DQ (3/10/2018): Adding assertion.
8998 ROSE_ASSERT(result2 != base_type);
8999
9000 return result2;
9001 }
9002
9003// DQ (8/27/2010): Added Fortran specific support for types based on kind expressions.
9006 {
9007 // DQ (9/3/2012): Added assertion.
9008 ROSE_ASSERT(base_type != NULL);
9009
9010 SgModifierType *result = new SgModifierType(base_type);
9011 ROSE_ASSERT(result != NULL);
9012
9013 result->set_type_kind(kindExpression);
9014
9015#if 0
9016 printf ("In SageBuilder::buildFortranKindType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9017#endif
9018
9019 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9020
9021 if (result != result2)
9022 {
9023#if 0
9024 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9025 printf ("(debugging) In SageBuilder::buildFortranKindType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9026#else
9027 delete result;
9028#endif
9029 }
9030
9031 return result2;
9032 }
9033
9034// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9037 {
9038 // DQ (9/3/2012): Added assertion.
9039 ROSE_ASSERT(base_type != NULL);
9040
9041 SgModifierType *result = new SgModifierType(base_type);
9042 ROSE_ASSERT(result!=NULL);
9043
9044 result->get_typeModifier().get_constVolatileModifier().setVolatile();
9045
9046#if 0
9047 printf ("In SageBuilder::buildVolatileType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9048#endif
9049
9050 // DQ (7/29/2010): Insert result type into type table and return it, or
9051 // replace the result type, if already available in the type table, with
9052 // the type from type table.
9053 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9054 if (result != result2)
9055 {
9056#if 0
9057 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9058 printf ("(debugging) In SageBuilder::buildVolatileType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9059#else
9060 delete result;
9061#endif
9062 }
9063
9064 return result2;
9065 }
9066
9067// DQ (1/19/2019): Adding support for const volatile type (both together as another value).
9070 {
9071 // DQ (9/3/2012): Added assertion.
9072 ROSE_ASSERT(base_type != NULL);
9073
9074 SgModifierType *result = new SgModifierType(base_type);
9075 ROSE_ASSERT(result!=NULL);
9076
9077 result->get_typeModifier().get_constVolatileModifier().setConst();
9078 result->get_typeModifier().get_constVolatileModifier().setVolatile();
9079
9080#if 1
9081 printf ("In SageBuilder::buildConstVolatileType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9082#endif
9083
9084 // DQ (7/29/2010): Insert result type into type table and return it, or
9085 // replace the result type, if already available in the type table, with
9086 // the type from type table.
9087 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9088 if (result != result2)
9089 {
9090#if 0
9091 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9092 printf ("(debugging) In SageBuilder::buildConstVolatileType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9093#else
9094 delete result;
9095#endif
9096 }
9097
9098 return result2;
9099 }
9100
9101string
9102generate_type_list (SgType* type)
9103 {
9104 // This function generates a list of types for each level of the type structure.
9105 string returnString;
9106
9107 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);
9108
9109 SgType* currentType = type;
9110
9111 SgModifierType* modType = NULL;
9112 SgPointerType* pointType = NULL;
9113 SgReferenceType* refType = NULL;
9114 SgRvalueReferenceType* rRefType = NULL;
9115 SgArrayType* arrayType = NULL;
9116 SgTypedefType* typedefType = NULL;
9117
9118 while (currentType != NULL)
9119 {
9120 returnString += currentType->class_name();
9121#if 0
9122 printf ("In generate_type_list(): returnString = %s \n",returnString.c_str());
9123#endif
9124 if ( (bit_array & SgType::STRIP_MODIFIER_TYPE) && (modType = isSgModifierType(currentType)) )
9125 {
9126 currentType = modType->get_base_type();
9127 }
9128 else if ( (bit_array & SgType::STRIP_REFERENCE_TYPE) && (refType = isSgReferenceType(currentType)) )
9129 {
9130 currentType = refType->get_base_type();
9131 }
9132 else if ( (bit_array & SgType::STRIP_RVALUE_REFERENCE_TYPE) && (rRefType = isSgRvalueReferenceType(currentType)) )
9133 {
9134 currentType = rRefType->get_base_type();
9135 }
9136 else if ( (bit_array & SgType::STRIP_POINTER_TYPE) && (pointType = isSgPointerType(currentType)) )
9137 {
9138 currentType = pointType->get_base_type();
9139 }
9140 else if ( (bit_array & SgType::STRIP_ARRAY_TYPE) && (arrayType = isSgArrayType(currentType)) )
9141 {
9142 currentType = arrayType->get_base_type();
9143 }
9144 else if ( (bit_array & SgType::STRIP_TYPEDEF_TYPE) && (typedefType = isSgTypedefType(currentType)) )
9145 {
9146 currentType = typedefType->get_base_type();
9147 }
9148 else
9149 {
9150 break;
9151 }
9152
9153 if (type != NULL)
9154 returnString += " , ";
9155 }
9156
9157 return returnString;
9158 }
9159
9160// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9163 {
9164 ROSE_ASSERT(base_type != NULL);
9165
9166 // DQ (1/30/2014): We need to include typedefs here as well (see test2014_77.c).
9167 // DQ (9/28/2012): Added that the base type could be an array (see test2012_03.c (C test code)).
9168 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type))
9169 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type))
9170 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type) && !isSgTypedefType(base_type))
9171 if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type) && !isSgTypedefType(base_type) && !isSgModifierType(base_type))
9172 {
9173 printf("ERROR: Base type of restrict type must be on a pointer or reference or array or typedef type: base_type = %p = %s \n",base_type,base_type->class_name().c_str());
9174 printf (" --- generate_type_list() = %s \n",generate_type_list(base_type).c_str());
9175 ROSE_ABORT();
9176 }
9177
9178 SgModifierType *result = new SgModifierType(base_type);
9179 ROSE_ASSERT(result!=NULL);
9180
9181 result->get_typeModifier().setRestrict();
9182
9183#if 0
9184 printf ("In SageBuilder::buildRestrictType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9185#endif
9186
9187 // DQ (7/29/2010): Insert result type into type table and return it, or
9188 // replace the result type, if already available in the type table, with
9189 // the type from type table.
9190 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9191 if (result != result2)
9192 {
9193#if 0
9194 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9195 printf ("(debugging) In SageBuilder::buildRestrictType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9196#else
9197 delete result;
9198#endif
9199 }
9200
9201 return result2;
9202 }
9203
9204
9205namespace
9206{
9207 // PP (2/16/24): model builder function after buildRestrictType
9209 _buildModifierType(SgType* base_type, std::function<void(SgModifierType*)> setModifiers)
9210 {
9211 ASSERT_not_null(base_type);
9212
9213 SgModifierType* result = new SgModifierType(base_type);
9214
9215 setModifiers(result);
9216
9217 SgModifierType* result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9218 if (result != result2) delete result;
9219
9220 return result2;
9221 }
9222}
9223
9224
9226 {
9227 auto op = [](SgModifierType* ty) { ty->get_typeModifier().setAliased(); };
9228
9229 return _buildModifierType(base_type, op);
9230 }
9231
9233 {
9234 auto op = [](SgModifierType* ty) { ty->get_typeModifier().setNotNull(); };
9235
9236 return _buildModifierType(base_type, op);
9237 }
9238
9239
9240// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9243 {
9244 // DQ (9/3/2012): Added assertion.
9245 ROSE_ASSERT(base_type != NULL);
9246
9247 SgModifierType *result = new SgModifierType(base_type);
9248 ROSE_ASSERT(result!=NULL);
9249
9250 result->get_typeModifier().get_upcModifier().set_modifier(SgUPC_AccessModifier::e_upc_strict);
9251
9252#if 0
9253 printf ("In SageBuilder::buildUpcStrictType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9254#endif
9255
9256 // DQ (7/29/2010): Insert result type into type table and return it, or
9257 // replace the result type, if already available in the type table, with
9258 // the type from type table.
9259 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9260 if (result != result2)
9261 {
9262#if 0
9263 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9264 printf ("(debugging) In SageBuilder::buildUpcStrictType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9265#else
9266 delete result;
9267#endif
9268 }
9269
9270 return result2;
9271 }
9272
9273// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9276 {
9277 // DQ (9/3/2012): Added assertion.
9278 ROSE_ASSERT(base_type != NULL);
9279
9280 SgModifierType *result = new SgModifierType(base_type);
9281 ROSE_ASSERT(result!=NULL);
9282
9283 result->get_typeModifier().get_upcModifier().set_modifier(SgUPC_AccessModifier::e_upc_relaxed);
9284
9285#if 0
9286 printf ("In SageBuilder::buildUpcRelaxedType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9287#endif
9288
9289 // DQ (7/29/2010): Insert result type into type table and return it, or
9290 // replace the result type, if already available in the type table, with
9291 // the type from type table.
9292 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9293 if (result != result2)
9294 {
9295#if 0
9296 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9297 printf ("(debugging) In SageBuilder::buildUpcRelaxedType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9298#else
9299 delete result;
9300#endif
9301 }
9302
9303 return result2;
9304 }
9305
9306// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9308SgModifierType* SageBuilder::buildUpcSharedType(SgType* base_type /*=NULL*/, long layout /*= -1*/)
9309 {
9310 // DQ (9/3/2012): Added assertion.
9311 ROSE_ASSERT(base_type != NULL);
9312
9313 SgModifierType *result = new SgModifierType(base_type);
9314 ROSE_ASSERT(result!=NULL);
9315
9316 result->get_typeModifier().get_upcModifier().set_isShared(true);
9317
9318 // DQ (7/29/2010): Modified to use new input parameter.
9319 // result->get_typeModifier().get_upcModifier().set_layout(-1); // No layout ("shared" without a block size)
9320 result->get_typeModifier().get_upcModifier().set_layout(layout); // No layout ("shared" without a block size)
9321
9322#if 0
9323 printf ("In SageBuilder::buildUpcSharedType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9324#endif
9325
9326 // DQ (7/29/2010): Insert result type into type table and return it, or
9327 // replace the result type, if already available in the type table, with
9328 // the type from type table.
9329 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9330 if (result != result2)
9331 {
9332#if 0
9333 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9334 printf ("(debugging) In SageBuilder::buildUpcSharedType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9335#else
9336 delete result;
9337#endif
9338 }
9339
9340 return result2;
9341 }
9342
9343// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9346 {
9347 // DQ (9/3/2012): Added assertion.
9348 ROSE_ASSERT(base_type != NULL);
9349
9350 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9351 ROSE_ASSERT(result!=NULL);
9352
9353 result->get_typeModifier().get_upcModifier().set_layout(0); // [] layout
9354
9355#if 0
9356 printf ("In SageBuilder::buildUpcBlockIndefiniteType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9357#endif
9358
9359 // DQ (7/29/2010): Insert result type into type table and return it, or
9360 // replace the result type, if already available in the type table, with
9361 // the type from type table.
9362 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9363
9364 return result;
9365 }
9366
9367// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9370 {
9371 // DQ (9/3/2012): Added assertion.
9372 ROSE_ASSERT(base_type != NULL);
9373
9374 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9375 ROSE_ASSERT(result!=NULL);
9376
9377 result->get_typeModifier().get_upcModifier().set_layout(-2); // [*] layout
9378
9379#if 0
9380 printf ("In SageBuilder::buildUpcBlockStarType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9381#endif
9382
9383 // DQ (7/29/2010): Insert result type into type table and return it, or
9384 // replace the result type, if already available in the type table, with
9385 // the type from type table.
9386 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9387
9388 return result;
9389 }
9390
9391// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9394 {
9395 // DQ (9/3/2012): Added assertion.
9396 ROSE_ASSERT(base_type != NULL);
9397
9398 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9399 ROSE_ASSERT(result!=NULL);
9400
9401 result->get_typeModifier().get_upcModifier().set_layout(block_factor); // [block_factor] layout
9402
9403#if 0
9404 printf ("In SageBuilder::buildUpcBlockNumberType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9405#endif
9406
9407 // DQ (7/29/2010): Insert result type into type table and return it, or
9408 // replace the result type, if already available in the type table, with
9409 // the type from type table.
9410 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9411
9412 return result;
9413 }
9414
9415
9416
9419 {
9420 // DQ (9/3/2012): Added assertion.
9421 ROSE_ASSERT(base_type != NULL);
9422
9423 SgTypeComplex *result = new SgTypeComplex(base_type);
9424 ROSE_ASSERT(result!=NULL);
9425 return result;
9426 }
9427
9430 {
9431 // DQ (9/3/2012): Added assertion.
9432 ROSE_ASSERT(base_type != NULL);
9433
9434 SgTypeImaginary *result = new SgTypeImaginary(base_type);
9435 ROSE_ASSERT(result!=NULL);
9436 return result;
9437 }
9438
9441{
9442 SgTypeMatrix *result = new SgTypeMatrix();
9443 ROSE_ASSERT(result != NULL);
9444 return result;
9445}
9446
9449{
9450 SgTypeTuple *result = new SgTypeTuple();
9451 ROSE_ASSERT(result != NULL);
9452
9453 if(t1) result->append_type(t1);
9454 if(t2) result->append_type(t2);
9455 if(t3) result->append_type(t3);
9456 if(t4) result->append_type(t4);
9457 if(t5) result->append_type(t5);
9458 if(t6) result->append_type(t6);
9459 if(t7) result->append_type(t7);
9460 if(t8) result->append_type(t8);
9461 if(t9) result->append_type(t9);
9462 if(t10) result->append_type(t10);
9463
9465
9466 return result;
9467}
9468
9471 SgNonrealDecl * nrdecl = buildNonrealDecl(name, scope);
9472 nrdecl->set_parent(scope);
9473 nrdecl->set_is_template_param (true);
9474 return nrdecl->get_type();
9475}
9476
9478{
9479 SgRangeExp *result = new SgRangeExp();
9481 ROSE_ASSERT(result != NULL);
9482
9483 result->append(start);
9484 return result;
9485}
9486
9488{
9489 SgRangeExp *result = new SgRangeExp();
9491 ROSE_ASSERT(result != NULL);
9492
9493 result->set_start(start);
9494 start->set_parent(result);
9495
9496 result->set_end(end);
9497 end->set_parent(result);
9498
9499 result->set_stride(stride);
9500 stride->set_parent(result);
9501 return result;
9502}
9503
9504
9506{
9507 SgMatrixExp *result = new SgMatrixExp();
9509
9510 result->append_expression(firstRow);
9511 ROSE_ASSERT(result != NULL);
9512
9513 return result;
9514}
9515
9517{
9518 SgMagicColonExp *result = new SgMagicColonExp();
9520
9521 ROSE_ASSERT(result != NULL);
9522
9523 return result;
9524}
9525
9528{
9529 SgConstVolatileModifier * result = NULL;
9530 result = new SgConstVolatileModifier();
9531 ROSE_ASSERT (result != NULL);
9532 result->set_modifier (mtype);
9533
9534 return result;
9535}
9536
9540 {
9541 // SgFunctionDeclaration* func_decl = buildDefiningFunctionDeclaration("__rose__lambda__",return_type,params,scope,NULL,NULL);
9542 SgFunctionDeclaration* func_decl = buildDefiningFunctionDeclaration("__rose__lambda__",return_type,params,scope,NULL,false,NULL,NULL);
9543
9544 SgLambdaRefExp* result = new SgLambdaRefExp(func_decl);
9545 func_decl->set_parent(result);
9546
9548
9549 return result;
9550 }
9551
9554 {
9555 SgTypeExpression *expr = new SgTypeExpression(type);
9557 return expr;
9558 }
9559
9560// DQ (8/11/2014): Added support for C++11 decltype used in new function return syntax.
9562SageBuilder::buildFunctionParameterRefExp(int parameter_number, int parameter_level )
9563 {
9564 SgFunctionParameterRefExp *expr = new SgFunctionParameterRefExp(NULL,parameter_number,parameter_level);
9565 ROSE_ASSERT(expr != NULL);
9566
9567 setSourcePosition(expr);
9568 return expr;
9569 }
9570
9571
9572// DQ (8/11/2014): Added support for C++11 decltype used in new function return syntax.
9574SageBuilder::buildFunctionParameterRefExp_nfi(int parameter_number, int parameter_level )
9575 {
9576 SgFunctionParameterRefExp *expr = new SgFunctionParameterRefExp(NULL,parameter_number,parameter_level);
9577 ROSE_ASSERT(expr != NULL);
9578
9580 return expr;
9581 }
9582
9583// DQ (9/3/2014): Adding support for C++11 Lambda expressions
9585SageBuilder::buildLambdaExp(SgLambdaCaptureList* lambda_capture_list, SgClassDeclaration* lambda_closure_class, SgFunctionDeclaration* lambda_function)
9586 {
9587 SgLambdaExp *expr = new SgLambdaExp(lambda_capture_list,lambda_closure_class,lambda_function);
9588 ROSE_ASSERT(expr != NULL);
9589
9590 // Set the parents
9591 if (lambda_capture_list != NULL)
9592 {
9593 lambda_capture_list->set_parent(expr);
9594 }
9595
9596 if (lambda_closure_class != NULL)
9597 {
9598 lambda_closure_class->set_parent(expr);
9599 }
9600
9601 if (lambda_function != NULL)
9602 {
9603#if 1
9604 lambda_function->set_parent(expr);
9605#else
9606 if (lambda_closure_class != NULL)
9607 {
9608 lambda_function->set_parent(lambda_closure_class);
9609 }
9610 else
9611 {
9612 printf ("Warning: In SageBuilder::buildLambdaExp(): lambda_closure_class == NULL: lambda_function parent not set! \n");
9613 }
9614#endif
9615 }
9616
9617 setSourcePosition(expr);
9618 return expr;
9619 }
9620
9622SageBuilder::buildLambdaExp_nfi(SgLambdaCaptureList* lambda_capture_list, SgClassDeclaration* lambda_closure_class, SgFunctionDeclaration* lambda_function)
9623 {
9624 SgLambdaExp *expr = new SgLambdaExp(lambda_capture_list,lambda_closure_class,lambda_function);
9625 ROSE_ASSERT(expr != NULL);
9626
9627 // Set the parents
9628 if (lambda_capture_list != NULL)
9629 {
9630 lambda_capture_list->set_parent(expr);
9631 }
9632
9633 if (lambda_closure_class != NULL)
9634 {
9635 lambda_closure_class->set_parent(expr);
9636 }
9637
9638 if (lambda_function != NULL)
9639 {
9640#if 1
9641 lambda_function->set_parent(expr);
9642#else
9643 if (lambda_closure_class != NULL)
9644 {
9645 lambda_function->set_parent(lambda_closure_class);
9646 }
9647 else
9648 {
9649 printf ("Warning: In SageBuilder::buildLambdaExp(): lambda_closure_class == NULL: lambda_function parent not set! \n");
9650 }
9651#endif
9652 }
9653
9655 return expr;
9656 }
9657
9658#if 0
9660SageBuilder::buildLambdaCapture(SgInitializedName* capture_variable, SgInitializedName* source_closure_variable, SgInitializedName* closure_variable)
9661 {
9662 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9663 ROSE_ASSERT(lambdaCapture != NULL);
9664
9665 setSourcePosition(lambdaCapture);
9666 return lambdaCapture;
9667 }
9668
9670SageBuilder::buildLambdaCapture_nfi(SgInitializedName* capture_variable, SgInitializedName* source_closure_variable, SgInitializedName* closure_variable)
9671 {
9672 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9673 ROSE_ASSERT(lambdaCapture != NULL);
9674
9675 setOneSourcePositionNull(lambdaCapture);
9676 return lambdaCapture;
9677 }
9678#else
9680SageBuilder::buildLambdaCapture(SgExpression* capture_variable, SgExpression* source_closure_variable, SgExpression* closure_variable)
9681 {
9682 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9683 ROSE_ASSERT(lambdaCapture != NULL);
9684
9685 setSourcePosition(lambdaCapture);
9686 return lambdaCapture;
9687 }
9688
9690SageBuilder::buildLambdaCapture_nfi(SgExpression* capture_variable, SgExpression* source_closure_variable, SgExpression* closure_variable)
9691 {
9692 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9693 ROSE_ASSERT(lambdaCapture != NULL);
9694
9695 setOneSourcePositionNull(lambdaCapture);
9696 return lambdaCapture;
9697 }
9698#endif
9699
9702 {
9703 SgLambdaCaptureList *lambdaCaptureList = new SgLambdaCaptureList(NULL);
9704 ROSE_ASSERT(lambdaCaptureList != NULL);
9705
9706 setSourcePosition(lambdaCaptureList);
9707 return lambdaCaptureList;
9708 }
9709
9712 {
9713 SgLambdaCaptureList *lambdaCaptureList = new SgLambdaCaptureList(NULL);
9714 ROSE_ASSERT(lambdaCaptureList != NULL);
9715
9716 setOneSourcePositionNull(lambdaCaptureList);
9717 return lambdaCaptureList;
9718 }
9719
9720// DQ (7/25/2020): Adding C++17 support
9722SageBuilder::buildFoldExpression(SgExpression* operands, string operator_token_string, bool is_left_associative)
9723 {
9724 SgFoldExpression* result = new SgFoldExpression(NULL,operands,operator_token_string,is_left_associative);
9725 ROSE_ASSERT(result != NULL);
9726
9728 return result;
9729 }
9730
9732SageBuilder::buildFoldExpression_nfi(SgExpression* operands, string operator_token_string, bool is_left_associative)
9733 {
9734 SgFoldExpression* result = new SgFoldExpression(NULL,operands,operator_token_string,is_left_associative);
9735 ROSE_ASSERT(result != NULL);
9736
9738 return result;
9739 }
9740
9741// DQ (7/25/2020): Adding C++20 support
9744 {
9745 SgAwaitExpression* result = new SgAwaitExpression(NULL,NULL);
9746 ROSE_ASSERT(result != NULL);
9747
9749 return result;
9750 }
9753 {
9754 SgAwaitExpression* result = new SgAwaitExpression(NULL,NULL);
9755 ROSE_ASSERT(result != NULL);
9756
9758 return result;
9759 }
9760
9761// DQ (7/25/2020): Adding C++20 support
9764 {
9765 SgChooseExpression* result = new SgChooseExpression(NULL,NULL);
9766 ROSE_ASSERT(result != NULL);
9767
9769 return result;
9770 }
9771
9774 {
9775 SgChooseExpression* result = new SgChooseExpression(NULL,NULL);
9776 ROSE_ASSERT(result != NULL);
9777
9779 return result;
9780 }
9781
9782
9783
9786 {
9787 SgNamespaceDefinitionStatement* result = NULL;
9788 if (d!=NULL) // the constructor does not check for NULL d, causing segmentation fault
9789 {
9790 result = new SgNamespaceDefinitionStatement(d);
9791 result->set_parent(d); // set_declaration() == set_parent() in this case
9792 }
9793 else
9794 {
9795 result = new SgNamespaceDefinitionStatement(d);
9796 }
9797
9798 ROSE_ASSERT(result);
9799
9801 return result;
9802 }
9803
9806{
9807 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
9808 SageInterface::setSourcePosition(nonreal_decl_scope);
9809 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
9810 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
9811 return nonreal_decl_scope;
9812}
9813
9815SageBuilder::buildClassDefinition(SgClassDeclaration *d/*= NULL*/, bool buildTemplateInstantiation )
9816 {
9817 SgClassDefinition* result = NULL;
9818 if (d != NULL) // the constructor does not check for NULL d, causing segmentation fault
9819 {
9820 // result->set_parent(d); // set_declaration() == set_parent() in this case
9821 // result = new SgClassDefinition(d);
9822 ROSE_ASSERT(buildTemplateInstantiation == false || isSgTemplateInstantiationDecl(d) != NULL);
9823 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn(isSgTemplateInstantiationDecl(d)) : new SgClassDefinition(d);
9824 }
9825 else
9826 {
9827 // result = new SgClassDefinition();
9828 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn() : new SgClassDefinition();
9829 }
9830
9831 ROSE_ASSERT(result);
9832
9833 // CR (3/22/2020): Fixed setting case insensitivity
9834 // if (symbol_table_case_insensitive_semantics == true)
9836 {
9837 result->setCaseInsensitive(true);
9838 }
9839
9841
9842 return result;
9843 }
9844
9845
9846
9848SageBuilder::buildClassDefinition_nfi(SgClassDeclaration *d/*= NULL*/, bool buildTemplateInstantiation )
9849 {
9850 SgClassDefinition* result = NULL;
9851 if (d!=NULL) // the constructor does not check for NULL d, causing segmentation fault
9852 {
9853 // result->set_parent(d); // set_declaration() == set_parent() in this case
9854 // result = new SgClassDefinition(d);
9855 ROSE_ASSERT(buildTemplateInstantiation == false || isSgTemplateInstantiationDecl(d) != NULL);
9856 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn(isSgTemplateInstantiationDecl(d)) : new SgClassDefinition(d);
9857 }
9858 else
9859 {
9860 // result = new SgClassDefinition();
9861 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn() : new SgClassDefinition();
9862 }
9863
9864 ROSE_ASSERT(result);
9865
9866 // CR (3/22/2020): Fixed setting case insensitivity
9867 // if (symbol_table_case_insensitive_semantics == true)
9869 result->setCaseInsensitive(true);
9870
9872 return result;
9873 }
9874
9875
9877SageBuilder::buildNondefiningClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList)
9878 {
9879 SgName nameWithoutTemplateArguments = XXX_name;
9880
9881 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
9882
9883 // SgClassDeclaration* nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
9884 SgClassDeclaration* nondefdecl = NULL;
9885
9886#define DEBUG_NONDEFINING_CLASS_DECLARATION 0
9887
9888 // DQ (11/26/2011): Debugging EDG 3.3 use of templateArguments.
9889#if DEBUG_NONDEFINING_CLASS_DECLARATION
9890 printf ("Building a SgClassDeclaration: buildNondefiningClassDeclaration_nfi() nameWithoutTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithoutTemplateArguments.str(),buildTemplateInstantiation ? "true:" : "false");
9891 printf (" --- scope = %p = %s \n",scope,(scope != NULL) ? scope->class_name().c_str() : "null");
9892#endif
9893
9894 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
9895 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
9896 ROSE_ASSERT(SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == false);
9897
9898 if (buildTemplateInstantiation == true)
9899 {
9900 ROSE_ASSERT(templateArgumentsList != NULL);
9901 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
9902
9903#if DEBUG_NONDEFINING_CLASS_DECLARATION
9904 printf ("Building a SgClassDeclaration: buildNondefiningClassDeclaration_nfi() nameWithTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithTemplateArguments.str(),buildTemplateInstantiation ? "true:" : "false");
9905#endif
9906
9907 // SgTemplateInstantiationDecl (SgName name, SgClassDeclaration::class_types class_type, SgClassType *type, SgClassDefinition *definition, SgTemplateDeclaration *templateDeclaration, SgTemplateArgumentPtrList templateArguments)
9908 SgTemplateArgumentPtrList emptyList;
9909 // nondefdecl = new SgTemplateInstantiationDecl(name,kind,NULL,NULL,NULL,emptyList);
9910 nondefdecl = new SgTemplateInstantiationDecl(nameWithTemplateArguments,kind,NULL,NULL,NULL,emptyList);
9911#if DEBUG_NONDEFINING_CLASS_DECLARATION
9912 printf ("In buildNondefiningClassDeclaration_nfi(): built new SgTemplateInstantiationDecl: nondefdecl = %p \n",nondefdecl);
9913#endif
9914 ROSE_ASSERT(nondefdecl->get_type() == NULL);
9915 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl) != NULL);
9916#if DEBUG_NONDEFINING_CLASS_DECLARATION
9917 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_name() = %s nondefdecl->get_templateName() = %s \n",
9918 nondefdecl->get_name().str(),isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().str());
9919#endif
9920 // DQ (6/6/2012): Added support for template arguments so that they can be a part of any generated type.
9921 ROSE_ASSERT(templateArgumentsList != NULL);
9922
9923#if DEBUG_NONDEFINING_CLASS_DECLARATION
9924 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
9925 printf ("nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
9926 printf ("Output templateArgumentsList: \n");
9927 for (size_t i = 0; i < templateArgumentsList->size(); i++)
9928 {
9929 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
9930 printf (" --- --- name = %s \n",unparseTemplateArgumentToString(templateArgumentsList->operator[](i)).str());
9931 }
9932#endif
9933
9934 // DQ (3/9/2018): Added assertion.
9935 ROSE_ASSERT(nondefdecl->get_name() == nameWithTemplateArguments);
9936
9937 // DQ (5/8/2013): This fails for explicit template instantation examples (e.g. template <> class RepeatedPtrField<string>::TypeHandler {};, in test2013_159.C)
9938 // ROSE_ASSERT(templateArgumentsList->size() > 0);
9939#if 0
9940 // DQ (9/16/2012): Call the newly refactored function after the firstNondefiningDeclaration is set.
9941
9942 // Calling the assignment operator for the STL container class.
9943 isSgTemplateInstantiationDecl(nondefdecl)->get_templateArguments() = *templateArgumentsList;
9944
9945#error "DEAD CODE!"
9946
9947#if 1
9948 // DQ (9/13/2012): Refactored this code.
9949 setTemplateArgumentParents(nondefdecl);
9950#else
9951 // DQ (7/25/2012): Added this code here to reset the parents of the template arguments.
9952 for (size_t i = 0; i < templateArgumentsList->size(); i++)
9953 {
9954 // DQ (7/25/2012): This should be true because the template argument was set to the functions
9955 // scope so that the name with template arguments could be computed (with name qualification).
9956 ROSE_ASSERT((*templateArgumentsList)[i]->get_parent() != NULL);
9957
9958#error "DEAD CODE!"
9959
9960 // ROSE_ASSERT(isSgGlobal(templateArgumentsList[i]->get_parent()) == NULL);
9961 // ROSE_ASSERT(templateArgumentsList[i]->get_parent() == nondefining_templateInstantiation);
9962
9963 // Be we want to reset it to be the function (now that it is available, because this is more precise).
9964 // All qualified names should compute to the same qualified name (if not then it is a bug in the name
9965 // qualification mechanism).
9966 (*templateArgumentsList)[i]->set_parent(nondefdecl);
9967 }
9968#endif
9969#endif
9970 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == true);
9971 isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(nameWithoutTemplateArguments);
9972 }
9973 else
9974 {
9975 // nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
9976 nondefdecl = new SgClassDeclaration(nameWithoutTemplateArguments,kind,NULL,NULL);
9977#if DEBUG_NONDEFINING_CLASS_DECLARATION
9978 printf ("In buildNondefiningClassDeclaration_nfi(): built new SgClassDeclaration: nondefdecl = %p \n",nondefdecl);
9979#endif
9980 // The default name for nameWithTemplateArguments is nameWithoutTemplateArguments so that we can use
9981 // nameWithTemplateArguments uniformally as the name of the function and it will work from non-template
9982 // instantiations.
9983 ROSE_ASSERT(nameWithoutTemplateArguments == nameWithTemplateArguments);
9984 }
9985
9986 ROSE_ASSERT(nondefdecl != NULL);
9987
9988 // DQ (6/9/2013): Added assertion to debug test2013_198.C.
9989 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
9990
9991 // DQ (3/22/2012): I think we can assert this! No, in fact we can assert that it is not built yet.
9992 // ROSE_ASSERT(nondefdecl->get_type() != NULL);
9993 ROSE_ASSERT(nondefdecl->get_type() == NULL);
9994
9995#if 0
9996 // DQ (3/22/2012): I think this may be too early.
9997 // Liao, we ask for explicit creation of SgClassType to avoid duplicated type nodes
9998 if (nondefdecl->get_type() == NULL)
9999 {
10000 nondefdecl->set_type(SgClassType::createType(nondefdecl));
10001 }
10002#endif
10003
10004#if 0
10005 printf ("SageBuilder::buildNondefiningClassDeclaration_nfi(): (and setting source position) nondefdecl = %p \n",nondefdecl);
10006#endif
10007
10008 // The non-defining declaration asociated with a declaration does not have a
10009 // source position...unless it is the position of the defining declaration.
10010 // setOneSourcePositionNull(nondefdecl);
10011 setSourcePosition(nondefdecl);
10012
10013 // This is find for now, but a little later in this function (if we can find a symbol)
10014 // we want to find the first non-defining declaration (using the symbol table) and use
10015 // that as a paramter to "nondefdecl->set_firstNondefiningDeclaration()".
10016 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10017 nondefdecl->set_definingDeclaration(NULL);
10018 nondefdecl->setForward();
10019
10020 // This is the structural parent (the logical scope can be different than the parent).
10021 // TPS (09/18/2009) added a condition to be able to build this properly
10022 if (scope == NULL)
10023 nondefdecl->set_parent(topScopeStack());
10024 else
10025 nondefdecl->set_parent(scope);
10026
10027 // This is the logical scope...
10028 nondefdecl->set_scope(scope);
10029
10030 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10031
10032 SgClassDeclaration* firstNondefdecl = NULL;
10033 if (scope != NULL)
10034 {
10035#if 0
10036 SgClassSymbol* mysymbol = new SgClassSymbol(nondefdecl);
10037 ROSE_ASSERT(mysymbol != NULL);
10038
10039 // printf ("In SageBuilder::buildNondefiningClassDeclaration(): for nondefdecl = %p built SgClassSymbol = %p \n",nondefdecl,mysymbol);
10040
10041#error "DEAD CODE"
10042
10043 scope->insert_symbol(name, mysymbol);
10044#else
10045 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would
10046 // not include name qualification on template arguments.
10047 // Reuse any previously defined symbols (to avoid redundant symbols in the symbol table)
10048 // and find the firstNondefiningDeclaration.
10049 // SgClassSymbol* mysymbol = scope->lookup_class_symbol(name);
10050 // SgClassSymbol* mysymbol = scope->lookup_nontemplate_class_symbol(name);
10051 // SgClassSymbol* mysymbol = scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments);
10052 SgClassSymbol* mysymbol = scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
10053
10054#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10055 printf ("In SageBuilder::buildNondefiningClassDeclaration(): mysymbol = %p = %s \n",mysymbol,(mysymbol != NULL) ? mysymbol->class_name().c_str() : "null");
10056#endif
10057 if (mysymbol != NULL)
10058 {
10059 firstNondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
10060 ROSE_ASSERT(firstNondefdecl != NULL);
10061
10062 // DQ (9/4/2012): Added assertion.
10063 ROSE_ASSERT(firstNondefdecl->get_type() != NULL);
10064
10065 // DQ (3/22/2012): Now we can built the type and have it use the same nondefining declaration as from the symbol (required to match).
10066 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10067
10068 if (nondefdecl->get_type() == NULL)
10069 {
10070#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10071 printf ("In SageBuilder::buildNondefiningClassDeclaration(): Why are we creating a new type instead of reusing the type (firstNondefdecl->get_type() = %p) from the firstNondefdecl = %p \n",firstNondefdecl->get_type(),firstNondefdecl);
10072#endif
10073 // Note: It would be better to just call: "nondefdecl->set_type(firstNondefdecl->get_type());"
10074#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10075 printf ("NOTE: Call nondefdecl->set_type(firstNondefdecl->get_type()); instead of nondefdecl->set_type(SgClassType::createType(firstNondefdecl)); \n");
10076#endif
10077 // DQ (3/22/2012): Be careful to use the same declaration as from the symbol.
10078 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
10079 nondefdecl->set_type(SgClassType::createType(firstNondefdecl));
10080 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10081#if 0
10082 printf ("In SageBuilder::buildNondefiningClassDeclaration(): built class type: part 1: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
10083#endif
10084
10085#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10086 printf ("In SageBuilder::buildNondefiningClassDeclaration(): nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
10087#endif
10088 // DQ (9/4/2012): Added assertion.
10089 ROSE_ASSERT(nondefdecl->get_type() == firstNondefdecl->get_type());
10090 }
10091
10092#if (REUSE_CLASS_DECLARATION_FROM_SYMBOL == 0)
10093 ROSE_ASSERT(nondefdecl != NULL);
10094 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10095
10096 // DQ (5/18/2014): Added test to match that in set_firstNondefiningDeclaration().
10097 // This is a problem for the Boost code after the fix to detec templates vs. template instantiation declarations.
10098 if (nondefdecl->variantT() != firstNondefdecl->variantT())
10099 {
10100 printf ("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): nondefdecl = %p = %s IS NOT THE SAME AS firstNondefiningDeclaration = %p = %s \n",
10101 nondefdecl,nondefdecl->class_name().c_str(),firstNondefdecl,firstNondefdecl->class_name().c_str());
10102 ROSE_ASSERT(nondefdecl->get_file_info() != NULL);
10103 nondefdecl->get_file_info()->display("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): nondefdecl: debug");
10104 ROSE_ASSERT(firstNondefdecl->get_file_info() != NULL);
10105 firstNondefdecl->get_file_info()->display("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): firstNondefdecl: debug");
10106 }
10107
10108 // DQ (5/18/2014): Added test to match that in set_firstNondefiningDeclaration().
10109 ROSE_ASSERT(nondefdecl->variantT() == firstNondefdecl->variantT());
10110
10111 nondefdecl->set_firstNondefiningDeclaration(firstNondefdecl);
10112
10113 // This might be NULL if the defining declaration has not been seen yet!
10114 nondefdecl->set_definingDeclaration(firstNondefdecl->get_definingDeclaration());
10115
10116 // DQ (3/22/2012): New assertions.
10117 ROSE_ASSERT(firstNondefdecl != NULL);
10118 ROSE_ASSERT(firstNondefdecl->get_type() != NULL);
10119
10120 // DQ (9/16/2012): This is a newly refactored function (call this after we know the firstNondefiningDeclaration is set correctly).
10121 // This is called in the other branch (mysymbol == NULL), but there is must be called before the symbol table is appended with
10122 // the new symbol for this declaration. So we have to call this in this brach and re can't refactor this be be called one before
10123 // both branches or once after both branches.
10124 if (buildTemplateInstantiation == true)
10125 {
10126 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
10127 }
10128
10129 // DQ (9/4/2012): We can now assert this because of how the type is constructed above.
10130 ROSE_ASSERT (nondefdecl->get_type() == firstNondefdecl->get_type());
10131
10132 // Share the type!
10133 if (nondefdecl->get_type() != firstNondefdecl->get_type())
10134 {
10135 // Remove the type from the new SgClassDeclaration and set the reference to the type in the firstNondefiningDeclaration.
10136 printf ("Deleting type in associated non-defining declaration (sharing type) nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
10137 printf ("Skipping delete of %p so we can maintain unique type pointers \n",nondefdecl->get_type());
10138 // delete nondefdecl->get_type();
10139 printf ("Setting the new type to be from firstNondefdecl = %p (sharing type) firstNondefdecl->get_type() = %p = %s \n",firstNondefdecl,firstNondefdecl->get_type(),firstNondefdecl->get_type()->class_name().c_str());
10140 nondefdecl->set_type(firstNondefdecl->get_type());
10141#if 1
10142 // DQ (12/13/2011): Is this executed!
10143 printf ("Unclear if this code is executed \n");
10144 ROSE_ABORT();
10145#endif
10146 }
10147#else
10148#error "DEAD CODE"
10149
10150 ROSE_ASSERT(nondefdecl == NULL);
10151#endif
10152 // This function should return a new nondefining declaration each time (to support multile class prototypes!).
10153 // nondefdecl = firstNondefdecl;
10154 }
10155 else
10156 {
10157#if REUSE_CLASS_DECLARATION_FROM_SYMBOL
10158 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
10159
10160#error "DEAD CODE"
10161
10162 nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
10163
10164#error "DEAD CODE"
10165
10166 ROSE_ASSERT(nondefdecl != NULL);
10167 if (nondefdecl->get_type() == NULL)
10168 nondefdel->set_type(SgClassType::createType(nondefdecl));
10169
10170 printf ("SageBuilder::buildNondefiningClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
10171
10172 setOneSourcePositionNull(nondefdecl);
10173
10174#error "DEAD CODE"
10175
10176 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10177 nondefdecl->set_definingDeclaration(NULL);
10178 nondefdecl->setForward();
10179#endif
10180
10181 // DQ (6/9/2013): Added assertion to debug test2013_198.C.
10182 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10183
10184 mysymbol = new SgClassSymbol(nondefdecl);
10185 firstNondefdecl = nondefdecl;
10186
10187 // DQ (6/9/2013): Adding assertions to make sure that symbols only reference non-defining declarations.
10188 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10189 ROSE_ASSERT(mysymbol->get_declaration()->get_definition() == NULL);
10190
10191 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
10192 // Note that since the symbol tables use the template arguments associated with the declaration it is best to
10193 // fixup the template arguments before the symbol table is fixup to have a symbol for this declaration. So we
10194 // fixup the template arguments here (just after we know that the firstNondefiningDeclaration is set correctly
10195 // and just before the symbol is inserted into the symbol table.
10196 if (buildTemplateInstantiation == true)
10197 {
10198 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
10199 }
10200#if DEBUG_NONDEFINING_CLASS_DECLARATION
10201 printf ("BEFORE scope->insert_symbol(): scope = %p = %s nameWithTemplateArguments = %s mysymbol = %p = %s \n",
10202 scope,scope->class_name().c_str(),nameWithTemplateArguments.str(),mysymbol,mysymbol->class_name().c_str());
10203#endif
10204
10205 // scope->insert_symbol(name, mysymbol);
10206 scope->insert_symbol(nameWithTemplateArguments, mysymbol);
10207
10208 // DQ (3/22/2012): Now we can built the type and have it use the same nondefining declaration as from the symbol (required to match).
10209 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10210 if (nondefdecl->get_type() == NULL)
10211 {
10212#if 0
10213 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
10214 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_firstNondefiningDeclaration() = %p \n",nondefdecl->get_firstNondefiningDeclaration());
10215#endif
10216 nondefdecl->set_type(SgClassType::createType(nondefdecl));
10217#if 0
10218 printf ("In SageBuilder::buildNondefiningClassDeclaration(): built class type: part 2: nondefdecl->get_type() = %p = %s = %s \n",
10219 nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str(),nondefdecl->get_type()->unparseToString().c_str());
10220#endif
10221 }
10222
10223#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10224 printf ("NOTE: In buildNondefiningClassDeclaration_nfi(): 2nd time this is a performance issue (maybe) to call the lookup_nontemplate_class_symbol() again \n");
10225#endif
10226 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would
10227 // not include name qualification on template arguments.
10228 // DQ (12/27/2011): Added new test.
10229 // ROSE_ASSERT(scope->lookup_nontemplate_class_symbol(name) != NULL);
10230 // TV (07/01/2013): this assertion fail when building basic class (buildTemplateInstantiation = false , templateArgumentsList = NULL)
10231 // ROSE_ASSERT(scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
10232
10233 // DQ (6/9/2013): Added test to make sure that symbols only reference non-defining declarations.
10234 SgClassSymbol* temp_classSymbol = nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
10235#if DEBUG_NONDEFINING_CLASS_DECLARATION
10236 // DQ (12/28/2018): When can this be NULL?
10237 printf ("In buildNondefiningClassDeclaration_nfi(): temp_classSymbol = %p \n",temp_classSymbol);
10238 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_scope() = %p = %s scope = %p \n",nondefdecl->get_scope(),nondefdecl->get_scope()->class_name().c_str(),scope);
10239
10240 printf ("In buildNondefiningClassDeclaration_nfi(): nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
10241 if (templateArgumentsList != NULL)
10242 {
10243 printf (" --- templateArgumentsList elements: \n");
10244 for (size_t i = 0; i < templateArgumentsList->size(); i++)
10245 {
10246 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
10247 printf (" --- --- templateArgumentsList->[%zu] = %s \n",i,templateArgumentsList->operator[](i)->class_name().c_str());
10248 templateArgumentsList->operator[](i)->display("In SageBuilder::buildNondefiningClassDeclaration_nfi()");
10249 }
10250 }
10251#endif
10252 // DQ (12/28/2018): When can this be NULL? When we call lookup_class_symbol() later it is NULL, so test it here.
10253 ROSE_ASSERT(nondefdecl->get_scope()->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
10254 ROSE_ASSERT(nondefdecl->get_scope() == scope);
10255
10256 // TV (07/01/2013): temp_classSymbol can be NULL, but lookup_class_symbol return a symbol
10257 // ROSE_ASSERT(temp_classSymbol->get_declaration()->get_definition() == NULL);
10258 ROSE_ASSERT(temp_classSymbol == NULL || temp_classSymbol->get_declaration()->get_definition() == NULL);
10259 }
10260
10261 ROSE_ASSERT(mysymbol != NULL);
10262 ROSE_ASSERT(firstNondefdecl != NULL);
10263#endif
10264 nondefdecl->set_scope(scope);
10265
10266 // DQ (1/25/2009): The scope is not the same as the parent, since the scope is logical, and the parent is structural (note that topScopeStack() is structural).
10267 // TPS (09/18/2009) added a condition to be able to build this properly
10268 if (scope==NULL)
10269 nondefdecl->set_parent(topScopeStack());
10270 else
10271 nondefdecl->set_parent(scope);
10272 }
10273
10274 // The support for SgEnumDeclaration handles the type, but why not for SgClassDeclaration?
10275 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10276
10277 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10278
10279#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10280 printf ("NOTE: In buildNondefiningClassDeclaration_nfi(): 3rd time this is a performance issue (maybe) to call the lookup_nontemplate_class_symbol() again \n");
10281#endif
10282
10283 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would not include name qualification on template arguments.
10284 // DQ (12/27/2011): Added new test.
10285 // ROSE_ASSERT(nondefdecl->get_scope()->lookup_nontemplate_class_symbol(name) != NULL);
10286 // TV (07/01/2013): this assertion fail when building basic class (buildTemplateInstantiation = false , templateArgumentsList = NULL)
10287 // ROSE_ASSERT(nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
10288
10289 // DQ (6/9/2013): Added test to make sure that symbols only reference non-defining declarations.
10290 SgClassSymbol* temp_classSymbol = nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
10291 // TV (07/01/2013): temp_classSymbol can be NULL, but lookup_class_symbol return a symbol
10292 ROSE_ASSERT(temp_classSymbol == NULL || temp_classSymbol->get_declaration()->get_definition() == NULL);
10293
10294 // DQ (3/9/2018): Added assertion.
10295 ROSE_ASSERT(nondefdecl != NULL);
10296 ROSE_ASSERT(nondefdecl->get_name() == nameWithTemplateArguments);
10297
10298 // DQ (3/9/2018): Test the consistancy of the template instantiation name.
10299 if (isSgTemplateInstantiationDecl(nondefdecl) != NULL)
10300 {
10301 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(nondefdecl);
10302 SgName finalName = appendTemplateArgumentsToName(templateInstantiationDecl->get_templateName(),templateInstantiationDecl->get_templateArguments());
10303 ROSE_ASSERT(finalName == nameWithTemplateArguments);
10304 ROSE_ASSERT(finalName == nondefdecl->get_name());
10305 }
10306
10307#if DEBUG_NONDEFINING_CLASS_DECLARATION
10308 printf ("Leaving buildNondefiningClassDeclaration_nfi(): nondefdecl = %p nondefdecl->unparseNameToString() = %s \n",nondefdecl,nondefdecl->unparseNameToString().c_str());
10309 printf (" --- nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
10310#endif
10311
10312#if DEBUG_NONDEFINING_CLASS_DECLARATION
10313 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
10314 printf ("Leaving buildNondefiningClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
10315 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
10316
10317 printf ("test_symbol = %p \n",test_symbol);
10318
10319 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
10320 printf ("Leaving buildNondefiningClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
10321 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
10322#endif
10323
10324 return nondefdecl;
10325 }
10326
10329 ROSE_ASSERT(stmt != NULL);
10330
10332 stmt->set_parent(result);
10333
10334 result->set_definingDeclaration(result);
10336 return result;
10337}
10338
10341 ROSE_ASSERT(stmt != NULL);
10342
10344 stmt->set_parent(result);
10345
10346 result->set_definingDeclaration(result);
10348 return result;
10349}
10350
10352SageBuilder::buildJovialDefineDeclaration_nfi(const SgName& name, const std::string& params,
10353 const std::string& def_string, SgScopeStatement* scope)
10354 {
10355 std::string directive_string(name);
10356
10357 if (scope == NULL)
10359 ROSE_ASSERT(scope);
10360
10361 if (params.length() > 0)
10362 directive_string += " " + params;
10363
10364 directive_string += " " + def_string;
10365
10366 SgJovialDefineDeclaration* define_decl = new SgJovialDefineDeclaration(directive_string);
10367 ROSE_ASSERT(define_decl);
10369
10370 // The first nondefining declaration must be set
10371 define_decl->set_firstNondefiningDeclaration(define_decl);
10372 define_decl->set_parent(scope);
10373
10374 return define_decl;
10375 }
10376
10377// Build a Jovial loop statement. Two variants are FOR and WHILE.
10378// A loop body will be created and its parent set to the loop statement.
10381{
10382 SgJovialForThenStatement* forStmt{nullptr};
10383
10385
10386 forStmt = new SgJovialForThenStatement(nullptr, nullptr, nullptr, body);
10387 ASSERT_not_null(forStmt);
10388 setOneSourcePositionNull(forStmt);
10389
10390 body->set_parent(forStmt);
10391
10393 forStmt->setCaseInsensitive(true);
10394 }
10395
10396 return forStmt;
10397}
10398
10399// This should take a SgClassDeclaration::class_types kind parameter!
10401 {
10402#if 0
10403
10404 if (scope == NULL)
10406
10407 // TODO How about class type??
10408 // build defining declaration
10410
10411 SgClassDeclaration* defdecl = new SgClassDeclaration (name,SgClassDeclaration::e_struct,NULL,classDef);
10412 ROSE_ASSERT(defdecl);
10414 // constructor is side-effect free
10415 classDef->set_declaration(defdecl);
10416 defdecl->set_definingDeclaration(defdecl);
10417
10418 // build the nondefining declaration
10419 SgClassDeclaration* nondefdecl = new SgClassDeclaration (name,SgClassDeclaration::e_struct,NULL,NULL);
10420 ROSE_ASSERT(nondefdecl);
10421
10423 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10424 nondefdecl->set_definingDeclaration(defdecl);
10425 defdecl->set_firstNondefiningDeclaration(nondefdecl);
10426 nondefdecl->setForward();
10427
10428 if (scope !=NULL ) // put into fixStructDeclaration() or alike later on
10429 {
10430 fixStructDeclaration(nondefdecl,scope);
10431 fixStructDeclaration(defdecl,scope);
10432 }
10433#else
10434 // DQ (1/24/2009): Refactored to use the buildStructDeclaration_nfi function.
10435 // (if this work it needs to be done uniformally for the other nfi functions)
10436 // Also, "_nfi" is not a great name.
10437 // SgClassDeclaration* defdecl = buildClassDeclaration_nfi(name,SgClassDeclaration::e_struct,scope,NULL);
10438 bool buildTemplateInstantiation = false;
10439 // SgClassDeclaration* defdecl = buildClassDeclaration_nfi(name,SgClassDeclaration::e_struct,scope,NULL,buildTemplateInstantiation);
10440 SgClassDeclaration* defdecl = buildClassDeclaration_nfi(name,SgClassDeclaration::e_struct,scope,NULL,buildTemplateInstantiation,NULL);
10441
10443 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
10445#endif
10446
10447 // DQ (1/26/2009): I think this should be an error, but that appears it would
10448 // break the existing interface. Need to discuss this with Liao.
10449 // ROSE_ASSERT(defdecl->get_parent() != NULL);
10450
10451 return defdecl;
10452 }
10453
10456 {
10458 SgDerivedTypeStatement* type_decl = buildClassDeclarationStatement_nfi <SgDerivedTypeStatement> (name, kind, scope);
10459
10461 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() != NULL);
10463
10464 return type_decl;
10465 }
10466
10469 {
10471 SgModuleStatement* module_stmt = buildClassDeclarationStatement_nfi <SgModuleStatement> (name, kind, scope);
10472
10474 ROSE_ASSERT(module_stmt->get_firstNondefiningDeclaration() != NULL);
10476
10477 return module_stmt;
10478 }
10479
10483 SgScopeStatement* scope /*=NULL*/)
10484 {
10485 SgJovialTableStatement* table_decl = buildClassDeclarationStatement_nfi <SgJovialTableStatement> (name, kind, scope);
10486
10488 ROSE_ASSERT(table_decl->get_firstNondefiningDeclaration() != NULL);
10490
10491 return table_decl;
10492 }
10493
10496 {
10497 std::string type_name(name);
10498 if (base_type) {
10499 // Mangle the name to make sure the table type and the base type don't have the same name
10500 type_name = "_table_of_" + type_name;
10501 // Add dim_info address if there are subscripts to ensure type is unique
10502 if (dim_info->get_expressions().size() > 0) {
10503 std::ostringstream address;
10504 address << (void const *)dim_info;
10505 type_name += "_" + address.str();
10506 }
10507 }
10508
10510 SgJovialTableStatement* table_decl = buildClassDeclarationStatement_nfi <SgJovialTableStatement> (type_name, kind, scope);
10511
10513 ROSE_ASSERT(table_decl->get_firstNondefiningDeclaration() != NULL);
10515
10516 // For a type declaration the parent of the nondefining declaration is the defining declaration
10517 SgClassDeclaration* nondef_decl = isSgClassDeclaration(table_decl->get_firstNondefiningDeclaration());
10518 ROSE_ASSERT(nondef_decl != NULL);
10519 nondef_decl->set_parent(table_decl);
10520
10521 SgJovialTableType* table_type = isSgJovialTableType(table_decl->get_type());
10522 ROSE_ASSERT(table_type != NULL);
10523
10524 table_type->set_base_type(base_type);
10525 table_type->set_dim_info(dim_info);
10526 table_type->set_rank(dim_info->get_expressions().size());
10527
10528 dim_info->set_parent(table_type);
10529 nondef_decl->set_type(table_type);
10530
10531 return table_type;
10532 }
10533
10535template <class DeclClass> DeclClass *
10537 SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl)
10538 {
10539 // DQ (3/15/2012): Added function to build C++ class (builds both the non-defining and defining declarations; in that order).
10540 // The implementation of this function could be simplified to directly call both:
10541 // SgClassDeclaration* buildNondefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10542 // and
10543 // SgClassDeclaration* buildDefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10544 // This might refactor the implementation nicely.
10545
10546 if (scope == NULL)
10547 {
10549 }
10550
10551 // Step 1. Build the nondefining declaration (but only if the input nonDefiningDecl pointer was NULL and it does not exist)
10552 // -----------------------------------------
10553 //
10554
10555 // Get the nondefining declaration from the symbol if it has been built (if this works,
10556 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
10557
10558 SgClassDeclaration* nondefdecl = NULL;
10559 SgClassSymbol* mysymbol = NULL;
10560
10561 if (scope != NULL)
10562 {
10563 // DQ (10/10/2015): look up the correct type of symbol.
10564 mysymbol = scope->lookup_class_symbol(name);
10565
10566 if (mysymbol == NULL)
10567 {
10568 // Note: this is an input parameter (could/should go away?) [CR]
10569 if (nonDefiningDecl != NULL)
10570 {
10571 // DQ (3/4/2018): I think this is the correct API to use (internal use only).
10572 SgSymbol* temp_mysymbol = nonDefiningDecl->get_symbol_from_symbol_table();
10573 ROSE_ASSERT(temp_mysymbol != NULL);
10574
10575 mysymbol = isSgClassSymbol(temp_mysymbol);
10576 ROSE_ASSERT(mysymbol != NULL);
10577
10578 // check that the scopes are the same.
10579 ROSE_ASSERT(scope == nonDefiningDecl->get_scope());
10580 }
10581 }
10582 }
10583
10584 if (mysymbol != NULL) // set links for existing nondefining declaration
10585 {
10586 nondefdecl = (mysymbol->get_declaration() == NULL)
10587 ? NULL : dynamic_cast<DeclClass*>(mysymbol->get_declaration());
10588 ROSE_ASSERT(nondefdecl != NULL);
10589
10590 // DQ (6/8/2013): This should not be true (see test2013_198.C).
10591 // Fundamentally the symbol should always only have a pointer to a non-defining
10592 // declaration, where by definition (get_definition() == NULL).
10593 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10594
10595 // DQ (9/16/2012): This should be true by definition (verify).
10596 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
10597
10598 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10599 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10600
10601 // DQ (9/7/2012): I think this might be the root of a problem in the haskell tests (ROSE compiling ROSE).
10602 if (nondefdecl->get_definingDeclaration() != NULL)
10603 {
10604 DeclClass* nondefining_classDeclaration = (nondefdecl == NULL) ? NULL : dynamic_cast<DeclClass*>(nondefdecl);
10605 ROSE_ASSERT(nondefining_classDeclaration != NULL);
10606 DeclClass* defining_classDeclaration = (nondefdecl->get_definingDeclaration() == NULL)
10607 ? NULL : dynamic_cast<DeclClass*>(nondefdecl->get_definingDeclaration());
10608 ROSE_ASSERT(defining_classDeclaration != NULL);
10609
10610 return defining_classDeclaration;
10611 }
10612 }
10613 else // build a nondefining declaration since it does not exist
10614 {
10615 ROSE_ASSERT(nondefdecl == NULL);
10616
10617 // DeclClass is the template type parameter
10618 nondefdecl = new DeclClass(name, kind, NULL, NULL);
10619 ROSE_ASSERT(nondefdecl != NULL);
10620
10621 // The first nondefining declaration has to be set before we generate the type.
10622 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10623
10624 // DQ (7/25/2017): This will be true, but it might not be what we want since it can be caught as an error in the code below.
10625 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
10626
10627 // DQ (3/14/2012): For C++ we need the scope set so that types will have proper locations to resolve them
10628 // from being ambiguous or not properly defined. Basically, we need a handle from which to generate something
10629 // that amounts to a kind of name qualification internally (maybe even exactly name qualification, but I would
10630 // have to think about that a bit more).
10631 ROSE_ASSERT(scope != NULL);
10632
10633 // Set the parent before calling the SgClassType::createType() as the name mangling will require it.
10634 // This is true for Fortran SgDerivedTypeStatement at least.
10635 nondefdecl->set_parent(scope);
10636 nondefdecl->set_scope(scope);
10637
10638 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
10639 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10640
10641 if (nondefdecl->get_type() == NULL)
10642 {
10643 SgClassType* class_type = NULL;
10644 switch (kind)
10645 {
10647 class_type = SgJavaParameterType::createType(nondefdecl);
10648 break;
10651 class_type = SgJovialTableType::createType(nondefdecl);
10652 break;
10653 default:
10654 class_type = SgClassType::createType(nondefdecl);
10655 break;
10656 }
10657 ROSE_ASSERT(class_type != NULL);
10658
10659 nondefdecl->set_type(class_type);
10660
10661 SgClassDeclaration* tmp_classDeclarationFromType = isSgClassDeclaration(class_type->get_declaration());
10662 ROSE_ASSERT(tmp_classDeclarationFromType != NULL);
10663 }
10664
10665 // DQ (3/22/2012): Added assertions.
10666 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10667 if (nondefdecl->get_type()->get_declaration() != nondefdecl)
10668 {
10669 printf ("ERROR: nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
10670 printf ("ERROR: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
10671 printf ("ERROR: nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
10672
10673 SgClassDeclaration* classDeclarationFromType = isSgClassDeclaration(nondefdecl->get_type()->get_declaration());
10674 ROSE_ASSERT(classDeclarationFromType != NULL);
10675
10676 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
10677 printf ("nondefdecl->get_type()->get_name() = %s \n",nondefdecl->get_type()->get_name().str());
10678 printf ("nondefdecl->get_type()->get_declaration()->get_name() = %s \n",classDeclarationFromType->get_name().str());
10679
10680 printf ("nondefdecl->get_mangled_name() = %s \n",nondefdecl->get_mangled_name().getString().c_str());
10681 printf ("nondefdecl->get_type()->get_mangled() = %s \n",nondefdecl->get_type()->get_mangled().getString().c_str());
10682 printf ("nondefdecl->get_type()->get_declaration()->get_mangled_name() = %s \n",classDeclarationFromType->get_mangled_name().getString().c_str());
10683
10684 // DQ (12/27/2018): Added additional debugging support.
10685 printf ("nondefdecl->get_type()->get_declaration()->get_firstNondefiningDeclaration() = %s \n",classDeclarationFromType->get_firstNondefiningDeclaration() ? "true" : "false");
10686 printf ("nondefdecl->get_firstNondefiningDeclaration() = %s \n",nondefdecl->get_firstNondefiningDeclaration() ? "true" : "false");
10687
10688 // DQ (12/27/2018): I think that if this is a base class declaration then it is OK for the type's declaration to not match.
10689 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10690 if (nondefdecl->get_parent() != NULL)
10691 {
10692 printf ("nondefdecl->get_parent() = %p = %s \n",nondefdecl->get_parent(),nondefdecl->get_parent()->class_name().c_str());
10693 }
10694 }
10695 ROSE_ASSERT(nondefdecl->get_type()->get_declaration() == nondefdecl);
10696
10697 // The nondefining declaration will not appear in the source code, but is compiler
10698 // generated (so we have something about the class that we can reference; e.g in
10699 // types). At the moment we make it a transformation, there might be another kind
10700 // of source position that would be more precise. FIXME.
10701 // setOneSourcePositionNull(nondefdecl);
10703 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
10704
10705#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
10706 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
10707 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
10708 {
10709 detectTransformations(nondefdecl);
10710 }
10711#endif
10712
10713 nondefdecl->setForward();
10714
10715 if (scope != NULL)
10716 {
10717 mysymbol = new SgClassSymbol(nondefdecl);
10718 scope->insert_symbol(name, mysymbol);
10719
10720 ROSE_ASSERT(nondefdecl->get_scope() == scope);
10721 }
10722 }
10723
10724 // DQ (3/15/2012): I have moved construction of defining declaration to be AFTER the nondefining declaration!
10725 // This is a better organization ans also should make sure that the declaration in the SgClassType will
10726 // properly reference the firstNondefiningDeclaration (instead of the defining declaration).
10727
10728 // Step 2. Build the defining declaration
10729 // --------------------------------------
10730 //
10732
10733 DeclClass* defdecl = new DeclClass(name,kind,NULL,classDef);
10734 ROSE_ASSERT(defdecl != NULL);
10735 ROSE_ASSERT(defdecl->get_type() == NULL);
10736
10737 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
10738 ROSE_ASSERT(defdecl->get_definition() != NULL);
10739 ROSE_ASSERT(defdecl != NULL);
10740
10741 // DQ (3/15/2012): Moved from original location above...
10742 nondefdecl->set_definingDeclaration(defdecl);
10743
10744 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
10745 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
10746
10748 // constructor is side-effect free
10749 classDef->set_declaration(defdecl);
10750 defdecl->set_definingDeclaration(defdecl);
10751
10752 defdecl->set_firstNondefiningDeclaration(nondefdecl);
10753
10754 // DQ (3/22/2012): I think we can assert this.
10755 ROSE_ASSERT(defdecl->get_type() == NULL);
10756
10757 // Liao, 10/30/2009
10758 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
10759 // This is not desired when building a defining declaration and an inefficience in the constructor
10760 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
10761 // the defining class declaration (and other nondefining declaration) just share that SgClassType.
10762 if (defdecl->get_type() != NULL)
10763 {
10764 // Removed several lines of dead code because of the assertion just above
10765 }
10766 else
10767 {
10768 // DQ (3/15/2012): Make sure that both the defining and non-defining declarations use the same type.
10769 ROSE_ASSERT (nondefdecl->get_type() != NULL);
10770 defdecl->set_type(nondefdecl->get_type());
10771
10772 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
10773 }
10774
10775 // DQ (9/4/2012): Added assertion.
10776 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10777
10778 // patch up the SgClassType for the defining class declaration
10779 ROSE_ASSERT (nondefdecl->get_type() != NULL);
10780 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
10781 // ROSE_ASSERT (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl));
10782 ROSE_ASSERT (defdecl->get_type() != NULL);
10783 ROSE_ASSERT (defdecl->get_type()->get_declaration() != NULL);
10784 ROSE_ASSERT (defdecl->get_type()->get_declaration() != isSgDeclarationStatement(defdecl));
10785 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
10786 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
10787
10788 // DQ (9/4/2012): Added assertion.
10789 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10790
10791 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
10792 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
10793 // used in a defining declaration).
10794 nondefdecl->setForward();
10795
10796 if (scope != NULL) // put into fixStructDeclaration() or alike later on
10797 {
10798 // DQ (9/4/2012): Added assertion.
10799 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10800
10801 // Note, this function sets the parent to be the scope if it is not already set.
10802 fixStructDeclaration(defdecl,scope);
10803
10804 // DQ (9/4/2012): Added assertion.
10805 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10806
10807 fixStructDeclaration(nondefdecl,scope);
10808
10809 // DQ (9/4/2012): Added assertion.
10810 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10811 }
10812
10813 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
10814 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
10815 // ROSE_ASSERT(defdecl->get_parent() != NULL);
10816
10817 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
10818
10819 // DQ (2/27/2012): Tracking down where parents are not set correctly (class declaration in typedef is incorrectly set to SgGlobal).
10820 ROSE_ASSERT(defdecl->get_parent() == NULL);
10821
10822 // DQ (2/29/2012): We can't assert this (fails for test2012_09.C).
10823 // ROSE_ASSERT(nondefdecl->get_parent() == NULL);
10824
10825 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
10826 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
10827
10828 // DQ (3/8/2018): Added for debugging.
10829 SgClassDeclaration* temp_firstNondefiningDeclaration = isSgClassDeclaration(defdecl->get_firstNondefiningDeclaration());
10830 SgClassDeclaration* temp_definingDeclaration = isSgClassDeclaration(defdecl->get_definingDeclaration());
10831 ROSE_ASSERT(temp_firstNondefiningDeclaration != NULL);
10832 ROSE_ASSERT(temp_definingDeclaration != NULL);
10833
10834 // DQ (3/8/2018): Added assertion.
10835 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_name() == temp_definingDeclaration->get_name());
10836 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_type() == temp_definingDeclaration->get_type());
10837
10838#if 0
10839 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
10840 printf ("Leaving buildClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
10841 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
10842
10843 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
10844 printf ("Leaving buildClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
10845 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
10846#endif
10847
10848 return defdecl;
10849 }
10850
10853 {
10854 SgNamespaceAliasDeclarationStatement* aliasdecl = new SgNamespaceAliasDeclarationStatement(name,namespaceDeclaration);
10857 return aliasdecl;
10858 }
10859
10860
10863 {
10865
10867 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
10869
10870 return defdecl;
10871 }
10872
10874SageBuilder::buildNamespaceDeclaration_nfi(const SgName& name, bool unnamednamespace, SgScopeStatement* scope)
10875 {
10876 if (scope == NULL)
10878
10879 ROSE_ASSERT(scope != NULL);
10880
10881#if 0
10882 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): scope = %p = %s = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
10883#endif
10884
10885 // TODO How about class type??
10886 // build defining declaration
10888
10889 SgNamespaceDeclarationStatement* defdecl = new SgNamespaceDeclarationStatement(name,namespaceDef,unnamednamespace);
10890 ROSE_ASSERT(defdecl != NULL);
10891 namespaceDef->set_parent(defdecl);
10892
10893#if 0
10894 printf ("#################### SageBuilder::buildNamespaceDeclaration_nfi(): defdecl = %p = %s namespaceDef = %p \n",defdecl,defdecl->get_name().str(),namespaceDef);
10895#endif
10896
10897 // setOneSourcePositionForTransformation(defdecl);
10898 setOneSourcePositionNull(defdecl);
10899
10900 // constructor is side-effect free
10901 namespaceDef->set_namespaceDeclaration(defdecl);
10902
10903 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
10904 // defdecl->set_definingDeclaration(defdecl);
10905 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
10906
10907 // Get the nondefining declaration from the symbol if it has been built (if this works,
10908 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
10909 SgNamespaceDeclarationStatement* nondefdecl = NULL;
10910
10911 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
10912 // ROSE_ASSERT(scope != NULL);
10913 SgNamespaceSymbol* mysymbol = NULL;
10914 if (scope != NULL)
10915 {
10916 mysymbol = scope->lookup_namespace_symbol(name);
10917 }
10918 else
10919 {
10920 // DQ (1/26/2009): I think this should be an error, but that appears it would
10921 // break the existing interface. Need to discuss this with Liao.
10922 printf ("Warning: In SageBuilder::buildNamespaceDeclaration_nfi(): scope == NULL \n");
10923 }
10924
10925#if 0
10926 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): mysymbol = %p \n",mysymbol);
10927#endif
10928
10929 if (mysymbol != NULL)
10930 {
10931 // nondefdecl = isSgNamespaceDeclarationStatement(mysymbol->get_declaration());
10932 SgNamespaceDeclarationStatement* namespaceDeclaration = mysymbol->get_declaration();
10933 ROSE_ASSERT(namespaceDeclaration != NULL);
10934 nondefdecl = isSgNamespaceDeclarationStatement(namespaceDeclaration);
10935
10936 ROSE_ASSERT(nondefdecl != NULL);
10937 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10938
10939 // DQ (5/16/2013): These should be non-defining declarations for the case of a C++ namespace (all instances are a non-defining declaration).
10940 // nondefdecl->set_definingDeclaration(defdecl);
10941 // ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
10942 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == NULL);
10943 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
10944
10945 // DQ (5/16/2013): Set the global definition for the new namespace definition.
10946 ROSE_ASSERT(namespaceDeclaration->get_definition() != NULL);
10947 if (namespaceDeclaration->get_definition()->get_global_definition() == NULL)
10948 {
10949 printf ("ERROR: namespaceDeclaration->get_definition()->get_global_definition() == NULL: namespaceDeclaration = %p = %s namespaceDeclaration->get_definition() = %p \n",
10950 namespaceDeclaration,namespaceDeclaration->get_name().str(),namespaceDeclaration->get_definition());
10951 }
10952 ROSE_ASSERT(namespaceDeclaration->get_definition()->get_global_definition() != NULL);
10953 namespaceDef->set_global_definition(namespaceDeclaration->get_definition()->get_global_definition());
10954 ROSE_ASSERT(namespaceDef->get_global_definition() != NULL);
10955
10956 // DQ (5/19/2013): Make the global_definition point to itself.
10957 ROSE_ASSERT(namespaceDef->get_global_definition() == namespaceDef->get_global_definition()->get_global_definition());
10958
10959 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
10960
10961 ROSE_ASSERT(nondefdecl->get_definition()->get_previousNamespaceDefinition() == NULL);
10962 // ROSE_ASSERT(nondefdecl->get_definition()->get_nextNamespaceDefinition() == NULL);
10963
10964 SgNamespaceDefinitionStatement* i = namespaceDeclaration->get_definition();
10965 ROSE_ASSERT(i != NULL);
10966 while (i != NULL && i->get_nextNamespaceDefinition() != NULL)
10967 {
10968 i = i->get_nextNamespaceDefinition();
10969 ROSE_ASSERT(i->get_previousNamespaceDefinition() != NULL);
10970 }
10971
10972 ROSE_ASSERT(i != NULL);
10973 i->set_nextNamespaceDefinition(namespaceDef);
10974 namespaceDef->set_previousNamespaceDefinition(i);
10975 }
10976 else
10977 {
10978 // DQ (5/16/2013): Note that since we don't build a SgNamespaceDefinition for the declaration we can't
10979 // build the global_definition. This is a potential problem.
10980
10981#if 1
10982 nondefdecl = defdecl;
10983 ROSE_ASSERT(nondefdecl != NULL);
10984 namespaceDef = nondefdecl->get_definition();
10985 ROSE_ASSERT(namespaceDef->get_namespaceDeclaration() != NULL);
10986#else
10987 // DQ (5/16/2013): We want to build an associated SgNamespaceDefinitionStatement so that we can
10988 // support a reference to a SgNamespaceDefinitionStatement as a global definition.
10989 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
10990 // nondefdecl = new SgNamespaceDeclarationStatement(name,NULL, unnamednamespace);
10991
10992#error "DEAD CODE!"
10993
10995 nondefdecl = new SgNamespaceDeclarationStatement(name,namespaceDef,unnamednamespace);
10996 ROSE_ASSERT(nondefdecl != NULL);
10997#if 0
10998 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): Built namespace definition for nondefdecl = %p = %s definition = %p \n",nondefdecl,nondefdecl->get_name().str(),namespaceDef);
10999#endif
11000 // DQ (5/16/2013): Added tests and setting of the associated declaration.
11001 ROSE_ASSERT(namespaceDef->get_namespaceDeclaration() == NULL);
11002 namespaceDef->set_namespaceDeclaration(nondefdecl);
11003 ROSE_ASSERT(namespaceDef->get_namespaceDeclaration() != NULL);
11004#endif
11005
11006 // DQ (5/16/2013): Now add the global definition where we will accumulate all of the symbols for the logical namespace.
11007 SgNamespaceDefinitionStatement* global_definition_namespaceDef = buildNamespaceDefinition();
11008 namespaceDef->set_global_definition(global_definition_namespaceDef);
11009 ROSE_ASSERT(namespaceDef->get_global_definition() != NULL);
11010
11011 // DQ (5/19/2013): Make the global_definition point to itself.
11012 global_definition_namespaceDef->set_global_definition(global_definition_namespaceDef);
11013
11014 global_definition_namespaceDef->set_isUnionOfReentrantNamespaceDefinitions(true);
11015
11016 // DQ (8/23/2013): Set the parent of the global_definition_namespaceDef.
11017 ROSE_ASSERT(global_definition_namespaceDef->get_parent() == NULL);
11018 global_definition_namespaceDef->set_parent(defdecl);
11019 ROSE_ASSERT(global_definition_namespaceDef->get_parent() != NULL);
11020
11021 // DQ (5/16/2013): Added tests and setting of the associated declaration.
11022 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() == NULL);
11023 global_definition_namespaceDef->set_namespaceDeclaration(nondefdecl);
11024 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() != NULL);
11025
11026 // DQ (5/16/2013): Set the associated declaration to be the nondefdecl.
11027 global_definition_namespaceDef->set_namespaceDeclaration(nondefdecl);
11028 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() != NULL);
11029
11030#if 0
11031 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() == NULL);
11032 // defdecl->get_definition()->set_global_definition(namespaceDef->get_global_definition());
11033 defdecl->get_definition()->set_global_definition(global_definition_namespaceDef);
11034#else
11035#if 0
11036 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): defdecl->get_definition()->get_global_definition() = %p \n",defdecl->get_definition()->get_global_definition());
11037#endif
11038 if (defdecl->get_definition()->get_global_definition() == NULL)
11039 {
11040 defdecl->get_definition()->set_global_definition(global_definition_namespaceDef);
11041 }
11042
11043 // DQ (5/19/2013): Make the global_definition point to itself.
11044 ROSE_ASSERT(global_definition_namespaceDef == global_definition_namespaceDef->get_global_definition());
11045#endif
11046 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
11047 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() == namespaceDef->get_global_definition());
11048#if 0
11049 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): Built namespace definition for nondefdecl = %p = %s get_global_definition() = %p \n",nondefdecl,nondefdecl->get_name().str(),namespaceDef->get_global_definition());
11050#endif
11051 // printf ("SageBuilder::buildNamespaceDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11052
11053 // The nondefining declaration will not appear in the source code, but is compiler
11054 // generated (so we have something about the class that we can reference; e.g in
11055 // types). At the moment we make it a transformation, there might be another kind
11056 // of source position that would be more precise. FIXME.
11057 // setOneSourcePositionNull(nondefdecl);
11058 // setOneSourcePositionForTransformation(nondefdecl);
11059
11060 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11061
11062 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
11063 // nondefdecl->set_definingDeclaration(defdecl);
11064 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == NULL);
11065 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
11066
11067 nondefdecl->setForward();
11068
11069 // nondefdecl->set_parent(topScopeStack());
11070 nondefdecl->set_parent(scope);
11071 ROSE_ASSERT(nondefdecl->get_parent());
11072
11073 if (scope != NULL)
11074 {
11075 mysymbol = new SgNamespaceSymbol(name,nondefdecl); // tps: added name to constructor
11076 scope->insert_symbol(name, mysymbol);
11077 }
11078 else
11079 {
11080 // DQ (1/26/2009): I think this should be an error, but that appears it would
11081 // break the existing interface. Need to discuss this with Liao.
11082 printf ("Warning: no scope provided to support symbol table entry! \n");
11083 }
11084
11085 ROSE_ASSERT(defdecl->get_definition() != NULL);
11086 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
11087
11088 ROSE_ASSERT(nondefdecl->get_definition()->get_previousNamespaceDefinition() == NULL);
11089 ROSE_ASSERT(nondefdecl->get_definition()->get_nextNamespaceDefinition() == NULL);
11090 }
11091
11092 ROSE_ASSERT(nondefdecl != NULL);
11093
11094 // printf ("SageBuilder::buildNamespaceDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11095
11096 // setOneSourcePositionForTransformation(nondefdecl);
11097 // setOneSourcePositionNull(nondefdecl);
11098
11099 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11100 // nondefdecl->set_definingDeclaration(defdecl);
11101 defdecl->set_firstNondefiningDeclaration(nondefdecl);
11102
11103 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
11104 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
11105 // used in a defining declaration).
11106 nondefdecl->setForward();
11107
11108 if (scope != NULL) // put into fixStructDeclaration() or alike later on
11109 {
11110 fixNamespaceDeclaration(nondefdecl,scope);
11111 fixNamespaceDeclaration(defdecl,scope);
11112#if 0
11113 SgClassSymbol* mysymbol = new SgClassSymbol(nondefdecl);
11114 ROSE_ASSERT(mysymbol);
11115 scope->insert_symbol(name, mysymbol);
11116#endif
11117
11118 // tps namespace has no scope
11119 //defdecl->set_scope(scope);
11120 //nondefdecl->set_scope(scope);
11121
11122 // defdecl->set_parent(scope);
11123
11124 // DQ (1/25/2009): The scope is not the same as the parent, since the scope is logical, and the parent is structural (note that topScopeStack() is structural).
11125 // nondefdecl->set_parent(scope);
11126 // nondefdecl->set_parent(topScopeStack());
11127 }
11128
11129 // defdecl->set_parent(topScopeStack());
11130
11131 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
11132 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
11133 // ROSE_ASSERT(defdecl->get_parent() != NULL);
11134
11135 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
11136
11137 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
11138 // ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
11139 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
11140
11141 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
11142 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
11143
11144 // DQ (5/16/2013): Added tests.
11145 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
11146 ROSE_ASSERT(defdecl->get_definition() != NULL);
11147 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
11148
11149#if 0
11150 // DQ (5/19/2013): There should always be proper source file position infomation so this should not be required.
11151 if (defdecl->get_file_info()->isOutputInCodeGeneration() == true)
11152 {
11153 defdecl->get_file_info()->display("In buildNamespaceDeclaration_nfi(): namespaceDeclaration: debug");
11154 }
11155 // ROSE_ASSERT(defdecl->get_file_info()->isOutputInCodeGeneration() == false);
11156#endif
11157
11158 return defdecl;
11159 }
11160
11161// driscoll6 (7/20/11) : Support n-ary operators for python
11164 SgNaryComparisonOp* result = new SgNaryComparisonOp();
11165
11166 result->get_operands().push_back(lhs);
11167 lhs->set_parent(result);
11168
11170 return result;
11171}
11172
11175 SgNaryComparisonOp* result = new SgNaryComparisonOp();
11176
11177 result->get_operands().push_back(lhs);
11178 lhs->set_parent(result);
11179
11181 return result;
11182}
11183
11186 SgNaryBooleanOp* result = new SgNaryBooleanOp();
11187
11188 result->get_operands().push_back(lhs);
11189 lhs->set_parent(result);
11190
11192 return result;
11193}
11194
11197 SgNaryBooleanOp* result = new SgNaryBooleanOp();
11198
11199 result->get_operands().push_back(lhs);
11200 lhs->set_parent(result);
11201
11203 return result;
11204}
11205
11208 ROSE_ASSERT(exp);
11209 SgStringConversion* result = new SgStringConversion(exp);
11210 exp->set_parent(result);
11211
11213 return result;
11214}
11215
11216
11219 ROSE_ASSERT(exp);
11220 SgStringConversion* result = new SgStringConversion(exp);
11221 exp->set_parent(result);
11222
11224 return result;
11225}
11226
11227// DQ (11/7/2009): Added more uniform support for building class declarations.
11230 {
11231 SgClassDeclaration* defdecl = NULL;
11232 SgClassDeclaration* nondefdecl = NULL;
11233
11234 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
11235 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
11236 ROSE_ASSERT(SageInterface::hasTemplateSyntax(name) == false);
11237
11238#if 1
11239 printf ("In buildNondefiningClassDeclaration(): name = %s scope = %p = %s \n",name.str(),scope,scope != NULL ? scope->class_name().c_str() : "NULL");
11240
11241 // DQ (8/12/2013): If this function were to be called then we would have to
11242 // support a template argument list for the call to lookup_class_symbol().
11243
11244 // DQ (6/9/2013): I want to know that I'm not debugging this function.
11245 ROSE_ABORT();
11246#endif
11247
11248 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
11249 // ROSE_ASSERT(scope != NULL);
11250 SgClassSymbol* mysymbol = NULL;
11251 if (scope != NULL)
11252 {
11253 // mysymbol = scope->lookup_class_symbol(name);
11254 mysymbol = scope->lookup_class_symbol(name,NULL);
11255 }
11256 else
11257 {
11258 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unkown.
11259 // DQ (1/26/2009): I think this should be an error, but that appears it would
11260 // break the existing interface. Need to discuss this with Liao.
11261 // printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): scope == NULL \n");
11262 }
11263
11264#if 0
11265 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
11266#endif
11267
11268 if (mysymbol != NULL) // set links if nondefining declaration already exists.
11269 {
11270 nondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
11271
11272 ROSE_ASSERT(nondefdecl != NULL);
11273 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11274
11275 nondefdecl->set_definingDeclaration(defdecl);
11276
11277 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
11278 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
11279
11280 // DQ (10/30/2010): There should be a properly defined type at this point!
11281 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11282
11283 // DQ (7/31/2019): Check that this is true.
11284 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11285 }
11286 else // build a nondefnining declaration if it does not exist
11287 {
11288 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
11289
11291 nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
11292 ROSE_ASSERT(nondefdecl != NULL);
11293 if (nondefdecl->get_type() == NULL)
11294 {
11295 nondefdecl->set_type(SgClassType::createType(nondefdecl));
11296#if 0
11297 printf ("In SageBuilder::buildNondefiningClassDeclaration(): built class type: part 3: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11298#endif
11299 }
11300
11301 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11302
11303 // The nondefining declaration will not appear in the source code, but is compiler
11304 // generated (so we have something about the class that we can reference; e.g in
11305 // types). At the moment we make it a transformation, there might be another kind
11306 // of source position that would be more precise. FIXME.
11307 // setOneSourcePositionNull(nondefdecl);
11309
11310 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11311 nondefdecl->set_definingDeclaration(defdecl);
11312 nondefdecl->setForward();
11313 // Liao, 9/2/2009. scope stack is optional, it can be empty
11314 // nondefdecl->set_parent(topScopeStack());
11315 // nondefdecl->set_parent(scope);
11316
11317 // DQ (7/31/2019): Check that this is true.
11318 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11319
11320 // DQ (3/24/2011): This should be NULL before we set it (if the scope is known).
11321 ROSE_ASSERT(nondefdecl->get_scope() == NULL);
11322 if (scope != NULL)
11323 {
11324 // DQ (3/24/2011): Decided with Liao that we should set the scope where possible. The AST consistancy test will make sure it is consistant with where it is inserted into the AST.
11325 nondefdecl->set_scope(scope);
11326 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
11327
11328 mysymbol = new SgClassSymbol(nondefdecl);
11329#if 0
11330 printf ("In buildNondefiningClassDeclaration(): Adding SgClassSymbol: mysymbol = %p from nondefdecl = %p = %s to scope = %p = %s \n",mysymbol,nondefdecl,nondefdecl->class_name().c_str(),scope,scope->class_name().c_str());
11331#endif
11332 scope->insert_symbol(name, mysymbol);
11333 }
11334 else
11335 {
11336 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknown.
11337 // DQ (1/26/2009): I think this should be an error, but that appears it would
11338 // break the existing interface. Need to discuss this with Liao.
11339 // printf ("Warning: no scope provided to support symbol table entry! \n");
11340 }
11341
11342 // DQ (10/30/2010): There should be a properly defined type at this point!
11343 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11344
11345 // DQ (3/24/2011): The scope should be set if the scope was available.
11346 ROSE_ASSERT(scope == NULL || (scope != NULL && nondefdecl->get_scope() != NULL));
11347 }
11348
11349 ROSE_ASSERT(nondefdecl != NULL);
11350
11351 return nondefdecl;
11352 }
11353
11354// DQ (11/7/2009): Added more uniform support for building class declarations.
11357 {
11358 // Note that the semantics of this function now differs from that of the buildDefiningFunctionDeclaration().
11359 // We want to have the non-defining declaration already exist before calling this function.
11360 // We could still build a higher level function that built both together. Or we could provide two versions
11361 // named differently (from this one) and deprecate this function...which I like much better.
11362 printf ("WARNING: This function for building defining class declarations has different semantics from that of the function to build defining function declarations. \n");
11363
11364#if 1
11365 printf ("In buildDefiningClassDeclaration(): name = %s scope = %p = %s \n",name.str(),scope,scope != NULL ? scope->class_name().c_str() : "NULL");
11366
11367 // DQ (6/9/2013): I want to know that I'm not debugging this function.
11368 ROSE_ABORT();
11369#endif
11370
11371 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
11372 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
11373 ROSE_ASSERT(SageInterface::hasTemplateSyntax(name) == false);
11374
11375 SgClassDeclaration* nondefiningClassDeclaration = buildNondefiningClassDeclaration(name,scope);
11376 ROSE_ASSERT(nondefiningClassDeclaration != NULL);
11377
11378 SgClassDefinition* definingClassDefinition = buildClassDefinition();
11379 ROSE_ASSERT(definingClassDefinition != NULL);
11380
11381 // DQ (10/30/2010): There should be a properly defined type at this point!
11382 SgClassType* classType = nondefiningClassDeclaration->get_type();
11383 ROSE_ASSERT(classType != NULL);
11384
11386
11387 // DQ (10/30/2010): We need to make sure that there is a type defined.
11388 // SgClassDeclaration* definingClassDeclaration = new SgClassDeclaration (name,kind,NULL,definingClassDefinition);
11389 SgClassDeclaration* definingClassDeclaration = new SgClassDeclaration (name,kind,classType,definingClassDefinition);
11390 ROSE_ASSERT(definingClassDeclaration != NULL);
11391
11392 // printf ("SageBuilder::buildDefiningClassDeclaration(): definingClassDeclaration = %p \n",definingClassDeclaration);
11393
11394 setOneSourcePositionForTransformation(definingClassDeclaration);
11395
11396 // constructor is side-effect free
11397 definingClassDefinition->set_declaration(definingClassDeclaration);
11398 definingClassDeclaration->set_definingDeclaration(definingClassDeclaration);
11399 definingClassDeclaration->set_firstNondefiningDeclaration(nondefiningClassDeclaration);
11400
11401 nondefiningClassDeclaration->set_definingDeclaration(definingClassDeclaration);
11402
11403 // some error checking
11404 ROSE_ASSERT(nondefiningClassDeclaration->get_definingDeclaration() != NULL);
11405 ROSE_ASSERT(nondefiningClassDeclaration->get_firstNondefiningDeclaration() != NULL);
11406 ROSE_ASSERT(definingClassDeclaration->get_firstNondefiningDeclaration() != NULL);
11407 ROSE_ASSERT(definingClassDeclaration->get_definition() != NULL);
11408
11409 ROSE_ASSERT(definingClassDeclaration->get_scope() == NULL);
11410 if (scope != NULL)
11411 {
11412 definingClassDeclaration->set_scope(scope);
11413 ROSE_ASSERT(definingClassDeclaration->get_scope() != NULL);
11414 ROSE_ASSERT(nondefiningClassDeclaration->get_scope() != NULL);
11415 }
11416
11417 ROSE_ASSERT(definingClassDeclaration->get_definition()->get_parent() != NULL);
11418
11419 // DQ (10/30/2010): There should be a properly defined type at this point!
11420 ROSE_ASSERT(definingClassDeclaration->get_type() != NULL);
11421
11422 return definingClassDeclaration;
11423 }
11424
11425// DQ (11/7/2009): Added more uniform support for building class declarations.
11428 {
11429 ROSE_ASSERT(scope != NULL);
11430 SgClassDeclaration* definingClassDeclaration = buildDefiningClassDeclaration(name,scope);
11431 ROSE_ASSERT(definingClassDeclaration != NULL);
11432
11433 return definingClassDeclaration;
11434 }
11435
11436
11437// DQ (6/6/2012): Added support for template arguments (so that the type could be computing using the template arguments when building a template instantiation).
11438// DQ (1/24/2009): Built this "nfi" version but factored the code.
11439// SgClassDeclaration* SageBuilder::buildClassDeclaration_nfi(const SgName& name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl , bool buildTemplateInstantiation )
11441SageBuilder::buildClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl , bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList )
11442 {
11443 // DQ (3/15/2012): Added function to build C++ class (builds both the non-defining and defining declarations; in that order).
11444 // The implementation of this function could be simplified to directly call both:
11445 // SgClassDeclaration* buildNondefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
11446 // and
11447 // SgClassDeclaration* buildDefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
11448 // This might refactor the implementation nicely.
11449
11450#define DEBUG_CLASS_DECLARATION 0
11451
11452 // Note that the nonDefiningDecl pointer does not appear to be used.
11453#if 0
11454 printf ("WARNING: In SageBuilder::buildClassDeclaration_nfi(): the nonDefiningDecl pointer = %p (input parameter) does not appear to be used. \n",nonDefiningDecl);
11455#endif
11456
11457#if 0
11458 // DQ (3/4/2018): Adding testing.
11459 // ROSE_ASSERT(nonDefiningDecl != NULL);
11460 if (nonDefiningDecl != NULL)
11461 {
11462 ROSE_ASSERT(nonDefiningDecl->get_type() != NULL);
11463 ROSE_ASSERT(nonDefiningDecl->get_type()->get_declaration() != NULL);
11464 printf ("nonDefiningDecl->get_type() = %p = %s \n",nonDefiningDecl->get_type(),nonDefiningDecl->get_type()->class_name().c_str());
11465 printf ("nonDefiningDecl->get_type()->get_declaration() = %p = %s \n",nonDefiningDecl->get_type()->get_declaration(),nonDefiningDecl->get_type()->get_declaration()->class_name().c_str());
11466#if 0
11467 printf ("In buildClassDeclaration_nfi(): nonDefiningDecl: unparseNameToString() = %s \n",nonDefiningDecl->unparseNameToString().c_str());
11468#endif
11469
11470 }
11471#endif
11472
11473
11474 // DQ (10/10/2015): I think we can assert this! NO we can't (see test2015_87.C).
11475 // ROSE_ASSERT(nonDefiningDecl != NULL);
11476
11477 // DQ (10/10/2015): OK, now we have a valid use on the input non-defining declaration.
11478 bool buildTemplateDeclaration = (isSgTemplateClassDeclaration(nonDefiningDecl) != NULL);
11479
11480 // DQ (10/10/2015): If this is true, then we should have called a different function to build the associated SgTemplateClassDeclaration.
11481 if (buildTemplateDeclaration == true)
11482 {
11483 // Error checking.
11484 printf ("ERROR: If buildTemplateDeclaration == true, then we should have called a different function to build the associated SgTemplateClassDeclaration \n");
11485 }
11486 ROSE_ASSERT(buildTemplateDeclaration == false);
11487
11488#if 0
11489 printf ("In SageBuilder::buildClassDeclaration_nfi(): XXX_name = %s \n",XXX_name.str());
11490 printf ("In SageBuilder::buildClassDeclaration_nfi(): the nonDefiningDecl pointer = %p = %s \n",nonDefiningDecl,nonDefiningDecl != NULL ? nonDefiningDecl->class_name().c_str() : "null");
11491 printf ("In SageBuilder::buildClassDeclaration_nfi(): buildTemplateDeclaration = %s \n",buildTemplateDeclaration ? "true" : "false");
11492 printf (" --- templateArgumentsList = %p \n",templateArgumentsList);
11493 if (templateArgumentsList != NULL)
11494 {
11495 printf (" --- templateArgumentsList.size() = %zu \n",templateArgumentsList->size());
11496 for (size_t i = 0; i < templateArgumentsList->size(); i++)
11497 {
11498 printf (" --- --- argument pointer: templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
11499 }
11500 }
11501#endif
11502
11503 if (scope == NULL)
11504 {
11506#if 0
11507 printf ("In SageBuilder::buildClassDeclaration_nfi(): no scope was provided so using the SageBuilder::topScopeStack() = %p = %s \n",scope,scope->class_name().c_str());
11508#endif
11509 }
11510 else
11511 {
11512#if 0
11513 printf ("In SageBuilder::buildClassDeclaration_nfi(): scope was provided scope = %p = %s \n",scope,scope->class_name().c_str());
11514#endif
11515 }
11516
11517#if 0
11518 printf ("Building a SgClassDeclaration: buildClassDeclaration_nfi() XXX_name = %s buildTemplateInstantiation = %s \n",XXX_name.str(),buildTemplateInstantiation ? "true" : "false");
11519#endif
11520
11521 // Step 2 (now step 1). build the nondefining declaration,
11522 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
11523
11524 // Get the nondefining declaration from the symbol if it has been built (if this works,
11525 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
11526 SgClassDeclaration* nondefdecl = NULL;
11527
11528 SgName nameWithoutTemplateArguments = XXX_name;
11529 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
11530 if (buildTemplateInstantiation == true)
11531 {
11532 ROSE_ASSERT(templateArgumentsList != NULL);
11533 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
11534 }
11535
11536#if DEBUG_CLASS_DECLARATION
11537 printf ("In SageBuilder::buildClassDeclaration_nfi():\n");
11538 printf (" -- nameWithoutTemplateArguments = %s\n", nameWithoutTemplateArguments.str());
11539 printf (" -- nameWithTemplateArguments = %s\n", nameWithTemplateArguments.str());
11540#endif
11541
11542 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
11543 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
11544 // This fails for test2005_35.C
11545 // ROSE_ASSERT(SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == false);
11546
11547 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
11548 // ROSE_ASSERT(scope != NULL);
11549 SgClassSymbol* mysymbol = NULL;
11550 if (scope != NULL)
11551 {
11552#if DEBUG_CLASS_DECLARATION
11553 printf ("Looking up the SgClassSymbol in scope = %p = %s nameWithTemplateArguments = %s \n",scope,scope->class_name().c_str(),nameWithTemplateArguments.str());
11554#endif
11555
11556 // DQ (8/22/2012): We need to provide more information ofr the symbol table lookup to correctly resolve
11557 // (and disambiguate template instantations where the name qualification of the template arguments would
11558 // be significant).
11559 // mysymbol = scope->lookup_class_symbol(name);
11560 // mysymbol = scope->lookup_class_symbol(name);
11561 // mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments);
11562#if 0
11563 // DQ (7/25/2017): Since this is overwritten below, for both branches, we don't need to call this here.
11564 printf ("This was a redundant call to lookup_class_symbol \n");
11565 // mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList);
11566#endif
11567
11568 // DQ (10/10/2015): look up the correct type of symbol.
11569 if (buildTemplateDeclaration == true)
11570 {
11571#if DEBUG_CLASS_DECLARATION
11572 printf ("Note: In SageBuilder::buildClassDeclaration_nfi(): Need to look up a template symbol \n");
11573#endif
11574 ROSE_ASSERT(nonDefiningDecl != NULL);
11575
11576 SgTemplateParameterPtrList templateParameterList;
11577 SgTemplateArgumentPtrList templateSpecializationArgumentList;
11578
11579 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateArguments,&templateParameterList,&templateSpecializationArgumentList) != NULL);
11580
11581 mysymbol = scope->lookup_template_class_symbol(nameWithTemplateArguments,&templateParameterList,&templateSpecializationArgumentList);
11582
11583 ROSE_ASSERT(mysymbol != NULL);
11584#if 0
11585 printf ("ERROR: Need to look up a template symbol \n");
11586 ROSE_ABORT();
11587#endif
11588 }
11589 else
11590 {
11591#if DEBUG_CLASS_DECLARATION
11592 printf ("In SageBuilder::buildClassDeclaration_nfi(): calling lookup_class_symbol(nameWithTemplateArguments = %s,templateArgumentsList->size() = %zu \n",
11593 nameWithTemplateArguments.str(),(templateArgumentsList != NULL) ? templateArgumentsList->size() : 999);
11594 if (templateArgumentsList != NULL)
11595 {
11596 printf (" --- templateArgumentsList elements: \n");
11597 for (size_t i = 0; i < templateArgumentsList->size(); i++)
11598 {
11599 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
11600 printf (" --- --- templateArgumentsList->[%zu] = %s \n",i,templateArgumentsList->operator[](i)->class_name().c_str());
11601 templateArgumentsList->operator[](i)->display("In SageBuilder::buildClassDeclaration_nfi()");
11602 }
11603 }
11604#endif
11605 mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList);
11606#if DEBUG_CLASS_DECLARATION
11607 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
11608#endif
11609 // DQ (3/4/2018): The only time I see this failing is when we should have used the nonDefiningDecl (see Cxx11_tests/test2015_08.C).
11610 if (mysymbol == NULL)
11611 {
11612#if DEBUG_CLASS_DECLARATION
11613 printf ("WARNING: scope->lookup_class_symbol(nameWithTemplateArguments = %s,templateArgumentsList->size() = %zu) == NULL \n",nameWithTemplateArguments.str(),templateArgumentsList->size());
11614#endif
11615 // ROSE_ASSERT(nonDefiningDecl != NULL);
11616
11617 // DQ (12/28/2018): Could it be that we wanted to use the name without template arguments.
11618#if DEBUG_CLASS_DECLARATION
11619 printf ("Checking lookup_class_symbol() using nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11620#endif
11621 ROSE_ASSERT(scope->lookup_class_symbol(nameWithoutTemplateArguments,templateArgumentsList) == NULL);
11622
11623#if DEBUG_CLASS_DECLARATION
11624 printf ("nonDefiningDecl = %p \n",nonDefiningDecl);
11625#endif
11626 if (nonDefiningDecl != NULL)
11627 {
11628#if DEBUG_CLASS_DECLARATION
11629 printf ("nonDefiningDecl = %p = %s \n",nonDefiningDecl,nonDefiningDecl->class_name().c_str());
11630#endif
11631 // DQ (3/4/2018): I think this is the correct API to use (internal use only).
11632 SgSymbol* temp_mysymbol = nonDefiningDecl->get_symbol_from_symbol_table();
11633 ROSE_ASSERT(temp_mysymbol != NULL);
11634
11635 mysymbol = isSgClassSymbol(temp_mysymbol);
11636 ROSE_ASSERT(mysymbol != NULL);
11637
11638 // DQ (3/4/2018): check that the scopes are the same.
11639 ROSE_ASSERT(scope == nonDefiningDecl->get_scope());
11640 }
11641 }
11642 }
11643
11644#if 0
11645 // DQ (11/21/2013): Added test based on debugging session with Philippe.
11646 // This test is not a test for a bug, since we require that symbols in base classes be aliased in the derived classes.
11647 if (mysymbol != NULL)
11648 {
11649 SgClassDeclaration* symbol_declaration = isSgClassDeclaration(mysymbol->get_declaration());
11650 ROSE_ASSERT(symbol_declaration != NULL);
11651 ROSE_ASSERT(symbol_declaration->get_scope() == scope);
11652
11653 printf ("In SageBuilder::buildClassDeclaration_nfi(): Testing scope->get_symbol_table()->exists(mysymbol) == true (expensive) \n");
11654
11655 ROSE_ASSERT(scope->get_symbol_table()->exists(mysymbol) == true);
11656 }
11657#endif
11658 }
11659 else
11660 {
11661 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknow.
11662 // DQ (1/26/2009): I think this should be an error, but that appears it would
11663 // break the existing interface. Need to discuss this with Liao.
11664 // printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): scope == NULL \n");
11665 }
11666
11667#if DEBUG_CLASS_DECLARATION
11668 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
11669#endif
11670
11671 if (mysymbol != NULL) // set links if nondefining declaration already exists.
11672 {
11673 nondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
11674
11675 ROSE_ASSERT(nondefdecl != NULL);
11676
11677#if DEBUG_CLASS_DECLARATION
11678 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol->get_declaration(): nondefdecl = %p = %s nondefdecl->get_definition() = %p = %s \n",
11679 nondefdecl,nondefdecl->class_name().c_str(),nondefdecl->get_definition(),
11680 nondefdecl->get_definition() != NULL ? nondefdecl->get_definition()->class_name().c_str() : "NULL");
11681#endif
11682 // DQ (6/8/2013): This should not be true (see test2013_198.C).
11683 // Fundamentally the symbol should always only have a pointer to a non-defining
11684 // declaration, where by definition (get_definition() == NULL).
11685 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
11686
11687 // DQ (9/16/2012): This should be true by definition (verify).
11688 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
11689
11690 // DQ (9/16/2012): The declaration was build previously, but test it to make sure the template arguments were setup properly.
11691 testTemplateArgumentParents(nondefdecl);
11692
11693#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11694 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11695 detectTransformations(nondefdecl);
11696#endif
11697
11698 // DQ (3/22/2012): I think we can assert this.
11699 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11700
11701 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11702 if (nondefdecl->get_parent() == NULL)
11703 {
11704#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11705 printf ("In SageBuilder::buildClassDeclaration_nfi(): Note that nondefdecl->get_parent() == NULL, this might be OK. \n");
11706#endif
11707 }
11708
11709#if 0
11710 // DQ (12/22/2019): This is the code that causes the class declarations between defining
11711 // class declarations across multiple translation units to be shared.
11712
11713 // DQ (9/7/2012): I think this might be the root of a problem in the haskell tests (ROSE compiling ROSE).
11714 if (nondefdecl->get_definingDeclaration() != NULL)
11715 {
11716#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11717 printf ("ERROR: In SageBuilder::buildClassDeclaration_nfi(): Non defining declaration nondefdecl = %p = %s already has a defining declaration, so we would be build another nondefdecl->get_definingDeclaration() = %p = %s \n",
11718 nondefdecl,nondefdecl->class_name().c_str(),nondefdecl->get_definingDeclaration(),nondefdecl->get_definingDeclaration()->class_name().c_str());
11719#endif
11720 SgClassDeclaration* nondefining_classDeclaration = isSgClassDeclaration(nondefdecl);
11721 ROSE_ASSERT(nondefining_classDeclaration != NULL);
11722 SgClassDeclaration* defining_classDeclaration = isSgClassDeclaration(nondefdecl->get_definingDeclaration());
11723 ROSE_ASSERT(defining_classDeclaration != NULL);
11724
11725#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11726 printf ("In SageBuilder::buildClassDeclaration_nfi(): nondefining_classDeclaration: scope = %p = %s name = %s \n",
11727 nondefining_classDeclaration->get_scope(),nondefining_classDeclaration->get_scope()->class_name().c_str(),nondefining_classDeclaration->get_name().str());
11728 printf ("In SageBuilder::buildClassDeclaration_nfi(): defining_classDeclaration: scope = %p = %s name = %s \n",
11729 defining_classDeclaration->get_scope(),defining_classDeclaration->get_scope()->class_name().c_str(),defining_classDeclaration->get_name().str());
11730 defining_classDeclaration->get_file_info()->display("already has a defining declaration");
11731#endif
11732#if 0
11733 printf ("Error: In SageBuilder::buildClassDeclaration_nfi(): exiting as part of test \n");
11734 ROSE_ABORT();
11735#endif
11736 // DQ (9/24/2012): This only appears to happen for large tests (e.g. ROSE compiling ROSE), alow it for the moment and look into this later.
11737#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11738 printf ("WARNING: In SageBuilder::buildClassDeclaration_nfi(): but a defining declaration was found to have already been built (might be an error), so returning it defining_classDeclaration = %p \n",defining_classDeclaration);
11739#endif
11740
11741#if 0
11742 // DQ (2/26/2019): Debugging support for multiple files on the command line.
11743 printf ("Exiting as a test! \n");
11744 ROSE_ABORT();
11745#endif
11746 return defining_classDeclaration;
11747 }
11748#endif
11749
11750#if 0
11751 nondefdecl->set_definingDeclaration(defdecl);
11752
11753 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
11754 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
11755#endif
11756 }
11757 else // build a nondefnining declaration if it does not exist
11758 {
11759#if DEBUG_CLASS_DECLARATION
11760 printf ("In SageBuilder::buildClassDeclaration_nfi(): building a nondefining declaration since it does not exist \n");
11761#endif
11762 // DQ (10/10/2015): This should be true.
11763 ROSE_ASSERT(nondefdecl == NULL);
11764
11765 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
11766 // DQ (1/1/2012): Fixed to force matching types or IR nodes for defining and non-defining declarations.
11767 if (buildTemplateInstantiation == true)
11768 {
11769 // This adds: SgTemplateDeclaration *templateDeclaration and SgTemplateArgumentPtrList templateArguments
11770#if DEBUG_CLASS_DECLARATION
11771 printf ("************************************************************************* \n");
11772 printf ("Building SgTemplateInstantiationDecl with empty SgTemplateArgumentPtrList \n");
11773 printf (" --- using nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
11774 printf ("************************************************************************* \n");
11775#endif
11776 SgTemplateArgumentPtrList emptyList;
11777 // nondefdecl = new SgTemplateInstantiationDecl (name,kind,NULL,NULL,NULL,emptyList);
11778 nondefdecl = new SgTemplateInstantiationDecl (nameWithTemplateArguments,kind,NULL,NULL,NULL,emptyList);
11779 ROSE_ASSERT(nondefdecl != NULL);
11780#if DEBUG_CLASS_DECLARATION
11781 printf ("In SageBuilder::buildClassDeclaration_nfi(): Build SgTemplateInstantiationDecl: nondefdecl = %p \n",nondefdecl);
11782#endif
11783 // DQ (2/27/2018): Added assertion now that we have implemented more consistant semantics
11784 // for template instantiations (types are not generated in the constructor calls).
11785 ROSE_ASSERT(nondefdecl->get_type() == NULL);
11786 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl) != NULL);
11787#if 0
11788 printf ("In buildClassDeclaration_nfi(): nondefdecl->get_name() = %s nondefdecl->get_templateName() = %s \n",nondefdecl->get_name().str(),isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().str());
11789#endif
11790#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11791 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11792 // detectTransformations(nondefdecl);
11793#endif
11794 // DQ (6/6/2012): Set the first non-defining declaration to be itself.
11795 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11796
11797 // DQ (1/1/2012): Added support for setting the template name (I think this should be fixed in the constructor).
11798 // It can't be fixed in the constructor since it has to be set after construction (or passed in explicitly).
11799 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == true);
11800
11801 // DQ (6/6/2012): Added support for template arguments so that types would be computed with the template arguments.
11802 ROSE_ASSERT(templateArgumentsList != NULL);
11803
11804#if 0
11805 // DQ (5/30/2014): Removing output spew.
11806 // DQ (5/17/2014): This must be allowed for some template instantiations (see test2014_77.C).
11807 // This occurs now under some revised rules for when to interpret a class or struct as a template
11808 // declaration or template instantiation declaration. This revisions is required for test2014_56.C
11809 // but has had a small cascading effect on other parts of ROSE (all fixed on 5/17/2014, if I can
11810 // finish this work today).
11811 // ROSE_ASSERT(templateArgumentsList->size() > 0);
11812 if (templateArgumentsList->size() == 0)
11813 {
11814 printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): templateArgumentsList->size() == 0 \n");
11815 }
11816#endif
11817 // DQ (9/16/2012): Set the firstNondefiningDeclaration so that we can set the template parameters.
11818 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11819#if 1
11820 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
11821 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
11822#else
11823 isSgTemplateInstantiationDecl(nondefdecl)->get_templateArguments() = *templateArgumentsList;
11824
11825#error "DEAD CODE!"
11826
11827 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
11828 // printf ("Calling setTemplateArgumentParents(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11829 setTemplateArgumentParents(nondefdecl);
11830 // printf ("DONE: Calling setTemplateArgumentParents(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11831
11832 testTemplateArgumentParents(nondefdecl);
11833#endif
11834 // DQ (6/6/2012): Generate the name without the template arguments.
11835#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11836 printf ("Warning: In buildClassDeclaration_nfi(): calling set_templateName(nameWithTemplateArguments = %s) for nondefining declaration \n",nameWithTemplateArguments.str());
11837#endif
11838 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(name);
11839 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName("SETME_NONDEFINING_DECL<>");
11840 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(name);
11841 isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(nameWithoutTemplateArguments);
11842
11843 // DQ (6/6/2012): I don't think we want this test any more (should apply only to the result of get_templateName()).
11844 // DQ (5/31/2012): Find locations where this is set and include template syntax.
11845 // ROSE_ASSERT(name.getString().find('<') == string::npos);
11846 // printf ("Commented out test for: name.getString().find('<') == string::npos (should apply only to the result of get_templateName() \n");
11847
11848 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == false);
11849
11850 // DQ (3/25/2017): Fixed Clang warning: warning: if statement has empty body [-Wempty-body]
11851 // DQ (3/22/2012): Make sure there is template syntax present.
11852 // if (isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().getString().find('>') == string::npos)
11853 // if (hasTemplateSyntax(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName()) == false);
11854 if (hasTemplateSyntax(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName()) == false)
11855 {
11856#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11857 printf ("WARNING: No template syntax present in name of template class instantiation (nondefdecl) \n");
11858#endif
11859 }
11860 // ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().getString().find('>') != string::npos);
11861
11862#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11863 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11864 // detectTransformations(nondefdecl);
11865#endif
11866 // DQ (7/25/2017): This will be true, but it might not be what we want since it can be caught as an error in the code below.
11867 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
11868 }
11869 else
11870 {
11871 // We know that the name without template arguments should be used here (but they are the same).
11872#if DEBUG_CLASS_DECLARATION
11873 printf ("WARNING: In buildClassDeclaration_nfi(): Are we building a new SgClassDeclaration as a nondefining declaration when we should be using the nonDefiningDecl = %p \n",nonDefiningDecl);
11874 printf (" --- nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11875#endif
11876 // nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
11877 nondefdecl = new SgClassDeclaration(nameWithoutTemplateArguments,kind,NULL,NULL);
11878
11879 ROSE_ASSERT(nondefdecl != NULL);
11880#if DEBUG_CLASS_DECLARATION
11881 printf ("In buildClassDeclaration_nfi(): (no file info set): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11882#endif
11883 // DQ (10/9/2015): Added assertion. We can't assert this yet (see test2015_87.C).
11884 // ROSE_ASSERT(nondefdecl->get_type() != NULL);
11885
11886 ROSE_ASSERT(nameWithoutTemplateArguments == nameWithTemplateArguments);
11887
11888#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11889 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11890 // detectTransformations(nondefdecl);
11891#endif
11892 // DQ (9/16/2012): Set the firstNondefiningDeclaration because this is the one branch left were it
11893 // was not set (required in the true branch so that we could set the template parameters).
11894 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11895
11896 testTemplateArgumentParents(nondefdecl);
11897
11898 // DQ (7/25/2017): This will be true, but it might not be what we want since it can be caught as an error in the code below.
11899 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
11900 }
11901
11902 ROSE_ASSERT(nondefdecl != NULL);
11903
11904 // DQ (6/6/2012): This has to be set before we generate the type.
11905 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11906 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
11907
11908 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
11909 // setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
11910
11911 // DQ (3/14/2012): For C++ we need the scope set so that types will have proper locations to revolve them
11912 // from being ambiguous or not properly defined. Basically, we need a handle from which to generate something
11913 // that amounts to a kind of name qualification internally (maybe even exactly name qualification, but I would
11914 // have to think about that a bit more).
11915 ROSE_ASSERT(scope != NULL);
11916
11917#if DEBUG_CLASS_DECLARATION
11918 printf ("In SageBuilder::buildClassDeclaration_nfi(): Set the scope of the new non-defining declaration to %p = %s \n",scope,scope->class_name().c_str());
11919#endif
11920 nondefdecl->set_scope(scope);
11921 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
11922
11923 // DQ (8/2/2019): The was required becuase the parent pointers were not being set when reading a file from the SageBuilder::buildFil() API.
11924 // However the bug was that the astPostprocessing's call to resetParentPointersInMemoryPool() was not properly working to find the global
11925 // scope in anyother case but when it was called usign a SgProject node. This is not fixed to permit caloling using a SgSourceFile node
11926 // and it is now an error to call it using any other kind of IR node.
11927 // DQ (8/1/2019): Set the parent for the non defining declaration to be the same as the scope by default.
11928 // nondefdecl->set_parent(scope);
11929#if 0
11930 printf ("In buildClassDeclaration_nfi(): setting the parent of the non defining declaration to be the scope by default) \n");
11931#endif
11932 // DQ (7/31/2019): Check that the parent is set if this was used a the declaration referenced by a symbol.
11933 // ROSE_ASSERT (nondefdecl->get_parent() != NULL);
11934
11935 // DQ (3/22/2012): I think we can assert this.
11936 // ROSE_ASSERT(nondefdecl->get_type() != NULL);
11937 ROSE_ASSERT(nondefdecl->get_type() == NULL);
11938
11939 if (nondefdecl->get_type() == NULL)
11940 {
11941#if DEBUG_CLASS_DECLARATION
11942 // DQ (12/27/2018): If we have already built a type, then why did we need to build a nondefining declaration?
11943 printf ("Calling scope->get_type_table()->lookup_type(): nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
11944
11945 printf ("WE NEED THE MANGLED NAME FOR THIS TO BE RELEVANT! \n");
11946
11947 // SgType* existingType = scope->get_type_table()->lookup_type(nameWithTemplateArguments);
11948 // ROSE_ASSERT(existingType == NULL);
11949#endif
11950
11951#if DEBUG_CLASS_DECLARATION
11952 printf ("In SageBuilder::buildClassDeclaration_nfi(): kind == SgClassDeclaration::e_java_parameter = %s \n",(kind == SgClassDeclaration::e_java_parameter) ? "true" : "false");
11953#endif
11956 : (SgClassType *) SgClassType::createType(nondefdecl));
11957#if DEBUG_CLASS_DECLARATION
11958 printf ("In SageBuilder::buildClassDeclaration_nfi(): nondefdecl->get_type() == NULL: building a new class_type = %p = %s \n",class_type,class_type->class_name().c_str());
11959#endif
11960 nondefdecl->set_type(class_type);
11961#if DEBUG_CLASS_DECLARATION
11962 printf ("In SageBuilder::buildNondefiningClassDeclaration(): built class type: part 4: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11963#endif
11964 SgClassDeclaration* tmp_classDeclarationFromType = isSgClassDeclaration(class_type->get_declaration());
11965 ROSE_ASSERT(tmp_classDeclarationFromType != NULL);
11966#if DEBUG_CLASS_DECLARATION
11967 SgScopeStatement* scope = tmp_classDeclarationFromType->get_scope();
11968 printf ("tmp_classDeclarationFromType: scope = %p = %s \n",scope,scope->class_name().c_str());
11969 printf ("tmp_classDeclarationFromType = %p = %s \n",tmp_classDeclarationFromType,tmp_classDeclarationFromType->class_name().c_str());
11970 printf ("tmp_classDeclarationFromType name = %s \n",tmp_classDeclarationFromType->get_name().str());
11971 if (tmp_classDeclarationFromType->get_file_info() != NULL)
11972 {
11973 tmp_classDeclarationFromType->get_file_info()->display("tmp_classDeclarationFromType: debug");
11974 }
11975#endif
11976 }
11977
11978 // DQ (3/22/2012): Added assertions.
11979 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11980 if (nondefdecl->get_type()->get_declaration() != nondefdecl)
11981 {
11982 printf ("ERROR: nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11983 printf ("ERROR: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11984 printf ("ERROR: nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
11985
11986 SgClassDeclaration* classDeclarationFromType = isSgClassDeclaration(nondefdecl->get_type()->get_declaration());
11987 ROSE_ASSERT(classDeclarationFromType != NULL);
11988
11989 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
11990 printf ("nondefdecl->get_type()->get_name() = %s \n",nondefdecl->get_type()->get_name().str());
11991 printf ("nondefdecl->get_type()->get_declaration()->get_name() = %s \n",classDeclarationFromType->get_name().str());
11992
11993 printf ("nondefdecl->get_mangled_name() = %s \n",nondefdecl->get_mangled_name().getString().c_str());
11994 printf ("nondefdecl->get_type()->get_mangled() = %s \n",nondefdecl->get_type()->get_mangled().getString().c_str());
11995 printf ("nondefdecl->get_type()->get_declaration()->get_mangled_name() = %s \n",classDeclarationFromType->get_mangled_name().getString().c_str());
11996
11997 // DQ (12/27/2018): Added additional debugging support.
11998 printf ("nondefdecl->get_type()->get_declaration()->get_firstNondefiningDeclaration() = %s \n",classDeclarationFromType->get_firstNondefiningDeclaration() ? "true" : "false");
11999 printf ("nondefdecl->get_firstNondefiningDeclaration() = %s \n",nondefdecl->get_firstNondefiningDeclaration() ? "true" : "false");
12000
12001 // DQ (12/27/2018): I think that if this is a base class declaration then it is OK for the type's declaration to not match.
12002 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
12003 {
12004 SgNode* parent = nondefdecl->get_parent();
12005 if (parent != NULL)
12006 {
12007 printf ("nondefdecl->get_parent() = %p = %s \n",parent,parent->class_name().c_str());
12008 }
12009 }
12010
12011 // DQ (12/27/2018): Activate this debugging support.
12012#if DEBUG_CLASS_DECLARATION
12013 nondefdecl->get_type()->get_declaration()->get_file_info()->display("nondefdecl->get_type()->get_declaration()");
12014
12015 // DQ (7/24/2017): Added more debug information to support debugging test2014_187.C.
12016 // Note that this can be caught as an error if the class declaration was built in the code above when
12017 // the symbol was not found. But if the nondefdecl->get_type()->get_declaration() == nondefdecl,
12018 // then this branch will not be taken (which is simply debugging information to assert that
12019 // nondefdecl->get_type()->get_declaration() == nondefdecl is true (below).
12020 if (nondefdecl->get_file_info() == NULL)
12021 {
12022 printf ("ERROR: In SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p = %s does not have its source position information setup \n",nondefdecl,nondefdecl->class_name().c_str());
12023 printf (" --- nondefdecl = %s \n",nondefdecl->get_name().str());
12024 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p \n",nondefdecl->get_firstNondefiningDeclaration());
12025 printf (" --- nondefdecl->get_definingDeclaration() = %p \n",nondefdecl->get_definingDeclaration());
12026 printf (" --- nondefdecl->get_type() = %p \n",nondefdecl->get_type());
12027 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
12028 printf ("The real error is: (nondefdecl->get_type()->get_declaration() != nondefdecl) \n");
12029 }
12030 else
12031 {
12032 ROSE_ASSERT(nondefdecl->get_file_info() != NULL);
12033 nondefdecl->get_file_info()->display("nondefdecl");
12034 }
12035#endif
12036 }
12037 ROSE_ASSERT(nondefdecl->get_type()->get_declaration() == nondefdecl);
12038
12039#if 0
12040 printf ("In buildClassDeclaration_nfi(): after set_type(): nondefdecl = %p = %s nondefdecl->get_type() = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str(),nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12041#endif
12042
12043 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
12044
12045 // The nondefining declaration will not appear in the source code, but is compiler
12046 // generated (so we have something about the class that we can reference; e.g in
12047 // types). At the moment we make it a transformation, there might be another kind
12048 // of source position that would be more precise. FIXME.
12049 // setOneSourcePositionNull(nondefdecl);
12051 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
12052
12053#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
12054 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
12056 {
12057 detectTransformations(nondefdecl);
12058 }
12059#endif
12060 // DQ (6/6/2012): This has to be set before we generate the type.
12061 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12062
12063 // DQ (3/15/2012): This is now set below.
12064 // nondefdecl->set_definingDeclaration(defdecl);
12065 nondefdecl->setForward();
12066
12067 // DQ (2/27/2012): I don't like that this is setting the parent to be a scope (not a bad default, but must be reset later if required).
12068 // Liao, 9/2/2009. scope stack is optional, it can be empty
12069 // nondefdecl->set_parent(topScopeStack());
12070#if 0
12071 printf ("WARNING: In buildClassDeclaration_nfi(): Skipping the setting of the parents (for both defining and nondefining declaration) to be the same as the scope \n");
12072#endif
12073 // nondefdecl->set_parent(scope);
12074 // defdecl->set_parent(scope);
12075
12076 if (scope != NULL)
12077 {
12078 mysymbol = new SgClassSymbol(nondefdecl);
12079#if 0
12080 printf ("In buildClassDeclaration_nfi(): Insert the new SgClassSymbol = %p from nondefdecl = %p = %s into the scope = %p = %s \n",mysymbol,nondefdecl,nondefdecl->class_name().c_str(),scope,scope->class_name().c_str());
12081#endif
12082 // scope->insert_symbol(name, mysymbol);
12083 scope->insert_symbol(nameWithTemplateArguments, mysymbol);
12084
12085 // DQ (11/21/2013): Added test based on debugging session with Philippe.
12086 ROSE_ASSERT(nondefdecl->get_scope() == scope);
12087 }
12088 else
12089 {
12090 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unkown.
12091 // DQ (1/26/2009): I think this should be an error, but that appears it would
12092 // break the existing interface. Need to discuss this with Liao.
12093 printf ("Warning: no scope provided to support symbol table entry! \n");
12094 }
12095
12096 // DQ (7/31/2019): Check that the parent is set if this was used a the declaration referenced by a symbol.
12097 // ROSE_ASSERT (nondefdecl->get_parent() != NULL);
12098 }
12099
12100 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
12101
12102#if 1
12103 // Refactored this code.
12104 testTemplateArgumentParents(nondefdecl);
12105#else
12106 if (buildTemplateInstantiation == true)
12107 {
12108 // DQ (7/25/2012): Added this code here to reset the parents of the template arguments.
12109 for (size_t i = 0; i < templateArgumentsList->size(); i++)
12110 {
12111 // DQ (7/25/2012): This should be true because the template argument was set to the functions
12112 // scope so that the name with template arguments could be computed (with name qualification).
12113 ROSE_ASSERT((*templateArgumentsList)[i]->get_parent() != NULL);
12114
12115#error "DEAD CODE!"
12116
12117 // ROSE_ASSERT(isSgGlobal(templateArgumentsList[i]->get_parent()) == NULL);
12118 // ROSE_ASSERT(templateArgumentsList[i]->get_parent() == nondefining_templateInstantiation);
12119
12120 // Be we want to reset it to be the function (now that it is available, because this is more precise).
12121 // All qualified names should compute to the same qualified name (if not then it is a bug in the name
12122 // qualification mechanism).
12123 (*templateArgumentsList)[i]->set_parent(nondefdecl);
12124 }
12125 }
12126#endif
12127
12128 // DQ (3/15/2012): I hhava moved construction of defining declaration to be AFTER the nondefining declaration!
12129 // This is a better organization ans also should make sure that the declaration in the SgClassType will
12130 // properly reference the firstNondefiningDeclaration (instead of the defining declaration).
12131
12132 // step 1 (now step 2). Build defining declaration
12133 // SgClassDefinition* classDef = buildClassDefinition();
12134 SgClassDefinition* classDef = buildClassDefinition(NULL,buildTemplateInstantiation);
12135
12136 // DQ (11/26/2011): Debugging EDG 3.3 use of templateArguments.
12137#if 0
12138 printf ("Building a SgClassDeclaration: buildClassDeclaration_nfi() buildTemplateInstantiation = %s \n",buildTemplateInstantiation ? "true:" : "false");
12139#endif
12140
12141 // SgClassDeclaration* defdecl = new SgClassDeclaration (name,kind,NULL,classDef);
12142 SgClassDeclaration* defdecl = NULL;
12143 if (buildTemplateInstantiation == true)
12144 {
12145 // This adds: SgTemplateDeclaration *templateDeclaration and SgTemplateArgumentPtrList templateArguments
12146 SgTemplateArgumentPtrList emptyList;
12147 // defdecl = new SgTemplateInstantiationDecl (name,kind,NULL,classDef,NULL,emptyList);
12148 defdecl = new SgTemplateInstantiationDecl (nameWithTemplateArguments,kind,NULL,classDef,NULL,emptyList);
12149
12150 // DQ (2/27/2018): Added assertion now that we have implemented more consistant semantics
12151 // for template instantiations (types are not generated in the constructor calls).
12152 ROSE_ASSERT(defdecl->get_type() == NULL);
12153 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl) != NULL);
12154#if 0
12155 printf ("In buildClassDeclaration_nfi(): defdecl->get_name() = %s defdecl->get_templateName() = %s \n",defdecl->get_name().str(),isSgTemplateInstantiationDecl(defdecl)->get_templateName().str());
12156#endif
12157 // DQ (1/1/2012): Added support for setting the template name (I think this should be fixed in the constructor).
12158 // It can't be fixed in the constructor since it has to be set after construction (or passed in explicitly).
12159 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().is_null() == true);
12160
12161#if 0
12162 printf ("Warning: In buildClassDeclaration_nfi(): calling set_templateName(name = %s) for defining declaration \n",name.str());
12163#if 0
12164 // isSgTemplateInstantiationDecl(defdecl)->set_templateName(name);
12165 // isSgTemplateInstantiationDecl(defdecl)->set_templateName("SETME_DEFINING_DECL<>");
12166 isSgTemplateInstantiationDecl(defdecl)->set_templateName(name);
12167
12168#error "DEAD CODE!"
12169
12170 // DQ (5/31/2012): Find locations where this is set and include template syntax.
12171 ROSE_ASSERT(name.getString().find('<') == string::npos);
12172#else
12173 // DQ (6/1/2012): Make sure that the templateName is set and they it does not include the template syntax.
12174 SgName templateName = generateTemplateNameFromTemplateNameWithTemplateArguments(name);
12175 printf ("In buildClassDeclaration_nfi(): templateName = %s \n",templateName.str());
12176 isSgTemplateInstantiationDecl(defdecl)->set_templateName(templateName);
12177
12178#error "DEAD CODE!"
12179
12180 // DQ (5/31/2012): Find locations where this is set and include template syntax.
12181 // ROSE_ASSERT(templateName.getString().find('<') == string::npos);
12182 ROSE_ASSERT(hasTemplateSyntax(templateName) == false);
12183
12184 // DQ (6/1/2012): Not clear if this is always true (for all template instantations).
12185 // ROSE_ASSERT(name.getString().find('<') != string::npos);
12186 ROSE_ASSERT(hasTemplateSyntax(name) == true);
12187#endif
12188#else
12189#if 0
12190 printf ("In buildClassDeclaration_nfi(): nameWithoutTemplateArguments = %s nameWithTemplateArguments = %s \n",nameWithoutTemplateArguments.str(),nameWithTemplateArguments.str());
12191#endif
12192 isSgTemplateInstantiationDecl(defdecl)->set_templateName(nameWithoutTemplateArguments);
12193
12194#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12195 // DQ (5/8/2013): This fails for test2013_159.C, and it appears that we have been overly restrictive here.
12196 if (hasTemplateSyntax(nameWithTemplateArguments) == false)
12197 {
12198 printf ("WARNING: In buildClassDeclaration_nfi(): nameWithTemplateArguments = %s is not using template syntax \n",nameWithTemplateArguments.str());
12199 }
12200#endif
12201 // ROSE_ASSERT(hasTemplateSyntax(nameWithTemplateArguments) == true);
12202
12203 // DQ (7/27/2012): This fails for test2005_35.C where conversion operators are seen.
12204 // ROSE_ASSERT(hasTemplateSyntax(nameWithoutTemplateArguments) == false);
12205#endif
12206
12207 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().is_null() == false);
12208
12209 // DQ (3/22/2012): Make sure there is template syntax present.
12210 if (isSgTemplateInstantiationDecl(defdecl)->get_templateName().getString().find('>') == string::npos)
12211 {
12212#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12213 printf ("WARNING: No template syntax present in name of template class instantiation (defdecl) \n");
12214#endif
12215 }
12216 // ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().getString().find('>') != string::npos);
12217#if 0
12218 printf ("Should we have set the template instantiation name at this point? \n");
12219 ROSE_ABORT();
12220#endif
12221 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
12222 ROSE_ASSERT(defdecl->get_definition() != NULL);
12223 ROSE_ASSERT(isSgTemplateInstantiationDefn(defdecl->get_definition()) != NULL);
12224 }
12225 else
12226 {
12227#if 0
12228 printf ("Building a SgClassDeclaration, but we might require a SgTemplateClassDeclaration \n");
12229#endif
12230 // defdecl = new SgClassDeclaration (name,kind,NULL,classDef);
12231 // defdecl = new SgClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
12232
12233 // DQ (10/11/2015): Try to build a matching SgTemplateClassDeclaration. The problem with this fix is that
12234 // I would prefer that the other function be called instead. We might still want to implementat that instead.
12235 if (buildTemplateDeclaration == true)
12236 {
12237 printf ("In buildClassDeclaration_nfi(): I think we also want template specialization arguments to be more general: using nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
12238
12239 // = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,classType,(SgClassDefinition*)NULL);
12240 defdecl = new SgTemplateClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
12241
12242 // DQ (2/27/2018): We should be able to enforce this, it should have always been true.
12243 ROSE_ASSERT(defdecl->get_type() == NULL);
12244#if 0
12245 printf ("Exiting afte test! \n");
12246 ROSE_ABORT();
12247#endif
12248 }
12249 else
12250 {
12251 defdecl = new SgClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
12252
12253#if 0
12254 // DQ (12/22/2019): Debugging the case of shared class declarations between multiple files referencing the same defining declaration.
12255 printf ("In SageBuilder::buildClassDeclaration_nfi(): build a SgClassDeclaration: defdecl = %p \n",defdecl);
12256#endif
12257
12258 // DQ (2/27/2018): We should be able to enforce this, it should have always been true.
12259 ROSE_ASSERT(defdecl->get_type() == NULL);
12260 }
12261
12262 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
12263 ROSE_ASSERT(defdecl->get_definition() != NULL);
12264 ROSE_ASSERT(isSgTemplateInstantiationDefn(defdecl->get_definition()) == NULL);
12265 }
12266 ROSE_ASSERT(defdecl != NULL);
12267
12268#if 0
12269 printf ("In buildClassDeclaration_nfi(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
12270#endif
12271
12272 // DQ (3/15/2012): Moved from original location above...
12273 nondefdecl->set_definingDeclaration(defdecl);
12274
12275 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
12276 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
12277
12278 // printf ("SageBuilder::buildClassDeclaration_nfi(): defdecl = %p \n",defdecl);
12279
12281 // constructor is side-effect free
12282 classDef->set_declaration(defdecl);
12283 defdecl->set_definingDeclaration(defdecl);
12284
12285 testTemplateArgumentParents(nondefdecl);
12287
12288 // setOneSourcePositionForTransformation(nondefdecl);
12289 //
12290 // Liao 1/18/2011, I changed the semantics of setOneSourcePositionNull to set file_info to null regardless the existence of
12291 // file_info of the input node.
12292 // We do want to keep the file_info of nodefdecl if it is set already as compiler generated.
12293 // setOneSourcePositionNull(nondefdecl);
12294
12295 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12296 // nondefdecl->set_definingDeclaration(defdecl);
12297 defdecl->set_firstNondefiningDeclaration(nondefdecl);
12298
12299 if (buildTemplateInstantiation == true)
12300 {
12301 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
12302 setTemplateArgumentsInDeclaration(defdecl,templateArgumentsList);
12303 }
12304
12305 // DQ (3/22/2012): I think we can assert this.
12306 ROSE_ASSERT(defdecl->get_type() == NULL);
12307
12308 // Liao, 10/30/2009
12309 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
12310 // This is not desired when building a defining declaration and an inefficience in the constructor
12311 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
12312 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
12313 if (defdecl->get_type() != NULL)
12314 {
12315 // if a defining class declaration's type is associated with a defining class.
12316 // This is a wrong SgClassType and has to be reset
12317 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl))
12318 {
12319 // DQ (3/21/2012): Added this test.
12320 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12321
12322 // DQ (3/15/2012): Make this conditional upon the types not already being equal.
12323 if (nondefdecl->get_type() != defdecl->get_type())
12324 {
12325#if 0
12326 printf ("Deleting defdecl->get_type() = %p = %s (using type from nondefdecl = %p) \n",defdecl->get_type(),defdecl->get_type()->class_name().c_str(),nondefdecl);
12327 printf ("Skipping delete of %p to maintain unique type pointers \n",defdecl->get_type());
12328#else
12329 delete defdecl->get_type();
12330#endif
12331 // DQ (3/15/2012): This will be reset below.
12332 defdecl->set_type(NULL);
12333#if 0
12334 printf ("In SageBuilder::buildClassDeclaration(): built class type: part 5: defdecl->get_type() = %p = %s \n",defdecl->get_type(),defdecl->get_type()->class_name().c_str());
12335#endif
12336#if 0
12337 // DQ (12/13/2011): Is this executed...
12338 printf ("Is this executed! \n");
12339 ROSE_ABORT();
12340#endif
12341 // DQ (3/21/2012): set the types to be the same type.
12342 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12343 defdecl->set_type(nondefdecl->get_type());
12344#if 0
12345 printf ("In SageBuilder::buildClassDeclaration(): built class type: part 6: nondefdecl->get_type() = %p = %s \n",defdecl->get_type(),defdecl->get_type()->class_name().c_str());
12346#endif
12347 // DQ (3/21/2012): Added these checks...
12348 SgClassType* classType = nondefdecl->get_type();
12349 ROSE_ASSERT(classType != NULL);
12350 SgClassDeclaration* local_classDeclaration = isSgClassDeclaration(classType->get_declaration());
12351 ROSE_ASSERT (local_classDeclaration != NULL);
12352 printf ("In buildClassDeclaration_nfi(): classType = %p local_classDeclaration = %p \n",classType,local_classDeclaration);
12353 ROSE_ASSERT (local_classDeclaration->get_firstNondefiningDeclaration() != NULL);
12354 ROSE_ASSERT (local_classDeclaration->get_firstNondefiningDeclaration() == local_classDeclaration);
12355 }
12356 }
12357 }
12358 else
12359 {
12360 // DQ (3/15/2012): Make sure that both the defining and non-defining declarations use the same type.
12361 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12362 defdecl->set_type(nondefdecl->get_type());
12363#if 0
12364 printf ("In buildClassDeclaration_nfi(): defdecl = %p = %s defdecl->get_type() = %p = %s \n",defdecl,defdecl->class_name().c_str(),defdecl->get_type(),defdecl->get_type()->class_name().c_str());
12365#endif
12366
12367 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
12368#if 0
12369 // DQ (11/20/2017): Commented out output spew.
12370 // DQ (2/28/2015): This test is failing in the new application support for templates within the testRoseHeaders_01.C.
12371 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()))
12372 {
12373 printf ("WARNING: In buildClassDeclaration_nfi(): inner test: commented out test for equality between the declaration asociated with the type and that associated with the firstNondefiningDeclaration \n");
12374 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12375 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
12376 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
12377 }
12378 // DQ (7/22/2017): Uncomment this test to better understand why this is a new issue (after two years).
12379 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
12380#endif
12381#if 0
12382 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
12383#endif
12384 }
12385
12386 // DQ (9/4/2012): Added assertion.
12387 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12388
12389 // patch up the SgClassType for the defining class declaration
12390 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12391 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
12392#if 0
12393 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl))
12394 {
12395 printf ("nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
12396 printf ("nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12397 printf ("nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
12398 printf ("nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
12399 }
12400#endif
12401 // ROSE_ASSERT (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl));
12402 ROSE_ASSERT (defdecl->get_type() != NULL);
12403 ROSE_ASSERT (defdecl->get_type()->get_declaration() != NULL);
12404 ROSE_ASSERT (defdecl->get_type()->get_declaration() != isSgDeclarationStatement(defdecl));
12405 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
12406 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
12407#if 0
12408 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
12409#else
12410
12411#if 0
12412 // DQ (11/20/2017): Commented out output spew.
12413 // DQ (2/28/2015): This test is failing in the new application support for templates within the testRoseHeaders_01.C.
12414 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()))
12415 {
12416 printf ("WARNING: In buildClassDeclaration_nfi(): outer test (test 1): commented out test for equality between the declaration asociated with the type and that associated with the firstNondefiningDeclaration \n");
12417 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12418 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
12419 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
12420 }
12421 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
12422 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl))
12423 {
12424 printf ("WARNING: In buildClassDeclaration_nfi(): outer test (test 2): commented out test for equality between the declaration asociated with the type and that associated with the firstNondefiningDeclaration \n");
12425 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12426 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
12427 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
12428 }
12429 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
12430#endif
12431
12432#endif
12433
12434 // DQ (9/4/2012): Added assertion.
12435 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12436
12437 // This appears to be redundant...is it?
12438 defdecl->set_type(nondefdecl->get_type());
12439
12440#if 0
12441 printf ("In buildClassDeclaration_nfi(): after calling set_type() again: defdecl = %p = %s defdecl->get_type() = %p = %s \n",
12442 defdecl,defdecl->class_name().c_str(),defdecl->get_type(),defdecl->get_type()->class_name().c_str());
12443#endif
12444
12445 // DQ (9/4/2012): Added assertion.
12446 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12447
12448 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
12449 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
12450 // used in a defining declaration).
12451 nondefdecl->setForward();
12452
12453 if (scope != NULL) // put into fixStructDeclaration() or alike later on
12454 {
12455 // DQ (9/4/2012): Added assertion.
12456 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12457
12458 // Note, this function sets the parent to be the scope if it is not already set.
12459 fixStructDeclaration(defdecl,scope);
12460
12461 // DQ (9/4/2012): Added assertion.
12462 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12463
12464 fixStructDeclaration(nondefdecl,scope);
12465
12466 // DQ (9/4/2012): Added assertion.
12467 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12468
12469#if 0
12470 SgClassSymbol* mysymbol = new SgClassSymbol(nondefdecl);
12471 ROSE_ASSERT(mysymbol);
12472 scope->insert_symbol(name, mysymbol);
12473 printf ("@@@@@@@@@@@@@@ In buildClassDeclaration_nfi(): setting scope of defining and non-defining declaration to scope = %s \n",scope->class_name().c_str());
12474 defdecl->set_scope(scope);
12475 nondefdecl->set_scope(scope);
12476
12477 // defdecl->set_parent(scope);
12478
12479 // Liao, 9/2/2009. merged into fixStructDeclaration
12480 // DQ (1/25/2009): The scope is not the same as the parent, since the scope is logical, and the parent is structural (note that topScopeStack() is structural).
12481 nondefdecl->set_parent(scope);
12482 // nondefdecl->set_parent(topScopeStack());
12483 // Liao, 9/2/2009. scope stack is optional, it can be empty
12484 defdecl->set_parent(scope);
12485 // defdecl->set_parent(topScopeStack());
12486#endif
12487 }
12488
12489 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
12490 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
12491 // ROSE_ASSERT(defdecl->get_parent() != NULL);
12492
12493 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
12494
12495 // DQ (2/27/2012): Tracking down where parents are not set correctly (class declaration in typedef is incorrectly set to SgGlobal).
12496 ROSE_ASSERT(defdecl->get_parent() == NULL);
12497
12498 // DQ (2/29/2012): We can't assert this (fails for test2012_09.C).
12499 // ROSE_ASSERT(nondefdecl->get_parent() == NULL);
12500
12501 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
12502 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
12503
12504 testTemplateArgumentParents(nondefdecl);
12506
12507 // DQ (3/8/2018): Added for debugging.
12508 SgClassDeclaration* temp_firstNondefiningDeclaration = isSgClassDeclaration(defdecl->get_firstNondefiningDeclaration());
12509 SgClassDeclaration* temp_definingDeclaration = isSgClassDeclaration(defdecl->get_definingDeclaration());
12510 ROSE_ASSERT(temp_firstNondefiningDeclaration != NULL);
12511 ROSE_ASSERT(temp_definingDeclaration != NULL);
12512
12513#if 0
12514 printf ("Leaving buildClassDeclaration_nfi(): defdecl = %p = %s = %s \n",defdecl,defdecl->class_name().c_str(),defdecl->get_name().str());
12515 printf (" --- defdecl->get_firstNondefiningDeclaration() = %p \n",defdecl->get_firstNondefiningDeclaration());
12516 printf (" --- defdecl->get_definingDeclaration() = %p \n",defdecl->get_definingDeclaration());
12517
12518 printf (" --- defdecl->get_firstNondefiningDeclaration()->get_name() = %s \n",temp_firstNondefiningDeclaration->get_name().str());
12519 printf (" --- defdecl->get_definingDeclaration()->get_name() = %s \n",temp_definingDeclaration->get_name().str());
12520
12521 printf (" --- defdecl->get_firstNondefiningDeclaration()->get_type() = %p = %s \n",
12522 temp_firstNondefiningDeclaration->get_type(),temp_firstNondefiningDeclaration->get_type()->unparseToString().c_str());
12523 printf (" --- defdecl->get_definingDeclaration()->get_type() = %p = %s \n",
12524 temp_definingDeclaration->get_type(),temp_definingDeclaration->get_type()->unparseToString().c_str());
12525
12526 printf (" --- nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
12527 printf (" --- nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
12528
12529#if 0
12530 printf ("Leaving buildClassDeclaration_nfi(): defdecl: unparseNameToString() = %s \n",defdecl->unparseNameToString().c_str());
12531#endif
12532#endif
12533
12534 // DQ (3/8/2018): Added assertion.
12535 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_name() == temp_definingDeclaration->get_name());
12536 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_type() == temp_definingDeclaration->get_type());
12537
12538 // DQ (3/7/2015): Only in EDG 4.7 does the defining declaration not have a valid templateDeclaration pointer (sometimes).
12539 SgTemplateInstantiationDecl* nondefiningDeclaration = isSgTemplateInstantiationDecl(defdecl->get_firstNondefiningDeclaration());
12540 SgTemplateInstantiationDecl* definingDeclaration = isSgTemplateInstantiationDecl(defdecl->get_definingDeclaration());
12541 if (definingDeclaration != NULL && nondefiningDeclaration != NULL)
12542 {
12543 SgTemplateClassDeclaration* templateDeclaration = nondefiningDeclaration->get_templateDeclaration();
12544 if (templateDeclaration != NULL && definingDeclaration->get_templateDeclaration() == NULL)
12545 {
12546#if 0
12547 printf ("NOTE: buildClassDeclaration_nfi(): Setting the templateDeclaration for the defining declaration = %p using the value = %p from the nondefiningDeclaration = %p \n",
12548 definingDeclaration,templateDeclaration,nondefiningDeclaration);
12549#endif
12550 definingDeclaration->set_templateDeclaration(templateDeclaration);
12551
12552 ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
12553 }
12554 // ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
12555 }
12556
12557 // DQ (3/7/2015): Only in EDG 4.7 does the defining declaration not have a valid templateDeclaration pointer (sometimes).
12558 if (definingDeclaration != NULL)
12559 {
12560 if (definingDeclaration->get_templateDeclaration() == NULL)
12561 {
12562#if 0
12563 printf ("NOTE: buildClassDeclaration_nfi(): definingDeclaration->get_templateDeclaration() == NULL \n");
12564#endif
12565 }
12566 // ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
12567 }
12568
12569#if 0
12570 printf ("Leaving buildClassDeclaration_nfi(): defdecl = %p defdecl->unparseNameToString() = %s \n",defdecl,defdecl->unparseNameToString().c_str());
12571#endif
12572
12573#if 0
12574 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12575 printf ("Leaving buildClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
12576 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
12577
12578 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12579 printf ("Leaving buildClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
12580 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
12581#endif
12582
12583 return defdecl;
12584 }
12585
12586
12588 {
12589 SgName myname(name);
12590 return buildStructDeclaration(myname, scope);
12591 }
12592
12594 {
12595 SgName myname(name);
12596 return buildStructDeclaration(myname, scope);
12597 }
12598
12599
12600#if 0
12601// DQ (11/19/2011): Added more uniform support for building class declarations.
12604 {
12605 ROSE_ASSERT(scope != NULL);
12606 SgTemplateClassDeclaration* definingClassDeclaration = buildDefiningTemplateClassDeclaration(name,scope);
12607 ROSE_ASSERT(definingClassDeclaration != NULL);
12608
12609 return definingClassDeclaration;
12610 }
12611#endif
12612
12613
12616 {
12617 SgTemplateClassDefinition* result = NULL;
12618 if (d != NULL) // the constructor does not check for NULL d, causing segmentation fault
12619 {
12620 result = new SgTemplateClassDefinition(d);
12621 // result->set_parent(d); // set_declaration() == set_parent() in this case
12622 }
12623 else
12624 {
12625 result = new SgTemplateClassDefinition();
12626 }
12627
12628 ROSE_ASSERT(result);
12629
12630 // CR (3/22/2020): Fixed setting case insensitivity
12631 // if (symbol_table_case_insensitive_semantics == true)
12633 result->setCaseInsensitive(true);
12634
12636 return result;
12637 }
12638
12640SageBuilder::buildNondefiningTemplateClassDeclaration(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12641{
12642 SgTemplateClassDeclaration* res = buildNondefiningTemplateClassDeclaration_nfi (XXX_name, kind, scope, templateParameterList, templateSpecializationArgumentList);
12644 return res;
12645}
12646
12647// SgTemplateClassDeclaration * SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(const SgName& name, SgClassDeclaration::class_types kind, SgScopeStatement* scope )
12649SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12650 {
12651#if 0
12652 printf("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(XXX_name = %p):\n", XXX_name.str());
12653#endif
12654
12655 if (scope == NULL)
12657
12658 // DQ (11/20/2011): This is for initial debugging only.
12659 ROSE_ASSERT(scope != NULL);
12660
12661#if 0
12662 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): XXX_name = %s scope = %p = %s \n",XXX_name.str(),scope,scope->class_name().c_str());
12663#endif
12664
12665 // DQ (9/12/2012): We want to add the template arguments of any specialization to the template name and keep track of the name with and without template specialization arguments.
12666 SgName nameWithoutTemplateArguments = XXX_name;
12667 SgName nameWithTemplateSpecializationArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateSpecializationArgumentList);
12668
12669#if 0
12670 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
12671#endif
12672
12673 // SgTemplateClassDeclaration::class_types template_class_kind = SgTemplateClassDeclaration::e_class;
12674
12675 // Step 2. build the nondefining declaration,
12676 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
12677
12678 // Get the nondefining declaration from the symbol if it has been built (if this works,
12679 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
12680 SgTemplateClassDeclaration* nondefdecl = NULL;
12681
12682 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
12683 // ROSE_ASSERT(scope != NULL);
12684
12685 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12686 // SgTemplateSymbol* mysymbol = NULL;
12687 SgClassSymbol* mysymbol = NULL;
12688
12689 if (scope != NULL)
12690 {
12691 // DQ (9/12/2012): We want to include the template specialization into the name where it is required (this handling
12692 // is similar to normal template arguments for non-template declaration, but different than template parameters).
12693 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12694 // mysymbol = scope->lookup_template_symbol(name);
12695 // mysymbol = scope->lookup_class_symbol(name);
12696 // mysymbol = scope->lookup_template_class_symbol(name);
12697 // mysymbol = scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList);
12698 mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
12699 }
12700 else
12701 {
12702 // Liao 9/2/2009: This is not an error. We support bottom-up AST construction and scope can be unknown.
12703 // DQ (1/26/2009): I think this should be an error, but that appears it would
12704 // break the existing interface. Need to discuss this with Liao.
12705 printf ("Warning: In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): scope == NULL \n");
12706 }
12707#if 0
12708 printf ("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
12709#endif
12710
12711 if (mysymbol != NULL) // set links if nondefining declaration already exists.
12712 {
12713 // DQ (3/7/2012): Build a seperate non-defining declaration (reusing the existing one will cause the test for unique statements to fail).
12714 // printf ("WARNING: Even if the first non-defining SgTemplateClassDeclaration is found in the symbol table then likely we still might want to build a 2nd one. \n");
12715 // nondefdecl = isSgTemplateClassDeclaration(mysymbol->get_declaration());
12716 SgClassType* classType = isSgClassType(mysymbol->get_type());
12717 ROSE_ASSERT(classType != NULL);
12718
12719 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12720 // nondefdecl = new SgTemplateClassDeclaration(name,kind,classType,(SgClassDefinition*)NULL);
12721 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,classType,(SgClassDefinition*)NULL);
12722
12723#if 0
12724 // DQ (3/4/2018): relax this requirement for SgTemplateInstantiationClassDeclaration.
12725 // DQ (2/27/2018): Enforce that this is not already set (should be set after the constructor to
12726 // simplify how derived classes (e.g. SgTemplateInstantiationClassDeclaration statements) work.
12727 if (nondefdecl->get_type() != NULL)
12728 {
12729 printf ("Note: SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): nondefdecl->get_type() != NULL: name = %s \n",nondefdecl->get_name().str());
12730 }
12731 // ROSE_ASSERT(nondefdecl->get_type() == NULL);
12732#endif
12733
12734 ROSE_ASSERT(nondefdecl != NULL);
12735
12736 // DQ (9/10/2012): Initialize the template parameter list.
12737 ROSE_ASSERT(templateParameterList != NULL);
12738 nondefdecl->get_templateParameters() = *templateParameterList;
12739
12740 // DQ (9/16/2012): Moved this initialization of firstNondefiningDeclaration from farther down in this branch (and added assertion).
12741 nondefdecl->set_firstNondefiningDeclaration(mysymbol->get_declaration());
12742 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
12743
12744 // TV (04/12/2018): Add a scope for nonreal classes (and their member) on the first non-defining declaration of template classes
12745 if (nondefdecl == nondefdecl->get_firstNondefiningDeclaration()) {
12746 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
12747
12748 nonreal_decl_scope->set_parent(nondefdecl);
12749 nondefdecl->set_nonreal_decl_scope(nonreal_decl_scope);
12750
12751 SageInterface::setSourcePosition(nonreal_decl_scope);
12752 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
12753 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
12754#if 0
12755 printf("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(XXX_name = %p): nrscope = %p (new)\n", XXX_name.str(), nonreal_decl_scope);
12756#endif
12757 }
12758
12759#if 1
12760 // DQ (9/16/2012): This newly refactored function can only be called after firstNondefiningDeclaration is set.
12761 // This also sets the template argument parents to the firstNondefiningDeclaration.
12762 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
12763#else
12764 // DQ (9/12/2012): Adding support for template specialization.
12765 ROSE_ASSERT(templateSpecializationArgumentList != NULL);
12766 nondefdecl->get_templateSpecializationArguments() = *templateSpecializationArgumentList;
12767#endif
12768 // DQ (9/10/2012): Test the just built template with its template parameters.
12769 if (nondefdecl->get_templateParameters().size() == 0)
12770 {
12771#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12772 printf ("WARNING: In buildNondefiningTemplateClassDeclaration_nfi(): (part 1) nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
12773#endif
12774 }
12775 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12776
12777 // DQ (3/7/2012): We want this to be set later, so we can't test it here.
12778 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
12779#if 0
12780 nondefdecl->set_definingDeclaration(defdecl);
12781
12782 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
12783 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
12784#endif
12785 // DQ (3/7/2012): But always refer to the first non-defining declaration so it will be unique (and set the scope).
12786 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
12787 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != nondefdecl);
12788 nondefdecl->set_scope(scope);
12789 nondefdecl->setForward();
12790
12791 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12792 nondefdecl->set_templateName(nameWithoutTemplateArguments);
12793
12794 testTemplateArgumentParents(nondefdecl);
12795 }
12796 else // build a nondefnining declaration if it does not exist
12797 {
12798 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,(SgClassType*)NULL,(SgClassDefinition*)NULL);
12799 ROSE_ASSERT(nondefdecl != NULL);
12800
12801 // DQ (9/10/2012): Initialize the template parameter list.
12802 ROSE_ASSERT(templateParameterList != NULL);
12803 nondefdecl->get_templateParameters() = *templateParameterList;
12804
12805 // DQ (9/16/2012): Moved this initialization of firstNondefiningDeclaration from farther down in this branch.
12806 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12807
12808 // DQ (9/16/2012): This newly refactored function can only be called after firstNondefiningDeclaration is set.
12809 // This also sets the template argument parents to the firstNondefiningDeclaration.
12810 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
12811
12812 // DQ (9/10/2012): Test the just built template with its template parameters.
12813 if (nondefdecl->get_templateParameters().size() == 0)
12814 {
12815#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12816 printf ("WARNING: In buildNondefiningTemplateClassDeclaration_nfi(): (part 2) nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
12817#endif
12818 }
12819 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12820
12821 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12822 nondefdecl->set_templateName(nameWithoutTemplateArguments);
12823
12824#if 0
12825 // DQ (12/4/2011): Now we want to enable this so that the SgClassType will be available from a SgTemplateClassDeclaration.
12826 if (nondefdecl->get_type() == NULL)
12827 {
12828 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
12829 // nondefdecl->set_type(NULL);
12830 // nondefdecl->set_type(SgTemplateType::createType(nondefdecl));
12831 // nondefdecl->set_type(SgTemplateType::createType());
12832 nondefdecl->set_type(SgClassType::createType(nondefdecl));
12833 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12834 }
12835#endif
12836 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
12837
12838 // The nondefining declaration will not appear in the source code, but is compiler
12839 // generated (so we have something about the class that we can reference; e.g in
12840 // types). At the moment we make it a transformation, there might be another kind
12841 // of source position that would be more precise. FIXME.
12842 // setOneSourcePositionNull(nondefdecl);
12844 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
12845
12846 // nondefdecl->set_definingDeclaration(defdecl);
12847 nondefdecl->setForward();
12848
12849 // Liao, 9/2/2009. scope stack is optional, it can be empty
12850 // nondefdecl->set_parent(topScopeStack());
12851#if 0
12852 printf ("In buildNondefiningTemplateClassDeclaration_nfi(): Commented out setting the parent to the scope. \n");
12853#endif
12854 // printf ("Note that for C++, the parent may not be the same as the scope (dangerous code). \n");
12855 // nondefdecl->set_parent(scope);
12856
12857 nondefdecl->set_scope(scope);
12858
12859#if 1
12860 // DQ (12/4/2011): Set the scope first and then set the type (scope is required to compute the type (name mangling)).
12861 // DQ (12/4/2011): Now we want to enable this so that the SgClassType will be available from a SgTemplateClassDeclaration.
12862 if (nondefdecl->get_type() == NULL)
12863 {
12864 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
12865 // nondefdecl->set_type(NULL);
12866 // nondefdecl->set_type(SgTemplateType::createType(nondefdecl));
12867 // nondefdecl->set_type(SgTemplateType::createType());
12868 nondefdecl->set_type(SgClassType::createType(nondefdecl));
12869 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12870#if 0
12871 printf ("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): built class type: part 1: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12872#endif
12873 }
12874#endif
12875
12876 // Build a SgTemplateClassSymbol and put it into the specified scope.
12877 if (scope != NULL)
12878 {
12879#if 0
12880 printf ("Building a SgTemplateSymbol using nameWithTemplateSpecializationArguments = %s and nondefdecl = %p = %s \n",nameWithTemplateSpecializationArguments.str(),nondefdecl,nondefdecl->class_name().c_str());
12881#endif
12882 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12883 // mysymbol = new SgTemplateSymbol(nondefdecl);
12884 // mysymbol = new SgClassSymbol(nondefdecl);
12885 mysymbol = new SgTemplateClassSymbol(nondefdecl);
12886 ROSE_ASSERT(mysymbol != NULL);
12887
12888 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12889 // DQ (3/6/2012): Added test for existing symbol (see test2012_18.C).
12890 // ROSE_ASSERT(scope->lookup_template_class_symbol(name) == NULL);
12891 // ROSE_ASSERT(scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList) == NULL);
12892 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList) == NULL);
12893
12894 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12895 // scope->insert_symbol(name, mysymbol);
12896 scope->insert_symbol(nameWithTemplateSpecializationArguments, mysymbol);
12897#if 0
12898 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi() (after building symbol): scope = %p = %s \n",scope,scope->class_name().c_str());
12899#endif
12900 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
12901
12902 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
12903
12904 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12905 // ROSE_ASSERT(scope->lookup_template_class_symbol(name) != NULL);
12906 // ROSE_ASSERT(scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList) != NULL);
12907 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList) != NULL);
12908 }
12909 else
12910 {
12911 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknown.
12912 }
12913
12914 testTemplateArgumentParents(nondefdecl);
12915
12916#if 1
12917 // DQ (7/16/2017): Added code to set the template parameters in the just build declaration (if it is a template declaration).
12918 // We want to set the parents of the template paremters to the frst nondefining template class declaration, and we want to reset
12919 // the scope of the declarations associated with any previously marked SgClassType objects associated with any template parameters.
12920 // printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): Calling setTemplateParametersInDeclaration(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
12921
12922 setTemplateParametersInDeclaration(nondefdecl,templateParameterList);
12923
12924 // DQ (8/13/2013): Adding test of template parameter lists.
12925 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(nondefdecl);
12926 ROSE_ASSERT(templateClassDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateClassDeclaration->get_templateParameters().size()));
12927#endif
12928 }
12929
12930 // defdecl->set_firstNondefiningDeclaration(nondefdecl);
12931
12932 // DQ (11/3/2012): Setup the default source position information.
12933 setSourcePosition(nondefdecl);
12934
12935#if 0
12936 // DQ (11/20/2011): SgTemplateClassDeclaration IR nodes don't have a SgType associated with them (template declarations don't have a type in C++, I think).
12937
12938 // Liao, 10/30/2009
12939 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
12940 // This is not desired when building a defining declaration and an inefficience in the constructor
12941 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
12942 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
12943 if (defdecl->get_type() != NULL)
12944 {
12945 // if a defining class declaration's type is associated with a defining class.
12946 // This is a wrong SgClassType and has to be reset
12947 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
12948 {
12949 delete defdecl->get_type();
12950 }
12951 }
12952
12953 // patch up the SgClassType for the defining class declaration
12954 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12955 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
12956 defdecl->set_type(nondefdecl->get_type());
12957#else
12958 // printf ("We might need to force the types used for defining and non-defining SgTemplateClassDeclaration to be the same! \n");
12959 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12960#endif
12961
12962 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
12963 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
12964 // used in a defining declaration).
12965 nondefdecl->setForward();
12966
12967 if (scope != NULL) // put into fixStructDeclaration() or alike later on
12968 {
12969 // fixStructDeclaration(defdecl,scope);
12970 // fixStructDeclaration(nondefdecl,scope);
12971
12972 // printf ("***** WARNING *****: Commented out call to fixStructDeclaration() \n");
12973 // ROSE_ASSERT(false);
12974 }
12975
12976#if 0
12977 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
12978 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
12979
12980 ROSE_ASSERT(defdecl->get_scope() != NULL);
12981#endif
12982
12983 // DQ (7/15/2012): We want to enforce this to not be set yet (might be part of non-autonomous declaration (e.g. nested in a typedef).
12984 ROSE_ASSERT(nondefdecl->get_parent() == NULL);
12985
12986 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
12987 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
12988
12989 testTemplateArgumentParents(nondefdecl);
12990
12991#if 0
12992 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12993 printf ("Leaving buildNondefiningTemplateClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
12994 SgClassDeclaration* tmp_classDeclaration = nondefdecl;
12995 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(tmp_classDeclaration);
12996
12997 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12998 printf ("Leaving buildNondefiningTemplateClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
12999 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
13000#endif
13001
13002 return nondefdecl;
13003 }
13004
13007 SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
13008{
13009 SgTemplateClassDeclaration * res = buildTemplateClassDeclaration_nfi (XXX_name, kind, scope, nonDefiningDecl, templateParameterList, templateSpecializationArgumentList);
13011 return res;
13012}
13013
13016 SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
13017 {
13018 // DQ (12/26/2011): Notes that the input nonDefiningDecl is not used...this is a confusing point.
13019 // The specification of the scope appears to be enough.
13020
13021 if (scope == NULL)
13023
13024#if 0
13025 printf ("In buildTemplateClassDeclaration_nfi(): nonDefiningDecl = %p \n",nonDefiningDecl);
13026 if (nonDefiningDecl != NULL)
13027 {
13028 printf ("--- nonDefiningDecl->get_firstNondefiningDeclaration() = %p \n",nonDefiningDecl->get_firstNondefiningDeclaration());
13029 printf ("--- nonDefiningDecl->get_definingDeclaration() = %p \n",nonDefiningDecl->get_definingDeclaration());
13030 }
13031#endif
13032
13033 // DQ (11/20/2011): This is for initial debugging only.
13034 ROSE_ASSERT(scope != NULL);
13035
13036 // DQ (9/12/2012): We want to add the template arguments of any specialization to the template name and keep track of the name with and without template specialization arguments.
13037 SgName nameWithoutTemplateArguments = XXX_name;
13038 SgName nameWithTemplateSpecializationArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateSpecializationArgumentList);
13039
13040 // step 1. Build defining declaration
13041 // Note that even the SgTemplateClassDeclaration uses a regular SgClassDefinition instead of the currently unused SgTemplateClassDefinition.
13042 // SgClassDefinition* classDef = buildClassDefinition();
13043 // SgTemplateClassDefinition* classDef = buildTemplateClassDefinition(name,);
13044
13045 // DQ (11/29/2011): Added checks...
13046 if (nonDefiningDecl != NULL)
13047 {
13048 ROSE_ASSERT(nonDefiningDecl->get_firstNondefiningDeclaration() == nonDefiningDecl);
13049 }
13050
13051 SgName templateString = "template string";
13052 // SgTemplateDeclaration::template_type_enum template_kind = SgTemplateDeclaration::e_template_class;
13053 SgTemplateParameterPtrList templateParameters;
13054
13055 // SgTemplateDeclaration (SgName name, SgName string, SgTemplateDeclaration::template_type_enum template_kind, SgTemplateParameterPtrList templateParameters)
13056 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,kind,NULL,classDef);
13057 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters);
13058
13059 // SgTemplateClassDeclaration::class_types template_class_kind = SgTemplateClassDeclaration::e_class;
13060 // SgTemplateType* classType = NULL;
13061 // SgTemplateClassDefinition* classDef = NULL;
13063
13064 // Constructure arguments: SgName, SgName, SgTemplateDeclaration::template_type_enum, SgTemplateParameterPtrList, SgTemplateClassDeclaration::class_types, SgClassType*, SgTemplateClassDefinition*
13065 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters);
13066 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,template_class_kind,classType,classDef);
13067 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,template_class_kind,classDef);
13068
13069#if 0
13070 printf ("In buildTemplateClassDeclaration_nfi(): calling new SgTemplateClassDeclaration() name = %s \n",nameWithTemplateSpecializationArguments.str());
13071#endif
13072
13073 // DQ (9/12/2012): We want to include the template specialization into the name where it is required (this handling
13074 // is similar to normal template arguments for non-template declaration, but different than template parameters).
13075 // This copy of SgName is required to support passing it to the SgTemplateClassDeclaration constructor.
13076 // SgName localName = name;
13077 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,template_class_kind,classDef);
13078 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,kind,NULL,classDef);
13079
13080 // DQ (1/13/2013): This is causing two defining declarations to be built for test2012_278.C (and the parent for the second defining
13081 // declaration is not being set, though the larger issue is that we have two defining declarations, however this might be acceptable
13082 // if this is a specialization).
13083 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (nameWithTemplateSpecializationArguments,kind,NULL,classDef);
13084 SgTemplateClassDeclaration* defdecl = NULL;
13085 if (nonDefiningDecl != NULL)
13086 {
13087 // If we have a non-defining declaration specified, try to use any existing defining declaration withouth building a 2nd one
13088 // (which would be an error, unless maybe if this is a specialization).
13089 if (nonDefiningDecl->get_definingDeclaration() != NULL)
13090 {
13091 // This must be a valid SgTemplateClassDefinition.
13092 defdecl = isSgTemplateClassDeclaration(nonDefiningDecl->get_definingDeclaration());
13093 ROSE_ASSERT(defdecl != NULL);
13094#if 0
13095 printf ("In buildTemplateClassDeclaration_nfi(): Reusing the defining declaration previously build: defdecl = %p = %s \n",defdecl,defdecl->get_name().str());
13096#endif
13097 }
13098 else
13099 {
13100#if 0
13101 printf ("In buildTemplateClassDeclaration_nfi(): No defining declaration found, so we have to build one. \n");
13102#endif
13103 }
13104 }
13105
13106 if (defdecl == NULL)
13107 {
13108#if 0
13109 printf ("Building a defining declaration \n");
13110#endif
13111 defdecl = new SgTemplateClassDeclaration (nameWithTemplateSpecializationArguments,kind,NULL,classDef);
13112 }
13113
13114 ROSE_ASSERT(defdecl != NULL);
13115
13116#if 0
13117 printf ("In buildTemplateClassDeclaration_nfi(): defdecl = %p = %s \n",defdecl,defdecl->class_name().c_str());
13118#endif
13119
13120 // DQ (9/10/2012): Initialize the template parameter list.
13121 ROSE_ASSERT(templateParameterList != NULL);
13122 defdecl->get_templateParameters() = *templateParameterList;
13123
13124 // DQ (9/12/2012): Adding support for template specialization.
13125 ROSE_ASSERT(templateSpecializationArgumentList != NULL);
13126 defdecl->get_templateSpecializationArguments() = *templateSpecializationArgumentList;
13127
13128 // DQ (9/16/2012): We can't test this yet, since the firstNondefiningDeclaration has not be set.
13129 // testTemplateArgumentParents(defdecl);
13130
13131 // DQ (9/10/2012): Test the just built template with its template parameters.
13132 if (defdecl->get_templateParameters().size() == 0)
13133 {
13134#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
13135 printf ("WARNING: In buildTemplateClassDeclaration_nfi(): defdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations defdecl = %p \n",defdecl);
13136#endif
13137 }
13138 // ROSE_ASSERT(defdecl->get_templateParameters().size() > 0);
13139
13140 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
13141 defdecl->set_templateName(nameWithoutTemplateArguments);
13142
13143#if 0
13144 printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): scope = %p = %s \n",scope,scope->class_name().c_str());
13145#endif
13146
13147 defdecl->set_scope(scope);
13148
13149 // DQ (7/15/2012): To support non-autonomous declarations (declarations nested in types) we don't want to set the parent here. It will be set later.
13150 // DQ (11/20/2011): Can name qualification make this incorrect?
13151 // defdecl->set_parent(scope);
13152
13153 ROSE_ASSERT(classDef != NULL);
13154
13155 // printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): defdecl = %p \n",defdecl);
13156
13158
13159 // constructor is side-effect free
13160 classDef->set_declaration(defdecl);
13161 defdecl->set_definingDeclaration(defdecl);
13162
13163 // Step 2. build the nondefining declaration,
13164 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
13165
13166 // Get the nondefining declaration from the symbol if it has been built (if this works,
13167 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
13168 SgTemplateClassDeclaration* nondefdecl = nonDefiningDecl;
13169 if (nondefdecl == NULL) {
13170 ROSE_ASSERT(scope != NULL);
13171
13172 SgClassSymbol* mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
13173#if 0
13174 printf ("In buildTemplateClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
13175#endif
13176
13177 if (mysymbol != NULL) {
13178 nondefdecl = isSgTemplateClassDeclaration(mysymbol->get_declaration());
13179 ROSE_ASSERT(nondefdecl != NULL);
13180
13181 nondefdecl->set_definingDeclaration(defdecl);
13182 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
13183 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
13184
13185 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13186 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
13187
13188 // DQ (9/16/2012): Test this previously setup firstNondefiningDeclaration.
13189 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
13190 testTemplateArgumentParents(nondefdecl);
13191 } else {
13192#if 0
13193 printf(" start build non-defn decl for %p\n",defdecl);
13194#endif
13195 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
13196 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,NULL,NULL);
13197 ROSE_ASSERT(nondefdecl != NULL);
13198
13199 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
13200 nondefdecl->set_definingDeclaration(defdecl);
13201#if 0
13202 printf(" nondefdecl = %p\n",nondefdecl);
13203#endif
13204#if 0
13205 // TV (04/12/2018): Add a scope for nonreal classes (and their member) on the first non-defining declaration of template classes
13206 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
13207
13208 nonreal_decl_scope->set_parent(nondefdecl);
13209 nondefdecl->set_nonreal_decl_scope(nonreal_decl_scope);
13210
13211 SageInterface::setSourcePosition(nonreal_decl_scope);
13212 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
13213 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
13214#if 1
13215 printf("In buildTemplateClassDeclaration_nfi(): nrscope = %p\n", nonreal_decl_scope);
13216#endif
13217#endif
13218 // DQ (9/10/2012): Initialize the template parameter list.
13219 ROSE_ASSERT(templateParameterList != NULL);
13220 nondefdecl->get_templateParameters() = *templateParameterList;
13221
13222 // DQ (9/16/2012): Newly refactored code.
13223 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
13224 testTemplateArgumentParents(nondefdecl);
13225
13226 // DQ (9/10/2012): Test the just built template with its template parameters.
13227 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
13228 if (nondefdecl->get_templateParameters().size() == 0)
13229 {
13230#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
13231 printf ("WARNING: In buildTemplateClassDeclaration_nfi(): nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
13232#endif
13233 }
13234 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
13235#if 0
13236 printf(" next 1\n");
13237#endif
13238
13239 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
13240 nondefdecl->set_templateName(nameWithoutTemplateArguments);
13241
13242 // DQ (12/26/2011): The non defining declaration should not have a valid pointer to the class definition.
13243 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
13244
13245 // The nondefining declaration will not appear in the source code, but is compiler
13246 // generated (so we have something about the class that we can reference; e.g in
13247 // types). At the moment we make it a transformation, there might be another kind
13248 // of source position that would be more precise. FIXME.
13250 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
13251
13252 nondefdecl->setForward();
13253
13254 // Liao, 9/2/2009. scope stack is optional, it can be empty
13255 nondefdecl->set_parent(scope);
13256 nondefdecl->set_scope(scope);
13257#if 0
13258 printf(" next 2\n");
13259#endif
13260
13261 if (nondefdecl->get_type() == NULL)
13262 {
13263 nondefdecl->set_type(SgClassType::createType(nondefdecl));
13264#if 0
13265 printf ("In SageBuilder::buildTemplateClassDeclaration_nfi(): built class type: part 1: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
13266#endif
13267 }
13268#if 0
13269 printf(" next 3\n");
13270#endif
13271
13272 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13273 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
13274
13275 // DQ (7/16/2017): Added code to set the template parameters in the just build declaration (if it is a template declaration).
13276 // We want to set the parents of the template paremters to the frst nondefining template class declaration, and we want to reset
13277 // the scope of the declarations associated with any previously marked SgClassType objects associated with any template parameters.
13278 // printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): Calling setTemplateParametersInDeclaration(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
13279
13280 setTemplateParametersInDeclaration(nondefdecl,templateParameterList);
13281
13282 // DQ (8/13/2013): Adding test of template parameter lists.
13283 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(nondefdecl);
13284 ROSE_ASSERT(templateClassDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateClassDeclaration->get_templateParameters().size()));
13285
13286 mysymbol = new SgTemplateClassSymbol(nondefdecl);
13287 scope->insert_symbol(nameWithTemplateSpecializationArguments, mysymbol);
13288#if 0
13289 printf(" end build non-defn decl\n");
13290#endif
13291 }
13292 } else {
13293 SgClassSymbol* mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
13294 if (mysymbol == NULL) {
13295 printf("WARNING: In buildTemplateClassDeclaration_nfi(): non-defining declaration was provided but cannot be located in the associated scope.\n");
13296 }
13297 }
13298
13299#if 0
13300 printf ("In buildTemplateClassDeclaration_nfi(): Setting the firstNondefiningDeclaration to be nondefdecl = %p \n",nondefdecl);
13301#endif
13302
13303 defdecl->set_firstNondefiningDeclaration(nondefdecl);
13304
13305 // DQ (9/16/2012): Setup the template specialization arguments on the defining declaration (tested below at base of function).
13306 setTemplateSpecializationArgumentsInDeclaration(defdecl,templateSpecializationArgumentList);
13307
13308#if 1
13309 // DQ (11/20/2011): SgTemplateClassDeclaration IR nodes don't have a SgType associated with them (template declarations don't have a type in C++, I think).
13310
13311 // Liao, 10/30/2009
13312 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
13313 // This is not desired when building a defining declaration and an inefficience in the constructor
13314 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
13315 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
13316 if (defdecl->get_type() != NULL)
13317 {
13318 // if a defining class declaration's type is associated with a defining class.
13319 // This is a wrong SgClassType and has to be reset
13320#if 0
13321 // if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
13322 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
13323 {
13324 delete defdecl->get_type();
13325 }
13326#else
13327 // DQ (1/13/2013): I am not clear what this means... if (defdecl->get_type() != NULL) then it makes
13328 // no sense to assert that (defdecl->get_type() == NULL). This is related to the reuse of the defining
13329 // declaration when it is available (instead of building a new one, which still might be required for a
13330 // template specialization (or template partial specialization)).
13331 // ROSE_ASSERT(defdecl->get_type() == NULL);
13332#endif
13333 }
13334
13335 // patch up the SgClassType for the defining class declaration
13336 ROSE_ASSERT (nondefdecl->get_type() != NULL);
13337 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
13338
13339 // DQ (1/22/2013): This assertion is a problem for boost code represented by ROSE compiling ROSE (see testRoseHeaders_01.C)
13340 if (isSgClassType(nondefdecl->get_type())->get_declaration() != isSgDeclarationStatement(nondefdecl))
13341 {
13342#if 0
13343 printf ("In buildTemplateClassDeclaration_nfi(): detected isSgClassType(nondefdecl->get_type())->get_declaration() != isSgDeclarationStatement(nondefdecl) (problem with Boost code in ROSE compiling ROSE) \n");
13344#endif
13345 }
13346 // ROSE_ASSERT (isSgClassType(nondefdecl->get_type())->get_declaration() == isSgDeclarationStatement(nondefdecl));
13347
13348 defdecl->set_type(nondefdecl->get_type());
13349
13350#if 0
13351 printf ("In SageBuilder::buildTemplateClassDeclaration_nfi(): built class type: part 2: defdecl->get_type() = %p = %s \n",defdecl->get_type(),defdecl->get_type()->class_name().c_str());
13352#endif
13353#endif
13354
13355 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
13356 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
13357 // used in a defining declaration).
13358 nondefdecl->setForward();
13359
13360#if 0
13361 if (scope != NULL) // put into fixStructDeclaration() or alike later on
13362 {
13363 // fixStructDeclaration(defdecl,scope);
13364 // fixStructDeclaration(nondefdecl,scope);
13365
13366 printf ("***** WARNING *****: Commented out call to fixStructDeclaration() \n");
13367 // ROSE_ASSERT(false);
13368 }
13369#endif
13370
13371 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
13372 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
13373
13374 ROSE_ASSERT(defdecl->get_scope() != NULL);
13375
13376 // DQ (12/4/2011): We need a concept for type for SgTemplateClassDeclaration so that we can construct SgMemberFunctionType nodes for template member functions.
13377 // We use a SgClassType which has been fixed to permit it to hold either a SgClassDeclaration or an SgTemplateClassDeclaration.
13378 ROSE_ASSERT(defdecl->get_type() != NULL);
13379
13380 // DQ (12/26/2011): The non defining declaration should not have a valid pointer to the class definition.
13381 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
13382
13383 // DQ (7/15/2012): We want to inforce this.
13384 // ROSE_ASSERT(defdecl->get_parent() == NULL);
13385 if (defdecl->get_parent() != NULL)
13386 {
13387#if PRINT_DEVELOPER_WARNINGS
13388 printf ("WARNING: the parent will have been set if the defining declaration was found and reused! defdecl = %p = %s \n",defdecl,defdecl->class_name().c_str());
13389#endif
13390 }
13391
13392 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13393 ROSE_ASSERT(defdecl->get_templateName().is_null() == false);
13394
13395 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13396 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
13397
13399 testTemplateArgumentParents(nondefdecl);
13400
13401#if 0
13402 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
13403 printf ("Leaving buildTemplateClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
13404 SgClassDeclaration* tmp_classDeclaration = defdecl;
13405 SgSymbol* test_symbol = defdecl->get_scope()->find_symbol_from_declaration(tmp_classDeclaration);
13406
13407 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
13408 printf ("Leaving buildTemplateClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
13409 ROSE_ASSERT(defdecl->get_symbol_from_symbol_table() != NULL);
13410#endif
13411
13412 return defdecl;
13413 }
13414
13416 {
13417 // DQ (1/11/2009): This function has semantics very different from the buildEnumDeclaration_nfi() function!
13418
13419 if (scope == NULL)
13421
13422 SgEnumDeclaration* decl = buildEnumDeclaration_nfi(name, scope);
13426
13427 // DQ (7/15/2012): We want to inforce this.
13428 ROSE_ASSERT(decl->get_parent() == NULL);
13429
13430 return decl;
13431 } //buildEnumDeclaration()
13432
13433
13436 {
13437 // The support for SgEnumDeclaration is identical to that for SgClassDeclaration (except for the type handling, why is that?).
13438 ASSERT_not_null(scope);
13439
13440 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
13441 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
13442 ASSERT_require(SageInterface::hasTemplateSyntax(name) == false);
13443
13444 SgEnumType* enumType = nullptr;
13445 SgEnumDeclaration* first_nondefdecl = nullptr;
13446
13447 if (scope)
13448 {
13449 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
13450 if (existing_symbol != NULL)
13451 {
13452 enumType = isSgEnumType(existing_symbol->get_type());
13453 first_nondefdecl = existing_symbol->get_declaration();
13454 ROSE_ASSERT(first_nondefdecl != NULL);
13455 }
13456 }
13457
13458 // DQ (5/8/2013): We do want to build a new SgEnumDeclaration (to avoid sharing).
13459 // This forces each call to buildNondefiningEnumDeclaration_nfi() to build a unique declaration
13460 // required to avoid sharing declaration in examples such as test2007_29.C.
13461 SgEnumDeclaration* nondefdecl = new SgEnumDeclaration(name, enumType);
13462
13463 ROSE_ASSERT(nondefdecl);
13464 setOneSourcePositionNull(nondefdecl);
13465
13466 // Set the defining and first non-defining declarations.
13467 if (first_nondefdecl)
13468 {
13469 nondefdecl->set_firstNondefiningDeclaration(first_nondefdecl);
13470 nondefdecl->set_definingDeclaration(first_nondefdecl->get_definingDeclaration());
13471 }
13472 else
13473 {
13474 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
13475 nondefdecl->set_definingDeclaration(nullptr);
13476 }
13477
13478 // Any non-defining declaration is not always a forward declaration.
13479 nondefdecl->setForward();
13480
13481 SgType* type = nondefdecl->get_type();
13482 ASSERT_not_null(type);
13483
13484 if (scope)
13485 {
13486 // Check for an existing symbol (reuse it if it is found).
13487 SgEnumSymbol* mysymbol = nullptr;
13488 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
13489
13490 if (existing_symbol)
13491 {
13492 mysymbol = existing_symbol;
13493 first_nondefdecl = mysymbol->get_declaration();
13494 }
13495 else
13496 {
13497 first_nondefdecl = nondefdecl;
13498
13499 mysymbol = new SgEnumSymbol(nondefdecl);
13500 ASSERT_not_null(mysymbol);
13501 scope->insert_symbol(name, mysymbol);
13502 }
13503
13504 nondefdecl->set_scope(scope);
13505
13506 // Can this be defined in C++ so that it is in a logical scope different from its structural scope?
13507 nondefdecl->set_parent(scope);
13508 }
13509
13510 if (first_nondefdecl != nondefdecl)
13511 {
13512 nondefdecl->set_firstNondefiningDeclaration(first_nondefdecl);
13513
13514 if (first_nondefdecl->get_definingDeclaration() != NULL)
13515 {
13516 nondefdecl->set_definingDeclaration(first_nondefdecl->get_definingDeclaration());
13517 }
13518 }
13519
13520 ASSERT_not_null(nondefdecl->get_type());
13521 ASSERT_not_null(scope->lookup_enum_symbol(name));
13522
13523 return nondefdecl;
13524 }
13525
13526
13529 {
13530 ROSE_ASSERT(scope != NULL);
13531
13532#if 0
13533 printf ("In buildEnumDeclaration_nfi(): name = %s scope = %p = %s \n",name.str(),scope,scope->class_name().c_str());
13534#endif
13535
13536 // DQ (5/8/2013): I think if we searched for the type it might exist and this would allow the types to be shared.
13537 SgEnumType* enumType = NULL;
13538
13539 if (scope != NULL)
13540 {
13541 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
13542 if (existing_symbol != NULL)
13543 {
13544 enumType = isSgEnumType(existing_symbol->get_type());
13545 }
13546 }
13547
13548#if 0
13549 printf ("In buildEnumDeclaration_nfi(): name = %s building using enumType = %p \n",name.str(),enumType);
13550#endif
13551
13552 // SgEnumDeclaration* defdecl = new SgEnumDeclaration (name,NULL);
13553 SgEnumDeclaration* defdecl = new SgEnumDeclaration (name,enumType);
13554 ROSE_ASSERT(defdecl);
13555
13556#if 0
13557 printf ("In buildEnumDeclaration_nfi(): built defining declaration = %p name = %s scope = %p = %s \n",defdecl,name.str(),scope,scope->class_name().c_str());
13558#endif
13559
13560 // DQ (5/8/2013): Make sure that the enum type is available.
13561 SgType* type = defdecl->get_type();
13562 ROSE_ASSERT(type != NULL);
13563
13564 setOneSourcePositionNull(defdecl);
13565 // constructor is side-effect free
13566 defdecl->set_definingDeclaration(defdecl);
13567
13568#if 0
13569 printf ("In buildEnumDeclaration_nfi(): name = %s \n",name.str());
13570#endif
13571
13572#if 1
13573 // DQ (4/3/2017): Check for an existing non-defining declaration before building one (to avoid multiple versions). See test2017_13.C.
13574 ROSE_ASSERT(scope != NULL);
13575 SgEnumSymbol* enumSymbol = scope->lookup_enum_symbol(name);
13576 // ROSE_ASSERT(enumSymbol != NULL);
13577 SgEnumDeclaration* nondefdecl = NULL;
13578 if (enumSymbol != NULL)
13579 {
13580 ROSE_ASSERT(enumSymbol->get_declaration() != NULL);
13581 nondefdecl = enumSymbol->get_declaration();
13582 ROSE_ASSERT(nondefdecl != NULL);
13583 }
13584 else
13585 {
13586 // build the nondefining declaration
13587 nondefdecl = buildNondefiningEnumDeclaration_nfi(name, scope);
13588#if 0
13589 printf ("###### In buildEnumDeclaration_nfi(): built a non-defining declaration to support the symbol table: name = %s nondefdecl = %p \n",name.str(),nondefdecl);
13590#endif
13591 }
13592#else
13593 // build the nondefining declaration
13594 SgEnumDeclaration* nondefdecl = buildNondefiningEnumDeclaration_nfi(name, scope);
13595#endif
13596
13597 nondefdecl->set_definingDeclaration(defdecl);
13598 // defdecl->set_firstNondefiningDeclaration(nondefdecl);
13600
13601 // DQ (4/22/2013): We need to set the defining declaration on the first non-defining declaration.
13602 if (nondefdecl->get_firstNondefiningDeclaration() != NULL && nondefdecl->get_firstNondefiningDeclaration() != nondefdecl)
13603 {
13605 }
13606
13607 // DQ (4/22/2013): Thing that should be true at this point.
13608 ROSE_ASSERT(nondefdecl->get_definingDeclaration() != NULL);
13609 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
13610 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration()->get_definingDeclaration() != NULL);
13611 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration()->get_firstNondefiningDeclaration() != NULL);
13612 ROSE_ASSERT(defdecl->get_definingDeclaration() != NULL);
13613 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
13614
13615 // DQ (1/11/2009): The buildNondefiningEnumDeclaration function builds an entry in the symbol table, and so we don't want a second one!
13616#if 0
13617 SgEnumSymbol* mysymbol = new SgEnumSymbol(nondefdecl);
13618 ROSE_ASSERT(mysymbol);
13619 // scope->print_symboltable("buildEnumDeclaration_nfi(): before inserting new SgEnumSymbol");
13620 scope->insert_symbol(name, mysymbol);
13621#endif
13622
13623 defdecl->set_scope(scope);
13624 nondefdecl->set_scope(scope);
13625
13626#if 0
13627 // DQ (7/12/2012): We can't set the parent here because if this is a non-autonomous declaration then it must be set later (to the outer declaration where this declaration is nested).
13628 defdecl->set_parent(scope);
13629 nondefdecl->set_parent(scope);
13630#endif
13631
13632 // DQ (7/12/2012): When this is an unnamed enum declaration, this it is NON-AUTONIMOUS
13633 // (and will have it's parent set in the associated variable or typedef declaration.
13634 // In the case of a class declaration this is always NULL (this should be similar).
13635 ROSE_ASSERT(defdecl->get_parent() == NULL);
13636
13637#if 0
13638 printf ("In buildEnumDeclaration_nfi(): name = %s defdecl = %p \n",name.str(),defdecl);
13639#endif
13640
13641 // DQ (5/8/2013): Check that the symbol is present.
13642 ROSE_ASSERT(scope->lookup_enum_symbol(name) != NULL);
13643
13644 return defdecl;
13645 } //buildEnumDeclaration_nfi()
13646
13647
13649SageBuilder::buildBaseClass ( SgClassDeclaration* classDeclaration, SgClassDefinition* classDefinition, bool isVirtual, bool isDirect )
13650 {
13651 // DQ (5/6/2013): Refactored the construction of the SgBaseClass support to the builder API.
13652
13653 // Note: classDeclaration should be the first non-defining class declaration, not required to be the the declaration associated with the SgClassDefinition.
13654 ROSE_ASSERT(classDeclaration != NULL);
13655 ROSE_ASSERT(classDefinition != NULL);
13656
13657 // DQ (5/6/2013): This is not always true (see test2013_63.C).
13658 // ROSE_ASSERT(classDeclaration == classDeclaration->get_firstNondefiningDeclaration());
13659
13660 ROSE_ASSERT(classDefinition->get_declaration() != NULL);
13661
13662 // DQ (5/6/2013): This is not always true (see test2004_30.C).
13663 // ROSE_ASSERT(classDefinition->get_declaration() == classDeclaration->get_firstNondefiningDeclaration());
13664
13665 SgBaseClass* baseclass = new SgBaseClass ( classDeclaration, isDirect );
13666 ROSE_ASSERT(baseclass != NULL);
13667
13668 if (isVirtual == true)
13669 {
13670 // DQ (1/21/2019): get_baseClassModifier() uses ROSETTA generated access functions which return a pointer.
13671 // baseclass->get_baseClassModifier().setVirtual();
13672 ROSE_ASSERT(baseclass->get_baseClassModifier() != NULL);
13673 baseclass->get_baseClassModifier()->setVirtual();
13674 }
13675
13676 // DQ (4/29/2004): add support to set access specifier
13677 // baseclass->get_baseClassModifier().get_accessModifier() = set_access_modifiers(bcdp->access);
13678 // baseclass->get_baseClassModifier().get_accessModifier() = buildAccessModifier(accessModifiers);
13679
13680 // DQ (6/21/2005): Set the parent of the base class to the class definition
13681 // (these are not traversed in ROSE currently, so their parents are not set).
13682 baseclass->set_parent(classDefinition);
13683
13684 // DQ (6/21/2005): Notice that this is copied by value (the base class list should be a list of pointers to SgBaseClass (later)
13685 classDefinition->append_inheritance(baseclass);
13686
13687 return baseclass;
13688 }
13689
13690
13692SageBuilder::buildNonrealBaseClass ( SgNonrealDecl* nrdecl, SgClassDefinition* classDefinition, bool isVirtual, bool isDirect )
13693 {
13694 ROSE_ASSERT(nrdecl != NULL);
13695 ROSE_ASSERT(classDefinition != NULL);
13696
13697 SgNonrealBaseClass * baseclass = new SgNonrealBaseClass ( NULL , isDirect , nrdecl );
13698 ROSE_ASSERT(baseclass != NULL);
13699
13700 if (isVirtual == true)
13701 {
13702 baseclass->get_baseClassModifier()->setVirtual();
13703 }
13704
13705 baseclass->set_parent(classDefinition);
13706
13707 classDefinition->append_inheritance(baseclass);
13708
13709 return baseclass;
13710 }
13711
13712
13713#if 0
13714// This function would be more complex that I want to support at present since the mapping of
13715// edg modifier values to ROSE modifier values is offset and backwards (reversed in numerical order).
13717SageBuilder::buildAccessModifier ( unsigned int access )
13718 {
13720
13721 switch (access)
13722 {
13723 case as_public:
13724#if 0
13725 printf ("In SageBuilder::set_access_modifiers(): Mark as public \n");
13726#endif
13727 a.setPublic();
13728 break;
13729
13730 case as_protected:
13731#if 0
13732 printf ("In SageBuilder::set_access_modifiers(): Mark as protected \n");
13733#endif
13734 a.setProtected();
13735 break;
13736
13737 case as_private:
13738#if 0
13739 printf ("In SageBuilder::set_access_modifiers(): Mark as private \n");
13740#endif
13741 a.setPrivate();
13742 break;
13743
13744 default:
13745 printf ("Error: default reached in SageBuilder::set_access_modifiers() \n");
13746 ROSE_ABORT ();
13747 }
13748
13749 return a;
13750 }
13751#endif
13752
13753
13754void
13755SageBuilder::fixupSourcePositionFileSpecification(SgNode* subtreeRoot, const std::string& newFileName)
13756 {
13757 // DQ (11/8/2019): This function changes the filename designation in all of the Sg_File_Info objects
13758 // associated with the designated AST subtree.
13759
13760 ROSE_ASSERT(subtreeRoot != NULL);
13761 ROSE_ASSERT(newFileName != "");
13762
13763#define DEBUG_FIXUP 0
13764
13765#if DEBUG_FIXUP
13766 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): newFileName = %s \n",newFileName.c_str());
13767 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13768#endif
13769
13770 class Traversal : public AstSimpleProcessing
13771 {
13772 public:
13773
13774 Traversal(const std::string& tmp_newFileName, int tmp_new_file_id, int tmp_originalFileId)
13775 {
13776 newFileName = tmp_newFileName;
13777 new_file_id = tmp_new_file_id;
13778 originalFileId = tmp_originalFileId;
13779#if DEBUG_FIXUP
13780 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): newFileName = %s new_file_id = %d originalFileId = %d \n",newFileName.c_str(),new_file_id,originalFileId);
13781#endif
13782 }
13783
13784 void visit (SgNode* node)
13785 {
13786#if DEBUG_FIXUP
13787 printf ("In fixupSourcePositionFileSpecification visit(): node = %p = %s \n",node,node->class_name().c_str());
13788#endif
13789
13790 SgLocatedNode* locatedNode = isSgLocatedNode(node);
13791 if (locatedNode != NULL)
13792 {
13793 // if (locatedNode->get_startOfConstruct()->get_file_id() == originalFileId)
13794 if (locatedNode->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13795 {
13796 ROSE_ASSERT(locatedNode->get_startOfConstruct() != NULL);
13797 ROSE_ASSERT(locatedNode->get_endOfConstruct() != NULL);
13798
13799 if (locatedNode->get_startOfConstruct()->isShared() == true)
13800 {
13801#if DEBUG_FIXUP
13802 printf ("Found SgLocatedNode marked as isShared() == true: locatedNode = %p = %s \n",locatedNode,locatedNode->class_name().c_str());
13803#endif
13804#if 0
13805 printf ("Exiting as a test! \n");
13806 ROSE_ABORT();
13807#endif
13808 }
13809 locatedNode->get_startOfConstruct()->set_file_id(new_file_id);
13810 locatedNode->get_endOfConstruct ()->set_file_id(new_file_id);
13811
13812 locatedNode->get_startOfConstruct()->set_physical_file_id(new_file_id);
13813 locatedNode->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13814
13815#if DEBUG_FIXUP
13816 printf ("locatedNode->get_startOfConstruct()->get_filename() = %s locatedNode->get_startOfConstruct()->get_physical_filename() = %s \n",
13817 locatedNode->get_startOfConstruct()->get_filenameString().c_str(),locatedNode->get_startOfConstruct()->get_physical_filename().c_str());
13818 printf ("locatedNode->get_startOfConstruct()->get_file_id() = %d locatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",
13819 locatedNode->get_startOfConstruct()->get_file_id(),locatedNode->get_startOfConstruct()->get_physical_file_id());
13820 printf ("locatedNode->get_startOfConstruct()->isShared() = %s \n",locatedNode->get_startOfConstruct()->isShared() ? "true" : "false");
13821#endif
13822 }
13823 else
13824 {
13825#if DEBUG_FIXUP
13826 printf ("NOT MATCHING: originalFileId = %d locatedNode->get_startOfConstruct()->get_file_id() = %d locatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",
13827 originalFileId,locatedNode->get_startOfConstruct()->get_file_id(),locatedNode->get_startOfConstruct()->get_physical_file_id());
13828 printf (" ------------ originalFileId = %d locatedNode->get_endOfConstruct()->get_file_id() = %d locatedNode->get_endOfConstruct()->get_physical_file_id() = %d \n",
13829 originalFileId,locatedNode->get_endOfConstruct()->get_file_id(),locatedNode->get_endOfConstruct()->get_physical_file_id());
13830#endif
13831 }
13832 }
13833 else
13834 {
13835 SgInitializedName* initializedName = isSgInitializedName(node);
13836 if (initializedName != NULL)
13837 {
13838 // if (initializedName->get_startOfConstruct()->get_file_id() == originalFileId)
13839 if (initializedName->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13840 {
13841 ROSE_ASSERT(initializedName->get_startOfConstruct() != NULL);
13842 ROSE_ASSERT(initializedName->get_endOfConstruct() != NULL);
13843
13844 initializedName->get_startOfConstruct()->set_file_id(new_file_id);
13845 initializedName->get_endOfConstruct ()->set_file_id(new_file_id);
13846
13847 initializedName->get_startOfConstruct()->set_physical_file_id(new_file_id);
13848 initializedName->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13849 }
13850 }
13851 else
13852 {
13853 SgSourceFile* sourceFile = isSgSourceFile(node);
13854 if (sourceFile != NULL)
13855 {
13856 ROSE_ASSERT(sourceFile->get_startOfConstruct() != NULL);
13857#if 0
13858 // A SgSourceFile has no endOfConstruct.
13859 if (sourceFile->get_endOfConstruct() == NULL)
13860 {
13861#if 0
13862 printf ("sourceFile->get_endOfConstruct() == NULL: fixup endOfConstruct \n");
13863#endif
13864 sourceFile->set_endOfConstruct(new Sg_File_Info());
13865 *(sourceFile->get_endOfConstruct()) = *(sourceFile->get_startOfConstruct());
13866 }
13867 ROSE_ASSERT(sourceFile->get_endOfConstruct() != NULL);
13868#endif
13869 // Need to test the physical_file_id because we already set the regular file_id (as part of seeding the process).
13870 // if (sourceFile->get_startOfConstruct()->get_file_id() == originalFileId)
13871 if (sourceFile->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13872 {
13873 sourceFile->get_startOfConstruct()->set_file_id(new_file_id);
13874 sourceFile->get_startOfConstruct()->set_physical_file_id(new_file_id);
13875#if DEBUG_FIXUP
13876 printf ("sourceFile->get_startOfConstruct()->get_file_id() = %d \n",sourceFile->get_startOfConstruct()->get_file_id());
13877 printf ("sourceFile->get_startOfConstruct()->get_physical_file_id() = %d \n",sourceFile->get_startOfConstruct()->get_physical_file_id());
13878#endif
13879 // sourceFile->get_endOfConstruct ()->set_file_id(new_file_id);
13880 // sourceFile->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13881 }
13882 }
13883 else
13884 {
13885#if DEBUG_FIXUP
13886 printf ("Unhandled: node = %p = %s \n",node,node->class_name().c_str());
13887#endif
13888 }
13889 }
13890 }
13891
13892 SgExpression* expression = isSgExpression(node);
13893 if (expression != NULL)
13894 {
13895 if (expression->get_operatorPosition()->get_physical_file_id() == originalFileId)
13896 {
13897 expression->get_operatorPosition()->set_file_id(new_file_id);
13898 expression->get_operatorPosition()->set_physical_file_id(new_file_id);
13899 }
13900 }
13901 }
13902
13903 // Data members.
13904 int new_file_id;
13905 int originalFileId;
13906 string newFileName;
13907 };
13908
13909
13910 SgFile* file = isSgFile(subtreeRoot);
13911 int new_file_id = -1;
13912 int originalFileId = -1;
13913
13914 if (file != NULL)
13915 {
13916 // We need to set the filename in at least one Sg_File_Info object so that we can have
13917 // the file_id be computed ans saved into the file_id to filename maps.
13918
13919 originalFileId = file->get_startOfConstruct()->get_file_id();
13920#if DEBUG_FIXUP
13921 printf ("originalFileId = %d \n",originalFileId);
13922#endif
13923 file->get_startOfConstruct()->set_filenameString(newFileName);
13924 new_file_id = Sg_File_Info::get_nametofileid_map()[newFileName];
13925
13926
13927#if 0
13928 file->get_endOfConstruct()->set_physical_file_id(new_file_id);
13929
13930 file->get_startOfConstruct()->set_physical_file_id(new_file_id);
13931 file->get_endOfConstruct()->set_physical_file_id(new_file_id);
13932
13933 // getFilenameFromID
13934 int new_file_id_2 = Sg_File_Info::getIDFromFilename(newFileName);
13935#if 0
13936 printf ("new_file_id = %d new_file_id_2 = %d \n",new_file_id,new_file_id_2);
13937#endif
13938 ROSE_ASSERT(new_file_id == new_file_id_2);
13939
13940 string new_filename_2 = Sg_File_Info::getFilenameFromID(new_file_id);
13941#if 0
13942 printf ("newFileName = %s new_filename_2 = %s \n",newFileName.c_str(),new_filename_2.c_str());
13943#endif
13944 ROSE_ASSERT(newFileName == new_filename_2);
13945#endif
13946
13947#if DEBUG_FIXUP
13948 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): file != NULL: newFileName = %s new_file_id = %d \n",newFileName.c_str(),new_file_id);
13949#endif
13950 }
13951 else
13952 {
13953 SgLocatedNode* subtreeLocatedNode = isSgLocatedNode(subtreeRoot);
13954 if (subtreeLocatedNode != NULL)
13955 {
13956#if DEBUG_FIXUP
13957 printf ("subtreeLocatedNode->get_startOfConstruct()->get_file_id() = %d \n",subtreeLocatedNode->get_startOfConstruct()->get_file_id());
13958 printf ("subtreeLocatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",subtreeLocatedNode->get_startOfConstruct()->get_physical_file_id());
13959#endif
13960 originalFileId = subtreeLocatedNode->get_startOfConstruct()->get_file_id();
13961 new_file_id = Sg_File_Info::getIDFromFilename(newFileName);
13962#if DEBUG_FIXUP
13963 printf ("originalFileId = %d \n",originalFileId);
13964 printf ("new_file_id = %d \n",new_file_id);
13965#endif
13966#if DEBUG_FIXUP
13967 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): subtreeLocatedNode = %s : originalFileId = %d newFileName = %s new_file_id = %d \n",
13968 subtreeLocatedNode->class_name().c_str(),originalFileId,newFileName.c_str(),new_file_id);
13969#endif
13970 }
13971 else
13972 {
13973 printf ("Error: In SageBuilder::fixupSourcePositionFileSpecification(): subtree should be a SgFile or SgLocatedNode: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13974 ROSE_ABORT();
13975 }
13976
13977#if 0
13978 printf ("Error: In SageBuilder::fixupSourcePositionFileSpecification(): subtree should be a SgFile: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13979 ROSE_ABORT();
13980#endif
13981 }
13982
13983 ROSE_ASSERT(new_file_id >= 0);
13984
13985 // Now build the traveral object and call the traversal (preorder) on the function definition.
13986 Traversal traversal (newFileName,new_file_id,originalFileId);
13987
13988 // traversal.traverse(subtreeRoot, preorder);
13989 // traversal.traverseInputFiles(subtreeRoot, preorder);
13990 // traversal.traverseWithinFile(subtreeRoot, preorder);
13991 traversal.traverse(subtreeRoot, preorder);
13992
13993#if 0
13994 printf ("Exiting as a test in SageBuilder::fixupSourcePositionFileSpecification() \n");
13995 ROSE_ABORT();
13996#endif
13997 }
13998
13999
14000
14001
14002
14003
14004
14005
14006void
14008 {
14009 // DQ (11/8/2019): This function changes the filename designation in all of the Sg_File_Info objects
14010 // associated with the designated AST subtree.
14011
14012 ROSE_ASSERT(subtreeRoot != NULL);
14013 ROSE_ASSERT(new_file_id >= 0);
14014
14015#if 0
14016 printf ("In SageBuilder::fixupSharingSourcePosition(): subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
14017 printf ("In SageBuilder::fixupSharingSourcePosition(): new_file_id = %d \n",new_file_id);
14018#endif
14019
14020 class Traversal : public AstSimpleProcessing
14021 {
14022 public:
14023
14024 Traversal(int tmp_new_file_id)
14025 {
14026 new_file_id = tmp_new_file_id;
14027#if 0
14028 printf ("In SageBuilder::fixupSharingSourcePosition(): new_file_id = %d \n",new_file_id);
14029#endif
14030 }
14031
14032 void visit (SgNode* node)
14033 {
14034#if 0
14035 printf ("In fixupSharingSourcePosition visit(): node = %p = %s new_file_id = %d \n",node,node->class_name().c_str(),new_file_id);
14036#endif
14037
14038 SgStatement* statement = isSgStatement(node);
14039 if (statement != NULL)
14040 {
14041 Sg_File_Info* startOfConstruct = statement->get_startOfConstruct();
14042 Sg_File_Info* endOfConstruct = statement->get_endOfConstruct();
14043#if 0
14044 printf ("new_file_id = %d startOfConstruct->get_physical_file_id() = %d \n",new_file_id,startOfConstruct->get_physical_file_id());
14045#endif
14046 // Only mark the files from the associated file (not statements in header files, for example).
14047 if (startOfConstruct->get_physical_file_id() == new_file_id)
14048 {
14049 // Mark this IR node as being shared
14050 startOfConstruct->setShared();
14051 endOfConstruct->setShared();
14052
14053 // Add this file_id to those file_id that will trigger this IR node to be unparsed.
14054#if 0
14055 printf (" --- adding entries for file_id and line number to support sharing: new_file_id = %d line = %d end line = %d \n",
14056 new_file_id,startOfConstruct->get_line(),endOfConstruct->get_line());
14057#endif
14058 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == startOfConstruct->get_fileLineNumbersToUnparse().size());
14059 ROSE_ASSERT(endOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
14060 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
14061
14062 // Add this existing_fi->get_file_id() to the list of file id's that will permit the assocated language construct to be unparsed.
14063 startOfConstruct->get_fileIDsToUnparse().push_back(new_file_id);
14064 startOfConstruct->get_fileLineNumbersToUnparse().push_back(startOfConstruct->get_line());
14065
14066 endOfConstruct->get_fileIDsToUnparse().push_back(new_file_id);
14067 endOfConstruct->get_fileLineNumbersToUnparse().push_back(endOfConstruct->get_line());
14068
14069 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == startOfConstruct->get_fileLineNumbersToUnparse().size());
14070 ROSE_ASSERT(endOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
14071 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
14072 }
14073 }
14074 else
14075 {
14076#if 0
14077 printf ("Unhandled: node = %p = %s \n",node,node->class_name().c_str());
14078#endif
14079 }
14080 }
14081
14082 // Data members.
14083 int new_file_id;
14084 };
14085
14086
14087 SgStatement* statement = isSgStatement(subtreeRoot);
14088 if (statement != NULL)
14089 {
14090#if 0
14091 printf ("statement->get_startOfConstruct()->get_file_id() = %d \n",statement->get_startOfConstruct()->get_file_id());
14092 printf ("statement->get_startOfConstruct()->get_physical_file_id() = %d \n",statement->get_startOfConstruct()->get_physical_file_id());
14093#endif
14094#if 0
14095 printf ("new_file_id = %d \n",new_file_id);
14096#endif
14097#if 0
14098 printf ("In SageBuilder::fixupSharingSourcePosition(): statement = %s : new_file_id = %d \n",statement->class_name().c_str(),new_file_id);
14099#endif
14100 }
14101 else
14102 {
14103 printf ("Error: In SageBuilder::fixupSharingSourcePosition(): subtree should be a SgFile or SgLocatedNode: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
14104 ROSE_ABORT();
14105 }
14106
14107 ROSE_ASSERT(new_file_id >= 0);
14108
14109 // Now buid the traveral object and call the traversal (preorder) on the function definition.
14110 Traversal traversal (new_file_id);
14111
14112 // traversal.traverse(subtreeRoot, preorder);
14113 // traversal.traverseInputFiles(subtreeRoot, preorder);
14114 // traversal.traverseWithinFile(subtreeRoot, preorder);
14115 traversal.traverse(subtreeRoot, preorder);
14116
14117#if 0
14118 printf ("Exiting as a test in SageBuilder::fixupSharingSourcePosition() \n");
14119 ROSE_ABORT();
14120#endif
14121 }
14122
14123
14124
14125
14126
14128SgFile*
14129SageBuilder::buildFile(const std::string& inputFileName, const std::string& outputFileName, SgProject* project/*=NULL*/, bool clear_globalScopeAcrossFiles /*=false*/)
14130 {
14131// Note that ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT defines a reduced set of ROSE to support front-end specific development.
14132// It is mostly used by quinlan to support laptop development where the smaller set of files permits one to do limited
14133// development work on a Mac (even with OSX's poor performance with large numbers of debug symbols). This is an
14134// infrequently used option.
14135#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
14136
14137#if 0
14138 printf ("In SageBuilder::buildFile(inputFileName = %s, outputFileName = %s, project = %p) \n",inputFileName.c_str(),outputFileName.c_str(),project);
14139 // printf (" --- fullname = %s \n",fullname.c_str());
14140#endif
14141
14142#if 0
14143 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14144 ROSE_ASSERT(project != NULL);
14145 std::set<SgLocatedNode*> tmp1_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14146
14147 if (tmp1_collectionOfModifiedLocatedNodes.size() > 0)
14148 {
14149 printf ("In Traversal::evaluateInheritedAttribute(): tmp1_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp1_collectionOfModifiedLocatedNodes.size());
14150#if 1
14151 printf ("Exiting as a test! \n");
14152 ROSE_ASSERT(false);
14153#endif
14154 }
14155#endif
14156
14157 ROSE_ASSERT(inputFileName.size() != 0); // empty file name is not allowed.
14158
14159 // DQ (9/18/2019): I am unclear what the use of fullname is below.
14160 // string sourceFilename = inputFileName, fullname;
14161 // string sourceFilename_fullname = inputFileName, fullname;
14162 string sourceFilename = inputFileName;
14163
14164#if 0
14165 // printf ("sourceFilename_fullname = %s \n",sourceFilename_fullname.c_str());
14166 printf ("sourceFilename = %s \n",sourceFilename.c_str());
14167#endif
14168
14169
14170 // DQ (11/5/2020): Experiment with clearing the global scope that is supporting multiple translation
14171 // units, since it is the cause of some problem when a tool is designed to read an input file twice.
14172 if (project != NULL)
14173 {
14174 SgGlobal* globalScopeAcrossFiles = project->get_globalScopeAcrossFiles();
14175 ROSE_ASSERT(globalScopeAcrossFiles != NULL);
14176
14177 ROSE_ASSERT(globalScopeAcrossFiles->get_symbol_table() != NULL);
14178 ROSE_ASSERT(globalScopeAcrossFiles->get_symbol_table()->get_table() != NULL);
14179
14180#if 0
14181 printf ("In SageBuilder::buildFile(): globalScopeAcrossFiles = %p \n",globalScopeAcrossFiles);
14182 printf (" --- globalScopeAcrossFiles->get_declarations().size() = %zu \n",globalScopeAcrossFiles->get_declarations().size());
14183 printf (" --- globalScopeAcrossFiles->get_symbol_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->size());
14184 printf (" --- globalScopeAcrossFiles->get_symbol_table()->get_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->get_table()->size());
14185#endif
14186#if 0
14187 printf ("Removing all elements from the globalScopeAcrossFiles->get_symbol_table() \n");
14188#endif
14189
14190 // DQ (11/5/2020): Clear the symbol table used to support multifile handling.
14191 // This breaks only one of the test codes in the codeSegregation tool, but it is a name
14192 // qualification that should likely be handled better so I think this is a good fix.
14193 if (clear_globalScopeAcrossFiles == true)
14194 {
14195 globalScopeAcrossFiles->get_symbol_table()->get_table()->delete_elements();
14196 }
14197
14198#if 0
14199 printf ("After removing all symbols (alias symbols): globalScopeAcrossFiles->get_symbol_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->size());
14200 printf ("After removing all symbols (alias symbols): globalScopeAcrossFiles->get_symbol_table()->get_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->get_table()->size());
14201#endif
14202 }
14203
14204 // DQ (9/18/2019): Test that the use of fullname has no effect.
14205 // ROSE_ASSERT(sourceFilename == sourceFilename_fullname);
14206
14207 Rose_STL_Container<std::string> arglist;
14208 int nextErrorCode = 0;
14209
14210#if 0
14211 bool set_header_file_unparsing_optimization = false;
14212#endif
14213
14214 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
14215 bool isCopyOfExistingFile_testForSharedNodes = false;
14216 SgFile* fileBeingCopied = NULL;
14217
14218 if (project == NULL)
14219 // SgProject is created on the fly
14220 // Make up an arglist in order to reuse the code inside SgFile::setupSourceFilename()
14221 {
14222#if 0
14223 printf ("In SageBuilder::buildFile(): build the SgProject \n");
14224#endif
14225 project = new SgProject();
14226 ROSE_ASSERT(project);
14227 project->get_fileList().clear();
14228
14229 arglist.push_back("cc");
14230 arglist.push_back("-c");
14231 project->set_originalCommandLineArgumentList (arglist);
14232 }
14233 else
14234 {
14235 // If project exists, then find the original source file if it exists and check the header file optimization setting for consistancy.
14236
14237 // DQ (9/18/2019): Adding debugging support to header file optimization support.
14238 SgFilePtrList & files = project->get_fileList();
14239 for (SgFilePtrList::iterator i = files.begin(); i != files.end(); i++)
14240 {
14241 SgFile* file = *i;
14242#if 0
14243 printf ("file = %p = %s name = %s \n",file,file->class_name().c_str(), file->getFileName().c_str());
14244
14245 printf ("file->get_header_file_unparsing_optimization() = %s \n",file->get_header_file_unparsing_optimization() ? "true" : "false");
14246 printf ("file->get_header_file_unparsing_optimization_source_file() = %s \n",file->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14247 printf ("file->get_header_file_unparsing_optimization_header_file() = %s \n",file->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14248#endif
14249 if (sourceFilename == file->getFileName())
14250 {
14251#if 0
14252 printf ("This is a copy of an existing file in the project: sourceFilename = %s \n",sourceFilename.c_str());
14253#endif
14254 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
14255 isCopyOfExistingFile_testForSharedNodes = true;
14256 fileBeingCopied = file;
14257
14258#if 0
14259 // DQ (4/24/2021): This data member header_file_unparsing_optimization is now static.
14260 // We are building a second copy of an originally specified file (so we need to set the optimization setting similarly).
14261 if (file->get_header_file_unparsing_optimization() == true)
14262 {
14263 set_header_file_unparsing_optimization = true;
14264 }
14265#endif
14266 }
14267 }
14268
14269#if 0
14270 printf ("Exiting as a test! \n");
14271 ROSE_ABORT();
14272#endif
14273 }
14274
14275 ifstream testfile(inputFileName.c_str());
14276 if (!testfile.is_open())
14277 {
14278 // create a temporary file if the file does not exist.
14279 // have to do this, otherwise StringUtility::getAbsolutePathFromRelativePath() complains
14280 // which is called by result->setupSourceFilename(arglist);
14281 testfile.close();
14282 ofstream outputfile(inputFileName.c_str(),ios::out);
14283 // DQ (2/6/2009): I think this comment is helpful to put into the file (helps explain why the file exists).
14284 outputfile<<"// Output file generated so that StringUtility::getAbsolutePathFromRelativePath() will see a vaild file ... unparsed file will have rose_ prefix "<<endl;
14285 outputfile.close();
14286 }
14287 else // file already exists , load and parse it
14288 {
14289 // should not reparse all files in case their ASTs have unsaved changes,
14290 // just parse the newly loaded file only.
14291 // use argv here, change non-existing input file later on
14292 // TODO add error code handling
14293
14294 // DQ (2/6/2009): Avoid closing this file twice (so put this here, instead of below).
14295 testfile.close();
14296 // should remove the old one here, Liao, 5/1/2009
14297 }
14298
14299 // DQ (2/6/2009): Avoid closing this file twice (moved to false branch above).
14300 // testfile.close();
14301
14302 // DQ (2/6/2009): Need to add the inputFileName to the source file list in the project,
14303 // because this list will be used to subtract off the source files as required to build
14304 // the commandline for the backend compiler.
14305 project->get_sourceFileNameList().push_back(inputFileName);
14306
14307 Rose_STL_Container<string> sourceFilenames = project->get_sourceFileNameList();
14308 // printf ("In SageBuilder::buildFile(): sourceFilenames.size() = %" PRIuPTR " sourceFilenames = %s \n",sourceFilenames.size(),StringUtility::listToString(sourceFilenames).c_str());
14309
14310 arglist = project->get_originalCommandLineArgumentList();
14311
14312 // DQ (2/6/2009): We will be compiling the source code generated in the
14313 // "rose_<inputFileName>" file, so we don't want this on the argument stack.
14314 // TV (09/19/2018): only add if not already present
14315 if (std::find(arglist.begin(), arglist.end(), sourceFilename) == arglist.end())
14316 {
14317 arglist.push_back(sourceFilename);
14318 }
14319
14320 // DQ (2/6/2009): Modified.
14321 // There is output file name specified for rose translators
14322 if (outputFileName.empty() == false)
14323 {
14324 arglist.push_back("-rose:o");
14325 // arglist.push_back("-o");
14326 arglist.push_back(outputFileName);
14327 }
14328
14329 // DQ (4/15/2010): Turn on verbose mode
14330 // arglist.push_back("-rose:verbose 2");
14331
14332 // This handles the case where the original command line may have referenced multiple files.
14333 Rose_STL_Container<string> fileList = CommandlineProcessing::generateSourceFilenames(arglist,/* binaryMode = */ false);
14334 CommandlineProcessing::removeAllFileNamesExcept(arglist,fileList,sourceFilename);
14335
14336 // DQ (9/3/2008): Added support for SgSourceFile IR node
14337 // SgFile* result = new SgFile (arglist, nextErrorCode, 0, project);
14338 // AS(10/04/08) Because of refactoring we require the determineFileType function to be called
14339 // to construct the node.
14340 // SgSourceFile* result = new SgSourceFile (arglist, nextErrorCode, 0, project);
14341 // SgSourceFile* result = isSgSourceFile(determineFileType(arglist, nextErrorCode, project));
14342 // TH (2009-07-15): changed to more generig isSgFile, this also supports SgBinaryComposite
14343 SgFile* result = determineFileType(arglist, nextErrorCode, project);
14344 ROSE_ASSERT(result != NULL);
14345
14346#if 0
14347 printf ("In SageBuilder::buildFile(): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",project,project->get_fileList_ptr()->get_listOfFiles().size());
14348#endif
14349
14350 SgSourceFile* sourceFile = isSgSourceFile(result);
14351 if (sourceFile != NULL)
14352 {
14353 SgGlobal* globalScope = sourceFile->get_globalScope();
14354 ROSE_ASSERT(globalScope != NULL);
14355
14356 // DQ (6/24/2021): We need to end this function with the isModified flag set to false. This is
14357 // important for the support of the token based unparsing when building a dynamic library.
14358 // This is important in permitting the simpleFrontierDetectionForTokenStreamMapping() function
14359 // to generate the correct settings for nodes in the second file constructed from the original file.
14360 if (globalScope->get_isModified() == true)
14361 {
14362#if 0
14363 printf ("In SageBuilder::buildFile(): globalScope->get_isModified() == true: reset to false \n");
14364#endif
14365 globalScope->set_isModified(false);
14366#if 0
14367 printf ("In SageBuilder::buildFile(): Verify false setting: globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
14368#endif
14369 }
14370 }
14371
14372#if 0
14373 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14374 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14375
14376 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14377 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14378#endif
14379
14380#if 0
14381 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14382 ROSE_ASSERT(project != NULL);
14383 std::set<SgLocatedNode*> tmp2_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14384
14385 if (tmp2_collectionOfModifiedLocatedNodes.size() > 0)
14386 {
14387 printf ("In Traversal::evaluateInheritedAttribute(): tmp2_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp2_collectionOfModifiedLocatedNodes.size());
14388#if 1
14389 printf ("Exiting as a test! \n");
14390 ROSE_ASSERT(false);
14391#endif
14392 }
14393#endif
14394
14395#if 0
14396 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14397 ROSE_ASSERT(project != NULL);
14398 std::set<SgLocatedNode*> tmp22_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(result);
14399
14400 if (tmp22_collectionOfModifiedLocatedNodes.size() > 0)
14401 {
14402 printf ("In Traversal::evaluateInheritedAttribute(): tmp22_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp22_collectionOfModifiedLocatedNodes.size());
14403#if 1
14404 printf ("Exiting as a test! \n");
14405 ROSE_ASSERT(false);
14406#endif
14407 }
14408#endif
14409
14410#if 0
14411 printf ("Calling outputFileIds() \n");
14412
14414
14415 printf ("DONE: Calling outputFileIds() \n");
14416#endif
14417
14418#if 0
14419 // DQ (9/18/2019): Adding debugging support.
14420 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization() = %s \n",
14421 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization() ? "true" : "false");
14422#endif
14423
14424#if 0
14425 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization_source_file() = %s \n",
14426 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14427 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization_header_file() = %s \n",
14428 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14429#endif
14430
14431 // DQ (9/18/2019): Adding debugging support.
14432 // ROSE_ASSERT(result->get_header_file_unparsing_optimization() == false);
14433 // ROSE_ASSERT(result->get_header_file_unparsing_optimization_source_file() == false);
14434 // ROSE_ASSERT(result->get_header_file_unparsing_optimization_header_file() == false);
14435
14436 // ROSE_ASSERT(result->get_header_file_unparsing_optimization() == true);
14437
14438#if 0
14439 // DQ (4/24/2021): This data member header_file_unparsing_optimization is now static (so we don't need this code).
14440 if (set_header_file_unparsing_optimization == true)
14441 {
14442 result->set_header_file_unparsing_optimization(true);
14443
14444 // DQ (9/18/2019): Also set the values for the source file and header files.
14445 // I think we only want to set the source file version to true and the header file version to false.
14446 // This is enforced in the attachPreprocessingInfo() function.
14447
14448 // DQ (4/24/2021): Debugging header file optimization.
14449 // result->set_header_file_unparsing_optimization_source_file(true);
14450
14451 // result->set_header_file_unparsing_optimization_header_file(true);
14452 result->set_header_file_unparsing_optimization_header_file(false);
14453
14454#if 0
14455 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization() = %s \n",
14456 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization() ? "true" : "false");
14457 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization_source_file() = %s \n",
14458 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14459 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization_header_file() = %s \n",
14460 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14461#endif
14462 }
14463#endif
14464
14465#if 0
14466 // DQ (3/4/2014): This fix is only for Java and for C will cause a second SgFile to be redundently added to the file list.
14467 // For now I will provide a temporary fix and check is this is for a Java project so that we can continue. But the longer
14468 // term fix would be to make the semantics for Java the same as that of C/C++ (or the other way around, whatever is the
14469 // cleaner semantics.
14470 // This just adds the new file to the list of files stored internally (note: this sets the parent of the newFile).
14471 // TOO1 (2/28/2014): This is definitely required for Java (ECJ frontend), though C passes without it (I think only
14472 // by luck :-).
14473 // The ECJ frontend uses the SgProject internally (via a global SgProject*). Therefore, the
14474 // SgProject must contain this newly created SgFile, otherwise ECJ won't be able to find it.
14475 // project->set_file ( *result );
14476 if (project->get_Java_only() == true)
14477 {
14478 // DQ (3/4/2014): For now we want to output a message and clean this up afterward (likely in the Java language support).
14479 printf ("WARNING: Java specific action to add new file to SgProject (using set_file()) (more uniform language handling symantics would avoid this problem) \n");
14480 project->set_file ( *result );
14481 }
14482#else
14483 // DQ (3/6/2014): The code below adresses the specific bug faced in the use of the outliner (so we use it directly).
14484 // This code was moved ahead of the call to "result->runFrontend(nextErrorCode);" because in the case of Java
14485 // the file must be set to be a part of the SgProject before calling the runFrontend() function.
14486 // project->set_file ( *result );
14487
14488 result->set_parent(project);
14489
14490#if 0
14491 printf ("In SageBuilder::buildFile(): Outliner::use_dlopen = %s \n",Outliner::use_dlopen ? "true" : "false");
14492#endif
14493
14494#if 0
14495 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14496 ROSE_ASSERT(project != NULL);
14497 std::set<SgLocatedNode*> tmp23_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(result);
14498
14499 if (tmp23_collectionOfModifiedLocatedNodes.size() > 0)
14500 {
14501 printf ("In Traversal::evaluateInheritedAttribute(): tmp23_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp23_collectionOfModifiedLocatedNodes.size());
14502#if 1
14503 printf ("Exiting as a test! \n");
14504 ROSE_ASSERT(false);
14505#endif
14506 }
14507#endif
14508
14509#if 0
14510 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14511 ROSE_ASSERT(project != NULL);
14512 std::set<SgLocatedNode*> tmp24_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14513
14514 if (tmp24_collectionOfModifiedLocatedNodes.size() > 0)
14515 {
14516 printf ("In Traversal::evaluateInheritedAttribute(): tmp24_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp24_collectionOfModifiedLocatedNodes.size());
14517#if 1
14518 printf ("Exiting as a test! \n");
14519 ROSE_ASSERT(false);
14520#endif
14521 }
14522#endif
14523
14524 // DQ (3/5/2014): I need to check with Liao to understand this part of the code better.
14525 // I think that the default value for Outliner::use_dlopen is false, so that when the
14526 // Java support is used the true branch is taken. However, if might be the we need
14527 // to support the outliner using the code below and so this would be a bug for the
14528 // outliner.
14529 if (!Outliner::use_dlopen)
14530 {
14531#if 0
14532 printf ("In SageBuilder::buildFile(): (after test for (!Outliner::use_dlopen) == true: project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14533 project,project->get_fileList_ptr()->get_listOfFiles().size());
14534#endif
14535 // DQ (3/5/2014): If we added the file above, then don't add it here since it is redundant.
14536 project->set_file(*result); // equal to push_back()
14537#if 0
14538 printf ("In SageBuilder::buildFile(): (after 2nd project->set_file()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14539 project,project->get_fileList_ptr()->get_listOfFiles().size());
14540#endif
14541 }
14542 else
14543 {
14544#if 0
14545 printf ("In SageBuilder::buildFile(): (after test for (!Outliner::use_dlopen) == false: project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14546 project,project->get_fileList_ptr()->get_listOfFiles().size());
14547#endif
14548
14549 // Liao, 5/1/2009,
14550 // if the original command line is: gcc -c -o my.o my.c and we want to
14551 // add a new file(mynew.c), the command line for the new file would become "gcc -c -o my.o mynew.c "
14552 // which overwrites the object file my.o from my.c and causes linking error.
14553 // To avoid this problem, I insert the file at the beginning and let the right object file to be the last generated one
14554 //
14555 // TODO This is not an elegant fix and it causes some strange assertion failure in addAssociatedNodes(): default case node
14556 // So we only turn this on if Outliner:: use_dlopen is used for now
14557 // The semantics of adding a new source file can cause changes to linking phase (new object files etc.)
14558 // But ROSE has a long-time bug in handling combined compiling and linking command like "translator -o a.out a.c b.c"
14559 // It will generated two command lines: "translator -o a.out a.c" and "translator -o a.out b.c", which are totally wrong.
14560 // This problem is very relevant to the bug.
14561 SgFilePtrList& flist = project->get_fileList();
14562 flist.insert(flist.begin(),result);
14563#if 0
14564 printf ("In SageBuilder::buildFile(): (after flist.insert(flist.begin(),result)): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14565 project,project->get_fileList_ptr()->get_listOfFiles().size());
14566#endif
14567 }
14568#endif
14569
14570#if 0
14571 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14572 ROSE_ASSERT(project != NULL);
14573 std::set<SgLocatedNode*> tmp25_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14574
14575 if (tmp25_collectionOfModifiedLocatedNodes.size() > 0)
14576 {
14577 printf ("In Traversal::evaluateInheritedAttribute(): tmp25_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp25_collectionOfModifiedLocatedNodes.size());
14578#if 1
14579 printf ("Exiting as a test! \n");
14580 ROSE_ASSERT(false);
14581#endif
14582 }
14583#endif
14584
14585 // DQ (6/3/2019): The case of outlining to a seperate file will have transformations
14586 // that this checking will fail on because it is for the typical case of checking the
14587 // AST for transformations after construction of the AST from an typical input file.
14588 EDG_ROSE_Translation::suppress_detection_of_transformations = true;
14589
14590#if 0
14591 printf ("In SageBuilder::buildFile(): EDG_ROSE_Translation::suppress_detection_of_transformations = %s \n",EDG_ROSE_Translation::suppress_detection_of_transformations ? "true" : "false");
14592#endif
14593
14594#if 0
14595 printf ("In SageBuilder::buildFile(): (after project->set_file()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",project,project->get_fileList_ptr()->get_listOfFiles().size());
14596#endif
14597
14598
14599 // DQ (6/5/2019): Record what is marked as isModified() and then reset these IR nodes to be isModified after the new file has been processed.
14600 // This is required because the modified IR nodes will be reset in this AST associated with the new file, and IR nodes that are common
14601 // across the two AST's will be reset (shared IR nodes, which are also not marked as shared). The solution is to compute the list of IR nodes
14602 // which are marked as isModified, and then build the new file (which will reset them for the new file's AST (plus any shared nodes visited in
14603 // the traversal) and then afterward reset the set of isModified IR nodes to isModified. By isolating the fix in this function we can eliminate
14604 // the complexity of it being seen from the outside (outside of this abstraction). Note that the function:
14605 // SageInterface::collectModifiedLocatedNodes() has previously been implemented and used for debugging.
14606 std::set<SgLocatedNode*> modifiedNodeSet = collectModifiedLocatedNodes(project);
14607
14608#if 0
14609 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14610 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14611
14612 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14613 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14614#endif
14615
14616#if 0
14617 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14618 ROSE_ASSERT(project != NULL);
14619 std::set<SgLocatedNode*> tmp251_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14620
14621 if (tmp251_collectionOfModifiedLocatedNodes.size() > 0)
14622 {
14623 printf ("In Traversal::evaluateInheritedAttribute(): tmp251_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp251_collectionOfModifiedLocatedNodes.size());
14624#if 1
14625 printf ("Exiting as a test! \n");
14626 ROSE_ASSERT(false);
14627#endif
14628 }
14629#endif
14630
14631 // DQ (3/6/2014): For Java, this function can only be called AFTER the SgFile has been added to the file list in the SgProject.
14632 // For C/C++ it does not appear to matter if the call is made before the SgFile has been added to the file list in the SgProject.
14633 // DQ (6/14/2013): Since we seperated the construction of the SgFile IR nodes from the invocation of the frontend, we have to call the frontend explicitly.
14634 result->runFrontend(nextErrorCode);
14635
14636#if 0
14637 printf ("In SageBuilder::buildFile(): (after result->runFrontend()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",project,project->get_fileList_ptr()->get_listOfFiles().size());
14638#endif
14639
14640#if 0
14641 printf ("After result->runFrontend(): calling outputFileIds() \n");
14642
14644
14645 printf ("DONE: After result->runFrontend(): calling outputFileIds() \n");
14646#endif
14647
14648#if 0
14649 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14650 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14651
14652 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14653 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14654#endif
14655
14656#if 0
14657 // DQ (6/24/2021): This can be expected to fail, because the new AST has been build and all of the
14658 // nodes are marked as isModified until rest in the AstPostProcessing() step (below).
14659 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14660 ROSE_ASSERT(project != NULL);
14661 std::set<SgLocatedNode*> tmp26_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14662
14663 if (tmp26_collectionOfModifiedLocatedNodes.size() > 0)
14664 {
14665 printf ("In Traversal::evaluateInheritedAttribute(): tmp26_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp26_collectionOfModifiedLocatedNodes.size());
14666#if 0
14667 printf ("Exiting as a test! \n");
14668 ROSE_ASSERT(false);
14669#endif
14670 }
14671#endif
14672
14673#if 0
14674 // Output an optional graph of the AST (just the tree, when active)
14675 printf ("Generating a dot file... (SgFile only) \n");
14676 generateDOT ( *project );
14677 // generateAstGraph(project, 2000);
14678#endif
14679
14680#if 0
14681 printf ("In SageBuilder::buildFile(): Generate the dot output for multiple files (ROSE AST) \n");
14682 // generateDOT ( *project );
14683 generateDOTforMultipleFile ( *project );
14684 printf ("DONE: Generate the dot output of the SAGE III AST \n");
14685#endif
14686
14687#if 0
14688 // DQ (7/18/2019): Output a graph of the AST for debugging.
14689 // Output an optional graph of the AST (the whole graph, of bounded complexity, when active)
14690 const int MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH = 8000;
14691 generateAstGraph(project,MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH);
14692#endif
14693
14694 // DQ (7/14/2019): I think we need to call the astPostProcessing at this point.
14695#if 0
14696 printf ("In SageBuilder::buildFile(): calling astPostProcessing() \n");
14697#endif
14698
14699 AstPostProcessing(result);
14700
14701#if 0
14702 printf ("In SageBuilder::buildFile(): DONE: calling astPostProcessing() \n");
14703#endif
14704
14705#if 0
14706 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14707 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14708
14709 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14710 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14711#endif
14712
14713#if 0
14714 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14715 ROSE_ASSERT(project != NULL);
14716 std::set<SgLocatedNode*> tmp265_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14717
14718 if (tmp265_collectionOfModifiedLocatedNodes.size() > 0)
14719 {
14720 printf ("In Traversal::evaluateInheritedAttribute(): tmp265_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp265_collectionOfModifiedLocatedNodes.size());
14721#if 1
14722 printf ("Exiting as a test! \n");
14723 ROSE_ASSERT(false);
14724#endif
14725 }
14726#endif
14727
14728#if 0
14729 result->display("SageBuilder::buildFile()");
14730#endif
14731
14732 ROSE_ASSERT(project != NULL);
14733 project->set_frontendErrorCode(max(project->get_frontendErrorCode(), nextErrorCode));
14734
14735 // Not sure why a warning shows up from astPostProcessing.C
14736 // SgNode::get_globalMangledNameMap().size() != 0 size = %" PRIuPTR " (clearing mangled name cache)
14737 if (result->get_globalMangledNameMap().size() != 0)
14738 {
14739 result->clearGlobalMangledNameMap();
14740 }
14741
14742 // DQ (6/5/2019): Use the previously constructed set (above) to reset the IR nodes to be marked as isModified.
14743 // std::set<SgLocatedNode*> modifiedNodeSet = collectModifiedLocatedNodes(project);
14744 // void resetModifiedLocatedNodes(const std::set<SgLocatedNode*> & modifiedNodeSet);
14745 resetModifiedLocatedNodes(modifiedNodeSet);
14746
14747#if 0
14748 printf ("Exiting as a test! \n");
14749 ROSE_ABORT();
14750#endif
14751
14752#if 0
14753 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14754 ROSE_ASSERT(project != NULL);
14755 std::set<SgLocatedNode*> tmp27_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14756
14757 if (tmp27_collectionOfModifiedLocatedNodes.size() > 0)
14758 {
14759 printf ("In Traversal::evaluateInheritedAttribute(): tmp27_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp27_collectionOfModifiedLocatedNodes.size());
14760#if 1
14761 printf ("Exiting as a test! \n");
14762 ROSE_ASSERT(false);
14763#endif
14764 }
14765#endif
14766
14767 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
14768 if (isCopyOfExistingFile_testForSharedNodes == true)
14769 {
14770 // Sharing of IR nodes happens in the AST when the same file is read twice.
14771 // Also in the case where two declarations in the global scope match in two different ASTs (typically in header files of different translation units).
14772
14773#if 0
14774 printf ("Found isCopyOfExistingFile_testForSharedNodes == true \n");
14775 printf ("fileBeingCopied = %p = %s \n",fileBeingCopied,fileBeingCopied->getFileName().c_str());
14776#endif
14777
14778 SgSourceFile* sourceFileBeingCopied = isSgSourceFile(fileBeingCopied);
14779 ROSE_ASSERT(sourceFileBeingCopied != NULL);
14780
14781 SgSourceFile* sourceResult = isSgSourceFile(result);
14782 ROSE_ASSERT(sourceResult != NULL);
14783
14784 SgGlobal* fileBeingCopied_globalScope = sourceFileBeingCopied->get_globalScope();
14785 SgGlobal* result_globalScope = sourceResult->get_globalScope();
14786#if 0
14787 printf ("fileBeingCopied_globalScope = %p \n",fileBeingCopied_globalScope);
14788 printf ("result_globalScope = %p \n",result_globalScope);
14789#endif
14790 ROSE_ASSERT(fileBeingCopied_globalScope != NULL);
14791 ROSE_ASSERT(result_globalScope != NULL);
14792
14793 SgDeclarationStatementPtrList fileBeingCopied_declarationList = fileBeingCopied_globalScope->get_declarations();
14794 SgDeclarationStatementPtrList result_declarationList = result_globalScope->get_declarations();
14795
14796#if 1
14797 // DQ (11/22/2019): Use set intersection to compute the list to make be shared (this is a better implementation).
14798 // This implementation is insensitive to transforamtions in the original AST for the file.
14799 vector<SgDeclarationStatement*>::iterator it;
14800 SgDeclarationStatementPtrList v(fileBeingCopied_declarationList.size());
14801
14802 // This is n log n in complexity, but likely OK.
14803 std::sort(fileBeingCopied_declarationList.begin(),fileBeingCopied_declarationList.end());
14804 std::sort(result_declarationList.begin(),result_declarationList.end());
14805
14806 // printf ("v.size() = %zu \n",v.size());
14807
14808 it = std::set_intersection(fileBeingCopied_declarationList.begin(),fileBeingCopied_declarationList.end(),result_declarationList.begin(),result_declarationList.end(),v.begin());
14809
14810 v.resize(it-v.begin());
14811
14812 int fileBeingCopied_file_id = fileBeingCopied->get_startOfConstruct()->get_physical_file_id();
14813
14814 // printf ("v.size() = %zu \n",v.size());
14815 for (size_t i = 0; i < v.size(); i++)
14816 {
14817 SgDeclarationStatement* intersection_element = v[i];
14818 // printf ("intersection_element = %p = %s \n",intersection_element,intersection_element->class_name().c_str());
14819#if 0
14820 printf (" --- SageBuilder::buildFile() is sharing this node: %p %s \n",intersection_element,intersection_element->class_name().c_str());
14821#endif
14822 // DQ (11/10/2019): Need to recursively mark this as shared so that the unparser will be able to test each line?
14823
14824 fixupSharingSourcePosition(intersection_element,fileBeingCopied_file_id);
14825#if 0
14826 printf ("Exiting as a test! \n");
14827 ROSE_ABORT();
14828#endif
14829 }
14830
14831#if 0
14832 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14833 ROSE_ASSERT(project != NULL);
14834 std::set<SgLocatedNode*> tmp28_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14835
14836 if (tmp28_collectionOfModifiedLocatedNodes.size() > 0)
14837 {
14838 printf ("In Traversal::evaluateInheritedAttribute(): tmp28_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp28_collectionOfModifiedLocatedNodes.size());
14839#if 1
14840 printf ("Exiting as a test! \n");
14841 ROSE_ASSERT(false);
14842#endif
14843 }
14844#endif
14845
14846#else
14847
14848#error "DEAD CODE!"
14849
14850 // This is the older implementation that is sensitive to transforamtions in the original AST from the file.
14851 // DQ (11/21/2019): Remove elements in the vector that are SgEmptyDeclarations which
14852 // are associated with some transformations (include header, for example).
14853 std::vector<SgDeclarationStatementPtrList::iterator> removeList;
14854 SgDeclarationStatementPtrList::iterator i = fileBeingCopied_declarationList.begin();
14855 while (i != fileBeingCopied_declarationList.end())
14856 {
14857 SgEmptyDeclaration* emptyDeclaration = isSgEmptyDeclaration(*i);
14858 if (emptyDeclaration != NULL)
14859 {
14860 removeList.push_back(i);
14861 }
14862
14863 i++;
14864 }
14865
14866#error "DEAD CODE!"
14867
14868 // Need seperate list to avoid iterator invalidation.
14869 // for (SgDeclarationStatementPtrList::iterator i = removeList.begin(); i != removeList.end(); i++)
14870 for (std::vector<SgDeclarationStatementPtrList::iterator>::iterator i = removeList.begin(); i != removeList.end(); i++)
14871 {
14872 fileBeingCopied_declarationList.erase(*i);
14873 }
14874
14875 // DQ (11/21/2019): These might be a different size if for example the file being
14876 // copied is being copied after some transformations to the AST from the original file.
14877 if (fileBeingCopied_declarationList.size() != result_declarationList.size())
14878 {
14879 printf ("fileBeingCopied_declarationList.size() = %zu \n",fileBeingCopied_declarationList.size());
14880 printf ("result_declarationList.size() = %zu \n",result_declarationList.size());
14881 }
14882 ROSE_ASSERT(fileBeingCopied_declarationList.size() == result_declarationList.size());
14883
14884#error "DEAD CODE!"
14885
14886#if 0
14887 printf ("Statements from global scope (size = %zu): \n",fileBeingCopied_declarationList.size());
14888#endif
14889 for (size_t i = 0; i < fileBeingCopied_declarationList.size(); i++)
14890 {
14891 SgDeclarationStatement* fileBeingCopied_decl = fileBeingCopied_declarationList[i];
14892 SgDeclarationStatement* result_decl = result_declarationList[i];
14893#if 0
14894 printf (" #%zu global scope entry: fileBeingCopied: %p %s result %p %s \n",i,fileBeingCopied_decl,fileBeingCopied_decl->class_name().c_str(),result_decl,result_decl->class_name().c_str());
14895#endif
14896 if (fileBeingCopied_decl == result_decl)
14897 {
14898#if 0
14899 printf (" --- SageBuilder::buildFile() is sharing this node: %p %s \n",fileBeingCopied_decl,fileBeingCopied_decl->class_name().c_str());
14900#endif
14901 // DQ (11/10/2019): Need to recursively mark this as shared so that the unparser will be able to test each line?
14902
14903#error "DEAD CODE!"
14904
14905 int fileBeingCopied_file_id = fileBeingCopied->get_startOfConstruct()->get_physical_file_id();
14906 fixupSharingSourcePosition(fileBeingCopied_decl,fileBeingCopied_file_id);
14907#if 0
14908 printf ("Exiting as a test! \n");
14909 ROSE_ABORT();
14910#endif
14911 }
14912 }
14913
14914#error "DEAD CODE!"
14915
14916#endif
14917
14918#if 0
14919 printf ("exiting as a test! \n");
14920 ROSE_ABORT();
14921#endif
14922 }
14923
14924#if 0
14925 reportModifiedStatements("Leaving SageBuilder::buildFile(): calling reportModifiedStatements()",project);
14926#endif
14927
14928#if 0
14929 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14930 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14931 printf ("Leaving SageBuilder::buildFile(): (after result->runFrontend()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14932 project,project->get_fileList_ptr()->get_listOfFiles().size());
14933 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14934 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14935#endif
14936
14937#if 0
14938 // DQ (11/8/2019): This is not working and breaks the current work at present.
14939 // DQ (11/8/2019): Support function to change the name in each of the IR node's source position info objects.
14940 fixupSourcePositionFileSpecification(result,outputFileName);
14941#endif
14942
14943 // DQ (7/2/2020): Added assertion (fails for snippet tests).
14944 ROSE_ASSERT(result->get_preprocessorDirectivesAndCommentsList() != NULL);
14945
14946#if 0
14947 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14948 ROSE_ASSERT(project != NULL);
14949 std::set<SgLocatedNode*> tmp3_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14950
14951 if (tmp3_collectionOfModifiedLocatedNodes.size() > 0)
14952 {
14953 printf ("In Traversal::evaluateInheritedAttribute(): tmp3_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp3_collectionOfModifiedLocatedNodes.size());
14954#if 1
14955 printf ("Exiting as a test! \n");
14956 ROSE_ASSERT(false);
14957#endif
14958 }
14959#endif
14960
14961 return result;
14962#else
14963
14964 // false branch of #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT (at top of function.
14965
14966 return NULL;
14967#endif
14968 }
14969
14970
14973SageBuilder::buildSourceFile(const std::string& outputFileName, SgProject* project, bool clear_globalScopeAcrossFiles /*=false*/)
14974 {
14975 // DQ (2/9/2013): Adding support to build a SgSourceFile with an empty global scope.
14976 // This function calls the buildFile(string,string,SgProject*) function and provides
14977 // a simple API where one wants to create a new SgSourceFile that will then have
14978 // statements added to it and then unparsed.
14979
14980 // This function needs a way to specify the associated language for the generated file.
14981 // Currently this is taken from the input file (generated from a prefix on the output filename.
14982
14983#if 1
14984 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
14985 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
14986 printf ("In SageBuilder::buildSourceFile(outputFileName = %s, project = %p) \n",outputFileName.c_str(),project);
14987 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
14988 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
14989#endif
14990
14991 // Call the supporting function to build a file.
14992 string inputFilePrefix = "temp_dummy_file_";
14993
14994#if 0
14995 printf ("In SageBuilder::buildSourceFile(const std::string& outputFileName, SgProject* project): calling buildFile() \n");
14996#endif
14997
14998 SgFile* file = buildFile(inputFilePrefix+outputFileName,outputFileName,project,clear_globalScopeAcrossFiles);
14999 ROSE_ASSERT(file != NULL);
15000
15001#if 0
15002 printf ("DONE: In SageBuilder::buildSourceFile(): calling buildFile() \n");
15003#endif
15004
15005 SgSourceFile* sourceFile = isSgSourceFile(file);
15006 ROSE_ASSERT(sourceFile != NULL);
15007
15008 ROSE_ASSERT(sourceFile->get_globalScope() != NULL);
15009
15010#if 0
15011 printf ("call the unparser on the just built file \n");
15012#endif
15013
15014#if 0
15015 printf ("Exiting as a test! \n");
15016 ROSE_ABORT();
15017#endif
15018
15019 return sourceFile;
15020
15021 }
15022
15023SgSourceFile* SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project, bool clear_globalScopeAcrossFiles /*=false*/)
15024 {
15025#if 0
15026 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
15027 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
15028 printf ("In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling buildFile() \n");
15029 // printf (" --- inputFileName = %s outputFileName = %s \n",inputFileName.c_str(),outputFileName.c_str());
15030 printf (" --- inputFileName = %s \n",inputFileName.c_str());
15031 printf (" --- outputFileName = %s \n",outputFileName.c_str());
15032 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
15033 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
15034#endif
15035
15036#if 0
15037 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
15038 ROSE_ASSERT(project != NULL);
15039 std::set<SgLocatedNode*> tmp1_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
15040
15041 if (tmp1_collectionOfModifiedLocatedNodes.size() > 0)
15042 {
15043 printf ("In Traversal::evaluateInheritedAttribute(): tmp1_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp1_collectionOfModifiedLocatedNodes.size());
15044#if 1
15045 printf ("Exiting as a test! \n");
15046 ROSE_ASSERT(false);
15047#endif
15048 }
15049#endif
15050
15051 SgFile* file = buildFile(inputFileName, outputFileName,project,clear_globalScopeAcrossFiles);
15052 ROSE_ASSERT(file != NULL);
15053
15054#if 0
15055 printf ("DONE: In SageBuilder::buildSourceFile(): calling buildFile() \n");
15056#endif
15057
15058#if 0
15059 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
15060 ROSE_ASSERT(project != NULL);
15061 std::set<SgLocatedNode*> tmp2_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
15062
15063 if (tmp2_collectionOfModifiedLocatedNodes.size() > 0)
15064 {
15065 printf ("In Traversal::evaluateInheritedAttribute(): tmp2_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp2_collectionOfModifiedLocatedNodes.size());
15066#if 1
15067 printf ("Exiting as a test! \n");
15068 ROSE_ASSERT(false);
15069#endif
15070 }
15071#endif
15072
15073 SgSourceFile* sourceFile = isSgSourceFile(file);
15074 ROSE_ASSERT(sourceFile != NULL);
15075
15076 ROSE_ASSERT(sourceFile->get_globalScope() != NULL);
15077
15078#if 0
15079 // DQ (9/18/2019): Adding support for debugging the header file optimization.
15080 printf ("Debugging the unparsing header file optimization \n");
15081
15082 printf ("sourceFile->get_header_file_unparsing_optimization() = %s \n",sourceFile->get_header_file_unparsing_optimization() ? "true" : "false");
15083 printf ("sourceFile->get_header_file_unparsing_optimization_source_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
15084 printf ("sourceFile->get_header_file_unparsing_optimization_header_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
15085#endif
15086
15087#if 0
15088 // ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == false);
15089
15090 // DQ (9/18/2019): These are now set to true when the inputFileName matches a previously read file for which the optimizaton was turned on.
15091 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization() == true);
15092 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_source_file() == true);
15093 // ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == true);
15094 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == false);
15095#endif
15096
15097 // DQ (9/18/2019): Adding support for the header file optimization.
15098 // Check is this file matches an existing file and if so avoid regathering the CPP directives and comments (if posible).
15099 // If the original file was specified as being optimized for unparsing header files, then make this one similarly.
15100 SgFilePtrList & fileList = project->get_fileList();
15101
15102#if 0
15103 printf ("Looking for file = %s \n",inputFileName.c_str());
15104#endif
15105
15106 for (SgFilePtrList::iterator i = fileList.begin(); i != fileList.end(); i++)
15107 {
15108 SgFile* temp_file = *i;
15109#if 0
15110 printf ("temp_file = %p = %s name = %s \n",temp_file,temp_file->class_name().c_str(),temp_file->getFileName().c_str());
15111#endif
15112 if (temp_file != file)
15113 {
15114 if (temp_file->getFileName() == file->getFileName())
15115 {
15116 // Then the temp_file is the original version of the file we are building for a second time
15117 // (usually as a part of the outlining to a seperate file). and we need to mark at least the
15118 // unparsing headr file optimizations to be the same across thje two file.
15119
15120 // DQ (6/12/2021): The header_file_unparsing_optimization is now a static data member and the
15121 // header_file_unparsing_optimization_source_file and header_file_unparsing_optimization_header_file
15122 // data members have been removed.
15123 // temp_file->set_header_file_unparsing_optimization(sourceFile->get_header_file_unparsing_optimization());
15124 // temp_file->set_header_file_unparsing_optimization_source_file(sourceFile->get_header_file_unparsing_optimization_source_file());
15125 // temp_file->set_header_file_unparsing_optimization_header_file(sourceFile->get_header_file_unparsing_optimization_header_file());
15126#if 0
15127 printf ("sourceFile = %p = %s \n",sourceFile,sourceFile->class_name().c_str());
15128 printf ("sourceFile->get_header_file_unparsing_optimization() = %s \n",sourceFile->get_header_file_unparsing_optimization() ? "true" : "false");
15129 printf ("sourceFile->get_header_file_unparsing_optimization_source_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
15130 printf ("sourceFile->get_header_file_unparsing_optimization_header_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
15131
15132 printf ("temp_file = %p = %s \n",temp_file,temp_file->class_name().c_str());
15133 printf ("temp_file->get_header_file_unparsing_optimization() = %s \n",temp_file->get_header_file_unparsing_optimization() ? "true" : "false");
15134 printf ("temp_file->get_header_file_unparsing_optimization_source_file() = %s \n",temp_file->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
15135 printf ("temp_file->get_header_file_unparsing_optimization_header_file() = %s \n",temp_file->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
15136#endif
15137 }
15138 else
15139 {
15140 // This is a different file.
15141 }
15142 }
15143 else
15144 {
15145 // This is the same file, already added to the SgProject file list (as it should be).
15146 }
15147 }
15148
15149
15150#if 0
15151 printf ("sourceFile->get_file_info()->get_filename() = %s \n",sourceFile->get_file_info()->get_filename());
15152 int filename_id = Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()];
15153 int filename_physical_id = Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()];
15154 printf ("Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()] = %d \n",filename_id);
15155 printf ("Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()] = %d \n",filename_physical_id);
15156 sourceFile->get_file_info()->set_physical_file_id(filename_physical_id);
15157
15158 printf ("sourceFile->get_file_info()->get_physical_filename() = %s \n",sourceFile->get_file_info()->get_physical_filename().c_str());
15159 printf ("sourceFile->get_file_info()->get_physical_file_id() = %d \n",sourceFile->get_file_info()->get_physical_file_id());
15160#endif
15161
15162#if 0
15163 printf ("Exiting as a test! \n");
15164 ROSE_ABORT();
15165#endif
15166
15167 // DQ (1/11/2021): I think we should be calling secondaryPassOverSourceFile() instead of attachPreprocessingInfo() because we need to support the token-based unparsing.
15168#if 0
15169
15170#error "DEAD CODE!"
15171
15172#if 1
15173 // DQ (11/4/2019): I need to add this when I went back to testing tool_G.
15174 // It is required in the functions to attach CPP directives and comments.
15175 if (sourceFile->get_preprocessorDirectivesAndCommentsList() == NULL)
15176 {
15177#if 1
15178 printf ("Initialize NULL p_preprocessorDirectivesAndCommentsList to empty ROSEAttributesListContainer \n");
15179#endif
15180 ROSEAttributesListContainer* tmp_preprocessorDirectivesAndCommentsList = new ROSEAttributesListContainer();
15181 sourceFile->set_preprocessorDirectivesAndCommentsList(tmp_preprocessorDirectivesAndCommentsList);
15182 }
15183 else
15184 {
15185#if 1
15186 printf ("NOTE: p_preprocessorDirectivesAndCommentsList is already defined! \n");
15187 printf (" --- inputFileName = %s \n",inputFileName.c_str());
15188 printf (" --- outputFileName = %s \n",outputFileName.c_str());
15189 printf (" --- sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size() = %zu \n",sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size());
15190#endif
15191 }
15192 ROSE_ASSERT (sourceFile->get_preprocessorDirectivesAndCommentsList() != NULL);
15193
15194#if 0
15195 // DQ (5/22/2020): If this is processing a previously processed file, then this
15196 // will cause comments and CPP directives to be collected twice. This happens
15197 // in the case where we build a copy of the source file to support construction
15198 // of a dynamic library.
15199 printf ("NOTE: SageBuilder::buildSourceFile(): If this is processing a previously processed source file then this will cause the source file comments and CPP directives to be collected redundently \n");
15200#endif
15201
15202 // DQ (11/4/2019): This is a test that is use in attaching CPP directives and comments to the AST.
15203 ROSEAttributesListContainerPtr filePreprocInfo = sourceFile->get_preprocessorDirectivesAndCommentsList();
15204 ROSE_ASSERT(filePreprocInfo != NULL);
15205#endif
15206
15207#error "DEAD CODE!"
15208
15209#if 0
15210 printf ("In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling attachPreprocessingInfo() \n");
15211 printf (" --- sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size() = %zu \n",sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size());
15212#endif
15213
15214#if 0
15215 // DQ (12/3/2020): This is the root of the problem, the comments are built for the outputFileName, but the comments are marked with the inputFileName.
15216 printf ("We read the comments in filename inputFileName, and build outputFileName, and this is a problem since the comments are marked with the inputFileName \n");
15217 printf (" --- inputFileName = %s \n",inputFileName.c_str());
15218 printf (" --- outputFileName = %s \n",outputFileName.c_str());
15219 printf ("sourceFile = %p \n",sourceFile);
15220 printf ("sourceFile->get_token_list.size() = %zu \n",sourceFile->get_token_list().size());
15221 printf ("sourceFile->get_tokenSubsequenceMap().size() = %zu \n",sourceFile->get_tokenSubsequenceMap().size());
15222#endif
15223
15224#error "DEAD CODE!"
15225
15226 // DQ (1/4/2020): Adding support to permit comments and CPP directives and token stream to be defined using the outputFileName.
15227 // Liao, 2019, 1/31: We often need the preprocessing info. (e.g. #include ..) attached to make the new file compilable.
15228 // attachPreprocessingInfo (sourceFile);
15229 attachPreprocessingInfo (sourceFile,outputFileName);
15230#else
15231 // DQ (1/11/2021): Call the secondaryPassOverSourceFile() instead of attachPreprocessingInfo() because we need to support the token-based unparsing.
15233#endif
15234
15235#if 0
15236 printf ("Exiting after test! processed first phase of collecting comments and CPP directives for source file) \n");
15237 ROSE_ASSERT(false);
15238#endif
15239
15240#if 0
15241 printf ("DONE: In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling attachPreprocessingInfo() \n");
15242#endif
15243
15244#if 0
15245 printf ("call the unparser on the just built file \n");
15246#endif
15247
15248#if 0
15249 printf ("In buildSourceFile(): AS A TEST: calling unparseFile(): filename = %s \n",sourceFile->getFileName().c_str());
15250 backend(project);
15251#endif
15252
15253#if 1
15254 // DQ (11/8/2019): This is not working and breaks the current work at present.
15255 // DQ (11/8/2019): Support function to change the name in each of the IR node's source position info objects.
15256 fixupSourcePositionFileSpecification(sourceFile,outputFileName);
15257#endif
15258
15259 // DQ (1/8/2021): Set the filename used in the generated SgSourceFile to be the output file.
15260 // This appears to be important so that we can get either key correct for the comments and CPP
15261 // directives and or the comments and CPP directives to be consistant as well as the token stream,
15262 // I think this might be less about the comments and CPP directives than the key for the token stream.
15263 // Either that or I need to have an extra field for the SgSourceFile name when it is read from one
15264 // file, but trying to be another file.
15265 // sourceFile->setFileName(outputFileName);
15266
15267#if 0
15268 printf ("In SageBuilder::buildSourceFile(): changing the name of the file represented in sourceFile: \n");
15269 printf ("inputFileName = %s \n",inputFileName.c_str());
15270 printf ("outputFileName = %s \n",outputFileName.c_str());
15271 printf ("sourceFile->getFileName() = %s \n",sourceFile->getFileName().c_str());
15272#endif
15273
15274 SgGlobal* globalScope = sourceFile->get_globalScope();
15275
15276#if 0
15277 printf ("Leaving SageBuilder::buildSourceFile() sourceFile = %p globalScope = %p \n",sourceFile,sourceFile->get_globalScope());
15278 printf ("sourceFile->get_file_info()->get_file_id() = %d \n",sourceFile->get_file_info()->get_file_id());
15279 printf ("sourceFile->get_file_info()->get_physical_file_id() = %d \n",sourceFile->get_file_info()->get_physical_file_id());
15280 printf ("sourceFile->get_token_list.size() = %zu \n",sourceFile->get_token_list().size());
15281 printf ("sourceFile->get_tokenSubsequenceMap().size() = %zu \n",sourceFile->get_tokenSubsequenceMap().size());
15282 printf ("inputFileName = %s \n",inputFileName.c_str());
15283 printf ("outputFileName = %s \n",outputFileName.c_str());
15284 printf ("sourceFile->getFileName() = %s \n",sourceFile->getFileName().c_str());
15285
15286 printf ("sourceFile->get_globalScope() = %p \n",globalScope);
15287 printf ("globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
15288#endif
15289
15290 // DQ (6/1/2021): We need to end this function with the isModified flag set to false. This is
15291 // important for the support of the token based unparsing when building a dynamic library.
15292 // This is important in permitting the simpleFrontierDetectionForTokenStreamMapping() function
15293 // to generate the correct settings for nodes in the second file constructed from the original file.
15294 if (globalScope->get_isModified() == true)
15295 {
15296#if 0
15297 printf ("globalScope->get_isModified() == true: reset to false \n");
15298#endif
15299 globalScope->set_isModified(false);
15300#if 0
15301 printf ("Verify false setting: globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
15302#endif
15303 }
15304
15305#if 0
15306 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
15307 ROSE_ASSERT(project != NULL);
15308 std::set<SgLocatedNode*> tmp3_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
15309
15310 if (tmp3_collectionOfModifiedLocatedNodes.size() > 0)
15311 {
15312 printf ("In Traversal::evaluateInheritedAttribute(): tmp3_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp3_collectionOfModifiedLocatedNodes.size());
15313#if 1
15314 printf ("Exiting as a test! \n");
15315 ROSE_ASSERT(false);
15316#endif
15317 }
15318#endif
15319
15320#if 0
15321 printf ("Exiting as a test! \n");
15322 ROSE_ABORT();
15323#endif
15324
15325 return sourceFile;
15326 }
15327
15328
15329PreprocessingInfo* SageBuilder::buildComment(SgLocatedNode* target, const std::string & content,PreprocessingInfo::RelativePositionType position/*=PreprocessingInfo::before*/,PreprocessingInfo::DirectiveType dtype/* = PreprocessingInfo::CpreprocessorUnknownDeclaration*/)
15330 {
15331 return SageInterface::attachComment(target,content, position, dtype);
15332 }
15333
15335PreprocessingInfo* SageBuilder::buildHeader(const std::string& header_filename,
15336 PreprocessingInfo::RelativePositionType position/*=PreprocessingInfo::before*/,
15337 bool isSystemHeader/* =false*/)
15338{
15339 std::string content;
15340 if (isSystemHeader)
15341 content = "#include <" + header_filename + "> \n";
15342 else
15343 content = "#include \"" + header_filename + "\" \n";
15344 PreprocessingInfo* result = new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration,
15345 content, "Transformation generated",0, 0, 0, position);
15346 ROSE_ASSERT(result);
15347
15348 result->get_file_info()->setTransformation();
15349 return result;
15350}
15351
15353PreprocessingInfo* SageBuilder::buildCpreprocessorDefineDeclaration(SgLocatedNode* target,const std::string & content,PreprocessingInfo::RelativePositionType position /* =PreprocessingInfo::before*/)
15354 {
15355 ROSE_ASSERT(target != NULL); //dangling #define xxx is not allowed in the ROSE AST
15356 // simple input verification
15357 std::string content2 = content;
15358 boost::algorithm::trim(content2);
15359 string prefix = "#define";
15360 string::size_type pos = content2.find(prefix, 0);
15361 ROSE_ASSERT (pos == 0);
15362
15363 PreprocessingInfo* result = NULL;
15364
15365 PreprocessingInfo::DirectiveType mytype = PreprocessingInfo::CpreprocessorDefineDeclaration;
15366
15367 // DQ (7/19/2008): Modified interface to PreprocessingInfo
15368 // result = new PreprocessingInfo (mytype,content, "transformation-generated", 0, 0, 0, position, false, true);
15369 result = new PreprocessingInfo (mytype,content, "transformation-generated", 0, 0, 0, position);
15370 ROSE_ASSERT(result);
15371 target->addToAttachedPreprocessingInfo(result);
15372 return result;
15373
15374 }
15375
15376
15377#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
15380{
15381 // avoid duplicated creation
15382 static std::map<SgNode*, AbstractHandle::abstract_handle *> handleMap;
15383
15384 ROSE_ASSERT(n != NULL);
15385 AbstractHandle::abstract_handle * ahandle =handleMap[n];
15386 if (ahandle==NULL)
15387 {
15389 ROSE_ASSERT(anode !=NULL );
15390 ahandle = new AbstractHandle::abstract_handle(anode);
15391 //TODO do we allow NULL handle to be returned?
15392 ROSE_ASSERT(ahandle != NULL);
15393 }
15394 return ahandle;
15395}
15396#endif
15397
15400{
15401 ROSE_ASSERT(exp1 != NULL);
15402 ROSE_ASSERT(exp2 != NULL);
15403
15404 SgExprListExp* tuple = buildExprListExp(exp1,exp2);
15405 SgExprListExp* setList = buildExprListExp(tuple);
15406 SgEquivalenceStatement* equivalenceStatement = new SgEquivalenceStatement();
15407 ROSE_ASSERT(equivalenceStatement->get_equivalence_set_list() == NULL);
15408 equivalenceStatement->set_equivalence_set_list(setList);
15409 ROSE_ASSERT(equivalenceStatement->get_equivalence_set_list() != NULL);
15410 equivalenceStatement->set_firstNondefiningDeclaration(equivalenceStatement);
15411 setOneSourcePositionForTransformation(equivalenceStatement);
15412 return equivalenceStatement;
15413}
15414
15415SgSymbol*
15417 {
15418 // Starting at the snippet_declaration, record the associated scope list to the global scope.
15419 // The do a reverse traversal on the list starting with the global scope of the target AST.
15420 // Lookup each declaration as we proceed deeper into the target AST to find the associated
15421 // symbol in the target AST (associated with the input declaration from the snippet AST).
15422
15423 SgSymbol* returnSymbol = NULL;
15424
15425 typedef Rose_STL_Container<SgScopeStatement*> SgScopeStatementPtrList;
15426 SgScopeStatementPtrList snippet_scope_list;
15427
15428 // Starting at the snippet_declaration, record the associated scope list to the global scope.
15429 // SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15430 SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15431#if 1
15432 printf ("First scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15433 SgClassDefinition* temp_classDefinition = isSgClassDefinition(snippet_scope);
15434 if (temp_classDefinition != NULL)
15435 {
15436 SgClassDeclaration* temp_classDeclaration = temp_classDefinition->get_declaration();
15437 SgName className = temp_classDeclaration->get_name();
15438#if 1
15439 printf ("Input snippet declaration's class name = %s \n",className.str());
15440#endif
15441 }
15442 SgNamespaceDefinitionStatement* namespaceDefinitionStatement = isSgNamespaceDefinitionStatement(snippet_scope);
15443 if (namespaceDefinitionStatement != NULL)
15444 {
15445
15446 }
15447#endif
15448 snippet_scope_list.push_back(snippet_scope);
15449 while (snippet_scope != NULL && isSgGlobal(snippet_scope) == NULL)
15450 {
15451 // The scopes between the snippet declaration and the global scope should be named scopes,
15452 // else we will not be able to identify the associated scope in the target AST.
15453 ROSE_ASSERT(snippet_scope->isNamedScope() == true);
15454
15455 snippet_scope = snippet_scope->get_scope();
15456#if 1
15457 printf ("snippet_scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15458#endif
15459 snippet_scope_list.push_back(snippet_scope);
15460 }
15461
15462#if 1
15463 printf ("snippet_scope_list.size() = %" PRIuPTR " \n",snippet_scope_list.size());
15464#endif
15465
15466 SgGlobal* global_scope_in_target_ast = TransformationSupport::getGlobalScope(targetScope);
15467 SgScopeStatementPtrList::reverse_iterator i = snippet_scope_list.rbegin();
15468
15469 SgScopeStatement* target_AST_scope = global_scope_in_target_ast;
15470 SgScopeStatement* snippet_AST_scope = *i;
15471
15472 ROSE_ASSERT(isSgGlobal(snippet_AST_scope) != NULL);
15473 // Iterate past the global scope
15474 i++;
15475
15476 // Traverse the snippet scopes in the reverse order from global scope to the associated scope in the target AST.
15477 while (i != snippet_scope_list.rend())
15478 {
15479 // This loop has to handle different types of names scopes (for C this only means structs, I think).
15480#if 1
15481 printf ("snippet_AST_scope list *i = %p = %s \n",*i,(*i)->class_name().c_str());
15482#endif
15483 // printf ("target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope ->class_name().c_str());
15484 // printf ("snippet_AST_scope = %p = %s \n",snippet_AST_scope,snippet_AST_scope ->class_name().c_str());
15485
15486 // DQ (12/5/2020): I think this should be a switch statement.
15487 SgClassDefinition* classDefinition = isSgClassDefinition(*i);
15488 if (classDefinition != NULL)
15489 {
15490 SgClassDeclaration* classDeclaration = classDefinition->get_declaration();
15491 SgName className = classDeclaration->get_name();
15492#if 1
15493 printf ("Found snippet class name = %s \n",className.str());
15494#endif
15495 SgClassSymbol* classSymbol = target_AST_scope->lookup_class_symbol(className);
15496 ROSE_ASSERT(classSymbol != NULL);
15497 ROSE_ASSERT(classSymbol->get_declaration() != NULL);
15498#if 1
15499 printf ("Associated symbol in taget AST: declaration = %p name = %s \n",classSymbol->get_declaration(),classSymbol->get_declaration()->get_name().str());
15500#endif
15501 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15502 returnSymbol = classSymbol;
15503
15504 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15505 target_AST_scope = classDefinition;
15506 }
15507
15508 // Not clear if we can have this case for C or C++.
15509 SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(*i);
15510 if (functionDefinition != NULL)
15511 {
15512 printf ("ERROR: Found an unusual case of SgFunctionDefinition in list of scopes holding a declaration for a type \n");
15513 ROSE_ABORT();
15514 }
15515
15516 SgNamespaceDefinitionStatement* namespaceDefinition = isSgNamespaceDefinitionStatement(*i);
15517 if (namespaceDefinition != NULL)
15518 {
15519 SgNamespaceDeclarationStatement* namespaceDeclaration = namespaceDefinition->get_namespaceDeclaration();
15520 SgName namespaceName = namespaceDeclaration->get_name();
15521#if 1
15522 printf ("Found snippet namespace name = %s \n",namespaceName.str());
15523#endif
15524 SgNamespaceSymbol* namespaceSymbol = target_AST_scope->lookup_namespace_symbol(namespaceName);
15525 ROSE_ASSERT(namespaceSymbol != NULL);
15526 ROSE_ASSERT(namespaceSymbol->get_declaration() != NULL);
15527#if 1
15528 printf ("Associated symbol in taget AST: declaration = %p name = %s \n",namespaceSymbol->get_declaration(),namespaceSymbol->get_declaration()->get_name().str());
15529#endif
15530 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15531 returnSymbol = namespaceSymbol;
15532
15533 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15534 target_AST_scope = namespaceDefinition;
15535 }
15536
15537 // Increment the reverse iterator.
15538 i++;
15539 }
15540
15541 // Handle the different cases using a switch (there are only a few cases).
15542 switch (snippet_declaration->variantT())
15543 {
15544 case V_SgClassDeclaration:
15545 {
15546 SgClassDeclaration* snippet_classDeclaration = isSgClassDeclaration(snippet_declaration);
15547 ROSE_ASSERT(snippet_classDeclaration != NULL);
15548
15549 SgName snippet_className = snippet_classDeclaration->get_name();
15550#if 0
15551 printf ("snippet snippet declaration's class name = %s \n",snippet_className.str());
15552#endif
15553 SgClassSymbol* target_symbol = target_AST_scope->lookup_class_symbol(snippet_className);
15554 ROSE_ASSERT(target_symbol != NULL);
15555 returnSymbol = target_symbol;
15556
15557 SgClassSymbol* classSymbolInTargetAST = isSgClassSymbol(returnSymbol);
15558 ROSE_ASSERT(classSymbolInTargetAST != NULL);
15559 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
15560 ROSE_ASSERT(target_classDeclaration != NULL);
15561#if 0
15562 printf ("snippet: classDeclaration = %p = %s \n",snippet_classDeclaration,snippet_classDeclaration->get_name().str());
15563 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
15564#endif
15565 ROSE_ASSERT(snippet_classDeclaration->get_name() == target_classDeclaration->get_name());
15566 break;
15567 }
15568
15569 case V_SgTypedefDeclaration:
15570 {
15571 SgTypedefDeclaration* snippet_typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
15572 ROSE_ASSERT(snippet_typedefDeclaration != NULL);
15573
15574 SgName snippet_typedefName = snippet_typedefDeclaration->get_name();
15575#if 0
15576 printf ("snippet snippet declaration's typedef name = %s \n",snippet_typedefName.str());
15577#endif
15578 SgTypedefSymbol* target_symbol = target_AST_scope->lookup_typedef_symbol(snippet_typedefName);
15579 ROSE_ASSERT(target_symbol != NULL);
15580 returnSymbol = target_symbol;
15581
15582 SgTypedefSymbol* typedefSymbolInTargetAST = isSgTypedefSymbol(returnSymbol);
15583 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15584 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
15585 ROSE_ASSERT(target_typedefDeclaration != NULL);
15586#if 0
15587 printf ("snippet: typedefDeclaration = %p = %s \n",snippet_typedefDeclaration,snippet_typedefDeclaration->get_name().str());
15588 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
15589#endif
15590 ROSE_ASSERT(snippet_typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
15591 break;
15592 }
15593
15594 case V_SgEnumDeclaration:
15595 {
15596 SgEnumDeclaration* snippet_enumDeclaration = isSgEnumDeclaration(snippet_declaration);
15597 ROSE_ASSERT(snippet_enumDeclaration != NULL);
15598
15599 SgName snippet_enumName = snippet_enumDeclaration->get_name();
15600#if 0
15601 printf ("snippet snippet declaration's enum name = %s \n",snippet_enumName.str());
15602#endif
15603 // DQ (4/13/2014): check if this is an un-named enum beclaration.
15604 bool isUnNamed = snippet_enumDeclaration->get_isUnNamed();
15605 if (isUnNamed == false)
15606 {
15607 // SgEnumSymbol* target_symbol = target_AST_scope->lookup_enum_symbol(snippet_enumName);
15608 SgEnumSymbol* target_symbol = lookupEnumSymbolInParentScopes(snippet_enumName,target_AST_scope);
15609 if (target_symbol == NULL)
15610 {
15611 // Debug this case.
15612 SgScopeStatement* scope = snippet_enumDeclaration->get_scope();
15613 printf ("scope = %p = %s \n",scope,scope->class_name().c_str());
15614 scope->get_file_info()->display("case V_SgEnumDeclaration: target_symbol == NULL: scope: debug");
15615 }
15616 ROSE_ASSERT(target_symbol != NULL);
15617 returnSymbol = target_symbol;
15618
15619 SgEnumSymbol* enumSymbolInTargetAST = isSgEnumSymbol(returnSymbol);
15620 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
15621 SgEnumDeclaration* target_enumDeclaration = isSgEnumDeclaration(enumSymbolInTargetAST->get_declaration());
15622 ROSE_ASSERT(target_enumDeclaration != NULL);
15623#if 0
15624 printf ("snippet: enumDeclaration = %p = %s \n",snippet_enumDeclaration,snippet_enumDeclaration->get_name().str());
15625 printf ("target: enumDeclaration = %p = %s \n",target_enumDeclaration,target_enumDeclaration->get_name().str());
15626#endif
15627 ROSE_ASSERT(snippet_enumDeclaration->get_name() == target_enumDeclaration->get_name());
15628 }
15629 else
15630 {
15631 // DQ (4/13/2014): I think we all agreed these would not have to be handled.
15632 printf ("Warning: can't handle unnamed enum declarations \n");
15633 ROSE_ASSERT(returnSymbol == NULL);
15634 }
15635 break;
15636 }
15637
15638 // DQ (12/5/2020): Adding support for codeSegregation tool.
15639 case V_SgMemberFunctionDeclaration:
15640 case V_SgFunctionDeclaration:
15641 {
15642 SgFunctionDeclaration* snippet_functionDeclaration = isSgFunctionDeclaration(snippet_declaration);
15643 ROSE_ASSERT(snippet_functionDeclaration != NULL);
15644#if 1
15645 printf ("snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15646#endif
15647 SgName snippet_functionName = snippet_functionDeclaration->get_name();
15648#if 1
15649 printf ("snippet snippet declaration's function name = %s \n",snippet_functionName.str());
15650 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope->class_name().c_str());
15651#endif
15652 SgFunctionSymbol* target_symbol = target_AST_scope->lookup_function_symbol(snippet_functionName);
15653 ROSE_ASSERT(target_symbol != NULL);
15654 returnSymbol = target_symbol;
15655
15656 SgFunctionSymbol* functionSymbolInTargetAST = isSgFunctionSymbol(returnSymbol);
15657 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
15658 SgFunctionDeclaration* target_functionDeclaration = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
15659 ROSE_ASSERT(target_functionDeclaration != NULL);
15660#if 1
15661 printf ("snippet: functionDeclaration = %p = %s \n",snippet_functionDeclaration,snippet_functionDeclaration->get_name().str());
15662 printf ("target: functionDeclaration = %p = %s \n",target_functionDeclaration,target_functionDeclaration->get_name().str());
15663#endif
15664 ROSE_ASSERT(snippet_functionDeclaration->get_name() == target_functionDeclaration->get_name());
15665 break;
15666 }
15667
15668 default:
15669 {
15670 printf ("Error: default reached in switch: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15671 ROSE_ABORT();
15672 }
15673 }
15674
15675 // return the last found symbol.
15676 return returnSymbol;
15677 }
15678
15679
15682 {
15683 // DQ (12/6/2020): This is a similar function to findAssociatedSymbolInTargetAST() but since
15684 // I need to modify it to support the requirements of the codeSegregation, it was useful to not
15685 // modify the existing findAssociatedSymbolInTargetAST() function too much so as to avoid
15686 // compromizing the snippet transformation support.
15687
15688#define DEBUG_FIND_ASSOCIATED_DECLARATION 0
15689
15690 SgSymbol* returnSymbol = NULL;
15691 SgDeclarationStatement* returnDeclaration = NULL;
15692
15693 bool isDefiningDeclaration = (snippet_declaration == snippet_declaration->get_definingDeclaration());
15694
15695#if DEBUG_FIND_ASSOCIATED_DECLARATION
15696 printf ("isDefiningDeclaration = %s \n",isDefiningDeclaration ? "true" : "false");
15697#endif
15698
15699 // DQ (12/7/2020): This should be true.
15700 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,targetScope) == false);
15701
15702 typedef Rose_STL_Container<SgScopeStatement*> SgScopeStatementPtrList;
15703 SgScopeStatementPtrList snippet_scope_list;
15704
15705 // Starting at the snippet_declaration, record the associated scope list to the global scope.
15706 // SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15707 SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15708#if DEBUG_FIND_ASSOCIATED_DECLARATION
15709 printf ("First scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15710 SgClassDefinition* temp_classDefinition = isSgClassDefinition(snippet_scope);
15711 if (temp_classDefinition != NULL)
15712 {
15713 SgClassDeclaration* temp_classDeclaration = temp_classDefinition->get_declaration();
15714 SgName className = temp_classDeclaration->get_name();
15715 printf ("Input declaration's class name = %s \n",className.str());
15716 }
15717
15718 SgNamespaceDefinitionStatement* namespaceDefinitionStatement = isSgNamespaceDefinitionStatement(snippet_scope);
15719 if (namespaceDefinitionStatement != NULL)
15720 {
15721 SgNamespaceDeclarationStatement* temp_namespaceDeclaration = namespaceDefinitionStatement->get_namespaceDeclaration();
15722 SgName namespaceName = temp_namespaceDeclaration->get_name();
15723 printf ("Input declaration's namespace name = %s \n",namespaceName.str());
15724 }
15725#endif
15726
15727 snippet_scope_list.push_back(snippet_scope);
15728 while (snippet_scope != NULL && isSgGlobal(snippet_scope) == NULL)
15729 {
15730 // The scopes between the snippet declaration and the global scope should be named scopes,
15731 // else we will not be able to identify the associated scope in the target AST.
15732 ROSE_ASSERT(snippet_scope->isNamedScope() == true);
15733
15734 snippet_scope = snippet_scope->get_scope();
15735
15736#if DEBUG_FIND_ASSOCIATED_DECLARATION
15737 printf ("snippet_scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15738#endif
15739 snippet_scope_list.push_back(snippet_scope);
15740
15741 // DQ (12/7/2020): At this point the scopes that we are traversing to the global scope should
15742 // have the same global scope as the input declaration.
15743 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_scope) == true);
15744 }
15745
15746#if DEBUG_FIND_ASSOCIATED_DECLARATION
15747 printf ("snippet_scope_list.size() = %" PRIuPTR " \n",snippet_scope_list.size());
15748 for (SgScopeStatementPtrList::iterator i = snippet_scope_list.begin(); i != snippet_scope_list.end(); i++)
15749 {
15750 SgScopeStatement* scope = *i;
15751 printf (" --- *i = %p = %s name = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
15752 SgGlobal* global_scope_from_declarations_scope = TransformationSupport::getGlobalScope(scope);
15753 printf (" --- --- global_scope_from_declarations_scope = %p \n",global_scope_from_declarations_scope);
15754 }
15755#endif
15756
15757 // DQ (12/7/2020): At this point the scopes that we are traversing to the global scope should
15758 // have the same global scope as the input declaration.
15759 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_scope) == true);
15760
15761 SgGlobal* global_scope_in_target_ast = TransformationSupport::getGlobalScope(targetScope);
15762 SgScopeStatementPtrList::reverse_iterator i = snippet_scope_list.rbegin();
15763
15764#if DEBUG_FIND_ASSOCIATED_DECLARATION
15765 printf ("global_scope_in_target_ast = %p = %s \n",global_scope_in_target_ast,global_scope_in_target_ast->class_name().c_str());
15766#endif
15767
15768 SgScopeStatement* target_AST_scope = global_scope_in_target_ast;
15769 SgScopeStatement* snippet_AST_scope = *i;
15770
15771 // DQ (12/7/2020): This should be true.
15772 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_AST_scope) == true);
15773
15774 ROSE_ASSERT(isSgGlobal(snippet_AST_scope) != NULL);
15775 // Iterate past the global scope
15776 i++;
15777
15778#if DEBUG_FIND_ASSOCIATED_DECLARATION
15779 string otherASTnameFromGlobalScope = global_scope_in_target_ast->get_file_info()->get_filenameString();
15780 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(targetScope,true);
15781 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15782 printf ("Now traverse the list of scopes in reverse to find the declaration in the other AST: \n");
15783 printf ("otherASTnameFromGlobalScope = %s \n",otherASTnameFromGlobalScope.c_str());
15784 printf ("otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15785#endif
15786
15787 // DQ (12/7/2020): This should be true.
15788 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15789
15790 // Traverse the snippet scopes in the reverse order from global scope to the associated scope in the target AST.
15791 while (i != snippet_scope_list.rend())
15792 {
15793 // This loop has to handle different types of names scopes (for C this only means structs, I think).
15794
15795 SgScopeStatement* scope = *i;
15796
15797#if DEBUG_FIND_ASSOCIATED_DECLARATION
15798 printf ("snippet_AST_scope list *i = %p = %s \n",*i,(*i)->class_name().c_str());
15799 printf (" --- *i = %p = %s name = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
15800 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope ->class_name().c_str());
15801 // printf ("snippet_AST_scope = %p = %s \n",snippet_AST_scope,snippet_AST_scope ->class_name().c_str());
15802#endif
15803
15804 // DQ (12/7/2020): This should still be true.
15805 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,scope) == true);
15806
15807#if DEBUG_FIND_ASSOCIATED_DECLARATION
15808 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(targetScope,true);
15809 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15810 printf (" --- otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15811#endif
15812
15813 // DQ (12/5/2020): I think this should be a switch statement.
15814 SgClassDefinition* classDefinition = isSgClassDefinition(*i);
15815 if (classDefinition != NULL)
15816 {
15817 SgClassDeclaration* classDeclaration = classDefinition->get_declaration();
15818 SgName className = classDeclaration->get_name();
15819#if DEBUG_FIND_ASSOCIATED_DECLARATION
15820 printf (" --- Found snippet class name = %s \n",className.str());
15821#endif
15822 SgClassSymbol* classSymbol = target_AST_scope->lookup_class_symbol(className);
15823 ROSE_ASSERT(classSymbol != NULL);
15824 ROSE_ASSERT(classSymbol->get_declaration() != NULL);
15825#if DEBUG_FIND_ASSOCIATED_DECLARATION
15826 printf (" --- Associated symbol in taget AST: declaration = %p name = %s \n",classSymbol->get_declaration(),classSymbol->get_declaration()->get_name().str());
15827#endif
15828 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15829 returnSymbol = classSymbol;
15830
15831 // DQ (12/8/2020): Need to get the associated class definition from the symbol in the target scope.
15832 SgClassDeclaration* temp_classDeclaration_in_target_ast = classSymbol->get_declaration();
15833 ROSE_ASSERT(temp_classDeclaration_in_target_ast != NULL);
15834 SgClassDeclaration* classDeclaration_in_target_ast = isSgClassDeclaration(temp_classDeclaration_in_target_ast->get_definingDeclaration());
15835 ROSE_ASSERT(classDeclaration_in_target_ast != NULL);
15836 SgClassDefinition* classDefinition_in_target_ast = classDeclaration_in_target_ast->get_definition();
15837 ROSE_ASSERT(classDefinition_in_target_ast != NULL);
15838
15839 // DQ (12/7/2020): This should be true.
15840 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15841
15842 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15843 // target_AST_scope = classDefinition;
15844 target_AST_scope = classDefinition_in_target_ast;
15845
15846 // DQ (12/7/2020): This should be true.
15847 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15848 }
15849
15850 // Not clear if we can have this case for C or C++.
15851 SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(*i);
15852 if (functionDefinition != NULL)
15853 {
15854 printf ("ERROR: Found an unusual case of SgFunctionDefinition in list of scopes holding a declaration for a type \n");
15855 ROSE_ABORT();
15856 }
15857
15858 SgNamespaceDefinitionStatement* namespaceDefinition = isSgNamespaceDefinitionStatement(*i);
15859 if (namespaceDefinition != NULL)
15860 {
15861 SgNamespaceDeclarationStatement* namespaceDeclaration = namespaceDefinition->get_namespaceDeclaration();
15862 SgName namespaceName = namespaceDeclaration->get_name();
15863#if DEBUG_FIND_ASSOCIATED_DECLARATION
15864 printf (" --- Found snippet namespace name = %s \n",namespaceName.str());
15865#endif
15866 SgNamespaceSymbol* namespaceSymbol = target_AST_scope->lookup_namespace_symbol(namespaceName);
15867 ROSE_ASSERT(namespaceSymbol != NULL);
15868 ROSE_ASSERT(namespaceSymbol->get_declaration() != NULL);
15869 SgNamespaceDeclarationStatement* otherASTnamespaceDeclaration = namespaceSymbol->get_declaration();
15870#if DEBUG_FIND_ASSOCIATED_DECLARATION
15871 printf (" --- Associated symbol in taget AST: declaration = %p name = %s \n",namespaceSymbol->get_declaration(),namespaceSymbol->get_declaration()->get_name().str());
15872#endif
15873 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15874 returnSymbol = namespaceSymbol;
15875
15876 // DQ (12/7/2020): This should be true.
15877 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15878
15879 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15880 // target_AST_scope = namespaceDefinition;
15881 target_AST_scope = otherASTnamespaceDeclaration->get_definition();
15882
15883 // DQ (12/7/2020): This should be true.
15884 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15885 }
15886
15887 // DQ (12/7/2020): This should be true.
15888 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15889
15890#if DEBUG_FIND_ASSOCIATED_DECLARATION
15891 printf (" --- At base of loop of the list of scopes in top to bottom: target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope->class_name().c_str());
15892
15893 {
15894 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(target_AST_scope,true);
15895 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15896 printf (" --- At base of loop: otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15897 }
15898#endif
15899 // Increment the reverse iterator.
15900 i++;
15901 }
15902
15903#if DEBUG_FIND_ASSOCIATED_DECLARATION
15904 printf ("##### Now based on the kind of declaration, search for that same named declaration in the target_AST_scope = %p = %s \n",
15905 target_AST_scope,target_AST_scope->class_name().c_str());
15906#endif
15907
15908 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15909
15910 // Handle the different cases using a switch (there are only a few cases).
15911 switch (snippet_declaration->variantT())
15912 {
15913 case V_SgClassDeclaration:
15914 {
15915 SgClassDeclaration* snippet_classDeclaration = isSgClassDeclaration(snippet_declaration);
15916 ROSE_ASSERT(snippet_classDeclaration != NULL);
15917
15918 SgName snippet_className = snippet_classDeclaration->get_name();
15919
15920#if DEBUG_FIND_ASSOCIATED_DECLARATION
15921 printf ("snippet snippet declaration's class name = %s \n",snippet_className.str());
15922#endif
15923 SgClassSymbol* target_symbol = target_AST_scope->lookup_class_symbol(snippet_className);
15924 ROSE_ASSERT(target_symbol != NULL);
15925 returnSymbol = target_symbol;
15926
15927 SgClassSymbol* classSymbolInTargetAST = isSgClassSymbol(returnSymbol);
15928 ROSE_ASSERT(classSymbolInTargetAST != NULL);
15929 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
15930 ROSE_ASSERT(target_classDeclaration != NULL);
15931
15932#if DEBUG_FIND_ASSOCIATED_DECLARATION
15933 printf ("snippet: classDeclaration = %p = %s \n",snippet_classDeclaration,snippet_classDeclaration->get_name().str());
15934 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
15935#endif
15936 ROSE_ASSERT(snippet_classDeclaration->get_name() == target_classDeclaration->get_name());
15937 break;
15938 }
15939
15940 case V_SgTypedefDeclaration:
15941 {
15942 SgTypedefDeclaration* snippet_typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
15943 ROSE_ASSERT(snippet_typedefDeclaration != NULL);
15944
15945 SgName snippet_typedefName = snippet_typedefDeclaration->get_name();
15946
15947#if DEBUG_FIND_ASSOCIATED_DECLARATION
15948 printf ("snippet snippet declaration's typedef name = %s \n",snippet_typedefName.str());
15949#endif
15950 SgTypedefSymbol* target_symbol = target_AST_scope->lookup_typedef_symbol(snippet_typedefName);
15951 ROSE_ASSERT(target_symbol != NULL);
15952 returnSymbol = target_symbol;
15953
15954 SgTypedefSymbol* typedefSymbolInTargetAST = isSgTypedefSymbol(returnSymbol);
15955 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15956 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
15957 ROSE_ASSERT(target_typedefDeclaration != NULL);
15958
15959#if DEBUG_FIND_ASSOCIATED_DECLARATION
15960 printf ("snippet: typedefDeclaration = %p = %s \n",snippet_typedefDeclaration,snippet_typedefDeclaration->get_name().str());
15961 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
15962#endif
15963 ROSE_ASSERT(snippet_typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
15964 break;
15965 }
15966
15967 case V_SgEnumDeclaration:
15968 {
15969 SgEnumDeclaration* snippet_enumDeclaration = isSgEnumDeclaration(snippet_declaration);
15970 ROSE_ASSERT(snippet_enumDeclaration != NULL);
15971
15972 SgName snippet_enumName = snippet_enumDeclaration->get_name();
15973
15974#if DEBUG_FIND_ASSOCIATED_DECLARATION
15975 printf ("snippet snippet declaration's enum name = %s \n",snippet_enumName.str());
15976#endif
15977 // DQ (4/13/2014): check if this is an un-named enum beclaration.
15978 bool isUnNamed = snippet_enumDeclaration->get_isUnNamed();
15979 if (isUnNamed == false)
15980 {
15981 // SgEnumSymbol* target_symbol = target_AST_scope->lookup_enum_symbol(snippet_enumName);
15982 SgEnumSymbol* target_symbol = lookupEnumSymbolInParentScopes(snippet_enumName,target_AST_scope);
15983 if (target_symbol == NULL)
15984 {
15985 // Debug this case.
15986 SgScopeStatement* scope = snippet_enumDeclaration->get_scope();
15987 printf ("scope = %p = %s \n",scope,scope->class_name().c_str());
15988 scope->get_file_info()->display("case V_SgEnumDeclaration: target_symbol == NULL: scope: debug");
15989 }
15990 ROSE_ASSERT(target_symbol != NULL);
15991 returnSymbol = target_symbol;
15992
15993 SgEnumSymbol* enumSymbolInTargetAST = isSgEnumSymbol(returnSymbol);
15994 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
15995 SgEnumDeclaration* target_enumDeclaration = isSgEnumDeclaration(enumSymbolInTargetAST->get_declaration());
15996 ROSE_ASSERT(target_enumDeclaration != NULL);
15997
15998#if DEBUG_FIND_ASSOCIATED_DECLARATION
15999 printf ("snippet: enumDeclaration = %p = %s \n",snippet_enumDeclaration,snippet_enumDeclaration->get_name().str());
16000 printf ("target: enumDeclaration = %p = %s \n",target_enumDeclaration,target_enumDeclaration->get_name().str());
16001#endif
16002 ROSE_ASSERT(snippet_enumDeclaration->get_name() == target_enumDeclaration->get_name());
16003 }
16004 else
16005 {
16006 // DQ (4/13/2014): I think we all agreed these would not have to be handled.
16007 printf ("Warning: can't handle unnamed enum declarations \n");
16008 ROSE_ASSERT(returnSymbol == NULL);
16009 }
16010 break;
16011 }
16012
16013 // DQ (12/11/2020): Adding support for codeSegregation tool.
16014 case V_SgTemplateMemberFunctionDeclaration:
16015 // DQ (12/8/2020): Adding support for codeSegregation tool.
16016 case V_SgTemplateFunctionDeclaration:
16017 // DQ (12/5/2020): Adding support for codeSegregation tool.
16018 case V_SgMemberFunctionDeclaration:
16019 case V_SgFunctionDeclaration:
16020 {
16021 SgFunctionDeclaration* snippet_functionDeclaration = isSgFunctionDeclaration(snippet_declaration);
16022 ROSE_ASSERT(snippet_functionDeclaration != NULL);
16023
16024#if DEBUG_FIND_ASSOCIATED_DECLARATION
16025 printf ("snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16026#endif
16027 SgName snippet_functionName = snippet_functionDeclaration->get_name();
16028
16029#if DEBUG_FIND_ASSOCIATED_DECLARATION
16030 printf ("snippet snippet declaration's function name = %s \n",snippet_functionName.str());
16031 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope->class_name().c_str());
16032#endif
16033 SgFunctionSymbol* target_symbol = target_AST_scope->lookup_function_symbol(snippet_functionName);
16034 ROSE_ASSERT(target_symbol != NULL);
16035 returnSymbol = target_symbol;
16036
16037 SgFunctionSymbol* functionSymbolInTargetAST = isSgFunctionSymbol(returnSymbol);
16038 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
16039 SgFunctionDeclaration* target_functionDeclaration = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
16040 ROSE_ASSERT(target_functionDeclaration != NULL);
16041
16042#if DEBUG_FIND_ASSOCIATED_DECLARATION
16043 printf ("snippet: functionDeclaration = %p = %s \n",snippet_functionDeclaration,snippet_functionDeclaration->get_name().str());
16044 printf ("target: functionDeclaration = %p = %s \n",target_functionDeclaration,target_functionDeclaration->get_name().str());
16045 printf ("isDefiningDeclaration = %s \n",isDefiningDeclaration ? "true" : "false");
16046#endif
16047 if (isDefiningDeclaration == true)
16048 {
16049#if DEBUG_FIND_ASSOCIATED_DECLARATION
16050 printf ("get the defining declaration instead of the firstNondefining declaration from the function symbol \n");
16051#endif
16052 returnDeclaration = target_functionDeclaration->get_definingDeclaration();
16053 }
16054
16055 ROSE_ASSERT(snippet_functionDeclaration->get_name() == target_functionDeclaration->get_name());
16056 break;
16057 }
16058
16059 default:
16060 {
16061 printf ("Error: default reached in switch: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16062 ROSE_ABORT();
16063 }
16064 }
16065
16066 ROSE_ASSERT(returnDeclaration != NULL);
16067
16068 // These should have different global scopes, because they are from different ASTs.
16069 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,returnDeclaration) == false);
16070
16071 // return the last found symbol.
16072 // return returnSymbol;
16073 return returnDeclaration;
16074 }
16075
16076
16077SgType*
16079 {
16080 // This is the inner function to getTargetFileType()
16081 SgType* returnType = NULL;
16082
16083 ROSE_ASSERT(snippet_type != NULL);
16084 ROSE_ASSERT(targetScope != NULL);
16085
16086 // DQ (3/17/2014): Refactored code.
16087 // See if the type might be asociated with the snippet file.
16088 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
16089 // SgType* type_copy = snippet_type;
16090
16091#if 0
16092 SgType* type_copy = snippet_type;
16093 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
16094#endif
16095
16096 SgNamedType* namedType = isSgNamedType(snippet_type);
16097 if (namedType != NULL)
16098 {
16099 // Find the associated declaration and it's corresponding declaration in the target AST.
16100 SgDeclarationStatement* snippet_declaration = namedType->get_declaration();
16101 ROSE_ASSERT(snippet_declaration != NULL);
16102#if 0
16103 printf ("Need to find the declaration in the target AST that is associated with the snippet_declaration in the snippet AST \n");
16104 printf (" --- snippet_declaration = %p = %s = %s \n",snippet_declaration,snippet_declaration->class_name().c_str(),SageInterface::get_name(snippet_declaration).c_str());
16105#endif
16106 // There are only a few cases here!
16107 switch (namedType->variantT())
16108 {
16109 case V_SgClassType:
16110 {
16111 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
16112 if (classDeclaration != NULL)
16113 {
16114 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
16115 if (classSymbolInTargetAST == NULL)
16116 {
16117 // For Java or C++ this could be a name qualified type and so we need a better mechanism
16118 // to identify it thorugh it's parent scopes. Build a list of parent scope back to the
16119 // global scope and then traverse the list backwards to identify each scope in the target
16120 // AST's global scope until we each the associated declaration in the target AST.
16121#if 0
16122 printf ("This is likely a name qualified scope (which can't be seen in a simple traversal of the parent scope (case of C++ or Java) \n");
16123 printf (" --- Looking for target AST match for class name = %s \n",classDeclaration->get_name().str());
16124#endif
16125 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
16126 ROSE_ASSERT(symbol != NULL);
16127
16128 classSymbolInTargetAST = isSgClassSymbol(symbol);
16129 }
16130
16131 ROSE_ASSERT(classSymbolInTargetAST != NULL);
16132 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
16133 ROSE_ASSERT(target_classDeclaration != NULL);
16134#if 0
16135 printf ("snippet: classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
16136 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
16137#endif
16138 ROSE_ASSERT(classDeclaration->get_name() == target_classDeclaration->get_name());
16139
16140 returnType = classSymbolInTargetAST->get_type();
16141 }
16142 break;
16143 }
16144
16145 case V_SgTypedefType:
16146 {
16147 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
16148 if (typedefDeclaration != NULL)
16149 {
16150 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(typedefDeclaration->get_name(),targetScope);
16151
16152 // Not clear if we have to handle a more general case here.
16153 // ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16154 // returnType = typedefSymbolInTargetAST->get_type();
16155 if (typedefSymbolInTargetAST == NULL)
16156 {
16157#if 0
16158 printf ("Error: It is an error to not have a typedef type defined in the target AST (this is an old rule, we have to support more general rules now)! \n");
16159 printf (" --- The target AST must have a valid typedef type (and associated declaration) to support resetting the SgTypedefType: %p \n",typedefDeclaration->get_type());
16160#endif
16161 // DQ (3/16/2014): Find the associated typedef declaration (from the target AST)
16162 // for the input type associated with its declaration in the snippet AST.
16163 SgSymbol* symbol = findAssociatedSymbolInTargetAST(typedefDeclaration,targetScope);
16164 ROSE_ASSERT(symbol != NULL);
16165
16166 typedefSymbolInTargetAST = isSgTypedefSymbol(symbol);
16167
16168 // Note that test5d demonstrates this problem.
16169 // ROSE_ASSERT(false);
16170 }
16171
16172 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16173 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
16174 ROSE_ASSERT(target_typedefDeclaration != NULL);
16175#if 0
16176 printf ("snippet: typedefDeclaration = %p = %s \n",typedefDeclaration,typedefDeclaration->get_name().str());
16177 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
16178#endif
16179 ROSE_ASSERT(typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
16180
16181 returnType = typedefSymbolInTargetAST->get_type();
16182 }
16183 break;
16184 }
16185
16186 case V_SgEnumType:
16187 {
16188 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(snippet_declaration);
16189 if (enumDeclaration != NULL)
16190 {
16191 ROSE_ASSERT(enumDeclaration->get_name().is_null() == false);
16192 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(enumDeclaration->get_name(),targetScope);
16193
16194 // Not clear if we have to handle a more general case here.
16195 // ROSE_ASSERT(enumSymbolInTargetAST != NULL);
16196 // returnType = enumSymbolInTargetAST->get_type();
16197 if (enumSymbolInTargetAST == NULL)
16198 {
16199 printf ("Error: It is an error to not have a enum type defined in the target AST! \n");
16200 printf (" --- The target AST must have a valid enum type (and associated declaration) to support resetting the SgEnumType: %p \n",enumDeclaration->get_type());
16201
16202 // We will allow this to pass for now, since it is a violation of the target AST, and not the snippet mechanism (I think).
16203 returnType = snippet_type;
16204
16205 // Note that test5d demonstrates this problem.
16206 // ROSE_ASSERT(false);
16207 }
16208 else
16209 {
16210 returnType = enumSymbolInTargetAST->get_type();
16211 }
16212 }
16213
16214 break;
16215 }
16216
16217 case V_SgJavaParameterizedType:
16218 {
16219 // DQ (3/10/2014): This type is a view of a generic class with dynamic type checking (e.g. T).
16220 // This acts more like a class with reference to the template instead of the template instantiation.
16221 // So reset the declaration.
16222#if 0
16223 printf ("In getTargetFileTypeSupport(): case V_SgJavaParameterizedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16224#endif
16225#if 1
16226 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
16227 if (classDeclaration != NULL)
16228 {
16229#if 0
16230 printf ("Looking for classDeclaration = %s \n",classDeclaration->get_name().str());
16231#endif
16232 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
16233 ROSE_ASSERT(javaParameterizedType != NULL);
16234#if 0
16235 // SgTemplateParameterPtrList* templateParameterList = javaParameterizedType->get_type_list();
16236 SgTemplateParameterList* templateParameterListNode = javaParameterizedType->get_type_list();
16237 ROSE_ASSERT(templateParameterListNode != NULL);
16238 SgTemplateParameterPtrList* templateParameterList = &templateParameterListNode->get_args();
16239#else
16240 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
16241 // SgTemplateParameterPtrList* templateParameterList = NULL;
16242#endif
16243 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
16244 // SgTemplateArgumentPtrList* templateSpecializationArgumentList = NULL;
16245#if 0
16246 printf ("Calling lookupTemplateClassSymbolInParentScopes() name = %s \n",classDeclaration->get_name().str());
16247#endif
16248 // SgTemplateClassSymbol* templateClassSymbolInTargetAST = lookupTemplateClassSymbolInParentScopes(classDeclaration->get_name(),templateParameterList,templateSpecializationArgumentList,targetScope);
16249 SgClassSymbol* templateClassSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
16250#if 0
16251 printf ("DONE: Calling lookupTemplateClassSymbolInParentScopes() \n");
16252#endif
16253#if 0
16254 printf ("targetScope->get_symbol_table()->size() = %d \n",targetScope->get_symbol_table()->size());
16255 if (templateClassSymbolInTargetAST == NULL)
16256 {
16257 targetScope->get_symbol_table()->print("ERROR: templateClassSymbolInTargetAST == NULL");
16258 }
16259#endif
16260 // DQ (3/30/2014): Add this approach.
16261 if (templateClassSymbolInTargetAST == NULL)
16262 {
16263#if 0
16264 printf ("Calling findAssociatedSymbolInTargetAST \n");
16265#endif
16266 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
16267 ROSE_ASSERT(symbol != NULL);
16268
16269 templateClassSymbolInTargetAST = isSgClassSymbol(symbol);
16270
16271 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
16272 }
16273
16274 // Not clear if we have to handle a more general case here.
16275 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
16276
16277 returnType = templateClassSymbolInTargetAST->get_type();
16278 }
16279#else
16280 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
16281 if (javaParameterizedType != NULL)
16282 {
16283#error "DEAD CODE!"
16284 // Not clear how to lookup this type in the target AST.
16285 returnType = javaParameterizedType;
16286
16287 SgType* internal_type = javaParameterizedType->get_raw_type();
16288 ROSE_ASSERT(internal_type != NULL);
16289 }
16290#endif
16291#if 0
16292 printf ("SgJavaParameterizedType not yet tested! \n");
16293 ROSE_ABORT();
16294#endif
16295 break;
16296 }
16297
16298 case V_SgJavaQualifiedType:
16299 {
16300 // DQ (3/10/2014): This type acts like a binary operator on types to define aggregate
16301 // types to represent what in C++ would be name qualification. I need only set the
16302 // declarations in each SgJavaQualifiedType to refer to a declaration in the target AST.
16303 // So reset the declaration.
16304
16305 // This case is demonstrated by test code:
16306 // SS_JAVA_CWES/src/Error_Handling/CWE_248/CWE_248_0.java,Error_Handling.CWE_248.CWE_248_0.cwe_248_0
16307 // printf ("***** SgJavaQualifiedType not yet tested! *** \n");
16308
16309 printf ("In getTargetFileTypeSupport(): case V_SgJavaQualifiedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16310
16311 SgJavaQualifiedType* javaQualifiedType = isSgJavaQualifiedType(namedType);
16312 if (javaQualifiedType != NULL)
16313 {
16314 // Not clear how to lookup this type in the target AST.
16315 returnType = javaQualifiedType;
16316
16317 SgType* internal_type_1 = javaQualifiedType->get_parent_type();
16318 ROSE_ASSERT(internal_type_1 != NULL);
16319 SgType* internal_type_2 = javaQualifiedType->get_type();
16320 ROSE_ASSERT(internal_type_2 != NULL);
16321 }
16322
16323 printf ("Case of SgJavaQualifiedType: not yet handled: commented out assertion! \n");
16324 // ROSE_ASSERT(false);
16325 break;
16326 }
16327
16328 case V_SgJavaWildcardType:
16329 {
16330 // DQ (3/10/2014): This type expressed constraints on an input type.
16331 // if (?) then it is associated with the Java object type.
16332 // It can be constraint with an upper bound or lower bound.
16333 // if (?extends List) would be an upper bound for List.
16334 // if (?super Integer) would be an lower bound for List.
16335 // So reset the declaration.
16336
16337 printf ("In getTargetFileTypeSupport(): case V_SgJavaWildcardType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16338
16339 SgJavaWildcardType* javaWildcardType = isSgJavaWildcardType(namedType);
16340 if (javaWildcardType != NULL)
16341 {
16342 // Not clear how to lookup this type in the target AST.
16343 returnType = javaWildcardType;
16344 }
16345
16346 printf ("SgJavaWildcardType not yet tested! \n");
16347 ROSE_ABORT();
16348 }
16349
16350 default:
16351 {
16352 printf ("Error: In getTargetFileTypeSupport(): default reached in switch: namedType = %p = %s \n",namedType,namedType->class_name().c_str());
16353 ROSE_ABORT();
16354 }
16355 }
16356
16357 ROSE_ASSERT(returnType != NULL);
16358#if 0
16359 printf ("Exiting as a test! \n");
16360 ROSE_ABORT();
16361#endif
16362 }
16363 else
16364 {
16365 // Non-named types are shared, so we need not reset them.
16366
16367 // If this was not a named type then return NULL (which is checked at the
16368 // calling point, so that the type will not be reset).
16369 }
16370
16371 return returnType;
16372 }
16373
16374
16375SgType*
16377 {
16378 SgType* returnType = NULL;
16379
16380 ROSE_ASSERT(snippet_type != NULL);
16381 ROSE_ASSERT(targetScope != NULL);
16382
16383 // DQ (3/17/2014): Refactored code.
16384 // See if the type might be asociated with the snippet file.
16385 SgType* type_copy = snippet_type;
16386
16387#if 0
16388 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
16389#endif
16390
16391 // We need to be able to reproduce the pointer types to class types, etc.
16392 Rose_STL_Container<SgType*> typeList = type_copy->getInternalTypes();
16393
16394#if 0
16395 for (size_t i = 0; i < typeList.size(); i++)
16396 {
16397 printf ("Input type: typeList[i=%" PRIuPTR "] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
16398 }
16399#endif
16400
16401#if 1
16402 // This is the unwrapped version of the getTargetFileType() function.
16403 returnType = getTargetFileTypeSupport(snippet_type,targetScope);
16404#else
16405 SgNamedType* namedType = isSgNamedType(snippet_type);
16406
16407#error "DEAD CODE!"
16408
16409 if (namedType != NULL)
16410 {
16411 // Find the associated declaration and it's corresponding declaration in the target AST.
16412 SgDeclarationStatement* snippet_declaration = namedType->get_declaration();
16413 ROSE_ASSERT(snippet_declaration != NULL);
16414#if 0
16415 printf ("Need to find the declaration in the target AST that is associated with the snippet_declaration in the snippet AST \n");
16416 printf (" --- snippet_declaration = %p = %s = %s \n",snippet_declaration,snippet_declaration->class_name().c_str(),SageInterface::get_name(snippet_declaration).c_str());
16417#endif
16418 // There are only a few cases here!
16419 switch (namedType->variantT())
16420 {
16421 case V_SgClassType:
16422 {
16423 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
16424 if (classDeclaration != NULL)
16425 {
16426 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
16427 if (classSymbolInTargetAST == NULL)
16428 {
16429 // For Java or C++ this could be a name qualified type and so we need a better mechanism
16430 // to identify it thorugh it's parent scopes. Build a list of parent scope back to the
16431 // global scope and then traverse the list backwards to identify each scope in the target
16432 // AST's global scope until we each the associated declaration in the target AST.
16433#if 0
16434 printf ("This is likely a name qualified scope (which can't be seen in a simple traversal of the parent scope (case of C++ or Java) \n");
16435 printf (" --- Looking for target AST match for class name = %s \n",classDeclaration->get_name().str());
16436#endif
16437 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
16438 ROSE_ASSERT(symbol != NULL);
16439
16440 classSymbolInTargetAST = isSgClassSymbol(symbol);
16441 }
16442
16443 ROSE_ASSERT(classSymbolInTargetAST != NULL);
16444 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
16445 ROSE_ASSERT(target_classDeclaration != NULL);
16446#if 0
16447 printf ("snippet: classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
16448 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
16449#endif
16450 ROSE_ASSERT(classDeclaration->get_name() == target_classDeclaration->get_name());
16451
16452 returnType = classSymbolInTargetAST->get_type();
16453 }
16454 break;
16455 }
16456
16457 case V_SgTypedefType:
16458 {
16459 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
16460 if (typedefDeclaration != NULL)
16461 {
16462 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(typedefDeclaration->get_name(),targetScope);
16463
16464 // Not clear if we have to handle a more general case here.
16465 // ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16466 // returnType = typedefSymbolInTargetAST->get_type();
16467 if (typedefSymbolInTargetAST == NULL)
16468 {
16469#if 0
16470 printf ("Error: It is an error to not have a typedef type defined in the target AST (this is an old rule, we have to support more general rules now)! \n");
16471 printf (" --- The target AST must have a valid typedef type (and associated declaration) to support resetting the SgTypedefType: %p \n",typedefDeclaration->get_type());
16472#endif
16473 // DQ (3/16/2014): Find the associated typedef declaration (from the target AST)
16474 // for the input type associated with its declaration in the snippet AST.
16475 SgSymbol* symbol = findAssociatedSymbolInTargetAST(typedefDeclaration,targetScope);
16476 ROSE_ASSERT(symbol != NULL);
16477
16478 typedefSymbolInTargetAST = isSgTypedefSymbol(symbol);
16479
16480 // Note that test5d demonstrates this problem.
16481 // ROSE_ASSERT(false);
16482 }
16483
16484 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16485 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
16486 ROSE_ASSERT(target_typedefDeclaration != NULL);
16487#if 0
16488 printf ("snippet: typedefDeclaration = %p = %s \n",typedefDeclaration,typedefDeclaration->get_name().str());
16489 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
16490#endif
16491 ROSE_ASSERT(typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
16492
16493 returnType = typedefSymbolInTargetAST->get_type();
16494 }
16495 break;
16496 }
16497
16498 case V_SgEnumType:
16499 {
16500 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(snippet_declaration);
16501 if (enumDeclaration != NULL)
16502 {
16503 ROSE_ASSERT(enumDeclaration->get_name().is_null() == false);
16504 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(enumDeclaration->get_name(),targetScope);
16505
16506 // Not clear if we have to handle a more general case here.
16507 // ROSE_ASSERT(enumSymbolInTargetAST != NULL);
16508 // returnType = enumSymbolInTargetAST->get_type();
16509 if (enumSymbolInTargetAST == NULL)
16510 {
16511 printf ("Error: It is an error to not have a enum type defined in the target AST! \n");
16512 printf (" --- The target AST must have a valid enum type (and associated declaration) to support resetting the SgEnumType: %p \n",enumDeclaration->get_type());
16513
16514 // We will allow this to pass for now, since it is a violation of the target AST, and not the snippet mechanism (I think).
16515 returnType = snippet_type;
16516
16517 // Note that test5d demonstrates this problem.
16518 // ROSE_ASSERT(false);
16519 }
16520 else
16521 {
16522 returnType = enumSymbolInTargetAST->get_type();
16523 }
16524 }
16525
16526 break;
16527 }
16528
16529 case V_SgJavaParameterizedType:
16530 {
16531 // DQ (3/10/2014): This type is a view of a generic class with dynamic type checking (e.g. T).
16532 // This acts more like a class with reference to the template instead of the template instantiation.
16533 // So reset the declaration.
16534
16535 printf ("In getTargetFileType(): case V_SgJavaParameterizedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16536#if 1
16537 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
16538 if (classDeclaration != NULL)
16539 {
16540 SgTemplateParameterPtrList* templateParameterList = NULL;
16541 SgTemplateArgumentPtrList* templateSpecializationArgumentList = NULL;
16542 SgTemplateClassSymbol* templateClassSymbolInTargetAST = lookupTemplateClassSymbolInParentScopes(classDeclaration->get_name(),templateParameterList,templateSpecializationArgumentList,targetScope);
16543
16544 // Not clear if we have to handle a more general case here.
16545 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
16546
16547 returnType = templateClassSymbolInTargetAST->get_type();
16548 }
16549#else
16550 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
16551 if (javaParameterizedType != NULL)
16552 {
16553 // Not clear how to lookup this type in the target AST.
16554 returnType = javaParameterizedType;
16555
16556 SgType* internal_type = javaParameterizedType->get_raw_type();
16557 ROSE_ASSERT(internal_type != NULL);
16558 }
16559#endif
16560 printf ("SgJavaParameterizedType not yet tested! \n");
16561 ROSE_ABORT();
16562 }
16563
16564 case V_SgJavaQualifiedType:
16565 {
16566 // DQ (3/10/2014): This type acts like a binary operator on types to define aggregate
16567 // types to represent what in C++ would be name qualification. I need only set the
16568 // declarations in each SgJavaQualifiedType to refer to a declaration in the target AST.
16569 // So reset the declaration.
16570
16571 printf ("In getTargetFileType(): case V_SgJavaQualifiedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16572
16573 SgJavaQualifiedType* javaQualifiedType = isSgJavaQualifiedType(namedType);
16574 if (javaQualifiedType != NULL)
16575 {
16576 // Not clear how to lookup this type in the target AST.
16577 returnType = javaQualifiedType;
16578
16579 SgType* internal_type_1 = javaQualifiedType->get_parent_type();
16580 ROSE_ASSERT(internal_type_1 != NULL);
16581 SgType* internal_type_2 = javaQualifiedType->get_type();
16582 ROSE_ASSERT(internal_type_2 != NULL);
16583 }
16584
16585 printf ("SgJavaQualifiedType not yet tested! \n");
16586 ROSE_ABORT();
16587 }
16588
16589 case V_SgJavaWildcardType:
16590 {
16591 // DQ (3/10/2014): This type expressed constraints on an input type.
16592 // if (?) then it is associated with the Java object type.
16593 // It can be constraint with an upper bound or lower bound.
16594 // if (?extends List) would be an upper bound for List.
16595 // if (?super Integer) would be an lower bound for List.
16596 // So reset the declaration.
16597
16598 printf ("In getTargetFileType(): case V_SgJavaWildcardType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16599
16600 SgJavaWildcardType* javaWildcardType = isSgJavaWildcardType(namedType);
16601 if (javaWildcardType != NULL)
16602 {
16603 // Not clear how to lookup this type in the target AST.
16604 returnType = javaWildcardType;
16605
16606 SgType* internal_type_1 = javaWildcardType->get_bound_type();
16607 // ROSE_ASSERT(internal_type_1 != NULL); // PC: 03/15/2014 - Dan, this cannot be asserted as the bound_type CAN BE NULL.
16608 }
16609
16610 printf ("SgJavaWildcardType not yet tested! \n");
16611 ROSE_ABORT();
16612 }
16613
16614 default:
16615 {
16616 printf ("Error: In getTargetFileType(): default reached in switch: namedType = %p = %s \n",namedType,namedType->class_name().c_str());
16617 ROSE_ABORT();
16618 }
16619 }
16620
16621 ROSE_ASSERT(returnType != NULL);
16622#if 0
16623 printf ("Exiting as a test! \n");
16624 ROSE_ABORT();
16625#endif
16626 }
16627 else
16628 {
16629 // Non-named types are shared, so we need not reset them.
16630
16631 // If this was not a named type then return NULL (which is checked at the
16632 // calling point, so that the type will not be reset).
16633 }
16634#endif
16635
16636 SgType* new_type = returnType;
16637
16638 // DQ (3/17/2014): Refactored code.
16639 // Now rebuild the type_copy as required to represent associated modifiers, typedef wrappers, pointers and references.
16640 if (new_type != NULL && typeList.size() > 1)
16641 {
16642 int size = (int)typeList.size();
16643 for (int i = size - 2; i >= 0; i--)
16644 {
16645#if 0
16646 printf ("Rebuild type: typeList[i=%d] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
16647#endif
16648 // SgModifierType* SgModifierType::createType(SgType* base_type, unsigned int f, SgExpression* optional_fortran_type_kind )
16649 switch(typeList[i]->variantT())
16650 {
16651 case V_SgModifierType:
16652 {
16653 SgModifierType* modifierType = isSgModifierType(typeList[i]);
16654 ROSE_ASSERT(modifierType != NULL);
16655 if (modifierType->get_typeModifier().get_constVolatileModifier().isConst() == true)
16656 {
16657 ROSE_ASSERT(new_type != NULL);
16658#if 0
16659 printf ("Building a SgModifierType: calling buildConstType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16660#endif
16661 new_type = buildConstType(new_type);
16662 }
16663 else
16664 {
16665 // Flag any additional modifiers that we might require (make anything not supported an error).
16666 printf ("Modifier kind not handled (not implemented) check what sort of modifier this is: \n");
16667 modifierType->get_typeModifier().display("Modifier kind not handled");
16668 ROSE_ABORT();
16669 }
16670 break;
16671 }
16672
16673 case V_SgTypedefType:
16674 {
16675 SgTypedefType* typedefType = isSgTypedefType(typeList[i]);
16676 ROSE_ASSERT(typedefType != NULL);
16677
16678 // DQ (3/17/2014): Call the associated support function instead.
16679 // SgType* SageBuilder::getTargetFileType(SgType* snippet_type, SgScopeStatement* targetScope)
16680 // SgType* new_typedefType = getTargetFileType(typedefType,targetScope);
16681 SgType* new_typedefType = getTargetFileTypeSupport(typedefType,targetScope);
16682 ROSE_ASSERT(new_typedefType != NULL);
16683 ROSE_ASSERT(isSgTypedefType(new_typedefType) != NULL);
16684
16685 new_type = new_typedefType;
16686#if 0
16687 printf ("ERROSE: SgTypedefType kind not handled (not implemented) \n");
16688 ROSE_ABORT();
16689#endif
16690 break;
16691 }
16692
16693 case V_SgPointerType:
16694 {
16695 SgPointerType* pointerType = isSgPointerType(typeList[i]);
16696 ROSE_ASSERT(pointerType != NULL);
16697#if 0
16698 printf ("Building a SgPointerType: calling buildPointerType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16699#endif
16700 ROSE_ASSERT(new_type != NULL);
16701 new_type = buildPointerType(new_type);
16702#if 0
16703 printf ("ERROSE: SgPointerType kind not handled (not implemented) \n");
16704 ROSE_ABORT();
16705#endif
16706 break;
16707 }
16708
16709 default:
16710 {
16711 printf ("Error: default reached in evaluation of typelist: typeList[i] = %p = %s \n",typeList[i],typeList[i]->class_name().c_str());
16712 ROSE_ABORT();
16713 }
16714 }
16715 }
16716
16717 returnType = new_type;
16718 }
16719
16720#if 0
16721 if (typeList.size() > 1)
16722 {
16723 printf ("Exiting as a test! \n");
16724 ROSE_ABORT();
16725 }
16726#endif
16727
16728
16729 return returnType;
16730 }
16731
16732
16733
16734void
16735SageBuilder::errorCheckingTargetAST (SgNode* node_copy, SgNode* node_original, SgFile* targetFile, bool failOnWarning )
16736 {
16737#if 0
16738 printf ("In errorCheckingTargetAST(): node_copy = %p = %s node_original = %p = %s \n",node_copy,node_copy->class_name().c_str(),node_original,node_original->class_name().c_str());
16739#endif
16740
16741 // Handle what is the same about all statements before getting to the switch.
16742 SgStatement* statement_copy = isSgStatement(node_copy);
16743 SgStatement* statement_original = isSgStatement(node_original);
16744 if (statement_copy != NULL)
16745 {
16746 // Check the scope if it is stored explicitly.
16747 if (statement_copy->hasExplicitScope() == true)
16748 {
16749 // Handle the scope for all statements.
16750 SgScopeStatement* scope_copy = statement_copy->get_scope();
16751 ROSE_ASSERT(statement_original != NULL);
16752 SgScopeStatement* scope_original = statement_original->get_scope();
16753 ROSE_ASSERT(scope_copy != NULL);
16754 ROSE_ASSERT(scope_original != NULL);
16755
16756 // if (TransformationSupport::getFile(scope_original) != targetFile)
16757 // if (getEnclosingFileNode(scope_original) != targetFile)
16758 if (getEnclosingFileNode(scope_copy) != targetFile)
16759 {
16760#if 0
16761 printf ("Warning: SgStatement: scope = %p = %s \n",scope_original,scope_original->class_name().c_str());
16762#endif
16763 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
16764 // SgFile* snippetFile = getEnclosingFileNode(scope_original);
16765 SgFile* snippetFile = getEnclosingFileNode(scope_copy);
16766 ROSE_ASSERT(snippetFile != NULL);
16767 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16768#if 1
16769 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16770 // ROSE_ASSERT(false);
16771#endif
16772 if (failOnWarning == true)
16773 {
16774 printf ("Exit on warning! \n");
16775 ROSE_ABORT();
16776 }
16777 }
16778#if 0
16779 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
16780 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
16781
16782 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
16783 // ROSE_ASSERT(targetScope != NULL);
16784
16785 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16786 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16787 // SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol->get_name(),targetScope);
16788 // ROSE_ASSERT(variableSymbolInTargetAST != NULL);
16789
16790 // Unless we know that this is a declaration we can't set the scope here using the information about this being a definng declaration.
16791 // If this is a defining declaration then we want to set it's scope to targetScope, else we want to lookup
16792 // the symbol through the parent scope and set the scope using the symbol's first non-defining declaration.
16793 // statement_copy->set_scope(targetScope);
16794
16795 // SgSymbol* symbol = statement_copy->search_for_symbol_from_symbol_table();
16796 // ROSE_ASSERT(symbol != NULL);
16797#endif
16798#if 0
16799 printf ("SgClassDeclaration: Exiting as a test! \n");
16800 ROSE_ABORT();
16801#endif
16802#if 0
16803 if (TransformationSupport::getFile(scope) != targetFile)
16804 {
16805 printf ("Warning: SgStatement: scope = %p = %s \n",scope,scope->class_name().c_str());
16806 SgFile* snippetFile = TransformationSupport::getFile(scope);
16807 ROSE_ASSERT(snippetFile != NULL);
16808 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16809
16810 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16811 // ROSE_ASSERT(false);
16812 }
16813#endif
16814 }
16815 }
16816
16817 // Handle what is the same about all declaration before getting to the switch.
16818 SgDeclarationStatement* declarationStatement_copy = isSgDeclarationStatement(node_copy);
16819 SgDeclarationStatement* declarationStatement_original = isSgDeclarationStatement(node_original);
16820 if (declarationStatement_copy != NULL)
16821 {
16822 // Check the firstnondefiningDeclaration and definingDeclaration
16823 SgDeclarationStatement* firstNondefiningDeclaration_copy = declarationStatement_copy->get_firstNondefiningDeclaration();
16824 SgDeclarationStatement* firstNondefiningDeclaration_original = declarationStatement_original->get_firstNondefiningDeclaration();
16825
16826 // DQ (3/17/2014): Bugfix, we want to use the firstNondefiningDeclaration_copy instead of firstNondefiningDeclaration_original.
16827 // DQ (3/10/2014): We want to allow for NULL return values from getEnclosingFileNode() for Java classes that are in java.lang (for example).
16828 // SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_original);
16829 SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_copy);
16830 if (snippetFile != NULL && snippetFile != targetFile)
16831 {
16832 // I think we want to allow this because it is a common occurence in any merged AST.
16833 // However, if might be worth fixing for other reasons. This needs to be discussed.
16834#if 0
16835 printf ("Note: SgDeclarationStatement: firstNondefiningDeclaration_original is not in target file (allowed for merged ASTs) \n");
16836#endif
16837 // ROSE_ASSERT(false);
16838 if (failOnWarning == true)
16839 {
16840 printf ("Exit on warning! \n");
16841 ROSE_ABORT();
16842 }
16843 }
16844 else
16845 {
16846 // Warn about this if snippetFile == NULL.
16847 if (snippetFile == NULL)
16848 {
16849 printf ("Note: firstNondefiningDeclaration_original = %p getEnclosingFileNode() returned NULL \n",firstNondefiningDeclaration_original);
16850
16851 if (failOnWarning == true)
16852 {
16853 printf ("Exit on warning! \n");
16854 ROSE_ABORT();
16855 }
16856 }
16857 }
16858
16859 SgDeclarationStatement* definingDeclaration_copy = declarationStatement_copy->get_definingDeclaration();
16860 SgDeclarationStatement* definingDeclaration_original = declarationStatement_original->get_definingDeclaration();
16861 if (definingDeclaration_original != NULL)
16862 {
16863 // DQ (3/17/2014): Bugfix, we want to use the definingDeclaration_copy instead of definingDeclaration_original.
16864 // if (TransformationSupport::getFile(definingDeclaration_original) != targetFile)
16865 // if (getEnclosingFileNode(definingDeclaration_original) != targetFile)
16866 // SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_original);
16867 SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_copy);
16868 if (snippetFile != NULL && snippetFile != targetFile)
16869 {
16870#if 1
16871 printf ("Warning: SgDeclarationStatement: definingDeclaration is not in target file \n");
16872 // ROSE_ASSERT(false);
16873#endif
16874 if (failOnWarning == true)
16875 {
16876 printf ("Exit on warning! \n");
16877 ROSE_ABORT();
16878 }
16879
16880 if (declarationStatement_original == definingDeclaration_original)
16881 {
16882 // This is a defining declaration, so we can set the scope (or can we?)
16883 // I guess we could if the translation map were complete, but it is not complete yet.
16884 }
16885 }
16886 else
16887 {
16888 // Warn about this if snippetFile == NULL.
16889 if (snippetFile == NULL)
16890 {
16891 printf ("Note: definingDeclaration_original = %p getEnclosingFileNode() returned NULL \n",definingDeclaration_original);
16892
16893 if (failOnWarning == true)
16894 {
16895 printf ("Exit on warning! \n");
16896 ROSE_ABORT();
16897 }
16898 }
16899 }
16900 }
16901 }
16902
16903 // Handle what is the same about all expressions before getting to the switch.
16904 SgExpression* expression = isSgExpression(node_copy);
16905 if (expression != NULL)
16906 {
16907 // Check the scope if it is stored explicitly.
16908
16909 // printf ("WARNING: Need to check if the type is explicitly stored in this expression! \n");
16910
16911 if (expression->hasExplicitType() == true)
16912 {
16913 // Handle the type for all expressions.
16914 SgType* type = expression->get_type();
16915 ROSE_ASSERT(type != NULL);
16916 }
16917 }
16918
16919#if 0
16920 printf ("Leaving errorCheckingTargetAST() \n");
16921#endif
16922 }
16923
16924
16925template <class T>
16926void
16927SageBuilder::resetDeclaration(T* classDeclaration_copy, T* classDeclaration_original, SgScopeStatement* targetScope)
16928 {
16929 // I'm not sure if this function is a good idea since we can't call set_scope() easily from any
16930 // SgDeclarationStatement and I don't want to make set_scope() a virtual function because it would
16931 // not make sense everywhere.
16932
16933 // DQ (3/17/2014): This code is similar to the case for SgEnumDeclaration (later we can refactor this if this works well).
16934 T* classDeclaration_copy_defining = dynamic_cast<T*>(classDeclaration_copy->get_definingDeclaration());
16935 T* classDeclaration_copy_nondefining = dynamic_cast<T*>(classDeclaration_copy->get_firstNondefiningDeclaration());
16936 T* classDeclaration_original_defining = dynamic_cast<T*>(classDeclaration_original->get_definingDeclaration());
16937 T* classDeclaration_original_nondefining = dynamic_cast<T*>(classDeclaration_original->get_firstNondefiningDeclaration());
16938
16939 // Set the scope if it is still set to the scope of the snippet AST.
16940 if (classDeclaration_copy_defining != NULL && classDeclaration_copy_defining->get_scope() == classDeclaration_original_defining->get_scope())
16941 {
16942#if 0
16943 printf ("reset the scope of classDeclaration_copy_defining \n");
16944#endif
16945 classDeclaration_copy_defining->set_scope(targetScope);
16946 }
16947
16948 // Set the scope if it is still set to the scope of the snippet AST.
16949 if (classDeclaration_copy_nondefining != NULL && classDeclaration_copy_nondefining->get_scope() == classDeclaration_original_nondefining->get_scope())
16950 {
16951#if 0
16952 printf ("reset the scope of classDeclaration_copy_nondefining \n");
16953#endif
16954 classDeclaration_copy_nondefining->set_scope(targetScope);
16955 }
16956
16957 // Set the parent if it is still set to a node of the snippet AST.
16958 if (classDeclaration_copy_nondefining != NULL && classDeclaration_copy_nondefining->get_parent() == classDeclaration_original_nondefining->get_parent())
16959 {
16960#if 0
16961 printf ("reset the parent of classDeclaration_copy_nondefining \n");
16962#endif
16963 classDeclaration_copy_nondefining->set_parent(classDeclaration_copy->get_parent());
16964 }
16965 }
16966
16967
16968void
16970 SgNode* node_copy, SgNode* node_original)
16971 {
16972 // This function fixes up invidual IR nodes to be consistant in the context of the target AST
16973 // where the node is inserted and at the point specified by insertionPoint. In this function,
16974 // node_copy is the copy that was made of node_original by the AST copy function. The node_original
16975 // is assumed to be the node that is in the AST snippet (it is still connected in the snippet's
16976 // AST (from compilation of the snippet file).
16977
16978 // This function hides the details of handling each different type of IR node.
16979 // It is assume that the node_copy is from an AST sub-tree generated by the AST copy mechanism,
16980 // and that the insertionPoint is a location in the target AST where the snippet AST has already
16981 // been inserted, this function makes each IR node internally consistant with the target AST.
16982
16983 // BTW, the translationMap should only be required to support references to things that are name
16984 // qualified (which are C++ specific). These are a performance option to simplify tacking back
16985 // through scopes with code similarly complex as to what is supported in the name qualification
16986 // support.
16987#if 0
16988 printf ("In fixupCopyOfNodeFromSeperateFileInNewTargetAst: node_copy = %p = %s \n",node_copy,node_copy->class_name().c_str());
16989#endif
16990
16991#if 0
16992 printf ("Disabled fixupCopyOfNodeFromSeperateFileInNewTargetAst() \n");
16993 return;
16994#endif
16995
16996 // SgFile* targetFile = TransformationSupport::getFile(insertionPoint);
16997 SgFile* targetFile = getEnclosingFileNode(insertionPoint);
16998
16999#if 0
17000 printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
17001 printf (" --- insertionPointIsScope = %s \n",insertionPointIsScope ? "true" : "false");
17002#endif
17003
17004 // DQ (3/4/2014): As I recall there is a reason why we can't setup the scope here.
17005
17006 // We also need to handle the symbol (move it from the body (SgBaicBlock) that was
17007 // a copy to the scope in the target AST where the SgInitializedName was inserted).
17008 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17009#if 0
17010 printf ("insertionPointScope = %p = %s \n",insertionPointScope,insertionPointScope->class_name().c_str());
17011#endif
17012 SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17013 ROSE_ASSERT(targetScope != NULL);
17014
17015#if 1
17016 // Refactored code (error checking done after AST fixup).
17017#if 0
17018 errorCheckingTargetAST(node_copy,node_original,targetFile, false);
17019#endif
17020#else
17021
17022#error "DEAD CODE!"
17023
17024 // Handle what is the same about all statements before getting to the switch.
17025 SgStatement* statement_copy = isSgStatement(node_copy);
17026 SgStatement* statement_original = isSgStatement(node_original);
17027 if (statement_copy != NULL)
17028 {
17029 // Check the scope if it is stored explicitly.
17030 if (statement_copy->hasExplicitScope() == true)
17031 {
17032 // Handle the scope for all statements.
17033 SgScopeStatement* scope_copy = statement_copy->get_scope();
17034 SgScopeStatement* scope_original = statement_original->get_scope();
17035 ROSE_ASSERT(scope_copy != NULL);
17036 ROSE_ASSERT(scope_original != NULL);
17037
17038 // if (TransformationSupport::getFile(scope_original) != targetFile)
17039 if (getEnclosingFileNode(scope_original) != targetFile)
17040 {
17041#if 0
17042 printf ("Warning: SgStatement: scope = %p = %s \n",scope_original,scope_original->class_name().c_str());
17043#endif
17044 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
17045 SgFile* snippetFile = getEnclosingFileNode(scope_original);
17046 ROSE_ASSERT(snippetFile != NULL);
17047 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
17048#if 0
17049 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
17050 // ROSE_ASSERT(false);
17051#endif
17052 }
17053#if 0
17054 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17055 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
17056
17057 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17058 // ROSE_ASSERT(targetScope != NULL);
17059
17060 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
17061 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
17062 // SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol->get_name(),targetScope);
17063 // ROSE_ASSERT(variableSymbolInTargetAST != NULL);
17064
17065 // Unless we know that this is a declaration we can't set the scope here using the information about this being a definng declaration.
17066 // If this is a defining declaration then we want to set it's scope to targetScope, else we want to lookup
17067 // the symbol through the parent scope and set the scope using the symbol's first non-defining declaration.
17068 // statement_copy->set_scope(targetScope);
17069
17070 // SgSymbol* symbol = statement_copy->search_for_symbol_from_symbol_table();
17071 // ROSE_ASSERT(symbol != NULL);
17072#endif
17073#if 0
17074 printf ("SgClassDeclaration: Exiting as a test! \n");
17075 ROSE_ABORT();
17076#endif
17077#if 0
17078 if (TransformationSupport::getFile(scope) != targetFile)
17079 {
17080 printf ("Warning: SgStatement: scope = %p = %s \n",scope,scope->class_name().c_str());
17081 SgFile* snippetFile = TransformationSupport::getFile(scope);
17082 ROSE_ASSERT(snippetFile != NULL);
17083 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
17084
17085 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
17086 // ROSE_ASSERT(false);
17087 }
17088#endif
17089 }
17090 }
17091
17092#error "DEAD CODE!"
17093
17094 // Handle what is the same about all declaration before getting to the switch.
17095 SgDeclarationStatement* declarationStatement_copy = isSgDeclarationStatement(node_copy);
17096 SgDeclarationStatement* declarationStatement_original = isSgDeclarationStatement(node_original);
17097 if (declarationStatement_copy != NULL)
17098 {
17099 // Check the firstnondefiningDeclaration and definingDeclaration
17100 SgDeclarationStatement* firstNondefiningDeclaration_original = declarationStatement_original->get_firstNondefiningDeclaration();
17101
17102 // DQ (3/10/2014): We want to allow for NULL return values from getEnclosingFileNode() for Java classes that are in java.lang (for example).
17103 SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_original);
17104 if (snippetFile != NULL && snippetFile != targetFile)
17105 {
17106 // I think we want to allow this because it is a common occurence in any merged AST.
17107 // However, if might be worth fixing for other reasons. This needs to be discussed.
17108#if 0
17109 printf ("Note: SgDeclarationStatement: firstNondefiningDeclaration_original is not in target file (allowed for merged ASTs) \n");
17110#endif
17111 // ROSE_ASSERT(false);
17112 }
17113 else
17114 {
17115 // Warn about this if snippetFile == NULL.
17116 if (snippetFile == NULL)
17117 {
17118 printf ("Note: firstNondefiningDeclaration_original = %p getEnclosingFileNode() returned NULL \n",firstNondefiningDeclaration_original);
17119 }
17120 }
17121
17122#error "DEAD CODE!"
17123
17124 SgDeclarationStatement* definingDeclaration_original = declarationStatement_original->get_definingDeclaration();
17125 if (definingDeclaration_original != NULL)
17126 {
17127 // if (TransformationSupport::getFile(definingDeclaration_original) != targetFile)
17128 // if (getEnclosingFileNode(definingDeclaration_original) != targetFile)
17129 SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_original);
17130 if (snippetFile != NULL && snippetFile != targetFile)
17131 {
17132#if 0
17133 printf ("Warning: SgDeclarationStatement: definingDeclaration is not in target file \n");
17134 // ROSE_ASSERT(false);
17135#endif
17136 if (declarationStatement_original == definingDeclaration_original)
17137 {
17138 // This is a defining declaration, so we can set the scope (or can we?)
17139 // I guess we could if the translation map were complete, but it is not complete yet.
17140 }
17141 }
17142 else
17143 {
17144 // Warn about this if snippetFile == NULL.
17145 if (snippetFile == NULL)
17146 {
17147 printf ("Note: definingDeclaration_original = %p getEnclosingFileNode() returned NULL \n",definingDeclaration_original);
17148 }
17149 }
17150 }
17151 }
17152
17153#error "DEAD CODE!"
17154
17155#endif
17156
17157 // Handle what is the same about all expressions before getting to the switch.
17158 SgExpression* expression = isSgExpression(node_copy);
17159 if (expression != NULL)
17160 {
17161 // Check the scope if it is stored explicitly.
17162
17163 // printf ("WARNING: Need to check if the type is explicitly stored in this expression! \n");
17164
17165 if (expression->hasExplicitType() == true)
17166 {
17167 // Handle the type for all expressions.
17168 SgType* type = expression->get_type();
17169 ROSE_ASSERT(type != NULL);
17170
17171 // DQ (3/17/2014): Avoid calling stripType with the newly refactored getTargetFileType() function.
17172 // SgType* new_type = getTargetFileType(type->stripType(),targetScope);
17173 SgType* new_type = getTargetFileType(type,targetScope);
17174 if (new_type != NULL)
17175 {
17176 // Reset the base type to be the one associated with the target file.
17177 expression->set_explicitly_stored_type(new_type);
17178 }
17179 }
17180 }
17181
17182 switch (node_copy->variantT())
17183 {
17184 case V_SgInitializedName:
17185 {
17186 SgInitializedName* initializedName_copy = isSgInitializedName(node_copy);
17187 SgInitializedName* initializedName_original = isSgInitializedName(node_original);
17188
17189 // See if the scope might be associated with the snippet file.
17190
17191 // Since we don't want the scope that is stored in the SgInitializedName we
17192 // have to get the associated statement and the scope of that statement.
17193 // SgScopeStatement* scope_copy = initializedName_copy->get_scope();
17194 SgStatement* enclosingStatement_copy = TransformationSupport::getStatement(initializedName_copy);
17195#if 0
17196 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
17197#endif
17198 SgScopeStatement* scope_copy = enclosingStatement_copy->get_scope();
17199
17200 SgScopeStatement* scope_original = initializedName_original->get_scope();
17201
17202 ROSE_ASSERT(scope_copy != NULL);
17203 ROSE_ASSERT(scope_original != NULL);
17204
17205 // if (TransformationSupport::getFile(scope_original) != targetFile)
17206 if (getEnclosingFileNode(scope_original) != targetFile)
17207 {
17208#if 0
17209 ROSE_ASSERT(initializedName_copy != NULL);
17210 printf ("initializedName_copy = %p = %s \n",initializedName_copy,initializedName_copy->get_name().str());
17211 ROSE_ASSERT(initializedName_original != NULL);
17212 printf ("initializedName_original = %p = %s \n",initializedName_original,initializedName_original->get_name().str());
17213 SgType* initializedName_original_type = initializedName_original->get_type();
17214 printf ("initializedName_original_type = %p = %s \n",initializedName_original_type,initializedName_original_type->class_name().c_str());
17215 SgClassType* classType = isSgClassType(initializedName_original_type);
17216 // ROSE_ASSERT(classType != NULL);
17217 if (classType != NULL)
17218 {
17219 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
17220 ROSE_ASSERT(classDeclaration != NULL);
17221 printf ("classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
17222 }
17223#endif
17224#if 0
17225 printf ("Warning: case V_SgInitializedName: scope_copy = %p = %s \n",scope_copy,scope_copy->class_name().c_str());
17226 printf ("Warning: case V_SgInitializedName: scope_original = %p = %s \n",scope_original,scope_original->class_name().c_str());
17227
17228 printf ("Warning: case V_SgInitializedName: initializedName_copy->get_parent() = %p \n",initializedName_copy->get_parent());
17229 printf ("Warning: case V_SgInitializedName: initializedName_original->get_parent() = %p \n",initializedName_original->get_parent());
17230#endif
17231 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
17232 SgFile* snippetFile = getEnclosingFileNode(scope_original);
17233
17234 ROSE_ASSERT(snippetFile != NULL);
17235 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
17236#if 0
17237 printf ("Warning: case V_SgInitializedName: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
17238 // ROSE_ASSERT(false);
17239#endif
17240 }
17241
17242 // See if the type might be asociated with the snippet file.
17243 SgType* type_copy = initializedName_copy->get_type();
17244#if 0
17245 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
17246#endif
17247
17248#if 0
17249
17250#error "DEAD CODE!"
17251
17252 // We need to be able to reproduce the pointer types to class types, etc.
17253 Rose_STL_Container<SgType*> typeList = type_copy->getInternalTypes();
17254#if 0
17255 for (size_t i = 0; i < typeList.size(); i++)
17256 {
17257 printf ("Input type: typeList[i=%" PRIuPTR "] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
17258 }
17259#endif
17260 // Note that the semantics of this function is that it can return a NULL pointer (e.g. for primative types).
17261 SgType* new_type = getTargetFileType(type_copy->stripType(),targetScope);
17262
17263#error "DEAD CODE!"
17264
17265 // Now rebuild the type_copy as required to represent associated modifiers, typedef wrappers, pointers and references.
17266 if (new_type != NULL && typeList.size() > 1)
17267 {
17268 int size = (int)typeList.size();
17269 for (int i = size - 2; i >= 0; i--)
17270 {
17271#if 0
17272 printf ("Rebuild type: typeList[i=%d] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
17273#endif
17274 // SgModifierType* SgModifierType::createType(SgType* base_type, unsigned int f, SgExpression* optional_fortran_type_kind )
17275 switch(typeList[i]->variantT())
17276 {
17277 case V_SgModifierType:
17278 {
17279 SgModifierType* modifierType = isSgModifierType(typeList[i]);
17280 ROSE_ASSERT(modifierType != NULL);
17281 if (modifierType->get_typeModifier().get_constVolatileModifier().isConst() == true)
17282 {
17283 ROSE_ASSERT(new_type != NULL);
17284#if 0
17285 printf ("Building a SgModifierType: calling buildConstType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
17286#endif
17287 new_type = buildConstType(new_type);
17288 }
17289 else
17290 {
17291 // Flag any additional modifiers that we might require (make anything not supported an error).
17292 printf ("Modifier kind not handled (not implemented) check what sort of modifier this is: \n");
17293 modifierType->get_typeModifier().display("Modifier kind not handled");
17294 ROSE_ABORT();
17295 }
17296 break;
17297 }
17298
17299#error "DEAD CODE!"
17300
17301 case V_SgTypedefType:
17302 {
17303 SgTypedefType* typedefType = isSgTypedefType(typeList[i]);
17304 ROSE_ASSERT(typedefType != NULL);
17305
17306 // SgType* SageBuilder::getTargetFileType(SgType* snippet_type, SgScopeStatement* targetScope)
17307 SgType* new_typedefType = getTargetFileType(typedefType,targetScope);
17308 ROSE_ASSERT(new_typedefType != NULL);
17309 ROSE_ASSERT(isSgTypedefType(new_typedefType) != NULL);
17310
17311 new_type = new_typedefType;
17312#if 0
17313 printf ("ERROSE: SgTypedefType kind not handled (not implemented) \n");
17314 ROSE_ABORT();
17315#endif
17316 break;
17317 }
17318
17319#error "DEAD CODE!"
17320
17321 case V_SgPointerType:
17322 {
17323 SgPointerType* pointerType = isSgPointerType(typeList[i]);
17324 ROSE_ASSERT(pointerType != NULL);
17325#if 0
17326 printf ("Building a SgPointerType: calling buildPointerType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
17327#endif
17328 ROSE_ASSERT(new_type != NULL);
17329 new_type = buildPointerType(new_type);
17330#if 0
17331 printf ("ERROSE: SgPointerType kind not handled (not implemented) \n");
17332 ROSE_ABORT();
17333#endif
17334 break;
17335 }
17336
17337#error "DEAD CODE!"
17338
17339 default:
17340 {
17341 printf ("Error: default reached in evaluation of typelist: typeList[i] = %p = %s \n",typeList[i],typeList[i]->class_name().c_str());
17342 ROSE_ABORT();
17343 }
17344 }
17345 }
17346 }
17347#if 0
17348 if (typeList.size() > 1)
17349 {
17350 printf ("Exiting as a test! \n");
17351 ROSE_ABORT();
17352 }
17353#endif
17354
17355#error "DEAD CODE!"
17356
17357#else
17358 // Refactored the above code to be a part of getTargetFileType() function.
17359 // Note that the semantics of this function is that it can return a NULL pointer (e.g. for primative types).
17360 // SgType* new_type = getTargetFileType(type_copy->stripType(),targetScope);
17361 SgType* new_type = getTargetFileType(type_copy,targetScope);
17362#endif
17363#if 0
17364 printf ("new_type = %p \n",new_type);
17365#endif
17366 if (new_type != NULL)
17367 {
17368 // Reset the base type to be the one associated with the target file.
17369#if 0
17370 printf ("Reset type for initializedName_copy = %p from type = %p to type = %p \n",initializedName_copy,initializedName_copy->get_type(),new_type);
17371#endif
17372 SgType* original_type = initializedName_copy->get_type();
17373 SgNamedType* original_named_type = isSgNamedType(original_type);
17374 SgNamedType* new_named_type = isSgNamedType(new_type);
17375 if (original_named_type != NULL)
17376 {
17377 ROSE_ASSERT(new_named_type != NULL);
17378 SgClassDeclaration* original_classDeclaration = isSgClassDeclaration(original_named_type->get_declaration());
17379 SgClassDeclaration* new_classDeclaration = isSgClassDeclaration(new_named_type->get_declaration());
17380 if (original_classDeclaration != NULL)
17381 {
17382 ROSE_ASSERT(new_classDeclaration != NULL);
17383#if 0
17384 printf ("original_classDeclaration = %p = %s \n",original_classDeclaration,original_classDeclaration->get_name().str());
17385 printf ("new_classDeclaration = %p = %s \n",new_classDeclaration,new_classDeclaration->get_name().str());
17386#endif
17387 // Make sure that the type names are the same.
17388 ROSE_ASSERT(new_classDeclaration->get_name() == original_classDeclaration->get_name());
17389 }
17390 }
17391#if 0
17392 SgType* old_type = initializedName_copy->get_type();
17393 printf ("Reset the type: initializedName_copy->set_type(new_type): old type = %p = %s new_type = %p = %s \n",old_type,old_type->class_name().c_str(),new_type,new_type->class_name().c_str());
17394#endif
17395 initializedName_copy->set_type(new_type);
17396 }
17397#if 0
17398 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
17399#endif
17400 SgFunctionParameterList* functionParameterList = isSgFunctionParameterList(enclosingStatement_copy);
17401 if (functionParameterList != NULL)
17402 {
17403 // The use of SgInitializedName in function parametes is handled differently then in other
17404 // locations in the AST (e.g. how the scope is set).
17405 // This is a function parameter and the scope is set to the SgFunctionDefinition if
17406 // this is for a defining function and the SgGlobal if it is a function prototype.
17407 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(functionParameterList->get_parent());
17408 ROSE_ASSERT(functionDeclaration != NULL);
17409 SgFunctionDefinition* functionDefinition = functionDeclaration->get_definition();
17410 if (functionDefinition != NULL)
17411 {
17412 ROSE_ASSERT(initializedName_copy->get_scope() == functionDefinition);
17413 // initializedName_copy->set_scope(functionDefinition);
17414 }
17415 else
17416 {
17417 SgGlobal* globalScope = isSgGlobal(functionDeclaration->get_scope());
17418 ROSE_ASSERT(globalScope != NULL);
17419 if (initializedName_copy->get_scope() != globalScope)
17420 {
17421#if 0
17422 printf ("Reset scope for initializedName_copy = %p = %s \n",initializedName_copy,initializedName_copy->get_name().str());
17423#endif
17424 initializedName_copy->set_scope(globalScope);
17425 }
17426 ROSE_ASSERT(initializedName_copy->get_scope() == globalScope);
17427 }
17428 }
17429 else
17430 {
17431#if 0
17432 printf ("initializedName_copy->get_scope() = %p = %s \n",initializedName_copy->get_scope(),initializedName_copy->get_scope()->class_name().c_str());
17433#endif
17434 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(enclosingStatement_copy);
17435 if (enumDeclaration != NULL)
17436 {
17437 // The case of enum declarations is special because the associated SgInitializedName IR nodes has a scope
17438 // that is external to the SgEnumDeclaration (in the scope of the SgEnumDeclaration). The typical case in C
17439 // is that the enum declaration is in global scope and then the enum fields (represented by SgInitializedName
17440 // objects) are have their associated symbol in the global scope.
17441
17442 // We have to use the name to search for the symbol instead of the pointer value of the initializedName_copy
17443 // (since the original symbol was associated with initializedName_original).
17444 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
17445 SgName name = initializedName_copy->get_name();
17446 SgSymbol* symbol = initializedName_copy->get_scope()->lookup_enum_field_symbol(name);
17447 ROSE_ASSERT(symbol != NULL);
17448
17449 SgEnumFieldSymbol* enumFieldSymbol = isSgEnumFieldSymbol(symbol);
17450 ROSE_ASSERT(enumFieldSymbol != NULL);
17451
17452 // DQ (3/17/2014): Build a new sysmbol to for the initializedName_copy instead of reusing the existing symbol
17453 // from the snippet AST.
17454 SgEnumFieldSymbol* new_enumFieldSymbol = new SgEnumFieldSymbol(initializedName_copy);
17455 ROSE_ASSERT(new_enumFieldSymbol != NULL);
17456
17457 // targetScope->insert_symbol(name,enumFieldSymbol);
17458 targetScope->insert_symbol(name,new_enumFieldSymbol);
17459
17460 // DQ (3/6/2014): Set the scope of the SgInitializedName IR node.
17461 initializedName_copy->set_scope(targetScope);
17462#if 0
17463 printf ("Exiting as a test! \n");
17464 ROSE_ABORT();
17465#endif
17466 }
17467 else
17468 {
17469#if 0
17470 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
17471#endif
17472 SgCatchOptionStmt* catchOptionStatement = isSgCatchOptionStmt(enclosingStatement_copy->get_parent());
17473 if (catchOptionStatement != NULL)
17474 {
17475 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(enclosingStatement_copy);
17476 ROSE_ASSERT(variableDeclaration != NULL);
17477
17478 // SgSymbol* symbol = targetScope->lookup_variable_symbol(initializedName_copy->get_name());
17479 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(initializedName_original);
17480 ROSE_ASSERT(enclosingStatement_original != NULL);
17481 SgCatchOptionStmt* catchOptionStatement_original = isSgCatchOptionStmt(enclosingStatement_original->get_parent());
17482
17483 // SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),targetScope);
17484 SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),catchOptionStatement_original);
17485 if (symbol == NULL)
17486 {
17487 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
17488 // initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
17489 }
17490 ROSE_ASSERT(symbol != NULL);
17491
17492 initializedName_copy->set_scope(targetScope);
17493
17494 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
17495 ROSE_ASSERT(new_variableSymbol != NULL);
17496
17497 // DQ (3/19/2014): I am not certain this is the correct location to insert this symbol.
17498 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
17499 }
17500 else
17501 {
17502 // DQ (3/29/2014): Adding support for SgInitializedName IR nodes found in a SgJavaForEachStatement.
17503 SgJavaForEachStatement* javaForEachStatement = isSgJavaForEachStatement(enclosingStatement_copy->get_parent());
17504 if (javaForEachStatement != NULL)
17505 {
17506 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(enclosingStatement_copy);
17507 ROSE_ASSERT(variableDeclaration != NULL);
17508
17509 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(initializedName_original);
17510 ROSE_ASSERT(enclosingStatement_original != NULL);
17511 SgJavaForEachStatement* javaForEachStatement_original = isSgJavaForEachStatement(enclosingStatement_original->get_parent());
17512
17513 SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),javaForEachStatement_original);
17514 if (symbol == NULL)
17515 {
17516 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
17517 // initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
17518 }
17519 ROSE_ASSERT(symbol != NULL);
17520
17521 initializedName_copy->set_scope(targetScope);
17522
17523 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
17524 ROSE_ASSERT(new_variableSymbol != NULL);
17525
17526 // DQ (3/29/2014): I am not certain this is the correct location to insert this symbol.
17527 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
17528#if 0
17529 printf ("Need to handle case of SgJavaForEachStatement \n");
17530 ROSE_ABORT();
17531#endif
17532 }
17533 else
17534 {
17535 // Case of non-SgFunctionParameterList and non-SgEnumDeclaration use of SgInitializedName in AST.
17536 SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
17537 if (symbol == NULL)
17538 {
17539 printf ("ERROR: enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
17540 ROSE_ASSERT(enclosingStatement_copy->get_parent() != NULL);
17541 printf ("ERROR: enclosingStatement_copy->get_parent() = %p = %s \n",enclosingStatement_copy->get_parent(),enclosingStatement_copy->get_parent()->class_name().c_str());
17542 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
17543 initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
17544
17545 // DQ (3/30/2014): Add this appraoch to find the symbol.
17546 SgScopeStatement* initializedName_copy_scope = isSgScopeStatement(initializedName_copy->get_scope());
17547 ROSE_ASSERT(initializedName_copy_scope != NULL);
17548 SgVariableSymbol* variableSymbol = initializedName_copy_scope->lookup_variable_symbol(initializedName_copy->get_name());
17549 ROSE_ASSERT(variableSymbol != NULL);
17550
17551 symbol = variableSymbol;
17552 }
17553 ROSE_ASSERT(symbol != NULL);
17554
17555 SgVariableSymbol* variableSymbol = isSgVariableSymbol(symbol);
17556 ROSE_ASSERT(variableSymbol != NULL);
17557#if 0
17558 printf ("Insert symbol = %p for initializedName_copy = %p = %s into targetScope = %p = %s \n",variableSymbol,initializedName_copy,initializedName_copy->get_name().str(),targetScope,targetScope->class_name().c_str());
17559#endif
17560 // DQ (3/17/2014): Build a new sysmbol to for the initializedName_copy instead of reusing the existing symbol
17561 // from the snippet AST.
17562 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
17563 ROSE_ASSERT(new_variableSymbol != NULL);
17564
17565 // targetScope->insert_symbol(initializedName_copy->get_name(),variableSymbol);
17566 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
17567
17568 // DQ (3/6/2014): Set the scope of the SgInitializedName IR node.
17569 initializedName_copy->set_scope(targetScope);
17570
17571 SgName mangledName = variableSymbol->get_mangled_name();
17572#if 0
17573 printf ("initializedName_copy: mangledName = %s \n",mangledName.str());
17574#endif
17575 // DQ (3/2/2014): Make sure this is true (I think it should be, but I don't see that it was explicitly set).
17576 // ROSE_ASSERT(initializedName_copy->get_scope() == targetScope);
17577 if (initializedName_copy->get_scope() != targetScope)
17578 {
17579 printf ("WARNING: initializedName_copy->get_scope() != targetScope: initializedName_copy->get_scope() = %p = %s \n",initializedName_copy->get_scope(),initializedName_copy->get_scope()->class_name().c_str());
17580
17581 printf ("I think this should be an error! \n");
17582 ROSE_ABORT();
17583 }
17584 }
17585 }
17586 }
17587 }
17588
17589 break;
17590 }
17591
17592 case V_SgVariableDeclaration:
17593 {
17594 // I think there is nothing to handle for this case (there is no type accessbile here
17595 // since they are in the SgInitializedName IR nodes).
17596 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(node_copy);
17597 ROSE_ASSERT(variableDeclaration != NULL);
17598
17599 break;
17600 }
17601
17602#define DEBUG_FUNCTION_DECLARATION 0
17603
17604 case V_SgFunctionDeclaration:
17605 {
17606 // SgFunctionDeclaration is handled directly in the snippet support (insertRelatedThingsForC() function).
17607
17608 // Note that function types are stored in global type tables so they need not be fixed up.
17609
17610 // DQ (3/13/2014): As of today, this assumption is no longer true, we need to be able to insert
17611 // any function declaration in insertRelatedThingsForC() and use this function to fixup the AST.
17612 // The target AST should have a prototype (non-defining declaration) of the function defined
17613 // so that all internal types of the SgFunctionType are defined in the target AST.
17614 SgFunctionDeclaration* functionDeclaration_copy = isSgFunctionDeclaration(node_copy);
17615 SgFunctionDeclaration* functionDeclaration_original = isSgFunctionDeclaration(node_original);
17616 SgFunctionType* functionType_copy = functionDeclaration_copy->get_type();
17617 SgFunctionType* functionType_original = functionDeclaration_original->get_type();
17618 ROSE_ASSERT(functionType_copy != NULL);
17619 ROSE_ASSERT(functionType_original != NULL);
17620 ROSE_ASSERT(functionType_copy == functionType_original);
17621#if DEBUG_FUNCTION_DECLARATION
17622 printf ("case SgFunctionDeclaration: part 1: Calling functionDeclaration_copy->search_for_symbol_from_symbol_table() \n");
17623#endif
17624 // SgSymbol* symbol_copy = functionDeclaration_copy->search_for_symbol_from_symbol_table();
17625 SgSymbol* symbol_original = functionDeclaration_original->search_for_symbol_from_symbol_table();
17626 ROSE_ASSERT(symbol_original != NULL);
17627 SgFunctionSymbol* functionSymbol_original = isSgFunctionSymbol(symbol_original);
17628 ROSE_ASSERT(functionSymbol_original != NULL);
17629
17630 SgFile* snippetFile = getEnclosingFileNode(functionSymbol_original);
17631 ROSE_ASSERT(snippetFile != NULL);
17632 if (snippetFile != targetFile)
17633 {
17634#if DEBUG_FUNCTION_DECLARATION
17635 printf ("Warning: case V_SgFunctionDeclaration: functionSymbol_original not in target file \n");
17636#endif
17637 // DQ (3/13/2014): Handle the case of a member function seperately (I think this can't appear in Java, only in C++).
17638 // ROSE_ASSERT(isSgMemberFunctionSymbol(symbol_copy) == NULL);
17639 ROSE_ASSERT(isSgMemberFunctionSymbol(symbol_original) == NULL);
17640
17641 // printf ("case SgFunctionDeclaration: part 2: Calling functionDeclaration_copy->search_for_symbol_from_symbol_table() \n");
17642 // SgFunctionSymbol* functionSymbol_copy = isSgFunctionSymbol(functionDeclaration_copy->search_for_symbol_from_symbol_table());
17643 // ROSE_ASSERT(functionSymbol_copy != NULL);
17644
17645 SgName name = functionDeclaration_copy->get_name();
17646 SgType* functionType = functionDeclaration_copy->get_type();
17647 ROSE_ASSERT(functionType != NULL);
17648#if DEBUG_FUNCTION_DECLARATION
17649 printf ("case V_SgFunctionDeclaration: name = %s \n",name.str());
17650 printf ("case V_SgFunctionDeclaration: functionType = %p \n",functionType);
17651 printf ("case V_SgFunctionDeclaration: functionType_original = %p \n",functionType_original);
17652 printf ("case V_SgFunctionDeclaration: functionType_copy = %p \n",functionType_copy);
17653#endif
17654 SgFunctionSymbol* functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,functionType,targetScope);
17655
17656 ROSE_ASSERT(targetScope != NULL);
17657 functionDeclaration_copy->set_scope(targetScope);
17658
17659 // Set the scope of the non-defining declaration.
17660 functionDeclaration_copy->get_firstNondefiningDeclaration()->set_scope(targetScope);
17661
17662 SgFunctionDeclaration* functionDeclaration_copy_firstNondefining = NULL;
17663
17664 if (functionSymbolInTargetAST == NULL)
17665 {
17666#if DEBUG_FUNCTION_DECLARATION
17667 printf ("functionSymbolInTargetAST not found in targetScope = %p = %s \n",targetScope,targetScope->class_name().c_str());
17668#endif
17669 // If could be that the symbol is in the local scope of the snippet AST.
17670 SgScopeStatement* otherPossibleScope = isSgScopeStatement(functionDeclaration_original->get_parent());
17671 ROSE_ASSERT(otherPossibleScope != NULL);
17672#if DEBUG_FUNCTION_DECLARATION
17673 printf ("case V_SgFunctionDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope,otherPossibleScope->class_name().c_str());
17674#endif
17675 // We want to out serch the additional other scope and not it's parent scope.
17676 // functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,functionType,otherPossibleScope);
17677 functionSymbolInTargetAST = otherPossibleScope->lookup_function_symbol(name,functionType);
17678
17679 if (functionSymbolInTargetAST == NULL)
17680 {
17681 printf ("function symbol not found in otherPossibleScope = %p = %s \n",otherPossibleScope,otherPossibleScope->class_name().c_str());
17682 }
17683
17684 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17685#if DEBUG_FUNCTION_DECLARATION
17686 printf ("(building a new SgFunctionSymbol): functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17687#endif
17688 // DQ (3/15/2014): We need to insert a new symbol into the targetScope instead of reusing
17689 // the existing symbol (because it points to the declaration in the snippet file).
17690 // Insert the symbol into the targetScope.
17691 // targetScope->insert_symbol(name,functionSymbolInTargetAST);
17692 functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionDeclaration_copy->get_firstNondefiningDeclaration());
17693 SgFunctionSymbol* new_symbol = new SgFunctionSymbol(functionDeclaration_copy_firstNondefining);
17694 ROSE_ASSERT(new_symbol != NULL);
17695
17696 targetScope->insert_symbol(name,new_symbol);
17697
17698 functionSymbolInTargetAST = new_symbol;
17699
17700 // DQ (3/26/2014): Added assertion.
17701 ROSE_ASSERT(lookupFunctionSymbolInParentScopes(name,functionType,targetScope) != NULL);
17702 }
17703 else
17704 {
17705 // If we happend to find an associated symbol in the target scope then we nave to use it and
17706 // set the first nondefining declaration pointer to the symbol's associate declaration.
17707 // This is the case of the test3a test code (because the snippet functions declaration is
17708 // in the target AST file (likely a mistake, but we should handle it properly).
17709#if DEBUG_FUNCTION_DECLARATION
17710 printf ("(using existing symbol found in target scope): functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17711#endif
17712 functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
17713 }
17714
17715 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17716
17717 ROSE_ASSERT(functionDeclaration_copy->get_firstNondefiningDeclaration() != NULL);
17718 ROSE_ASSERT(functionDeclaration_copy_firstNondefining != NULL);
17719
17720 // SgFunctionDeclaration* functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionDeclaration_copy->get_firstNondefiningDeclaration());
17721 SgFunctionDeclaration* functionDeclaration_original_firstNondefining = isSgFunctionDeclaration(functionDeclaration_original->get_firstNondefiningDeclaration());
17722 SgFunctionDeclaration* functionDeclaration_copy_defining = isSgFunctionDeclaration(functionDeclaration_copy->get_definingDeclaration());
17723 SgFunctionDeclaration* functionDeclaration_original_defining = isSgFunctionDeclaration(functionDeclaration_original->get_definingDeclaration());
17724 if (functionDeclaration_copy_firstNondefining->get_symbol_from_symbol_table() == NULL)
17725 {
17726 // Check what might be wrong here!
17727 ROSE_ASSERT(functionDeclaration_original_firstNondefining != NULL);
17728 printf ("functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17729
17730 printf ("functionDeclaration_original = %p = %s \n",functionDeclaration_original,functionDeclaration_original->class_name().c_str());
17731 printf ("functionDeclaration_copy = %p = %s \n",functionDeclaration_copy,functionDeclaration_copy->class_name().c_str());
17732 printf ("functionDeclaration_original_firstNondefining = %p \n",functionDeclaration_original_firstNondefining);
17733 printf ("functionDeclaration_copy_firstNondefining = %p \n",functionDeclaration_copy_firstNondefining);
17734 printf ("functionDeclaration_original_defining = %p \n",functionDeclaration_original_defining);
17735 printf ("functionDeclaration_copy_defining = %p \n",functionDeclaration_copy_defining);
17736
17737 printf ("functionDeclaration_original->get_scope() = %p = %s \n",functionDeclaration_original->get_scope(),functionDeclaration_original->get_scope()->class_name().c_str());
17738 printf ("functionDeclaration_copy->get_scope() = %p = %s \n",functionDeclaration_copy->get_scope(),functionDeclaration_copy->get_scope()->class_name().c_str());
17739 printf ("functionDeclaration_original_firstNondefining->get_scope() = %p = %s \n",functionDeclaration_original_firstNondefining->get_scope(),functionDeclaration_original_firstNondefining->get_scope()->class_name().c_str());
17740 printf ("functionDeclaration_copy_firstNondefining->get_scope() = %p = %s \n",functionDeclaration_copy_firstNondefining->get_scope(),functionDeclaration_copy_firstNondefining->get_scope()->class_name().c_str());
17741 printf ("functionDeclaration_original_defining->get_scope() = %p = %s \n",functionDeclaration_original_defining->get_scope(),functionDeclaration_original_defining->get_scope()->class_name().c_str());
17742 printf ("functionDeclaration_copy_defining->get_scope() = %p = %s \n",functionDeclaration_copy_defining->get_scope(),functionDeclaration_copy_defining->get_scope()->class_name().c_str());
17743 printf ("functionSymbolInTargetAST = %p = %s \n",functionSymbolInTargetAST,functionSymbolInTargetAST->class_name().c_str());
17744 }
17745
17746 ROSE_ASSERT(targetScope->lookup_function_symbol(name,functionType) != NULL);
17747
17748 // TV (10/22/2014): Might not be the case as we now have a project wide global scope
17749 // ROSE_ASSERT(functionDeclaration_copy_firstNondefining->get_scope() == targetScope);
17750
17751 ROSE_ASSERT(functionDeclaration_copy_firstNondefining == functionDeclaration_copy_firstNondefining->get_firstNondefiningDeclaration());
17752
17753 // This is what is called internal to the get_symbol_from_symbol_table() function below.
17754 // Use this function, SgFunctionDeclaration::get_symbol_from_symbol_table(), but not the template function: find_symbol_from_declaration().
17755 // ROSE_ASSERT(targetScope->find_symbol_from_declaration(functionDeclaration_copy_firstNondefining) != NULL);
17756
17757 ROSE_ASSERT(functionDeclaration_copy_firstNondefining->get_symbol_from_symbol_table() != NULL);
17758
17759#if 0
17760 bool isDefiningDeclaration (functionDeclaration_original->get_declaration() != NULL);
17761 if (isDefiningDeclaration == true)
17762 {
17763 // We may have to build a non-defining declaration.
17764 SgFunctionDeclaration* nondefiningFunctionDeclaration_original = functionDeclaration_original->get_firstNondefiningDeclaration();
17765 SgFile* nondefiningDeclarationFile = getEnclosingFileNode(functionSymbol_original);
17766 ROSE_ASSERT(nondefiningDeclarationFile != NULL);
17767 if (nondefiningDeclarationFile == targetFile)
17768 {
17769 // Use this nondefining declaration.
17770 }
17771 else
17772 {
17773 // Make a copy of the non-defining declaration for use in the symbol.
17774 }
17775
17776 }
17777 else
17778 {
17779 // Use this as non-defining declaration.
17780 }
17781
17782 SgFile* snippetFile = getEnclosingFileNode(functionSymbol_original);
17783 SgFunctionSymbol* new_function_symbol = new SgFunctionSymbol(isSgFunctionDeclaration(func));
17784 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
17785 targetScope->insert_symbol(name,symbol_original);
17786
17787 ROSE_ABORT();
17788#endif
17789 }
17790
17791 // DQ (3/17/2014): Refactored code to support resetting the scopes in the SgDeclarationStatement IR nodes.
17792 resetDeclaration(functionDeclaration_copy,functionDeclaration_original,targetScope);
17793#if 0
17794 printf ("SageBuilder::fixupCopyOfNodeFromSeperateFileInNewTargetAst(): Need to be able to fixup the SgFunctionDeclaration \n");
17795 ROSE_ABORT();
17796#endif
17797 break;
17798 }
17799
17800 case V_SgClassDeclaration:
17801 {
17802 // Need to handle the referenced types
17803 SgClassDeclaration* classDeclaration_copy = isSgClassDeclaration(node_copy);
17804 SgClassDeclaration* classDeclaration_original = isSgClassDeclaration(node_original);
17805 SgClassType* classType = classDeclaration_copy->get_type();
17806 ROSE_ASSERT(classType != NULL);
17807#if 0
17808 printf ("Need to handle named types from class declarations \n");
17809#endif
17810 // SgClassSymbol* classSymbol_copy = isSgClassSymbol(classDeclaration_copy->search_for_symbol_from_symbol_table());
17811 // ROSE_ASSERT(classSymbol_copy != NULL);
17812
17813 // if (TransformationSupport::getFile(classSymbol_copy) != targetFile)
17814 // if (getEnclosingFileNode(classSymbol_copy) != targetFile)
17815 // if (getEnclosingFileNode(classDeclaration_copy) != targetFile)
17816 {
17817 // printf ("Warning: case V_SgClassDeclaration: classSymbol_copy not in target file \n");
17818#if 0
17819 printf ("Warning: case V_SgClassDeclaration: assume getEnclosingFileNode(classDeclaration_copy) != targetFile \n");
17820#endif
17821 // Find the symbol in the target scope.
17822 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17823#if 0
17824 // printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
17825#endif
17826 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
17827
17828 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17829 // ROSE_ASSERT(targetScope != NULL);
17830
17831 SgName name = classDeclaration_copy->get_name();
17832#if 0
17833 // If we randomize the names then we need to handle this case...
17834 printf ("case V_SgClassDeclaration: targetScope = %p classSymbol_copy->get_name() = %s \n",targetScope,classSymbol_copy->get_name().str());
17835#endif
17836 // SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classSymbol_copy->get_name(),targetScope);
17837 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(name,targetScope);
17838
17839 if (classSymbolInTargetAST == NULL)
17840 {
17841 // If could be that the symbol is in the local scope of the snippet AST.
17842 SgScopeStatement* otherPossibleScope = isSgScopeStatement(classDeclaration_original->get_parent());
17843 ROSE_ASSERT(otherPossibleScope != NULL);
17844#if 0
17845 printf ("case V_SgClassDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
17846#endif
17847 // classSymbolInTargetAST = lookupClassSymbolInParentScopes(classSymbol_copy->get_name(),otherPossibleScope);
17848 classSymbolInTargetAST = lookupClassSymbolInParentScopes(name,otherPossibleScope);
17849 ROSE_ASSERT(classSymbolInTargetAST != NULL);
17850#if 0
17851 // I think this is the wrong code.
17852 SgClassDeclaration* classDeclaration = classSymbolInTargetAST->get_declaration();
17853 ROSE_ASSERT(classDeclaration != NULL);
17854 SgScopeStatement* scope = classDeclaration->get_scope();
17855 ROSE_ASSERT(scope != NULL);
17856 classDeclaration_copy->set_scope(scope);
17857#else
17858 // DQ (3/17/2014): The scope must be set to be the targetScope (at least for C, but maybe not C++).
17859 classDeclaration_copy->set_scope(targetScope);
17860#endif
17861 // DQ (3/17/2014): Build a new SgClassSymbol using the classDeclaration_copy.
17862 SgClassSymbol* classSymbol = new SgClassSymbol(classDeclaration_copy);
17863 ROSE_ASSERT(classSymbol != NULL);
17864 classSymbolInTargetAST = classSymbol;
17865
17866 // Insert the symbol into the targetScope.
17867 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
17868 targetScope->insert_symbol(name,classSymbolInTargetAST);
17869 }
17870 else
17871 {
17872 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
17873 SgClassDeclaration* classDeclaration = classSymbolInTargetAST->get_declaration();
17874 ROSE_ASSERT(classDeclaration != NULL);
17875 SgScopeStatement* scope = classDeclaration->get_scope();
17876 ROSE_ASSERT(scope != NULL);
17877 classDeclaration_copy->set_scope(scope);
17878 }
17879
17880 ROSE_ASSERT(classSymbolInTargetAST != NULL);
17881 }
17882
17883 // DQ (3/17/2014): Avoid calling strip type now that we have refactored the getTargetFileType() function.
17884 // DQ (3/10/2014): Added remaining type for this case.
17885 // SgType* new_type = getTargetFileType(classType->stripType(),targetScope);
17886 SgType* new_type = getTargetFileType(classType,targetScope);
17887 SgClassType* new_class_type = isSgClassType(new_type);
17888 if (new_class_type != NULL)
17889 {
17890 // Reset the base type to be the one associated with the target file.
17891 classDeclaration_copy->set_type(new_class_type);
17892#if 0
17893 printf ("case V_SgClassDeclaration: built class type: part 1: classDeclaration_copy->get_type() = %p = %s \n",
17894 classDeclaration_copy->get_type(),classDeclaration_copy->get_type()->class_name().c_str());
17895#endif
17896 }
17897
17898 resetDeclaration(classDeclaration_copy,classDeclaration_original,targetScope);
17899#if 0
17900 printf ("SgClassDeclaration: Exiting as a test! \n");
17901 ROSE_ABORT();
17902#endif
17903 break;
17904 }
17905
17906 case V_SgEnumDeclaration:
17907 {
17908 // Need to handle the referenced types
17909 SgEnumDeclaration* enumDeclaration_copy = isSgEnumDeclaration(node_copy);
17910 SgEnumDeclaration* enumDeclaration_original = isSgEnumDeclaration(node_original);
17911
17912 // SgEnumType* enumType = enumDeclaration_copy->get_type();
17913 // ROSE_ASSERT(enumType != NULL);
17914
17915 // I don't think we have to test for this being a part of the snippet file.
17916 {
17917 SgName name = enumDeclaration_copy->get_name();
17918#if 0
17919 // If we randomize the names then we need to handle this case...
17920 printf ("case V_SgEnumDeclaration: targetScope = %p enumSymbol_copy->get_name() = %s \n",targetScope,name.str());
17921#endif
17922 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(name,targetScope);
17923
17924 if (enumSymbolInTargetAST == NULL)
17925 {
17926 // If could be that the symbol is in the local scope of the snippet AST.
17927 SgScopeStatement* otherPossibleScope = isSgScopeStatement(enumDeclaration_original->get_parent());
17928 ROSE_ASSERT(otherPossibleScope != NULL);
17929#if 0
17930 printf ("case V_SgEnumDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
17931#endif
17932 // I think we are not looking in the correct scope! Or else we need to also look in the target global scope.
17933#if 0
17934 printf ("Since the symbol has not been inserted yet, what symbol are we looking for? \n");
17935#endif
17936 enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(name,otherPossibleScope);
17937
17938 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
17939 SgEnumDeclaration* enumDeclaration = enumSymbolInTargetAST->get_declaration();
17940 ROSE_ASSERT(enumDeclaration != NULL);
17941
17942 ROSE_ASSERT(enumDeclaration != enumDeclaration_original);
17943
17944 // This is true, so we need to build a new sysmbol.
17945 ROSE_ASSERT(enumSymbolInTargetAST->get_declaration() == enumDeclaration_original->get_firstNondefiningDeclaration());
17946
17947 // Build a new SgEnumSymbol using the enumDeclaration_copy.
17948 SgEnumSymbol* enumSymbol = new SgEnumSymbol(enumDeclaration_copy);
17949 ROSE_ASSERT(enumSymbol != NULL);
17950 enumSymbolInTargetAST = enumSymbol;
17951
17952 // If this is false then we need to build a new SgEnumSymbol rather than reusing the existing one.
17953 ROSE_ASSERT(enumSymbolInTargetAST->get_declaration() != enumDeclaration_original->get_firstNondefiningDeclaration());
17954
17955 // SgScopeStatement* scope = enumDeclaration->get_scope();
17956 SgScopeStatement* scope = targetScope;
17957 ROSE_ASSERT(scope != NULL);
17958 enumDeclaration_copy->set_scope(scope);
17959#if 0
17960 printf ("case V_SgEnumDeclaration: insert_symbol(): name = %s enumSymbolInTargetAST = %p \n",name.str(),enumSymbolInTargetAST);
17961#endif
17962 // Insert the symbol into the targetScope.
17963 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
17964 targetScope->insert_symbol(name,enumSymbolInTargetAST);
17965 }
17966 else
17967 {
17968#if 0
17969 printf ("Found an existing enum declaration: name = %s enumSymbolInTargetAST = %p \n",name.str(),enumSymbolInTargetAST);
17970#endif
17971 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
17972 SgEnumDeclaration* enumDeclaration = enumSymbolInTargetAST->get_declaration();
17973 ROSE_ASSERT(enumDeclaration != NULL);
17974#if 0
17975 SgScopeStatement* scope = enumDeclaration->get_scope();
17976 ROSE_ASSERT(scope != NULL);
17977 ROSE_ASSERT(scope == targetScope);
17978 // enumDeclaration_copy->set_scope(scope);
17979#else
17980 // TV (10/22/2014): Might not be the case as we now have a project wide global scope
17981 // ROSE_ASSERT(enumDeclaration->get_scope() == targetScope);
17982#endif
17983 }
17984
17985 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
17986 }
17987#if 0
17988 printf ("Exiting as a test 1! \n");
17989 ROSE_ABORT();
17990#endif
17991 SgEnumType* enumType = enumDeclaration_copy->get_type();
17992 ROSE_ASSERT(enumType != NULL);
17993 SgType* new_type = getTargetFileType(enumType,targetScope);
17994#if 0
17995 printf ("Return type from getTargetFileType(): original enumType = %p new_type = %p \n",enumType,new_type);
17996#endif
17997 SgEnumType* new_enum_type = isSgEnumType(new_type);
17998 if (new_enum_type != NULL)
17999 {
18000 // Reset the base type to be the one associated with the target file.
18001#if 0
18002 printf ("reset the type using the new enum type from the target AST \n");
18003#endif
18004 enumDeclaration_copy->set_type(new_enum_type);
18005 }
18006#if 0
18007 printf ("Exiting as a test 2! \n");
18008 ROSE_ABORT();
18009#endif
18010
18011 resetDeclaration(enumDeclaration_copy,enumDeclaration_original,targetScope);
18012 break;
18013 }
18014
18015 // This is not a required declaration of C.
18016 case V_SgTemplateClassDeclaration:
18017 {
18018 // Need to handle the referenced types
18019 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(node_copy);
18020 SgClassType* templateClassType = templateClassDeclaration->get_type();
18021 ROSE_ASSERT(templateClassType != NULL);
18022
18023 // DQ (3/10/2014): Added support for enum types.
18024 SgType* new_type = getTargetFileType(templateClassType,targetScope);
18025 SgClassType* new_templateClass_type = isSgClassType(new_type);
18026 if (new_templateClass_type != NULL)
18027 {
18028 // Reset the base type to be the one associated with the target file.
18029 templateClassDeclaration->set_type(new_templateClass_type);
18030#if 0
18031 printf ("case V_SgTemplateClassDeclaration: built class type: part 1: templateClassDeclaration->get_type() = %p = %s \n",
18032 templateClassDeclaration->get_type(),templateClassDeclaration->get_type()->class_name().c_str());
18033#endif
18034 }
18035
18036 break;
18037 }
18038
18039 case V_SgTypedefDeclaration:
18040 {
18041 // Need to handle the referenced types (there are two for the case of a SgTypedefDeclaration).
18042 SgTypedefDeclaration* typedefDeclaration_copy = isSgTypedefDeclaration(node_copy);
18043 SgTypedefDeclaration* typedefDeclaration_original = isSgTypedefDeclaration(node_original);
18044
18045 SgType* base_type = typedefDeclaration_copy->get_base_type();
18046 ROSE_ASSERT(base_type != NULL);
18047 SgType* new_base_type = getTargetFileType(base_type,targetScope);
18048 if (new_base_type != NULL)
18049 {
18050 // Reset the base type to be the one associated with the target file.
18051 typedefDeclaration_copy->set_base_type(new_base_type);
18052 }
18053
18054 // I don't think we have to test for this being a part of the snippet file.
18055 {
18056 SgName name = typedefDeclaration_copy->get_name();
18057#if 0
18058 // If we randomize the names then we need to handle this case...
18059 printf ("case V_SgTypedefDeclaration: targetScope = %p typedefSymbol_copy->get_name() = %s \n",targetScope,name.str());
18060#endif
18061 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(name,targetScope);
18062
18063 if (typedefSymbolInTargetAST == NULL)
18064 {
18065 // If could be that the symbol is in the local scope of the snippet AST.
18066 SgScopeStatement* otherPossibleScope = isSgScopeStatement(typedefDeclaration_original->get_parent());
18067 ROSE_ASSERT(otherPossibleScope != NULL);
18068#if 0
18069 printf ("case V_SgTypedefDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
18070#endif
18071 typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(name,otherPossibleScope);
18072
18073 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
18074 SgTypedefDeclaration* typedefDeclaration = typedefSymbolInTargetAST->get_declaration();
18075 ROSE_ASSERT(typedefDeclaration != NULL);
18076 // SgScopeStatement* scope = typedefDeclaration->get_scope();
18077 SgScopeStatement* scope = targetScope;
18078 ROSE_ASSERT(scope != NULL);
18079 typedefDeclaration_copy->set_scope(scope);
18080
18081 // DQ (3/17/2014): Build a new SgTypedefSymbol using the typedefDeclaration_copy.
18082 SgTypedefSymbol* typedefSymbol = new SgTypedefSymbol(typedefDeclaration_copy);
18083 ROSE_ASSERT(typedefSymbol != NULL);
18084 typedefSymbolInTargetAST = typedefSymbol;
18085#if 0
18086 printf ("case V_SgTypedefDeclaration: insert_symbol(): name = %s typedefSymbolInTargetAST = %p \n",name.str(),typedefSymbolInTargetAST);
18087#endif
18088 // Insert the symbol into the targetScope.
18089 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
18090 targetScope->insert_symbol(name,typedefSymbolInTargetAST);
18091 }
18092 else
18093 {
18094#if 0
18095 printf ("Found an existing typedef declaration: name = %s typedefSymbolInTargetAST = %p \n",name.str(),typedefSymbolInTargetAST);
18096#endif
18097 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
18098 SgTypedefDeclaration* typedefDeclaration = typedefSymbolInTargetAST->get_declaration();
18099 ROSE_ASSERT(typedefDeclaration != NULL);
18100 SgScopeStatement* scope = typedefDeclaration->get_scope();
18101 ROSE_ASSERT(scope != NULL);
18102 typedefDeclaration_copy->set_scope(scope);
18103 }
18104
18105 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
18106 }
18107#if 0
18108 printf ("Exiting as a test 1! \n");
18109 ROSE_ABORT();
18110#endif
18111 SgTypedefType* typedefType = typedefDeclaration_copy->get_type();
18112 ROSE_ASSERT(typedefType != NULL);
18113 SgType* new_type = getTargetFileType(typedefType,targetScope);
18114 SgTypedefType* new_typedef_type = isSgTypedefType(new_type);
18115 if (new_typedef_type != NULL)
18116 {
18117 // Reset the base type to be the one associated with the target file.
18118#if 0
18119 printf ("reset the type using the new typedef type from the target AST \n");
18120#endif
18121 typedefDeclaration_copy->set_type(new_typedef_type);
18122#if 0
18123 printf ("case V_SgTypedefDeclaration: built class type: part 1: typedefDeclaration_copy->get_type() = %p = %s \n",
18124 typedefDeclaration_copy->get_type(),typedefDeclaration_copy->get_type()->class_name().c_str());
18125#endif
18126 }
18127
18128 resetDeclaration(typedefDeclaration_copy,typedefDeclaration_original,targetScope);
18129#if 0
18130 printf ("Exiting as a test 2! \n");
18131 ROSE_ABORT();
18132#endif
18133 break;
18134 }
18135
18136 case V_SgVarRefExp:
18137 {
18138 // Need to handle the referenced symbol.
18139 // but if we have handle this in the declaration for the variable (case V_SgInitializedName)
18140 // then we don't have to do anything here. However, we have only handled this variable
18141 // declaration if the variable declaration was a part of the snippet. If the variable
18142 // declaration is not a part of the original snippet (the copy of the snippet's AST that
18143 // we are inserting (not the snippet program where it would have to be defined for the
18144 // snippet to compile) then we have to find the associated variable sysmbol in the target
18145 // AST and reset the SgVarRefExp to use that symbol.
18146
18147 SgVarRefExp* varRefExp_copy = isSgVarRefExp(node_copy);
18148 SgVarRefExp* varRefExp_original = isSgVarRefExp(node_original);
18149 SgVariableSymbol* variableSymbol_copy = isSgVariableSymbol(varRefExp_copy->get_symbol());
18150 ROSE_ASSERT(variableSymbol_copy != NULL);
18151 // if (TransformationSupport::getFile(variableSymbol_copy) != targetFile)
18152 if (getEnclosingFileNode(variableSymbol_copy) != targetFile)
18153 {
18154#if 0
18155 printf ("Warning: case V_SgVarRefExp: variableSymbol not in target file: name = %s \n",variableSymbol_copy->get_name().str());
18156#endif
18157#if 0
18158 printf ("insertionPoint = %p = %s \n",insertionPoint,insertionPoint->class_name().c_str());
18159#endif
18160 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
18161#if 0
18162 // printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
18163#endif
18164 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
18165
18166 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
18167 // ROSE_ASSERT(targetScope != NULL);
18168
18169 SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),targetScope);
18170
18171 if (variableSymbolInTargetAST == NULL)
18172 {
18173 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
18174 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
18175 // previously added snippet.
18176#if 0
18177 printf ("Error: The associated variable = %s should have been found in a parent scope of the target AST \n",variableSymbol_copy->get_name().str());
18178#endif
18179 // We need to look into the scope of the block used to define the statments as seperate snippets (same issue as for functions).
18180
18181 // If could be that the symbol is in the local scope of the snippet AST.
18182 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(varRefExp_original);
18183 ROSE_ASSERT(enclosingStatement_original != NULL);
18184#if 0
18185 printf ("case V_SgVarRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
18186#endif
18187 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
18188 ROSE_ASSERT(otherPossibleScope_original != NULL);
18189 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
18190 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
18191 ROSE_ASSERT(file != NULL);
18192#if 0
18193 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
18194 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18195
18196 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
18197 printf ("case V_SgClassDeclaration: variableSymbol_copy->get_name() = %s \n",variableSymbol_copy->get_name().str());
18198#endif
18199 variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),otherPossibleScope_original);
18200 if (variableSymbolInTargetAST == NULL)
18201 {
18202#if 0
18203 targetScope->get_symbol_table()->print("targetScope: symbol table");
18204 otherPossibleScope_original->get_symbol_table()->print("otherPossibleScope_original: symbol table");
18205#endif
18206
18207 // Check for the case of a record reference (member of data structure).
18208 SgExpression* parentExpression = isSgExpression(varRefExp_copy->get_parent());
18209 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
18210 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
18211 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
18212 if (parentDotExp != NULL || parentArrowExp != NULL)
18213 {
18214 // This is a data member reference, so it's scope is the associated data structure.
18215 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
18216 ROSE_ASSERT(lhs != NULL);
18217 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == varRefExp_copy);
18218
18219 SgType* type = lhs->get_type();
18220 ROSE_ASSERT(type != NULL);
18221#if 0
18222 printf ("type = %p = %s \n",type,type->class_name().c_str());
18223#endif
18224 SgNamedType* namedType = isSgNamedType(type);
18225 ROSE_ASSERT(namedType != NULL);
18226 SgDeclarationStatement* declaration = namedType->get_declaration();
18227 ROSE_ASSERT(declaration != NULL);
18228 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
18229 ROSE_ASSERT(classDeclaration != NULL);
18230 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
18231 ROSE_ASSERT(definingClassDeclaration != NULL);
18232 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18233 ROSE_ASSERT(classDefinition != NULL);
18234#if 0
18235 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
18236#endif
18237 // I think we want the copy.
18238 otherPossibleScope_original = classDefinition;
18239
18240 variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),otherPossibleScope_original);
18241 }
18242
18243 }
18244 ROSE_ASSERT(variableSymbolInTargetAST != NULL);
18245 SgInitializedName* initializedName = variableSymbolInTargetAST->get_declaration();
18246 ROSE_ASSERT(initializedName != NULL);
18247 SgScopeStatement* scope = initializedName->get_scope();
18248 ROSE_ASSERT(scope != NULL);
18249
18250 // Is this the correct scope?
18251 initializedName->set_scope(scope);
18252
18253 // Insert the symbol into the targetScope.
18254 targetScope->insert_symbol(variableSymbol_copy->get_name(),variableSymbolInTargetAST);
18255 }
18256 ROSE_ASSERT(variableSymbolInTargetAST != NULL);
18257
18258 // Reset the symbol associated with this variable reference.
18259 varRefExp_copy->set_symbol(variableSymbolInTargetAST);
18260
18261 // printf ("Exiting as a test! \n");
18262 // ROSE_ASSERT(false);
18263 }
18264
18265 break;
18266 }
18267
18268 case V_SgFunctionRefExp:
18269 {
18270 // Need to handle the referenced symbol
18271 SgFunctionRefExp* functionRefExp_copy = isSgFunctionRefExp(node_copy);
18272 // SgFunctionRefExp* functionRefExp_original = isSgFunctionRefExp(node_original);
18273 SgFunctionSymbol* functionSymbol_copy = isSgFunctionSymbol(functionRefExp_copy->get_symbol());
18274 ROSE_ASSERT(functionSymbol_copy != NULL);
18275 // if (TransformationSupport::getFile(functionSymbol) != targetFile)
18276 if (getEnclosingFileNode(functionSymbol_copy) != targetFile)
18277 {
18278#if 0
18279 printf ("Warning: case V_SgFunctionRefExp: functionSymbol_copy not in target file (find function = %s) \n",functionSymbol_copy->get_name().str());
18280#endif
18281 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
18282#if 0
18283 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
18284#endif
18285 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
18286
18287 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
18288 // ROSE_ASSERT(targetScope != NULL);
18289
18290 SgName name = functionSymbol_copy->get_name();
18291
18292 // I think we need the function's mangled name to support this lookup.
18293 SgFunctionSymbol* functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,targetScope);
18294
18295 if (functionSymbolInTargetAST == NULL)
18296 {
18297 // DQ (3/17/2014): Revised as of further discussion about how the snippet mechanism will copy required
18298 // declaration from the snippet file to the target AST.
18299 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
18300 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
18301 // previously added snippet.
18302 // DQ (3/17/2014): After some revision of the specification for the snippet injection, this is still
18303 // an error since this is the case where a declaration should have been visible from having already been
18304 // inserted into the target AST and this visible from this injection point in the target AST.
18305
18306 fprintf (stderr, "Error: The associated function = \"%s\" should have been found in a parent scope"
18307 " of the target AST\n", name.str());
18308
18309 fprintf (stderr, " targetScope = %p = %s \n",targetScope,targetScope->class_name().c_str());
18310 SgGlobal* globalScope = TransformationSupport::getGlobalScope(targetScope);
18311 ROSE_ASSERT(globalScope != NULL);
18312 fprintf (stderr, " globalScope = %p = %s \n",globalScope,globalScope->class_name().c_str());
18313#if 0
18314 targetScope->get_file_info()->display("case V_SgFunctionRefExp: targetScope: debug");
18315 node_original->get_file_info()->display("case V_SgFunctionRefExp: node_original: debug");
18316#endif
18317#if 0
18318 // DQ (3/10/2014): This might be important for friend functions in C++ (but we can ignore it for now).
18319#error "DEAD CODE!"
18320 // If could be that the symbol is in the local scope of the snippet AST.
18321 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(functionRefExp_original);
18322 ROSE_ASSERT(enclosingStatement_original != NULL);
18323#if 0
18324 printf ("case V_SgFunctionRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
18325#endif
18326 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
18327 ROSE_ASSERT(otherPossibleScope_original != NULL);
18328 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
18329 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
18330 ROSE_ASSERT(file != NULL);
18331#if 0
18332 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
18333 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18334
18335 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
18336 printf ("case V_SgClassDeclaration: functionSymbol_copy->get_name() = %s \n",functionSymbol_copy->get_name().str());
18337#endif
18338 functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(functionSymbol_copy->get_name(),otherPossibleScope_original);
18339#error "DEAD CODE!"
18340 if (functionSymbolInTargetAST == NULL)
18341 {
18342 // Check for the case of a record reference (member function of class declaration).
18343 SgExpression* parentExpression = isSgExpression(functionRefExp_copy->get_parent());
18344 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
18345 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
18346 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
18347 if (parentDotExp != NULL || parentArrowExp != NULL)
18348 {
18349 // This is a data member reference, so it's scope is the associated data structure.
18350 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
18351 ROSE_ASSERT(lhs != NULL);
18352 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == functionRefExp_copy);
18353#error "DEAD CODE!"
18354 SgType* type = lhs->get_type();
18355 ROSE_ASSERT(type != NULL);
18356#if 0
18357 printf ("type = %p = %s \n",type,type->class_name().c_str());
18358#endif
18359 SgNamedType* namedType = isSgNamedType(type);
18360 ROSE_ASSERT(namedType != NULL);
18361 SgDeclarationStatement* declaration = namedType->get_declaration();
18362 ROSE_ASSERT(declaration != NULL);
18363 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
18364 ROSE_ASSERT(classDeclaration != NULL);
18365 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
18366 ROSE_ASSERT(definingClassDeclaration != NULL);
18367 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18368 ROSE_ASSERT(classDefinition != NULL);
18369#if 0
18370 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
18371#endif
18372 // I think we want the copy.
18373 otherPossibleScope_original = classDefinition;
18374
18375 functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(functionSymbol_copy->get_name(),otherPossibleScope_original);
18376 }
18377 }
18378
18379#error "DEAD CODE!"
18380 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
18381 SgFunctionDeclaration* functionDeclaration = functionSymbolInTargetAST->get_declaration();
18382 ROSE_ASSERT(functionDeclaration != NULL);
18383 SgScopeStatement* scope = functionDeclaration->get_scope();
18384 ROSE_ASSERT(scope != NULL);
18385
18386 // Is this the correct scope?
18387 functionDeclaration->set_scope(scope);
18388#endif
18389 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
18390
18391 // Insert the symbol into the targetScope.
18392 targetScope->insert_symbol(functionSymbol_copy->get_name(),functionSymbolInTargetAST);
18393 }
18394 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
18395
18396 // Reset the symbol associated with this function reference.
18397 functionRefExp_copy->set_symbol(functionSymbolInTargetAST);
18398#if 0
18399 printf ("Exiting as a test! \n");
18400 ROSE_ABORT();
18401#endif
18402 }
18403
18404 break;
18405 }
18406
18407#define DEBUG_MEMBER_FUNCTION_REF_EXP 0
18408
18409 case V_SgMemberFunctionRefExp:
18410 {
18411 // Need to handle the referenced symbol
18412 SgMemberFunctionRefExp* memberFunctionRefExp_copy = isSgMemberFunctionRefExp(node_copy);
18413 SgMemberFunctionRefExp* memberFunctionRefExp_original = isSgMemberFunctionRefExp(node_original);
18414 SgMemberFunctionSymbol* memberFunctionSymbol_copy = isSgMemberFunctionSymbol(memberFunctionRefExp_copy->get_symbol());
18415 ROSE_ASSERT(memberFunctionSymbol_copy != NULL);
18416 // if (TransformationSupport::getFile(memberFunctionSymbol) != targetFile)
18417 if (getEnclosingFileNode(memberFunctionSymbol_copy) != targetFile)
18418 {
18419 // Not implemented (initial work is focused on C, then Java, then C++.
18420#if DEBUG_MEMBER_FUNCTION_REF_EXP
18421 printf ("Warning: case V_SgMemberFunctionRefExp: memberFunctionSymbol_copy not in target file (find member function = %s) \n",memberFunctionSymbol_copy->get_name().str());
18422#endif
18423 SgMemberFunctionSymbol* memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),targetScope));
18424
18425 if (memberFunctionSymbolInTargetAST == NULL)
18426 {
18427 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
18428 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
18429 // previously added snippet.
18430#if DEBUG_MEMBER_FUNCTION_REF_EXP
18431 printf ("Error: The associated memberFunction_copy = %s should have been found in a parent scope of the target AST \n",memberFunctionSymbol_copy->get_name().str());
18432#endif
18433 // DQ (3/10/2014): This is important for member functions in Java and C++.
18434
18435 // If could be that the symbol is in the local scope of the snippet AST.
18436 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(memberFunctionRefExp_original);
18437 ROSE_ASSERT(enclosingStatement_original != NULL);
18438#if DEBUG_MEMBER_FUNCTION_REF_EXP
18439 printf ("case V_SgMemberFunctionRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
18440#endif
18441 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
18442 ROSE_ASSERT(otherPossibleScope_original != NULL);
18443 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
18444 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
18445 ROSE_ASSERT(file != NULL);
18446#if DEBUG_MEMBER_FUNCTION_REF_EXP
18447 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
18448 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18449
18450 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
18451 printf ("case V_SgClassDeclaration: memberFunctionSymbol_copy->get_name() = %s \n",memberFunctionSymbol_copy->get_name().str());
18452#endif
18453 memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original));
18454 if (memberFunctionSymbolInTargetAST == NULL)
18455 {
18456#if DEBUG_MEMBER_FUNCTION_REF_EXP
18457 printf ("Backup and look for the associated class and then look for the member function in the class (assume non-friend function or Java member function) \n");
18458#endif
18459 // Check for the case of a record reference (member function of class declaration).
18460 SgExpression* parentExpression = isSgExpression(memberFunctionRefExp_copy->get_parent());
18461
18462 ROSE_ASSERT(parentExpression != NULL);
18463#if DEBUG_MEMBER_FUNCTION_REF_EXP
18464 printf ("parentExpression = %p = %s \n",parentExpression,parentExpression->class_name().c_str());
18465#endif
18466 bool handle_as_java = false;
18467 SgFunctionCallExp* functionCallExp = isSgFunctionCallExp(parentExpression);
18468 if (functionCallExp != NULL)
18469 {
18470 // Note that this is a Java specific organization of the SgMemberFunctionRefExp and the SgFunctionCallExp.
18471 // We might want to make this more uniform between C++ and Java later.
18472 handle_as_java = true;
18473
18474 SgExpression* parentOfFunctionCallExpression = isSgExpression(functionCallExp->get_parent());
18475
18476 ROSE_ASSERT(parentOfFunctionCallExpression != NULL);
18477#if DEBUG_MEMBER_FUNCTION_REF_EXP
18478 printf ("parentOfFunctionCallExpression = %p = %s \n",parentOfFunctionCallExpression,parentOfFunctionCallExpression->class_name().c_str());
18479#endif
18480 parentExpression = parentOfFunctionCallExpression;
18481 }
18482
18483 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
18484 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
18485 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
18486#if DEBUG_MEMBER_FUNCTION_REF_EXP
18487 printf ("parentBinaryOp = %p \n",parentBinaryOp);
18488 printf ("parentDotExp = %p \n",parentDotExp);
18489 printf ("parentArrowExp = %p \n",parentArrowExp);
18490#endif
18491 if (parentDotExp != NULL || parentArrowExp != NULL)
18492 {
18493 // This is a data member reference, so it's scope is the associated data structure.
18494 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
18495 ROSE_ASSERT(lhs != NULL);
18496
18497 // This will be true for C++, but not Java (a little odd).
18498 if (handle_as_java == true)
18499 {
18500 // The rhs is the SgFunctionCallExp for Java.
18501 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == functionCallExp);
18502 }
18503 else
18504 {
18505 // This is what we expect to be true for C++.
18506 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == memberFunctionRefExp_copy);
18507 }
18508#if DEBUG_MEMBER_FUNCTION_REF_EXP
18509 printf ("lhs = %p = %s \n",lhs,lhs->class_name().c_str());
18510#endif
18511 SgVarRefExp* varRefExp = isSgVarRefExp(lhs);
18512
18513 // DQ (3/15/2014): This can be a SgJavaTypeExpression (see testJava3a).
18514 // ROSE_ASSERT(varRefExp != NULL);
18515 if (varRefExp != NULL)
18516 {
18517 SgVariableSymbol* variableSymbol = isSgVariableSymbol(varRefExp->get_symbol());
18518 ROSE_ASSERT(variableSymbol != NULL);
18519 SgInitializedName* initializedName = variableSymbol->get_declaration();
18520 ROSE_ASSERT(initializedName != NULL);
18521
18522 SgType* initializedName_type = initializedName->get_type();
18523#if DEBUG_MEMBER_FUNCTION_REF_EXP
18524 printf ("initializedName = %p = %s \n",initializedName,initializedName->get_name().str());
18525 printf ("initializedName_type = %p \n",initializedName_type);
18526#endif
18527 SgClassType* classType = isSgClassType(initializedName_type);
18528 if (classType != NULL)
18529 {
18530 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
18531 ROSE_ASSERT(classDeclaration != NULL);
18532 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(classDeclaration->get_definingDeclaration());
18533 ROSE_ASSERT(definingClassDeclaration != NULL);
18534 printf ("definingClassDeclaration->get_name() = %s \n",definingClassDeclaration->get_name().str());
18535
18536 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18537 ROSE_ASSERT(classDefinition != NULL);
18538 SgType* memberFunctionType = memberFunctionSymbol_copy->get_type();
18539 SgName memberFunctionName = memberFunctionSymbol_copy->get_name();
18540 ROSE_ASSERT(memberFunctionType != NULL);
18541 SgFunctionSymbol *functionSymbol = classDefinition->lookup_function_symbol(memberFunctionName,memberFunctionType);
18542 if (functionSymbol == NULL)
18543 {
18544 printf ("Symbol not found: output symbol table (size = %d): \n",classDefinition->get_symbol_table()->size());
18545#if DEBUG_MEMBER_FUNCTION_REF_EXP
18546 classDefinition->get_symbol_table()->print("Symbol not found: output symbol table: SgClassDefinition");
18547#endif
18548 // DQ (3/30/2014): If functionSymbol is not found then I think it is because the class was not availalbe
18549 // in the target where the snippet is being copied. This is an error in the constrains for how the target
18550 // must be prepared for the snippet to be copied into it.
18551 printf ("\n*************************************************************** \n");
18552 printf ("ERROR: target has not be properly setup to receive the snippet. \n");
18553 printf ("*************************************************************** \n");
18554 }
18555 ROSE_ASSERT(functionSymbol != NULL);
18556 SgMemberFunctionSymbol *memberFunctionSymbol = isSgMemberFunctionSymbol(functionSymbol);
18557 ROSE_ASSERT(memberFunctionSymbol != NULL);
18558
18559 memberFunctionSymbolInTargetAST = memberFunctionSymbol;
18560#if 0
18561 printf ("Exiting as a test! \n");
18562 ROSE_ABORT();
18563#endif
18564 }
18565 }
18566
18567 // DQ (3/30/2014): If this is a value expression then calling the member function uses a shared
18568 // symbol from the global scope (or a type defined deep in the global scope, but common to the
18569 // snippet AST and the target AST).
18570 SgValueExp* valueExp = isSgValueExp(lhs);
18571 if (valueExp != NULL)
18572 {
18573 memberFunctionSymbolInTargetAST = memberFunctionSymbol_copy;
18574 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18575 }
18576
18577 if (memberFunctionSymbolInTargetAST == NULL)
18578 {
18579#if 1
18580 SgType* type = lhs->get_type();
18581 ROSE_ASSERT(type != NULL);
18582#if DEBUG_MEMBER_FUNCTION_REF_EXP
18583 printf ("type = %p = %s \n",type,type->class_name().c_str());
18584#endif
18585 SgNamedType* namedType = isSgNamedType(type);
18586 ROSE_ASSERT(namedType != NULL);
18587 SgDeclarationStatement* declaration = namedType->get_declaration();
18588 ROSE_ASSERT(declaration != NULL);
18589 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
18590 ROSE_ASSERT(classDeclaration != NULL);
18591 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
18592 ROSE_ASSERT(definingClassDeclaration != NULL);
18593 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18594 ROSE_ASSERT(classDefinition != NULL);
18595#if DEBUG_MEMBER_FUNCTION_REF_EXP
18596 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
18597#endif
18598 // I think we want the copy.
18599 otherPossibleScope_original = classDefinition;
18600#if DEBUG_MEMBER_FUNCTION_REF_EXP
18601 classDefinition->get_symbol_table()->print("Java classDefinition");
18602#endif
18603#if DEBUG_MEMBER_FUNCTION_REF_EXP
18604 SgClassDeclaration* associated_classDeclaration = classDefinition->get_declaration();
18605 SgFunctionSymbol* functionSymbol = lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original);
18606 printf ("associated_classDeclaration = %p name = %s \n",associated_classDeclaration,associated_classDeclaration->get_name().str());
18607 printf ("functionSymbol = %p \n",functionSymbol);
18608#endif
18609 memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original));
18610 if (memberFunctionSymbolInTargetAST == NULL)
18611 {
18612 // Output debugging info (16 of the CWE injection test codes fail here: see test_results.txt file for details).
18613 printf ("Error: (memberFunctionSymbolInTargetAST == NULL): memberFunctionSymbol_copy->get_name() = %s \n",memberFunctionSymbol_copy->get_name().str());
18614 }
18615#endif
18616 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18617 }
18618 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18619 }
18620 }
18621
18622 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18623 SgFunctionDeclaration* functionDeclaration = memberFunctionSymbolInTargetAST->get_declaration();
18624 ROSE_ASSERT(functionDeclaration != NULL);
18625 SgScopeStatement* scope = functionDeclaration->get_scope();
18626 ROSE_ASSERT(scope != NULL);
18627
18628 // Is this the correct scope?
18629 functionDeclaration->set_scope(scope);
18630 }
18631 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18632
18633 // Reset the symbol associated with this function reference.
18634 memberFunctionRefExp_copy->set_symbol(memberFunctionSymbolInTargetAST);
18635 }
18636
18637 break;
18638 }
18639
18640 // DQ (3/21/2014): I think we need this.
18641 case V_SgTryStmt:
18642 {
18643#if 0
18644 printf ("Exiting as a test! (SgTryStmt) \n");
18645 ROSE_ABORT();
18646#endif
18647 break;
18648 }
18649
18650 // DQ (3/19/2014): Just found this case in a few of the CWE Java snippet tests.
18651 case V_SgCatchStatementSeq:
18652 {
18653 // DQ (3/19/2014): Note sure that we need to handle this specific case.
18654
18655#if 0
18656 printf ("Exiting as a test! (SgCatchStatementSeq) \n");
18657 ROSE_ABORT();
18658#endif
18659 break;
18660 }
18661
18662 // DQ (3/19/2014): Just found this case in a few of the CWE Java snippet tests.
18663 case V_SgCatchOptionStmt:
18664 {
18665 // DQ (3/19/2014): Note sure that we need to handle this specific case.
18666 // Decide if we need to implement this newly identified case tomorrow (note that this is a SgScopeStatement).
18667 SgCatchOptionStmt* catchOptionStatement_copy = isSgCatchOptionStmt(node_copy);
18668 ROSE_ASSERT(catchOptionStatement_copy);
18669
18670 printf ("Need to check the symbol table of the SgCatchOptionStmt (which is a SgScopeStatement) \n");
18671
18672#if 0
18673 printf ("Exiting as a test! (SgCatchOptionStmt) \n");
18674 ROSE_ABORT();
18675#endif
18676 break;
18677 }
18678
18679 // DQ (3/21/2014): I think we need this.
18680 case V_SgJavaPackageStatement:
18681 {
18682#if 1
18683 printf ("Exiting as a test! (SgJavaPackageStatement) \n");
18684 ROSE_ABORT();
18685#endif
18686 break;
18687 }
18688
18689 case V_SgEnumVal:
18690 {
18691 // SgEnumVal expressions contain a reference to the associated SgEnumDeclaration, so this may have to be updated.
18692#if 0
18693 printf ("enum values contain a reference to the associated SgEnumDeclaration \n");
18694#endif
18695 SgEnumVal* enumVal_copy = isSgEnumVal(node_copy);
18696 SgEnumVal* enumVal_original = isSgEnumVal(node_original);
18697#if 0
18698 printf (" --- enumVal_original = %p = %d name = %s \n",enumVal_original,enumVal_original->get_value(),enumVal_original->get_name().str());
18699#endif
18700 SgEnumDeclaration* associatedEnumDeclaration_copy = isSgEnumDeclaration(enumVal_copy->get_declaration());
18701 SgEnumDeclaration* associatedEnumDeclaration_original = isSgEnumDeclaration(enumVal_original->get_declaration());
18702
18703 // DQ (4/13/2014): check if this is an un-named enum beclaration.
18704 bool isUnNamed = associatedEnumDeclaration_original->get_isUnNamed();
18705 if (isUnNamed == false)
18706 {
18707 if (associatedEnumDeclaration_copy == associatedEnumDeclaration_original)
18708 {
18709#if 0
18710 printf (" --- The stored reference to the enum declaration in the SgEnumVal must be reset \n");
18711#endif
18712 // SgSymbol* SageBuilder::findAssociatedSymbolInTargetAST(SgDeclarationStatement* snippet_declaration, SgScopeStatement* targetScope)
18713 SgSymbol* symbol = findAssociatedSymbolInTargetAST(associatedEnumDeclaration_original,targetScope);
18714 if (symbol == NULL)
18715 {
18716 // debug this case.
18717 enumVal_original->get_file_info()->display("case V_SgEnumVal: symbol == NULL: debug");
18718 }
18719 ROSE_ASSERT(symbol != NULL);
18720 SgEnumSymbol* enumSymbol = isSgEnumSymbol(symbol);
18721 ROSE_ASSERT(enumSymbol != NULL);
18722 SgEnumDeclaration* new_associatedEnumDeclaration_copy = enumSymbol->get_declaration();
18723 ROSE_ASSERT(new_associatedEnumDeclaration_copy != NULL);
18724
18725 // If this is false then in means that we should have built a new SgEnumSymbol instead of reusing the existing one from the snippet.
18726 ROSE_ASSERT(new_associatedEnumDeclaration_copy != associatedEnumDeclaration_original);// TV (10/22/2014): with project wide global scope this will always be false because 'symbol' is resolve to the first-non-defn-decl in original scope
18727 // ROSE_ASSERT(new_associatedEnumDeclaration_copy != associatedEnumDeclaration_original->get_firstNondefiningDeclaration());
18728 ROSE_ASSERT(new_associatedEnumDeclaration_copy != associatedEnumDeclaration_original->get_definingDeclaration());
18729
18730 enumVal_copy->set_declaration(new_associatedEnumDeclaration_copy);
18731#if 0
18732 printf ("Exiting as a test! \n");
18733 ROSE_ABORT();
18734#endif
18735 }
18736 }
18737 else
18738 {
18739 // DQ (4/13/2014): I think we all agreed these would not have to be handled, so issue a warning.
18740 // It still is likely that I can allow this, but permit this intermediate fix.
18741 printf ("Warning: can't handle enum values from unnamed enum declarations \n");
18742 printf (" --- enumVal_original = %p = %lld name = %s \n",enumVal_original,enumVal_original->get_value(),enumVal_original->get_name().str());
18743 }
18744
18745 break;
18746 }
18747
18748 default:
18749 {
18750 // Most IR nodes do not require specialized fixup (are not processed).
18751 }
18752 }
18753
18754#if 1
18755 // DQ (3/17/2014): Cause failure on warnings about any constructs referencing the snippet AST.
18756#if 0
18757 // Assert fail on warnings.
18758 errorCheckingTargetAST(node_copy,node_original,targetFile, true);
18759#else
18760 // Cause only warnings.
18761 errorCheckingTargetAST(node_copy,node_original,targetFile, false);
18762#endif
18763#endif
18764 }
18765
18766
18767void
18769 SgStatement *toInsert, SgStatement* original_before_copy)
18770 {
18771 // The semantics of the copy is that it will have been disconnected from the snippet AST in a few ways,
18772 // Namely the root of the copy of the snippet's AST will have been set with a NULL parent, and then
18773 // the parent would have been reset when the copy of the snippet was inserted into the target AST.
18774 // So a simple traversal of parents back to the SgFile will return the target AST's SgFile (confirmed below).
18775
18776 ROSE_ASSERT(insertionPoint != NULL);
18777 ROSE_ASSERT(toInsert != NULL);
18778 ROSE_ASSERT(original_before_copy != NULL);
18779
18780 // DQ (3/30/2014): Turn this on to support finding symbols in base classes (in Java).
18781 // Will be turned off at the base of this function (since we only only want to use it for the AST fixup, currently).
18782 SgSymbolTable::set_force_search_of_base_classes(true);
18783
18784 // DQ (3/4/2014): Switch to using the SageInterface function.
18785 // SgFile* targetFile = TransformationSupport::getFile(insertionPoint);
18786 SgFile* targetFile = getEnclosingFileNode(insertionPoint);
18787
18788 // For Java support this might be NULL, if the insertion point was in global scope.
18789 ROSE_ASSERT(targetFile != NULL);
18790
18791 // SgFile* snippetFile_of_copy = TransformationSupport::getFile(toInsert);
18792 SgFile* snippetFile_of_copy = getEnclosingFileNode(toInsert);
18793
18794 // At this point the parent pointers are set so that the same SgFile is found via a traversal back to the SgProject.
18795 // Confirm that the SgFile found by a traversal of parents in the copy of rthe snippet's AST will return that of the
18796 // SgFile for the target AST. This also confirms that the copy of the snippet has already been inserted into the
18797 // target AST.
18798 ROSE_ASSERT(snippetFile_of_copy == targetFile);
18799
18800 // SgFile* snippetFile_of_original = TransformationSupport::getFile(original_before_copy);
18801 SgFile* snippetFile_of_original = getEnclosingFileNode(original_before_copy);
18802
18803 ROSE_ASSERT(snippetFile_of_original != targetFile);
18804
18805#if 0
18806 printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18807 printf (" --- snippetFile_of_copy = %p = %s \n",snippetFile_of_copy,snippetFile_of_copy->get_sourceFileNameWithPath().c_str());
18808 printf (" --- snippetFile_of_original = %p = %s \n",snippetFile_of_original,snippetFile_of_original->get_sourceFileNameWithPath().c_str());
18809#endif
18810
18811 // Any node that has entries not referenced in the target file needs to be fixed up.
18812 // We can assume that any referenced variable or function that is referenced in the
18813 // snippet will exist in either the snippet or the target file.
18814
18815 // DQ (3/4/2014): This is a test of the structural equality of the original snippet and it's copy.
18816 // If they are different then we can't support fixing up the AST. Transformations on the snippet
18817 // should have been made after insertion into the AST. The complexity of this test is a traversal
18818 // of the copy of the snippet to be inserted (typically very small compared to the target application).
18819 bool isStructurallyEquivalent = isStructurallyEquivalentAST(toInsert,original_before_copy);
18820 if (isStructurallyEquivalent == false)
18821 {
18822 printf ("WARNING: The copy of the snippet is a different size than the original snippet (don't do transformations on the copy before inserting into the target AST). \n");
18823 return;
18824 }
18825 ROSE_ASSERT(isStructurallyEquivalent == true);
18826
18827#ifndef USE_CMAKEx
18828 // DQ (3/8/2014): Make this conditionally compiled based on when CMake is not used because the libraries are not configured yet.
18829
18830 // This is AST container for the ROSE AST that will provide an iterator.
18831 // We want two iterators (one for the copy of the snippet and one for the
18832 // original snippet so that we can query the original snippet's AST
18833 // as we process each IR node of the AST for the copy of the snippet.
18834 // Only the copy of the snippet is inserted into the target AST.
18835 RoseAst ast_of_copy(toInsert);
18836 RoseAst ast_of_original(original_before_copy);
18837
18838 // printf ("ast_of_copy.size() = %" PRIuPTR " \n",ast_of_copy.size());
18839
18840 // Build the iterators so that we can increment thorugh both ASTs one IR node at a time.
18841 RoseAst::iterator i_copy = ast_of_copy.begin();
18842 RoseAst::iterator i_original = ast_of_original.begin();
18843
18844 // Iterate of the copy of the snippet's AST.
18845 while (i_copy != ast_of_copy.end())
18846 {
18847 // DQ (2/28/2014): This is a problem for some of the test codes (TEST store/load heap string [test7a] and [test7a])
18848 // ROSE_ASSERT((*i_copy)->variantT() == (*i_original)->variantT());
18849 if ((*i_copy)->variantT() != (*i_original)->variantT())
18850 {
18851 printf ("ERROR: return from fixupCopyOfAstFromSeparateFileInNewTargetAst(): "
18852 "(*i_copy)->variantT() != (*i_original)->variantT() \n");
18853#if 1
18854 printf ("Making this an error! \n");
18855 ROSE_ABORT();
18856#endif
18857 return;
18858 }
18859
18860 // Operate on individual IR nodes.
18861 fixupCopyOfNodeFromSeparateFileInNewTargetAst(insertionPoint, insertionPointIsScope, *i_copy, *i_original);
18862
18863 i_copy++;
18864
18865 // Verify that we have not reached the end of the ast for the original (both the
18866 // copy and the original are the same structurally, and thus the same size).
18867 ROSE_ASSERT(i_original != ast_of_original.end());
18868 i_original++;
18869 }
18870
18871 // We have reached the end of both ASTs.
18872 ROSE_ASSERT(i_copy == ast_of_copy.end() && i_original == ast_of_original.end());
18873
18874 // DQ (3/8/2014): ENDIF: Make this conditionally compiled based on when CMake is not used because the libraries are not configured yet.
18875#endif
18876
18877#if 0
18878 if (functionDeclaration != NULL)
18879 {
18880 printf ("functionDeclaration = %s \n",functionDeclaration->get_name().str());
18881#if 0
18882 printf ("Exiting as a test! \n");
18883 ROSE_ABORT();
18884#endif
18885 }
18886#endif
18887
18888 // DQ (3/30/2014): Turn this off (since we only only want to use it for the AST fixup, currently).
18889 SgSymbolTable::set_force_search_of_base_classes(false);
18890 }
18891
18892// Liao 9/18/2015
18893// The parser is implemented in
18894// src/frontend/SageIII/astFromString/AstFromString.h .C
18896{
18897
18898 SgStatement* result = NULL;
18899 ROSE_ASSERT (scope != NULL);
18900 // set input and context for the parser
18901 AstFromString::c_char = s.c_str();
18902 ROSE_ASSERT(AstFromString::c_char== s.c_str());
18905
18907 {
18908 result = isSgStatement(AstFromString::c_parsed_node); // grab the result
18909 ROSE_ASSERT(result != NULL);
18910 }
18911 else
18912 {
18913 cerr<<"Error. buildStatementFromString() cannot parse the input string:"<<s
18914 <<"\n\t within the given scope:"<<scope->class_name() <<endl;
18915 ROSE_ABORT();
18916 }
18917 return result;
18918}
18919
18929
18930//
18931// pp (07/16/16)
18932// initial support for creating template instantiations
18933// from template declarations
18934
18935namespace {
18936 // internal functions
18937
18938 template <class SgAstNode>
18939 SgTemplateArgument* createTemplateArg_(SgAstNode& n)
18940 {
18941 static const bool explicitlySpecified = true;
18942
18943 return new SgTemplateArgument(&n, explicitlySpecified);
18944 }
18945
18946 SgTemplateArgument* createTemplateArg_(SgExpression& n)
18947 {
18948 SgTemplateArgument* res = createTemplateArg_<SgExpression>(n);
18949
18950 n.set_parent(res);
18951 return res;
18952 }
18953
18954 SgTemplateArgument* createTemplateArg(SgNode& n)
18955 {
18956 SgTemplateArgument* res = NULL;
18957
18958 if (isSgType(&n))
18959 res = createTemplateArg_(*isSgType(&n));
18960 else if (isSgExpression(&n))
18961 res = createTemplateArg_(*isSgExpression(&n));
18962 else
18963 {
18964 ROSE_ASSERT(isSgTemplateDeclaration(&n));
18965 res = createTemplateArg_(*isSgTemplateDeclaration(&n));
18966 }
18967
18968 ROSE_ASSERT(res);
18969 return res;
18970 }
18971#if 0
18972 SgName genTemplateName(SgName base, Rose_STL_Container<SgNode*>& targs)
18973 {
18974 Rose_STL_Container<SgNode*>::iterator aa = targs.begin();
18975 Rose_STL_Container<SgNode*>::iterator zz = targs.begin();
18976 std::string name(base.getString());
18977
18978 name.append("<");
18979 for ( ; aa != zz; ++aa) name.append((*aa)->unparseToString());
18980 name.append(">");
18981
18982 return SgName(name);
18983 }
18984#endif
18985 SgTemplateArgumentPtrList genTemplateArgumentList(Rose_STL_Container<SgNode*>& targs)
18986 {
18987 Rose_STL_Container<SgNode*>::iterator aa = targs.begin();
18988 Rose_STL_Container<SgNode*>::iterator zz = targs.begin();
18989 SgTemplateArgumentPtrList lst;
18990
18991 for ( ; aa != zz; ++aa)
18992 {
18993 lst.push_back(createTemplateArg(**aa));
18994 }
18995
18996 return lst;
18997 }
18998
18999 SgTemplateClassDeclaration* getCanonicalTemplateDecl(SgTemplateClassDeclaration* main_decl)
19000 {
19001 ROSE_ASSERT(main_decl);
19002 SgClassType* ct = main_decl->get_type();
19003 ROSE_ASSERT(ct);
19004 SgDeclarationStatement* decl = ct->get_declaration();
19005 SgTemplateClassDeclaration* tdecl = isSgTemplateClassDeclaration(decl);
19006
19007 ROSE_ASSERT(tdecl);
19008 return tdecl;
19009 }
19010
19011 SgTemplateInstantiationDecl* genTemplateInstantiationDecl(SgName tname, SgTemplateClassDeclaration* tclassdecl, SgTemplateArgumentPtrList targs)
19012 {
19013 ROSE_ASSERT(tclassdecl);
19014
19015 SgTemplateInstantiationDecl* res = NULL;
19016
19017 res = new SgTemplateInstantiationDecl( tname,
19019 NULL /* SgClassType* type -- to be set later */,
19020 NULL /* SgClassDefinition* def -- to be set later */,
19021 tclassdecl,
19022 targs
19023 );
19024
19025 res->set_scope(tclassdecl->get_scope());
19026 res->set_templateName(tname); // \todo \pp create mangled name from tname
19028 res->setForward(); // \pp set forward, since this is not a proper declaration
19029 return res;
19030 }
19031
19032 SgClassType* genTemplateClass(SgTemplateInstantiationDecl* tdecl)
19033 {
19034 ROSE_ASSERT(tdecl);
19035
19036 return SgClassType::createType(tdecl);
19037 }
19038
19039 struct TemplateArgumentParentSetter
19040 {
19042
19043 TemplateArgumentParentSetter(SgTemplateInstantiationDecl* p)
19044 : parent(p)
19045 {}
19046
19047 void operator()(SgTemplateArgument* targ)
19048 {
19049 targ->set_parent(parent);
19050 }
19051 };
19052} /* anonymous namespace */
19053
19054
19057Rose_STL_Container<SgNode *>& template_args)
19058{
19059 return buildClassTemplateType (template_decl,template_args);
19060}
19061
19064Rose_STL_Container<SgNode *>& template_args)
19065{
19066 ROSE_ASSERT(template_decl);
19067
19068 // create a template instantiation decl
19069 SgName name = template_decl->get_name();
19070 // SgName tname = genTemplateName(, template_args);
19071 SgTemplateArgumentPtrList targs = genTemplateArgumentList(template_args);
19072 SgTemplateClassDeclaration* tdecl = getCanonicalTemplateDecl(template_decl);
19073 SgTemplateInstantiationDecl* tinst = genTemplateInstantiationDecl(name, tdecl, targs);
19074 ROSE_ASSERT(tinst);
19075
19076 // create class type
19077 SgClassType* tclass = genTemplateClass(tinst);
19078 ROSE_ASSERT(tclass);
19079
19080 // set remaining fields in the template instantiation decl
19081 tinst->set_type(tclass);
19082 tinst->set_definition(static_cast<SgTemplateInstantiationDefn*>(0)); /* \pp not sure what to set this to .. */
19083
19084 // set parent of template arguments
19085 std::for_each(targs.begin(), targs.end(), TemplateArgumentParentSetter(tinst)); //
19086
19087 return tclass;
19088}
19089
19090//-----------------------------------------------------------------------------
19091#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
19092//-----------------------------------------------------------------------------
19093
19098 ROSE_ASSERT(Rose::Frontend::Java::lengthSymbol);
19099 SgVarRefExp *var_ref = SageBuilder::buildVarRefExp(Rose::Frontend::Java::lengthSymbol);
19101 return var_ref;
19102}
19103
19108 SgScopeStatement *scope = new SgScopeStatement();
19110 if (parent_scope != NULL) {
19111 scope -> set_parent(parent_scope);
19112 }
19113 return scope;
19114}
19115
19122 return expr;
19123}
19124
19129 SgJavaMarkerAnnotation *annotation = new SgJavaMarkerAnnotation(type);
19131 return annotation;
19132}
19133
19140 pair -> set_name(name);
19141 pair -> set_value(value);
19142 value -> set_parent(pair);
19143 return pair;
19144}
19145
19150 SgJavaSingleMemberAnnotation *annotation = new SgJavaSingleMemberAnnotation(type, value);
19152 return annotation;
19153}
19154
19159 SgJavaNormalAnnotation *annotation = new SgJavaNormalAnnotation(type);
19161 return annotation;
19162}
19163
19167SgJavaNormalAnnotation *SageBuilder::buildJavaNormalAnnotation(SgType *type, list<SgJavaMemberValuePair *>& pair_list) {
19169 for (std::list<SgJavaMemberValuePair *>::iterator i = pair_list.begin(); i != pair_list.end(); i++) {
19170 SgJavaMemberValuePair *member_value_pair = *i;
19171 member_value_pair -> set_parent(annotation);
19172 annotation -> append_value_pair(member_value_pair);
19173 }
19174 return annotation;
19175}
19176
19177
19181SgInitializedName *SageBuilder::buildJavaFormalParameter(SgType *argument_type, const SgName &argument_name, bool is_var_args, bool is_final) {
19182 SgInitializedName *initialized_name = NULL;
19183 if (is_var_args) {
19184 initialized_name = SageBuilder::buildInitializedName(argument_name, SageBuilder::getUniqueJavaArrayType(argument_type, 1), NULL);
19185 initialized_name -> setAttribute("var_args", new AstRegExAttribute(""));
19186 }
19187 else {
19188 initialized_name = SageBuilder::buildInitializedName(argument_name, argument_type, NULL);
19189 }
19190 SageInterface::setSourcePosition(initialized_name);
19191 if (is_final) {
19192 initialized_name -> setAttribute("final", new AstRegExAttribute(""));
19193 }
19194
19195 return initialized_name;
19196}
19197
19202 SgJavaPackageStatement *package_statement = new SgJavaPackageStatement(package_name);
19203 SageInterface::setSourcePosition(package_statement);
19204 package_statement -> set_firstNondefiningDeclaration(package_statement);
19205 package_statement -> set_definingDeclaration(package_statement);
19206 return package_statement;
19207}
19208
19212SgJavaImportStatement *SageBuilder::buildJavaImportStatement(string import_info, bool contains_wildcard) {
19213 SgJavaImportStatement *import_statement = new SgJavaImportStatement(import_info, contains_wildcard);
19214 SageInterface::setSourcePosition(import_statement);
19215 import_statement -> set_firstNondefiningDeclaration(import_statement);
19216 import_statement -> set_definingDeclaration(import_statement);
19217 return import_statement;
19218}
19219
19224 ROSE_ASSERT(scope);
19225 SgName class_name = name;
19226 ROSE_ASSERT(scope -> lookup_class_symbol(class_name) == NULL);
19227
19228 SgClassDeclaration* nonDefiningDecl = NULL;
19229 bool buildTemplateInstantiation = false;
19230 SgTemplateArgumentPtrList* templateArgumentsList = NULL;
19231 SgClassDeclaration *class_declaration = SageBuilder::buildClassDeclaration_nfi(class_name, kind, scope, nonDefiningDecl, buildTemplateInstantiation, templateArgumentsList);
19232 ROSE_ASSERT(class_declaration);
19233 class_declaration -> set_parent(scope);
19234 class_declaration -> set_scope(scope);
19235 SageInterface::setSourcePosition(class_declaration);
19236 SgClassDefinition *class_definition = class_declaration -> get_definition();
19237 ROSE_ASSERT(class_definition);
19238 SageInterface::setSourcePosition(class_definition);
19239
19240 class_definition -> setAttribute("extensions", new AstSgNodeListAttribute());
19241 class_definition -> setAttribute("extension_type_names", new AstRegExAttribute());
19242
19243 SgScopeStatement *type_space = new SgScopeStatement();
19244 type_space -> set_parent(class_definition);
19246 class_declaration -> setAttribute("type_space", new AstSgNodeAttribute(type_space));
19247
19248 return class_declaration;
19249}
19250
19251
19256SgSourceFile *SageBuilder::buildJavaSourceFile(SgProject *project, string directory_name, SgClassDefinition *package_definition, string type_name) {
19257 string filename = directory_name + "/" + type_name + ".java";
19258 ROSE_ASSERT((*project)[filename] == NULL); // does not already exist!
19259
19260 string command = string("touch ") + filename; // create the file
19261 int status = system(command.c_str());
19262 ROSE_ASSERT(status == 0);
19263 project -> get_sourceFileNameList().push_back(filename);
19264 Rose_STL_Container<std::string> arg_list = project -> get_originalCommandLineArgumentList();
19265 arg_list.push_back(filename);
19266 Rose_STL_Container<string> fileList = CommandlineProcessing::generateSourceFilenames(arg_list, // binaryMode
19267 false);
19268 CommandlineProcessing::removeAllFileNamesExcept(arg_list, fileList, filename);
19269 int error_code = 0;
19270 SgFile *file = determineFileType(arg_list, error_code, project);
19271 SgSourceFile *sourcefile = isSgSourceFile(file);
19272 ROSE_ASSERT(sourcefile);
19273 sourcefile -> set_parent(project);
19274 project -> get_fileList_ptr() -> get_listOfFiles().push_back(sourcefile);
19275 ROSE_ASSERT(sourcefile == isSgSourceFile((*project)[filename]));
19276
19277 //
19278 // Create a package statement and add it to the source file
19279 //
19280 SgClassDeclaration* pkgDefDecl = package_definition->get_declaration();
19281 ROSE_ASSERT(pkgDefDecl != NULL);
19282 SgJavaPackageStatement *package_statement = SageBuilder::buildJavaPackageStatement(pkgDefDecl->get_qualified_name().getString());
19283 package_statement->set_parent(package_definition);
19284 sourcefile->set_package(package_statement);
19285
19286 //
19287 // Initialize an import-list for the sourcefile
19288 //
19289 SgJavaImportStatementList *import_statement_list = new SgJavaImportStatementList();
19290 import_statement_list -> set_parent(sourcefile);
19291 sourcefile -> set_import_list(import_statement_list);
19292
19293 //
19294 // Initialize a class-declaration-list for the sourcefile
19295 //
19296 SgJavaClassDeclarationList *class_declaration_list = new SgJavaClassDeclarationList();
19297 class_declaration_list -> set_parent(package_definition);
19298 sourcefile -> set_class_list(class_declaration_list);
19299
19300 return sourcefile;
19301}
19302
19303
19307SgArrayType *SageBuilder::getUniqueJavaArrayType(SgType *base_type, int num_dimensions) {
19308 ROSE_ASSERT(num_dimensions > 0);
19309 if (num_dimensions > 1) {
19310 base_type = getUniqueJavaArrayType(base_type, num_dimensions - 1);
19311 }
19312
19313 ROSE_ASSERT(base_type != NULL);
19314 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) base_type -> getAttribute("array");
19315 if (attribute == NULL) {
19316 SgArrayType *array_type = SageBuilder::buildArrayType(base_type);
19317 array_type -> set_rank(num_dimensions);
19318 attribute = new AstSgNodeAttribute(array_type);
19319 base_type -> setAttribute("array", attribute);
19320 }
19321
19322 return isSgArrayType(attribute -> getNode());
19323}
19324
19325
19329SgJavaParameterizedType *SageBuilder::getUniqueJavaParameterizedType(SgNamedType *generic_type, SgTemplateParameterPtrList *new_args) {
19330 AstParameterizedTypeAttribute *attribute = (AstParameterizedTypeAttribute *) generic_type -> getAttribute("parameterized types");
19331 if (! attribute) {
19332 attribute = new AstParameterizedTypeAttribute(generic_type);
19333 generic_type -> setAttribute("parameterized types", attribute);
19334 }
19335 ROSE_ASSERT(attribute);
19336
19337 return attribute -> findOrInsertParameterizedType(new_args);
19338}
19339
19340
19345 AstSgNodeListAttribute *attribute = (AstSgNodeListAttribute *) type -> getAttribute("qualified types");
19346 if (! attribute) {
19347 attribute = new AstSgNodeListAttribute();
19348 type -> setAttribute("qualified types", attribute);
19349 }
19350 ROSE_ASSERT(attribute);
19351
19352 for (int i = 0; i < attribute -> size(); i++) {
19353 SgJavaQualifiedType *qualified_type = isSgJavaQualifiedType(attribute -> getNode(i));
19354 ROSE_ASSERT(qualified_type);
19355 if (qualified_type -> get_parent_type() == parent_type && qualified_type -> get_type() == type) {
19356 return qualified_type;
19357 }
19358 }
19359
19360 SgJavaQualifiedType *qualified_type = new SgJavaQualifiedType(class_declaration);
19361 qualified_type -> set_parent_type(parent_type);
19362 qualified_type -> set_type(type);
19363
19364 attribute -> addNode(qualified_type);
19365
19366 return qualified_type;
19367}
19368
19369
19375 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) Rose::Frontend::Java::ObjectClassType -> getAttribute("unbound");
19376 if (! attribute) {
19377 SgClassDeclaration *class_declaration = isSgClassDeclaration(Rose::Frontend::Java::ObjectClassType -> get_declaration());
19378 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration());
19379 attribute = new AstSgNodeAttribute(wildcard);
19380 Rose::Frontend::Java::ObjectClassType -> setAttribute("unbound", attribute);
19381 }
19382
19383 return isSgJavaWildcardType(attribute -> getNode());
19384}
19385
19386
19391 ROSE_ASSERT(type);
19392 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) type -> getAttribute("extends");
19393 if (! attribute) {
19394 SgArrayType *array_type = isSgArrayType(type);
19395 SgNamedType *named_type = isSgNamedType(type);
19396 ROSE_ASSERT(array_type || named_type);
19397 SgClassDeclaration *class_declaration = isSgClassDeclaration((array_type ? (SgNamedType *) Rose::Frontend::Java::ObjectClassType : named_type) -> get_declaration());
19398 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration(), type);
19399
19400 wildcard -> set_has_extends(true);
19401
19402 attribute = new AstSgNodeAttribute(wildcard);
19403 type -> setAttribute("extends", attribute);
19404 }
19405
19406 return isSgJavaWildcardType(attribute -> getNode());
19407}
19408
19409
19414 ROSE_ASSERT(type);
19415 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) type -> getAttribute("super");
19416 if (! attribute) {
19417 SgArrayType *array_type = isSgArrayType(type);
19418 SgNamedType *named_type = isSgNamedType(type);
19419 ROSE_ASSERT(array_type || named_type);
19420 SgClassDeclaration *class_declaration = isSgClassDeclaration((array_type ? (SgNamedType *) Rose::Frontend::Java::ObjectClassType : named_type) -> get_declaration());
19421 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration(), type);
19422
19423 wildcard -> set_has_super(true);
19424
19425 attribute = new AstSgNodeAttribute(wildcard);
19426 type -> setAttribute("super", attribute);
19427 }
19428
19429 return isSgJavaWildcardType(attribute -> getNode());
19430}
19431
19432
19433//-----------------------------------------------------------------------------
19434#endif // ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
19435//-----------------------------------------------------------------------------
19436
19437
19438namespace Rose {
19439 namespace Builder {
19440 namespace Templates {
19441
19442SgTemplateArgument * buildTemplateArgument(SgType * t) {
19443 ROSE_ASSERT(t != nullptr);
19444 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::type_argument, false, t, nullptr, nullptr);
19445 return r;
19446}
19447
19448SgTemplateArgument * buildTemplateArgument(SgExpression * e) {
19449 ROSE_ASSERT(e != nullptr);
19450 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
19451 e->set_parent(r);
19452 return r;
19453}
19454
19455SgTemplateArgument * buildTemplateArgument(int v) {
19457 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
19458 e->set_parent(r);
19459 return r;
19460}
19461
19462SgTemplateArgument * buildTemplateArgument(bool v) {
19464 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
19465 e->set_parent(r);
19466 return r;
19467}
19468
19469std::string strTemplateArgument(int v) {
19470 std::ostringstream oss;
19471 oss << v;
19472 return oss.str();
19473}
19474
19475std::string strTemplateArgument(bool v) {
19476 std::ostringstream oss;
19477 if (v) oss << "true";
19478 else oss << "false";
19479 return oss.str();
19480}
19481
19482std::string strTemplateArgument(SgNamedType * nt) {
19483 std::ostringstream oss;
19484 oss << nt->get_qualified_name().getString();
19485 return oss.str();
19486}
19487
19488std::string strTemplateArgument(SgType * t) {
19489 std::ostringstream oss;
19490 oss << t->unparseToString();
19491 return oss.str();
19492}
19493
19494std::string strTemplateArgument(SgExpression * e) {
19495 std::ostringstream oss;
19496 oss << e->unparseToString();
19497 return oss.str();
19498}
19499
19500#define DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps 0
19501
19502SgExpression * instantiateNonrealRefExps(
19503 SgExpression * expr,
19504 std::vector<SgTemplateParameter *> & tpl_params,
19505 std::vector<SgTemplateArgument *> & tpl_args
19506) {
19507#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19508 std::cout << "Rose::Builder::Templates::instantiateNonrealRefExps" << std::endl;
19509 std::cout << " expr = " << std::hex << expr << " : " << ( expr ? expr->class_name() : "" ) << std::endl;
19510#endif
19511 if (!expr) {
19512 return nullptr;
19513 } else if (isSgNonrealRefExp(expr)) {
19514 ROSE_ABORT();
19515 } else if (isSgVarRefExp(expr)) {
19516 SgVarRefExp * vref = (SgVarRefExp*)expr;
19517 SgInitializedName * iname = vref->get_symbol()->get_declaration();
19518 ROSE_ASSERT(iname);
19519#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19520 std::cout << " iname = " << std::hex << iname << " : " << ( iname ? iname->class_name() : "" ) << std::endl;
19521 std::cout << " iname->get_name() = " << iname->get_name() << std::endl;
19522 std::cout << " iname->get_initializer() = " << std::hex << iname->get_initializer() << " : " << ( iname->get_initializer() ? iname->get_initializer()->class_name() : "" ) << std::endl;
19523 std::cout << " iname->get_parent() = " << std::hex << iname->get_parent() << " : " << ( iname->get_parent() ? iname->get_parent()->class_name() : "" ) << std::endl;
19524 std::cout << " iname->get_parent()->get_parent() = " << std::hex << iname->get_parent()->get_parent() << " : " << ( iname->get_parent()->get_parent() ? iname->get_parent()->get_parent()->class_name() : "" ) << std::endl;
19525#endif
19526
19527 unsigned pos = 0;
19528 for (auto tpl_param: tpl_params) {
19529 if (tpl_param->get_initializedName()) {
19530#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19531 std::cout << " tpl_param->get_initializedName() = " << std::hex << tpl_param->get_initializedName() << std::endl;
19532 std::cout << " tpl_param->get_initializedName()->get_name() = " << tpl_param->get_initializedName()->get_name() << std::endl;
19533#endif
19534 if (tpl_param->get_initializedName()->get_name() == iname->get_name()) {
19535 iname = tpl_param->get_initializedName();
19536 break;
19537 }
19538 }
19539 pos++;
19540 }
19541
19542 if (pos < tpl_params.size() && pos < tpl_args.size()) {
19543 ROSE_ASSERT(tpl_args[pos]->get_expression());
19544 return tpl_args[pos]->get_expression();
19545 } else if (pos < tpl_params.size()) {
19546 SgExpression * dft = tpl_params[pos]->get_defaultExpressionParameter();
19547 ROSE_ASSERT(dft);
19548 return instantiateNonrealRefExps(dft, tpl_params, tpl_args);
19549 }
19550
19551 return vref;
19552 } else if (isSgValueExp(expr)) {
19553 return expr;
19554 } else if (isSgConditionalExp(expr)) {
19555 SgConditionalExp * cond = (SgConditionalExp*)expr;
19556 cond->set_conditional_exp(instantiateNonrealRefExps(cond->get_conditional_exp(), tpl_params, tpl_args));
19557 cond->set_true_exp(instantiateNonrealRefExps(cond->get_true_exp(), tpl_params, tpl_args));
19558 cond->set_false_exp(instantiateNonrealRefExps(cond->get_false_exp(), tpl_params, tpl_args));
19559 return cond;
19560 } else if (isSgSizeOfOp(expr)) {
19561 SgSizeOfOp * szo = (SgSizeOfOp*)expr;
19562 szo->set_operand_expr(instantiateNonrealRefExps(szo->get_operand_expr(), tpl_params, tpl_args));
19563 szo->set_operand_type(instantiateNonrealTypes(szo->get_operand_type(), tpl_params, tpl_args));
19564 return szo;
19565 } else if (isSgCastExp(expr)) {
19566 SgCastExp * cast = (SgCastExp*)expr;
19567 cast->set_operand_i(instantiateNonrealRefExps(cast->get_operand_i(), tpl_params, tpl_args));
19568 cast->set_type(instantiateNonrealTypes(cast->get_type(), tpl_params, tpl_args));
19569 return cast;
19570 } else if (isSgUnaryOp(expr)) {
19571 SgUnaryOp * uop = (SgUnaryOp*)expr;
19572 uop->set_operand_i(instantiateNonrealRefExps(uop->get_operand_i(), tpl_params, tpl_args));
19573 return uop;
19574 } else if (isSgBinaryOp(expr)) {
19575 SgBinaryOp * bop = (SgBinaryOp*)expr;
19576 bop->set_lhs_operand_i(instantiateNonrealRefExps(bop->get_lhs_operand_i(), tpl_params, tpl_args));
19577 bop->set_rhs_operand_i(instantiateNonrealRefExps(bop->get_rhs_operand_i(), tpl_params, tpl_args));
19578 return bop;
19579 } else {
19580 std::cerr << "!!! expr = " << std::hex << expr << " : " << ( expr ? expr->class_name() : "" ) << std::endl;
19581 ROSE_ABORT();
19582 }
19583}
19584
19585#define DEBUG_Rose_Builder_Templates_instantiateNonrealTypes 0
19586
19587SgType * instantiateNonrealTypes(
19588 SgType * type,
19589 std::vector<SgTemplateParameter *> & tpl_params,
19590 std::vector<SgTemplateArgument *> & tpl_args
19591) {
19592#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19593 std::cout << "Rose::Builder::Templates::instantiateNonrealTypes" << std::endl;
19594 std::cout << " type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
19595#endif
19596 if (!type) {
19597 return nullptr;
19598 } else if (isSgNonrealType(type)) {
19599 SgNonrealType * nrtype = (SgNonrealType*)type;
19600 SgNonrealDecl * nrdecl = isSgNonrealDecl(nrtype->get_declaration());
19601 ROSE_ASSERT(nrdecl != nullptr);
19602#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19603 std::cout << " nrdecl = " << std::hex << nrdecl << " : " << nrdecl->class_name() << std::endl;
19604 std::cout << " ->get_tpl_args() = " << std::dec << nrdecl->get_tpl_args().size() << std::endl;
19605 std::cout << " ->get_tpl_params() = " << std::dec << nrdecl->get_tpl_params().size() << std::endl;
19606 std::cout << " ->get_is_class_member() = " << ( nrdecl->get_is_class_member() ? "true" : "false" ) << std::endl;
19607 std::cout << " ->get_is_template_param() = " << ( nrdecl->get_is_template_param() ? "true" : "false" ) << std::endl;
19608 std::cout << " ->get_is_template_template_param() = " << ( nrdecl->get_is_template_template_param() ? "true" : "false" ) << std::endl;
19609 std::cout << " ->get_is_nonreal_template() = " << ( nrdecl->get_is_nonreal_template() ? "true" : "false" ) << std::endl;
19610 std::cout << " ->get_is_nonreal_function() = " << ( nrdecl->get_is_nonreal_function() ? "true" : "false" ) << std::endl;
19611#endif
19612 SgDeclarationStatement * tpldecl = nrdecl->get_templateDeclaration();
19613 if (tpldecl != nullptr) {
19614#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19615 std::cout << " tpldecl = " << std::hex << tpldecl << " : " << tpldecl->class_name() << std::endl;
19616#endif
19617
19618 SgTemplateClassDeclaration * xtpldecl = isSgTemplateClassDeclaration(tpldecl);
19619 if (xtpldecl != nullptr) {
19620#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19621 std::cout << " xtpldecl->get_name() = " << xtpldecl->get_name() << std::endl;
19622#endif
19623 std::vector<SgTemplateArgument *> inst_tpl_args;
19624 for (SgTemplateArgument * tplarg: nrdecl->get_tpl_args()) {
19625 if (tplarg->get_type()) {
19626#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19627 std::cout << " tplarg->get_type() = " << std::hex << tplarg->get_type() << " : " << ( tplarg->get_type() ? tplarg->get_type()->class_name() : "" ) << std::endl;
19628#endif
19629 auto inst_tplarg = instantiateNonrealTypes(tplarg->get_type(), tpl_params, tpl_args);
19630 if (inst_tplarg)
19631 inst_tpl_args.push_back(buildTemplateArgument(inst_tplarg));
19632 else
19633 break; // nullptr is interpreted as "use default argument from this one"
19634 } else if (tplarg->get_expression()) {
19635#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19636 std::cout << " tplarg->get_expression() = " << std::hex << tplarg->get_expression() << " : " << ( tplarg->get_expression() ? tplarg->get_expression()->class_name() : "" ) << std::endl;
19637 std::cout << " ->unparseToString() = " << tplarg->get_expression()->unparseToString() << std::endl;
19638#endif
19639 auto inst_tplarg = instantiateNonrealRefExps(SageInterface::copyExpression(tplarg->get_expression()), tpl_params, tpl_args);
19640#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19641 std::cout << " inst_tplarg = " << std::hex << inst_tplarg << " : " << ( inst_tplarg ? inst_tplarg->class_name() : "" ) << std::endl;
19642 std::cout << " inst_tplarg->unparseToString() = " << ( inst_tplarg ? inst_tplarg->unparseToString() : "" ) << std::endl;
19643#endif
19644 if (inst_tplarg)
19645 inst_tpl_args.push_back(buildTemplateArgument(inst_tplarg));
19646 else
19647 break; // nullptr is interpreted as "use default argument from this one"
19648 } else if (tplarg->get_templateDeclaration()) {
19649#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19650 std::cout << " tplarg->get_templateDeclaration() = " << std::hex << tplarg->get_templateDeclaration() << " : " << ( tplarg->get_templateDeclaration() ? tplarg->get_templateDeclaration()->class_name() : "" ) << std::endl;
19651#endif
19652 ROSE_ABORT(); // TODO
19653 } else {
19654 ROSE_ABORT();
19655 }
19656 }
19657 SgTemplateInstantiationDecl * inst_decl = isSgTemplateInstantiationDecl(SageBuilder::buildClassDeclaration_nfi(
19658 xtpldecl->get_name(), SgClassDeclaration::e_struct, xtpldecl->get_scope(), nullptr, true, &inst_tpl_args
19659 ));
19660 ROSE_ASSERT(inst_decl);
19661#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19662 std::cout << " inst_decl = " << std::hex << inst_decl << " : " << inst_decl->class_name() << std::endl;
19663 std::cout << " inst_decl->get_firstNondefiningDeclaration() = " << std::hex << inst_decl->get_firstNondefiningDeclaration() << std::endl;
19664 std::cout << " inst_decl->get_definingDeclaration() = " << std::hex << inst_decl->get_definingDeclaration() << std::endl;
19665#endif
19666 ROSE_ASSERT(inst_decl->get_definingDeclaration());
19667 ROSE_ASSERT(inst_decl->get_definingDeclaration() == inst_decl);
19668 inst_decl->set_templateDeclaration(xtpldecl);
19669 ((SgTemplateInstantiationDecl *)(inst_decl->get_firstNondefiningDeclaration()))->set_templateDeclaration(xtpldecl);
19670
19671 xtpldecl->get_scope()->append_statement(inst_decl);
19672 return inst_decl->get_type();
19673 } else {
19674 ROSE_ABORT(); // TODO probably typedef
19675 }
19676 } else if (nrdecl->get_is_template_param()) {
19677#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19678 std::cout << " ->get_template_parameter_position() = " << std::dec << nrdecl->get_template_parameter_position() << std::endl;
19679 std::cout << " ->get_template_parameter_depth() = " << std::dec << nrdecl->get_template_parameter_depth() << std::endl;
19680#endif
19681 ROSE_ASSERT(nrdecl->get_template_parameter_position() > 0);
19682 if (nrdecl->get_template_parameter_position() <= tpl_args.size()) {
19683 return tpl_args[nrdecl->get_template_parameter_position()-1]->get_type();
19684// } else if (nrdecl->get_template_parameter_position() <= tpl_params.size()) {
19685// SgType * dft_tpl_arg = tpl_params[nrdecl->get_template_parameter_position()-1]->get_defaultTypeParameter();
19686// return instantiateNonrealTypes(dft_tpl_arg, tpl_params, tpl_args);
19687 } else {
19688 return nullptr;
19689 }
19690 }
19691 } else if (isSgTypedefType(type) || isSgTypeUnsignedLong(type) || isSgTypeUnsignedInt(type)) {
19692 return type;
19693 } else {
19694 std::cerr << "!!! type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
19695 ROSE_ABORT(); // TODO maybe pointer/reference/const type
19696 }
19697 return nullptr;
19698}
19699
19700} } }
19701
to specify a construct using a specifier Can be used alone or with parent handles when relative speci...
Users should provide a concrete node implementation especially a constructor/builder to avoid duplica...
Attribute containing a regex expression as a string.
Attribute storing an SgNode.
Class for traversing the AST.
virtual void visit(SgNode *astNode)=0
this method is called at every traversed node.
For preprocessing information including source comments, include , if, define, etc.
RelativePositionType
MK: Enum type to store if the directive goes before or after the corresponding line of source code.
AST iterator.
Definition RoseAst.h:54
Interface for iterating over an AST.
Definition RoseAst.h:26
iterator begin()
Iterator positioned at root of subtree.
iterator end()
Iterator positioned at the end of the traversal.
Collection of streams.
Definition Message.h:1606
std::string comment() const
Property: Comment associated with facility.
This class represents the concept of a C Assembler statement.
This class represents the rhs of a variable declaration which includes an optional assignment (e....
This class represents the concept of a block (not a basic block from control flow analysis).
This class represents the notion of a binary operator. It is derived from a SgExpression because oper...
void set_rhs_operand_i(SgExpression *rhs_operand_i)
This function allows the p_rhs_operand_i pointer to be set (used internally).
SgExpression * get_lhs_operand() const
returns SgExpression pointer to the lhs operand associated with this binary operator.
SgExpression * get_rhs_operand_i() const
returns SgExpression pointer to the operand associated with this binary operator.
SgExpression * get_lhs_operand_i() const
returns SgExpression pointer to the operand associated with this binary operator.
void set_lhs_operand_i(SgExpression *lhs_operand_i)
This function allows the p_lhs_operand_i pointer to be set (used internally).
SgExpression * get_rhs_operand() const
returns SgExpression pointer to the rhs operand associated with this binary operator.
This class represents a boolean value (expression value).
This class represents the notion of a break statement (typically used in a switch statment).
This class represents the concept of a C and C++ case option (used within a switch statement).
This class represents a cast of one type to another.
cast_type_enum
Classification of Casts.
SgType * get_type() const override
unparsing support for pragmas
This class represents the concept of a catch within a try-catch construct used in C++ exception handl...
This class represents the concept of a C++ sequence of catch statements.
This class represents the concept of a class declaration statement. It includes the concept of an ins...
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
virtual std::string class_name() const override
returns a string representing the class name
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
SgScopeStatement * get_scope() const override
Returns scope of current statement.
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the concept of a class definition in C++.
SgClassDeclaration * get_declaration() const
returns the class declaration associated with this class decinition.
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a C++ expression built from a class name.
This class represents the concept of a class name within the compiler.
virtual std::string class_name() const override
returns a string representing the class name
SgType * get_type() const override
This function returns the type associated with the named entity.
virtual std::string class_name() const override
returns a string representing the class name
virtual SgName get_mangled(void) const override
Mangled name support for unparser support.
SgName get_name() const override
Support for some classes which have pure virtual function in base classes.
static SgClassType * createType(SgDeclarationStatement *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgClassType (types whose constructors take par...
This class represents the concept of a C trinary conditional expression (e.g. "test ?...
SgExpression * get_true_exp() const
Access function for p_true_exp.
void set_false_exp(SgExpression *false_exp)
Access function for p_false_exp.
SgExpression * get_conditional_exp() const
Access function for p_conditional_exp.
SgExpression * get_false_exp() const
Access function for p_false_exp.
void set_true_exp(SgExpression *true_exp)
Access function for p_true_exp.
void set_conditional_exp(SgExpression *conditional_exp)
Access function for p_conditional_exp.
cv_modifier_enum
Const Volatile Modifier.
This class represents the call of a class constructor to initialize a variable. For example "Foo foo;...
This class represents the concept of a C or C++ continue statement.
This class represents the concept of a contructor initializer list (used in constructor (member funct...
static SgDeclType * createType(SgExpression *expr=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgDeclType (types whose constructors take para...
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a declaration statement.
SgSymbol * search_for_symbol_from_symbol_table() const
User interface for retrieving the associated symbol from the declaration.
void set_definingDeclaration(SgDeclarationStatement *definingDeclaration)
This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see tha...
void set_firstNondefiningDeclaration(SgDeclarationStatement *firstNondefiningDeclaration)
This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member ...
SgDeclarationStatement * get_definingDeclaration() const
This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see tha...
virtual VariantT variantT() const override
returns new style SageIII enum values
virtual std::string class_name() const override
returns a string representing the class name
SgDeclarationStatement * get_firstNondefiningDeclaration() const
This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member ...
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
void setForward()
Marks a declaration as a forward declaration.
This class represents the concept of a C or C++ default case within a switch statement.
This class represents the concept of a C++ call to the delete operator.
This class represents the concept of a do-while statement.
SgStatement * get_condition() const
Access function for p_condition.
SgStatement * get_body() const
Access function for p_body.
void set_condition(SgStatement *condition)
Access function for p_condition.
void set_body(SgStatement *body)
Access function for p_body.
This class represents the notion of an value (expression value).
This class represents the concept of an enum declaration.
void set_type(SgEnumType *type)
Access function for p_type.
SgScopeStatement * get_scope() const override
Access function for p_scope.
SgName get_name() const
Access function for p_name.
void set_scope(SgScopeStatement *scope) override
Access function for p_scope.
SgEnumType * get_type() const
Access function for p_type.
SgType * get_type() const override
This function returns the type associated with the named entity.
This class represents the concept of the dynamic execution of a string, file, or code object....
This class represents the concept of a C and C++ expression list.
This class represents the concept of a C or C++ statement which contains a expression.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes,...
virtual std::string class_name() const override
returns a string representing the class name
void set_need_paren(bool need_paren)
This function allows the p_need_paren flag to be set (used internally).
virtual SgType * get_type() const
unparsing support for pragmas
bool hasExplicitType()
Some expressions store internal SgType pointers explicitly while others compute them from other expre...
virtual Sg_File_Info * get_file_info(void) const override
Interface function to implement original SAGE interface to SgFile_Info objects.
void set_lvalue(bool lvalue)
This function allows the p_lvalue flag to be set (used internally).
void set_explicitly_stored_type(SgType *type)
Some expressions store internal SgType pointers explicitly, this allows these IR nodes to be reset wi...
This class represents a source file for a project (which may contian many source files and or directo...
Sg_File_Info * get_startOfConstruct() const override
New function interface for Sg_File_Info data stores starting location of contruct (typically the open...
void secondaryPassOverSourceFile()
Fixups to be run when the whole project has been created (this attaches preprocessing information).
@ e_Fortran_language
std::string getFileName() const
associated filename
virtual std::string class_name() const override
returns a string representing the class name
Sg_File_Info * get_file_info() const override
Access function calling get_startOfConstruct(), provided to support older interface.
This class represents the notion of an value (expression value).
This class represents the variable declaration or variable initialization withn a for loop.
const SgStatementPtrList & get_init_stmt() const
Returns const reference to a SgStatementPtrList (typedef to a STL list).
This class represents the concept of a for loop.
SgForInitStatement * get_for_init_stmt() const
Access function for p_for_init_stmt.
void set_loop_body(SgStatement *loop_body)
Access function for p_loop_body.
SgStatement * get_loop_body() const
Access function for p_loop_body.
void set_for_init_stmt(SgForInitStatement *for_init_stmt)
Access function for p_for_init_stmt.
This class represents the concept of a C++ function call (which is an expression).
This class represents the concept of a function declaration statement.
SgScopeStatement * get_scope() const override
Returns scope of current statement.
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
void set_body(SgBasicBlock *body)
Access function for p_body.
This class represents the concept of a declaration list.
const SgInitializedNamePtrList & get_args() const
Access function for p_args.
const SgTypePtrList & get_arguments() const
Get a const list of input types (types of the parameters list) to this function type (from a cost fun...
This class represents the function being called and must be assembled in the SgFunctionCall with the ...
SgType * get_type() const override
Get the type associated with this expression.
virtual std::string class_name() const override
returns a string representing the class name
SgName get_name() const override
Access function for getting name from declarations or types internally.
This class represents the function type table (stores all function types so that they can be shared i...
This class represents a type for all functions.
virtual std::string class_name() const override
returns a string representing the class name
virtual SgName get_mangled(void) const override
Mangled name support for unparser support.
This class represents the concept of a namespace definition.
virtual std::string class_name() const override
returns a string representing the class name
const SgDeclarationStatementPtrList & get_declarations() const
Returns a const list to the global scope declarations.
This class represents the concept of a C or C++ goto statement.
This class represents the concept of an "if" construct.
void set_use_then_keyword(bool use_then_keyword)
Fortran specific function to indicate if the Fortran "if" statement uses the "then" construct (C/C++ ...
void set_has_end_statement(bool has_end_statement)
Fortran specific function to indicate if the Fortran "if" statement has an "end" construct (C/C++ use...
This class represents the notion of a declared variable.
SgName get_qualified_name() const
Returns the name with appropriate qualified names representing nested scopes.
SgSymbol * get_symbol_from_symbol_table() const
Get the associated SgSymbol from the symbol table located in the scope, without considering possible ...
virtual std::string class_name() const override
returns a string representing the class name
SgSymbol * search_for_symbol_from_symbol_table() const
User interface for retrieving the associated symbol. It searches through the possible chain of prev_d...
This class represents the notion of an initializer for a variable declaration or expression in a func...
virtual std::string class_name() const override
returns a string representing the class name
static SgJavaParameterType * createType(SgClassDeclaration *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgJavaParameterType (types whose constructors ...
static SgJovialBitType * createType(SgExpression *size=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgJovialBitType (types whose constructors take...
static SgJovialTableType * createType(SgClassDeclaration *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgJovialTableType (types whose constructors ta...
This class represents the concept of a C or C++ label statement.
This class represents a lambda expression.
This class represents a list display.
This class represents the notion of an expression or statement which has a position within the source...
virtual std::string class_name() const override
returns a string representing the class name
Sg_File_Info * get_endOfConstruct() const override
New function interface for Sg_File_Info data stores ending location of contruct (typically the closin...
void set_endOfConstruct(Sg_File_Info *endOfConstruct)
This function sets the current source location position of the end of the current construct.
Sg_File_Info * get_startOfConstruct() const override
New function interface for Sg_File_Info data stores starting location of contruct (typically the open...
virtual Sg_File_Info * get_file_info() const override
Interface function to implement original SAGE interface to SgFile_Info objects.
This class represents the notion of an value (expression value).
This class represents the concept of a member function declaration statement.
SgCtorInitializerList * get_CtorInitializerList() const
Access function for p_CtorInitializerList.
void set_associatedClassDeclaration(SgDeclarationStatement *associatedClassDeclaration)
This is an access function for the p_associatedClassDeclaration data member.
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
This class represents the member function being called and must be assembled in the SgFunctionCall wi...
SgType * get_type() const override
Get the type associated with this expression.
SgName get_name() const override
Access function for getting name from declarations or types internally.
SgType * get_type() const override
This function returns the type associated with the named entity.
virtual std::string class_name() const override
returns a string representing the class name
bool isLvalueReferenceFunc() const
L-value reference access/set/unset member functions and member function type.
bool isRvalueReferenceFunc() const
R-value reference access/set/unset member functions and member function type.
virtual SgName get_mangled(void) const override
Mangled name support for unparser support.
static SgMemberFunctionType * createType(SgPartialFunctionType *type=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgMemberFunctionType (types whose constructors...
This class represents the numeric negation of a value. Not to be confused with SgSubtractOp.
SgTypeModifier & get_typeModifier()
Access function for modifier.
virtual std::string class_name() const override
returns a string representing the class name
This class represents strings within the IR nodes.
virtual std::string class_name() const override
returns a string representing the class name
SgName get_qualified_name() const
Used for the SgNamedType object (base class for the SgClassType, SgTypedefType and the SgEnumType obj...
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the concept of a C++ namespace alias declaration statement.
This class represents the concept of a C++ namespace declaration.
SgName get_name() const
Access function for p_name.
SgNamespaceDefinitionStatement * get_definition() const
Returns pointer to SgNamespaceDefinitionStatement.
This class represents the concept of a namespace definition.
This class represents the concept of a namespace name within the compiler.
SgNamespaceDeclarationStatement * get_declaration() const
Access function for getting the declaration of the original namespace.
This class represents the notion of an n-ary boolean operation. This node is intended for use with Py...
This class represents the notion of an n-ary comparison operation. This node is intended for use with...
This class represents the concept of a C++ call to the new operator.
This class represents the base class for all IR nodes within Sage III.
static void clearGlobalMangledNameMap()
Support to clear the performance optimizing global mangled name map.
virtual Sg_File_Info * get_endOfConstruct(void) const
New function interface for Sg_File_Info data stores ending location of contruct (typically the closin...
SgNode * get_parent() const
Access function for parent node.
void set_isModified(bool isModified)
All nodes in the AST contain a isModified flag used to track changes to the AST.
virtual VariantT variantT() const
returns new style SageIII enum values
void set_parent(SgNode *parent)
All nodes in the AST contain a reference to a parent node.
virtual std::string unparseToString(SgUnparse_Info *info) const
This function unparses the AST node (excluding comments and unnecessary white space)
virtual std::string class_name() const
returns a string representing the class name
static std::map< SgNode *, std::string > & get_globalMangledNameMap()
Access function for performance optimizing global mangled name map.
static SgFunctionTypeTable * get_globalFunctionTypeTable()
Access function for symbol table specific to function types.
virtual Sg_File_Info * get_file_info(void) const
File information containing filename, line number, column number, and if the SgNode is a part of a ne...
bool get_isModified() const
Acess function for isModified flag.
virtual std::string class_name() const override
returns a string representing the class name
virtual std::string class_name() const override
returns a string representing the class name
virtual std::string class_name() const override
returns a string representing the class name
static SgPointerType * createType(SgType *type=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgPointerType (types whose constructors take p...
This class represents the concept of a C Assembler statement (untested).
subprogram_kind_enum
Classification for different types of Fortran subprograms.
This class represents a source project, with a list of SgFile objects and global information about th...
void set_originalCommandLineArgumentList(SgStringList originalCommandLineArgumentList)
Sets the list of strings representing the original command-line.
SgStringList get_originalCommandLineArgumentList() const
Returns a list of strings representing the original command-line.
void set_file(SgFile &)
Access function for putting a new SgFile object into the list stored internally This function is depr...
This class represents the concept of a 'global' stmt in Python.
virtual void append_name(SgInitializedName *element)
Append a name to the list of identifiers imported into the inner scope.
static SgReferenceType * createType(SgType *type=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgReferenceType (types whose constructors take...
This class represents the concept of a C Assembler statement (untested).
static SgRvalueReferenceType * createType(SgType *type=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgRvalueReferenceType (types whose constructor...
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
bool isNamedScope()
Some scopes have associated names for purposed of name qualification. This returns true if the scope ...
SgSymbolTable * get_symbol_table() const
Returns a pointer to the locally strored SgSymbolTable.
void append_statement(SgStatement *stmt)
Higher level function to handle statements and declarations is scopes.
virtual std::string class_name() const override
returns a string representing the class name
bool containsOnlyDeclarations() const
This function is used to indicate if either the getDeclarationList() or getStatementList() can be cal...
void insert_symbol(const SgName &n, SgSymbol *s)
Puts a SgSymbol object into the local symbol table.
This class represents the "sizeof()" operator (applied to any type).
virtual std::string class_name() const override
returns a string representing the class name
This class represents the GNU extension "statement expression" (thus is non-standard C and C++).
This class represents the notion of a statement.
virtual std::string class_name() const override
returns a string representing the class name
virtual void set_scope(SgScopeStatement *newScope)
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
virtual bool hasExplicitScope() const
Support for where the scope is explicitly required.
virtual SgScopeStatement * get_scope(void) const
Returns scope of current statement.
This class is intended to be a wrapper around SgStatements, allowing them to exist in scopes that onl...
void setExtern()
Set storage.
bool isExtern() const
Storage modifier is extern (not the same as extern "C").
storage_modifier_enum
Storage Modifiers (only one value can be specified)
This class represents the conversion of an arbitrary expression to a string. This node is intended fo...
This class represents the concept of a switch.
void print(std::string label, VariantT nodeType=V_SgSymbol)
Outputs symbol table information (useful for debugging)
int size() const
Computes the number of symbols in the symbol table (forced to count them, I think,...
This class represents the concept of a name within the compiler.
This class represents template argument within the use of a template to build an instantiation.
SgExpression * get_expression() const
This function returns argumentExpression.
SgType * get_type() const
This function returns argumentType.
SgTemplateArgument::template_argument_enum get_argumentType() const
This function returns argumentType.
virtual std::string class_name() const override
returns a string representing the class name
SgType * get_type() const override
This function returns the type associated with the named entity.
This class represents the concept of a template declaration.
This class represents the concept of an instantiated class template.
virtual std::string class_name() const override
returns a string representing the class name
void set_templateDeclaration(SgTemplateClassDeclaration *templateDeclaration)
Access function for p_templateDeclaration.
SgName get_templateName() const
Returns name of class template, the name excludes template arguments.
void set_templateName(SgName templateName)
sets name of instantiated class template, name excludes template arguments.
const SgTemplateArgumentPtrList & get_templateArguments() const
Returns pointer to STL list of pointers to SgTemplateArgument objects.
SgTemplateClassDeclaration * get_templateDeclaration() const
Returns pointer to SgTemplateDeclaration from which instantiation is generated.
This class represents the concept of a class definition in C++.
This class represents the concept of an instantiation of function template.
const SgTemplateArgumentPtrList & get_templateArguments() const
Returns pointer to STL list of pointers to SgTemplateArgument objects.
SgName get_templateName() const
Returns name of instantiated function template, name includes template arguments.
void set_templateName(SgName templateName)
sets name of instantiated function template, name includes template arguments.
This class represents the concept of an instantiation of member function template or a member functio...
void set_templateName(SgName templateName)
sets name of instantiated function template, name includes template arguments.
virtual std::string class_name() const override
returns a string representing the class name
const SgTemplateArgumentPtrList & get_templateArguments() const
Returns pointer to STL list of pointers to SgTemplateArgument objects.
SgName get_templateName() const
Returns name of instantiated function template, name includes template arguments.
virtual std::string class_name() const override
returns a string representing the class name
virtual std::string class_name() const override
returns a string representing the class name
This class represents the "this" operator (can be applied to any member data).
This class represents the C++ throw expression (handled as a unary operator).
e_throw_kind
Throw IR node can be used in three different ways.
This class represents the concept of try statement within the try-catch support for exception handlin...
SgCatchStatementSeq * get_catch_statement_seq_root() const
Returns pointer to SgCatchStatementSeq.
This class represents a tuple display.
static SgTypeBool * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeChar16 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeChar32 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeChar * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents a C99 complex type.
static SgTypeDouble * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFixed * createType(SgExpression *scale=NULL, SgExpression *fraction=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypeFixed (types whose constructors take par...
static SgTypeFloat128 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat80 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents a C99 complex type.
static SgTypeInt * createType(int sz=0, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypeInt (types whose constructors take param...
static SgTypeLongDouble * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeLongLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeNullptr * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeOfType * createType(SgExpression *expr=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypeOfType (types whose constructors take pa...
static SgTypeShort * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSigned128bitInteger * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedChar * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedInt * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedLongLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedShort * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents a string type used for SgStringVal IR node.
static SgTypeUnknown * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsigned128bitInteger * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedChar * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedInt * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedLongLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedShort * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeVoid * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeWchar * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents the base class for all types.
std::vector< SgType * > getInternalTypes() const
Generate a container of types hidden in the input type.
SgType * stripType(unsigned char bit_array=STRIP_MODIFIER_TYPE|STRIP_REFERENCE_TYPE|STRIP_RVALUE_REFERENCE_TYPE|STRIP_POINTER_TYPE|STRIP_ARRAY_TYPE|STRIP_TYPEDEF_TYPE|STRIP_POINTER_MEMBER_TYPE) const
Returns hidden type beneath layers of typedefs, pointers, references, modifiers, array representation...
virtual std::string class_name() const override
returns a string representing the class name
This class represents the notion of a typedef declaration.
SgScopeStatement * get_scope() const override
Returns scope of current statement.
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
SgType * get_type() const override
This function returns the type associated with the named entity.
virtual std::string class_name() const override
returns a string representing the class name
SgType * get_base_type() const
This is used in the SgTypedefType object (is not associated with a base_type data field)
static SgTypedefType * createType(SgTypedefDeclaration *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypedefType (types whose constructors take p...
This class represents the notion of a unary operator. It is derived from a SgExpression because opera...
void set_mode(SgUnaryOp::Sgop_mode mode)
Set the mode (prefix/postfix) associated with this operator.
SgExpression * get_operand_i() const
returns SgExpression pointer to the operand associated with this unary operator.
Sgop_mode
Enum value defines operators as prefix or postfix, as appropriate, e.g. operator++().
void set_operand_i(SgExpression *operand_i)
This function allows the p_operand_i pointer to be set (used internally).
This class represents the concept of a C++ using directive.
This class represents the notion of an value (expression value).
This class represents the variable refernece in expressions.
This class represents the concept of a C or C++ variable declaration.
const SgInitializedNamePtrList & get_variables() const
Access function for p_variables.
This class represents the definition (initialization) of a variable.
void set_vardefn(SgInitializedName *vardefn)
Access function for SgInitializedName in p_vardefn.
This class represents the concept of a variable name within the compiler (a shared container for the ...
SgName get_name() const override
Access function for getting name from declarations or types internally.
This class represents the concept of a do-while statement.
This class represents the location of the code associated with the IR node in the original source cod...
static std::map< std::string, int > & get_nametofileid_map()
Access function for static datamember nametofileid_map.
void setTransformation()
Marks an IR node to be a transformation if it is not one already.
const char * get_filename() const
Returns filename of source code associated with IR node.
bool isOutputInCodeGeneration() const
Returns true only if required to be unparsed in generated code.
void unsetOutputInCodeGeneration()
Mark as to be output by the unparser (code generator)
int get_line() const
Returns the line number of the associated code for this IR node.
void setShared()
Marks IR node as shared.
void setCompilerGenerated()
Marks IR node as compiler generated.
bool isShared() const
Returns true only if shared internally (either by the front-end or by ROSE).
ROSE_DLL_API roseNode * buildroseNode(SgNode *snode)
A builder function to avoid duplicated building.
ROSE_DLL_API const char * c_char
A namespace scope char* to avoid passing and returning a target c string for every and each function ...
ROSE_DLL_API SgNode * c_sgnode
current anchor SgNode associated with parsing. It will serve as a start point to find enclosing scope...
ROSE_DLL_API SgNode * c_parsed_node
Store the AST substree (expression, statement) generated from a helper function.
ROSE_DLL_API bool afs_match_statement()
match any statement, not complete yet. Don't use it yet . : labeled_statement | compound_statement | ...
ROSE_DLL_API std::vector< std::string > generateSourceFilenames(std::vector< std::string > argList, bool binaryMode)
Build the list of isolated file names from the command line.
ROSE_UTIL_API void removeAllFileNamesExcept(std::vector< std::string > &argv, std::vector< std::string > filenameList, std::string exceptFilename)
Remove file names specified in filenameList from argv, except for 'exceptFilename'.
Controls diagnostic messages from ROSE.
ROSE_DLL_API void initAndRegister(Facility *mlog, const std::string &name)
Initialize and register a logging facility.
ROSE_DLL_API Sawyer::Message::Facility mlog
Diagnostic facility for the ROSE library as a whole.
Definition sageBuilder.C:58
ROSE_UTIL_API std::string intToHex(uint64_t)
Convert an integer to a hexadecimal string.
The ROSE library.
Functions that build an AST.
Definition sageBuilder.h:32
ROSE_DLL_API SgTemplateInstantiationTypedefDeclaration * buildTemplateInstantiationTypedefDeclaration_nfi(SgName &name, SgType *base_type, SgScopeStatement *scope, bool has_defining_base, SgTemplateTypedefDeclaration *templateTypedefDeclaration, SgTemplateArgumentPtrList &templateArgumentsList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgJavaMemberValuePair * buildJavaMemberValuePair(const SgName &, SgExpression *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgCastExp * buildCastExp_nfi(SgExpression *operand_i, SgType *expression_type, SgCastExp::cast_type_enum cast_type)
ROSE_DLL_API SgUpcBarrierStatement * buildUpcBarrierStatement_nfi(SgExpression *exp)
Build a UPC barrier statement.
ROSE_DLL_API SgAtomicStmt * buildAtomicStmt(SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAtStmt * buildAtStmt(SgExpression *expression, SgBasicBlock *body)
MH (6/11/2014): Added at support.
ROSE_DLL_API SgJovialBitType * buildJovialBitType(SgExpression *size)
Build a Jovial bit type of a given size.
ROSE_DLL_API SgColonShapeExp * buildColonShapeExp()
Build a Fortran colon-shape expression, set file info as the default one.
ROSE_DLL_API SgJovialTableType * buildJovialTableType(const SgName &name, SgType *base_type, SgExprListExp *dim_info, SgScopeStatement *scope=NULL)
Build a Jovial table type with required class definition and defining and nondefining declarations.
ROSE_DLL_API SgFunctionDeclaration * buildNondefiningFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope=NULL, SgExprListExp *decoratorList=NULL, bool buildTemplateInstantiation=false, SgTemplateArgumentPtrList *templateArgumentsList=NULL, SgStorageModifier::storage_modifier_enum sm=SgStorageModifier::e_default)
Build a prototype for a function, handle function type, symbol etc transparently.
ROSE_DLL_API SgTemplateArgumentPtrList * getTemplateArgumentList(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgSwitchStatement * buildSwitchStatement_nfi(SgStatement *item_selector, SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgBaseClass * buildBaseClass(SgClassDeclaration *classDeclaration, SgClassDefinition *classDefinition, bool isVirtual, bool isDirect)
DQ (5/6/2013): Added build functions to support SgBaseClass construction.
SourcePositionClassification
intended to be a private member, don't access it directly. could be changed any time
@ e_sourcePosition_last
Specify as source position to be filled in as part of AST construction in the front-end.
@ e_sourcePositionNullPointers
Classify as compiler generated code (e.g. template instantiation).
@ e_sourcePositionCompilerGenerated
Classify as a transformation.
@ e_sourcePositionFrontendConstruction
Set pointers to Sg_File_Info objects to NULL.
@ e_sourcePositionDefault
Error value for enum.
@ e_sourcePositionTransformation
Default source position.
ROSE_DLL_API SgFunctionParameterRefExp * buildFunctionParameterRefExp_nfi(int parameter_number, int parameter_level)
ROSE_DLL_API SgThrowOp * buildThrowOp(SgExpression *, SgThrowOp::e_throw_kind)
Build a ThrowOp expression.
ROSE_DLL_API SgPointerMemberType * buildPointerMemberType(SgType *base_type, SgType *classType)
Pei-Hung (06/30/2023): support for SgPointerMemberType.
ROSE_DLL_API SgPragma * buildPragma(const std::string &name)
Build SgPragma.
ROSE_DLL_API void testTemplateParameterParents(SgDeclarationStatement *decl)
DQ (9/16/2012): Added function to support setting the template parameters and setting their parents (...
ROSE_DLL_API SgStringConversion * buildStringConversion(SgExpression *exp)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgChooseExpression * buildChooseExpression_nfi()
ROSE_DLL_API SgJavaWildcardType * getUniqueJavaWildcardExtends(SgType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgUpcForAllStatement * buildUpcForAllStatement_nfi(SgStatement *initialize_stmt, SgStatement *test, SgExpression *increment, SgExpression *affinity, SgStatement *loop_body)
Build a UPC forall statement.
ROSE_DLL_API SgUnsignedLongVal * buildUnsignedLongValHex(unsigned long v=0)
ROSE_DLL_API SgClassType * buildClassTemplateType(SgTemplateClassDeclaration *template_decl, std::vector< SgNode * > &template_args)
Some support for building class template instantiation declarations.
ROSE_DLL_API SgNullptrValExp * buildNullptrValExp_nfi()
ROSE_DLL_API SgDerivedTypeStatement * buildDerivedTypeStatement(const SgName &name, SgScopeStatement *scope=NULL)
Build an SgDerivedTypeStatement Fortran derived type declaration with a class declaration and definit...
ROSE_DLL_API SgExprStatement * buildFunctionCallStmt(const SgName &name, SgType *return_type, SgExprListExp *parameters=NULL, SgScopeStatement *scope=NULL)
Build a regular function call statement.
ROSE_DLL_API SgExecStatement * buildExecStatement(SgExpression *executable, SgExpression *globals=NULL, SgExpression *locals=NULL)
Build an exec statement.
ROSE_DLL_API SgShortVal * buildShortValHex(short value=0)
ROSE_DLL_API SgClassDeclaration * buildClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgClassDeclaration *nonDefiningDecl, bool buildTemplateInstantiation, SgTemplateArgumentPtrList *templateArgumentsList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeSignedLongLong * buildSignedLongLongType()
Built in simple types.
ROSE_DLL_API SgNewExp * buildNewExp(SgType *type, SgExprListExp *exprListExp, SgConstructorInitializer *constInit, SgExpression *expr, short int val, SgFunctionDeclaration *funcDecl)
SgPythonGlobalStmt * buildPythonGlobalStmt_nfi(SgInitializedNamePtrList &names)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SourcePositionClassification getSourcePositionClassificationMode()
Get the current source position classification (defines how IR nodes built by the SageBuilder interfa...
SgNullStatement * buildNullStatement_nfi()
Build a NULL statement.
ROSE_DLL_API SgForStatement * buildForStatement_nfi(SgStatement *initialize_stmt, SgStatement *test, SgExpression *increment, SgStatement *loop_body, SgStatement *else_body=NULL)
Based on the contribution from Pradeep Srinivasa@ LANL.
ROSE_DLL_API SgTypeUnsignedLongLong * buildUnsignedLongLongType()
Built in simple types.
ROSE_DLL_API SgInitializedName * buildInitializedName_nfi(const SgName &name, SgType *type, SgInitializer *init)
Initialized names are tricky, their scope vary depending on context, so scope and symbol information ...
ROSE_DLL_API SgCompoundInitializer * buildCompoundInitializer(SgExprListExp *initializers=NULL, SgType *type=NULL)
Build a compound initializer, for vector type initialization.
ROSE_DLL_API SgTypeString * buildStringType()
DQ (8/21/2010): We want to move to the new buildStringType( SgExpression*,size_t) function over the o...
ROSE_DLL_API SgUpcThreads * buildUpcThreads_nfi()
Build UPC THREADS (integer expression)
ROSE_DLL_API SgModifierType * buildModifierType(SgType *base_type=nullptr)
Build a modifier type.
ROSE_DLL_API SgCaseOptionStmt * buildCaseOptionStmt(SgExpression *key=NULL, SgStatement *body=NULL)
Build a case option statement.
ROSE_DLL_API SgTemplateFunctionDeclaration * buildDefiningTemplateFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, SgTemplateFunctionDeclaration *first_nondefining_declaration)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgCatchOptionStmt * buildCatchOptionStmt(SgVariableDeclaration *condition=NULL, SgStatement *body=NULL)
Build a catch statement.
ROSE_DLL_API SgLongLongIntVal * buildLongLongIntVal_nfi(long long value, const std::string &str)
ROSE_DLL_API SgClassType * buildTemplateClassType(SgTemplateClassDeclaration *template_decl, std::vector< SgNode * > &template_args)
Same as buildClassTemplateType(), just better name.
SgFortranContinueStmt * buildFortranContinueStmt_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTemplateMemberFunctionDeclaration * buildNondefiningTemplateMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, SgTemplateParameterPtrList *templateParameterList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgLabelStatement * buildLabelStatement(const SgName &name, SgStatement *stmt=NULL, SgScopeStatement *scope=NULL)
Build a label statement, name is the label's name. Handling label symbol and scope internally.
ROSE_DLL_API SgFortranDo * buildFortranDo_nfi(SgExpression *initialization, SgExpression *bound, SgExpression *increment, SgBasicBlock *)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUpcThreads * buildUpcThreads()
Build UPC THREADS (integer expression)
ROSE_DLL_API SgModifierType * buildRestrictType(SgType *base_type)
Build a restrict type.
ROSE_DLL_API SgIntVal * buildIntVal_nfi(int value=0)
ROSE_DLL_API SgLongDoubleVal * buildLongDoubleVal(long double value=0.0)
SgFunctionParameterList * buildFunctionParameterList_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API AbstractHandle::abstract_handle * buildAbstractHandle(SgNode *n)
Build an abstract handle from a SgNode.
ROSE_DLL_API SgClassDeclaration * buildClassDeclaration(SgName name, SgScopeStatement *scope)
Build C++ class (builds both the non-defining and defining declarations; in that order).
ROSE_DLL_API SgMinusOp * buildMinusOp_nfi(SgExpression *op)
ROSE_DLL_API SgTemplateFunctionDeclaration * buildNondefiningTemplateFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope=NULL, SgExprListExp *decoratorList=NULL, SgTemplateParameterPtrList *templateParameterList=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAsmStmt * buildMultibyteNopStatement(int n)
DQ (4/30/2010): Added support for building nop statement using asm statement Building nop statement u...
ROSE_DLL_API SgKeyDatumPair * buildKeyDatumPair(SgExpression *key, SgExpression *datum)
Build a key-datum pair.
ROSE_DLL_API SgComprehension * buildComprehension(SgExpression *target, SgExpression *iter, SgExprListExp *ifs)
ROSE_DLL_API SgJavaParameterizedType * getUniqueJavaParameterizedType(SgNamedType *, SgTemplateParameterPtrList *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgComplexVal * buildImaginaryVal_nfi(SgValueExp *imaginary_value, const std::string &str)
ROSE_DLL_API SgFunctionCallExp * buildFunctionCallExp(SgFunctionSymbol *sym, SgExprListExp *parameters=NULL)
Build a function call expression.
ROSE_DLL_API SgType * getTargetFileType(SgType *snippet_type, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgTemplateParameter * buildTemplateParameter(SgTemplateParameter::template_parameter_enum parameterType, SgType *)
Build a template parameter, passing enum kind and SgTemplateType template_parameter_enum { parameter_...
ROSE_DLL_API SgNoexceptOp * buildNoexceptOp(SgExpression *exp=NULL)
Build noexcept operator expression with an expression parameter.
ROSE_DLL_API SgClassDeclaration * buildNondefiningClassDeclaration(SgName name, SgScopeStatement *scope)
DQ (11/7/2009): Added functions to build C++ class.
SgMemberFunctionRefExp * buildMemberFunctionRefExp_nfi(SgMemberFunctionSymbol *sym, bool virtual_call, bool need_qualifier)
ROSE_DLL_API SgFunctionDeclaration * buildDefiningFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, bool buildTemplateInstantiation=false, SgFunctionDeclaration *first_nondefinng_declaration=NULL, SgTemplateArgumentPtrList *templateArgumentsList=NULL)
Build a function declaration with a function body.
ROSE_DLL_API SgModifierType * buildUpcSharedType(SgType *base_type=nullptr, long layout=-1)
Build a UPC shared type.
ROSE_DLL_API SgGotoStatement * buildGotoStatement(SgLabelStatement *label=NULL)
Build a goto statement.
ROSE_DLL_API std::string display(SourcePositionClassification &scp)
display function for debugging
ROSE_DLL_API SgUnsignedLongVal * buildUnsignedLongVal_nfi(unsigned long v, const std::string &str)
ROSE_DLL_API SgLabelRefExp * buildLabelRefExp(SgLabelSymbol *s)
Build a Fortran numeric label ref exp.
ROSE_DLL_API SgCompoundInitializer * buildCompoundInitializer_nfi(SgExprListExp *initializers, SgType *type=NULL)
Build a compound initializer, for vector type initialization.
ROSE_DLL_API SgSourceFile * buildJavaSourceFile(SgProject *, std::string, SgClassDefinition *, std::string)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgCatchStatementSeq * buildCatchStatementSeq(SgCatchOptionStmt *=NULL)
Build an initial sequence of Catch blocks containing 0 or 1 element.
ROSE_DLL_API SgInitializedName * buildInitializedName(const SgName &name, SgType *type, SgInitializer *init=NULL)
Initialized names are tricky, their scope vary depending on context, so scope and symbol information ...
ROSE_DLL_API SgTryStmt * buildTryStmt(SgStatement *body, SgCatchOptionStmt *catch0=NULL, SgCatchOptionStmt *catch1=NULL, SgCatchOptionStmt *catch2=NULL, SgCatchOptionStmt *catch3=NULL, SgCatchOptionStmt *catch4=NULL)
Build a try statement.
ROSE_DLL_API SgJavaImportStatement * buildJavaImportStatement(std::string, bool)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgThisExp * buildThisExp_nfi(SgSymbol *sym)
ROSE_DLL_API SgEnumDeclaration * buildEnumDeclaration_nfi(const SgName &name, SgScopeStatement *scope=NULL)
Build an enum, It is also a declaration statement in SAGE III.
ROSE_DLL_API SgNonrealDecl * buildNonrealDecl(const SgName &name, SgDeclarationScope *scope, SgDeclarationScope *child_scope=NULL)
Build a declaration of a non-real class or class-member representing template parameters and their me...
SgAssertStmt * buildAssertStmt_nfi(SgExpression *test)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgThisExp * buildThisExp(SgSymbol *sym)
Build this pointer.
ROSE_DLL_API SgSymbol * findAssociatedSymbolInTargetAST(SgDeclarationStatement *snippet_declaration, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgListComprehension * buildListComprehension(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgMinusMinusOp * buildMinusMinusOp_nfi(SgExpression *op)
ROSE_DLL_API SgModifierType * buildUpcBlockStarType(SgType *base_type=nullptr)
Build a UPC shared[*] type.
ROSE_DLL_API SgStringConversion * buildStringConversion_nfi(SgExpression *exp)
Build a variable declaration, handle symbol table transparently.
SgTupleExp * buildTupleExp_nfi()
ROSE_DLL_API SgIntVal * buildIntValHex(int value=0)
ROSE_DLL_API SgTemplateClassDeclaration * buildNondefiningTemplateClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateSpecializationArgumentList)
DQ (11/29/2011): Adding template declaration support to the AST.
ROSE_DLL_API void setTemplateParametersInDeclaration(SgDeclarationStatement *decl, SgTemplateParameterPtrList *templateParametersList_input)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDeclType * buildDeclType(SgExpression *base_expression, SgType *base_type)
Build a decltype reference type.
ROSE_DLL_API SgUnsignedShortVal * buildUnsignedShortVal_nfi(unsigned short v, const std::string &str)
ROSE_DLL_API SgJavaWildcardType * getUniqueJavaWildcardUnbound()
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgIfStmt * buildIfStmt_nfi(SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDictionaryComprehension * buildDictionaryComprehension(SgKeyDatumPair *kd_pair, SgExprListExp *generators)
ROSE_DLL_API SgShortVal * buildShortVal_nfi(short value, const std::string &str)
ROSE_DLL_API void clearScopeStack()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgLongIntVal * buildLongIntVal(long value=0)
Build a long integer value expression.
ROSE_DLL_API SgJavaTypeExpression * buildJavaTypeExpression(SgType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgChar16Val * buildChar16Val(unsigned short value=0)
ROSE_DLL_API SgAwaitExpression * buildAwaitExpression()
SgDeleteExp * buildDeleteExp_nfi(SgExpression *target, bool is_array=false, bool need_global_specifier=false, SgFunctionDeclaration *deleteOperatorDeclaration=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgFoldExpression * buildFoldExpression_nfi(SgExpression *operands, std::string operator_token_string, bool is_left_associative)
ROSE_DLL_API SgBracedInitializer * buildBracedInitializer_nfi(SgExprListExp *initializers=NULL, SgType *expression_type=NULL)
ROSE_DLL_API SgMemberFunctionType * buildMemberFunctionType(SgType *return_type, SgFunctionParameterTypeList *typeList, SgScopeStatement *struct_name, unsigned int mfunc_specifier)
Built in simple types.
ROSE_DLL_API SgVariableDefinition * buildVariableDefinition_nfi(SgVariableDeclaration *decl, SgInitializedName *init_name, SgInitializer *init)
Build variable definition.
ROSE_DLL_API SgBasicBlock * buildBasicBlock_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUpcMythread * buildUpcMythread_nfi()
Build UPC MYTHREAD (integer expression)
ROSE_DLL_API SgWhileStmt * buildWhileStmt(SgStatement *condition, SgStatement *body, SgStatement *else_body=NULL)
Build while statement.
ROSE_DLL_API SgTemplateClassDeclaration * buildNondefiningTemplateClassDeclaration(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateSpecializationArgumentList)
buildNondefiningTemplateClassDeclaration()
ROSE_DLL_API void setSourcePositionClassificationMode(SourcePositionClassification X)
Set the current source position classification (defines how IR nodes built by the SageBuilder interfa...
ROSE_DLL_API SgClassDeclaration * buildStructDeclaration(const SgName &name, SgScopeStatement *scope=NULL)
Build a structure, It is also a declaration statement in SAGE III.
SgCtorInitializerList * buildCtorInitializerList_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgNamespaceAliasDeclarationStatement * buildNamespaceAliasDeclarationStatement(const SgName &name, SgNamespaceDeclarationStatement *namespaceDeclaration)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgClassDefinition * buildClassDefinition(SgClassDeclaration *d=NULL, bool buildTemplateInstantiation=false)
Build a class definition scope statement.
ROSE_DLL_API SgJovialBitVal * buildJovialBitVal_nfi(const std::string &str)
Build a Jovial bit value expression.
ROSE_DLL_API SgCharVal * buildCharVal_nfi(char value, const std::string &str)
ROSE_DLL_API SgJavaThrowStatement * buildJavaThrowStatement(SgThrowOp *)
Build a Java Throw statement.
ROSE_DLL_API SgJavaSynchronizedStatement * buildJavaSynchronizedStatement(SgExpression *, SgBasicBlock *)
Build a Java Synchronized statement.
ROSE_DLL_API PreprocessingInfo * buildComment(SgLocatedNode *target, const std::string &content, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before, PreprocessingInfo::DirectiveType dtype=PreprocessingInfo::CpreprocessorUnknownDeclaration)
Build and attach a comment, comment style is inferred from the language type of the target node if no...
SgConditionalExp * buildConditionalExp_nfi(SgExpression *test, SgExpression *a, SgExpression *b, SgType *t)
ROSE_DLL_API SgNamespaceDefinitionStatement * buildNamespaceDefinition(SgNamespaceDeclarationStatement *d=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDefaultOptionStmt * buildDefaultOptionStmt(SgStatement *body=NULL)
Build a default option statement.
SgCudaKernelExecConfig * buildCudaKernelExecConfig_nfi(SgExpression *grid=NULL, SgExpression *blocks=NULL, SgExpression *shared=NULL, SgExpression *stream=NULL)
Build a CUDA kernel execution configuration (<<<grid, blocks, shared, stream>>>)
ROSE_DLL_API SgJavaSingleMemberAnnotation * buildJavaSingleMemberAnnotation(SgType *, SgExpression *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgForStatement * buildForStatement(SgStatement *initialize_stmt, SgStatement *test, SgExpression *increment, SgStatement *loop_body, SgStatement *else_body=NULL)
Build a for statement, assume none of the arguments is NULL.
ROSE_DLL_API SgTypeMatrix * buildMatrixType()
Build a Matlab Matrix Type.
ROSE_DLL_API SgModuleStatement * buildModuleStatement(const SgName &name, SgScopeStatement *scope)
Build a Fortran module declaration.
ROSE_DLL_API SgContinueStmt * buildContinueStmt()
Build a continue statement.
ROSE_DLL_API SgEmptyDeclaration * buildEmptyDeclaration()
Build an empty declaration (useful for adding precission to comments and CPP handling under token-bas...
ROSE_DLL_API SgUnsignedIntVal * buildUnsignedIntValHex(unsigned int v=0)
ROSE_DLL_API SgTemplateType * buildTemplateType(SgName name="")
Build a template type, used for template parameter and later argument.
ROSE_DLL_API SgLambdaRefExp * buildLambdaRefExp(SgType *return_type, SgFunctionParameterList *params, SgScopeStatement *scope)
Build lambda expression.
ROSE_DLL_API SgFloatVal * buildFloatVal_nfi(float value=0.0)
ROSE_DLL_API SgConditionalExp * buildConditionalExp(SgExpression *test=NULL, SgExpression *a=NULL, SgExpression *b=NULL)
Build a conditional expression ?:
ROSE_DLL_API SgUnsignedLongVal * buildUnsignedLongVal(unsigned long v=0)
Build a unsigned long integer.
ROSE_DLL_API SgTypeInt * buildIntType()
Built in simple types.
SgDictionaryComprehension * buildDictionaryComprehension_nfi(SgKeyDatumPair *kd_pair, SgExprListExp *generators)
ROSE_DLL_API SgTemplateClassDeclaration * buildTemplateClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgTemplateClassDeclaration *nonDefiningDecl, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateSpecializationArgumentList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeUnsignedInt * buildUnsignedIntType()
Built in simple types.
ROSE_DLL_API SgFloat80Val * buildFloat80Val(long double value=0.0)
SgSubscriptExpression * buildSubscriptExpression_nfi(SgExpression *lower_bound, SgExpression *upper_bound, SgExpression *stride)
Build a SgSubscriptExpression, used for array shape expressions. The lower bound and stride may be nu...
ROSE_DLL_API SgDotDotExp * buildDotDotExp()
Build a variable declaration, handle symbol table transparently.
SourcePositionClassification SourcePositionClassificationMode
C++ SageBuilder namespace specific state for storage of the source code position state (used to contr...
ROSE_DLL_API SgMinusOp * buildMinusOp(SgExpression *op=NULL)
std::list< SgScopeStatement * > ScopeStack
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgModifierType * buildUpcBlockIndefiniteType(SgType *base_type=nullptr)
Build a UPC shared[] type.
SgSetComprehension * buildSetComprehension_nfi(SgExpression *elt, SgExprListExp *generators)
SgName unparseTemplateArgumentToString(SgTemplateArgument *templateArgument)
DQ (3/9/2018): Added to support debugging.
ROSE_DLL_API SgSuperExp * buildSuperExp(SgClassSymbol *sym)
Build super pointer.
ROSE_DLL_API SgExprListExp * buildExprListExp(SgExpression *expr1=NULL, SgExpression *expr2=NULL, SgExpression *expr3=NULL, SgExpression *expr4=NULL, SgExpression *expr5=NULL, SgExpression *expr6=NULL, SgExpression *expr7=NULL, SgExpression *expr8=NULL, SgExpression *expr9=NULL, SgExpression *expr10=NULL)
Build a SgExprListExp, used for function call parameter list etc.
ROSE_DLL_API void resetDeclaration(T *classDeclaration_copy, T *classDeclaration_original, SgScopeStatement *targetScope)
Function to reset scopes in SgDeclarationStatement IR nodes.
ROSE_DLL_API SgRangeBasedForStatement * buildRangeBasedForStatement_nfi(SgVariableDeclaration *initializer, SgVariableDeclaration *range, SgVariableDeclaration *begin_declaration, SgVariableDeclaration *end_declaration, SgExpression *not_equal_expression, SgExpression *increment_expression, SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgJavaPackageStatement * buildJavaPackageStatement(std::string)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgJavaLabelStatement * buildJavaLabelStatement(const SgName &, SgStatement *=NULL)
Build a Java Label statement.
ROSE_DLL_API SgEquivalenceStatement * buildEquivalenceStatement(SgExpression *lhs, SgExpression *rhs)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgListExp * buildListExp(SgExpression *expr1=NULL, SgExpression *expr2=NULL, SgExpression *expr3=NULL, SgExpression *expr4=NULL, SgExpression *expr5=NULL, SgExpression *expr6=NULL, SgExpression *expr7=NULL, SgExpression *expr8=NULL, SgExpression *expr9=NULL, SgExpression *expr10=NULL)
Build a SgListExp.
ROSE_DLL_API SgUnsignedCharVal * buildUnsignedCharValHex(unsigned char v=0)
ROSE_DLL_API SgModifierType * buildNotNullType(SgType *base_type)
Build a not null type for Ada.
ROSE_DLL_API SgLambdaExp * buildLambdaExp_nfi(SgLambdaCaptureList *lambda_capture_list, SgClassDeclaration *lambda_closure_class, SgFunctionDeclaration *lambda_function)
ROSE_DLL_API SgTemplateClassDeclaration * buildTemplateClassDeclaration(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgTemplateClassDeclaration *nonDefiningDecl, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateSpecializationArgumentList)
Build tempplate class declaration.
ROSE_DLL_API SgSourceFile * buildSourceFile(const std::string &outputFileName, SgProject *project=NULL, bool clear_globalScopeAcrossFiles=false)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API void setTemplateSpecializationArgumentsInDeclaration(SgDeclarationStatement *decl, SgTemplateArgumentPtrList *templateSpecializationArgumentsList_input)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgArrayType * buildArrayType(SgType *base_type=nullptr, SgExpression *index=nullptr)
Build ArrayType.
ROSE_DLL_API SgEnumDeclaration * buildNondefiningEnumDeclaration_nfi(const SgName &name, SgScopeStatement *scope)
Build an enum first nondefining declaration, without file info.
ROSE_DLL_API SgComplexVal * buildImaginaryVal(long double imaginary_value)
ROSE_DLL_API SgLambdaCapture * buildLambdaCapture_nfi(SgExpression *capture_variable, SgExpression *source_closure_variable, SgExpression *closure_variable)
ROSE_DLL_API SgNullptrValExp * buildNullptrValExp()
DQ (7/31/2014): Adding support for C++11 nullptr const value expressions.
ROSE_DLL_API void fixupCopyOfAstFromSeparateFileInNewTargetAst(SgStatement *insertionPoint, bool insertionPointIsScope, SgStatement *toInsert, SgStatement *original_before_copy)
Fixup any AST moved from one file two another (references to symbols, types, etc.).
SgExprStatement * buildExprStatement_nfi(SgExpression *exp)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeExpression * buildTypeExpression(SgType *type)
DQ (7/24/2014): Adding support for c11 generic operands.
ROSE_DLL_API SgTypeFixed * buildFixedType(SgExpression *fraction, SgExpression *scale)
Build a Jovial fixed type with a fraction specifier and a scale specifier.
SgPythonPrintStmt * buildPythonPrintStmt_nfi(SgExpression *dest=NULL, SgExprListExp *values=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTemplateVariableDeclaration * buildTemplateVariableDeclaration_nfi(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgNaryComparisonOp * buildNaryComparisonOp_nfi(SgExpression *lhs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgReturnStmt * buildReturnStmt(SgExpression *expression=NULL)
Build a return statement.
SgCaseOptionStmt * buildCaseOptionStmt_nfi(SgExpression *key, SgStatement *body)
Build a variable declaration, handle symbol table transparently.
SgWithStatement * buildWithStatement_nfi(SgExpression *expr, SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUpcFenceStatement * buildUpcFenceStatement_nfi()
Build a UPC fence statement.
ROSE_DLL_API SgComplexVal * buildComplexVal_nfi(SgValueExp *real_value, SgValueExp *imaginary_value, const std::string &str)
SgCudaKernelCallExp * buildCudaKernelCallExp_nfi(SgExpression *kernel, SgExprListExp *parameters=NULL, SgCudaKernelExecConfig *config=NULL)
Build a CUDA kernel call expression (kernel<<<config>>>(parameters))
SgCompoundLiteralExp * buildCompoundLiteralExp_nfi(SgVariableSymbol *varSymbol)
Build function for compound literals (uses a SgVariableSymbol and is similar to buildVarRefExp_nfi())...
actualFunction * buildDefiningFunctionDeclaration_T(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, bool isMemberFunction, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, actualFunction *first_nondefinng_declaration, SgTemplateArgumentPtrList *templateArgumentsList)
A template function for function declaration builders.
ROSE_DLL_API SgChar16Val * buildChar16Val_nfi(unsigned short value, const std::string &str)
ROSE_DLL_API SgTypeLongLong * buildLongLongType()
Built in simple types.
ROSE_DLL_API SgTypeFloat128 * buildFloat128Type()
Built in simple types.
ROSE_DLL_API SgProcedureHeaderStatement * buildNondefiningProcedureHeaderStatement(const SgName &name, SgType *return_type, SgFunctionParameterList *param_list, SgProcedureHeaderStatement::subprogram_kind_enum, SgScopeStatement *scope=NULL)
Build a nondefining SgProcedureHeaderStatement, handle function type, symbol etc transparently.
ROSE_DLL_API SgVarRefExp * buildVarRefExp(const SgName &name, SgScopeStatement *scope=NULL)
Build SgVarRefExp based on a variable's Sage name. It will lookup the name in the symbol table intern...
SgComprehension * buildComprehension_nfi(SgExpression *target, SgExpression *iter, SgExprListExp *ifs)
ROSE_DLL_API SgJovialTableStatement * buildJovialTableStatement(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope=NULL)
Build a Jovial table declaration statement.
ROSE_DLL_API SgLongLongIntVal * buildLongLongIntVal(long long value=0)
Build a long long integer value expression.
ROSE_DLL_API SgUnsignedLongLongIntVal * buildUnsignedLongLongIntVal(unsigned long long v=0)
Build an unsigned long long integer.
ROSE_DLL_API SgVarRefExp * buildJavaArrayLengthVarRefExp()
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgSuperExp * buildSuperExp_nfi(SgClassSymbol *sym)
SgKeyDatumPair * buildKeyDatumPair_nfi(SgExpression *key, SgExpression *datum)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgNamespaceDeclarationStatement * buildNamespaceDeclaration(const SgName &name, SgScopeStatement *scope=NULL)
tps (09/02/2009) : Added support for building namespaces
ROSE_DLL_API SgAggregateInitializer * buildAggregateInitializer_nfi(SgExprListExp *initializers, SgType *type=NULL)
Build an aggregate initializer.
ROSE_DLL_API SgTypeUnsignedShort * buildUnsignedShortType()
Built in simple types.
ROSE_DLL_API SgTypedefDeclaration * buildTypedefDeclaration_nfi(const std::string &name, SgType *base_type, SgScopeStatement *scope=NULL, bool has_defining_base=false)
Build a typedef declaration, such as: typedef int myint;.
ROSE_DLL_API SgTemplateVariableDeclaration * buildTemplateVariableDeclaration(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope)
Build template variable declarations.
ROSE_DLL_API SgMinusMinusOp * buildMinusMinusOp(SgExpression *op=NULL)
ROSE_DLL_API void buildDoWhileStatement_nfi(SgDoWhileStmt *result, SgStatement *body, SgStatement *condition)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeSigned128bitInteger * buildSigned128bitIntegerType()
Built in simple types.
ROSE_DLL_API SgUnsignedCharVal * buildUnsignedCharVal_nfi(unsigned char v, const std::string &str)
bool symbol_table_case_insensitive_semantics
Support for construction of case sensitive/insensitive symbol table handling in scopes.
SgListExp * buildListExp_nfi()
ROSE_DLL_API SgPythonPrintStmt * buildPythonPrintStmt(SgExpression *dest=NULL, SgExprListExp *values=NULL)
Build a python print statement.
ROSE_DLL_API SgConstructorInitializer * buildConstructorInitializer(SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type, bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown)
ROSE_DLL_API SgDoWhileStmt * buildDoWhileStmt(SgStatement *body, SgStatement *condition)
Build do-while statement.
ROSE_DLL_API void errorCheckingTargetAST(SgNode *node_copy, SgNode *node_original, SgFile *targetFile, bool failOnWarning)
Error checking the inserted snippet AST.
ROSE_DLL_API SgDotExp * buildDotExp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgFortranDo * buildFortranDo(SgExpression *initialization, SgExpression *bound, SgExpression *increment, SgBasicBlock *)
Build a Fortran do construct.
ROSE_DLL_API SgPythonGlobalStmt * buildPythonGlobalStmt(SgInitializedNamePtrList &names)
Build a python global statement.
ROSE_DLL_API SgUnsignedLongLongIntVal * buildUnsignedLongLongIntValHex(unsigned long long v=0)
ROSE_DLL_API SgBoolValExp * buildBoolValExp_nfi(int value)
ROSE_DLL_API SgReturnStmt * buildReturnStmt_nfi(SgExpression *expression)
Build a return statement.
ROSE_DLL_API SgClassExp * buildClassExp(SgClassSymbol *sym)
Build class pointer.
ROSE_DLL_API SgTypeChar16 * buildChar16Type()
Built in simple types.
ROSE_DLL_API SgLambdaExp * buildLambdaExp(SgLambdaCaptureList *lambda_capture_list, SgClassDeclaration *lambda_closure_class, SgFunctionDeclaration *lambda_function)
DQ (9/3/2014): Adding support for C++11 Lambda expressions.
ROSE_DLL_API SgWhenStmt * buildWhenStmt(SgExpression *expression, SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
SgAsmStmt * buildAsmStatement_nfi(std::string s)
Build an asm statement.
SgListComprehension * buildListComprehension_nfi(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgClassDeclaration * buildJavaDefiningClassDeclaration(SgScopeStatement *, std::string, SgClassDeclaration::class_types kind=SgClassDeclaration::e_class)
Build a SgFile node and attach it to SgProject.
SgContinueStmt * buildContinueStmt_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAssignInitializer * buildAssignInitializer(SgExpression *operand_i=NULL, SgType *expression_type=NULL)
Build the rhs of a variable declaration which includes an assignment.
ROSE_DLL_API SgArrayType * getUniqueJavaArrayType(SgType *, int)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgLambdaCapture * buildLambdaCapture(SgExpression *capture_variable, SgExpression *source_closure_variable, SgExpression *closure_variable)
ROSE_DLL_API SgRangeExp * buildRangeExp(SgExpression *start)
Build a Matlab range expression like start:end or start:stride:end.
ROSE_DLL_API SgEnumDeclaration * buildEnumDeclaration(const SgName &name, SgScopeStatement *scope=NULL)
Build an enum, It is also a declaration statement in SAGE III.
ROSE_DLL_API SgModifierType * buildConstVolatileType(SgType *base_type=nullptr)
Build a const volatile type.
ROSE_DLL_API SgEnumVal * buildEnumVal(long long int value, SgEnumDeclaration *decl, SgName name)
ROSE_DLL_API SgEnumVal * buildEnumVal_nfi(long long int value, SgEnumDeclaration *decl, SgName name)
ROSE_DLL_API void setTemplateNameInTemplateInstantiations(SgFunctionDeclaration *func, const SgName &name)
DQ (2/11/2012): Added support to set the template name in function template instantiations (member an...
ROSE_DLL_API SgVariableDeclaration * buildVariableDeclaration(const SgName &name, SgType *type, SgInitializer *varInit=NULL, SgScopeStatement *scope=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgFloat128Val * buildFloat128Val(long double value=0.0)
ROSE_DLL_API SgJovialDefineDeclaration * buildJovialDefineDeclaration_nfi(const SgName &name, const std::string &params, const std::string &def_string, SgScopeStatement *scope=NULL)
Build a Jovial define directive declaration statement.
ROSE_DLL_API SgTypeFloat80 * buildFloat80Type()
Built in simple types.
SgBreakStmt * buildBreakStmt_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgWcharVal * buildWcharVal_nfi(wchar_t value, const std::string &str)
ROSE_DLL_API SgFloatVal * buildFloatVal(float value=0.0)
ROSE_DLL_API SgFinishStmt * buildFinishStmt(SgBasicBlock *body)
MH (6/11/2014): Added finish support.
ROSE_DLL_API SgScopeStatement * topScopeStack()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgModifierType * buildUpcRelaxedType(SgType *base_type=nullptr)
Build a UPC relaxed type.
SgScopeStatement * getGlobalScopeFromScopeStack()
Support to retrive the SgGlobal from the internal scope stack (error if not present in a non-empty li...
ROSE_DLL_API SgChooseExpression * buildChooseExpression()
SgClassDefinition * buildClassDefinition_nfi(SgClassDeclaration *d=NULL, bool buildTemplateInstantiation=false)
Build a class definition scope statement.
ROSE_DLL_API SgClassNameRefExp * buildClassNameRefExp(SgClassSymbol *sym)
ROSE_DLL_API SgWithStatement * buildWithStatement(SgExpression *expr, SgStatement *body)
Build a with statement.
SgTemplateClassDefinition * buildTemplateClassDefinition(SgTemplateClassDeclaration *d=NULL)
Build a template class definition statement.
ROSE_DLL_API SgNullExpression * buildNullExpression()
Build a null expression, set file info as the default one.
ROSE_DLL_API SgNaryBooleanOp * buildNaryBooleanOp_nfi(SgExpression *lhs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgModifierType * buildAliasedType(SgType *base_type)
Build an aliased type for Ada.
ROSE_DLL_API SgTupleExp * buildTupleExp(SgExpression *expr1=NULL, SgExpression *expr2=NULL, SgExpression *expr3=NULL, SgExpression *expr4=NULL, SgExpression *expr5=NULL, SgExpression *expr6=NULL, SgExpression *expr7=NULL, SgExpression *expr8=NULL, SgExpression *expr9=NULL, SgExpression *expr10=NULL)
Build a SgTupleExp.
ROSE_DLL_API SgTypeImaginary * buildImaginaryType(SgType *base_type=nullptr)
Build an imaginary type.
ROSE_DLL_API SgStringVal * buildStringVal_nfi(std::string value)
ROSE_DLL_API SgStatementExpression * buildStatementExpression_nfi(SgStatement *exp)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void setTemplateArgumentParents(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgStmtDeclarationStatement * buildStmtDeclarationStatement(SgStatement *stmt)
Build a StmtDeclarationStmt.
ROSE_DLL_API SgAwaitExpression * buildAwaitExpression_nfi()
ROSE_DLL_API SgTemplateParameterVal * buildTemplateParameterVal_nfi(int template_parameter_position, const std::string &str)
ROSE_DLL_API SgJavaQualifiedType * getUniqueJavaQualifiedType(SgClassDeclaration *, SgNamedType *, SgNamedType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgFinishExp * buildFinishExp(SgExpression *expression, SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgYieldExpression * buildYieldExpression(SgExpression *value)
Build a yield statement.
ROSE_DLL_API SgJavaInstanceOfOp * buildJavaInstanceOfOp(SgExpression *exp=NULL, SgType *type=NULL)
This is part of Java specific operator support.
ROSE_DLL_API SgLambdaCaptureList * buildLambdaCaptureList_nfi()
ROSE_DLL_API SgShortVal * buildShortVal(short value=0)
ROSE_DLL_API SgAsmStmt * buildAsmStatement(std::string s)
Build a NULL statement.
ROSE_DLL_API SgModifierType * buildConstType(SgType *base_type=nullptr)
Build a const type.
ROSE_DLL_API void setTemplateArgumentsInDeclaration(SgDeclarationStatement *decl, SgTemplateArgumentPtrList *templateArgumentsList_input)
DQ (9/16/2012): Added function to support setting the template arguments and setting their parents (a...
ROSE_DLL_API SgJavaNormalAnnotation * buildJavaNormalAnnotation(SgType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgDoubleVal * buildDoubleVal_nfi(double value, const std::string &str)
ROSE_DLL_API SgUnsignedShortVal * buildUnsignedShortVal(unsigned short v=0)
Build an unsigned short integer.
ROSE_DLL_API PreprocessingInfo * buildCpreprocessorDefineDeclaration(SgLocatedNode *target, const std::string &content, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before)
Build and attach #define XX directives, pass "#define xxx xxx" as content.
ROSE_DLL_API SgTypeDouble * buildDoubleType()
Built in simple types.
ROSE_DLL_API SgReferenceType * buildReferenceType(SgType *base_type=nullptr)
Build a reference type.
SgExecStatement * buildExecStatement_nfi(SgExpression *executable, SgExpression *globals=NULL, SgExpression *locals=NULL)
Build an exec stmt.
ROSE_DLL_API SgTypeLongDouble * buildLongDoubleType()
Built in simple types.
ROSE_DLL_API SgTypeLong * buildLongType()
Built in simple types.
ROSE_DLL_API SgExprStatement * buildExprStatement(SgExpression *exp=NULL)
Build a SgExprStatement, set File_Info automatically.
ROSE_DLL_API SgLongIntVal * buildLongIntVal_nfi(long value, const std::string &str)
ROSE_DLL_API SgFunctionParameterRefExp * buildFunctionParameterRefExp(int parameter_number, int parameter_level)
ROSE_DLL_API SgTemplateTypedefDeclaration * buildTemplateTypedefDeclaration_nfi(const SgName &name, SgType *base_type, SgScopeStatement *scope=NULL, bool has_defining_base=false)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void fixupSourcePositionFileSpecification(SgNode *subtreeRoot, const std::string &newFileName)
Change the source file associated with the source position information in the AST.
ROSE_DLL_API SgAssertStmt * buildAssertStmt(SgExpression *test)
Build a Assert statement.
ROSE_DLL_API SgAtExp * buildAtExp(SgExpression *expression, SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgChar32Val * buildChar32Val(unsigned int value=0)
ROSE_DLL_API SgSizeOfOp * buildSizeOfOp_nfi(SgExpression *exp)
Build sizeof() expression with an expression parameter.
ROSE_DLL_API SgIfStmt * buildIfStmt(SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Build if statement.
ROSE_DLL_API SgAsyncStmt * buildAsyncStmt(SgBasicBlock *body)
MH (6/10/2014): Added async support.
ROSE_DLL_API SgFunctionParameterList * buildFunctionParameterList(SgInitializedName *in1=NULL, SgInitializedName *in2=NULL, SgInitializedName *in3=NULL, SgInitializedName *in4=NULL, SgInitializedName *in5=NULL, SgInitializedName *in6=NULL, SgInitializedName *in7=NULL, SgInitializedName *in8=NULL, SgInitializedName *in9=NULL, SgInitializedName *in10=NULL)
Build an empty SgFunctionParameterList, possibly with some initialized names filled in.
ROSE_DLL_API SgModifierType * buildFortranKindType(SgType *base_type, SgExpression *kindExpression)
Build a type based on the Fortran kind mechanism.
ROSE_DLL_API SgPragmaDeclaration * buildPragmaDeclaration(const std::string &name, SgScopeStatement *scope=NULL)
Build pragma declaration, handle SgPragma and defining/nondefining pointers internally.
ROSE_DLL_API SgUnsignedCharVal * buildUnsignedCharVal(unsigned char v=0)
Build an unsigned char.
SgLabelStatement * buildLabelStatement_nfi(const SgName &name, SgStatement *stmt, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAlignOfOp * buildAlignOfOp(SgExpression *exp=NULL)
Build alignof() expression with an expression parameter.
ROSE_DLL_API SgMatlabForStatement * buildMatlabForStatement(SgExpression *loop_index, SgExpression *loop_range, SgBasicBlock *loop_body)
Build a For-loop statement for matlab.
bool inSwitchScope()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgUpcMythread * buildUpcMythread()
Build UPC MYTHREAD (integer expression)
ROSE_DLL_API SgTypeUnsignedLong * buildUnsignedLongType()
Built in simple types.
ROSE_DLL_API SgPlusPlusOp * buildPlusPlusOp_nfi(SgExpression *op)
ROSE_DLL_API SgTypeShort * buildShortType()
Built in simple types.
ROSE_DLL_API SgNonrealRefExp * buildNonrealRefExp_nfi(SgNonrealSymbol *sym)
Build a reference to the non-real declaration of a member of a non-real class.
SgFunctionCallExp * buildFunctionCallExp_nfi(SgExpression *f, SgExprListExp *parameters=NULL)
ROSE_DLL_API SgTypeVoid * buildVoidType()
Built in simple types.
ROSE_DLL_API void fixupSharingSourcePosition(SgNode *subtreeRoot, int new_file_id)
Sharing IR nodes requires that the file id be added to the fileIDsToUnparse held in the Sg_File_Info ...
ROSE_DLL_API SgAssignInitializer * buildAssignInitializer_nfi(SgExpression *operand_i=NULL, SgType *expression_type=NULL)
ROSE_DLL_API SgTypeBool * buildBoolType()
Built in simple types.
ROSE_DLL_API SgMicrosoftAttributeDeclaration * buildMicrosoftAttributeDeclaration(const SgName &name)
DQ (8/17/2014): Adding support for Microsoft MSVC specific attributes.
ROSE_DLL_API SgStatement * buildStatementFromString(const std::string &stmt_str, SgScopeStatement *scope)
Liao (9/18/2015): experimental support of building a statement from a string.
ROSE_DLL_API SgFile * buildFile(const std::string &inputFileName, const std::string &outputFileName, SgProject *project=NULL, bool clear_globalScopeAcrossFiles=false)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgMemberFunctionDeclaration * buildDefiningMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, bool buildTemplateInstantiation, unsigned int functionConstVolatileFlags, SgMemberFunctionDeclaration *first_nondefinng_declaration, SgTemplateArgumentPtrList *templateArgumentsList)
Build a defining ( non-prototype) member function declaration.
ROSE_DLL_API SgVarRefExp * buildVarRefExp_nfi(SgVariableSymbol *varSymbol)
ROSE_DLL_API SgPointerType * buildPointerType(SgType *base_type=nullptr)
Build a pointer type.
ROSE_DLL_API SgLongDoubleVal * buildLongDoubleVal_nfi(long double value, const std::string &str)
ROSE_DLL_API SgMagicColonExp * buildMagicColonExp()
Build a Matlab colon expression :
ROSE_DLL_API SgTypedefDeclaration * buildTypedefDeclaration(const std::string &name, SgType *base_type, SgScopeStatement *scope=NULL, bool has_defining_base=false)
Build a typedef declaration, such as: typedef int myint; typedef struct A {..} s_A;.
ROSE_DLL_API SgTemplateParameterVal * buildTemplateParameterVal(int template_parameter_position=-1)
Build an template parameter value expression.
ROSE_DLL_API SgFortranContinueStmt * buildFortranContinueStmt()
Build a Fortran continue statement.
ROSE_DLL_API SgFloat128Val * buildFloat128Val_nfi(long double value, const std::string &str)
ROSE_DLL_API SgBoolValExp * buildBoolValExp(int value=0)
Build a bool value expression, the name convention of SgBoolValExp is little different from others fo...
ROSE_DLL_API SgSwitchStatement * buildSwitchStatement(SgStatement *item_selector=NULL, SgStatement *body=NULL)
Build a switch statement.
ROSE_DLL_API SgType * buildOpaqueType(std::string const type_name, SgScopeStatement *scope)
Build an opaque type with a name, useful when a type's details are unknown during transformation,...
ROSE_DLL_API SgTypeChar32 * buildChar32Type()
Built in simple types.
ROSE_DLL_API SgConstructorInitializer * buildConstructorInitializer_nfi(SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type, bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown)
ROSE_DLL_API SgMatrixExp * buildMatrixExp(SgExprListExp *firstRow)
Build a Matlab Matrix.
ROSE_DLL_API SgPassStatement * buildPassStatement()
Build a pass statement.
ROSE_DLL_API SgTypeComplex * buildComplexType(SgType *base_type=nullptr)
Build a complex type.
ROSE_DLL_API SgProcedureHeaderStatement * buildProcedureHeaderStatement(const SgName &name, SgType *return_type, SgFunctionParameterList *parameter_list, SgProcedureHeaderStatement::subprogram_kind_enum, SgScopeStatement *scope=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDeclarationStatement * findAssociatedDeclarationInTargetAST(SgDeclarationStatement *snippet_declaration, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgTypeTuple * buildTupleType(SgType *t1=NULL, SgType *t2=NULL, SgType *t3=NULL, SgType *t4=NULL, SgType *t5=NULL, SgType *t6=NULL, SgType *t7=NULL, SgType *t8=NULL, SgType *t9=NULL, SgType *t10=NULL)
Build a tuple of types. Useful for a function returning multiple variables of different types.
ROSE_DLL_API SgNaryComparisonOp * buildNaryComparisonOp(SgExpression *lhs)
driscoll6 (7/20/11) : Support n-ary operators for python
ROSE_DLL_API SgNonrealType * buildNonrealType(const SgName &name, SgDeclarationScope *scope)
Build a non real type used for template parameter. Internally a SgNorealDecl is also built.
ROSE_DLL_API SgDeclarationScope * buildDeclarationScope()
Build a scope statement. Used to build SgNonrealDecl and SgNonrealType.
ROSE_DLL_API SgName appendTemplateArgumentsToName(const SgName &name, const SgTemplateArgumentPtrList &templateArgumentsList)
DQ (7/27/2012): changed semantics from removing the template arguments in names to adding the templat...
ROSE_DLL_API SgStaticAssertionDeclaration * buildStaticAssertionDeclaration(SgExpression *condition, const SgName &string_literal)
DQ (7/25/2014): Adding support for C11 static assertions.
ROSE_DLL_API SgNullExpression * buildNullExpression_nfi()
No file info version of buildNullExpression(). File info is to be set later on.
ROSE_DLL_API SgFunctionParameterTypeList * buildFunctionParameterTypeList(SgFunctionParameterList *paralist)
Build SgFunctionParameterTypeList from SgFunctionParameterList.
ROSE_DLL_API SgFunctionCallExp * buildMemberFunctionCall(std::string className, SgExpression *objectExpression, std::string functionName, SgExprListExp *params, SgScopeStatement *scope)
Build member function calls.
SgDefaultOptionStmt * buildDefaultOptionStmt_nfi(SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgActualArgumentExpression * buildActualArgumentExpression(SgName arg_name, SgExpression *arg)
Build an Actual Argument Expression.
ROSE_DLL_API PreprocessingInfo * buildHeader(const std::string &header_filename, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before, bool isSystemHeader=false)
Build a dangling #include "x.h" header, insertHeader() is needed to actually insert it.
SgPassStatement * buildPassStatement_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgStringVal * buildStringVal(std::string value="")
ROSE_DLL_API SgTypeSignedLong * buildSignedLongType()
Built in simple types.
ROSE_DLL_API SgClassDeclaration * buildDefiningClassDeclaration(SgName name, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
SgGotoStatement * buildGotoStatement_nfi(SgLabelStatement *label)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeChar * buildCharType()
Built in simple types.
ROSE_DLL_API SgTemplateParameterPtrList * getTemplateParameterList(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgClassExp * buildClassExp_nfi(SgClassSymbol *sym)
ROSE_DLL_API SgBreakStmt * buildBreakStmt()
Build a break statement.
ROSE_DLL_API SgForInitStatement * buildForInitStatement_nfi(SgStatementPtrList &statements)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void setTemplateParameterParents(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void pushScopeStack(SgScopeStatement *stmt)
Public interfaces of the scope stack, should be stable.
ROSE_DLL_API SgTypeSignedShort * buildSignedShortType()
Built in simple types.
ROSE_DLL_API SgUsingDirectiveStatement * buildUsingDirectiveStatement(SgNamespaceDeclarationStatement *ns_decl)
Build a using directive statement.
SgDictionaryExp * buildDictionaryExp_nfi(std::vector< SgKeyDatumPair * > pairs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgCastExp * buildCastExp(SgExpression *operand_i=NULL, SgType *expression_type=NULL, SgCastExp::cast_type_enum cast_type=SgCastExp::e_C_style_cast)
Build a type casting expression.
SgTemplateMemberFunctionRefExp * buildTemplateMemberFunctionRefExp_nfi(SgTemplateMemberFunctionSymbol *sym, bool virtual_call, bool need_qualifier)
DQ (12/29/2011): Adding template declaration support to the AST.
ROSE_DLL_API SgRvalueReferenceType * buildRvalueReferenceType(SgType *base_type)
Build a rvalue reference type.
ROSE_DLL_API SgClassDeclaration * buildNondefiningClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, bool buildTemplateInstantiation, SgTemplateArgumentPtrList *templateArgumentsList)
Build a structure first nondefining declaration, without file info.
ROSE_DLL_API SgStmtDeclarationStatement * buildStmtDeclarationStatement_nfi(SgStatement *stmt)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgForInitStatement * buildForInitStatement()
Build a for init statement.
SgDoWhileStmt * buildDoWhileStmt_nfi(SgStatement *body, SgStatement *condition)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void popScopeStack()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgAlignOfOp * buildAlignOfOp_nfi(SgExpression *exp)
Build alignof() expression with an expression parameter.
ROSE_DLL_API SgVarArgOp * buildVarArgOp_nfi(SgExpression *operand_i, SgType *expression_type)
Build vararg op expression.
ROSE_DLL_API void testTemplateArgumentParents(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeNullptr * buildNullptrType()
Built in simple types.
ROSE_DLL_API SgModifierType * buildUpcStrictType(SgType *base_type=nullptr)
Build a UPC strict type.
ROSE_DLL_API SgExprStatement * buildAssignStatement_ast_translate(SgExpression *lhs, SgExpression *rhs)
This version does not recursively reset the file info as a transformation.
ROSE_DLL_API SgTypeFloat * buildFloatType()
Built in simple types.
ROSE_DLL_API SgDeleteExp * buildDeleteExp(SgExpression *variable, short is_array, short need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
ROSE_DLL_API SgTypeOfType * buildTypeOfType(SgExpression *base_expression, SgType *base_type)
Build a GNU typeof operator.
ROSE_DLL_API SgVoidVal * buildVoidVal()
DQ (2/14/2019): Adding support for C++14 void value expressions.
SgWhileStmt * buildWhileStmt_nfi(SgStatement *condition, SgStatement *body, SgStatement *else_body=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API bool emptyScopeStack()
intended to be a private member, don't access it directly. could be changed any time
SgClassNameRefExp * buildClassNameRefExp_nfi(SgClassSymbol *sym)
ROSE_DLL_API SgFloat80Val * buildFloat80Val_nfi(long double value, const std::string &str)
ROSE_DLL_API SgSetComprehension * buildSetComprehension(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgColonShapeExp * buildColonShapeExp_nfi()
No file info version of buildColonShapeExp(). File info is to be set later on.
ROSE_DLL_API SgVoidVal * buildVoidVal_nfi()
ROSE_DLL_API SgModifierType * buildVolatileType(SgType *base_type=nullptr)
Build a volatile type.
ROSE_DLL_API SgFunctionRefExp * buildFunctionRefExp(const SgName &name, const SgType *func_type, SgScopeStatement *scope=NULL)
Build SgFunctionRefExp based on a C++ function's name and function type. It will lookup symbol table ...
ROSE_DLL_API SgTypeWchar * buildWcharType()
Built in simple types.
ROSE_DLL_API SgBasicBlock * buildBasicBlock(SgStatement *stmt1=NULL, SgStatement *stmt2=NULL, SgStatement *stmt3=NULL, SgStatement *stmt4=NULL, SgStatement *stmt5=NULL, SgStatement *stmt6=NULL, SgStatement *stmt7=NULL, SgStatement *stmt8=NULL, SgStatement *stmt9=NULL, SgStatement *stmt10=NULL)
Build a SgBasicBlock, setting file info internally.
ROSE_DLL_API SgAggregateInitializer * buildAggregateInitializer(SgExprListExp *initializers=NULL, SgType *type=NULL)
Build an aggregate initializer.
ROSE_DLL_API SgNoexceptOp * buildNoexceptOp_nfi(SgExpression *exp)
Build noexcept operator expression with an expression parameter.
ROSE_DLL_API SgTypeUnknown * buildUnknownType()
Built in simple types.
ROSE_DLL_API SgFoldExpression * buildFoldExpression(SgExpression *operands, std::string operator_token_string, bool is_left_associative)
ROSE_DLL_API SgVariableDeclaration * buildVariableDeclaration_nfi(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope, bool builtFromUseOnly=false, SgStorageModifier::storage_modifier_enum sm=SgStorageModifier::e_default)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeIdOp * buildTypeIdOp(SgExpression *operand_expr, SgType *operand_type)
DQ (1/25/2013): Added support for typeId operators.
ROSE_DLL_API SgExprStatement * buildAssignStatement(SgExpression *lhs, SgExpression *rhs)
Build an assignment statement from lefthand operand and right hand operand.
ROSE_DLL_API SgTypeUnsigned128bitInteger * buildUnsigned128bitIntegerType()
Built in simple types.
ROSE_DLL_API SgUnsignedIntVal * buildUnsignedIntVal(unsigned int v=0)
Build an unsigned integer.
SgFunctionRefExp * buildFunctionRefExp_nfi(SgFunctionSymbol *sym)
ROSE_DLL_API SgCharVal * buildCharVal(char value=0)
SgActualArgumentExpression * buildActualArgumentExpression_nfi(SgName arg_name, SgExpression *arg)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgSizeOfOp * buildSizeOfOp(SgExpression *exp=NULL)
Build sizeof() expression with an expression parameter.
ROSE_DLL_API SgMemberFunctionDeclaration * buildNondefiningMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, bool buildTemplateInstantiation, SgTemplateArgumentPtrList *templateArgumentsList)
Build a prototype member function declaration.
ROSE_DLL_API SgJavaWildcardType * getUniqueJavaWildcardSuper(SgType *)
Build a SgFile node and attach it to SgProject.
SgTypeTraitBuiltinOperator * buildTypeTraitBuiltinOperator(SgName functionName, SgNodePtrList parameters)
SgCompoundLiteralExp * buildCompoundLiteralExp(SgVariableSymbol *varSymbol)
Build function for compound literals (uses a SgVariableSymbol and is similar to buildVarRefExp()).
SgExprListExp * buildExprListExp_nfi()
ROSE_DLL_API SgType * getTargetFileTypeSupport(SgType *snippet_type, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgVariantExpression * buildVariantExpression()
ROSE_DLL_API SgNonrealBaseClass * buildNonrealBaseClass(SgNonrealDecl *classDeclaration, SgClassDefinition *classDefinition, bool isVirtual, bool isDirect)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeSignedInt * buildSignedIntType()
Built in simple types.
ROSE_DLL_API void fixupCopyOfNodeFromSeparateFileInNewTargetAst(SgStatement *insertionPoint, bool insertionPointIsScope, SgNode *node_copy, SgNode *node_original)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgWcharVal * buildWcharVal(wchar_t value=0)
ROSE_DLL_API SgUnsignedShortVal * buildUnsignedShortValHex(unsigned short v=0)
ROSE_DLL_API SgTemplateMemberFunctionDeclaration * buildDefiningTemplateMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, SgTemplateMemberFunctionDeclaration *first_nondefing_declaration)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgVarRefExp * buildOpaqueVarRefExp(const std::string &varName, SgScopeStatement *scope=NULL)
Build a variable reference expression at scope to an opaque variable which has unknown information ex...
ROSE_DLL_API SgTypeUnsignedChar * buildUnsignedCharType()
Built in simple types.
ROSE_DLL_API SgJavaMarkerAnnotation * buildJavaMarkerAnnotation(SgType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgUnsignedIntVal * buildUnsignedIntVal_nfi(unsigned int v, const std::string &str)
ROSE_DLL_API SgNaryBooleanOp * buildNaryBooleanOp(SgExpression *lhs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgModifierType * buildUpcBlockNumberType(SgType *base_type, long block_factor)
Build a UPC shared[n] type.
ROSE_DLL_API SgStatementExpression * buildStatementExpression(SgStatement *exp)
Build a GNU statement expression.
ROSE_DLL_API SgTypeSignedChar * buildSignedCharType()
Built in simple types.
ROSE_DLL_API SgUpcWaitStatement * buildUpcWaitStatement_nfi(SgExpression *exp)
Build a UPC wait statement.
ROSE_DLL_API SgDoubleVal * buildDoubleVal(double value=0.0)
Build a double value expression.
ROSE_DLL_API SgMemberFunctionDeclaration * buildDefaultConstructor(SgClassType *classType)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUnsignedLongLongIntVal * buildUnsignedLongLongIntVal_nfi(unsigned long long v, const std::string &str)
ROSE_DLL_API SgAutoType * buildAutoType()
Built in simple types.
ROSE_DLL_API SgMemberFunctionRefExp * buildMemberFunctionRefExp(SgMemberFunctionSymbol *sym, bool virtual_call, bool need_qualifier)
ROSE_DLL_API SgHereExp * buildHereExpression()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgPlusPlusOp * buildPlusPlusOp(SgExpression *op=NULL)
ROSE_DLL_API SgComplexVal * buildComplexVal(SgValueExp *real_value, SgValueExp *imaginary_value)
ROSE_DLL_API SgNamespaceDeclarationStatement * buildNamespaceDeclaration_nfi(const SgName &name, bool unnamednamespace, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgIntVal * buildIntVal(int value=0)
Build an integer value expression.
SgYieldExpression * buildYieldExpression_nfi(SgExpression *value)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgChar32Val * buildChar32Val_nfi(unsigned int value, const std::string &str)
ROSE_DLL_API DeclClass * buildClassDeclarationStatement_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope=NULL, SgClassDeclaration *nonDefiningDecl=NULL)
Build a generic class declaration statement (SgClassDeclaration or subclass) with a class declaration...
SgTemplateFunctionRefExp * buildTemplateFunctionRefExp_nfi(SgTemplateFunctionSymbol *sym)
DQ (12/15/2011): Adding template declaration support to the AST.
ROSE_DLL_API SgNullStatement * buildNullStatement()
Build a NULL statement.
ROSE_DLL_API SgUpcNotifyStatement * buildUpcNotifyStatement_nfi(SgExpression *exp)
Build a UPC notify statement.
ROSE_DLL_API SgConstVolatileModifier * buildConstVolatileModifier(SgConstVolatileModifier::cv_modifier_enum mtype=SgConstVolatileModifier::e_unknown)
Build a const/volatile type qualifier.
ROSE_DLL_API SgJavaForEachStatement * buildJavaForEachStatement(SgVariableDeclaration *=NULL, SgExpression *=NULL, SgStatement *=NULL)
Build a Java Foreach statement.
ROSE_DLL_API SgBracedInitializer * buildBracedInitializer(SgExprListExp *initializers=NULL, SgType *expression_type=NULL)
Build an braced initializer.
ROSE_DLL_API SgFunctionType * buildFunctionType(SgType *return_type, SgFunctionParameterTypeList *typeList=nullptr)
Build function type from return type and parameter type list.
ROSE_DLL_API SgScopeStatement * buildScopeStatement(SgClassDefinition *=NULL)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgDictionaryExp * buildDictionaryExp(std::vector< SgKeyDatumPair * > pairs)
Build a list of key-datum pairs.
ROSE_DLL_API SgLambdaCaptureList * buildLambdaCaptureList()
ROSE_DLL_API SgJovialForThenStatement * buildJovialForThenStatement_nfi()
Build a Jovial loop statement.
ROSE_DLL_API SgInitializedName * buildJavaFormalParameter(SgType *, const SgName &, bool is_var_args=false, bool is_final=false)
Build a SgFile node and attach it to SgProject.
SgDeclarationStatement * associatedDeclaration(const SgSymbol &n)
returns the associated declaration for symbol n or nullptr if there is none.
Functions that are useful when operating on the AST.
Definition sageBuilder.h:25
void initializeIfStmt(SgIfStmt *ifstmt, SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void fixNamespaceDeclaration(SgNamespaceDeclarationStatement *structDecl, SgScopeStatement *scope)
Fix symbols, parent and scope pointers. Used internally within appendStatment(), insertStatement() et...
ROSE_DLL_API bool is_Jovial_language()
ROSE_DLL_API bool hasSameGlobalScope(SgStatement *statement_1, SgStatement *statement_2)
This is supporting the recognition of functions in header files from two different ASTs.
ROSE_DLL_API bool language_may_contain_nondeclarations_in_scope()
ROSE_DLL_API void fixStructDeclaration(SgClassDeclaration *structDecl, SgScopeStatement *scope)
Fix symbols, parent and scope pointers. Used internally within appendStatment(), insertStatement() et...
ROSE_DLL_API void appendExpressionList(SgExprListExp *, const std::vector< SgExpression * > &)
Append an expression list to a SgExprListExp, set the parent pointers also.
ROSE_DLL_API int set_name(SgInitializedName *initializedNameNode, SgName new_name)
set_name of symbol in symbol table.
ROSE_DLL_API SgVariableSymbol * getFirstVarSym(SgVariableDeclaration *decl)
Get the variable symbol for the first initialized name of a declaration stmt.
void initializeSwitchStatement(SgSwitchStatement *switchStatement, SgStatement *item_selector, SgStatement *body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void setOneSourcePositionForTransformation(SgNode *root)
Set current node's source position as transformation generated.
PreprocessingInfo * attachComment(SgSourceFile *source_file, const std::string &content, PreprocessingInfo::DirectiveType directive_type=PreprocessingInfo::C_StyleComment, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before)
Build and attach comment onto the global scope of a source file.
ROSE_DLL_API SgInitializedName * getFirstInitializedName(SgVariableDeclaration *decl)
Get the first initialized name of a declaration statement.
ROSE_DLL_API void reportModifiedStatements(const std::string &label, SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API void setSourcePositionForTransformation(SgNode *root)
Recursively set source position info(Sg_File_Info) as transformation generated.
ROSE_DLL_API SgGlobal * getGlobalScope(const SgNode *astNode)
Traverse back through a node's parents to find the enclosing global scope.
ROSE_DLL_API bool templateArgumentListEquivalence(const SgTemplateArgumentPtrList &list1, const SgTemplateArgumentPtrList &list2)
Verify that 2 SgTemplateArgumentPtrList are equivalent.
ROSE_DLL_API void reportModifiedLocatedNodes(const std::string &label, SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
void initializeWhileStatement(SgWhileStmt *whileStatement, SgStatement *condition, SgStatement *body, SgStatement *else_body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void setSourcePosition(SgNode *node)
Set the source code positon for the current (input) node.
bool isStructurallyEquivalentAST(SgNode *tree1, SgNode *tree2)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API bool is_language_case_insensitive()
ROSE_DLL_API SgFunctionSymbol * lookupFunctionSymbolInParentScopes(const SgName &functionName, SgScopeStatement *currentScope=NULL)
look up the first matched function symbol in parent scopes given only a function name,...
ROSE_DLL_API SgFile * getEnclosingFileNode(SgNode *astNode)
get the SgFile node from current node
bool ROSE_DLL_API isAncestor(SgNode *node1, SgNode *node2)
check if node1 is a strict ancestor of node 2. (a node is not considered its own ancestor)
ROSE_DLL_API void resetModifiedLocatedNodes(const std::set< SgLocatedNode * > &modifiedNodeSet)
Use the set of IR nodes and set the isModified flag in each IR node to true.
ROSE_DLL_API SgEnumSymbol * lookupEnumSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API SgTypedefSymbol * lookupTypedefSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API bool is_Fortran_language()
ROSE_DLL_API SgVariableSymbol * lookupVariableSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API void outputFileIds(SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API SgTemplateClassSymbol * lookupTemplateClassSymbolInParentScopes(const SgName &name, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateArgumentList, SgScopeStatement *cscope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
void collectVarRefs(SgLocatedNode *root, std::vector< SgVarRefExp * > &result)
Collect all variable references in a subtree.
ROSE_DLL_API SgVariableSymbol * appendArg(SgFunctionParameterList *, SgInitializedName *)
Append an argument to SgFunctionParameterList, transparently set parent,scope, and symbols for argume...
ROSE_DLL_API int fixVariableReferences(SgNode *root, bool cleanUnusedSymbol=true)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API void appendStatement(SgStatement *stmt, SgScopeStatement *scope=NULL)
Append a statement to the end of the current scope, handle side effect of appending statements,...
ROSE_DLL_API void setOneSourcePositionNull(SgNode *node)
Set current node's source position as NULL.
ROSE_DLL_API void fixVariableDeclaration(SgVariableDeclaration *varDecl, SgScopeStatement *scope)
Patch up symbol, scope, and parent information when a SgVariableDeclaration's scope is known.
ROSE_DLL_API SgFunctionDefinition * getEnclosingProcedure(SgNode *n, const bool includingSelf=false)
Find the function definition.
std::string get_name(const SgNode *node)
Generate a useful name to describe the SgNode.
ROSE_DLL_API bool is_Ada_language()
ROSE_DLL_API std::set< SgLocatedNode * > collectModifiedLocatedNodes(SgNode *node)
This collects the SgLocatedNodes that are marked as modified (a flag automatically set by all set_* g...
ROSE_DLL_API void fixLabelStatement(SgLabelStatement *label_stmt, SgScopeStatement *scope)
Fix symbol table for SgLabelStatement. Used Internally when the label is built without knowing its ta...
ROSE_DLL_API void appendStatementList(const std::vector< SgStatement * > &stmt, SgScopeStatement *scope=NULL)
Append a list of statements to the end of the current scope, handle side effect of appending statemen...
bool hasTemplateSyntax(const SgName &name)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API SgClassSymbol * lookupClassSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL, SgTemplateArgumentPtrList *templateArgumentList=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API void appendExpression(SgExprListExp *, SgExpression *)
Append an expression to a SgExprListExp, set the parent pointer also.
ROSE_DLL_API void prependStatement(SgStatement *stmt, SgScopeStatement *scope=NULL)
Prepend a statement to the beginning of the current scope, handling side effects as appropriate.
ROSE_DLL_API void setSourcePositionAtRootAndAllChildren(SgNode *root)
Set the source code positon for the subtree (including the root).
ROSE_DLL_API SgExpression * copyExpression(SgExpression *e)
Deep copy an expression.
void setParameterList(actualFunction *func, SgFunctionParameterList *paralist)
Set parameter list for a function declaration, considering existing parameter list etc.
ROSE_DLL_API SgFunctionType * findFunctionType(SgType *return_type, SgFunctionParameterTypeList *typeList)
Find the function type matching a function signature plus a given return type.