ROSE 0.11.145.317
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 case V_SgNamespaceAliasDeclarationStatement:
799 case V_SgNamespaceDeclarationStatement:
800 case V_SgEnumDeclaration:
801 case V_SgVariableDeclaration:
802 case V_SgTypedefDeclaration:
803 case V_SgProcedureHeaderStatement:
804 case V_SgJovialTableStatement:
805 case V_SgJavaPackageDeclaration:
806 case V_SgFunctionDeclaration:
807 case V_SgMemberFunctionDeclaration:
808 case V_SgClassDeclaration:
809 {
810 templateArgumentsList = NULL;
811 break;
812 }
813
814 case V_SgTemplateInstantiationDecl:
815 {
816 templateArgumentsList = &(isSgTemplateInstantiationDecl(decl)->get_templateArguments());
817 break;
818 }
819
820 case V_SgTemplateClassDeclaration:
821 {
822 templateArgumentsList = &(isSgTemplateClassDeclaration(decl)->get_templateSpecializationArguments());
823 break;
824 }
825
826 case V_SgTemplateInstantiationFunctionDecl:
827 {
828 templateArgumentsList = &(isSgTemplateInstantiationFunctionDecl(decl)->get_templateArguments());
829 break;
830 }
831
832 case V_SgTemplateFunctionDeclaration:
833 {
834 templateArgumentsList = &(isSgTemplateFunctionDeclaration(decl)->get_templateSpecializationArguments());
835 break;
836 }
837
838 case V_SgTemplateInstantiationMemberFunctionDecl:
839 {
840 templateArgumentsList = &(isSgTemplateInstantiationMemberFunctionDecl(decl)->get_templateArguments());
841 break;
842 }
843
844 case V_SgTemplateMemberFunctionDeclaration:
845 {
846 templateArgumentsList = &(isSgTemplateMemberFunctionDeclaration(decl)->get_templateSpecializationArguments());
847 break;
848 }
849
850 case V_SgTemplateVariableDeclaration:
851 {
852 templateArgumentsList = &(isSgTemplateVariableDeclaration(decl)->get_templateSpecializationArguments());
853 break;
854 }
855
856 case V_SgTemplateVariableInstantiation:
857 {
858 templateArgumentsList = &(isSgTemplateVariableInstantiation(decl)->get_templateArguments());
859 break;
860 }
861
862 case V_SgTemplateTypedefDeclaration:
863 {
864 templateArgumentsList = &(isSgTemplateTypedefDeclaration(decl)->get_templateSpecializationArguments());
865 break;
866 }
867
868 case V_SgTemplateInstantiationTypedefDeclaration:
869 {
870 templateArgumentsList = &(isSgTemplateInstantiationTypedefDeclaration(decl)->get_templateArguments());
871 break;
872 }
873
874 case V_SgTemplateDeclaration:
875 {
876 templateArgumentsList = NULL;
877 break;
878 }
879
880 case V_SgNonrealDecl:
881 {
882 templateArgumentsList = &(isSgNonrealDecl(decl)->get_tpl_args());
883 break;
884 }
885
886 default:
887 {
888 printf ("getTemplateArgumentList(): Default reached in switch: decl = %p = %s \n",decl,decl->class_name().c_str());
889 ROSE_ABORT();
890 }
891 }
892
893 return templateArgumentsList;
894 }
895
896
897
898SgTemplateParameterPtrList*
900 {
901 // DQ (9/16/2012): This function returns the SgTemplateParameterPtrList that is associated with template declarations.
902 // For all other cases it returns NULL (or is an error).
903
904 ROSE_ASSERT(decl != NULL);
905
906 SgTemplateParameterPtrList* templateParameterList = NULL;
907
908 switch(decl->variantT())
909 {
910 case V_SgNamespaceAliasDeclarationStatement:
911 case V_SgNamespaceDeclarationStatement:
912 case V_SgEnumDeclaration:
913 case V_SgVariableDeclaration:
914 case V_SgTypedefDeclaration:
915 case V_SgProcedureHeaderStatement:
916 case V_SgJovialTableStatement:
917 case V_SgJavaPackageDeclaration:
918 case V_SgFunctionDeclaration:
919 case V_SgMemberFunctionDeclaration:
920 case V_SgClassDeclaration:
921 case V_SgTemplateInstantiationTypedefDeclaration:
922 case V_SgTemplateInstantiationFunctionDecl:
923 case V_SgTemplateInstantiationMemberFunctionDecl:
924 case V_SgTemplateVariableInstantiation:
925 case V_SgTemplateInstantiationDecl:
926 {
927 templateParameterList = NULL;
928 break;
929 }
930
931 case V_SgTemplateClassDeclaration:
932 {
933 templateParameterList = &(isSgTemplateClassDeclaration(decl)->get_templateParameters());
934 break;
935 }
936
937 case V_SgTemplateFunctionDeclaration:
938 {
939 templateParameterList = &(isSgTemplateFunctionDeclaration(decl)->get_templateParameters());
940 break;
941 }
942
943 case V_SgTemplateMemberFunctionDeclaration:
944 {
945 templateParameterList = &(isSgTemplateMemberFunctionDeclaration(decl)->get_templateParameters());
946 break;
947 }
948
949 case V_SgTemplateVariableDeclaration:
950 {
951 templateParameterList = &(isSgTemplateVariableDeclaration(decl)->get_templateParameters());
952 break;
953 }
954
955 case V_SgTemplateTypedefDeclaration:
956 {
957 templateParameterList = &(isSgTemplateTypedefDeclaration(decl)->get_templateParameters());
958 break;
959 }
960
961 case V_SgNonrealDecl:
962 {
963 templateParameterList = &(isSgNonrealDecl(decl)->get_tpl_params());
964 break;
965 }
966
967 case V_SgTemplateDeclaration:
968 {
969 templateParameterList = &(isSgTemplateDeclaration(decl)->get_templateParameters());
970 break;
971 }
972
973 default:
974 {
975 printf ("getTemplateParameterList(): Default reached in switch: decl = %p = %s \n",decl,decl->class_name().c_str());
976 ROSE_ABORT();
977 }
978 }
979
980 return templateParameterList;
981 }
982
983
984
985void
987 {
988 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
989
990 ROSE_ASSERT(decl != NULL);
991
992 SgTemplateArgumentPtrList* templateArgumentsList = getTemplateArgumentList(decl);
993
994 if (templateArgumentsList != NULL)
995 {
997 ROSE_ASSERT(first_decl != NULL);
998
999 SgTemplateArgumentPtrList::iterator i = templateArgumentsList->begin();
1000 while (i != templateArgumentsList->end())
1001 {
1002 SgNode* parent = (*i)->get_parent();
1003 if (parent== NULL)
1004 {
1005 // (*i)->set_parent(decl);
1006 (*i)->set_parent(first_decl);
1007 }
1008 else
1009 {
1010 SgScopeStatement* scope = isSgScopeStatement(parent);
1011 if (scope != NULL)
1012 {
1013 // Template Arguments should have had there parents set to a scope when they were build, we want
1014 // to refine that now that the declaration which we want them to be specified in has been build.
1015 (*i)->set_parent(first_decl);
1016 }
1017 else
1018 {
1019 SgDeclarationStatement* declaration = isSgDeclarationStatement(parent);
1020 if (declaration != NULL)
1021 {
1022#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
1023 printf ("In setTemplateArgumentParents(): Template argument already set to declaration = %p = %s \n",declaration,declaration->class_name().c_str());
1024#endif
1025 }
1026 else
1027 {
1028#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
1029 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());
1030#endif
1031 }
1032 }
1033 }
1034
1035 i++;
1036 }
1037 }
1038
1040 }
1041
1042
1043void
1045 {
1046 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1047 ROSE_ASSERT(decl != NULL);
1048
1049 SgTemplateParameterPtrList* templateParameterList = getTemplateParameterList(decl);
1050
1051 if (templateParameterList != NULL)
1052 {
1054 ROSE_ASSERT(first_decl != NULL);
1055
1056 SgTemplateParameterPtrList::iterator i = templateParameterList->begin();
1057 while (i != templateParameterList->end())
1058 {
1059 SgNode* parent = (*i)->get_parent();
1060 if (parent == NULL)
1061 {
1062 (*i)->set_parent(first_decl);
1063 }
1064 else
1065 {
1066 SgScopeStatement* scope = isSgScopeStatement(parent);
1067 if (scope != NULL)
1068 {
1069 // Template Arguments should have had their parents set to a scope when they were build, we want
1070 // to refine that now that the declaration which we want them to be specified in has been build.
1071 (*i)->set_parent(first_decl);
1072 }
1073 }
1074
1075 i++;
1076 }
1077 }
1078
1080 }
1081
1082
1083void
1085 {
1086 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1087
1088 ROSE_ASSERT(decl != NULL);
1089
1090 SgTemplateArgumentPtrList* templateArgumentsList = getTemplateArgumentList(decl);
1091
1092 if (templateArgumentsList != NULL)
1093 {
1094 SgTemplateArgumentPtrList::iterator i = templateArgumentsList->begin();
1095 while (i != templateArgumentsList->end())
1096 {
1097 SgNode* parent = (*i)->get_parent();
1098 if (parent == NULL)
1099 {
1100 printf ("Error: In testTemplateArgumentParents(): decl = %p = %s has template argument = %p with null parent \n",decl,decl->class_name().c_str(),*i);
1101 }
1102 ROSE_ASSERT(parent != NULL);
1103
1104 // DQ (9/16/2012): Adding new test.
1105 ROSE_ASSERT(decl->get_firstNondefiningDeclaration() != NULL);
1106 // DQ (1/30/2013): Commented this test out so that we could reuse SgTemplateArguments and
1107 // assure that the mapping from EDG a_template_arg_ptr's to SgTemplateArgument's was 1-to-1.
1108 // It is not clear if we can relax this constraint in the future.
1109
1110 i++;
1111 }
1112 }
1113 }
1114
1115
1116void
1118 {
1119 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1120
1121 ROSE_ASSERT(decl != NULL);
1122
1123 SgTemplateParameterPtrList* templateParameterList = getTemplateParameterList(decl);
1124
1125 if (templateParameterList != NULL)
1126 {
1127 SgTemplateParameterPtrList::iterator i = templateParameterList->begin();
1128 while (i != templateParameterList->end())
1129 {
1130 SgNode* parent = (*i)->get_parent();
1131 if (parent == NULL)
1132 {
1133 printf ("Error: In testTemplateParameterParents(): decl = %p = %s has template argument = %p with null parent \n",decl,decl->class_name().c_str(),*i);
1134 }
1135 ROSE_ASSERT(parent != NULL);
1136
1137 // DQ (9/16/2012): Adding new test.
1138 ROSE_ASSERT(decl->get_firstNondefiningDeclaration() != NULL);
1139 if (parent != decl->get_firstNondefiningDeclaration())
1140 {
1141#if 0
1142 // 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).
1143 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());
1144#endif
1145 }
1146
1147 // DQ (8/22/2013): Since these are now shared, it makes less sense to expect these to have such simple parent relationships.
1148 // This commit of work on ROSE added caching to template parameters so that we could support pointer equality for tests
1149 // of template parameter equality in the symbol table handling (this was a technique previously used for template arguments).
1150 // 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).
1151
1152 i++;
1153 }
1154 }
1155 }
1156
1157
1158void
1159SageBuilder::setTemplateArgumentsInDeclaration( SgDeclarationStatement* decl, SgTemplateArgumentPtrList* templateArgumentsList_input )
1160 {
1161 // DQ (9/16/2012): Setup the template arguments for any type of template instantiation.
1162
1163 ROSE_ASSERT(templateArgumentsList_input != NULL);
1164
1165 ROSE_ASSERT(decl->variantT() == V_SgTemplateInstantiationDecl ||
1166 decl->variantT() == V_SgTemplateInstantiationFunctionDecl ||
1167 decl->variantT() == V_SgTemplateInstantiationMemberFunctionDecl ||
1168 decl->variantT() == V_SgTemplateInstantiationTypedefDeclaration);
1169
1170 SgTemplateArgumentPtrList* templateArgumentsList_from_declaration = getTemplateArgumentList(decl);
1171
1172 if (templateArgumentsList_from_declaration != NULL)
1173 {
1174 *templateArgumentsList_from_declaration = *templateArgumentsList_input;
1175
1176 // Set the parents.
1178 }
1179
1181 }
1182
1183
1184void
1185SageBuilder::setTemplateSpecializationArgumentsInDeclaration( SgDeclarationStatement* decl, SgTemplateArgumentPtrList* templateSpecializationArgumentsList_input )
1186 {
1187 // DQ (9/16/2012): Setup the template arguments for any type of template declaration
1188
1189 ROSE_ASSERT(templateSpecializationArgumentsList_input != NULL);
1190
1191 ROSE_ASSERT(decl->variantT() == V_SgTemplateClassDeclaration || decl->variantT() == V_SgTemplateFunctionDeclaration ||
1192 decl->variantT() == V_SgTemplateMemberFunctionDeclaration || decl->variantT() == V_SgTemplateVariableDeclaration );
1193
1194 SgTemplateArgumentPtrList* templateSpecializationArgumentsList_from_declaration = getTemplateArgumentList(decl);
1195
1196 if (templateSpecializationArgumentsList_from_declaration != NULL)
1197 {
1198 *templateSpecializationArgumentsList_from_declaration = *templateSpecializationArgumentsList_input;
1199
1200 // Set the parents.
1202 }
1203
1205 }
1206
1207void
1208SageBuilder::setTemplateParametersInDeclaration( SgDeclarationStatement* decl, SgTemplateParameterPtrList* templateParameterList_input )
1209 {
1210 // DQ (9/16/2012): Setup the template parameters for any type of template declaration.
1211
1212 ROSE_ASSERT(templateParameterList_input != NULL);
1213
1214 ROSE_ASSERT(decl->variantT() == V_SgTemplateClassDeclaration || decl->variantT() == V_SgTemplateFunctionDeclaration ||
1215 decl->variantT() == V_SgTemplateMemberFunctionDeclaration || decl->variantT() == V_SgTemplateVariableDeclaration );
1216
1217 SgTemplateParameterPtrList* templateParameterList_from_declaration = getTemplateParameterList(decl);
1218
1219 if (templateParameterList_from_declaration != NULL)
1220 {
1221 *templateParameterList_from_declaration = *templateParameterList_input;
1222
1223 // Set the parents.
1225 }
1226
1228 }
1229
1230#define DEBUG__buildInitializedName 0
1231// Only used to build parameter arguments for function ??
1232// should be transparently generated for most variable declaration builder
1233// deferred symbol insertion, scope setting , etc
1234// do them when it is actually used with the parameterList!!
1236#if DEBUG__buildInitializedName
1237 std::cout << "SageBuilder::buildInitializedName" << std::endl;
1238 std::cout << " name = " << name << std::endl;
1239#endif
1240 ASSERT_not_null(type);
1241
1242 SgInitializedName* initializedName = new SgInitializedName(name,type,init);
1243 ROSE_ASSERT(initializedName);
1244
1246 return initializedName;
1247}
1248
1249SgInitializedName * SageBuilder::buildInitializedName ( const std::string & name, SgType* type) {
1250 SgName var_name(name);
1251 return buildInitializedName(var_name,type);
1252}
1253
1255 string var_name(name);
1256 return buildInitializedName(var_name,type);
1257}
1258
1260#if DEBUG__buildInitializedName
1261 std::cout << "SageBuilder::buildInitializedName_nfi" << std::endl;
1262 std::cout << " name = " << name << std::endl;
1263#endif
1264 ROSE_ASSERT(type != NULL);
1265
1266 SgInitializedName* initializedName = new SgInitializedName(name,type,init);
1267 ROSE_ASSERT(initializedName != NULL);
1268
1269 if (declptr)
1270 {
1271 initializedName->set_parent(declptr);
1272 initializedName->set_declptr(declptr);
1273 }
1274
1275 setOneSourcePositionNull(initializedName);
1276
1277 return initializedName;
1278}
1279
1280//-----------------------------------------------
1281// could have two declarations for a same variable
1282// extern int i;
1283// int i;
1286 //(const SgName & name, SgType* type, SgInitializer * varInit= NULL, SgScopeStatement* scope = NULL)
1287{
1288 if (scope == NULL)
1290 ROSE_ASSERT(name.is_null() == false);
1291 ROSE_ASSERT(type != NULL);
1292
1293 SgVariableDeclaration * varDecl = new SgVariableDeclaration(name, type, varInit);
1294 ROSE_ASSERT(varDecl);
1295
1296// DQ (8/21/2011): Note that the default is to set the declaration modifier's access modifier to be
1297// default (which is the same as public). So the effect it to set it to be public. This is ignored
1298// by the unparser for most languguages in ROSE.
1299 varDecl->set_firstNondefiningDeclaration(varDecl);
1300
1301 if (scope!=NULL)
1302 {
1303 // Liao 12/13/2010
1304 // Fortran subroutine/function parameters have corresponding variable declarations in the body
1305 // For this declaration, it should use the initialized names of the parameters instead of creating new ones
1306 // The symbol of the init name should be under SgFunctionDefinition, instead of the function body block
1307 bool isFortranParameter = false;
1309 {
1311 if (f_def != NULL)
1312 {
1313 // DQ (5/21/2013): Removed direct reference to symbol table (namespace handling is only supported at the SgScopeStatement level).
1314 SgVariableSymbol * v_symbol = f_def->lookup_variable_symbol(name);
1315 if (v_symbol != NULL) // find a function parameter with the same name
1316 {
1317 // replace the default one with the one from parameter
1318 SgInitializedName *default_initName = varDecl->get_decl_item (name);
1319 ROSE_ASSERT (default_initName != NULL);
1320 SgInitializedName * new_initName = v_symbol->get_declaration();
1321 ROSE_ASSERT (new_initName != NULL);
1322 ROSE_ASSERT (default_initName != new_initName);
1323
1324 SgInitializedNamePtrList& n_list= varDecl->get_variables();
1325 std::replace (n_list.begin(), n_list.end(),default_initName, new_initName );
1326 ROSE_ASSERT (varDecl->get_decl_item (name)==new_initName); //ensure the new one can be found
1327
1328 // change the function argument's old parent to the variable declaration
1329 SgNode * old_parent = new_initName->get_parent();
1330 ROSE_ASSERT (old_parent != NULL);
1331 ROSE_ASSERT (isSgFunctionParameterList(old_parent) != NULL);
1332 new_initName->set_parent(varDecl); // adjust parent from SgFunctionParameterList to SgVariableDeclaration
1333
1334 // DQ (1/25/2011): Deleting these causes problems if I use this function in the Fortran support...
1335 // delete (default_initName->get_declptr()); // delete the var definition
1336 // delete (default_initName->get_declptr()); // relink the var definition
1337
1338 SgVariableDefinition * var_def = isSgVariableDefinition(default_initName->get_declptr()) ;
1339 ROSE_ASSERT (var_def != NULL);
1340 var_def->set_parent(new_initName);
1341 var_def->set_vardefn(new_initName);
1342 new_initName->set_declptr(var_def); // it was set to SgProcedureHeaderStatement as a function argument
1343
1344 delete (default_initName); // must delete the old one to pass AST consistency test
1345
1346 // DQ (12/13/2011): Is this executed...
1347 //printf ("Is this executed \n");
1348 //ROSE_ASSERT(false);
1349
1350 isFortranParameter = true;
1351 }
1352 }
1353 }
1354 if (! isFortranParameter) // No need to add symbol to the function body if it is a Fortran parameter
1355 // The symbol should already exist under function definition for the parameter
1356 fixVariableDeclaration(varDecl,scope);
1357 }
1358
1359 SgInitializedName *initName = varDecl->get_decl_item (name);
1360 ROSE_ASSERT(initName != NULL);
1361 ROSE_ASSERT((initName->get_declptr())!=NULL);
1362
1363 //bug 119, SgVariableDefintion's File_info is needed for deep copy to work
1364 // AstQuery based setSourcePositionForTransformation() cannot access all child nodes
1365 // have to set SgVariableDefintion explicitly
1366 SgDeclarationStatement* variableDefinition_original = initName->get_declptr();
1367 setOneSourcePositionForTransformation(variableDefinition_original);
1368 ROSE_ASSERT((variableDefinition_original->get_startOfConstruct()) !=NULL);
1369 ROSE_ASSERT((variableDefinition_original->get_endOfConstruct())!=NULL);
1370
1372 //ROSE_ASSERT (isSgVariableDefinition(initName->get_declptr())->get_startOfConstruct()!=NULL);
1373
1374
1375 // DQ (4/16/2015): This is replaced with a better implementation.
1376 // DQ (4/15/2015): We should reset the isModified flags as part of the transforamtion
1377 // because we have added statements explicitly marked as transformations.
1378 // checkIsModifiedFlag(varDecl);
1379 unsetNodesMarkedAsModified(varDecl);
1380
1381// ROSE_ASSERT(findFirstSgCastExpMarkedAsTransformation(varDecl,"testing buildVariableDeclaration(): 9") == false);
1382// ROSE_ASSERT(findFirstSgCastExpMarkedAsTransformation(scope,"testing buildVariableDeclaration(): 9-scope") == false);
1383
1384 return varDecl;
1385}
1386
1387//-----------------------------------------------
1388// could have two declarations for a same variable
1389// extern int i;
1390// int i;
1393 {
1394
1395#define DEBUG_BUILD_VARIABLE_DECLARATION 0
1396
1397#if DEBUG_BUILD_VARIABLE_DECLARATION
1398 printf ("In SageBuilder::buildVariableDeclaration_nfi(): name = %s scope = %p varInit = %p \n",name.str(),scope,varInit);
1399 if (scope != NULL)
1400 {
1401 printf (" --- scope = %p = %s \n",scope,scope->class_name().c_str());
1402 }
1403#endif
1404
1405 if (scope == NULL)
1406 {
1407#if DEBUG_BUILD_VARIABLE_DECLARATION
1408 printf ("Scope determined from the SageBuilder::topScopeStack() \n");
1409#endif
1411 }
1412
1413 ROSE_ASSERT (scope != NULL);
1414 ROSE_ASSERT(type != NULL);
1415
1416 // DQ (7/18/2012): Added debugging code (should fail for test2011_75.C).
1417 SgVariableSymbol* variableSymbol = scope->lookup_variable_symbol(name);
1418
1419#if DEBUG_BUILD_VARIABLE_DECLARATION
1420 printf ("In SageBuilder::buildVariableDeclaration_nfi(): variableSymbol = %p \n",variableSymbol);
1421#endif
1422
1423 // 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.
1424 SgVariableDeclaration * varDecl = NULL;
1425 if (variableSymbol == NULL)
1426 {
1427 varDecl = new SgVariableDeclaration(name, type, varInit);
1428#if DEBUG_BUILD_VARIABLE_DECLARATION
1429 SgInitializedName* tmp_initializedName = getFirstInitializedName(varDecl);
1430 ROSE_ASSERT(tmp_initializedName != NULL);
1431 printf ("In SageBuilder::buildVariableDeclaration_nfi(): variableSymbol == NULL: varDecl = %p: initializedName = %p = %s \n",varDecl,tmp_initializedName,tmp_initializedName->get_name().str());
1432 printf (" --- tmp_initializedName->get_initptr() = %p \n",tmp_initializedName->get_initptr());
1433#endif
1434 // DQ (6/25/2019): This is a new feature to input the builtFromUseOnly function optional parameter.
1435 if (builtFromUseOnly == true)
1436 {
1437#if DEBUG_BUILD_VARIABLE_DECLARATION
1438 printf ("In buildVariableDeclaration_nfi(): this is the first reference to this variable: building a new SgVariableDeclaration: varDecl = %p name = %s \n",varDecl,name.str());
1439#endif
1440 varDecl->set_builtFromUseOnly(true);
1441 }
1442 }
1443 else
1444 {
1445 SgInitializedName* initializedName = variableSymbol->get_declaration();
1446 ROSE_ASSERT(initializedName != NULL);
1447
1448 SgVariableDeclaration* associatedVariableDeclaration = isSgVariableDeclaration(initializedName->get_parent());
1449
1450#if DEBUG_BUILD_VARIABLE_DECLARATION
1451 printf ("In SageBuilder::buildVariableDeclaration_nfi(): initializedName->get_parent() = %p \n",initializedName->get_parent());
1452 if (initializedName->get_parent() != NULL)
1453 {
1454 printf ("In SageBuilder::buildVariableDeclaration_nfi(): initializedName->get_parent() = %p = %s \n",initializedName->get_parent(),initializedName->get_parent()->class_name().c_str());
1455 }
1456 printf ("In SageBuilder::buildVariableDeclaration_nfi(): associatedVariableDeclaration = %p \n",associatedVariableDeclaration);
1457#endif
1458#if DEBUG_BUILD_VARIABLE_DECLARATION
1459 // DQ (6/24/2019): If this has been previously built as part of a variable use (in a class declaration),
1460 // then it should not be attached to the class definition as a variable declaration yet, and we should reuse it.
1461 if (associatedVariableDeclaration != NULL && associatedVariableDeclaration->get_parent() != NULL)
1462 {
1463 printf ("In SageBuilder::buildVariableDeclaration_nfi(): associatedVariableDeclaration->get_parent() = %p = %s \n",
1464 associatedVariableDeclaration->get_parent(),associatedVariableDeclaration->get_parent()->class_name().c_str());
1465 }
1466#endif
1467
1468#if DEBUG_BUILD_VARIABLE_DECLARATION
1469 printf ("associatedVariableDeclaration = %p \n",associatedVariableDeclaration);
1470 if (associatedVariableDeclaration != NULL)
1471 {
1472 printf ("associatedVariableDeclaration->get_builtFromUseOnly() = %s \n",associatedVariableDeclaration->get_builtFromUseOnly() ? "true" : "false");
1473 }
1474#endif
1475
1476 // DQ (6/25/2019): Trigger the reuse of the available variable declaration.
1477 bool reuseTheAssociatedVariableDeclaration = ((associatedVariableDeclaration != NULL) && (associatedVariableDeclaration->get_builtFromUseOnly() == true));
1478 if (reuseTheAssociatedVariableDeclaration == true)
1479 {
1480 // Build a seperate SgVariableDeclaration so that we can avoid sharing the SgInitializedName
1481 // (and it's possible initializer which would be an error for the secondary declaration
1482 // (the declaration in the class for the case of a static declaration))
1483
1484 ROSE_ASSERT(associatedVariableDeclaration != NULL);
1485
1486 // DQ (6/24/2019): Fix this to use the associatedVariableDeclaration.
1487 varDecl = associatedVariableDeclaration;
1488
1489 // DQ (6/25/2019): Mark this variable declaration so that it will not be reused again.
1490 varDecl->set_builtFromUseOnly(false);
1491
1492 // 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.
1493 varDecl->set_parent(NULL);
1494
1495 // DQ (6/24/2019): this veriable declaration that is being reused, should not have had an initializer (check this).
1497 ROSE_ASSERT(variable != NULL);
1498
1499 // DQ (6/25/2019): See Cxx11_tests/test2019_121.C and Cxx11_tests/test2019_482.C.
1500 // ROSE_ASSERT(variable->get_initptr() == NULL);
1501#if DEBUG_BUILD_VARIABLE_DECLARATION
1502 if (variable->get_initptr() != NULL)
1503 {
1504 printf ("Found initializer associated with variable declaration being reused: variable = %p name = %s \n",variable,variable->get_name().str());
1505 }
1506#endif
1507 // DQ (7/3/2019): Reuse in a conditional will have a valid initializer.
1508 }
1509 else
1510 {
1511 // DQ (6/25/2019): We can't reuse the existing SgInitializedName, because it could have been initialized in the other SgVariableDeclaration.
1512 // DQ (6/26/2019): Added assertion.
1513 ROSE_ASSERT(reuseTheAssociatedVariableDeclaration == false);
1514
1515 // DQ (6/27/2019): If the SgInitializedName was generated from the convert_variable_use() function in the
1516 // EDG/ROSE translation, then where was not associated SgVariableDeclaration built (an inconsistancy).
1517 // So we want to check for the parent being a scope statement (e.g. SgIfStmt or other statement that can
1518 // accept a conditional expression where in C++ it can alternatively declare a variable.
1519 if (associatedVariableDeclaration == NULL)
1520 {
1521 ROSE_ASSERT(initializedName->get_parent() != NULL);
1522 SgScopeStatement* scopeStatement = isSgScopeStatement(initializedName->get_parent());
1523 if (scopeStatement != NULL)
1524 {
1525#if DEBUG_BUILD_VARIABLE_DECLARATION
1526 printf ("scopeStatement = %p = %s \n",scopeStatement,scopeStatement->class_name().c_str());
1527#endif
1528 }
1529 else
1530 {
1531#if DEBUG_BUILD_VARIABLE_DECLARATION
1532 printf ("initializedName->get_parent() = %p = %s \n",initializedName->get_parent(),initializedName->get_parent()->class_name().c_str());
1533#endif
1534 }
1535 }
1536
1537 // DQ (6/27/2019): In some case we want to reuse the associated SgInitializedName node.
1538 // For example: variable declarations in conditionals (e.g. SgIfStmt, and other scope statements).
1539 // DQ (6/26/2019): Build an additional variable to support another reference to the original variable.
1540 // Note: we need another one because either one can have an initializer that cannot be shared in the AST.
1541 SgInitializedName* additional_variable = NULL;
1542
1543#if DEBUG_BUILD_VARIABLE_DECLARATION
1544 printf ("In SageBuilder::buildVariableDeclaration_nfi(): initializedName->get_scope() = %p = %s \n",initializedName->get_scope(),initializedName->get_scope()->class_name().c_str());
1545#endif
1546 SgScopeStatement* scopeStatement = isSgScopeStatement(initializedName->get_parent());
1547 if (scopeStatement != NULL)
1548 {
1549 additional_variable = initializedName;
1550
1551 // DQ (6/28/2019): Support case when the borrowed SgInitializedName has a valid initializer.
1552 // DQ (6/26/2019): Adding the initializer.
1553 if (additional_variable->get_initptr() != NULL)
1554 {
1555#if DEBUG_BUILD_VARIABLE_DECLARATION
1556 printf ("In SageBuilder::buildVariableDeclaration_nfi(): borrowed SgInitializedName is alread initialized \n");
1557 printf (" --- additional_variable->get_initptr() = %p \n",additional_variable->get_initptr());
1558 printf (" --- varInit = %p \n",varInit);
1559#endif
1560 // DQ (6/28/2019): when this is assertion is false, we have constructed a redundant initializer (debugging this).
1561 // PP (7/22/2019) faults in CUDA code
1562 }
1563 else
1564 {
1565 additional_variable->set_initptr(varInit);
1566 }
1567
1568#if DEBUG_BUILD_VARIABLE_DECLARATION || 0
1569 printf (" --- additional_variable->get_scope() = %p = %s \n",additional_variable->get_scope(),additional_variable->get_scope()->class_name().c_str());
1570 printf (" --- Reusing the SgInitializedName (not associated with a previous SgVariableDeclaration where the parent is a SgScopeStatement) \n");
1571#endif
1572 }
1573 else
1574 {
1575#if DEBUG_BUILD_VARIABLE_DECLARATION
1576 printf (" --- Building a new SgInitializedName \n");
1577#endif
1578 additional_variable = buildInitializedName_nfi(name,type,varInit);
1579 }
1580
1581#if DEBUG_BUILD_VARIABLE_DECLARATION
1582 ROSE_ASSERT(initializedName->get_scope() != NULL);
1583#endif
1584 // DQ (6/26/2019): Set the scopes to be the same (a symbol already exists at this point).
1585 // DQ (6/26/2019): Set the pointer to the original version of this variable (unless we reused the SgInitializedName above).
1586 if (additional_variable != initializedName)
1587 {
1588 additional_variable->set_prev_decl_item(initializedName);
1589 }
1590
1591 // If there is not an associated SgVariableDeclaration then reuse the existing SgInitializedName.
1592 varDecl = new SgVariableDeclaration(additional_variable);
1593#if DEBUG_BUILD_VARIABLE_DECLARATION
1594 ROSE_ASSERT(initializedName->get_parent() != NULL);
1595 printf ("initializedName->get_parent() = %p = %s \n",initializedName->get_parent(),initializedName->get_parent()->class_name().c_str());
1596 ROSE_ASSERT(additional_variable->get_parent() != NULL);
1597 printf ("additional_variable->get_parent() = %p = %s \n",additional_variable->get_parent(),additional_variable->get_parent()->class_name().c_str());
1598#endif
1599 // DQ (6/26/2019): Set the parent of the first SgInitializedName to that of the second SgInitializedName.
1600 // This is an issue for the range for initialization: see test2019_483.C.
1601
1602 ASSERT_not_null(initializedName->get_scope());
1603
1604 // DQ (6/26/2019): Set the pointer to the original version of this variable (unless we reused the SgInitializedName above).
1605 if (additional_variable != initializedName)
1606 {
1607 additional_variable->set_scope(initializedName->get_scope());
1608 }
1609 // DQ (7/14/2014): Set the variable initialized (see test2014_107.C, also required for boost for_each support)).
1610 // initializedName->set_initptr(varInit);
1611#if DEBUG_BUILD_VARIABLE_DECLARATION
1612 printf ("In SageBuilder::buildVariableDeclaration_nfi(): After sharing the exisitng SgInitializedName: initializedName = %p = %s \n",initializedName,initializedName->get_name().str());
1613 printf (" --- initializedName->get_initptr() = %p \n",initializedName->get_initptr());
1614 printf (" --- additional_variable->get_initptr() = %p \n",additional_variable->get_initptr());
1615#endif
1616 }
1617 }
1618
1619 // DQ (11/3/2012): The SgInitializedName inside the SgVariableDeclaration must have valid source position object (even if default initialized).
1621 ASSERT_not_null(variable);
1623
1624 ASSERT_not_null(varDecl);
1625 varDecl->set_firstNondefiningDeclaration(varDecl);
1626 varDecl->get_declarationModifier().get_storageModifier().set_modifier(sm);
1627
1628 // DQ (7/9/2012): Added test (parent should not be set yet; set in parse_statement).
1629 ROSE_ASSERT(varDecl->get_parent() == NULL);
1630
1631 if (name != "")
1632 {
1633 // Anonymous bit fields should not have symbols
1634 fixVariableDeclaration(varDecl,scope);
1635
1636 // DQ (7/9/2012): Added test (parent should not be set yet; set in parse_statement).
1637 }
1638 else
1639 {
1640 // 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).
1641 // 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...
1642 varDecl->set_parent(topScopeStack());
1643 ASSERT_not_null(varDecl->get_parent());
1644 }
1645
1646 SgInitializedName *initName = varDecl->get_decl_item (name);
1647 ASSERT_not_null(initName);
1648 ASSERT_not_null(initName->get_declptr());
1649
1650 if (initName->get_scope())
1651 {
1652 // Make this a warning for the few places where this fails.
1653#if DEBUG_BUILD_VARIABLE_DECLARATION
1654 printf ("WARNING: Note in buildVariableDeclaration_nfi(): initName->get_scope() == NULL \n");
1655#endif
1656 }
1657
1658 // DQ (7/9/2012): Added test (parent should not be set yet; set in parse_statement).
1659 // bug 119, SgVariableDefintion's File_info is needed for deep copy to work
1660 // AstQuery based setSourcePositionForTransformation() cannot access all child nodes
1661 // have to set SgVariableDefintion explicitly
1662 SgVariableDefinition* variableDefinition_original = isSgVariableDefinition(initName->get_declptr());
1663 ASSERT_not_null(variableDefinition_original);
1664 setOneSourcePositionNull(variableDefinition_original);
1665 setOneSourcePositionNull(varDecl);
1666
1667 // DQ (7/12/2012): The parent should be set to the current scope (not the same as that specified
1668 // in the scope (since that applies to the variable (SgInitializedName) not the SgVariableDeclaration).
1669 // Liao, 1/23/2013, quick fix for now, this condition is a mirror to the code setting parent in SageInterface::fixVariableDeclaration()
1670 if (topScopeStack())
1671 {
1672 ASSERT_not_null(varDecl->get_parent());
1673 }
1674
1675 // DQ (4/16/2015): This is replaced with a better implementation.
1676 // DQ (4/15/2015): We should reset the isModified flags as part of the transforamtion
1677 // because we have added statements explicitly marked as transformations.
1678 unsetNodesMarkedAsModified(varDecl);
1679
1680 ASSERT_not_null(varDecl);
1681
1682#if DEBUG_BUILD_VARIABLE_DECLARATION
1683 printf ("Leaving buildVariableDeclaration_nfi(): varDecl = %p varDecl->get_parent() = %p \n",varDecl,varDecl->get_parent());
1684#endif
1685
1686 return varDecl;
1687 }
1688
1689
1692{
1693// refactored from ROSETTA/Grammar/Statement.code SgVariableDeclaration::append_variable ()
1694
1695 ROSE_ASSERT (decl!=NULL);
1696 ROSE_ASSERT (init_name !=NULL);
1697 // init can be NULL
1698
1699 SgVariableDefinition *defn_stmt = NULL;
1700 if (!isSgFunctionType(init_name->get_type()))
1701 {
1702 Sg_File_Info* copyOfFileInfo = NULL;
1703 if (decl->get_file_info() != NULL)
1704 {
1705 copyOfFileInfo = new Sg_File_Info(*(decl->get_file_info()));
1706 ROSE_ASSERT (copyOfFileInfo != NULL);
1707
1708 // Note that the SgVariableDefinition will connect the new IR node into the AST.
1709 defn_stmt = new SgVariableDefinition(copyOfFileInfo, init_name, init);
1710 ROSE_ASSERT (defn_stmt != NULL);
1711
1712 copyOfFileInfo->set_parent(defn_stmt);
1713
1714 // DQ (3/13/2007): We can't enforce that the endOfConstruct is set (if the interface using the startOfConstruct is used.
1715 // DQ (2/3/2007): Need to build the endOfConstruct position as well.
1716 if (decl->get_endOfConstruct() != NULL)
1717 {
1718 Sg_File_Info* copyOfEndOfConstruct = new Sg_File_Info(*(decl->get_endOfConstruct()));
1719 defn_stmt->set_endOfConstruct(copyOfEndOfConstruct);
1720 copyOfEndOfConstruct->set_parent(defn_stmt);
1721 }
1722 }
1723 else
1724 {
1725 // Note that the SgVariableDefinition will connect the new IR node into the AST.
1726 defn_stmt = new SgVariableDefinition(init_name, init);
1727 }
1728 ROSE_ASSERT(defn_stmt != NULL);
1729 }
1730 else
1731 defn_stmt = NULL;
1732 return defn_stmt ;
1733}
1734
1735
1738{
1741 return res;
1742}
1743
1746 {
1747 ROSE_ASSERT (scope != NULL);
1748 ROSE_ASSERT(type != NULL);
1749
1750 SgTemplateVariableDeclaration * varDecl = new SgTemplateVariableDeclaration(name, type, varInit);
1751 ROSE_ASSERT(varDecl);
1752
1753 varDecl->set_firstNondefiningDeclaration(varDecl);
1754
1755 // DQ (11/3/2012): The SgInitializedName inside the SgVariableDeclaration must have valid source position object (even if default initialized).
1757 ROSE_ASSERT(variable != NULL);
1759
1760 if (name != "")
1761 {
1762 // Anonymous bit fields should not have symbols
1763 fixVariableDeclaration(varDecl,scope);
1764 }
1765
1766 SgInitializedName *initName = varDecl->get_decl_item (name);
1767 ROSE_ASSERT(initName);
1768 ROSE_ASSERT((initName->get_declptr())!=NULL);
1769
1770 // bug 119, SgVariableDefintion's File_info is needed for deep copy to work
1771 // AstQuery based setSourcePositionForTransformation() cannot access all child nodes
1772 // have to set SgVariableDefintion explicitly
1773 SgVariableDefinition* variableDefinition_original = isSgVariableDefinition(initName->get_declptr());
1774 ROSE_ASSERT(variableDefinition_original != NULL);
1775 setOneSourcePositionNull(variableDefinition_original);
1776
1777 setOneSourcePositionNull(varDecl);
1778
1779 return varDecl;
1780 }
1781
1784 const SgName & name, SgType *type, SgInitializer *varInit, SgScopeStatement* scope,
1786 SgTemplateArgumentPtrList & tpl_args
1787) {
1788 SgTemplateVariableInstantiation* res = buildTemplateVariableInstantiation_nfi(name, type, varInit, scope, tpl_decl, tpl_args);
1790 return res;
1791}
1792
1793#define DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi 0
1794
1797 const SgName & name, SgType *type, SgInitializer *varInit, SgScopeStatement* scope,
1799 SgTemplateArgumentPtrList & tpl_args
1800) {
1801#if DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi
1802 std::cout << "SageBuilder::buildTemplateVariableInstantiation_nfi" << std::endl;
1803 std::cout << " name = " << name.getString() << std::endl;
1804 std::cout << " type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
1805 std::cout << " scope = " << std::hex << scope << " : " << ( scope ? scope->class_name() : "" ) << std::endl;
1806#endif
1807 ROSE_ASSERT (type != NULL);
1808
1809 SgName nameWithoutTemplateArguments = name;
1810 SgName nameWithTemplateArguments = appendTemplateArgumentsToName(name,tpl_args);
1811#if DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi
1812 std::cout << " nameWithoutTemplateArguments = " << nameWithoutTemplateArguments.getString() << std::endl;
1813 std::cout << " nameWithTemplateArguments = " << nameWithTemplateArguments.getString() << std::endl;
1814#endif
1815
1816 ROSE_ASSERT (scope != NULL);
1817 ROSE_ASSERT(type != NULL);
1818
1819 SgTemplateVariableInstantiation * varDecl = new SgTemplateVariableInstantiation(name, type, varInit);
1820 ROSE_ASSERT(varDecl);
1821#if DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi
1822 std::cout << " varDecl = " << std::hex << varDecl << " : " << ( varDecl ? varDecl->class_name() : "" ) << std::endl;
1823#endif
1824
1825 varDecl->set_firstNondefiningDeclaration(varDecl);
1826 varDecl->get_templateArguments() = tpl_args;
1827
1829 ROSE_ASSERT(variable != NULL);
1831
1832 if (name != "") {
1833 fixVariableDeclaration(varDecl, scope);
1834 }
1835
1836 SgInitializedName *initName = varDecl->get_decl_item (name);
1837 ROSE_ASSERT(initName);
1838 ROSE_ASSERT((initName->get_declptr()) != nullptr);
1839#if DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi
1840 std::cout << " initName = " << std::hex << initName << " : " << ( initName ? initName->class_name() : "" ) << std::endl;
1841#endif
1842
1843 SgVariableDefinition* variableDefinition_original = isSgVariableDefinition(initName->get_declptr());
1844 ROSE_ASSERT(variableDefinition_original != NULL);
1845 setOneSourcePositionNull(variableDefinition_original);
1846
1847 setOneSourcePositionNull(varDecl);
1848
1849 return varDecl;
1850 }
1851
1853SageBuilder::buildVariableDeclaration(const std::string & name, SgType* type, SgInitializer * varInit, SgScopeStatement* scope)
1854{
1855 SgName name2(name);
1856 return buildVariableDeclaration(name2,type, varInit,scope);
1857}
1858
1861{
1862 SgName name2(name);
1863 return buildVariableDeclaration(name2,type, varInit,scope);
1864}
1865
1868SageBuilder::buildTypedefDeclaration(const std::string& name, SgType* base_type, SgScopeStatement* scope /*= NULL*/, bool has_defining_base/*= false*/)
1869{
1870 SgTypedefDeclaration* type_decl = buildTypedefDeclaration_nfi(name, base_type, scope, has_defining_base);
1872
1873 return type_decl;
1874}
1875
1877// The side effects include: creating SgTypedefType, SgTypedefSymbol, and add SgTypedefType to the base type
1879SageBuilder::buildTypedefDeclaration_nfi(const std::string& name, SgType* base_type, SgScopeStatement* scope /*= NULL*/, bool has_defining_base/*=false*/)
1880 {
1881 ROSE_ASSERT (base_type != NULL);
1882
1883 if (scope == NULL )
1884 {
1886 }
1887
1888 // We don't yet support bottom up construction for this node yet
1889 ASSERT_not_null(scope);
1890
1891 SgDeclarationStatement* base_decl = nullptr;
1892
1893 // Handle the case where this is a pointer, reference, or typedef to another type.
1894 SgType* stripedBaseType = base_type->stripType();
1895 ASSERT_not_null(stripedBaseType);
1896
1897 SgNamedType* namedType = isSgNamedType(stripedBaseType);
1898 if (namedType)
1899 {
1900 // DQ (12/28/2019): the problem with getting the base declaration from the type is that it forces sharing
1901 // of the base declaration when the typedef has a defining declaration for a base type in multiple files.
1902
1903 // DQ (3/20/2012): Use this to set the value of base_decl (which was previously unset).
1904 // isSgNamedType(base_type)->get_declaration();
1905 // base_decl = isSgNamedType(base_type)->get_declaration();
1906 base_decl = namedType->get_declaration();
1907
1908 // DQ (3/20/2012): All named types should have a valid declaration!
1909 ROSE_ASSERT(base_decl != NULL);
1910 }
1911
1912 // DQ (3/20/2012): I don't remember why we need to provide the symbol for the scope of the
1913 // parent rather then the scope. But as I recall there was a special corner of C++ that
1914 // required this sort of support.
1915 SgSymbol* parent_scope = NULL;
1916#ifndef ROSE_USE_CLANG_FRONTEND
1917 if (scope != NULL)
1918 {
1919 ROSE_ASSERT(scope->get_parent() != NULL);
1920 SgDeclarationStatement* declaration = isSgDeclarationStatement(scope->get_parent());
1921
1922 // PP (3/9/22)
1923 // In Ada, discriminated type may not have been fully built yet.
1924 // this is because a the discriminated type obtains the name of the underlying
1925 // declaration.
1926 // PP (5/9/22)
1927 // Unsure if declaration link should be set at all for Ada.
1928 // The AstConsistencyTest flags typedefdecls with declaration link set...
1929 if (declaration && !isSgAdaDiscriminatedTypeDecl(declaration))
1930 {
1931 mprintf ("Found a valid declaration = %p = %s \n",declaration,declaration->class_name().c_str());
1932
1933 ROSE_ASSERT(SageInterface::is_Ada_language() || declaration->get_firstNondefiningDeclaration() != NULL);
1934
1935 parent_scope = declaration->search_for_symbol_from_symbol_table();
1936
1937 ROSE_ASSERT(parent_scope != NULL);
1938 }
1939 }
1940#endif
1941
1942 // Create the first nondefining declaration (note that the typedef type is always a NULL input value).
1943 SgTypedefDeclaration* type_decl = new SgTypedefDeclaration(SgName(name), base_type, NULL, base_decl, parent_scope);
1944 ROSE_ASSERT(type_decl != NULL);
1945
1946 // 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)
1947 type_decl->set_scope(scope);
1948 type_decl->set_parent(scope);
1949
1950 // DQ (2/27/2018): Add this call here to reflect change to the constructor semantics.
1951 type_decl->set_type(SgTypedefType::createType(type_decl));
1952
1953 // 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)).
1954 type_decl->set_firstNondefiningDeclaration (type_decl);
1955 type_decl->set_definingDeclaration(NULL);
1956
1957 // Set the source code position information.
1958 setOneSourcePositionNull(type_decl);
1959
1960 // Liao 11/29/2012, for typedef struct Frame {int x;} st_frame; We have to set parent for the struct.
1961 // AstPostProcessing() has resetParentPointers(). But it is kind of too late.
1962 if (SgClassDeclaration* base_class = isSgClassDeclaration(base_decl))
1963 {
1964 SgClassDeclaration* def_class = isSgClassDeclaration(base_class->get_definingDeclaration());
1965 SgClassDeclaration* nondef_class = isSgClassDeclaration(base_class->get_firstNondefiningDeclaration());
1966 // Dan and Liao, 12/3/2012, handle test2003_08.C nested typedef
1967 if (has_defining_base)
1968 {
1969 if (def_class != NULL)
1970 if (def_class->get_parent() == NULL)
1971 def_class->set_parent(type_decl);
1972 }
1973 else
1974 {
1975 if (nondef_class != NULL)
1976 if (nondef_class->get_parent() == NULL)
1977 {
1978 nondef_class->set_parent(type_decl);
1979 }
1980 }
1981 }
1982
1983 SgTypedefSymbol* typedef_symbol = new SgTypedefSymbol(type_decl);
1984 ROSE_ASSERT(typedef_symbol);
1985
1986 scope->insert_symbol(SgName(name),typedef_symbol);
1987
1988 return type_decl;
1989 }
1990
1991
1993SageBuilder::buildTemplateTypedefDeclaration_nfi(const SgName & name, SgType* base_type, SgScopeStatement* scope, bool has_defining_base )
1994 {
1995 // DQ (11/2/2014): Adding support for templated typedef.
1996
1997 ROSE_ASSERT (base_type != NULL);
1998
1999 if (scope == NULL )
2000 {
2002 }
2003
2004 // We don't yet support bottom up construction for this node yet
2005 ROSE_ASSERT(scope != NULL);
2006
2007 SgDeclarationStatement* base_decl = NULL;
2008
2009 // DQ (3/20/2012): I don't remember why we need to provide the symbol for the scope of the
2010 // parent rather then the scope. But as I recall there was a special corner of C++ that
2011 // required this sort of support.
2012 SgSymbol* parent_scope = NULL;
2013 if (scope != NULL)
2014 {
2015 ROSE_ASSERT(scope->get_parent() != NULL);
2016 SgDeclarationStatement* declaration = isSgDeclarationStatement(scope->get_parent());
2017
2018 if (declaration != NULL)
2019 {
2020 ROSE_ASSERT(declaration->get_firstNondefiningDeclaration() != NULL);
2021 parent_scope = declaration->search_for_symbol_from_symbol_table();
2022
2023 ROSE_ASSERT(parent_scope != NULL);
2024 }
2025 // 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.
2026 SgNamedType* namedType = isSgNamedType(base_type);
2027
2028 // DQ (3/4/2018): This might not always be true (sure enough it fails for Cxx11_tests/test2014_58.C).
2029
2030 if (namedType != NULL)
2031 {
2032 SgDeclarationStatement* declarationStatement = namedType->get_declaration();
2033
2034 // This might not always be true.
2035 ROSE_ASSERT(declarationStatement != NULL);
2036 if (declarationStatement != NULL)
2037 {
2038 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(declarationStatement);
2039 if (templateInstantiationDecl != NULL)
2040 {
2041 SgName name = templateInstantiationDecl->get_name();
2042 // DQ (2/28/2018): Added debugging to track down redundnat symbol.
2043 if (scope->lookup_template_typedef_symbol(name) != NULL)
2044 {
2045 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());
2046 }
2047 ROSE_ASSERT(scope->lookup_template_typedef_symbol(name) == NULL);
2048 }
2049 }
2050 }
2051 }
2052
2053 // We need to add the template parameter and partial specialization support to the SgTemplateTypedefDeclaration IR node.
2054 SgTemplateTypedefDeclaration* type_decl = new SgTemplateTypedefDeclaration(name, base_type, NULL, base_decl, parent_scope);
2055 ROSE_ASSERT(type_decl != NULL);
2056
2057 // 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)
2058 type_decl->set_scope(scope);
2059 type_decl->set_parent(scope);
2060
2061 // DQ (2/27/2018): We now have to set the type explicitly.
2062 ROSE_ASSERT(type_decl->get_type() == NULL);
2063
2064 SgTypedefType* typedefType = SgTypedefType::createType(type_decl);
2065 ROSE_ASSERT(typedefType != NULL);
2066
2067 // DQ (2/27/2018): It is an inconsistancy for the type to be set here.
2068 type_decl->set_type(typedefType);
2069
2070 // DQ (2/27/2018): This should be non-null, since we just built the new type.
2071 ROSE_ASSERT(type_decl->get_type() != NULL);
2072
2073 // 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)).
2074 type_decl->set_firstNondefiningDeclaration (type_decl);
2075 type_decl->set_definingDeclaration(NULL);
2076
2077 // Set the source code position information.
2078 setOneSourcePositionNull(type_decl);
2079
2080 // 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.
2081 SgNamedType* namedType = isSgNamedType(base_type);
2082
2083 // DQ (3/4/2018): This might not always be true (sure enough it fails for Cxx11_tests/test2014_58.C).
2084
2085 if (namedType != NULL)
2086 {
2087 SgDeclarationStatement* declarationStatement = namedType->get_declaration();
2088
2089 // This might not always be true.
2090 ROSE_ASSERT(declarationStatement != NULL);
2091 if (declarationStatement != NULL)
2092 {
2093 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(declarationStatement);
2094 if (templateInstantiationDecl != NULL)
2095 {
2096 SgName name = templateInstantiationDecl->get_name();
2097 // DQ (2/28/2018): Added debugging to track down redundnat symbol.
2098 if (scope->lookup_template_typedef_symbol(name) != NULL)
2099 {
2100 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());
2101 }
2102 ROSE_ASSERT(scope->lookup_template_typedef_symbol(name) == NULL);
2103 }
2104 }
2105 }
2106
2107 SgTemplateTypedefSymbol* typedef_symbol = new SgTemplateTypedefSymbol(type_decl);
2108 ROSE_ASSERT(typedef_symbol);
2109
2110 // DQ (5/16/2013): This is the code we want now that we have implemented the namespace support behind the scope symbol bable interface.
2111 scope->insert_symbol(name, typedef_symbol);
2112
2113 ROSE_ASSERT(scope->lookup_template_typedef_symbol(name) != NULL);
2114
2115 return type_decl;
2116 }
2117
2118#define DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi 0
2119
2122 SgName & name, SgType* base_type, SgScopeStatement* scope, bool has_defining_base,
2123 SgTemplateTypedefDeclaration* templateTypedefDeclaration,
2124 SgTemplateArgumentPtrList & templateArgumentsList
2125) {
2126#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2127 std::cout << "SageBuilder::buildTemplateInstantiationTypedefDeclaration_nfi" << std::endl;
2128 std::cout << " name = " << name.getString() << std::endl;
2129 std::cout << " base_type = " << std::hex << base_type << " : " << ( base_type ? base_type->class_name() : "" ) << std::endl;
2130#endif
2131 ROSE_ASSERT (base_type != NULL);
2132
2133 SgName nameWithoutTemplateArguments = name;
2134 SgName nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,templateArgumentsList);
2135#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2136 std::cout << " nameWithoutTemplateArguments = " << nameWithoutTemplateArguments.getString() << std::endl;
2137 std::cout << " nameWithTemplateArguments = " << nameWithTemplateArguments.getString() << std::endl;
2138#endif
2139
2140 // We don't yet support bottom up construction for this node yet
2141 ROSE_ASSERT(scope != NULL);
2142
2143 SgDeclarationStatement* base_decl = NULL;
2144
2145 // DQ (3/20/2012): I don't remember why we need to provide the symbol for the scope of the
2146 // parent rather then the scope. But as I recall there was a special corner of C++ that
2147 // required this sort of support.
2148 SgSymbol* parent_scope = NULL;
2149 if (scope != NULL)
2150 {
2151 ROSE_ASSERT(scope->get_parent() != NULL);
2152 SgDeclarationStatement* declaration = isSgDeclarationStatement(scope->get_parent());
2153 if (declaration != NULL)
2154 {
2155 ROSE_ASSERT(declaration->get_firstNondefiningDeclaration() != NULL);
2156 parent_scope = declaration->search_for_symbol_from_symbol_table();
2157
2158 ROSE_ASSERT(parent_scope != NULL);
2159 }
2160 }
2161
2162 // DQ (11/5/2014): I think this might be set afterward.
2163 ROSE_ASSERT(templateTypedefDeclaration != NULL);
2164
2165 SgTemplateTypedefSymbol* prexisting_template_typedef_symbol = scope->lookup_template_typedef_symbol(nameWithTemplateArguments);
2166 if (prexisting_template_typedef_symbol != NULL)
2167 {
2168 SgDeclarationStatement* declarationStatement = prexisting_template_typedef_symbol->get_declaration();
2169 ROSE_ASSERT(declarationStatement != NULL);
2170#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2171 std::cout << " declarationStatement = " << declarationStatement << " : " << declarationStatement->class_name() << std::endl;
2172#endif
2173 SgTemplateInstantiationTypedefDeclaration* return_declaration = isSgTemplateInstantiationTypedefDeclaration(declarationStatement);
2174 ROSE_ASSERT(return_declaration != NULL);
2175 return return_declaration;
2176 }
2177 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == NULL);
2178
2179 // DQ (2/25/2018): Not clear if we want to use the template name with arguments.
2180 // Calling: SgTemplateInstantiationTypedefDeclaration(SgName, SgType*, SgTypedefType*, SgDeclarationStatement*, SgSymbol*, SgTemplateTypedefDeclaration*, SgTemplateArgumentPtrList)
2181 SgTypedefType* typedefType = NULL;
2183 new SgTemplateInstantiationTypedefDeclaration(nameWithTemplateArguments, base_type, typedefType, base_decl, parent_scope, templateTypedefDeclaration, templateArgumentsList);
2184 ROSE_ASSERT(type_decl != NULL);
2185 ROSE_ASSERT(type_decl->get_base_type() == base_type);
2186
2187#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2188 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2189 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;
2190#endif
2191
2192 // DQ (2/27/2018): This is a change in the constructor semantics, we now have to build the type explicitly.
2193 // printf ("We now have to build the type explicitly \n");
2194 ROSE_ASSERT(type_decl->get_type() == NULL);
2195
2196
2197 // DQ (2/27/2018): Set the template name that this instantiation is using.
2198 type_decl->set_templateName(nameWithoutTemplateArguments);
2199
2200 ROSE_ASSERT(scope != NULL);
2201 type_decl->set_scope(scope);
2202
2203 // DQ (3/1/2018): A bug in the name of the template with arguments has been detected (extra spaces in
2204 // the name generated by type_decl->resetTemplateName()), make sure that we have a consistant naming.
2205 ROSE_ASSERT(type_decl->get_name() == nameWithTemplateArguments);
2206
2207 // DQ (2/28/2018): Added debugging to track down redundnat symbol.
2208 if (scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != NULL)
2209 {
2210 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());
2211 }
2212 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == NULL);
2213
2214
2215 // DQ (2/26/2018): Can we assert this?
2216 ROSE_ASSERT(type_decl->get_type() == NULL);
2217
2218 SgTypedefType* new_typedefType = SgTypedefType::createType(type_decl);
2219 ROSE_ASSERT(new_typedefType != NULL);
2220
2221 type_decl->set_type(new_typedefType);
2222 ROSE_ASSERT(type_decl->get_type() != NULL);
2223 ROSE_ASSERT(type_decl->get_scope() != NULL);
2224
2225 type_decl->set_firstNondefiningDeclaration (type_decl);
2226 type_decl->set_definingDeclaration(NULL);
2227
2228 setOneSourcePositionNull(type_decl);
2229
2230 setTemplateArgumentsInDeclaration(type_decl,&templateArgumentsList);
2231
2232 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() != NULL);
2233 ROSE_ASSERT(type_decl->get_definingDeclaration() == NULL);
2234 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() == type_decl);
2235
2236 ROSE_ASSERT(type_decl->get_type() != NULL);
2237 ROSE_ASSERT(scope != NULL);
2238
2239#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2240 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2241 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;
2242#endif
2243
2244 if (scope != NULL)
2245 {
2246 if (scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != NULL)
2247 {
2248 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());
2249 }
2250 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == NULL);
2251
2252 SgTemplateTypedefSymbol* typedef_symbol = new SgTemplateTypedefSymbol(type_decl);
2253 ROSE_ASSERT(typedef_symbol);
2254
2255 scope->insert_symbol(nameWithTemplateArguments,typedef_symbol);
2256 type_decl->set_scope(scope);
2257 type_decl->set_parent(scope);
2258 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != NULL);
2259 }
2260
2261#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2262 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2263 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;
2264#endif
2265
2266 return type_decl;
2267 }
2268
2269
2270
2271
2272
2273//-----------------------------------------------
2274// Assertion `definingDeclaration != NULL || firstNondefiningDeclaration != NULL'
2277{
2278 SgFunctionParameterList *parameterList = new SgFunctionParameterList();
2279 ROSE_ASSERT (parameterList);
2280
2281 parameterList->set_definingDeclaration (NULL);
2282 parameterList->set_firstNondefiningDeclaration (parameterList);
2283
2285
2286 if (in1) appendArg(parameterList, in1);
2287 if (in2) appendArg(parameterList, in2);
2288 if (in3) appendArg(parameterList, in3);
2289 if (in4) appendArg(parameterList, in4);
2290 if (in5) appendArg(parameterList, in5);
2291 if (in6) appendArg(parameterList, in6);
2292 if (in7) appendArg(parameterList, in7);
2293 if (in8) appendArg(parameterList, in8);
2294 if (in9) appendArg(parameterList, in9);
2295 if (in10) appendArg(parameterList, in10);
2296
2297 return parameterList;
2298}
2299
2302 SgFunctionParameterList *parameterList = new SgFunctionParameterList();
2303 ROSE_ASSERT (parameterList);
2304 parameterList->set_definingDeclaration (NULL);
2305 parameterList->set_firstNondefiningDeclaration (parameterList);
2306
2307 setOneSourcePositionNull(parameterList);
2308
2309 return parameterList;
2310}
2311
2312//-----------------------------------------------
2315 SgCtorInitializerList *ctorInitList = new SgCtorInitializerList();
2316 ROSE_ASSERT (ctorInitList);
2317 ctorInitList->set_definingDeclaration (NULL);
2318 ctorInitList->set_firstNondefiningDeclaration (ctorInitList);
2319
2320 setOneSourcePositionNull(ctorInitList);
2321
2322 return ctorInitList;
2323}
2324
2325//-----------------------------------------------
2326// no type vs. void type ?
2329 {
2330 // DQ (8/19/2012): I am not a fan of this sort of codeing style either (NULL pointers as inputs should be an error).
2331 if (paralist == NULL)
2332 {
2333 printf ("WARNING: In buildFunctionParameterTypeList(): Accepting NULL input and returning NULL pointer. \n");
2334
2335 return NULL;
2336 }
2337
2338 // 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).
2339 // if (paralist->get_args().size()==0)
2340 // return NULL;
2341
2343 ROSE_ASSERT(typePtrList != NULL);
2344
2345 SgInitializedNamePtrList args = paralist->get_args();
2346 SgInitializedNamePtrList::const_iterator i;
2347 for(i = args.begin(); i != args.end(); i++)
2348 (typePtrList->get_arguments()).push_back( (*i)->get_type() );
2349
2351
2352 return typePtrList;
2353 }
2354
2355
2358 {
2359 if (expList ==NULL) return NULL;
2360 SgExpressionPtrList expPtrList = expList->get_expressions();
2361
2363 ROSE_ASSERT(typePtrList);
2364
2365 SgExpressionPtrList::const_iterator i;
2366 for (i=expPtrList.begin();i!=expPtrList.end();i++)
2367 {
2368 typePtrList->get_arguments().push_back( (*i)->get_type() );
2369 }
2370
2372
2373 return typePtrList;
2374 }
2375
2378 SgType* type4, SgType* type5, SgType* type6, SgType* type7)
2379 {
2381 ROSE_ASSERT(typePtrList);
2382
2383 SgTypePtrList & types = typePtrList->get_arguments();
2384
2385 if (type0 != NULL) types.push_back(type0);
2386 if (type1 != NULL) types.push_back(type1);
2387 if (type2 != NULL) types.push_back(type2);
2388 if (type3 != NULL) types.push_back(type3);
2389 if (type4 != NULL) types.push_back(type4);
2390 if (type5 != NULL) types.push_back(type5);
2391 if (type6 != NULL) types.push_back(type6);
2392 if (type7 != NULL) types.push_back(type7);
2393
2394 return typePtrList;
2395 }
2396
2397//-----------------------------------------------
2398// build function type,
2399//
2400// insert into symbol table when not duplicated
2403 {
2404 ROSE_ASSERT(return_type != NULL);
2405
2406 // DQ (8/19/2012): Can we enforce this?
2407 ROSE_ASSERT(typeList != NULL);
2408
2410 ROSE_ASSERT(fTable);
2411
2412 // This function make clever use of a static member function which can't be built
2413 // for the case of a SgMemberFunctionType (or at least not without more work).
2414 SgName typeName = SgFunctionType::get_mangled(return_type, typeList);
2415
2416 SgFunctionType* funcType = isSgFunctionType(fTable->lookup_function_type(typeName));
2417
2418 if (funcType == NULL)
2419 {
2420 // Only build the new type if it can't be found in the global type table.
2421 funcType = new SgFunctionType(return_type, false);
2422 ROSE_ASSERT(funcType);
2423
2424 if (typeList != NULL)
2425 {
2426 // DQ (12/5/2012): We want to avoid overwriting an existing SgFunctionParameterTypeList. Could be related to failing tests for AST File I/O.
2427 if (funcType->get_argument_list() != NULL)
2428 {
2429 delete funcType->get_argument_list();
2430 funcType->set_argument_list(NULL);
2431 }
2432 ROSE_ASSERT(funcType->get_argument_list() == NULL);
2433
2434 funcType->set_argument_list(typeList);
2435 typeList->set_parent(funcType);
2436 }
2437
2438 fTable->insert_function_type(typeName,funcType);
2439 }
2440 else
2441 {
2442 // DQ (12/6/2012): Tracking down orphaned SgFunctionParameterTypeList objects.
2443 }
2444
2445 return funcType;
2446 }
2447
2448
2449
2451SageBuilder::buildMemberFunctionType(SgType* return_type, SgFunctionParameterTypeList* typeList, SgType *classType, unsigned int mfunc_specifier)
2452 {
2453 // DQ (8/19/2012): This is a refactored version of the buildMemberFunctionType() below so that we can
2454 // isolate out the part that uses a SgClassType from the version that uses the SgClassDefinition.
2455
2456 // Maintain the global type table
2458 ROSE_ASSERT(fTable != NULL);
2459
2460 // DQ (12/6/2012): Added assertion.
2461 // ROSE_ASSERT(classType != NULL);
2462
2463 // DQ (12/13/2012): Added assertion.
2464 ROSE_ASSERT(typeList != NULL);
2465
2466 // DQ (12/6/2012): Newer simpler code (using static function SgMemberFunctionType::get_mangled()).
2467 SgName typeName = SgMemberFunctionType::get_mangled(return_type,typeList,classType,mfunc_specifier);
2468 SgType* typeInTable = fTable->lookup_function_type(typeName);
2469
2470#if 0
2471 printf ("In buildMemberFunctionType(SgType*,SgFunctionParameterTypeList*,SgType*,int,int): fTable->lookup_function_type(typeName = %s) = %p \n",typeName.str(),typeInTable);
2472 printf (" --- mfunc_specifier = %d ref_qualifiers = %d \n",mfunc_specifier,ref_qualifiers);
2473#endif
2474
2475#if 0
2476 // DQ (1/10/2020): I think that these qualifiers are contained in the mfunc_specifier.
2477 if (ref_qualifiers > 0)
2478 {
2479 printf ("Exiting as a test! \n");
2480 ROSE_ABORT();
2481 }
2482#endif
2483
2484 SgMemberFunctionType* funcType = NULL;
2485 if (typeInTable == NULL)
2486 {
2487 bool has_ellipses = false;
2488 //~ SgPartialFunctionType* partialFunctionType = new SgPartialFunctionType(return_type, has_ellipses, classType, mfunc_specifier, ref_qualifiers);
2489 // PP (10/4/22): removing ref_qualifiers
2490 SgPartialFunctionType* partialFunctionType = new SgPartialFunctionType(return_type, has_ellipses, classType, mfunc_specifier);
2491 ROSE_ASSERT(partialFunctionType != NULL);
2492#if 0
2493 printf ("Building a SgPartialFunctionType: partialFunctionType = %p \n",partialFunctionType);
2494 printf (" --- partialFunctionType->isLvalueReferenceFunc() = %s \n",partialFunctionType->isLvalueReferenceFunc() ? "true" : "false");
2495 printf (" --- partialFunctionType->isRvalueReferenceFunc() = %s \n",partialFunctionType->isRvalueReferenceFunc() ? "true" : "false");
2496#endif
2497 // DQ (12/5/2012): We want to avoid overwriting an existing SgFunctionParameterTypeList. Could be related to failing tests for AST File I/O.
2498 if (partialFunctionType->get_argument_list() != NULL)
2499 {
2500 delete partialFunctionType->get_argument_list();
2501 partialFunctionType->set_argument_list(NULL);
2502 }
2503 ROSE_ASSERT(partialFunctionType->get_argument_list() == NULL);
2504
2505 typeList->set_parent(partialFunctionType);
2506
2507 // DQ (12/6/2012): Set the SgFunctionParameterTypeList in the SgPartialFunctionType before trying
2508 // to build a SgMemberFunctionType (not critical that it be set before, but might be in the future,
2509 // but it is important that it be set).
2510 partialFunctionType->set_argument_list(typeList);
2511
2512 ROSE_ASSERT(partialFunctionType->get_argument_list() != NULL);
2513
2514 // The optional_fortran_type_kind is only required for Fortran support.
2515 SgExpression* optional_fortran_type_kind = NULL;
2516 funcType = SgMemberFunctionType::createType(partialFunctionType, optional_fortran_type_kind);
2517
2518 // DQ (12/13/2012): Remove the SgPartialFunctionType after it has been used to build the SgMemberFunctionType.
2519 // I would rather modify the SgMemberFunctionType::createType() API so that we didn't use the SgPartialFunctionType IR nodes.
2520 // First we have to reset the pointer to the type argument list to NULL since it is shared with the SgMemberFunctionType.
2521 partialFunctionType->set_argument_list(NULL);
2522
2523 // Then we can delete the SgPartialFunctionType.
2524 delete partialFunctionType;
2525 partialFunctionType = NULL;
2526
2527 // This is perhaps redundant since it was set to a derived class (but might be an important distiction).
2528 typeList->set_parent(funcType);
2529
2530 ROSE_ASSERT(funcType->get_argument_list() != NULL);
2531 }
2532
2533 if (typeInTable == nullptr)
2534 {
2535 ASSERT_not_null(funcType);
2536 fTable->insert_function_type(typeName,funcType);
2537 }
2538 else
2539 {
2540 // DQ (12/3/2011): Added this case to support reuse of function types (not handled by the createType functions).
2541 // Delete the one generated so that we could form the mangled name.
2542 ASSERT_require(typeInTable != funcType);
2543 delete funcType;
2544
2545 // Return the one from the global type table.
2546 funcType = isSgMemberFunctionType(typeInTable);
2547 ASSERT_not_null(funcType);
2548 }
2549
2550 return funcType;
2551 }
2552
2553
2554// DQ (1/4/2009): Need to finish this!!!
2555//-----------------------------------------------
2556// build member function type,
2557//
2558// insert into symbol table when not duplicated
2560SageBuilder::buildMemberFunctionType(SgType* return_type, SgFunctionParameterTypeList* typeList, SgScopeStatement * struct_name, unsigned int mfunc_specifier)
2561 {
2562 // This function has to first build a version of the SgMemberFunctionType so that it can generate a mangled name.
2563 // If the mangled name can be use to lookup a SgMemberFunctionType then the "just built" SgMemberFunctionType
2564 // is deleted and the one from the global function type table is returned. This fixes a lot of subtle C++
2565 // specific issues with the build interface and it's use with the newer EDG 4.3 connection to ROSE.
2566
2567 ROSE_ASSERT(return_type != NULL);
2568
2569 // SgMemberFunctionType (SgType *return_type=NULL, bool has_ellipses=true, SgClassDefinition *struct_name=NULL, unsigned int mfunc_specifier=0)
2570 // SgMemberFunctionType * funcType = new SgMemberFunctionType(return_type, false);
2571
2572 ROSE_ASSERT(struct_name != NULL);
2573
2574#if 0
2575 printf("In buildMemberFunctionType():\n");
2576 printf(" - struct_name = %p (%s)\n", struct_name, struct_name->class_name().c_str());
2577#endif
2578
2579#if 0
2580 // DQ (1/9/2020): Unclear why this function is not using the ref_qualifiers.
2581 printf ("SageBuilder::buildMemberFunctionType(SgType*,SgFunctionParameterTypeList*,SgScopeStatement*,int,int): This function does not use the input ref_qualifiers = %x \n",ref_qualifiers);
2582 printf (" --- mfunc_specifier = %d ref_qualifiers = %d \n",mfunc_specifier,ref_qualifiers);
2583#endif
2584
2585#if 0
2586 printf ("Exiting as a test! \n");
2587 ROSE_ABORT();
2588#endif
2589
2590 ROSE_ASSERT(struct_name->get_parent() != NULL);
2591 // ROSE_ASSERT(struct_name->get_declaration() != NULL);
2592
2593#if 0
2594 printf("struct_name = %p ( %s )\n", struct_name, struct_name->class_name().c_str());
2595#endif
2596
2597 // SgDeclarationStatement* declaration = struct_name->get_declaration();
2598 SgClassDefinition* classDefinition = isSgClassDefinition(struct_name);
2599 SgDeclarationScope* decl_scope = isSgDeclarationScope(struct_name);
2600
2601 if (classDefinition == NULL && decl_scope == NULL)
2602 {
2603 printf ("Error: (classDefinition == NULL && decl_scope == NULL): struct_name = %p = %s name = %s \n",
2604 struct_name,struct_name->class_name().c_str(),SageInterface::get_name(struct_name).c_str());
2605 }
2606 ROSE_ASSERT(classDefinition != NULL || decl_scope != NULL);
2607
2608 SgDeclarationStatement* declaration = NULL;
2609 if (classDefinition != NULL)
2610 {
2611 declaration = classDefinition->get_declaration();
2612 }
2613 else if (decl_scope != NULL)
2614 {
2615 declaration = isSgDeclarationStatement(decl_scope->get_parent());
2616 }
2617 else
2618 {
2619 ROSE_ABORT();
2620 }
2621
2622 ROSE_ASSERT(declaration != NULL);
2623
2624 if (typeList != NULL)
2625 {
2626#if 0
2627 SgTypePtrList & typeListArgs = typeList->get_arguments();
2628 for (SgTypePtrList::iterator i = typeListArgs.begin(); i != typeListArgs.end(); i++)
2629 {
2630 printf (" --- type argument = %p = %s \n",*i,(*i)->class_name().c_str());
2631 }
2632#endif
2633 }
2634 else
2635 {
2636 printf ("WARNING: typeList == NULL \n");
2637 }
2638
2639 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
2640 // SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(declaration);
2641 SgNonrealDecl * nrdecl = isSgNonrealDecl(declaration);
2642
2643 ROSE_ASSERT(classDeclaration != NULL || nrdecl != NULL);
2644
2645 SgMemberFunctionType* funcType = NULL;
2646
2647 // DQ (12/4/2011): Modified SgClassType to support template declarations (SgTemplateClassDeclaration now contains a type set to SgClassType.
2648 // The SgClassType has been modified (browdened) to support a SgDeclarationStatement instead of a SgClassDeclaration.
2649 // SgClassType* classType = classDeclaration->get_type();
2650 SgType* classType = NULL;
2651 if (classDeclaration != NULL)
2652 {
2653 classType = classDeclaration->get_type();
2654 }
2655 else if (decl_scope != NULL)
2656 {
2657 classType = nrdecl->get_type();
2658 }
2659 else
2660 {
2661 ROSE_ABORT();
2662 }
2663
2664 ROSE_ASSERT(classType != NULL);
2665
2666#if 0
2667 printf ("In buildMemberFunctionType(): Calling refactored function: buildMemberFunctionType(...,classType = %p,...) \n",classType);
2668#endif
2669
2670 // DQ (8/19/2012): This code has been refactored.
2671 funcType = buildMemberFunctionType(return_type,typeList,classType,mfunc_specifier);
2672
2673#if 0
2674 printf ("In buildMemberFunctionType(): DONE: Calling refactored function: buildMemberFunctionType(...,classType = %p,...) \n",classType);
2675#endif
2676
2677 return funcType;
2678 }
2679
2680
2683 {
2684 ROSE_ASSERT(base_type != NULL);
2685
2686 ROSE_ASSERT(classType != NULL);
2687 SgPointerMemberType* pointerToMemberType = new SgPointerMemberType(base_type,classType);
2688 return pointerToMemberType;
2689
2690 }
2691
2692//----------------------------------------------------
2694SgType * SageBuilder::buildOpaqueType(std::string const name, SgScopeStatement * scope)
2695{
2696 // we require users to specify a target scope
2697 ASSERT_not_null(scope);
2698 SgTypedefDeclaration* type_decl = NULL;
2699 SgTypedefType* result = NULL;
2700
2701 // Liao and Greg Bronevetsky , 8/27/2009
2702 // patch up the symbol
2703 // and avoid duplicated creation
2704 // TODO a function like fixTypeDeclaration() (similar to SageInterface::fixVariableDeclaration()) for this
2705 SgTypedefSymbol* type_symbol = scope->lookup_typedef_symbol(name);
2706 if (type_symbol == NULL)
2707 {
2708 type_decl = new SgTypedefDeclaration(name,buildIntType(),NULL, NULL, NULL);
2709 ASSERT_not_null(type_decl);
2710
2711 type_decl->set_scope(scope); // PP (05/29/25): set the scope of the decl
2712
2713 // DQ (2/27/2018): Add this call here to reflect change to the constructor semantics.
2714 type_decl->set_type(SgTypedefType::createType(type_decl));
2715
2716 type_symbol = new SgTypedefSymbol(type_decl);
2717 ROSE_ASSERT(type_symbol);
2718 SgName n = name;
2719
2720 // DQ (5/21/2013): The symbol table should only be accessed through the SgScopeStatement interface.
2721 scope->insert_symbol(n,type_symbol);
2722
2723 type_decl->set_firstNondefiningDeclaration (type_decl);
2725 prependStatement(type_decl,scope);
2726 // Hide it from unparser
2727 Sg_File_Info* file_info = type_decl->get_file_info();
2728 file_info->unsetOutputInCodeGeneration ();
2729 result = new SgTypedefType(type_decl); // QUESTION: PP: why do not we return type_decl->get_type()?
2730 }
2731 else
2732 {
2733 type_decl = type_symbol->get_declaration();
2734 result = type_decl->get_type();
2735 }
2736 ASSERT_not_null(result);
2737 return result;
2738}
2739
2740
2741//----------------- function type------------
2742// same function declarations (defining or nondefining) should share the same function type!
2745 {
2746 ASSERT_not_null(argList);
2747
2749 SgFunctionType* func_type = buildFunctionType(return_type, typeList);
2750
2751 if (func_type->get_argument_list() != typeList)
2752 {
2753 delete typeList;
2754 typeList = NULL;
2755 }
2756
2757 return func_type;
2758 }
2759
2760void
2761checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope ( SgDeclarationStatement* func, SgScopeStatement* scope )
2762 {
2763 // DQ (12/14/2011): We need the parent to be set so that we can call some of the test functions
2764 // (e.g assert that get_class_scope() for member functions). So we set the parent to the scope
2765 // by default and see if this will work, else we could disable to assertion that the parent is
2766 // non-null in the get_class_scope() member function.
2767
2768 if (isSgMemberFunctionDeclaration(func) != NULL)
2769 {
2770#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
2771 printf ("WARNING: setting parent of function to match scope by default \n");
2772#endif
2773 func->set_parent(scope);
2774
2775 ROSE_ASSERT(scope != NULL);
2776
2777 if (isSgTemplateInstantiationMemberFunctionDecl(func) != NULL)
2778 {
2779 // DQ (12/14/2011): We should not have a member function template instantiation in a template class definition.
2780
2781 // DQ (8/25/2014): Un-Commented out to revert to previous working state.
2782 // DQ (8/25/2014): Commented out to test new logic at base of isTemplateDeclaration(a_routine_ptr).
2783 // DQ (8/25/2014): Un-Commented out to revert to previous working state.
2784 // DQ (8/25/2014): Allow non-template functions in a template class declaration (see test2014_161.C).
2785#if !ENFORCE_NO_FUNCTION_TEMPLATE_DECLARATIONS_IN_TEMPLATE_CLASS_INSTANTIATIONS
2786 // 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");
2787#endif
2788 }
2789 }
2790 else
2791 {
2792 if (isSgTemplateFunctionDeclaration(func) != NULL)
2793 {
2794 if (isSgTemplateInstantiationMemberFunctionDecl(func) != NULL)
2795 {
2796 ROSE_ASSERT(isSgTemplateClassDefinition(scope) != NULL);
2797 }
2798 }
2799 }
2800 }
2801
2802//----------------- function declaration------------
2803// considering
2804// 1. fresh building
2805// 2. secondary building after another nondefining functiondeclaration
2806// 3. secondary building after another defining function declaration
2807// 4. fortran ?
2808template <class actualFunction>
2809actualFunction*
2810SageBuilder::buildNondefiningFunctionDeclaration_T (
2811 const SgName & XXX_name, SgType* return_type, SgFunctionParameterList * paralist, bool isMemberFunction,
2812 SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags,
2813 SgTemplateArgumentPtrList* templateArgumentsList, SgTemplateParameterPtrList* templateParameterList,
2815) {
2816 // DQ (11/25/2011): This function has been modified to work when used with a SgTemplateFunctionDeclaration as a template argument.
2817 // It was originally designed to work with only SgFunctionDeclaration and SgMemberFunctionDeclaration, it now works with these
2818 // plus SgTemplateFunctionDeclaration and SgTemplateMemberonDeclaration IR nodes. This is part of providing new support for template
2819 // declarations in the AST and a general update of this function to support this expanded use.
2820
2821 // 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.
2822
2823 // argument verification
2824 if (scope == nullptr)
2825 {
2827 }
2828 ASSERT_not_null(scope);
2829
2830 if (XXX_name.is_null() == true)
2831 {
2832 // DQ (4/2/2013): This case is generated for test2013_86.C.
2833 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");
2834 }
2835
2836 SgName nameWithoutTemplateArguments = XXX_name;
2837 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
2838
2839 bool buildTemplateInstantiation = ((VariantT)actualFunction::static_variant == V_SgTemplateInstantiationFunctionDecl || (VariantT)actualFunction::static_variant == V_SgTemplateInstantiationMemberFunctionDecl);
2840
2841 // DQ (8/7/2013): Added support for template declarations.
2842 bool buildTemplateDeclaration = ((VariantT)actualFunction::static_variant == V_SgTemplateFunctionDeclaration || (VariantT)actualFunction::static_variant == V_SgTemplateMemberFunctionDeclaration);
2843
2844 // DQ (8/7/2013): Added support for template declarations (need to handle template names overloaded on template parameters).
2845 // We want to use the template arguments in the symbol table lookup, but not in the name generation.
2846 if (buildTemplateInstantiation == true)
2847 {
2848 ASSERT_not_null(templateArgumentsList);
2849 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
2850 }
2851
2852 // this function is also called when building a function reference before the function declaration exists. So, skip the check
2853 if (nameWithTemplateArguments.is_null() == true)
2854 {
2855 // DQ (3/25/2017): Modified to use message logging.
2856 // DQ (4/2/2013): This case is generated for test2013_86.C.
2857 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");
2858 }
2859
2860 if (nameWithoutTemplateArguments.is_null() == true)
2861 {
2862 // DQ (3/25/2017): Modified to use message logging.
2863 // DQ (4/2/2013): This case is generated for test2013_86.C.
2864 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");
2865 }
2866
2867 ASSERT_not_null(return_type);
2868 ASSERT_not_null(paralist);
2869
2870 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
2871 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
2872 if (SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == true)
2873 {
2874#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
2875 printf ("Warning: In buildNondefiningFunctionDeclaration_T(): nameWithoutTemplateArguments = %s nameWithTemplateArguments = %s \n",nameWithoutTemplateArguments.str(),nameWithTemplateArguments.str());
2876#endif
2877 }
2878 // DQ (7/27/2012): There are reasons why this can fail: e.g. for functions with names such as:
2879 // "operator std::auto_ptr_ref<_Tp1>" which is a user defined conversion operator to one class from another.
2880
2881 // tentatively build a function type, since it is shared
2882 // by all prototypes and defining declarations of a same function!
2883
2884 SgFunctionType* func_type = nullptr;
2885 if (isMemberFunction == true)
2886 {
2888 func_type = buildMemberFunctionType(return_type,typeList,scope, functionConstVolatileFlags);
2889 }
2890 else
2891 {
2892 func_type = buildFunctionType(return_type,paralist);
2893 }
2894
2895 ASSERT_not_null(func_type);
2896
2897 // function declaration
2898 actualFunction* func = nullptr;
2899
2900 // search before using the function type to create the function declaration
2901 // TODO only search current scope or all ancestor scope?? (DQ: Only current scope!)
2902 // We don't have lookup_member_function_symbol yet
2903
2904 // DQ (12/27/2011): Under the new design we can make the symbol type SgFunctionSymbol instead of the less specific SgSymbol.
2905 // DQ (11/25/2011): We want to add the support for template function declarations,
2906 // so this should be a SgSymbol so that we can have it be either a SgFunctionSymbol
2907 // or a SgTemplateSymbol.
2908 SgFunctionSymbol* func_symbol = NULL;
2909
2910 if (scope != NULL)
2911 {
2912 // DQ (3/13/2012): Experiment with new function to support only associating the right type of symbol with the
2913 // function being built. I don't think I like the design of this interface, but we might change that later.
2914
2915 // 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.
2916 func_symbol = scope->find_symbol_by_type_of_function<actualFunction>(nameWithTemplateArguments,func_type,templateParameterList,templateArgumentsList);
2917
2918#if 0 // DBG1
2919 printf ("In buildNondefiningFunctionDeclaration_T(): func_symbol from scope->find_symbol_by_type_of_function<actualFunction>(name = %s) = %p \n",nameWithTemplateArguments.str(),func_symbol);
2920 if (func_symbol != NULL) {
2921 printf ("In buildNondefiningFunctionDeclaration_T(): func_symbol->get_declaration() = %p \n", func_symbol->get_declaration());
2922 }
2923#endif /* DBG1 */
2924
2925 // If not a proper function (or instantiated template function), then check for a template function declaration.
2926 if (func_symbol == NULL)
2927 {
2928 // Note that a template function does not have a function type (just a name).
2929 ROSE_ASSERT(func_type != NULL);
2930 }
2931 }
2932
2933 // DQ (3/13/2012): I want to introduce error checking on the symbol matching the template parameter.
2934 if (func_symbol != NULL)
2935 {
2936 switch((VariantT)actualFunction::static_variant)
2937 {
2938 case V_SgFunctionDeclaration:
2939 case V_SgProcedureHeaderStatement:
2940 case V_SgTemplateInstantiationFunctionDecl:
2941 {
2942 ROSE_ASSERT(isSgFunctionSymbol(func_symbol) != NULL);
2943 break;
2944 }
2945 case V_SgMemberFunctionDeclaration:
2946 case V_SgTemplateInstantiationMemberFunctionDecl:
2947 {
2948 ROSE_ASSERT(isSgMemberFunctionSymbol(func_symbol) != NULL);
2949 break;
2950 }
2951 case V_SgTemplateFunctionDeclaration:
2952 {
2953 ROSE_ASSERT(isSgTemplateFunctionSymbol(func_symbol) != NULL);
2954 break;
2955 }
2956 case V_SgTemplateMemberFunctionDeclaration:
2957 {
2958 ROSE_ASSERT(isSgTemplateMemberFunctionSymbol(func_symbol) != NULL);
2959 break;
2960 }
2961
2962 default:
2963 {
2964 printf ("default reach in buildNondefiningFunctionDeclaration_T(): variantT(actualFunction::static_variant) = %d \n",actualFunction::static_variant);
2965 ROSE_ABORT();
2966 }
2967 }
2968
2969 // TV (2/5/14): Found symbol might come from another file, in this case we need to insert it in the current scope.
2970 // Can only happen when scope is a global scope
2971 ROSE_ASSERT(scope != NULL);
2972 if ( isSgGlobal(scope) != NULL
2973 && scope != func_symbol->get_scope()
2974 && !SageInterface::isAncestor(scope, func_symbol->get_scope())
2975 && !scope->symbol_exists(nameWithTemplateArguments, func_symbol) )
2976 {
2977 scope->insert_symbol(nameWithTemplateArguments, func_symbol);
2978 }
2979 }
2980
2981 if (func_symbol == NULL)
2982 {
2983 func = new actualFunction (nameWithTemplateArguments,func_type,NULL);
2984 ROSE_ASSERT(func != NULL);
2985
2986 // Storage modifier (esp. static) must be set before inserting symbol
2987 func->get_declarationModifier().get_storageModifier().set_modifier(sm);
2988
2989 // DQ (5/1/2012): This should always be true.
2990 ROSE_ASSERT(func->get_file_info() == NULL);
2991
2992 // DQ (12/14/2011): Moved this from lower in this function.
2993 func->set_scope(scope);
2994
2995 // DQ (12/15/2011): Added test.
2996 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(func,scope);
2997
2998 // This fails below for a SgTemplateFunctionDeclaration, so test it here.
2999 ROSE_ASSERT(func->get_parameterList() != NULL);
3000
3001 // NOTE: we want to allow the input scope to be NULL (and even the SageBuilder::topScopeStack() == NULL)
3002 // so that function can be built bottom up style. However this means that the symbol tables in the
3003 // scope of the returned function declaration will have to be setup separately.
3004 if (scope != NULL)
3005 {
3006 // function symbol table
3007 if (isSgMemberFunctionDeclaration(func))
3008 {
3009 // DQ (11/23/2011): This change allows this to compile for where SgTemplateFunctionDeclarations are used. I have
3010 // not decided if template declarations should cause symbols to be generated for functions and member functions.
3011 // func_symbol = new SgMemberFunctionSymbol(func);
3012 if (isSgTemplateMemberFunctionDeclaration(func) != NULL)
3013 func_symbol = new SgTemplateMemberFunctionSymbol(isSgTemplateMemberFunctionDeclaration(func));
3014 else
3015 {
3016 SgMemberFunctionDeclaration* memberFunctionDeclaration = isSgMemberFunctionDeclaration(func);
3017 ROSE_ASSERT(memberFunctionDeclaration != NULL);
3018 func_symbol = new SgMemberFunctionSymbol(memberFunctionDeclaration);
3019 }
3020
3021 ROSE_ASSERT(func_symbol != NULL);
3022 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
3023 }
3024 else
3025 {
3026 // if (isSgFunctionDeclaration(func))
3027 if (isSgTemplateFunctionDeclaration(func))
3028 {
3029 // How should we handled template functions in the symbol table???
3030 // DQ (11/24/2011): After some thought, I think that template declarations for function are more template declarations
3031 // than functions. So all template function declarations will be handled as SgTemplateSymbols and not SgFunctionSymbols.mplate function declarations.
3032 SgTemplateFunctionDeclaration* templatedeclaration = isSgTemplateFunctionDeclaration(func);
3033 ROSE_ASSERT(templatedeclaration != NULL);
3034 SgTemplateFunctionSymbol* template_symbol = new SgTemplateFunctionSymbol(templatedeclaration);
3035 ROSE_ASSERT(template_symbol != NULL);
3036 ROSE_ASSERT(template_symbol->get_symbol_basis() != NULL);
3037 func_symbol = template_symbol;
3038 }
3039 else
3040 {
3041 func_symbol = new SgFunctionSymbol(isSgFunctionDeclaration(func));
3042 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
3043 }
3044 }
3045
3046 ROSE_ASSERT(func_symbol != NULL);
3047 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
3048 scope->insert_symbol(nameWithTemplateArguments, func_symbol);
3049
3050 // DQ (3/8/2012): Added assertion.
3051 ROSE_ASSERT(func->get_symbol_from_symbol_table() != NULL);
3052
3053 if (isSgFunctionDeclaration(func) == NULL)
3054 {
3055 // DQ (12/18/2011): If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3056 // DQ (8/12/2013): Added template parameter list.
3057 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3058 // In this case these are unavailable from this point.
3059 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3060 }
3061
3062 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3063 // In this case these are unavailable from this point.
3064 // DQ (11/25/2011): Added support for template functions.
3065 // DQ (2/26/2009): uncommented assertion.
3066 // Did not pass for member function? Should we have used the mangled name?
3067 ROSE_ASSERT(buildTemplateDeclaration == false || templateParameterList != NULL);
3068
3069 // DQ (8/13/2013): We need to test for function symbols (which will include member function symbols),
3070 // template functions and template member functions. Each must be tested for seperately because template
3071 // functions and template member functions are not connected to derivation which non-template functions
3072 // and non-template member functions are connected through derivation.
3073 ROSE_ASSERT(scope->lookup_function_symbol(nameWithTemplateArguments) != NULL ||
3074 scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL ||
3075 scope->lookup_template_member_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3076
3077#if BUILDER_MAKE_REDUNDANT_CALLS_TO_SYMBOL_TABLE_LOOKUP
3078 // if (scope->lookup_function_symbol(name) == NULL || scope->lookup_template_symbol(name) != NULL)
3079 // if (scope->lookup_function_symbol(nameWithTemplateArguments) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments) != NULL)
3080 // if (scope->lookup_function_symbol(nameWithTemplateArguments) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments,NULL,NULL) != NULL)
3081 if (scope->lookup_function_symbol(nameWithTemplateArguments,templateArgumentList) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments,templateParameterList,NULL) != NULL)
3082 {
3083 // Make sure this is a template function declaration...
3084 printf ("Need to make sure this is a template function declaration... \n");
3085 }
3086#endif
3087 }
3088
3089 // DQ (12/14/2011): Added test.
3090 ROSE_ASSERT(func->get_scope() != NULL);
3091
3092 if (isSgFunctionDeclaration(func) == NULL)
3093 {
3094 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3095
3096 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3097 // In this case these are unavailable from this point.
3098 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3099 }
3100 func->set_firstNondefiningDeclaration(func);
3101 func->set_definingDeclaration(NULL);
3102
3103 // DQ (5/8/2016): We need to test the first defining declaration that we used.
3104 ROSE_ASSERT(func->get_firstNondefiningDeclaration() == func);
3105
3106 ROSE_ASSERT(func->get_definingDeclaration() == NULL);
3107
3108 // DQ (12/14/2011): Error checking
3109 SgTemplateInstantiationMemberFunctionDecl* testMemberDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
3110 if (testMemberDecl != NULL)
3111 {
3112 ROSE_ASSERT(testMemberDecl->get_scope() != NULL);
3113 ROSE_ASSERT(testMemberDecl->get_class_scope() != NULL);
3114 ROSE_ASSERT(testMemberDecl->get_associatedClassDeclaration() != NULL);
3115 }
3116 }
3117 else
3118 {
3119 ROSE_ASSERT(func_symbol != NULL);
3120
3121 ROSE_ASSERT(scope != NULL);
3122
3123 // 2nd, or 3rd... prototype declaration
3124 // reuse function type, function symbol of previous declaration
3125
3126 // std::cout<<"debug:SageBuilder.C: 267: "<<"found func_symbol!"<<std::endl;
3127 // delete (func_type-> get_argument_list ());
3128 // delete func_type; // bug 189
3129 SgNode* associatedSymbolBasis = func_symbol->get_symbol_basis();
3130 ROSE_ASSERT(associatedSymbolBasis != NULL);
3131
3132 SgDeclarationStatement* associatedDeclaration = isSgDeclarationStatement(associatedSymbolBasis);
3133 ROSE_ASSERT(associatedDeclaration != NULL);
3134 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(associatedDeclaration);
3135 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(associatedDeclaration);
3136
3137 if (functionDeclaration != NULL)
3138 {
3139 func_type = functionDeclaration->get_type();
3140 }
3141 else
3142 {
3143 if (templateFunctionDeclaration != NULL)
3144 {
3145 // DQ (5/8/2016): I think this code is never executed (because a templateFunctionDeclaration
3146 // is derived from a SgFunctionDeclaration, in the newer design (a few years ago)).
3147
3148 printf ("This code should not be reachable! \n");
3149 ROSE_ABORT();
3150
3151 func_type = templateFunctionDeclaration->get_type();
3152 }
3153 else
3154 {
3155 printf ("Error: associatedDeclaration = %p = %s \n",associatedDeclaration,associatedDeclaration->class_name().c_str());
3156 ROSE_ABORT();
3157 }
3158 }
3159 ROSE_ASSERT(func_type != NULL);
3160
3161 func = new actualFunction(nameWithTemplateArguments,func_type,NULL);
3162 ROSE_ASSERT(func != NULL);
3163
3164#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3165 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as translformations.
3166 // This is too early a point to test since the source position has not been set for func yet.
3167 // detectTransformations_local(func);
3168#endif
3169
3170 // DQ (12/14/2011): Moved this up from below.
3171 func->set_scope(scope);
3172
3173 // DQ (3/8/2012): Added assertion.
3174 ROSE_ASSERT(func->get_symbol_from_symbol_table() == NULL);
3175
3176 // DQ (12/15/2011): Added test.
3177 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(func,scope);
3178
3179 // we don't care if it is member function or function here for a pointer
3180 SgDeclarationStatement* prevDecl = NULL;
3181
3182 // This does not handle the case of a template function declaration.
3183 if (functionDeclaration != NULL)
3184 {
3185 prevDecl = functionDeclaration;
3186 }
3187 else
3188 {
3189 ROSE_ASSERT(templateFunctionDeclaration != NULL);
3190 prevDecl = templateFunctionDeclaration;
3191 }
3192
3193 ROSE_ASSERT(prevDecl != NULL);
3194
3195 SgFunctionSymbol *function_symbol = isSgFunctionSymbol(func_symbol);
3196 if (prevDecl == prevDecl->get_definingDeclaration())
3197 {
3198 // The symbol points to a defining declaration and now that we have added a non-defining
3199 // declaration we should have the symbol point to the new non-defining declaration.
3200 printf ("WARNING: Switching declaration in functionSymbol to point to the non-defining declaration \n");
3201 function_symbol->set_declaration(isSgFunctionDeclaration(func));
3202 ROSE_ASSERT(function_symbol->get_declaration() != NULL);
3203 }
3204
3205 // If this is the first non-defining declaration then set the associated data member.
3206 SgDeclarationStatement* nondefiningDeclaration = prevDecl->get_firstNondefiningDeclaration();
3207 if (nondefiningDeclaration == NULL)
3208 {
3209 nondefiningDeclaration = func;
3210 }
3211
3212 ROSE_ASSERT(nondefiningDeclaration != NULL);
3213 ROSE_ASSERT(func != NULL);
3214 ROSE_ASSERT(prevDecl != NULL);
3215
3216 func->set_firstNondefiningDeclaration(nondefiningDeclaration);
3217 func->set_definingDeclaration(prevDecl->get_definingDeclaration());
3218
3219 ROSE_ASSERT(nondefiningDeclaration->get_symbol_from_symbol_table() != NULL);
3220 ROSE_ASSERT(func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3221
3222 // DQ (3/8/2012): If this is the redundant function prototype then we have to look
3223 // at the first defining declaration since only it will have an associated symbol.
3224 if (func->get_symbol_from_symbol_table() == NULL)
3225 {
3226 ROSE_ASSERT(nondefiningDeclaration != NULL);
3227 ROSE_ASSERT(func->get_firstNondefiningDeclaration() == nondefiningDeclaration);
3228 }
3229
3230 // DQ (12/14/2011): Added test.
3231 ROSE_ASSERT(scope != NULL);
3232 ROSE_ASSERT(func->get_scope() != NULL);
3233 ROSE_ASSERT(func->get_scope() == scope);
3234
3235 // DQ (12/14/2011): Error checking
3236 SgTemplateInstantiationMemberFunctionDecl* testMemberDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
3237 if (testMemberDecl != NULL)
3238 {
3239 ROSE_ASSERT(testMemberDecl->get_scope() != NULL);
3240 ROSE_ASSERT(testMemberDecl->get_associatedClassDeclaration() != NULL);
3241 }
3242
3243 // DQ (12/18/2011): Testing to debug generation of wrong kind of declaration (symbol not found in correct scope or ...).
3244 if (isSgFunctionDeclaration(func) == NULL)
3245 {
3246 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3247 // DQ (8/12/2013): Added template parameter list.
3248 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3249 // In this case these are unavailable from this point.
3250 // DQ (12/18/2011): This fails because the first use of the function causes a non-defining function declaration
3251 // to be built and it is built as a template instantiation instead of a template declaration. So the symbol for
3252 // the non-defining declaration is put into the correct scope, but as a SgMemberFunctionSymbol instead of as a
3253 // SgTemplateSymbol (if it were built as a SgTemplateMemberFunctionDeclaration). So of course we can't find it
3254 // using lookup_template_symbol().
3255 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3256 }
3257 }
3258
3259 ROSE_ASSERT(func != NULL);
3260
3261 ROSE_ASSERT(func->get_file_info() == NULL);
3262
3263 // DQ (3/8/2012): Added assertion.
3264 ROSE_ASSERT(func->get_firstNondefiningDeclaration() != NULL);
3265 ROSE_ASSERT(func_symbol != NULL);
3266 ROSE_ASSERT(func_symbol->get_symbol_basis() == func->get_firstNondefiningDeclaration());
3267 ROSE_ASSERT(func->get_symbol_from_symbol_table() != NULL || func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3268
3269 // DQ (2/24/2009): Delete the old parameter list build by the actualFunction (template argument) constructor.
3270 ROSE_ASSERT(func->get_parameterList() != NULL);
3271 delete func->get_parameterList();
3272 func->set_parameterList(NULL);
3273
3274 // DQ (9/16/2012): Setup up the template arguments and the parents of the template arguments.
3275 if (buildTemplateInstantiation == true)
3276 {
3277 setTemplateArgumentsInDeclaration(func,templateArgumentsList);
3278 }
3279
3280 // DQ (8/10/2013): Setup the template parameters if this is a template declaration.
3281 if (buildTemplateDeclaration == true)
3282 {
3283 setTemplateParametersInDeclaration(func,templateParameterList);
3284
3285 // DQ (8/13/2013): Adding test of template parameter lists.
3286 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(func);
3287 ROSE_ASSERT(templateFunctionDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateFunctionDeclaration->get_templateParameters().size()));
3288
3289 SgTemplateMemberFunctionDeclaration* templateMemberFunctionDeclaration = isSgTemplateMemberFunctionDeclaration(func);
3290 ROSE_ASSERT(templateMemberFunctionDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateMemberFunctionDeclaration->get_templateParameters().size()));
3291 }
3292
3293 // parameter list
3294 // DQ (11/23/2011): This change allows this to compile for where SgTemplateFunctionDeclarations are used.
3295 setParameterList(func, paralist);
3296
3297 for (SgInitializedName* i_name : paralist->get_args())
3298 {
3299 i_name->set_scope(scope);
3300 }
3301
3302#if 0
3303 // DQ (7/12/2021): Debugging where nodes in the outliner are being marked as transformations (SgCastExpressions should not be marked as transformations).
3304 printf ("In buildNondefiningFunctionDeclaration_T(): setting the source position information (calling setTransformation()) \n");
3305#endif
3306
3307 // DQ (5/2/2012): Test this to make sure we have SgInitializedNames set properly.
3309
3310#if 0
3311 // DQ (7/12/2021): Debugging where nodes in the outliner are being marked as transformations (SgCastExpressions should not be marked as transformations).
3312 printf ("In buildNondefiningFunctionDeclaration_T(): DONE: setting the source position information (calling setTransformation()) \n");
3313#endif
3314
3315#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3316 // Liao 11/21/2012: we should assert no transformation only when the current model is NOT transformation
3317 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
3318 {
3319 detectTransformations_local(paralist);
3320 }
3321#endif
3322
3323 ASSERT_not_null(scope);
3324 ASSERT_not_null(func->get_scope());
3325 ASSERT_require(func->get_scope() == scope);
3326
3327 // DQ (1/5/2009): This is not always true (should likely use SageBuilder::topScopeStack() instead)
3328 if (SageBuilder::topScopeStack() != nullptr) // This comparison only makes sense when topScopeStack() returns non-NULL value
3329 {
3330 // since stack scope is totally optional in SageBuilder.
3331 if (scope != SageBuilder::topScopeStack())
3332 {
3333#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
3334 printf ("Warning: SageBuilder::buildNondefiningFunctionDeclaration_T(): scope parameter may not be the same as the topScopeStack() (e.g. for member functions) \n");
3335#endif
3336 }
3337 }
3338
3339 func->set_parent(scope);
3340 ASSERT_not_null(func->get_firstNondefiningDeclaration());
3341
3342 // mark as a forward declartion
3343 func->setForward();
3344
3345 ROSE_ASSERT(func->get_file_info() == NULL);
3346
3347 // set File_Info as transformation generated or front end generated
3349
3350 ROSE_ASSERT(func->get_file_info() != NULL);
3351
3352#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3353 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3354 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
3355 {
3356 detectTransformations_local(func);
3357 }
3358#endif
3359
3360 // printf ("In SageBuilder::buildNondefiningFunctionDeclaration_T(): generated function func = %p \n",func);
3361
3362 // Liao 12/2/2010, special handling for Fortran functions and subroutines
3363 if ((SageInterface::is_Fortran_language() == true) && (getEnclosingFileNode(scope)->get_outputLanguage() == SgFile::e_Fortran_language))
3364 {
3365 SgProcedureHeaderStatement * f_func = isSgProcedureHeaderStatement(func);
3366 ROSE_ASSERT (f_func != NULL);
3367 if (return_type == buildVoidType())
3369 else
3370 f_func->set_subprogram_kind(SgProcedureHeaderStatement::e_function_subprogram_kind);
3371
3372 // hide it from the unparser since fortran prototype func declaration is internally used by ROSE AST
3375 ROSE_ASSERT(f_func->get_startOfConstruct()->isOutputInCodeGeneration() == false);
3376 ROSE_ASSERT(f_func->get_endOfConstruct()->isOutputInCodeGeneration() == false);
3377 }
3378
3379 // DQ (12/11/2011): Added new test.
3380 ROSE_ASSERT(func->get_firstNondefiningDeclaration() != NULL);
3381 SgSymbol* symbol_from_first_nondefining_function = func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table();
3382 ROSE_ASSERT(symbol_from_first_nondefining_function != NULL);
3383
3384 // DQ (12/11/2011): Note that this may be false when func is not the first nondefining declaration.
3385 if (func != func->get_firstNondefiningDeclaration())
3386 {
3387 SgSymbol* symbol_from_nondefining_function = func->get_symbol_from_symbol_table();
3388 ROSE_ASSERT(symbol_from_nondefining_function == NULL);
3389 }
3390
3391 // DQ (12/18/2011): Testing to debug generation of wrong kind of declaration (symbol not found in correct scope or ...).
3392 if (isSgFunctionDeclaration(func) == NULL)
3393 {
3394 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3395 // DQ (8/12/2013): Make sure we use the template parameters and the template arguments that are available.
3396 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3397 // In this case these are unavailable from this point.
3398 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3399 }
3400
3401 // 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)).
3402 setTemplateNameInTemplateInstantiations(func,nameWithoutTemplateArguments);
3403
3404#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3405 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3406 if (SourcePositionClassificationMode !=e_sourcePositionTransformation)
3407 {
3408 detectTransformations_local(func);
3409 }
3410#endif
3411
3412 // DQ (12/11/2012): Force the two different ways that this can be set to match (we want consistancy).
3413 if (functionConstVolatileFlags & SgMemberFunctionType::e_restrict)
3414 {
3415 func->get_declarationModifier().get_typeModifier().setRestrict();
3416 }
3417
3418 // DQ (8/19/2013): Added assertion that is tested and which fails for test_3 of the RoseExample_tests directory (in edgRose.C).
3419 // This fails for everything.... not sure why...
3420
3421 // DQ (4/16/2015): This is replaced with a better implementation.
3422 // Make sure the isModified boolean is clear for all newly-parsed nodes.
3423 unsetNodesMarkedAsModified(func);
3424
3425 ROSE_ASSERT(paralist->get_parent() != NULL);
3426 return func;
3427 }
3428
3429
3433{
3434 ROSE_ASSERT(funcdecl!=NULL);
3435 SgName name=funcdecl->get_name();
3436 SgFunctionType * funcType = funcdecl->get_type();
3437 SgType* return_type = funcType->get_return_type();
3438 SgFunctionParameterList* paralist = deepCopy<SgFunctionParameterList>(funcdecl->get_parameterList());
3439
3440 // make sure the function has consistent function type based on its return type and parameter list
3441 SgFunctionType * ref_funcType= findFunctionType (return_type, funcType->get_argument_list());
3442 ROSE_ASSERT(funcType== ref_funcType);
3443
3444 // buildNondefiningFunctionDeclaration() will check if a same function is created before by looking up function symbols.
3445 SgFunctionDeclaration* returnFunction = buildNondefiningFunctionDeclaration (name, return_type, paralist, scope, decoratorList, false, NULL);
3446
3447 returnFunction->set_linkage(funcdecl->get_linkage());
3448 if (funcdecl->get_declarationModifier().get_storageModifier().isExtern() == true)
3449 {
3450 returnFunction->get_declarationModifier().get_storageModifier().setExtern();
3451 }
3452
3453 ROSE_ASSERT (returnFunction->get_linkage() == funcdecl->get_linkage());
3454 ROSE_ASSERT (returnFunction->get_declarationModifier().get_storageModifier().isExtern() ==
3455 funcdecl->get_declarationModifier().get_storageModifier().isExtern());
3456
3457 ROSE_ASSERT(returnFunction->get_firstNondefiningDeclaration() != NULL);
3458 // Make sure that internal references are to the same file (else the symbol table information will not be consistent).
3459 if (scope != NULL)
3460 {
3461 ROSE_ASSERT(returnFunction->get_firstNondefiningDeclaration() != NULL);
3462 }
3463
3464 return returnFunction;
3465}
3466
3468SageBuilder::buildNondefiningFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList, SgStorageModifier::storage_modifier_enum sm)
3469 {
3470 SgFunctionDeclaration * result = NULL;
3471 if ((SageInterface::is_Fortran_language() == true) && (getEnclosingFileNode(scope)->get_outputLanguage() == SgFile::e_Fortran_language))
3472 {
3473 result = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, NULL, sm);
3474 }
3475 else
3476 {
3477 // 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).
3478 if (buildTemplateInstantiation == true)
3479 {
3480 result = buildNondefiningFunctionDeclaration_T <SgTemplateInstantiationFunctionDecl> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, templateArgumentsList, NULL, sm);
3481 }
3482 else
3483 {
3484 result = buildNondefiningFunctionDeclaration_T <SgFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, NULL, sm);
3485 }
3486 }
3487
3488 return result;
3489 }
3490
3491
3492// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficent).
3493// We need to decide if the SageBuilder API should include these sorts of functions.
3496 {
3497 unsigned int memberFunctionModifiers = 0;
3498 return buildNondefiningMemberFunctionDeclaration (name,return_type,paralist,scope,NULL,memberFunctionModifiers,false,NULL);
3499 }
3500
3501// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficient).
3502// We need to decide if the SageBuilder API should include these sorts of functions.
3505 {
3506 if (scope == NULL)
3507 {
3509 }
3510
3511 unsigned int memberFunctionModifiers = 0;
3513 SgMemberFunctionDeclaration* nondefining_decl = NULL;
3514 SgMemberFunctionType* member_func_type = buildMemberFunctionType(return_type,param_type_list, scope, memberFunctionModifiers);
3515 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgMemberFunctionDeclaration>(name,member_func_type,NULL,NULL);
3516 SgMemberFunctionSymbol* member_func_symbol = isSgMemberFunctionSymbol(func_symbol);
3517
3518 if (member_func_symbol != NULL)
3519 {
3520 nondefining_decl = member_func_symbol->get_declaration();
3521 }
3522 else
3523 {
3524 // each defining member function decl must have a non-defining counter part now. 11/27/2012, Liao
3525 nondefining_decl = buildNondefiningMemberFunctionDeclaration (name, return_type, paralist, scope,NULL, memberFunctionModifiers, false, NULL);
3526 }
3527 return buildDefiningMemberFunctionDeclaration (name,return_type,paralist,scope,NULL,false,memberFunctionModifiers,nondefining_decl,NULL);
3528 }
3529
3530
3531// SgTemplateFunctionDeclaration* SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList)
3532// SgTemplateFunctionDeclaration* SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateArgumentPtrList* templateArgumentsList)
3534SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateParameterPtrList* templateParameterList)
3535 {
3536 // DQ (8/15/2013): Note that we don't need template arguments because teplate functions can't support partial specialization.
3537
3538 // DQ (11/25/2011): Adding support for template declarations in the AST.
3539
3540 // DQ (8/7/2013): Added support for template function overloading using template parameters.
3541 SgTemplateFunctionDeclaration* result = buildNondefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, templateParameterList, SgStorageModifier::e_default);
3542
3543 // DQ (12/12/2011): Added test.
3544 ROSE_ASSERT(result != NULL);
3545 if (result->get_symbol_from_symbol_table() == NULL)
3546 {
3547 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3548 ROSE_ASSERT(result != result->get_firstNondefiningDeclaration());
3549 ROSE_ASSERT(result->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3550 }
3551
3552 // DQ (2/12/2015): Added assertions earlier before calling buildDefiningFunctionDeclaration_T<>().
3553 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3554
3555 return result;
3556 }
3557
3559SageBuilder::buildDefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateFunctionDeclaration* first_nondefining_declaration)
3560 {
3561 // DQ (12/1/2011): Adding support for template declarations in the AST.
3562
3563 // DQ (7/31/2013): Added assertions earlier before calling buildDefiningFunctionDeclaration_T<>().
3564 ROSE_ASSERT(first_nondefining_declaration != NULL);
3565 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() != NULL);
3566 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3567
3568 // template <class actualFunction> actualFunction * buildDefiningFunctionDeclaration_T (const SgName & name, SgType* return_type, SgFunctionParameterList * parlist, SgScopeStatement* scope=NULL, SgExprListExp* decoratorList = NULL);
3569 // SgTemplateFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ false, scope, decoratorList,functionConstVolatileFlags);
3570 // SgTemplateFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ false, scope, decoratorList, 0, first_nondefining_declaration);
3571 SgTemplateFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ false, scope, decoratorList, 0, first_nondefining_declaration, NULL);
3572
3573 return result;
3574 }
3575
3577SageBuilder::buildDefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList *paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, SgTemplateMemberFunctionDeclaration* first_nondefining_declaration)
3578 {
3579 // DQ (12/1/2011): Adding support for template declarations in the AST.
3580
3581 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3582
3583 SgTemplateMemberFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true, scope, decoratorList, functionConstVolatileFlags, first_nondefining_declaration, NULL);
3584 ROSE_ASSERT(result != NULL);
3585
3586 ROSE_ASSERT(result->get_definition() != NULL);
3587
3588 return result;
3589 }
3590
3593 SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList)
3594 {
3595 // This function builds either a SgMemberFunctionDeclaration (non-template; normal member function) or a SgTemplateInstantiationMemberFunctionDecl (template instantiation).
3596
3597 // DQ (11/27/2011): Added support for instations of template member functions.
3598 SgMemberFunctionDeclaration * result = NULL;
3599
3600 if (buildTemplateInstantiation == true)
3601 {
3602 // This is how we build an instantiation of a template (SgTemplateInstantiationMemberFunctionDecl).
3603 result = buildNondefiningFunctionDeclaration_T <SgTemplateInstantiationMemberFunctionDecl> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,templateArgumentsList,NULL, SgStorageModifier::e_default);
3604 }
3605 else
3606 {
3607 // This is a non-template instatiation (normal member function).
3608 result = buildNondefiningFunctionDeclaration_T <SgMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,NULL,NULL, SgStorageModifier::e_default);
3609 }
3610 ROSE_ASSERT(result != NULL);
3611
3612 // set definingdecl for SgCtorInitializerList
3614 ROSE_ASSERT(ctor != NULL);
3615
3616 // required in AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3617 ctor->set_definingDeclaration(ctor);
3619
3620 // DQ (1/4/2009): Error checking
3621 ROSE_ASSERT(result->get_associatedClassDeclaration() != NULL);
3622
3623 if (result->get_associatedClassDeclaration() == NULL)
3624 {
3625 printf ("Warning, must set the SgMemberFunctionDeclaration::associatedClassDeclaration \n");
3626
3627 ROSE_ASSERT(scope != NULL);
3628 SgClassDefinition* classDefinition = isSgClassDefinition(scope);
3629 ROSE_ASSERT(classDefinition != NULL);
3630 SgDeclarationStatement* associatedDeclaration = classDefinition->get_declaration();
3631 ROSE_ASSERT(associatedDeclaration != NULL);
3632 SgClassDeclaration* associatedClassDeclaration = isSgClassDeclaration(associatedDeclaration);
3633
3634 // DQ (1/4/2009): This needs to be set, checked in AstConsistencyTests.C!
3635 result->set_associatedClassDeclaration(associatedClassDeclaration);
3636 }
3637
3638 return result;
3639 }
3640
3641
3642// DQ (8/12/2013): This function needs to handle the SgTemplateParameterPtrList (since it is generating a template).
3643// It need not take a SgTemplateArgumentPtrList because template functions (including template member functions) can not support partial specialization.
3644// SgTemplateMemberFunctionDeclaration* SageBuilder::buildNondefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags)
3646SageBuilder::buildNondefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, SgTemplateParameterPtrList* templateParameterList)
3647 {
3648 // This function only builds template member function declarations.
3649
3650 SgTemplateMemberFunctionDeclaration * result = buildNondefiningFunctionDeclaration_T <SgTemplateMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,NULL,templateParameterList, SgStorageModifier::e_default);
3651
3652 // set definingdecl for SgCtorInitializerList
3653 ROSE_ASSERT(result != NULL);
3654
3655#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3656 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as translformations.
3658 {
3659 detectTransformations_local(result);
3660 }
3661#endif
3662
3663 // DQ (8/12/2013): Added template paremter list to call to get the function template symbol.
3664 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3665 // In this case these are unavailable from this point.
3666 SgSymbol* associatedSymbol = scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList);
3667 if (associatedSymbol == NULL)
3668 {
3669 printf ("ERROR: associatedSymbol == NULL \n");
3670 printf (" --- result = %p = %s \n",result,result->class_name().c_str());
3671 printf (" --- scope = %p = %s \n",scope,scope->class_name().c_str());
3672 printf (" --- name = %s \n",name.str());
3673 printf (" --- result->get_type() = %p = %s \n",result->get_type(),result->get_type()->class_name().c_str());
3674 printf (" --- result->get_type()->get_mangled() = %s \n",result->get_type()->get_mangled().str());
3675 }
3676 ROSE_ASSERT(associatedSymbol != NULL);
3677
3679 ROSE_ASSERT(ctor != NULL);
3680 // required ty AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3681 ctor->set_definingDeclaration(ctor);
3683
3684 // DQ (12/11/2011): Added new test (also at the base of buildNondefiningFunctionDeclaration_T<>() function).
3685 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3686 SgSymbol* symbol_from_first_nondefining_function = result->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table();
3687 ROSE_ASSERT(symbol_from_first_nondefining_function != NULL);
3688
3689 // DQ (12/11/2011): Note that this may be false when func is not the first nondefining declaration.
3690 if (result != result->get_firstNondefiningDeclaration())
3691 {
3692 SgSymbol* symbol_from_nondefining_function = result->get_symbol_from_symbol_table();
3693 ROSE_ASSERT(symbol_from_nondefining_function == NULL);
3694 }
3695
3696#if BUILDER_MAKE_REDUNDANT_CALLS_TO_SYMBOL_TABLE_LOOKUP
3697 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3698 // In this case these are unavailable from this point.
3699 if (scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList) == NULL)
3700 {
3701 printf ("Error: scope->lookup_template_member_function_symbol(name,result->get_type()) == NULL (investigate this) \n");
3702 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());
3703 scope->get_symbol_table()->print("Error: scope->lookup_template_member_function_symbol(name,result->get_type()) == NULL (investigate this)");
3704 }
3705#endif
3706 ROSE_ASSERT(scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList) != NULL);
3707
3708#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3709 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3711 {
3712 detectTransformations_local(result);
3713 }
3714#endif
3715
3716 return result;
3717 }
3718
3720SageBuilder::buildDefiningMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, unsigned int functionConstVolatileFlags, SgMemberFunctionDeclaration* first_nondefining_declaration, SgTemplateArgumentPtrList* templateArgumentsList)
3721 {
3722 // DQ (12/18/2011): Need to build a SgTemplateInstantiationMemberFunctionDecl when buildTemplateInstantiation == true
3723 SgMemberFunctionDeclaration * result = NULL;
3724 if (buildTemplateInstantiation == true)
3725 {
3726 SgTemplateInstantiationMemberFunctionDecl* templateInstantiationMemberFunctionDecl = isSgTemplateInstantiationMemberFunctionDecl(first_nondefining_declaration);
3727 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
3728
3729 // DQ (1/26/2013): Added test failing in buildDefiningFunctionDeclaration_T().
3730 {
3731 ROSE_ASSERT(templateArgumentsList != NULL);
3732 string nameWithoutTemplateArguments = name;
3733 string nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
3734 SgMemberFunctionType* func_type = isSgMemberFunctionType(first_nondefining_declaration->get_type());
3735 ROSE_ASSERT(func_type != NULL);
3736
3737 // DQ (8/7/2013): API change due to added support for template function overloading using template parameters.
3738 SgSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgTemplateInstantiationMemberFunctionDecl>(nameWithTemplateArguments,func_type,NULL,templateArgumentsList);
3739 if (func_symbol == NULL)
3740 {
3741 printf ("ERROR caught in SageBuilder::buildDefiningMemberFunctionDeclaration(): nameWithTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithTemplateArguments.c_str(),buildTemplateInstantiation ? "true:" : "false");
3742 printf ("ERROR caught in SageBuilder::buildDefiningMemberFunctionDeclaration(): func_symbol == NULL for first_nondefining_declaration = %p = %s and func_type = %p = %s \n",
3743 templateInstantiationMemberFunctionDecl,templateInstantiationMemberFunctionDecl->class_name().c_str(),func_type,func_type->class_name().c_str());
3744 }
3745 }
3746
3747 result = buildDefiningFunctionDeclaration_T <SgTemplateInstantiationMemberFunctionDecl> (name, return_type, paralist, /* isMemberFunction = */ true, scope, decoratorList, functionConstVolatileFlags, templateInstantiationMemberFunctionDecl, templateArgumentsList);
3748 ROSE_ASSERT(isSgTemplateInstantiationMemberFunctionDecl(result) != NULL);
3749 ROSE_ASSERT(isSgTemplateInstantiationMemberFunctionDecl(result)->get_templateName().is_null() == false);
3750 }
3751 else
3752 {
3753 ROSE_ASSERT(first_nondefining_declaration != NULL);
3754
3755 // DQ (12/27/20134): Added these to permit testing earlier than in the buildDefiningFunctionDeclaration_T() function.
3756 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() != NULL);
3757 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3758
3759 result = buildDefiningFunctionDeclaration_T <SgMemberFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,first_nondefining_declaration, NULL);
3760 }
3761
3762 ROSE_ASSERT(result != NULL);
3763
3764 // set definingdecl for SgCtorInitializerList
3766 ROSE_ASSERT(ctor != NULL);
3767
3768 // required ty AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3769 ctor->set_definingDeclaration(ctor);
3771
3772 // DQ (1/4/2009): Error checking
3773 ROSE_ASSERT(result->get_associatedClassDeclaration() != NULL);
3774
3775 return result;
3776 }
3777
3778
3779//----------------- defining function declaration------------
3780// a template builder for all kinds of defining SgFunctionDeclaration
3781// handle common chores for function type, symbol, paramter etc.
3782
3783template <class actualFunction>
3784actualFunction*
3785SageBuilder::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)
3786 {
3787 // Note that the semantics of this function now differs from that of the buildDefiningClassDeclaration().
3788 // We want to have the non-defining declaration already exist before calling this function.
3789 // We could still build a higher level function that built both together. Or we could provide two versions
3790 // named differently (from this one) and depricate this function...which I like much better.
3791
3792#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
3793 printf ("WARNING: This function for building defining function declarations has different semantics from that of the function to build defining class declarations. \n");
3794#endif
3795
3796 ASSERT_not_null(first_nondefining_declaration);
3797 ASSERT_require(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3798
3799 if (scope == nullptr)
3800 {
3802 }
3803
3804 ASSERT_require(XXX_name.is_null() == false);
3805 ASSERT_not_null(scope);
3806 ASSERT_not_null(return_type);
3807
3808 SgName nameWithoutTemplateArguments = XXX_name;
3809 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
3810
3811 bool buildTemplateInstantiation = ((VariantT)actualFunction::static_variant == V_SgTemplateInstantiationFunctionDecl || (VariantT)actualFunction::static_variant == V_SgTemplateInstantiationMemberFunctionDecl);
3812
3813 // DQ (8/7/2013): Added support for template declarations.
3814 bool buildTemplateDeclaration = ((VariantT)actualFunction::static_variant == V_SgTemplateFunctionDeclaration || (VariantT)actualFunction::static_variant == V_SgTemplateMemberFunctionDeclaration);
3815
3816 // DQ (8/11/2013): Check that the template argument lists are consistant. The templateArgumentsList can then be considered redundant if this works.
3817 if (buildTemplateInstantiation == true)
3818 {
3819 ASSERT_not_null(templateArgumentsList);
3820
3821 SgTemplateArgumentPtrList & templateArgumentsList_from_first_nondefining_declaration = (isMemberFunction == false) ?
3822 isSgTemplateInstantiationFunctionDecl(first_nondefining_declaration)->get_templateArguments() :
3823 isSgTemplateInstantiationMemberFunctionDecl(first_nondefining_declaration)->get_templateArguments();
3824
3825 ASSERT_not_null(templateArgumentsList);
3826 bool templateArgumentListsAreEquivalent = SageInterface::templateArgumentListEquivalence(*templateArgumentsList, templateArgumentsList_from_first_nondefining_declaration);
3827 ASSERT_require(templateArgumentListsAreEquivalent == true);
3828 }
3829
3830 SgTemplateParameterPtrList* templateParameterList = nullptr;
3831 if (buildTemplateDeclaration == true)
3832 {
3833 // 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.
3834 templateParameterList = (isMemberFunction == false) ?
3835 &(isSgTemplateFunctionDeclaration(first_nondefining_declaration)->get_templateParameters()) :
3836 &(isSgTemplateMemberFunctionDeclaration(first_nondefining_declaration)->get_templateParameters());
3837
3838 ASSERT_require(templateArgumentsList == nullptr);
3839 ASSERT_not_null(templateParameterList);
3840 }
3841
3842 if (buildTemplateInstantiation == true)
3843 {
3844 ASSERT_not_null(templateArgumentsList);
3845 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
3846
3847 if (nameWithTemplateArguments == "insert < __normal_iterator< SgInitializedName ** , __type > > ")
3848 {
3849 printf ("In buildDefiningFunctionDeclaration_T(): Found function nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
3850 }
3851 }
3852
3853 ASSERT_require(nameWithoutTemplateArguments.is_null() == false);
3854 ASSERT_require(nameWithTemplateArguments.is_null() == false);
3855 ASSERT_not_null(paralist);
3856
3858 {
3859 ASSERT_require(scope->containsOnlyDeclarations());
3860 }
3861
3862 // build function type, manage function type symbol internally
3863 actualFunction* defining_func = nullptr;
3864 SgFunctionType* func_type = nullptr;
3865
3866 // 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).
3867 // This is a special problem for templates because the function parameters will evaluate different for different builds of the same template.
3868 // This is a problem for test2012_74.C (and a dozen other test codes that make use of STL).
3869 ASSERT_not_null(first_nondefining_declaration);
3870
3871 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
3872 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
3873 // DQ (7/27/2012): There are reasons why this can fail: e.g. for functions with names such as:
3874 // "operator std::auto_ptr_ref<_Tp1>" which is a user defined conversion operator to one class from another.
3875
3876 // DQ (5/12/2012): Use the newly added parameter to get the exact SgFunctionType used to build the symbol.
3877 // This should make the template handling more robust since we were sometimes using types that had different
3878 // levels of template instantiation between the non-definng and defining function declarations and this
3879 // caused symbols build to support the non-defining declaration to not be found when we searched for them
3880 // using the function type built for the defining declaration. We want the function types for all defining
3881 // and non-defining declarations to be identical. This define also means that we don't have to build a
3882 // SgFunctionType just to look up a symbol in the symbol table (which was always silly). However, only
3883 // the defining function declaration can use the existing function type because it is required that a
3884 // non-defining declaration exist prior to the construction of the defining declaration (built by this
3885 // function).
3886 func_type = first_nondefining_declaration->get_type();
3887 ASSERT_not_null(func_type);
3888
3889 // Make sure these are the same (this will fail until we generate the func_type directly from first_nondefining_declaration).
3890 ASSERT_require(func_type == first_nondefining_declaration->get_type());
3891
3892 SgDeclarationStatement* firstNondefiningFunctionDeclaration = nullptr;
3893
3894 // symbol table and non-defining
3895 SgSymbol* func_symbol = scope->find_symbol_by_type_of_function<actualFunction>(nameWithTemplateArguments,func_type,templateParameterList,templateArgumentsList);
3896
3897 // DQ (1/26/2013): This fails for ROSE compiling ROSE.
3898 ASSERT_not_null(func_symbol);
3899
3900 if (func_symbol == nullptr)
3901 {
3902 // DQ (12/2/2011): After discussion with Liao, we think this should be an error.
3903 // The defining declaration requires that the associated non-defining declaration should already exist.
3904 // If required, a higher level build function could build both of these and connect them as required.
3905 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");
3906 ROSE_ABORT();
3907 }
3908 else
3909 {
3910 // We will now build a reference to the non-defining declaration found in the symbol.
3911
3912 // defining declaration after nondefining declaration
3913 // reuse function type, function symbol
3914
3915 // Cong (10/25/2010): Make sure in this situation there is no defining declaration for this symbol.
3916
3917 SgFunctionSymbol* temp_function_sym = isSgFunctionSymbol(func_symbol);
3918 SgTemplateSymbol* temp_template_sym = isSgTemplateSymbol(func_symbol);
3919 if (temp_function_sym != nullptr)
3920 {
3921 func_type = temp_function_sym->get_declaration()->get_type();
3922 firstNondefiningFunctionDeclaration = temp_function_sym->get_declaration()->get_firstNondefiningDeclaration();
3923 }
3924 else
3925 {
3926 // There is no type for a template function declaration.
3927 ASSERT_not_null(temp_template_sym);
3928 firstNondefiningFunctionDeclaration = temp_template_sym->get_declaration()->get_firstNondefiningDeclaration();
3929 }
3930 ASSERT_not_null(firstNondefiningFunctionDeclaration);
3931 }
3932
3933 defining_func = new actualFunction(nameWithTemplateArguments,func_type,nullptr);
3934 ASSERT_not_null(defining_func);
3935
3936 ASSERT_not_null(firstNondefiningFunctionDeclaration);
3937 defining_func->set_firstNondefiningDeclaration(firstNondefiningFunctionDeclaration);
3938
3939 // fix up defining declarations before current statement
3940 firstNondefiningFunctionDeclaration->set_definingDeclaration(defining_func);
3941
3942 // Handle decorators (Python specific)
3943 if (decoratorList != nullptr)
3944 {
3945 defining_func->set_decoratorList(decoratorList);
3946 decoratorList->set_parent(defining_func);
3947 }
3948
3949 // definingDeclaration
3950 defining_func->set_definingDeclaration(defining_func);
3951
3952 // function body and definition are created before setting argument list
3953 SgBasicBlock * func_body = new SgBasicBlock();
3954 ASSERT_not_null(func_body);
3955
3956 SgFunctionDefinition* func_def = nullptr;
3957 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(defining_func);
3958
3959 // Build either a definition for a template or non-template function definition.
3960 if (templateFunctionDeclaration == nullptr)
3961 {
3962 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(defining_func);
3963 ASSERT_not_null(functionDeclaration);
3964 func_def = new SgFunctionDefinition(functionDeclaration,func_body);
3965 }
3966 else
3967 {
3968 ASSERT_not_null(templateFunctionDeclaration);
3969 func_def = new SgTemplateFunctionDefinition(templateFunctionDeclaration,func_body);
3970 }
3971 ASSERT_not_null(func_def);
3972
3974 {
3975 func_def->setCaseInsensitive(true);
3976 func_body->setCaseInsensitive(true);
3977 }
3978
3979 func_def->set_parent(defining_func);
3980 func_def->set_body(func_body);
3981 func_body->set_parent(func_def);
3982
3983 // parameter list,
3984 // TODO consider the difference between C++ and Fortran
3985 setParameterList(defining_func,paralist);
3986 // fixup the scope and symbol of arguments,
3987 for (SgInitializedName* i_name : paralist->get_args())
3988 {
3989 i_name->set_scope(func_def);
3990
3991 SgVariableSymbol* variableSymbol = new SgVariableSymbol(i_name);
3992 ASSERT_not_null(variableSymbol);
3993 func_def->insert_symbol(i_name->get_name(), variableSymbol);
3994
3995 // For variable length array types in the function parameter list
3996 SgArrayType* arrayType = isSgArrayType(i_name->get_type());
3997 if (arrayType != nullptr)
3998 {
3999 // Check if this is a VLA array type, if so look for the index expressions and check
4000 // if we need to add asociated symbols to the current function definition scope.
4001 SgExpression* indexExpression = arrayType->get_index();
4002
4003 if (indexExpression != nullptr)
4004 {
4005 // DQ (2/14/2016): Handle the case of an expression tree with any number of variable references.
4006 // Get the list of SgVarRef IR nodes and process each one as above.
4007 vector<SgVarRefExp* > varRefList;
4008 collectVarRefs(indexExpression,varRefList);
4009
4010 for (size_t i = 0; i < varRefList.size(); i++)
4011 {
4012 // Process each index subtree's SgVarRefExp.
4013 SgVariableSymbol* dimension_variableSymbol = varRefList[i]->get_symbol();
4014 ASSERT_not_null(dimension_variableSymbol);
4015 ASSERT_require(dimension_variableSymbol != variableSymbol);
4016
4017 // The symbol from the referenced variable for the array dimension expression shuld already by in the function definition's symbol table.
4018 SgSymbol* symbolFromLookup = func_def->lookup_symbol(dimension_variableSymbol->get_name());
4019 if (symbolFromLookup != nullptr)
4020 {
4021 SgVariableSymbol* variableSymbolFromLookup = isSgVariableSymbol(symbolFromLookup);
4022 ASSERT_not_null(variableSymbolFromLookup);
4023
4024 varRefList[i]->set_symbol(variableSymbolFromLookup);
4025 ASSERT_require(dimension_variableSymbol != variableSymbol);
4026 }
4027 else
4028 {
4029 // 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.
4030 }
4031 }
4032 }
4033 }
4034 }
4035
4036 defining_func->set_parent(scope);
4037 defining_func->set_scope(scope);
4038
4039 ASSERT_not_null(defining_func->get_scope());
4040
4041 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(defining_func,scope);
4042
4043 // set File_Info as transformation generated
4045
4046 // Enforce that the return type matches the specification to build a member function.
4047 if (isMemberFunction == true)
4048 {
4049 ASSERT_not_null(isSgMemberFunctionDeclaration(defining_func));
4050 }
4051
4052 // 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)).
4053 setTemplateNameInTemplateInstantiations(defining_func,nameWithoutTemplateArguments);
4054
4055 // DQ (9/16/2012): Setup up the template arguments and the parents of the template arguments.
4056 if (buildTemplateInstantiation == true)
4057 {
4058 setTemplateArgumentsInDeclaration(defining_func,templateArgumentsList);
4059 }
4060
4061 // DQ (8/13/2013): Added code to set the template parameters in the defining declaration (if it is a template declaration).
4062 if (buildTemplateDeclaration == true)
4063 {
4064 setTemplateParametersInDeclaration(defining_func,templateParameterList);
4065
4066 // DQ (8/13/2013): Adding test of template parameter lists.
4067 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(defining_func);
4068 ROSE_ASSERT(templateFunctionDeclaration == nullptr || (templateParameterList != nullptr && templateParameterList->size() == templateFunctionDeclaration->get_templateParameters().size()));
4069 SgTemplateMemberFunctionDeclaration* templateMemberFunctionDeclaration = isSgTemplateMemberFunctionDeclaration(defining_func);
4070 ROSE_ASSERT(templateMemberFunctionDeclaration == nullptr || (templateParameterList != nullptr && templateParameterList->size() == templateMemberFunctionDeclaration->get_templateParameters().size()));
4071 }
4072
4073 // DQ (12/12/2012): Force the two different ways that this can be set to match (we want consistancy).
4074 if (functionConstVolatileFlags & SgMemberFunctionType::e_restrict)
4075 {
4076 defining_func->get_declarationModifier().get_typeModifier().setRestrict();
4077 }
4078
4079 // DQ (4/16/2015): This is replaced with a better implementation.
4080 // DQ (4/15/2015): We should reset the isModified flags as part of the transforamtion
4081 // because we have added statements explicitly marked as transformations.
4082 // checkIsModifiedFlag(defining_func);
4083 unsetNodesMarkedAsModified(defining_func);
4084
4085 return defining_func;
4086 }
4087
4088void
4090 {
4091 // 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)).
4092
4093 SgTemplateInstantiationFunctionDecl* templateInstantiationFunctionDecl = isSgTemplateInstantiationFunctionDecl(func);
4094 SgTemplateInstantiationMemberFunctionDecl* templateInstantiationMemberFunctionDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
4095 bool isTemplateInstantition = (templateInstantiationFunctionDecl != NULL) || (templateInstantiationMemberFunctionDecl != NULL);
4096 if (isTemplateInstantition == true)
4097 {
4098 // If this is a template instantiation then we need to take care of a few more issues.
4099
4100 SgName templateNameWithoutArguments = name;
4101
4102 // DQ (7/27/2012): New semantics is that we want to have the input name be without template arguments and
4103 // we will add the template arguments instead of trying to remove then (which was problematic for examples
4104 // such as "X<Y<Z>> operator X&()" and "X<Y<Z>> operator>()".
4105
4106 bool isMemberFunction = (templateInstantiationMemberFunctionDecl != NULL);
4107 if (isMemberFunction == true)
4108 {
4109 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
4110 ROSE_ASSERT(templateInstantiationFunctionDecl == NULL);
4111
4112 if (templateInstantiationMemberFunctionDecl->get_templateName().is_null() == true)
4113 {
4114 // Set the template name for the member function template instantiation.
4115 // templateInstantiationMemberFunctionDecl->set_templateName(name);
4116 templateInstantiationMemberFunctionDecl->set_templateName(templateNameWithoutArguments);
4117
4118 // DQ (5/31/2012): Find locations where this is set and include template syntax.
4119 }
4120 ROSE_ASSERT(templateInstantiationMemberFunctionDecl->get_templateName().is_null() == false);
4121 }
4122 else
4123 {
4124 ROSE_ASSERT(templateInstantiationFunctionDecl != NULL);
4125 ROSE_ASSERT(templateInstantiationMemberFunctionDecl == NULL);
4126
4127 if (templateInstantiationFunctionDecl->get_templateName().is_null() == true)
4128 {
4129 // Set the template name for the function template instantiation.
4130 // templateInstantiationFunctionDecl->set_templateName(name);
4131 templateInstantiationFunctionDecl->set_templateName(templateNameWithoutArguments);
4132
4133 // DQ (5/31/2012): Find locations where this is set and include template syntax.
4134 ROSE_ASSERT(hasTemplateSyntax(templateNameWithoutArguments) == false);
4135 }
4136 ROSE_ASSERT(templateInstantiationFunctionDecl->get_templateName().is_null() == false);
4137 }
4138 }
4139 }
4140
4142SageBuilder::buildDefiningFunctionDeclaration(const SgName& name, SgType* return_type, SgFunctionParameterList* paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, SgFunctionDeclaration* first_nondefining_declaration, SgTemplateArgumentPtrList* templateArgumentsList)
4143 {
4144 // DQ (2/10/2012): Fixed to build either SgTemplateInstantiationFunctionDecl or SgFunctionDeclaration.
4145 SgFunctionDeclaration* func = NULL;
4146 if (buildTemplateInstantiation == true)
4147 {
4148 SgTemplateInstantiationFunctionDecl* templateInstantiationFunctionDecl = isSgTemplateInstantiationFunctionDecl(first_nondefining_declaration);
4149
4150 ROSE_ASSERT(first_nondefining_declaration != NULL);
4151
4152 func = buildDefiningFunctionDeclaration_T<SgTemplateInstantiationFunctionDecl>(name,return_type,paralist,/* isMemberFunction = */ false,scope,decoratorList,0,templateInstantiationFunctionDecl, templateArgumentsList);
4153
4154 ROSE_ASSERT(isSgTemplateInstantiationFunctionDecl(func) != NULL);
4155 ROSE_ASSERT(isSgTemplateInstantiationFunctionDecl(func)->get_templateName().is_null() == false);
4156 }
4157 else
4158 {
4159 ROSE_ASSERT(first_nondefining_declaration != NULL);
4160
4161 func = buildDefiningFunctionDeclaration_T<SgFunctionDeclaration>(name,return_type,paralist,/* isMemberFunction = */ false,scope,decoratorList,0,first_nondefining_declaration, NULL);
4162
4163 ROSE_ASSERT(isSgFunctionDeclaration(func) != NULL);
4164 }
4165
4166 return func;
4167 }
4168
4169
4170// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficent).
4171// We need to decide if the SageBuilder API should include these sorts of functions.
4174 {
4175 // DQ (11/12/2012): Note that this function is not used in the AST construction in the EDG/ROSE interface.
4176
4177 // DQ (8/23/2013): Added assertions.
4178 ROSE_ASSERT(return_type != NULL);
4179 ROSE_ASSERT(parameter_list != NULL);
4180
4181 // DQ (8/23/2013): We need to provide the buildDefiningFunctionDeclaration() function with a pointer to the first non-defining declaration.
4182 // 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.
4183 // DQ (11/12/2012): Building a defining declaration from scratch now requires a non-defining declaration to exist.
4184 // SgFunctionDeclaration* nondefininfDeclaration = buildNondefiningFunctionDeclaration(name,return_type,parameter_list,scope,NULL);
4185
4186 if (scope == NULL)
4187 {
4189 }
4190
4191 SgFunctionDeclaration* nondefiningDeclaration = NULL;
4192
4193 SgFunctionType* func_type = buildFunctionType(return_type,parameter_list);
4194 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgFunctionDeclaration>(name,func_type,NULL,NULL);
4195 if (func_symbol != NULL)
4196 {
4197 nondefiningDeclaration = func_symbol->get_declaration();
4198 }
4199 else
4200 {
4201 nondefiningDeclaration = buildNondefiningFunctionDeclaration(name,return_type,parameter_list,scope,NULL);
4202 }
4203
4204 ROSE_ASSERT(nondefiningDeclaration != NULL);
4205 ROSE_ASSERT(nondefiningDeclaration->get_firstNondefiningDeclaration() != NULL);
4206 ROSE_ASSERT(nondefiningDeclaration->get_firstNondefiningDeclaration() == nondefiningDeclaration);
4207
4208 return buildDefiningFunctionDeclaration (name,return_type,parameter_list,scope,NULL,false,nondefiningDeclaration,NULL);
4209 }
4210
4211// Build a nondefining SgProcedureHeaderStatement, handle function type, symbol etc transparently [Rasmussen 9/24/2020]
4215 {
4216 ASSERT_not_null(return_type);
4217 ASSERT_not_null(param_list);
4218
4219 SgProcedureHeaderStatement* nondef_decl = nullptr;
4220
4221 if (scope == nullptr) {
4223 }
4224
4225 // A new nondefing declaration is needed even if the function symbol already exists. The function symbol
4226 // should always contain the _first_ nondefining declaration (even though this may not be the first one).
4227 nondef_decl = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement>
4228 ( name, return_type, param_list, /*isMemberFunction*/false, scope, /*decoratorList*/nullptr,
4229 /*functionConstVolatileFlags*/0, nullptr, nullptr, SgStorageModifier::e_default );
4230
4231 ASSERT_not_null(isSgProcedureHeaderStatement(nondef_decl));
4232 ASSERT_not_null(nondef_decl->get_firstNondefiningDeclaration());
4233
4234 nondef_decl->set_subprogram_kind(kind);
4235
4236 return nondef_decl;
4237 }
4238
4240buildProcedureHeaderStatement(const SgName& name, SgType* return_type, SgFunctionParameterList* parameter_list,
4242 {
4243 ASSERT_not_null(return_type);
4244 ASSERT_not_null(parameter_list);
4245
4246 SgFunctionDeclaration* nondef_decl = nullptr;
4247
4248 if (scope == nullptr) {
4250 }
4251
4252 SgFunctionType* func_type = buildFunctionType(return_type,parameter_list);
4253 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgProcedureHeaderStatement>(name,func_type,nullptr,nullptr);
4254 if (func_symbol == nullptr)
4255 {
4256 nondef_decl = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement>
4257 ( name, return_type, parameter_list, /*isMemberFunction*/false, scope,
4258 /*decoratorList*/nullptr, /*functionConstVolatileFlags*/0, nullptr, nullptr, SgStorageModifier::e_default);
4259 }
4260 else
4261 {
4262 nondef_decl = func_symbol->get_declaration();
4263 }
4264
4265 SgProcedureHeaderStatement* proc_header_stmt = isSgProcedureHeaderStatement(nondef_decl);
4266 ASSERT_not_null(proc_header_stmt);
4267 ASSERT_require(nondef_decl->get_firstNondefiningDeclaration() == nondef_decl);
4268
4269 return buildProcedureHeaderStatement(name.str(), return_type, parameter_list, kind, scope, proc_header_stmt);
4270 }
4271
4272
4277 SgProcedureHeaderStatement* firstNondefDecl)
4278{
4279 ASSERT_not_null(firstNondefDecl);
4280 SgProcedureHeaderStatement* func{nullptr};
4281
4284 ASSERT_require(returnType == buildVoidType());
4285 }
4287 mlog[ERROR] << "unhandled subprogram kind for Fortran (or Jovial) function declaration:"
4288 << kind << endl;
4289 ROSE_ABORT();
4290 }
4291
4292 func = buildDefiningFunctionDeclaration_T<SgProcedureHeaderStatement>(SgName(name), returnType, params, /*isMemberFunction =*/false,
4293 scope, nullptr, 0U, firstNondefDecl, nullptr);
4294 ASSERT_not_null(func);
4295 func->set_subprogram_kind(kind);
4296
4297 return func;
4298}
4299
4300//------------------build value expressions -------------------
4301//-------------------------------------------------------------
4303{
4304 //TODO does valueString matter here?
4305 SgBoolValExp* boolValue= new SgBoolValExp(value);
4306 ROSE_ASSERT(boolValue);
4308 return boolValue;
4309}
4311{
4312 return buildBoolValExp(int(value));
4313}
4315{
4316 SgBoolValExp* boolValue= new SgBoolValExp(value);
4317 ROSE_ASSERT(boolValue);
4318 setOneSourcePositionNull(boolValue);
4319 return boolValue;
4320}
4321
4323 {
4324 SgNullptrValExp* nullptrValue = new SgNullptrValExp();
4325 ROSE_ASSERT(nullptrValue);
4327 return nullptrValue;
4328 }
4329
4331 {
4332 SgNullptrValExp* nullptrValue = new SgNullptrValExp();
4333 ROSE_ASSERT(nullptrValue);
4334 setOneSourcePositionNull(nullptrValue);
4335 return nullptrValue;
4336 }
4337
4339 {
4340 SgVoidVal* voidValue = new SgVoidVal();
4341 ROSE_ASSERT(voidValue);
4343 return voidValue;
4344 }
4345
4347 {
4348 SgVoidVal* voidValue = new SgVoidVal();
4349 ROSE_ASSERT(voidValue);
4350 setOneSourcePositionNull(voidValue);
4351 return voidValue;
4352 }
4353
4355{
4356 SgCharVal* result = new SgCharVal(value, "");
4357 ROSE_ASSERT(result);
4359 return result;
4360}
4361
4362SgCharVal* SageBuilder::buildCharVal_nfi(char value, const string& str)
4363{
4364 SgCharVal* result = new SgCharVal(value, str);
4365 ROSE_ASSERT(result);
4367 return result;
4368}
4369
4371{
4372 SgWcharVal* result = new SgWcharVal(value, "");
4373 ROSE_ASSERT(result);
4375 return result;
4376}
4377
4378SgWcharVal* SageBuilder::buildWcharVal_nfi(wchar_t value, const string& str)
4379{
4380 SgWcharVal* result = new SgWcharVal(value, str);
4381 ROSE_ASSERT(result);
4383 return result;
4384}
4385
4386// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
4387SgChar16Val* SageBuilder::buildChar16Val(unsigned short value /*= 0*/)
4388{
4389 SgChar16Val* result = new SgChar16Val(value, "");
4390 ROSE_ASSERT(result);
4392 return result;
4393}
4394
4395SgChar16Val* SageBuilder::buildChar16Val_nfi(unsigned short value, const string& str)
4396{
4397 SgChar16Val* result = new SgChar16Val(value, str);
4398 ROSE_ASSERT(result);
4400 return result;
4401}
4402
4403// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
4404SgChar32Val* SageBuilder::buildChar32Val(unsigned int value /*= 0*/)
4405{
4406 SgChar32Val* result = new SgChar32Val(value, "");
4407 ROSE_ASSERT(result);
4409 return result;
4410}
4411
4412SgChar32Val* SageBuilder::buildChar32Val_nfi(unsigned int value, const string& str)
4413{
4414 SgChar32Val* result = new SgChar32Val(value, str);
4415 ROSE_ASSERT(result);
4417 return result;
4418}
4419
4420
4422{
4423 SgComplexVal* result = new SgComplexVal(real_value,imaginary_value,imaginary_value->get_type(),"");
4424 ROSE_ASSERT(result);
4425
4426// DQ (12/31/2008): set and test the parents
4427 if (real_value != NULL)
4428 real_value->set_parent(result);
4429
4430 if (imaginary_value != NULL)
4431 imaginary_value->set_parent(result);
4432
4433 ROSE_ASSERT(real_value == NULL || real_value->get_parent() != NULL);
4434 ROSE_ASSERT(imaginary_value == NULL || imaginary_value->get_parent() != NULL);
4435
4437 return result;
4438}
4439
4440SgComplexVal* SageBuilder::buildComplexVal_nfi(SgValueExp* real_value, SgValueExp* imaginary_value, const std::string& str)
4441{
4442 ROSE_ASSERT(imaginary_value != NULL);
4443 SgComplexVal* result = new SgComplexVal(real_value,imaginary_value,imaginary_value->get_type(),str);
4444 ROSE_ASSERT(result != NULL);
4445
4446// DQ (12/31/2008): set and test the parents
4447 if (real_value != NULL)
4448 real_value->set_parent(result);
4449
4450 if (imaginary_value != NULL)
4451 imaginary_value->set_parent(result);
4452
4453 ROSE_ASSERT(real_value == NULL || real_value->get_parent() != NULL);
4454 ROSE_ASSERT(imaginary_value == NULL || imaginary_value->get_parent() != NULL);
4455
4457 return result;
4458}
4459
4460SgComplexVal* SageBuilder::buildImaginaryVal(long double imaginary_value /*= 0.0*/ )
4461{
4462 SgComplexVal* result = new SgComplexVal(NULL,buildLongDoubleVal(imaginary_value),SgTypeLongDouble::createType(),"");
4463 ROSE_ASSERT(result);
4464
4465// DQ (12/31/2008): set and test the parents
4466 result->get_imaginary_value()->set_parent(result);
4467 ROSE_ASSERT(result->get_imaginary_value()->get_parent() != NULL);
4468
4470 return result;
4471}
4472
4474{
4475 ROSE_ASSERT(imaginary_value != NULL);
4476
4477 SgComplexVal* result = new SgComplexVal(NULL,imaginary_value,imaginary_value->get_type(),"");
4478 ROSE_ASSERT(result);
4479
4480// DQ (12/31/2008): set and test the parents
4481 imaginary_value->set_parent(result);
4482 ROSE_ASSERT(imaginary_value->get_parent() != NULL);
4483
4485 return result;
4486}
4487
4488SgComplexVal* SageBuilder::buildImaginaryVal_nfi(SgValueExp* imaginary_value, const std::string& str)
4489{
4490 ROSE_ASSERT(imaginary_value != NULL);
4491
4492 SgComplexVal* result = new SgComplexVal(NULL,imaginary_value,imaginary_value->get_type(),str);
4493 imaginary_value->set_parent(result);
4494 ROSE_ASSERT(result);
4495
4496// DQ (12/31/2008): set and test the parents
4497 ROSE_ASSERT(imaginary_value->get_parent() != NULL);
4498
4500 return result;
4501}
4502
4504{
4505 SgDoubleVal* value = new SgDoubleVal(t,"");
4506 ROSE_ASSERT(value);
4508 return value;
4509}
4510
4512{
4513 SgDoubleVal* value = new SgDoubleVal(t,str);
4514 ROSE_ASSERT(value);
4516 return value;
4517}
4518
4520{
4521 SgFloatVal* result = new SgFloatVal(value,"");
4522 ROSE_ASSERT(result);
4524 return result;
4525}
4526
4528{
4529 SgFloatVal* result = new SgFloatVal(value,"");
4530 ROSE_ASSERT(result);
4532 return result;
4533}
4534
4535SgFloatVal* SageBuilder::buildFloatVal_nfi(float value, const string& str)
4536{
4537 SgFloatVal* result = new SgFloatVal(value,str);
4538 ROSE_ASSERT(result);
4540 return result;
4541}
4542
4544{
4545 // C++11 please [CR 2020.02.25]
4546 // return buildFloatVal_nfi(std::stof(str), str);
4547 return buildFloatVal_nfi(atof(str.c_str()), str);
4548}
4549
4551 {
4552 SgIntVal* intValue= new SgIntVal(value,"");
4553 ASSERT_not_null(intValue);
4555 return intValue;
4556 }
4557
4559 {
4560 SgIntVal* intValue= new SgIntVal(value, (value >= 0 ? StringUtility::intToHex((unsigned int)value) : "-" + StringUtility::intToHex((unsigned int)(-value))));
4561 ASSERT_not_null(intValue);
4563 return intValue;
4564 }
4565
4567 {
4568 SgIntVal* intValue = new SgIntVal(value,"");
4569 ASSERT_not_null(intValue);
4570 setOneSourcePositionNull(intValue);
4571 return intValue;
4572 }
4573
4574SgIntVal* SageBuilder::buildIntVal_nfi(int value, const string& str)
4575 {
4576 SgIntVal* intValue = new SgIntVal(value,str);
4577 ASSERT_not_null(intValue);
4578 setOneSourcePositionNull(intValue);
4579 return intValue;
4580 }
4581
4583 {
4584 return buildIntVal_nfi(std::stoi(str), str);
4585 }
4586
4588{
4589 SgLongIntVal* intValue= new SgLongIntVal(value,"");
4590 ASSERT_not_null(intValue);
4592 return intValue;
4593}
4594
4595SgLongIntVal* SageBuilder::buildLongIntVal_nfi(long value, const string& str)
4596{
4597 SgLongIntVal* intValue= new SgLongIntVal(value,str);
4598 ASSERT_not_null(intValue);
4599 setOneSourcePositionNull(intValue);
4600 return intValue;
4601}
4602
4604{
4605 SgLongLongIntVal* intValue= new SgLongLongIntVal(value,"");
4606 ASSERT_not_null(intValue);
4608 return intValue;
4609}
4610
4611SgLongLongIntVal* SageBuilder::buildLongLongIntVal_nfi(long long value, const string& str)
4612{
4613 SgLongLongIntVal* intValue= new SgLongLongIntVal(value,str);
4614 ASSERT_not_null(intValue);
4615 setOneSourcePositionNull(intValue);
4616 return intValue;
4617}
4618
4620 {
4621 SgEnumVal* enumVal= new SgEnumVal(value,decl,name);
4622 ASSERT_not_null(enumVal);
4624 return enumVal;
4625 }
4626
4627
4629 {
4630 SgEnumVal* enumVal= new SgEnumVal(value,decl,name);
4631 ASSERT_not_null(enumVal);
4632 setOneSourcePositionNull(enumVal);
4633 return enumVal;
4634 }
4635
4637 SgInitializedName * init_name = sym->get_declaration();
4638 ROSE_ASSERT(init_name != NULL);
4639 SgAssignInitializer * assign_init = isSgAssignInitializer(init_name->get_initptr());
4640 ROSE_ASSERT(assign_init != NULL);
4641 SgEnumVal * enum_val = isSgEnumVal(assign_init->get_operand_i());
4642 ROSE_ASSERT(enum_val != NULL);
4643 enum_val = isSgEnumVal(SageInterface::copyExpression(enum_val));
4644 return enum_val;
4645}
4646
4648{
4649 SgLongDoubleVal* result = new SgLongDoubleVal(value,"");
4650 ASSERT_not_null(result);
4652 return result;
4653}
4654
4655SgLongDoubleVal* SageBuilder::buildLongDoubleVal_nfi(long double value, const string& str)
4656{
4657 SgLongDoubleVal* result = new SgLongDoubleVal(value,str);
4658 ASSERT_not_null(result);
4660 return result;
4661}
4662
4663SgFloat80Val* SageBuilder::buildFloat80Val(long double value /*= 0.0*/)
4664{
4665 SgFloat80Val* result = new SgFloat80Val(value,"");
4666 ASSERT_not_null(result);
4668 return result;
4669}
4670
4671SgFloat80Val* SageBuilder::buildFloat80Val_nfi(long double value, const string& str)
4672{
4673 SgFloat80Val* result = new SgFloat80Val(value,str);
4674 ASSERT_not_null(result);
4676 return result;
4677}
4678
4680{
4681 SgFloat128Val* result = new SgFloat128Val(value,"");
4682 ASSERT_not_null(result);
4684 return result;
4685}
4686
4687SgFloat128Val* SageBuilder::buildFloat128Val_nfi(long double value, const string& str)
4688{
4689 SgFloat128Val* result = new SgFloat128Val(value,str);
4690 ASSERT_not_null(result);
4692 return result;
4693}
4694
4695SgStringVal* SageBuilder::buildStringVal(std::string value /*=""*/)
4696{
4697 SgStringVal* result = new SgStringVal(value);
4698 ASSERT_not_null(result);
4700 return result;
4701}
4702
4704{
4705 SgStringVal* result = new SgStringVal(value);
4706 ASSERT_not_null(result);
4708 return result;
4709}
4710
4712{
4713 SgUnsignedCharVal* result = new SgUnsignedCharVal(v,"");
4714 ASSERT_not_null(result);
4716 return result;
4717}
4718
4720{
4722 ASSERT_not_null(result);
4724 return result;
4725}
4726
4728{
4729 SgUnsignedCharVal* result = new SgUnsignedCharVal(v,str);
4730 ASSERT_not_null(result);
4732 return result;
4733}
4734
4736{
4737 SgSignedCharVal* result = new SgSignedCharVal(v,"");
4738 ASSERT_not_null(result);
4740 return result;
4741}
4742
4744{
4746 ASSERT_not_null(result);
4748 return result;
4749}
4750
4752{
4753 SgSignedCharVal* result = new SgSignedCharVal(v,str);
4754 ASSERT_not_null(result);
4756 return result;
4757}
4758
4760{
4761 SgShortVal* result = new SgShortVal(v,"");
4762 ASSERT_not_null(result);
4764 return result;
4765}
4766
4768{
4769 SgShortVal* result = new SgShortVal(v, (v >= 0 ? StringUtility::intToHex((unsigned int)v) : "-" + StringUtility::intToHex((unsigned int)(-v))));
4770 ASSERT_not_null(result);
4772 return result;
4773}
4774
4775SgShortVal* SageBuilder::buildShortVal_nfi(short v, const string& str)
4776{
4777 SgShortVal* result = new SgShortVal(v,str);
4778 ASSERT_not_null(result);
4780 return result;
4781}
4782
4784{
4785 SgUnsignedShortVal* result = new SgUnsignedShortVal(v,"");
4786 ASSERT_not_null(result);
4788 return result;
4789}
4790
4792{
4794 ASSERT_not_null(result);
4796 return result;
4797}
4798
4800{
4801 SgUnsignedShortVal* result = new SgUnsignedShortVal(v,str);
4802 ASSERT_not_null(result);
4804 return result;
4805}
4806
4808{
4809 SgUnsignedIntVal* result = new SgUnsignedIntVal(v,"");
4810 ASSERT_not_null(result);
4812 return result;
4813}
4814
4816{
4818 ASSERT_not_null(result);
4820 return result;
4821}
4822
4824{
4825 SgUnsignedIntVal* result = new SgUnsignedIntVal(v,str);
4826 ASSERT_not_null(result);
4828 return result;
4829}
4830
4832{
4833 SgUnsignedLongVal* result = new SgUnsignedLongVal(v,"");
4834 ASSERT_not_null(result);
4836 return result;
4837}
4838
4840{
4842 ASSERT_not_null(result);
4844 return result;
4845}
4846
4848{
4849 SgUnsignedLongVal* result = new SgUnsignedLongVal(v,str);
4850 ASSERT_not_null(result);
4852 return result;
4853}
4854
4856{
4858 ASSERT_not_null(result);
4860 return result;
4861}
4862
4864{
4866 ASSERT_not_null(result);
4868 return result;
4869}
4870
4872{
4874 ASSERT_not_null(result);
4876 return result;
4877}
4878
4879SgJovialBitVal* SageBuilder::buildJovialBitVal_nfi(const string& str)
4880{
4881 SgJovialBitVal* result = new SgJovialBitVal(str);
4882 ASSERT_not_null(result);
4884 return result;
4885}
4886
4888{
4889 SgTemplateType* result = new SgTemplateType (name);
4890 ASSERT_not_null (result);
4892 return result;
4893}
4894
4896{
4897 ROSE_ASSERT (t);
4898 SgTemplateParameter* result = new SgTemplateParameter(parameterType, t);
4899 ROSE_ASSERT (result);
4901 return result;
4902}
4903
4905{
4906 SgTemplateParameterVal* templateParameterValue = new SgTemplateParameterVal(template_parameter_position,"");
4907 ROSE_ASSERT(templateParameterValue);
4908 setOneSourcePositionForTransformation(templateParameterValue);
4909
4910// DQ (7/25/2012): Assert this (it will be set later).
4911 ROSE_ASSERT(templateParameterValue->get_parent() == NULL);
4912
4913 return templateParameterValue;
4914}
4915
4916SgTemplateParameterVal* SageBuilder::buildTemplateParameterVal_nfi(int template_parameter_position, const string& str)
4917{
4918 SgTemplateParameterVal* templateParameterValue= new SgTemplateParameterVal(template_parameter_position,str);
4919 ROSE_ASSERT(templateParameterValue);
4920 setOneSourcePositionNull(templateParameterValue);
4921
4922// DQ (7/25/2012): Assert this (it will be set later).
4923 ROSE_ASSERT(templateParameterValue->get_parent() == NULL);
4924
4925 return templateParameterValue;
4926}
4927
4928#define DEBUG_BUILD_NONREAL_DECL 0
4929
4931 ROSE_ASSERT(scope != NULL);
4932#if DEBUG_BUILD_NONREAL_DECL
4933 printf("ENTER SageBuilder::buildNonrealDecl\n");
4934 printf(" --- name = %s\n", name.str());
4935 printf(" --- scope = %p (%s)\n", scope, scope->class_name().c_str());
4936#endif
4937
4938 SgNonrealDecl * nrdecl = NULL;
4939
4940 nrdecl = new SgNonrealDecl(name);
4942 nrdecl->set_firstNondefiningDeclaration(nrdecl);
4943#if DEBUG_BUILD_NONREAL_DECL
4944 printf(" --- nrdecl = %p (%s)\n", nrdecl, nrdecl->class_name().c_str());
4945#endif
4946
4947 SgNonrealSymbol * symbol = new SgNonrealSymbol(nrdecl);
4948 scope->insert_symbol(name, symbol);
4949#if DEBUG_BUILD_NONREAL_DECL
4950 printf(" --- symbol = %p (%s)\n", symbol, symbol->class_name().c_str());
4951#endif
4952
4953 SgNonrealType * type = new SgNonrealType();
4954 type->set_declaration(nrdecl);
4955 type->set_parent(scope);
4956 nrdecl->set_type(type);
4957 // FIXME (???) insert `type` in `scope`
4958#if DEBUG_BUILD_NONREAL_DECL
4959 printf(" --- type = %p (%s)\n", type, type->class_name().c_str());
4960#endif
4961
4962 if (child_scope == NULL) {
4963 child_scope = new SgDeclarationScope();
4964#if DEBUG_BUILD_NONREAL_DECL
4965 printf(" --- child_scope = %p (new)\n", name.str(), child_scope);
4966#endif
4969 child_scope->get_endOfConstruct()->setCompilerGenerated();
4970 } else {
4971#if DEBUG_BUILD_NONREAL_DECL
4972 printf(" --- child_scope = %p (provided)\n", name.str(), child_scope);
4973#endif
4974
4975 }
4976 child_scope->set_parent(nrdecl);
4977 nrdecl->set_nonreal_decl_scope(child_scope);
4978
4979#if DEBUG_BUILD_NONREAL_DECL
4980 printf("LEAVE SageBuilder::buildNonrealDecl\n");
4981#endif
4982
4983 return nrdecl;
4984}
4985
4988{
4989 SgUpcThreads* result = new SgUpcThreads(0,"");
4990 ROSE_ASSERT(result);
4992 return result;
4993}
4994
4997{
4998 SgUpcThreads* result = new SgUpcThreads(0,"");
4999 ROSE_ASSERT(result);
5001 return result;
5002}
5003
5006{
5007 SgUpcMythread* result = new SgUpcMythread(0,"");
5008 ROSE_ASSERT(result);
5010 return result;
5011}
5012
5015{
5016 SgUpcMythread* result = new SgUpcMythread(0,"");
5017 ROSE_ASSERT(result);
5019 return result;
5020}
5021
5023{
5024 SgThisExp* result = new SgThisExp(isSgClassSymbol(sym), isSgNonrealSymbol(sym), 0);
5025 ROSE_ASSERT(result);
5027 return result;
5028}
5029
5031{
5032 SgThisExp* result = new SgThisExp(isSgClassSymbol(sym), isSgNonrealSymbol(sym), 0);
5033 ROSE_ASSERT(result);
5035 return result;
5036}
5037
5039{
5040 SgSuperExp* result = new SgSuperExp(sym, 0);
5041 ROSE_ASSERT(result);
5043 return result;
5044}
5045
5047{
5048 SgSuperExp* result = new SgSuperExp(sym, 0);
5049 ROSE_ASSERT(result);
5051 return result;
5052}
5053
5055{
5056 SgClassExp* result = new SgClassExp(sym, 0);
5057 ROSE_ASSERT(result);
5059 return result;
5060}
5061
5063{
5064 SgClassExp* result = new SgClassExp(sym, 0);
5065 ROSE_ASSERT(result);
5067 return result;
5068}
5069
5072{
5073 SgTupleExp* tuple = new SgTupleExp();
5074 ROSE_ASSERT(tuple);
5075 if (elt1) appendExpression(tuple, elt1);
5076 if (elt2) appendExpression(tuple, elt2);
5077 if (elt3) appendExpression(tuple, elt3);
5078 if (elt4) appendExpression(tuple, elt4);
5079 if (elt5) appendExpression(tuple, elt5);
5080 if (elt6) appendExpression(tuple, elt6);
5081 if (elt7) appendExpression(tuple, elt7);
5082 if (elt8) appendExpression(tuple, elt8);
5083 if (elt9) appendExpression(tuple, elt9);
5084 if (elt10) appendExpression(tuple, elt10);
5085
5087 return tuple;
5088}
5089
5091SageBuilder::buildTupleExp(const std::vector<SgExpression*>& elts)
5092{
5094 appendExpressionList(expList, elts);
5095 return expList;
5096}
5097
5100{
5101 SgTupleExp* tuple = new SgTupleExp();
5102 ROSE_ASSERT(tuple);
5104 return tuple;
5105}
5106
5108SageBuilder::buildTupleExp_nfi(const std::vector<SgExpression*>& elts)
5109{
5111 appendExpressionList(tuple, elts);
5112 return tuple;
5113}
5114
5115SgListExp*
5117{
5118 SgListExp* tuple = new SgListExp();
5119 ROSE_ASSERT(tuple);
5120 if (elt1) appendExpression(tuple, elt1);
5121 if (elt2) appendExpression(tuple, elt2);
5122 if (elt3) appendExpression(tuple, elt3);
5123 if (elt4) appendExpression(tuple, elt4);
5124 if (elt5) appendExpression(tuple, elt5);
5125 if (elt6) appendExpression(tuple, elt6);
5126 if (elt7) appendExpression(tuple, elt7);
5127 if (elt8) appendExpression(tuple, elt8);
5128 if (elt9) appendExpression(tuple, elt9);
5129 if (elt10) appendExpression(tuple, elt10);
5130
5132 return tuple;
5133}
5134
5135SgListExp*
5136SageBuilder::buildListExp(const std::vector<SgExpression*>& elts)
5137{
5139 appendExpressionList(expList, elts);
5140 return expList;
5141}
5142
5143SgListExp*
5145{
5146 SgListExp* tuple = new SgListExp();
5147 ROSE_ASSERT(tuple);
5149 return tuple;
5150}
5151
5152SgListExp*
5153SageBuilder::buildListExp_nfi(const std::vector<SgExpression*>& elts)
5154{
5156 appendExpressionList(tuple, elts);
5157 return tuple;
5158}
5159
5160
5161#define BUILD_UNARY_DEF(suffix) \
5162 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix##_nfi(SgExpression* op) \
5163 { \
5164 return SageBuilder::buildUnaryExpression_nfi<Sg##suffix>(op); \
5165 } \
5166 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix(SgExpression* op) \
5167 { \
5168 return SageBuilder::buildUnaryExpression<Sg##suffix>(op); \
5169 }
5170
5171BUILD_UNARY_DEF(AddressOfOp)
5172BUILD_UNARY_DEF(BitComplementOp)
5173BUILD_UNARY_DEF(MinusOp)
5174BUILD_UNARY_DEF(NotOp)
5175BUILD_UNARY_DEF(PointerDerefExp)
5176BUILD_UNARY_DEF(UnaryAddOp)
5177BUILD_UNARY_DEF(AbsOp)
5178BUILD_UNARY_DEF(MinusMinusOp)
5179BUILD_UNARY_DEF(PlusPlusOp)
5180BUILD_UNARY_DEF(RealPartOp)
5181BUILD_UNARY_DEF(ImagPartOp)
5182BUILD_UNARY_DEF(ConjugateOp)
5183BUILD_UNARY_DEF(VarArgStartOneOperandOp)
5184BUILD_UNARY_DEF(VarArgEndOp)
5185
5186BUILD_UNARY_DEF(MatrixTransposeOp) //SK(08/20/2015): Matlab matrix transpose operators
5187
5188#undef BUILD_UNARY_DEF
5189
5191 SgType * expression_type,
5192 SgCastExp::cast_type_enum cast_type)
5193{
5194 SgCastExp* result = new SgCastExp(operand_i, expression_type, cast_type);
5195 ROSE_ASSERT(result);
5196 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5198 return result;
5199}
5200
5201SgNewExp*
5203 SgExprListExp* placement_args,
5204 SgConstructorInitializer* constructor_args,
5205 SgExpression* builtin_args,
5206 // FIXME: Change this from "short int" to "bool".
5207 short int need_global_specifier,
5208 SgFunctionDeclaration* newOperatorDeclaration)
5209 {
5210 // DQ (11/18/2012): Modified parameter names to make this function more clear.
5211 SgNewExp* result = new SgNewExp(specified_type, placement_args, constructor_args, builtin_args, need_global_specifier, newOperatorDeclaration);
5212 ROSE_ASSERT(result);
5213
5215 return result;
5216 }
5217
5219 short is_array,
5220 short need_global_specifier,
5221 SgFunctionDeclaration* deleteOperatorDeclaration)
5222{
5223 SgDeleteExp* result = new SgDeleteExp(variable, is_array,
5224 need_global_specifier, deleteOperatorDeclaration);
5225 ROSE_ASSERT(result);
5227 return result;
5228}
5229
5232 {
5233 // DQ (1/25/2013): Added support for typeId operators.
5234 SgTypeIdOp* result = new SgTypeIdOp(operand_expr,operand_type);
5235 ROSE_ASSERT(result != NULL);
5237 return result;
5238 }
5239
5241{
5242 SgCastExp* result = new SgCastExp(operand_i, expression_type, cast_type);
5243 ROSE_ASSERT(result);
5244 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5246 return result;
5247}
5248
5250 SgVarArgOp* result = new SgVarArgOp(operand_i, expression_type);
5251 ROSE_ASSERT(result);
5252 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5254 return result;
5255}
5256
5258{
5259 SgMinusMinusOp* result = buildUnaryExpression<SgMinusMinusOp>(operand_i);
5260 ROSE_ASSERT(result);
5261 result->set_mode(a_mode);
5262 return result;
5263}
5264
5266{
5267 SgMinusMinusOp* result = buildUnaryExpression_nfi<SgMinusMinusOp>(operand_i);
5268 ROSE_ASSERT(result);
5269 result->set_mode(a_mode);
5270 return result;
5271}
5272
5274{
5275 SgMinusOp* result = buildUnaryExpression<SgMinusOp>(operand_i);
5276 ROSE_ASSERT(result);
5277 result->set_mode(a_mode);
5278 return result;
5279}
5280
5282{
5283 SgMinusOp* result = buildUnaryExpression_nfi<SgMinusOp>(operand_i);
5284 ROSE_ASSERT(result);
5285 result->set_mode(a_mode);
5286 return result;
5287}
5288
5290{
5291 SgPlusPlusOp* result = buildUnaryExpression<SgPlusPlusOp>(operand_i);
5292 ROSE_ASSERT(result);
5293 result->set_mode(a_mode);
5294 return result;
5295}
5296
5297
5299{
5300 SgPlusPlusOp* result = buildUnaryExpression_nfi<SgPlusPlusOp>(operand_i);
5301 ROSE_ASSERT(result);
5302 result->set_mode(a_mode);
5303 return result;
5304}
5305
5307 {
5308 // DQ (11/8/2011): operand_i is allowed to be NULL.
5309
5310 // SgThrowOp* result = new SgThrowOp(operand_i, operand_i -> get_type(), throwKind);
5311 SgThrowOp* result = new SgThrowOp(operand_i, (operand_i != NULL) ? operand_i->get_type() : NULL, throwKind);
5312
5313 if (operand_i)
5314 {
5315 markLhsValues(result);
5316 }
5317
5319
5320 if (operand_i)
5321 operand_i -> set_parent(result);
5322
5323 ROSE_ASSERT(result);
5324
5325 return result;
5326 }
5327
5328
5329
5330#define BUILD_BINARY_DEF(suffix) \
5331 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix##_nfi(SgExpression* lhs, SgExpression* rhs) \
5332 { \
5333 return buildBinaryExpression_nfi<Sg##suffix>(lhs, rhs); \
5334 } \
5335 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix(SgExpression* lhs, SgExpression* rhs) \
5336 { \
5337 return buildBinaryExpression<Sg##suffix>(lhs, rhs); \
5338 }
5339
5340BUILD_BINARY_DEF(AddOp)
5341BUILD_BINARY_DEF(AndAssignOp)
5342BUILD_BINARY_DEF(AndOp)
5343BUILD_BINARY_DEF(ArrowExp)
5344BUILD_BINARY_DEF(ArrowStarOp)
5345BUILD_BINARY_DEF(AssignOp)
5346BUILD_BINARY_DEF(AtOp)
5347BUILD_BINARY_DEF(BitAndOp)
5348BUILD_BINARY_DEF(BitOrOp)
5349BUILD_BINARY_DEF(BitXorOp)
5350
5351BUILD_BINARY_DEF(CommaOpExp)
5352BUILD_BINARY_DEF(ConcatenationOp)
5353BUILD_BINARY_DEF(DivAssignOp)
5354BUILD_BINARY_DEF(DivideOp)
5355BUILD_BINARY_DEF(DotExp)
5356BUILD_BINARY_DEF(DotStarOp)
5357BUILD_BINARY_DEF(EqualityOp)
5358
5359BUILD_BINARY_DEF(ExponentiationOp)
5360BUILD_BINARY_DEF(ExponentiationAssignOp)
5361BUILD_BINARY_DEF(GreaterOrEqualOp)
5362BUILD_BINARY_DEF(GreaterThanOp)
5363BUILD_BINARY_DEF(IntegerDivideOp)
5364BUILD_BINARY_DEF(IntegerDivideAssignOp)
5365BUILD_BINARY_DEF(IorAssignOp)
5366BUILD_BINARY_DEF(IsOp)
5367BUILD_BINARY_DEF(IsNotOp)
5368
5369BUILD_BINARY_DEF(LessOrEqualOp)
5370BUILD_BINARY_DEF(LessThanOp)
5371BUILD_BINARY_DEF(LshiftAssignOp)
5372BUILD_BINARY_DEF(LshiftOp)
5373
5374BUILD_BINARY_DEF(MembershipOp)
5375BUILD_BINARY_DEF(MinusAssignOp)
5376BUILD_BINARY_DEF(ModAssignOp)
5377BUILD_BINARY_DEF(ModOp)
5378BUILD_BINARY_DEF(MultAssignOp)
5379BUILD_BINARY_DEF(MultiplyOp)
5380
5381BUILD_BINARY_DEF(NotEqualOp)
5382BUILD_BINARY_DEF(NonMembershipOp)
5383BUILD_BINARY_DEF(OrOp)
5384BUILD_BINARY_DEF(PlusAssignOp)
5385BUILD_BINARY_DEF(PntrArrRefExp)
5386BUILD_BINARY_DEF(RemOp)
5387BUILD_BINARY_DEF(RshiftAssignOp)
5388BUILD_BINARY_DEF(JavaUnsignedRshiftAssignOp)
5389
5390BUILD_BINARY_DEF(RshiftOp)
5391BUILD_BINARY_DEF(JavaUnsignedRshiftOp)
5392BUILD_BINARY_DEF(ScopeOp)
5393BUILD_BINARY_DEF(SubtractOp)
5394BUILD_BINARY_DEF(XorAssignOp)
5395
5396BUILD_BINARY_DEF(VarArgCopyOp)
5397BUILD_BINARY_DEF(VarArgStartOp)
5398
5399// CR(07/26/2018): Jovial operators
5400BUILD_BINARY_DEF(ReplicationOp);
5401
5402//SK(08/20/2015): Matlab operators
5403BUILD_BINARY_DEF(PowerOp);
5404BUILD_BINARY_DEF(ElementwisePowerOp);
5405BUILD_BINARY_DEF(ElementwiseMultiplyOp);
5406BUILD_BINARY_DEF(ElementwiseDivideOp);
5407BUILD_BINARY_DEF(LeftDivideOp);
5408BUILD_BINARY_DEF(ElementwiseLeftDivideOp);
5409BUILD_BINARY_DEF(ElementwiseAddOp);
5410BUILD_BINARY_DEF(ElementwiseSubtractOp);
5411
5412// DQ (7/25/2020): Adding C++20 support
5413BUILD_BINARY_DEF(SpaceshipOp)
5414
5415#undef BUILD_BINARY_DEF
5416
5417
5418
5419// CR ( 1/25/2018):
5420// (10/30/2018): Fixed case when this function is called with NULL dim_info object.
5422 {
5423 ROSE_ASSERT(base_type != NULL);
5424
5425 // There must always be a dim_info object for this function. If not, the
5426 // overloaded function must be used to handle it.
5427 if (dim_info == NULL)
5428 {
5429 SgExpression* index = NULL;
5430 return buildArrayType(base_type, index);
5431 }
5432
5433 SgExpression* index = new SgNullExpression();
5434 ROSE_ASSERT(index);
5435 setSourcePosition(index);
5436
5437 SgArrayType* array_type = new SgArrayType(base_type, index);
5438 ROSE_ASSERT(array_type);
5439 ROSE_ASSERT(array_type->get_dim_info() == NULL);
5440
5441 index ->set_parent(array_type);
5442 dim_info->set_parent(array_type);
5443
5444 array_type->set_dim_info(dim_info);
5445 array_type->set_rank(dim_info->get_expressions().size());
5446
5447 return array_type;
5448 }
5449
5450SgArrayType* SageBuilder::buildArrayType(SgType* base_type/*=NULL*/, SgExpression* index/*=NULL*/)
5451{
5452 SgArrayType* result = new SgArrayType(base_type,index);
5453 ASSERT_not_null(result);
5454
5455 if (index != nullptr) {
5456 index->set_parent(result); // important!
5457 }
5458
5459 return result;
5460}
5461
5463{
5464 SgConditionalExp* result = new SgConditionalExp(test, a, b, NULL);
5465 if (test) test->set_parent(result);
5466 if (a) a->set_parent(result);
5467 if (b) b->set_parent(result);
5469 return result;
5470}
5471
5473{
5474 SgConditionalExp* result = new SgConditionalExp(test, a, b, t);
5475 if (test) test->set_parent(result);
5476 if (a) {a->set_parent(result); markLhsValues(a);}
5477 if (b) {b->set_parent(result); markLhsValues(b);}
5479 return result;
5480}
5481
5483{
5485 ROSE_ASSERT(result);
5487 return result;
5488}
5489
5492 ROSE_ASSERT(ne);
5494 return ne;
5495}
5496
5502
5504 SgColonShapeExp* expr = new SgColonShapeExp();
5505 ASSERT_not_null(expr);
5507 return expr;
5508}
5509
5515
5516SgAssignInitializer * SageBuilder::buildAssignInitializer(SgExpression * operand_i /*= NULL*/, SgType * expression_type /* = NULL */)
5517 {
5518 SgAssignInitializer* result = new SgAssignInitializer(operand_i, expression_type);
5519 ROSE_ASSERT(result);
5520 if (operand_i!=NULL)
5521 {
5522 operand_i->set_parent(result);
5523 // set lvalue, it asserts operand!=NULL
5524 markLhsValues(result);
5525 }
5527 return result;
5528 }
5529
5530SgAssignInitializer * SageBuilder::buildAssignInitializer_nfi(SgExpression * operand_i /*= nullptr*/, SgType * expression_type /*=nullptr*/)
5531 {
5532 SgAssignInitializer* result = new SgAssignInitializer(operand_i, expression_type);
5533 ASSERT_not_null(result);
5534 if (operand_i)
5535 {
5536 operand_i->set_parent(result);
5537 // set lvalue, it asserts operand!=NULL
5538 markLhsValues(result);
5539 }
5540
5541 setSourcePosition(result);
5542 result->set_need_paren(false);
5543
5544 return result;
5545 }
5546
5549{
5550 SgAggregateInitializer* result = new SgAggregateInitializer(initializers, type);
5551 ROSE_ASSERT(result);
5552 if (initializers!=NULL)
5553 {
5554 initializers->set_parent(result);
5555 }
5556 result->set_need_explicit_braces(true);
5558 return result;
5559}
5560
5563{
5564 SgAggregateInitializer* result = new SgAggregateInitializer(initializers, type);
5565 ROSE_ASSERT(result);
5566 if (initializers!=NULL)
5567 {
5568 initializers->set_parent(result);
5569 }
5570 result->set_need_explicit_braces(true);
5572 return result;
5573}
5574
5577{
5578 SgCompoundInitializer* result = new SgCompoundInitializer(initializers, type);
5579 ROSE_ASSERT(result);
5580 if (initializers!=NULL)
5581 {
5582 initializers->set_parent(result);
5583 }
5585 return result;
5586}
5587
5590{
5591 SgCompoundInitializer* result = new SgCompoundInitializer(initializers, type);
5592 ROSE_ASSERT(result);
5593 if (initializers!=NULL)
5594 {
5595 initializers->set_parent(result);
5596 }
5598 return result;
5599}
5600
5601// DQ (1/4/2009): Added support for SgConstructorInitializer
5604 SgMemberFunctionDeclaration *declaration/* = NULL*/,
5605 SgExprListExp *args/* = NULL*/,
5606 SgType *expression_type/* = NULL*/,
5607 bool need_name /*= false*/,
5608 bool need_qualifier /*= false*/,
5609 bool need_parenthesis_after_name /*= false*/,
5610 bool associated_class_unknown /*= false*/)
5611 {
5612 // Prototype:
5613 // SgConstructorInitializer (SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type,
5614 // bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown);
5615
5616 //George Vulov (05/24/2011) Modified this assertion to allow for a NULL declaration (in case of implicit constructors)
5617 ROSE_ASSERT(declaration == NULL || declaration->get_associatedClassDeclaration() != NULL);
5618
5619 SgConstructorInitializer* result = new SgConstructorInitializer( declaration, args, expression_type, need_name,
5620 need_qualifier, need_parenthesis_after_name, associated_class_unknown );
5621 ROSE_ASSERT(result != NULL);
5622 if (args != NULL)
5623 {
5624 args->set_parent(result);
5626 }
5627
5629
5630 return result;
5631 }
5632
5633// DQ (1/4/2009): Added support for SgConstructorInitializer
5636 SgMemberFunctionDeclaration *declaration/* = NULL*/,
5637 SgExprListExp *args/* = NULL*/,
5638 SgType *expression_type/* = NULL*/,
5639 bool need_name /*= false*/,
5640 bool need_qualifier /*= false*/,
5641 bool need_parenthesis_after_name /*= false*/,
5642 bool associated_class_unknown /*= false*/)
5643 {
5644 // Prototype:
5645 // SgConstructorInitializer (SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type, bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown);
5646
5647 // DQ (11/7/2011): Fix symetric to the way George did it above.
5648 ROSE_ASSERT(declaration == NULL || declaration->get_associatedClassDeclaration() != NULL);
5649
5650 SgConstructorInitializer* result = new SgConstructorInitializer( declaration, args, expression_type, need_name, need_qualifier, need_parenthesis_after_name, associated_class_unknown );
5651 ROSE_ASSERT(result != NULL);
5652
5654
5655 if (args != NULL)
5656 {
5657 args->set_parent(result);
5658 }
5659
5660 // DQ (11/4/2012): This is required and appears to work fine now.
5661 // DQ (11/23/2011): Fixup the expression list (but this does not appear to work...)
5662 if (result->get_args()->get_startOfConstruct() == NULL)
5663 {
5664 setOneSourcePositionNull(result->get_args());
5665 }
5666
5667 return result;
5668 }
5669
5670// DQ (11/15/2016):Adding support for braced initializer (required for template support).
5674 {
5675 SgBracedInitializer* result = new SgBracedInitializer(initializers, expression_type);
5676 ROSE_ASSERT(result);
5677 if (initializers!=NULL)
5678 {
5679 initializers->set_parent(result);
5680 }
5682 return result;
5683 }
5684
5686 {
5687 SgBracedInitializer* result = new SgBracedInitializer(initializers, expression_type);
5688 ROSE_ASSERT(result);
5689 if (initializers!=NULL)
5690 {
5691 initializers->set_parent(result);
5692 }
5694 return result;
5695 }
5696
5697
5700 {
5701 // SgType* exp_type = NULL;
5702 // if (exp) exp_type = exp->get_type();
5703
5704 SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, NULL);
5705 // SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, exp_type);
5706 ROSE_ASSERT(result);
5707 if (exp)
5708 {
5709 exp->set_parent(result);
5710 markLhsValues(result);
5711 }
5713 return result;
5714 }
5715
5718 {
5719 // SgType* exp_type =NULL;
5720 // if (exp) exp_type = exp->get_type();
5721
5722 SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, NULL);
5723 // SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, exp_type);
5724 ROSE_ASSERT(result);
5725 if (exp)
5726 {
5727 exp->set_parent(result);
5728 markLhsValues(result);
5729 }
5731 return result;
5732 }
5733
5736 {
5737 SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,NULL);
5738 // SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,type);
5739 ROSE_ASSERT(result);
5741 return result;
5742 }
5743
5746 {
5747 SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,NULL);
5748 // SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,type);
5749 ROSE_ASSERT(result);
5751 return result;
5752 }
5753
5756 {
5757 // SgType* exp_type =NULL;
5758 // if (exp) exp_type = exp->get_type();
5759
5760 SgAlignOfOp* result = new SgAlignOfOp(exp,NULL, NULL);
5761 ROSE_ASSERT(result);
5762 if (exp)
5763 {
5764 exp->set_parent(result);
5765 markLhsValues(result);
5766 }
5768 return result;
5769 }
5770
5773 {
5774 // SgType* exp_type =NULL;
5775 // if (exp) exp_type = exp->get_type();
5776
5777 SgAlignOfOp* result = new SgAlignOfOp(exp,NULL, NULL);
5778 ROSE_ASSERT(result);
5779 if (exp)
5780 {
5781 exp->set_parent(result);
5782 markLhsValues(result);
5783 }
5785 return result;
5786 }
5787
5790 {
5791 // SgType* exp_type =NULL;
5792 // if (exp) exp_type = exp->get_type();
5793
5794 SgNoexceptOp* result = new SgNoexceptOp(exp);
5795 ROSE_ASSERT(result);
5796 if (exp)
5797 {
5798 exp->set_parent(result);
5799 markLhsValues(result);
5800 }
5801
5803 return result;
5804 }
5805
5808 {
5809 // SgType* exp_type =NULL;
5810 // if (exp) exp_type = exp->get_type();
5811
5812 SgNoexceptOp* result = new SgNoexceptOp(exp);
5813 ROSE_ASSERT(result);
5814 if (exp)
5815 {
5816 exp->set_parent(result);
5817 markLhsValues(result);
5818 }
5819
5821 return result;
5822 }
5823
5826 {
5827 SgAlignOfOp* result = new SgAlignOfOp((SgExpression*)NULL,type,NULL);
5828 ROSE_ASSERT(result);
5830 return result;
5831 }
5832
5835 {
5836 SgAlignOfOp* result = new SgAlignOfOp((SgExpression*)NULL,type,NULL);
5837 ROSE_ASSERT(result);
5839 return result;
5840 }
5841
5842
5844{
5845 SgExprListExp* expList = new SgExprListExp();
5846 ROSE_ASSERT(expList);
5847
5848// printf ("In SageBuilder::buildExprListExp(SgExpression * expr1, SgExpression* expr2, ...): SgExprListExp* expList = %p \n",expList);
5849
5851 if (expr1) appendExpression(expList, expr1);
5852 if (expr2) appendExpression(expList, expr2);
5853 if (expr3) appendExpression(expList, expr3);
5854 if (expr4) appendExpression(expList, expr4);
5855 if (expr5) appendExpression(expList, expr5);
5856 if (expr6) appendExpression(expList, expr6);
5857 if (expr7) appendExpression(expList, expr7);
5858 if (expr8) appendExpression(expList, expr8);
5859 if (expr9) appendExpression(expList, expr9);
5860 if (expr10) appendExpression(expList, expr10);
5861 return expList;
5862}
5863
5864// CH (5/11/2010): Seems that this function is useful.
5865SgExprListExp * SageBuilder::buildExprListExp(const std::vector<SgExpression*>& exprs)
5866{
5867 SgExprListExp* expList = new SgExprListExp();
5868 ROSE_ASSERT(expList);
5869
5871 for (size_t i = 0; i < exprs.size(); ++i) {
5872 appendExpression(expList, exprs[i]);
5873 }
5874 return expList;
5875}
5876
5878 {
5879 SgExprListExp* expList = new SgExprListExp();
5880 ROSE_ASSERT(expList);
5881
5882 setOneSourcePositionNull(expList);
5883 return expList;
5884 }
5885
5886SgExprListExp * SageBuilder::buildExprListExp_nfi(const std::vector<SgExpression*>& exprs)
5887 {
5888 SgExprListExp* expList = new SgExprListExp();
5889 ROSE_ASSERT(expList != NULL);
5890
5891 setOneSourcePositionNull(expList);
5892 for (size_t i = 0; i < exprs.size(); ++i)
5893 {
5894 appendExpression(expList, exprs[i]);
5895 }
5896
5897 // DQ (4/3/2012): Added test to make sure that the pointers are unique.
5898 testAstForUniqueNodes(expList);
5899
5900 return expList;
5901 }
5902
5905 {
5906 if (lower_bound == NULL)
5907 {
5909 }
5910 if (stride == NULL)
5911 {
5913 }
5914
5915 ROSE_ASSERT(lower_bound);
5916 ROSE_ASSERT(upper_bound);
5917 ROSE_ASSERT(stride);
5918
5919 SgSubscriptExpression* subscript = new SgSubscriptExpression(lower_bound, upper_bound, stride);
5920 ROSE_ASSERT(subscript);
5922
5923 // Set the parents of all the parts of the SgSubscriptExpression
5924 lower_bound->set_parent(subscript);
5925 upper_bound->set_parent(subscript);
5926 stride ->set_parent(subscript);
5927
5928 return subscript;
5929 }
5930
5933 {
5934 ROSE_ASSERT(initname);
5935 if (scope == NULL)
5937
5938 SgVarRefExp *varRef = NULL;
5939 // there is assertion for get_scope() != NULL in get_symbol_from_symbol_table()
5940 SgSymbol* symbol = NULL;
5941 if (initname->get_scope()!=NULL)
5942 symbol = initname->get_symbol_from_symbol_table ();
5943
5944 if (symbol != NULL)
5945 {
5946 varRef = new SgVarRefExp(isSgVariableSymbol(symbol));
5948 ROSE_ASSERT(varRef);
5949 }
5950 else
5951 {
5952 varRef = buildVarRefExp(initname->get_name(), scope);
5953 }
5954
5955 return varRef;
5956 }
5957
5960{
5961 SgName name(varName);
5962 return buildVarRefExp(name,scope);
5963}
5964
5966SageBuilder::buildVarRefExp(const std::string& varName, SgScopeStatement* scope)
5967{
5968 SgName name(varName);
5969 return buildVarRefExp(name,scope);
5970}
5971
5974 {
5975 if (scope == NULL)
5977
5978 SgSymbol* symbol = NULL;
5979 SgVariableSymbol* varSymbol = NULL;
5980
5981 if (scope != NULL)
5982 {
5983 // DQ (12/30/2011): This is a bad idea for C++ since qualified names might indicate different scopes.
5984 // If the scope has been provided then is should be the correct scope.
5985
5986 // DQ (8/16/2013): Modified to use the new API supporting template parameters and template arguments, however
5987 // this should more likely be using lookupVariableSymbolInParentScopes() instead of lookupSymbolInParentScopes().
5988 symbol = lookupVariableSymbolInParentScopes(name,scope);
5989 }
5990
5991 if (symbol != NULL)
5992 {
5993 varSymbol = isSgVariableSymbol(symbol);
5994 }
5995 else
5996 {
5997 // if not found: put fake init name and symbol here and
5998 // waiting for a postProcessing phase to clean it up
5999 // two features: no scope and unknown type for initializedName
6001 name1->set_scope(scope); // buildInitializedName() does not set scope for various reasons
6002 name1->set_parent(scope);
6003 varSymbol = new SgVariableSymbol(name1);
6004 varSymbol->set_parent(scope);
6005 }
6006
6007 if (varSymbol == NULL)
6008 {
6009 printf ("Error: varSymbol == NULL for name = %s \n",name.str());
6010 }
6011 ROSE_ASSERT(varSymbol != NULL);
6012
6013 SgVarRefExp *varRef = new SgVarRefExp(varSymbol);
6015 ROSE_ASSERT(varRef != NULL);
6016
6017 ROSE_ASSERT (isSgVariableSymbol(varRef->get_symbol())->get_declaration()!=NULL);
6018
6019 return varRef;
6020 }
6021
6025 {
6026 SgVariableSymbol* symbol = getFirstVarSym(vardecl);
6027 ROSE_ASSERT(symbol);
6028
6029 return buildVarRefExp(symbol);
6030 }
6031
6032
6035 {
6036 SgVarRefExp *varRef = new SgVarRefExp(sym);
6037 ROSE_ASSERT(varRef);
6038
6040
6041 return varRef;
6042 }
6043
6046 {
6047 SgVarRefExp *varRef = new SgVarRefExp(sym);
6048 ROSE_ASSERT(varRef);
6049
6051
6052 return varRef;
6053 }
6054
6057 {
6058 SgNonrealRefExp * refexp = new SgNonrealRefExp(sym);
6059 ROSE_ASSERT(refexp != NULL);
6061 return refexp;
6062 }
6063
6065
6068SageBuilder::buildOpaqueVarRefExp(const std::string& name,SgScopeStatement* scope/* =NULL */)
6069 {
6070 SgVarRefExp *result = NULL;
6071
6072 if (scope == NULL)
6074 ROSE_ASSERT(scope != NULL);
6075
6076 // DQ (8/16/2013): Modified to use the new API supporting template parameters and template arguments, however
6077 // this should more likely be using lookupVariableSymbolInParentScopes() instead of lookupSymbolInParentScopes().
6078 // SgSymbol * symbol = lookupSymbolInParentScopes(name,scope);
6079 SgSymbol * symbol = lookupVariableSymbolInParentScopes(name,scope);
6080
6081 if (symbol)
6082 {
6083 // Can be the same opaque var ref built before
6084 // cerr<<"Error: trying to build an opaque var ref when the variable is actual explicit!"<<endl;
6085 ROSE_ASSERT(isSgVariableSymbol(symbol));
6086 result = buildVarRefExp(isSgVariableSymbol(symbol));
6087 }
6088 else
6089 {
6090 SgVariableDeclaration* fakeVar = buildVariableDeclaration(name, buildIntType(),NULL, scope);
6091 Sg_File_Info* file_info = fakeVar->get_file_info();
6092
6093 // TGWE (7/16/2014): on the advice of DQ who doesn't like the function at all
6094 fakeVar->set_parent(scope);
6095
6096 file_info->unsetOutputInCodeGeneration ();
6097 SgVariableSymbol* fakeSymbol = getFirstVarSym (fakeVar);
6098 result = buildVarRefExp(fakeSymbol);
6099 }
6100
6101 return result;
6102 } // buildOpaqueVarRefExp()
6103
6104
6105// DQ (9/4/2013): Added support for building compound literals (similar to a SgVarRefExp).
6109 {
6110 SgCompoundLiteralExp *compoundLiteral = new SgCompoundLiteralExp(varSymbol);
6111 ROSE_ASSERT(compoundLiteral != NULL);
6112
6113 setOneSourcePositionNull(compoundLiteral);
6114
6115 return compoundLiteral;
6116 }
6117
6118// DQ (9/4/2013): Added support for building compound literals (similar to a SgVarRefExp).
6122 {
6123 SgCompoundLiteralExp *compoundLiteral = new SgCompoundLiteralExp(varSymbol);
6124 ROSE_ASSERT(compoundLiteral != NULL);
6125
6127
6128 return compoundLiteral;
6129 }
6130
6131
6134{
6135 SgLabelRefExp * result= NULL;
6136 ROSE_ASSERT (s!= NULL);
6137 result = new SgLabelRefExp(s);
6138 ROSE_ASSERT (result != NULL);
6140 return result;
6141}
6142
6145{
6147 if (paraTypeList==NULL) return paraList;
6148
6149 SgTypePtrList typeList = paraTypeList->get_arguments();
6150 SgTypePtrList::iterator i;
6151 for (i=typeList.begin();i!=typeList.end();i++)
6152 {
6154 appendArg(paraList,arg);
6155 }
6156
6157 return paraList;
6158}
6159
6162{
6164 ROSE_ASSERT (paraList);
6165 SgTypePtrList typeList = paraTypeList->get_arguments();
6166 SgTypePtrList::iterator i;
6167 for (i=typeList.begin();i!=typeList.end();i++)
6168 {
6170 appendArg(paraList,arg);
6171 }
6172 return paraList;
6173}
6174
6175// lookup function symbol to create a reference to it
6177SageBuilder::buildFunctionRefExp(const SgName& name,const SgType* funcType, SgScopeStatement* scope /*=NULL*/)
6178{
6179 ASSERT_not_null(funcType); // function type cannot be NULL
6180 SgFunctionType* func_type = isSgFunctionType(const_cast<SgType*>(funcType));
6181 ASSERT_not_null(func_type);
6182
6183 bool isMemberFunc = isSgMemberFunctionType(func_type);
6184
6185 if (scope == nullptr) {
6187 }
6188 ASSERT_not_null(scope);
6189 SgFunctionSymbol* symbol = lookupFunctionSymbolInParentScopes(name,func_type,scope);
6190 if (symbol == nullptr)
6191 // in rare cases when function calls are inserted before any prototypes exist
6192 {
6193 SgType* return_type = func_type->get_return_type();
6194 SgFunctionParameterTypeList * paraTypeList = func_type->get_argument_list();
6195 SgFunctionParameterList *parList = buildFunctionParameterList(paraTypeList);
6196
6197 SgGlobal* globalscope = getGlobalScope(scope);
6198
6199 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
6200
6201 // TODO: consider C++ template functions
6202 SgFunctionDeclaration * funcDecl = nullptr;
6204 {
6205 funcDecl = buildNondefiningFunctionDeclaration_T
6206 <SgProcedureHeaderStatement>(name,return_type,parList,false,globalscope,nullptr,false,nullptr,nullptr,SgStorageModifier::e_default);
6207 }
6208 else
6209 {
6210 funcDecl = buildNondefiningFunctionDeclaration_T
6211 <SgFunctionDeclaration>(name,return_type,parList,false,globalscope,nullptr,false,nullptr,nullptr,SgStorageModifier::e_default);
6212 }
6213
6214 funcDecl->get_declarationModifier().get_storageModifier().setExtern();
6215
6216 symbol = lookupFunctionSymbolInParentScopes(name,func_type,scope);
6217 ASSERT_not_null(symbol);
6218 }
6219 SgFunctionRefExp* func_ref = new SgFunctionRefExp(symbol,func_type);
6221
6222 ASSERT_not_null(func_ref);
6223 return func_ref;
6224}
6225
6227SageBuilder::buildFunctionRefExp(const char* name,const SgType* funcType, SgScopeStatement* scope /*=NULL*/)
6228{
6229 SgName name2(name);
6230 return buildFunctionRefExp(name2,funcType,scope);
6231}
6232
6233// lookup function symbol to create a reference to it
6236{
6237 ROSE_ASSERT(func_decl != NULL);
6238 SgDeclarationStatement* nondef_func = func_decl->get_firstNondefiningDeclaration ();
6239 SgDeclarationStatement* def_func = func_decl->get_definingDeclaration ();
6240 SgSymbol* symbol = NULL;
6241 if (nondef_func != NULL)
6242 {
6243 ROSE_ASSERT(nondef_func!= NULL);
6244 symbol = nondef_func->get_symbol_from_symbol_table();
6245 ROSE_ASSERT( symbol != NULL);
6246 }
6247 // Liao 12/1/2010. It is possible that there is no prototype declarations at all
6248 else if (def_func != NULL)
6249 {
6250 symbol = def_func->get_symbol_from_symbol_table();
6251 }
6252 else
6253 {
6254 std::cerr<<"Fatal error: SageBuilder::buildFunctionRefExp():defining and nondefining declarations for a function cannot be both NULL"<<std::endl;
6255 ROSE_ABORT ();
6256 }
6257 ROSE_ASSERT( symbol != NULL);
6258 return buildFunctionRefExp( isSgFunctionSymbol (symbol));
6259}
6260
6261
6262// lookup function symbol to create a reference to it
6265{
6266 SgFunctionRefExp* func_ref = new SgFunctionRefExp(sym, NULL);
6268 ROSE_ASSERT(func_ref);
6269 return func_ref;
6270}
6271
6272// lookup function symbol to create a reference to it
6275{
6276 SgFunctionRefExp* func_ref = new SgFunctionRefExp(sym, NULL);
6277 setOneSourcePositionNull(func_ref);
6278 ROSE_ASSERT(func_ref);
6279 return func_ref;
6280}
6281
6282// DQ (12/15/2011): Adding template declaration support to the AST.
6285 {
6286 // DQ (2/23/2013): Added assertion.
6287 ROSE_ASSERT(sym != NULL);
6288
6290 ROSE_ASSERT(func_ref != NULL);
6291
6292 setOneSourcePositionNull(func_ref);
6293
6294 // DQ (2/23/2013): Added assertion.
6295 ROSE_ASSERT(func_ref->get_symbol() != NULL);
6296
6297 return func_ref;
6298 }
6299
6300// DQ (12/29/2011): Adding template declaration support to the AST.
6303 {
6304 SgTemplateMemberFunctionRefExp* func_ref = new SgTemplateMemberFunctionRefExp(sym, virtual_call, need_qualifier);
6305 setOneSourcePositionNull(func_ref);
6306 ROSE_ASSERT(func_ref);
6307 return func_ref;
6308 }
6309
6310// lookup member function symbol to create a reference to it
6312SageBuilder::buildMemberFunctionRefExp_nfi(SgMemberFunctionSymbol* sym, bool virtual_call, bool need_qualifier)
6313{
6314 SgMemberFunctionRefExp* func_ref = new SgMemberFunctionRefExp(sym, virtual_call, NULL, need_qualifier);
6315 setOneSourcePositionNull(func_ref);
6316 ROSE_ASSERT(func_ref);
6317 return func_ref;
6318}
6319
6320// lookup member function symbol to create a reference to it
6322SageBuilder::buildMemberFunctionRefExp(SgMemberFunctionSymbol* sym, bool virtual_call, bool need_qualifier)
6323{
6324 SgMemberFunctionRefExp* func_ref = new SgMemberFunctionRefExp(sym, virtual_call, NULL, need_qualifier);
6326 ROSE_ASSERT(func_ref);
6327 return func_ref;
6328}
6329
6330// lookup class symbol to create a reference to it
6333{
6334 SgClassNameRefExp* class_ref = new SgClassNameRefExp(sym);
6335 setOneSourcePositionNull(class_ref);
6336 ROSE_ASSERT(class_ref);
6337 return class_ref;
6338}
6339
6342{
6343 SgClassNameRefExp* class_ref = new SgClassNameRefExp(sym);
6345 ROSE_ASSERT(class_ref);
6346 return class_ref;
6347}
6348
6352{
6353 if (scope == NULL)
6355 ROSE_ASSERT(scope != NULL);
6357
6358 if (symbol==NULL)
6359// in rare cases when function calls are inserted before any prototypes exist
6360 {
6361// assume int return type, and empty parameter list
6362
6363#if 1
6364// DQ (7/26/2012): I am at least temporarily removing this function from the API.
6365// Later if we need it, we can update it to reflect that passing of the new
6366// SgTemplateArgumentPtrList function parameter (part of the new API design).
6367
6368 SgFunctionDeclaration* funcDecl = NULL;
6369 printf ("Error: buildFunctionRefExp(): This function should not be used! \n");
6370 ROSE_ABORT();
6371#else
6372 SgType* return_type = buildIntType();
6374
6375 SgGlobal* globalscope = getGlobalScope(scope);
6376
6377 SgFunctionDeclaration * funcDecl = buildNondefiningFunctionDeclaration(name,return_type,parList,globalscope);
6378#endif
6379
6380 funcDecl->get_declarationModifier().get_storageModifier().setExtern();
6381
6382 symbol = lookupFunctionSymbolInParentScopes(name,scope);
6383 ROSE_ASSERT(symbol);
6384 }
6385
6386 SgFunctionRefExp* func_ref = buildFunctionRefExp(symbol);
6388
6389 ROSE_ASSERT(func_ref);
6390 return func_ref;
6391}
6392
6394SageBuilder::buildFunctionRefExp(const char* name, SgScopeStatement* scope /*=NULL*/)
6395{
6396 SgName name2(name);
6397 return buildFunctionRefExp(name2,scope);
6398}
6399
6400
6403{
6404 SgExprStatement* expStmt = new SgExprStatement(exp);
6405 ROSE_ASSERT(expStmt);
6406 if (exp) exp->set_parent(expStmt);
6408 return expStmt;
6409}
6410
6413{
6414 SgExprStatement* expStmt = new SgExprStatement(exp);
6415 ROSE_ASSERT(expStmt);
6416 if (exp) exp->set_parent(expStmt);
6417 setOneSourcePositionNull(expStmt);
6418 return expStmt;
6419}
6420
6421// DQ (3/27/2015): Added support for SgStatementExpression.
6424{
6425 SgStatementExpression* expStmt = new SgStatementExpression(exp);
6426 ROSE_ASSERT(expStmt);
6427 if (exp) exp->set_parent(expStmt);
6429
6430 return expStmt;
6431}
6432
6433// DQ (3/27/2015): Added support for SgStatementExpression.
6436{
6437 SgStatementExpression* expStmt = new SgStatementExpression(exp);
6438 ROSE_ASSERT(expStmt);
6439 if (exp) exp->set_parent(expStmt);
6440 setOneSourcePositionNull(expStmt);
6441
6442 return expStmt;
6443}
6444
6446SageBuilder::buildFunctionCallExp(const SgName& name, SgType* return_type, SgExprListExp* parameters/*=NULL*/, SgScopeStatement* scope/*=NULL*/)
6447 {
6448 if (scope == nullptr) {
6450 }
6451 ASSERT_not_null(scope);
6452
6453 if (parameters == nullptr) {
6454 parameters = buildExprListExp();
6455 }
6456
6458 SgFunctionType * func_type = buildFunctionType(return_type,typeList);
6459 SgFunctionRefExp* func_ref = buildFunctionRefExp(name,func_type,scope);
6460 SgFunctionCallExp * func_call_expr = new SgFunctionCallExp(func_ref,parameters,func_ref->get_type());
6461 parameters->set_parent(func_call_expr);
6462
6464 ASSERT_not_null(func_call_expr);
6465
6466 return func_call_expr;
6467 }
6468
6469
6472 SgExprListExp* parameters/*=NULL*/)
6473 {
6474 ROSE_ASSERT (sym != NULL);
6475 if (parameters == NULL)
6476 parameters = buildExprListExp();
6477 ROSE_ASSERT (parameters != NULL);
6478
6479 // DQ (8/21/2011): We want to preserve the support for member functions to be built as SgMemberFunctionRefExp.
6480 // This is important for the Java support and the C++ support else we will be lowering all mmember function calls
6481 // to function calls which will be a proble for eht analysis of object oriented languages.
6482 SgFunctionCallExp * func_call_expr = NULL;
6483 SgMemberFunctionSymbol* memberFunctionSymbol = isSgMemberFunctionSymbol(sym);
6484 if (memberFunctionSymbol != NULL)
6485 {
6486 // Note that we can't at this point be sure this is not a virtual function.
6487 bool virtual_call = false;
6488
6489 // Name qualificaiton is handled separately from the setting of this variable (old API).
6490 bool need_qualifier = false;
6491
6492 SgMemberFunctionRefExp* member_func_ref = buildMemberFunctionRefExp(memberFunctionSymbol,virtual_call,need_qualifier);
6493 func_call_expr = new SgFunctionCallExp(member_func_ref,parameters,member_func_ref->get_type());
6494 member_func_ref->set_parent(func_call_expr);
6495 }
6496 else
6497 {
6498 SgFunctionRefExp * func_ref = buildFunctionRefExp(sym);
6499 func_call_expr = new SgFunctionCallExp(func_ref,parameters,func_ref->get_type());
6500 func_ref->set_parent(func_call_expr);
6501 }
6502
6503
6504 parameters->set_parent(func_call_expr);
6505
6507
6508 ROSE_ASSERT(func_call_expr);
6509 return func_call_expr;
6510 }
6511
6514 {
6515 ROSE_ASSERT(f != NULL);
6516 SgFunctionCallExp* func_call_expr = new SgFunctionCallExp(f,parameters,f->get_type());
6517 ROSE_ASSERT(func_call_expr != NULL);
6518
6519 if (f != NULL) {
6520 f->set_parent(func_call_expr);
6521 }
6522 if (parameters != NULL) {
6523 parameters->set_parent(func_call_expr);
6524 }
6525 setOneSourcePositionNull(func_call_expr);
6526
6527 return func_call_expr;
6528 }
6529
6532 {
6533 ROSE_ASSERT(f != NULL);
6534 SgFunctionCallExp * func_call_expr = new SgFunctionCallExp(f,parameters,f->get_type());
6535 ROSE_ASSERT(func_call_expr != NULL);
6536
6537 if (f) f->set_parent(func_call_expr);
6538 if (parameters) parameters->set_parent(func_call_expr);
6540
6541 return func_call_expr;
6542 }
6543
6546 SgType* return_type,
6547 SgExprListExp* parameters /*= NULL*/,
6548 SgScopeStatement* scope /*=NULL*/)
6549{
6550 if (scope == NULL)
6552 ROSE_ASSERT(scope != NULL);
6553 SgFunctionCallExp* func_call_expr = buildFunctionCallExp(name,return_type,parameters,scope);
6554 SgExprStatement * expStmt = buildExprStatement(func_call_expr);
6555 return expStmt;
6556}
6557
6561{
6562 SgFunctionCallExp* func_call_expr = buildFunctionCallExp(function_exp, parameters);
6563 SgExprStatement * expStmt = buildExprStatement(func_call_expr);
6564 return expStmt;
6565}
6566
6567
6569
6577 SgExpression* objectExpression,
6578 std::string functionName,
6579 SgExprListExp* params,
6580 SgScopeStatement* scope
6581 )
6582{
6583 SgClassSymbol* classSymbol = SageInterface::lookupClassSymbolInParentScopes(className, scope);
6584 ROSE_ASSERT(classSymbol);
6585
6586 SgDeclarationStatement* classDecl = classSymbol->get_declaration()->get_definingDeclaration();
6587 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classDecl);
6588 ROSE_ASSERT(classDeclaration != NULL);
6589
6590 SgClassDefinition* classDefinition = classDeclaration->get_definition();
6591 ROSE_ASSERT(classDefinition);
6592
6593 SgSymbol* funsy = lookupFunctionSymbolInParentScopes(functionName, classDefinition);
6594 SgMemberFunctionSymbol* functionSymbol = isSgMemberFunctionSymbol(funsy);
6595 ROSE_ASSERT(functionSymbol);
6596
6597 SgMemberFunctionRefExp* memref = buildMemberFunctionRefExp(functionSymbol, false, false);
6598
6599 return buildFunctionCallExp(buildDotExp(objectExpression, memref), params);
6600}
6601
6602// with known varRef and mem function symbol : a.size()
6604 SgExprListExp* params)
6605{
6606 SgMemberFunctionRefExp* memref = SageBuilder::buildMemberFunctionRefExp(functionSymbol, false, false);
6607 return SageBuilder::buildFunctionCallExp(SageBuilder::buildDotExp(objectExpression, memref), params);
6608}
6609
6611SageBuilder::buildTypeTraitBuiltinOperator(SgName functionName, SgNodePtrList parameters)
6612 {
6613 // DQ (7/14/2013): This is supporting compiler extensions that are required to support type traits in C++.
6614 // These operators are used increasingly in newer versions of GNU and other compilers. They are builtin
6615 // compiler extensions that typically take types as arguments.
6616
6617 SgTypeTraitBuiltinOperator * builtin_func_call_expr = new SgTypeTraitBuiltinOperator(functionName);
6618 ROSE_ASSERT(builtin_func_call_expr != NULL);
6619
6620 SgNodePtrList & args = builtin_func_call_expr->get_args();
6621 for (SgNodePtrList::iterator it = parameters.begin(); it != parameters.end(); ++it) {
6622 args.push_back(*it);
6623 (*it)->set_parent(builtin_func_call_expr);
6624 }
6625
6626 return builtin_func_call_expr;
6627 }
6628
6629
6632 {
6633 ROSE_ASSERT(kernel);
6634 ROSE_ASSERT(parameters);
6635 ROSE_ASSERT(config);
6636
6637 // DQ (1/19/2016): Adding template function ref support.
6638 SgFunctionRefExp * func_ref_exp = isSgFunctionRefExp(kernel);
6639 SgTemplateFunctionRefExp * template_func_ref_exp = isSgTemplateFunctionRefExp(kernel);
6640 if (func_ref_exp == NULL && template_func_ref_exp == NULL)
6641 {
6642 std::cerr << "SgCudaKernelCallExp accept only direct reference to a function. Got, " << typeid(*kernel).name()
6643 << " with, " << kernel->unparseToString() << std::endl;
6644
6645 // PP (7/1/19): experimental support for RAJA/CUDA Lulesh codes (producing SgNonrealRefExp) **1
6646 // was: ROSE_ASSERT(false);
6647 }
6648 // DQ (1/19/2016): Adding template function ref support.
6649 else if ( (func_ref_exp != NULL && func_ref_exp->get_symbol_i()->get_declaration()->get_functionModifier().isCudaKernel() == false) &&
6650 (template_func_ref_exp != NULL && template_func_ref_exp->get_symbol_i()->get_declaration()->get_functionModifier().isCudaKernel() == false) )
6651 {
6652 std::cerr << "To build a SgCudaKernelCallExp the callee needs to be a kernel (having \"__global__\" attribute)." << std::endl;
6653 ROSE_ABORT();
6654 }
6655
6656 SgCudaKernelCallExp * kernel_call_expr = new SgCudaKernelCallExp(kernel, parameters, kernel->get_type(), config);
6657
6658 kernel->set_parent(kernel_call_expr);
6659 parameters->set_parent(kernel_call_expr);
6660 config->set_parent(kernel_call_expr);
6661
6662 setOneSourcePositionNull(kernel_call_expr);
6663
6664 ROSE_ASSERT(kernel_call_expr);
6665
6666 return kernel_call_expr;
6667 }
6668
6671 if (!grid || !blocks) {
6672 std::cerr << "SgCudaKernelExecConfig need fields 'grid' and 'blocks' to be set." << std::endl;
6673 ROSE_ABORT();
6674 }
6675
6676 // TODO-CUDA check types
6677
6678 SgCudaKernelExecConfig * config = new SgCudaKernelExecConfig (grid, blocks, shared, stream);
6679
6680 grid->set_parent(config);
6681 blocks->set_parent(config);
6682 if (shared)
6683 shared->set_parent(config);
6684 if (stream)
6685 stream->set_parent(config);
6686
6688
6689 ROSE_ASSERT(config);
6690
6691 return config;
6692}
6693
6696//SageBuilder::buildAssignStatement(SgExpression* lhs,SgExpression* rhs, SgScopeStatement* scope=NULL)
6697{
6698 ROSE_ASSERT(lhs != NULL);
6699 ROSE_ASSERT(rhs != NULL);
6700
6701 //SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,lhs->get_type());
6702// SgBinaryOp::get_type() assume p_expression_type is not set
6703 SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,NULL);
6704 ROSE_ASSERT(assignOp);
6706 lhs->set_parent(assignOp);
6707 rhs->set_parent(assignOp);
6708
6709 lhs->set_lvalue (true);
6710 SgExprStatement* exp = new SgExprStatement(assignOp);
6711 ROSE_ASSERT(exp);
6712 // some child nodes are transparently generated, using recursive setting is safer
6714 //setOneSourcePositionForTransformation(exp);
6715 assignOp->set_parent(exp);
6716 return exp;
6717}
6718
6719// DQ (8/16/2011): This is an AST translate specific version (see note below).
6720// We would like to phase out the version above if possible (but we want to
6721// test this later).
6724{
6725 ROSE_ASSERT(lhs != NULL);
6726 ROSE_ASSERT(rhs != NULL);
6727
6728 //SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,lhs->get_type());
6729// SgBinaryOp::get_type() assume p_expression_type is not set
6730 SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,NULL);
6731 ROSE_ASSERT(assignOp);
6733 lhs->set_parent(assignOp);
6734 rhs->set_parent(assignOp);
6735
6736 lhs->set_lvalue (true);
6737 SgExprStatement* exp = new SgExprStatement(assignOp);
6738 ROSE_ASSERT(exp);
6739
6740// DQ (8/16/2011): Modified to avoid recursive call to reset source position information
6741// (this version is required for the Java support where we have set source code position
6742// information on the lhs and rhs and we don't want it to be reset as a transformation.
6743// some child nodes are transparently generated, using recursive setting is safer
6745 assignOp->set_parent(exp);
6746 return exp;
6747}
6748
6749
6751{
6752 if (scope == NULL)
6754
6755 // should including current scope when searching for the function definition
6756 // since users can only pass FunctionDefinition when the function body is not yet attached
6757 SgLabelStatement * labelstmt = new SgLabelStatement(name,stmt);
6758 ROSE_ASSERT(labelstmt);
6760
6761 if(stmt!=NULL)
6762 stmt->set_parent(labelstmt);
6763
6764 // Liao 1/7/2010
6765 // SgLabelStatement is used for CONTINUE statement in Fortran
6766 // In this case , it has no inherent association with a Label symbol.
6767 // It is up to the SageInterface::setNumericalLabel(SgStatement*) to handle label symbol
6769 fixLabelStatement(labelstmt,scope);
6770 // we don't want to set parent here yet
6771 // delay it until append_statement() or alike
6772 return labelstmt;
6773}
6774
6776{
6777 SgLabelStatement* labelStmt = new SgLabelStatement(name,stmt);
6778 ASSERT_not_null(labelStmt);
6780
6781 if (stmt != nullptr) {
6782 stmt->set_parent(labelStmt);
6783 }
6784 if (scope) {
6785 fixLabelStatement(labelStmt,scope);
6786 }
6787
6788 // we don't want to set parent here yet
6789 // delay it until append_statement() or alike
6790 return labelStmt;
6791}
6792
6793SgIfStmt * SageBuilder::buildIfStmt(SgStatement* conditional, SgStatement * true_body, SgStatement * false_body)
6794{
6795 ROSE_ASSERT(conditional);
6796 ROSE_ASSERT(true_body);
6797 SgIfStmt *ifstmt = new SgIfStmt(conditional, true_body, false_body);
6798 ROSE_ASSERT(ifstmt);
6799
6800 // CR (3/22/2020): Fixed setting case insensitivity
6801 // if (symbol_table_case_insensitive_semantics == true)
6803 ifstmt->setCaseInsensitive(true);
6804
6806 conditional->set_parent(ifstmt);
6807 true_body->set_parent(ifstmt);
6808 if (false_body != NULL) false_body->set_parent(ifstmt);
6809
6811 {
6812 // Liao 1/20/2010
6813 // According to Fortran 77 standard Chapter 11.5 to 11.9,
6814 // this is a Fortran Block IF statement, if the true body is:
6815 // 1. A block of statement under SgBasicBlock
6816 // 2. DO, block if, or another logical if
6817 // Otherwise it is a logical if statement
6818 if (isSgBasicBlock(true_body)|| isSgFortranDo(true_body)|| isSgIfStmt(true_body))
6819 {
6820 ifstmt->set_use_then_keyword(true);
6821 ifstmt->set_has_end_statement(true);
6822 }
6823 }
6824
6825 return ifstmt;
6826}
6827
6829 {
6830 SgIfStmt *ifstmt = new SgIfStmt(conditional, true_body, false_body);
6831 ROSE_ASSERT(ifstmt);
6832 // DQ (2/13/2012): This allows us to separate the construction from the initialization (see note below).
6833 initializeIfStmt(ifstmt,conditional,true_body,false_body);
6834 return ifstmt;
6835 }
6836
6837// Rasmussen (9/3/2018): Added build function for a Fortran do construct
6839{
6840 if (initialization == nullptr) initialization = buildNullExpression();
6841 if (bound == nullptr) bound = buildNullExpression();
6842 if (increment == nullptr) increment = buildNullExpression();
6843 if (loopBody == nullptr) loopBody = buildBasicBlock();
6844
6845 SgFortranDo* result = new SgFortranDo(initialization, bound, increment, loopBody);
6846 ASSERT_not_null(result);
6847
6849 result->setCaseInsensitive(true);
6850 }
6851
6853
6854 initialization->set_parent(result);
6855 bound->set_parent(result);
6856 increment->set_parent(result);
6857 loopBody->set_parent(result);
6858
6859 return result;
6860}
6861
6863{
6864 if (initialization == nullptr) initialization = buildNullExpression_nfi();
6865 if (bound == nullptr) bound = buildNullExpression_nfi();
6866 if (increment == nullptr) increment = buildNullExpression_nfi();
6867 if (loopBody == nullptr) loopBody = buildBasicBlock_nfi();
6868
6869 SgFortranDo* result = new SgFortranDo(initialization, bound, increment, loopBody);
6870 ASSERT_not_null(result);
6871
6873 result->setCaseInsensitive(true);
6874 }
6875
6877
6878 initialization->set_parent(result);
6879 bound->set_parent(result);
6880 increment->set_parent(result);
6881 loopBody->set_parent(result);
6882
6883 return result;
6884}
6885
6886// charles4 10/14/2011: Vanilla allocation. Use prepend_init_stmt and append_init_stmt to populate afterward.
6888 {
6889 // return new SgForInitStatement();
6890 SgForInitStatement* result = new SgForInitStatement();
6891
6892 // DQ (11/3/2012): Added call to set file info to default settings.
6893 setSourcePosition(result);
6894
6895 return result;
6896 }
6897
6898// DQ (10/12/2012): Added specific API to handle simple (single) statement.
6901 {
6902 SgForInitStatement* forInit = new SgForInitStatement();
6903 ROSE_ASSERT(forInit != NULL);
6904
6905 ROSE_ASSERT(statement != NULL);
6906 forInit->append_init_stmt(statement);
6907
6908 // DQ (11/3/2012): Added call to set file info to default settings.
6909 setSourcePosition(forInit);
6910
6911 return forInit;
6912 }
6913
6914SgForInitStatement * SageBuilder::buildForInitStatement(const SgStatementPtrList & statements)
6915{
6916 SgForInitStatement * result = new SgForInitStatement();
6917 result->get_init_stmt() = statements;
6918
6919 for (SgStatementPtrList::iterator it = result->get_init_stmt().begin(); it != result->get_init_stmt().end(); it++)
6920 (*it)->set_parent(result);
6921
6923 return result;
6924}
6925
6927SageBuilder::buildForInitStatement_nfi(SgStatementPtrList & statements)
6928 {
6929 SgForInitStatement * result = new SgForInitStatement();
6930
6931 result->get_init_stmt() = statements;
6932
6933 for (SgStatementPtrList::iterator it = result->get_init_stmt().begin(); it != result->get_init_stmt().end(); it++)
6934 {
6935 (*it)->set_parent(result);
6936 }
6937
6938 // DQ (11/3/2012): Added call to set file info to default settings.
6939 setSourcePosition(result);
6940
6941 return result;
6942 }
6943
6945//Liao, 8/27/2008
6946SgForStatement * SageBuilder::buildForStatement(SgStatement* initialize_stmt, SgStatement * test, SgExpression * increment, SgStatement * loop_body, SgStatement * else_body)
6947{
6948 SgForStatement * result = new SgForStatement(test,increment, loop_body);
6949 ROSE_ASSERT(result);
6950
6952 result->setCaseInsensitive(true);
6953
6955 if (test)
6956 test->set_parent(result);
6957 if (loop_body)
6958 loop_body->set_parent(result);
6959 if (increment)
6960 increment->set_parent(result);
6961
6962 if (else_body)
6963 else_body->set_parent(result);
6964 result->set_else_body(else_body);
6965
6966 // CH (5/13/2010): If the initialize_stmt is an object of SgForInitStatement, we can directly put it
6967 // into for statement. Or else, there will be two semicolons after unparsing.
6968 if (SgForInitStatement* for_init_stmt = isSgForInitStatement(initialize_stmt))
6969 {
6970 // DQ (7/30/2011): We have to delete the the SgForInitStatement build within the SgForStatement::post_constructor_initialization()
6971 // to avoid causing errors in the AST consistancy checking later.
6972 if (result->get_for_init_stmt() != NULL)
6973 {
6974 delete result->get_for_init_stmt();
6975 result->set_for_init_stmt(NULL);
6976 }
6977
6978 result->set_for_init_stmt(for_init_stmt);
6979 for_init_stmt->set_parent(result);
6980 return result;
6981 }
6982
6983 SgForInitStatement* init_stmt = new SgForInitStatement();
6984 ROSE_ASSERT(init_stmt);
6986
6987 // DQ (7/30/2011): We have to delete the the SgForInitStatement build within the SgForStatement::post_constructor_initialization().
6988 // to avoid causeing errors in the AST consistancy checking later.
6989 if (result->get_for_init_stmt() != NULL)
6990 {
6991 delete result->get_for_init_stmt();
6992 result->set_for_init_stmt(NULL);
6993 }
6994
6995 result->set_for_init_stmt(init_stmt);
6996 init_stmt->set_parent(result);
6997
6998 if (initialize_stmt)
6999 {
7000 init_stmt->append_init_stmt(initialize_stmt);
7001 // Support for "for (int i=0; )", Liao, 3/11/2009
7002 // The symbols are inserted into the symbol table attached to SgForStatement
7003 if (isSgVariableDeclaration(initialize_stmt))
7004 {
7005 fixVariableDeclaration(isSgVariableDeclaration(initialize_stmt),result);
7006 // fix varRefExp to the index variable used in increment, conditional expressions
7007 fixVariableReferences(result);
7008 }
7009 }
7010
7011 return result;
7012 }
7013
7014
7016//Liao, 8/27/2008
7018SageBuilder::buildForStatement_nfi(SgStatement* initialize_stmt, SgStatement * test, SgExpression * increment, SgStatement * loop_body, SgStatement * else_body)
7019 {
7020 SgForStatement * result = new SgForStatement(test, increment, loop_body);
7021 ROSE_ASSERT(result);
7022
7023 // Rasmussen (3/22/2020): Fixed setting case insensitivity
7024 // if (symbol_table_case_insensitive_semantics == true)
7026 result->setCaseInsensitive(true);
7027
7029 if (test) test->set_parent(result);
7030 if (loop_body) loop_body->set_parent(result);
7031 if (increment) increment->set_parent(result);
7032 if (else_body) else_body->set_parent(result);
7033
7034 result->set_else_body(else_body);
7035
7036 if (initialize_stmt != NULL)
7037 {
7038 SgForInitStatement* init_stmt = result->get_for_init_stmt();
7039 ROSE_ASSERT(init_stmt);
7040 setOneSourcePositionNull(init_stmt);
7041 init_stmt->append_init_stmt(initialize_stmt);
7042 initialize_stmt->set_parent(init_stmt);
7043 }
7044
7045 return result;
7046 }
7047
7048
7051 {
7052 SgForStatement * result = new SgForStatement(init_stmt, test, increment, loop_body);
7053 ROSE_ASSERT(result != NULL);
7054
7055 // DQ (9/26/2012): Refactored this function to allow for where the SgForStatement had to be
7056 // constructed early to define the scope for types that can be defined in the SgForInitStatement.
7057 buildForStatement_nfi(result,init_stmt,test,increment,loop_body,else_body);
7058
7059 return result;
7060 }
7061
7062
7063void
7065 {
7066 // DQ (9/26/2012): Refactored this function to allow for where the SgForStatement had to be
7067 // constructed early to define the scope for types that can be defined in the SgForInitStatement.
7068
7069 ROSE_ASSERT(result != NULL);
7070
7071 // DQ (11/4/2012): I have added support for remove existing subtrees if they are different from what is provided as input.
7072 if (result->get_for_init_stmt() != NULL && init_stmt != result->get_for_init_stmt())
7073 {
7074 delete result->get_for_init_stmt();
7075 result->set_for_init_stmt(NULL);
7076 }
7077
7078 if (result->get_test() != NULL && test != result->get_test())
7079 {
7080 delete result->get_test();
7081 result->set_test(NULL);
7082 }
7083
7084 if (result->get_increment() != NULL && increment != result->get_increment())
7085 {
7086 delete result->get_increment();
7087 result->set_increment(NULL);
7088 }
7089
7090 if (result->get_loop_body() != NULL && loop_body != result->get_loop_body())
7091 {
7092 delete result->get_loop_body();
7093 result->set_loop_body(NULL);
7094 }
7095
7096 if (result->get_else_body() != NULL && else_body != result->get_else_body())
7097 {
7098 delete result->get_else_body();
7099 result->set_else_body(NULL);
7100 }
7101
7102 result->set_for_init_stmt(init_stmt);
7103 result->set_test(test);
7104 result->set_increment(increment);
7105 result->set_loop_body(loop_body);
7106
7108 result->setCaseInsensitive(true);
7109
7111 if (test) test->set_parent(result);
7112 if (loop_body) loop_body->set_parent(result);
7113 if (increment) increment->set_parent(result);
7114 if (init_stmt) init_stmt->set_parent(result);
7115 if (else_body) else_body->set_parent(result);
7116
7117 result->set_else_body(else_body);
7118
7119 ROSE_ASSERT(result->get_for_init_stmt() != NULL);
7120 ROSE_ASSERT(result->get_test() != NULL);
7121 ROSE_ASSERT(result->get_increment() != NULL);
7122 ROSE_ASSERT(result->get_loop_body() != NULL);
7123 }
7124
7125
7126// DQ (3/26/2018): Adding support for range based for statement.
7127// SgRangeBasedForStatement* SageBuilder::buildRangeBasedForStatement_nfi(SgVariableDeclaration* initializer, SgExpression* range, SgStatement* body)
7130 SgVariableDeclaration* initializer, SgVariableDeclaration* range,
7131 SgVariableDeclaration* begin_declaration, SgVariableDeclaration* end_declaration,
7132 SgExpression* not_equal_expression, SgExpression* increment_expression,
7133 SgStatement* body)
7134 {
7135 // DQ (6/26/2019): Commented these out so that we could build the SgRangeBasedForStatement before
7136 // building the children, since the scope of the chldren will be the SgRangeBasedForStatement and
7137 // it must exist before the children are constructed.
7138 // ROSE_ASSERT(initializer != NULL);
7139 // ROSE_ASSERT(range != NULL);
7140
7141 // DQ (6/26/2019): This was already commented out.
7142 // ROSE_ASSERT(body != NULL);
7143
7144 SgRangeBasedForStatement* result = new SgRangeBasedForStatement(initializer, range, begin_declaration, end_declaration, not_equal_expression, increment_expression, body);
7145 ROSE_ASSERT(result != NULL);
7146
7148
7149 if (initializer != NULL) initializer->set_parent(result);
7150 if (range != NULL) range->set_parent(result);
7151
7152 if (begin_declaration != NULL) begin_declaration->set_parent(result);
7153 if (end_declaration != NULL) end_declaration->set_parent(result);
7154
7155 if (not_equal_expression != NULL) not_equal_expression->set_parent(result);
7156 if (increment_expression != NULL) increment_expression->set_parent(result);
7157
7158 if (body != NULL) body->set_parent(result);
7159
7160 return result;
7161 }
7162
7163
7164void
7166 {
7167 // DQ (3/22/2014): This function has been built to support reusing an existing SgDoWhileStatement
7168 // that may have been built and pushed onto the stack as part of a top-down construction of the AST.
7169 // It is required in the EDG 4.8 useage because of a change from EDG 4.7 to 4.8 in how blocks are
7170 // handled (end-of-construct entries).
7171
7172 ASSERT_not_null(result);
7173 ASSERT_not_null(body);
7174 ASSERT_not_null(condition);
7175
7176 ASSERT_require(result->get_body() == nullptr);
7177 ASSERT_require(result->get_condition() == nullptr);
7178
7179 result->set_body(body);
7180 result->set_condition(condition);
7181
7182 body->set_parent(result);
7183 condition->set_parent(result);
7184
7186
7187 ASSERT_not_null(result->get_body());
7188 ASSERT_not_null(result->get_condition());
7189
7190 ASSERT_require(result->get_body()->get_parent() == result);
7191 ASSERT_require(result->get_condition()->get_parent() == result);
7192 }
7193
7194
7195
7197//Liao, 8/27/2008
7199{
7200 SgUpcForAllStatement * result = new SgUpcForAllStatement(test,increment, affinity, loop_body);
7201 ROSE_ASSERT(result);
7203 if (test) test->set_parent(result);
7204 if (loop_body) loop_body->set_parent(result);
7205 if (increment) increment->set_parent(result);
7206 if (affinity) affinity->set_parent(result);
7207
7208 if (initialize_stmt != NULL) {
7209 SgForInitStatement* init_stmt = result->get_for_init_stmt();
7210 ROSE_ASSERT(init_stmt);
7211 setOneSourcePositionNull(init_stmt);
7212 init_stmt->append_init_stmt(initialize_stmt);
7213 initialize_stmt->set_parent(init_stmt);
7214 }
7215
7216 return result;
7217}
7218
7219
7221{
7222 SgUpcForAllStatement * result = new SgUpcForAllStatement(init_stmt, test, increment, affinity, loop_body);
7223 ROSE_ASSERT(result);
7224
7225 // CR (3/22/2020): Fixed setting case insensitivity
7226 // if (symbol_table_case_insensitive_semantics == true)
7228 result->setCaseInsensitive(true);
7229
7231 if (test) test->set_parent(result);
7232 if (loop_body) loop_body->set_parent(result);
7233 if (increment) increment->set_parent(result);
7234 if (affinity) affinity->set_parent(result);
7235 if (init_stmt) init_stmt->set_parent(result);
7236
7237 return result;
7238}
7239
7240// DQ (3/3/2013): Added UPC specific build functions.
7243 {
7244 SgUpcNotifyStatement* result = new SgUpcNotifyStatement(exp);
7245
7247
7248 exp->set_parent(result);
7249
7250 ROSE_ASSERT(exp->get_parent() != NULL);
7251
7252 return result;
7253 }
7254
7257 {
7258 SgUpcWaitStatement* result = new SgUpcWaitStatement(exp);
7259
7261
7262 exp->set_parent(result);
7263
7264 ROSE_ASSERT(exp->get_parent() != NULL);
7265
7266 return result;
7267 }
7268
7271 {
7273
7275
7276 exp->set_parent(result);
7277
7278 ROSE_ASSERT(exp->get_parent() != NULL);
7279
7280 return result;
7281 }
7282
7285 {
7287
7289
7290 return result;
7291 }
7292
7293
7294
7295
7297{
7298 ROSE_ASSERT(condition);
7299 ROSE_ASSERT(body);
7300 SgWhileStmt * result = new SgWhileStmt(condition,body);
7301 ROSE_ASSERT(result);
7302
7303 // CR (3/22/2020): Fixed setting case insensitivity
7304 // if (symbol_table_case_insensitive_semantics == true)
7306 result->setCaseInsensitive(true);
7307
7309 condition->set_parent(result);
7310 body->set_parent(result);
7311
7312// DQ (8/10/2011): This is added by Michael to support a Python specific feature.
7313 if (else_body != NULL) {
7314 result->set_else_body(else_body);
7315 else_body->set_parent(result);
7316 }
7317
7318 return result;
7319}
7320
7321
7324 {
7325 SgWhileStmt * result = new SgWhileStmt(condition,body);
7326 ROSE_ASSERT(result);
7327
7328#if 0
7329 // DQ (11/28/2010): Added specification of case insensitivity for Fortran.
7331 result->setCaseInsensitive(true);
7332
7334 if (condition) condition->set_parent(result);
7335 if (body) body->set_parent(result);
7336
7337 // DQ (8/10/2011): This is added by Michael to support a Python specific feature.
7338 if (else_body != NULL)
7339 {
7340 result->set_else_body(else_body);
7341 else_body->set_parent(result);
7342 }
7343#else
7344 // DQ (2/15/2012): This function supports the case where in C++ the condition can include a variable declaration.
7345 initializeWhileStatement(result,condition,body,else_body);
7346#endif
7347
7348 return result;
7349 }
7350
7351
7353{
7354 ROSE_ASSERT(expr != NULL && body != NULL);
7355 SgWithStatement* result = new SgWithStatement(expr, body);
7356 expr->set_parent(result);
7357 body->set_parent(result);
7358
7360 return result;
7361}
7362
7364{
7365 ROSE_ASSERT(expr != NULL && body != NULL);
7366 SgWithStatement* result = new SgWithStatement(expr, body);
7367 expr->set_parent(result);
7368 body->set_parent(result);
7369
7371 return result;
7372}
7373
7375{
7376 ROSE_ASSERT(condition);
7377 ROSE_ASSERT(body);
7378 SgDoWhileStmt * result = new SgDoWhileStmt(body, condition);
7379 ROSE_ASSERT(result);
7381 condition->set_parent(result);
7382 body->set_parent(result);
7383 return result;
7384}
7385
7387{
7388 SgDoWhileStmt * result = new SgDoWhileStmt(body, condition);
7389 ROSE_ASSERT(result);
7391 if (condition) condition->set_parent(result);
7392 if (body) body->set_parent(result);
7393 return result;
7394}
7395
7397{
7398 SgMatlabForStatement* result = new SgMatlabForStatement(loop_index, loop_range, loop_body);
7400
7401 ROSE_ASSERT(result != NULL);
7402
7403 loop_index->set_parent(result);
7404 loop_range->set_parent(result);
7405 loop_body->set_parent(result);
7406 return result;
7407}
7408
7410{
7411 SgBreakStmt* result = new SgBreakStmt();
7412 ROSE_ASSERT(result);
7414 return result;
7415}
7416
7418{
7419 SgBreakStmt* result = new SgBreakStmt();
7420 ROSE_ASSERT(result);
7422 return result;
7423}
7424
7426{
7427 SgContinueStmt* result = new SgContinueStmt();
7428 ASSERT_not_null(result);
7430 return result;
7431}
7432
7434{
7435 SgContinueStmt* result = new SgContinueStmt();
7436 ASSERT_not_null(result);
7438 return result;
7439}
7440
7442{
7444 ASSERT_not_null(result);
7446 return result;
7447}
7448
7450{
7452 ASSERT_not_null(result);
7454 return result;
7455}
7456
7458{
7459 SgPassStatement* result = new SgPassStatement();
7460 ROSE_ASSERT(result);
7462 return result;
7463}
7464
7466{
7467 SgPassStatement* result = new SgPassStatement();
7468 ROSE_ASSERT(result);
7470 return result;
7471}
7472
7473SgDeleteExp* SageBuilder::buildDeleteExp(SgExpression *target, bool is_array, bool need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
7474{
7475 SgDeleteExp *result = new SgDeleteExp(target, is_array, need_global_specifier, deleteOperatorDeclaration);
7476 target->set_parent(result);
7478 return result;
7479}
7480
7481SgDeleteExp* SageBuilder::buildDeleteExp_nfi(SgExpression *target, bool is_array, bool need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
7482{
7483 SgDeleteExp *result = new SgDeleteExp(target, is_array, need_global_specifier, deleteOperatorDeclaration);
7484 target->set_parent(result);
7486 return result;
7487}
7488
7490{
7491 SgAssertStmt* result = new SgAssertStmt(test);
7492 ROSE_ASSERT(test != NULL);
7493 test->set_parent(result);
7495 return result;
7496}
7497
7498// DQ (7/18/2011): Added support for SgJavaInstanceOfOp
7501 {
7502 SgType* exp_type = SgTypeBool::createType();
7503
7504 SgJavaInstanceOfOp* result = new SgJavaInstanceOfOp(exp, type, exp_type);
7505 ROSE_ASSERT(result);
7506 if (exp != NULL)
7507 {
7508 exp->set_parent(result);
7509 markLhsValues(result);
7510 }
7511
7513 return result;
7514 }
7515
7517{
7518 SgAssertStmt* result = new SgAssertStmt(test);
7519 ROSE_ASSERT(test != NULL);
7520 test->set_parent(result);
7521 if (exceptionArgument != NULL) {
7522 result -> set_exception_argument(exceptionArgument);
7523 exceptionArgument->set_parent(result);
7524 }
7526 return result;
7527}
7528
7530{
7531 SgAssertStmt* result = new SgAssertStmt(test);
7532 ROSE_ASSERT(test != NULL);
7533 test->set_parent(result);
7535 return result;
7536}
7537
7539{
7540 ROSE_ASSERT(value != NULL);
7541 SgYieldExpression* result = new SgYieldExpression(value);
7542 value->set_parent(result);
7544 return result;
7545}
7546
7548{
7549 ROSE_ASSERT(value != NULL);
7550 SgYieldExpression* result = new SgYieldExpression(value);
7551 value->set_parent(result);
7553 return result;
7554}
7555
7557{
7558 ROSE_ASSERT(key != NULL && datum != NULL);
7559 SgKeyDatumPair *result = new SgKeyDatumPair(key, datum);
7560 key->set_parent(result);
7561 datum->set_parent(result);
7563 return result;
7564}
7565
7567{
7568 ROSE_ASSERT(key != NULL && datum != NULL);
7569 SgKeyDatumPair *result = new SgKeyDatumPair(key, datum);
7570 key->set_parent(result);
7571 datum->set_parent(result);
7573 return result;
7574}
7575
7576SgDictionaryExp* SageBuilder::buildDictionaryExp(std::vector<SgKeyDatumPair*> pairs)
7577{
7578 SgDictionaryExp *result = new SgDictionaryExp();
7579 ROSE_ASSERT(result);
7580 for (size_t i = 0; i < pairs.size(); ++i)
7581 result->append_pair(pairs[i]);
7583 return result;
7584}
7585
7586SgDictionaryExp* SageBuilder::buildDictionaryExp_nfi(std::vector<SgKeyDatumPair*> pairs)
7587{
7588 SgDictionaryExp *result = new SgDictionaryExp();
7589 ROSE_ASSERT(result);
7590 for (size_t i = 0; i < pairs.size(); ++i)
7591 result->append_pair(pairs[i]);
7593 return result;
7594}
7595
7598{
7599 ROSE_ASSERT(target != NULL);
7600 ROSE_ASSERT(iter != NULL);
7601 SgComprehension *result = new SgComprehension(target, iter, ifs);
7602 ROSE_ASSERT(result);
7603
7604 target->set_parent(result);
7605 iter->set_parent(result);
7606 if (ifs != NULL) ifs->set_parent(result);
7607
7609 return result;
7610}
7611
7614{
7615 ROSE_ASSERT(target != NULL);
7616 ROSE_ASSERT(iter != NULL);
7617 SgComprehension *result = new SgComprehension(target, iter, ifs);
7618 ROSE_ASSERT(result);
7619 target->set_parent(result);
7620 iter->set_parent(result);
7621 if (ifs != NULL) ifs->set_parent(result);
7623 return result;
7624}
7625
7628{
7629 ROSE_ASSERT(elt != NULL);
7630 ROSE_ASSERT(generators != NULL);
7631 SgListComprehension* result = new SgListComprehension(elt, generators);
7632 elt->set_parent(result);
7633 generators->set_parent(result);
7635 return result;
7636}
7637
7640{
7641 ROSE_ASSERT(elt != NULL);
7642 ROSE_ASSERT(generators != NULL);
7643 SgListComprehension* result = new SgListComprehension(elt, generators);
7644 elt->set_parent(result);
7645 generators->set_parent(result);
7647 return result;
7648}
7649
7652{
7653 ROSE_ASSERT(elt != NULL);
7654 ROSE_ASSERT(generators != NULL);
7655 SgSetComprehension* result = new SgSetComprehension(elt, generators);
7656 elt->set_parent(result);
7657 generators->set_parent(result);
7659 return result;
7660}
7661
7664{
7665 ROSE_ASSERT(elt != NULL);
7666 ROSE_ASSERT(generators != NULL);
7667 SgSetComprehension* result = new SgSetComprehension(elt, generators);
7668 elt->set_parent(result);
7669 generators->set_parent(result);
7671 return result;
7672}
7673
7676{
7677 ROSE_ASSERT(kd_pair != NULL);
7678 ROSE_ASSERT(generators != NULL);
7679 SgDictionaryComprehension* result = new SgDictionaryComprehension(kd_pair, generators);
7680 kd_pair->set_parent(result);
7681 generators->set_parent(result);
7683 return result;
7684}
7685
7688{
7689 ROSE_ASSERT(kd_pair != NULL);
7690 ROSE_ASSERT(generators != NULL);
7691 SgDictionaryComprehension* result = new SgDictionaryComprehension(kd_pair, generators);
7692 kd_pair->set_parent(result);
7693 generators->set_parent(result);
7695 return result;
7696}
7697
7700 ROSE_ASSERT(arg != NULL);
7701 SgActualArgumentExpression* result = new SgActualArgumentExpression(arg_name, arg);
7702 arg->set_parent(result);
7704 return result;
7705}
7706
7709 ROSE_ASSERT(arg != NULL);
7710 SgActualArgumentExpression* result = new SgActualArgumentExpression(arg_name, arg);
7711 arg->set_parent(result);
7713 return result;
7714}
7715
7718 {
7719 if (scope == NULL)
7721
7722 SgPragma* pragma = new SgPragma(name);
7723 ROSE_ASSERT(pragma);
7724
7726
7727 SgPragmaDeclaration* result = new SgPragmaDeclaration(pragma);
7728 ROSE_ASSERT(result);
7729
7731
7732 result->set_definingDeclaration (result);
7733 result->set_firstNondefiningDeclaration(result);
7734 pragma->set_parent(result);
7735
7736 // DQ (7/14/2012): Set the parent so that we can be consistent where possible (class declarations and
7737 // enum declaration can't have there parent set since they could be non-autonomous declarations).
7738 result->set_parent(scope);
7739
7740 if (scope || topScopeStack())
7741 ROSE_ASSERT(result->get_parent() != NULL);
7742
7743 return result;
7744 }
7745
7747SgPragma* SageBuilder::buildPragma(const std::string & name)
7748{
7749 SgPragma* result= new SgPragma(name);
7750 ROSE_ASSERT(result);
7752 return result;
7753}
7754
7755
7757 {
7758 // Build an empty declaration (useful for adding precission to comments and CPP handling under token-based unparsing).
7759 SgEmptyDeclaration* emptyDeclaration = new SgEmptyDeclaration();
7760 ROSE_ASSERT(emptyDeclaration != NULL);
7761
7762 setOneSourcePositionForTransformation(emptyDeclaration);
7763
7764 emptyDeclaration->set_definingDeclaration (emptyDeclaration);
7765 emptyDeclaration->set_firstNondefiningDeclaration(emptyDeclaration);
7766
7767 // DQ (7/14/2012): Set the parent so that we can be consistent where possible (class declarations and
7768 // enum declaration can't have there parent set since they could be non-autonomous declarations).
7769 emptyDeclaration->set_parent(topScopeStack());
7770
7771 if (topScopeStack() != NULL)
7772 {
7773 ROSE_ASSERT(emptyDeclaration->get_parent() != NULL);
7774 }
7775
7776 return emptyDeclaration;
7777 }
7778
7779
7781{
7782 SgBasicBlock* result = new SgBasicBlock();
7783 ROSE_ASSERT(result);
7784
7785 // CR (3/22/2020): Fixed setting case insensitivity
7786 // if (symbol_table_case_insensitive_semantics == true)
7788 result->setCaseInsensitive(true);
7789
7791 if (stmt1) SageInterface::appendStatement(stmt1, result);
7792 if (stmt2) SageInterface::appendStatement(stmt2, result);
7793 if (stmt3) SageInterface::appendStatement(stmt3, result);
7794 if (stmt4) SageInterface::appendStatement(stmt4, result);
7795 if (stmt5) SageInterface::appendStatement(stmt5, result);
7796 if (stmt6) SageInterface::appendStatement(stmt6, result);
7797 if (stmt7) SageInterface::appendStatement(stmt7, result);
7798 if (stmt8) SageInterface::appendStatement(stmt8, result);
7799 if (stmt9) SageInterface::appendStatement(stmt9, result);
7800 if (stmt10) SageInterface::appendStatement(stmt10, result);
7801
7802 return result;
7803}
7804
7806 {
7807 SgBasicBlock* result = new SgBasicBlock();
7808 ROSE_ASSERT(result);
7809
7810 // CR (3/22/2020): Fixed setting case insensitivity
7811 // if (symbol_table_case_insensitive_semantics == true)
7813 {
7814 result->setCaseInsensitive(true);
7815 }
7816
7818
7819#if 0
7820 printf ("In buildBasicBlock_nfi(): returning result = %p \n",result);
7821#endif
7822
7823 return result;
7824 }
7825
7826SgBasicBlock* SageBuilder::buildBasicBlock_nfi(const vector<SgStatement*>& stmts)
7827 {
7829 appendStatementList(stmts, result);
7830
7831#if 0
7832 printf ("In buildBasicBlock_nfi(const vector<SgStatement*>& stmts): returning result = %p \n",result);
7833#endif
7834
7835#if 0
7836 printf ("Exiting as a test! \n");
7837 ROSE_ABORT();
7838#endif
7839
7840 return result;
7841 }
7842
7843// CR (7/24/2020): Added additional functionality.
7844// Build a SgBasicBlock and set its parent. This function does NOT link the parent scope to the block.
7847{
7849 block->set_parent(parent);
7850
7851 return block;
7852}
7853
7854
7857{
7858 SgGotoStatement* result = new SgGotoStatement(label);
7859 ROSE_ASSERT(result);
7861 return result;
7862}
7863
7866{
7867 SgGotoStatement* result = NULL;
7868 ROSE_ASSERT (symbol != NULL);
7870 { // Fortran case
7871 result = buildGotoStatement((SgLabelStatement *)NULL);
7872 SgLabelRefExp* l_exp = buildLabelRefExp(symbol);
7873 l_exp->set_parent(result);
7874 result->set_label_expression(l_exp);
7875 }
7876 else // C/C++ case
7877 {
7878 SgLabelStatement* l_stmt = isSgLabelStatement(symbol->get_declaration());
7879 ROSE_ASSERT (l_stmt != NULL);
7880 result = buildGotoStatement(l_stmt);
7881 }
7882 ROSE_ASSERT(result);
7883 return result;
7884}
7885
7888{
7889 SgGotoStatement* result = new SgGotoStatement(label);
7890 ROSE_ASSERT(result);
7892 return result;
7893}
7894
7895// DQ (11/22/2017): Added support for computed code goto as defined by GNU C/C++ extension.
7898 {
7899 SgLabelStatement* label = NULL;
7900 SgGotoStatement* result = new SgGotoStatement(label);
7901 result->set_selector_expression(label_expression);
7902 ROSE_ASSERT(result);
7904 return result;
7905 }
7906
7909{
7910 // Liao 2/6/2013. We no longer allow NULL express pointer. Use SgNullExpression instead.
7911 // CR (4/27/18): The expression argument to the builder function is optional
7912 // (NULL is allowed). What is not allowed is constructing an SgReturnStmt with a NULL
7913 // expression argument.
7914 if (expression == NULL)
7915 {
7916 expression = buildNullExpression();
7917 }
7918 SgReturnStmt * result = new SgReturnStmt(expression);
7919 ROSE_ASSERT(result);
7920 if (expression != NULL) expression->set_parent(result);
7922 return result;
7923}
7924
7927{
7928 SgReturnStmt * result = new SgReturnStmt(expression);
7929 ROSE_ASSERT(result);
7930 if (expression != NULL) expression->set_parent(result);
7932 return result;
7933}
7934
7936{
7937 SgCaseOptionStmt* result = new SgCaseOptionStmt(key,body);
7938 ROSE_ASSERT(result);
7940 if (key) key->set_parent(result);
7941 if (body) body->set_parent(result);
7942 return result;
7943}
7944
7946{
7947 SgCaseOptionStmt* result = new SgCaseOptionStmt(key,body);
7948 ROSE_ASSERT(result);
7950 if (key) key->set_parent(result);
7951 if (body) body->set_parent(result);
7952 return result;
7953}
7954
7956{
7957 SgDefaultOptionStmt* result = new SgDefaultOptionStmt(body);
7958 ROSE_ASSERT(result);
7960 if (body) body->set_parent(result);
7961
7962#if 0
7963 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7964 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7965 printf ("SageBuilder::buildDefaultOptionStmt() body = %p \n",body);
7966 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7967 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7968#endif
7969
7970 return result;
7971}
7972
7974{
7975 SgDefaultOptionStmt* result = new SgDefaultOptionStmt(body);
7976 ROSE_ASSERT(result);
7978 if (body) body->set_parent(result);
7979
7980#if 0
7981 static int count = 0;
7982
7983 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7984 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7985 printf ("SageBuilder::buildDefaultOptionStmt_nfi() body = %p \n",body);
7986 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7987 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7988
7989 if (count >= 1)
7990 {
7991 printf ("Exiting as a test! \n");
7992 ROSE_ASSERT(false);
7993 }
7994 count++;
7995#endif
7996
7997 return result;
7998}
7999
8001{
8002 SgSwitchStatement* result = new SgSwitchStatement(item_selector,body);
8003 ROSE_ASSERT(result);
8004
8005 // CR (3/22/2020): Fixed setting case insensitivity
8006 // if (symbol_table_case_insensitive_semantics == true)
8008 result->setCaseInsensitive(true);
8009
8011 if (item_selector) item_selector->set_parent(result);
8012 if (body) body->set_parent(result);
8013 return result;
8014}
8015
8018 {
8019 SgSwitchStatement* result = new SgSwitchStatement(item_selector,body);
8020 ROSE_ASSERT(result);
8021
8022#if 0
8023 // DQ (11/28/2010): Added specification of case insensitivity for Fortran.
8025 result->setCaseInsensitive(true);
8026
8028 if (item_selector) item_selector->set_parent(result);
8029 if (body) body->set_parent(result);
8030#else
8031 // DQ (2/15/2012): Modified to handle C++ case where variable declarations are allowed in the condition.
8032 initializeSwitchStatement(result,item_selector,body);
8033#endif
8034
8035 return result;
8036 }
8037
8040{
8041 SgNullStatement* result = NULL;
8042 result = new SgNullStatement();
8043 ROSE_ASSERT(result);
8045 return result;
8046}
8047
8050{
8051 SgNullStatement* result = NULL;
8052 result = new SgNullStatement();
8053 ROSE_ASSERT(result);
8055 return result;
8056}
8057
8060 SgExpression* globals,
8061 SgExpression* locals) {
8062 if (locals != NULL && globals == NULL)
8063 ROSE_ASSERT(!"buildExecStatement with non-NULL locals requires non-NULL globals");
8064 ROSE_ASSERT(executable != NULL);
8065
8066 SgExecStatement* result = new SgExecStatement(executable, globals, locals);
8067 executable->set_parent(result);
8068 if (globals != NULL) globals->set_parent(result);
8069 if (locals != NULL) locals->set_parent(result);
8070
8072 return result;
8073}
8074
8077 SgExpression* globals,
8078 SgExpression* locals) {
8079 if (locals != NULL && globals == NULL)
8080 ROSE_ASSERT(!"buildExecStatement with non-NULL locals requires non-NULL globals");
8081 ROSE_ASSERT(executable != NULL);
8082
8083 SgExecStatement* result = new SgExecStatement(executable, globals, locals);
8084 executable->set_parent(result);
8085 if (globals != NULL) globals->set_parent(result);
8086 if (locals != NULL) locals->set_parent(result);
8087
8089 return result;
8090}
8091
8092// MH (6/10/2014): Added async support
8094{
8095 ROSE_ASSERT(body != NULL);
8096 SgAsyncStmt *async_stmt = new SgAsyncStmt(body);
8097 ROSE_ASSERT(async_stmt);
8098 body->set_parent(async_stmt);
8100
8101 return async_stmt;
8102}
8103
8104// MH (6/11/2014): Added finish support
8106{
8107 ROSE_ASSERT(body != NULL);
8108 SgFinishStmt *finish_stmt = new SgFinishStmt(body);
8109 ROSE_ASSERT(finish_stmt);
8110 body->set_parent(finish_stmt);
8112
8113 return finish_stmt;
8114}
8115
8116// MH (6/11/2014): Added at support
8118{
8119 ROSE_ASSERT(expression);
8120 ROSE_ASSERT(body);
8121 SgAtStmt *at_stmt = new SgAtStmt(expression, body);
8123 expression->set_parent(at_stmt);
8124 body->set_parent(at_stmt);
8125
8126 return at_stmt;
8127}
8128
8129// MH (11/12/2014): Added atomic support
8131{
8132 ROSE_ASSERT(body != NULL);
8133 SgAtomicStmt *atomic_stmt = new SgAtomicStmt(body);
8134 ROSE_ASSERT(atomic_stmt);
8135 body->set_parent(atomic_stmt);
8137
8138 return atomic_stmt;
8139}
8140
8141
8143{
8144 ROSE_ASSERT(expression);
8145 ROSE_ASSERT(body);
8146 SgWhenStmt *when_stmt = new SgWhenStmt(expression, body);
8148 expression->set_parent(when_stmt);
8149 body->set_parent(when_stmt);
8150
8151 return when_stmt;
8152}
8153
8154// MH (9/14/2014): Added atexpr support
8156{
8157 ROSE_ASSERT(expression);
8158 ROSE_ASSERT(body);
8159 SgAtExp *at_exp = new SgAtExp(expression, body);
8161 expression->set_parent(at_exp);
8162 body->set_parent(at_exp);
8163
8164 return at_exp;
8165}
8166
8167// MH (11/7/2014): Added finish expression support
8169{
8170 ROSE_ASSERT(expression);
8171 ROSE_ASSERT(body);
8172 SgFinishExp *finish_exp = new SgFinishExp(expression, body);
8174 expression->set_parent(finish_exp);
8175 body->set_parent(finish_exp);
8176
8177 return finish_exp;
8178}
8179
8181{
8182 SgHereExp *here = new SgHereExp(NULL);
8183 return here;
8184}
8185
8187{
8188 SgDotDotExp *dotdot = new SgDotDotExp(NULL);
8189 return dotdot;
8190}
8191
8192
8195 SgCatchOptionStmt* catch0,
8196 SgCatchOptionStmt* catch1,
8197 SgCatchOptionStmt* catch2,
8198 SgCatchOptionStmt* catch3,
8199 SgCatchOptionStmt* catch4
8200 )
8201 {
8202 ROSE_ASSERT(body != NULL);
8203 SgTryStmt* try_stmt = new SgTryStmt(body);
8204 body->set_parent(try_stmt);
8205
8206 // DQ (11/3/2012): Added setting default source position info.
8207 setSourcePosition(try_stmt);
8208
8209 if (try_stmt->get_catch_statement_seq_root() != NULL)
8210 {
8211 if (try_stmt->get_catch_statement_seq_root()->get_startOfConstruct() == NULL)
8212 {
8213 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_endOfConstruct() == NULL);
8215 }
8216
8217 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_startOfConstruct() != NULL);
8218 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_endOfConstruct() != NULL);
8219 }
8220
8221 if (catch0 != NULL) try_stmt->append_catch_statement(catch0);
8222 if (catch1 != NULL) try_stmt->append_catch_statement(catch1);
8223 if (catch2 != NULL) try_stmt->append_catch_statement(catch2);
8224 if (catch3 != NULL) try_stmt->append_catch_statement(catch3);
8225 if (catch4 != NULL) try_stmt->append_catch_statement(catch4);
8226
8227 return try_stmt;
8228 }
8229
8230
8231// charles4 09/16/2011
8234 {
8235 //
8236 // charles4 09/23/2011 - Note that when an SgTryStmt is allocated, its constructor
8237 // preallocates a SgCatchStementSeq for the field p_catch_statement_sequence_root.
8238 // So, although the method set_catch_statement_seq_root(catch_statement_sequence) is
8239 // available, it should not be used to set the catch_statement_sequence_root as that
8240 // would leave the one that was allocated by the constructor dangling!
8241 //
8242 ROSE_ASSERT(try_body != NULL);
8243 SgTryStmt* try_stmt = new SgTryStmt(try_body);
8244 try_body -> set_parent(try_stmt);
8245
8246 // DQ (11/3/2012): Added setting default source position info.
8247 setSourcePosition(try_stmt);
8248
8249 if (finally_body) {
8250 try_stmt -> set_finally_body(finally_body);
8251 finally_body -> set_parent(try_stmt);
8252 }
8253
8254 return try_stmt;
8255}
8256
8257// charles4 09/16/2011
8258// ! Build an initial sequence of Catch blocks containing 0 or 1 element.
8260 SgCatchStatementSeq *catch_statement_sequence = new SgCatchStatementSeq();
8261
8262 // DQ (11/3/2012): Added setting default source position info.
8263 setSourcePosition(catch_statement_sequence);
8264
8265 if (catch_option_stmt) {
8266 catch_statement_sequence -> append_catch_statement(catch_option_stmt);
8267 catch_option_stmt -> set_parent(catch_statement_sequence);
8268 }
8269
8270 return catch_statement_sequence;
8271}
8272
8273// charles4 09/21/2011 - Make condition and body arguments optional.
8276 SgCatchOptionStmt* result = new SgCatchOptionStmt(condition, body, /* SgTryStmt*= */ NULL);
8277 if (condition) condition->set_parent(result);
8278 if (body) body->set_parent(result);
8280 return result;
8281}
8282
8284{
8285 ROSE_ASSERT(expression);
8286 ROSE_ASSERT(body);
8287 SgJavaSynchronizedStatement *sync_stmt = new SgJavaSynchronizedStatement(expression, body);
8289
8290 expression->set_parent(sync_stmt);
8291 body->set_parent(sync_stmt);
8292
8293 return sync_stmt;
8294}
8295
8297{
8298 ROSE_ASSERT(op);
8299 SgJavaThrowStatement *throw_stmt = new SgJavaThrowStatement(op);
8300 ROSE_ASSERT(throw_stmt);
8301
8302 op->set_parent(throw_stmt);
8303
8304 return throw_stmt;
8305}
8306
8307// DQ (9/3/2011): Changed the API to conform to the Java grammar.
8308// SgJavaForEachStatement *SageBuilder::buildJavaForEachStatement(SgInitializedName *variable, SgExpression *collection, SgStatement *body)
8310{
8311 SgJavaForEachStatement *foreach_stmt = new SgJavaForEachStatement(variable, collection, body);
8312 ROSE_ASSERT(foreach_stmt);
8313 if (variable) variable -> set_parent(foreach_stmt);
8314 if (collection) collection -> set_parent(foreach_stmt);
8315 if (body) body -> set_parent(foreach_stmt);
8316
8317 return foreach_stmt;
8318}
8319
8321{
8322 SgJavaLabelStatement *label_stmt = new SgJavaLabelStatement(name, stmt);
8323 ROSE_ASSERT(label_stmt);
8325
8326 if (stmt != NULL)
8327 stmt -> set_parent(label_stmt);
8328
8329 SgJavaLabelSymbol *lsymbol = label_stmt -> lookup_java_label_symbol(name);
8330 if (! lsymbol) // Should be an Assertion - always true!
8331 {
8332 lsymbol= new SgJavaLabelSymbol(label_stmt);
8333 ROSE_ASSERT(lsymbol);
8334 label_stmt -> insert_symbol(lsymbol -> get_name(), lsymbol);
8335 }
8336
8337 return label_stmt;
8338}
8339
8342 SgPythonPrintStmt* result = new SgPythonPrintStmt(dest, values);
8343 if (dest) dest->set_parent(result);
8344 if (values) values->set_parent(result);
8346 return result;
8347}
8348
8351 SgPythonPrintStmt* result = new SgPythonPrintStmt(dest, values);
8352 if (dest) dest->set_parent(result);
8353 if (values) values->set_parent(result);
8355 return result;
8356}
8357
8359SageBuilder::buildPythonGlobalStmt(SgInitializedNamePtrList& names) {
8360 SgPythonGlobalStmt* result = new SgPythonGlobalStmt();
8361 for (SgInitializedName* name: names) {
8362 result->append_name(name);
8363 }
8365 return result;
8366}
8367
8369SageBuilder::buildPythonGlobalStmt_nfi(SgInitializedNamePtrList& names) {
8370 SgPythonGlobalStmt* result = new SgPythonGlobalStmt();
8371 for (SgInitializedName* name: names) {
8372 result->append_name(name);
8373 }
8375 return result;
8376}
8377
8378// DQ (4/30/2010): Added support for building asm statements.
8381{
8382 SgAsmStmt* result = NULL;
8383 result = new SgAsmStmt();
8384 ROSE_ASSERT(result);
8385 result->set_assemblyCode(s);
8387 return result;
8388}
8389
8390// DQ (4/30/2010): Added support for building asm statements.
8393{
8394 SgAsmStmt* result = NULL;
8395 result = new SgAsmStmt();
8396 ROSE_ASSERT(result);
8397 result->set_assemblyCode(s);
8399 return result;
8400}
8401
8402SgAsmStmt*
8404 {
8405// Multi-byte NOP instructions.
8406// Note: I can't seem to get the memonic versions to work properly
8407#define NOP_1_BYTE_STRING "nop"
8408#define NOP_2_BYTE_STRING ".byte 0x66,0x90"
8409#define NOP_3_BYTE_STRING "nopl (%eax)"
8410#define NOP_4_BYTE_STRING "nopl 0x01(%eax)"
8411#define NOP_5_BYTE_STRING ".byte 0x0f,0x1f,0x44,0x00,0x00"
8412#define NOP_6_BYTE_STRING ".byte 0x66,0x0f,0x1f,0x44,0x00,0x00"
8413#define NOP_7_BYTE_STRING ".byte 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00"
8414#define NOP_8_BYTE_STRING ".byte 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00"
8415#define NOP_9_BYTE_STRING ".byte 0x66,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00"
8416
8417 ROSE_ASSERT(n > 0);
8418
8419 SgAsmStmt* nopStatement = NULL;
8420
8421 switch (n)
8422 {
8423 case 1: nopStatement = buildAsmStatement(NOP_1_BYTE_STRING); break;
8424 case 2: nopStatement = buildAsmStatement(NOP_2_BYTE_STRING); break;
8425 case 3: nopStatement = buildAsmStatement(NOP_3_BYTE_STRING); break;
8426 case 4: nopStatement = buildAsmStatement(NOP_4_BYTE_STRING); break;
8427 case 5: nopStatement = buildAsmStatement(NOP_5_BYTE_STRING); break;
8428 case 6: nopStatement = buildAsmStatement(NOP_6_BYTE_STRING); break;
8429 case 7: nopStatement = buildAsmStatement(NOP_7_BYTE_STRING); break;
8430 case 8: nopStatement = buildAsmStatement(NOP_8_BYTE_STRING); break;
8431 case 9: nopStatement = buildAsmStatement(NOP_9_BYTE_STRING); break;
8432
8433 default:
8434 {
8435 printf ("Only supporting values of multi-byte nop's up to 9 bytes long. \n");
8436 ROSE_ABORT();
8437 }
8438 }
8439
8440 return nopStatement;
8441 }
8442
8444 {
8445 // DQ (7/25/2014): Adding support for C11 static assertions.
8446
8447 ROSE_ASSERT(condition != NULL);
8448
8449 SgStaticAssertionDeclaration* result = new SgStaticAssertionDeclaration(condition,string_literal);
8450 ROSE_ASSERT(result != NULL);
8451
8452 // DQ (7/25/2014): It is enforced that at least the firstNondefiningDeclaration be set.
8453 ROSE_ASSERT(result->get_firstNondefiningDeclaration() == NULL);
8454 result->set_firstNondefiningDeclaration(result);
8455 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
8456
8458
8459 return result;
8460 }
8461
8462
8463// DQ (8/17/2014): Adding support for Microsoft MSVC specific attributes.
8465 {
8467 ROSE_ASSERT(result != NULL);
8468
8469 // DQ (8/17/2014): It is enforced that at least the firstNondefiningDeclaration be set.
8470 ROSE_ASSERT(result->get_firstNondefiningDeclaration() == NULL);
8471 result->set_firstNondefiningDeclaration(result);
8472 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
8473
8475
8476 return result;
8477 }
8478
8480// This does not work properly since the global scope expects declaration statement, not just SgNullStatement
8481#if 0
8483{
8484 SgStatement* result = NULL;
8485
8486 return result;
8487
8488} //buildStatementFromString()
8489#endif
8490
8492 {
8493 // 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.
8494 // 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");
8495 // ROSE_ASSERT(false);
8496
8497 // DQ (7/29/2010): This function needs to call the SgPointerType::createType() function to support the new type table.
8498 // SgPointerType* result = new SgPointerType(base_type);
8499 if (isSgReferenceType (base_type))
8500 {
8501 cerr<<"Error in SageBuilder::buildPointerType(): trying to build a pointer to a reference type! This is not allowed in C++."<<endl;
8502 ROSE_ABORT ();
8503 }
8504
8505 SgPointerType* result = SgPointerType::createType(base_type);
8506 ROSE_ASSERT(result != NULL);
8507
8508 return result;
8509 }
8510
8512 {
8513 // 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.
8514 // 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");
8515 // ROSE_ASSERT(false);
8516
8517 // DQ (7/29/2010): This function needs to call the SgPointerType::createType() function to support the new type table.
8518 // SgReferenceType* result= new SgReferenceType(base_type);
8519 SgReferenceType* result = SgReferenceType::createType(base_type);
8520 ROSE_ASSERT(result != NULL);
8521
8522 return result;
8523 }
8524
8526 {
8527 ROSE_ASSERT(base_type != NULL);
8529 ROSE_ASSERT(result != NULL);
8530
8531 return result;
8532 }
8533
8535 {
8536 ROSE_ASSERT(base_expression != NULL);
8537
8538 // SgDeclType* result = SgDeclType::createType(base_expression);
8539 SgDeclType* result = NULL;
8540 if (isSgFunctionParameterRefExp(base_expression) != NULL)
8541 {
8542 result = new SgDeclType(base_expression);
8543 result->set_base_type(base_type);
8544 }
8545 else
8546 {
8547 result = SgDeclType::createType(base_expression);
8548 }
8549
8550 ROSE_ASSERT(result != NULL);
8551
8552 // DQ (8/12/2014): Set the parent in the expression.
8553 base_expression->set_parent(result);
8554
8555 return result;
8556 }
8557
8560 {
8561 // ROSE_ASSERT(base_expression != NULL);
8562
8563#define DEBUG_TYPEOF_TYPE 0
8564
8565#if DEBUG_TYPEOF_TYPE
8566 printf ("In SageBuilder::buildTypeOfType(): base_expression = %p = %s \n",base_expression,base_expression != NULL ? base_expression->class_name().c_str() : "NULL");
8567 printf (" ------------------------------- base_type = %p = %s \n",base_type,base_type != NULL ? base_type->class_name().c_str() : "NULL");
8568#endif
8569
8570 SgTypeOfType* result = NULL;
8571 if (isSgFunctionParameterRefExp(base_expression) != NULL)
8572 {
8573#if DEBUG_TYPEOF_TYPE
8574 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) != NULL: calling new SgTypeOfType(base_expression,NULL) \n");
8575#endif
8576 result = new SgTypeOfType(base_expression,NULL);
8577
8578 // DQ (3/28/2015): Testing for corruption in return value.
8579 ROSE_ASSERT(result != NULL);
8580#if DEBUG_TYPEOF_TYPE
8581 printf ("In buildTypeOfType(): test 1: result = %p = %s \n",result,result->class_name().c_str());
8582#endif
8583 result->set_base_type(base_type);
8584 }
8585 else
8586 {
8587 if (base_expression != NULL)
8588 {
8589#if DEBUG_TYPEOF_TYPE
8590 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) == NULL: base_expression != NULL: calling SgTypeOfType::createType(base_expression,NULL) \n");
8591#endif
8592 result = SgTypeOfType::createType(base_expression,NULL);
8593
8594 // DQ (3/28/2015): Testing for corruption in return value.
8595 ROSE_ASSERT(result != NULL);
8596#if DEBUG_TYPEOF_TYPE
8597 printf ("In buildTypeOfType(): test 2: result = %p = %s \n",result,result->class_name().c_str());
8598#endif
8599 }
8600 else
8601 {
8602 ROSE_ASSERT(base_type != NULL);
8603
8604#if DEBUG_TYPEOF_TYPE
8605 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) == NULL: base_expression == NULL: calling SgTypeOfType::createType(base_type,NULL) \n");
8606#endif
8607 result = SgTypeOfType::createType(base_type,NULL);
8608
8609 // DQ (3/28/2015): Testing for corruption in return value.
8610 ROSE_ASSERT(result != NULL);
8611
8612#if DEBUG_TYPEOF_TYPE
8613 printf ("In buildTypeOfType(): test 3: result = %p = %s \n",result,result->class_name().c_str());
8614#endif
8615 // result->set_base_type(base_type);
8616 if (result->get_base_type() != base_type)
8617 {
8618 ROSE_ASSERT(result->get_base_type() != NULL);
8619#if DEBUG_TYPEOF_TYPE
8620 printf ("result->get_base_type() = %p = %s \n",result->get_base_type(),result->get_base_type()->class_name().c_str());
8621#endif
8622 ROSE_ASSERT(base_type != NULL);
8623#if DEBUG_TYPEOF_TYPE
8624 printf ("base_type = %p = %s \n",base_type,base_type->class_name().c_str());
8625#endif
8626 }
8627 }
8628 }
8629
8630 ROSE_ASSERT(result != NULL);
8631
8632 if (base_expression != NULL)
8633 {
8634 base_expression->set_parent(result);
8635 }
8636
8637 // DQ (3/28/2015): Testing for corruption in return value.
8638 ROSE_ASSERT(result != NULL);
8639
8640#if DEBUG_TYPEOF_TYPE
8641 printf ("In buildTypeOfType(): test 4: result = %p = %s \n",result,result->class_name().c_str());
8642#endif
8643
8644 return result;
8645 }
8646
8647
8648
8649#if 0
8650// Liao, 8/16/2010, This function is being phased out. Please don't call this!!
8652 {
8653 // DQ (7/30/2010): Note that this is called by the outline test: tests/nonsmoke/functional/roseTests/astOutliningTests/moreTest3.cpp
8654 // DQ (7/28/2010): Now we want to make calling this function an error, the functions buildConst() will return SgModifierType objects instead.
8655 printf ("Error: this function SageBuilder::buildModifierType() should not be called! (call the buildConst() function (or whatever other function is required) directly \n");
8656 ROSE_ABORT();
8657 // Liao, 8/13/2010, This function is being phased out. Please don't call this!!
8658
8659 // 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.
8660 SgModifierType* result = new SgModifierType(base_type);
8661 // SgModifierType* result = SgModifierType::createType(base_type);
8662 ROSE_ASSERT(result != NULL);
8663
8664 // DQ (7/28/2010): Insert result type into type table and return it, or
8665 // replace the result type, if already available in the type table, with
8666 // the type from type table.
8667 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
8668
8669 return result;
8670 }
8671#endif
8672
8673// CR (2/20/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8675 SgTypeBool * result = SgTypeBool::createType(kind_expr);
8676 ROSE_ASSERT(result);
8677 if (kind_expr != NULL) kind_expr->set_parent(result);
8678 return result;
8679}
8683
8685 {
8687 ROSE_ASSERT(result);
8688 return result;
8689 }
8690
8692{
8694 ROSE_ASSERT(result);
8695 return result;
8696}
8697
8698#if 0 // did not work, build##itemType would be expanded correctly
8699#define BUILD_SGTYPE_DEF(item) \
8700 SgType##item * SageBuilder::build##itemType() { \
8701 SgType##item * result =SgType##item::createType(); \
8702 ROSE_ASSERT(result); \
8703 return result; \
8704 }
8705
8706 BUILD_SGTYPE_DEF(Bool)
8707 BUILD_SGTYPE_DEF(Char)
8708 BUILD_SGTYPE_DEF(Double)
8709 BUILD_SGTYPE_DEF(Float)
8710 BUILD_SGTYPE_DEF(Int)
8711 BUILD_SGTYPE_DEF(Long)
8712 BUILD_SGTYPE_DEF(LongDouble)
8713 BUILD_SGTYPE_DEF(LongLong)
8714 BUILD_SGTYPE_DEF(Short)
8715 BUILD_SGTYPE_DEF(Void)
8716
8717 BUILD_SGTYPE_DEF(Wchar)
8718
8719// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
8720 BUILD_SGTYPE_DEF(Char16)
8721 BUILD_SGTYPE_DEF(Char32)
8722
8723 BUILD_SGTYPE_DEF(SignedChar)
8724 BUILD_SGTYPE_DEF(SignedInt)
8725 BUILD_SGTYPE_DEF(SignedLong)
8726 BUILD_SGTYPE_DEF(SignedShort)
8727 BUILD_SGTYPE_DEF(UnsignedChar)
8728 BUILD_SGTYPE_DEF(UnsignedInt)
8729 BUILD_SGTYPE_DEF(UnsignedLong)
8730 BUILD_SGTYPE_DEF(UnsignedLongLong)
8731 BUILD_SGTYPE_DEF(UnsignedShort)
8732#undef BUILD_SGTYPE_DEF
8733#endif
8735{
8737 ROSE_ASSERT(result);
8738 return result;
8739}
8740
8742{
8744 ROSE_ASSERT(result);
8745 return result;
8746}
8747
8749{
8751 ROSE_ASSERT(result);
8752 return result;
8753}
8754
8756{
8758 ROSE_ASSERT(result);
8759 return result;
8760}
8761
8762// Rasmussen (2/20/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8764{
8766 ROSE_ASSERT(result);
8767 if (kind_expr != NULL) kind_expr->set_parent(result);
8768 return result;
8769}
8774
8776{
8778 ROSE_ASSERT(result);
8779 return result;
8780}
8781
8784 ROSE_ASSERT(result);
8785 return result;
8786}
8787
8790 ROSE_ASSERT(result);
8791 return result;
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{
8818 ROSE_ASSERT(result);
8819 return result;
8820}
8821
8822#if 1
8829
8836#endif
8837
8838
8840{
8842 ROSE_ASSERT(result);
8843 return result;
8844}
8845
8846// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
8848{
8850 ROSE_ASSERT(result);
8851 return result;
8852}
8853
8854// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
8856{
8858 ROSE_ASSERT(result);
8859 return result;
8860}
8861
8862
8864{
8866 ROSE_ASSERT(result);
8867 return result;
8868}
8869
8871{
8873 ROSE_ASSERT(result);
8874 return result;
8875}
8876
8878{
8880 ROSE_ASSERT(result);
8881 return result;
8882}
8883
8885{
8886 SgAutoType * result =new SgAutoType();
8887 ROSE_ASSERT(result);
8888 return result;
8889}
8890
8892{
8894 ROSE_ASSERT(result);
8895 return result;
8896}
8897
8899{
8901 ROSE_ASSERT(result);
8902 return result;
8903}
8904
8906{
8908 ROSE_ASSERT(result);
8909 return result;
8910}
8911
8913 {
8914 // DQ (8/17/2010): This function needs to use a different API to handle a literal
8915 // value for the string size (typical) or an expression for the string size (rare).
8916 // For now we will make it an error to call this function.
8917
8918 // SgTypeString * result =SgTypeString::createType();
8919 SgTypeString * result = NULL;
8920 ROSE_ASSERT(result != NULL);
8921 return result;
8922 }
8923
8925 {
8926 // DQ (8/21/2010): This is a new API for this function. This type is specific to Fortran use,
8927 // in C/C++ a string is just an array of char. We could have a consistant handling between
8928 // C/C++ and Fortrna, but we have just corrected the implementation in Fortran to use this IR
8929 // node and we would have to add such support to C/C++. The current implementation reflects
8930 // the grammar of the two languages.
8931
8932 // This function needs to use a different API to handle a literal
8933 // value for the string size (typical) or an expression for the string size (rare).
8934
8935 SgTypeString* result = SgTypeString::createType(stringLengthExpression);
8936 ASSERT_not_null(result);
8937 return result;
8938 }
8939
8940// Rasmussen (2/20/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8942{
8943 SgTypeInt * result;
8944 if (kind_expr != NULL)
8945 {
8946 result = SgTypeInt::createType(0, kind_expr);
8947 kind_expr->set_parent(result);
8948 }
8949 else
8950 {
8951 result = SgTypeInt::createType();
8952 }
8953 ASSERT_not_null(result);
8954 return result;
8955}
8957{
8958 return buildIntType(NULL);
8959}
8960
8962{
8964 ROSE_ASSERT(result);
8965 return result;
8966}
8967
8968// Rasmussen (3/6/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8970{
8971 SgTypeFloat * result;
8972 if (kind_expr != NULL)
8973 {
8974 result = SgTypeFloat::createType(kind_expr);
8975 kind_expr->set_parent(result);
8976 }
8977 else
8978 {
8979 result = SgTypeFloat::createType();
8980 }
8981 ASSERT_not_null(result);
8982 return result;
8983}
8985{
8987 ASSERT_not_null(result);
8988 return result;
8989}
8990
8991// Rasmussen (2/20/2020): Added builder for Jovial fixed type
8993{
8994 SgTypeFixed * result = SgTypeFixed::createType(scale, fraction);
8995 ROSE_ASSERT(result);
8996
8997 if (scale) scale->set_parent(result);
8998 if (fraction) fraction->set_parent(result);
8999
9000 return result;
9001}
9002
9003// Rasmussen (5/5/2020): Added builder for Jovial bit type
9005{
9006 SgJovialBitType * result = SgJovialBitType::createType(size, NULL);
9007
9008 if (size) size->set_parent(result);
9009
9010 return result;
9011}
9012
9013// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9016 {
9017 // DQ (9/3/2012): Added assertion.
9018 ROSE_ASSERT(base_type != NULL);
9019
9020 // DQ (7/28/2010): New (similar) approach using type table support.
9021 SgModifierType* result = new SgModifierType(base_type);
9022 ROSE_ASSERT(result != NULL);
9023
9024 // DQ (3/10/2018): Adding assertion.
9025 ROSE_ASSERT(result != base_type);
9026
9027 // DQ (7/28/2010): Insert result type into type table and return it, or
9028 // replace the result type, if already available in the type table, with
9029 // the type from type table.
9030 SgModifierType* result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9031
9032 if (result != result2)
9033 {
9034 // DQ (10/27/2015): This is the cause of a bug in the test2015_97.C (boost template problem).
9035 printf ("WARNING: In SageBuilder::buildModifierType(): using previously build SgModifierType from global type table: result2 = %p = %s \n",result2,result2->class_name().c_str());
9036 delete result;
9037 }
9038
9039 // DQ (3/10/2018): Adding assertion.
9040 ROSE_ASSERT(result2 != base_type);
9041
9042 return result2;
9043 }
9044
9047 {
9048 // DQ (9/3/2012): Added assertion.
9049 ROSE_ASSERT(base_type != NULL);
9050
9051 // DQ (7/28/2010): New (similar) approach using type table support.
9052 SgModifierType *result = new SgModifierType(base_type);
9053 ROSE_ASSERT(result!=NULL);
9054 result->get_typeModifier().get_constVolatileModifier().setConst();
9055
9056 // DQ (7/28/2010): Insert result type into type table and return it, or
9057 // replace the result type, if already available in the type table, with
9058 // the type from type table.
9059 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9060
9061 if (result != result2)
9062 {
9063 delete result;
9064 }
9065
9066 // DQ (3/10/2018): Adding assertion.
9067 ROSE_ASSERT(result2 != base_type);
9068
9069 return result2;
9070 }
9071
9072// DQ (8/27/2010): Added Fortran specific support for types based on kind expressions.
9075 {
9076 // DQ (9/3/2012): Added assertion.
9077 ROSE_ASSERT(base_type != NULL);
9078
9079 SgModifierType *result = new SgModifierType(base_type);
9080 ROSE_ASSERT(result != NULL);
9081
9082 result->set_type_kind(kindExpression);
9083
9084#if 0
9085 printf ("In SageBuilder::buildFortranKindType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9086#endif
9087
9088 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9089
9090 if (result != result2)
9091 {
9092#if 0
9093 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9094 printf ("(debugging) In SageBuilder::buildFortranKindType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9095#else
9096 delete result;
9097#endif
9098 }
9099
9100 return result2;
9101 }
9102
9103// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9106 {
9107 // DQ (9/3/2012): Added assertion.
9108 ROSE_ASSERT(base_type != NULL);
9109
9110 SgModifierType *result = new SgModifierType(base_type);
9111 ROSE_ASSERT(result!=NULL);
9112
9113 result->get_typeModifier().get_constVolatileModifier().setVolatile();
9114
9115#if 0
9116 printf ("In SageBuilder::buildVolatileType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9117#endif
9118
9119 // DQ (7/29/2010): Insert result type into type table and return it, or
9120 // replace the result type, if already available in the type table, with
9121 // the type from type table.
9122 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9123 if (result != result2)
9124 {
9125#if 0
9126 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9127 printf ("(debugging) In SageBuilder::buildVolatileType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9128#else
9129 delete result;
9130#endif
9131 }
9132
9133 return result2;
9134 }
9135
9136// DQ (1/19/2019): Adding support for const volatile type (both together as another value).
9139 {
9140 // DQ (9/3/2012): Added assertion.
9141 ROSE_ASSERT(base_type != NULL);
9142
9143 SgModifierType *result = new SgModifierType(base_type);
9144 ROSE_ASSERT(result!=NULL);
9145
9146 result->get_typeModifier().get_constVolatileModifier().setConst();
9147 result->get_typeModifier().get_constVolatileModifier().setVolatile();
9148
9149#if 1
9150 printf ("In SageBuilder::buildConstVolatileType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9151#endif
9152
9153 // DQ (7/29/2010): Insert result type into type table and return it, or
9154 // replace the result type, if already available in the type table, with
9155 // the type from type table.
9156 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9157 if (result != result2)
9158 {
9159#if 0
9160 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9161 printf ("(debugging) In SageBuilder::buildConstVolatileType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9162#else
9163 delete result;
9164#endif
9165 }
9166
9167 return result2;
9168 }
9169
9170string
9171generate_type_list (SgType* type)
9172 {
9173 // This function generates a list of types for each level of the type structure.
9174 string returnString;
9175
9176 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);
9177
9178 SgType* currentType = type;
9179
9180 SgModifierType* modType = NULL;
9181 SgPointerType* pointType = NULL;
9182 SgReferenceType* refType = NULL;
9183 SgRvalueReferenceType* rRefType = NULL;
9184 SgArrayType* arrayType = NULL;
9185 SgTypedefType* typedefType = NULL;
9186
9187 while (currentType != NULL)
9188 {
9189 returnString += currentType->class_name();
9190#if 0
9191 printf ("In generate_type_list(): returnString = %s \n",returnString.c_str());
9192#endif
9193 if ( (bit_array & SgType::STRIP_MODIFIER_TYPE) && (modType = isSgModifierType(currentType)) )
9194 {
9195 currentType = modType->get_base_type();
9196 }
9197 else if ( (bit_array & SgType::STRIP_REFERENCE_TYPE) && (refType = isSgReferenceType(currentType)) )
9198 {
9199 currentType = refType->get_base_type();
9200 }
9201 else if ( (bit_array & SgType::STRIP_RVALUE_REFERENCE_TYPE) && (rRefType = isSgRvalueReferenceType(currentType)) )
9202 {
9203 currentType = rRefType->get_base_type();
9204 }
9205 else if ( (bit_array & SgType::STRIP_POINTER_TYPE) && (pointType = isSgPointerType(currentType)) )
9206 {
9207 currentType = pointType->get_base_type();
9208 }
9209 else if ( (bit_array & SgType::STRIP_ARRAY_TYPE) && (arrayType = isSgArrayType(currentType)) )
9210 {
9211 currentType = arrayType->get_base_type();
9212 }
9213 else if ( (bit_array & SgType::STRIP_TYPEDEF_TYPE) && (typedefType = isSgTypedefType(currentType)) )
9214 {
9215 currentType = typedefType->get_base_type();
9216 }
9217 else
9218 {
9219 break;
9220 }
9221
9222 if (type != NULL)
9223 returnString += " , ";
9224 }
9225
9226 return returnString;
9227 }
9228
9229// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9232 {
9233 ROSE_ASSERT(base_type != NULL);
9234
9235 // DQ (1/30/2014): We need to include typedefs here as well (see test2014_77.c).
9236 // DQ (9/28/2012): Added that the base type could be an array (see test2012_03.c (C test code)).
9237 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type))
9238 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type))
9239 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type) && !isSgTypedefType(base_type))
9240 if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type) && !isSgTypedefType(base_type) && !isSgModifierType(base_type))
9241 {
9242 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());
9243 printf (" --- generate_type_list() = %s \n",generate_type_list(base_type).c_str());
9244 ROSE_ABORT();
9245 }
9246
9247 SgModifierType *result = new SgModifierType(base_type);
9248 ROSE_ASSERT(result!=NULL);
9249
9250 result->get_typeModifier().setRestrict();
9251
9252#if 0
9253 printf ("In SageBuilder::buildRestrictType(): 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::buildRestrictType(): 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
9274namespace
9275{
9276 // PP (2/16/24): model builder function after buildRestrictType
9278 _buildModifierType(SgType* base_type, std::function<void(SgModifierType*)> setModifiers)
9279 {
9280 ASSERT_not_null(base_type);
9281
9282 SgModifierType* result = new SgModifierType(base_type);
9283
9284 setModifiers(result);
9285
9286 SgModifierType* result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9287 if (result != result2) delete result;
9288
9289 return result2;
9290 }
9291}
9292
9293
9295 {
9296 auto op = [](SgModifierType* ty) { ty->get_typeModifier().setAliased(); };
9297
9298 return _buildModifierType(base_type, op);
9299 }
9300
9302 {
9303 auto op = [](SgModifierType* ty) { ty->get_typeModifier().setNotNull(); };
9304
9305 return _buildModifierType(base_type, op);
9306 }
9307
9308
9309// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9312 {
9313 // DQ (9/3/2012): Added assertion.
9314 ROSE_ASSERT(base_type != NULL);
9315
9316 SgModifierType *result = new SgModifierType(base_type);
9317 ROSE_ASSERT(result!=NULL);
9318
9319 result->get_typeModifier().get_upcModifier().set_modifier(SgUPC_AccessModifier::e_upc_strict);
9320
9321#if 0
9322 printf ("In SageBuilder::buildUpcStrictType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9323#endif
9324
9325 // DQ (7/29/2010): Insert result type into type table and return it, or
9326 // replace the result type, if already available in the type table, with
9327 // the type from type table.
9328 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9329 if (result != result2)
9330 {
9331#if 0
9332 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9333 printf ("(debugging) In SageBuilder::buildUpcStrictType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9334#else
9335 delete result;
9336#endif
9337 }
9338
9339 return result2;
9340 }
9341
9342// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9345 {
9346 // DQ (9/3/2012): Added assertion.
9347 ROSE_ASSERT(base_type != NULL);
9348
9349 SgModifierType *result = new SgModifierType(base_type);
9350 ROSE_ASSERT(result!=NULL);
9351
9352 result->get_typeModifier().get_upcModifier().set_modifier(SgUPC_AccessModifier::e_upc_relaxed);
9353
9354#if 0
9355 printf ("In SageBuilder::buildUpcRelaxedType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9356#endif
9357
9358 // DQ (7/29/2010): Insert result type into type table and return it, or
9359 // replace the result type, if already available in the type table, with
9360 // the type from type table.
9361 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9362 if (result != result2)
9363 {
9364#if 0
9365 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9366 printf ("(debugging) In SageBuilder::buildUpcRelaxedType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9367#else
9368 delete result;
9369#endif
9370 }
9371
9372 return result2;
9373 }
9374
9375// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9377SgModifierType* SageBuilder::buildUpcSharedType(SgType* base_type /*=NULL*/, long layout /*= -1*/)
9378 {
9379 // DQ (9/3/2012): Added assertion.
9380 ROSE_ASSERT(base_type != NULL);
9381
9382 SgModifierType *result = new SgModifierType(base_type);
9383 ROSE_ASSERT(result!=NULL);
9384
9385 result->get_typeModifier().get_upcModifier().set_isShared(true);
9386
9387 // DQ (7/29/2010): Modified to use new input parameter.
9388 // result->get_typeModifier().get_upcModifier().set_layout(-1); // No layout ("shared" without a block size)
9389 result->get_typeModifier().get_upcModifier().set_layout(layout); // No layout ("shared" without a block size)
9390
9391#if 0
9392 printf ("In SageBuilder::buildUpcSharedType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9393#endif
9394
9395 // DQ (7/29/2010): Insert result type into type table and return it, or
9396 // replace the result type, if already available in the type table, with
9397 // the type from type table.
9398 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9399 if (result != result2)
9400 {
9401#if 0
9402 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9403 printf ("(debugging) In SageBuilder::buildUpcSharedType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9404#else
9405 delete result;
9406#endif
9407 }
9408
9409 return result2;
9410 }
9411
9412// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9415 {
9416 // DQ (9/3/2012): Added assertion.
9417 ROSE_ASSERT(base_type != NULL);
9418
9419 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9420 ROSE_ASSERT(result!=NULL);
9421
9422 result->get_typeModifier().get_upcModifier().set_layout(0); // [] layout
9423
9424#if 0
9425 printf ("In SageBuilder::buildUpcBlockIndefiniteType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9426#endif
9427
9428 // DQ (7/29/2010): Insert result type into type table and return it, or
9429 // replace the result type, if already available in the type table, with
9430 // the type from type table.
9431 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9432
9433 return result;
9434 }
9435
9436// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9439 {
9440 // DQ (9/3/2012): Added assertion.
9441 ROSE_ASSERT(base_type != NULL);
9442
9443 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9444 ROSE_ASSERT(result!=NULL);
9445
9446 result->get_typeModifier().get_upcModifier().set_layout(-2); // [*] layout
9447
9448#if 0
9449 printf ("In SageBuilder::buildUpcBlockStarType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9450#endif
9451
9452 // DQ (7/29/2010): Insert result type into type table and return it, or
9453 // replace the result type, if already available in the type table, with
9454 // the type from type table.
9455 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9456
9457 return result;
9458 }
9459
9460// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9463 {
9464 // DQ (9/3/2012): Added assertion.
9465 ROSE_ASSERT(base_type != NULL);
9466
9467 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9468 ROSE_ASSERT(result!=NULL);
9469
9470 result->get_typeModifier().get_upcModifier().set_layout(block_factor); // [block_factor] layout
9471
9472#if 0
9473 printf ("In SageBuilder::buildUpcBlockNumberType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9474#endif
9475
9476 // DQ (7/29/2010): Insert result type into type table and return it, or
9477 // replace the result type, if already available in the type table, with
9478 // the type from type table.
9479 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9480
9481 return result;
9482 }
9483
9484
9485
9488 {
9489 // DQ (9/3/2012): Added assertion.
9490 ROSE_ASSERT(base_type != NULL);
9491
9492 SgTypeComplex *result = new SgTypeComplex(base_type);
9493 ROSE_ASSERT(result!=NULL);
9494 return result;
9495 }
9496
9499 {
9500 // DQ (9/3/2012): Added assertion.
9501 ROSE_ASSERT(base_type != NULL);
9502
9503 SgTypeImaginary *result = new SgTypeImaginary(base_type);
9504 ROSE_ASSERT(result!=NULL);
9505 return result;
9506 }
9507
9510{
9511 SgTypeMatrix *result = new SgTypeMatrix();
9512 ROSE_ASSERT(result != NULL);
9513 return result;
9514}
9515
9518{
9519 SgTypeTuple *result = new SgTypeTuple();
9520 ROSE_ASSERT(result != NULL);
9521
9522 if(t1) result->append_type(t1);
9523 if(t2) result->append_type(t2);
9524 if(t3) result->append_type(t3);
9525 if(t4) result->append_type(t4);
9526 if(t5) result->append_type(t5);
9527 if(t6) result->append_type(t6);
9528 if(t7) result->append_type(t7);
9529 if(t8) result->append_type(t8);
9530 if(t9) result->append_type(t9);
9531 if(t10) result->append_type(t10);
9532
9534
9535 return result;
9536}
9537
9540 SgNonrealDecl * nrdecl = buildNonrealDecl(name, scope);
9541 nrdecl->set_parent(scope);
9542 nrdecl->set_is_template_param (true);
9543 return nrdecl->get_type();
9544}
9545
9547{
9548 SgRangeExp *result = new SgRangeExp();
9550 ROSE_ASSERT(result != NULL);
9551
9552 result->append(start);
9553 return result;
9554}
9555
9557{
9558 SgRangeExp *result = new SgRangeExp();
9560 ROSE_ASSERT(result != NULL);
9561
9562 result->set_start(start);
9563 start->set_parent(result);
9564
9565 result->set_end(end);
9566 end->set_parent(result);
9567
9568 result->set_stride(stride);
9569 stride->set_parent(result);
9570 return result;
9571}
9572
9573
9575{
9576 SgMatrixExp *result = new SgMatrixExp();
9578
9579 result->append_expression(firstRow);
9580 ROSE_ASSERT(result != NULL);
9581
9582 return result;
9583}
9584
9586{
9587 SgMagicColonExp *result = new SgMagicColonExp();
9589
9590 ROSE_ASSERT(result != NULL);
9591
9592 return result;
9593}
9594
9597{
9598 SgConstVolatileModifier * result = NULL;
9599 result = new SgConstVolatileModifier();
9600 ROSE_ASSERT (result != NULL);
9601 result->set_modifier (mtype);
9602
9603 return result;
9604}
9605
9609 {
9610 // SgFunctionDeclaration* func_decl = buildDefiningFunctionDeclaration("__rose__lambda__",return_type,params,scope,NULL,NULL);
9611 SgFunctionDeclaration* func_decl = buildDefiningFunctionDeclaration("__rose__lambda__",return_type,params,scope,NULL,false,NULL,NULL);
9612
9613 SgLambdaRefExp* result = new SgLambdaRefExp(func_decl);
9614 func_decl->set_parent(result);
9615
9617
9618 return result;
9619 }
9620
9623 {
9624 SgTypeExpression *expr = new SgTypeExpression(type);
9626 return expr;
9627 }
9628
9629// DQ (8/11/2014): Added support for C++11 decltype used in new function return syntax.
9631SageBuilder::buildFunctionParameterRefExp(int parameter_number, int parameter_level )
9632 {
9633 SgFunctionParameterRefExp *expr = new SgFunctionParameterRefExp(NULL,parameter_number,parameter_level);
9634 ROSE_ASSERT(expr != NULL);
9635
9636 setSourcePosition(expr);
9637 return expr;
9638 }
9639
9640
9641// DQ (8/11/2014): Added support for C++11 decltype used in new function return syntax.
9643SageBuilder::buildFunctionParameterRefExp_nfi(int parameter_number, int parameter_level )
9644 {
9645 SgFunctionParameterRefExp *expr = new SgFunctionParameterRefExp(NULL,parameter_number,parameter_level);
9646 ROSE_ASSERT(expr != NULL);
9647
9649 return expr;
9650 }
9651
9652// DQ (9/3/2014): Adding support for C++11 Lambda expressions
9654SageBuilder::buildLambdaExp(SgLambdaCaptureList* lambda_capture_list, SgClassDeclaration* lambda_closure_class, SgFunctionDeclaration* lambda_function)
9655 {
9656 SgLambdaExp *expr = new SgLambdaExp(lambda_capture_list,lambda_closure_class,lambda_function);
9657 ROSE_ASSERT(expr != NULL);
9658
9659 // Set the parents
9660 if (lambda_capture_list != NULL)
9661 {
9662 lambda_capture_list->set_parent(expr);
9663 }
9664
9665 if (lambda_closure_class != NULL)
9666 {
9667 lambda_closure_class->set_parent(expr);
9668 }
9669
9670 if (lambda_function != NULL)
9671 {
9672#if 1
9673 lambda_function->set_parent(expr);
9674#else
9675 if (lambda_closure_class != NULL)
9676 {
9677 lambda_function->set_parent(lambda_closure_class);
9678 }
9679 else
9680 {
9681 printf ("Warning: In SageBuilder::buildLambdaExp(): lambda_closure_class == NULL: lambda_function parent not set! \n");
9682 }
9683#endif
9684 }
9685
9686 setSourcePosition(expr);
9687 return expr;
9688 }
9689
9691SageBuilder::buildLambdaExp_nfi(SgLambdaCaptureList* lambda_capture_list, SgClassDeclaration* lambda_closure_class, SgFunctionDeclaration* lambda_function)
9692 {
9693 SgLambdaExp *expr = new SgLambdaExp(lambda_capture_list,lambda_closure_class,lambda_function);
9694 ROSE_ASSERT(expr != NULL);
9695
9696 // Set the parents
9697 if (lambda_capture_list != NULL)
9698 {
9699 lambda_capture_list->set_parent(expr);
9700 }
9701
9702 if (lambda_closure_class != NULL)
9703 {
9704 lambda_closure_class->set_parent(expr);
9705 }
9706
9707 if (lambda_function != NULL)
9708 {
9709#if 1
9710 lambda_function->set_parent(expr);
9711#else
9712 if (lambda_closure_class != NULL)
9713 {
9714 lambda_function->set_parent(lambda_closure_class);
9715 }
9716 else
9717 {
9718 printf ("Warning: In SageBuilder::buildLambdaExp(): lambda_closure_class == NULL: lambda_function parent not set! \n");
9719 }
9720#endif
9721 }
9722
9724 return expr;
9725 }
9726
9727#if 0
9729SageBuilder::buildLambdaCapture(SgInitializedName* capture_variable, SgInitializedName* source_closure_variable, SgInitializedName* closure_variable)
9730 {
9731 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9732 ROSE_ASSERT(lambdaCapture != NULL);
9733
9734 setSourcePosition(lambdaCapture);
9735 return lambdaCapture;
9736 }
9737
9739SageBuilder::buildLambdaCapture_nfi(SgInitializedName* capture_variable, SgInitializedName* source_closure_variable, SgInitializedName* closure_variable)
9740 {
9741 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9742 ROSE_ASSERT(lambdaCapture != NULL);
9743
9744 setOneSourcePositionNull(lambdaCapture);
9745 return lambdaCapture;
9746 }
9747#else
9749SageBuilder::buildLambdaCapture(SgExpression* capture_variable, SgExpression* source_closure_variable, SgExpression* closure_variable)
9750 {
9751 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9752 ROSE_ASSERT(lambdaCapture != NULL);
9753
9754 setSourcePosition(lambdaCapture);
9755 return lambdaCapture;
9756 }
9757
9759SageBuilder::buildLambdaCapture_nfi(SgExpression* capture_variable, SgExpression* source_closure_variable, SgExpression* closure_variable)
9760 {
9761 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9762 ROSE_ASSERT(lambdaCapture != NULL);
9763
9764 setOneSourcePositionNull(lambdaCapture);
9765 return lambdaCapture;
9766 }
9767#endif
9768
9771 {
9772 SgLambdaCaptureList *lambdaCaptureList = new SgLambdaCaptureList(NULL);
9773 ROSE_ASSERT(lambdaCaptureList != NULL);
9774
9775 setSourcePosition(lambdaCaptureList);
9776 return lambdaCaptureList;
9777 }
9778
9781 {
9782 SgLambdaCaptureList *lambdaCaptureList = new SgLambdaCaptureList(NULL);
9783 ROSE_ASSERT(lambdaCaptureList != NULL);
9784
9785 setOneSourcePositionNull(lambdaCaptureList);
9786 return lambdaCaptureList;
9787 }
9788
9789// DQ (7/25/2020): Adding C++17 support
9791SageBuilder::buildFoldExpression(SgExpression* operands, string operator_token_string, bool is_left_associative)
9792 {
9793 SgFoldExpression* result = new SgFoldExpression(NULL,operands,operator_token_string,is_left_associative);
9794 ROSE_ASSERT(result != NULL);
9795
9797 return result;
9798 }
9799
9801SageBuilder::buildFoldExpression_nfi(SgExpression* operands, string operator_token_string, bool is_left_associative)
9802 {
9803 SgFoldExpression* result = new SgFoldExpression(NULL,operands,operator_token_string,is_left_associative);
9804 ROSE_ASSERT(result != NULL);
9805
9807 return result;
9808 }
9809
9810// DQ (7/25/2020): Adding C++20 support
9813 {
9814 SgAwaitExpression* result = new SgAwaitExpression(NULL,NULL);
9815 ROSE_ASSERT(result != NULL);
9816
9818 return result;
9819 }
9822 {
9823 SgAwaitExpression* result = new SgAwaitExpression(NULL,NULL);
9824 ROSE_ASSERT(result != NULL);
9825
9827 return result;
9828 }
9829
9830// DQ (7/25/2020): Adding C++20 support
9833 {
9834 SgChooseExpression* result = new SgChooseExpression(NULL,NULL);
9835 ROSE_ASSERT(result != NULL);
9836
9838 return result;
9839 }
9840
9843 {
9844 SgChooseExpression* result = new SgChooseExpression(NULL,NULL);
9845 ROSE_ASSERT(result != NULL);
9846
9848 return result;
9849 }
9850
9851
9852
9855 {
9856 SgNamespaceDefinitionStatement* result = NULL;
9857 if (d!=NULL) // the constructor does not check for NULL d, causing segmentation fault
9858 {
9859 result = new SgNamespaceDefinitionStatement(d);
9860 result->set_parent(d); // set_declaration() == set_parent() in this case
9861 }
9862 else
9863 {
9864 result = new SgNamespaceDefinitionStatement(d);
9865 }
9866
9867 ROSE_ASSERT(result);
9868
9870 return result;
9871 }
9872
9875{
9876 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
9877 SageInterface::setSourcePosition(nonreal_decl_scope);
9878 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
9879 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
9880 return nonreal_decl_scope;
9881}
9882
9884SageBuilder::buildClassDefinition(SgClassDeclaration *d/*= NULL*/, bool buildTemplateInstantiation )
9885 {
9886 SgClassDefinition* result = NULL;
9887 if (d != NULL) // the constructor does not check for NULL d, causing segmentation fault
9888 {
9889 // result->set_parent(d); // set_declaration() == set_parent() in this case
9890 // result = new SgClassDefinition(d);
9891 ROSE_ASSERT(buildTemplateInstantiation == false || isSgTemplateInstantiationDecl(d) != NULL);
9892 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn(isSgTemplateInstantiationDecl(d)) : new SgClassDefinition(d);
9893 }
9894 else
9895 {
9896 // result = new SgClassDefinition();
9897 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn() : new SgClassDefinition();
9898 }
9899
9900 ROSE_ASSERT(result);
9901
9902 // CR (3/22/2020): Fixed setting case insensitivity
9903 // if (symbol_table_case_insensitive_semantics == true)
9905 {
9906 result->setCaseInsensitive(true);
9907 }
9908
9910
9911 return result;
9912 }
9913
9914
9915
9917SageBuilder::buildClassDefinition_nfi(SgClassDeclaration *d/*= NULL*/, bool buildTemplateInstantiation )
9918 {
9919 SgClassDefinition* result = NULL;
9920 if (d!=NULL) // the constructor does not check for NULL d, causing segmentation fault
9921 {
9922 // result->set_parent(d); // set_declaration() == set_parent() in this case
9923 // result = new SgClassDefinition(d);
9924 ROSE_ASSERT(buildTemplateInstantiation == false || isSgTemplateInstantiationDecl(d) != NULL);
9925 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn(isSgTemplateInstantiationDecl(d)) : new SgClassDefinition(d);
9926 }
9927 else
9928 {
9929 // result = new SgClassDefinition();
9930 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn() : new SgClassDefinition();
9931 }
9932
9933 ROSE_ASSERT(result);
9934
9935 // CR (3/22/2020): Fixed setting case insensitivity
9936 // if (symbol_table_case_insensitive_semantics == true)
9938 result->setCaseInsensitive(true);
9939
9941 return result;
9942 }
9943
9944
9946SageBuilder::buildNondefiningClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList)
9947 {
9948 SgName nameWithoutTemplateArguments = XXX_name;
9949
9950 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
9951
9952 // SgClassDeclaration* nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
9953 SgClassDeclaration* nondefdecl = NULL;
9954
9955#define DEBUG_NONDEFINING_CLASS_DECLARATION 0
9956
9957 // DQ (11/26/2011): Debugging EDG 3.3 use of templateArguments.
9958#if DEBUG_NONDEFINING_CLASS_DECLARATION
9959 printf ("Building a SgClassDeclaration: buildNondefiningClassDeclaration_nfi() nameWithoutTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithoutTemplateArguments.str(),buildTemplateInstantiation ? "true:" : "false");
9960 printf (" --- scope = %p = %s \n",scope,(scope != NULL) ? scope->class_name().c_str() : "null");
9961#endif
9962
9963 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
9964 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
9965 ROSE_ASSERT(SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == false);
9966
9967 if (buildTemplateInstantiation == true)
9968 {
9969 ROSE_ASSERT(templateArgumentsList != NULL);
9970 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
9971
9972#if DEBUG_NONDEFINING_CLASS_DECLARATION
9973 printf ("Building a SgClassDeclaration: buildNondefiningClassDeclaration_nfi() nameWithTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithTemplateArguments.str(),buildTemplateInstantiation ? "true:" : "false");
9974#endif
9975
9976 // SgTemplateInstantiationDecl (SgName name, SgClassDeclaration::class_types class_type, SgClassType *type, SgClassDefinition *definition, SgTemplateDeclaration *templateDeclaration, SgTemplateArgumentPtrList templateArguments)
9977 SgTemplateArgumentPtrList emptyList;
9978 // nondefdecl = new SgTemplateInstantiationDecl(name,kind,NULL,NULL,NULL,emptyList);
9979 nondefdecl = new SgTemplateInstantiationDecl(nameWithTemplateArguments,kind,NULL,NULL,NULL,emptyList);
9980#if DEBUG_NONDEFINING_CLASS_DECLARATION
9981 printf ("In buildNondefiningClassDeclaration_nfi(): built new SgTemplateInstantiationDecl: nondefdecl = %p \n",nondefdecl);
9982#endif
9983 ROSE_ASSERT(nondefdecl->get_type() == NULL);
9984 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl) != NULL);
9985#if DEBUG_NONDEFINING_CLASS_DECLARATION
9986 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_name() = %s nondefdecl->get_templateName() = %s \n",
9987 nondefdecl->get_name().str(),isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().str());
9988#endif
9989 // DQ (6/6/2012): Added support for template arguments so that they can be a part of any generated type.
9990 ROSE_ASSERT(templateArgumentsList != NULL);
9991
9992#if DEBUG_NONDEFINING_CLASS_DECLARATION
9993 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
9994 printf ("nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
9995 printf ("Output templateArgumentsList: \n");
9996 for (size_t i = 0; i < templateArgumentsList->size(); i++)
9997 {
9998 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
9999 printf (" --- --- name = %s \n",unparseTemplateArgumentToString(templateArgumentsList->operator[](i)).str());
10000 }
10001#endif
10002
10003 // DQ (3/9/2018): Added assertion.
10004 ROSE_ASSERT(nondefdecl->get_name() == nameWithTemplateArguments);
10005
10006 // DQ (5/8/2013): This fails for explicit template instantation examples (e.g. template <> class RepeatedPtrField<string>::TypeHandler {};, in test2013_159.C)
10007 // ROSE_ASSERT(templateArgumentsList->size() > 0);
10008#if 0
10009 // DQ (9/16/2012): Call the newly refactored function after the firstNondefiningDeclaration is set.
10010
10011 // Calling the assignment operator for the STL container class.
10012 isSgTemplateInstantiationDecl(nondefdecl)->get_templateArguments() = *templateArgumentsList;
10013
10014#error "DEAD CODE!"
10015
10016#if 1
10017 // DQ (9/13/2012): Refactored this code.
10018 setTemplateArgumentParents(nondefdecl);
10019#else
10020 // DQ (7/25/2012): Added this code here to reset the parents of the template arguments.
10021 for (size_t i = 0; i < templateArgumentsList->size(); i++)
10022 {
10023 // DQ (7/25/2012): This should be true because the template argument was set to the functions
10024 // scope so that the name with template arguments could be computed (with name qualification).
10025 ROSE_ASSERT((*templateArgumentsList)[i]->get_parent() != NULL);
10026
10027#error "DEAD CODE!"
10028
10029 // ROSE_ASSERT(isSgGlobal(templateArgumentsList[i]->get_parent()) == NULL);
10030 // ROSE_ASSERT(templateArgumentsList[i]->get_parent() == nondefining_templateInstantiation);
10031
10032 // Be we want to reset it to be the function (now that it is available, because this is more precise).
10033 // All qualified names should compute to the same qualified name (if not then it is a bug in the name
10034 // qualification mechanism).
10035 (*templateArgumentsList)[i]->set_parent(nondefdecl);
10036 }
10037#endif
10038#endif
10039 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == true);
10040 isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(nameWithoutTemplateArguments);
10041 }
10042 else
10043 {
10044 // nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
10045 nondefdecl = new SgClassDeclaration(nameWithoutTemplateArguments,kind,NULL,NULL);
10046#if DEBUG_NONDEFINING_CLASS_DECLARATION
10047 printf ("In buildNondefiningClassDeclaration_nfi(): built new SgClassDeclaration: nondefdecl = %p \n",nondefdecl);
10048#endif
10049 // The default name for nameWithTemplateArguments is nameWithoutTemplateArguments so that we can use
10050 // nameWithTemplateArguments uniformally as the name of the function and it will work from non-template
10051 // instantiations.
10052 ROSE_ASSERT(nameWithoutTemplateArguments == nameWithTemplateArguments);
10053 }
10054
10055 ROSE_ASSERT(nondefdecl != NULL);
10056
10057 // DQ (6/9/2013): Added assertion to debug test2013_198.C.
10058 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10059
10060 // DQ (3/22/2012): I think we can assert this! No, in fact we can assert that it is not built yet.
10061 // ROSE_ASSERT(nondefdecl->get_type() != NULL);
10062 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10063
10064#if 0
10065 // DQ (3/22/2012): I think this may be too early.
10066 // Liao, we ask for explicit creation of SgClassType to avoid duplicated type nodes
10067 if (nondefdecl->get_type() == NULL)
10068 {
10069 nondefdecl->set_type(SgClassType::createType(nondefdecl));
10070 }
10071#endif
10072
10073#if 0
10074 printf ("SageBuilder::buildNondefiningClassDeclaration_nfi(): (and setting source position) nondefdecl = %p \n",nondefdecl);
10075#endif
10076
10077 // The non-defining declaration asociated with a declaration does not have a
10078 // source position...unless it is the position of the defining declaration.
10079 // setOneSourcePositionNull(nondefdecl);
10080 setSourcePosition(nondefdecl);
10081
10082 // This is find for now, but a little later in this function (if we can find a symbol)
10083 // we want to find the first non-defining declaration (using the symbol table) and use
10084 // that as a paramter to "nondefdecl->set_firstNondefiningDeclaration()".
10085 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10086 nondefdecl->set_definingDeclaration(NULL);
10087 nondefdecl->setForward();
10088
10089 // This is the structural parent (the logical scope can be different than the parent).
10090 // TPS (09/18/2009) added a condition to be able to build this properly
10091 if (scope == NULL)
10092 nondefdecl->set_parent(topScopeStack());
10093 else
10094 nondefdecl->set_parent(scope);
10095
10096 // This is the logical scope...
10097 nondefdecl->set_scope(scope);
10098
10099 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10100
10101 SgClassDeclaration* firstNondefdecl = NULL;
10102 if (scope != NULL)
10103 {
10104#if 0
10105 SgClassSymbol* mysymbol = new SgClassSymbol(nondefdecl);
10106 ROSE_ASSERT(mysymbol != NULL);
10107
10108 // printf ("In SageBuilder::buildNondefiningClassDeclaration(): for nondefdecl = %p built SgClassSymbol = %p \n",nondefdecl,mysymbol);
10109
10110#error "DEAD CODE"
10111
10112 scope->insert_symbol(name, mysymbol);
10113#else
10114 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would
10115 // not include name qualification on template arguments.
10116 // Reuse any previously defined symbols (to avoid redundant symbols in the symbol table)
10117 // and find the firstNondefiningDeclaration.
10118 // SgClassSymbol* mysymbol = scope->lookup_class_symbol(name);
10119 // SgClassSymbol* mysymbol = scope->lookup_nontemplate_class_symbol(name);
10120 // SgClassSymbol* mysymbol = scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments);
10121 SgClassSymbol* mysymbol = scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
10122
10123#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10124 printf ("In SageBuilder::buildNondefiningClassDeclaration(): mysymbol = %p = %s \n",mysymbol,(mysymbol != NULL) ? mysymbol->class_name().c_str() : "null");
10125#endif
10126 if (mysymbol != NULL)
10127 {
10128 firstNondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
10129 ROSE_ASSERT(firstNondefdecl != NULL);
10130
10131 // DQ (9/4/2012): Added assertion.
10132 ROSE_ASSERT(firstNondefdecl->get_type() != NULL);
10133
10134 // 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).
10135 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10136
10137 if (nondefdecl->get_type() == NULL)
10138 {
10139#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10140 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);
10141#endif
10142 // Note: It would be better to just call: "nondefdecl->set_type(firstNondefdecl->get_type());"
10143#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10144 printf ("NOTE: Call nondefdecl->set_type(firstNondefdecl->get_type()); instead of nondefdecl->set_type(SgClassType::createType(firstNondefdecl)); \n");
10145#endif
10146 // DQ (3/22/2012): Be careful to use the same declaration as from the symbol.
10147 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
10148 nondefdecl->set_type(SgClassType::createType(firstNondefdecl));
10149 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10150#if 0
10151 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());
10152#endif
10153
10154#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10155 printf ("In SageBuilder::buildNondefiningClassDeclaration(): nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
10156#endif
10157 // DQ (9/4/2012): Added assertion.
10158 ROSE_ASSERT(nondefdecl->get_type() == firstNondefdecl->get_type());
10159 }
10160
10161#if (REUSE_CLASS_DECLARATION_FROM_SYMBOL == 0)
10162 ROSE_ASSERT(nondefdecl != NULL);
10163 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10164
10165 // DQ (5/18/2014): Added test to match that in set_firstNondefiningDeclaration().
10166 // This is a problem for the Boost code after the fix to detec templates vs. template instantiation declarations.
10167 if (nondefdecl->variantT() != firstNondefdecl->variantT())
10168 {
10169 printf ("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): nondefdecl = %p = %s IS NOT THE SAME AS firstNondefiningDeclaration = %p = %s \n",
10170 nondefdecl,nondefdecl->class_name().c_str(),firstNondefdecl,firstNondefdecl->class_name().c_str());
10171 ROSE_ASSERT(nondefdecl->get_file_info() != NULL);
10172 nondefdecl->get_file_info()->display("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): nondefdecl: debug");
10173 ROSE_ASSERT(firstNondefdecl->get_file_info() != NULL);
10174 firstNondefdecl->get_file_info()->display("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): firstNondefdecl: debug");
10175 }
10176
10177 // DQ (5/18/2014): Added test to match that in set_firstNondefiningDeclaration().
10178 ROSE_ASSERT(nondefdecl->variantT() == firstNondefdecl->variantT());
10179
10180 nondefdecl->set_firstNondefiningDeclaration(firstNondefdecl);
10181
10182 // This might be NULL if the defining declaration has not been seen yet!
10183 nondefdecl->set_definingDeclaration(firstNondefdecl->get_definingDeclaration());
10184
10185 // DQ (3/22/2012): New assertions.
10186 ROSE_ASSERT(firstNondefdecl != NULL);
10187 ROSE_ASSERT(firstNondefdecl->get_type() != NULL);
10188
10189 // DQ (9/16/2012): This is a newly refactored function (call this after we know the firstNondefiningDeclaration is set correctly).
10190 // This is called in the other branch (mysymbol == NULL), but there is must be called before the symbol table is appended with
10191 // 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
10192 // both branches or once after both branches.
10193 if (buildTemplateInstantiation == true)
10194 {
10195 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
10196 }
10197
10198 // DQ (9/4/2012): We can now assert this because of how the type is constructed above.
10199 ROSE_ASSERT (nondefdecl->get_type() == firstNondefdecl->get_type());
10200
10201 // Share the type!
10202 if (nondefdecl->get_type() != firstNondefdecl->get_type())
10203 {
10204 // Remove the type from the new SgClassDeclaration and set the reference to the type in the firstNondefiningDeclaration.
10205 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());
10206 printf ("Skipping delete of %p so we can maintain unique type pointers \n",nondefdecl->get_type());
10207 // delete nondefdecl->get_type();
10208 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());
10209 nondefdecl->set_type(firstNondefdecl->get_type());
10210#if 1
10211 // DQ (12/13/2011): Is this executed!
10212 printf ("Unclear if this code is executed \n");
10213 ROSE_ABORT();
10214#endif
10215 }
10216#else
10217#error "DEAD CODE"
10218
10219 ROSE_ASSERT(nondefdecl == NULL);
10220#endif
10221 // This function should return a new nondefining declaration each time (to support multile class prototypes!).
10222 // nondefdecl = firstNondefdecl;
10223 }
10224 else
10225 {
10226#if REUSE_CLASS_DECLARATION_FROM_SYMBOL
10227 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
10228
10229#error "DEAD CODE"
10230
10231 nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
10232
10233#error "DEAD CODE"
10234
10235 ROSE_ASSERT(nondefdecl != NULL);
10236 if (nondefdecl->get_type() == NULL)
10237 nondefdel->set_type(SgClassType::createType(nondefdecl));
10238
10239 printf ("SageBuilder::buildNondefiningClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
10240
10241 setOneSourcePositionNull(nondefdecl);
10242
10243#error "DEAD CODE"
10244
10245 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10246 nondefdecl->set_definingDeclaration(NULL);
10247 nondefdecl->setForward();
10248#endif
10249
10250 // DQ (6/9/2013): Added assertion to debug test2013_198.C.
10251 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10252
10253 mysymbol = new SgClassSymbol(nondefdecl);
10254 firstNondefdecl = nondefdecl;
10255
10256 // DQ (6/9/2013): Adding assertions to make sure that symbols only reference non-defining declarations.
10257 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10258 ROSE_ASSERT(mysymbol->get_declaration()->get_definition() == NULL);
10259
10260 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
10261 // Note that since the symbol tables use the template arguments associated with the declaration it is best to
10262 // fixup the template arguments before the symbol table is fixup to have a symbol for this declaration. So we
10263 // fixup the template arguments here (just after we know that the firstNondefiningDeclaration is set correctly
10264 // and just before the symbol is inserted into the symbol table.
10265 if (buildTemplateInstantiation == true)
10266 {
10267 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
10268 }
10269#if DEBUG_NONDEFINING_CLASS_DECLARATION
10270 printf ("BEFORE scope->insert_symbol(): scope = %p = %s nameWithTemplateArguments = %s mysymbol = %p = %s \n",
10271 scope,scope->class_name().c_str(),nameWithTemplateArguments.str(),mysymbol,mysymbol->class_name().c_str());
10272#endif
10273
10274 // scope->insert_symbol(name, mysymbol);
10275 scope->insert_symbol(nameWithTemplateArguments, mysymbol);
10276
10277 // 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).
10278 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10279 if (nondefdecl->get_type() == NULL)
10280 {
10281#if 0
10282 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
10283 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_firstNondefiningDeclaration() = %p \n",nondefdecl->get_firstNondefiningDeclaration());
10284#endif
10285 nondefdecl->set_type(SgClassType::createType(nondefdecl));
10286#if 0
10287 printf ("In SageBuilder::buildNondefiningClassDeclaration(): built class type: part 2: nondefdecl->get_type() = %p = %s = %s \n",
10288 nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str(),nondefdecl->get_type()->unparseToString().c_str());
10289#endif
10290 }
10291
10292#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10293 printf ("NOTE: In buildNondefiningClassDeclaration_nfi(): 2nd time this is a performance issue (maybe) to call the lookup_nontemplate_class_symbol() again \n");
10294#endif
10295 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would
10296 // not include name qualification on template arguments.
10297 // DQ (12/27/2011): Added new test.
10298 // ROSE_ASSERT(scope->lookup_nontemplate_class_symbol(name) != NULL);
10299 // TV (07/01/2013): this assertion fail when building basic class (buildTemplateInstantiation = false , templateArgumentsList = NULL)
10300 // ROSE_ASSERT(scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
10301
10302 // DQ (6/9/2013): Added test to make sure that symbols only reference non-defining declarations.
10303 SgClassSymbol* temp_classSymbol = nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
10304#if DEBUG_NONDEFINING_CLASS_DECLARATION
10305 // DQ (12/28/2018): When can this be NULL?
10306 printf ("In buildNondefiningClassDeclaration_nfi(): temp_classSymbol = %p \n",temp_classSymbol);
10307 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_scope() = %p = %s scope = %p \n",nondefdecl->get_scope(),nondefdecl->get_scope()->class_name().c_str(),scope);
10308
10309 printf ("In buildNondefiningClassDeclaration_nfi(): nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
10310 if (templateArgumentsList != NULL)
10311 {
10312 printf (" --- templateArgumentsList elements: \n");
10313 for (size_t i = 0; i < templateArgumentsList->size(); i++)
10314 {
10315 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
10316 printf (" --- --- templateArgumentsList->[%zu] = %s \n",i,templateArgumentsList->operator[](i)->class_name().c_str());
10317 templateArgumentsList->operator[](i)->display("In SageBuilder::buildNondefiningClassDeclaration_nfi()");
10318 }
10319 }
10320#endif
10321 // DQ (12/28/2018): When can this be NULL? When we call lookup_class_symbol() later it is NULL, so test it here.
10322 ROSE_ASSERT(nondefdecl->get_scope()->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
10323 ROSE_ASSERT(nondefdecl->get_scope() == scope);
10324
10325 // TV (07/01/2013): temp_classSymbol can be NULL, but lookup_class_symbol return a symbol
10326 // ROSE_ASSERT(temp_classSymbol->get_declaration()->get_definition() == NULL);
10327 ROSE_ASSERT(temp_classSymbol == NULL || temp_classSymbol->get_declaration()->get_definition() == NULL);
10328 }
10329
10330 ROSE_ASSERT(mysymbol != NULL);
10331 ROSE_ASSERT(firstNondefdecl != NULL);
10332#endif
10333 nondefdecl->set_scope(scope);
10334
10335 // 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).
10336 // TPS (09/18/2009) added a condition to be able to build this properly
10337 if (scope==NULL)
10338 nondefdecl->set_parent(topScopeStack());
10339 else
10340 nondefdecl->set_parent(scope);
10341 }
10342
10343 // The support for SgEnumDeclaration handles the type, but why not for SgClassDeclaration?
10344 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10345
10346 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10347
10348#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10349 printf ("NOTE: In buildNondefiningClassDeclaration_nfi(): 3rd time this is a performance issue (maybe) to call the lookup_nontemplate_class_symbol() again \n");
10350#endif
10351
10352 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would not include name qualification on template arguments.
10353 // DQ (12/27/2011): Added new test.
10354 // ROSE_ASSERT(nondefdecl->get_scope()->lookup_nontemplate_class_symbol(name) != NULL);
10355 // TV (07/01/2013): this assertion fail when building basic class (buildTemplateInstantiation = false , templateArgumentsList = NULL)
10356 // ROSE_ASSERT(nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
10357
10358 // DQ (6/9/2013): Added test to make sure that symbols only reference non-defining declarations.
10359 SgClassSymbol* temp_classSymbol = nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
10360 // TV (07/01/2013): temp_classSymbol can be NULL, but lookup_class_symbol return a symbol
10361 ROSE_ASSERT(temp_classSymbol == NULL || temp_classSymbol->get_declaration()->get_definition() == NULL);
10362
10363 // DQ (3/9/2018): Added assertion.
10364 ROSE_ASSERT(nondefdecl != NULL);
10365 ROSE_ASSERT(nondefdecl->get_name() == nameWithTemplateArguments);
10366
10367 // DQ (3/9/2018): Test the consistancy of the template instantiation name.
10368 if (isSgTemplateInstantiationDecl(nondefdecl) != NULL)
10369 {
10370 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(nondefdecl);
10371 SgName finalName = appendTemplateArgumentsToName(templateInstantiationDecl->get_templateName(),templateInstantiationDecl->get_templateArguments());
10372 ROSE_ASSERT(finalName == nameWithTemplateArguments);
10373 ROSE_ASSERT(finalName == nondefdecl->get_name());
10374 }
10375
10376#if DEBUG_NONDEFINING_CLASS_DECLARATION
10377 printf ("Leaving buildNondefiningClassDeclaration_nfi(): nondefdecl = %p nondefdecl->unparseNameToString() = %s \n",nondefdecl,nondefdecl->unparseNameToString().c_str());
10378 printf (" --- nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
10379#endif
10380
10381#if DEBUG_NONDEFINING_CLASS_DECLARATION
10382 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
10383 printf ("Leaving buildNondefiningClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
10384 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
10385
10386 printf ("test_symbol = %p \n",test_symbol);
10387
10388 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
10389 printf ("Leaving buildNondefiningClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
10390 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
10391#endif
10392
10393 return nondefdecl;
10394 }
10395
10398 ROSE_ASSERT(stmt != NULL);
10399
10401 stmt->set_parent(result);
10402
10403 result->set_definingDeclaration(result);
10405 return result;
10406}
10407
10410 ROSE_ASSERT(stmt != NULL);
10411
10413 stmt->set_parent(result);
10414
10415 result->set_definingDeclaration(result);
10417 return result;
10418}
10419
10421SageBuilder::buildJovialDefineDeclaration_nfi(const SgName& name, const std::string& params,
10422 const std::string& def_string, SgScopeStatement* scope)
10423 {
10424 std::string directive_string(name);
10425
10426 if (scope == NULL)
10428 ROSE_ASSERT(scope);
10429
10430 if (params.length() > 0)
10431 directive_string += " " + params;
10432
10433 directive_string += " " + def_string;
10434
10435 SgJovialDefineDeclaration* define_decl = new SgJovialDefineDeclaration(directive_string);
10436 ROSE_ASSERT(define_decl);
10438
10439 // The first nondefining declaration must be set
10440 define_decl->set_firstNondefiningDeclaration(define_decl);
10441 define_decl->set_parent(scope);
10442
10443 return define_decl;
10444 }
10445
10446// Build a Jovial loop statement. Two variants are FOR and WHILE.
10447// A loop body will be created and its parent set to the loop statement.
10450{
10451 SgJovialForThenStatement* forStmt{nullptr};
10452
10454
10455 forStmt = new SgJovialForThenStatement(nullptr, nullptr, nullptr, body);
10456 ASSERT_not_null(forStmt);
10457 setOneSourcePositionNull(forStmt);
10458
10459 body->set_parent(forStmt);
10460
10462 forStmt->setCaseInsensitive(true);
10463 }
10464
10465 return forStmt;
10466}
10467
10468// This should take a SgClassDeclaration::class_types kind parameter!
10470 {
10471#if 0
10472
10473 if (scope == NULL)
10475
10476 // TODO How about class type??
10477 // build defining declaration
10479
10480 SgClassDeclaration* defdecl = new SgClassDeclaration (name,SgClassDeclaration::e_struct,NULL,classDef);
10481 ROSE_ASSERT(defdecl);
10483 // constructor is side-effect free
10484 classDef->set_declaration(defdecl);
10485 defdecl->set_definingDeclaration(defdecl);
10486
10487 // build the nondefining declaration
10488 SgClassDeclaration* nondefdecl = new SgClassDeclaration (name,SgClassDeclaration::e_struct,NULL,NULL);
10489 ROSE_ASSERT(nondefdecl);
10490
10492 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10493 nondefdecl->set_definingDeclaration(defdecl);
10494 defdecl->set_firstNondefiningDeclaration(nondefdecl);
10495 nondefdecl->setForward();
10496
10497 if (scope !=NULL ) // put into fixStructDeclaration() or alike later on
10498 {
10499 fixStructDeclaration(nondefdecl,scope);
10500 fixStructDeclaration(defdecl,scope);
10501 }
10502#else
10503 // DQ (1/24/2009): Refactored to use the buildStructDeclaration_nfi function.
10504 // (if this work it needs to be done uniformally for the other nfi functions)
10505 // Also, "_nfi" is not a great name.
10506 // SgClassDeclaration* defdecl = buildClassDeclaration_nfi(name,SgClassDeclaration::e_struct,scope,NULL);
10507 bool buildTemplateInstantiation = false;
10508 // SgClassDeclaration* defdecl = buildClassDeclaration_nfi(name,SgClassDeclaration::e_struct,scope,NULL,buildTemplateInstantiation);
10509 SgClassDeclaration* defdecl = buildClassDeclaration_nfi(name,SgClassDeclaration::e_struct,scope,NULL,buildTemplateInstantiation,NULL);
10510
10512 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
10514#endif
10515
10516 // DQ (1/26/2009): I think this should be an error, but that appears it would
10517 // break the existing interface. Need to discuss this with Liao.
10518 // ROSE_ASSERT(defdecl->get_parent() != NULL);
10519
10520 return defdecl;
10521 }
10522
10525 {
10527 SgDerivedTypeStatement* type_decl = buildClassDeclarationStatement_nfi <SgDerivedTypeStatement> (name, kind, scope);
10528
10530 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() != NULL);
10532
10533 return type_decl;
10534 }
10535
10538 {
10540 SgModuleStatement* module_stmt = buildClassDeclarationStatement_nfi <SgModuleStatement> (name, kind, scope);
10541
10543 ROSE_ASSERT(module_stmt->get_firstNondefiningDeclaration() != NULL);
10545
10546 return module_stmt;
10547 }
10548
10552 SgScopeStatement* scope /*=NULL*/)
10553 {
10554 SgJovialTableStatement* table_decl = buildClassDeclarationStatement_nfi <SgJovialTableStatement> (name, kind, scope);
10555
10557 ROSE_ASSERT(table_decl->get_firstNondefiningDeclaration() != NULL);
10559
10560 return table_decl;
10561 }
10562
10565 {
10566 std::string type_name(name);
10567 if (base_type) {
10568 // Mangle the name to make sure the table type and the base type don't have the same name
10569 type_name = "_table_of_" + type_name;
10570 // Add dim_info address if there are subscripts to ensure type is unique
10571 if (dim_info->get_expressions().size() > 0) {
10572 std::ostringstream address;
10573 address << (void const *)dim_info;
10574 type_name += "_" + address.str();
10575 }
10576 }
10577
10579 SgJovialTableStatement* table_decl = buildClassDeclarationStatement_nfi <SgJovialTableStatement> (type_name, kind, scope);
10580
10582 ROSE_ASSERT(table_decl->get_firstNondefiningDeclaration() != NULL);
10584
10585 // For a type declaration the parent of the nondefining declaration is the defining declaration
10586 SgClassDeclaration* nondef_decl = isSgClassDeclaration(table_decl->get_firstNondefiningDeclaration());
10587 ROSE_ASSERT(nondef_decl != NULL);
10588 nondef_decl->set_parent(table_decl);
10589
10590 SgJovialTableType* table_type = isSgJovialTableType(table_decl->get_type());
10591 ROSE_ASSERT(table_type != NULL);
10592
10593 table_type->set_base_type(base_type);
10594 table_type->set_dim_info(dim_info);
10595 table_type->set_rank(dim_info->get_expressions().size());
10596
10597 dim_info->set_parent(table_type);
10598 nondef_decl->set_type(table_type);
10599
10600 return table_type;
10601 }
10602
10604template <class DeclClass> DeclClass *
10606 SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl)
10607 {
10608 // DQ (3/15/2012): Added function to build C++ class (builds both the non-defining and defining declarations; in that order).
10609 // The implementation of this function could be simplified to directly call both:
10610 // SgClassDeclaration* buildNondefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10611 // and
10612 // SgClassDeclaration* buildDefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10613 // This might refactor the implementation nicely.
10614
10615 if (scope == NULL)
10616 {
10618 }
10619
10620 // Step 1. Build the nondefining declaration (but only if the input nonDefiningDecl pointer was NULL and it does not exist)
10621 // -----------------------------------------
10622 //
10623
10624 // Get the nondefining declaration from the symbol if it has been built (if this works,
10625 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
10626
10627 SgClassDeclaration* nondefdecl = NULL;
10628 SgClassSymbol* mysymbol = NULL;
10629
10630 if (scope != NULL)
10631 {
10632 // DQ (10/10/2015): look up the correct type of symbol.
10633 mysymbol = scope->lookup_class_symbol(name);
10634
10635 if (mysymbol == NULL)
10636 {
10637 // Note: this is an input parameter (could/should go away?) [CR]
10638 if (nonDefiningDecl != NULL)
10639 {
10640 // DQ (3/4/2018): I think this is the correct API to use (internal use only).
10641 SgSymbol* temp_mysymbol = nonDefiningDecl->get_symbol_from_symbol_table();
10642 ROSE_ASSERT(temp_mysymbol != NULL);
10643
10644 mysymbol = isSgClassSymbol(temp_mysymbol);
10645 ROSE_ASSERT(mysymbol != NULL);
10646
10647 // check that the scopes are the same.
10648 ROSE_ASSERT(scope == nonDefiningDecl->get_scope());
10649 }
10650 }
10651 }
10652
10653 if (mysymbol != NULL) // set links for existing nondefining declaration
10654 {
10655 nondefdecl = (mysymbol->get_declaration() == NULL)
10656 ? NULL : dynamic_cast<DeclClass*>(mysymbol->get_declaration());
10657 ROSE_ASSERT(nondefdecl != NULL);
10658
10659 // DQ (6/8/2013): This should not be true (see test2013_198.C).
10660 // Fundamentally the symbol should always only have a pointer to a non-defining
10661 // declaration, where by definition (get_definition() == NULL).
10662 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10663
10664 // DQ (9/16/2012): This should be true by definition (verify).
10665 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
10666
10667 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10668 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10669
10670 // DQ (9/7/2012): I think this might be the root of a problem in the haskell tests (ROSE compiling ROSE).
10671 if (nondefdecl->get_definingDeclaration() != NULL)
10672 {
10673 DeclClass* nondefining_classDeclaration = (nondefdecl == NULL) ? NULL : dynamic_cast<DeclClass*>(nondefdecl);
10674 ROSE_ASSERT(nondefining_classDeclaration != NULL);
10675 DeclClass* defining_classDeclaration = (nondefdecl->get_definingDeclaration() == NULL)
10676 ? NULL : dynamic_cast<DeclClass*>(nondefdecl->get_definingDeclaration());
10677 ROSE_ASSERT(defining_classDeclaration != NULL);
10678
10679 return defining_classDeclaration;
10680 }
10681 }
10682 else // build a nondefining declaration since it does not exist
10683 {
10684 ROSE_ASSERT(nondefdecl == NULL);
10685
10686 // DeclClass is the template type parameter
10687 nondefdecl = new DeclClass(name, kind, NULL, NULL);
10688 ROSE_ASSERT(nondefdecl != NULL);
10689
10690 // The first nondefining declaration has to be set before we generate the type.
10691 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10692
10693 // 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.
10694 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
10695
10696 // DQ (3/14/2012): For C++ we need the scope set so that types will have proper locations to resolve them
10697 // from being ambiguous or not properly defined. Basically, we need a handle from which to generate something
10698 // that amounts to a kind of name qualification internally (maybe even exactly name qualification, but I would
10699 // have to think about that a bit more).
10700 ROSE_ASSERT(scope != NULL);
10701
10702 // Set the parent before calling the SgClassType::createType() as the name mangling will require it.
10703 // This is true for Fortran SgDerivedTypeStatement at least.
10704 nondefdecl->set_parent(scope);
10705 nondefdecl->set_scope(scope);
10706
10707 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
10708 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10709
10710 if (nondefdecl->get_type() == NULL)
10711 {
10712 SgClassType* class_type = NULL;
10713 switch (kind)
10714 {
10716 class_type = SgJavaParameterType::createType(nondefdecl);
10717 break;
10720 class_type = SgJovialTableType::createType(nondefdecl);
10721 break;
10722 default:
10723 class_type = SgClassType::createType(nondefdecl);
10724 break;
10725 }
10726 ROSE_ASSERT(class_type != NULL);
10727
10728 nondefdecl->set_type(class_type);
10729
10730 SgClassDeclaration* tmp_classDeclarationFromType = isSgClassDeclaration(class_type->get_declaration());
10731 ROSE_ASSERT(tmp_classDeclarationFromType != NULL);
10732 }
10733
10734 // DQ (3/22/2012): Added assertions.
10735 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10736 if (nondefdecl->get_type()->get_declaration() != nondefdecl)
10737 {
10738 printf ("ERROR: nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
10739 printf ("ERROR: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
10740 printf ("ERROR: nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
10741
10742 SgClassDeclaration* classDeclarationFromType = isSgClassDeclaration(nondefdecl->get_type()->get_declaration());
10743 ROSE_ASSERT(classDeclarationFromType != NULL);
10744
10745 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
10746 printf ("nondefdecl->get_type()->get_name() = %s \n",nondefdecl->get_type()->get_name().str());
10747 printf ("nondefdecl->get_type()->get_declaration()->get_name() = %s \n",classDeclarationFromType->get_name().str());
10748
10749 printf ("nondefdecl->get_mangled_name() = %s \n",nondefdecl->get_mangled_name().getString().c_str());
10750 printf ("nondefdecl->get_type()->get_mangled() = %s \n",nondefdecl->get_type()->get_mangled().getString().c_str());
10751 printf ("nondefdecl->get_type()->get_declaration()->get_mangled_name() = %s \n",classDeclarationFromType->get_mangled_name().getString().c_str());
10752
10753 // DQ (12/27/2018): Added additional debugging support.
10754 printf ("nondefdecl->get_type()->get_declaration()->get_firstNondefiningDeclaration() = %s \n",classDeclarationFromType->get_firstNondefiningDeclaration() ? "true" : "false");
10755 printf ("nondefdecl->get_firstNondefiningDeclaration() = %s \n",nondefdecl->get_firstNondefiningDeclaration() ? "true" : "false");
10756
10757 // 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.
10758 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10759 if (nondefdecl->get_parent() != NULL)
10760 {
10761 printf ("nondefdecl->get_parent() = %p = %s \n",nondefdecl->get_parent(),nondefdecl->get_parent()->class_name().c_str());
10762 }
10763 }
10764 ROSE_ASSERT(nondefdecl->get_type()->get_declaration() == nondefdecl);
10765
10766 // The nondefining declaration will not appear in the source code, but is compiler
10767 // generated (so we have something about the class that we can reference; e.g in
10768 // types). At the moment we make it a transformation, there might be another kind
10769 // of source position that would be more precise. FIXME.
10770 // setOneSourcePositionNull(nondefdecl);
10772 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
10773
10774#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
10775 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
10776 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
10777 {
10778 detectTransformations(nondefdecl);
10779 }
10780#endif
10781
10782 nondefdecl->setForward();
10783
10784 if (scope != NULL)
10785 {
10786 mysymbol = new SgClassSymbol(nondefdecl);
10787 scope->insert_symbol(name, mysymbol);
10788
10789 ROSE_ASSERT(nondefdecl->get_scope() == scope);
10790 }
10791 }
10792
10793 // DQ (3/15/2012): I have moved construction of defining declaration to be AFTER the nondefining declaration!
10794 // This is a better organization ans also should make sure that the declaration in the SgClassType will
10795 // properly reference the firstNondefiningDeclaration (instead of the defining declaration).
10796
10797 // Step 2. Build the defining declaration
10798 // --------------------------------------
10799 //
10801
10802 DeclClass* defdecl = new DeclClass(name,kind,NULL,classDef);
10803 ROSE_ASSERT(defdecl != NULL);
10804 ROSE_ASSERT(defdecl->get_type() == NULL);
10805
10806 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
10807 ROSE_ASSERT(defdecl->get_definition() != NULL);
10808 ROSE_ASSERT(defdecl != NULL);
10809
10810 // DQ (3/15/2012): Moved from original location above...
10811 nondefdecl->set_definingDeclaration(defdecl);
10812
10813 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
10814 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
10815
10817 // constructor is side-effect free
10818 classDef->set_declaration(defdecl);
10819 defdecl->set_definingDeclaration(defdecl);
10820
10821 defdecl->set_firstNondefiningDeclaration(nondefdecl);
10822
10823 // DQ (3/22/2012): I think we can assert this.
10824 ROSE_ASSERT(defdecl->get_type() == NULL);
10825
10826 // Liao, 10/30/2009
10827 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
10828 // This is not desired when building a defining declaration and an inefficience in the constructor
10829 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
10830 // the defining class declaration (and other nondefining declaration) just share that SgClassType.
10831 if (defdecl->get_type() != NULL)
10832 {
10833 // Removed several lines of dead code because of the assertion just above
10834 }
10835 else
10836 {
10837 // DQ (3/15/2012): Make sure that both the defining and non-defining declarations use the same type.
10838 ROSE_ASSERT (nondefdecl->get_type() != NULL);
10839 defdecl->set_type(nondefdecl->get_type());
10840
10841 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
10842 }
10843
10844 // DQ (9/4/2012): Added assertion.
10845 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10846
10847 // patch up the SgClassType for the defining class declaration
10848 ROSE_ASSERT (nondefdecl->get_type() != NULL);
10849 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
10850 // ROSE_ASSERT (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl));
10851 ROSE_ASSERT (defdecl->get_type() != NULL);
10852 ROSE_ASSERT (defdecl->get_type()->get_declaration() != NULL);
10853 ROSE_ASSERT (defdecl->get_type()->get_declaration() != isSgDeclarationStatement(defdecl));
10854 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
10855 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
10856
10857 // DQ (9/4/2012): Added assertion.
10858 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10859
10860 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
10861 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
10862 // used in a defining declaration).
10863 nondefdecl->setForward();
10864
10865 if (scope != NULL) // put into fixStructDeclaration() or alike later on
10866 {
10867 // DQ (9/4/2012): Added assertion.
10868 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10869
10870 // Note, this function sets the parent to be the scope if it is not already set.
10871 fixStructDeclaration(defdecl,scope);
10872
10873 // DQ (9/4/2012): Added assertion.
10874 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10875
10876 fixStructDeclaration(nondefdecl,scope);
10877
10878 // DQ (9/4/2012): Added assertion.
10879 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10880 }
10881
10882 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
10883 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
10884 // ROSE_ASSERT(defdecl->get_parent() != NULL);
10885
10886 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
10887
10888 // DQ (2/27/2012): Tracking down where parents are not set correctly (class declaration in typedef is incorrectly set to SgGlobal).
10889 ROSE_ASSERT(defdecl->get_parent() == NULL);
10890
10891 // DQ (2/29/2012): We can't assert this (fails for test2012_09.C).
10892 // ROSE_ASSERT(nondefdecl->get_parent() == NULL);
10893
10894 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
10895 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
10896
10897 // DQ (3/8/2018): Added for debugging.
10898 SgClassDeclaration* temp_firstNondefiningDeclaration = isSgClassDeclaration(defdecl->get_firstNondefiningDeclaration());
10899 SgClassDeclaration* temp_definingDeclaration = isSgClassDeclaration(defdecl->get_definingDeclaration());
10900 ROSE_ASSERT(temp_firstNondefiningDeclaration != NULL);
10901 ROSE_ASSERT(temp_definingDeclaration != NULL);
10902
10903 // DQ (3/8/2018): Added assertion.
10904 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_name() == temp_definingDeclaration->get_name());
10905 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_type() == temp_definingDeclaration->get_type());
10906
10907#if 0
10908 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
10909 printf ("Leaving buildClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
10910 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
10911
10912 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
10913 printf ("Leaving buildClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
10914 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
10915#endif
10916
10917 return defdecl;
10918 }
10919
10922 {
10923 SgNamespaceAliasDeclarationStatement* aliasdecl = new SgNamespaceAliasDeclarationStatement(name,namespaceDeclaration);
10926 return aliasdecl;
10927 }
10928
10929
10932 {
10934
10936 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
10938
10939 return defdecl;
10940 }
10941
10943SageBuilder::buildNamespaceDeclaration_nfi(const SgName& name, bool unnamednamespace, SgScopeStatement* scope)
10944 {
10945 if (scope == NULL)
10947
10948 ROSE_ASSERT(scope != NULL);
10949
10950#if 0
10951 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): scope = %p = %s = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
10952#endif
10953
10954 // TODO How about class type??
10955 // build defining declaration
10957
10958 SgNamespaceDeclarationStatement* defdecl = new SgNamespaceDeclarationStatement(name,namespaceDef,unnamednamespace);
10959 ROSE_ASSERT(defdecl != NULL);
10960 namespaceDef->set_parent(defdecl);
10961
10962#if 0
10963 printf ("#################### SageBuilder::buildNamespaceDeclaration_nfi(): defdecl = %p = %s namespaceDef = %p \n",defdecl,defdecl->get_name().str(),namespaceDef);
10964#endif
10965
10966 // setOneSourcePositionForTransformation(defdecl);
10967 setOneSourcePositionNull(defdecl);
10968
10969 // constructor is side-effect free
10970 namespaceDef->set_namespaceDeclaration(defdecl);
10971
10972 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
10973 // defdecl->set_definingDeclaration(defdecl);
10974 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
10975
10976 // Get the nondefining declaration from the symbol if it has been built (if this works,
10977 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
10978 SgNamespaceDeclarationStatement* nondefdecl = NULL;
10979
10980 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
10981 // ROSE_ASSERT(scope != NULL);
10982 SgNamespaceSymbol* mysymbol = NULL;
10983 if (scope != NULL)
10984 {
10985 mysymbol = scope->lookup_namespace_symbol(name);
10986 }
10987 else
10988 {
10989 // DQ (1/26/2009): I think this should be an error, but that appears it would
10990 // break the existing interface. Need to discuss this with Liao.
10991 printf ("Warning: In SageBuilder::buildNamespaceDeclaration_nfi(): scope == NULL \n");
10992 }
10993
10994#if 0
10995 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): mysymbol = %p \n",mysymbol);
10996#endif
10997
10998 if (mysymbol != NULL)
10999 {
11000 // nondefdecl = isSgNamespaceDeclarationStatement(mysymbol->get_declaration());
11001 SgNamespaceDeclarationStatement* namespaceDeclaration = mysymbol->get_declaration();
11002 ROSE_ASSERT(namespaceDeclaration != NULL);
11003 nondefdecl = isSgNamespaceDeclarationStatement(namespaceDeclaration);
11004
11005 ROSE_ASSERT(nondefdecl != NULL);
11006 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11007
11008 // DQ (5/16/2013): These should be non-defining declarations for the case of a C++ namespace (all instances are a non-defining declaration).
11009 // nondefdecl->set_definingDeclaration(defdecl);
11010 // ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
11011 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == NULL);
11012 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
11013
11014 // DQ (5/16/2013): Set the global definition for the new namespace definition.
11015 ROSE_ASSERT(namespaceDeclaration->get_definition() != NULL);
11016 if (namespaceDeclaration->get_definition()->get_global_definition() == NULL)
11017 {
11018 printf ("ERROR: namespaceDeclaration->get_definition()->get_global_definition() == NULL: namespaceDeclaration = %p = %s namespaceDeclaration->get_definition() = %p \n",
11019 namespaceDeclaration,namespaceDeclaration->get_name().str(),namespaceDeclaration->get_definition());
11020 }
11021 ROSE_ASSERT(namespaceDeclaration->get_definition()->get_global_definition() != NULL);
11022 namespaceDef->set_global_definition(namespaceDeclaration->get_definition()->get_global_definition());
11023 ROSE_ASSERT(namespaceDef->get_global_definition() != NULL);
11024
11025 // DQ (5/19/2013): Make the global_definition point to itself.
11026 ROSE_ASSERT(namespaceDef->get_global_definition() == namespaceDef->get_global_definition()->get_global_definition());
11027
11028 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
11029
11030 ROSE_ASSERT(nondefdecl->get_definition()->get_previousNamespaceDefinition() == NULL);
11031 // ROSE_ASSERT(nondefdecl->get_definition()->get_nextNamespaceDefinition() == NULL);
11032
11033 SgNamespaceDefinitionStatement* i = namespaceDeclaration->get_definition();
11034 ROSE_ASSERT(i != NULL);
11035 while (i != NULL && i->get_nextNamespaceDefinition() != NULL)
11036 {
11037 i = i->get_nextNamespaceDefinition();
11038 ROSE_ASSERT(i->get_previousNamespaceDefinition() != NULL);
11039 }
11040
11041 ROSE_ASSERT(i != NULL);
11042 i->set_nextNamespaceDefinition(namespaceDef);
11043 namespaceDef->set_previousNamespaceDefinition(i);
11044 }
11045 else
11046 {
11047 // DQ (5/16/2013): Note that since we don't build a SgNamespaceDefinition for the declaration we can't
11048 // build the global_definition. This is a potential problem.
11049
11050#if 1
11051 nondefdecl = defdecl;
11052 ROSE_ASSERT(nondefdecl != NULL);
11053 namespaceDef = nondefdecl->get_definition();
11054 ROSE_ASSERT(namespaceDef->get_namespaceDeclaration() != NULL);
11055#else
11056 // DQ (5/16/2013): We want to build an associated SgNamespaceDefinitionStatement so that we can
11057 // support a reference to a SgNamespaceDefinitionStatement as a global definition.
11058 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
11059 // nondefdecl = new SgNamespaceDeclarationStatement(name,NULL, unnamednamespace);
11060
11061#error "DEAD CODE!"
11062
11064 nondefdecl = new SgNamespaceDeclarationStatement(name,namespaceDef,unnamednamespace);
11065 ROSE_ASSERT(nondefdecl != NULL);
11066#if 0
11067 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): Built namespace definition for nondefdecl = %p = %s definition = %p \n",nondefdecl,nondefdecl->get_name().str(),namespaceDef);
11068#endif
11069 // DQ (5/16/2013): Added tests and setting of the associated declaration.
11070 ROSE_ASSERT(namespaceDef->get_namespaceDeclaration() == NULL);
11071 namespaceDef->set_namespaceDeclaration(nondefdecl);
11072 ROSE_ASSERT(namespaceDef->get_namespaceDeclaration() != NULL);
11073#endif
11074
11075 // DQ (5/16/2013): Now add the global definition where we will accumulate all of the symbols for the logical namespace.
11076 SgNamespaceDefinitionStatement* global_definition_namespaceDef = buildNamespaceDefinition();
11077 namespaceDef->set_global_definition(global_definition_namespaceDef);
11078 ROSE_ASSERT(namespaceDef->get_global_definition() != NULL);
11079
11080 // DQ (5/19/2013): Make the global_definition point to itself.
11081 global_definition_namespaceDef->set_global_definition(global_definition_namespaceDef);
11082
11083 global_definition_namespaceDef->set_isUnionOfReentrantNamespaceDefinitions(true);
11084
11085 // DQ (8/23/2013): Set the parent of the global_definition_namespaceDef.
11086 ROSE_ASSERT(global_definition_namespaceDef->get_parent() == NULL);
11087 global_definition_namespaceDef->set_parent(defdecl);
11088 ROSE_ASSERT(global_definition_namespaceDef->get_parent() != NULL);
11089
11090 // DQ (5/16/2013): Added tests and setting of the associated declaration.
11091 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() == NULL);
11092 global_definition_namespaceDef->set_namespaceDeclaration(nondefdecl);
11093 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() != NULL);
11094
11095 // DQ (5/16/2013): Set the associated declaration to be the nondefdecl.
11096 global_definition_namespaceDef->set_namespaceDeclaration(nondefdecl);
11097 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() != NULL);
11098
11099#if 0
11100 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() == NULL);
11101 // defdecl->get_definition()->set_global_definition(namespaceDef->get_global_definition());
11102 defdecl->get_definition()->set_global_definition(global_definition_namespaceDef);
11103#else
11104#if 0
11105 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): defdecl->get_definition()->get_global_definition() = %p \n",defdecl->get_definition()->get_global_definition());
11106#endif
11107 if (defdecl->get_definition()->get_global_definition() == NULL)
11108 {
11109 defdecl->get_definition()->set_global_definition(global_definition_namespaceDef);
11110 }
11111
11112 // DQ (5/19/2013): Make the global_definition point to itself.
11113 ROSE_ASSERT(global_definition_namespaceDef == global_definition_namespaceDef->get_global_definition());
11114#endif
11115 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
11116 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() == namespaceDef->get_global_definition());
11117#if 0
11118 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());
11119#endif
11120 // printf ("SageBuilder::buildNamespaceDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11121
11122 // The nondefining declaration will not appear in the source code, but is compiler
11123 // generated (so we have something about the class that we can reference; e.g in
11124 // types). At the moment we make it a transformation, there might be another kind
11125 // of source position that would be more precise. FIXME.
11126 // setOneSourcePositionNull(nondefdecl);
11127 // setOneSourcePositionForTransformation(nondefdecl);
11128
11129 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11130
11131 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
11132 // nondefdecl->set_definingDeclaration(defdecl);
11133 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == NULL);
11134 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
11135
11136 nondefdecl->setForward();
11137
11138 // nondefdecl->set_parent(topScopeStack());
11139 nondefdecl->set_parent(scope);
11140 ROSE_ASSERT(nondefdecl->get_parent());
11141
11142 if (scope != NULL)
11143 {
11144 mysymbol = new SgNamespaceSymbol(name,nondefdecl); // tps: added name to constructor
11145 scope->insert_symbol(name, mysymbol);
11146 }
11147 else
11148 {
11149 // DQ (1/26/2009): I think this should be an error, but that appears it would
11150 // break the existing interface. Need to discuss this with Liao.
11151 printf ("Warning: no scope provided to support symbol table entry! \n");
11152 }
11153
11154 ROSE_ASSERT(defdecl->get_definition() != NULL);
11155 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
11156
11157 ROSE_ASSERT(nondefdecl->get_definition()->get_previousNamespaceDefinition() == NULL);
11158 ROSE_ASSERT(nondefdecl->get_definition()->get_nextNamespaceDefinition() == NULL);
11159 }
11160
11161 ROSE_ASSERT(nondefdecl != NULL);
11162
11163 // printf ("SageBuilder::buildNamespaceDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11164
11165 // setOneSourcePositionForTransformation(nondefdecl);
11166 // setOneSourcePositionNull(nondefdecl);
11167
11168 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11169 // nondefdecl->set_definingDeclaration(defdecl);
11170 defdecl->set_firstNondefiningDeclaration(nondefdecl);
11171
11172 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
11173 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
11174 // used in a defining declaration).
11175 nondefdecl->setForward();
11176
11177 if (scope != NULL) // put into fixStructDeclaration() or alike later on
11178 {
11179 fixNamespaceDeclaration(nondefdecl,scope);
11180 fixNamespaceDeclaration(defdecl,scope);
11181#if 0
11182 SgClassSymbol* mysymbol = new SgClassSymbol(nondefdecl);
11183 ROSE_ASSERT(mysymbol);
11184 scope->insert_symbol(name, mysymbol);
11185#endif
11186
11187 // tps namespace has no scope
11188 //defdecl->set_scope(scope);
11189 //nondefdecl->set_scope(scope);
11190
11191 // defdecl->set_parent(scope);
11192
11193 // 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).
11194 // nondefdecl->set_parent(scope);
11195 // nondefdecl->set_parent(topScopeStack());
11196 }
11197
11198 // defdecl->set_parent(topScopeStack());
11199
11200 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
11201 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
11202 // ROSE_ASSERT(defdecl->get_parent() != NULL);
11203
11204 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
11205
11206 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
11207 // ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
11208 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
11209
11210 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
11211 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
11212
11213 // DQ (5/16/2013): Added tests.
11214 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
11215 ROSE_ASSERT(defdecl->get_definition() != NULL);
11216 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
11217
11218#if 0
11219 // DQ (5/19/2013): There should always be proper source file position infomation so this should not be required.
11220 if (defdecl->get_file_info()->isOutputInCodeGeneration() == true)
11221 {
11222 defdecl->get_file_info()->display("In buildNamespaceDeclaration_nfi(): namespaceDeclaration: debug");
11223 }
11224 // ROSE_ASSERT(defdecl->get_file_info()->isOutputInCodeGeneration() == false);
11225#endif
11226
11227 return defdecl;
11228 }
11229
11230// driscoll6 (7/20/11) : Support n-ary operators for python
11233 SgNaryComparisonOp* result = new SgNaryComparisonOp();
11234
11235 result->get_operands().push_back(lhs);
11236 lhs->set_parent(result);
11237
11239 return result;
11240}
11241
11244 SgNaryComparisonOp* result = new SgNaryComparisonOp();
11245
11246 result->get_operands().push_back(lhs);
11247 lhs->set_parent(result);
11248
11250 return result;
11251}
11252
11255 SgNaryBooleanOp* result = new SgNaryBooleanOp();
11256
11257 result->get_operands().push_back(lhs);
11258 lhs->set_parent(result);
11259
11261 return result;
11262}
11263
11266 SgNaryBooleanOp* result = new SgNaryBooleanOp();
11267
11268 result->get_operands().push_back(lhs);
11269 lhs->set_parent(result);
11270
11272 return result;
11273}
11274
11277 ROSE_ASSERT(exp);
11278 SgStringConversion* result = new SgStringConversion(exp);
11279 exp->set_parent(result);
11280
11282 return result;
11283}
11284
11285
11288 ROSE_ASSERT(exp);
11289 SgStringConversion* result = new SgStringConversion(exp);
11290 exp->set_parent(result);
11291
11293 return result;
11294}
11295
11296// DQ (11/7/2009): Added more uniform support for building class declarations.
11299 {
11300 SgClassDeclaration* defdecl = NULL;
11301 SgClassDeclaration* nondefdecl = NULL;
11302
11303 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
11304 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
11305 ROSE_ASSERT(SageInterface::hasTemplateSyntax(name) == false);
11306
11307#if 1
11308 printf ("In buildNondefiningClassDeclaration(): name = %s scope = %p = %s \n",name.str(),scope,scope != NULL ? scope->class_name().c_str() : "NULL");
11309
11310 // DQ (8/12/2013): If this function were to be called then we would have to
11311 // support a template argument list for the call to lookup_class_symbol().
11312
11313 // DQ (6/9/2013): I want to know that I'm not debugging this function.
11314 ROSE_ABORT();
11315#endif
11316
11317 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
11318 // ROSE_ASSERT(scope != NULL);
11319 SgClassSymbol* mysymbol = NULL;
11320 if (scope != NULL)
11321 {
11322 // mysymbol = scope->lookup_class_symbol(name);
11323 mysymbol = scope->lookup_class_symbol(name,NULL);
11324 }
11325 else
11326 {
11327 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unkown.
11328 // DQ (1/26/2009): I think this should be an error, but that appears it would
11329 // break the existing interface. Need to discuss this with Liao.
11330 // printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): scope == NULL \n");
11331 }
11332
11333#if 0
11334 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
11335#endif
11336
11337 if (mysymbol != NULL) // set links if nondefining declaration already exists.
11338 {
11339 nondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
11340
11341 ROSE_ASSERT(nondefdecl != NULL);
11342 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11343
11344 nondefdecl->set_definingDeclaration(defdecl);
11345
11346 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
11347 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
11348
11349 // DQ (10/30/2010): There should be a properly defined type at this point!
11350 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11351
11352 // DQ (7/31/2019): Check that this is true.
11353 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11354 }
11355 else // build a nondefnining declaration if it does not exist
11356 {
11357 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
11358
11360 nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
11361 ROSE_ASSERT(nondefdecl != NULL);
11362 if (nondefdecl->get_type() == NULL)
11363 {
11364 nondefdecl->set_type(SgClassType::createType(nondefdecl));
11365#if 0
11366 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());
11367#endif
11368 }
11369
11370 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11371
11372 // The nondefining declaration will not appear in the source code, but is compiler
11373 // generated (so we have something about the class that we can reference; e.g in
11374 // types). At the moment we make it a transformation, there might be another kind
11375 // of source position that would be more precise. FIXME.
11376 // setOneSourcePositionNull(nondefdecl);
11378
11379 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11380 nondefdecl->set_definingDeclaration(defdecl);
11381 nondefdecl->setForward();
11382 // Liao, 9/2/2009. scope stack is optional, it can be empty
11383 // nondefdecl->set_parent(topScopeStack());
11384 // nondefdecl->set_parent(scope);
11385
11386 // DQ (7/31/2019): Check that this is true.
11387 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11388
11389 // DQ (3/24/2011): This should be NULL before we set it (if the scope is known).
11390 ROSE_ASSERT(nondefdecl->get_scope() == NULL);
11391 if (scope != NULL)
11392 {
11393 // 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.
11394 nondefdecl->set_scope(scope);
11395 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
11396
11397 mysymbol = new SgClassSymbol(nondefdecl);
11398#if 0
11399 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());
11400#endif
11401 scope->insert_symbol(name, mysymbol);
11402 }
11403 else
11404 {
11405 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknown.
11406 // DQ (1/26/2009): I think this should be an error, but that appears it would
11407 // break the existing interface. Need to discuss this with Liao.
11408 // printf ("Warning: no scope provided to support symbol table entry! \n");
11409 }
11410
11411 // DQ (10/30/2010): There should be a properly defined type at this point!
11412 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11413
11414 // DQ (3/24/2011): The scope should be set if the scope was available.
11415 ROSE_ASSERT(scope == NULL || (scope != NULL && nondefdecl->get_scope() != NULL));
11416 }
11417
11418 ROSE_ASSERT(nondefdecl != NULL);
11419
11420 return nondefdecl;
11421 }
11422
11423// DQ (11/7/2009): Added more uniform support for building class declarations.
11426 {
11427 // Note that the semantics of this function now differs from that of the buildDefiningFunctionDeclaration().
11428 // We want to have the non-defining declaration already exist before calling this function.
11429 // We could still build a higher level function that built both together. Or we could provide two versions
11430 // named differently (from this one) and deprecate this function...which I like much better.
11431 printf ("WARNING: This function for building defining class declarations has different semantics from that of the function to build defining function declarations. \n");
11432
11433#if 1
11434 printf ("In buildDefiningClassDeclaration(): name = %s scope = %p = %s \n",name.str(),scope,scope != NULL ? scope->class_name().c_str() : "NULL");
11435
11436 // DQ (6/9/2013): I want to know that I'm not debugging this function.
11437 ROSE_ABORT();
11438#endif
11439
11440 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
11441 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
11442 ROSE_ASSERT(SageInterface::hasTemplateSyntax(name) == false);
11443
11444 SgClassDeclaration* nondefiningClassDeclaration = buildNondefiningClassDeclaration(name,scope);
11445 ROSE_ASSERT(nondefiningClassDeclaration != NULL);
11446
11447 SgClassDefinition* definingClassDefinition = buildClassDefinition();
11448 ROSE_ASSERT(definingClassDefinition != NULL);
11449
11450 // DQ (10/30/2010): There should be a properly defined type at this point!
11451 SgClassType* classType = nondefiningClassDeclaration->get_type();
11452 ROSE_ASSERT(classType != NULL);
11453
11455
11456 // DQ (10/30/2010): We need to make sure that there is a type defined.
11457 // SgClassDeclaration* definingClassDeclaration = new SgClassDeclaration (name,kind,NULL,definingClassDefinition);
11458 SgClassDeclaration* definingClassDeclaration = new SgClassDeclaration (name,kind,classType,definingClassDefinition);
11459 ROSE_ASSERT(definingClassDeclaration != NULL);
11460
11461 // printf ("SageBuilder::buildDefiningClassDeclaration(): definingClassDeclaration = %p \n",definingClassDeclaration);
11462
11463 setOneSourcePositionForTransformation(definingClassDeclaration);
11464
11465 // constructor is side-effect free
11466 definingClassDefinition->set_declaration(definingClassDeclaration);
11467 definingClassDeclaration->set_definingDeclaration(definingClassDeclaration);
11468 definingClassDeclaration->set_firstNondefiningDeclaration(nondefiningClassDeclaration);
11469
11470 nondefiningClassDeclaration->set_definingDeclaration(definingClassDeclaration);
11471
11472 // some error checking
11473 ROSE_ASSERT(nondefiningClassDeclaration->get_definingDeclaration() != NULL);
11474 ROSE_ASSERT(nondefiningClassDeclaration->get_firstNondefiningDeclaration() != NULL);
11475 ROSE_ASSERT(definingClassDeclaration->get_firstNondefiningDeclaration() != NULL);
11476 ROSE_ASSERT(definingClassDeclaration->get_definition() != NULL);
11477
11478 ROSE_ASSERT(definingClassDeclaration->get_scope() == NULL);
11479 if (scope != NULL)
11480 {
11481 definingClassDeclaration->set_scope(scope);
11482 ROSE_ASSERT(definingClassDeclaration->get_scope() != NULL);
11483 ROSE_ASSERT(nondefiningClassDeclaration->get_scope() != NULL);
11484 }
11485
11486 ROSE_ASSERT(definingClassDeclaration->get_definition()->get_parent() != NULL);
11487
11488 // DQ (10/30/2010): There should be a properly defined type at this point!
11489 ROSE_ASSERT(definingClassDeclaration->get_type() != NULL);
11490
11491 return definingClassDeclaration;
11492 }
11493
11494// DQ (11/7/2009): Added more uniform support for building class declarations.
11497 {
11498 ROSE_ASSERT(scope != NULL);
11499 SgClassDeclaration* definingClassDeclaration = buildDefiningClassDeclaration(name,scope);
11500 ROSE_ASSERT(definingClassDeclaration != NULL);
11501
11502 return definingClassDeclaration;
11503 }
11504
11505
11506// 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).
11507// DQ (1/24/2009): Built this "nfi" version but factored the code.
11508// SgClassDeclaration* SageBuilder::buildClassDeclaration_nfi(const SgName& name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl , bool buildTemplateInstantiation )
11510SageBuilder::buildClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl , bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList )
11511 {
11512 // DQ (3/15/2012): Added function to build C++ class (builds both the non-defining and defining declarations; in that order).
11513 // The implementation of this function could be simplified to directly call both:
11514 // SgClassDeclaration* buildNondefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
11515 // and
11516 // SgClassDeclaration* buildDefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
11517 // This might refactor the implementation nicely.
11518
11519#define DEBUG_CLASS_DECLARATION 0
11520
11521 // Note that the nonDefiningDecl pointer does not appear to be used.
11522#if 0
11523 printf ("WARNING: In SageBuilder::buildClassDeclaration_nfi(): the nonDefiningDecl pointer = %p (input parameter) does not appear to be used. \n",nonDefiningDecl);
11524#endif
11525
11526#if 0
11527 // DQ (3/4/2018): Adding testing.
11528 // ROSE_ASSERT(nonDefiningDecl != NULL);
11529 if (nonDefiningDecl != NULL)
11530 {
11531 ROSE_ASSERT(nonDefiningDecl->get_type() != NULL);
11532 ROSE_ASSERT(nonDefiningDecl->get_type()->get_declaration() != NULL);
11533 printf ("nonDefiningDecl->get_type() = %p = %s \n",nonDefiningDecl->get_type(),nonDefiningDecl->get_type()->class_name().c_str());
11534 printf ("nonDefiningDecl->get_type()->get_declaration() = %p = %s \n",nonDefiningDecl->get_type()->get_declaration(),nonDefiningDecl->get_type()->get_declaration()->class_name().c_str());
11535#if 0
11536 printf ("In buildClassDeclaration_nfi(): nonDefiningDecl: unparseNameToString() = %s \n",nonDefiningDecl->unparseNameToString().c_str());
11537#endif
11538
11539 }
11540#endif
11541
11542
11543 // DQ (10/10/2015): I think we can assert this! NO we can't (see test2015_87.C).
11544 // ROSE_ASSERT(nonDefiningDecl != NULL);
11545
11546 // DQ (10/10/2015): OK, now we have a valid use on the input non-defining declaration.
11547 bool buildTemplateDeclaration = (isSgTemplateClassDeclaration(nonDefiningDecl) != NULL);
11548
11549 // DQ (10/10/2015): If this is true, then we should have called a different function to build the associated SgTemplateClassDeclaration.
11550 if (buildTemplateDeclaration == true)
11551 {
11552 // Error checking.
11553 printf ("ERROR: If buildTemplateDeclaration == true, then we should have called a different function to build the associated SgTemplateClassDeclaration \n");
11554 }
11555 ROSE_ASSERT(buildTemplateDeclaration == false);
11556
11557#if 0
11558 printf ("In SageBuilder::buildClassDeclaration_nfi(): XXX_name = %s \n",XXX_name.str());
11559 printf ("In SageBuilder::buildClassDeclaration_nfi(): the nonDefiningDecl pointer = %p = %s \n",nonDefiningDecl,nonDefiningDecl != NULL ? nonDefiningDecl->class_name().c_str() : "null");
11560 printf ("In SageBuilder::buildClassDeclaration_nfi(): buildTemplateDeclaration = %s \n",buildTemplateDeclaration ? "true" : "false");
11561 printf (" --- templateArgumentsList = %p \n",templateArgumentsList);
11562 if (templateArgumentsList != NULL)
11563 {
11564 printf (" --- templateArgumentsList.size() = %zu \n",templateArgumentsList->size());
11565 for (size_t i = 0; i < templateArgumentsList->size(); i++)
11566 {
11567 printf (" --- --- argument pointer: templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
11568 }
11569 }
11570#endif
11571
11572 if (scope == NULL)
11573 {
11575#if 0
11576 printf ("In SageBuilder::buildClassDeclaration_nfi(): no scope was provided so using the SageBuilder::topScopeStack() = %p = %s \n",scope,scope->class_name().c_str());
11577#endif
11578 }
11579 else
11580 {
11581#if 0
11582 printf ("In SageBuilder::buildClassDeclaration_nfi(): scope was provided scope = %p = %s \n",scope,scope->class_name().c_str());
11583#endif
11584 }
11585
11586#if 0
11587 printf ("Building a SgClassDeclaration: buildClassDeclaration_nfi() XXX_name = %s buildTemplateInstantiation = %s \n",XXX_name.str(),buildTemplateInstantiation ? "true" : "false");
11588#endif
11589
11590 // Step 2 (now step 1). build the nondefining declaration,
11591 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
11592
11593 // Get the nondefining declaration from the symbol if it has been built (if this works,
11594 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
11595 SgClassDeclaration* nondefdecl = NULL;
11596
11597 SgName nameWithoutTemplateArguments = XXX_name;
11598 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
11599 if (buildTemplateInstantiation == true)
11600 {
11601 ROSE_ASSERT(templateArgumentsList != NULL);
11602 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
11603 }
11604
11605#if DEBUG_CLASS_DECLARATION
11606 printf ("In SageBuilder::buildClassDeclaration_nfi():\n");
11607 printf (" -- nameWithoutTemplateArguments = %s\n", nameWithoutTemplateArguments.str());
11608 printf (" -- nameWithTemplateArguments = %s\n", nameWithTemplateArguments.str());
11609#endif
11610
11611 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
11612 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
11613 // This fails for test2005_35.C
11614 // ROSE_ASSERT(SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == false);
11615
11616 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
11617 // ROSE_ASSERT(scope != NULL);
11618 SgClassSymbol* mysymbol = NULL;
11619 if (scope != NULL)
11620 {
11621#if DEBUG_CLASS_DECLARATION
11622 printf ("Looking up the SgClassSymbol in scope = %p = %s nameWithTemplateArguments = %s \n",scope,scope->class_name().c_str(),nameWithTemplateArguments.str());
11623#endif
11624
11625 // DQ (8/22/2012): We need to provide more information ofr the symbol table lookup to correctly resolve
11626 // (and disambiguate template instantations where the name qualification of the template arguments would
11627 // be significant).
11628 // mysymbol = scope->lookup_class_symbol(name);
11629 // mysymbol = scope->lookup_class_symbol(name);
11630 // mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments);
11631#if 0
11632 // DQ (7/25/2017): Since this is overwritten below, for both branches, we don't need to call this here.
11633 printf ("This was a redundant call to lookup_class_symbol \n");
11634 // mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList);
11635#endif
11636
11637 // DQ (10/10/2015): look up the correct type of symbol.
11638 if (buildTemplateDeclaration == true)
11639 {
11640#if DEBUG_CLASS_DECLARATION
11641 printf ("Note: In SageBuilder::buildClassDeclaration_nfi(): Need to look up a template symbol \n");
11642#endif
11643 ROSE_ASSERT(nonDefiningDecl != NULL);
11644
11645 SgTemplateParameterPtrList templateParameterList;
11646 SgTemplateArgumentPtrList templateSpecializationArgumentList;
11647
11648 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateArguments,&templateParameterList,&templateSpecializationArgumentList) != NULL);
11649
11650 mysymbol = scope->lookup_template_class_symbol(nameWithTemplateArguments,&templateParameterList,&templateSpecializationArgumentList);
11651
11652 ROSE_ASSERT(mysymbol != NULL);
11653#if 0
11654 printf ("ERROR: Need to look up a template symbol \n");
11655 ROSE_ABORT();
11656#endif
11657 }
11658 else
11659 {
11660#if DEBUG_CLASS_DECLARATION
11661 printf ("In SageBuilder::buildClassDeclaration_nfi(): calling lookup_class_symbol(nameWithTemplateArguments = %s,templateArgumentsList->size() = %zu \n",
11662 nameWithTemplateArguments.str(),(templateArgumentsList != NULL) ? templateArgumentsList->size() : 999);
11663 if (templateArgumentsList != NULL)
11664 {
11665 printf (" --- templateArgumentsList elements: \n");
11666 for (size_t i = 0; i < templateArgumentsList->size(); i++)
11667 {
11668 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
11669 printf (" --- --- templateArgumentsList->[%zu] = %s \n",i,templateArgumentsList->operator[](i)->class_name().c_str());
11670 templateArgumentsList->operator[](i)->display("In SageBuilder::buildClassDeclaration_nfi()");
11671 }
11672 }
11673#endif
11674 mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList);
11675#if DEBUG_CLASS_DECLARATION
11676 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
11677#endif
11678 // 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).
11679 if (mysymbol == NULL)
11680 {
11681#if DEBUG_CLASS_DECLARATION
11682 printf ("WARNING: scope->lookup_class_symbol(nameWithTemplateArguments = %s,templateArgumentsList->size() = %zu) == NULL \n",nameWithTemplateArguments.str(),templateArgumentsList->size());
11683#endif
11684 // ROSE_ASSERT(nonDefiningDecl != NULL);
11685
11686 // DQ (12/28/2018): Could it be that we wanted to use the name without template arguments.
11687#if DEBUG_CLASS_DECLARATION
11688 printf ("Checking lookup_class_symbol() using nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11689#endif
11690 ROSE_ASSERT(scope->lookup_class_symbol(nameWithoutTemplateArguments,templateArgumentsList) == NULL);
11691
11692#if DEBUG_CLASS_DECLARATION
11693 printf ("nonDefiningDecl = %p \n",nonDefiningDecl);
11694#endif
11695 if (nonDefiningDecl != NULL)
11696 {
11697#if DEBUG_CLASS_DECLARATION
11698 printf ("nonDefiningDecl = %p = %s \n",nonDefiningDecl,nonDefiningDecl->class_name().c_str());
11699#endif
11700 // DQ (3/4/2018): I think this is the correct API to use (internal use only).
11701 SgSymbol* temp_mysymbol = nonDefiningDecl->get_symbol_from_symbol_table();
11702 ROSE_ASSERT(temp_mysymbol != NULL);
11703
11704 mysymbol = isSgClassSymbol(temp_mysymbol);
11705 ROSE_ASSERT(mysymbol != NULL);
11706
11707 // DQ (3/4/2018): check that the scopes are the same.
11708 ROSE_ASSERT(scope == nonDefiningDecl->get_scope());
11709 }
11710 }
11711 }
11712
11713#if 0
11714 // DQ (11/21/2013): Added test based on debugging session with Philippe.
11715 // This test is not a test for a bug, since we require that symbols in base classes be aliased in the derived classes.
11716 if (mysymbol != NULL)
11717 {
11718 SgClassDeclaration* symbol_declaration = isSgClassDeclaration(mysymbol->get_declaration());
11719 ROSE_ASSERT(symbol_declaration != NULL);
11720 ROSE_ASSERT(symbol_declaration->get_scope() == scope);
11721
11722 printf ("In SageBuilder::buildClassDeclaration_nfi(): Testing scope->get_symbol_table()->exists(mysymbol) == true (expensive) \n");
11723
11724 ROSE_ASSERT(scope->get_symbol_table()->exists(mysymbol) == true);
11725 }
11726#endif
11727 }
11728 else
11729 {
11730 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknow.
11731 // DQ (1/26/2009): I think this should be an error, but that appears it would
11732 // break the existing interface. Need to discuss this with Liao.
11733 // printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): scope == NULL \n");
11734 }
11735
11736#if DEBUG_CLASS_DECLARATION
11737 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
11738#endif
11739
11740 if (mysymbol != NULL) // set links if nondefining declaration already exists.
11741 {
11742 nondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
11743
11744 ROSE_ASSERT(nondefdecl != NULL);
11745
11746#if DEBUG_CLASS_DECLARATION
11747 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol->get_declaration(): nondefdecl = %p = %s nondefdecl->get_definition() = %p = %s \n",
11748 nondefdecl,nondefdecl->class_name().c_str(),nondefdecl->get_definition(),
11749 nondefdecl->get_definition() != NULL ? nondefdecl->get_definition()->class_name().c_str() : "NULL");
11750#endif
11751 // DQ (6/8/2013): This should not be true (see test2013_198.C).
11752 // Fundamentally the symbol should always only have a pointer to a non-defining
11753 // declaration, where by definition (get_definition() == NULL).
11754 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
11755
11756 // DQ (9/16/2012): This should be true by definition (verify).
11757 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
11758
11759 // DQ (9/16/2012): The declaration was build previously, but test it to make sure the template arguments were setup properly.
11760 testTemplateArgumentParents(nondefdecl);
11761
11762#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11763 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11764 detectTransformations(nondefdecl);
11765#endif
11766
11767 // DQ (3/22/2012): I think we can assert this.
11768 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11769
11770 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11771 if (nondefdecl->get_parent() == NULL)
11772 {
11773#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11774 printf ("In SageBuilder::buildClassDeclaration_nfi(): Note that nondefdecl->get_parent() == NULL, this might be OK. \n");
11775#endif
11776 }
11777
11778#if 0
11779 // DQ (12/22/2019): This is the code that causes the class declarations between defining
11780 // class declarations across multiple translation units to be shared.
11781
11782 // DQ (9/7/2012): I think this might be the root of a problem in the haskell tests (ROSE compiling ROSE).
11783 if (nondefdecl->get_definingDeclaration() != NULL)
11784 {
11785#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11786 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",
11787 nondefdecl,nondefdecl->class_name().c_str(),nondefdecl->get_definingDeclaration(),nondefdecl->get_definingDeclaration()->class_name().c_str());
11788#endif
11789 SgClassDeclaration* nondefining_classDeclaration = isSgClassDeclaration(nondefdecl);
11790 ROSE_ASSERT(nondefining_classDeclaration != NULL);
11791 SgClassDeclaration* defining_classDeclaration = isSgClassDeclaration(nondefdecl->get_definingDeclaration());
11792 ROSE_ASSERT(defining_classDeclaration != NULL);
11793
11794#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11795 printf ("In SageBuilder::buildClassDeclaration_nfi(): nondefining_classDeclaration: scope = %p = %s name = %s \n",
11796 nondefining_classDeclaration->get_scope(),nondefining_classDeclaration->get_scope()->class_name().c_str(),nondefining_classDeclaration->get_name().str());
11797 printf ("In SageBuilder::buildClassDeclaration_nfi(): defining_classDeclaration: scope = %p = %s name = %s \n",
11798 defining_classDeclaration->get_scope(),defining_classDeclaration->get_scope()->class_name().c_str(),defining_classDeclaration->get_name().str());
11799 defining_classDeclaration->get_file_info()->display("already has a defining declaration");
11800#endif
11801#if 0
11802 printf ("Error: In SageBuilder::buildClassDeclaration_nfi(): exiting as part of test \n");
11803 ROSE_ABORT();
11804#endif
11805 // 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.
11806#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11807 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);
11808#endif
11809
11810#if 0
11811 // DQ (2/26/2019): Debugging support for multiple files on the command line.
11812 printf ("Exiting as a test! \n");
11813 ROSE_ABORT();
11814#endif
11815 return defining_classDeclaration;
11816 }
11817#endif
11818
11819#if 0
11820 nondefdecl->set_definingDeclaration(defdecl);
11821
11822 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
11823 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
11824#endif
11825 }
11826 else // build a nondefnining declaration if it does not exist
11827 {
11828#if DEBUG_CLASS_DECLARATION
11829 printf ("In SageBuilder::buildClassDeclaration_nfi(): building a nondefining declaration since it does not exist \n");
11830#endif
11831 // DQ (10/10/2015): This should be true.
11832 ROSE_ASSERT(nondefdecl == NULL);
11833
11834 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
11835 // DQ (1/1/2012): Fixed to force matching types or IR nodes for defining and non-defining declarations.
11836 if (buildTemplateInstantiation == true)
11837 {
11838 // This adds: SgTemplateDeclaration *templateDeclaration and SgTemplateArgumentPtrList templateArguments
11839#if DEBUG_CLASS_DECLARATION
11840 printf ("************************************************************************* \n");
11841 printf ("Building SgTemplateInstantiationDecl with empty SgTemplateArgumentPtrList \n");
11842 printf (" --- using nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
11843 printf ("************************************************************************* \n");
11844#endif
11845 SgTemplateArgumentPtrList emptyList;
11846 // nondefdecl = new SgTemplateInstantiationDecl (name,kind,NULL,NULL,NULL,emptyList);
11847 nondefdecl = new SgTemplateInstantiationDecl (nameWithTemplateArguments,kind,NULL,NULL,NULL,emptyList);
11848 ROSE_ASSERT(nondefdecl != NULL);
11849#if DEBUG_CLASS_DECLARATION
11850 printf ("In SageBuilder::buildClassDeclaration_nfi(): Build SgTemplateInstantiationDecl: nondefdecl = %p \n",nondefdecl);
11851#endif
11852 // DQ (2/27/2018): Added assertion now that we have implemented more consistant semantics
11853 // for template instantiations (types are not generated in the constructor calls).
11854 ROSE_ASSERT(nondefdecl->get_type() == NULL);
11855 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl) != NULL);
11856#if 0
11857 printf ("In buildClassDeclaration_nfi(): nondefdecl->get_name() = %s nondefdecl->get_templateName() = %s \n",nondefdecl->get_name().str(),isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().str());
11858#endif
11859#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11860 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11861 // detectTransformations(nondefdecl);
11862#endif
11863 // DQ (6/6/2012): Set the first non-defining declaration to be itself.
11864 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11865
11866 // DQ (1/1/2012): Added support for setting the template name (I think this should be fixed in the constructor).
11867 // It can't be fixed in the constructor since it has to be set after construction (or passed in explicitly).
11868 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == true);
11869
11870 // DQ (6/6/2012): Added support for template arguments so that types would be computed with the template arguments.
11871 ROSE_ASSERT(templateArgumentsList != NULL);
11872
11873#if 0
11874 // DQ (5/30/2014): Removing output spew.
11875 // DQ (5/17/2014): This must be allowed for some template instantiations (see test2014_77.C).
11876 // This occurs now under some revised rules for when to interpret a class or struct as a template
11877 // declaration or template instantiation declaration. This revisions is required for test2014_56.C
11878 // but has had a small cascading effect on other parts of ROSE (all fixed on 5/17/2014, if I can
11879 // finish this work today).
11880 // ROSE_ASSERT(templateArgumentsList->size() > 0);
11881 if (templateArgumentsList->size() == 0)
11882 {
11883 printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): templateArgumentsList->size() == 0 \n");
11884 }
11885#endif
11886 // DQ (9/16/2012): Set the firstNondefiningDeclaration so that we can set the template parameters.
11887 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11888#if 1
11889 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
11890 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
11891#else
11892 isSgTemplateInstantiationDecl(nondefdecl)->get_templateArguments() = *templateArgumentsList;
11893
11894#error "DEAD CODE!"
11895
11896 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
11897 // printf ("Calling setTemplateArgumentParents(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11898 setTemplateArgumentParents(nondefdecl);
11899 // printf ("DONE: Calling setTemplateArgumentParents(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11900
11901 testTemplateArgumentParents(nondefdecl);
11902#endif
11903 // DQ (6/6/2012): Generate the name without the template arguments.
11904#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11905 printf ("Warning: In buildClassDeclaration_nfi(): calling set_templateName(nameWithTemplateArguments = %s) for nondefining declaration \n",nameWithTemplateArguments.str());
11906#endif
11907 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(name);
11908 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName("SETME_NONDEFINING_DECL<>");
11909 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(name);
11910 isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(nameWithoutTemplateArguments);
11911
11912 // DQ (6/6/2012): I don't think we want this test any more (should apply only to the result of get_templateName()).
11913 // DQ (5/31/2012): Find locations where this is set and include template syntax.
11914 // ROSE_ASSERT(name.getString().find('<') == string::npos);
11915 // printf ("Commented out test for: name.getString().find('<') == string::npos (should apply only to the result of get_templateName() \n");
11916
11917 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == false);
11918
11919 // DQ (3/25/2017): Fixed Clang warning: warning: if statement has empty body [-Wempty-body]
11920 // DQ (3/22/2012): Make sure there is template syntax present.
11921 // if (isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().getString().find('>') == string::npos)
11922 // if (hasTemplateSyntax(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName()) == false);
11923 if (hasTemplateSyntax(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName()) == false)
11924 {
11925#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11926 printf ("WARNING: No template syntax present in name of template class instantiation (nondefdecl) \n");
11927#endif
11928 }
11929 // ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().getString().find('>') != string::npos);
11930
11931#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11932 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11933 // detectTransformations(nondefdecl);
11934#endif
11935 // 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.
11936 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
11937 }
11938 else
11939 {
11940 // We know that the name without template arguments should be used here (but they are the same).
11941#if DEBUG_CLASS_DECLARATION
11942 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);
11943 printf (" --- nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11944#endif
11945 // nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
11946 nondefdecl = new SgClassDeclaration(nameWithoutTemplateArguments,kind,NULL,NULL);
11947
11948 ROSE_ASSERT(nondefdecl != NULL);
11949#if DEBUG_CLASS_DECLARATION
11950 printf ("In buildClassDeclaration_nfi(): (no file info set): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11951#endif
11952 // DQ (10/9/2015): Added assertion. We can't assert this yet (see test2015_87.C).
11953 // ROSE_ASSERT(nondefdecl->get_type() != NULL);
11954
11955 ROSE_ASSERT(nameWithoutTemplateArguments == nameWithTemplateArguments);
11956
11957#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11958 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11959 // detectTransformations(nondefdecl);
11960#endif
11961 // DQ (9/16/2012): Set the firstNondefiningDeclaration because this is the one branch left were it
11962 // was not set (required in the true branch so that we could set the template parameters).
11963 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11964
11965 testTemplateArgumentParents(nondefdecl);
11966
11967 // 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.
11968 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
11969 }
11970
11971 ROSE_ASSERT(nondefdecl != NULL);
11972
11973 // DQ (6/6/2012): This has to be set before we generate the type.
11974 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11975 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
11976
11977 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
11978 // setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
11979
11980 // DQ (3/14/2012): For C++ we need the scope set so that types will have proper locations to revolve them
11981 // from being ambiguous or not properly defined. Basically, we need a handle from which to generate something
11982 // that amounts to a kind of name qualification internally (maybe even exactly name qualification, but I would
11983 // have to think about that a bit more).
11984 ROSE_ASSERT(scope != NULL);
11985
11986#if DEBUG_CLASS_DECLARATION
11987 printf ("In SageBuilder::buildClassDeclaration_nfi(): Set the scope of the new non-defining declaration to %p = %s \n",scope,scope->class_name().c_str());
11988#endif
11989 nondefdecl->set_scope(scope);
11990 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
11991
11992 // DQ (8/2/2019): The was required becuase the parent pointers were not being set when reading a file from the SageBuilder::buildFil() API.
11993 // However the bug was that the astPostprocessing's call to resetParentPointersInMemoryPool() was not properly working to find the global
11994 // scope in anyother case but when it was called usign a SgProject node. This is not fixed to permit caloling using a SgSourceFile node
11995 // and it is now an error to call it using any other kind of IR node.
11996 // DQ (8/1/2019): Set the parent for the non defining declaration to be the same as the scope by default.
11997 // nondefdecl->set_parent(scope);
11998#if 0
11999 printf ("In buildClassDeclaration_nfi(): setting the parent of the non defining declaration to be the scope by default) \n");
12000#endif
12001 // DQ (7/31/2019): Check that the parent is set if this was used a the declaration referenced by a symbol.
12002 // ROSE_ASSERT (nondefdecl->get_parent() != NULL);
12003
12004 // DQ (3/22/2012): I think we can assert this.
12005 // ROSE_ASSERT(nondefdecl->get_type() != NULL);
12006 ROSE_ASSERT(nondefdecl->get_type() == NULL);
12007
12008 if (nondefdecl->get_type() == NULL)
12009 {
12010#if DEBUG_CLASS_DECLARATION
12011 // DQ (12/27/2018): If we have already built a type, then why did we need to build a nondefining declaration?
12012 printf ("Calling scope->get_type_table()->lookup_type(): nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
12013
12014 printf ("WE NEED THE MANGLED NAME FOR THIS TO BE RELEVANT! \n");
12015
12016 // SgType* existingType = scope->get_type_table()->lookup_type(nameWithTemplateArguments);
12017 // ROSE_ASSERT(existingType == NULL);
12018#endif
12019
12020#if DEBUG_CLASS_DECLARATION
12021 printf ("In SageBuilder::buildClassDeclaration_nfi(): kind == SgClassDeclaration::e_java_parameter = %s \n",(kind == SgClassDeclaration::e_java_parameter) ? "true" : "false");
12022#endif
12025 : (SgClassType *) SgClassType::createType(nondefdecl));
12026#if DEBUG_CLASS_DECLARATION
12027 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());
12028#endif
12029 nondefdecl->set_type(class_type);
12030#if DEBUG_CLASS_DECLARATION
12031 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());
12032#endif
12033 SgClassDeclaration* tmp_classDeclarationFromType = isSgClassDeclaration(class_type->get_declaration());
12034 ROSE_ASSERT(tmp_classDeclarationFromType != NULL);
12035#if DEBUG_CLASS_DECLARATION
12036 SgScopeStatement* scope = tmp_classDeclarationFromType->get_scope();
12037 printf ("tmp_classDeclarationFromType: scope = %p = %s \n",scope,scope->class_name().c_str());
12038 printf ("tmp_classDeclarationFromType = %p = %s \n",tmp_classDeclarationFromType,tmp_classDeclarationFromType->class_name().c_str());
12039 printf ("tmp_classDeclarationFromType name = %s \n",tmp_classDeclarationFromType->get_name().str());
12040 if (tmp_classDeclarationFromType->get_file_info() != NULL)
12041 {
12042 tmp_classDeclarationFromType->get_file_info()->display("tmp_classDeclarationFromType: debug");
12043 }
12044#endif
12045 }
12046
12047 // DQ (3/22/2012): Added assertions.
12048 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12049 if (nondefdecl->get_type()->get_declaration() != nondefdecl)
12050 {
12051 printf ("ERROR: nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
12052 printf ("ERROR: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12053 printf ("ERROR: nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
12054
12055 SgClassDeclaration* classDeclarationFromType = isSgClassDeclaration(nondefdecl->get_type()->get_declaration());
12056 ROSE_ASSERT(classDeclarationFromType != NULL);
12057
12058 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
12059 printf ("nondefdecl->get_type()->get_name() = %s \n",nondefdecl->get_type()->get_name().str());
12060 printf ("nondefdecl->get_type()->get_declaration()->get_name() = %s \n",classDeclarationFromType->get_name().str());
12061
12062 printf ("nondefdecl->get_mangled_name() = %s \n",nondefdecl->get_mangled_name().getString().c_str());
12063 printf ("nondefdecl->get_type()->get_mangled() = %s \n",nondefdecl->get_type()->get_mangled().getString().c_str());
12064 printf ("nondefdecl->get_type()->get_declaration()->get_mangled_name() = %s \n",classDeclarationFromType->get_mangled_name().getString().c_str());
12065
12066 // DQ (12/27/2018): Added additional debugging support.
12067 printf ("nondefdecl->get_type()->get_declaration()->get_firstNondefiningDeclaration() = %s \n",classDeclarationFromType->get_firstNondefiningDeclaration() ? "true" : "false");
12068 printf ("nondefdecl->get_firstNondefiningDeclaration() = %s \n",nondefdecl->get_firstNondefiningDeclaration() ? "true" : "false");
12069
12070 // 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.
12071 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
12072 {
12073 SgNode* parent = nondefdecl->get_parent();
12074 if (parent != NULL)
12075 {
12076 printf ("nondefdecl->get_parent() = %p = %s \n",parent,parent->class_name().c_str());
12077 }
12078 }
12079
12080 // DQ (12/27/2018): Activate this debugging support.
12081#if DEBUG_CLASS_DECLARATION
12082 nondefdecl->get_type()->get_declaration()->get_file_info()->display("nondefdecl->get_type()->get_declaration()");
12083
12084 // DQ (7/24/2017): Added more debug information to support debugging test2014_187.C.
12085 // Note that this can be caught as an error if the class declaration was built in the code above when
12086 // the symbol was not found. But if the nondefdecl->get_type()->get_declaration() == nondefdecl,
12087 // then this branch will not be taken (which is simply debugging information to assert that
12088 // nondefdecl->get_type()->get_declaration() == nondefdecl is true (below).
12089 if (nondefdecl->get_file_info() == NULL)
12090 {
12091 printf ("ERROR: In SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p = %s does not have its source position information setup \n",nondefdecl,nondefdecl->class_name().c_str());
12092 printf (" --- nondefdecl = %s \n",nondefdecl->get_name().str());
12093 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p \n",nondefdecl->get_firstNondefiningDeclaration());
12094 printf (" --- nondefdecl->get_definingDeclaration() = %p \n",nondefdecl->get_definingDeclaration());
12095 printf (" --- nondefdecl->get_type() = %p \n",nondefdecl->get_type());
12096 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
12097 printf ("The real error is: (nondefdecl->get_type()->get_declaration() != nondefdecl) \n");
12098 }
12099 else
12100 {
12101 ROSE_ASSERT(nondefdecl->get_file_info() != NULL);
12102 nondefdecl->get_file_info()->display("nondefdecl");
12103 }
12104#endif
12105 }
12106 ROSE_ASSERT(nondefdecl->get_type()->get_declaration() == nondefdecl);
12107
12108#if 0
12109 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());
12110#endif
12111
12112 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
12113
12114 // The nondefining declaration will not appear in the source code, but is compiler
12115 // generated (so we have something about the class that we can reference; e.g in
12116 // types). At the moment we make it a transformation, there might be another kind
12117 // of source position that would be more precise. FIXME.
12118 // setOneSourcePositionNull(nondefdecl);
12120 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
12121
12122#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
12123 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
12125 {
12126 detectTransformations(nondefdecl);
12127 }
12128#endif
12129 // DQ (6/6/2012): This has to be set before we generate the type.
12130 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12131
12132 // DQ (3/15/2012): This is now set below.
12133 // nondefdecl->set_definingDeclaration(defdecl);
12134 nondefdecl->setForward();
12135
12136 // 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).
12137 // Liao, 9/2/2009. scope stack is optional, it can be empty
12138 // nondefdecl->set_parent(topScopeStack());
12139#if 0
12140 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");
12141#endif
12142 // nondefdecl->set_parent(scope);
12143 // defdecl->set_parent(scope);
12144
12145 if (scope != NULL)
12146 {
12147 mysymbol = new SgClassSymbol(nondefdecl);
12148#if 0
12149 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());
12150#endif
12151 // scope->insert_symbol(name, mysymbol);
12152 scope->insert_symbol(nameWithTemplateArguments, mysymbol);
12153
12154 // DQ (11/21/2013): Added test based on debugging session with Philippe.
12155 ROSE_ASSERT(nondefdecl->get_scope() == scope);
12156 }
12157 else
12158 {
12159 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unkown.
12160 // DQ (1/26/2009): I think this should be an error, but that appears it would
12161 // break the existing interface. Need to discuss this with Liao.
12162 printf ("Warning: no scope provided to support symbol table entry! \n");
12163 }
12164
12165 // DQ (7/31/2019): Check that the parent is set if this was used a the declaration referenced by a symbol.
12166 // ROSE_ASSERT (nondefdecl->get_parent() != NULL);
12167 }
12168
12169 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
12170
12171#if 1
12172 // Refactored this code.
12173 testTemplateArgumentParents(nondefdecl);
12174#else
12175 if (buildTemplateInstantiation == true)
12176 {
12177 // DQ (7/25/2012): Added this code here to reset the parents of the template arguments.
12178 for (size_t i = 0; i < templateArgumentsList->size(); i++)
12179 {
12180 // DQ (7/25/2012): This should be true because the template argument was set to the functions
12181 // scope so that the name with template arguments could be computed (with name qualification).
12182 ROSE_ASSERT((*templateArgumentsList)[i]->get_parent() != NULL);
12183
12184#error "DEAD CODE!"
12185
12186 // ROSE_ASSERT(isSgGlobal(templateArgumentsList[i]->get_parent()) == NULL);
12187 // ROSE_ASSERT(templateArgumentsList[i]->get_parent() == nondefining_templateInstantiation);
12188
12189 // Be we want to reset it to be the function (now that it is available, because this is more precise).
12190 // All qualified names should compute to the same qualified name (if not then it is a bug in the name
12191 // qualification mechanism).
12192 (*templateArgumentsList)[i]->set_parent(nondefdecl);
12193 }
12194 }
12195#endif
12196
12197 // DQ (3/15/2012): I hhava moved construction of defining declaration to be AFTER the nondefining declaration!
12198 // This is a better organization ans also should make sure that the declaration in the SgClassType will
12199 // properly reference the firstNondefiningDeclaration (instead of the defining declaration).
12200
12201 // step 1 (now step 2). Build defining declaration
12202 // SgClassDefinition* classDef = buildClassDefinition();
12203 SgClassDefinition* classDef = buildClassDefinition(NULL,buildTemplateInstantiation);
12204
12205 // DQ (11/26/2011): Debugging EDG 3.3 use of templateArguments.
12206#if 0
12207 printf ("Building a SgClassDeclaration: buildClassDeclaration_nfi() buildTemplateInstantiation = %s \n",buildTemplateInstantiation ? "true:" : "false");
12208#endif
12209
12210 // SgClassDeclaration* defdecl = new SgClassDeclaration (name,kind,NULL,classDef);
12211 SgClassDeclaration* defdecl = NULL;
12212 if (buildTemplateInstantiation == true)
12213 {
12214 // This adds: SgTemplateDeclaration *templateDeclaration and SgTemplateArgumentPtrList templateArguments
12215 SgTemplateArgumentPtrList emptyList;
12216 // defdecl = new SgTemplateInstantiationDecl (name,kind,NULL,classDef,NULL,emptyList);
12217 defdecl = new SgTemplateInstantiationDecl (nameWithTemplateArguments,kind,NULL,classDef,NULL,emptyList);
12218
12219 // DQ (2/27/2018): Added assertion now that we have implemented more consistant semantics
12220 // for template instantiations (types are not generated in the constructor calls).
12221 ROSE_ASSERT(defdecl->get_type() == NULL);
12222 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl) != NULL);
12223#if 0
12224 printf ("In buildClassDeclaration_nfi(): defdecl->get_name() = %s defdecl->get_templateName() = %s \n",defdecl->get_name().str(),isSgTemplateInstantiationDecl(defdecl)->get_templateName().str());
12225#endif
12226 // DQ (1/1/2012): Added support for setting the template name (I think this should be fixed in the constructor).
12227 // It can't be fixed in the constructor since it has to be set after construction (or passed in explicitly).
12228 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().is_null() == true);
12229
12230#if 0
12231 printf ("Warning: In buildClassDeclaration_nfi(): calling set_templateName(name = %s) for defining declaration \n",name.str());
12232#if 0
12233 // isSgTemplateInstantiationDecl(defdecl)->set_templateName(name);
12234 // isSgTemplateInstantiationDecl(defdecl)->set_templateName("SETME_DEFINING_DECL<>");
12235 isSgTemplateInstantiationDecl(defdecl)->set_templateName(name);
12236
12237#error "DEAD CODE!"
12238
12239 // DQ (5/31/2012): Find locations where this is set and include template syntax.
12240 ROSE_ASSERT(name.getString().find('<') == string::npos);
12241#else
12242 // DQ (6/1/2012): Make sure that the templateName is set and they it does not include the template syntax.
12243 SgName templateName = generateTemplateNameFromTemplateNameWithTemplateArguments(name);
12244 printf ("In buildClassDeclaration_nfi(): templateName = %s \n",templateName.str());
12245 isSgTemplateInstantiationDecl(defdecl)->set_templateName(templateName);
12246
12247#error "DEAD CODE!"
12248
12249 // DQ (5/31/2012): Find locations where this is set and include template syntax.
12250 // ROSE_ASSERT(templateName.getString().find('<') == string::npos);
12251 ROSE_ASSERT(hasTemplateSyntax(templateName) == false);
12252
12253 // DQ (6/1/2012): Not clear if this is always true (for all template instantations).
12254 // ROSE_ASSERT(name.getString().find('<') != string::npos);
12255 ROSE_ASSERT(hasTemplateSyntax(name) == true);
12256#endif
12257#else
12258#if 0
12259 printf ("In buildClassDeclaration_nfi(): nameWithoutTemplateArguments = %s nameWithTemplateArguments = %s \n",nameWithoutTemplateArguments.str(),nameWithTemplateArguments.str());
12260#endif
12261 isSgTemplateInstantiationDecl(defdecl)->set_templateName(nameWithoutTemplateArguments);
12262
12263#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12264 // DQ (5/8/2013): This fails for test2013_159.C, and it appears that we have been overly restrictive here.
12265 if (hasTemplateSyntax(nameWithTemplateArguments) == false)
12266 {
12267 printf ("WARNING: In buildClassDeclaration_nfi(): nameWithTemplateArguments = %s is not using template syntax \n",nameWithTemplateArguments.str());
12268 }
12269#endif
12270 // ROSE_ASSERT(hasTemplateSyntax(nameWithTemplateArguments) == true);
12271
12272 // DQ (7/27/2012): This fails for test2005_35.C where conversion operators are seen.
12273 // ROSE_ASSERT(hasTemplateSyntax(nameWithoutTemplateArguments) == false);
12274#endif
12275
12276 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().is_null() == false);
12277
12278 // DQ (3/22/2012): Make sure there is template syntax present.
12279 if (isSgTemplateInstantiationDecl(defdecl)->get_templateName().getString().find('>') == string::npos)
12280 {
12281#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12282 printf ("WARNING: No template syntax present in name of template class instantiation (defdecl) \n");
12283#endif
12284 }
12285 // ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().getString().find('>') != string::npos);
12286#if 0
12287 printf ("Should we have set the template instantiation name at this point? \n");
12288 ROSE_ABORT();
12289#endif
12290 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
12291 ROSE_ASSERT(defdecl->get_definition() != NULL);
12292 ROSE_ASSERT(isSgTemplateInstantiationDefn(defdecl->get_definition()) != NULL);
12293 }
12294 else
12295 {
12296#if 0
12297 printf ("Building a SgClassDeclaration, but we might require a SgTemplateClassDeclaration \n");
12298#endif
12299 // defdecl = new SgClassDeclaration (name,kind,NULL,classDef);
12300 // defdecl = new SgClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
12301
12302 // DQ (10/11/2015): Try to build a matching SgTemplateClassDeclaration. The problem with this fix is that
12303 // I would prefer that the other function be called instead. We might still want to implementat that instead.
12304 if (buildTemplateDeclaration == true)
12305 {
12306 printf ("In buildClassDeclaration_nfi(): I think we also want template specialization arguments to be more general: using nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
12307
12308 // = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,classType,(SgClassDefinition*)NULL);
12309 defdecl = new SgTemplateClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
12310
12311 // DQ (2/27/2018): We should be able to enforce this, it should have always been true.
12312 ROSE_ASSERT(defdecl->get_type() == NULL);
12313#if 0
12314 printf ("Exiting afte test! \n");
12315 ROSE_ABORT();
12316#endif
12317 }
12318 else
12319 {
12320 defdecl = new SgClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
12321
12322#if 0
12323 // DQ (12/22/2019): Debugging the case of shared class declarations between multiple files referencing the same defining declaration.
12324 printf ("In SageBuilder::buildClassDeclaration_nfi(): build a SgClassDeclaration: defdecl = %p \n",defdecl);
12325#endif
12326
12327 // DQ (2/27/2018): We should be able to enforce this, it should have always been true.
12328 ROSE_ASSERT(defdecl->get_type() == NULL);
12329 }
12330
12331 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
12332 ROSE_ASSERT(defdecl->get_definition() != NULL);
12333 ROSE_ASSERT(isSgTemplateInstantiationDefn(defdecl->get_definition()) == NULL);
12334 }
12335 ROSE_ASSERT(defdecl != NULL);
12336
12337#if 0
12338 printf ("In buildClassDeclaration_nfi(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
12339#endif
12340
12341 // DQ (3/15/2012): Moved from original location above...
12342 nondefdecl->set_definingDeclaration(defdecl);
12343
12344 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
12345 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
12346
12347 // printf ("SageBuilder::buildClassDeclaration_nfi(): defdecl = %p \n",defdecl);
12348
12350 // constructor is side-effect free
12351 classDef->set_declaration(defdecl);
12352 defdecl->set_definingDeclaration(defdecl);
12353
12354 testTemplateArgumentParents(nondefdecl);
12356
12357 // setOneSourcePositionForTransformation(nondefdecl);
12358 //
12359 // Liao 1/18/2011, I changed the semantics of setOneSourcePositionNull to set file_info to null regardless the existence of
12360 // file_info of the input node.
12361 // We do want to keep the file_info of nodefdecl if it is set already as compiler generated.
12362 // setOneSourcePositionNull(nondefdecl);
12363
12364 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12365 // nondefdecl->set_definingDeclaration(defdecl);
12366 defdecl->set_firstNondefiningDeclaration(nondefdecl);
12367
12368 if (buildTemplateInstantiation == true)
12369 {
12370 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
12371 setTemplateArgumentsInDeclaration(defdecl,templateArgumentsList);
12372 }
12373
12374 // DQ (3/22/2012): I think we can assert this.
12375 ROSE_ASSERT(defdecl->get_type() == NULL);
12376
12377 // Liao, 10/30/2009
12378 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
12379 // This is not desired when building a defining declaration and an inefficience in the constructor
12380 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
12381 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
12382 if (defdecl->get_type() != NULL)
12383 {
12384 // if a defining class declaration's type is associated with a defining class.
12385 // This is a wrong SgClassType and has to be reset
12386 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl))
12387 {
12388 // DQ (3/21/2012): Added this test.
12389 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12390
12391 // DQ (3/15/2012): Make this conditional upon the types not already being equal.
12392 if (nondefdecl->get_type() != defdecl->get_type())
12393 {
12394#if 0
12395 printf ("Deleting defdecl->get_type() = %p = %s (using type from nondefdecl = %p) \n",defdecl->get_type(),defdecl->get_type()->class_name().c_str(),nondefdecl);
12396 printf ("Skipping delete of %p to maintain unique type pointers \n",defdecl->get_type());
12397#else
12398 delete defdecl->get_type();
12399#endif
12400 // DQ (3/15/2012): This will be reset below.
12401 defdecl->set_type(NULL);
12402#if 0
12403 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());
12404#endif
12405#if 0
12406 // DQ (12/13/2011): Is this executed...
12407 printf ("Is this executed! \n");
12408 ROSE_ABORT();
12409#endif
12410 // DQ (3/21/2012): set the types to be the same type.
12411 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12412 defdecl->set_type(nondefdecl->get_type());
12413#if 0
12414 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());
12415#endif
12416 // DQ (3/21/2012): Added these checks...
12417 SgClassType* classType = nondefdecl->get_type();
12418 ROSE_ASSERT(classType != NULL);
12419 SgClassDeclaration* local_classDeclaration = isSgClassDeclaration(classType->get_declaration());
12420 ROSE_ASSERT (local_classDeclaration != NULL);
12421 printf ("In buildClassDeclaration_nfi(): classType = %p local_classDeclaration = %p \n",classType,local_classDeclaration);
12422 ROSE_ASSERT (local_classDeclaration->get_firstNondefiningDeclaration() != NULL);
12423 ROSE_ASSERT (local_classDeclaration->get_firstNondefiningDeclaration() == local_classDeclaration);
12424 }
12425 }
12426 }
12427 else
12428 {
12429 // DQ (3/15/2012): Make sure that both the defining and non-defining declarations use the same type.
12430 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12431 defdecl->set_type(nondefdecl->get_type());
12432#if 0
12433 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());
12434#endif
12435
12436 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
12437#if 0
12438 // DQ (11/20/2017): Commented out output spew.
12439 // DQ (2/28/2015): This test is failing in the new application support for templates within the testRoseHeaders_01.C.
12440 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()))
12441 {
12442 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");
12443 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12444 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
12445 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
12446 }
12447 // DQ (7/22/2017): Uncomment this test to better understand why this is a new issue (after two years).
12448 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
12449#endif
12450#if 0
12451 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
12452#endif
12453 }
12454
12455 // DQ (9/4/2012): Added assertion.
12456 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12457
12458 // patch up the SgClassType for the defining class declaration
12459 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12460 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
12461#if 0
12462 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl))
12463 {
12464 printf ("nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
12465 printf ("nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12466 printf ("nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
12467 printf ("nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
12468 }
12469#endif
12470 // ROSE_ASSERT (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl));
12471 ROSE_ASSERT (defdecl->get_type() != NULL);
12472 ROSE_ASSERT (defdecl->get_type()->get_declaration() != NULL);
12473 ROSE_ASSERT (defdecl->get_type()->get_declaration() != isSgDeclarationStatement(defdecl));
12474 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
12475 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
12476#if 0
12477 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
12478#else
12479
12480#if 0
12481 // DQ (11/20/2017): Commented out output spew.
12482 // DQ (2/28/2015): This test is failing in the new application support for templates within the testRoseHeaders_01.C.
12483 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()))
12484 {
12485 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");
12486 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12487 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
12488 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
12489 }
12490 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
12491 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl))
12492 {
12493 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");
12494 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12495 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
12496 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
12497 }
12498 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
12499#endif
12500
12501#endif
12502
12503 // DQ (9/4/2012): Added assertion.
12504 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12505
12506 // This appears to be redundant...is it?
12507 defdecl->set_type(nondefdecl->get_type());
12508
12509#if 0
12510 printf ("In buildClassDeclaration_nfi(): after calling set_type() again: defdecl = %p = %s defdecl->get_type() = %p = %s \n",
12511 defdecl,defdecl->class_name().c_str(),defdecl->get_type(),defdecl->get_type()->class_name().c_str());
12512#endif
12513
12514 // DQ (9/4/2012): Added assertion.
12515 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12516
12517 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
12518 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
12519 // used in a defining declaration).
12520 nondefdecl->setForward();
12521
12522 if (scope != NULL) // put into fixStructDeclaration() or alike later on
12523 {
12524 // DQ (9/4/2012): Added assertion.
12525 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12526
12527 // Note, this function sets the parent to be the scope if it is not already set.
12528 fixStructDeclaration(defdecl,scope);
12529
12530 // DQ (9/4/2012): Added assertion.
12531 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12532
12533 fixStructDeclaration(nondefdecl,scope);
12534
12535 // DQ (9/4/2012): Added assertion.
12536 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12537
12538#if 0
12539 SgClassSymbol* mysymbol = new SgClassSymbol(nondefdecl);
12540 ROSE_ASSERT(mysymbol);
12541 scope->insert_symbol(name, mysymbol);
12542 printf ("@@@@@@@@@@@@@@ In buildClassDeclaration_nfi(): setting scope of defining and non-defining declaration to scope = %s \n",scope->class_name().c_str());
12543 defdecl->set_scope(scope);
12544 nondefdecl->set_scope(scope);
12545
12546 // defdecl->set_parent(scope);
12547
12548 // Liao, 9/2/2009. merged into fixStructDeclaration
12549 // 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).
12550 nondefdecl->set_parent(scope);
12551 // nondefdecl->set_parent(topScopeStack());
12552 // Liao, 9/2/2009. scope stack is optional, it can be empty
12553 defdecl->set_parent(scope);
12554 // defdecl->set_parent(topScopeStack());
12555#endif
12556 }
12557
12558 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
12559 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
12560 // ROSE_ASSERT(defdecl->get_parent() != NULL);
12561
12562 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
12563
12564 // DQ (2/27/2012): Tracking down where parents are not set correctly (class declaration in typedef is incorrectly set to SgGlobal).
12565 ROSE_ASSERT(defdecl->get_parent() == NULL);
12566
12567 // DQ (2/29/2012): We can't assert this (fails for test2012_09.C).
12568 // ROSE_ASSERT(nondefdecl->get_parent() == NULL);
12569
12570 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
12571 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
12572
12573 testTemplateArgumentParents(nondefdecl);
12575
12576 // DQ (3/8/2018): Added for debugging.
12577 SgClassDeclaration* temp_firstNondefiningDeclaration = isSgClassDeclaration(defdecl->get_firstNondefiningDeclaration());
12578 SgClassDeclaration* temp_definingDeclaration = isSgClassDeclaration(defdecl->get_definingDeclaration());
12579 ROSE_ASSERT(temp_firstNondefiningDeclaration != NULL);
12580 ROSE_ASSERT(temp_definingDeclaration != NULL);
12581
12582#if 0
12583 printf ("Leaving buildClassDeclaration_nfi(): defdecl = %p = %s = %s \n",defdecl,defdecl->class_name().c_str(),defdecl->get_name().str());
12584 printf (" --- defdecl->get_firstNondefiningDeclaration() = %p \n",defdecl->get_firstNondefiningDeclaration());
12585 printf (" --- defdecl->get_definingDeclaration() = %p \n",defdecl->get_definingDeclaration());
12586
12587 printf (" --- defdecl->get_firstNondefiningDeclaration()->get_name() = %s \n",temp_firstNondefiningDeclaration->get_name().str());
12588 printf (" --- defdecl->get_definingDeclaration()->get_name() = %s \n",temp_definingDeclaration->get_name().str());
12589
12590 printf (" --- defdecl->get_firstNondefiningDeclaration()->get_type() = %p = %s \n",
12591 temp_firstNondefiningDeclaration->get_type(),temp_firstNondefiningDeclaration->get_type()->unparseToString().c_str());
12592 printf (" --- defdecl->get_definingDeclaration()->get_type() = %p = %s \n",
12593 temp_definingDeclaration->get_type(),temp_definingDeclaration->get_type()->unparseToString().c_str());
12594
12595 printf (" --- nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
12596 printf (" --- nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
12597
12598#if 0
12599 printf ("Leaving buildClassDeclaration_nfi(): defdecl: unparseNameToString() = %s \n",defdecl->unparseNameToString().c_str());
12600#endif
12601#endif
12602
12603 // DQ (3/8/2018): Added assertion.
12604 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_name() == temp_definingDeclaration->get_name());
12605 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_type() == temp_definingDeclaration->get_type());
12606
12607 // DQ (3/7/2015): Only in EDG 4.7 does the defining declaration not have a valid templateDeclaration pointer (sometimes).
12608 SgTemplateInstantiationDecl* nondefiningDeclaration = isSgTemplateInstantiationDecl(defdecl->get_firstNondefiningDeclaration());
12609 SgTemplateInstantiationDecl* definingDeclaration = isSgTemplateInstantiationDecl(defdecl->get_definingDeclaration());
12610 if (definingDeclaration != NULL && nondefiningDeclaration != NULL)
12611 {
12612 SgTemplateClassDeclaration* templateDeclaration = nondefiningDeclaration->get_templateDeclaration();
12613 if (templateDeclaration != NULL && definingDeclaration->get_templateDeclaration() == NULL)
12614 {
12615#if 0
12616 printf ("NOTE: buildClassDeclaration_nfi(): Setting the templateDeclaration for the defining declaration = %p using the value = %p from the nondefiningDeclaration = %p \n",
12617 definingDeclaration,templateDeclaration,nondefiningDeclaration);
12618#endif
12619 definingDeclaration->set_templateDeclaration(templateDeclaration);
12620
12621 ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
12622 }
12623 // ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
12624 }
12625
12626 // DQ (3/7/2015): Only in EDG 4.7 does the defining declaration not have a valid templateDeclaration pointer (sometimes).
12627 if (definingDeclaration != NULL)
12628 {
12629 if (definingDeclaration->get_templateDeclaration() == NULL)
12630 {
12631#if 0
12632 printf ("NOTE: buildClassDeclaration_nfi(): definingDeclaration->get_templateDeclaration() == NULL \n");
12633#endif
12634 }
12635 // ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
12636 }
12637
12638#if 0
12639 printf ("Leaving buildClassDeclaration_nfi(): defdecl = %p defdecl->unparseNameToString() = %s \n",defdecl,defdecl->unparseNameToString().c_str());
12640#endif
12641
12642#if 0
12643 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12644 printf ("Leaving buildClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
12645 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
12646
12647 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12648 printf ("Leaving buildClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
12649 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
12650#endif
12651
12652 return defdecl;
12653 }
12654
12655
12657 {
12658 SgName myname(name);
12659 return buildStructDeclaration(myname, scope);
12660 }
12661
12663 {
12664 SgName myname(name);
12665 return buildStructDeclaration(myname, scope);
12666 }
12667
12668
12669#if 0
12670// DQ (11/19/2011): Added more uniform support for building class declarations.
12673 {
12674 ROSE_ASSERT(scope != NULL);
12675 SgTemplateClassDeclaration* definingClassDeclaration = buildDefiningTemplateClassDeclaration(name,scope);
12676 ROSE_ASSERT(definingClassDeclaration != NULL);
12677
12678 return definingClassDeclaration;
12679 }
12680#endif
12681
12682
12685 {
12686 SgTemplateClassDefinition* result = NULL;
12687 if (d != NULL) // the constructor does not check for NULL d, causing segmentation fault
12688 {
12689 result = new SgTemplateClassDefinition(d);
12690 // result->set_parent(d); // set_declaration() == set_parent() in this case
12691 }
12692 else
12693 {
12694 result = new SgTemplateClassDefinition();
12695 }
12696
12697 ROSE_ASSERT(result);
12698
12699 // CR (3/22/2020): Fixed setting case insensitivity
12700 // if (symbol_table_case_insensitive_semantics == true)
12702 result->setCaseInsensitive(true);
12703
12705 return result;
12706 }
12707
12709SageBuilder::buildNondefiningTemplateClassDeclaration(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12710{
12711 SgTemplateClassDeclaration* res = buildNondefiningTemplateClassDeclaration_nfi (XXX_name, kind, scope, templateParameterList, templateSpecializationArgumentList);
12713 return res;
12714}
12715
12716// SgTemplateClassDeclaration * SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(const SgName& name, SgClassDeclaration::class_types kind, SgScopeStatement* scope )
12718SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12719 {
12720#if 0
12721 printf("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(XXX_name = %p):\n", XXX_name.str());
12722#endif
12723
12724 if (scope == NULL)
12726
12727 // DQ (11/20/2011): This is for initial debugging only.
12728 ROSE_ASSERT(scope != NULL);
12729
12730#if 0
12731 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): XXX_name = %s scope = %p = %s \n",XXX_name.str(),scope,scope->class_name().c_str());
12732#endif
12733
12734 // 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.
12735 SgName nameWithoutTemplateArguments = XXX_name;
12736 SgName nameWithTemplateSpecializationArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateSpecializationArgumentList);
12737
12738#if 0
12739 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
12740#endif
12741
12742 // SgTemplateClassDeclaration::class_types template_class_kind = SgTemplateClassDeclaration::e_class;
12743
12744 // Step 2. build the nondefining declaration,
12745 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
12746
12747 // Get the nondefining declaration from the symbol if it has been built (if this works,
12748 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
12749 SgTemplateClassDeclaration* nondefdecl = NULL;
12750
12751 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
12752 // ROSE_ASSERT(scope != NULL);
12753
12754 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12755 // SgTemplateSymbol* mysymbol = NULL;
12756 SgClassSymbol* mysymbol = NULL;
12757
12758 if (scope != NULL)
12759 {
12760 // DQ (9/12/2012): We want to include the template specialization into the name where it is required (this handling
12761 // is similar to normal template arguments for non-template declaration, but different than template parameters).
12762 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12763 // mysymbol = scope->lookup_template_symbol(name);
12764 // mysymbol = scope->lookup_class_symbol(name);
12765 // mysymbol = scope->lookup_template_class_symbol(name);
12766 // mysymbol = scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList);
12767 mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
12768 }
12769 else
12770 {
12771 // Liao 9/2/2009: This is not an error. We support bottom-up AST construction and scope can be unknown.
12772 // DQ (1/26/2009): I think this should be an error, but that appears it would
12773 // break the existing interface. Need to discuss this with Liao.
12774 printf ("Warning: In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): scope == NULL \n");
12775 }
12776#if 0
12777 printf ("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
12778#endif
12779
12780 if (mysymbol != NULL) // set links if nondefining declaration already exists.
12781 {
12782 // DQ (3/7/2012): Build a seperate non-defining declaration (reusing the existing one will cause the test for unique statements to fail).
12783 // 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");
12784 // nondefdecl = isSgTemplateClassDeclaration(mysymbol->get_declaration());
12785 SgClassType* classType = isSgClassType(mysymbol->get_type());
12786 ROSE_ASSERT(classType != NULL);
12787
12788 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12789 // nondefdecl = new SgTemplateClassDeclaration(name,kind,classType,(SgClassDefinition*)NULL);
12790 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,classType,(SgClassDefinition*)NULL);
12791
12792#if 0
12793 // DQ (3/4/2018): relax this requirement for SgTemplateInstantiationClassDeclaration.
12794 // DQ (2/27/2018): Enforce that this is not already set (should be set after the constructor to
12795 // simplify how derived classes (e.g. SgTemplateInstantiationClassDeclaration statements) work.
12796 if (nondefdecl->get_type() != NULL)
12797 {
12798 printf ("Note: SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): nondefdecl->get_type() != NULL: name = %s \n",nondefdecl->get_name().str());
12799 }
12800 // ROSE_ASSERT(nondefdecl->get_type() == NULL);
12801#endif
12802
12803 ROSE_ASSERT(nondefdecl != NULL);
12804
12805 // DQ (9/10/2012): Initialize the template parameter list.
12806 ROSE_ASSERT(templateParameterList != NULL);
12807 nondefdecl->get_templateParameters() = *templateParameterList;
12808
12809 // DQ (9/16/2012): Moved this initialization of firstNondefiningDeclaration from farther down in this branch (and added assertion).
12810 nondefdecl->set_firstNondefiningDeclaration(mysymbol->get_declaration());
12811 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
12812
12813 // TV (04/12/2018): Add a scope for nonreal classes (and their member) on the first non-defining declaration of template classes
12814 if (nondefdecl == nondefdecl->get_firstNondefiningDeclaration()) {
12815 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
12816
12817 nonreal_decl_scope->set_parent(nondefdecl);
12818 nondefdecl->set_nonreal_decl_scope(nonreal_decl_scope);
12819
12820 SageInterface::setSourcePosition(nonreal_decl_scope);
12821 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
12822 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
12823#if 0
12824 printf("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(XXX_name = %p): nrscope = %p (new)\n", XXX_name.str(), nonreal_decl_scope);
12825#endif
12826 }
12827
12828#if 1
12829 // DQ (9/16/2012): This newly refactored function can only be called after firstNondefiningDeclaration is set.
12830 // This also sets the template argument parents to the firstNondefiningDeclaration.
12831 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
12832#else
12833 // DQ (9/12/2012): Adding support for template specialization.
12834 ROSE_ASSERT(templateSpecializationArgumentList != NULL);
12835 nondefdecl->get_templateSpecializationArguments() = *templateSpecializationArgumentList;
12836#endif
12837 // DQ (9/10/2012): Test the just built template with its template parameters.
12838 if (nondefdecl->get_templateParameters().size() == 0)
12839 {
12840#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12841 printf ("WARNING: In buildNondefiningTemplateClassDeclaration_nfi(): (part 1) nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
12842#endif
12843 }
12844 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12845
12846 // DQ (3/7/2012): We want this to be set later, so we can't test it here.
12847 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
12848#if 0
12849 nondefdecl->set_definingDeclaration(defdecl);
12850
12851 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
12852 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
12853#endif
12854 // DQ (3/7/2012): But always refer to the first non-defining declaration so it will be unique (and set the scope).
12855 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
12856 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != nondefdecl);
12857 nondefdecl->set_scope(scope);
12858 nondefdecl->setForward();
12859
12860 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12861 nondefdecl->set_templateName(nameWithoutTemplateArguments);
12862
12863 testTemplateArgumentParents(nondefdecl);
12864 }
12865 else // build a nondefnining declaration if it does not exist
12866 {
12867 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,(SgClassType*)NULL,(SgClassDefinition*)NULL);
12868 ROSE_ASSERT(nondefdecl != NULL);
12869
12870 // DQ (9/10/2012): Initialize the template parameter list.
12871 ROSE_ASSERT(templateParameterList != NULL);
12872 nondefdecl->get_templateParameters() = *templateParameterList;
12873
12874 // DQ (9/16/2012): Moved this initialization of firstNondefiningDeclaration from farther down in this branch.
12875 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12876
12877 // DQ (9/16/2012): This newly refactored function can only be called after firstNondefiningDeclaration is set.
12878 // This also sets the template argument parents to the firstNondefiningDeclaration.
12879 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
12880
12881 // DQ (9/10/2012): Test the just built template with its template parameters.
12882 if (nondefdecl->get_templateParameters().size() == 0)
12883 {
12884#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12885 printf ("WARNING: In buildNondefiningTemplateClassDeclaration_nfi(): (part 2) nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
12886#endif
12887 }
12888 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12889
12890 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12891 nondefdecl->set_templateName(nameWithoutTemplateArguments);
12892
12893#if 0
12894 // DQ (12/4/2011): Now we want to enable this so that the SgClassType will be available from a SgTemplateClassDeclaration.
12895 if (nondefdecl->get_type() == NULL)
12896 {
12897 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
12898 // nondefdecl->set_type(NULL);
12899 // nondefdecl->set_type(SgTemplateType::createType(nondefdecl));
12900 // nondefdecl->set_type(SgTemplateType::createType());
12901 nondefdecl->set_type(SgClassType::createType(nondefdecl));
12902 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12903 }
12904#endif
12905 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
12906
12907 // The nondefining declaration will not appear in the source code, but is compiler
12908 // generated (so we have something about the class that we can reference; e.g in
12909 // types). At the moment we make it a transformation, there might be another kind
12910 // of source position that would be more precise. FIXME.
12911 // setOneSourcePositionNull(nondefdecl);
12913 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
12914
12915 // nondefdecl->set_definingDeclaration(defdecl);
12916 nondefdecl->setForward();
12917
12918 // Liao, 9/2/2009. scope stack is optional, it can be empty
12919 // nondefdecl->set_parent(topScopeStack());
12920#if 0
12921 printf ("In buildNondefiningTemplateClassDeclaration_nfi(): Commented out setting the parent to the scope. \n");
12922#endif
12923 // printf ("Note that for C++, the parent may not be the same as the scope (dangerous code). \n");
12924 // nondefdecl->set_parent(scope);
12925
12926 nondefdecl->set_scope(scope);
12927
12928#if 1
12929 // DQ (12/4/2011): Set the scope first and then set the type (scope is required to compute the type (name mangling)).
12930 // DQ (12/4/2011): Now we want to enable this so that the SgClassType will be available from a SgTemplateClassDeclaration.
12931 if (nondefdecl->get_type() == NULL)
12932 {
12933 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
12934 // nondefdecl->set_type(NULL);
12935 // nondefdecl->set_type(SgTemplateType::createType(nondefdecl));
12936 // nondefdecl->set_type(SgTemplateType::createType());
12937 nondefdecl->set_type(SgClassType::createType(nondefdecl));
12938 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12939#if 0
12940 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());
12941#endif
12942 }
12943#endif
12944
12945 // Build a SgTemplateClassSymbol and put it into the specified scope.
12946 if (scope != NULL)
12947 {
12948#if 0
12949 printf ("Building a SgTemplateSymbol using nameWithTemplateSpecializationArguments = %s and nondefdecl = %p = %s \n",nameWithTemplateSpecializationArguments.str(),nondefdecl,nondefdecl->class_name().c_str());
12950#endif
12951 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12952 // mysymbol = new SgTemplateSymbol(nondefdecl);
12953 // mysymbol = new SgClassSymbol(nondefdecl);
12954 mysymbol = new SgTemplateClassSymbol(nondefdecl);
12955 ROSE_ASSERT(mysymbol != NULL);
12956
12957 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12958 // DQ (3/6/2012): Added test for existing symbol (see test2012_18.C).
12959 // ROSE_ASSERT(scope->lookup_template_class_symbol(name) == NULL);
12960 // ROSE_ASSERT(scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList) == NULL);
12961 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList) == NULL);
12962
12963 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12964 // scope->insert_symbol(name, mysymbol);
12965 scope->insert_symbol(nameWithTemplateSpecializationArguments, mysymbol);
12966#if 0
12967 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi() (after building symbol): scope = %p = %s \n",scope,scope->class_name().c_str());
12968#endif
12969 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
12970
12971 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
12972
12973 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12974 // ROSE_ASSERT(scope->lookup_template_class_symbol(name) != NULL);
12975 // ROSE_ASSERT(scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList) != NULL);
12976 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList) != NULL);
12977 }
12978 else
12979 {
12980 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknown.
12981 }
12982
12983 testTemplateArgumentParents(nondefdecl);
12984
12985#if 1
12986 // DQ (7/16/2017): Added code to set the template parameters in the just build declaration (if it is a template declaration).
12987 // We want to set the parents of the template paremters to the frst nondefining template class declaration, and we want to reset
12988 // the scope of the declarations associated with any previously marked SgClassType objects associated with any template parameters.
12989 // printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): Calling setTemplateParametersInDeclaration(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
12990
12991 setTemplateParametersInDeclaration(nondefdecl,templateParameterList);
12992
12993 // DQ (8/13/2013): Adding test of template parameter lists.
12994 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(nondefdecl);
12995 ROSE_ASSERT(templateClassDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateClassDeclaration->get_templateParameters().size()));
12996#endif
12997 }
12998
12999 // defdecl->set_firstNondefiningDeclaration(nondefdecl);
13000
13001 // DQ (11/3/2012): Setup the default source position information.
13002 setSourcePosition(nondefdecl);
13003
13004#if 0
13005 // 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).
13006
13007 // Liao, 10/30/2009
13008 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
13009 // This is not desired when building a defining declaration and an inefficience in the constructor
13010 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
13011 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
13012 if (defdecl->get_type() != NULL)
13013 {
13014 // if a defining class declaration's type is associated with a defining class.
13015 // This is a wrong SgClassType and has to be reset
13016 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
13017 {
13018 delete defdecl->get_type();
13019 }
13020 }
13021
13022 // patch up the SgClassType for the defining class declaration
13023 ROSE_ASSERT (nondefdecl->get_type() != NULL);
13024 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
13025 defdecl->set_type(nondefdecl->get_type());
13026#else
13027 // printf ("We might need to force the types used for defining and non-defining SgTemplateClassDeclaration to be the same! \n");
13028 ROSE_ASSERT(nondefdecl->get_type() != NULL);
13029#endif
13030
13031 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
13032 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
13033 // used in a defining declaration).
13034 nondefdecl->setForward();
13035
13036 if (scope != NULL) // put into fixStructDeclaration() or alike later on
13037 {
13038 // fixStructDeclaration(defdecl,scope);
13039 // fixStructDeclaration(nondefdecl,scope);
13040
13041 // printf ("***** WARNING *****: Commented out call to fixStructDeclaration() \n");
13042 // ROSE_ASSERT(false);
13043 }
13044
13045#if 0
13046 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
13047 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
13048
13049 ROSE_ASSERT(defdecl->get_scope() != NULL);
13050#endif
13051
13052 // 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).
13053 ROSE_ASSERT(nondefdecl->get_parent() == NULL);
13054
13055 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13056 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
13057
13058 testTemplateArgumentParents(nondefdecl);
13059
13060#if 0
13061 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
13062 printf ("Leaving buildNondefiningTemplateClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
13063 SgClassDeclaration* tmp_classDeclaration = nondefdecl;
13064 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(tmp_classDeclaration);
13065
13066 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
13067 printf ("Leaving buildNondefiningTemplateClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
13068 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
13069#endif
13070
13071 return nondefdecl;
13072 }
13073
13076 SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
13077{
13078 SgTemplateClassDeclaration * res = buildTemplateClassDeclaration_nfi (XXX_name, kind, scope, nonDefiningDecl, templateParameterList, templateSpecializationArgumentList);
13080 return res;
13081}
13082
13085 SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
13086 {
13087 // DQ (12/26/2011): Notes that the input nonDefiningDecl is not used...this is a confusing point.
13088 // The specification of the scope appears to be enough.
13089
13090 if (scope == NULL)
13092
13093#if 0
13094 printf ("In buildTemplateClassDeclaration_nfi(): nonDefiningDecl = %p \n",nonDefiningDecl);
13095 if (nonDefiningDecl != NULL)
13096 {
13097 printf ("--- nonDefiningDecl->get_firstNondefiningDeclaration() = %p \n",nonDefiningDecl->get_firstNondefiningDeclaration());
13098 printf ("--- nonDefiningDecl->get_definingDeclaration() = %p \n",nonDefiningDecl->get_definingDeclaration());
13099 }
13100#endif
13101
13102 // DQ (11/20/2011): This is for initial debugging only.
13103 ROSE_ASSERT(scope != NULL);
13104
13105 // 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.
13106 SgName nameWithoutTemplateArguments = XXX_name;
13107 SgName nameWithTemplateSpecializationArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateSpecializationArgumentList);
13108
13109 // step 1. Build defining declaration
13110 // Note that even the SgTemplateClassDeclaration uses a regular SgClassDefinition instead of the currently unused SgTemplateClassDefinition.
13111 // SgClassDefinition* classDef = buildClassDefinition();
13112 // SgTemplateClassDefinition* classDef = buildTemplateClassDefinition(name,);
13113
13114 // DQ (11/29/2011): Added checks...
13115 if (nonDefiningDecl != NULL)
13116 {
13117 ROSE_ASSERT(nonDefiningDecl->get_firstNondefiningDeclaration() == nonDefiningDecl);
13118 }
13119
13120 SgName templateString = "template string";
13121 // SgTemplateDeclaration::template_type_enum template_kind = SgTemplateDeclaration::e_template_class;
13122 SgTemplateParameterPtrList templateParameters;
13123
13124 // SgTemplateDeclaration (SgName name, SgName string, SgTemplateDeclaration::template_type_enum template_kind, SgTemplateParameterPtrList templateParameters)
13125 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,kind,NULL,classDef);
13126 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters);
13127
13128 // SgTemplateClassDeclaration::class_types template_class_kind = SgTemplateClassDeclaration::e_class;
13129 // SgTemplateType* classType = NULL;
13130 // SgTemplateClassDefinition* classDef = NULL;
13132
13133 // Constructure arguments: SgName, SgName, SgTemplateDeclaration::template_type_enum, SgTemplateParameterPtrList, SgTemplateClassDeclaration::class_types, SgClassType*, SgTemplateClassDefinition*
13134 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters);
13135 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,template_class_kind,classType,classDef);
13136 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,template_class_kind,classDef);
13137
13138#if 0
13139 printf ("In buildTemplateClassDeclaration_nfi(): calling new SgTemplateClassDeclaration() name = %s \n",nameWithTemplateSpecializationArguments.str());
13140#endif
13141
13142 // DQ (9/12/2012): We want to include the template specialization into the name where it is required (this handling
13143 // is similar to normal template arguments for non-template declaration, but different than template parameters).
13144 // This copy of SgName is required to support passing it to the SgTemplateClassDeclaration constructor.
13145 // SgName localName = name;
13146 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,template_class_kind,classDef);
13147 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,kind,NULL,classDef);
13148
13149 // DQ (1/13/2013): This is causing two defining declarations to be built for test2012_278.C (and the parent for the second defining
13150 // declaration is not being set, though the larger issue is that we have two defining declarations, however this might be acceptable
13151 // if this is a specialization).
13152 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (nameWithTemplateSpecializationArguments,kind,NULL,classDef);
13153 SgTemplateClassDeclaration* defdecl = NULL;
13154 if (nonDefiningDecl != NULL)
13155 {
13156 // If we have a non-defining declaration specified, try to use any existing defining declaration withouth building a 2nd one
13157 // (which would be an error, unless maybe if this is a specialization).
13158 if (nonDefiningDecl->get_definingDeclaration() != NULL)
13159 {
13160 // This must be a valid SgTemplateClassDefinition.
13161 defdecl = isSgTemplateClassDeclaration(nonDefiningDecl->get_definingDeclaration());
13162 ROSE_ASSERT(defdecl != NULL);
13163#if 0
13164 printf ("In buildTemplateClassDeclaration_nfi(): Reusing the defining declaration previously build: defdecl = %p = %s \n",defdecl,defdecl->get_name().str());
13165#endif
13166 }
13167 else
13168 {
13169#if 0
13170 printf ("In buildTemplateClassDeclaration_nfi(): No defining declaration found, so we have to build one. \n");
13171#endif
13172 }
13173 }
13174
13175 if (defdecl == NULL)
13176 {
13177#if 0
13178 printf ("Building a defining declaration \n");
13179#endif
13180 defdecl = new SgTemplateClassDeclaration (nameWithTemplateSpecializationArguments,kind,NULL,classDef);
13181 }
13182
13183 ROSE_ASSERT(defdecl != NULL);
13184
13185#if 0
13186 printf ("In buildTemplateClassDeclaration_nfi(): defdecl = %p = %s \n",defdecl,defdecl->class_name().c_str());
13187#endif
13188
13189 // DQ (9/10/2012): Initialize the template parameter list.
13190 ROSE_ASSERT(templateParameterList != NULL);
13191 defdecl->get_templateParameters() = *templateParameterList;
13192
13193 // DQ (9/12/2012): Adding support for template specialization.
13194 ROSE_ASSERT(templateSpecializationArgumentList != NULL);
13195 defdecl->get_templateSpecializationArguments() = *templateSpecializationArgumentList;
13196
13197 // DQ (9/16/2012): We can't test this yet, since the firstNondefiningDeclaration has not be set.
13198 // testTemplateArgumentParents(defdecl);
13199
13200 // DQ (9/10/2012): Test the just built template with its template parameters.
13201 if (defdecl->get_templateParameters().size() == 0)
13202 {
13203#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
13204 printf ("WARNING: In buildTemplateClassDeclaration_nfi(): defdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations defdecl = %p \n",defdecl);
13205#endif
13206 }
13207 // ROSE_ASSERT(defdecl->get_templateParameters().size() > 0);
13208
13209 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
13210 defdecl->set_templateName(nameWithoutTemplateArguments);
13211
13212#if 0
13213 printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): scope = %p = %s \n",scope,scope->class_name().c_str());
13214#endif
13215
13216 defdecl->set_scope(scope);
13217
13218 // 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.
13219 // DQ (11/20/2011): Can name qualification make this incorrect?
13220 // defdecl->set_parent(scope);
13221
13222 ROSE_ASSERT(classDef != NULL);
13223
13224 // printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): defdecl = %p \n",defdecl);
13225
13227
13228 // constructor is side-effect free
13229 classDef->set_declaration(defdecl);
13230 defdecl->set_definingDeclaration(defdecl);
13231
13232 // Step 2. build the nondefining declaration,
13233 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
13234
13235 // Get the nondefining declaration from the symbol if it has been built (if this works,
13236 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
13237 SgTemplateClassDeclaration* nondefdecl = nonDefiningDecl;
13238 if (nondefdecl == NULL) {
13239 ROSE_ASSERT(scope != NULL);
13240
13241 SgClassSymbol* mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
13242#if 0
13243 printf ("In buildTemplateClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
13244#endif
13245
13246 if (mysymbol != NULL) {
13247 nondefdecl = isSgTemplateClassDeclaration(mysymbol->get_declaration());
13248 ROSE_ASSERT(nondefdecl != NULL);
13249
13250 nondefdecl->set_definingDeclaration(defdecl);
13251 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
13252 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
13253
13254 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13255 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
13256
13257 // DQ (9/16/2012): Test this previously setup firstNondefiningDeclaration.
13258 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
13259 testTemplateArgumentParents(nondefdecl);
13260 } else {
13261#if 0
13262 printf(" start build non-defn decl for %p\n",defdecl);
13263#endif
13264 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
13265 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,NULL,NULL);
13266 ROSE_ASSERT(nondefdecl != NULL);
13267
13268 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
13269 nondefdecl->set_definingDeclaration(defdecl);
13270#if 0
13271 printf(" nondefdecl = %p\n",nondefdecl);
13272#endif
13273#if 0
13274 // TV (04/12/2018): Add a scope for nonreal classes (and their member) on the first non-defining declaration of template classes
13275 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
13276
13277 nonreal_decl_scope->set_parent(nondefdecl);
13278 nondefdecl->set_nonreal_decl_scope(nonreal_decl_scope);
13279
13280 SageInterface::setSourcePosition(nonreal_decl_scope);
13281 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
13282 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
13283#if 1
13284 printf("In buildTemplateClassDeclaration_nfi(): nrscope = %p\n", nonreal_decl_scope);
13285#endif
13286#endif
13287 // DQ (9/10/2012): Initialize the template parameter list.
13288 ROSE_ASSERT(templateParameterList != NULL);
13289 nondefdecl->get_templateParameters() = *templateParameterList;
13290
13291 // DQ (9/16/2012): Newly refactored code.
13292 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
13293 testTemplateArgumentParents(nondefdecl);
13294
13295 // DQ (9/10/2012): Test the just built template with its template parameters.
13296 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
13297 if (nondefdecl->get_templateParameters().size() == 0)
13298 {
13299#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
13300 printf ("WARNING: In buildTemplateClassDeclaration_nfi(): nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
13301#endif
13302 }
13303 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
13304#if 0
13305 printf(" next 1\n");
13306#endif
13307
13308 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
13309 nondefdecl->set_templateName(nameWithoutTemplateArguments);
13310
13311 // DQ (12/26/2011): The non defining declaration should not have a valid pointer to the class definition.
13312 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
13313
13314 // The nondefining declaration will not appear in the source code, but is compiler
13315 // generated (so we have something about the class that we can reference; e.g in
13316 // types). At the moment we make it a transformation, there might be another kind
13317 // of source position that would be more precise. FIXME.
13319 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
13320
13321 nondefdecl->setForward();
13322
13323 // Liao, 9/2/2009. scope stack is optional, it can be empty
13324 nondefdecl->set_parent(scope);
13325 nondefdecl->set_scope(scope);
13326#if 0
13327 printf(" next 2\n");
13328#endif
13329
13330 if (nondefdecl->get_type() == NULL)
13331 {
13332 nondefdecl->set_type(SgClassType::createType(nondefdecl));
13333#if 0
13334 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());
13335#endif
13336 }
13337#if 0
13338 printf(" next 3\n");
13339#endif
13340
13341 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13342 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
13343
13344 // DQ (7/16/2017): Added code to set the template parameters in the just build declaration (if it is a template declaration).
13345 // We want to set the parents of the template paremters to the frst nondefining template class declaration, and we want to reset
13346 // the scope of the declarations associated with any previously marked SgClassType objects associated with any template parameters.
13347 // printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): Calling setTemplateParametersInDeclaration(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
13348
13349 setTemplateParametersInDeclaration(nondefdecl,templateParameterList);
13350
13351 // DQ (8/13/2013): Adding test of template parameter lists.
13352 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(nondefdecl);
13353 ROSE_ASSERT(templateClassDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateClassDeclaration->get_templateParameters().size()));
13354
13355 mysymbol = new SgTemplateClassSymbol(nondefdecl);
13356 scope->insert_symbol(nameWithTemplateSpecializationArguments, mysymbol);
13357#if 0
13358 printf(" end build non-defn decl\n");
13359#endif
13360 }
13361 } else {
13362 SgClassSymbol* mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
13363 if (mysymbol == NULL) {
13364 printf("WARNING: In buildTemplateClassDeclaration_nfi(): non-defining declaration was provided but cannot be located in the associated scope.\n");
13365 }
13366 }
13367
13368#if 0
13369 printf ("In buildTemplateClassDeclaration_nfi(): Setting the firstNondefiningDeclaration to be nondefdecl = %p \n",nondefdecl);
13370#endif
13371
13372 defdecl->set_firstNondefiningDeclaration(nondefdecl);
13373
13374 // DQ (9/16/2012): Setup the template specialization arguments on the defining declaration (tested below at base of function).
13375 setTemplateSpecializationArgumentsInDeclaration(defdecl,templateSpecializationArgumentList);
13376
13377#if 1
13378 // 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).
13379
13380 // Liao, 10/30/2009
13381 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
13382 // This is not desired when building a defining declaration and an inefficience in the constructor
13383 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
13384 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
13385 if (defdecl->get_type() != NULL)
13386 {
13387 // if a defining class declaration's type is associated with a defining class.
13388 // This is a wrong SgClassType and has to be reset
13389#if 0
13390 // if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
13391 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
13392 {
13393 delete defdecl->get_type();
13394 }
13395#else
13396 // DQ (1/13/2013): I am not clear what this means... if (defdecl->get_type() != NULL) then it makes
13397 // no sense to assert that (defdecl->get_type() == NULL). This is related to the reuse of the defining
13398 // declaration when it is available (instead of building a new one, which still might be required for a
13399 // template specialization (or template partial specialization)).
13400 // ROSE_ASSERT(defdecl->get_type() == NULL);
13401#endif
13402 }
13403
13404 // patch up the SgClassType for the defining class declaration
13405 ROSE_ASSERT (nondefdecl->get_type() != NULL);
13406 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
13407
13408 // DQ (1/22/2013): This assertion is a problem for boost code represented by ROSE compiling ROSE (see testRoseHeaders_01.C)
13409 if (isSgClassType(nondefdecl->get_type())->get_declaration() != isSgDeclarationStatement(nondefdecl))
13410 {
13411#if 0
13412 printf ("In buildTemplateClassDeclaration_nfi(): detected isSgClassType(nondefdecl->get_type())->get_declaration() != isSgDeclarationStatement(nondefdecl) (problem with Boost code in ROSE compiling ROSE) \n");
13413#endif
13414 }
13415 // ROSE_ASSERT (isSgClassType(nondefdecl->get_type())->get_declaration() == isSgDeclarationStatement(nondefdecl));
13416
13417 defdecl->set_type(nondefdecl->get_type());
13418
13419#if 0
13420 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());
13421#endif
13422#endif
13423
13424 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
13425 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
13426 // used in a defining declaration).
13427 nondefdecl->setForward();
13428
13429#if 0
13430 if (scope != NULL) // put into fixStructDeclaration() or alike later on
13431 {
13432 // fixStructDeclaration(defdecl,scope);
13433 // fixStructDeclaration(nondefdecl,scope);
13434
13435 printf ("***** WARNING *****: Commented out call to fixStructDeclaration() \n");
13436 // ROSE_ASSERT(false);
13437 }
13438#endif
13439
13440 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
13441 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
13442
13443 ROSE_ASSERT(defdecl->get_scope() != NULL);
13444
13445 // DQ (12/4/2011): We need a concept for type for SgTemplateClassDeclaration so that we can construct SgMemberFunctionType nodes for template member functions.
13446 // We use a SgClassType which has been fixed to permit it to hold either a SgClassDeclaration or an SgTemplateClassDeclaration.
13447 ROSE_ASSERT(defdecl->get_type() != NULL);
13448
13449 // DQ (12/26/2011): The non defining declaration should not have a valid pointer to the class definition.
13450 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
13451
13452 // DQ (7/15/2012): We want to inforce this.
13453 // ROSE_ASSERT(defdecl->get_parent() == NULL);
13454 if (defdecl->get_parent() != NULL)
13455 {
13456#if PRINT_DEVELOPER_WARNINGS
13457 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());
13458#endif
13459 }
13460
13461 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13462 ROSE_ASSERT(defdecl->get_templateName().is_null() == false);
13463
13464 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13465 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
13466
13468 testTemplateArgumentParents(nondefdecl);
13469
13470#if 0
13471 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
13472 printf ("Leaving buildTemplateClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
13473 SgClassDeclaration* tmp_classDeclaration = defdecl;
13474 SgSymbol* test_symbol = defdecl->get_scope()->find_symbol_from_declaration(tmp_classDeclaration);
13475
13476 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
13477 printf ("Leaving buildTemplateClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
13478 ROSE_ASSERT(defdecl->get_symbol_from_symbol_table() != NULL);
13479#endif
13480
13481 return defdecl;
13482 }
13483
13485 {
13486 // DQ (1/11/2009): This function has semantics very different from the buildEnumDeclaration_nfi() function!
13487
13488 if (scope == NULL)
13490
13491 SgEnumDeclaration* decl = buildEnumDeclaration_nfi(name, scope);
13495
13496 // DQ (7/15/2012): We want to inforce this.
13497 ROSE_ASSERT(decl->get_parent() == NULL);
13498
13499 return decl;
13500 } //buildEnumDeclaration()
13501
13502
13505 {
13506 // The support for SgEnumDeclaration is identical to that for SgClassDeclaration (except for the type handling, why is that?).
13507 ASSERT_not_null(scope);
13508
13509 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
13510 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
13511 ASSERT_require(SageInterface::hasTemplateSyntax(name) == false);
13512
13513 SgEnumType* enumType = nullptr;
13514 SgEnumDeclaration* first_nondefdecl = nullptr;
13515
13516 if (scope)
13517 {
13518 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
13519 if (existing_symbol != NULL)
13520 {
13521 enumType = isSgEnumType(existing_symbol->get_type());
13522 first_nondefdecl = existing_symbol->get_declaration();
13523 ROSE_ASSERT(first_nondefdecl != NULL);
13524 }
13525 }
13526
13527 // DQ (5/8/2013): We do want to build a new SgEnumDeclaration (to avoid sharing).
13528 // This forces each call to buildNondefiningEnumDeclaration_nfi() to build a unique declaration
13529 // required to avoid sharing declaration in examples such as test2007_29.C.
13530 SgEnumDeclaration* nondefdecl = new SgEnumDeclaration(name, enumType);
13531
13532 ROSE_ASSERT(nondefdecl);
13533 setOneSourcePositionNull(nondefdecl);
13534
13535 // Set the defining and first non-defining declarations.
13536 if (first_nondefdecl)
13537 {
13538 nondefdecl->set_firstNondefiningDeclaration(first_nondefdecl);
13539 nondefdecl->set_definingDeclaration(first_nondefdecl->get_definingDeclaration());
13540 }
13541 else
13542 {
13543 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
13544 nondefdecl->set_definingDeclaration(nullptr);
13545 }
13546
13547 // Any non-defining declaration is not always a forward declaration.
13548 nondefdecl->setForward();
13549
13550 SgType* type = nondefdecl->get_type();
13551 ASSERT_not_null(type);
13552
13553 if (scope)
13554 {
13555 // Check for an existing symbol (reuse it if it is found).
13556 SgEnumSymbol* mysymbol = nullptr;
13557 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
13558
13559 if (existing_symbol)
13560 {
13561 mysymbol = existing_symbol;
13562 first_nondefdecl = mysymbol->get_declaration();
13563 }
13564 else
13565 {
13566 first_nondefdecl = nondefdecl;
13567
13568 mysymbol = new SgEnumSymbol(nondefdecl);
13569 ASSERT_not_null(mysymbol);
13570 scope->insert_symbol(name, mysymbol);
13571 }
13572
13573 nondefdecl->set_scope(scope);
13574
13575 // Can this be defined in C++ so that it is in a logical scope different from its structural scope?
13576 nondefdecl->set_parent(scope);
13577 }
13578
13579 if (first_nondefdecl != nondefdecl)
13580 {
13581 nondefdecl->set_firstNondefiningDeclaration(first_nondefdecl);
13582
13583 if (first_nondefdecl->get_definingDeclaration() != NULL)
13584 {
13585 nondefdecl->set_definingDeclaration(first_nondefdecl->get_definingDeclaration());
13586 }
13587 }
13588
13589 ASSERT_not_null(nondefdecl->get_type());
13590 ASSERT_not_null(scope->lookup_enum_symbol(name));
13591
13592 return nondefdecl;
13593 }
13594
13595
13598 {
13599 ROSE_ASSERT(scope != NULL);
13600
13601#if 0
13602 printf ("In buildEnumDeclaration_nfi(): name = %s scope = %p = %s \n",name.str(),scope,scope->class_name().c_str());
13603#endif
13604
13605 // DQ (5/8/2013): I think if we searched for the type it might exist and this would allow the types to be shared.
13606 SgEnumType* enumType = NULL;
13607
13608 if (scope != NULL)
13609 {
13610 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
13611 if (existing_symbol != NULL)
13612 {
13613 enumType = isSgEnumType(existing_symbol->get_type());
13614 }
13615 }
13616
13617#if 0
13618 printf ("In buildEnumDeclaration_nfi(): name = %s building using enumType = %p \n",name.str(),enumType);
13619#endif
13620
13621 // SgEnumDeclaration* defdecl = new SgEnumDeclaration (name,NULL);
13622 SgEnumDeclaration* defdecl = new SgEnumDeclaration (name,enumType);
13623 ROSE_ASSERT(defdecl);
13624
13625#if 0
13626 printf ("In buildEnumDeclaration_nfi(): built defining declaration = %p name = %s scope = %p = %s \n",defdecl,name.str(),scope,scope->class_name().c_str());
13627#endif
13628
13629 // DQ (5/8/2013): Make sure that the enum type is available.
13630 SgType* type = defdecl->get_type();
13631 ROSE_ASSERT(type != NULL);
13632
13633 setOneSourcePositionNull(defdecl);
13634 // constructor is side-effect free
13635 defdecl->set_definingDeclaration(defdecl);
13636
13637#if 0
13638 printf ("In buildEnumDeclaration_nfi(): name = %s \n",name.str());
13639#endif
13640
13641#if 1
13642 // DQ (4/3/2017): Check for an existing non-defining declaration before building one (to avoid multiple versions). See test2017_13.C.
13643 ROSE_ASSERT(scope != NULL);
13644 SgEnumSymbol* enumSymbol = scope->lookup_enum_symbol(name);
13645 // ROSE_ASSERT(enumSymbol != NULL);
13646 SgEnumDeclaration* nondefdecl = NULL;
13647 if (enumSymbol != NULL)
13648 {
13649 ROSE_ASSERT(enumSymbol->get_declaration() != NULL);
13650 nondefdecl = enumSymbol->get_declaration();
13651 ROSE_ASSERT(nondefdecl != NULL);
13652 }
13653 else
13654 {
13655 // build the nondefining declaration
13656 nondefdecl = buildNondefiningEnumDeclaration_nfi(name, scope);
13657#if 0
13658 printf ("###### In buildEnumDeclaration_nfi(): built a non-defining declaration to support the symbol table: name = %s nondefdecl = %p \n",name.str(),nondefdecl);
13659#endif
13660 }
13661#else
13662 // build the nondefining declaration
13663 SgEnumDeclaration* nondefdecl = buildNondefiningEnumDeclaration_nfi(name, scope);
13664#endif
13665
13666 nondefdecl->set_definingDeclaration(defdecl);
13667 // defdecl->set_firstNondefiningDeclaration(nondefdecl);
13669
13670 // DQ (4/22/2013): We need to set the defining declaration on the first non-defining declaration.
13671 if (nondefdecl->get_firstNondefiningDeclaration() != NULL && nondefdecl->get_firstNondefiningDeclaration() != nondefdecl)
13672 {
13674 }
13675
13676 // DQ (4/22/2013): Thing that should be true at this point.
13677 ROSE_ASSERT(nondefdecl->get_definingDeclaration() != NULL);
13678 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
13679 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration()->get_definingDeclaration() != NULL);
13680 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration()->get_firstNondefiningDeclaration() != NULL);
13681 ROSE_ASSERT(defdecl->get_definingDeclaration() != NULL);
13682 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
13683
13684 // DQ (1/11/2009): The buildNondefiningEnumDeclaration function builds an entry in the symbol table, and so we don't want a second one!
13685#if 0
13686 SgEnumSymbol* mysymbol = new SgEnumSymbol(nondefdecl);
13687 ROSE_ASSERT(mysymbol);
13688 // scope->print_symboltable("buildEnumDeclaration_nfi(): before inserting new SgEnumSymbol");
13689 scope->insert_symbol(name, mysymbol);
13690#endif
13691
13692 defdecl->set_scope(scope);
13693 nondefdecl->set_scope(scope);
13694
13695#if 0
13696 // 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).
13697 defdecl->set_parent(scope);
13698 nondefdecl->set_parent(scope);
13699#endif
13700
13701 // DQ (7/12/2012): When this is an unnamed enum declaration, this it is NON-AUTONIMOUS
13702 // (and will have it's parent set in the associated variable or typedef declaration.
13703 // In the case of a class declaration this is always NULL (this should be similar).
13704 ROSE_ASSERT(defdecl->get_parent() == NULL);
13705
13706#if 0
13707 printf ("In buildEnumDeclaration_nfi(): name = %s defdecl = %p \n",name.str(),defdecl);
13708#endif
13709
13710 // DQ (5/8/2013): Check that the symbol is present.
13711 ROSE_ASSERT(scope->lookup_enum_symbol(name) != NULL);
13712
13713 return defdecl;
13714 } //buildEnumDeclaration_nfi()
13715
13716
13718SageBuilder::buildBaseClass ( SgClassDeclaration* classDeclaration, SgClassDefinition* classDefinition, bool isVirtual, bool isDirect )
13719 {
13720 // DQ (5/6/2013): Refactored the construction of the SgBaseClass support to the builder API.
13721
13722 // Note: classDeclaration should be the first non-defining class declaration, not required to be the the declaration associated with the SgClassDefinition.
13723 ROSE_ASSERT(classDeclaration != NULL);
13724 ROSE_ASSERT(classDefinition != NULL);
13725
13726 // DQ (5/6/2013): This is not always true (see test2013_63.C).
13727 // ROSE_ASSERT(classDeclaration == classDeclaration->get_firstNondefiningDeclaration());
13728
13729 ROSE_ASSERT(classDefinition->get_declaration() != NULL);
13730
13731 // DQ (5/6/2013): This is not always true (see test2004_30.C).
13732 // ROSE_ASSERT(classDefinition->get_declaration() == classDeclaration->get_firstNondefiningDeclaration());
13733
13734 SgBaseClass* baseclass = new SgBaseClass ( classDeclaration, isDirect );
13735 ROSE_ASSERT(baseclass != NULL);
13736
13737 if (isVirtual == true)
13738 {
13739 // DQ (1/21/2019): get_baseClassModifier() uses ROSETTA generated access functions which return a pointer.
13740 // baseclass->get_baseClassModifier().setVirtual();
13741 ROSE_ASSERT(baseclass->get_baseClassModifier() != NULL);
13742 baseclass->get_baseClassModifier()->setVirtual();
13743 }
13744
13745 // DQ (4/29/2004): add support to set access specifier
13746 // baseclass->get_baseClassModifier().get_accessModifier() = set_access_modifiers(bcdp->access);
13747 // baseclass->get_baseClassModifier().get_accessModifier() = buildAccessModifier(accessModifiers);
13748
13749 // DQ (6/21/2005): Set the parent of the base class to the class definition
13750 // (these are not traversed in ROSE currently, so their parents are not set).
13751 baseclass->set_parent(classDefinition);
13752
13753 // DQ (6/21/2005): Notice that this is copied by value (the base class list should be a list of pointers to SgBaseClass (later)
13754 classDefinition->append_inheritance(baseclass);
13755
13756 return baseclass;
13757 }
13758
13759
13761SageBuilder::buildNonrealBaseClass ( SgNonrealDecl* nrdecl, SgClassDefinition* classDefinition, bool isVirtual, bool isDirect )
13762 {
13763 ROSE_ASSERT(nrdecl != NULL);
13764 ROSE_ASSERT(classDefinition != NULL);
13765
13766 SgNonrealBaseClass * baseclass = new SgNonrealBaseClass ( NULL , isDirect , nrdecl );
13767 ROSE_ASSERT(baseclass != NULL);
13768
13769 if (isVirtual == true)
13770 {
13771 baseclass->get_baseClassModifier()->setVirtual();
13772 }
13773
13774 baseclass->set_parent(classDefinition);
13775
13776 classDefinition->append_inheritance(baseclass);
13777
13778 return baseclass;
13779 }
13780
13781
13782#if 0
13783// This function would be more complex that I want to support at present since the mapping of
13784// edg modifier values to ROSE modifier values is offset and backwards (reversed in numerical order).
13786SageBuilder::buildAccessModifier ( unsigned int access )
13787 {
13789
13790 switch (access)
13791 {
13792 case as_public:
13793#if 0
13794 printf ("In SageBuilder::set_access_modifiers(): Mark as public \n");
13795#endif
13796 a.setPublic();
13797 break;
13798
13799 case as_protected:
13800#if 0
13801 printf ("In SageBuilder::set_access_modifiers(): Mark as protected \n");
13802#endif
13803 a.setProtected();
13804 break;
13805
13806 case as_private:
13807#if 0
13808 printf ("In SageBuilder::set_access_modifiers(): Mark as private \n");
13809#endif
13810 a.setPrivate();
13811 break;
13812
13813 default:
13814 printf ("Error: default reached in SageBuilder::set_access_modifiers() \n");
13815 ROSE_ABORT ();
13816 }
13817
13818 return a;
13819 }
13820#endif
13821
13822
13823void
13824SageBuilder::fixupSourcePositionFileSpecification(SgNode* subtreeRoot, const std::string& newFileName)
13825 {
13826 // DQ (11/8/2019): This function changes the filename designation in all of the Sg_File_Info objects
13827 // associated with the designated AST subtree.
13828
13829 ROSE_ASSERT(subtreeRoot != NULL);
13830 ROSE_ASSERT(newFileName != "");
13831
13832#define DEBUG_FIXUP 0
13833
13834#if DEBUG_FIXUP
13835 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): newFileName = %s \n",newFileName.c_str());
13836 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13837#endif
13838
13839 class Traversal : public AstSimpleProcessing
13840 {
13841 public:
13842
13843 Traversal(const std::string& tmp_newFileName, int tmp_new_file_id, int tmp_originalFileId)
13844 {
13845 newFileName = tmp_newFileName;
13846 new_file_id = tmp_new_file_id;
13847 originalFileId = tmp_originalFileId;
13848#if DEBUG_FIXUP
13849 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): newFileName = %s new_file_id = %d originalFileId = %d \n",newFileName.c_str(),new_file_id,originalFileId);
13850#endif
13851 }
13852
13853 void visit (SgNode* node)
13854 {
13855#if DEBUG_FIXUP
13856 printf ("In fixupSourcePositionFileSpecification visit(): node = %p = %s \n",node,node->class_name().c_str());
13857#endif
13858
13859 SgLocatedNode* locatedNode = isSgLocatedNode(node);
13860 if (locatedNode != NULL)
13861 {
13862 // if (locatedNode->get_startOfConstruct()->get_file_id() == originalFileId)
13863 if (locatedNode->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13864 {
13865 ROSE_ASSERT(locatedNode->get_startOfConstruct() != NULL);
13866 ROSE_ASSERT(locatedNode->get_endOfConstruct() != NULL);
13867
13868 if (locatedNode->get_startOfConstruct()->isShared() == true)
13869 {
13870#if DEBUG_FIXUP
13871 printf ("Found SgLocatedNode marked as isShared() == true: locatedNode = %p = %s \n",locatedNode,locatedNode->class_name().c_str());
13872#endif
13873#if 0
13874 printf ("Exiting as a test! \n");
13875 ROSE_ABORT();
13876#endif
13877 }
13878 locatedNode->get_startOfConstruct()->set_file_id(new_file_id);
13879 locatedNode->get_endOfConstruct ()->set_file_id(new_file_id);
13880
13881 locatedNode->get_startOfConstruct()->set_physical_file_id(new_file_id);
13882 locatedNode->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13883
13884#if DEBUG_FIXUP
13885 printf ("locatedNode->get_startOfConstruct()->get_filename() = %s locatedNode->get_startOfConstruct()->get_physical_filename() = %s \n",
13886 locatedNode->get_startOfConstruct()->get_filenameString().c_str(),locatedNode->get_startOfConstruct()->get_physical_filename().c_str());
13887 printf ("locatedNode->get_startOfConstruct()->get_file_id() = %d locatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",
13888 locatedNode->get_startOfConstruct()->get_file_id(),locatedNode->get_startOfConstruct()->get_physical_file_id());
13889 printf ("locatedNode->get_startOfConstruct()->isShared() = %s \n",locatedNode->get_startOfConstruct()->isShared() ? "true" : "false");
13890#endif
13891 }
13892 else
13893 {
13894#if DEBUG_FIXUP
13895 printf ("NOT MATCHING: originalFileId = %d locatedNode->get_startOfConstruct()->get_file_id() = %d locatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",
13896 originalFileId,locatedNode->get_startOfConstruct()->get_file_id(),locatedNode->get_startOfConstruct()->get_physical_file_id());
13897 printf (" ------------ originalFileId = %d locatedNode->get_endOfConstruct()->get_file_id() = %d locatedNode->get_endOfConstruct()->get_physical_file_id() = %d \n",
13898 originalFileId,locatedNode->get_endOfConstruct()->get_file_id(),locatedNode->get_endOfConstruct()->get_physical_file_id());
13899#endif
13900 }
13901 }
13902 else
13903 {
13904 SgInitializedName* initializedName = isSgInitializedName(node);
13905 if (initializedName != NULL)
13906 {
13907 // if (initializedName->get_startOfConstruct()->get_file_id() == originalFileId)
13908 if (initializedName->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13909 {
13910 ROSE_ASSERT(initializedName->get_startOfConstruct() != NULL);
13911 ROSE_ASSERT(initializedName->get_endOfConstruct() != NULL);
13912
13913 initializedName->get_startOfConstruct()->set_file_id(new_file_id);
13914 initializedName->get_endOfConstruct ()->set_file_id(new_file_id);
13915
13916 initializedName->get_startOfConstruct()->set_physical_file_id(new_file_id);
13917 initializedName->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13918 }
13919 }
13920 else
13921 {
13922 SgSourceFile* sourceFile = isSgSourceFile(node);
13923 if (sourceFile != NULL)
13924 {
13925 ROSE_ASSERT(sourceFile->get_startOfConstruct() != NULL);
13926#if 0
13927 // A SgSourceFile has no endOfConstruct.
13928 if (sourceFile->get_endOfConstruct() == NULL)
13929 {
13930#if 0
13931 printf ("sourceFile->get_endOfConstruct() == NULL: fixup endOfConstruct \n");
13932#endif
13933 sourceFile->set_endOfConstruct(new Sg_File_Info());
13934 *(sourceFile->get_endOfConstruct()) = *(sourceFile->get_startOfConstruct());
13935 }
13936 ROSE_ASSERT(sourceFile->get_endOfConstruct() != NULL);
13937#endif
13938 // Need to test the physical_file_id because we already set the regular file_id (as part of seeding the process).
13939 // if (sourceFile->get_startOfConstruct()->get_file_id() == originalFileId)
13940 if (sourceFile->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13941 {
13942 sourceFile->get_startOfConstruct()->set_file_id(new_file_id);
13943 sourceFile->get_startOfConstruct()->set_physical_file_id(new_file_id);
13944#if DEBUG_FIXUP
13945 printf ("sourceFile->get_startOfConstruct()->get_file_id() = %d \n",sourceFile->get_startOfConstruct()->get_file_id());
13946 printf ("sourceFile->get_startOfConstruct()->get_physical_file_id() = %d \n",sourceFile->get_startOfConstruct()->get_physical_file_id());
13947#endif
13948 // sourceFile->get_endOfConstruct ()->set_file_id(new_file_id);
13949 // sourceFile->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13950 }
13951 }
13952 else
13953 {
13954#if DEBUG_FIXUP
13955 printf ("Unhandled: node = %p = %s \n",node,node->class_name().c_str());
13956#endif
13957 }
13958 }
13959 }
13960
13961 SgExpression* expression = isSgExpression(node);
13962 if (expression != NULL)
13963 {
13964 if (expression->get_operatorPosition()->get_physical_file_id() == originalFileId)
13965 {
13966 expression->get_operatorPosition()->set_file_id(new_file_id);
13967 expression->get_operatorPosition()->set_physical_file_id(new_file_id);
13968 }
13969 }
13970 }
13971
13972 // Data members.
13973 int new_file_id;
13974 int originalFileId;
13975 string newFileName;
13976 };
13977
13978
13979 SgFile* file = isSgFile(subtreeRoot);
13980 int new_file_id = -1;
13981 int originalFileId = -1;
13982
13983 if (file != NULL)
13984 {
13985 // We need to set the filename in at least one Sg_File_Info object so that we can have
13986 // the file_id be computed ans saved into the file_id to filename maps.
13987
13988 originalFileId = file->get_startOfConstruct()->get_file_id();
13989#if DEBUG_FIXUP
13990 printf ("originalFileId = %d \n",originalFileId);
13991#endif
13992 file->get_startOfConstruct()->set_filenameString(newFileName);
13993 new_file_id = Sg_File_Info::get_nametofileid_map()[newFileName];
13994
13995
13996#if 0
13997 file->get_endOfConstruct()->set_physical_file_id(new_file_id);
13998
13999 file->get_startOfConstruct()->set_physical_file_id(new_file_id);
14000 file->get_endOfConstruct()->set_physical_file_id(new_file_id);
14001
14002 // getFilenameFromID
14003 int new_file_id_2 = Sg_File_Info::getIDFromFilename(newFileName);
14004#if 0
14005 printf ("new_file_id = %d new_file_id_2 = %d \n",new_file_id,new_file_id_2);
14006#endif
14007 ROSE_ASSERT(new_file_id == new_file_id_2);
14008
14009 string new_filename_2 = Sg_File_Info::getFilenameFromID(new_file_id);
14010#if 0
14011 printf ("newFileName = %s new_filename_2 = %s \n",newFileName.c_str(),new_filename_2.c_str());
14012#endif
14013 ROSE_ASSERT(newFileName == new_filename_2);
14014#endif
14015
14016#if DEBUG_FIXUP
14017 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): file != NULL: newFileName = %s new_file_id = %d \n",newFileName.c_str(),new_file_id);
14018#endif
14019 }
14020 else
14021 {
14022 SgLocatedNode* subtreeLocatedNode = isSgLocatedNode(subtreeRoot);
14023 if (subtreeLocatedNode != NULL)
14024 {
14025#if DEBUG_FIXUP
14026 printf ("subtreeLocatedNode->get_startOfConstruct()->get_file_id() = %d \n",subtreeLocatedNode->get_startOfConstruct()->get_file_id());
14027 printf ("subtreeLocatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",subtreeLocatedNode->get_startOfConstruct()->get_physical_file_id());
14028#endif
14029 originalFileId = subtreeLocatedNode->get_startOfConstruct()->get_file_id();
14030 new_file_id = Sg_File_Info::getIDFromFilename(newFileName);
14031#if DEBUG_FIXUP
14032 printf ("originalFileId = %d \n",originalFileId);
14033 printf ("new_file_id = %d \n",new_file_id);
14034#endif
14035#if DEBUG_FIXUP
14036 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): subtreeLocatedNode = %s : originalFileId = %d newFileName = %s new_file_id = %d \n",
14037 subtreeLocatedNode->class_name().c_str(),originalFileId,newFileName.c_str(),new_file_id);
14038#endif
14039 }
14040 else
14041 {
14042 printf ("Error: In SageBuilder::fixupSourcePositionFileSpecification(): subtree should be a SgFile or SgLocatedNode: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
14043 ROSE_ABORT();
14044 }
14045
14046#if 0
14047 printf ("Error: In SageBuilder::fixupSourcePositionFileSpecification(): subtree should be a SgFile: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
14048 ROSE_ABORT();
14049#endif
14050 }
14051
14052 ROSE_ASSERT(new_file_id >= 0);
14053
14054 // Now build the traveral object and call the traversal (preorder) on the function definition.
14055 Traversal traversal (newFileName,new_file_id,originalFileId);
14056
14057 // traversal.traverse(subtreeRoot, preorder);
14058 // traversal.traverseInputFiles(subtreeRoot, preorder);
14059 // traversal.traverseWithinFile(subtreeRoot, preorder);
14060 traversal.traverse(subtreeRoot, preorder);
14061
14062#if 0
14063 printf ("Exiting as a test in SageBuilder::fixupSourcePositionFileSpecification() \n");
14064 ROSE_ABORT();
14065#endif
14066 }
14067
14068
14069
14070
14071
14072
14073
14074
14075void
14077 {
14078 // DQ (11/8/2019): This function changes the filename designation in all of the Sg_File_Info objects
14079 // associated with the designated AST subtree.
14080
14081 ROSE_ASSERT(subtreeRoot != NULL);
14082 ROSE_ASSERT(new_file_id >= 0);
14083
14084#if 0
14085 printf ("In SageBuilder::fixupSharingSourcePosition(): subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
14086 printf ("In SageBuilder::fixupSharingSourcePosition(): new_file_id = %d \n",new_file_id);
14087#endif
14088
14089 class Traversal : public AstSimpleProcessing
14090 {
14091 public:
14092
14093 Traversal(int tmp_new_file_id)
14094 {
14095 new_file_id = tmp_new_file_id;
14096#if 0
14097 printf ("In SageBuilder::fixupSharingSourcePosition(): new_file_id = %d \n",new_file_id);
14098#endif
14099 }
14100
14101 void visit (SgNode* node)
14102 {
14103#if 0
14104 printf ("In fixupSharingSourcePosition visit(): node = %p = %s new_file_id = %d \n",node,node->class_name().c_str(),new_file_id);
14105#endif
14106
14107 SgStatement* statement = isSgStatement(node);
14108 if (statement != NULL)
14109 {
14110 Sg_File_Info* startOfConstruct = statement->get_startOfConstruct();
14111 Sg_File_Info* endOfConstruct = statement->get_endOfConstruct();
14112#if 0
14113 printf ("new_file_id = %d startOfConstruct->get_physical_file_id() = %d \n",new_file_id,startOfConstruct->get_physical_file_id());
14114#endif
14115 // Only mark the files from the associated file (not statements in header files, for example).
14116 if (startOfConstruct->get_physical_file_id() == new_file_id)
14117 {
14118 // Mark this IR node as being shared
14119 startOfConstruct->setShared();
14120 endOfConstruct->setShared();
14121
14122 // Add this file_id to those file_id that will trigger this IR node to be unparsed.
14123#if 0
14124 printf (" --- adding entries for file_id and line number to support sharing: new_file_id = %d line = %d end line = %d \n",
14125 new_file_id,startOfConstruct->get_line(),endOfConstruct->get_line());
14126#endif
14127 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == startOfConstruct->get_fileLineNumbersToUnparse().size());
14128 ROSE_ASSERT(endOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
14129 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
14130
14131 // Add this existing_fi->get_file_id() to the list of file id's that will permit the assocated language construct to be unparsed.
14132 startOfConstruct->get_fileIDsToUnparse().push_back(new_file_id);
14133 startOfConstruct->get_fileLineNumbersToUnparse().push_back(startOfConstruct->get_line());
14134
14135 endOfConstruct->get_fileIDsToUnparse().push_back(new_file_id);
14136 endOfConstruct->get_fileLineNumbersToUnparse().push_back(endOfConstruct->get_line());
14137
14138 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == startOfConstruct->get_fileLineNumbersToUnparse().size());
14139 ROSE_ASSERT(endOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
14140 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
14141 }
14142 }
14143 else
14144 {
14145#if 0
14146 printf ("Unhandled: node = %p = %s \n",node,node->class_name().c_str());
14147#endif
14148 }
14149 }
14150
14151 // Data members.
14152 int new_file_id;
14153 };
14154
14155
14156 SgStatement* statement = isSgStatement(subtreeRoot);
14157 if (statement != NULL)
14158 {
14159#if 0
14160 printf ("statement->get_startOfConstruct()->get_file_id() = %d \n",statement->get_startOfConstruct()->get_file_id());
14161 printf ("statement->get_startOfConstruct()->get_physical_file_id() = %d \n",statement->get_startOfConstruct()->get_physical_file_id());
14162#endif
14163#if 0
14164 printf ("new_file_id = %d \n",new_file_id);
14165#endif
14166#if 0
14167 printf ("In SageBuilder::fixupSharingSourcePosition(): statement = %s : new_file_id = %d \n",statement->class_name().c_str(),new_file_id);
14168#endif
14169 }
14170 else
14171 {
14172 printf ("Error: In SageBuilder::fixupSharingSourcePosition(): subtree should be a SgFile or SgLocatedNode: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
14173 ROSE_ABORT();
14174 }
14175
14176 ROSE_ASSERT(new_file_id >= 0);
14177
14178 // Now buid the traveral object and call the traversal (preorder) on the function definition.
14179 Traversal traversal (new_file_id);
14180
14181 // traversal.traverse(subtreeRoot, preorder);
14182 // traversal.traverseInputFiles(subtreeRoot, preorder);
14183 // traversal.traverseWithinFile(subtreeRoot, preorder);
14184 traversal.traverse(subtreeRoot, preorder);
14185
14186#if 0
14187 printf ("Exiting as a test in SageBuilder::fixupSharingSourcePosition() \n");
14188 ROSE_ABORT();
14189#endif
14190 }
14191
14192
14193
14194
14195
14197SgFile*
14198SageBuilder::buildFile(const std::string& inputFileName, const std::string& outputFileName, SgProject* project/*=NULL*/, bool clear_globalScopeAcrossFiles /*=false*/)
14199 {
14200// Note that ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT defines a reduced set of ROSE to support front-end specific development.
14201// It is mostly used by quinlan to support laptop development where the smaller set of files permits one to do limited
14202// development work on a Mac (even with OSX's poor performance with large numbers of debug symbols). This is an
14203// infrequently used option.
14204#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
14205
14206#if 0
14207 printf ("In SageBuilder::buildFile(inputFileName = %s, outputFileName = %s, project = %p) \n",inputFileName.c_str(),outputFileName.c_str(),project);
14208 // printf (" --- fullname = %s \n",fullname.c_str());
14209#endif
14210
14211#if 0
14212 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14213 ROSE_ASSERT(project != NULL);
14214 std::set<SgLocatedNode*> tmp1_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14215
14216 if (tmp1_collectionOfModifiedLocatedNodes.size() > 0)
14217 {
14218 printf ("In Traversal::evaluateInheritedAttribute(): tmp1_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp1_collectionOfModifiedLocatedNodes.size());
14219#if 1
14220 printf ("Exiting as a test! \n");
14221 ROSE_ASSERT(false);
14222#endif
14223 }
14224#endif
14225
14226 ROSE_ASSERT(inputFileName.size() != 0); // empty file name is not allowed.
14227
14228 // DQ (9/18/2019): I am unclear what the use of fullname is below.
14229 // string sourceFilename = inputFileName, fullname;
14230 // string sourceFilename_fullname = inputFileName, fullname;
14231 string sourceFilename = inputFileName;
14232
14233#if 0
14234 // printf ("sourceFilename_fullname = %s \n",sourceFilename_fullname.c_str());
14235 printf ("sourceFilename = %s \n",sourceFilename.c_str());
14236#endif
14237
14238
14239 // DQ (11/5/2020): Experiment with clearing the global scope that is supporting multiple translation
14240 // units, since it is the cause of some problem when a tool is designed to read an input file twice.
14241 if (project != NULL)
14242 {
14243 SgGlobal* globalScopeAcrossFiles = project->get_globalScopeAcrossFiles();
14244 ROSE_ASSERT(globalScopeAcrossFiles != NULL);
14245
14246 ROSE_ASSERT(globalScopeAcrossFiles->get_symbol_table() != NULL);
14247 ROSE_ASSERT(globalScopeAcrossFiles->get_symbol_table()->get_table() != NULL);
14248
14249#if 0
14250 printf ("In SageBuilder::buildFile(): globalScopeAcrossFiles = %p \n",globalScopeAcrossFiles);
14251 printf (" --- globalScopeAcrossFiles->get_declarations().size() = %zu \n",globalScopeAcrossFiles->get_declarations().size());
14252 printf (" --- globalScopeAcrossFiles->get_symbol_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->size());
14253 printf (" --- globalScopeAcrossFiles->get_symbol_table()->get_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->get_table()->size());
14254#endif
14255#if 0
14256 printf ("Removing all elements from the globalScopeAcrossFiles->get_symbol_table() \n");
14257#endif
14258
14259 // DQ (11/5/2020): Clear the symbol table used to support multifile handling.
14260 // This breaks only one of the test codes in the codeSegregation tool, but it is a name
14261 // qualification that should likely be handled better so I think this is a good fix.
14262 if (clear_globalScopeAcrossFiles == true)
14263 {
14264 globalScopeAcrossFiles->get_symbol_table()->get_table()->delete_elements();
14265 }
14266
14267#if 0
14268 printf ("After removing all symbols (alias symbols): globalScopeAcrossFiles->get_symbol_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->size());
14269 printf ("After removing all symbols (alias symbols): globalScopeAcrossFiles->get_symbol_table()->get_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->get_table()->size());
14270#endif
14271 }
14272
14273 // DQ (9/18/2019): Test that the use of fullname has no effect.
14274 // ROSE_ASSERT(sourceFilename == sourceFilename_fullname);
14275
14276 Rose_STL_Container<std::string> arglist;
14277 int nextErrorCode = 0;
14278
14279#if 0
14280 bool set_header_file_unparsing_optimization = false;
14281#endif
14282
14283 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
14284 bool isCopyOfExistingFile_testForSharedNodes = false;
14285 SgFile* fileBeingCopied = NULL;
14286
14287 if (project == NULL)
14288 // SgProject is created on the fly
14289 // Make up an arglist in order to reuse the code inside SgFile::setupSourceFilename()
14290 {
14291#if 0
14292 printf ("In SageBuilder::buildFile(): build the SgProject \n");
14293#endif
14294 project = new SgProject();
14295 ROSE_ASSERT(project);
14296 project->get_fileList().clear();
14297
14298 arglist.push_back("cc");
14299 arglist.push_back("-c");
14300 project->set_originalCommandLineArgumentList (arglist);
14301 }
14302 else
14303 {
14304 // If project exists, then find the original source file if it exists and check the header file optimization setting for consistancy.
14305
14306 // DQ (9/18/2019): Adding debugging support to header file optimization support.
14307 SgFilePtrList & files = project->get_fileList();
14308 for (SgFilePtrList::iterator i = files.begin(); i != files.end(); i++)
14309 {
14310 SgFile* file = *i;
14311#if 0
14312 printf ("file = %p = %s name = %s \n",file,file->class_name().c_str(), file->getFileName().c_str());
14313
14314 printf ("file->get_header_file_unparsing_optimization() = %s \n",file->get_header_file_unparsing_optimization() ? "true" : "false");
14315 printf ("file->get_header_file_unparsing_optimization_source_file() = %s \n",file->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14316 printf ("file->get_header_file_unparsing_optimization_header_file() = %s \n",file->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14317#endif
14318 if (sourceFilename == file->getFileName())
14319 {
14320#if 0
14321 printf ("This is a copy of an existing file in the project: sourceFilename = %s \n",sourceFilename.c_str());
14322#endif
14323 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
14324 isCopyOfExistingFile_testForSharedNodes = true;
14325 fileBeingCopied = file;
14326
14327#if 0
14328 // DQ (4/24/2021): This data member header_file_unparsing_optimization is now static.
14329 // We are building a second copy of an originally specified file (so we need to set the optimization setting similarly).
14330 if (file->get_header_file_unparsing_optimization() == true)
14331 {
14332 set_header_file_unparsing_optimization = true;
14333 }
14334#endif
14335 }
14336 }
14337
14338#if 0
14339 printf ("Exiting as a test! \n");
14340 ROSE_ABORT();
14341#endif
14342 }
14343
14344 ifstream testfile(inputFileName.c_str());
14345 if (!testfile.is_open())
14346 {
14347 // create a temporary file if the file does not exist.
14348 // have to do this, otherwise StringUtility::getAbsolutePathFromRelativePath() complains
14349 // which is called by result->setupSourceFilename(arglist);
14350 testfile.close();
14351 ofstream outputfile(inputFileName.c_str(),ios::out);
14352 // DQ (2/6/2009): I think this comment is helpful to put into the file (helps explain why the file exists).
14353 outputfile<<"// Output file generated so that StringUtility::getAbsolutePathFromRelativePath() will see a vaild file ... unparsed file will have rose_ prefix "<<endl;
14354 outputfile.close();
14355 }
14356 else // file already exists , load and parse it
14357 {
14358 // should not reparse all files in case their ASTs have unsaved changes,
14359 // just parse the newly loaded file only.
14360 // use argv here, change non-existing input file later on
14361 // TODO add error code handling
14362
14363 // DQ (2/6/2009): Avoid closing this file twice (so put this here, instead of below).
14364 testfile.close();
14365 // should remove the old one here, Liao, 5/1/2009
14366 }
14367
14368 // DQ (2/6/2009): Avoid closing this file twice (moved to false branch above).
14369 // testfile.close();
14370
14371 // DQ (2/6/2009): Need to add the inputFileName to the source file list in the project,
14372 // because this list will be used to subtract off the source files as required to build
14373 // the commandline for the backend compiler.
14374 project->get_sourceFileNameList().push_back(inputFileName);
14375
14376 Rose_STL_Container<string> sourceFilenames = project->get_sourceFileNameList();
14377 // printf ("In SageBuilder::buildFile(): sourceFilenames.size() = %" PRIuPTR " sourceFilenames = %s \n",sourceFilenames.size(),StringUtility::listToString(sourceFilenames).c_str());
14378
14379 arglist = project->get_originalCommandLineArgumentList();
14380
14381 // DQ (2/6/2009): We will be compiling the source code generated in the
14382 // "rose_<inputFileName>" file, so we don't want this on the argument stack.
14383 // TV (09/19/2018): only add if not already present
14384 if (std::find(arglist.begin(), arglist.end(), sourceFilename) == arglist.end())
14385 {
14386 arglist.push_back(sourceFilename);
14387 }
14388
14389 // DQ (2/6/2009): Modified.
14390 // There is output file name specified for rose translators
14391 if (outputFileName.empty() == false)
14392 {
14393 arglist.push_back("-rose:o");
14394 // arglist.push_back("-o");
14395 arglist.push_back(outputFileName);
14396 }
14397
14398 // DQ (4/15/2010): Turn on verbose mode
14399 // arglist.push_back("-rose:verbose 2");
14400
14401 // This handles the case where the original command line may have referenced multiple files.
14402 Rose_STL_Container<string> fileList = CommandlineProcessing::generateSourceFilenames(arglist,/* binaryMode = */ false);
14403 CommandlineProcessing::removeAllFileNamesExcept(arglist,fileList,sourceFilename);
14404
14405 // DQ (9/3/2008): Added support for SgSourceFile IR node
14406 // SgFile* result = new SgFile (arglist, nextErrorCode, 0, project);
14407 // AS(10/04/08) Because of refactoring we require the determineFileType function to be called
14408 // to construct the node.
14409 // SgSourceFile* result = new SgSourceFile (arglist, nextErrorCode, 0, project);
14410 // SgSourceFile* result = isSgSourceFile(determineFileType(arglist, nextErrorCode, project));
14411 // TH (2009-07-15): changed to more generig isSgFile, this also supports SgBinaryComposite
14412 SgFile* result = determineFileType(arglist, nextErrorCode, project);
14413 ROSE_ASSERT(result != NULL);
14414
14415#if 0
14416 printf ("In SageBuilder::buildFile(): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",project,project->get_fileList_ptr()->get_listOfFiles().size());
14417#endif
14418
14419 SgSourceFile* sourceFile = isSgSourceFile(result);
14420 if (sourceFile != NULL)
14421 {
14422 SgGlobal* globalScope = sourceFile->get_globalScope();
14423 ROSE_ASSERT(globalScope != NULL);
14424
14425 // DQ (6/24/2021): We need to end this function with the isModified flag set to false. This is
14426 // important for the support of the token based unparsing when building a dynamic library.
14427 // This is important in permitting the simpleFrontierDetectionForTokenStreamMapping() function
14428 // to generate the correct settings for nodes in the second file constructed from the original file.
14429 if (globalScope->get_isModified() == true)
14430 {
14431#if 0
14432 printf ("In SageBuilder::buildFile(): globalScope->get_isModified() == true: reset to false \n");
14433#endif
14434 globalScope->set_isModified(false);
14435#if 0
14436 printf ("In SageBuilder::buildFile(): Verify false setting: globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
14437#endif
14438 }
14439 }
14440
14441#if 0
14442 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14443 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14444
14445 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14446 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14447#endif
14448
14449#if 0
14450 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14451 ROSE_ASSERT(project != NULL);
14452 std::set<SgLocatedNode*> tmp2_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14453
14454 if (tmp2_collectionOfModifiedLocatedNodes.size() > 0)
14455 {
14456 printf ("In Traversal::evaluateInheritedAttribute(): tmp2_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp2_collectionOfModifiedLocatedNodes.size());
14457#if 1
14458 printf ("Exiting as a test! \n");
14459 ROSE_ASSERT(false);
14460#endif
14461 }
14462#endif
14463
14464#if 0
14465 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14466 ROSE_ASSERT(project != NULL);
14467 std::set<SgLocatedNode*> tmp22_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(result);
14468
14469 if (tmp22_collectionOfModifiedLocatedNodes.size() > 0)
14470 {
14471 printf ("In Traversal::evaluateInheritedAttribute(): tmp22_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp22_collectionOfModifiedLocatedNodes.size());
14472#if 1
14473 printf ("Exiting as a test! \n");
14474 ROSE_ASSERT(false);
14475#endif
14476 }
14477#endif
14478
14479#if 0
14480 printf ("Calling outputFileIds() \n");
14481
14483
14484 printf ("DONE: Calling outputFileIds() \n");
14485#endif
14486
14487#if 0
14488 // DQ (9/18/2019): Adding debugging support.
14489 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization() = %s \n",
14490 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization() ? "true" : "false");
14491#endif
14492
14493#if 0
14494 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization_source_file() = %s \n",
14495 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14496 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization_header_file() = %s \n",
14497 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14498#endif
14499
14500 // DQ (9/18/2019): Adding debugging support.
14501 // ROSE_ASSERT(result->get_header_file_unparsing_optimization() == false);
14502 // ROSE_ASSERT(result->get_header_file_unparsing_optimization_source_file() == false);
14503 // ROSE_ASSERT(result->get_header_file_unparsing_optimization_header_file() == false);
14504
14505 // ROSE_ASSERT(result->get_header_file_unparsing_optimization() == true);
14506
14507#if 0
14508 // DQ (4/24/2021): This data member header_file_unparsing_optimization is now static (so we don't need this code).
14509 if (set_header_file_unparsing_optimization == true)
14510 {
14511 result->set_header_file_unparsing_optimization(true);
14512
14513 // DQ (9/18/2019): Also set the values for the source file and header files.
14514 // I think we only want to set the source file version to true and the header file version to false.
14515 // This is enforced in the attachPreprocessingInfo() function.
14516
14517 // DQ (4/24/2021): Debugging header file optimization.
14518 // result->set_header_file_unparsing_optimization_source_file(true);
14519
14520 // result->set_header_file_unparsing_optimization_header_file(true);
14521 result->set_header_file_unparsing_optimization_header_file(false);
14522
14523#if 0
14524 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization() = %s \n",
14525 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization() ? "true" : "false");
14526 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization_source_file() = %s \n",
14527 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14528 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization_header_file() = %s \n",
14529 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14530#endif
14531 }
14532#endif
14533
14534#if 0
14535 // 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.
14536 // 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
14537 // 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
14538 // cleaner semantics.
14539 // This just adds the new file to the list of files stored internally (note: this sets the parent of the newFile).
14540 // TOO1 (2/28/2014): This is definitely required for Java (ECJ frontend), though C passes without it (I think only
14541 // by luck :-).
14542 // The ECJ frontend uses the SgProject internally (via a global SgProject*). Therefore, the
14543 // SgProject must contain this newly created SgFile, otherwise ECJ won't be able to find it.
14544 // project->set_file ( *result );
14545 if (project->get_Java_only() == true)
14546 {
14547 // DQ (3/4/2014): For now we want to output a message and clean this up afterward (likely in the Java language support).
14548 printf ("WARNING: Java specific action to add new file to SgProject (using set_file()) (more uniform language handling symantics would avoid this problem) \n");
14549 project->set_file ( *result );
14550 }
14551#else
14552 // DQ (3/6/2014): The code below adresses the specific bug faced in the use of the outliner (so we use it directly).
14553 // This code was moved ahead of the call to "result->runFrontend(nextErrorCode);" because in the case of Java
14554 // the file must be set to be a part of the SgProject before calling the runFrontend() function.
14555 // project->set_file ( *result );
14556
14557 result->set_parent(project);
14558
14559#if 0
14560 printf ("In SageBuilder::buildFile(): Outliner::use_dlopen = %s \n",Outliner::use_dlopen ? "true" : "false");
14561#endif
14562
14563#if 0
14564 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14565 ROSE_ASSERT(project != NULL);
14566 std::set<SgLocatedNode*> tmp23_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(result);
14567
14568 if (tmp23_collectionOfModifiedLocatedNodes.size() > 0)
14569 {
14570 printf ("In Traversal::evaluateInheritedAttribute(): tmp23_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp23_collectionOfModifiedLocatedNodes.size());
14571#if 1
14572 printf ("Exiting as a test! \n");
14573 ROSE_ASSERT(false);
14574#endif
14575 }
14576#endif
14577
14578#if 0
14579 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14580 ROSE_ASSERT(project != NULL);
14581 std::set<SgLocatedNode*> tmp24_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14582
14583 if (tmp24_collectionOfModifiedLocatedNodes.size() > 0)
14584 {
14585 printf ("In Traversal::evaluateInheritedAttribute(): tmp24_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp24_collectionOfModifiedLocatedNodes.size());
14586#if 1
14587 printf ("Exiting as a test! \n");
14588 ROSE_ASSERT(false);
14589#endif
14590 }
14591#endif
14592
14593 // DQ (3/5/2014): I need to check with Liao to understand this part of the code better.
14594 // I think that the default value for Outliner::use_dlopen is false, so that when the
14595 // Java support is used the true branch is taken. However, if might be the we need
14596 // to support the outliner using the code below and so this would be a bug for the
14597 // outliner.
14598 if (!Outliner::use_dlopen)
14599 {
14600#if 0
14601 printf ("In SageBuilder::buildFile(): (after test for (!Outliner::use_dlopen) == true: project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14602 project,project->get_fileList_ptr()->get_listOfFiles().size());
14603#endif
14604 // DQ (3/5/2014): If we added the file above, then don't add it here since it is redundant.
14605 project->set_file(*result); // equal to push_back()
14606#if 0
14607 printf ("In SageBuilder::buildFile(): (after 2nd project->set_file()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14608 project,project->get_fileList_ptr()->get_listOfFiles().size());
14609#endif
14610 }
14611 else
14612 {
14613#if 0
14614 printf ("In SageBuilder::buildFile(): (after test for (!Outliner::use_dlopen) == false: project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14615 project,project->get_fileList_ptr()->get_listOfFiles().size());
14616#endif
14617
14618 // Liao, 5/1/2009,
14619 // if the original command line is: gcc -c -o my.o my.c and we want to
14620 // add a new file(mynew.c), the command line for the new file would become "gcc -c -o my.o mynew.c "
14621 // which overwrites the object file my.o from my.c and causes linking error.
14622 // To avoid this problem, I insert the file at the beginning and let the right object file to be the last generated one
14623 //
14624 // TODO This is not an elegant fix and it causes some strange assertion failure in addAssociatedNodes(): default case node
14625 // So we only turn this on if Outliner:: use_dlopen is used for now
14626 // The semantics of adding a new source file can cause changes to linking phase (new object files etc.)
14627 // But ROSE has a long-time bug in handling combined compiling and linking command like "translator -o a.out a.c b.c"
14628 // It will generated two command lines: "translator -o a.out a.c" and "translator -o a.out b.c", which are totally wrong.
14629 // This problem is very relevant to the bug.
14630 SgFilePtrList& flist = project->get_fileList();
14631 flist.insert(flist.begin(),result);
14632#if 0
14633 printf ("In SageBuilder::buildFile(): (after flist.insert(flist.begin(),result)): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14634 project,project->get_fileList_ptr()->get_listOfFiles().size());
14635#endif
14636 }
14637#endif
14638
14639#if 0
14640 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14641 ROSE_ASSERT(project != NULL);
14642 std::set<SgLocatedNode*> tmp25_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14643
14644 if (tmp25_collectionOfModifiedLocatedNodes.size() > 0)
14645 {
14646 printf ("In Traversal::evaluateInheritedAttribute(): tmp25_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp25_collectionOfModifiedLocatedNodes.size());
14647#if 1
14648 printf ("Exiting as a test! \n");
14649 ROSE_ASSERT(false);
14650#endif
14651 }
14652#endif
14653
14654 // DQ (6/3/2019): The case of outlining to a seperate file will have transformations
14655 // that this checking will fail on because it is for the typical case of checking the
14656 // AST for transformations after construction of the AST from an typical input file.
14657 EDG_ROSE_Translation::suppress_detection_of_transformations = true;
14658
14659#if 0
14660 printf ("In SageBuilder::buildFile(): EDG_ROSE_Translation::suppress_detection_of_transformations = %s \n",EDG_ROSE_Translation::suppress_detection_of_transformations ? "true" : "false");
14661#endif
14662
14663#if 0
14664 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());
14665#endif
14666
14667
14668 // 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.
14669 // 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
14670 // 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
14671 // 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
14672 // the traversal) and then afterward reset the set of isModified IR nodes to isModified. By isolating the fix in this function we can eliminate
14673 // the complexity of it being seen from the outside (outside of this abstraction). Note that the function:
14674 // SageInterface::collectModifiedLocatedNodes() has previously been implemented and used for debugging.
14675 std::set<SgLocatedNode*> modifiedNodeSet = collectModifiedLocatedNodes(project);
14676
14677#if 0
14678 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14679 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14680
14681 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14682 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14683#endif
14684
14685#if 0
14686 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14687 ROSE_ASSERT(project != NULL);
14688 std::set<SgLocatedNode*> tmp251_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14689
14690 if (tmp251_collectionOfModifiedLocatedNodes.size() > 0)
14691 {
14692 printf ("In Traversal::evaluateInheritedAttribute(): tmp251_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp251_collectionOfModifiedLocatedNodes.size());
14693#if 1
14694 printf ("Exiting as a test! \n");
14695 ROSE_ASSERT(false);
14696#endif
14697 }
14698#endif
14699
14700 // 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.
14701 // 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.
14702 // 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.
14703 result->runFrontend(nextErrorCode);
14704
14705#if 0
14706 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());
14707#endif
14708
14709#if 0
14710 printf ("After result->runFrontend(): calling outputFileIds() \n");
14711
14713
14714 printf ("DONE: After result->runFrontend(): calling outputFileIds() \n");
14715#endif
14716
14717#if 0
14718 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14719 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14720
14721 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14722 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14723#endif
14724
14725#if 0
14726 // DQ (6/24/2021): This can be expected to fail, because the new AST has been build and all of the
14727 // nodes are marked as isModified until rest in the AstPostProcessing() step (below).
14728 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14729 ROSE_ASSERT(project != NULL);
14730 std::set<SgLocatedNode*> tmp26_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14731
14732 if (tmp26_collectionOfModifiedLocatedNodes.size() > 0)
14733 {
14734 printf ("In Traversal::evaluateInheritedAttribute(): tmp26_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp26_collectionOfModifiedLocatedNodes.size());
14735#if 0
14736 printf ("Exiting as a test! \n");
14737 ROSE_ASSERT(false);
14738#endif
14739 }
14740#endif
14741
14742#if 0
14743 // Output an optional graph of the AST (just the tree, when active)
14744 printf ("Generating a dot file... (SgFile only) \n");
14745 generateDOT ( *project );
14746 // generateAstGraph(project, 2000);
14747#endif
14748
14749#if 0
14750 printf ("In SageBuilder::buildFile(): Generate the dot output for multiple files (ROSE AST) \n");
14751 // generateDOT ( *project );
14752 generateDOTforMultipleFile ( *project );
14753 printf ("DONE: Generate the dot output of the SAGE III AST \n");
14754#endif
14755
14756#if 0
14757 // DQ (7/18/2019): Output a graph of the AST for debugging.
14758 // Output an optional graph of the AST (the whole graph, of bounded complexity, when active)
14759 const int MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH = 8000;
14760 generateAstGraph(project,MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH);
14761#endif
14762
14763 // DQ (7/14/2019): I think we need to call the astPostProcessing at this point.
14764#if 0
14765 printf ("In SageBuilder::buildFile(): calling astPostProcessing() \n");
14766#endif
14767
14768 if (!project->get_skip_post_processing()) AstPostProcessing(result);
14769
14770#if 0
14771 printf ("In SageBuilder::buildFile(): DONE: calling astPostProcessing() \n");
14772#endif
14773
14774#if 0
14775 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14776 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14777
14778 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14779 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14780#endif
14781
14782#if 0
14783 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14784 ROSE_ASSERT(project != NULL);
14785 std::set<SgLocatedNode*> tmp265_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14786
14787 if (tmp265_collectionOfModifiedLocatedNodes.size() > 0)
14788 {
14789 printf ("In Traversal::evaluateInheritedAttribute(): tmp265_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp265_collectionOfModifiedLocatedNodes.size());
14790#if 1
14791 printf ("Exiting as a test! \n");
14792 ROSE_ASSERT(false);
14793#endif
14794 }
14795#endif
14796
14797#if 0
14798 result->display("SageBuilder::buildFile()");
14799#endif
14800
14801 ROSE_ASSERT(project != NULL);
14802 project->set_frontendErrorCode(max(project->get_frontendErrorCode(), nextErrorCode));
14803
14804 // Not sure why a warning shows up from astPostProcessing.C
14805 // SgNode::get_globalMangledNameMap().size() != 0 size = %" PRIuPTR " (clearing mangled name cache)
14806 if (result->get_globalMangledNameMap().size() != 0)
14807 {
14808 result->clearGlobalMangledNameMap();
14809 }
14810
14811 // DQ (6/5/2019): Use the previously constructed set (above) to reset the IR nodes to be marked as isModified.
14812 // std::set<SgLocatedNode*> modifiedNodeSet = collectModifiedLocatedNodes(project);
14813 // void resetModifiedLocatedNodes(const std::set<SgLocatedNode*> & modifiedNodeSet);
14814 resetModifiedLocatedNodes(modifiedNodeSet);
14815
14816#if 0
14817 printf ("Exiting as a test! \n");
14818 ROSE_ABORT();
14819#endif
14820
14821#if 0
14822 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14823 ROSE_ASSERT(project != NULL);
14824 std::set<SgLocatedNode*> tmp27_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14825
14826 if (tmp27_collectionOfModifiedLocatedNodes.size() > 0)
14827 {
14828 printf ("In Traversal::evaluateInheritedAttribute(): tmp27_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp27_collectionOfModifiedLocatedNodes.size());
14829#if 1
14830 printf ("Exiting as a test! \n");
14831 ROSE_ASSERT(false);
14832#endif
14833 }
14834#endif
14835
14836 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
14837 if (isCopyOfExistingFile_testForSharedNodes == true)
14838 {
14839 // Sharing of IR nodes happens in the AST when the same file is read twice.
14840 // Also in the case where two declarations in the global scope match in two different ASTs (typically in header files of different translation units).
14841
14842#if 0
14843 printf ("Found isCopyOfExistingFile_testForSharedNodes == true \n");
14844 printf ("fileBeingCopied = %p = %s \n",fileBeingCopied,fileBeingCopied->getFileName().c_str());
14845#endif
14846
14847 SgSourceFile* sourceFileBeingCopied = isSgSourceFile(fileBeingCopied);
14848 ROSE_ASSERT(sourceFileBeingCopied != NULL);
14849
14850 SgSourceFile* sourceResult = isSgSourceFile(result);
14851 ROSE_ASSERT(sourceResult != NULL);
14852
14853 SgGlobal* fileBeingCopied_globalScope = sourceFileBeingCopied->get_globalScope();
14854 SgGlobal* result_globalScope = sourceResult->get_globalScope();
14855#if 0
14856 printf ("fileBeingCopied_globalScope = %p \n",fileBeingCopied_globalScope);
14857 printf ("result_globalScope = %p \n",result_globalScope);
14858#endif
14859 ROSE_ASSERT(fileBeingCopied_globalScope != NULL);
14860 ROSE_ASSERT(result_globalScope != NULL);
14861
14862 SgDeclarationStatementPtrList fileBeingCopied_declarationList = fileBeingCopied_globalScope->get_declarations();
14863 SgDeclarationStatementPtrList result_declarationList = result_globalScope->get_declarations();
14864
14865#if 1
14866 // DQ (11/22/2019): Use set intersection to compute the list to make be shared (this is a better implementation).
14867 // This implementation is insensitive to transforamtions in the original AST for the file.
14868 vector<SgDeclarationStatement*>::iterator it;
14869 SgDeclarationStatementPtrList v(fileBeingCopied_declarationList.size());
14870
14871 // This is n log n in complexity, but likely OK.
14872 std::sort(fileBeingCopied_declarationList.begin(),fileBeingCopied_declarationList.end());
14873 std::sort(result_declarationList.begin(),result_declarationList.end());
14874
14875 // printf ("v.size() = %zu \n",v.size());
14876
14877 it = std::set_intersection(fileBeingCopied_declarationList.begin(),fileBeingCopied_declarationList.end(),result_declarationList.begin(),result_declarationList.end(),v.begin());
14878
14879 v.resize(it-v.begin());
14880
14881 int fileBeingCopied_file_id = fileBeingCopied->get_startOfConstruct()->get_physical_file_id();
14882
14883 // printf ("v.size() = %zu \n",v.size());
14884 for (size_t i = 0; i < v.size(); i++)
14885 {
14886 SgDeclarationStatement* intersection_element = v[i];
14887 // printf ("intersection_element = %p = %s \n",intersection_element,intersection_element->class_name().c_str());
14888#if 0
14889 printf (" --- SageBuilder::buildFile() is sharing this node: %p %s \n",intersection_element,intersection_element->class_name().c_str());
14890#endif
14891 // DQ (11/10/2019): Need to recursively mark this as shared so that the unparser will be able to test each line?
14892
14893 fixupSharingSourcePosition(intersection_element,fileBeingCopied_file_id);
14894#if 0
14895 printf ("Exiting as a test! \n");
14896 ROSE_ABORT();
14897#endif
14898 }
14899
14900#if 0
14901 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14902 ROSE_ASSERT(project != NULL);
14903 std::set<SgLocatedNode*> tmp28_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14904
14905 if (tmp28_collectionOfModifiedLocatedNodes.size() > 0)
14906 {
14907 printf ("In Traversal::evaluateInheritedAttribute(): tmp28_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp28_collectionOfModifiedLocatedNodes.size());
14908#if 1
14909 printf ("Exiting as a test! \n");
14910 ROSE_ASSERT(false);
14911#endif
14912 }
14913#endif
14914
14915#else
14916
14917#error "DEAD CODE!"
14918
14919 // This is the older implementation that is sensitive to transforamtions in the original AST from the file.
14920 // DQ (11/21/2019): Remove elements in the vector that are SgEmptyDeclarations which
14921 // are associated with some transformations (include header, for example).
14922 std::vector<SgDeclarationStatementPtrList::iterator> removeList;
14923 SgDeclarationStatementPtrList::iterator i = fileBeingCopied_declarationList.begin();
14924 while (i != fileBeingCopied_declarationList.end())
14925 {
14926 SgEmptyDeclaration* emptyDeclaration = isSgEmptyDeclaration(*i);
14927 if (emptyDeclaration != NULL)
14928 {
14929 removeList.push_back(i);
14930 }
14931
14932 i++;
14933 }
14934
14935#error "DEAD CODE!"
14936
14937 // Need seperate list to avoid iterator invalidation.
14938 // for (SgDeclarationStatementPtrList::iterator i = removeList.begin(); i != removeList.end(); i++)
14939 for (std::vector<SgDeclarationStatementPtrList::iterator>::iterator i = removeList.begin(); i != removeList.end(); i++)
14940 {
14941 fileBeingCopied_declarationList.erase(*i);
14942 }
14943
14944 // DQ (11/21/2019): These might be a different size if for example the file being
14945 // copied is being copied after some transformations to the AST from the original file.
14946 if (fileBeingCopied_declarationList.size() != result_declarationList.size())
14947 {
14948 printf ("fileBeingCopied_declarationList.size() = %zu \n",fileBeingCopied_declarationList.size());
14949 printf ("result_declarationList.size() = %zu \n",result_declarationList.size());
14950 }
14951 ROSE_ASSERT(fileBeingCopied_declarationList.size() == result_declarationList.size());
14952
14953#error "DEAD CODE!"
14954
14955#if 0
14956 printf ("Statements from global scope (size = %zu): \n",fileBeingCopied_declarationList.size());
14957#endif
14958 for (size_t i = 0; i < fileBeingCopied_declarationList.size(); i++)
14959 {
14960 SgDeclarationStatement* fileBeingCopied_decl = fileBeingCopied_declarationList[i];
14961 SgDeclarationStatement* result_decl = result_declarationList[i];
14962#if 0
14963 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());
14964#endif
14965 if (fileBeingCopied_decl == result_decl)
14966 {
14967#if 0
14968 printf (" --- SageBuilder::buildFile() is sharing this node: %p %s \n",fileBeingCopied_decl,fileBeingCopied_decl->class_name().c_str());
14969#endif
14970 // DQ (11/10/2019): Need to recursively mark this as shared so that the unparser will be able to test each line?
14971
14972#error "DEAD CODE!"
14973
14974 int fileBeingCopied_file_id = fileBeingCopied->get_startOfConstruct()->get_physical_file_id();
14975 fixupSharingSourcePosition(fileBeingCopied_decl,fileBeingCopied_file_id);
14976#if 0
14977 printf ("Exiting as a test! \n");
14978 ROSE_ABORT();
14979#endif
14980 }
14981 }
14982
14983#error "DEAD CODE!"
14984
14985#endif
14986
14987#if 0
14988 printf ("exiting as a test! \n");
14989 ROSE_ABORT();
14990#endif
14991 }
14992
14993#if 0
14994 reportModifiedStatements("Leaving SageBuilder::buildFile(): calling reportModifiedStatements()",project);
14995#endif
14996
14997#if 0
14998 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14999 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
15000 printf ("Leaving SageBuilder::buildFile(): (after result->runFrontend()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
15001 project,project->get_fileList_ptr()->get_listOfFiles().size());
15002 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
15003 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
15004#endif
15005
15006#if 0
15007 // DQ (11/8/2019): This is not working and breaks the current work at present.
15008 // DQ (11/8/2019): Support function to change the name in each of the IR node's source position info objects.
15009 fixupSourcePositionFileSpecification(result,outputFileName);
15010#endif
15011
15012 // DQ (7/2/2020): Added assertion (fails for snippet tests).
15013 ROSE_ASSERT(result->get_preprocessorDirectivesAndCommentsList() != NULL);
15014
15015#if 0
15016 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
15017 ROSE_ASSERT(project != NULL);
15018 std::set<SgLocatedNode*> tmp3_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
15019
15020 if (tmp3_collectionOfModifiedLocatedNodes.size() > 0)
15021 {
15022 printf ("In Traversal::evaluateInheritedAttribute(): tmp3_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp3_collectionOfModifiedLocatedNodes.size());
15023#if 1
15024 printf ("Exiting as a test! \n");
15025 ROSE_ASSERT(false);
15026#endif
15027 }
15028#endif
15029
15030 return result;
15031#else
15032
15033 // false branch of #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT (at top of function.
15034
15035 return NULL;
15036#endif
15037 }
15038
15039
15042SageBuilder::buildSourceFile(const std::string& outputFileName, SgProject* project, bool clear_globalScopeAcrossFiles /*=false*/)
15043 {
15044 // DQ (2/9/2013): Adding support to build a SgSourceFile with an empty global scope.
15045 // This function calls the buildFile(string,string,SgProject*) function and provides
15046 // a simple API where one wants to create a new SgSourceFile that will then have
15047 // statements added to it and then unparsed.
15048
15049 // This function needs a way to specify the associated language for the generated file.
15050 // Currently this is taken from the input file (generated from a prefix on the output filename.
15051
15052#if 1
15053 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
15054 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
15055 printf ("In SageBuilder::buildSourceFile(outputFileName = %s, project = %p) \n",outputFileName.c_str(),project);
15056 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
15057 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
15058#endif
15059
15060 // Call the supporting function to build a file.
15061 string inputFilePrefix = "temp_dummy_file_";
15062
15063#if 0
15064 printf ("In SageBuilder::buildSourceFile(const std::string& outputFileName, SgProject* project): calling buildFile() \n");
15065#endif
15066
15067 SgFile* file = buildFile(inputFilePrefix+outputFileName,outputFileName,project,clear_globalScopeAcrossFiles);
15068 ROSE_ASSERT(file != NULL);
15069
15070#if 0
15071 printf ("DONE: In SageBuilder::buildSourceFile(): calling buildFile() \n");
15072#endif
15073
15074 SgSourceFile* sourceFile = isSgSourceFile(file);
15075 ROSE_ASSERT(sourceFile != NULL);
15076
15077 ROSE_ASSERT(sourceFile->get_globalScope() != NULL);
15078
15079#if 0
15080 printf ("call the unparser on the just built file \n");
15081#endif
15082
15083#if 0
15084 printf ("Exiting as a test! \n");
15085 ROSE_ABORT();
15086#endif
15087
15088 return sourceFile;
15089
15090 }
15091
15092SgSourceFile* SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project, bool clear_globalScopeAcrossFiles /*=false*/)
15093 {
15094#if 0
15095 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
15096 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
15097 printf ("In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling buildFile() \n");
15098 // printf (" --- inputFileName = %s outputFileName = %s \n",inputFileName.c_str(),outputFileName.c_str());
15099 printf (" --- inputFileName = %s \n",inputFileName.c_str());
15100 printf (" --- outputFileName = %s \n",outputFileName.c_str());
15101 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
15102 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
15103#endif
15104
15105#if 0
15106 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
15107 ROSE_ASSERT(project != NULL);
15108 std::set<SgLocatedNode*> tmp1_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
15109
15110 if (tmp1_collectionOfModifiedLocatedNodes.size() > 0)
15111 {
15112 printf ("In Traversal::evaluateInheritedAttribute(): tmp1_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp1_collectionOfModifiedLocatedNodes.size());
15113#if 1
15114 printf ("Exiting as a test! \n");
15115 ROSE_ASSERT(false);
15116#endif
15117 }
15118#endif
15119
15120 SgFile* file = buildFile(inputFileName, outputFileName,project,clear_globalScopeAcrossFiles);
15121 ROSE_ASSERT(file != NULL);
15122
15123#if 0
15124 printf ("DONE: In SageBuilder::buildSourceFile(): calling buildFile() \n");
15125#endif
15126
15127#if 0
15128 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
15129 ROSE_ASSERT(project != NULL);
15130 std::set<SgLocatedNode*> tmp2_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
15131
15132 if (tmp2_collectionOfModifiedLocatedNodes.size() > 0)
15133 {
15134 printf ("In Traversal::evaluateInheritedAttribute(): tmp2_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp2_collectionOfModifiedLocatedNodes.size());
15135#if 1
15136 printf ("Exiting as a test! \n");
15137 ROSE_ASSERT(false);
15138#endif
15139 }
15140#endif
15141
15142 SgSourceFile* sourceFile = isSgSourceFile(file);
15143 ROSE_ASSERT(sourceFile != NULL);
15144
15145 ROSE_ASSERT(sourceFile->get_globalScope() != NULL);
15146
15147#if 0
15148 // DQ (9/18/2019): Adding support for debugging the header file optimization.
15149 printf ("Debugging the unparsing header file optimization \n");
15150
15151 printf ("sourceFile->get_header_file_unparsing_optimization() = %s \n",sourceFile->get_header_file_unparsing_optimization() ? "true" : "false");
15152 printf ("sourceFile->get_header_file_unparsing_optimization_source_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
15153 printf ("sourceFile->get_header_file_unparsing_optimization_header_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
15154#endif
15155
15156#if 0
15157 // ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == false);
15158
15159 // 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.
15160 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization() == true);
15161 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_source_file() == true);
15162 // ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == true);
15163 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == false);
15164#endif
15165
15166 // DQ (9/18/2019): Adding support for the header file optimization.
15167 // Check is this file matches an existing file and if so avoid regathering the CPP directives and comments (if posible).
15168 // If the original file was specified as being optimized for unparsing header files, then make this one similarly.
15169 SgFilePtrList & fileList = project->get_fileList();
15170
15171#if 0
15172 printf ("Looking for file = %s \n",inputFileName.c_str());
15173#endif
15174
15175 for (SgFilePtrList::iterator i = fileList.begin(); i != fileList.end(); i++)
15176 {
15177 SgFile* temp_file = *i;
15178#if 0
15179 printf ("temp_file = %p = %s name = %s \n",temp_file,temp_file->class_name().c_str(),temp_file->getFileName().c_str());
15180#endif
15181 if (temp_file != file)
15182 {
15183 if (temp_file->getFileName() == file->getFileName())
15184 {
15185 // Then the temp_file is the original version of the file we are building for a second time
15186 // (usually as a part of the outlining to a seperate file). and we need to mark at least the
15187 // unparsing headr file optimizations to be the same across thje two file.
15188
15189 // DQ (6/12/2021): The header_file_unparsing_optimization is now a static data member and the
15190 // header_file_unparsing_optimization_source_file and header_file_unparsing_optimization_header_file
15191 // data members have been removed.
15192 // temp_file->set_header_file_unparsing_optimization(sourceFile->get_header_file_unparsing_optimization());
15193 // temp_file->set_header_file_unparsing_optimization_source_file(sourceFile->get_header_file_unparsing_optimization_source_file());
15194 // temp_file->set_header_file_unparsing_optimization_header_file(sourceFile->get_header_file_unparsing_optimization_header_file());
15195#if 0
15196 printf ("sourceFile = %p = %s \n",sourceFile,sourceFile->class_name().c_str());
15197 printf ("sourceFile->get_header_file_unparsing_optimization() = %s \n",sourceFile->get_header_file_unparsing_optimization() ? "true" : "false");
15198 printf ("sourceFile->get_header_file_unparsing_optimization_source_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
15199 printf ("sourceFile->get_header_file_unparsing_optimization_header_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
15200
15201 printf ("temp_file = %p = %s \n",temp_file,temp_file->class_name().c_str());
15202 printf ("temp_file->get_header_file_unparsing_optimization() = %s \n",temp_file->get_header_file_unparsing_optimization() ? "true" : "false");
15203 printf ("temp_file->get_header_file_unparsing_optimization_source_file() = %s \n",temp_file->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
15204 printf ("temp_file->get_header_file_unparsing_optimization_header_file() = %s \n",temp_file->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
15205#endif
15206 }
15207 else
15208 {
15209 // This is a different file.
15210 }
15211 }
15212 else
15213 {
15214 // This is the same file, already added to the SgProject file list (as it should be).
15215 }
15216 }
15217
15218
15219#if 0
15220 printf ("sourceFile->get_file_info()->get_filename() = %s \n",sourceFile->get_file_info()->get_filename());
15221 int filename_id = Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()];
15222 int filename_physical_id = Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()];
15223 printf ("Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()] = %d \n",filename_id);
15224 printf ("Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()] = %d \n",filename_physical_id);
15225 sourceFile->get_file_info()->set_physical_file_id(filename_physical_id);
15226
15227 printf ("sourceFile->get_file_info()->get_physical_filename() = %s \n",sourceFile->get_file_info()->get_physical_filename().c_str());
15228 printf ("sourceFile->get_file_info()->get_physical_file_id() = %d \n",sourceFile->get_file_info()->get_physical_file_id());
15229#endif
15230
15231#if 0
15232 printf ("Exiting as a test! \n");
15233 ROSE_ABORT();
15234#endif
15235
15236 // DQ (1/11/2021): I think we should be calling secondaryPassOverSourceFile() instead of attachPreprocessingInfo() because we need to support the token-based unparsing.
15237#if 0
15238
15239#error "DEAD CODE!"
15240
15241#if 1
15242 // DQ (11/4/2019): I need to add this when I went back to testing tool_G.
15243 // It is required in the functions to attach CPP directives and comments.
15244 if (sourceFile->get_preprocessorDirectivesAndCommentsList() == NULL)
15245 {
15246#if 1
15247 printf ("Initialize NULL p_preprocessorDirectivesAndCommentsList to empty ROSEAttributesListContainer \n");
15248#endif
15249 ROSEAttributesListContainer* tmp_preprocessorDirectivesAndCommentsList = new ROSEAttributesListContainer();
15250 sourceFile->set_preprocessorDirectivesAndCommentsList(tmp_preprocessorDirectivesAndCommentsList);
15251 }
15252 else
15253 {
15254#if 1
15255 printf ("NOTE: p_preprocessorDirectivesAndCommentsList is already defined! \n");
15256 printf (" --- inputFileName = %s \n",inputFileName.c_str());
15257 printf (" --- outputFileName = %s \n",outputFileName.c_str());
15258 printf (" --- sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size() = %zu \n",sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size());
15259#endif
15260 }
15261 ROSE_ASSERT (sourceFile->get_preprocessorDirectivesAndCommentsList() != NULL);
15262
15263#if 0
15264 // DQ (5/22/2020): If this is processing a previously processed file, then this
15265 // will cause comments and CPP directives to be collected twice. This happens
15266 // in the case where we build a copy of the source file to support construction
15267 // of a dynamic library.
15268 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");
15269#endif
15270
15271 // DQ (11/4/2019): This is a test that is use in attaching CPP directives and comments to the AST.
15272 ROSEAttributesListContainerPtr filePreprocInfo = sourceFile->get_preprocessorDirectivesAndCommentsList();
15273 ROSE_ASSERT(filePreprocInfo != NULL);
15274#endif
15275
15276#error "DEAD CODE!"
15277
15278#if 0
15279 printf ("In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling attachPreprocessingInfo() \n");
15280 printf (" --- sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size() = %zu \n",sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size());
15281#endif
15282
15283#if 0
15284 // 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.
15285 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");
15286 printf (" --- inputFileName = %s \n",inputFileName.c_str());
15287 printf (" --- outputFileName = %s \n",outputFileName.c_str());
15288 printf ("sourceFile = %p \n",sourceFile);
15289 printf ("sourceFile->get_token_list.size() = %zu \n",sourceFile->get_token_list().size());
15290 printf ("sourceFile->get_tokenSubsequenceMap().size() = %zu \n",sourceFile->get_tokenSubsequenceMap().size());
15291#endif
15292
15293#error "DEAD CODE!"
15294
15295 // DQ (1/4/2020): Adding support to permit comments and CPP directives and token stream to be defined using the outputFileName.
15296 // Liao, 2019, 1/31: We often need the preprocessing info. (e.g. #include ..) attached to make the new file compilable.
15297 // attachPreprocessingInfo (sourceFile);
15298 attachPreprocessingInfo (sourceFile,outputFileName);
15299#else
15300 // DQ (1/11/2021): Call the secondaryPassOverSourceFile() instead of attachPreprocessingInfo() because we need to support the token-based unparsing.
15302#endif
15303
15304#if 0
15305 printf ("Exiting after test! processed first phase of collecting comments and CPP directives for source file) \n");
15306 ROSE_ASSERT(false);
15307#endif
15308
15309#if 0
15310 printf ("DONE: In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling attachPreprocessingInfo() \n");
15311#endif
15312
15313#if 0
15314 printf ("call the unparser on the just built file \n");
15315#endif
15316
15317#if 0
15318 printf ("In buildSourceFile(): AS A TEST: calling unparseFile(): filename = %s \n",sourceFile->getFileName().c_str());
15319 backend(project);
15320#endif
15321
15322#if 1
15323 // DQ (11/8/2019): This is not working and breaks the current work at present.
15324 // DQ (11/8/2019): Support function to change the name in each of the IR node's source position info objects.
15325 fixupSourcePositionFileSpecification(sourceFile,outputFileName);
15326#endif
15327
15328 // DQ (1/8/2021): Set the filename used in the generated SgSourceFile to be the output file.
15329 // This appears to be important so that we can get either key correct for the comments and CPP
15330 // directives and or the comments and CPP directives to be consistant as well as the token stream,
15331 // I think this might be less about the comments and CPP directives than the key for the token stream.
15332 // Either that or I need to have an extra field for the SgSourceFile name when it is read from one
15333 // file, but trying to be another file.
15334 // sourceFile->setFileName(outputFileName);
15335
15336#if 0
15337 printf ("In SageBuilder::buildSourceFile(): changing the name of the file represented in sourceFile: \n");
15338 printf ("inputFileName = %s \n",inputFileName.c_str());
15339 printf ("outputFileName = %s \n",outputFileName.c_str());
15340 printf ("sourceFile->getFileName() = %s \n",sourceFile->getFileName().c_str());
15341#endif
15342
15343 SgGlobal* globalScope = sourceFile->get_globalScope();
15344
15345#if 0
15346 printf ("Leaving SageBuilder::buildSourceFile() sourceFile = %p globalScope = %p \n",sourceFile,sourceFile->get_globalScope());
15347 printf ("sourceFile->get_file_info()->get_file_id() = %d \n",sourceFile->get_file_info()->get_file_id());
15348 printf ("sourceFile->get_file_info()->get_physical_file_id() = %d \n",sourceFile->get_file_info()->get_physical_file_id());
15349 printf ("sourceFile->get_token_list.size() = %zu \n",sourceFile->get_token_list().size());
15350 printf ("sourceFile->get_tokenSubsequenceMap().size() = %zu \n",sourceFile->get_tokenSubsequenceMap().size());
15351 printf ("inputFileName = %s \n",inputFileName.c_str());
15352 printf ("outputFileName = %s \n",outputFileName.c_str());
15353 printf ("sourceFile->getFileName() = %s \n",sourceFile->getFileName().c_str());
15354
15355 printf ("sourceFile->get_globalScope() = %p \n",globalScope);
15356 printf ("globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
15357#endif
15358
15359 // DQ (6/1/2021): We need to end this function with the isModified flag set to false. This is
15360 // important for the support of the token based unparsing when building a dynamic library.
15361 // This is important in permitting the simpleFrontierDetectionForTokenStreamMapping() function
15362 // to generate the correct settings for nodes in the second file constructed from the original file.
15363 if (globalScope->get_isModified() == true)
15364 {
15365#if 0
15366 printf ("globalScope->get_isModified() == true: reset to false \n");
15367#endif
15368 globalScope->set_isModified(false);
15369#if 0
15370 printf ("Verify false setting: globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
15371#endif
15372 }
15373
15374#if 0
15375 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
15376 ROSE_ASSERT(project != NULL);
15377 std::set<SgLocatedNode*> tmp3_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
15378
15379 if (tmp3_collectionOfModifiedLocatedNodes.size() > 0)
15380 {
15381 printf ("In Traversal::evaluateInheritedAttribute(): tmp3_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp3_collectionOfModifiedLocatedNodes.size());
15382#if 1
15383 printf ("Exiting as a test! \n");
15384 ROSE_ASSERT(false);
15385#endif
15386 }
15387#endif
15388
15389#if 0
15390 printf ("Exiting as a test! \n");
15391 ROSE_ABORT();
15392#endif
15393
15394 return sourceFile;
15395 }
15396
15397
15398PreprocessingInfo* SageBuilder::buildComment(SgLocatedNode* target, const std::string & content,PreprocessingInfo::RelativePositionType position/*=PreprocessingInfo::before*/,PreprocessingInfo::DirectiveType dtype/* = PreprocessingInfo::CpreprocessorUnknownDeclaration*/)
15399 {
15400 return SageInterface::attachComment(target,content, position, dtype);
15401 }
15402
15404PreprocessingInfo* SageBuilder::buildHeader(const std::string& header_filename,
15405 PreprocessingInfo::RelativePositionType position/*=PreprocessingInfo::before*/,
15406 bool isSystemHeader/* =false*/)
15407{
15408 std::string content;
15409 if (isSystemHeader)
15410 content = "#include <" + header_filename + "> \n";
15411 else
15412 content = "#include \"" + header_filename + "\" \n";
15413 PreprocessingInfo* result = new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration,
15414 content, "Transformation generated",0, 0, 0, position);
15415 ROSE_ASSERT(result);
15416
15417 result->get_file_info()->setTransformation();
15418 return result;
15419}
15420
15422PreprocessingInfo* SageBuilder::buildCpreprocessorDefineDeclaration(SgLocatedNode* target,const std::string & content,PreprocessingInfo::RelativePositionType position /* =PreprocessingInfo::before*/)
15423 {
15424 ROSE_ASSERT(target != NULL); //dangling #define xxx is not allowed in the ROSE AST
15425 // simple input verification
15426 std::string content2 = content;
15427 boost::algorithm::trim(content2);
15428 string prefix = "#define";
15429 string::size_type pos = content2.find(prefix, 0);
15430 ROSE_ASSERT (pos == 0);
15431
15432 PreprocessingInfo* result = NULL;
15433
15434 PreprocessingInfo::DirectiveType mytype = PreprocessingInfo::CpreprocessorDefineDeclaration;
15435
15436 // DQ (7/19/2008): Modified interface to PreprocessingInfo
15437 // result = new PreprocessingInfo (mytype,content, "transformation-generated", 0, 0, 0, position, false, true);
15438 result = new PreprocessingInfo (mytype,content, "transformation-generated", 0, 0, 0, position);
15439 ROSE_ASSERT(result);
15440 target->addToAttachedPreprocessingInfo(result);
15441 return result;
15442
15443 }
15444
15445
15446#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
15449{
15450 // avoid duplicated creation
15451 static std::map<SgNode*, AbstractHandle::abstract_handle *> handleMap;
15452
15453 ROSE_ASSERT(n != NULL);
15454 AbstractHandle::abstract_handle * ahandle =handleMap[n];
15455 if (ahandle==NULL)
15456 {
15458 ROSE_ASSERT(anode !=NULL );
15459 ahandle = new AbstractHandle::abstract_handle(anode);
15460 //TODO do we allow NULL handle to be returned?
15461 ROSE_ASSERT(ahandle != NULL);
15462 }
15463 return ahandle;
15464}
15465#endif
15466
15469{
15470 ROSE_ASSERT(exp1 != NULL);
15471 ROSE_ASSERT(exp2 != NULL);
15472
15473 SgExprListExp* tuple = buildExprListExp(exp1,exp2);
15474 SgExprListExp* setList = buildExprListExp(tuple);
15475 SgEquivalenceStatement* equivalenceStatement = new SgEquivalenceStatement();
15476 ROSE_ASSERT(equivalenceStatement->get_equivalence_set_list() == NULL);
15477 equivalenceStatement->set_equivalence_set_list(setList);
15478 ROSE_ASSERT(equivalenceStatement->get_equivalence_set_list() != NULL);
15479 equivalenceStatement->set_firstNondefiningDeclaration(equivalenceStatement);
15480 setOneSourcePositionForTransformation(equivalenceStatement);
15481 return equivalenceStatement;
15482}
15483
15484SgSymbol*
15486 {
15487 // Starting at the snippet_declaration, record the associated scope list to the global scope.
15488 // The do a reverse traversal on the list starting with the global scope of the target AST.
15489 // Lookup each declaration as we proceed deeper into the target AST to find the associated
15490 // symbol in the target AST (associated with the input declaration from the snippet AST).
15491
15492 SgSymbol* returnSymbol = NULL;
15493
15494 typedef Rose_STL_Container<SgScopeStatement*> SgScopeStatementPtrList;
15495 SgScopeStatementPtrList snippet_scope_list;
15496
15497 // Starting at the snippet_declaration, record the associated scope list to the global scope.
15498 // SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15499 SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15500#if 1
15501 printf ("First scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15502 SgClassDefinition* temp_classDefinition = isSgClassDefinition(snippet_scope);
15503 if (temp_classDefinition != NULL)
15504 {
15505 SgClassDeclaration* temp_classDeclaration = temp_classDefinition->get_declaration();
15506 SgName className = temp_classDeclaration->get_name();
15507#if 1
15508 printf ("Input snippet declaration's class name = %s \n",className.str());
15509#endif
15510 }
15511 SgNamespaceDefinitionStatement* namespaceDefinitionStatement = isSgNamespaceDefinitionStatement(snippet_scope);
15512 if (namespaceDefinitionStatement != NULL)
15513 {
15514
15515 }
15516#endif
15517 snippet_scope_list.push_back(snippet_scope);
15518 while (snippet_scope != NULL && isSgGlobal(snippet_scope) == NULL)
15519 {
15520 // The scopes between the snippet declaration and the global scope should be named scopes,
15521 // else we will not be able to identify the associated scope in the target AST.
15522 ROSE_ASSERT(snippet_scope->isNamedScope() == true);
15523
15524 snippet_scope = snippet_scope->get_scope();
15525#if 1
15526 printf ("snippet_scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15527#endif
15528 snippet_scope_list.push_back(snippet_scope);
15529 }
15530
15531#if 1
15532 printf ("snippet_scope_list.size() = %" PRIuPTR " \n",snippet_scope_list.size());
15533#endif
15534
15535 SgGlobal* global_scope_in_target_ast = TransformationSupport::getGlobalScope(targetScope);
15536 SgScopeStatementPtrList::reverse_iterator i = snippet_scope_list.rbegin();
15537
15538 SgScopeStatement* target_AST_scope = global_scope_in_target_ast;
15539 SgScopeStatement* snippet_AST_scope = *i;
15540
15541 ROSE_ASSERT(isSgGlobal(snippet_AST_scope) != NULL);
15542 // Iterate past the global scope
15543 i++;
15544
15545 // Traverse the snippet scopes in the reverse order from global scope to the associated scope in the target AST.
15546 while (i != snippet_scope_list.rend())
15547 {
15548 // This loop has to handle different types of names scopes (for C this only means structs, I think).
15549#if 1
15550 printf ("snippet_AST_scope list *i = %p = %s \n",*i,(*i)->class_name().c_str());
15551#endif
15552 // printf ("target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope ->class_name().c_str());
15553 // printf ("snippet_AST_scope = %p = %s \n",snippet_AST_scope,snippet_AST_scope ->class_name().c_str());
15554
15555 // DQ (12/5/2020): I think this should be a switch statement.
15556 SgClassDefinition* classDefinition = isSgClassDefinition(*i);
15557 if (classDefinition != NULL)
15558 {
15559 SgClassDeclaration* classDeclaration = classDefinition->get_declaration();
15560 SgName className = classDeclaration->get_name();
15561#if 1
15562 printf ("Found snippet class name = %s \n",className.str());
15563#endif
15564 SgClassSymbol* classSymbol = target_AST_scope->lookup_class_symbol(className);
15565 ROSE_ASSERT(classSymbol != NULL);
15566 ROSE_ASSERT(classSymbol->get_declaration() != NULL);
15567#if 1
15568 printf ("Associated symbol in taget AST: declaration = %p name = %s \n",classSymbol->get_declaration(),classSymbol->get_declaration()->get_name().str());
15569#endif
15570 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15571 returnSymbol = classSymbol;
15572
15573 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15574 target_AST_scope = classDefinition;
15575 }
15576
15577 // Not clear if we can have this case for C or C++.
15578 SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(*i);
15579 if (functionDefinition != NULL)
15580 {
15581 printf ("ERROR: Found an unusual case of SgFunctionDefinition in list of scopes holding a declaration for a type \n");
15582 ROSE_ABORT();
15583 }
15584
15585 SgNamespaceDefinitionStatement* namespaceDefinition = isSgNamespaceDefinitionStatement(*i);
15586 if (namespaceDefinition != NULL)
15587 {
15588 SgNamespaceDeclarationStatement* namespaceDeclaration = namespaceDefinition->get_namespaceDeclaration();
15589 SgName namespaceName = namespaceDeclaration->get_name();
15590#if 1
15591 printf ("Found snippet namespace name = %s \n",namespaceName.str());
15592#endif
15593 SgNamespaceSymbol* namespaceSymbol = target_AST_scope->lookup_namespace_symbol(namespaceName);
15594 ROSE_ASSERT(namespaceSymbol != NULL);
15595 ROSE_ASSERT(namespaceSymbol->get_declaration() != NULL);
15596#if 1
15597 printf ("Associated symbol in taget AST: declaration = %p name = %s \n",namespaceSymbol->get_declaration(),namespaceSymbol->get_declaration()->get_name().str());
15598#endif
15599 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15600 returnSymbol = namespaceSymbol;
15601
15602 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15603 target_AST_scope = namespaceDefinition;
15604 }
15605
15606 // Increment the reverse iterator.
15607 i++;
15608 }
15609
15610 // Handle the different cases using a switch (there are only a few cases).
15611 switch (snippet_declaration->variantT())
15612 {
15613 case V_SgClassDeclaration:
15614 {
15615 SgClassDeclaration* snippet_classDeclaration = isSgClassDeclaration(snippet_declaration);
15616 ROSE_ASSERT(snippet_classDeclaration != NULL);
15617
15618 SgName snippet_className = snippet_classDeclaration->get_name();
15619#if 0
15620 printf ("snippet snippet declaration's class name = %s \n",snippet_className.str());
15621#endif
15622 SgClassSymbol* target_symbol = target_AST_scope->lookup_class_symbol(snippet_className);
15623 ROSE_ASSERT(target_symbol != NULL);
15624 returnSymbol = target_symbol;
15625
15626 SgClassSymbol* classSymbolInTargetAST = isSgClassSymbol(returnSymbol);
15627 ROSE_ASSERT(classSymbolInTargetAST != NULL);
15628 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
15629 ROSE_ASSERT(target_classDeclaration != NULL);
15630#if 0
15631 printf ("snippet: classDeclaration = %p = %s \n",snippet_classDeclaration,snippet_classDeclaration->get_name().str());
15632 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
15633#endif
15634 ROSE_ASSERT(snippet_classDeclaration->get_name() == target_classDeclaration->get_name());
15635 break;
15636 }
15637
15638 case V_SgTypedefDeclaration:
15639 {
15640 SgTypedefDeclaration* snippet_typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
15641 ROSE_ASSERT(snippet_typedefDeclaration != NULL);
15642
15643 SgName snippet_typedefName = snippet_typedefDeclaration->get_name();
15644#if 0
15645 printf ("snippet snippet declaration's typedef name = %s \n",snippet_typedefName.str());
15646#endif
15647 SgTypedefSymbol* target_symbol = target_AST_scope->lookup_typedef_symbol(snippet_typedefName);
15648 ROSE_ASSERT(target_symbol != NULL);
15649 returnSymbol = target_symbol;
15650
15651 SgTypedefSymbol* typedefSymbolInTargetAST = isSgTypedefSymbol(returnSymbol);
15652 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15653 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
15654 ROSE_ASSERT(target_typedefDeclaration != NULL);
15655#if 0
15656 printf ("snippet: typedefDeclaration = %p = %s \n",snippet_typedefDeclaration,snippet_typedefDeclaration->get_name().str());
15657 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
15658#endif
15659 ROSE_ASSERT(snippet_typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
15660 break;
15661 }
15662
15663 case V_SgEnumDeclaration:
15664 {
15665 SgEnumDeclaration* snippet_enumDeclaration = isSgEnumDeclaration(snippet_declaration);
15666 ROSE_ASSERT(snippet_enumDeclaration != NULL);
15667
15668 SgName snippet_enumName = snippet_enumDeclaration->get_name();
15669#if 0
15670 printf ("snippet snippet declaration's enum name = %s \n",snippet_enumName.str());
15671#endif
15672 // DQ (4/13/2014): check if this is an un-named enum beclaration.
15673 bool isUnNamed = snippet_enumDeclaration->get_isUnNamed();
15674 if (isUnNamed == false)
15675 {
15676 // SgEnumSymbol* target_symbol = target_AST_scope->lookup_enum_symbol(snippet_enumName);
15677 SgEnumSymbol* target_symbol = lookupEnumSymbolInParentScopes(snippet_enumName,target_AST_scope);
15678 if (target_symbol == NULL)
15679 {
15680 // Debug this case.
15681 SgScopeStatement* scope = snippet_enumDeclaration->get_scope();
15682 printf ("scope = %p = %s \n",scope,scope->class_name().c_str());
15683 scope->get_file_info()->display("case V_SgEnumDeclaration: target_symbol == NULL: scope: debug");
15684 }
15685 ROSE_ASSERT(target_symbol != NULL);
15686 returnSymbol = target_symbol;
15687
15688 SgEnumSymbol* enumSymbolInTargetAST = isSgEnumSymbol(returnSymbol);
15689 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
15690 SgEnumDeclaration* target_enumDeclaration = isSgEnumDeclaration(enumSymbolInTargetAST->get_declaration());
15691 ROSE_ASSERT(target_enumDeclaration != NULL);
15692#if 0
15693 printf ("snippet: enumDeclaration = %p = %s \n",snippet_enumDeclaration,snippet_enumDeclaration->get_name().str());
15694 printf ("target: enumDeclaration = %p = %s \n",target_enumDeclaration,target_enumDeclaration->get_name().str());
15695#endif
15696 ROSE_ASSERT(snippet_enumDeclaration->get_name() == target_enumDeclaration->get_name());
15697 }
15698 else
15699 {
15700 // DQ (4/13/2014): I think we all agreed these would not have to be handled.
15701 printf ("Warning: can't handle unnamed enum declarations \n");
15702 ROSE_ASSERT(returnSymbol == NULL);
15703 }
15704 break;
15705 }
15706
15707 // DQ (12/5/2020): Adding support for codeSegregation tool.
15708 case V_SgMemberFunctionDeclaration:
15709 case V_SgFunctionDeclaration:
15710 {
15711 SgFunctionDeclaration* snippet_functionDeclaration = isSgFunctionDeclaration(snippet_declaration);
15712 ROSE_ASSERT(snippet_functionDeclaration != NULL);
15713#if 1
15714 printf ("snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15715#endif
15716 SgName snippet_functionName = snippet_functionDeclaration->get_name();
15717#if 1
15718 printf ("snippet snippet declaration's function name = %s \n",snippet_functionName.str());
15719 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope->class_name().c_str());
15720#endif
15721 SgFunctionSymbol* target_symbol = target_AST_scope->lookup_function_symbol(snippet_functionName);
15722 ROSE_ASSERT(target_symbol != NULL);
15723 returnSymbol = target_symbol;
15724
15725 SgFunctionSymbol* functionSymbolInTargetAST = isSgFunctionSymbol(returnSymbol);
15726 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
15727 SgFunctionDeclaration* target_functionDeclaration = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
15728 ROSE_ASSERT(target_functionDeclaration != NULL);
15729#if 1
15730 printf ("snippet: functionDeclaration = %p = %s \n",snippet_functionDeclaration,snippet_functionDeclaration->get_name().str());
15731 printf ("target: functionDeclaration = %p = %s \n",target_functionDeclaration,target_functionDeclaration->get_name().str());
15732#endif
15733 ROSE_ASSERT(snippet_functionDeclaration->get_name() == target_functionDeclaration->get_name());
15734 break;
15735 }
15736
15737 default:
15738 {
15739 printf ("Error: default reached in switch: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15740 ROSE_ABORT();
15741 }
15742 }
15743
15744 // return the last found symbol.
15745 return returnSymbol;
15746 }
15747
15748
15751 {
15752 // DQ (12/6/2020): This is a similar function to findAssociatedSymbolInTargetAST() but since
15753 // I need to modify it to support the requirements of the codeSegregation, it was useful to not
15754 // modify the existing findAssociatedSymbolInTargetAST() function too much so as to avoid
15755 // compromizing the snippet transformation support.
15756
15757#define DEBUG_FIND_ASSOCIATED_DECLARATION 0
15758
15759 SgSymbol* returnSymbol = NULL;
15760 SgDeclarationStatement* returnDeclaration = NULL;
15761
15762 bool isDefiningDeclaration = (snippet_declaration == snippet_declaration->get_definingDeclaration());
15763
15764#if DEBUG_FIND_ASSOCIATED_DECLARATION
15765 printf ("isDefiningDeclaration = %s \n",isDefiningDeclaration ? "true" : "false");
15766#endif
15767
15768 // DQ (12/7/2020): This should be true.
15769 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,targetScope) == false);
15770
15771 typedef Rose_STL_Container<SgScopeStatement*> SgScopeStatementPtrList;
15772 SgScopeStatementPtrList snippet_scope_list;
15773
15774 // Starting at the snippet_declaration, record the associated scope list to the global scope.
15775 // SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15776 SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15777#if DEBUG_FIND_ASSOCIATED_DECLARATION
15778 printf ("First scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15779 SgClassDefinition* temp_classDefinition = isSgClassDefinition(snippet_scope);
15780 if (temp_classDefinition != NULL)
15781 {
15782 SgClassDeclaration* temp_classDeclaration = temp_classDefinition->get_declaration();
15783 SgName className = temp_classDeclaration->get_name();
15784 printf ("Input declaration's class name = %s \n",className.str());
15785 }
15786
15787 SgNamespaceDefinitionStatement* namespaceDefinitionStatement = isSgNamespaceDefinitionStatement(snippet_scope);
15788 if (namespaceDefinitionStatement != NULL)
15789 {
15790 SgNamespaceDeclarationStatement* temp_namespaceDeclaration = namespaceDefinitionStatement->get_namespaceDeclaration();
15791 SgName namespaceName = temp_namespaceDeclaration->get_name();
15792 printf ("Input declaration's namespace name = %s \n",namespaceName.str());
15793 }
15794#endif
15795
15796 snippet_scope_list.push_back(snippet_scope);
15797 while (snippet_scope != NULL && isSgGlobal(snippet_scope) == NULL)
15798 {
15799 // The scopes between the snippet declaration and the global scope should be named scopes,
15800 // else we will not be able to identify the associated scope in the target AST.
15801 ROSE_ASSERT(snippet_scope->isNamedScope() == true);
15802
15803 snippet_scope = snippet_scope->get_scope();
15804
15805#if DEBUG_FIND_ASSOCIATED_DECLARATION
15806 printf ("snippet_scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15807#endif
15808 snippet_scope_list.push_back(snippet_scope);
15809
15810 // DQ (12/7/2020): At this point the scopes that we are traversing to the global scope should
15811 // have the same global scope as the input declaration.
15812 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_scope) == true);
15813 }
15814
15815#if DEBUG_FIND_ASSOCIATED_DECLARATION
15816 printf ("snippet_scope_list.size() = %" PRIuPTR " \n",snippet_scope_list.size());
15817 for (SgScopeStatementPtrList::iterator i = snippet_scope_list.begin(); i != snippet_scope_list.end(); i++)
15818 {
15819 SgScopeStatement* scope = *i;
15820 printf (" --- *i = %p = %s name = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
15821 SgGlobal* global_scope_from_declarations_scope = TransformationSupport::getGlobalScope(scope);
15822 printf (" --- --- global_scope_from_declarations_scope = %p \n",global_scope_from_declarations_scope);
15823 }
15824#endif
15825
15826 // DQ (12/7/2020): At this point the scopes that we are traversing to the global scope should
15827 // have the same global scope as the input declaration.
15828 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_scope) == true);
15829
15830 SgGlobal* global_scope_in_target_ast = TransformationSupport::getGlobalScope(targetScope);
15831 SgScopeStatementPtrList::reverse_iterator i = snippet_scope_list.rbegin();
15832
15833#if DEBUG_FIND_ASSOCIATED_DECLARATION
15834 printf ("global_scope_in_target_ast = %p = %s \n",global_scope_in_target_ast,global_scope_in_target_ast->class_name().c_str());
15835#endif
15836
15837 SgScopeStatement* target_AST_scope = global_scope_in_target_ast;
15838 SgScopeStatement* snippet_AST_scope = *i;
15839
15840 // DQ (12/7/2020): This should be true.
15841 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_AST_scope) == true);
15842
15843 ROSE_ASSERT(isSgGlobal(snippet_AST_scope) != NULL);
15844 // Iterate past the global scope
15845 i++;
15846
15847#if DEBUG_FIND_ASSOCIATED_DECLARATION
15848 string otherASTnameFromGlobalScope = global_scope_in_target_ast->get_file_info()->get_filenameString();
15849 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(targetScope,true);
15850 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15851 printf ("Now traverse the list of scopes in reverse to find the declaration in the other AST: \n");
15852 printf ("otherASTnameFromGlobalScope = %s \n",otherASTnameFromGlobalScope.c_str());
15853 printf ("otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15854#endif
15855
15856 // DQ (12/7/2020): This should be true.
15857 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15858
15859 // Traverse the snippet scopes in the reverse order from global scope to the associated scope in the target AST.
15860 while (i != snippet_scope_list.rend())
15861 {
15862 // This loop has to handle different types of names scopes (for C this only means structs, I think).
15863
15864 SgScopeStatement* scope = *i;
15865
15866#if DEBUG_FIND_ASSOCIATED_DECLARATION
15867 printf ("snippet_AST_scope list *i = %p = %s \n",*i,(*i)->class_name().c_str());
15868 printf (" --- *i = %p = %s name = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
15869 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope ->class_name().c_str());
15870 // printf ("snippet_AST_scope = %p = %s \n",snippet_AST_scope,snippet_AST_scope ->class_name().c_str());
15871#endif
15872
15873 // DQ (12/7/2020): This should still be true.
15874 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,scope) == true);
15875
15876#if DEBUG_FIND_ASSOCIATED_DECLARATION
15877 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(targetScope,true);
15878 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15879 printf (" --- otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15880#endif
15881
15882 // DQ (12/5/2020): I think this should be a switch statement.
15883 SgClassDefinition* classDefinition = isSgClassDefinition(*i);
15884 if (classDefinition != NULL)
15885 {
15886 SgClassDeclaration* classDeclaration = classDefinition->get_declaration();
15887 SgName className = classDeclaration->get_name();
15888#if DEBUG_FIND_ASSOCIATED_DECLARATION
15889 printf (" --- Found snippet class name = %s \n",className.str());
15890#endif
15891 SgClassSymbol* classSymbol = target_AST_scope->lookup_class_symbol(className);
15892 ROSE_ASSERT(classSymbol != NULL);
15893 ROSE_ASSERT(classSymbol->get_declaration() != NULL);
15894#if DEBUG_FIND_ASSOCIATED_DECLARATION
15895 printf (" --- Associated symbol in taget AST: declaration = %p name = %s \n",classSymbol->get_declaration(),classSymbol->get_declaration()->get_name().str());
15896#endif
15897 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15898 returnSymbol = classSymbol;
15899
15900 // DQ (12/8/2020): Need to get the associated class definition from the symbol in the target scope.
15901 SgClassDeclaration* temp_classDeclaration_in_target_ast = classSymbol->get_declaration();
15902 ROSE_ASSERT(temp_classDeclaration_in_target_ast != NULL);
15903 SgClassDeclaration* classDeclaration_in_target_ast = isSgClassDeclaration(temp_classDeclaration_in_target_ast->get_definingDeclaration());
15904 ROSE_ASSERT(classDeclaration_in_target_ast != NULL);
15905 SgClassDefinition* classDefinition_in_target_ast = classDeclaration_in_target_ast->get_definition();
15906 ROSE_ASSERT(classDefinition_in_target_ast != NULL);
15907
15908 // DQ (12/7/2020): This should be true.
15909 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15910
15911 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15912 // target_AST_scope = classDefinition;
15913 target_AST_scope = classDefinition_in_target_ast;
15914
15915 // DQ (12/7/2020): This should be true.
15916 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15917 }
15918
15919 // Not clear if we can have this case for C or C++.
15920 SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(*i);
15921 if (functionDefinition != NULL)
15922 {
15923 printf ("ERROR: Found an unusual case of SgFunctionDefinition in list of scopes holding a declaration for a type \n");
15924 ROSE_ABORT();
15925 }
15926
15927 SgNamespaceDefinitionStatement* namespaceDefinition = isSgNamespaceDefinitionStatement(*i);
15928 if (namespaceDefinition != NULL)
15929 {
15930 SgNamespaceDeclarationStatement* namespaceDeclaration = namespaceDefinition->get_namespaceDeclaration();
15931 SgName namespaceName = namespaceDeclaration->get_name();
15932#if DEBUG_FIND_ASSOCIATED_DECLARATION
15933 printf (" --- Found snippet namespace name = %s \n",namespaceName.str());
15934#endif
15935 SgNamespaceSymbol* namespaceSymbol = target_AST_scope->lookup_namespace_symbol(namespaceName);
15936 ROSE_ASSERT(namespaceSymbol != NULL);
15937 ROSE_ASSERT(namespaceSymbol->get_declaration() != NULL);
15938 SgNamespaceDeclarationStatement* otherASTnamespaceDeclaration = namespaceSymbol->get_declaration();
15939#if DEBUG_FIND_ASSOCIATED_DECLARATION
15940 printf (" --- Associated symbol in taget AST: declaration = %p name = %s \n",namespaceSymbol->get_declaration(),namespaceSymbol->get_declaration()->get_name().str());
15941#endif
15942 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15943 returnSymbol = namespaceSymbol;
15944
15945 // DQ (12/7/2020): This should be true.
15946 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15947
15948 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15949 // target_AST_scope = namespaceDefinition;
15950 target_AST_scope = otherASTnamespaceDeclaration->get_definition();
15951
15952 // DQ (12/7/2020): This should be true.
15953 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15954 }
15955
15956 // DQ (12/7/2020): This should be true.
15957 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15958
15959#if DEBUG_FIND_ASSOCIATED_DECLARATION
15960 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());
15961
15962 {
15963 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(target_AST_scope,true);
15964 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15965 printf (" --- At base of loop: otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15966 }
15967#endif
15968 // Increment the reverse iterator.
15969 i++;
15970 }
15971
15972#if DEBUG_FIND_ASSOCIATED_DECLARATION
15973 printf ("##### Now based on the kind of declaration, search for that same named declaration in the target_AST_scope = %p = %s \n",
15974 target_AST_scope,target_AST_scope->class_name().c_str());
15975#endif
15976
15977 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15978
15979 // Handle the different cases using a switch (there are only a few cases).
15980 switch (snippet_declaration->variantT())
15981 {
15982 case V_SgClassDeclaration:
15983 {
15984 SgClassDeclaration* snippet_classDeclaration = isSgClassDeclaration(snippet_declaration);
15985 ROSE_ASSERT(snippet_classDeclaration != NULL);
15986
15987 SgName snippet_className = snippet_classDeclaration->get_name();
15988
15989#if DEBUG_FIND_ASSOCIATED_DECLARATION
15990 printf ("snippet snippet declaration's class name = %s \n",snippet_className.str());
15991#endif
15992 SgClassSymbol* target_symbol = target_AST_scope->lookup_class_symbol(snippet_className);
15993 ROSE_ASSERT(target_symbol != NULL);
15994 returnSymbol = target_symbol;
15995
15996 SgClassSymbol* classSymbolInTargetAST = isSgClassSymbol(returnSymbol);
15997 ROSE_ASSERT(classSymbolInTargetAST != NULL);
15998 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
15999 ROSE_ASSERT(target_classDeclaration != NULL);
16000
16001#if DEBUG_FIND_ASSOCIATED_DECLARATION
16002 printf ("snippet: classDeclaration = %p = %s \n",snippet_classDeclaration,snippet_classDeclaration->get_name().str());
16003 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
16004#endif
16005 ROSE_ASSERT(snippet_classDeclaration->get_name() == target_classDeclaration->get_name());
16006 break;
16007 }
16008
16009 case V_SgTypedefDeclaration:
16010 {
16011 SgTypedefDeclaration* snippet_typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
16012 ROSE_ASSERT(snippet_typedefDeclaration != NULL);
16013
16014 SgName snippet_typedefName = snippet_typedefDeclaration->get_name();
16015
16016#if DEBUG_FIND_ASSOCIATED_DECLARATION
16017 printf ("snippet snippet declaration's typedef name = %s \n",snippet_typedefName.str());
16018#endif
16019 SgTypedefSymbol* target_symbol = target_AST_scope->lookup_typedef_symbol(snippet_typedefName);
16020 ROSE_ASSERT(target_symbol != NULL);
16021 returnSymbol = target_symbol;
16022
16023 SgTypedefSymbol* typedefSymbolInTargetAST = isSgTypedefSymbol(returnSymbol);
16024 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16025 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
16026 ROSE_ASSERT(target_typedefDeclaration != NULL);
16027
16028#if DEBUG_FIND_ASSOCIATED_DECLARATION
16029 printf ("snippet: typedefDeclaration = %p = %s \n",snippet_typedefDeclaration,snippet_typedefDeclaration->get_name().str());
16030 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
16031#endif
16032 ROSE_ASSERT(snippet_typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
16033 break;
16034 }
16035
16036 case V_SgEnumDeclaration:
16037 {
16038 SgEnumDeclaration* snippet_enumDeclaration = isSgEnumDeclaration(snippet_declaration);
16039 ROSE_ASSERT(snippet_enumDeclaration != NULL);
16040
16041 SgName snippet_enumName = snippet_enumDeclaration->get_name();
16042
16043#if DEBUG_FIND_ASSOCIATED_DECLARATION
16044 printf ("snippet snippet declaration's enum name = %s \n",snippet_enumName.str());
16045#endif
16046 // DQ (4/13/2014): check if this is an un-named enum beclaration.
16047 bool isUnNamed = snippet_enumDeclaration->get_isUnNamed();
16048 if (isUnNamed == false)
16049 {
16050 // SgEnumSymbol* target_symbol = target_AST_scope->lookup_enum_symbol(snippet_enumName);
16051 SgEnumSymbol* target_symbol = lookupEnumSymbolInParentScopes(snippet_enumName,target_AST_scope);
16052 if (target_symbol == NULL)
16053 {
16054 // Debug this case.
16055 SgScopeStatement* scope = snippet_enumDeclaration->get_scope();
16056 printf ("scope = %p = %s \n",scope,scope->class_name().c_str());
16057 scope->get_file_info()->display("case V_SgEnumDeclaration: target_symbol == NULL: scope: debug");
16058 }
16059 ROSE_ASSERT(target_symbol != NULL);
16060 returnSymbol = target_symbol;
16061
16062 SgEnumSymbol* enumSymbolInTargetAST = isSgEnumSymbol(returnSymbol);
16063 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
16064 SgEnumDeclaration* target_enumDeclaration = isSgEnumDeclaration(enumSymbolInTargetAST->get_declaration());
16065 ROSE_ASSERT(target_enumDeclaration != NULL);
16066
16067#if DEBUG_FIND_ASSOCIATED_DECLARATION
16068 printf ("snippet: enumDeclaration = %p = %s \n",snippet_enumDeclaration,snippet_enumDeclaration->get_name().str());
16069 printf ("target: enumDeclaration = %p = %s \n",target_enumDeclaration,target_enumDeclaration->get_name().str());
16070#endif
16071 ROSE_ASSERT(snippet_enumDeclaration->get_name() == target_enumDeclaration->get_name());
16072 }
16073 else
16074 {
16075 // DQ (4/13/2014): I think we all agreed these would not have to be handled.
16076 printf ("Warning: can't handle unnamed enum declarations \n");
16077 ROSE_ASSERT(returnSymbol == NULL);
16078 }
16079 break;
16080 }
16081
16082 // DQ (12/11/2020): Adding support for codeSegregation tool.
16083 case V_SgTemplateMemberFunctionDeclaration:
16084 // DQ (12/8/2020): Adding support for codeSegregation tool.
16085 case V_SgTemplateFunctionDeclaration:
16086 // DQ (12/5/2020): Adding support for codeSegregation tool.
16087 case V_SgMemberFunctionDeclaration:
16088 case V_SgFunctionDeclaration:
16089 {
16090 SgFunctionDeclaration* snippet_functionDeclaration = isSgFunctionDeclaration(snippet_declaration);
16091 ROSE_ASSERT(snippet_functionDeclaration != NULL);
16092
16093#if DEBUG_FIND_ASSOCIATED_DECLARATION
16094 printf ("snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16095#endif
16096 SgName snippet_functionName = snippet_functionDeclaration->get_name();
16097
16098#if DEBUG_FIND_ASSOCIATED_DECLARATION
16099 printf ("snippet snippet declaration's function name = %s \n",snippet_functionName.str());
16100 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope->class_name().c_str());
16101#endif
16102 SgFunctionSymbol* target_symbol = target_AST_scope->lookup_function_symbol(snippet_functionName);
16103 ROSE_ASSERT(target_symbol != NULL);
16104 returnSymbol = target_symbol;
16105
16106 SgFunctionSymbol* functionSymbolInTargetAST = isSgFunctionSymbol(returnSymbol);
16107 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
16108 SgFunctionDeclaration* target_functionDeclaration = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
16109 ROSE_ASSERT(target_functionDeclaration != NULL);
16110
16111#if DEBUG_FIND_ASSOCIATED_DECLARATION
16112 printf ("snippet: functionDeclaration = %p = %s \n",snippet_functionDeclaration,snippet_functionDeclaration->get_name().str());
16113 printf ("target: functionDeclaration = %p = %s \n",target_functionDeclaration,target_functionDeclaration->get_name().str());
16114 printf ("isDefiningDeclaration = %s \n",isDefiningDeclaration ? "true" : "false");
16115#endif
16116 if (isDefiningDeclaration == true)
16117 {
16118#if DEBUG_FIND_ASSOCIATED_DECLARATION
16119 printf ("get the defining declaration instead of the firstNondefining declaration from the function symbol \n");
16120#endif
16121 returnDeclaration = target_functionDeclaration->get_definingDeclaration();
16122 }
16123
16124 ROSE_ASSERT(snippet_functionDeclaration->get_name() == target_functionDeclaration->get_name());
16125 break;
16126 }
16127
16128 default:
16129 {
16130 printf ("Error: default reached in switch: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16131 ROSE_ABORT();
16132 }
16133 }
16134
16135 ROSE_ASSERT(returnDeclaration != NULL);
16136
16137 // These should have different global scopes, because they are from different ASTs.
16138 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,returnDeclaration) == false);
16139
16140 // return the last found symbol.
16141 // return returnSymbol;
16142 return returnDeclaration;
16143 }
16144
16145
16146SgType*
16148 {
16149 // This is the inner function to getTargetFileType()
16150 SgType* returnType = NULL;
16151
16152 ROSE_ASSERT(snippet_type != NULL);
16153 ROSE_ASSERT(targetScope != NULL);
16154
16155 // DQ (3/17/2014): Refactored code.
16156 // See if the type might be asociated with the snippet file.
16157 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
16158 // SgType* type_copy = snippet_type;
16159
16160#if 0
16161 SgType* type_copy = snippet_type;
16162 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
16163#endif
16164
16165 SgNamedType* namedType = isSgNamedType(snippet_type);
16166 if (namedType != NULL)
16167 {
16168 // Find the associated declaration and it's corresponding declaration in the target AST.
16169 SgDeclarationStatement* snippet_declaration = namedType->get_declaration();
16170 ROSE_ASSERT(snippet_declaration != NULL);
16171#if 0
16172 printf ("Need to find the declaration in the target AST that is associated with the snippet_declaration in the snippet AST \n");
16173 printf (" --- snippet_declaration = %p = %s = %s \n",snippet_declaration,snippet_declaration->class_name().c_str(),SageInterface::get_name(snippet_declaration).c_str());
16174#endif
16175 // There are only a few cases here!
16176 switch (namedType->variantT())
16177 {
16178 case V_SgClassType:
16179 {
16180 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
16181 if (classDeclaration != NULL)
16182 {
16183 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
16184 if (classSymbolInTargetAST == NULL)
16185 {
16186 // For Java or C++ this could be a name qualified type and so we need a better mechanism
16187 // to identify it thorugh it's parent scopes. Build a list of parent scope back to the
16188 // global scope and then traverse the list backwards to identify each scope in the target
16189 // AST's global scope until we each the associated declaration in the target AST.
16190#if 0
16191 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");
16192 printf (" --- Looking for target AST match for class name = %s \n",classDeclaration->get_name().str());
16193#endif
16194 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
16195 ROSE_ASSERT(symbol != NULL);
16196
16197 classSymbolInTargetAST = isSgClassSymbol(symbol);
16198 }
16199
16200 ROSE_ASSERT(classSymbolInTargetAST != NULL);
16201 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
16202 ROSE_ASSERT(target_classDeclaration != NULL);
16203#if 0
16204 printf ("snippet: classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
16205 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
16206#endif
16207 ROSE_ASSERT(classDeclaration->get_name() == target_classDeclaration->get_name());
16208
16209 returnType = classSymbolInTargetAST->get_type();
16210 }
16211 break;
16212 }
16213
16214 case V_SgTypedefType:
16215 {
16216 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
16217 if (typedefDeclaration != NULL)
16218 {
16219 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(typedefDeclaration->get_name(),targetScope);
16220
16221 // Not clear if we have to handle a more general case here.
16222 // ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16223 // returnType = typedefSymbolInTargetAST->get_type();
16224 if (typedefSymbolInTargetAST == NULL)
16225 {
16226#if 0
16227 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");
16228 printf (" --- The target AST must have a valid typedef type (and associated declaration) to support resetting the SgTypedefType: %p \n",typedefDeclaration->get_type());
16229#endif
16230 // DQ (3/16/2014): Find the associated typedef declaration (from the target AST)
16231 // for the input type associated with its declaration in the snippet AST.
16232 SgSymbol* symbol = findAssociatedSymbolInTargetAST(typedefDeclaration,targetScope);
16233 ROSE_ASSERT(symbol != NULL);
16234
16235 typedefSymbolInTargetAST = isSgTypedefSymbol(symbol);
16236
16237 // Note that test5d demonstrates this problem.
16238 // ROSE_ASSERT(false);
16239 }
16240
16241 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16242 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
16243 ROSE_ASSERT(target_typedefDeclaration != NULL);
16244#if 0
16245 printf ("snippet: typedefDeclaration = %p = %s \n",typedefDeclaration,typedefDeclaration->get_name().str());
16246 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
16247#endif
16248 ROSE_ASSERT(typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
16249
16250 returnType = typedefSymbolInTargetAST->get_type();
16251 }
16252 break;
16253 }
16254
16255 case V_SgEnumType:
16256 {
16257 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(snippet_declaration);
16258 if (enumDeclaration != NULL)
16259 {
16260 ROSE_ASSERT(enumDeclaration->get_name().is_null() == false);
16261 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(enumDeclaration->get_name(),targetScope);
16262
16263 // Not clear if we have to handle a more general case here.
16264 // ROSE_ASSERT(enumSymbolInTargetAST != NULL);
16265 // returnType = enumSymbolInTargetAST->get_type();
16266 if (enumSymbolInTargetAST == NULL)
16267 {
16268 printf ("Error: It is an error to not have a enum type defined in the target AST! \n");
16269 printf (" --- The target AST must have a valid enum type (and associated declaration) to support resetting the SgEnumType: %p \n",enumDeclaration->get_type());
16270
16271 // We will allow this to pass for now, since it is a violation of the target AST, and not the snippet mechanism (I think).
16272 returnType = snippet_type;
16273
16274 // Note that test5d demonstrates this problem.
16275 // ROSE_ASSERT(false);
16276 }
16277 else
16278 {
16279 returnType = enumSymbolInTargetAST->get_type();
16280 }
16281 }
16282
16283 break;
16284 }
16285
16286 case V_SgJavaParameterizedType:
16287 {
16288 // DQ (3/10/2014): This type is a view of a generic class with dynamic type checking (e.g. T).
16289 // This acts more like a class with reference to the template instead of the template instantiation.
16290 // So reset the declaration.
16291#if 0
16292 printf ("In getTargetFileTypeSupport(): case V_SgJavaParameterizedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16293#endif
16294#if 1
16295 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
16296 if (classDeclaration != NULL)
16297 {
16298#if 0
16299 printf ("Looking for classDeclaration = %s \n",classDeclaration->get_name().str());
16300#endif
16301 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
16302 ROSE_ASSERT(javaParameterizedType != NULL);
16303#if 0
16304 // SgTemplateParameterPtrList* templateParameterList = javaParameterizedType->get_type_list();
16305 SgTemplateParameterList* templateParameterListNode = javaParameterizedType->get_type_list();
16306 ROSE_ASSERT(templateParameterListNode != NULL);
16307 SgTemplateParameterPtrList* templateParameterList = &templateParameterListNode->get_args();
16308#else
16309 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
16310 // SgTemplateParameterPtrList* templateParameterList = NULL;
16311#endif
16312 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
16313 // SgTemplateArgumentPtrList* templateSpecializationArgumentList = NULL;
16314#if 0
16315 printf ("Calling lookupTemplateClassSymbolInParentScopes() name = %s \n",classDeclaration->get_name().str());
16316#endif
16317 // SgTemplateClassSymbol* templateClassSymbolInTargetAST = lookupTemplateClassSymbolInParentScopes(classDeclaration->get_name(),templateParameterList,templateSpecializationArgumentList,targetScope);
16318 SgClassSymbol* templateClassSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
16319#if 0
16320 printf ("DONE: Calling lookupTemplateClassSymbolInParentScopes() \n");
16321#endif
16322#if 0
16323 printf ("targetScope->get_symbol_table()->size() = %d \n",targetScope->get_symbol_table()->size());
16324 if (templateClassSymbolInTargetAST == NULL)
16325 {
16326 targetScope->get_symbol_table()->print("ERROR: templateClassSymbolInTargetAST == NULL");
16327 }
16328#endif
16329 // DQ (3/30/2014): Add this approach.
16330 if (templateClassSymbolInTargetAST == NULL)
16331 {
16332#if 0
16333 printf ("Calling findAssociatedSymbolInTargetAST \n");
16334#endif
16335 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
16336 ROSE_ASSERT(symbol != NULL);
16337
16338 templateClassSymbolInTargetAST = isSgClassSymbol(symbol);
16339
16340 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
16341 }
16342
16343 // Not clear if we have to handle a more general case here.
16344 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
16345
16346 returnType = templateClassSymbolInTargetAST->get_type();
16347 }
16348#else
16349 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
16350 if (javaParameterizedType != NULL)
16351 {
16352#error "DEAD CODE!"
16353 // Not clear how to lookup this type in the target AST.
16354 returnType = javaParameterizedType;
16355
16356 SgType* internal_type = javaParameterizedType->get_raw_type();
16357 ROSE_ASSERT(internal_type != NULL);
16358 }
16359#endif
16360#if 0
16361 printf ("SgJavaParameterizedType not yet tested! \n");
16362 ROSE_ABORT();
16363#endif
16364 break;
16365 }
16366
16367 case V_SgJavaQualifiedType:
16368 {
16369 // DQ (3/10/2014): This type acts like a binary operator on types to define aggregate
16370 // types to represent what in C++ would be name qualification. I need only set the
16371 // declarations in each SgJavaQualifiedType to refer to a declaration in the target AST.
16372 // So reset the declaration.
16373
16374 // This case is demonstrated by test code:
16375 // SS_JAVA_CWES/src/Error_Handling/CWE_248/CWE_248_0.java,Error_Handling.CWE_248.CWE_248_0.cwe_248_0
16376 // printf ("***** SgJavaQualifiedType not yet tested! *** \n");
16377
16378 printf ("In getTargetFileTypeSupport(): case V_SgJavaQualifiedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16379
16380 SgJavaQualifiedType* javaQualifiedType = isSgJavaQualifiedType(namedType);
16381 if (javaQualifiedType != NULL)
16382 {
16383 // Not clear how to lookup this type in the target AST.
16384 returnType = javaQualifiedType;
16385
16386 SgType* internal_type_1 = javaQualifiedType->get_parent_type();
16387 ROSE_ASSERT(internal_type_1 != NULL);
16388 SgType* internal_type_2 = javaQualifiedType->get_type();
16389 ROSE_ASSERT(internal_type_2 != NULL);
16390 }
16391
16392 printf ("Case of SgJavaQualifiedType: not yet handled: commented out assertion! \n");
16393 // ROSE_ASSERT(false);
16394 break;
16395 }
16396
16397 case V_SgJavaWildcardType:
16398 {
16399 // DQ (3/10/2014): This type expressed constraints on an input type.
16400 // if (?) then it is associated with the Java object type.
16401 // It can be constraint with an upper bound or lower bound.
16402 // if (?extends List) would be an upper bound for List.
16403 // if (?super Integer) would be an lower bound for List.
16404 // So reset the declaration.
16405
16406 printf ("In getTargetFileTypeSupport(): case V_SgJavaWildcardType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16407
16408 SgJavaWildcardType* javaWildcardType = isSgJavaWildcardType(namedType);
16409 if (javaWildcardType != NULL)
16410 {
16411 // Not clear how to lookup this type in the target AST.
16412 returnType = javaWildcardType;
16413 }
16414
16415 printf ("SgJavaWildcardType not yet tested! \n");
16416 ROSE_ABORT();
16417 }
16418
16419 default:
16420 {
16421 printf ("Error: In getTargetFileTypeSupport(): default reached in switch: namedType = %p = %s \n",namedType,namedType->class_name().c_str());
16422 ROSE_ABORT();
16423 }
16424 }
16425
16426 ROSE_ASSERT(returnType != NULL);
16427#if 0
16428 printf ("Exiting as a test! \n");
16429 ROSE_ABORT();
16430#endif
16431 }
16432 else
16433 {
16434 // Non-named types are shared, so we need not reset them.
16435
16436 // If this was not a named type then return NULL (which is checked at the
16437 // calling point, so that the type will not be reset).
16438 }
16439
16440 return returnType;
16441 }
16442
16443
16444SgType*
16446 {
16447 SgType* returnType = NULL;
16448
16449 ROSE_ASSERT(snippet_type != NULL);
16450 ROSE_ASSERT(targetScope != NULL);
16451
16452 // DQ (3/17/2014): Refactored code.
16453 // See if the type might be asociated with the snippet file.
16454 SgType* type_copy = snippet_type;
16455
16456#if 0
16457 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
16458#endif
16459
16460 // We need to be able to reproduce the pointer types to class types, etc.
16461 Rose_STL_Container<SgType*> typeList = type_copy->getInternalTypes();
16462
16463#if 0
16464 for (size_t i = 0; i < typeList.size(); i++)
16465 {
16466 printf ("Input type: typeList[i=%" PRIuPTR "] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
16467 }
16468#endif
16469
16470#if 1
16471 // This is the unwrapped version of the getTargetFileType() function.
16472 returnType = getTargetFileTypeSupport(snippet_type,targetScope);
16473#else
16474 SgNamedType* namedType = isSgNamedType(snippet_type);
16475
16476#error "DEAD CODE!"
16477
16478 if (namedType != NULL)
16479 {
16480 // Find the associated declaration and it's corresponding declaration in the target AST.
16481 SgDeclarationStatement* snippet_declaration = namedType->get_declaration();
16482 ROSE_ASSERT(snippet_declaration != NULL);
16483#if 0
16484 printf ("Need to find the declaration in the target AST that is associated with the snippet_declaration in the snippet AST \n");
16485 printf (" --- snippet_declaration = %p = %s = %s \n",snippet_declaration,snippet_declaration->class_name().c_str(),SageInterface::get_name(snippet_declaration).c_str());
16486#endif
16487 // There are only a few cases here!
16488 switch (namedType->variantT())
16489 {
16490 case V_SgClassType:
16491 {
16492 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
16493 if (classDeclaration != NULL)
16494 {
16495 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
16496 if (classSymbolInTargetAST == NULL)
16497 {
16498 // For Java or C++ this could be a name qualified type and so we need a better mechanism
16499 // to identify it thorugh it's parent scopes. Build a list of parent scope back to the
16500 // global scope and then traverse the list backwards to identify each scope in the target
16501 // AST's global scope until we each the associated declaration in the target AST.
16502#if 0
16503 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");
16504 printf (" --- Looking for target AST match for class name = %s \n",classDeclaration->get_name().str());
16505#endif
16506 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
16507 ROSE_ASSERT(symbol != NULL);
16508
16509 classSymbolInTargetAST = isSgClassSymbol(symbol);
16510 }
16511
16512 ROSE_ASSERT(classSymbolInTargetAST != NULL);
16513 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
16514 ROSE_ASSERT(target_classDeclaration != NULL);
16515#if 0
16516 printf ("snippet: classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
16517 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
16518#endif
16519 ROSE_ASSERT(classDeclaration->get_name() == target_classDeclaration->get_name());
16520
16521 returnType = classSymbolInTargetAST->get_type();
16522 }
16523 break;
16524 }
16525
16526 case V_SgTypedefType:
16527 {
16528 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
16529 if (typedefDeclaration != NULL)
16530 {
16531 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(typedefDeclaration->get_name(),targetScope);
16532
16533 // Not clear if we have to handle a more general case here.
16534 // ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16535 // returnType = typedefSymbolInTargetAST->get_type();
16536 if (typedefSymbolInTargetAST == NULL)
16537 {
16538#if 0
16539 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");
16540 printf (" --- The target AST must have a valid typedef type (and associated declaration) to support resetting the SgTypedefType: %p \n",typedefDeclaration->get_type());
16541#endif
16542 // DQ (3/16/2014): Find the associated typedef declaration (from the target AST)
16543 // for the input type associated with its declaration in the snippet AST.
16544 SgSymbol* symbol = findAssociatedSymbolInTargetAST(typedefDeclaration,targetScope);
16545 ROSE_ASSERT(symbol != NULL);
16546
16547 typedefSymbolInTargetAST = isSgTypedefSymbol(symbol);
16548
16549 // Note that test5d demonstrates this problem.
16550 // ROSE_ASSERT(false);
16551 }
16552
16553 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16554 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
16555 ROSE_ASSERT(target_typedefDeclaration != NULL);
16556#if 0
16557 printf ("snippet: typedefDeclaration = %p = %s \n",typedefDeclaration,typedefDeclaration->get_name().str());
16558 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
16559#endif
16560 ROSE_ASSERT(typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
16561
16562 returnType = typedefSymbolInTargetAST->get_type();
16563 }
16564 break;
16565 }
16566
16567 case V_SgEnumType:
16568 {
16569 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(snippet_declaration);
16570 if (enumDeclaration != NULL)
16571 {
16572 ROSE_ASSERT(enumDeclaration->get_name().is_null() == false);
16573 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(enumDeclaration->get_name(),targetScope);
16574
16575 // Not clear if we have to handle a more general case here.
16576 // ROSE_ASSERT(enumSymbolInTargetAST != NULL);
16577 // returnType = enumSymbolInTargetAST->get_type();
16578 if (enumSymbolInTargetAST == NULL)
16579 {
16580 printf ("Error: It is an error to not have a enum type defined in the target AST! \n");
16581 printf (" --- The target AST must have a valid enum type (and associated declaration) to support resetting the SgEnumType: %p \n",enumDeclaration->get_type());
16582
16583 // We will allow this to pass for now, since it is a violation of the target AST, and not the snippet mechanism (I think).
16584 returnType = snippet_type;
16585
16586 // Note that test5d demonstrates this problem.
16587 // ROSE_ASSERT(false);
16588 }
16589 else
16590 {
16591 returnType = enumSymbolInTargetAST->get_type();
16592 }
16593 }
16594
16595 break;
16596 }
16597
16598 case V_SgJavaParameterizedType:
16599 {
16600 // DQ (3/10/2014): This type is a view of a generic class with dynamic type checking (e.g. T).
16601 // This acts more like a class with reference to the template instead of the template instantiation.
16602 // So reset the declaration.
16603
16604 printf ("In getTargetFileType(): case V_SgJavaParameterizedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16605#if 1
16606 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
16607 if (classDeclaration != NULL)
16608 {
16609 SgTemplateParameterPtrList* templateParameterList = NULL;
16610 SgTemplateArgumentPtrList* templateSpecializationArgumentList = NULL;
16611 SgTemplateClassSymbol* templateClassSymbolInTargetAST = lookupTemplateClassSymbolInParentScopes(classDeclaration->get_name(),templateParameterList,templateSpecializationArgumentList,targetScope);
16612
16613 // Not clear if we have to handle a more general case here.
16614 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
16615
16616 returnType = templateClassSymbolInTargetAST->get_type();
16617 }
16618#else
16619 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
16620 if (javaParameterizedType != NULL)
16621 {
16622 // Not clear how to lookup this type in the target AST.
16623 returnType = javaParameterizedType;
16624
16625 SgType* internal_type = javaParameterizedType->get_raw_type();
16626 ROSE_ASSERT(internal_type != NULL);
16627 }
16628#endif
16629 printf ("SgJavaParameterizedType not yet tested! \n");
16630 ROSE_ABORT();
16631 }
16632
16633 case V_SgJavaQualifiedType:
16634 {
16635 // DQ (3/10/2014): This type acts like a binary operator on types to define aggregate
16636 // types to represent what in C++ would be name qualification. I need only set the
16637 // declarations in each SgJavaQualifiedType to refer to a declaration in the target AST.
16638 // So reset the declaration.
16639
16640 printf ("In getTargetFileType(): case V_SgJavaQualifiedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16641
16642 SgJavaQualifiedType* javaQualifiedType = isSgJavaQualifiedType(namedType);
16643 if (javaQualifiedType != NULL)
16644 {
16645 // Not clear how to lookup this type in the target AST.
16646 returnType = javaQualifiedType;
16647
16648 SgType* internal_type_1 = javaQualifiedType->get_parent_type();
16649 ROSE_ASSERT(internal_type_1 != NULL);
16650 SgType* internal_type_2 = javaQualifiedType->get_type();
16651 ROSE_ASSERT(internal_type_2 != NULL);
16652 }
16653
16654 printf ("SgJavaQualifiedType not yet tested! \n");
16655 ROSE_ABORT();
16656 }
16657
16658 case V_SgJavaWildcardType:
16659 {
16660 // DQ (3/10/2014): This type expressed constraints on an input type.
16661 // if (?) then it is associated with the Java object type.
16662 // It can be constraint with an upper bound or lower bound.
16663 // if (?extends List) would be an upper bound for List.
16664 // if (?super Integer) would be an lower bound for List.
16665 // So reset the declaration.
16666
16667 printf ("In getTargetFileType(): case V_SgJavaWildcardType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16668
16669 SgJavaWildcardType* javaWildcardType = isSgJavaWildcardType(namedType);
16670 if (javaWildcardType != NULL)
16671 {
16672 // Not clear how to lookup this type in the target AST.
16673 returnType = javaWildcardType;
16674
16675 SgType* internal_type_1 = javaWildcardType->get_bound_type();
16676 // ROSE_ASSERT(internal_type_1 != NULL); // PC: 03/15/2014 - Dan, this cannot be asserted as the bound_type CAN BE NULL.
16677 }
16678
16679 printf ("SgJavaWildcardType not yet tested! \n");
16680 ROSE_ABORT();
16681 }
16682
16683 default:
16684 {
16685 printf ("Error: In getTargetFileType(): default reached in switch: namedType = %p = %s \n",namedType,namedType->class_name().c_str());
16686 ROSE_ABORT();
16687 }
16688 }
16689
16690 ROSE_ASSERT(returnType != NULL);
16691#if 0
16692 printf ("Exiting as a test! \n");
16693 ROSE_ABORT();
16694#endif
16695 }
16696 else
16697 {
16698 // Non-named types are shared, so we need not reset them.
16699
16700 // If this was not a named type then return NULL (which is checked at the
16701 // calling point, so that the type will not be reset).
16702 }
16703#endif
16704
16705 SgType* new_type = returnType;
16706
16707 // DQ (3/17/2014): Refactored code.
16708 // Now rebuild the type_copy as required to represent associated modifiers, typedef wrappers, pointers and references.
16709 if (new_type != NULL && typeList.size() > 1)
16710 {
16711 int size = (int)typeList.size();
16712 for (int i = size - 2; i >= 0; i--)
16713 {
16714#if 0
16715 printf ("Rebuild type: typeList[i=%d] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
16716#endif
16717 // SgModifierType* SgModifierType::createType(SgType* base_type, unsigned int f, SgExpression* optional_fortran_type_kind )
16718 switch(typeList[i]->variantT())
16719 {
16720 case V_SgModifierType:
16721 {
16722 SgModifierType* modifierType = isSgModifierType(typeList[i]);
16723 ROSE_ASSERT(modifierType != NULL);
16724 if (modifierType->get_typeModifier().get_constVolatileModifier().isConst() == true)
16725 {
16726 ROSE_ASSERT(new_type != NULL);
16727#if 0
16728 printf ("Building a SgModifierType: calling buildConstType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16729#endif
16730 new_type = buildConstType(new_type);
16731 }
16732 else
16733 {
16734 // Flag any additional modifiers that we might require (make anything not supported an error).
16735 printf ("Modifier kind not handled (not implemented) check what sort of modifier this is: \n");
16736 modifierType->get_typeModifier().display("Modifier kind not handled");
16737 ROSE_ABORT();
16738 }
16739 break;
16740 }
16741
16742 case V_SgTypedefType:
16743 {
16744 SgTypedefType* typedefType = isSgTypedefType(typeList[i]);
16745 ROSE_ASSERT(typedefType != NULL);
16746
16747 // DQ (3/17/2014): Call the associated support function instead.
16748 // SgType* SageBuilder::getTargetFileType(SgType* snippet_type, SgScopeStatement* targetScope)
16749 // SgType* new_typedefType = getTargetFileType(typedefType,targetScope);
16750 SgType* new_typedefType = getTargetFileTypeSupport(typedefType,targetScope);
16751 ROSE_ASSERT(new_typedefType != NULL);
16752 ROSE_ASSERT(isSgTypedefType(new_typedefType) != NULL);
16753
16754 new_type = new_typedefType;
16755#if 0
16756 printf ("ERROSE: SgTypedefType kind not handled (not implemented) \n");
16757 ROSE_ABORT();
16758#endif
16759 break;
16760 }
16761
16762 case V_SgPointerType:
16763 {
16764 SgPointerType* pointerType = isSgPointerType(typeList[i]);
16765 ROSE_ASSERT(pointerType != NULL);
16766#if 0
16767 printf ("Building a SgPointerType: calling buildPointerType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16768#endif
16769 ROSE_ASSERT(new_type != NULL);
16770 new_type = buildPointerType(new_type);
16771#if 0
16772 printf ("ERROSE: SgPointerType kind not handled (not implemented) \n");
16773 ROSE_ABORT();
16774#endif
16775 break;
16776 }
16777
16778 default:
16779 {
16780 printf ("Error: default reached in evaluation of typelist: typeList[i] = %p = %s \n",typeList[i],typeList[i]->class_name().c_str());
16781 ROSE_ABORT();
16782 }
16783 }
16784 }
16785
16786 returnType = new_type;
16787 }
16788
16789#if 0
16790 if (typeList.size() > 1)
16791 {
16792 printf ("Exiting as a test! \n");
16793 ROSE_ABORT();
16794 }
16795#endif
16796
16797
16798 return returnType;
16799 }
16800
16801
16802
16803void
16804SageBuilder::errorCheckingTargetAST (SgNode* node_copy, SgNode* node_original, SgFile* targetFile, bool failOnWarning )
16805 {
16806#if 0
16807 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());
16808#endif
16809
16810 // Handle what is the same about all statements before getting to the switch.
16811 SgStatement* statement_copy = isSgStatement(node_copy);
16812 SgStatement* statement_original = isSgStatement(node_original);
16813 if (statement_copy != NULL)
16814 {
16815 // Check the scope if it is stored explicitly.
16816 if (statement_copy->hasExplicitScope() == true)
16817 {
16818 // Handle the scope for all statements.
16819 SgScopeStatement* scope_copy = statement_copy->get_scope();
16820 ROSE_ASSERT(statement_original != NULL);
16821 SgScopeStatement* scope_original = statement_original->get_scope();
16822 ROSE_ASSERT(scope_copy != NULL);
16823 ROSE_ASSERT(scope_original != NULL);
16824
16825 // if (TransformationSupport::getFile(scope_original) != targetFile)
16826 // if (getEnclosingFileNode(scope_original) != targetFile)
16827 if (getEnclosingFileNode(scope_copy) != targetFile)
16828 {
16829#if 0
16830 printf ("Warning: SgStatement: scope = %p = %s \n",scope_original,scope_original->class_name().c_str());
16831#endif
16832 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
16833 // SgFile* snippetFile = getEnclosingFileNode(scope_original);
16834 SgFile* snippetFile = getEnclosingFileNode(scope_copy);
16835 ROSE_ASSERT(snippetFile != NULL);
16836 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16837#if 1
16838 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16839 // ROSE_ASSERT(false);
16840#endif
16841 if (failOnWarning == true)
16842 {
16843 printf ("Exit on warning! \n");
16844 ROSE_ABORT();
16845 }
16846 }
16847#if 0
16848 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
16849 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
16850
16851 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
16852 // ROSE_ASSERT(targetScope != NULL);
16853
16854 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16855 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16856 // SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol->get_name(),targetScope);
16857 // ROSE_ASSERT(variableSymbolInTargetAST != NULL);
16858
16859 // Unless we know that this is a declaration we can't set the scope here using the information about this being a definng declaration.
16860 // If this is a defining declaration then we want to set it's scope to targetScope, else we want to lookup
16861 // the symbol through the parent scope and set the scope using the symbol's first non-defining declaration.
16862 // statement_copy->set_scope(targetScope);
16863
16864 // SgSymbol* symbol = statement_copy->search_for_symbol_from_symbol_table();
16865 // ROSE_ASSERT(symbol != NULL);
16866#endif
16867#if 0
16868 printf ("SgClassDeclaration: Exiting as a test! \n");
16869 ROSE_ABORT();
16870#endif
16871#if 0
16872 if (TransformationSupport::getFile(scope) != targetFile)
16873 {
16874 printf ("Warning: SgStatement: scope = %p = %s \n",scope,scope->class_name().c_str());
16875 SgFile* snippetFile = TransformationSupport::getFile(scope);
16876 ROSE_ASSERT(snippetFile != NULL);
16877 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16878
16879 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16880 // ROSE_ASSERT(false);
16881 }
16882#endif
16883 }
16884 }
16885
16886 // Handle what is the same about all declaration before getting to the switch.
16887 SgDeclarationStatement* declarationStatement_copy = isSgDeclarationStatement(node_copy);
16888 SgDeclarationStatement* declarationStatement_original = isSgDeclarationStatement(node_original);
16889 if (declarationStatement_copy != NULL)
16890 {
16891 // Check the firstnondefiningDeclaration and definingDeclaration
16892 SgDeclarationStatement* firstNondefiningDeclaration_copy = declarationStatement_copy->get_firstNondefiningDeclaration();
16893 SgDeclarationStatement* firstNondefiningDeclaration_original = declarationStatement_original->get_firstNondefiningDeclaration();
16894
16895 // DQ (3/17/2014): Bugfix, we want to use the firstNondefiningDeclaration_copy instead of firstNondefiningDeclaration_original.
16896 // DQ (3/10/2014): We want to allow for NULL return values from getEnclosingFileNode() for Java classes that are in java.lang (for example).
16897 // SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_original);
16898 SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_copy);
16899 if (snippetFile != NULL && snippetFile != targetFile)
16900 {
16901 // I think we want to allow this because it is a common occurence in any merged AST.
16902 // However, if might be worth fixing for other reasons. This needs to be discussed.
16903#if 0
16904 printf ("Note: SgDeclarationStatement: firstNondefiningDeclaration_original is not in target file (allowed for merged ASTs) \n");
16905#endif
16906 // ROSE_ASSERT(false);
16907 if (failOnWarning == true)
16908 {
16909 printf ("Exit on warning! \n");
16910 ROSE_ABORT();
16911 }
16912 }
16913 else
16914 {
16915 // Warn about this if snippetFile == NULL.
16916 if (snippetFile == NULL)
16917 {
16918 printf ("Note: firstNondefiningDeclaration_original = %p getEnclosingFileNode() returned NULL \n",firstNondefiningDeclaration_original);
16919
16920 if (failOnWarning == true)
16921 {
16922 printf ("Exit on warning! \n");
16923 ROSE_ABORT();
16924 }
16925 }
16926 }
16927
16928 SgDeclarationStatement* definingDeclaration_copy = declarationStatement_copy->get_definingDeclaration();
16929 SgDeclarationStatement* definingDeclaration_original = declarationStatement_original->get_definingDeclaration();
16930 if (definingDeclaration_original != NULL)
16931 {
16932 // DQ (3/17/2014): Bugfix, we want to use the definingDeclaration_copy instead of definingDeclaration_original.
16933 // if (TransformationSupport::getFile(definingDeclaration_original) != targetFile)
16934 // if (getEnclosingFileNode(definingDeclaration_original) != targetFile)
16935 // SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_original);
16936 SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_copy);
16937 if (snippetFile != NULL && snippetFile != targetFile)
16938 {
16939#if 1
16940 printf ("Warning: SgDeclarationStatement: definingDeclaration is not in target file \n");
16941 // ROSE_ASSERT(false);
16942#endif
16943 if (failOnWarning == true)
16944 {
16945 printf ("Exit on warning! \n");
16946 ROSE_ABORT();
16947 }
16948
16949 if (declarationStatement_original == definingDeclaration_original)
16950 {
16951 // This is a defining declaration, so we can set the scope (or can we?)
16952 // I guess we could if the translation map were complete, but it is not complete yet.
16953 }
16954 }
16955 else
16956 {
16957 // Warn about this if snippetFile == NULL.
16958 if (snippetFile == NULL)
16959 {
16960 printf ("Note: definingDeclaration_original = %p getEnclosingFileNode() returned NULL \n",definingDeclaration_original);
16961
16962 if (failOnWarning == true)
16963 {
16964 printf ("Exit on warning! \n");
16965 ROSE_ABORT();
16966 }
16967 }
16968 }
16969 }
16970 }
16971
16972 // Handle what is the same about all expressions before getting to the switch.
16973 SgExpression* expression = isSgExpression(node_copy);
16974 if (expression != NULL)
16975 {
16976 // Check the scope if it is stored explicitly.
16977
16978 // printf ("WARNING: Need to check if the type is explicitly stored in this expression! \n");
16979
16980 if (expression->hasExplicitType() == true)
16981 {
16982 // Handle the type for all expressions.
16983 SgType* type = expression->get_type();
16984 ROSE_ASSERT(type != NULL);
16985 }
16986 }
16987
16988#if 0
16989 printf ("Leaving errorCheckingTargetAST() \n");
16990#endif
16991 }
16992
16993
16994template <class T>
16995void
16996SageBuilder::resetDeclaration(T* classDeclaration_copy, T* classDeclaration_original, SgScopeStatement* targetScope)
16997 {
16998 // I'm not sure if this function is a good idea since we can't call set_scope() easily from any
16999 // SgDeclarationStatement and I don't want to make set_scope() a virtual function because it would
17000 // not make sense everywhere.
17001
17002 // DQ (3/17/2014): This code is similar to the case for SgEnumDeclaration (later we can refactor this if this works well).
17003 T* classDeclaration_copy_defining = dynamic_cast<T*>(classDeclaration_copy->get_definingDeclaration());
17004 T* classDeclaration_copy_nondefining = dynamic_cast<T*>(classDeclaration_copy->get_firstNondefiningDeclaration());
17005 T* classDeclaration_original_defining = dynamic_cast<T*>(classDeclaration_original->get_definingDeclaration());
17006 T* classDeclaration_original_nondefining = dynamic_cast<T*>(classDeclaration_original->get_firstNondefiningDeclaration());
17007
17008 // Set the scope if it is still set to the scope of the snippet AST.
17009 if (classDeclaration_copy_defining != NULL && classDeclaration_copy_defining->get_scope() == classDeclaration_original_defining->get_scope())
17010 {
17011#if 0
17012 printf ("reset the scope of classDeclaration_copy_defining \n");
17013#endif
17014 classDeclaration_copy_defining->set_scope(targetScope);
17015 }
17016
17017 // Set the scope if it is still set to the scope of the snippet AST.
17018 if (classDeclaration_copy_nondefining != NULL && classDeclaration_copy_nondefining->get_scope() == classDeclaration_original_nondefining->get_scope())
17019 {
17020#if 0
17021 printf ("reset the scope of classDeclaration_copy_nondefining \n");
17022#endif
17023 classDeclaration_copy_nondefining->set_scope(targetScope);
17024 }
17025
17026 // Set the parent if it is still set to a node of the snippet AST.
17027 if (classDeclaration_copy_nondefining != NULL && classDeclaration_copy_nondefining->get_parent() == classDeclaration_original_nondefining->get_parent())
17028 {
17029#if 0
17030 printf ("reset the parent of classDeclaration_copy_nondefining \n");
17031#endif
17032 classDeclaration_copy_nondefining->set_parent(classDeclaration_copy->get_parent());
17033 }
17034 }
17035
17036
17037void
17039 SgNode* node_copy, SgNode* node_original)
17040 {
17041 // This function fixes up invidual IR nodes to be consistant in the context of the target AST
17042 // where the node is inserted and at the point specified by insertionPoint. In this function,
17043 // node_copy is the copy that was made of node_original by the AST copy function. The node_original
17044 // is assumed to be the node that is in the AST snippet (it is still connected in the snippet's
17045 // AST (from compilation of the snippet file).
17046
17047 // This function hides the details of handling each different type of IR node.
17048 // It is assume that the node_copy is from an AST sub-tree generated by the AST copy mechanism,
17049 // and that the insertionPoint is a location in the target AST where the snippet AST has already
17050 // been inserted, this function makes each IR node internally consistant with the target AST.
17051
17052 // BTW, the translationMap should only be required to support references to things that are name
17053 // qualified (which are C++ specific). These are a performance option to simplify tacking back
17054 // through scopes with code similarly complex as to what is supported in the name qualification
17055 // support.
17056#if 0
17057 printf ("In fixupCopyOfNodeFromSeperateFileInNewTargetAst: node_copy = %p = %s \n",node_copy,node_copy->class_name().c_str());
17058#endif
17059
17060#if 0
17061 printf ("Disabled fixupCopyOfNodeFromSeperateFileInNewTargetAst() \n");
17062 return;
17063#endif
17064
17065 // SgFile* targetFile = TransformationSupport::getFile(insertionPoint);
17066 SgFile* targetFile = getEnclosingFileNode(insertionPoint);
17067
17068#if 0
17069 printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
17070 printf (" --- insertionPointIsScope = %s \n",insertionPointIsScope ? "true" : "false");
17071#endif
17072
17073 // DQ (3/4/2014): As I recall there is a reason why we can't setup the scope here.
17074
17075 // We also need to handle the symbol (move it from the body (SgBaicBlock) that was
17076 // a copy to the scope in the target AST where the SgInitializedName was inserted).
17077 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17078#if 0
17079 printf ("insertionPointScope = %p = %s \n",insertionPointScope,insertionPointScope->class_name().c_str());
17080#endif
17081 SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17082 ROSE_ASSERT(targetScope != NULL);
17083
17084#if 1
17085 // Refactored code (error checking done after AST fixup).
17086#if 0
17087 errorCheckingTargetAST(node_copy,node_original,targetFile, false);
17088#endif
17089#else
17090
17091#error "DEAD CODE!"
17092
17093 // Handle what is the same about all statements before getting to the switch.
17094 SgStatement* statement_copy = isSgStatement(node_copy);
17095 SgStatement* statement_original = isSgStatement(node_original);
17096 if (statement_copy != NULL)
17097 {
17098 // Check the scope if it is stored explicitly.
17099 if (statement_copy->hasExplicitScope() == true)
17100 {
17101 // Handle the scope for all statements.
17102 SgScopeStatement* scope_copy = statement_copy->get_scope();
17103 SgScopeStatement* scope_original = statement_original->get_scope();
17104 ROSE_ASSERT(scope_copy != NULL);
17105 ROSE_ASSERT(scope_original != NULL);
17106
17107 // if (TransformationSupport::getFile(scope_original) != targetFile)
17108 if (getEnclosingFileNode(scope_original) != targetFile)
17109 {
17110#if 0
17111 printf ("Warning: SgStatement: scope = %p = %s \n",scope_original,scope_original->class_name().c_str());
17112#endif
17113 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
17114 SgFile* snippetFile = getEnclosingFileNode(scope_original);
17115 ROSE_ASSERT(snippetFile != NULL);
17116 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
17117#if 0
17118 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
17119 // ROSE_ASSERT(false);
17120#endif
17121 }
17122#if 0
17123 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17124 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
17125
17126 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17127 // ROSE_ASSERT(targetScope != NULL);
17128
17129 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
17130 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
17131 // SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol->get_name(),targetScope);
17132 // ROSE_ASSERT(variableSymbolInTargetAST != NULL);
17133
17134 // Unless we know that this is a declaration we can't set the scope here using the information about this being a definng declaration.
17135 // If this is a defining declaration then we want to set it's scope to targetScope, else we want to lookup
17136 // the symbol through the parent scope and set the scope using the symbol's first non-defining declaration.
17137 // statement_copy->set_scope(targetScope);
17138
17139 // SgSymbol* symbol = statement_copy->search_for_symbol_from_symbol_table();
17140 // ROSE_ASSERT(symbol != NULL);
17141#endif
17142#if 0
17143 printf ("SgClassDeclaration: Exiting as a test! \n");
17144 ROSE_ABORT();
17145#endif
17146#if 0
17147 if (TransformationSupport::getFile(scope) != targetFile)
17148 {
17149 printf ("Warning: SgStatement: scope = %p = %s \n",scope,scope->class_name().c_str());
17150 SgFile* snippetFile = TransformationSupport::getFile(scope);
17151 ROSE_ASSERT(snippetFile != NULL);
17152 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
17153
17154 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
17155 // ROSE_ASSERT(false);
17156 }
17157#endif
17158 }
17159 }
17160
17161#error "DEAD CODE!"
17162
17163 // Handle what is the same about all declaration before getting to the switch.
17164 SgDeclarationStatement* declarationStatement_copy = isSgDeclarationStatement(node_copy);
17165 SgDeclarationStatement* declarationStatement_original = isSgDeclarationStatement(node_original);
17166 if (declarationStatement_copy != NULL)
17167 {
17168 // Check the firstnondefiningDeclaration and definingDeclaration
17169 SgDeclarationStatement* firstNondefiningDeclaration_original = declarationStatement_original->get_firstNondefiningDeclaration();
17170
17171 // DQ (3/10/2014): We want to allow for NULL return values from getEnclosingFileNode() for Java classes that are in java.lang (for example).
17172 SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_original);
17173 if (snippetFile != NULL && snippetFile != targetFile)
17174 {
17175 // I think we want to allow this because it is a common occurence in any merged AST.
17176 // However, if might be worth fixing for other reasons. This needs to be discussed.
17177#if 0
17178 printf ("Note: SgDeclarationStatement: firstNondefiningDeclaration_original is not in target file (allowed for merged ASTs) \n");
17179#endif
17180 // ROSE_ASSERT(false);
17181 }
17182 else
17183 {
17184 // Warn about this if snippetFile == NULL.
17185 if (snippetFile == NULL)
17186 {
17187 printf ("Note: firstNondefiningDeclaration_original = %p getEnclosingFileNode() returned NULL \n",firstNondefiningDeclaration_original);
17188 }
17189 }
17190
17191#error "DEAD CODE!"
17192
17193 SgDeclarationStatement* definingDeclaration_original = declarationStatement_original->get_definingDeclaration();
17194 if (definingDeclaration_original != NULL)
17195 {
17196 // if (TransformationSupport::getFile(definingDeclaration_original) != targetFile)
17197 // if (getEnclosingFileNode(definingDeclaration_original) != targetFile)
17198 SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_original);
17199 if (snippetFile != NULL && snippetFile != targetFile)
17200 {
17201#if 0
17202 printf ("Warning: SgDeclarationStatement: definingDeclaration is not in target file \n");
17203 // ROSE_ASSERT(false);
17204#endif
17205 if (declarationStatement_original == definingDeclaration_original)
17206 {
17207 // This is a defining declaration, so we can set the scope (or can we?)
17208 // I guess we could if the translation map were complete, but it is not complete yet.
17209 }
17210 }
17211 else
17212 {
17213 // Warn about this if snippetFile == NULL.
17214 if (snippetFile == NULL)
17215 {
17216 printf ("Note: definingDeclaration_original = %p getEnclosingFileNode() returned NULL \n",definingDeclaration_original);
17217 }
17218 }
17219 }
17220 }
17221
17222#error "DEAD CODE!"
17223
17224#endif
17225
17226 // Handle what is the same about all expressions before getting to the switch.
17227 SgExpression* expression = isSgExpression(node_copy);
17228 if (expression != NULL)
17229 {
17230 // Check the scope if it is stored explicitly.
17231
17232 // printf ("WARNING: Need to check if the type is explicitly stored in this expression! \n");
17233
17234 if (expression->hasExplicitType() == true)
17235 {
17236 // Handle the type for all expressions.
17237 SgType* type = expression->get_type();
17238 ROSE_ASSERT(type != NULL);
17239
17240 // DQ (3/17/2014): Avoid calling stripType with the newly refactored getTargetFileType() function.
17241 // SgType* new_type = getTargetFileType(type->stripType(),targetScope);
17242 SgType* new_type = getTargetFileType(type,targetScope);
17243 if (new_type != NULL)
17244 {
17245 // Reset the base type to be the one associated with the target file.
17246 expression->set_explicitly_stored_type(new_type);
17247 }
17248 }
17249 }
17250
17251 switch (node_copy->variantT())
17252 {
17253 case V_SgInitializedName:
17254 {
17255 SgInitializedName* initializedName_copy = isSgInitializedName(node_copy);
17256 SgInitializedName* initializedName_original = isSgInitializedName(node_original);
17257
17258 // See if the scope might be associated with the snippet file.
17259
17260 // Since we don't want the scope that is stored in the SgInitializedName we
17261 // have to get the associated statement and the scope of that statement.
17262 // SgScopeStatement* scope_copy = initializedName_copy->get_scope();
17263 SgStatement* enclosingStatement_copy = TransformationSupport::getStatement(initializedName_copy);
17264#if 0
17265 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
17266#endif
17267 SgScopeStatement* scope_copy = enclosingStatement_copy->get_scope();
17268
17269 SgScopeStatement* scope_original = initializedName_original->get_scope();
17270
17271 ROSE_ASSERT(scope_copy != NULL);
17272 ROSE_ASSERT(scope_original != NULL);
17273
17274 // if (TransformationSupport::getFile(scope_original) != targetFile)
17275 if (getEnclosingFileNode(scope_original) != targetFile)
17276 {
17277#if 0
17278 ROSE_ASSERT(initializedName_copy != NULL);
17279 printf ("initializedName_copy = %p = %s \n",initializedName_copy,initializedName_copy->get_name().str());
17280 ROSE_ASSERT(initializedName_original != NULL);
17281 printf ("initializedName_original = %p = %s \n",initializedName_original,initializedName_original->get_name().str());
17282 SgType* initializedName_original_type = initializedName_original->get_type();
17283 printf ("initializedName_original_type = %p = %s \n",initializedName_original_type,initializedName_original_type->class_name().c_str());
17284 SgClassType* classType = isSgClassType(initializedName_original_type);
17285 // ROSE_ASSERT(classType != NULL);
17286 if (classType != NULL)
17287 {
17288 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
17289 ROSE_ASSERT(classDeclaration != NULL);
17290 printf ("classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
17291 }
17292#endif
17293#if 0
17294 printf ("Warning: case V_SgInitializedName: scope_copy = %p = %s \n",scope_copy,scope_copy->class_name().c_str());
17295 printf ("Warning: case V_SgInitializedName: scope_original = %p = %s \n",scope_original,scope_original->class_name().c_str());
17296
17297 printf ("Warning: case V_SgInitializedName: initializedName_copy->get_parent() = %p \n",initializedName_copy->get_parent());
17298 printf ("Warning: case V_SgInitializedName: initializedName_original->get_parent() = %p \n",initializedName_original->get_parent());
17299#endif
17300 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
17301 SgFile* snippetFile = getEnclosingFileNode(scope_original);
17302
17303 ROSE_ASSERT(snippetFile != NULL);
17304 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
17305#if 0
17306 printf ("Warning: case V_SgInitializedName: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
17307 // ROSE_ASSERT(false);
17308#endif
17309 }
17310
17311 // See if the type might be asociated with the snippet file.
17312 SgType* type_copy = initializedName_copy->get_type();
17313#if 0
17314 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
17315#endif
17316
17317#if 0
17318
17319#error "DEAD CODE!"
17320
17321 // We need to be able to reproduce the pointer types to class types, etc.
17322 Rose_STL_Container<SgType*> typeList = type_copy->getInternalTypes();
17323#if 0
17324 for (size_t i = 0; i < typeList.size(); i++)
17325 {
17326 printf ("Input type: typeList[i=%" PRIuPTR "] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
17327 }
17328#endif
17329 // Note that the semantics of this function is that it can return a NULL pointer (e.g. for primative types).
17330 SgType* new_type = getTargetFileType(type_copy->stripType(),targetScope);
17331
17332#error "DEAD CODE!"
17333
17334 // Now rebuild the type_copy as required to represent associated modifiers, typedef wrappers, pointers and references.
17335 if (new_type != NULL && typeList.size() > 1)
17336 {
17337 int size = (int)typeList.size();
17338 for (int i = size - 2; i >= 0; i--)
17339 {
17340#if 0
17341 printf ("Rebuild type: typeList[i=%d] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
17342#endif
17343 // SgModifierType* SgModifierType::createType(SgType* base_type, unsigned int f, SgExpression* optional_fortran_type_kind )
17344 switch(typeList[i]->variantT())
17345 {
17346 case V_SgModifierType:
17347 {
17348 SgModifierType* modifierType = isSgModifierType(typeList[i]);
17349 ROSE_ASSERT(modifierType != NULL);
17350 if (modifierType->get_typeModifier().get_constVolatileModifier().isConst() == true)
17351 {
17352 ROSE_ASSERT(new_type != NULL);
17353#if 0
17354 printf ("Building a SgModifierType: calling buildConstType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
17355#endif
17356 new_type = buildConstType(new_type);
17357 }
17358 else
17359 {
17360 // Flag any additional modifiers that we might require (make anything not supported an error).
17361 printf ("Modifier kind not handled (not implemented) check what sort of modifier this is: \n");
17362 modifierType->get_typeModifier().display("Modifier kind not handled");
17363 ROSE_ABORT();
17364 }
17365 break;
17366 }
17367
17368#error "DEAD CODE!"
17369
17370 case V_SgTypedefType:
17371 {
17372 SgTypedefType* typedefType = isSgTypedefType(typeList[i]);
17373 ROSE_ASSERT(typedefType != NULL);
17374
17375 // SgType* SageBuilder::getTargetFileType(SgType* snippet_type, SgScopeStatement* targetScope)
17376 SgType* new_typedefType = getTargetFileType(typedefType,targetScope);
17377 ROSE_ASSERT(new_typedefType != NULL);
17378 ROSE_ASSERT(isSgTypedefType(new_typedefType) != NULL);
17379
17380 new_type = new_typedefType;
17381#if 0
17382 printf ("ERROSE: SgTypedefType kind not handled (not implemented) \n");
17383 ROSE_ABORT();
17384#endif
17385 break;
17386 }
17387
17388#error "DEAD CODE!"
17389
17390 case V_SgPointerType:
17391 {
17392 SgPointerType* pointerType = isSgPointerType(typeList[i]);
17393 ROSE_ASSERT(pointerType != NULL);
17394#if 0
17395 printf ("Building a SgPointerType: calling buildPointerType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
17396#endif
17397 ROSE_ASSERT(new_type != NULL);
17398 new_type = buildPointerType(new_type);
17399#if 0
17400 printf ("ERROSE: SgPointerType kind not handled (not implemented) \n");
17401 ROSE_ABORT();
17402#endif
17403 break;
17404 }
17405
17406#error "DEAD CODE!"
17407
17408 default:
17409 {
17410 printf ("Error: default reached in evaluation of typelist: typeList[i] = %p = %s \n",typeList[i],typeList[i]->class_name().c_str());
17411 ROSE_ABORT();
17412 }
17413 }
17414 }
17415 }
17416#if 0
17417 if (typeList.size() > 1)
17418 {
17419 printf ("Exiting as a test! \n");
17420 ROSE_ABORT();
17421 }
17422#endif
17423
17424#error "DEAD CODE!"
17425
17426#else
17427 // Refactored the above code to be a part of getTargetFileType() function.
17428 // Note that the semantics of this function is that it can return a NULL pointer (e.g. for primative types).
17429 // SgType* new_type = getTargetFileType(type_copy->stripType(),targetScope);
17430 SgType* new_type = getTargetFileType(type_copy,targetScope);
17431#endif
17432#if 0
17433 printf ("new_type = %p \n",new_type);
17434#endif
17435 if (new_type != NULL)
17436 {
17437 // Reset the base type to be the one associated with the target file.
17438#if 0
17439 printf ("Reset type for initializedName_copy = %p from type = %p to type = %p \n",initializedName_copy,initializedName_copy->get_type(),new_type);
17440#endif
17441 SgType* original_type = initializedName_copy->get_type();
17442 SgNamedType* original_named_type = isSgNamedType(original_type);
17443 SgNamedType* new_named_type = isSgNamedType(new_type);
17444 if (original_named_type != NULL)
17445 {
17446 ROSE_ASSERT(new_named_type != NULL);
17447 SgClassDeclaration* original_classDeclaration = isSgClassDeclaration(original_named_type->get_declaration());
17448 SgClassDeclaration* new_classDeclaration = isSgClassDeclaration(new_named_type->get_declaration());
17449 if (original_classDeclaration != NULL)
17450 {
17451 ROSE_ASSERT(new_classDeclaration != NULL);
17452#if 0
17453 printf ("original_classDeclaration = %p = %s \n",original_classDeclaration,original_classDeclaration->get_name().str());
17454 printf ("new_classDeclaration = %p = %s \n",new_classDeclaration,new_classDeclaration->get_name().str());
17455#endif
17456 // Make sure that the type names are the same.
17457 ROSE_ASSERT(new_classDeclaration->get_name() == original_classDeclaration->get_name());
17458 }
17459 }
17460#if 0
17461 SgType* old_type = initializedName_copy->get_type();
17462 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());
17463#endif
17464 initializedName_copy->set_type(new_type);
17465 }
17466#if 0
17467 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
17468#endif
17469 SgFunctionParameterList* functionParameterList = isSgFunctionParameterList(enclosingStatement_copy);
17470 if (functionParameterList != NULL)
17471 {
17472 // The use of SgInitializedName in function parametes is handled differently then in other
17473 // locations in the AST (e.g. how the scope is set).
17474 // This is a function parameter and the scope is set to the SgFunctionDefinition if
17475 // this is for a defining function and the SgGlobal if it is a function prototype.
17476 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(functionParameterList->get_parent());
17477 ROSE_ASSERT(functionDeclaration != NULL);
17478 SgFunctionDefinition* functionDefinition = functionDeclaration->get_definition();
17479 if (functionDefinition != NULL)
17480 {
17481 ROSE_ASSERT(initializedName_copy->get_scope() == functionDefinition);
17482 // initializedName_copy->set_scope(functionDefinition);
17483 }
17484 else
17485 {
17486 SgGlobal* globalScope = isSgGlobal(functionDeclaration->get_scope());
17487 ROSE_ASSERT(globalScope != NULL);
17488 if (initializedName_copy->get_scope() != globalScope)
17489 {
17490#if 0
17491 printf ("Reset scope for initializedName_copy = %p = %s \n",initializedName_copy,initializedName_copy->get_name().str());
17492#endif
17493 initializedName_copy->set_scope(globalScope);
17494 }
17495 ROSE_ASSERT(initializedName_copy->get_scope() == globalScope);
17496 }
17497 }
17498 else
17499 {
17500#if 0
17501 printf ("initializedName_copy->get_scope() = %p = %s \n",initializedName_copy->get_scope(),initializedName_copy->get_scope()->class_name().c_str());
17502#endif
17503 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(enclosingStatement_copy);
17504 if (enumDeclaration != NULL)
17505 {
17506 // The case of enum declarations is special because the associated SgInitializedName IR nodes has a scope
17507 // that is external to the SgEnumDeclaration (in the scope of the SgEnumDeclaration). The typical case in C
17508 // is that the enum declaration is in global scope and then the enum fields (represented by SgInitializedName
17509 // objects) are have their associated symbol in the global scope.
17510
17511 // We have to use the name to search for the symbol instead of the pointer value of the initializedName_copy
17512 // (since the original symbol was associated with initializedName_original).
17513 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
17514 SgName name = initializedName_copy->get_name();
17515 SgSymbol* symbol = initializedName_copy->get_scope()->lookup_enum_field_symbol(name);
17516 ROSE_ASSERT(symbol != NULL);
17517
17518 SgEnumFieldSymbol* enumFieldSymbol = isSgEnumFieldSymbol(symbol);
17519 ROSE_ASSERT(enumFieldSymbol != NULL);
17520
17521 // DQ (3/17/2014): Build a new sysmbol to for the initializedName_copy instead of reusing the existing symbol
17522 // from the snippet AST.
17523 SgEnumFieldSymbol* new_enumFieldSymbol = new SgEnumFieldSymbol(initializedName_copy);
17524 ROSE_ASSERT(new_enumFieldSymbol != NULL);
17525
17526 // targetScope->insert_symbol(name,enumFieldSymbol);
17527 targetScope->insert_symbol(name,new_enumFieldSymbol);
17528
17529 // DQ (3/6/2014): Set the scope of the SgInitializedName IR node.
17530 initializedName_copy->set_scope(targetScope);
17531#if 0
17532 printf ("Exiting as a test! \n");
17533 ROSE_ABORT();
17534#endif
17535 }
17536 else
17537 {
17538#if 0
17539 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
17540#endif
17541 SgCatchOptionStmt* catchOptionStatement = isSgCatchOptionStmt(enclosingStatement_copy->get_parent());
17542 if (catchOptionStatement != NULL)
17543 {
17544 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(enclosingStatement_copy);
17545 ROSE_ASSERT(variableDeclaration != NULL);
17546
17547 // SgSymbol* symbol = targetScope->lookup_variable_symbol(initializedName_copy->get_name());
17548 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(initializedName_original);
17549 ROSE_ASSERT(enclosingStatement_original != NULL);
17550 SgCatchOptionStmt* catchOptionStatement_original = isSgCatchOptionStmt(enclosingStatement_original->get_parent());
17551
17552 // SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),targetScope);
17553 SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),catchOptionStatement_original);
17554 if (symbol == NULL)
17555 {
17556 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
17557 // initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
17558 }
17559 ROSE_ASSERT(symbol != NULL);
17560
17561 initializedName_copy->set_scope(targetScope);
17562
17563 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
17564 ROSE_ASSERT(new_variableSymbol != NULL);
17565
17566 // DQ (3/19/2014): I am not certain this is the correct location to insert this symbol.
17567 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
17568 }
17569 else
17570 {
17571 // DQ (3/29/2014): Adding support for SgInitializedName IR nodes found in a SgJavaForEachStatement.
17572 SgJavaForEachStatement* javaForEachStatement = isSgJavaForEachStatement(enclosingStatement_copy->get_parent());
17573 if (javaForEachStatement != NULL)
17574 {
17575 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(enclosingStatement_copy);
17576 ROSE_ASSERT(variableDeclaration != NULL);
17577
17578 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(initializedName_original);
17579 ROSE_ASSERT(enclosingStatement_original != NULL);
17580 SgJavaForEachStatement* javaForEachStatement_original = isSgJavaForEachStatement(enclosingStatement_original->get_parent());
17581
17582 SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),javaForEachStatement_original);
17583 if (symbol == NULL)
17584 {
17585 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
17586 // initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
17587 }
17588 ROSE_ASSERT(symbol != NULL);
17589
17590 initializedName_copy->set_scope(targetScope);
17591
17592 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
17593 ROSE_ASSERT(new_variableSymbol != NULL);
17594
17595 // DQ (3/29/2014): I am not certain this is the correct location to insert this symbol.
17596 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
17597#if 0
17598 printf ("Need to handle case of SgJavaForEachStatement \n");
17599 ROSE_ABORT();
17600#endif
17601 }
17602 else
17603 {
17604 // Case of non-SgFunctionParameterList and non-SgEnumDeclaration use of SgInitializedName in AST.
17605 SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
17606 if (symbol == NULL)
17607 {
17608 printf ("ERROR: enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
17609 ROSE_ASSERT(enclosingStatement_copy->get_parent() != NULL);
17610 printf ("ERROR: enclosingStatement_copy->get_parent() = %p = %s \n",enclosingStatement_copy->get_parent(),enclosingStatement_copy->get_parent()->class_name().c_str());
17611 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
17612 initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
17613
17614 // DQ (3/30/2014): Add this appraoch to find the symbol.
17615 SgScopeStatement* initializedName_copy_scope = isSgScopeStatement(initializedName_copy->get_scope());
17616 ROSE_ASSERT(initializedName_copy_scope != NULL);
17617 SgVariableSymbol* variableSymbol = initializedName_copy_scope->lookup_variable_symbol(initializedName_copy->get_name());
17618 ROSE_ASSERT(variableSymbol != NULL);
17619
17620 symbol = variableSymbol;
17621 }
17622 ROSE_ASSERT(symbol != NULL);
17623
17624 SgVariableSymbol* variableSymbol = isSgVariableSymbol(symbol);
17625 ROSE_ASSERT(variableSymbol != NULL);
17626#if 0
17627 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());
17628#endif
17629 // DQ (3/17/2014): Build a new sysmbol to for the initializedName_copy instead of reusing the existing symbol
17630 // from the snippet AST.
17631 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
17632 ROSE_ASSERT(new_variableSymbol != NULL);
17633
17634 // targetScope->insert_symbol(initializedName_copy->get_name(),variableSymbol);
17635 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
17636
17637 // DQ (3/6/2014): Set the scope of the SgInitializedName IR node.
17638 initializedName_copy->set_scope(targetScope);
17639
17640#if 0
17641 SgName mangledName = variableSymbol->get_mangled_name();
17642 printf ("initializedName_copy: mangledName = %s \n",mangledName.str());
17643#endif
17644 // DQ (3/2/2014): Make sure this is true (I think it should be, but I don't see that it was explicitly set).
17645 // ROSE_ASSERT(initializedName_copy->get_scope() == targetScope);
17646 if (initializedName_copy->get_scope() != targetScope)
17647 {
17648 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());
17649
17650 printf ("I think this should be an error! \n");
17651 ROSE_ABORT();
17652 }
17653 }
17654 }
17655 }
17656 }
17657
17658 break;
17659 }
17660
17661 case V_SgVariableDeclaration:
17662 {
17663 // I think there is nothing to handle for this case (there is no type accessbile here
17664 // since they are in the SgInitializedName IR nodes).
17665 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(node_copy);
17666 ROSE_ASSERT(variableDeclaration != NULL);
17667
17668 break;
17669 }
17670
17671#define DEBUG_FUNCTION_DECLARATION 0
17672
17673 case V_SgFunctionDeclaration:
17674 {
17675 // SgFunctionDeclaration is handled directly in the snippet support (insertRelatedThingsForC() function).
17676
17677 // Note that function types are stored in global type tables so they need not be fixed up.
17678
17679 // DQ (3/13/2014): As of today, this assumption is no longer true, we need to be able to insert
17680 // any function declaration in insertRelatedThingsForC() and use this function to fixup the AST.
17681 // The target AST should have a prototype (non-defining declaration) of the function defined
17682 // so that all internal types of the SgFunctionType are defined in the target AST.
17683 SgFunctionDeclaration* functionDeclaration_copy = isSgFunctionDeclaration(node_copy);
17684 SgFunctionDeclaration* functionDeclaration_original = isSgFunctionDeclaration(node_original);
17685 SgFunctionType* functionType_copy = functionDeclaration_copy->get_type();
17686 SgFunctionType* functionType_original = functionDeclaration_original->get_type();
17687 ROSE_ASSERT(functionType_copy != NULL);
17688 ROSE_ASSERT(functionType_original != NULL);
17689 ROSE_ASSERT(functionType_copy == functionType_original);
17690#if DEBUG_FUNCTION_DECLARATION
17691 printf ("case SgFunctionDeclaration: part 1: Calling functionDeclaration_copy->search_for_symbol_from_symbol_table() \n");
17692#endif
17693 // SgSymbol* symbol_copy = functionDeclaration_copy->search_for_symbol_from_symbol_table();
17694 SgSymbol* symbol_original = functionDeclaration_original->search_for_symbol_from_symbol_table();
17695 ROSE_ASSERT(symbol_original != NULL);
17696 SgFunctionSymbol* functionSymbol_original = isSgFunctionSymbol(symbol_original);
17697 ROSE_ASSERT(functionSymbol_original != NULL);
17698
17699 SgFile* snippetFile = getEnclosingFileNode(functionSymbol_original);
17700 ROSE_ASSERT(snippetFile != NULL);
17701 if (snippetFile != targetFile)
17702 {
17703#if DEBUG_FUNCTION_DECLARATION
17704 printf ("Warning: case V_SgFunctionDeclaration: functionSymbol_original not in target file \n");
17705#endif
17706 // DQ (3/13/2014): Handle the case of a member function seperately (I think this can't appear in Java, only in C++).
17707 // ROSE_ASSERT(isSgMemberFunctionSymbol(symbol_copy) == NULL);
17708 ROSE_ASSERT(isSgMemberFunctionSymbol(symbol_original) == NULL);
17709
17710 // printf ("case SgFunctionDeclaration: part 2: Calling functionDeclaration_copy->search_for_symbol_from_symbol_table() \n");
17711 // SgFunctionSymbol* functionSymbol_copy = isSgFunctionSymbol(functionDeclaration_copy->search_for_symbol_from_symbol_table());
17712 // ROSE_ASSERT(functionSymbol_copy != NULL);
17713
17714 SgName name = functionDeclaration_copy->get_name();
17715 SgType* functionType = functionDeclaration_copy->get_type();
17716 ROSE_ASSERT(functionType != NULL);
17717#if DEBUG_FUNCTION_DECLARATION
17718 printf ("case V_SgFunctionDeclaration: name = %s \n",name.str());
17719 printf ("case V_SgFunctionDeclaration: functionType = %p \n",functionType);
17720 printf ("case V_SgFunctionDeclaration: functionType_original = %p \n",functionType_original);
17721 printf ("case V_SgFunctionDeclaration: functionType_copy = %p \n",functionType_copy);
17722#endif
17723 SgFunctionSymbol* functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,functionType,targetScope);
17724
17725 ROSE_ASSERT(targetScope != NULL);
17726 functionDeclaration_copy->set_scope(targetScope);
17727
17728 // Set the scope of the non-defining declaration.
17729 functionDeclaration_copy->get_firstNondefiningDeclaration()->set_scope(targetScope);
17730
17731 SgFunctionDeclaration* functionDeclaration_copy_firstNondefining = NULL;
17732
17733 if (functionSymbolInTargetAST == NULL)
17734 {
17735#if DEBUG_FUNCTION_DECLARATION
17736 printf ("functionSymbolInTargetAST not found in targetScope = %p = %s \n",targetScope,targetScope->class_name().c_str());
17737#endif
17738 // If could be that the symbol is in the local scope of the snippet AST.
17739 SgScopeStatement* otherPossibleScope = isSgScopeStatement(functionDeclaration_original->get_parent());
17740 ROSE_ASSERT(otherPossibleScope != NULL);
17741#if DEBUG_FUNCTION_DECLARATION
17742 printf ("case V_SgFunctionDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope,otherPossibleScope->class_name().c_str());
17743#endif
17744 // We want to out serch the additional other scope and not it's parent scope.
17745 // functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,functionType,otherPossibleScope);
17746 functionSymbolInTargetAST = otherPossibleScope->lookup_function_symbol(name,functionType);
17747
17748 if (functionSymbolInTargetAST == NULL)
17749 {
17750 printf ("function symbol not found in otherPossibleScope = %p = %s \n",otherPossibleScope,otherPossibleScope->class_name().c_str());
17751 }
17752
17753 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17754#if DEBUG_FUNCTION_DECLARATION
17755 printf ("(building a new SgFunctionSymbol): functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17756#endif
17757 // DQ (3/15/2014): We need to insert a new symbol into the targetScope instead of reusing
17758 // the existing symbol (because it points to the declaration in the snippet file).
17759 // Insert the symbol into the targetScope.
17760 // targetScope->insert_symbol(name,functionSymbolInTargetAST);
17761 functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionDeclaration_copy->get_firstNondefiningDeclaration());
17762 SgFunctionSymbol* new_symbol = new SgFunctionSymbol(functionDeclaration_copy_firstNondefining);
17763 ROSE_ASSERT(new_symbol != NULL);
17764
17765 targetScope->insert_symbol(name,new_symbol);
17766
17767 functionSymbolInTargetAST = new_symbol;
17768
17769 // DQ (3/26/2014): Added assertion.
17770 ROSE_ASSERT(lookupFunctionSymbolInParentScopes(name,functionType,targetScope) != NULL);
17771 }
17772 else
17773 {
17774 // If we happend to find an associated symbol in the target scope then we nave to use it and
17775 // set the first nondefining declaration pointer to the symbol's associate declaration.
17776 // This is the case of the test3a test code (because the snippet functions declaration is
17777 // in the target AST file (likely a mistake, but we should handle it properly).
17778#if DEBUG_FUNCTION_DECLARATION
17779 printf ("(using existing symbol found in target scope): functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17780#endif
17781 functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
17782 }
17783
17784 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17785
17786 ROSE_ASSERT(functionDeclaration_copy->get_firstNondefiningDeclaration() != NULL);
17787 ROSE_ASSERT(functionDeclaration_copy_firstNondefining != NULL);
17788
17789 // SgFunctionDeclaration* functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionDeclaration_copy->get_firstNondefiningDeclaration());
17790 SgFunctionDeclaration* functionDeclaration_original_firstNondefining = isSgFunctionDeclaration(functionDeclaration_original->get_firstNondefiningDeclaration());
17791 SgFunctionDeclaration* functionDeclaration_copy_defining = isSgFunctionDeclaration(functionDeclaration_copy->get_definingDeclaration());
17792 SgFunctionDeclaration* functionDeclaration_original_defining = isSgFunctionDeclaration(functionDeclaration_original->get_definingDeclaration());
17793 if (functionDeclaration_copy_firstNondefining->get_symbol_from_symbol_table() == NULL)
17794 {
17795 // Check what might be wrong here!
17796 ROSE_ASSERT(functionDeclaration_original_firstNondefining != NULL);
17797 printf ("functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17798
17799 printf ("functionDeclaration_original = %p = %s \n",functionDeclaration_original,functionDeclaration_original->class_name().c_str());
17800 printf ("functionDeclaration_copy = %p = %s \n",functionDeclaration_copy,functionDeclaration_copy->class_name().c_str());
17801 printf ("functionDeclaration_original_firstNondefining = %p \n",functionDeclaration_original_firstNondefining);
17802 printf ("functionDeclaration_copy_firstNondefining = %p \n",functionDeclaration_copy_firstNondefining);
17803 printf ("functionDeclaration_original_defining = %p \n",functionDeclaration_original_defining);
17804 printf ("functionDeclaration_copy_defining = %p \n",functionDeclaration_copy_defining);
17805
17806 printf ("functionDeclaration_original->get_scope() = %p = %s \n",functionDeclaration_original->get_scope(),functionDeclaration_original->get_scope()->class_name().c_str());
17807 printf ("functionDeclaration_copy->get_scope() = %p = %s \n",functionDeclaration_copy->get_scope(),functionDeclaration_copy->get_scope()->class_name().c_str());
17808 printf ("functionDeclaration_original_firstNondefining->get_scope() = %p = %s \n",functionDeclaration_original_firstNondefining->get_scope(),functionDeclaration_original_firstNondefining->get_scope()->class_name().c_str());
17809 printf ("functionDeclaration_copy_firstNondefining->get_scope() = %p = %s \n",functionDeclaration_copy_firstNondefining->get_scope(),functionDeclaration_copy_firstNondefining->get_scope()->class_name().c_str());
17810 printf ("functionDeclaration_original_defining->get_scope() = %p = %s \n",functionDeclaration_original_defining->get_scope(),functionDeclaration_original_defining->get_scope()->class_name().c_str());
17811 printf ("functionDeclaration_copy_defining->get_scope() = %p = %s \n",functionDeclaration_copy_defining->get_scope(),functionDeclaration_copy_defining->get_scope()->class_name().c_str());
17812 printf ("functionSymbolInTargetAST = %p = %s \n",functionSymbolInTargetAST,functionSymbolInTargetAST->class_name().c_str());
17813 }
17814
17815 ROSE_ASSERT(targetScope->lookup_function_symbol(name,functionType) != NULL);
17816
17817 // TV (10/22/2014): Might not be the case as we now have a project wide global scope
17818 // ROSE_ASSERT(functionDeclaration_copy_firstNondefining->get_scope() == targetScope);
17819
17820 ROSE_ASSERT(functionDeclaration_copy_firstNondefining == functionDeclaration_copy_firstNondefining->get_firstNondefiningDeclaration());
17821
17822 // This is what is called internal to the get_symbol_from_symbol_table() function below.
17823 // Use this function, SgFunctionDeclaration::get_symbol_from_symbol_table(), but not the template function: find_symbol_from_declaration().
17824 // ROSE_ASSERT(targetScope->find_symbol_from_declaration(functionDeclaration_copy_firstNondefining) != NULL);
17825
17826 ROSE_ASSERT(functionDeclaration_copy_firstNondefining->get_symbol_from_symbol_table() != NULL);
17827
17828#if 0
17829 bool isDefiningDeclaration (functionDeclaration_original->get_declaration() != NULL);
17830 if (isDefiningDeclaration == true)
17831 {
17832 // We may have to build a non-defining declaration.
17833 SgFunctionDeclaration* nondefiningFunctionDeclaration_original = functionDeclaration_original->get_firstNondefiningDeclaration();
17834 SgFile* nondefiningDeclarationFile = getEnclosingFileNode(functionSymbol_original);
17835 ROSE_ASSERT(nondefiningDeclarationFile != NULL);
17836 if (nondefiningDeclarationFile == targetFile)
17837 {
17838 // Use this nondefining declaration.
17839 }
17840 else
17841 {
17842 // Make a copy of the non-defining declaration for use in the symbol.
17843 }
17844
17845 }
17846 else
17847 {
17848 // Use this as non-defining declaration.
17849 }
17850
17851 SgFile* snippetFile = getEnclosingFileNode(functionSymbol_original);
17852 SgFunctionSymbol* new_function_symbol = new SgFunctionSymbol(isSgFunctionDeclaration(func));
17853 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
17854 targetScope->insert_symbol(name,symbol_original);
17855
17856 ROSE_ABORT();
17857#endif
17858 }
17859
17860 // DQ (3/17/2014): Refactored code to support resetting the scopes in the SgDeclarationStatement IR nodes.
17861 resetDeclaration(functionDeclaration_copy,functionDeclaration_original,targetScope);
17862#if 0
17863 printf ("SageBuilder::fixupCopyOfNodeFromSeperateFileInNewTargetAst(): Need to be able to fixup the SgFunctionDeclaration \n");
17864 ROSE_ABORT();
17865#endif
17866 break;
17867 }
17868
17869 case V_SgClassDeclaration:
17870 {
17871 // Need to handle the referenced types
17872 SgClassDeclaration* classDeclaration_copy = isSgClassDeclaration(node_copy);
17873 SgClassDeclaration* classDeclaration_original = isSgClassDeclaration(node_original);
17874 SgClassType* classType = classDeclaration_copy->get_type();
17875 ROSE_ASSERT(classType != NULL);
17876#if 0
17877 printf ("Need to handle named types from class declarations \n");
17878#endif
17879 // SgClassSymbol* classSymbol_copy = isSgClassSymbol(classDeclaration_copy->search_for_symbol_from_symbol_table());
17880 // ROSE_ASSERT(classSymbol_copy != NULL);
17881
17882 // if (TransformationSupport::getFile(classSymbol_copy) != targetFile)
17883 // if (getEnclosingFileNode(classSymbol_copy) != targetFile)
17884 // if (getEnclosingFileNode(classDeclaration_copy) != targetFile)
17885 {
17886 // printf ("Warning: case V_SgClassDeclaration: classSymbol_copy not in target file \n");
17887#if 0
17888 printf ("Warning: case V_SgClassDeclaration: assume getEnclosingFileNode(classDeclaration_copy) != targetFile \n");
17889#endif
17890 // Find the symbol in the target scope.
17891 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17892#if 0
17893 // printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
17894#endif
17895 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
17896
17897 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17898 // ROSE_ASSERT(targetScope != NULL);
17899
17900 SgName name = classDeclaration_copy->get_name();
17901#if 0
17902 // If we randomize the names then we need to handle this case...
17903 printf ("case V_SgClassDeclaration: targetScope = %p classSymbol_copy->get_name() = %s \n",targetScope,classSymbol_copy->get_name().str());
17904#endif
17905 // SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classSymbol_copy->get_name(),targetScope);
17906 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(name,targetScope);
17907
17908 if (classSymbolInTargetAST == NULL)
17909 {
17910 // If could be that the symbol is in the local scope of the snippet AST.
17911 SgScopeStatement* otherPossibleScope = isSgScopeStatement(classDeclaration_original->get_parent());
17912 ROSE_ASSERT(otherPossibleScope != NULL);
17913#if 0
17914 printf ("case V_SgClassDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
17915#endif
17916 // classSymbolInTargetAST = lookupClassSymbolInParentScopes(classSymbol_copy->get_name(),otherPossibleScope);
17917 classSymbolInTargetAST = lookupClassSymbolInParentScopes(name,otherPossibleScope);
17918 ROSE_ASSERT(classSymbolInTargetAST != NULL);
17919#if 0
17920 // I think this is the wrong code.
17921 SgClassDeclaration* classDeclaration = classSymbolInTargetAST->get_declaration();
17922 ROSE_ASSERT(classDeclaration != NULL);
17923 SgScopeStatement* scope = classDeclaration->get_scope();
17924 ROSE_ASSERT(scope != NULL);
17925 classDeclaration_copy->set_scope(scope);
17926#else
17927 // DQ (3/17/2014): The scope must be set to be the targetScope (at least for C, but maybe not C++).
17928 classDeclaration_copy->set_scope(targetScope);
17929#endif
17930 // DQ (3/17/2014): Build a new SgClassSymbol using the classDeclaration_copy.
17931 SgClassSymbol* classSymbol = new SgClassSymbol(classDeclaration_copy);
17932 ROSE_ASSERT(classSymbol != NULL);
17933 classSymbolInTargetAST = classSymbol;
17934
17935 // Insert the symbol into the targetScope.
17936 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
17937 targetScope->insert_symbol(name,classSymbolInTargetAST);
17938 }
17939 else
17940 {
17941 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
17942 SgClassDeclaration* classDeclaration = classSymbolInTargetAST->get_declaration();
17943 ROSE_ASSERT(classDeclaration != NULL);
17944 SgScopeStatement* scope = classDeclaration->get_scope();
17945 ROSE_ASSERT(scope != NULL);
17946 classDeclaration_copy->set_scope(scope);
17947 }
17948
17949 ROSE_ASSERT(classSymbolInTargetAST != NULL);
17950 }
17951
17952 // DQ (3/17/2014): Avoid calling strip type now that we have refactored the getTargetFileType() function.
17953 // DQ (3/10/2014): Added remaining type for this case.
17954 // SgType* new_type = getTargetFileType(classType->stripType(),targetScope);
17955 SgType* new_type = getTargetFileType(classType,targetScope);
17956 SgClassType* new_class_type = isSgClassType(new_type);
17957 if (new_class_type != NULL)
17958 {
17959 // Reset the base type to be the one associated with the target file.
17960 classDeclaration_copy->set_type(new_class_type);
17961#if 0
17962 printf ("case V_SgClassDeclaration: built class type: part 1: classDeclaration_copy->get_type() = %p = %s \n",
17963 classDeclaration_copy->get_type(),classDeclaration_copy->get_type()->class_name().c_str());
17964#endif
17965 }
17966
17967 resetDeclaration(classDeclaration_copy,classDeclaration_original,targetScope);
17968#if 0
17969 printf ("SgClassDeclaration: Exiting as a test! \n");
17970 ROSE_ABORT();
17971#endif
17972 break;
17973 }
17974
17975 case V_SgEnumDeclaration:
17976 {
17977 // Need to handle the referenced types
17978 SgEnumDeclaration* enumDeclaration_copy = isSgEnumDeclaration(node_copy);
17979 SgEnumDeclaration* enumDeclaration_original = isSgEnumDeclaration(node_original);
17980
17981 // SgEnumType* enumType = enumDeclaration_copy->get_type();
17982 // ROSE_ASSERT(enumType != NULL);
17983
17984 // I don't think we have to test for this being a part of the snippet file.
17985 {
17986 SgName name = enumDeclaration_copy->get_name();
17987#if 0
17988 // If we randomize the names then we need to handle this case...
17989 printf ("case V_SgEnumDeclaration: targetScope = %p enumSymbol_copy->get_name() = %s \n",targetScope,name.str());
17990#endif
17991 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(name,targetScope);
17992
17993 if (enumSymbolInTargetAST == NULL)
17994 {
17995 // If could be that the symbol is in the local scope of the snippet AST.
17996 SgScopeStatement* otherPossibleScope = isSgScopeStatement(enumDeclaration_original->get_parent());
17997 ROSE_ASSERT(otherPossibleScope != NULL);
17998#if 0
17999 printf ("case V_SgEnumDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
18000#endif
18001 // I think we are not looking in the correct scope! Or else we need to also look in the target global scope.
18002#if 0
18003 printf ("Since the symbol has not been inserted yet, what symbol are we looking for? \n");
18004#endif
18005 enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(name,otherPossibleScope);
18006
18007 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
18008 SgEnumDeclaration* enumDeclaration = enumSymbolInTargetAST->get_declaration();
18009 ROSE_ASSERT(enumDeclaration != NULL);
18010
18011 ROSE_ASSERT(enumDeclaration != enumDeclaration_original);
18012
18013 // This is true, so we need to build a new sysmbol.
18014 ROSE_ASSERT(enumSymbolInTargetAST->get_declaration() == enumDeclaration_original->get_firstNondefiningDeclaration());
18015
18016 // Build a new SgEnumSymbol using the enumDeclaration_copy.
18017 SgEnumSymbol* enumSymbol = new SgEnumSymbol(enumDeclaration_copy);
18018 ROSE_ASSERT(enumSymbol != NULL);
18019 enumSymbolInTargetAST = enumSymbol;
18020
18021 // If this is false then we need to build a new SgEnumSymbol rather than reusing the existing one.
18022 ROSE_ASSERT(enumSymbolInTargetAST->get_declaration() != enumDeclaration_original->get_firstNondefiningDeclaration());
18023
18024 // SgScopeStatement* scope = enumDeclaration->get_scope();
18025 SgScopeStatement* scope = targetScope;
18026 ROSE_ASSERT(scope != NULL);
18027 enumDeclaration_copy->set_scope(scope);
18028#if 0
18029 printf ("case V_SgEnumDeclaration: insert_symbol(): name = %s enumSymbolInTargetAST = %p \n",name.str(),enumSymbolInTargetAST);
18030#endif
18031 // Insert the symbol into the targetScope.
18032 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
18033 targetScope->insert_symbol(name,enumSymbolInTargetAST);
18034 }
18035 else
18036 {
18037#if 0
18038 printf ("Found an existing enum declaration: name = %s enumSymbolInTargetAST = %p \n",name.str(),enumSymbolInTargetAST);
18039#endif
18040 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
18041 SgEnumDeclaration* enumDeclaration = enumSymbolInTargetAST->get_declaration();
18042 ROSE_ASSERT(enumDeclaration != NULL);
18043#if 0
18044 SgScopeStatement* scope = enumDeclaration->get_scope();
18045 ROSE_ASSERT(scope != NULL);
18046 ROSE_ASSERT(scope == targetScope);
18047 // enumDeclaration_copy->set_scope(scope);
18048#else
18049 // TV (10/22/2014): Might not be the case as we now have a project wide global scope
18050 // ROSE_ASSERT(enumDeclaration->get_scope() == targetScope);
18051#endif
18052 }
18053
18054 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
18055 }
18056#if 0
18057 printf ("Exiting as a test 1! \n");
18058 ROSE_ABORT();
18059#endif
18060 SgEnumType* enumType = enumDeclaration_copy->get_type();
18061 ROSE_ASSERT(enumType != NULL);
18062 SgType* new_type = getTargetFileType(enumType,targetScope);
18063#if 0
18064 printf ("Return type from getTargetFileType(): original enumType = %p new_type = %p \n",enumType,new_type);
18065#endif
18066 SgEnumType* new_enum_type = isSgEnumType(new_type);
18067 if (new_enum_type != NULL)
18068 {
18069 // Reset the base type to be the one associated with the target file.
18070#if 0
18071 printf ("reset the type using the new enum type from the target AST \n");
18072#endif
18073 enumDeclaration_copy->set_type(new_enum_type);
18074 }
18075#if 0
18076 printf ("Exiting as a test 2! \n");
18077 ROSE_ABORT();
18078#endif
18079
18080 resetDeclaration(enumDeclaration_copy,enumDeclaration_original,targetScope);
18081 break;
18082 }
18083
18084 // This is not a required declaration of C.
18085 case V_SgTemplateClassDeclaration:
18086 {
18087 // Need to handle the referenced types
18088 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(node_copy);
18089 SgClassType* templateClassType = templateClassDeclaration->get_type();
18090 ROSE_ASSERT(templateClassType != NULL);
18091
18092 // DQ (3/10/2014): Added support for enum types.
18093 SgType* new_type = getTargetFileType(templateClassType,targetScope);
18094 SgClassType* new_templateClass_type = isSgClassType(new_type);
18095 if (new_templateClass_type != NULL)
18096 {
18097 // Reset the base type to be the one associated with the target file.
18098 templateClassDeclaration->set_type(new_templateClass_type);
18099#if 0
18100 printf ("case V_SgTemplateClassDeclaration: built class type: part 1: templateClassDeclaration->get_type() = %p = %s \n",
18101 templateClassDeclaration->get_type(),templateClassDeclaration->get_type()->class_name().c_str());
18102#endif
18103 }
18104
18105 break;
18106 }
18107
18108 case V_SgTypedefDeclaration:
18109 {
18110 // Need to handle the referenced types (there are two for the case of a SgTypedefDeclaration).
18111 SgTypedefDeclaration* typedefDeclaration_copy = isSgTypedefDeclaration(node_copy);
18112 SgTypedefDeclaration* typedefDeclaration_original = isSgTypedefDeclaration(node_original);
18113
18114 SgType* base_type = typedefDeclaration_copy->get_base_type();
18115 ROSE_ASSERT(base_type != NULL);
18116 SgType* new_base_type = getTargetFileType(base_type,targetScope);
18117 if (new_base_type != NULL)
18118 {
18119 // Reset the base type to be the one associated with the target file.
18120 typedefDeclaration_copy->set_base_type(new_base_type);
18121 }
18122
18123 // I don't think we have to test for this being a part of the snippet file.
18124 {
18125 SgName name = typedefDeclaration_copy->get_name();
18126#if 0
18127 // If we randomize the names then we need to handle this case...
18128 printf ("case V_SgTypedefDeclaration: targetScope = %p typedefSymbol_copy->get_name() = %s \n",targetScope,name.str());
18129#endif
18130 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(name,targetScope);
18131
18132 if (typedefSymbolInTargetAST == NULL)
18133 {
18134 // If could be that the symbol is in the local scope of the snippet AST.
18135 SgScopeStatement* otherPossibleScope = isSgScopeStatement(typedefDeclaration_original->get_parent());
18136 ROSE_ASSERT(otherPossibleScope != NULL);
18137#if 0
18138 printf ("case V_SgTypedefDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
18139#endif
18140 typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(name,otherPossibleScope);
18141
18142 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
18143 SgTypedefDeclaration* typedefDeclaration = typedefSymbolInTargetAST->get_declaration();
18144 ROSE_ASSERT(typedefDeclaration != NULL);
18145 // SgScopeStatement* scope = typedefDeclaration->get_scope();
18146 SgScopeStatement* scope = targetScope;
18147 ROSE_ASSERT(scope != NULL);
18148 typedefDeclaration_copy->set_scope(scope);
18149
18150 // DQ (3/17/2014): Build a new SgTypedefSymbol using the typedefDeclaration_copy.
18151 SgTypedefSymbol* typedefSymbol = new SgTypedefSymbol(typedefDeclaration_copy);
18152 ROSE_ASSERT(typedefSymbol != NULL);
18153 typedefSymbolInTargetAST = typedefSymbol;
18154#if 0
18155 printf ("case V_SgTypedefDeclaration: insert_symbol(): name = %s typedefSymbolInTargetAST = %p \n",name.str(),typedefSymbolInTargetAST);
18156#endif
18157 // Insert the symbol into the targetScope.
18158 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
18159 targetScope->insert_symbol(name,typedefSymbolInTargetAST);
18160 }
18161 else
18162 {
18163#if 0
18164 printf ("Found an existing typedef declaration: name = %s typedefSymbolInTargetAST = %p \n",name.str(),typedefSymbolInTargetAST);
18165#endif
18166 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
18167 SgTypedefDeclaration* typedefDeclaration = typedefSymbolInTargetAST->get_declaration();
18168 ROSE_ASSERT(typedefDeclaration != NULL);
18169 SgScopeStatement* scope = typedefDeclaration->get_scope();
18170 ROSE_ASSERT(scope != NULL);
18171 typedefDeclaration_copy->set_scope(scope);
18172 }
18173
18174 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
18175 }
18176#if 0
18177 printf ("Exiting as a test 1! \n");
18178 ROSE_ABORT();
18179#endif
18180 SgTypedefType* typedefType = typedefDeclaration_copy->get_type();
18181 ROSE_ASSERT(typedefType != NULL);
18182 SgType* new_type = getTargetFileType(typedefType,targetScope);
18183 SgTypedefType* new_typedef_type = isSgTypedefType(new_type);
18184 if (new_typedef_type != NULL)
18185 {
18186 // Reset the base type to be the one associated with the target file.
18187#if 0
18188 printf ("reset the type using the new typedef type from the target AST \n");
18189#endif
18190 typedefDeclaration_copy->set_type(new_typedef_type);
18191#if 0
18192 printf ("case V_SgTypedefDeclaration: built class type: part 1: typedefDeclaration_copy->get_type() = %p = %s \n",
18193 typedefDeclaration_copy->get_type(),typedefDeclaration_copy->get_type()->class_name().c_str());
18194#endif
18195 }
18196
18197 resetDeclaration(typedefDeclaration_copy,typedefDeclaration_original,targetScope);
18198#if 0
18199 printf ("Exiting as a test 2! \n");
18200 ROSE_ABORT();
18201#endif
18202 break;
18203 }
18204
18205 case V_SgVarRefExp:
18206 {
18207 // Need to handle the referenced symbol.
18208 // but if we have handle this in the declaration for the variable (case V_SgInitializedName)
18209 // then we don't have to do anything here. However, we have only handled this variable
18210 // declaration if the variable declaration was a part of the snippet. If the variable
18211 // declaration is not a part of the original snippet (the copy of the snippet's AST that
18212 // we are inserting (not the snippet program where it would have to be defined for the
18213 // snippet to compile) then we have to find the associated variable sysmbol in the target
18214 // AST and reset the SgVarRefExp to use that symbol.
18215
18216 SgVarRefExp* varRefExp_copy = isSgVarRefExp(node_copy);
18217 SgVarRefExp* varRefExp_original = isSgVarRefExp(node_original);
18218 SgVariableSymbol* variableSymbol_copy = isSgVariableSymbol(varRefExp_copy->get_symbol());
18219 ROSE_ASSERT(variableSymbol_copy != NULL);
18220 // if (TransformationSupport::getFile(variableSymbol_copy) != targetFile)
18221 if (getEnclosingFileNode(variableSymbol_copy) != targetFile)
18222 {
18223#if 0
18224 printf ("Warning: case V_SgVarRefExp: variableSymbol not in target file: name = %s \n",variableSymbol_copy->get_name().str());
18225#endif
18226#if 0
18227 printf ("insertionPoint = %p = %s \n",insertionPoint,insertionPoint->class_name().c_str());
18228#endif
18229 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
18230#if 0
18231 // printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
18232#endif
18233 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
18234
18235 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
18236 // ROSE_ASSERT(targetScope != NULL);
18237
18238 SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),targetScope);
18239
18240 if (variableSymbolInTargetAST == NULL)
18241 {
18242 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
18243 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
18244 // previously added snippet.
18245#if 0
18246 printf ("Error: The associated variable = %s should have been found in a parent scope of the target AST \n",variableSymbol_copy->get_name().str());
18247#endif
18248 // We need to look into the scope of the block used to define the statments as seperate snippets (same issue as for functions).
18249
18250 // If could be that the symbol is in the local scope of the snippet AST.
18251 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(varRefExp_original);
18252 ROSE_ASSERT(enclosingStatement_original != NULL);
18253#if 0
18254 printf ("case V_SgVarRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
18255#endif
18256 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
18257 ROSE_ASSERT(otherPossibleScope_original != NULL);
18258 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
18259 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
18260 ROSE_ASSERT(file != NULL);
18261#if 0
18262 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
18263 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18264
18265 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
18266 printf ("case V_SgClassDeclaration: variableSymbol_copy->get_name() = %s \n",variableSymbol_copy->get_name().str());
18267#endif
18268 variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),otherPossibleScope_original);
18269 if (variableSymbolInTargetAST == NULL)
18270 {
18271#if 0
18272 targetScope->get_symbol_table()->print("targetScope: symbol table");
18273 otherPossibleScope_original->get_symbol_table()->print("otherPossibleScope_original: symbol table");
18274#endif
18275
18276 // Check for the case of a record reference (member of data structure).
18277 SgExpression* parentExpression = isSgExpression(varRefExp_copy->get_parent());
18278 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
18279 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
18280 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
18281 if (parentDotExp != NULL || parentArrowExp != NULL)
18282 {
18283 // This is a data member reference, so it's scope is the associated data structure.
18284 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
18285 ROSE_ASSERT(lhs != NULL);
18286 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == varRefExp_copy);
18287
18288 SgType* type = lhs->get_type();
18289 ROSE_ASSERT(type != NULL);
18290#if 0
18291 printf ("type = %p = %s \n",type,type->class_name().c_str());
18292#endif
18293 SgNamedType* namedType = isSgNamedType(type);
18294 ROSE_ASSERT(namedType != NULL);
18295 SgDeclarationStatement* declaration = namedType->get_declaration();
18296 ROSE_ASSERT(declaration != NULL);
18297 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
18298 ROSE_ASSERT(classDeclaration != NULL);
18299 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
18300 ROSE_ASSERT(definingClassDeclaration != NULL);
18301 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18302 ROSE_ASSERT(classDefinition != NULL);
18303#if 0
18304 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
18305#endif
18306 // I think we want the copy.
18307 otherPossibleScope_original = classDefinition;
18308
18309 variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),otherPossibleScope_original);
18310 }
18311
18312 }
18313 ROSE_ASSERT(variableSymbolInTargetAST != NULL);
18314 SgInitializedName* initializedName = variableSymbolInTargetAST->get_declaration();
18315 ROSE_ASSERT(initializedName != NULL);
18316 SgScopeStatement* scope = initializedName->get_scope();
18317 ROSE_ASSERT(scope != NULL);
18318
18319 // Is this the correct scope?
18320 initializedName->set_scope(scope);
18321
18322 // Insert the symbol into the targetScope.
18323 targetScope->insert_symbol(variableSymbol_copy->get_name(),variableSymbolInTargetAST);
18324 }
18325 ROSE_ASSERT(variableSymbolInTargetAST != NULL);
18326
18327 // Reset the symbol associated with this variable reference.
18328 varRefExp_copy->set_symbol(variableSymbolInTargetAST);
18329
18330 // printf ("Exiting as a test! \n");
18331 // ROSE_ASSERT(false);
18332 }
18333
18334 break;
18335 }
18336
18337 case V_SgFunctionRefExp:
18338 {
18339 // Need to handle the referenced symbol
18340 SgFunctionRefExp* functionRefExp_copy = isSgFunctionRefExp(node_copy);
18341 // SgFunctionRefExp* functionRefExp_original = isSgFunctionRefExp(node_original);
18342 SgFunctionSymbol* functionSymbol_copy = isSgFunctionSymbol(functionRefExp_copy->get_symbol());
18343 ROSE_ASSERT(functionSymbol_copy != NULL);
18344 // if (TransformationSupport::getFile(functionSymbol) != targetFile)
18345 if (getEnclosingFileNode(functionSymbol_copy) != targetFile)
18346 {
18347#if 0
18348 printf ("Warning: case V_SgFunctionRefExp: functionSymbol_copy not in target file (find function = %s) \n",functionSymbol_copy->get_name().str());
18349#endif
18350 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
18351#if 0
18352 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
18353#endif
18354 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
18355
18356 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
18357 // ROSE_ASSERT(targetScope != NULL);
18358
18359 SgName name = functionSymbol_copy->get_name();
18360
18361 // I think we need the function's mangled name to support this lookup.
18362 SgFunctionSymbol* functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,targetScope);
18363
18364 if (functionSymbolInTargetAST == NULL)
18365 {
18366 // DQ (3/17/2014): Revised as of further discussion about how the snippet mechanism will copy required
18367 // declaration from the snippet file to the target AST.
18368 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
18369 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
18370 // previously added snippet.
18371 // DQ (3/17/2014): After some revision of the specification for the snippet injection, this is still
18372 // an error since this is the case where a declaration should have been visible from having already been
18373 // inserted into the target AST and this visible from this injection point in the target AST.
18374
18375 fprintf (stderr, "Error: The associated function = \"%s\" should have been found in a parent scope"
18376 " of the target AST\n", name.str());
18377
18378 fprintf (stderr, " targetScope = %p = %s \n",targetScope,targetScope->class_name().c_str());
18379 SgGlobal* globalScope = TransformationSupport::getGlobalScope(targetScope);
18380 ROSE_ASSERT(globalScope != NULL);
18381 fprintf (stderr, " globalScope = %p = %s \n",globalScope,globalScope->class_name().c_str());
18382#if 0
18383 targetScope->get_file_info()->display("case V_SgFunctionRefExp: targetScope: debug");
18384 node_original->get_file_info()->display("case V_SgFunctionRefExp: node_original: debug");
18385#endif
18386#if 0
18387 // DQ (3/10/2014): This might be important for friend functions in C++ (but we can ignore it for now).
18388#error "DEAD CODE!"
18389 // If could be that the symbol is in the local scope of the snippet AST.
18390 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(functionRefExp_original);
18391 ROSE_ASSERT(enclosingStatement_original != NULL);
18392#if 0
18393 printf ("case V_SgFunctionRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
18394#endif
18395 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
18396 ROSE_ASSERT(otherPossibleScope_original != NULL);
18397 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
18398 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
18399 ROSE_ASSERT(file != NULL);
18400#if 0
18401 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
18402 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18403
18404 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
18405 printf ("case V_SgClassDeclaration: functionSymbol_copy->get_name() = %s \n",functionSymbol_copy->get_name().str());
18406#endif
18407 functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(functionSymbol_copy->get_name(),otherPossibleScope_original);
18408#error "DEAD CODE!"
18409 if (functionSymbolInTargetAST == NULL)
18410 {
18411 // Check for the case of a record reference (member function of class declaration).
18412 SgExpression* parentExpression = isSgExpression(functionRefExp_copy->get_parent());
18413 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
18414 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
18415 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
18416 if (parentDotExp != NULL || parentArrowExp != NULL)
18417 {
18418 // This is a data member reference, so it's scope is the associated data structure.
18419 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
18420 ROSE_ASSERT(lhs != NULL);
18421 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == functionRefExp_copy);
18422#error "DEAD CODE!"
18423 SgType* type = lhs->get_type();
18424 ROSE_ASSERT(type != NULL);
18425#if 0
18426 printf ("type = %p = %s \n",type,type->class_name().c_str());
18427#endif
18428 SgNamedType* namedType = isSgNamedType(type);
18429 ROSE_ASSERT(namedType != NULL);
18430 SgDeclarationStatement* declaration = namedType->get_declaration();
18431 ROSE_ASSERT(declaration != NULL);
18432 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
18433 ROSE_ASSERT(classDeclaration != NULL);
18434 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
18435 ROSE_ASSERT(definingClassDeclaration != NULL);
18436 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18437 ROSE_ASSERT(classDefinition != NULL);
18438#if 0
18439 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
18440#endif
18441 // I think we want the copy.
18442 otherPossibleScope_original = classDefinition;
18443
18444 functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(functionSymbol_copy->get_name(),otherPossibleScope_original);
18445 }
18446 }
18447
18448#error "DEAD CODE!"
18449 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
18450 SgFunctionDeclaration* functionDeclaration = functionSymbolInTargetAST->get_declaration();
18451 ROSE_ASSERT(functionDeclaration != NULL);
18452 SgScopeStatement* scope = functionDeclaration->get_scope();
18453 ROSE_ASSERT(scope != NULL);
18454
18455 // Is this the correct scope?
18456 functionDeclaration->set_scope(scope);
18457#endif
18458 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
18459
18460 // Insert the symbol into the targetScope.
18461 targetScope->insert_symbol(functionSymbol_copy->get_name(),functionSymbolInTargetAST);
18462 }
18463 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
18464
18465 // Reset the symbol associated with this function reference.
18466 functionRefExp_copy->set_symbol(functionSymbolInTargetAST);
18467#if 0
18468 printf ("Exiting as a test! \n");
18469 ROSE_ABORT();
18470#endif
18471 }
18472
18473 break;
18474 }
18475
18476#define DEBUG_MEMBER_FUNCTION_REF_EXP 0
18477
18478 case V_SgMemberFunctionRefExp:
18479 {
18480 // Need to handle the referenced symbol
18481 SgMemberFunctionRefExp* memberFunctionRefExp_copy = isSgMemberFunctionRefExp(node_copy);
18482 SgMemberFunctionRefExp* memberFunctionRefExp_original = isSgMemberFunctionRefExp(node_original);
18483 SgMemberFunctionSymbol* memberFunctionSymbol_copy = isSgMemberFunctionSymbol(memberFunctionRefExp_copy->get_symbol());
18484 ROSE_ASSERT(memberFunctionSymbol_copy != NULL);
18485 // if (TransformationSupport::getFile(memberFunctionSymbol) != targetFile)
18486 if (getEnclosingFileNode(memberFunctionSymbol_copy) != targetFile)
18487 {
18488 // Not implemented (initial work is focused on C, then Java, then C++.
18489#if DEBUG_MEMBER_FUNCTION_REF_EXP
18490 printf ("Warning: case V_SgMemberFunctionRefExp: memberFunctionSymbol_copy not in target file (find member function = %s) \n",memberFunctionSymbol_copy->get_name().str());
18491#endif
18492 SgMemberFunctionSymbol* memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),targetScope));
18493
18494 if (memberFunctionSymbolInTargetAST == NULL)
18495 {
18496 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
18497 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
18498 // previously added snippet.
18499#if DEBUG_MEMBER_FUNCTION_REF_EXP
18500 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());
18501#endif
18502 // DQ (3/10/2014): This is important for member functions in Java and C++.
18503
18504 // If could be that the symbol is in the local scope of the snippet AST.
18505 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(memberFunctionRefExp_original);
18506 ROSE_ASSERT(enclosingStatement_original != NULL);
18507#if DEBUG_MEMBER_FUNCTION_REF_EXP
18508 printf ("case V_SgMemberFunctionRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
18509#endif
18510 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
18511 ROSE_ASSERT(otherPossibleScope_original != NULL);
18512 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
18513 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
18514 ROSE_ASSERT(file != NULL);
18515#if DEBUG_MEMBER_FUNCTION_REF_EXP
18516 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
18517 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18518
18519 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
18520 printf ("case V_SgClassDeclaration: memberFunctionSymbol_copy->get_name() = %s \n",memberFunctionSymbol_copy->get_name().str());
18521#endif
18522 memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original));
18523 if (memberFunctionSymbolInTargetAST == NULL)
18524 {
18525#if DEBUG_MEMBER_FUNCTION_REF_EXP
18526 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");
18527#endif
18528 // Check for the case of a record reference (member function of class declaration).
18529 SgExpression* parentExpression = isSgExpression(memberFunctionRefExp_copy->get_parent());
18530
18531 ROSE_ASSERT(parentExpression != NULL);
18532#if DEBUG_MEMBER_FUNCTION_REF_EXP
18533 printf ("parentExpression = %p = %s \n",parentExpression,parentExpression->class_name().c_str());
18534#endif
18535 bool handle_as_java = false;
18536 SgFunctionCallExp* functionCallExp = isSgFunctionCallExp(parentExpression);
18537 if (functionCallExp != NULL)
18538 {
18539 // Note that this is a Java specific organization of the SgMemberFunctionRefExp and the SgFunctionCallExp.
18540 // We might want to make this more uniform between C++ and Java later.
18541 handle_as_java = true;
18542
18543 SgExpression* parentOfFunctionCallExpression = isSgExpression(functionCallExp->get_parent());
18544
18545 ROSE_ASSERT(parentOfFunctionCallExpression != NULL);
18546#if DEBUG_MEMBER_FUNCTION_REF_EXP
18547 printf ("parentOfFunctionCallExpression = %p = %s \n",parentOfFunctionCallExpression,parentOfFunctionCallExpression->class_name().c_str());
18548#endif
18549 parentExpression = parentOfFunctionCallExpression;
18550 }
18551
18552 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
18553 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
18554 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
18555#if DEBUG_MEMBER_FUNCTION_REF_EXP
18556 printf ("parentBinaryOp = %p \n",parentBinaryOp);
18557 printf ("parentDotExp = %p \n",parentDotExp);
18558 printf ("parentArrowExp = %p \n",parentArrowExp);
18559#endif
18560 if (parentDotExp != NULL || parentArrowExp != NULL)
18561 {
18562 // This is a data member reference, so it's scope is the associated data structure.
18563 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
18564 ROSE_ASSERT(lhs != NULL);
18565
18566 // This will be true for C++, but not Java (a little odd).
18567 if (handle_as_java == true)
18568 {
18569 // The rhs is the SgFunctionCallExp for Java.
18570 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == functionCallExp);
18571 }
18572 else
18573 {
18574 // This is what we expect to be true for C++.
18575 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == memberFunctionRefExp_copy);
18576 }
18577#if DEBUG_MEMBER_FUNCTION_REF_EXP
18578 printf ("lhs = %p = %s \n",lhs,lhs->class_name().c_str());
18579#endif
18580 SgVarRefExp* varRefExp = isSgVarRefExp(lhs);
18581
18582 // DQ (3/15/2014): This can be a SgJavaTypeExpression (see testJava3a).
18583 // ROSE_ASSERT(varRefExp != NULL);
18584 if (varRefExp != NULL)
18585 {
18586 SgVariableSymbol* variableSymbol = isSgVariableSymbol(varRefExp->get_symbol());
18587 ROSE_ASSERT(variableSymbol != NULL);
18588 SgInitializedName* initializedName = variableSymbol->get_declaration();
18589 ROSE_ASSERT(initializedName != NULL);
18590
18591 SgType* initializedName_type = initializedName->get_type();
18592#if DEBUG_MEMBER_FUNCTION_REF_EXP
18593 printf ("initializedName = %p = %s \n",initializedName,initializedName->get_name().str());
18594 printf ("initializedName_type = %p \n",initializedName_type);
18595#endif
18596 SgClassType* classType = isSgClassType(initializedName_type);
18597 if (classType != NULL)
18598 {
18599 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
18600 ROSE_ASSERT(classDeclaration != NULL);
18601 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(classDeclaration->get_definingDeclaration());
18602 ROSE_ASSERT(definingClassDeclaration != NULL);
18603 printf ("definingClassDeclaration->get_name() = %s \n",definingClassDeclaration->get_name().str());
18604
18605 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18606 ROSE_ASSERT(classDefinition != NULL);
18607 SgType* memberFunctionType = memberFunctionSymbol_copy->get_type();
18608 SgName memberFunctionName = memberFunctionSymbol_copy->get_name();
18609 ROSE_ASSERT(memberFunctionType != NULL);
18610 SgFunctionSymbol *functionSymbol = classDefinition->lookup_function_symbol(memberFunctionName,memberFunctionType);
18611 if (functionSymbol == NULL)
18612 {
18613 printf ("Symbol not found: output symbol table (size = %d): \n",classDefinition->get_symbol_table()->size());
18614#if DEBUG_MEMBER_FUNCTION_REF_EXP
18615 classDefinition->get_symbol_table()->print("Symbol not found: output symbol table: SgClassDefinition");
18616#endif
18617 // DQ (3/30/2014): If functionSymbol is not found then I think it is because the class was not availalbe
18618 // in the target where the snippet is being copied. This is an error in the constrains for how the target
18619 // must be prepared for the snippet to be copied into it.
18620 printf ("\n*************************************************************** \n");
18621 printf ("ERROR: target has not be properly setup to receive the snippet. \n");
18622 printf ("*************************************************************** \n");
18623 }
18624 ROSE_ASSERT(functionSymbol != NULL);
18625 SgMemberFunctionSymbol *memberFunctionSymbol = isSgMemberFunctionSymbol(functionSymbol);
18626 ROSE_ASSERT(memberFunctionSymbol != NULL);
18627
18628 memberFunctionSymbolInTargetAST = memberFunctionSymbol;
18629#if 0
18630 printf ("Exiting as a test! \n");
18631 ROSE_ABORT();
18632#endif
18633 }
18634 }
18635
18636 // DQ (3/30/2014): If this is a value expression then calling the member function uses a shared
18637 // symbol from the global scope (or a type defined deep in the global scope, but common to the
18638 // snippet AST and the target AST).
18639 SgValueExp* valueExp = isSgValueExp(lhs);
18640 if (valueExp != NULL)
18641 {
18642 memberFunctionSymbolInTargetAST = memberFunctionSymbol_copy;
18643 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18644 }
18645
18646 if (memberFunctionSymbolInTargetAST == NULL)
18647 {
18648#if 1
18649 SgType* type = lhs->get_type();
18650 ROSE_ASSERT(type != NULL);
18651#if DEBUG_MEMBER_FUNCTION_REF_EXP
18652 printf ("type = %p = %s \n",type,type->class_name().c_str());
18653#endif
18654 SgNamedType* namedType = isSgNamedType(type);
18655 ROSE_ASSERT(namedType != NULL);
18656 SgDeclarationStatement* declaration = namedType->get_declaration();
18657 ROSE_ASSERT(declaration != NULL);
18658 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
18659 ROSE_ASSERT(classDeclaration != NULL);
18660 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
18661 ROSE_ASSERT(definingClassDeclaration != NULL);
18662 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18663 ROSE_ASSERT(classDefinition != NULL);
18664#if DEBUG_MEMBER_FUNCTION_REF_EXP
18665 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
18666#endif
18667 // I think we want the copy.
18668 otherPossibleScope_original = classDefinition;
18669#if DEBUG_MEMBER_FUNCTION_REF_EXP
18670 classDefinition->get_symbol_table()->print("Java classDefinition");
18671#endif
18672#if DEBUG_MEMBER_FUNCTION_REF_EXP
18673 SgClassDeclaration* associated_classDeclaration = classDefinition->get_declaration();
18674 SgFunctionSymbol* functionSymbol = lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original);
18675 printf ("associated_classDeclaration = %p name = %s \n",associated_classDeclaration,associated_classDeclaration->get_name().str());
18676 printf ("functionSymbol = %p \n",functionSymbol);
18677#endif
18678 memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original));
18679 if (memberFunctionSymbolInTargetAST == NULL)
18680 {
18681 // Output debugging info (16 of the CWE injection test codes fail here: see test_results.txt file for details).
18682 printf ("Error: (memberFunctionSymbolInTargetAST == NULL): memberFunctionSymbol_copy->get_name() = %s \n",memberFunctionSymbol_copy->get_name().str());
18683 }
18684#endif
18685 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18686 }
18687 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18688 }
18689 }
18690
18691 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18692 SgFunctionDeclaration* functionDeclaration = memberFunctionSymbolInTargetAST->get_declaration();
18693 ROSE_ASSERT(functionDeclaration != NULL);
18694 SgScopeStatement* scope = functionDeclaration->get_scope();
18695 ROSE_ASSERT(scope != NULL);
18696
18697 // Is this the correct scope?
18698 functionDeclaration->set_scope(scope);
18699 }
18700 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18701
18702 // Reset the symbol associated with this function reference.
18703 memberFunctionRefExp_copy->set_symbol(memberFunctionSymbolInTargetAST);
18704 }
18705
18706 break;
18707 }
18708
18709 // DQ (3/21/2014): I think we need this.
18710 case V_SgTryStmt:
18711 {
18712#if 0
18713 printf ("Exiting as a test! (SgTryStmt) \n");
18714 ROSE_ABORT();
18715#endif
18716 break;
18717 }
18718
18719 // DQ (3/19/2014): Just found this case in a few of the CWE Java snippet tests.
18720 case V_SgCatchStatementSeq:
18721 {
18722 // DQ (3/19/2014): Note sure that we need to handle this specific case.
18723
18724#if 0
18725 printf ("Exiting as a test! (SgCatchStatementSeq) \n");
18726 ROSE_ABORT();
18727#endif
18728 break;
18729 }
18730
18731 // DQ (3/19/2014): Just found this case in a few of the CWE Java snippet tests.
18732 case V_SgCatchOptionStmt:
18733 {
18734 // DQ (3/19/2014): Note sure that we need to handle this specific case.
18735 // Decide if we need to implement this newly identified case tomorrow (note that this is a SgScopeStatement).
18736 SgCatchOptionStmt* catchOptionStatement_copy = isSgCatchOptionStmt(node_copy);
18737 ROSE_ASSERT(catchOptionStatement_copy);
18738
18739 printf ("Need to check the symbol table of the SgCatchOptionStmt (which is a SgScopeStatement) \n");
18740
18741#if 0
18742 printf ("Exiting as a test! (SgCatchOptionStmt) \n");
18743 ROSE_ABORT();
18744#endif
18745 break;
18746 }
18747
18748 // DQ (3/21/2014): I think we need this.
18749 case V_SgJavaPackageStatement:
18750 {
18751#if 1
18752 printf ("Exiting as a test! (SgJavaPackageStatement) \n");
18753 ROSE_ABORT();
18754#endif
18755 break;
18756 }
18757
18758 case V_SgEnumVal:
18759 {
18760 // SgEnumVal expressions contain a reference to the associated SgEnumDeclaration, so this may have to be updated.
18761#if 0
18762 printf ("enum values contain a reference to the associated SgEnumDeclaration \n");
18763#endif
18764 SgEnumVal* enumVal_copy = isSgEnumVal(node_copy);
18765 SgEnumVal* enumVal_original = isSgEnumVal(node_original);
18766#if 0
18767 printf (" --- enumVal_original = %p = %d name = %s \n",enumVal_original,enumVal_original->get_value(),enumVal_original->get_name().str());
18768#endif
18769 SgEnumDeclaration* associatedEnumDeclaration_copy = isSgEnumDeclaration(enumVal_copy->get_declaration());
18770 SgEnumDeclaration* associatedEnumDeclaration_original = isSgEnumDeclaration(enumVal_original->get_declaration());
18771
18772 // DQ (4/13/2014): check if this is an un-named enum beclaration.
18773 bool isUnNamed = associatedEnumDeclaration_original->get_isUnNamed();
18774 if (isUnNamed == false)
18775 {
18776 if (associatedEnumDeclaration_copy == associatedEnumDeclaration_original)
18777 {
18778#if 0
18779 printf (" --- The stored reference to the enum declaration in the SgEnumVal must be reset \n");
18780#endif
18781 // SgSymbol* SageBuilder::findAssociatedSymbolInTargetAST(SgDeclarationStatement* snippet_declaration, SgScopeStatement* targetScope)
18782 SgSymbol* symbol = findAssociatedSymbolInTargetAST(associatedEnumDeclaration_original,targetScope);
18783 if (symbol == NULL)
18784 {
18785 // debug this case.
18786 enumVal_original->get_file_info()->display("case V_SgEnumVal: symbol == NULL: debug");
18787 }
18788 ROSE_ASSERT(symbol != NULL);
18789 SgEnumSymbol* enumSymbol = isSgEnumSymbol(symbol);
18790 ROSE_ASSERT(enumSymbol != NULL);
18791 SgEnumDeclaration* new_associatedEnumDeclaration_copy = enumSymbol->get_declaration();
18792 ROSE_ASSERT(new_associatedEnumDeclaration_copy != NULL);
18793
18794 // If this is false then in means that we should have built a new SgEnumSymbol instead of reusing the existing one from the snippet.
18795 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
18796 // ROSE_ASSERT(new_associatedEnumDeclaration_copy != associatedEnumDeclaration_original->get_firstNondefiningDeclaration());
18797 ROSE_ASSERT(new_associatedEnumDeclaration_copy != associatedEnumDeclaration_original->get_definingDeclaration());
18798
18799 enumVal_copy->set_declaration(new_associatedEnumDeclaration_copy);
18800#if 0
18801 printf ("Exiting as a test! \n");
18802 ROSE_ABORT();
18803#endif
18804 }
18805 }
18806 else
18807 {
18808 // DQ (4/13/2014): I think we all agreed these would not have to be handled, so issue a warning.
18809 // It still is likely that I can allow this, but permit this intermediate fix.
18810 printf ("Warning: can't handle enum values from unnamed enum declarations \n");
18811 printf (" --- enumVal_original = %p = %lld name = %s \n",enumVal_original,enumVal_original->get_value(),enumVal_original->get_name().str());
18812 }
18813
18814 break;
18815 }
18816
18817 default:
18818 {
18819 // Most IR nodes do not require specialized fixup (are not processed).
18820 }
18821 }
18822
18823#if 1
18824 // DQ (3/17/2014): Cause failure on warnings about any constructs referencing the snippet AST.
18825#if 0
18826 // Assert fail on warnings.
18827 errorCheckingTargetAST(node_copy,node_original,targetFile, true);
18828#else
18829 // Cause only warnings.
18830 errorCheckingTargetAST(node_copy,node_original,targetFile, false);
18831#endif
18832#endif
18833 }
18834
18835
18836void
18838 SgStatement *toInsert, SgStatement* original_before_copy)
18839 {
18840 // The semantics of the copy is that it will have been disconnected from the snippet AST in a few ways,
18841 // Namely the root of the copy of the snippet's AST will have been set with a NULL parent, and then
18842 // the parent would have been reset when the copy of the snippet was inserted into the target AST.
18843 // So a simple traversal of parents back to the SgFile will return the target AST's SgFile (confirmed below).
18844
18845 ROSE_ASSERT(insertionPoint != NULL);
18846 ROSE_ASSERT(toInsert != NULL);
18847 ROSE_ASSERT(original_before_copy != NULL);
18848
18849 // DQ (3/30/2014): Turn this on to support finding symbols in base classes (in Java).
18850 // Will be turned off at the base of this function (since we only only want to use it for the AST fixup, currently).
18851 SgSymbolTable::set_force_search_of_base_classes(true);
18852
18853 // DQ (3/4/2014): Switch to using the SageInterface function.
18854 // SgFile* targetFile = TransformationSupport::getFile(insertionPoint);
18855 SgFile* targetFile = getEnclosingFileNode(insertionPoint);
18856
18857 // For Java support this might be NULL, if the insertion point was in global scope.
18858 ROSE_ASSERT(targetFile != NULL);
18859
18860 // SgFile* snippetFile_of_copy = TransformationSupport::getFile(toInsert);
18861 SgFile* snippetFile_of_copy = getEnclosingFileNode(toInsert);
18862
18863 // At this point the parent pointers are set so that the same SgFile is found via a traversal back to the SgProject.
18864 // Confirm that the SgFile found by a traversal of parents in the copy of rthe snippet's AST will return that of the
18865 // SgFile for the target AST. This also confirms that the copy of the snippet has already been inserted into the
18866 // target AST.
18867 ROSE_ASSERT(snippetFile_of_copy == targetFile);
18868
18869 // SgFile* snippetFile_of_original = TransformationSupport::getFile(original_before_copy);
18870 SgFile* snippetFile_of_original = getEnclosingFileNode(original_before_copy);
18871
18872 ROSE_ASSERT(snippetFile_of_original != targetFile);
18873
18874#if 0
18875 printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18876 printf (" --- snippetFile_of_copy = %p = %s \n",snippetFile_of_copy,snippetFile_of_copy->get_sourceFileNameWithPath().c_str());
18877 printf (" --- snippetFile_of_original = %p = %s \n",snippetFile_of_original,snippetFile_of_original->get_sourceFileNameWithPath().c_str());
18878#endif
18879
18880 // Any node that has entries not referenced in the target file needs to be fixed up.
18881 // We can assume that any referenced variable or function that is referenced in the
18882 // snippet will exist in either the snippet or the target file.
18883
18884 // DQ (3/4/2014): This is a test of the structural equality of the original snippet and it's copy.
18885 // If they are different then we can't support fixing up the AST. Transformations on the snippet
18886 // should have been made after insertion into the AST. The complexity of this test is a traversal
18887 // of the copy of the snippet to be inserted (typically very small compared to the target application).
18888 bool isStructurallyEquivalent = isStructurallyEquivalentAST(toInsert,original_before_copy);
18889 if (isStructurallyEquivalent == false)
18890 {
18891 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");
18892 return;
18893 }
18894 ROSE_ASSERT(isStructurallyEquivalent == true);
18895
18896#ifndef USE_CMAKEx
18897 // DQ (3/8/2014): Make this conditionally compiled based on when CMake is not used because the libraries are not configured yet.
18898
18899 // This is AST container for the ROSE AST that will provide an iterator.
18900 // We want two iterators (one for the copy of the snippet and one for the
18901 // original snippet so that we can query the original snippet's AST
18902 // as we process each IR node of the AST for the copy of the snippet.
18903 // Only the copy of the snippet is inserted into the target AST.
18904 RoseAst ast_of_copy(toInsert);
18905 RoseAst ast_of_original(original_before_copy);
18906
18907 // printf ("ast_of_copy.size() = %" PRIuPTR " \n",ast_of_copy.size());
18908
18909 // Build the iterators so that we can increment thorugh both ASTs one IR node at a time.
18910 RoseAst::iterator i_copy = ast_of_copy.begin();
18911 RoseAst::iterator i_original = ast_of_original.begin();
18912
18913 // Iterate of the copy of the snippet's AST.
18914 while (i_copy != ast_of_copy.end())
18915 {
18916 // DQ (2/28/2014): This is a problem for some of the test codes (TEST store/load heap string [test7a] and [test7a])
18917 // ROSE_ASSERT((*i_copy)->variantT() == (*i_original)->variantT());
18918 if ((*i_copy)->variantT() != (*i_original)->variantT())
18919 {
18920 printf ("ERROR: return from fixupCopyOfAstFromSeparateFileInNewTargetAst(): "
18921 "(*i_copy)->variantT() != (*i_original)->variantT() \n");
18922#if 1
18923 printf ("Making this an error! \n");
18924 ROSE_ABORT();
18925#endif
18926 return;
18927 }
18928
18929 // Operate on individual IR nodes.
18930 fixupCopyOfNodeFromSeparateFileInNewTargetAst(insertionPoint, insertionPointIsScope, *i_copy, *i_original);
18931
18932 i_copy++;
18933
18934 // Verify that we have not reached the end of the ast for the original (both the
18935 // copy and the original are the same structurally, and thus the same size).
18936 ROSE_ASSERT(i_original != ast_of_original.end());
18937 i_original++;
18938 }
18939
18940 // We have reached the end of both ASTs.
18941 ROSE_ASSERT(i_copy == ast_of_copy.end() && i_original == ast_of_original.end());
18942
18943 // DQ (3/8/2014): ENDIF: Make this conditionally compiled based on when CMake is not used because the libraries are not configured yet.
18944#endif
18945
18946#if 0
18947 if (functionDeclaration != NULL)
18948 {
18949 printf ("functionDeclaration = %s \n",functionDeclaration->get_name().str());
18950#if 0
18951 printf ("Exiting as a test! \n");
18952 ROSE_ABORT();
18953#endif
18954 }
18955#endif
18956
18957 // DQ (3/30/2014): Turn this off (since we only only want to use it for the AST fixup, currently).
18958 SgSymbolTable::set_force_search_of_base_classes(false);
18959 }
18960
18961// Liao 9/18/2015
18962// The parser is implemented in
18963// src/frontend/SageIII/astFromString/AstFromString.h .C
18965{
18966
18967 SgStatement* result = NULL;
18968 ROSE_ASSERT (scope != NULL);
18969 // set input and context for the parser
18970 AstFromString::c_char = s.c_str();
18971 ROSE_ASSERT(AstFromString::c_char== s.c_str());
18974
18976 {
18977 result = isSgStatement(AstFromString::c_parsed_node); // grab the result
18978 ROSE_ASSERT(result != NULL);
18979 }
18980 else
18981 {
18982 cerr<<"Error. buildStatementFromString() cannot parse the input string:"<<s
18983 <<"\n\t within the given scope:"<<scope->class_name() <<endl;
18984 ROSE_ABORT();
18985 }
18986 return result;
18987}
18988
18998
18999//
19000// pp (07/16/16)
19001// initial support for creating template instantiations
19002// from template declarations
19003
19004namespace {
19005 // internal functions
19006
19007 template <class SgAstNode>
19008 SgTemplateArgument* createTemplateArg_(SgAstNode& n)
19009 {
19010 static const bool explicitlySpecified = true;
19011
19012 return new SgTemplateArgument(&n, explicitlySpecified);
19013 }
19014
19015 SgTemplateArgument* createTemplateArg_(SgExpression& n)
19016 {
19017 SgTemplateArgument* res = createTemplateArg_<SgExpression>(n);
19018
19019 n.set_parent(res);
19020 return res;
19021 }
19022
19023 SgTemplateArgument* createTemplateArg(SgNode& n)
19024 {
19025 SgTemplateArgument* res = NULL;
19026
19027 if (isSgType(&n))
19028 res = createTemplateArg_(*isSgType(&n));
19029 else if (isSgExpression(&n))
19030 res = createTemplateArg_(*isSgExpression(&n));
19031 else
19032 {
19033 ROSE_ASSERT(isSgTemplateDeclaration(&n));
19034 res = createTemplateArg_(*isSgTemplateDeclaration(&n));
19035 }
19036
19037 ROSE_ASSERT(res);
19038 return res;
19039 }
19040#if 0
19041 SgName genTemplateName(SgName base, Rose_STL_Container<SgNode*>& targs)
19042 {
19043 Rose_STL_Container<SgNode*>::iterator aa = targs.begin();
19044 Rose_STL_Container<SgNode*>::iterator zz = targs.begin();
19045 std::string name(base.getString());
19046
19047 name.append("<");
19048 for ( ; aa != zz; ++aa) name.append((*aa)->unparseToString());
19049 name.append(">");
19050
19051 return SgName(name);
19052 }
19053#endif
19054 SgTemplateArgumentPtrList genTemplateArgumentList(Rose_STL_Container<SgNode*>& targs)
19055 {
19056 Rose_STL_Container<SgNode*>::iterator aa = targs.begin();
19057 Rose_STL_Container<SgNode*>::iterator zz = targs.begin();
19058 SgTemplateArgumentPtrList lst;
19059
19060 for ( ; aa != zz; ++aa)
19061 {
19062 lst.push_back(createTemplateArg(**aa));
19063 }
19064
19065 return lst;
19066 }
19067
19068 SgTemplateClassDeclaration* getCanonicalTemplateDecl(SgTemplateClassDeclaration* main_decl)
19069 {
19070 ROSE_ASSERT(main_decl);
19071 SgClassType* ct = main_decl->get_type();
19072 ROSE_ASSERT(ct);
19073 SgDeclarationStatement* decl = ct->get_declaration();
19074 SgTemplateClassDeclaration* tdecl = isSgTemplateClassDeclaration(decl);
19075
19076 ROSE_ASSERT(tdecl);
19077 return tdecl;
19078 }
19079
19080 SgTemplateInstantiationDecl* genTemplateInstantiationDecl(SgName tname, SgTemplateClassDeclaration* tclassdecl, SgTemplateArgumentPtrList targs)
19081 {
19082 ROSE_ASSERT(tclassdecl);
19083
19084 SgTemplateInstantiationDecl* res = NULL;
19085
19086 res = new SgTemplateInstantiationDecl( tname,
19088 NULL /* SgClassType* type -- to be set later */,
19089 NULL /* SgClassDefinition* def -- to be set later */,
19090 tclassdecl,
19091 targs
19092 );
19093
19094 res->set_scope(tclassdecl->get_scope());
19095 res->set_templateName(tname); // \todo \pp create mangled name from tname
19097 res->setForward(); // \pp set forward, since this is not a proper declaration
19098 return res;
19099 }
19100
19101 SgClassType* genTemplateClass(SgTemplateInstantiationDecl* tdecl)
19102 {
19103 ROSE_ASSERT(tdecl);
19104
19105 return SgClassType::createType(tdecl);
19106 }
19107
19108 struct TemplateArgumentParentSetter
19109 {
19111
19112 TemplateArgumentParentSetter(SgTemplateInstantiationDecl* p)
19113 : parent(p)
19114 {}
19115
19116 void operator()(SgTemplateArgument* targ)
19117 {
19118 targ->set_parent(parent);
19119 }
19120 };
19121} /* anonymous namespace */
19122
19123
19126Rose_STL_Container<SgNode *>& template_args)
19127{
19128 return buildClassTemplateType (template_decl,template_args);
19129}
19130
19133Rose_STL_Container<SgNode *>& template_args)
19134{
19135 ROSE_ASSERT(template_decl);
19136
19137 // create a template instantiation decl
19138 SgName name = template_decl->get_name();
19139 // SgName tname = genTemplateName(, template_args);
19140 SgTemplateArgumentPtrList targs = genTemplateArgumentList(template_args);
19141 SgTemplateClassDeclaration* tdecl = getCanonicalTemplateDecl(template_decl);
19142 SgTemplateInstantiationDecl* tinst = genTemplateInstantiationDecl(name, tdecl, targs);
19143 ROSE_ASSERT(tinst);
19144
19145 // create class type
19146 SgClassType* tclass = genTemplateClass(tinst);
19147 ROSE_ASSERT(tclass);
19148
19149 // set remaining fields in the template instantiation decl
19150 tinst->set_type(tclass);
19151 tinst->set_definition(static_cast<SgTemplateInstantiationDefn*>(0)); /* \pp not sure what to set this to .. */
19152
19153 // set parent of template arguments
19154 std::for_each(targs.begin(), targs.end(), TemplateArgumentParentSetter(tinst)); //
19155
19156 return tclass;
19157}
19158
19159//-----------------------------------------------------------------------------
19160#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
19161//-----------------------------------------------------------------------------
19162
19167 ROSE_ASSERT(Rose::Frontend::Java::lengthSymbol);
19168 SgVarRefExp *var_ref = SageBuilder::buildVarRefExp(Rose::Frontend::Java::lengthSymbol);
19170 return var_ref;
19171}
19172
19177 SgScopeStatement *scope = new SgScopeStatement();
19179 if (parent_scope != NULL) {
19180 scope -> set_parent(parent_scope);
19181 }
19182 return scope;
19183}
19184
19191 return expr;
19192}
19193
19198 SgJavaMarkerAnnotation *annotation = new SgJavaMarkerAnnotation(type);
19200 return annotation;
19201}
19202
19209 pair -> set_name(name);
19210 pair -> set_value(value);
19211 value -> set_parent(pair);
19212 return pair;
19213}
19214
19219 SgJavaSingleMemberAnnotation *annotation = new SgJavaSingleMemberAnnotation(type, value);
19221 return annotation;
19222}
19223
19228 SgJavaNormalAnnotation *annotation = new SgJavaNormalAnnotation(type);
19230 return annotation;
19231}
19232
19236SgJavaNormalAnnotation *SageBuilder::buildJavaNormalAnnotation(SgType *type, list<SgJavaMemberValuePair *>& pair_list) {
19238 for (std::list<SgJavaMemberValuePair *>::iterator i = pair_list.begin(); i != pair_list.end(); i++) {
19239 SgJavaMemberValuePair *member_value_pair = *i;
19240 member_value_pair -> set_parent(annotation);
19241 annotation -> append_value_pair(member_value_pair);
19242 }
19243 return annotation;
19244}
19245
19246
19250SgInitializedName *SageBuilder::buildJavaFormalParameter(SgType *argument_type, const SgName &argument_name, bool is_var_args, bool is_final) {
19251 SgInitializedName *initialized_name = NULL;
19252 if (is_var_args) {
19253 initialized_name = SageBuilder::buildInitializedName(argument_name, SageBuilder::getUniqueJavaArrayType(argument_type, 1), NULL);
19254 initialized_name -> setAttribute("var_args", new AstRegExAttribute(""));
19255 }
19256 else {
19257 initialized_name = SageBuilder::buildInitializedName(argument_name, argument_type, NULL);
19258 }
19259 SageInterface::setSourcePosition(initialized_name);
19260 if (is_final) {
19261 initialized_name -> setAttribute("final", new AstRegExAttribute(""));
19262 }
19263
19264 return initialized_name;
19265}
19266
19271 SgJavaPackageStatement *package_statement = new SgJavaPackageStatement(package_name);
19272 SageInterface::setSourcePosition(package_statement);
19273 package_statement -> set_firstNondefiningDeclaration(package_statement);
19274 package_statement -> set_definingDeclaration(package_statement);
19275 return package_statement;
19276}
19277
19281SgJavaImportStatement *SageBuilder::buildJavaImportStatement(string import_info, bool contains_wildcard) {
19282 SgJavaImportStatement *import_statement = new SgJavaImportStatement(import_info, contains_wildcard);
19283 SageInterface::setSourcePosition(import_statement);
19284 import_statement -> set_firstNondefiningDeclaration(import_statement);
19285 import_statement -> set_definingDeclaration(import_statement);
19286 return import_statement;
19287}
19288
19293 ROSE_ASSERT(scope);
19294 SgName class_name = name;
19295 ROSE_ASSERT(scope -> lookup_class_symbol(class_name) == NULL);
19296
19297 SgClassDeclaration* nonDefiningDecl = NULL;
19298 bool buildTemplateInstantiation = false;
19299 SgTemplateArgumentPtrList* templateArgumentsList = NULL;
19300 SgClassDeclaration *class_declaration = SageBuilder::buildClassDeclaration_nfi(class_name, kind, scope, nonDefiningDecl, buildTemplateInstantiation, templateArgumentsList);
19301 ROSE_ASSERT(class_declaration);
19302 class_declaration -> set_parent(scope);
19303 class_declaration -> set_scope(scope);
19304 SageInterface::setSourcePosition(class_declaration);
19305 SgClassDefinition *class_definition = class_declaration -> get_definition();
19306 ROSE_ASSERT(class_definition);
19307 SageInterface::setSourcePosition(class_definition);
19308
19309 class_definition -> setAttribute("extensions", new AstSgNodeListAttribute());
19310 class_definition -> setAttribute("extension_type_names", new AstRegExAttribute());
19311
19312 SgScopeStatement *type_space = new SgScopeStatement();
19313 type_space -> set_parent(class_definition);
19315 class_declaration -> setAttribute("type_space", new AstSgNodeAttribute(type_space));
19316
19317 return class_declaration;
19318}
19319
19320
19325SgSourceFile *SageBuilder::buildJavaSourceFile(SgProject *project, string directory_name, SgClassDefinition *package_definition, string type_name) {
19326 string filename = directory_name + "/" + type_name + ".java";
19327 ROSE_ASSERT((*project)[filename] == NULL); // does not already exist!
19328
19329 string command = string("touch ") + filename; // create the file
19330 int status = system(command.c_str());
19331 ROSE_ASSERT(status == 0);
19332 project -> get_sourceFileNameList().push_back(filename);
19333 Rose_STL_Container<std::string> arg_list = project -> get_originalCommandLineArgumentList();
19334 arg_list.push_back(filename);
19335 Rose_STL_Container<string> fileList = CommandlineProcessing::generateSourceFilenames(arg_list, // binaryMode
19336 false);
19337 CommandlineProcessing::removeAllFileNamesExcept(arg_list, fileList, filename);
19338 int error_code = 0;
19339 SgFile *file = determineFileType(arg_list, error_code, project);
19340 SgSourceFile *sourcefile = isSgSourceFile(file);
19341 ROSE_ASSERT(sourcefile);
19342 sourcefile -> set_parent(project);
19343 project -> get_fileList_ptr() -> get_listOfFiles().push_back(sourcefile);
19344 ROSE_ASSERT(sourcefile == isSgSourceFile((*project)[filename]));
19345
19346 //
19347 // Create a package statement and add it to the source file
19348 //
19349 SgClassDeclaration* pkgDefDecl = package_definition->get_declaration();
19350 ROSE_ASSERT(pkgDefDecl != NULL);
19351 SgJavaPackageStatement *package_statement = SageBuilder::buildJavaPackageStatement(pkgDefDecl->get_qualified_name().getString());
19352 package_statement->set_parent(package_definition);
19353 sourcefile->set_package(package_statement);
19354
19355 //
19356 // Initialize an import-list for the sourcefile
19357 //
19358 SgJavaImportStatementList *import_statement_list = new SgJavaImportStatementList();
19359 import_statement_list -> set_parent(sourcefile);
19360 sourcefile -> set_import_list(import_statement_list);
19361
19362 //
19363 // Initialize a class-declaration-list for the sourcefile
19364 //
19365 SgJavaClassDeclarationList *class_declaration_list = new SgJavaClassDeclarationList();
19366 class_declaration_list -> set_parent(package_definition);
19367 sourcefile -> set_class_list(class_declaration_list);
19368
19369 return sourcefile;
19370}
19371
19372
19376SgArrayType *SageBuilder::getUniqueJavaArrayType(SgType *base_type, int num_dimensions) {
19377 ROSE_ASSERT(num_dimensions > 0);
19378 if (num_dimensions > 1) {
19379 base_type = getUniqueJavaArrayType(base_type, num_dimensions - 1);
19380 }
19381
19382 ROSE_ASSERT(base_type != NULL);
19383 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) base_type -> getAttribute("array");
19384 if (attribute == NULL) {
19385 SgArrayType *array_type = SageBuilder::buildArrayType(base_type);
19386 array_type -> set_rank(num_dimensions);
19387 attribute = new AstSgNodeAttribute(array_type);
19388 base_type -> setAttribute("array", attribute);
19389 }
19390
19391 return isSgArrayType(attribute -> getNode());
19392}
19393
19394
19398SgJavaParameterizedType *SageBuilder::getUniqueJavaParameterizedType(SgNamedType *generic_type, SgTemplateParameterPtrList *new_args) {
19399 AstParameterizedTypeAttribute *attribute = (AstParameterizedTypeAttribute *) generic_type -> getAttribute("parameterized types");
19400 if (! attribute) {
19401 attribute = new AstParameterizedTypeAttribute(generic_type);
19402 generic_type -> setAttribute("parameterized types", attribute);
19403 }
19404 ROSE_ASSERT(attribute);
19405
19406 return attribute -> findOrInsertParameterizedType(new_args);
19407}
19408
19409
19414 AstSgNodeListAttribute *attribute = (AstSgNodeListAttribute *) type -> getAttribute("qualified types");
19415 if (! attribute) {
19416 attribute = new AstSgNodeListAttribute();
19417 type -> setAttribute("qualified types", attribute);
19418 }
19419 ROSE_ASSERT(attribute);
19420
19421 for (int i = 0; i < attribute -> size(); i++) {
19422 SgJavaQualifiedType *qualified_type = isSgJavaQualifiedType(attribute -> getNode(i));
19423 ROSE_ASSERT(qualified_type);
19424 if (qualified_type -> get_parent_type() == parent_type && qualified_type -> get_type() == type) {
19425 return qualified_type;
19426 }
19427 }
19428
19429 SgJavaQualifiedType *qualified_type = new SgJavaQualifiedType(class_declaration);
19430 qualified_type -> set_parent_type(parent_type);
19431 qualified_type -> set_type(type);
19432
19433 attribute -> addNode(qualified_type);
19434
19435 return qualified_type;
19436}
19437
19438
19444 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) Rose::Frontend::Java::ObjectClassType -> getAttribute("unbound");
19445 if (! attribute) {
19446 SgClassDeclaration *class_declaration = isSgClassDeclaration(Rose::Frontend::Java::ObjectClassType -> get_declaration());
19447 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration());
19448 attribute = new AstSgNodeAttribute(wildcard);
19449 Rose::Frontend::Java::ObjectClassType -> setAttribute("unbound", attribute);
19450 }
19451
19452 return isSgJavaWildcardType(attribute -> getNode());
19453}
19454
19455
19460 ROSE_ASSERT(type);
19461 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) type -> getAttribute("extends");
19462 if (! attribute) {
19463 SgArrayType *array_type = isSgArrayType(type);
19464 SgNamedType *named_type = isSgNamedType(type);
19465 ROSE_ASSERT(array_type || named_type);
19466 SgClassDeclaration *class_declaration = isSgClassDeclaration((array_type ? (SgNamedType *) Rose::Frontend::Java::ObjectClassType : named_type) -> get_declaration());
19467 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration(), type);
19468
19469 wildcard -> set_has_extends(true);
19470
19471 attribute = new AstSgNodeAttribute(wildcard);
19472 type -> setAttribute("extends", attribute);
19473 }
19474
19475 return isSgJavaWildcardType(attribute -> getNode());
19476}
19477
19478
19483 ROSE_ASSERT(type);
19484 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) type -> getAttribute("super");
19485 if (! attribute) {
19486 SgArrayType *array_type = isSgArrayType(type);
19487 SgNamedType *named_type = isSgNamedType(type);
19488 ROSE_ASSERT(array_type || named_type);
19489 SgClassDeclaration *class_declaration = isSgClassDeclaration((array_type ? (SgNamedType *) Rose::Frontend::Java::ObjectClassType : named_type) -> get_declaration());
19490 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration(), type);
19491
19492 wildcard -> set_has_super(true);
19493
19494 attribute = new AstSgNodeAttribute(wildcard);
19495 type -> setAttribute("super", attribute);
19496 }
19497
19498 return isSgJavaWildcardType(attribute -> getNode());
19499}
19500
19501
19502//-----------------------------------------------------------------------------
19503#endif // ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
19504//-----------------------------------------------------------------------------
19505
19506
19507namespace Rose {
19508 namespace Builder {
19509 namespace Templates {
19510
19511SgTemplateArgument * buildTemplateArgument(SgType * t) {
19512 if (t == nullptr) return nullptr;
19513 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::type_argument, false, t, nullptr, nullptr);
19514 return r;
19515}
19516
19517SgTemplateArgument * buildTemplateArgument(SgExpression * e) {
19518 if (e == nullptr) return nullptr;
19519 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
19520 e->set_parent(r);
19521 return r;
19522}
19523
19524SgTemplateArgument * buildTemplateArgument(int v) {
19526 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
19527 e->set_parent(r);
19528 return r;
19529}
19530
19531SgTemplateArgument * buildTemplateArgument(bool v) {
19533 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
19534 e->set_parent(r);
19535 return r;
19536}
19537
19538std::string strTemplateArgument(int v) {
19539 std::ostringstream oss;
19540 oss << v;
19541 return oss.str();
19542}
19543
19544std::string strTemplateArgument(bool v) {
19545 std::ostringstream oss;
19546 if (v) oss << "true";
19547 else oss << "false";
19548 return oss.str();
19549}
19550
19551std::string strTemplateArgument(SgNamedType * nt) {
19552 std::ostringstream oss;
19553 oss << nt->get_qualified_name().getString();
19554 return oss.str();
19555}
19556
19557std::string strTemplateArgument(SgType * t) {
19558 std::ostringstream oss;
19559 oss << t->unparseToString();
19560 return oss.str();
19561}
19562
19563std::string strTemplateArgument(SgExpression * e) {
19564 std::ostringstream oss;
19565 oss << e->unparseToString();
19566 return oss.str();
19567}
19568
19569#define DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps 0
19570
19571SgExpression * instantiateNonrealRefExps(
19572 SgExpression * expr,
19573 std::vector<std::vector<SgTemplateParameter *>> & tpl_params,
19574 std::vector<std::vector<SgTemplateArgument *>> & tpl_args
19575) {
19576#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19577 std::cout << "Rose::Builder::Templates::instantiateNonrealRefExps" << std::endl;
19578 std::cout << " expr = " << std::hex << expr << " : " << ( expr ? expr->class_name() : "" ) << std::endl;
19579 std::cout << " = " << ( expr ? expr->unparseToString() : "" ) << std::endl;
19580#endif
19581 if (!expr) {
19582 return nullptr;
19583 } else if (isSgNonrealRefExp(expr)) {
19584#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19585 std::cerr << "Error: In instantiateNonrealRefExps: case of a SgNonrealRefExp!!!" << std::endl;
19586#endif
19587 return nullptr;
19588 } else if (isSgVarRefExp(expr)) {
19589 SgVarRefExp * vref = (SgVarRefExp*)expr;
19590 SgInitializedName * iname = vref->get_symbol()->get_declaration();
19591 ROSE_ASSERT(iname);
19592#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19593 std::cout << " iname = " << std::hex << iname << " : " << ( iname ? iname->class_name() : "" ) << std::endl;
19594 std::cout << " iname->get_name() = " << iname->get_name() << std::endl;
19595 std::cout << " iname->get_initializer() = " << std::hex << iname->get_initializer() << " : " << ( iname->get_initializer() ? iname->get_initializer()->class_name() : "" ) << std::endl;
19596 std::cout << " iname->get_parent() = " << std::hex << iname->get_parent() << " : " << ( iname->get_parent() ? iname->get_parent()->class_name() : "" ) << std::endl;
19597#endif
19598
19599 unsigned depth = 0;
19600 unsigned pos = 0;
19601 for (auto tpl_params_: tpl_params) {
19602 pos = 0;
19603 for (auto tpl_param: tpl_params_) {
19604 if (tpl_param->get_initializedName()) {
19605#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19606 std::cout << " tpl_param->get_initializedName() = " << std::hex << tpl_param->get_initializedName() << std::endl;
19607 std::cout << " tpl_param->get_initializedName()->get_name() = " << tpl_param->get_initializedName()->get_name() << std::endl;
19608#endif
19609 if (tpl_param->get_initializedName()->get_name() == iname->get_name()) {
19610 iname = tpl_param->get_initializedName();
19611 break;
19612 }
19613 }
19614 pos++;
19615 }
19616 depth++;
19617 }
19618
19619 if (depth < tpl_args.size() && pos < tpl_args[depth].size()) {
19620 SgExpression * res = tpl_args[depth][pos]->get_expression();
19621 ROSE_ASSERT(res);
19622 return res;
19623 } else if (depth < tpl_params.size() && pos < tpl_params[depth].size()) {
19624 SgExpression * dft = tpl_params[depth][pos]->get_defaultExpressionParameter();
19625 ROSE_ASSERT(dft);
19626 dft = instantiateNonrealRefExps(dft, tpl_params, tpl_args);
19627 ROSE_ASSERT(dft);
19628 return dft;
19629 }
19630#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19631 std::cerr << "Error: In instantiateNonrealRefExps: this should not be reached!!!" << std::endl;
19632#endif
19633 return vref;
19634 } else if (isSgValueExp(expr)) {
19635 return expr;
19636 } else if (isSgConditionalExp(expr)) {
19637 SgConditionalExp * cond = (SgConditionalExp*)expr;
19638 cond->set_conditional_exp(instantiateNonrealRefExps(cond->get_conditional_exp(), tpl_params, tpl_args));
19639 cond->set_true_exp(instantiateNonrealRefExps(cond->get_true_exp(), tpl_params, tpl_args));
19640 cond->set_false_exp(instantiateNonrealRefExps(cond->get_false_exp(), tpl_params, tpl_args));
19641 return cond;
19642 } else if (isSgSizeOfOp(expr)) {
19643 SgSizeOfOp * szo = (SgSizeOfOp*)expr;
19644#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19645 std::cout << " szo->get_operand_expr() = " << std::hex << szo->get_operand_expr() << " : " << ( szo->get_operand_expr() ? szo->get_operand_expr()->class_name() : "" ) << std::endl;
19646 std::cout << " szo->get_operand_type() = " << std::hex << szo->get_operand_type() << " : " << ( szo->get_operand_type() ? szo->get_operand_type()->class_name() : "" ) << std::endl;
19647#endif
19648 SgExpression * eres = instantiateNonrealRefExps(szo->get_operand_expr(), tpl_params, tpl_args);
19649 ROSE_ASSERT(szo->get_operand_expr() == nullptr || eres != nullptr);
19650 szo->set_operand_expr(eres);
19651
19652 SgType * tres = instantiateNonrealTypes(szo->get_operand_type(), tpl_params, tpl_args);
19653 ROSE_ASSERT(szo->get_operand_type() == nullptr || tres != nullptr);
19654 szo->set_operand_type(tres);
19655
19656#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19657 std::cout << " szo->get_operand_expr() = " << std::hex << szo->get_operand_expr() << " : " << ( szo->get_operand_expr() ? szo->get_operand_expr()->class_name() : "" ) << std::endl;
19658 std::cout << " szo->get_operand_type() = " << std::hex << szo->get_operand_type() << " : " << ( szo->get_operand_type() ? szo->get_operand_type()->class_name() : "" ) << std::endl;
19659#endif
19660 return szo;
19661 } else if (isSgCastExp(expr)) {
19662 SgCastExp * cast = (SgCastExp*)expr;
19663 auto operand = instantiateNonrealRefExps(cast->get_operand_i(), tpl_params, tpl_args);
19664 if (operand == nullptr) return nullptr;
19665 auto type = instantiateNonrealTypes(cast->get_type(), tpl_params, tpl_args);
19666 if (type == nullptr) return operand;
19667 cast->set_operand_i(operand);
19668 cast->set_type(type);
19669 return cast;
19670 } else if (isSgUnaryOp(expr)) {
19671 SgUnaryOp * uop = (SgUnaryOp*)expr;
19672 uop->set_operand_i(instantiateNonrealRefExps(uop->get_operand_i(), tpl_params, tpl_args));
19673 return uop;
19674 } else if (isSgBinaryOp(expr)) {
19675 SgBinaryOp * bop = (SgBinaryOp*)expr;
19676 bop->set_lhs_operand_i(instantiateNonrealRefExps(bop->get_lhs_operand_i(), tpl_params, tpl_args));
19677 bop->set_rhs_operand_i(instantiateNonrealRefExps(bop->get_rhs_operand_i(), tpl_params, tpl_args));
19678 return bop;
19679 } else {
19680 std::cerr << "!!! expr = " << std::hex << expr << " : " << ( expr ? expr->class_name() : "" ) << std::endl;
19681 ROSE_ABORT();
19682 }
19683}
19684
19685SgExpression * instantiateNonrealRefExps(
19686 SgExpression * expr,
19687 std::vector<SgTemplateParameter *> & tpl_params,
19688 std::vector<SgTemplateArgument *> & tpl_args
19689) {
19690 std::vector<std::vector<SgTemplateParameter *>> tpl_params_{tpl_params};
19691 std::vector<std::vector<SgTemplateArgument *>> tpl_args_{tpl_args};
19692 return instantiateNonrealRefExps(expr, tpl_params_, tpl_args_);
19693}
19694
19695#define DEBUG_Rose_Builder_Templates_instantiateNonrealTypes 0
19696
19697SgType * instantiateNonrealTypes(
19698 SgType * type,
19699 std::vector<std::vector<SgTemplateParameter *>> & tpl_params,
19700 std::vector<std::vector<SgTemplateArgument *>> & tpl_args
19701) {
19702#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19703 std::cout << "Rose::Builder::Templates::instantiateNonrealTypes" << std::endl;
19704 std::cout << " type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
19705 std::cout << " = " << ( type ? type->unparseToString() : "" ) << std::endl;
19706#endif
19707 if (!type) {
19708 return nullptr;
19709 } else if (isSgNonrealType(type)) {
19710 SgNonrealType * nrtype = (SgNonrealType*)type;
19711 SgNonrealDecl * nrdecl = isSgNonrealDecl(nrtype->get_declaration());
19712 ROSE_ASSERT(nrdecl != nullptr);
19713#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19714 std::cout << " nrdecl = " << std::hex << nrdecl << " : " << nrdecl->class_name() << std::endl;
19715 std::cout << " ->get_qualified_name() = " << nrdecl->get_qualified_name().getString() << std::endl;
19716// std::cout << " ->unparseToString() = " << nrdecl->unparseToString() << std::endl;
19717 std::cout << " ->get_tpl_args() = " << std::dec << nrdecl->get_tpl_args().size() << std::endl;
19718 std::cout << " ->get_tpl_params() = " << std::dec << nrdecl->get_tpl_params().size() << std::endl;
19719 std::cout << " ->get_is_class_member() = " << ( nrdecl->get_is_class_member() ? "true" : "false" ) << std::endl;
19720 std::cout << " ->get_is_template_param() = " << ( nrdecl->get_is_template_param() ? "true" : "false" ) << std::endl;
19721 std::cout << " ->get_is_template_template_param() = " << ( nrdecl->get_is_template_template_param() ? "true" : "false" ) << std::endl;
19722 std::cout << " ->get_is_nonreal_template() = " << ( nrdecl->get_is_nonreal_template() ? "true" : "false" ) << std::endl;
19723 std::cout << " ->get_is_nonreal_function() = " << ( nrdecl->get_is_nonreal_function() ? "true" : "false" ) << std::endl;
19724#endif
19725 SgDeclarationStatement * tpldecl = nrdecl->get_templateDeclaration();
19726 if (tpldecl != nullptr) {
19727#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19728 std::cout << " tpldecl = " << std::hex << tpldecl << " : " << tpldecl->class_name() << std::endl;
19729#endif
19730
19731 SgTemplateClassDeclaration * xtpldecl = isSgTemplateClassDeclaration(tpldecl);
19732 if (xtpldecl != nullptr) {
19733#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19734 std::cout << " xtpldecl->get_name() = " << xtpldecl->get_name() << std::endl;
19735#endif
19736 std::vector<SgTemplateArgument *> inst_tpl_args;
19737 for (SgTemplateArgument * tplarg: nrdecl->get_tpl_args()) {
19738#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19739 std::cout << " tplarg = " << std::hex << tplarg << " : " << ( tplarg ? tplarg->class_name() : "" ) << std::endl;
19740 std::cout << " ->get_argumentType() = " << tplarg->get_argumentType() << std::endl;
19741#endif
19742 switch (tplarg->get_argumentType()) {
19744#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19745 std::cout << " tplarg->get_type() = " << std::hex << tplarg->get_type() << " : " << ( tplarg->get_type() ? tplarg->get_type()->class_name() : "" ) << std::endl;
19746#endif
19747 auto inst_tplarg = instantiateNonrealTypes(tplarg->get_type(), tpl_params, tpl_args);
19748 if (inst_tplarg)
19749 inst_tpl_args.push_back(buildTemplateArgument(inst_tplarg));
19750 break;
19751 }
19753#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19754 std::cout << " tplarg->get_expression() = " << std::hex << tplarg->get_expression() << " : " << ( tplarg->get_expression() ? tplarg->get_expression()->class_name() : "" ) << std::endl;
19755 std::cout << " ->unparseToString() = " << tplarg->get_expression()->unparseToString() << std::endl;
19756#endif
19757 auto inst_tplarg = instantiateNonrealRefExps(SageInterface::copyExpression(tplarg->get_expression()), tpl_params, tpl_args);
19758#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19759 std::cout << " inst_tplarg = " << std::hex << inst_tplarg << " : " << ( inst_tplarg ? inst_tplarg->class_name() : "" ) << std::endl;
19760 std::cout << " inst_tplarg->unparseToString() = " << ( inst_tplarg ? inst_tplarg->unparseToString() : "" ) << std::endl;
19761#endif
19762 if (inst_tplarg)
19763 inst_tpl_args.push_back(buildTemplateArgument(inst_tplarg));
19764 break;
19765 }
19767#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19768 std::cout << " tplarg->get_templateDeclaration() = " << std::hex << tplarg->get_templateDeclaration() << " : " << ( tplarg->get_templateDeclaration() ? tplarg->get_templateDeclaration()->class_name() : "" ) << std::endl;
19769#endif
19770 ROSE_ABORT(); // TODO
19771 }
19773#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19774 std::cout << " start_of_pack_expansion_argument" << std::endl;
19775#endif
19776 break; // NOP
19777 }
19778 default: ROSE_ABORT();
19779 }
19780 }
19781 SgTemplateInstantiationDecl * inst_decl = isSgTemplateInstantiationDecl(SageBuilder::buildClassDeclaration_nfi(
19782 xtpldecl->get_name(), SgClassDeclaration::e_struct, xtpldecl->get_scope(), nullptr, true, &inst_tpl_args
19783 ));
19784 ROSE_ASSERT(inst_decl);
19785#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19786 std::cout << " inst_decl = " << std::hex << inst_decl << " : " << inst_decl->class_name() << std::endl;
19787 std::cout << " inst_decl->get_firstNondefiningDeclaration() = " << std::hex << inst_decl->get_firstNondefiningDeclaration() << std::endl;
19788 std::cout << " inst_decl->get_definingDeclaration() = " << std::hex << inst_decl->get_definingDeclaration() << std::endl;
19789#endif
19790 ROSE_ASSERT(inst_decl->get_definingDeclaration());
19791 ROSE_ASSERT(inst_decl->get_definingDeclaration() == inst_decl);
19792 inst_decl->set_templateDeclaration(xtpldecl);
19793 ((SgTemplateInstantiationDecl *)(inst_decl->get_firstNondefiningDeclaration()))->set_templateDeclaration(xtpldecl);
19794
19795 for (auto inst_tpl_arg: inst_tpl_args) {
19796 inst_tpl_arg->set_parent(inst_decl);
19797 }
19798
19799 xtpldecl->get_scope()->append_statement(inst_decl);
19800 return inst_decl->get_type();
19801 } else {
19802 ROSE_ABORT(); // TODO probably typedef
19803 }
19804 } else if (nrdecl->get_is_template_param()) {
19805 auto depth = nrdecl->get_template_parameter_depth();
19806 auto position = nrdecl->get_template_parameter_position();
19807#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19808 std::cout << " ->get_template_parameter_position() = " << std::dec << position << std::endl;
19809 std::cout << " ->get_template_parameter_depth() = " << std::dec << depth << std::endl;
19810#endif
19811 ROSE_ASSERT(depth > 0);
19812 ROSE_ASSERT(position > 0);
19813 if (std::size_t(depth) <= tpl_args.size() && std::size_t(position) <= tpl_args[depth-1].size()) {
19814 SgType * res = tpl_args[depth-1][position-1]->get_type();
19815#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19816 std::cout << " tpl_args[" << std::dec << depth-1 << "][" << std::dec << position-1 << "]->get_type() = " << std::dec << res << std::endl;
19817#endif
19818 return res;
19819 } else if (std::size_t(depth) <= tpl_params.size() && std::size_t(position) <= tpl_params[depth-1].size()) {
19820 SgType * dft_tpl_arg = tpl_params[depth-1][position-1]->get_defaultTypeParameter();
19821#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19822 std::cout << " tpl_params[" << std::dec << depth-1 << "][" << std::dec << position-1 << "]->get_type() = " << std::dec << dft_tpl_arg << std::endl;
19823#endif
19824 dft_tpl_arg = instantiateNonrealTypes(dft_tpl_arg, tpl_params, tpl_args);
19825#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19826 std::cout << " dft_tpl_arg = " << std::dec << dft_tpl_arg << std::endl;
19827#endif
19828 return dft_tpl_arg;
19829 } else {
19830 return nullptr;
19831 }
19832 } else if (nrdecl->get_is_class_member()) {
19833#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19834 std::cout << " Case of a non-real class member will return INT." << std::endl;
19835#endif
19836 // TODO case such as "template <unsigned depth=0> static constexpr typename range_at_depth_t<depth>::Base ub;"
19837 // -> retrieve parent type
19838 // -> instantiate parent type
19839 // -> lookup member(s) in original parent type
19840 // -> instantiate (matching) member inside instantiated parent type
19841
19843 } else {
19844 ROSE_ABORT();
19845 }
19846 } else if (isSgTypeVoid(type) || isSgTypeUnsignedLong(type) || isSgTypeInt(type) || isSgTypeLong(type) || isSgTypeUnsignedInt(type) || isSgTypedefType(type) || isSgClassType(type)) {
19847 return type;
19848 } else if (isSgModifierType(type)) {
19849 SgModifierType * mtype = (SgModifierType *)type;
19850 SgType * btype = mtype->get_base_type();
19851 ROSE_ASSERT(btype != nullptr);
19853 ROSE_ASSERT(rtype != nullptr);
19854 rtype->get_typeModifier() = mtype->get_typeModifier();
19855 return rtype;
19856 } else {
19857 std::cerr << "!!! type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
19858 ROSE_ABORT(); // TODO maybe pointer/reference
19859 }
19860 return nullptr;
19861}
19862
19863SgType * instantiateNonrealTypes(
19864 SgType * type,
19865 std::vector<SgTemplateParameter *> & tpl_params,
19866 std::vector<SgTemplateArgument *> & tpl_args
19867) {
19868 std::vector<std::vector<SgTemplateParameter *>> tpl_params_{tpl_params};
19869 std::vector<std::vector<SgTemplateArgument *>> tpl_args_{tpl_args};
19870 return instantiateNonrealTypes(type, tpl_params_, tpl_args_);
19871}
19872
19873} } }
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
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'.
Unsigned position(size_t i)
Generate a single-bit mask.
Definition BitOps.h:159
Controls diagnostic messages from ROSE.
ROSE_DLL_API void initAndRegister(Facility *mlog, const std::string &name)
Initialize and register a logging facility.
ROSE_DLL_API Sawyer::Message::Facility mlog
Diagnostic facility for the ROSE library as a whole.
Definition sageBuilder.C: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 SgCompoundInitializer * buildCompoundInitializer(SgExprListExp *initializers=NULL, SgType *type=NULL)
Build a compound initializer, for vector type initialization.
ROSE_DLL_API SgTypeString * buildStringType()
DQ (8/21/2010): We want to move to the new buildStringType( SgExpression*,size_t) function over the o...
ROSE_DLL_API SgUpcThreads * buildUpcThreads_nfi()
Build UPC THREADS (integer expression)
ROSE_DLL_API SgModifierType * buildModifierType(SgType *base_type=nullptr)
Build a modifier type.
ROSE_DLL_API SgCaseOptionStmt * buildCaseOptionStmt(SgExpression *key=NULL, SgStatement *body=NULL)
Build a case option statement.
ROSE_DLL_API SgTemplateFunctionDeclaration * buildDefiningTemplateFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, SgTemplateFunctionDeclaration *first_nondefining_declaration)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgCatchOptionStmt * buildCatchOptionStmt(SgVariableDeclaration *condition=NULL, SgStatement *body=NULL)
Build a catch statement.
ROSE_DLL_API SgLongLongIntVal * buildLongLongIntVal_nfi(long long value, const std::string &str)
ROSE_DLL_API SgClassType * buildTemplateClassType(SgTemplateClassDeclaration *template_decl, std::vector< SgNode * > &template_args)
Same as buildClassTemplateType(), just better name.
SgFortranContinueStmt * buildFortranContinueStmt_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTemplateMemberFunctionDeclaration * buildNondefiningTemplateMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, SgTemplateParameterPtrList *templateParameterList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgLabelStatement * buildLabelStatement(const SgName &name, SgStatement *stmt=NULL, SgScopeStatement *scope=NULL)
Build a label statement, name is the label's name. Handling label symbol and scope internally.
ROSE_DLL_API SgFortranDo * buildFortranDo_nfi(SgExpression *initialization, SgExpression *bound, SgExpression *increment, SgBasicBlock *)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUpcThreads * buildUpcThreads()
Build UPC THREADS (integer expression)
ROSE_DLL_API SgModifierType * buildRestrictType(SgType *base_type)
Build a restrict type.
ROSE_DLL_API SgIntVal * buildIntVal_nfi(int value=0)
ROSE_DLL_API SgLongDoubleVal * buildLongDoubleVal(long double value=0.0)
SgFunctionParameterList * buildFunctionParameterList_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API AbstractHandle::abstract_handle * buildAbstractHandle(SgNode *n)
Build an abstract handle from a SgNode.
ROSE_DLL_API SgClassDeclaration * buildClassDeclaration(SgName name, SgScopeStatement *scope)
Build C++ class (builds both the non-defining and defining declarations; in that order).
ROSE_DLL_API SgMinusOp * buildMinusOp_nfi(SgExpression *op)
ROSE_DLL_API SgTemplateFunctionDeclaration * buildNondefiningTemplateFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope=NULL, SgExprListExp *decoratorList=NULL, SgTemplateParameterPtrList *templateParameterList=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAsmStmt * buildMultibyteNopStatement(int n)
DQ (4/30/2010): Added support for building nop statement using asm statement Building nop statement u...
ROSE_DLL_API SgKeyDatumPair * buildKeyDatumPair(SgExpression *key, SgExpression *datum)
Build a key-datum pair.
ROSE_DLL_API SgComprehension * buildComprehension(SgExpression *target, SgExpression *iter, SgExprListExp *ifs)
ROSE_DLL_API SgJavaParameterizedType * getUniqueJavaParameterizedType(SgNamedType *, SgTemplateParameterPtrList *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgComplexVal * buildImaginaryVal_nfi(SgValueExp *imaginary_value, const std::string &str)
ROSE_DLL_API SgFunctionCallExp * buildFunctionCallExp(SgFunctionSymbol *sym, SgExprListExp *parameters=NULL)
Build a function call expression.
ROSE_DLL_API SgType * getTargetFileType(SgType *snippet_type, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgTemplateParameter * buildTemplateParameter(SgTemplateParameter::template_parameter_enum parameterType, SgType *)
Build a template parameter, passing enum kind and SgTemplateType template_parameter_enum { parameter_...
ROSE_DLL_API SgNoexceptOp * buildNoexceptOp(SgExpression *exp=NULL)
Build noexcept operator expression with an expression parameter.
ROSE_DLL_API SgSignedCharVal * buildSignedCharVal_nfi(signed char v, const std::string &str)
ROSE_DLL_API SgClassDeclaration * buildNondefiningClassDeclaration(SgName name, SgScopeStatement *scope)
DQ (11/7/2009): Added functions to build C++ class.
SgMemberFunctionRefExp * buildMemberFunctionRefExp_nfi(SgMemberFunctionSymbol *sym, bool virtual_call, bool need_qualifier)
ROSE_DLL_API SgFunctionDeclaration * buildDefiningFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, bool buildTemplateInstantiation=false, SgFunctionDeclaration *first_nondefinng_declaration=NULL, SgTemplateArgumentPtrList *templateArgumentsList=NULL)
Build a function declaration with a function body.
ROSE_DLL_API SgModifierType * buildUpcSharedType(SgType *base_type=nullptr, long layout=-1)
Build a UPC shared type.
ROSE_DLL_API SgGotoStatement * buildGotoStatement(SgLabelStatement *label=NULL)
Build a goto statement.
ROSE_DLL_API std::string display(SourcePositionClassification &scp)
display function for debugging
ROSE_DLL_API SgUnsignedLongVal * buildUnsignedLongVal_nfi(unsigned long v, const std::string &str)
ROSE_DLL_API SgLabelRefExp * buildLabelRefExp(SgLabelSymbol *s)
Build a Fortran numeric label ref exp.
ROSE_DLL_API SgCompoundInitializer * buildCompoundInitializer_nfi(SgExprListExp *initializers, SgType *type=NULL)
Build a compound initializer, for vector type initialization.
ROSE_DLL_API SgSourceFile * buildJavaSourceFile(SgProject *, std::string, SgClassDefinition *, std::string)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgCatchStatementSeq * buildCatchStatementSeq(SgCatchOptionStmt *=NULL)
Build an initial sequence of Catch blocks containing 0 or 1 element.
ROSE_DLL_API SgInitializedName * buildInitializedName(const SgName &name, SgType *type, SgInitializer *init=NULL)
Initialized names are tricky, their scope vary depending on context, so scope and symbol information ...
ROSE_DLL_API SgTryStmt * buildTryStmt(SgStatement *body, SgCatchOptionStmt *catch0=NULL, SgCatchOptionStmt *catch1=NULL, SgCatchOptionStmt *catch2=NULL, SgCatchOptionStmt *catch3=NULL, SgCatchOptionStmt *catch4=NULL)
Build a try statement.
ROSE_DLL_API SgJavaImportStatement * buildJavaImportStatement(std::string, bool)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgThisExp * buildThisExp_nfi(SgSymbol *sym)
ROSE_DLL_API SgEnumDeclaration * buildEnumDeclaration_nfi(const SgName &name, SgScopeStatement *scope=NULL)
Build an enum, It is also a declaration statement in SAGE III.
ROSE_DLL_API SgNonrealDecl * buildNonrealDecl(const SgName &name, SgDeclarationScope *scope, SgDeclarationScope *child_scope=NULL)
Build a declaration of a non-real class or class-member representing template parameters and their me...
SgAssertStmt * buildAssertStmt_nfi(SgExpression *test)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgThisExp * buildThisExp(SgSymbol *sym)
Build this pointer.
ROSE_DLL_API SgSymbol * findAssociatedSymbolInTargetAST(SgDeclarationStatement *snippet_declaration, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgListComprehension * buildListComprehension(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgMinusMinusOp * buildMinusMinusOp_nfi(SgExpression *op)
ROSE_DLL_API SgModifierType * buildUpcBlockStarType(SgType *base_type=nullptr)
Build a UPC shared[*] type.
ROSE_DLL_API SgStringConversion * buildStringConversion_nfi(SgExpression *exp)
Build a variable declaration, handle symbol table transparently.
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 SgInitializedName * buildInitializedName_nfi(const SgName &name, SgType *type, SgInitializer *init, SgVariableDeclaration *declptr=NULL)
Initialized names are tricky, their scope vary depending on context, so scope and symbol information ...
ROSE_DLL_API PreprocessingInfo * buildCpreprocessorDefineDeclaration(SgLocatedNode *target, const std::string &content, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before)
Build and attach #define XX directives, pass "#define xxx xxx" as content.
ROSE_DLL_API SgTypeDouble * buildDoubleType()
Built in simple types.
ROSE_DLL_API SgReferenceType * buildReferenceType(SgType *base_type=nullptr)
Build a reference type.
SgExecStatement * buildExecStatement_nfi(SgExpression *executable, SgExpression *globals=NULL, SgExpression *locals=NULL)
Build an exec stmt.
ROSE_DLL_API SgTypeLongDouble * buildLongDoubleType()
Built in simple types.
ROSE_DLL_API SgTypeLong * buildLongType()
Built in simple types.
ROSE_DLL_API SgExprStatement * buildExprStatement(SgExpression *exp=NULL)
Build a SgExprStatement, set File_Info automatically.
ROSE_DLL_API SgLongIntVal * buildLongIntVal_nfi(long value, const std::string &str)
ROSE_DLL_API SgFunctionParameterRefExp * buildFunctionParameterRefExp(int parameter_number, int parameter_level)
ROSE_DLL_API SgTemplateTypedefDeclaration * buildTemplateTypedefDeclaration_nfi(const SgName &name, SgType *base_type, SgScopeStatement *scope=NULL, bool has_defining_base=false)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void fixupSourcePositionFileSpecification(SgNode *subtreeRoot, const std::string &newFileName)
Change the source file associated with the source position information in the AST.
ROSE_DLL_API SgAssertStmt * buildAssertStmt(SgExpression *test)
Build a Assert statement.
ROSE_DLL_API SgAtExp * buildAtExp(SgExpression *expression, SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgChar32Val * buildChar32Val(unsigned int value=0)
ROSE_DLL_API SgSizeOfOp * buildSizeOfOp_nfi(SgExpression *exp)
Build sizeof() expression with an expression parameter.
ROSE_DLL_API SgIfStmt * buildIfStmt(SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Build if statement.
ROSE_DLL_API SgAsyncStmt * buildAsyncStmt(SgBasicBlock *body)
MH (6/10/2014): Added async support.
ROSE_DLL_API SgFunctionParameterList * buildFunctionParameterList(SgInitializedName *in1=NULL, SgInitializedName *in2=NULL, SgInitializedName *in3=NULL, SgInitializedName *in4=NULL, SgInitializedName *in5=NULL, SgInitializedName *in6=NULL, SgInitializedName *in7=NULL, SgInitializedName *in8=NULL, SgInitializedName *in9=NULL, SgInitializedName *in10=NULL)
Build an empty SgFunctionParameterList, possibly with some initialized names filled in.
ROSE_DLL_API SgModifierType * buildFortranKindType(SgType *base_type, SgExpression *kindExpression)
Build a type based on the Fortran kind mechanism.
ROSE_DLL_API SgPragmaDeclaration * buildPragmaDeclaration(const std::string &name, SgScopeStatement *scope=NULL)
Build pragma declaration, handle SgPragma and defining/nondefining pointers internally.
ROSE_DLL_API SgUnsignedCharVal * buildUnsignedCharVal(unsigned char v=0)
Build an unsigned char.
SgLabelStatement * buildLabelStatement_nfi(const SgName &name, SgStatement *stmt, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAlignOfOp * buildAlignOfOp(SgExpression *exp=NULL)
Build alignof() expression with an expression parameter.
ROSE_DLL_API SgMatlabForStatement * buildMatlabForStatement(SgExpression *loop_index, SgExpression *loop_range, SgBasicBlock *loop_body)
Build a For-loop statement for matlab.
bool inSwitchScope()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgUpcMythread * buildUpcMythread()
Build UPC MYTHREAD (integer expression)
ROSE_DLL_API SgTypeUnsignedLong * buildUnsignedLongType()
Built in simple types.
ROSE_DLL_API SgPlusPlusOp * buildPlusPlusOp_nfi(SgExpression *op)
ROSE_DLL_API SgSignedCharVal * buildSignedCharValHex(signed char v=0)
ROSE_DLL_API SgTypeShort * buildShortType()
Built in simple types.
ROSE_DLL_API SgNonrealRefExp * buildNonrealRefExp_nfi(SgNonrealSymbol *sym)
Build a reference to the non-real declaration of a member of a non-real class.
SgFunctionCallExp * buildFunctionCallExp_nfi(SgExpression *f, SgExprListExp *parameters=NULL)
ROSE_DLL_API SgTypeVoid * buildVoidType()
Built in simple types.
ROSE_DLL_API void fixupSharingSourcePosition(SgNode *subtreeRoot, int new_file_id)
Sharing IR nodes requires that the file id be added to the fileIDsToUnparse held in the Sg_File_Info ...
ROSE_DLL_API SgAssignInitializer * buildAssignInitializer_nfi(SgExpression *operand_i=NULL, SgType *expression_type=NULL)
ROSE_DLL_API SgTypeBool * buildBoolType()
Built in simple types.
ROSE_DLL_API SgMicrosoftAttributeDeclaration * buildMicrosoftAttributeDeclaration(const SgName &name)
DQ (8/17/2014): Adding support for Microsoft MSVC specific attributes.
ROSE_DLL_API SgStatement * buildStatementFromString(const std::string &stmt_str, SgScopeStatement *scope)
Liao (9/18/2015): experimental support of building a statement from a string.
ROSE_DLL_API SgFile * buildFile(const std::string &inputFileName, const std::string &outputFileName, SgProject *project=NULL, bool clear_globalScopeAcrossFiles=false)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgMemberFunctionDeclaration * buildDefiningMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, bool buildTemplateInstantiation, unsigned int functionConstVolatileFlags, SgMemberFunctionDeclaration *first_nondefinng_declaration, SgTemplateArgumentPtrList *templateArgumentsList)
Build a defining ( non-prototype) member function declaration.
ROSE_DLL_API SgVarRefExp * buildVarRefExp_nfi(SgVariableSymbol *varSymbol)
ROSE_DLL_API SgPointerType * buildPointerType(SgType *base_type=nullptr)
Build a pointer type.
ROSE_DLL_API SgLongDoubleVal * buildLongDoubleVal_nfi(long double value, const std::string &str)
ROSE_DLL_API SgMagicColonExp * buildMagicColonExp()
Build a Matlab colon expression :
ROSE_DLL_API SgTypedefDeclaration * buildTypedefDeclaration(const std::string &name, SgType *base_type, SgScopeStatement *scope=NULL, bool has_defining_base=false)
Build a typedef declaration, such as: typedef int myint; typedef struct A {..} s_A;.
ROSE_DLL_API SgTemplateParameterVal * buildTemplateParameterVal(int template_parameter_position=-1)
Build an template parameter value expression.
ROSE_DLL_API SgFortranContinueStmt * buildFortranContinueStmt()
Build a Fortran continue statement.
ROSE_DLL_API SgFloat128Val * buildFloat128Val_nfi(long double value, const std::string &str)
ROSE_DLL_API SgBoolValExp * buildBoolValExp(int value=0)
Build a bool value expression, the name convention of SgBoolValExp is little different from others fo...
ROSE_DLL_API SgSwitchStatement * buildSwitchStatement(SgStatement *item_selector=NULL, SgStatement *body=NULL)
Build a switch statement.
ROSE_DLL_API SgType * buildOpaqueType(std::string const type_name, SgScopeStatement *scope)
Build an opaque type with a name, useful when a type's details are unknown during transformation,...
ROSE_DLL_API SgTypeChar32 * buildChar32Type()
Built in simple types.
ROSE_DLL_API SgConstructorInitializer * buildConstructorInitializer_nfi(SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type, bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown)
ROSE_DLL_API SgMatrixExp * buildMatrixExp(SgExprListExp *firstRow)
Build a Matlab Matrix.
ROSE_DLL_API SgPassStatement * buildPassStatement()
Build a pass statement.
ROSE_DLL_API SgTypeComplex * buildComplexType(SgType *base_type=nullptr)
Build a complex type.
ROSE_DLL_API SgProcedureHeaderStatement * buildProcedureHeaderStatement(const SgName &name, SgType *return_type, SgFunctionParameterList *parameter_list, SgProcedureHeaderStatement::subprogram_kind_enum, SgScopeStatement *scope=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDeclarationStatement * findAssociatedDeclarationInTargetAST(SgDeclarationStatement *snippet_declaration, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgTypeTuple * buildTupleType(SgType *t1=NULL, SgType *t2=NULL, SgType *t3=NULL, SgType *t4=NULL, SgType *t5=NULL, SgType *t6=NULL, SgType *t7=NULL, SgType *t8=NULL, SgType *t9=NULL, SgType *t10=NULL)
Build a tuple of types. Useful for a function returning multiple variables of different types.
ROSE_DLL_API SgNaryComparisonOp * buildNaryComparisonOp(SgExpression *lhs)
driscoll6 (7/20/11) : Support n-ary operators for python
ROSE_DLL_API SgNonrealType * buildNonrealType(const SgName &name, SgDeclarationScope *scope)
Build a non real type used for template parameter. Internally a SgNorealDecl is also built.
ROSE_DLL_API SgDeclarationScope * buildDeclarationScope()
Build a scope statement. Used to build SgNonrealDecl and SgNonrealType.
ROSE_DLL_API SgName appendTemplateArgumentsToName(const SgName &name, const SgTemplateArgumentPtrList &templateArgumentsList)
DQ (7/27/2012): changed semantics from removing the template arguments in names to adding the templat...
ROSE_DLL_API SgStaticAssertionDeclaration * buildStaticAssertionDeclaration(SgExpression *condition, const SgName &string_literal)
DQ (7/25/2014): Adding support for C11 static assertions.
ROSE_DLL_API SgNullExpression * buildNullExpression_nfi()
No file info version of buildNullExpression(). File info is to be set later on.
ROSE_DLL_API SgFunctionParameterTypeList * buildFunctionParameterTypeList(SgFunctionParameterList *paralist)
Build SgFunctionParameterTypeList from SgFunctionParameterList.
ROSE_DLL_API SgFunctionCallExp * buildMemberFunctionCall(std::string className, SgExpression *objectExpression, std::string functionName, SgExprListExp *params, SgScopeStatement *scope)
Build member function calls.
SgDefaultOptionStmt * buildDefaultOptionStmt_nfi(SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgActualArgumentExpression * buildActualArgumentExpression(SgName arg_name, SgExpression *arg)
Build an Actual Argument Expression.
ROSE_DLL_API PreprocessingInfo * buildHeader(const std::string &header_filename, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before, bool isSystemHeader=false)
Build a dangling #include "x.h" header, insertHeader() is needed to actually insert it.
SgPassStatement * buildPassStatement_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgStringVal * buildStringVal(std::string value="")
ROSE_DLL_API SgTypeSignedLong * buildSignedLongType()
Built in simple types.
ROSE_DLL_API SgClassDeclaration * buildDefiningClassDeclaration(SgName name, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
SgGotoStatement * buildGotoStatement_nfi(SgLabelStatement *label)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeChar * buildCharType()
Built in simple types.
ROSE_DLL_API SgTemplateParameterPtrList * getTemplateParameterList(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgClassExp * buildClassExp_nfi(SgClassSymbol *sym)
ROSE_DLL_API SgBreakStmt * buildBreakStmt()
Build a break statement.
ROSE_DLL_API SgForInitStatement * buildForInitStatement_nfi(SgStatementPtrList &statements)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void setTemplateParameterParents(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void pushScopeStack(SgScopeStatement *stmt)
Public interfaces of the scope stack, should be stable.
ROSE_DLL_API SgTypeSignedShort * buildSignedShortType()
Built in simple types.
ROSE_DLL_API SgUsingDirectiveStatement * buildUsingDirectiveStatement(SgNamespaceDeclarationStatement *ns_decl)
Build a using directive statement.
SgDictionaryExp * buildDictionaryExp_nfi(std::vector< SgKeyDatumPair * > pairs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgCastExp * buildCastExp(SgExpression *operand_i=NULL, SgType *expression_type=NULL, SgCastExp::cast_type_enum cast_type=SgCastExp::e_C_style_cast)
Build a type casting expression.
SgTemplateMemberFunctionRefExp * buildTemplateMemberFunctionRefExp_nfi(SgTemplateMemberFunctionSymbol *sym, bool virtual_call, bool need_qualifier)
DQ (12/29/2011): Adding template declaration support to the AST.
ROSE_DLL_API SgRvalueReferenceType * buildRvalueReferenceType(SgType *base_type)
Build a rvalue reference type.
ROSE_DLL_API SgClassDeclaration * buildNondefiningClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, bool buildTemplateInstantiation, SgTemplateArgumentPtrList *templateArgumentsList)
Build a structure first nondefining declaration, without file info.
ROSE_DLL_API SgStmtDeclarationStatement * buildStmtDeclarationStatement_nfi(SgStatement *stmt)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgForInitStatement * buildForInitStatement()
Build a for init statement.
SgDoWhileStmt * buildDoWhileStmt_nfi(SgStatement *body, SgStatement *condition)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void popScopeStack()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgSignedCharVal * buildSignedCharVal(signed char v=0)
Build a signed char.
ROSE_DLL_API SgAlignOfOp * buildAlignOfOp_nfi(SgExpression *exp)
Build alignof() expression with an expression parameter.
ROSE_DLL_API SgVarArgOp * buildVarArgOp_nfi(SgExpression *operand_i, SgType *expression_type)
Build vararg op expression.
ROSE_DLL_API void testTemplateArgumentParents(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeNullptr * buildNullptrType()
Built in simple types.
ROSE_DLL_API SgModifierType * buildUpcStrictType(SgType *base_type=nullptr)
Build a UPC strict type.
ROSE_DLL_API SgExprStatement * buildAssignStatement_ast_translate(SgExpression *lhs, SgExpression *rhs)
This version does not recursively reset the file info as a transformation.
ROSE_DLL_API SgTypeFloat * buildFloatType()
Built in simple types.
ROSE_DLL_API SgDeleteExp * buildDeleteExp(SgExpression *variable, short is_array, short need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
ROSE_DLL_API SgTypeOfType * buildTypeOfType(SgExpression *base_expression, SgType *base_type)
Build a GNU typeof operator.
ROSE_DLL_API SgVoidVal * buildVoidVal()
DQ (2/14/2019): Adding support for C++14 void value expressions.
SgWhileStmt * buildWhileStmt_nfi(SgStatement *condition, SgStatement *body, SgStatement *else_body=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API bool emptyScopeStack()
intended to be a private member, don't access it directly. could be changed any time
SgClassNameRefExp * buildClassNameRefExp_nfi(SgClassSymbol *sym)
ROSE_DLL_API SgFloat80Val * buildFloat80Val_nfi(long double value, const std::string &str)
ROSE_DLL_API SgSetComprehension * buildSetComprehension(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgColonShapeExp * buildColonShapeExp_nfi()
No file info version of buildColonShapeExp(). File info is to be set later on.
ROSE_DLL_API SgVoidVal * buildVoidVal_nfi()
ROSE_DLL_API SgModifierType * buildVolatileType(SgType *base_type=nullptr)
Build a volatile type.
ROSE_DLL_API SgFunctionRefExp * buildFunctionRefExp(const SgName &name, const SgType *func_type, SgScopeStatement *scope=NULL)
Build SgFunctionRefExp based on a C++ function's name and function type. It will lookup symbol table ...
ROSE_DLL_API SgTemplateVariableInstantiation * buildTemplateVariableInstantiation(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope, SgTemplateVariableDeclaration *tpl_decl, SgTemplateArgumentPtrList &tpl_args)
Build template variable declarations.
ROSE_DLL_API SgTypeWchar * buildWcharType()
Built in simple types.
ROSE_DLL_API SgBasicBlock * buildBasicBlock(SgStatement *stmt1=NULL, SgStatement *stmt2=NULL, SgStatement *stmt3=NULL, SgStatement *stmt4=NULL, SgStatement *stmt5=NULL, SgStatement *stmt6=NULL, SgStatement *stmt7=NULL, SgStatement *stmt8=NULL, SgStatement *stmt9=NULL, SgStatement *stmt10=NULL)
Build a SgBasicBlock, setting file info internally.
ROSE_DLL_API SgAggregateInitializer * buildAggregateInitializer(SgExprListExp *initializers=NULL, SgType *type=NULL)
Build an aggregate initializer.
ROSE_DLL_API SgNoexceptOp * buildNoexceptOp_nfi(SgExpression *exp)
Build noexcept operator expression with an expression parameter.
ROSE_DLL_API SgTypeUnknown * buildUnknownType()
Built in simple types.
ROSE_DLL_API SgFoldExpression * buildFoldExpression(SgExpression *operands, std::string operator_token_string, bool is_left_associative)
ROSE_DLL_API SgVariableDeclaration * buildVariableDeclaration_nfi(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope, bool builtFromUseOnly=false, SgStorageModifier::storage_modifier_enum sm=SgStorageModifier::e_default)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeIdOp * buildTypeIdOp(SgExpression *operand_expr, SgType *operand_type)
DQ (1/25/2013): Added support for typeId operators.
ROSE_DLL_API SgExprStatement * buildAssignStatement(SgExpression *lhs, SgExpression *rhs)
Build an assignment statement from lefthand operand and right hand operand.
ROSE_DLL_API SgTypeUnsigned128bitInteger * buildUnsigned128bitIntegerType()
Built in simple types.
ROSE_DLL_API SgUnsignedIntVal * buildUnsignedIntVal(unsigned int v=0)
Build an unsigned integer.
SgFunctionRefExp * buildFunctionRefExp_nfi(SgFunctionSymbol *sym)
ROSE_DLL_API SgCharVal * buildCharVal(char value=0)
SgActualArgumentExpression * buildActualArgumentExpression_nfi(SgName arg_name, SgExpression *arg)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgSizeOfOp * buildSizeOfOp(SgExpression *exp=NULL)
Build sizeof() expression with an expression parameter.
ROSE_DLL_API SgMemberFunctionDeclaration * buildNondefiningMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, bool buildTemplateInstantiation, SgTemplateArgumentPtrList *templateArgumentsList)
Build a prototype member function declaration.
ROSE_DLL_API SgJavaWildcardType * getUniqueJavaWildcardSuper(SgType *)
Build a SgFile node and attach it to SgProject.
SgTypeTraitBuiltinOperator * buildTypeTraitBuiltinOperator(SgName functionName, SgNodePtrList parameters)
SgCompoundLiteralExp * buildCompoundLiteralExp(SgVariableSymbol *varSymbol)
Build function for compound literals (uses a SgVariableSymbol and is similar to buildVarRefExp()).
ROSE_DLL_API SgTemplateVariableInstantiation * buildTemplateVariableInstantiation_nfi(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope, SgTemplateVariableDeclaration *tpl_decl, SgTemplateArgumentPtrList &tpl_args)
Build a variable declaration, handle symbol table transparently.
SgExprListExp * buildExprListExp_nfi()
ROSE_DLL_API SgType * getTargetFileTypeSupport(SgType *snippet_type, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgVariantExpression * buildVariantExpression()
ROSE_DLL_API SgNonrealBaseClass * buildNonrealBaseClass(SgNonrealDecl *classDeclaration, SgClassDefinition *classDefinition, bool isVirtual, bool isDirect)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeSignedInt * buildSignedIntType()
Built in simple types.
ROSE_DLL_API 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.