ROSE 0.11.145.250
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 SgName mangled_name = type_decl->get_mangled_name();
2231 setTemplateArgumentsInDeclaration(type_decl,&templateArgumentsList);
2232
2233 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() != NULL);
2234 ROSE_ASSERT(type_decl->get_definingDeclaration() == NULL);
2235 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() == type_decl);
2236
2237 ROSE_ASSERT(type_decl->get_type() != NULL);
2238 ROSE_ASSERT(scope != NULL);
2239
2240#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2241 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2242 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;
2243#endif
2244
2245 if (scope != NULL)
2246 {
2247 if (scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != NULL)
2248 {
2249 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());
2250 }
2251 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == NULL);
2252
2253 SgTemplateTypedefSymbol* typedef_symbol = new SgTemplateTypedefSymbol(type_decl);
2254 ROSE_ASSERT(typedef_symbol);
2255
2256 scope->insert_symbol(nameWithTemplateArguments,typedef_symbol);
2257 type_decl->set_scope(scope);
2258 type_decl->set_parent(scope);
2259 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != NULL);
2260 }
2261
2262#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2263 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2264 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;
2265#endif
2266
2267 return type_decl;
2268 }
2269
2270
2271
2272
2273
2274//-----------------------------------------------
2275// Assertion `definingDeclaration != NULL || firstNondefiningDeclaration != NULL'
2278{
2279 SgFunctionParameterList *parameterList = new SgFunctionParameterList();
2280 ROSE_ASSERT (parameterList);
2281
2282 parameterList->set_definingDeclaration (NULL);
2283 parameterList->set_firstNondefiningDeclaration (parameterList);
2284
2286
2287 if (in1) appendArg(parameterList, in1);
2288 if (in2) appendArg(parameterList, in2);
2289 if (in3) appendArg(parameterList, in3);
2290 if (in4) appendArg(parameterList, in4);
2291 if (in5) appendArg(parameterList, in5);
2292 if (in6) appendArg(parameterList, in6);
2293 if (in7) appendArg(parameterList, in7);
2294 if (in8) appendArg(parameterList, in8);
2295 if (in9) appendArg(parameterList, in9);
2296 if (in10) appendArg(parameterList, in10);
2297
2298 return parameterList;
2299}
2300
2303 SgFunctionParameterList *parameterList = new SgFunctionParameterList();
2304 ROSE_ASSERT (parameterList);
2305 parameterList->set_definingDeclaration (NULL);
2306 parameterList->set_firstNondefiningDeclaration (parameterList);
2307
2308 setOneSourcePositionNull(parameterList);
2309
2310 return parameterList;
2311}
2312
2313//-----------------------------------------------
2316 SgCtorInitializerList *ctorInitList = new SgCtorInitializerList();
2317 ROSE_ASSERT (ctorInitList);
2318 ctorInitList->set_definingDeclaration (NULL);
2319 ctorInitList->set_firstNondefiningDeclaration (ctorInitList);
2320
2321 setOneSourcePositionNull(ctorInitList);
2322
2323 return ctorInitList;
2324}
2325
2326//-----------------------------------------------
2327// no type vs. void type ?
2330 {
2331 // DQ (8/19/2012): I am not a fan of this sort of codeing style either (NULL pointers as inputs should be an error).
2332 if (paralist == NULL)
2333 {
2334 printf ("WARNING: In buildFunctionParameterTypeList(): Accepting NULL input and returning NULL pointer. \n");
2335
2336 return NULL;
2337 }
2338
2339 // 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).
2340 // if (paralist->get_args().size()==0)
2341 // return NULL;
2342
2344 ROSE_ASSERT(typePtrList != NULL);
2345
2346 SgInitializedNamePtrList args = paralist->get_args();
2347 SgInitializedNamePtrList::const_iterator i;
2348 for(i = args.begin(); i != args.end(); i++)
2349 (typePtrList->get_arguments()).push_back( (*i)->get_type() );
2350
2352
2353 return typePtrList;
2354 }
2355
2356
2359 {
2360 if (expList ==NULL) return NULL;
2361 SgExpressionPtrList expPtrList = expList->get_expressions();
2362
2364 ROSE_ASSERT(typePtrList);
2365
2366 SgExpressionPtrList::const_iterator i;
2367 for (i=expPtrList.begin();i!=expPtrList.end();i++)
2368 {
2369 typePtrList->get_arguments().push_back( (*i)->get_type() );
2370 }
2371
2373
2374 return typePtrList;
2375 }
2376
2379 SgType* type4, SgType* type5, SgType* type6, SgType* type7)
2380 {
2382 ROSE_ASSERT(typePtrList);
2383
2384 SgTypePtrList & types = typePtrList->get_arguments();
2385
2386 if (type0 != NULL) types.push_back(type0);
2387 if (type1 != NULL) types.push_back(type1);
2388 if (type2 != NULL) types.push_back(type2);
2389 if (type3 != NULL) types.push_back(type3);
2390 if (type4 != NULL) types.push_back(type4);
2391 if (type5 != NULL) types.push_back(type5);
2392 if (type6 != NULL) types.push_back(type6);
2393 if (type7 != NULL) types.push_back(type7);
2394
2395 return typePtrList;
2396 }
2397
2398//-----------------------------------------------
2399// build function type,
2400//
2401// insert into symbol table when not duplicated
2404 {
2405 ROSE_ASSERT(return_type != NULL);
2406
2407 // DQ (8/19/2012): Can we enforce this?
2408 ROSE_ASSERT(typeList != NULL);
2409
2411 ROSE_ASSERT(fTable);
2412
2413 // This function make clever use of a static member function which can't be built
2414 // for the case of a SgMemberFunctionType (or at least not without more work).
2415 SgName typeName = SgFunctionType::get_mangled(return_type, typeList);
2416
2417 SgFunctionType* funcType = isSgFunctionType(fTable->lookup_function_type(typeName));
2418
2419 if (funcType == NULL)
2420 {
2421 // Only build the new type if it can't be found in the global type table.
2422 funcType = new SgFunctionType(return_type, false);
2423 ROSE_ASSERT(funcType);
2424
2425 if (typeList != NULL)
2426 {
2427 // DQ (12/5/2012): We want to avoid overwriting an existing SgFunctionParameterTypeList. Could be related to failing tests for AST File I/O.
2428 if (funcType->get_argument_list() != NULL)
2429 {
2430 delete funcType->get_argument_list();
2431 funcType->set_argument_list(NULL);
2432 }
2433 ROSE_ASSERT(funcType->get_argument_list() == NULL);
2434
2435 funcType->set_argument_list(typeList);
2436 typeList->set_parent(funcType);
2437 }
2438
2439 fTable->insert_function_type(typeName,funcType);
2440 }
2441 else
2442 {
2443 // DQ (12/6/2012): Tracking down orphaned SgFunctionParameterTypeList objects.
2444 }
2445
2446 return funcType;
2447 }
2448
2449
2450
2452SageBuilder::buildMemberFunctionType(SgType* return_type, SgFunctionParameterTypeList* typeList, SgType *classType, unsigned int mfunc_specifier)
2453 {
2454 // DQ (8/19/2012): This is a refactored version of the buildMemberFunctionType() below so that we can
2455 // isolate out the part that uses a SgClassType from the version that uses the SgClassDefinition.
2456
2457 // Maintain the global type table
2459 ROSE_ASSERT(fTable != NULL);
2460
2461 // DQ (12/6/2012): Added assertion.
2462 // ROSE_ASSERT(classType != NULL);
2463
2464 // DQ (12/13/2012): Added assertion.
2465 ROSE_ASSERT(typeList != NULL);
2466
2467 // DQ (12/6/2012): Newer simpler code (using static function SgMemberFunctionType::get_mangled()).
2468 SgName typeName = SgMemberFunctionType::get_mangled(return_type,typeList,classType,mfunc_specifier);
2469 SgType* typeInTable = fTable->lookup_function_type(typeName);
2470
2471#if 0
2472 printf ("In buildMemberFunctionType(SgType*,SgFunctionParameterTypeList*,SgType*,int,int): fTable->lookup_function_type(typeName = %s) = %p \n",typeName.str(),typeInTable);
2473 printf (" --- mfunc_specifier = %d ref_qualifiers = %d \n",mfunc_specifier,ref_qualifiers);
2474#endif
2475
2476#if 0
2477 // DQ (1/10/2020): I think that these qualifiers are contained in the mfunc_specifier.
2478 if (ref_qualifiers > 0)
2479 {
2480 printf ("Exiting as a test! \n");
2481 ROSE_ABORT();
2482 }
2483#endif
2484
2485 SgMemberFunctionType* funcType = NULL;
2486 if (typeInTable == NULL)
2487 {
2488 bool has_ellipses = false;
2489 //~ SgPartialFunctionType* partialFunctionType = new SgPartialFunctionType(return_type, has_ellipses, classType, mfunc_specifier, ref_qualifiers);
2490 // PP (10/4/22): removing ref_qualifiers
2491 SgPartialFunctionType* partialFunctionType = new SgPartialFunctionType(return_type, has_ellipses, classType, mfunc_specifier);
2492 ROSE_ASSERT(partialFunctionType != NULL);
2493#if 0
2494 printf ("Building a SgPartialFunctionType: partialFunctionType = %p \n",partialFunctionType);
2495 printf (" --- partialFunctionType->isLvalueReferenceFunc() = %s \n",partialFunctionType->isLvalueReferenceFunc() ? "true" : "false");
2496 printf (" --- partialFunctionType->isRvalueReferenceFunc() = %s \n",partialFunctionType->isRvalueReferenceFunc() ? "true" : "false");
2497#endif
2498 // DQ (12/5/2012): We want to avoid overwriting an existing SgFunctionParameterTypeList. Could be related to failing tests for AST File I/O.
2499 if (partialFunctionType->get_argument_list() != NULL)
2500 {
2501 delete partialFunctionType->get_argument_list();
2502 partialFunctionType->set_argument_list(NULL);
2503 }
2504 ROSE_ASSERT(partialFunctionType->get_argument_list() == NULL);
2505
2506 typeList->set_parent(partialFunctionType);
2507
2508 // DQ (12/6/2012): Set the SgFunctionParameterTypeList in the SgPartialFunctionType before trying
2509 // to build a SgMemberFunctionType (not critical that it be set before, but might be in the future,
2510 // but it is important that it be set).
2511 partialFunctionType->set_argument_list(typeList);
2512
2513 ROSE_ASSERT(partialFunctionType->get_argument_list() != NULL);
2514
2515 // The optional_fortran_type_kind is only required for Fortran support.
2516 SgExpression* optional_fortran_type_kind = NULL;
2517 funcType = SgMemberFunctionType::createType(partialFunctionType, optional_fortran_type_kind);
2518
2519 // DQ (12/13/2012): Remove the SgPartialFunctionType after it has been used to build the SgMemberFunctionType.
2520 // I would rather modify the SgMemberFunctionType::createType() API so that we didn't use the SgPartialFunctionType IR nodes.
2521 // First we have to reset the pointer to the type argument list to NULL since it is shared with the SgMemberFunctionType.
2522 partialFunctionType->set_argument_list(NULL);
2523
2524 // Then we can delete the SgPartialFunctionType.
2525 delete partialFunctionType;
2526 partialFunctionType = NULL;
2527
2528 // This is perhaps redundant since it was set to a derived class (but might be an important distiction).
2529 typeList->set_parent(funcType);
2530
2531 ROSE_ASSERT(funcType->get_argument_list() != NULL);
2532 }
2533
2534 if (typeInTable == nullptr)
2535 {
2536 ASSERT_not_null(funcType);
2537 fTable->insert_function_type(typeName,funcType);
2538 }
2539 else
2540 {
2541 // DQ (12/3/2011): Added this case to support reuse of function types (not handled by the createType functions).
2542 // Delete the one generated so that we could form the mangled name.
2543 ASSERT_require(typeInTable != funcType);
2544 delete funcType;
2545
2546 // Return the one from the global type table.
2547 funcType = isSgMemberFunctionType(typeInTable);
2548 ASSERT_not_null(funcType);
2549 }
2550
2551 return funcType;
2552 }
2553
2554
2555// DQ (1/4/2009): Need to finish this!!!
2556//-----------------------------------------------
2557// build member function type,
2558//
2559// insert into symbol table when not duplicated
2561SageBuilder::buildMemberFunctionType(SgType* return_type, SgFunctionParameterTypeList* typeList, SgScopeStatement * struct_name, unsigned int mfunc_specifier)
2562 {
2563 // This function has to first build a version of the SgMemberFunctionType so that it can generate a mangled name.
2564 // If the mangled name can be use to lookup a SgMemberFunctionType then the "just built" SgMemberFunctionType
2565 // is deleted and the one from the global function type table is returned. This fixes a lot of subtle C++
2566 // specific issues with the build interface and it's use with the newer EDG 4.3 connection to ROSE.
2567
2568 ROSE_ASSERT(return_type != NULL);
2569
2570 // SgMemberFunctionType (SgType *return_type=NULL, bool has_ellipses=true, SgClassDefinition *struct_name=NULL, unsigned int mfunc_specifier=0)
2571 // SgMemberFunctionType * funcType = new SgMemberFunctionType(return_type, false);
2572
2573 ROSE_ASSERT(struct_name != NULL);
2574
2575#if 0
2576 printf("In buildMemberFunctionType():\n");
2577 printf(" - struct_name = %p (%s)\n", struct_name, struct_name->class_name().c_str());
2578#endif
2579
2580#if 0
2581 // DQ (1/9/2020): Unclear why this function is not using the ref_qualifiers.
2582 printf ("SageBuilder::buildMemberFunctionType(SgType*,SgFunctionParameterTypeList*,SgScopeStatement*,int,int): This function does not use the input ref_qualifiers = %x \n",ref_qualifiers);
2583 printf (" --- mfunc_specifier = %d ref_qualifiers = %d \n",mfunc_specifier,ref_qualifiers);
2584#endif
2585
2586#if 0
2587 printf ("Exiting as a test! \n");
2588 ROSE_ABORT();
2589#endif
2590
2591 ROSE_ASSERT(struct_name->get_parent() != NULL);
2592 // ROSE_ASSERT(struct_name->get_declaration() != NULL);
2593
2594#if 0
2595 printf("struct_name = %p ( %s )\n", struct_name, struct_name->class_name().c_str());
2596#endif
2597
2598 // SgDeclarationStatement* declaration = struct_name->get_declaration();
2599 SgClassDefinition* classDefinition = isSgClassDefinition(struct_name);
2600 SgDeclarationScope* decl_scope = isSgDeclarationScope(struct_name);
2601
2602 if (classDefinition == NULL && decl_scope == NULL)
2603 {
2604 printf ("Error: (classDefinition == NULL && decl_scope == NULL): struct_name = %p = %s name = %s \n",
2605 struct_name,struct_name->class_name().c_str(),SageInterface::get_name(struct_name).c_str());
2606 }
2607 ROSE_ASSERT(classDefinition != NULL || decl_scope != NULL);
2608
2609 SgDeclarationStatement* declaration = NULL;
2610 if (classDefinition != NULL)
2611 {
2612 declaration = classDefinition->get_declaration();
2613 }
2614 else if (decl_scope != NULL)
2615 {
2616 declaration = isSgDeclarationStatement(decl_scope->get_parent());
2617 }
2618 else
2619 {
2620 ROSE_ABORT();
2621 }
2622
2623 ROSE_ASSERT(declaration != NULL);
2624
2625 if (typeList != NULL)
2626 {
2627#if 0
2628 SgTypePtrList & typeListArgs = typeList->get_arguments();
2629 for (SgTypePtrList::iterator i = typeListArgs.begin(); i != typeListArgs.end(); i++)
2630 {
2631 printf (" --- type argument = %p = %s \n",*i,(*i)->class_name().c_str());
2632 }
2633#endif
2634 }
2635 else
2636 {
2637 printf ("WARNING: typeList == NULL \n");
2638 }
2639
2640 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
2641 // SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(declaration);
2642 SgNonrealDecl * nrdecl = isSgNonrealDecl(declaration);
2643
2644 ROSE_ASSERT(classDeclaration != NULL || nrdecl != NULL);
2645
2646 SgMemberFunctionType* funcType = NULL;
2647
2648 // DQ (12/4/2011): Modified SgClassType to support template declarations (SgTemplateClassDeclaration now contains a type set to SgClassType.
2649 // The SgClassType has been modified (browdened) to support a SgDeclarationStatement instead of a SgClassDeclaration.
2650 // SgClassType* classType = classDeclaration->get_type();
2651 SgType* classType = NULL;
2652 if (classDeclaration != NULL)
2653 {
2654 classType = classDeclaration->get_type();
2655 }
2656 else if (decl_scope != NULL)
2657 {
2658 classType = nrdecl->get_type();
2659 }
2660 else
2661 {
2662 ROSE_ABORT();
2663 }
2664
2665 ROSE_ASSERT(classType != NULL);
2666
2667#if 0
2668 printf ("In buildMemberFunctionType(): Calling refactored function: buildMemberFunctionType(...,classType = %p,...) \n",classType);
2669#endif
2670
2671 // DQ (8/19/2012): This code has been refactored.
2672 funcType = buildMemberFunctionType(return_type,typeList,classType,mfunc_specifier);
2673
2674#if 0
2675 printf ("In buildMemberFunctionType(): DONE: Calling refactored function: buildMemberFunctionType(...,classType = %p,...) \n",classType);
2676#endif
2677
2678 return funcType;
2679 }
2680
2681
2684 {
2685 ROSE_ASSERT(base_type != NULL);
2686
2687 ROSE_ASSERT(classType != NULL);
2688 SgPointerMemberType* pointerToMemberType = new SgPointerMemberType(base_type,classType);
2689 return pointerToMemberType;
2690
2691 }
2692
2693//----------------------------------------------------
2695SgType * SageBuilder::buildOpaqueType(std::string const name, SgScopeStatement * scope)
2696{
2697 // we require users to specify a target scope
2698 ROSE_ASSERT(scope);
2699 SgTypedefDeclaration* type_decl = NULL;
2700 SgTypedefType* result = NULL;
2701
2702 // Liao and Greg Bronevetsky , 8/27/2009
2703 // patch up the symbol
2704 // and avoid duplicated creation
2705 // TODO a function like fixTypeDeclaration() (similar to SageInterface::fixVariableDeclaration()) for this
2706 SgTypedefSymbol* type_symbol = scope->lookup_typedef_symbol(name);
2707 if (type_symbol == NULL)
2708 {
2709 type_decl = new SgTypedefDeclaration(name,buildIntType(),NULL, NULL, NULL);
2710 ROSE_ASSERT(type_decl);
2711
2712 // DQ (2/27/2018): Add this call here to reflect change to the constructor semantics.
2713 type_decl->set_type(SgTypedefType::createType(type_decl));
2714
2715 type_symbol = new SgTypedefSymbol(type_decl);
2716 ROSE_ASSERT(type_symbol);
2717 SgName n = name;
2718
2719 // DQ (5/21/2013): The symbol table should only be accessed through the SgScopeStatement interface.
2720 scope->insert_symbol(n,type_symbol);
2721
2722 type_decl->set_firstNondefiningDeclaration (type_decl);
2724 prependStatement(type_decl,scope);
2725 // Hide it from unparser
2726 Sg_File_Info* file_info = type_decl->get_file_info();
2727 file_info->unsetOutputInCodeGeneration ();
2728 result = new SgTypedefType(type_decl);
2729 }
2730 else
2731 {
2732 type_decl = type_symbol->get_declaration();
2733 result = type_decl->get_type();
2734 }
2735 ROSE_ASSERT(result);
2736 return result;
2737}
2738
2739
2740//----------------- function type------------
2741// same function declarations (defining or nondefining) should share the same function type!
2744 {
2745 ASSERT_not_null(argList);
2746
2748 SgFunctionType* func_type = buildFunctionType(return_type, typeList);
2749
2750 if (func_type->get_argument_list() != typeList)
2751 {
2752 delete typeList;
2753 typeList = NULL;
2754 }
2755
2756 return func_type;
2757 }
2758
2759void
2760checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope ( SgDeclarationStatement* func, SgScopeStatement* scope )
2761 {
2762 // DQ (12/14/2011): We need the parent to be set so that we can call some of the test functions
2763 // (e.g assert that get_class_scope() for member functions). So we set the parent to the scope
2764 // by default and see if this will work, else we could disable to assertion that the parent is
2765 // non-null in the get_class_scope() member function.
2766
2767 if (isSgMemberFunctionDeclaration(func) != NULL)
2768 {
2769#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
2770 printf ("WARNING: setting parent of function to match scope by default \n");
2771#endif
2772 func->set_parent(scope);
2773
2774 ROSE_ASSERT(scope != NULL);
2775
2776 if (isSgTemplateInstantiationMemberFunctionDecl(func) != NULL)
2777 {
2778 // DQ (12/14/2011): We should not have a member function template instantiation in a template class definition.
2779
2780 // DQ (8/25/2014): Un-Commented out to revert to previous working state.
2781 // DQ (8/25/2014): Commented out to test new logic at base of isTemplateDeclaration(a_routine_ptr).
2782 // DQ (8/25/2014): Un-Commented out to revert to previous working state.
2783 // DQ (8/25/2014): Allow non-template functions in a template class declaration (see test2014_161.C).
2784#if !ENFORCE_NO_FUNCTION_TEMPLATE_DECLARATIONS_IN_TEMPLATE_CLASS_INSTANTIATIONS
2785 // 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");
2786#endif
2787 }
2788 }
2789 else
2790 {
2791 if (isSgTemplateFunctionDeclaration(func) != NULL)
2792 {
2793 if (isSgTemplateInstantiationMemberFunctionDecl(func) != NULL)
2794 {
2795 ROSE_ASSERT(isSgTemplateClassDefinition(scope) != NULL);
2796 }
2797 }
2798 }
2799 }
2800
2801//----------------- function declaration------------
2802// considering
2803// 1. fresh building
2804// 2. secondary building after another nondefining functiondeclaration
2805// 3. secondary building after another defining function declaration
2806// 4. fortran ?
2807template <class actualFunction>
2808actualFunction*
2809SageBuilder::buildNondefiningFunctionDeclaration_T (
2810 const SgName & XXX_name, SgType* return_type, SgFunctionParameterList * paralist, bool isMemberFunction,
2811 SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags,
2812 SgTemplateArgumentPtrList* templateArgumentsList, SgTemplateParameterPtrList* templateParameterList,
2814) {
2815 // DQ (11/25/2011): This function has been modified to work when used with a SgTemplateFunctionDeclaration as a template argument.
2816 // It was originally designed to work with only SgFunctionDeclaration and SgMemberFunctionDeclaration, it now works with these
2817 // plus SgTemplateFunctionDeclaration and SgTemplateMemberonDeclaration IR nodes. This is part of providing new support for template
2818 // declarations in the AST and a general update of this function to support this expanded use.
2819
2820 // 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.
2821
2822 // argument verification
2823 if (scope == nullptr)
2824 {
2826 }
2827 ASSERT_not_null(scope);
2828
2829 if (XXX_name.is_null() == true)
2830 {
2831 // DQ (4/2/2013): This case is generated for test2013_86.C.
2832 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");
2833 }
2834
2835 SgName nameWithoutTemplateArguments = XXX_name;
2836 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
2837
2838 bool buildTemplateInstantiation = ((VariantT)actualFunction::static_variant == V_SgTemplateInstantiationFunctionDecl || (VariantT)actualFunction::static_variant == V_SgTemplateInstantiationMemberFunctionDecl);
2839
2840 // DQ (8/7/2013): Added support for template declarations.
2841 bool buildTemplateDeclaration = ((VariantT)actualFunction::static_variant == V_SgTemplateFunctionDeclaration || (VariantT)actualFunction::static_variant == V_SgTemplateMemberFunctionDeclaration);
2842
2843 // DQ (8/7/2013): Added support for template declarations (need to handle template names overloaded on template parameters).
2844 // We want to use the template arguments in the symbol table lookup, but not in the name generation.
2845 if (buildTemplateInstantiation == true)
2846 {
2847 ASSERT_not_null(templateArgumentsList);
2848 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
2849 }
2850
2851 // this function is also called when building a function reference before the function declaration exists. So, skip the check
2852 if (nameWithTemplateArguments.is_null() == true)
2853 {
2854 // DQ (3/25/2017): Modified to use message logging.
2855 // DQ (4/2/2013): This case is generated for test2013_86.C.
2856 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");
2857 }
2858
2859 if (nameWithoutTemplateArguments.is_null() == true)
2860 {
2861 // DQ (3/25/2017): Modified to use message logging.
2862 // DQ (4/2/2013): This case is generated for test2013_86.C.
2863 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");
2864 }
2865
2866 ASSERT_not_null(return_type);
2867 ASSERT_not_null(paralist);
2868
2869 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
2870 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
2871 if (SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == true)
2872 {
2873#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
2874 printf ("Warning: In buildNondefiningFunctionDeclaration_T(): nameWithoutTemplateArguments = %s nameWithTemplateArguments = %s \n",nameWithoutTemplateArguments.str(),nameWithTemplateArguments.str());
2875#endif
2876 }
2877 // DQ (7/27/2012): There are reasons why this can fail: e.g. for functions with names such as:
2878 // "operator std::auto_ptr_ref<_Tp1>" which is a user defined conversion operator to one class from another.
2879
2880 // tentatively build a function type, since it is shared
2881 // by all prototypes and defining declarations of a same function!
2882
2883 SgFunctionType* func_type = nullptr;
2884 if (isMemberFunction == true)
2885 {
2887 func_type = buildMemberFunctionType(return_type,typeList,scope, functionConstVolatileFlags);
2888 }
2889 else
2890 {
2891 func_type = buildFunctionType(return_type,paralist);
2892 }
2893
2894 ASSERT_not_null(func_type);
2895
2896 // function declaration
2897 actualFunction* func = nullptr;
2898
2899 // search before using the function type to create the function declaration
2900 // TODO only search current scope or all ancestor scope?? (DQ: Only current scope!)
2901 // We don't have lookup_member_function_symbol yet
2902
2903 // DQ (12/27/2011): Under the new design we can make the symbol type SgFunctionSymbol instead of the less specific SgSymbol.
2904 // DQ (11/25/2011): We want to add the support for template function declarations,
2905 // so this should be a SgSymbol so that we can have it be either a SgFunctionSymbol
2906 // or a SgTemplateSymbol.
2907 SgFunctionSymbol* func_symbol = NULL;
2908
2909 if (scope != NULL)
2910 {
2911 // DQ (3/13/2012): Experiment with new function to support only associating the right type of symbol with the
2912 // function being built. I don't think I like the design of this interface, but we might change that later.
2913
2914 // 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.
2915 func_symbol = scope->find_symbol_by_type_of_function<actualFunction>(nameWithTemplateArguments,func_type,templateParameterList,templateArgumentsList);
2916
2917#if 0 // DBG1
2918 printf ("In buildNondefiningFunctionDeclaration_T(): func_symbol from scope->find_symbol_by_type_of_function<actualFunction>(name = %s) = %p \n",nameWithTemplateArguments.str(),func_symbol);
2919 if (func_symbol != NULL) {
2920 printf ("In buildNondefiningFunctionDeclaration_T(): func_symbol->get_declaration() = %p \n", func_symbol->get_declaration());
2921 }
2922#endif /* DBG1 */
2923
2924 // If not a proper function (or instantiated template function), then check for a template function declaration.
2925 if (func_symbol == NULL)
2926 {
2927 // Note that a template function does not have a function type (just a name).
2928 ROSE_ASSERT(func_type != NULL);
2929 }
2930 }
2931
2932 // DQ (3/13/2012): I want to introduce error checking on the symbol matching the template parameter.
2933 if (func_symbol != NULL)
2934 {
2935 switch((VariantT)actualFunction::static_variant)
2936 {
2937 case V_SgFunctionDeclaration:
2938 case V_SgProcedureHeaderStatement:
2939 case V_SgTemplateInstantiationFunctionDecl:
2940 {
2941 ROSE_ASSERT(isSgFunctionSymbol(func_symbol) != NULL);
2942 break;
2943 }
2944 case V_SgMemberFunctionDeclaration:
2945 case V_SgTemplateInstantiationMemberFunctionDecl:
2946 {
2947 ROSE_ASSERT(isSgMemberFunctionSymbol(func_symbol) != NULL);
2948 break;
2949 }
2950 case V_SgTemplateFunctionDeclaration:
2951 {
2952 ROSE_ASSERT(isSgTemplateFunctionSymbol(func_symbol) != NULL);
2953 break;
2954 }
2955 case V_SgTemplateMemberFunctionDeclaration:
2956 {
2957 ROSE_ASSERT(isSgTemplateMemberFunctionSymbol(func_symbol) != NULL);
2958 break;
2959 }
2960
2961 default:
2962 {
2963 printf ("default reach in buildNondefiningFunctionDeclaration_T(): variantT(actualFunction::static_variant) = %d \n",actualFunction::static_variant);
2964 ROSE_ABORT();
2965 }
2966 }
2967
2968 // TV (2/5/14): Found symbol might come from another file, in this case we need to insert it in the current scope.
2969 // Can only happen when scope is a global scope
2970 ROSE_ASSERT(scope != NULL);
2971 if ( isSgGlobal(scope) != NULL
2972 && scope != func_symbol->get_scope()
2973 && !SageInterface::isAncestor(scope, func_symbol->get_scope())
2974 && !scope->symbol_exists(nameWithTemplateArguments, func_symbol) )
2975 {
2976 scope->insert_symbol(nameWithTemplateArguments, func_symbol);
2977 }
2978 }
2979
2980 if (func_symbol == NULL)
2981 {
2982 func = new actualFunction (nameWithTemplateArguments,func_type,NULL);
2983 ROSE_ASSERT(func != NULL);
2984
2985 // Storage modifier (esp. static) must be set before inserting symbol
2986 func->get_declarationModifier().get_storageModifier().set_modifier(sm);
2987
2988 // DQ (5/1/2012): This should always be true.
2989 ROSE_ASSERT(func->get_file_info() == NULL);
2990
2991 // DQ (12/14/2011): Moved this from lower in this function.
2992 func->set_scope(scope);
2993
2994 // DQ (12/15/2011): Added test.
2995 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(func,scope);
2996
2997 // This fails below for a SgTemplateFunctionDeclaration, so test it here.
2998 ROSE_ASSERT(func->get_parameterList() != NULL);
2999
3000 // NOTE: we want to allow the input scope to be NULL (and even the SageBuilder::topScopeStack() == NULL)
3001 // so that function can be built bottom up style. However this means that the symbol tables in the
3002 // scope of the returned function declaration will have to be setup separately.
3003 if (scope != NULL)
3004 {
3005 // function symbol table
3006 if (isSgMemberFunctionDeclaration(func))
3007 {
3008 // DQ (11/23/2011): This change allows this to compile for where SgTemplateFunctionDeclarations are used. I have
3009 // not decided if template declarations should cause symbols to be generated for functions and member functions.
3010 // func_symbol = new SgMemberFunctionSymbol(func);
3011 if (isSgTemplateMemberFunctionDeclaration(func) != NULL)
3012 func_symbol = new SgTemplateMemberFunctionSymbol(isSgTemplateMemberFunctionDeclaration(func));
3013 else
3014 {
3015 SgMemberFunctionDeclaration* memberFunctionDeclaration = isSgMemberFunctionDeclaration(func);
3016 ROSE_ASSERT(memberFunctionDeclaration != NULL);
3017 func_symbol = new SgMemberFunctionSymbol(memberFunctionDeclaration);
3018 }
3019
3020 ROSE_ASSERT(func_symbol != NULL);
3021 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
3022 }
3023 else
3024 {
3025 // if (isSgFunctionDeclaration(func))
3026 if (isSgTemplateFunctionDeclaration(func))
3027 {
3028 // How should we handled template functions in the symbol table???
3029 // DQ (11/24/2011): After some thought, I think that template declarations for function are more template declarations
3030 // than functions. So all template function declarations will be handled as SgTemplateSymbols and not SgFunctionSymbols.mplate function declarations.
3031 SgTemplateFunctionDeclaration* templatedeclaration = isSgTemplateFunctionDeclaration(func);
3032 ROSE_ASSERT(templatedeclaration != NULL);
3033 SgTemplateFunctionSymbol* template_symbol = new SgTemplateFunctionSymbol(templatedeclaration);
3034 ROSE_ASSERT(template_symbol != NULL);
3035 ROSE_ASSERT(template_symbol->get_symbol_basis() != NULL);
3036 func_symbol = template_symbol;
3037 }
3038 else
3039 {
3040 func_symbol = new SgFunctionSymbol(isSgFunctionDeclaration(func));
3041 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
3042 }
3043 }
3044
3045 ROSE_ASSERT(func_symbol != NULL);
3046 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
3047 scope->insert_symbol(nameWithTemplateArguments, func_symbol);
3048
3049 // DQ (3/8/2012): Added assertion.
3050 ROSE_ASSERT(func->get_symbol_from_symbol_table() != NULL);
3051
3052 if (isSgFunctionDeclaration(func) == NULL)
3053 {
3054 // DQ (12/18/2011): If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3055 // DQ (8/12/2013): Added template parameter list.
3056 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3057 // In this case these are unavailable from this point.
3058 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3059 }
3060
3061 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3062 // In this case these are unavailable from this point.
3063 // DQ (11/25/2011): Added support for template functions.
3064 // DQ (2/26/2009): uncommented assertion.
3065 // Did not pass for member function? Should we have used the mangled name?
3066 ROSE_ASSERT(buildTemplateDeclaration == false || templateParameterList != NULL);
3067
3068 // DQ (8/13/2013): We need to test for function symbols (which will include member function symbols),
3069 // template functions and template member functions. Each must be tested for seperately because template
3070 // functions and template member functions are not connected to derivation which non-template functions
3071 // and non-template member functions are connected through derivation.
3072 ROSE_ASSERT(scope->lookup_function_symbol(nameWithTemplateArguments) != NULL ||
3073 scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL ||
3074 scope->lookup_template_member_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3075
3076#if BUILDER_MAKE_REDUNDANT_CALLS_TO_SYMBOL_TABLE_LOOKUP
3077 // if (scope->lookup_function_symbol(name) == NULL || scope->lookup_template_symbol(name) != NULL)
3078 // if (scope->lookup_function_symbol(nameWithTemplateArguments) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments) != NULL)
3079 // if (scope->lookup_function_symbol(nameWithTemplateArguments) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments,NULL,NULL) != NULL)
3080 if (scope->lookup_function_symbol(nameWithTemplateArguments,templateArgumentList) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments,templateParameterList,NULL) != NULL)
3081 {
3082 // Make sure this is a template function declaration...
3083 printf ("Need to make sure this is a template function declaration... \n");
3084 }
3085#endif
3086 }
3087
3088 // DQ (12/14/2011): Added test.
3089 ROSE_ASSERT(func->get_scope() != NULL);
3090
3091 if (isSgFunctionDeclaration(func) == NULL)
3092 {
3093 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3094
3095 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3096 // In this case these are unavailable from this point.
3097 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3098 }
3099 func->set_firstNondefiningDeclaration(func);
3100 func->set_definingDeclaration(NULL);
3101
3102 // DQ (5/8/2016): We need to test the first defining declaration that we used.
3103 ROSE_ASSERT(func->get_firstNondefiningDeclaration() == func);
3104
3105 ROSE_ASSERT(func->get_definingDeclaration() == NULL);
3106
3107 // DQ (12/14/2011): Error checking
3108 SgTemplateInstantiationMemberFunctionDecl* testMemberDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
3109 if (testMemberDecl != NULL)
3110 {
3111 ROSE_ASSERT(testMemberDecl->get_scope() != NULL);
3112 ROSE_ASSERT(testMemberDecl->get_class_scope() != NULL);
3113 ROSE_ASSERT(testMemberDecl->get_associatedClassDeclaration() != NULL);
3114 }
3115 }
3116 else
3117 {
3118 ROSE_ASSERT(func_symbol != NULL);
3119
3120 ROSE_ASSERT(scope != NULL);
3121
3122 // 2nd, or 3rd... prototype declaration
3123 // reuse function type, function symbol of previous declaration
3124
3125 // std::cout<<"debug:SageBuilder.C: 267: "<<"found func_symbol!"<<std::endl;
3126 // delete (func_type-> get_argument_list ());
3127 // delete func_type; // bug 189
3128 SgNode* associatedSymbolBasis = func_symbol->get_symbol_basis();
3129 ROSE_ASSERT(associatedSymbolBasis != NULL);
3130
3131 SgDeclarationStatement* associatedDeclaration = isSgDeclarationStatement(associatedSymbolBasis);
3132 ROSE_ASSERT(associatedDeclaration != NULL);
3133 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(associatedDeclaration);
3134 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(associatedDeclaration);
3135
3136 if (functionDeclaration != NULL)
3137 {
3138 func_type = functionDeclaration->get_type();
3139 }
3140 else
3141 {
3142 if (templateFunctionDeclaration != NULL)
3143 {
3144 // DQ (5/8/2016): I think this code is never executed (because a templateFunctionDeclaration
3145 // is derived from a SgFunctionDeclaration, in the newer design (a few years ago)).
3146
3147 printf ("This code should not be reachable! \n");
3148 ROSE_ABORT();
3149
3150 func_type = templateFunctionDeclaration->get_type();
3151 }
3152 else
3153 {
3154 printf ("Error: associatedDeclaration = %p = %s \n",associatedDeclaration,associatedDeclaration->class_name().c_str());
3155 ROSE_ABORT();
3156 }
3157 }
3158 ROSE_ASSERT(func_type != NULL);
3159
3160 func = new actualFunction(nameWithTemplateArguments,func_type,NULL);
3161 ROSE_ASSERT(func != NULL);
3162
3163#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3164 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as translformations.
3165 // This is too early a point to test since the source position has not been set for func yet.
3166 // detectTransformations_local(func);
3167#endif
3168
3169 // DQ (12/14/2011): Moved this up from below.
3170 func->set_scope(scope);
3171
3172 // DQ (3/8/2012): Added assertion.
3173 ROSE_ASSERT(func->get_symbol_from_symbol_table() == NULL);
3174
3175 // DQ (12/15/2011): Added test.
3176 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(func,scope);
3177
3178 // we don't care if it is member function or function here for a pointer
3179 SgDeclarationStatement* prevDecl = NULL;
3180
3181 // This does not handle the case of a template function declaration.
3182 if (functionDeclaration != NULL)
3183 {
3184 prevDecl = functionDeclaration;
3185 }
3186 else
3187 {
3188 ROSE_ASSERT(templateFunctionDeclaration != NULL);
3189 prevDecl = templateFunctionDeclaration;
3190 }
3191
3192 ROSE_ASSERT(prevDecl != NULL);
3193
3194 SgFunctionSymbol *function_symbol = isSgFunctionSymbol(func_symbol);
3195 if (prevDecl == prevDecl->get_definingDeclaration())
3196 {
3197 // The symbol points to a defining declaration and now that we have added a non-defining
3198 // declaration we should have the symbol point to the new non-defining declaration.
3199 printf ("WARNING: Switching declaration in functionSymbol to point to the non-defining declaration \n");
3200 function_symbol->set_declaration(isSgFunctionDeclaration(func));
3201 ROSE_ASSERT(function_symbol->get_declaration() != NULL);
3202 }
3203
3204 // If this is the first non-defining declaration then set the associated data member.
3205 SgDeclarationStatement* nondefiningDeclaration = prevDecl->get_firstNondefiningDeclaration();
3206 if (nondefiningDeclaration == NULL)
3207 {
3208 nondefiningDeclaration = func;
3209 }
3210
3211 ROSE_ASSERT(nondefiningDeclaration != NULL);
3212 ROSE_ASSERT(func != NULL);
3213 ROSE_ASSERT(prevDecl != NULL);
3214
3215 func->set_firstNondefiningDeclaration(nondefiningDeclaration);
3216 func->set_definingDeclaration(prevDecl->get_definingDeclaration());
3217
3218 ROSE_ASSERT(nondefiningDeclaration->get_symbol_from_symbol_table() != NULL);
3219 ROSE_ASSERT(func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3220
3221 // DQ (3/8/2012): If this is the redundant function prototype then we have to look
3222 // at the first defining declaration since only it will have an associated symbol.
3223 if (func->get_symbol_from_symbol_table() == NULL)
3224 {
3225 ROSE_ASSERT(nondefiningDeclaration != NULL);
3226 ROSE_ASSERT(func->get_firstNondefiningDeclaration() == nondefiningDeclaration);
3227 }
3228
3229 // DQ (12/14/2011): Added test.
3230 ROSE_ASSERT(scope != NULL);
3231 ROSE_ASSERT(func->get_scope() != NULL);
3232 ROSE_ASSERT(func->get_scope() == scope);
3233
3234 // DQ (12/14/2011): Error checking
3235 SgTemplateInstantiationMemberFunctionDecl* testMemberDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
3236 if (testMemberDecl != NULL)
3237 {
3238 ROSE_ASSERT(testMemberDecl->get_scope() != NULL);
3239 ROSE_ASSERT(testMemberDecl->get_associatedClassDeclaration() != NULL);
3240 }
3241
3242 // DQ (12/18/2011): Testing to debug generation of wrong kind of declaration (symbol not found in correct scope or ...).
3243 if (isSgFunctionDeclaration(func) == NULL)
3244 {
3245 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3246 // DQ (8/12/2013): Added template parameter list.
3247 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3248 // In this case these are unavailable from this point.
3249 // DQ (12/18/2011): This fails because the first use of the function causes a non-defining function declaration
3250 // to be built and it is built as a template instantiation instead of a template declaration. So the symbol for
3251 // the non-defining declaration is put into the correct scope, but as a SgMemberFunctionSymbol instead of as a
3252 // SgTemplateSymbol (if it were built as a SgTemplateMemberFunctionDeclaration). So of course we can't find it
3253 // using lookup_template_symbol().
3254 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3255 }
3256 }
3257
3258 ROSE_ASSERT(func != NULL);
3259
3260 ROSE_ASSERT(func->get_file_info() == NULL);
3261
3262 // DQ (3/8/2012): Added assertion.
3263 ROSE_ASSERT(func->get_firstNondefiningDeclaration() != NULL);
3264 ROSE_ASSERT(func_symbol != NULL);
3265 ROSE_ASSERT(func_symbol->get_symbol_basis() == func->get_firstNondefiningDeclaration());
3266 ROSE_ASSERT(func->get_symbol_from_symbol_table() != NULL || func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3267
3268 // DQ (2/24/2009): Delete the old parameter list build by the actualFunction (template argument) constructor.
3269 ROSE_ASSERT(func->get_parameterList() != NULL);
3270 delete func->get_parameterList();
3271 func->set_parameterList(NULL);
3272
3273 // DQ (9/16/2012): Setup up the template arguments and the parents of the template arguments.
3274 if (buildTemplateInstantiation == true)
3275 {
3276 setTemplateArgumentsInDeclaration(func,templateArgumentsList);
3277 }
3278
3279 // DQ (8/10/2013): Setup the template parameters if this is a template declaration.
3280 if (buildTemplateDeclaration == true)
3281 {
3282 setTemplateParametersInDeclaration(func,templateParameterList);
3283
3284 // DQ (8/13/2013): Adding test of template parameter lists.
3285 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(func);
3286 ROSE_ASSERT(templateFunctionDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateFunctionDeclaration->get_templateParameters().size()));
3287
3288 SgTemplateMemberFunctionDeclaration* templateMemberFunctionDeclaration = isSgTemplateMemberFunctionDeclaration(func);
3289 ROSE_ASSERT(templateMemberFunctionDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateMemberFunctionDeclaration->get_templateParameters().size()));
3290 }
3291
3292 // parameter list
3293 // DQ (11/23/2011): This change allows this to compile for where SgTemplateFunctionDeclarations are used.
3294 setParameterList(func, paralist);
3295
3296 for (SgInitializedName* i_name : paralist->get_args())
3297 {
3298 i_name->set_scope(scope);
3299 }
3300
3301#if 0
3302 // DQ (7/12/2021): Debugging where nodes in the outliner are being marked as transformations (SgCastExpressions should not be marked as transformations).
3303 printf ("In buildNondefiningFunctionDeclaration_T(): setting the source position information (calling setTransformation()) \n");
3304#endif
3305
3306 // DQ (5/2/2012): Test this to make sure we have SgInitializedNames set properly.
3308
3309#if 0
3310 // DQ (7/12/2021): Debugging where nodes in the outliner are being marked as transformations (SgCastExpressions should not be marked as transformations).
3311 printf ("In buildNondefiningFunctionDeclaration_T(): DONE: setting the source position information (calling setTransformation()) \n");
3312#endif
3313
3314#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3315 // Liao 11/21/2012: we should assert no transformation only when the current model is NOT transformation
3316 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
3317 {
3318 detectTransformations_local(paralist);
3319 }
3320#endif
3321
3322 ASSERT_not_null(scope);
3323 ASSERT_not_null(func->get_scope());
3324 ASSERT_require(func->get_scope() == scope);
3325
3326 // DQ (1/5/2009): This is not always true (should likely use SageBuilder::topScopeStack() instead)
3327 if (SageBuilder::topScopeStack() != nullptr) // This comparison only makes sense when topScopeStack() returns non-NULL value
3328 {
3329 // since stack scope is totally optional in SageBuilder.
3330 if (scope != SageBuilder::topScopeStack())
3331 {
3332#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
3333 printf ("Warning: SageBuilder::buildNondefiningFunctionDeclaration_T(): scope parameter may not be the same as the topScopeStack() (e.g. for member functions) \n");
3334#endif
3335 }
3336 }
3337
3338 func->set_parent(scope);
3339 ASSERT_not_null(func->get_firstNondefiningDeclaration());
3340
3341 // mark as a forward declartion
3342 func->setForward();
3343
3344 ROSE_ASSERT(func->get_file_info() == NULL);
3345
3346 // set File_Info as transformation generated or front end generated
3348
3349 ROSE_ASSERT(func->get_file_info() != NULL);
3350
3351#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3352 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3353 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
3354 {
3355 detectTransformations_local(func);
3356 }
3357#endif
3358
3359 // printf ("In SageBuilder::buildNondefiningFunctionDeclaration_T(): generated function func = %p \n",func);
3360
3361 // Liao 12/2/2010, special handling for Fortran functions and subroutines
3362 if ((SageInterface::is_Fortran_language() == true) && (getEnclosingFileNode(scope)->get_outputLanguage() == SgFile::e_Fortran_language))
3363 {
3364 SgProcedureHeaderStatement * f_func = isSgProcedureHeaderStatement(func);
3365 ROSE_ASSERT (f_func != NULL);
3366 if (return_type == buildVoidType())
3368 else
3369 f_func->set_subprogram_kind(SgProcedureHeaderStatement::e_function_subprogram_kind);
3370
3371 // hide it from the unparser since fortran prototype func declaration is internally used by ROSE AST
3374 ROSE_ASSERT(f_func->get_startOfConstruct()->isOutputInCodeGeneration() == false);
3375 ROSE_ASSERT(f_func->get_endOfConstruct()->isOutputInCodeGeneration() == false);
3376 }
3377
3378 // DQ (12/11/2011): Added new test.
3379 ROSE_ASSERT(func->get_firstNondefiningDeclaration() != NULL);
3380 SgSymbol* symbol_from_first_nondefining_function = func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table();
3381 ROSE_ASSERT(symbol_from_first_nondefining_function != NULL);
3382
3383 // DQ (12/11/2011): Note that this may be false when func is not the first nondefining declaration.
3384 if (func != func->get_firstNondefiningDeclaration())
3385 {
3386 SgSymbol* symbol_from_nondefining_function = func->get_symbol_from_symbol_table();
3387 ROSE_ASSERT(symbol_from_nondefining_function == NULL);
3388 }
3389
3390 // DQ (12/18/2011): Testing to debug generation of wrong kind of declaration (symbol not found in correct scope or ...).
3391 if (isSgFunctionDeclaration(func) == NULL)
3392 {
3393 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3394 // DQ (8/12/2013): Make sure we use the template parameters and the template arguments that are available.
3395 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3396 // In this case these are unavailable from this point.
3397 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3398 }
3399
3400 // 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)).
3401 setTemplateNameInTemplateInstantiations(func,nameWithoutTemplateArguments);
3402
3403#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3404 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3405 if (SourcePositionClassificationMode !=e_sourcePositionTransformation)
3406 {
3407 detectTransformations_local(func);
3408 }
3409#endif
3410
3411 // DQ (12/11/2012): Force the two different ways that this can be set to match (we want consistancy).
3412 if (functionConstVolatileFlags & SgMemberFunctionType::e_restrict)
3413 {
3414 func->get_declarationModifier().get_typeModifier().setRestrict();
3415 }
3416
3417 // DQ (8/19/2013): Added assertion that is tested and which fails for test_3 of the RoseExample_tests directory (in edgRose.C).
3418 // This fails for everything.... not sure why...
3419
3420 // DQ (4/16/2015): This is replaced with a better implementation.
3421 // Make sure the isModified boolean is clear for all newly-parsed nodes.
3422 unsetNodesMarkedAsModified(func);
3423
3424 ROSE_ASSERT(paralist->get_parent() != NULL);
3425 return func;
3426 }
3427
3428
3432{
3433 ROSE_ASSERT(funcdecl!=NULL);
3434 SgName name=funcdecl->get_name();
3435 SgFunctionType * funcType = funcdecl->get_type();
3436 SgType* return_type = funcType->get_return_type();
3437 SgFunctionParameterList* paralist = deepCopy<SgFunctionParameterList>(funcdecl->get_parameterList());
3438
3439 // make sure the function has consistent function type based on its return type and parameter list
3440 SgFunctionType * ref_funcType= findFunctionType (return_type, funcType->get_argument_list());
3441 ROSE_ASSERT(funcType== ref_funcType);
3442
3443 // buildNondefiningFunctionDeclaration() will check if a same function is created before by looking up function symbols.
3444 SgFunctionDeclaration* returnFunction = buildNondefiningFunctionDeclaration (name, return_type, paralist, scope, decoratorList, false, NULL);
3445
3446 returnFunction->set_linkage(funcdecl->get_linkage());
3447 if (funcdecl->get_declarationModifier().get_storageModifier().isExtern() == true)
3448 {
3449 returnFunction->get_declarationModifier().get_storageModifier().setExtern();
3450 }
3451
3452 ROSE_ASSERT (returnFunction->get_linkage() == funcdecl->get_linkage());
3453 ROSE_ASSERT (returnFunction->get_declarationModifier().get_storageModifier().isExtern() ==
3454 funcdecl->get_declarationModifier().get_storageModifier().isExtern());
3455
3456 ROSE_ASSERT(returnFunction->get_firstNondefiningDeclaration() != NULL);
3457 // Make sure that internal references are to the same file (else the symbol table information will not be consistent).
3458 if (scope != NULL)
3459 {
3460 ROSE_ASSERT(returnFunction->get_firstNondefiningDeclaration() != NULL);
3461 }
3462
3463 return returnFunction;
3464}
3465
3467SageBuilder::buildNondefiningFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList, SgStorageModifier::storage_modifier_enum sm)
3468 {
3469 SgFunctionDeclaration * result = NULL;
3470 if ((SageInterface::is_Fortran_language() == true) && (getEnclosingFileNode(scope)->get_outputLanguage() == SgFile::e_Fortran_language))
3471 {
3472 result = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, NULL, sm);
3473 }
3474 else
3475 {
3476 // 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).
3477 if (buildTemplateInstantiation == true)
3478 {
3479 result = buildNondefiningFunctionDeclaration_T <SgTemplateInstantiationFunctionDecl> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, templateArgumentsList, NULL, sm);
3480 }
3481 else
3482 {
3483 result = buildNondefiningFunctionDeclaration_T <SgFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, NULL, sm);
3484 }
3485 }
3486
3487 return result;
3488 }
3489
3490
3491// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficent).
3492// We need to decide if the SageBuilder API should include these sorts of functions.
3495 {
3496 unsigned int memberFunctionModifiers = 0;
3497 return buildNondefiningMemberFunctionDeclaration (name,return_type,paralist,scope,NULL,memberFunctionModifiers,false,NULL);
3498 }
3499
3500// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficient).
3501// We need to decide if the SageBuilder API should include these sorts of functions.
3504 {
3505 if (scope == NULL)
3506 {
3508 }
3509
3510 unsigned int memberFunctionModifiers = 0;
3512 SgMemberFunctionDeclaration* nondefining_decl = NULL;
3513 SgMemberFunctionType* member_func_type = buildMemberFunctionType(return_type,param_type_list, scope, memberFunctionModifiers);
3514 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgMemberFunctionDeclaration>(name,member_func_type,NULL,NULL);
3515 SgMemberFunctionSymbol* member_func_symbol = isSgMemberFunctionSymbol(func_symbol);
3516
3517 if (member_func_symbol != NULL)
3518 {
3519 nondefining_decl = member_func_symbol->get_declaration();
3520 }
3521 else
3522 {
3523 // each defining member function decl must have a non-defining counter part now. 11/27/2012, Liao
3524 nondefining_decl = buildNondefiningMemberFunctionDeclaration (name, return_type, paralist, scope,NULL, memberFunctionModifiers, false, NULL);
3525 }
3526 return buildDefiningMemberFunctionDeclaration (name,return_type,paralist,scope,NULL,false,memberFunctionModifiers,nondefining_decl,NULL);
3527 }
3528
3529
3530// SgTemplateFunctionDeclaration* SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList)
3531// SgTemplateFunctionDeclaration* SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateArgumentPtrList* templateArgumentsList)
3533SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateParameterPtrList* templateParameterList)
3534 {
3535 // DQ (8/15/2013): Note that we don't need template arguments because teplate functions can't support partial specialization.
3536
3537 // DQ (11/25/2011): Adding support for template declarations in the AST.
3538
3539 // DQ (8/7/2013): Added support for template function overloading using template parameters.
3540 SgTemplateFunctionDeclaration* result = buildNondefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, templateParameterList, SgStorageModifier::e_default);
3541
3542 // DQ (12/12/2011): Added test.
3543 ROSE_ASSERT(result != NULL);
3544 if (result->get_symbol_from_symbol_table() == NULL)
3545 {
3546 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3547 ROSE_ASSERT(result != result->get_firstNondefiningDeclaration());
3548 ROSE_ASSERT(result->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3549 }
3550
3551 // DQ (2/12/2015): Added assertions earlier before calling buildDefiningFunctionDeclaration_T<>().
3552 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3553
3554 return result;
3555 }
3556
3558SageBuilder::buildDefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateFunctionDeclaration* first_nondefining_declaration)
3559 {
3560 // DQ (12/1/2011): Adding support for template declarations in the AST.
3561
3562 // DQ (7/31/2013): Added assertions earlier before calling buildDefiningFunctionDeclaration_T<>().
3563 ROSE_ASSERT(first_nondefining_declaration != NULL);
3564 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() != NULL);
3565 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3566
3567 // template <class actualFunction> actualFunction * buildDefiningFunctionDeclaration_T (const SgName & name, SgType* return_type, SgFunctionParameterList * parlist, SgScopeStatement* scope=NULL, SgExprListExp* decoratorList = NULL);
3568 // SgTemplateFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ false, scope, decoratorList,functionConstVolatileFlags);
3569 // SgTemplateFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ false, scope, decoratorList, 0, first_nondefining_declaration);
3570 SgTemplateFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ false, scope, decoratorList, 0, first_nondefining_declaration, NULL);
3571
3572 return result;
3573 }
3574
3576SageBuilder::buildDefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList *paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, SgTemplateMemberFunctionDeclaration* first_nondefining_declaration)
3577 {
3578 // DQ (12/1/2011): Adding support for template declarations in the AST.
3579
3580 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3581
3582 SgTemplateMemberFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true, scope, decoratorList, functionConstVolatileFlags, first_nondefining_declaration, NULL);
3583 ROSE_ASSERT(result != NULL);
3584
3585 ROSE_ASSERT(result->get_definition() != NULL);
3586
3587 return result;
3588 }
3589
3592 SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList)
3593 {
3594 // This function builds either a SgMemberFunctionDeclaration (non-template; normal member function) or a SgTemplateInstantiationMemberFunctionDecl (template instantiation).
3595
3596 // DQ (11/27/2011): Added support for instations of template member functions.
3597 SgMemberFunctionDeclaration * result = NULL;
3598
3599 if (buildTemplateInstantiation == true)
3600 {
3601 // This is how we build an instantiation of a template (SgTemplateInstantiationMemberFunctionDecl).
3602 result = buildNondefiningFunctionDeclaration_T <SgTemplateInstantiationMemberFunctionDecl> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,templateArgumentsList,NULL, SgStorageModifier::e_default);
3603 }
3604 else
3605 {
3606 // This is a non-template instatiation (normal member function).
3607 result = buildNondefiningFunctionDeclaration_T <SgMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,NULL,NULL, SgStorageModifier::e_default);
3608 }
3609 ROSE_ASSERT(result != NULL);
3610
3611 // set definingdecl for SgCtorInitializerList
3613 ROSE_ASSERT(ctor != NULL);
3614
3615 // required in AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3616 ctor->set_definingDeclaration(ctor);
3618
3619 // DQ (1/4/2009): Error checking
3620 ROSE_ASSERT(result->get_associatedClassDeclaration() != NULL);
3621
3622 if (result->get_associatedClassDeclaration() == NULL)
3623 {
3624 printf ("Warning, must set the SgMemberFunctionDeclaration::associatedClassDeclaration \n");
3625
3626 ROSE_ASSERT(scope != NULL);
3627 SgClassDefinition* classDefinition = isSgClassDefinition(scope);
3628 ROSE_ASSERT(classDefinition != NULL);
3629 SgDeclarationStatement* associatedDeclaration = classDefinition->get_declaration();
3630 ROSE_ASSERT(associatedDeclaration != NULL);
3631 SgClassDeclaration* associatedClassDeclaration = isSgClassDeclaration(associatedDeclaration);
3632
3633 // DQ (1/4/2009): This needs to be set, checked in AstConsistencyTests.C!
3634 result->set_associatedClassDeclaration(associatedClassDeclaration);
3635 }
3636
3637 return result;
3638 }
3639
3640
3641// DQ (8/12/2013): This function needs to handle the SgTemplateParameterPtrList (since it is generating a template).
3642// It need not take a SgTemplateArgumentPtrList because template functions (including template member functions) can not support partial specialization.
3643// SgTemplateMemberFunctionDeclaration* SageBuilder::buildNondefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags)
3645SageBuilder::buildNondefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, SgTemplateParameterPtrList* templateParameterList)
3646 {
3647 // This function only builds template member function declarations.
3648
3649 SgTemplateMemberFunctionDeclaration * result = buildNondefiningFunctionDeclaration_T <SgTemplateMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,NULL,templateParameterList, SgStorageModifier::e_default);
3650
3651 // set definingdecl for SgCtorInitializerList
3652 ROSE_ASSERT(result != NULL);
3653
3654#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3655 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as translformations.
3657 {
3658 detectTransformations_local(result);
3659 }
3660#endif
3661
3662 // DQ (8/12/2013): Added template paremter list to call to get the function template symbol.
3663 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3664 // In this case these are unavailable from this point.
3665 SgSymbol* associatedSymbol = scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList);
3666 if (associatedSymbol == NULL)
3667 {
3668 printf ("ERROR: associatedSymbol == NULL \n");
3669 printf (" --- result = %p = %s \n",result,result->class_name().c_str());
3670 printf (" --- scope = %p = %s \n",scope,scope->class_name().c_str());
3671 printf (" --- name = %s \n",name.str());
3672 printf (" --- result->get_type() = %p = %s \n",result->get_type(),result->get_type()->class_name().c_str());
3673 printf (" --- result->get_type()->get_mangled() = %s \n",result->get_type()->get_mangled().str());
3674 }
3675 ROSE_ASSERT(associatedSymbol != NULL);
3676
3678 ROSE_ASSERT(ctor != NULL);
3679 // required ty AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3680 ctor->set_definingDeclaration(ctor);
3682
3683 // DQ (12/11/2011): Added new test (also at the base of buildNondefiningFunctionDeclaration_T<>() function).
3684 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3685 SgSymbol* symbol_from_first_nondefining_function = result->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table();
3686 ROSE_ASSERT(symbol_from_first_nondefining_function != NULL);
3687
3688 // DQ (12/11/2011): Note that this may be false when func is not the first nondefining declaration.
3689 if (result != result->get_firstNondefiningDeclaration())
3690 {
3691 SgSymbol* symbol_from_nondefining_function = result->get_symbol_from_symbol_table();
3692 ROSE_ASSERT(symbol_from_nondefining_function == NULL);
3693 }
3694
3695#if BUILDER_MAKE_REDUNDANT_CALLS_TO_SYMBOL_TABLE_LOOKUP
3696 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3697 // In this case these are unavailable from this point.
3698 if (scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList) == NULL)
3699 {
3700 printf ("Error: scope->lookup_template_member_function_symbol(name,result->get_type()) == NULL (investigate this) \n");
3701 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());
3702 scope->get_symbol_table()->print("Error: scope->lookup_template_member_function_symbol(name,result->get_type()) == NULL (investigate this)");
3703 }
3704#endif
3705 ROSE_ASSERT(scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList) != NULL);
3706
3707#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3708 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3710 {
3711 detectTransformations_local(result);
3712 }
3713#endif
3714
3715 return result;
3716 }
3717
3719SageBuilder::buildDefiningMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, unsigned int functionConstVolatileFlags, SgMemberFunctionDeclaration* first_nondefining_declaration, SgTemplateArgumentPtrList* templateArgumentsList)
3720 {
3721 // DQ (12/18/2011): Need to build a SgTemplateInstantiationMemberFunctionDecl when buildTemplateInstantiation == true
3722 SgMemberFunctionDeclaration * result = NULL;
3723 if (buildTemplateInstantiation == true)
3724 {
3725 SgTemplateInstantiationMemberFunctionDecl* templateInstantiationMemberFunctionDecl = isSgTemplateInstantiationMemberFunctionDecl(first_nondefining_declaration);
3726 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
3727
3728 // DQ (1/26/2013): Added test failing in buildDefiningFunctionDeclaration_T().
3729 {
3730 ROSE_ASSERT(templateArgumentsList != NULL);
3731 string nameWithoutTemplateArguments = name;
3732 string nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
3733 SgMemberFunctionType* func_type = isSgMemberFunctionType(first_nondefining_declaration->get_type());
3734 ROSE_ASSERT(func_type != NULL);
3735
3736 // DQ (8/7/2013): API change due to added support for template function overloading using template parameters.
3737 SgSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgTemplateInstantiationMemberFunctionDecl>(nameWithTemplateArguments,func_type,NULL,templateArgumentsList);
3738 if (func_symbol == NULL)
3739 {
3740 printf ("ERROR caught in SageBuilder::buildDefiningMemberFunctionDeclaration(): nameWithTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithTemplateArguments.c_str(),buildTemplateInstantiation ? "true:" : "false");
3741 printf ("ERROR caught in SageBuilder::buildDefiningMemberFunctionDeclaration(): func_symbol == NULL for first_nondefining_declaration = %p = %s and func_type = %p = %s \n",
3742 templateInstantiationMemberFunctionDecl,templateInstantiationMemberFunctionDecl->class_name().c_str(),func_type,func_type->class_name().c_str());
3743 }
3744 }
3745
3746 result = buildDefiningFunctionDeclaration_T <SgTemplateInstantiationMemberFunctionDecl> (name, return_type, paralist, /* isMemberFunction = */ true, scope, decoratorList, functionConstVolatileFlags, templateInstantiationMemberFunctionDecl, templateArgumentsList);
3747 ROSE_ASSERT(isSgTemplateInstantiationMemberFunctionDecl(result) != NULL);
3748 ROSE_ASSERT(isSgTemplateInstantiationMemberFunctionDecl(result)->get_templateName().is_null() == false);
3749 }
3750 else
3751 {
3752 ROSE_ASSERT(first_nondefining_declaration != NULL);
3753
3754 // DQ (12/27/20134): Added these to permit testing earlier than in the buildDefiningFunctionDeclaration_T() function.
3755 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() != NULL);
3756 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3757
3758 result = buildDefiningFunctionDeclaration_T <SgMemberFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,first_nondefining_declaration, NULL);
3759 }
3760
3761 ROSE_ASSERT(result != NULL);
3762
3763 // set definingdecl for SgCtorInitializerList
3765 ROSE_ASSERT(ctor != NULL);
3766
3767 // required ty AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3768 ctor->set_definingDeclaration(ctor);
3770
3771 // DQ (1/4/2009): Error checking
3772 ROSE_ASSERT(result->get_associatedClassDeclaration() != NULL);
3773
3774 return result;
3775 }
3776
3777
3778//----------------- defining function declaration------------
3779// a template builder for all kinds of defining SgFunctionDeclaration
3780// handle common chores for function type, symbol, paramter etc.
3781
3782template <class actualFunction>
3783actualFunction*
3784SageBuilder::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)
3785 {
3786 // Note that the semantics of this function now differs from that of the buildDefiningClassDeclaration().
3787 // We want to have the non-defining declaration already exist before calling this function.
3788 // We could still build a higher level function that built both together. Or we could provide two versions
3789 // named differently (from this one) and depricate this function...which I like much better.
3790
3791#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
3792 printf ("WARNING: This function for building defining function declarations has different semantics from that of the function to build defining class declarations. \n");
3793#endif
3794
3795 ASSERT_not_null(first_nondefining_declaration);
3796 ASSERT_require(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3797
3798 if (scope == nullptr)
3799 {
3801 }
3802
3803 ASSERT_require(XXX_name.is_null() == false);
3804 ASSERT_not_null(scope);
3805 ASSERT_not_null(return_type);
3806
3807 SgName nameWithoutTemplateArguments = XXX_name;
3808 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
3809
3810 bool buildTemplateInstantiation = ((VariantT)actualFunction::static_variant == V_SgTemplateInstantiationFunctionDecl || (VariantT)actualFunction::static_variant == V_SgTemplateInstantiationMemberFunctionDecl);
3811
3812 // DQ (8/7/2013): Added support for template declarations.
3813 bool buildTemplateDeclaration = ((VariantT)actualFunction::static_variant == V_SgTemplateFunctionDeclaration || (VariantT)actualFunction::static_variant == V_SgTemplateMemberFunctionDeclaration);
3814
3815 // DQ (8/11/2013): Check that the template argument lists are consistant. The templateArgumentsList can then be considered redundant if this works.
3816 if (buildTemplateInstantiation == true)
3817 {
3818 ASSERT_not_null(templateArgumentsList);
3819
3820 SgTemplateArgumentPtrList & templateArgumentsList_from_first_nondefining_declaration = (isMemberFunction == false) ?
3821 isSgTemplateInstantiationFunctionDecl(first_nondefining_declaration)->get_templateArguments() :
3822 isSgTemplateInstantiationMemberFunctionDecl(first_nondefining_declaration)->get_templateArguments();
3823
3824 ASSERT_not_null(templateArgumentsList);
3825 bool templateArgumentListsAreEquivalent = SageInterface::templateArgumentListEquivalence(*templateArgumentsList, templateArgumentsList_from_first_nondefining_declaration);
3826 ASSERT_require(templateArgumentListsAreEquivalent == true);
3827 }
3828
3829 SgTemplateParameterPtrList* templateParameterList = nullptr;
3830 if (buildTemplateDeclaration == true)
3831 {
3832 // 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.
3833 templateParameterList = (isMemberFunction == false) ?
3834 &(isSgTemplateFunctionDeclaration(first_nondefining_declaration)->get_templateParameters()) :
3835 &(isSgTemplateMemberFunctionDeclaration(first_nondefining_declaration)->get_templateParameters());
3836
3837 ASSERT_require(templateArgumentsList == nullptr);
3838 ASSERT_not_null(templateParameterList);
3839 }
3840
3841 if (buildTemplateInstantiation == true)
3842 {
3843 ASSERT_not_null(templateArgumentsList);
3844 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
3845
3846 if (nameWithTemplateArguments == "insert < __normal_iterator< SgInitializedName ** , __type > > ")
3847 {
3848 printf ("In buildDefiningFunctionDeclaration_T(): Found function nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
3849 }
3850 }
3851
3852 ASSERT_require(nameWithoutTemplateArguments.is_null() == false);
3853 ASSERT_require(nameWithTemplateArguments.is_null() == false);
3854 ASSERT_not_null(paralist);
3855
3857 {
3858 ASSERT_require(scope->containsOnlyDeclarations());
3859 }
3860
3861 // build function type, manage function type symbol internally
3862 actualFunction* defining_func = nullptr;
3863 SgFunctionType* func_type = nullptr;
3864
3865 // 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).
3866 // This is a special problem for templates because the function parameters will evaluate different for different builds of the same template.
3867 // This is a problem for test2012_74.C (and a dozen other test codes that make use of STL).
3868 ASSERT_not_null(first_nondefining_declaration);
3869
3870 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
3871 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
3872 // DQ (7/27/2012): There are reasons why this can fail: e.g. for functions with names such as:
3873 // "operator std::auto_ptr_ref<_Tp1>" which is a user defined conversion operator to one class from another.
3874
3875 // DQ (5/12/2012): Use the newly added parameter to get the exact SgFunctionType used to build the symbol.
3876 // This should make the template handling more robust since we were sometimes using types that had different
3877 // levels of template instantiation between the non-definng and defining function declarations and this
3878 // caused symbols build to support the non-defining declaration to not be found when we searched for them
3879 // using the function type built for the defining declaration. We want the function types for all defining
3880 // and non-defining declarations to be identical. This define also means that we don't have to build a
3881 // SgFunctionType just to look up a symbol in the symbol table (which was always silly). However, only
3882 // the defining function declaration can use the existing function type because it is required that a
3883 // non-defining declaration exist prior to the construction of the defining declaration (built by this
3884 // function).
3885 func_type = first_nondefining_declaration->get_type();
3886 ASSERT_not_null(func_type);
3887
3888 // Make sure these are the same (this will fail until we generate the func_type directly from first_nondefining_declaration).
3889 ASSERT_require(func_type == first_nondefining_declaration->get_type());
3890
3891 SgDeclarationStatement* firstNondefiningFunctionDeclaration = nullptr;
3892
3893 // symbol table and non-defining
3894 SgSymbol* func_symbol = scope->find_symbol_by_type_of_function<actualFunction>(nameWithTemplateArguments,func_type,templateParameterList,templateArgumentsList);
3895
3896 // DQ (1/26/2013): This fails for ROSE compiling ROSE.
3897 ASSERT_not_null(func_symbol);
3898
3899 if (func_symbol == nullptr)
3900 {
3901 // DQ (12/2/2011): After discussion with Liao, we think this should be an error.
3902 // The defining declaration requires that the associated non-defining declaration should already exist.
3903 // If required, a higher level build function could build both of these and connect them as required.
3904 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");
3905 ROSE_ABORT();
3906 }
3907 else
3908 {
3909 // We will now build a reference to the non-defining declaration found in the symbol.
3910
3911 // defining declaration after nondefining declaration
3912 // reuse function type, function symbol
3913
3914 // Cong (10/25/2010): Make sure in this situation there is no defining declaration for this symbol.
3915
3916 SgFunctionSymbol* temp_function_sym = isSgFunctionSymbol(func_symbol);
3917 SgTemplateSymbol* temp_template_sym = isSgTemplateSymbol(func_symbol);
3918 if (temp_function_sym != nullptr)
3919 {
3920 func_type = temp_function_sym->get_declaration()->get_type();
3921 firstNondefiningFunctionDeclaration = temp_function_sym->get_declaration()->get_firstNondefiningDeclaration();
3922 }
3923 else
3924 {
3925 // There is no type for a template function declaration.
3926 ASSERT_not_null(temp_template_sym);
3927 firstNondefiningFunctionDeclaration = temp_template_sym->get_declaration()->get_firstNondefiningDeclaration();
3928 }
3929 ASSERT_not_null(firstNondefiningFunctionDeclaration);
3930 }
3931
3932 defining_func = new actualFunction(nameWithTemplateArguments,func_type,nullptr);
3933 ASSERT_not_null(defining_func);
3934
3935 ASSERT_not_null(firstNondefiningFunctionDeclaration);
3936 defining_func->set_firstNondefiningDeclaration(firstNondefiningFunctionDeclaration);
3937
3938 // fix up defining declarations before current statement
3939 firstNondefiningFunctionDeclaration->set_definingDeclaration(defining_func);
3940
3941 // Handle decorators (Python specific)
3942 if (decoratorList != nullptr)
3943 {
3944 defining_func->set_decoratorList(decoratorList);
3945 decoratorList->set_parent(defining_func);
3946 }
3947
3948 // definingDeclaration
3949 defining_func->set_definingDeclaration(defining_func);
3950
3951 // function body and definition are created before setting argument list
3952 SgBasicBlock * func_body = new SgBasicBlock();
3953 ASSERT_not_null(func_body);
3954
3955 SgFunctionDefinition* func_def = nullptr;
3956 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(defining_func);
3957
3958 // Build either a definition for a template or non-template function definition.
3959 if (templateFunctionDeclaration == nullptr)
3960 {
3961 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(defining_func);
3962 ASSERT_not_null(functionDeclaration);
3963 func_def = new SgFunctionDefinition(functionDeclaration,func_body);
3964 }
3965 else
3966 {
3967 ASSERT_not_null(templateFunctionDeclaration);
3968 func_def = new SgTemplateFunctionDefinition(templateFunctionDeclaration,func_body);
3969 }
3970 ASSERT_not_null(func_def);
3971
3973 {
3974 func_def->setCaseInsensitive(true);
3975 func_body->setCaseInsensitive(true);
3976 }
3977
3978 func_def->set_parent(defining_func);
3979 func_def->set_body(func_body);
3980 func_body->set_parent(func_def);
3981
3982 // parameter list,
3983 // TODO consider the difference between C++ and Fortran
3984 setParameterList(defining_func,paralist);
3985 // fixup the scope and symbol of arguments,
3986 for (SgInitializedName* i_name : paralist->get_args())
3987 {
3988 i_name->set_scope(func_def);
3989
3990 SgVariableSymbol* variableSymbol = new SgVariableSymbol(i_name);
3991 ASSERT_not_null(variableSymbol);
3992 func_def->insert_symbol(i_name->get_name(), variableSymbol);
3993
3994 // For variable length array types in the function parameter list
3995 SgArrayType* arrayType = isSgArrayType(i_name->get_type());
3996 if (arrayType != nullptr)
3997 {
3998 // Check if this is a VLA array type, if so look for the index expressions and check
3999 // if we need to add asociated symbols to the current function definition scope.
4000 SgExpression* indexExpression = arrayType->get_index();
4001
4002 if (indexExpression != nullptr)
4003 {
4004 // DQ (2/14/2016): Handle the case of an expression tree with any number of variable references.
4005 // Get the list of SgVarRef IR nodes and process each one as above.
4006 vector<SgVarRefExp* > varRefList;
4007 collectVarRefs(indexExpression,varRefList);
4008
4009 for (size_t i = 0; i < varRefList.size(); i++)
4010 {
4011 // Process each index subtree's SgVarRefExp.
4012 SgVariableSymbol* dimension_variableSymbol = varRefList[i]->get_symbol();
4013 ASSERT_not_null(dimension_variableSymbol);
4014 ASSERT_require(dimension_variableSymbol != variableSymbol);
4015
4016 // The symbol from the referenced variable for the array dimension expression shuld already by in the function definition's symbol table.
4017 SgSymbol* symbolFromLookup = func_def->lookup_symbol(dimension_variableSymbol->get_name());
4018 if (symbolFromLookup != nullptr)
4019 {
4020 SgVariableSymbol* variableSymbolFromLookup = isSgVariableSymbol(symbolFromLookup);
4021 ASSERT_not_null(variableSymbolFromLookup);
4022
4023 varRefList[i]->set_symbol(variableSymbolFromLookup);
4024 ASSERT_require(dimension_variableSymbol != variableSymbol);
4025 }
4026 else
4027 {
4028 // 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.
4029 }
4030 }
4031 }
4032 }
4033 }
4034
4035 defining_func->set_parent(scope);
4036 defining_func->set_scope(scope);
4037
4038 ASSERT_not_null(defining_func->get_scope());
4039
4040 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(defining_func,scope);
4041
4042 // set File_Info as transformation generated
4044
4045 // Enforce that the return type matches the specification to build a member function.
4046 if (isMemberFunction == true)
4047 {
4048 ASSERT_not_null(isSgMemberFunctionDeclaration(defining_func));
4049 }
4050
4051 // 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)).
4052 setTemplateNameInTemplateInstantiations(defining_func,nameWithoutTemplateArguments);
4053
4054 // DQ (9/16/2012): Setup up the template arguments and the parents of the template arguments.
4055 if (buildTemplateInstantiation == true)
4056 {
4057 setTemplateArgumentsInDeclaration(defining_func,templateArgumentsList);
4058 }
4059
4060 // DQ (8/13/2013): Added code to set the template parameters in the defining declaration (if it is a template declaration).
4061 if (buildTemplateDeclaration == true)
4062 {
4063 setTemplateParametersInDeclaration(defining_func,templateParameterList);
4064
4065 // DQ (8/13/2013): Adding test of template parameter lists.
4066 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(defining_func);
4067 ROSE_ASSERT(templateFunctionDeclaration == nullptr || (templateParameterList != nullptr && templateParameterList->size() == templateFunctionDeclaration->get_templateParameters().size()));
4068 SgTemplateMemberFunctionDeclaration* templateMemberFunctionDeclaration = isSgTemplateMemberFunctionDeclaration(defining_func);
4069 ROSE_ASSERT(templateMemberFunctionDeclaration == nullptr || (templateParameterList != nullptr && templateParameterList->size() == templateMemberFunctionDeclaration->get_templateParameters().size()));
4070 }
4071
4072 // DQ (12/12/2012): Force the two different ways that this can be set to match (we want consistancy).
4073 if (functionConstVolatileFlags & SgMemberFunctionType::e_restrict)
4074 {
4075 defining_func->get_declarationModifier().get_typeModifier().setRestrict();
4076 }
4077
4078 // DQ (4/16/2015): This is replaced with a better implementation.
4079 // DQ (4/15/2015): We should reset the isModified flags as part of the transforamtion
4080 // because we have added statements explicitly marked as transformations.
4081 // checkIsModifiedFlag(defining_func);
4082 unsetNodesMarkedAsModified(defining_func);
4083
4084 return defining_func;
4085 }
4086
4087void
4089 {
4090 // 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)).
4091
4092 SgTemplateInstantiationFunctionDecl* templateInstantiationFunctionDecl = isSgTemplateInstantiationFunctionDecl(func);
4093 SgTemplateInstantiationMemberFunctionDecl* templateInstantiationMemberFunctionDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
4094 bool isTemplateInstantition = (templateInstantiationFunctionDecl != NULL) || (templateInstantiationMemberFunctionDecl != NULL);
4095 if (isTemplateInstantition == true)
4096 {
4097 // If this is a template instantiation then we need to take care of a few more issues.
4098
4099 SgName templateNameWithoutArguments = name;
4100
4101 // DQ (7/27/2012): New semantics is that we want to have the input name be without template arguments and
4102 // we will add the template arguments instead of trying to remove then (which was problematic for examples
4103 // such as "X<Y<Z>> operator X&()" and "X<Y<Z>> operator>()".
4104
4105 bool isMemberFunction = (templateInstantiationMemberFunctionDecl != NULL);
4106 if (isMemberFunction == true)
4107 {
4108 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
4109 ROSE_ASSERT(templateInstantiationFunctionDecl == NULL);
4110
4111 if (templateInstantiationMemberFunctionDecl->get_templateName().is_null() == true)
4112 {
4113 // Set the template name for the member function template instantiation.
4114 // templateInstantiationMemberFunctionDecl->set_templateName(name);
4115 templateInstantiationMemberFunctionDecl->set_templateName(templateNameWithoutArguments);
4116
4117 // DQ (5/31/2012): Find locations where this is set and include template syntax.
4118 }
4119 ROSE_ASSERT(templateInstantiationMemberFunctionDecl->get_templateName().is_null() == false);
4120 }
4121 else
4122 {
4123 ROSE_ASSERT(templateInstantiationFunctionDecl != NULL);
4124 ROSE_ASSERT(templateInstantiationMemberFunctionDecl == NULL);
4125
4126 if (templateInstantiationFunctionDecl->get_templateName().is_null() == true)
4127 {
4128 // Set the template name for the function template instantiation.
4129 // templateInstantiationFunctionDecl->set_templateName(name);
4130 templateInstantiationFunctionDecl->set_templateName(templateNameWithoutArguments);
4131
4132 // DQ (5/31/2012): Find locations where this is set and include template syntax.
4133 ROSE_ASSERT(hasTemplateSyntax(templateNameWithoutArguments) == false);
4134 }
4135 ROSE_ASSERT(templateInstantiationFunctionDecl->get_templateName().is_null() == false);
4136 }
4137 }
4138 }
4139
4141SageBuilder::buildDefiningFunctionDeclaration(const SgName& name, SgType* return_type, SgFunctionParameterList* paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, SgFunctionDeclaration* first_nondefining_declaration, SgTemplateArgumentPtrList* templateArgumentsList)
4142 {
4143 // DQ (2/10/2012): Fixed to build either SgTemplateInstantiationFunctionDecl or SgFunctionDeclaration.
4144 SgFunctionDeclaration* func = NULL;
4145 if (buildTemplateInstantiation == true)
4146 {
4147 SgTemplateInstantiationFunctionDecl* templateInstantiationFunctionDecl = isSgTemplateInstantiationFunctionDecl(first_nondefining_declaration);
4148
4149 ROSE_ASSERT(first_nondefining_declaration != NULL);
4150
4151 func = buildDefiningFunctionDeclaration_T<SgTemplateInstantiationFunctionDecl>(name,return_type,paralist,/* isMemberFunction = */ false,scope,decoratorList,0,templateInstantiationFunctionDecl, templateArgumentsList);
4152
4153 ROSE_ASSERT(isSgTemplateInstantiationFunctionDecl(func) != NULL);
4154 ROSE_ASSERT(isSgTemplateInstantiationFunctionDecl(func)->get_templateName().is_null() == false);
4155 }
4156 else
4157 {
4158 ROSE_ASSERT(first_nondefining_declaration != NULL);
4159
4160 func = buildDefiningFunctionDeclaration_T<SgFunctionDeclaration>(name,return_type,paralist,/* isMemberFunction = */ false,scope,decoratorList,0,first_nondefining_declaration, NULL);
4161
4162 ROSE_ASSERT(isSgFunctionDeclaration(func) != NULL);
4163 }
4164
4165 return func;
4166 }
4167
4168
4169// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficent).
4170// We need to decide if the SageBuilder API should include these sorts of functions.
4173 {
4174 // DQ (11/12/2012): Note that this function is not used in the AST construction in the EDG/ROSE interface.
4175
4176 // DQ (8/23/2013): Added assertions.
4177 ROSE_ASSERT(return_type != NULL);
4178 ROSE_ASSERT(parameter_list != NULL);
4179
4180 // DQ (8/23/2013): We need to provide the buildDefiningFunctionDeclaration() function with a pointer to the first non-defining declaration.
4181 // 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.
4182 // DQ (11/12/2012): Building a defining declaration from scratch now requires a non-defining declaration to exist.
4183 // SgFunctionDeclaration* nondefininfDeclaration = buildNondefiningFunctionDeclaration(name,return_type,parameter_list,scope,NULL);
4184
4185 if (scope == NULL)
4186 {
4188 }
4189
4190 SgFunctionDeclaration* nondefiningDeclaration = NULL;
4191
4192 SgFunctionType* func_type = buildFunctionType(return_type,parameter_list);
4193 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgFunctionDeclaration>(name,func_type,NULL,NULL);
4194 if (func_symbol != NULL)
4195 {
4196 nondefiningDeclaration = func_symbol->get_declaration();
4197 }
4198 else
4199 {
4200 nondefiningDeclaration = buildNondefiningFunctionDeclaration(name,return_type,parameter_list,scope,NULL);
4201 }
4202
4203 ROSE_ASSERT(nondefiningDeclaration != NULL);
4204 ROSE_ASSERT(nondefiningDeclaration->get_firstNondefiningDeclaration() != NULL);
4205 ROSE_ASSERT(nondefiningDeclaration->get_firstNondefiningDeclaration() == nondefiningDeclaration);
4206
4207 return buildDefiningFunctionDeclaration (name,return_type,parameter_list,scope,NULL,false,nondefiningDeclaration,NULL);
4208 }
4209
4210// Build a nondefining SgProcedureHeaderStatement, handle function type, symbol etc transparently [Rasmussen 9/24/2020]
4214 {
4215 ASSERT_not_null(return_type);
4216 ASSERT_not_null(param_list);
4217
4218 SgProcedureHeaderStatement* nondef_decl = nullptr;
4219
4220 if (scope == nullptr) {
4222 }
4223
4224 // A new nondefing declaration is needed even if the function symbol already exists. The function symbol
4225 // should always contain the _first_ nondefining declaration (even though this may not be the first one).
4226 nondef_decl = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement>
4227 ( name, return_type, param_list, /*isMemberFunction*/false, scope, /*decoratorList*/nullptr,
4228 /*functionConstVolatileFlags*/0, nullptr, nullptr, SgStorageModifier::e_default );
4229
4230 ASSERT_not_null(isSgProcedureHeaderStatement(nondef_decl));
4231 ASSERT_not_null(nondef_decl->get_firstNondefiningDeclaration());
4232
4233 nondef_decl->set_subprogram_kind(kind);
4234
4235 return nondef_decl;
4236 }
4237
4239buildProcedureHeaderStatement(const SgName& name, SgType* return_type, SgFunctionParameterList* parameter_list,
4241 {
4242 ASSERT_not_null(return_type);
4243 ASSERT_not_null(parameter_list);
4244
4245 SgFunctionDeclaration* nondef_decl = nullptr;
4246
4247 if (scope == nullptr) {
4249 }
4250
4251 SgFunctionType* func_type = buildFunctionType(return_type,parameter_list);
4252 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgProcedureHeaderStatement>(name,func_type,nullptr,nullptr);
4253 if (func_symbol == nullptr)
4254 {
4255 nondef_decl = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement>
4256 ( name, return_type, parameter_list, /*isMemberFunction*/false, scope,
4257 /*decoratorList*/nullptr, /*functionConstVolatileFlags*/0, nullptr, nullptr, SgStorageModifier::e_default);
4258 }
4259 else
4260 {
4261 nondef_decl = func_symbol->get_declaration();
4262 }
4263
4264 SgProcedureHeaderStatement* proc_header_stmt = isSgProcedureHeaderStatement(nondef_decl);
4265 ASSERT_not_null(proc_header_stmt);
4266 ASSERT_require(nondef_decl->get_firstNondefiningDeclaration() == nondef_decl);
4267
4268 return buildProcedureHeaderStatement(name.str(), return_type, parameter_list, kind, scope, proc_header_stmt);
4269 }
4270
4271
4276 SgProcedureHeaderStatement* firstNondefDecl)
4277{
4278 ASSERT_not_null(firstNondefDecl);
4279 SgProcedureHeaderStatement* func{nullptr};
4280
4283 ASSERT_require(returnType == buildVoidType());
4284 }
4286 mlog[ERROR] << "unhandled subprogram kind for Fortran (or Jovial) function declaration:"
4287 << kind << endl;
4288 ROSE_ABORT();
4289 }
4290
4291 func = buildDefiningFunctionDeclaration_T<SgProcedureHeaderStatement>(SgName(name), returnType, params, /*isMemberFunction =*/false,
4292 scope, nullptr, 0U, firstNondefDecl, nullptr);
4293 ASSERT_not_null(func);
4294 func->set_subprogram_kind(kind);
4295
4296 return func;
4297}
4298
4299//------------------build value expressions -------------------
4300//-------------------------------------------------------------
4302{
4303 //TODO does valueString matter here?
4304 SgBoolValExp* boolValue= new SgBoolValExp(value);
4305 ROSE_ASSERT(boolValue);
4307 return boolValue;
4308}
4310{
4311 return buildBoolValExp(int(value));
4312}
4314{
4315 SgBoolValExp* boolValue= new SgBoolValExp(value);
4316 ROSE_ASSERT(boolValue);
4317 setOneSourcePositionNull(boolValue);
4318 return boolValue;
4319}
4320
4322 {
4323 SgNullptrValExp* nullptrValue = new SgNullptrValExp();
4324 ROSE_ASSERT(nullptrValue);
4326 return nullptrValue;
4327 }
4328
4330 {
4331 SgNullptrValExp* nullptrValue = new SgNullptrValExp();
4332 ROSE_ASSERT(nullptrValue);
4333 setOneSourcePositionNull(nullptrValue);
4334 return nullptrValue;
4335 }
4336
4338 {
4339 SgVoidVal* voidValue = new SgVoidVal();
4340 ROSE_ASSERT(voidValue);
4342 return voidValue;
4343 }
4344
4346 {
4347 SgVoidVal* voidValue = new SgVoidVal();
4348 ROSE_ASSERT(voidValue);
4349 setOneSourcePositionNull(voidValue);
4350 return voidValue;
4351 }
4352
4354{
4355 SgCharVal* result = new SgCharVal(value, "");
4356 ROSE_ASSERT(result);
4358 return result;
4359}
4360
4361SgCharVal* SageBuilder::buildCharVal_nfi(char value, const string& str)
4362{
4363 SgCharVal* result = new SgCharVal(value, str);
4364 ROSE_ASSERT(result);
4366 return result;
4367}
4368
4370{
4371 SgWcharVal* result = new SgWcharVal(value, "");
4372 ROSE_ASSERT(result);
4374 return result;
4375}
4376
4377SgWcharVal* SageBuilder::buildWcharVal_nfi(wchar_t value, const string& str)
4378{
4379 SgWcharVal* result = new SgWcharVal(value, str);
4380 ROSE_ASSERT(result);
4382 return result;
4383}
4384
4385// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
4386SgChar16Val* SageBuilder::buildChar16Val(unsigned short value /*= 0*/)
4387{
4388 SgChar16Val* result = new SgChar16Val(value, "");
4389 ROSE_ASSERT(result);
4391 return result;
4392}
4393
4394SgChar16Val* SageBuilder::buildChar16Val_nfi(unsigned short value, const string& str)
4395{
4396 SgChar16Val* result = new SgChar16Val(value, str);
4397 ROSE_ASSERT(result);
4399 return result;
4400}
4401
4402// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
4403SgChar32Val* SageBuilder::buildChar32Val(unsigned int value /*= 0*/)
4404{
4405 SgChar32Val* result = new SgChar32Val(value, "");
4406 ROSE_ASSERT(result);
4408 return result;
4409}
4410
4411SgChar32Val* SageBuilder::buildChar32Val_nfi(unsigned int value, const string& str)
4412{
4413 SgChar32Val* result = new SgChar32Val(value, str);
4414 ROSE_ASSERT(result);
4416 return result;
4417}
4418
4419
4421{
4422 SgComplexVal* result = new SgComplexVal(real_value,imaginary_value,imaginary_value->get_type(),"");
4423 ROSE_ASSERT(result);
4424
4425// DQ (12/31/2008): set and test the parents
4426 if (real_value != NULL)
4427 real_value->set_parent(result);
4428
4429 if (imaginary_value != NULL)
4430 imaginary_value->set_parent(result);
4431
4432 ROSE_ASSERT(real_value == NULL || real_value->get_parent() != NULL);
4433 ROSE_ASSERT(imaginary_value == NULL || imaginary_value->get_parent() != NULL);
4434
4436 return result;
4437}
4438
4439SgComplexVal* SageBuilder::buildComplexVal_nfi(SgValueExp* real_value, SgValueExp* imaginary_value, const std::string& str)
4440{
4441 ROSE_ASSERT(imaginary_value != NULL);
4442 SgComplexVal* result = new SgComplexVal(real_value,imaginary_value,imaginary_value->get_type(),str);
4443 ROSE_ASSERT(result != NULL);
4444
4445// DQ (12/31/2008): set and test the parents
4446 if (real_value != NULL)
4447 real_value->set_parent(result);
4448
4449 if (imaginary_value != NULL)
4450 imaginary_value->set_parent(result);
4451
4452 ROSE_ASSERT(real_value == NULL || real_value->get_parent() != NULL);
4453 ROSE_ASSERT(imaginary_value == NULL || imaginary_value->get_parent() != NULL);
4454
4456 return result;
4457}
4458
4459SgComplexVal* SageBuilder::buildImaginaryVal(long double imaginary_value /*= 0.0*/ )
4460{
4461 SgComplexVal* result = new SgComplexVal(NULL,buildLongDoubleVal(imaginary_value),SgTypeLongDouble::createType(),"");
4462 ROSE_ASSERT(result);
4463
4464// DQ (12/31/2008): set and test the parents
4465 result->get_imaginary_value()->set_parent(result);
4466 ROSE_ASSERT(result->get_imaginary_value()->get_parent() != NULL);
4467
4469 return result;
4470}
4471
4473{
4474 ROSE_ASSERT(imaginary_value != NULL);
4475
4476 SgComplexVal* result = new SgComplexVal(NULL,imaginary_value,imaginary_value->get_type(),"");
4477 ROSE_ASSERT(result);
4478
4479// DQ (12/31/2008): set and test the parents
4480 imaginary_value->set_parent(result);
4481 ROSE_ASSERT(imaginary_value->get_parent() != NULL);
4482
4484 return result;
4485}
4486
4487SgComplexVal* SageBuilder::buildImaginaryVal_nfi(SgValueExp* imaginary_value, const std::string& str)
4488{
4489 ROSE_ASSERT(imaginary_value != NULL);
4490
4491 SgComplexVal* result = new SgComplexVal(NULL,imaginary_value,imaginary_value->get_type(),str);
4492 imaginary_value->set_parent(result);
4493 ROSE_ASSERT(result);
4494
4495// DQ (12/31/2008): set and test the parents
4496 ROSE_ASSERT(imaginary_value->get_parent() != NULL);
4497
4499 return result;
4500}
4501
4503{
4504 SgDoubleVal* value = new SgDoubleVal(t,"");
4505 ROSE_ASSERT(value);
4507 return value;
4508}
4509
4511{
4512 SgDoubleVal* value = new SgDoubleVal(t,str);
4513 ROSE_ASSERT(value);
4515 return value;
4516}
4517
4519{
4520 SgFloatVal* result = new SgFloatVal(value,"");
4521 ROSE_ASSERT(result);
4523 return result;
4524}
4525
4527{
4528 SgFloatVal* result = new SgFloatVal(value,"");
4529 ROSE_ASSERT(result);
4531 return result;
4532}
4533
4534SgFloatVal* SageBuilder::buildFloatVal_nfi(float value, const string& str)
4535{
4536 SgFloatVal* result = new SgFloatVal(value,str);
4537 ROSE_ASSERT(result);
4539 return result;
4540}
4541
4543{
4544 // C++11 please [CR 2020.02.25]
4545 // return buildFloatVal_nfi(std::stof(str), str);
4546 return buildFloatVal_nfi(atof(str.c_str()), str);
4547}
4548
4550 {
4551 SgIntVal* intValue= new SgIntVal(value,"");
4552 ASSERT_not_null(intValue);
4554 return intValue;
4555 }
4556
4558 {
4559 SgIntVal* intValue= new SgIntVal(value, (value >= 0 ? StringUtility::intToHex((unsigned int)value) : "-" + StringUtility::intToHex((unsigned int)(-value))));
4560 ASSERT_not_null(intValue);
4562 return intValue;
4563 }
4564
4566 {
4567 SgIntVal* intValue = new SgIntVal(value,"");
4568 ASSERT_not_null(intValue);
4569 setOneSourcePositionNull(intValue);
4570 return intValue;
4571 }
4572
4573SgIntVal* SageBuilder::buildIntVal_nfi(int value, const string& str)
4574 {
4575 SgIntVal* intValue = new SgIntVal(value,str);
4576 ASSERT_not_null(intValue);
4577 setOneSourcePositionNull(intValue);
4578 return intValue;
4579 }
4580
4582 {
4583 return buildIntVal_nfi(std::stoi(str), str);
4584 }
4585
4587{
4588 SgLongIntVal* intValue= new SgLongIntVal(value,"");
4589 ASSERT_not_null(intValue);
4591 return intValue;
4592}
4593
4594SgLongIntVal* SageBuilder::buildLongIntVal_nfi(long value, const string& str)
4595{
4596 SgLongIntVal* intValue= new SgLongIntVal(value,str);
4597 ASSERT_not_null(intValue);
4598 setOneSourcePositionNull(intValue);
4599 return intValue;
4600}
4601
4603{
4604 SgLongLongIntVal* intValue= new SgLongLongIntVal(value,"");
4605 ASSERT_not_null(intValue);
4607 return intValue;
4608}
4609
4610SgLongLongIntVal* SageBuilder::buildLongLongIntVal_nfi(long long value, const string& str)
4611{
4612 SgLongLongIntVal* intValue= new SgLongLongIntVal(value,str);
4613 ASSERT_not_null(intValue);
4614 setOneSourcePositionNull(intValue);
4615 return intValue;
4616}
4617
4619 {
4620 SgEnumVal* enumVal= new SgEnumVal(value,decl,name);
4621 ASSERT_not_null(enumVal);
4623 return enumVal;
4624 }
4625
4626
4628 {
4629 SgEnumVal* enumVal= new SgEnumVal(value,decl,name);
4630 ASSERT_not_null(enumVal);
4631 setOneSourcePositionNull(enumVal);
4632 return enumVal;
4633 }
4634
4636 SgInitializedName * init_name = sym->get_declaration();
4637 ROSE_ASSERT(init_name != NULL);
4638 SgAssignInitializer * assign_init = isSgAssignInitializer(init_name->get_initptr());
4639 ROSE_ASSERT(assign_init != NULL);
4640 SgEnumVal * enum_val = isSgEnumVal(assign_init->get_operand_i());
4641 ROSE_ASSERT(enum_val != NULL);
4642 enum_val = isSgEnumVal(SageInterface::copyExpression(enum_val));
4643 return enum_val;
4644}
4645
4647{
4648 SgLongDoubleVal* result = new SgLongDoubleVal(value,"");
4649 ASSERT_not_null(result);
4651 return result;
4652}
4653
4654SgLongDoubleVal* SageBuilder::buildLongDoubleVal_nfi(long double value, const string& str)
4655{
4656 SgLongDoubleVal* result = new SgLongDoubleVal(value,str);
4657 ASSERT_not_null(result);
4659 return result;
4660}
4661
4662SgFloat80Val* SageBuilder::buildFloat80Val(long double value /*= 0.0*/)
4663{
4664 SgFloat80Val* result = new SgFloat80Val(value,"");
4665 ASSERT_not_null(result);
4667 return result;
4668}
4669
4670SgFloat80Val* SageBuilder::buildFloat80Val_nfi(long double value, const string& str)
4671{
4672 SgFloat80Val* result = new SgFloat80Val(value,str);
4673 ASSERT_not_null(result);
4675 return result;
4676}
4677
4679{
4680 SgFloat128Val* result = new SgFloat128Val(value,"");
4681 ASSERT_not_null(result);
4683 return result;
4684}
4685
4686SgFloat128Val* SageBuilder::buildFloat128Val_nfi(long double value, const string& str)
4687{
4688 SgFloat128Val* result = new SgFloat128Val(value,str);
4689 ASSERT_not_null(result);
4691 return result;
4692}
4693
4694SgStringVal* SageBuilder::buildStringVal(std::string value /*=""*/)
4695{
4696 SgStringVal* result = new SgStringVal(value);
4697 ASSERT_not_null(result);
4699 return result;
4700}
4701
4703{
4704 SgStringVal* result = new SgStringVal(value);
4705 ASSERT_not_null(result);
4707 return result;
4708}
4709
4711{
4712 SgUnsignedCharVal* result = new SgUnsignedCharVal(v,"");
4713 ASSERT_not_null(result);
4715 return result;
4716}
4717
4719{
4721 ASSERT_not_null(result);
4723 return result;
4724}
4725
4727{
4728 SgUnsignedCharVal* result = new SgUnsignedCharVal(v,str);
4729 ASSERT_not_null(result);
4731 return result;
4732}
4733
4735{
4736 SgSignedCharVal* result = new SgSignedCharVal(v,"");
4737 ASSERT_not_null(result);
4739 return result;
4740}
4741
4743{
4745 ASSERT_not_null(result);
4747 return result;
4748}
4749
4751{
4752 SgSignedCharVal* result = new SgSignedCharVal(v,str);
4753 ASSERT_not_null(result);
4755 return result;
4756}
4757
4759{
4760 SgShortVal* result = new SgShortVal(v,"");
4761 ASSERT_not_null(result);
4763 return result;
4764}
4765
4767{
4768 SgShortVal* result = new SgShortVal(v, (v >= 0 ? StringUtility::intToHex((unsigned int)v) : "-" + StringUtility::intToHex((unsigned int)(-v))));
4769 ASSERT_not_null(result);
4771 return result;
4772}
4773
4774SgShortVal* SageBuilder::buildShortVal_nfi(short v, const string& str)
4775{
4776 SgShortVal* result = new SgShortVal(v,str);
4777 ASSERT_not_null(result);
4779 return result;
4780}
4781
4783{
4784 SgUnsignedShortVal* result = new SgUnsignedShortVal(v,"");
4785 ASSERT_not_null(result);
4787 return result;
4788}
4789
4791{
4793 ASSERT_not_null(result);
4795 return result;
4796}
4797
4799{
4800 SgUnsignedShortVal* result = new SgUnsignedShortVal(v,str);
4801 ASSERT_not_null(result);
4803 return result;
4804}
4805
4807{
4808 SgUnsignedIntVal* result = new SgUnsignedIntVal(v,"");
4809 ASSERT_not_null(result);
4811 return result;
4812}
4813
4815{
4817 ASSERT_not_null(result);
4819 return result;
4820}
4821
4823{
4824 SgUnsignedIntVal* result = new SgUnsignedIntVal(v,str);
4825 ASSERT_not_null(result);
4827 return result;
4828}
4829
4831{
4832 SgUnsignedLongVal* result = new SgUnsignedLongVal(v,"");
4833 ASSERT_not_null(result);
4835 return result;
4836}
4837
4839{
4841 ASSERT_not_null(result);
4843 return result;
4844}
4845
4847{
4848 SgUnsignedLongVal* result = new SgUnsignedLongVal(v,str);
4849 ASSERT_not_null(result);
4851 return result;
4852}
4853
4855{
4857 ASSERT_not_null(result);
4859 return result;
4860}
4861
4863{
4865 ASSERT_not_null(result);
4867 return result;
4868}
4869
4871{
4873 ASSERT_not_null(result);
4875 return result;
4876}
4877
4878SgJovialBitVal* SageBuilder::buildJovialBitVal_nfi(const string& str)
4879{
4880 SgJovialBitVal* result = new SgJovialBitVal(str);
4881 ASSERT_not_null(result);
4883 return result;
4884}
4885
4887{
4888 SgTemplateType* result = new SgTemplateType (name);
4889 ASSERT_not_null (result);
4891 return result;
4892}
4893
4895{
4896 ROSE_ASSERT (t);
4897 SgTemplateParameter* result = new SgTemplateParameter(parameterType, t);
4898 ROSE_ASSERT (result);
4900 return result;
4901}
4902
4904{
4905 SgTemplateParameterVal* templateParameterValue = new SgTemplateParameterVal(template_parameter_position,"");
4906 ROSE_ASSERT(templateParameterValue);
4907 setOneSourcePositionForTransformation(templateParameterValue);
4908
4909// DQ (7/25/2012): Assert this (it will be set later).
4910 ROSE_ASSERT(templateParameterValue->get_parent() == NULL);
4911
4912 return templateParameterValue;
4913}
4914
4915SgTemplateParameterVal* SageBuilder::buildTemplateParameterVal_nfi(int template_parameter_position, const string& str)
4916{
4917 SgTemplateParameterVal* templateParameterValue= new SgTemplateParameterVal(template_parameter_position,str);
4918 ROSE_ASSERT(templateParameterValue);
4919 setOneSourcePositionNull(templateParameterValue);
4920
4921// DQ (7/25/2012): Assert this (it will be set later).
4922 ROSE_ASSERT(templateParameterValue->get_parent() == NULL);
4923
4924 return templateParameterValue;
4925}
4926
4927#define DEBUG_BUILD_NONREAL_DECL 0
4928
4930 ROSE_ASSERT(scope != NULL);
4931#if DEBUG_BUILD_NONREAL_DECL
4932 printf("ENTER SageBuilder::buildNonrealDecl\n");
4933 printf(" --- name = %s\n", name.str());
4934 printf(" --- scope = %p (%s)\n", scope, scope->class_name().c_str());
4935#endif
4936
4937 SgNonrealDecl * nrdecl = NULL;
4938
4939 nrdecl = new SgNonrealDecl(name);
4941 nrdecl->set_firstNondefiningDeclaration(nrdecl);
4942#if DEBUG_BUILD_NONREAL_DECL
4943 printf(" --- nrdecl = %p (%s)\n", nrdecl, nrdecl->class_name().c_str());
4944#endif
4945
4946 SgNonrealSymbol * symbol = new SgNonrealSymbol(nrdecl);
4947 scope->insert_symbol(name, symbol);
4948#if DEBUG_BUILD_NONREAL_DECL
4949 printf(" --- symbol = %p (%s)\n", symbol, symbol->class_name().c_str());
4950#endif
4951
4952 SgNonrealType * type = new SgNonrealType();
4953 type->set_declaration(nrdecl);
4954 type->set_parent(scope);
4955 nrdecl->set_type(type);
4956 // FIXME (???) insert `type` in `scope`
4957#if DEBUG_BUILD_NONREAL_DECL
4958 printf(" --- type = %p (%s)\n", type, type->class_name().c_str());
4959#endif
4960
4961 if (child_scope == NULL) {
4962 child_scope = new SgDeclarationScope();
4963#if DEBUG_BUILD_NONREAL_DECL
4964 printf(" --- child_scope = %p (new)\n", name.str(), child_scope);
4965#endif
4968 child_scope->get_endOfConstruct()->setCompilerGenerated();
4969 } else {
4970#if DEBUG_BUILD_NONREAL_DECL
4971 printf(" --- child_scope = %p (provided)\n", name.str(), child_scope);
4972#endif
4973
4974 }
4975 child_scope->set_parent(nrdecl);
4976 nrdecl->set_nonreal_decl_scope(child_scope);
4977
4978#if DEBUG_BUILD_NONREAL_DECL
4979 printf("LEAVE SageBuilder::buildNonrealDecl\n");
4980#endif
4981
4982 return nrdecl;
4983}
4984
4987{
4988 SgUpcThreads* result = new SgUpcThreads(0,"");
4989 ROSE_ASSERT(result);
4991 return result;
4992}
4993
4996{
4997 SgUpcThreads* result = new SgUpcThreads(0,"");
4998 ROSE_ASSERT(result);
5000 return result;
5001}
5002
5005{
5006 SgUpcMythread* result = new SgUpcMythread(0,"");
5007 ROSE_ASSERT(result);
5009 return result;
5010}
5011
5014{
5015 SgUpcMythread* result = new SgUpcMythread(0,"");
5016 ROSE_ASSERT(result);
5018 return result;
5019}
5020
5022{
5023 SgThisExp* result = new SgThisExp(isSgClassSymbol(sym), isSgNonrealSymbol(sym), 0);
5024 ROSE_ASSERT(result);
5026 return result;
5027}
5028
5030{
5031 SgThisExp* result = new SgThisExp(isSgClassSymbol(sym), isSgNonrealSymbol(sym), 0);
5032 ROSE_ASSERT(result);
5034 return result;
5035}
5036
5038{
5039 SgSuperExp* result = new SgSuperExp(sym, 0);
5040 ROSE_ASSERT(result);
5042 return result;
5043}
5044
5046{
5047 SgSuperExp* result = new SgSuperExp(sym, 0);
5048 ROSE_ASSERT(result);
5050 return result;
5051}
5052
5054{
5055 SgClassExp* result = new SgClassExp(sym, 0);
5056 ROSE_ASSERT(result);
5058 return result;
5059}
5060
5062{
5063 SgClassExp* result = new SgClassExp(sym, 0);
5064 ROSE_ASSERT(result);
5066 return result;
5067}
5068
5071{
5072 SgTupleExp* tuple = new SgTupleExp();
5073 ROSE_ASSERT(tuple);
5074 if (elt1) appendExpression(tuple, elt1);
5075 if (elt2) appendExpression(tuple, elt2);
5076 if (elt3) appendExpression(tuple, elt3);
5077 if (elt4) appendExpression(tuple, elt4);
5078 if (elt5) appendExpression(tuple, elt5);
5079 if (elt6) appendExpression(tuple, elt6);
5080 if (elt7) appendExpression(tuple, elt7);
5081 if (elt8) appendExpression(tuple, elt8);
5082 if (elt9) appendExpression(tuple, elt9);
5083 if (elt10) appendExpression(tuple, elt10);
5084
5086 return tuple;
5087}
5088
5090SageBuilder::buildTupleExp(const std::vector<SgExpression*>& elts)
5091{
5093 appendExpressionList(expList, elts);
5094 return expList;
5095}
5096
5099{
5100 SgTupleExp* tuple = new SgTupleExp();
5101 ROSE_ASSERT(tuple);
5103 return tuple;
5104}
5105
5107SageBuilder::buildTupleExp_nfi(const std::vector<SgExpression*>& elts)
5108{
5110 appendExpressionList(tuple, elts);
5111 return tuple;
5112}
5113
5114SgListExp*
5116{
5117 SgListExp* tuple = new SgListExp();
5118 ROSE_ASSERT(tuple);
5119 if (elt1) appendExpression(tuple, elt1);
5120 if (elt2) appendExpression(tuple, elt2);
5121 if (elt3) appendExpression(tuple, elt3);
5122 if (elt4) appendExpression(tuple, elt4);
5123 if (elt5) appendExpression(tuple, elt5);
5124 if (elt6) appendExpression(tuple, elt6);
5125 if (elt7) appendExpression(tuple, elt7);
5126 if (elt8) appendExpression(tuple, elt8);
5127 if (elt9) appendExpression(tuple, elt9);
5128 if (elt10) appendExpression(tuple, elt10);
5129
5131 return tuple;
5132}
5133
5134SgListExp*
5135SageBuilder::buildListExp(const std::vector<SgExpression*>& elts)
5136{
5138 appendExpressionList(expList, elts);
5139 return expList;
5140}
5141
5142SgListExp*
5144{
5145 SgListExp* tuple = new SgListExp();
5146 ROSE_ASSERT(tuple);
5148 return tuple;
5149}
5150
5151SgListExp*
5152SageBuilder::buildListExp_nfi(const std::vector<SgExpression*>& elts)
5153{
5155 appendExpressionList(tuple, elts);
5156 return tuple;
5157}
5158
5159
5160#define BUILD_UNARY_DEF(suffix) \
5161 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix##_nfi(SgExpression* op) \
5162 { \
5163 return SageBuilder::buildUnaryExpression_nfi<Sg##suffix>(op); \
5164 } \
5165 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix(SgExpression* op) \
5166 { \
5167 return SageBuilder::buildUnaryExpression<Sg##suffix>(op); \
5168 }
5169
5170BUILD_UNARY_DEF(AddressOfOp)
5171BUILD_UNARY_DEF(BitComplementOp)
5172BUILD_UNARY_DEF(MinusOp)
5173BUILD_UNARY_DEF(NotOp)
5174BUILD_UNARY_DEF(PointerDerefExp)
5175BUILD_UNARY_DEF(UnaryAddOp)
5176BUILD_UNARY_DEF(AbsOp)
5177BUILD_UNARY_DEF(MinusMinusOp)
5178BUILD_UNARY_DEF(PlusPlusOp)
5179BUILD_UNARY_DEF(RealPartOp)
5180BUILD_UNARY_DEF(ImagPartOp)
5181BUILD_UNARY_DEF(ConjugateOp)
5182BUILD_UNARY_DEF(VarArgStartOneOperandOp)
5183BUILD_UNARY_DEF(VarArgEndOp)
5184
5185BUILD_UNARY_DEF(MatrixTransposeOp) //SK(08/20/2015): Matlab matrix transpose operators
5186
5187#undef BUILD_UNARY_DEF
5188
5190 SgType * expression_type,
5191 SgCastExp::cast_type_enum cast_type)
5192{
5193 SgCastExp* result = new SgCastExp(operand_i, expression_type, cast_type);
5194 ROSE_ASSERT(result);
5195 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5197 return result;
5198}
5199
5200SgNewExp*
5202 SgExprListExp* placement_args,
5203 SgConstructorInitializer* constructor_args,
5204 SgExpression* builtin_args,
5205 // FIXME: Change this from "short int" to "bool".
5206 short int need_global_specifier,
5207 SgFunctionDeclaration* newOperatorDeclaration)
5208 {
5209 // DQ (11/18/2012): Modified parameter names to make this function more clear.
5210 SgNewExp* result = new SgNewExp(specified_type, placement_args, constructor_args, builtin_args, need_global_specifier, newOperatorDeclaration);
5211 ROSE_ASSERT(result);
5212
5214 return result;
5215 }
5216
5218 short is_array,
5219 short need_global_specifier,
5220 SgFunctionDeclaration* deleteOperatorDeclaration)
5221{
5222 SgDeleteExp* result = new SgDeleteExp(variable, is_array,
5223 need_global_specifier, deleteOperatorDeclaration);
5224 ROSE_ASSERT(result);
5226 return result;
5227}
5228
5231 {
5232 // DQ (1/25/2013): Added support for typeId operators.
5233 SgTypeIdOp* result = new SgTypeIdOp(operand_expr,operand_type);
5234 ROSE_ASSERT(result != NULL);
5236 return result;
5237 }
5238
5240{
5241 SgCastExp* result = new SgCastExp(operand_i, expression_type, cast_type);
5242 ROSE_ASSERT(result);
5243 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5245 return result;
5246}
5247
5249 SgVarArgOp* result = new SgVarArgOp(operand_i, expression_type);
5250 ROSE_ASSERT(result);
5251 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5253 return result;
5254}
5255
5257{
5258 SgMinusMinusOp* result = buildUnaryExpression<SgMinusMinusOp>(operand_i);
5259 ROSE_ASSERT(result);
5260 result->set_mode(a_mode);
5261 return result;
5262}
5263
5265{
5266 SgMinusMinusOp* result = buildUnaryExpression_nfi<SgMinusMinusOp>(operand_i);
5267 ROSE_ASSERT(result);
5268 result->set_mode(a_mode);
5269 return result;
5270}
5271
5273{
5274 SgMinusOp* result = buildUnaryExpression<SgMinusOp>(operand_i);
5275 ROSE_ASSERT(result);
5276 result->set_mode(a_mode);
5277 return result;
5278}
5279
5281{
5282 SgMinusOp* result = buildUnaryExpression_nfi<SgMinusOp>(operand_i);
5283 ROSE_ASSERT(result);
5284 result->set_mode(a_mode);
5285 return result;
5286}
5287
5289{
5290 SgPlusPlusOp* result = buildUnaryExpression<SgPlusPlusOp>(operand_i);
5291 ROSE_ASSERT(result);
5292 result->set_mode(a_mode);
5293 return result;
5294}
5295
5296
5298{
5299 SgPlusPlusOp* result = buildUnaryExpression_nfi<SgPlusPlusOp>(operand_i);
5300 ROSE_ASSERT(result);
5301 result->set_mode(a_mode);
5302 return result;
5303}
5304
5306 {
5307 // DQ (11/8/2011): operand_i is allowed to be NULL.
5308
5309 // SgThrowOp* result = new SgThrowOp(operand_i, operand_i -> get_type(), throwKind);
5310 SgThrowOp* result = new SgThrowOp(operand_i, (operand_i != NULL) ? operand_i->get_type() : NULL, throwKind);
5311
5312 if (operand_i)
5313 {
5314 markLhsValues(result);
5315 }
5316
5318
5319 if (operand_i)
5320 operand_i -> set_parent(result);
5321
5322 ROSE_ASSERT(result);
5323
5324 return result;
5325 }
5326
5327
5328
5329#define BUILD_BINARY_DEF(suffix) \
5330 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix##_nfi(SgExpression* lhs, SgExpression* rhs) \
5331 { \
5332 return buildBinaryExpression_nfi<Sg##suffix>(lhs, rhs); \
5333 } \
5334 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix(SgExpression* lhs, SgExpression* rhs) \
5335 { \
5336 return buildBinaryExpression<Sg##suffix>(lhs, rhs); \
5337 }
5338
5339BUILD_BINARY_DEF(AddOp)
5340BUILD_BINARY_DEF(AndAssignOp)
5341BUILD_BINARY_DEF(AndOp)
5342BUILD_BINARY_DEF(ArrowExp)
5343BUILD_BINARY_DEF(ArrowStarOp)
5344BUILD_BINARY_DEF(AssignOp)
5345BUILD_BINARY_DEF(AtOp)
5346BUILD_BINARY_DEF(BitAndOp)
5347BUILD_BINARY_DEF(BitOrOp)
5348BUILD_BINARY_DEF(BitXorOp)
5349
5350BUILD_BINARY_DEF(CommaOpExp)
5351BUILD_BINARY_DEF(ConcatenationOp)
5352BUILD_BINARY_DEF(DivAssignOp)
5353BUILD_BINARY_DEF(DivideOp)
5354BUILD_BINARY_DEF(DotExp)
5355BUILD_BINARY_DEF(DotStarOp)
5356BUILD_BINARY_DEF(EqualityOp)
5357
5358BUILD_BINARY_DEF(ExponentiationOp)
5359BUILD_BINARY_DEF(ExponentiationAssignOp)
5360BUILD_BINARY_DEF(GreaterOrEqualOp)
5361BUILD_BINARY_DEF(GreaterThanOp)
5362BUILD_BINARY_DEF(IntegerDivideOp)
5363BUILD_BINARY_DEF(IntegerDivideAssignOp)
5364BUILD_BINARY_DEF(IorAssignOp)
5365BUILD_BINARY_DEF(IsOp)
5366BUILD_BINARY_DEF(IsNotOp)
5367
5368BUILD_BINARY_DEF(LessOrEqualOp)
5369BUILD_BINARY_DEF(LessThanOp)
5370BUILD_BINARY_DEF(LshiftAssignOp)
5371BUILD_BINARY_DEF(LshiftOp)
5372
5373BUILD_BINARY_DEF(MembershipOp)
5374BUILD_BINARY_DEF(MinusAssignOp)
5375BUILD_BINARY_DEF(ModAssignOp)
5376BUILD_BINARY_DEF(ModOp)
5377BUILD_BINARY_DEF(MultAssignOp)
5378BUILD_BINARY_DEF(MultiplyOp)
5379
5380BUILD_BINARY_DEF(NotEqualOp)
5381BUILD_BINARY_DEF(NonMembershipOp)
5382BUILD_BINARY_DEF(OrOp)
5383BUILD_BINARY_DEF(PlusAssignOp)
5384BUILD_BINARY_DEF(PntrArrRefExp)
5385BUILD_BINARY_DEF(RemOp)
5386BUILD_BINARY_DEF(RshiftAssignOp)
5387BUILD_BINARY_DEF(JavaUnsignedRshiftAssignOp)
5388
5389BUILD_BINARY_DEF(RshiftOp)
5390BUILD_BINARY_DEF(JavaUnsignedRshiftOp)
5391BUILD_BINARY_DEF(ScopeOp)
5392BUILD_BINARY_DEF(SubtractOp)
5393BUILD_BINARY_DEF(XorAssignOp)
5394
5395BUILD_BINARY_DEF(VarArgCopyOp)
5396BUILD_BINARY_DEF(VarArgStartOp)
5397
5398// CR(07/26/2018): Jovial operators
5399BUILD_BINARY_DEF(ReplicationOp);
5400
5401//SK(08/20/2015): Matlab operators
5402BUILD_BINARY_DEF(PowerOp);
5403BUILD_BINARY_DEF(ElementwisePowerOp);
5404BUILD_BINARY_DEF(ElementwiseMultiplyOp);
5405BUILD_BINARY_DEF(ElementwiseDivideOp);
5406BUILD_BINARY_DEF(LeftDivideOp);
5407BUILD_BINARY_DEF(ElementwiseLeftDivideOp);
5408BUILD_BINARY_DEF(ElementwiseAddOp);
5409BUILD_BINARY_DEF(ElementwiseSubtractOp);
5410
5411// DQ (7/25/2020): Adding C++20 support
5412BUILD_BINARY_DEF(SpaceshipOp)
5413
5414#undef BUILD_BINARY_DEF
5415
5416
5417
5418// CR ( 1/25/2018):
5419// (10/30/2018): Fixed case when this function is called with NULL dim_info object.
5421 {
5422 ROSE_ASSERT(base_type != NULL);
5423
5424 // There must always be a dim_info object for this function. If not, the
5425 // overloaded function must be used to handle it.
5426 if (dim_info == NULL)
5427 {
5428 SgExpression* index = NULL;
5429 return buildArrayType(base_type, index);
5430 }
5431
5432 SgExpression* index = new SgNullExpression();
5433 ROSE_ASSERT(index);
5434 setSourcePosition(index);
5435
5436 SgArrayType* array_type = new SgArrayType(base_type, index);
5437 ROSE_ASSERT(array_type);
5438 ROSE_ASSERT(array_type->get_dim_info() == NULL);
5439
5440 index ->set_parent(array_type);
5441 dim_info->set_parent(array_type);
5442
5443 array_type->set_dim_info(dim_info);
5444 array_type->set_rank(dim_info->get_expressions().size());
5445
5446 return array_type;
5447 }
5448
5449SgArrayType* SageBuilder::buildArrayType(SgType* base_type/*=NULL*/, SgExpression* index/*=NULL*/)
5450{
5451 SgArrayType* result = new SgArrayType(base_type,index);
5452 ASSERT_not_null(result);
5453
5454 if (index != nullptr) {
5455 index->set_parent(result); // important!
5456 }
5457
5458 return result;
5459}
5460
5462{
5463 SgConditionalExp* result = new SgConditionalExp(test, a, b, NULL);
5464 if (test) test->set_parent(result);
5465 if (a) a->set_parent(result);
5466 if (b) b->set_parent(result);
5468 return result;
5469}
5470
5472{
5473 SgConditionalExp* result = new SgConditionalExp(test, a, b, t);
5474 if (test) test->set_parent(result);
5475 if (a) {a->set_parent(result); markLhsValues(a);}
5476 if (b) {b->set_parent(result); markLhsValues(b);}
5478 return result;
5479}
5480
5482{
5484 ROSE_ASSERT(result);
5486 return result;
5487}
5488
5491 ROSE_ASSERT(ne);
5493 return ne;
5494}
5495
5501
5503 SgColonShapeExp* expr = new SgColonShapeExp();
5504 ASSERT_not_null(expr);
5506 return expr;
5507}
5508
5514
5515SgAssignInitializer * SageBuilder::buildAssignInitializer(SgExpression * operand_i /*= NULL*/, SgType * expression_type /* = NULL */)
5516 {
5517 SgAssignInitializer* result = new SgAssignInitializer(operand_i, expression_type);
5518 ROSE_ASSERT(result);
5519 if (operand_i!=NULL)
5520 {
5521 operand_i->set_parent(result);
5522 // set lvalue, it asserts operand!=NULL
5523 markLhsValues(result);
5524 }
5526 return result;
5527 }
5528
5529SgAssignInitializer * SageBuilder::buildAssignInitializer_nfi(SgExpression * operand_i /*= nullptr*/, SgType * expression_type /*=nullptr*/)
5530 {
5531 SgAssignInitializer* result = new SgAssignInitializer(operand_i, expression_type);
5532 ASSERT_not_null(result);
5533 if (operand_i)
5534 {
5535 operand_i->set_parent(result);
5536 // set lvalue, it asserts operand!=NULL
5537 markLhsValues(result);
5538 }
5539
5540 setSourcePosition(result);
5541 result->set_need_paren(false);
5542
5543 return result;
5544 }
5545
5548{
5549 SgAggregateInitializer* result = new SgAggregateInitializer(initializers, type);
5550 ROSE_ASSERT(result);
5551 if (initializers!=NULL)
5552 {
5553 initializers->set_parent(result);
5554 }
5555 result->set_need_explicit_braces(true);
5557 return result;
5558}
5559
5562{
5563 SgAggregateInitializer* result = new SgAggregateInitializer(initializers, type);
5564 ROSE_ASSERT(result);
5565 if (initializers!=NULL)
5566 {
5567 initializers->set_parent(result);
5568 }
5569 result->set_need_explicit_braces(true);
5571 return result;
5572}
5573
5576{
5577 SgCompoundInitializer* result = new SgCompoundInitializer(initializers, type);
5578 ROSE_ASSERT(result);
5579 if (initializers!=NULL)
5580 {
5581 initializers->set_parent(result);
5582 }
5584 return result;
5585}
5586
5589{
5590 SgCompoundInitializer* result = new SgCompoundInitializer(initializers, type);
5591 ROSE_ASSERT(result);
5592 if (initializers!=NULL)
5593 {
5594 initializers->set_parent(result);
5595 }
5597 return result;
5598}
5599
5600// DQ (1/4/2009): Added support for SgConstructorInitializer
5603 SgMemberFunctionDeclaration *declaration/* = NULL*/,
5604 SgExprListExp *args/* = NULL*/,
5605 SgType *expression_type/* = NULL*/,
5606 bool need_name /*= false*/,
5607 bool need_qualifier /*= false*/,
5608 bool need_parenthesis_after_name /*= false*/,
5609 bool associated_class_unknown /*= false*/)
5610 {
5611 // Prototype:
5612 // SgConstructorInitializer (SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type,
5613 // bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown);
5614
5615 //George Vulov (05/24/2011) Modified this assertion to allow for a NULL declaration (in case of implicit constructors)
5616 ROSE_ASSERT(declaration == NULL || declaration->get_associatedClassDeclaration() != NULL);
5617
5618 SgConstructorInitializer* result = new SgConstructorInitializer( declaration, args, expression_type, need_name,
5619 need_qualifier, need_parenthesis_after_name, associated_class_unknown );
5620 ROSE_ASSERT(result != NULL);
5621 if (args != NULL)
5622 {
5623 args->set_parent(result);
5625 }
5626
5628
5629 return result;
5630 }
5631
5632// DQ (1/4/2009): Added support for SgConstructorInitializer
5635 SgMemberFunctionDeclaration *declaration/* = NULL*/,
5636 SgExprListExp *args/* = NULL*/,
5637 SgType *expression_type/* = NULL*/,
5638 bool need_name /*= false*/,
5639 bool need_qualifier /*= false*/,
5640 bool need_parenthesis_after_name /*= false*/,
5641 bool associated_class_unknown /*= false*/)
5642 {
5643 // Prototype:
5644 // SgConstructorInitializer (SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type, bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown);
5645
5646 // DQ (11/7/2011): Fix symetric to the way George did it above.
5647 ROSE_ASSERT(declaration == NULL || declaration->get_associatedClassDeclaration() != NULL);
5648
5649 SgConstructorInitializer* result = new SgConstructorInitializer( declaration, args, expression_type, need_name, need_qualifier, need_parenthesis_after_name, associated_class_unknown );
5650 ROSE_ASSERT(result != NULL);
5651
5653
5654 if (args != NULL)
5655 {
5656 args->set_parent(result);
5657 }
5658
5659 // DQ (11/4/2012): This is required and appears to work fine now.
5660 // DQ (11/23/2011): Fixup the expression list (but this does not appear to work...)
5661 if (result->get_args()->get_startOfConstruct() == NULL)
5662 {
5663 setOneSourcePositionNull(result->get_args());
5664 }
5665
5666 return result;
5667 }
5668
5669// DQ (11/15/2016):Adding support for braced initializer (required for template support).
5673 {
5674 SgBracedInitializer* result = new SgBracedInitializer(initializers, expression_type);
5675 ROSE_ASSERT(result);
5676 if (initializers!=NULL)
5677 {
5678 initializers->set_parent(result);
5679 }
5681 return result;
5682 }
5683
5685 {
5686 SgBracedInitializer* result = new SgBracedInitializer(initializers, expression_type);
5687 ROSE_ASSERT(result);
5688 if (initializers!=NULL)
5689 {
5690 initializers->set_parent(result);
5691 }
5693 return result;
5694 }
5695
5696
5699 {
5700 // SgType* exp_type = NULL;
5701 // if (exp) exp_type = exp->get_type();
5702
5703 SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, NULL);
5704 // SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, exp_type);
5705 ROSE_ASSERT(result);
5706 if (exp)
5707 {
5708 exp->set_parent(result);
5709 markLhsValues(result);
5710 }
5712 return result;
5713 }
5714
5717 {
5718 // SgType* exp_type =NULL;
5719 // if (exp) exp_type = exp->get_type();
5720
5721 SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, NULL);
5722 // SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, exp_type);
5723 ROSE_ASSERT(result);
5724 if (exp)
5725 {
5726 exp->set_parent(result);
5727 markLhsValues(result);
5728 }
5730 return result;
5731 }
5732
5735 {
5736 SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,NULL);
5737 // SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,type);
5738 ROSE_ASSERT(result);
5740 return result;
5741 }
5742
5745 {
5746 SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,NULL);
5747 // SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,type);
5748 ROSE_ASSERT(result);
5750 return result;
5751 }
5752
5755 {
5756 // SgType* exp_type =NULL;
5757 // if (exp) exp_type = exp->get_type();
5758
5759 SgAlignOfOp* result = new SgAlignOfOp(exp,NULL, NULL);
5760 ROSE_ASSERT(result);
5761 if (exp)
5762 {
5763 exp->set_parent(result);
5764 markLhsValues(result);
5765 }
5767 return result;
5768 }
5769
5772 {
5773 // SgType* exp_type =NULL;
5774 // if (exp) exp_type = exp->get_type();
5775
5776 SgAlignOfOp* result = new SgAlignOfOp(exp,NULL, NULL);
5777 ROSE_ASSERT(result);
5778 if (exp)
5779 {
5780 exp->set_parent(result);
5781 markLhsValues(result);
5782 }
5784 return result;
5785 }
5786
5789 {
5790 // SgType* exp_type =NULL;
5791 // if (exp) exp_type = exp->get_type();
5792
5793 SgNoexceptOp* result = new SgNoexceptOp(exp);
5794 ROSE_ASSERT(result);
5795 if (exp)
5796 {
5797 exp->set_parent(result);
5798 markLhsValues(result);
5799 }
5800
5802 return result;
5803 }
5804
5807 {
5808 // SgType* exp_type =NULL;
5809 // if (exp) exp_type = exp->get_type();
5810
5811 SgNoexceptOp* result = new SgNoexceptOp(exp);
5812 ROSE_ASSERT(result);
5813 if (exp)
5814 {
5815 exp->set_parent(result);
5816 markLhsValues(result);
5817 }
5818
5820 return result;
5821 }
5822
5825 {
5826 SgAlignOfOp* result = new SgAlignOfOp((SgExpression*)NULL,type,NULL);
5827 ROSE_ASSERT(result);
5829 return result;
5830 }
5831
5834 {
5835 SgAlignOfOp* result = new SgAlignOfOp((SgExpression*)NULL,type,NULL);
5836 ROSE_ASSERT(result);
5838 return result;
5839 }
5840
5841
5843{
5844 SgExprListExp* expList = new SgExprListExp();
5845 ROSE_ASSERT(expList);
5846
5847// printf ("In SageBuilder::buildExprListExp(SgExpression * expr1, SgExpression* expr2, ...): SgExprListExp* expList = %p \n",expList);
5848
5850 if (expr1) appendExpression(expList, expr1);
5851 if (expr2) appendExpression(expList, expr2);
5852 if (expr3) appendExpression(expList, expr3);
5853 if (expr4) appendExpression(expList, expr4);
5854 if (expr5) appendExpression(expList, expr5);
5855 if (expr6) appendExpression(expList, expr6);
5856 if (expr7) appendExpression(expList, expr7);
5857 if (expr8) appendExpression(expList, expr8);
5858 if (expr9) appendExpression(expList, expr9);
5859 if (expr10) appendExpression(expList, expr10);
5860 return expList;
5861}
5862
5863// CH (5/11/2010): Seems that this function is useful.
5864SgExprListExp * SageBuilder::buildExprListExp(const std::vector<SgExpression*>& exprs)
5865{
5866 SgExprListExp* expList = new SgExprListExp();
5867 ROSE_ASSERT(expList);
5868
5870 for (size_t i = 0; i < exprs.size(); ++i) {
5871 appendExpression(expList, exprs[i]);
5872 }
5873 return expList;
5874}
5875
5877 {
5878 SgExprListExp* expList = new SgExprListExp();
5879 ROSE_ASSERT(expList);
5880
5881 setOneSourcePositionNull(expList);
5882 return expList;
5883 }
5884
5885SgExprListExp * SageBuilder::buildExprListExp_nfi(const std::vector<SgExpression*>& exprs)
5886 {
5887 SgExprListExp* expList = new SgExprListExp();
5888 ROSE_ASSERT(expList != NULL);
5889
5890 setOneSourcePositionNull(expList);
5891 for (size_t i = 0; i < exprs.size(); ++i)
5892 {
5893 appendExpression(expList, exprs[i]);
5894 }
5895
5896 // DQ (4/3/2012): Added test to make sure that the pointers are unique.
5897 testAstForUniqueNodes(expList);
5898
5899 return expList;
5900 }
5901
5904 {
5905 if (lower_bound == NULL)
5906 {
5908 }
5909 if (stride == NULL)
5910 {
5912 }
5913
5914 ROSE_ASSERT(lower_bound);
5915 ROSE_ASSERT(upper_bound);
5916 ROSE_ASSERT(stride);
5917
5918 SgSubscriptExpression* subscript = new SgSubscriptExpression(lower_bound, upper_bound, stride);
5919 ROSE_ASSERT(subscript);
5921
5922 // Set the parents of all the parts of the SgSubscriptExpression
5923 lower_bound->set_parent(subscript);
5924 upper_bound->set_parent(subscript);
5925 stride ->set_parent(subscript);
5926
5927 return subscript;
5928 }
5929
5932 {
5933 ROSE_ASSERT(initname);
5934 if (scope == NULL)
5936
5937 SgVarRefExp *varRef = NULL;
5938 // there is assertion for get_scope() != NULL in get_symbol_from_symbol_table()
5939 SgSymbol* symbol = NULL;
5940 if (initname->get_scope()!=NULL)
5941 symbol = initname->get_symbol_from_symbol_table ();
5942
5943 if (symbol != NULL)
5944 {
5945 varRef = new SgVarRefExp(isSgVariableSymbol(symbol));
5947 ROSE_ASSERT(varRef);
5948 }
5949 else
5950 {
5951 varRef = buildVarRefExp(initname->get_name(), scope);
5952 }
5953
5954 return varRef;
5955 }
5956
5959{
5960 SgName name(varName);
5961 return buildVarRefExp(name,scope);
5962}
5963
5965SageBuilder::buildVarRefExp(const std::string& varName, SgScopeStatement* scope)
5966{
5967 SgName name(varName);
5968 return buildVarRefExp(name,scope);
5969}
5970
5973 {
5974 if (scope == NULL)
5976
5977 SgSymbol* symbol = NULL;
5978 SgVariableSymbol* varSymbol = NULL;
5979
5980 if (scope != NULL)
5981 {
5982 // DQ (12/30/2011): This is a bad idea for C++ since qualified names might indicate different scopes.
5983 // If the scope has been provided then is should be the correct scope.
5984
5985 // DQ (8/16/2013): Modified to use the new API supporting template parameters and template arguments, however
5986 // this should more likely be using lookupVariableSymbolInParentScopes() instead of lookupSymbolInParentScopes().
5987 symbol = lookupVariableSymbolInParentScopes(name,scope);
5988 }
5989
5990 if (symbol != NULL)
5991 {
5992 varSymbol = isSgVariableSymbol(symbol);
5993 }
5994 else
5995 {
5996 // if not found: put fake init name and symbol here and
5997 // waiting for a postProcessing phase to clean it up
5998 // two features: no scope and unknown type for initializedName
6000 name1->set_scope(scope); // buildInitializedName() does not set scope for various reasons
6001 name1->set_parent(scope);
6002 varSymbol = new SgVariableSymbol(name1);
6003 varSymbol->set_parent(scope);
6004 }
6005
6006 if (varSymbol == NULL)
6007 {
6008 printf ("Error: varSymbol == NULL for name = %s \n",name.str());
6009 }
6010 ROSE_ASSERT(varSymbol != NULL);
6011
6012 SgVarRefExp *varRef = new SgVarRefExp(varSymbol);
6014 ROSE_ASSERT(varRef != NULL);
6015
6016 ROSE_ASSERT (isSgVariableSymbol(varRef->get_symbol())->get_declaration()!=NULL);
6017
6018 return varRef;
6019 }
6020
6024 {
6025 SgVariableSymbol* symbol = getFirstVarSym(vardecl);
6026 ROSE_ASSERT(symbol);
6027
6028 return buildVarRefExp(symbol);
6029 }
6030
6031
6034 {
6035 SgVarRefExp *varRef = new SgVarRefExp(sym);
6036 ROSE_ASSERT(varRef);
6037
6039
6040 return varRef;
6041 }
6042
6045 {
6046 SgVarRefExp *varRef = new SgVarRefExp(sym);
6047 ROSE_ASSERT(varRef);
6048
6050
6051 return varRef;
6052 }
6053
6056 {
6057 SgNonrealRefExp * refexp = new SgNonrealRefExp(sym);
6058 ROSE_ASSERT(refexp != NULL);
6060 return refexp;
6061 }
6062
6064
6067SageBuilder::buildOpaqueVarRefExp(const std::string& name,SgScopeStatement* scope/* =NULL */)
6068 {
6069 SgVarRefExp *result = NULL;
6070
6071 if (scope == NULL)
6073 ROSE_ASSERT(scope != NULL);
6074
6075 // DQ (8/16/2013): Modified to use the new API supporting template parameters and template arguments, however
6076 // this should more likely be using lookupVariableSymbolInParentScopes() instead of lookupSymbolInParentScopes().
6077 // SgSymbol * symbol = lookupSymbolInParentScopes(name,scope);
6078 SgSymbol * symbol = lookupVariableSymbolInParentScopes(name,scope);
6079
6080 if (symbol)
6081 {
6082 // Can be the same opaque var ref built before
6083 // cerr<<"Error: trying to build an opaque var ref when the variable is actual explicit!"<<endl;
6084 ROSE_ASSERT(isSgVariableSymbol(symbol));
6085 result = buildVarRefExp(isSgVariableSymbol(symbol));
6086 }
6087 else
6088 {
6089 SgVariableDeclaration* fakeVar = buildVariableDeclaration(name, buildIntType(),NULL, scope);
6090 Sg_File_Info* file_info = fakeVar->get_file_info();
6091
6092 // TGWE (7/16/2014): on the advice of DQ who doesn't like the function at all
6093 fakeVar->set_parent(scope);
6094
6095 file_info->unsetOutputInCodeGeneration ();
6096 SgVariableSymbol* fakeSymbol = getFirstVarSym (fakeVar);
6097 result = buildVarRefExp(fakeSymbol);
6098 }
6099
6100 return result;
6101 } // buildOpaqueVarRefExp()
6102
6103
6104// DQ (9/4/2013): Added support for building compound literals (similar to a SgVarRefExp).
6108 {
6109 SgCompoundLiteralExp *compoundLiteral = new SgCompoundLiteralExp(varSymbol);
6110 ROSE_ASSERT(compoundLiteral != NULL);
6111
6112 setOneSourcePositionNull(compoundLiteral);
6113
6114 return compoundLiteral;
6115 }
6116
6117// DQ (9/4/2013): Added support for building compound literals (similar to a SgVarRefExp).
6121 {
6122 SgCompoundLiteralExp *compoundLiteral = new SgCompoundLiteralExp(varSymbol);
6123 ROSE_ASSERT(compoundLiteral != NULL);
6124
6126
6127 return compoundLiteral;
6128 }
6129
6130
6133{
6134 SgLabelRefExp * result= NULL;
6135 ROSE_ASSERT (s!= NULL);
6136 result = new SgLabelRefExp(s);
6137 ROSE_ASSERT (result != NULL);
6139 return result;
6140}
6141
6144{
6146 if (paraTypeList==NULL) return paraList;
6147
6148 SgTypePtrList typeList = paraTypeList->get_arguments();
6149 SgTypePtrList::iterator i;
6150 for (i=typeList.begin();i!=typeList.end();i++)
6151 {
6153 appendArg(paraList,arg);
6154 }
6155
6156 return paraList;
6157}
6158
6161{
6163 ROSE_ASSERT (paraList);
6164 SgTypePtrList typeList = paraTypeList->get_arguments();
6165 SgTypePtrList::iterator i;
6166 for (i=typeList.begin();i!=typeList.end();i++)
6167 {
6169 appendArg(paraList,arg);
6170 }
6171 return paraList;
6172}
6173
6174// lookup function symbol to create a reference to it
6176SageBuilder::buildFunctionRefExp(const SgName& name,const SgType* funcType, SgScopeStatement* scope /*=NULL*/)
6177{
6178 ASSERT_not_null(funcType); // function type cannot be NULL
6179 SgFunctionType* func_type = isSgFunctionType(const_cast<SgType*>(funcType));
6180 ASSERT_not_null(func_type);
6181
6182 bool isMemberFunc = isSgMemberFunctionType(func_type);
6183
6184 if (scope == nullptr) {
6186 }
6187 ASSERT_not_null(scope);
6188 SgFunctionSymbol* symbol = lookupFunctionSymbolInParentScopes(name,func_type,scope);
6189 if (symbol == nullptr)
6190 // in rare cases when function calls are inserted before any prototypes exist
6191 {
6192 SgType* return_type = func_type->get_return_type();
6193 SgFunctionParameterTypeList * paraTypeList = func_type->get_argument_list();
6194 SgFunctionParameterList *parList = buildFunctionParameterList(paraTypeList);
6195
6196 SgGlobal* globalscope = getGlobalScope(scope);
6197
6198 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
6199
6200 // TODO: consider C++ template functions
6201 SgFunctionDeclaration * funcDecl = nullptr;
6203 {
6204 funcDecl = buildNondefiningFunctionDeclaration_T
6205 <SgProcedureHeaderStatement>(name,return_type,parList,false,globalscope,nullptr,false,nullptr,nullptr,SgStorageModifier::e_default);
6206 }
6207 else
6208 {
6209 funcDecl = buildNondefiningFunctionDeclaration_T
6210 <SgFunctionDeclaration>(name,return_type,parList,false,globalscope,nullptr,false,nullptr,nullptr,SgStorageModifier::e_default);
6211 }
6212
6213 funcDecl->get_declarationModifier().get_storageModifier().setExtern();
6214
6215 symbol = lookupFunctionSymbolInParentScopes(name,func_type,scope);
6216 ASSERT_not_null(symbol);
6217 }
6218 SgFunctionRefExp* func_ref = new SgFunctionRefExp(symbol,func_type);
6220
6221 ASSERT_not_null(func_ref);
6222 return func_ref;
6223}
6224
6226SageBuilder::buildFunctionRefExp(const char* name,const SgType* funcType, SgScopeStatement* scope /*=NULL*/)
6227{
6228 SgName name2(name);
6229 return buildFunctionRefExp(name2,funcType,scope);
6230}
6231
6232// lookup function symbol to create a reference to it
6235{
6236 ROSE_ASSERT(func_decl != NULL);
6237 SgDeclarationStatement* nondef_func = func_decl->get_firstNondefiningDeclaration ();
6238 SgDeclarationStatement* def_func = func_decl->get_definingDeclaration ();
6239 SgSymbol* symbol = NULL;
6240 if (nondef_func != NULL)
6241 {
6242 ROSE_ASSERT(nondef_func!= NULL);
6243 symbol = nondef_func->get_symbol_from_symbol_table();
6244 ROSE_ASSERT( symbol != NULL);
6245 }
6246 // Liao 12/1/2010. It is possible that there is no prototype declarations at all
6247 else if (def_func != NULL)
6248 {
6249 symbol = def_func->get_symbol_from_symbol_table();
6250 }
6251 else
6252 {
6253 std::cerr<<"Fatal error: SageBuilder::buildFunctionRefExp():defining and nondefining declarations for a function cannot be both NULL"<<std::endl;
6254 ROSE_ABORT ();
6255 }
6256 ROSE_ASSERT( symbol != NULL);
6257 return buildFunctionRefExp( isSgFunctionSymbol (symbol));
6258}
6259
6260
6261// lookup function symbol to create a reference to it
6264{
6265 SgFunctionRefExp* func_ref = new SgFunctionRefExp(sym, NULL);
6267 ROSE_ASSERT(func_ref);
6268 return func_ref;
6269}
6270
6271// lookup function symbol to create a reference to it
6274{
6275 SgFunctionRefExp* func_ref = new SgFunctionRefExp(sym, NULL);
6276 setOneSourcePositionNull(func_ref);
6277 ROSE_ASSERT(func_ref);
6278 return func_ref;
6279}
6280
6281// DQ (12/15/2011): Adding template declaration support to the AST.
6284 {
6285 // DQ (2/23/2013): Added assertion.
6286 ROSE_ASSERT(sym != NULL);
6287
6289 ROSE_ASSERT(func_ref != NULL);
6290
6291 setOneSourcePositionNull(func_ref);
6292
6293 // DQ (2/23/2013): Added assertion.
6294 ROSE_ASSERT(func_ref->get_symbol() != NULL);
6295
6296 return func_ref;
6297 }
6298
6299// DQ (12/29/2011): Adding template declaration support to the AST.
6302 {
6303 SgTemplateMemberFunctionRefExp* func_ref = new SgTemplateMemberFunctionRefExp(sym, virtual_call, need_qualifier);
6304 setOneSourcePositionNull(func_ref);
6305 ROSE_ASSERT(func_ref);
6306 return func_ref;
6307 }
6308
6309// lookup member function symbol to create a reference to it
6311SageBuilder::buildMemberFunctionRefExp_nfi(SgMemberFunctionSymbol* sym, bool virtual_call, bool need_qualifier)
6312{
6313 SgMemberFunctionRefExp* func_ref = new SgMemberFunctionRefExp(sym, virtual_call, NULL, need_qualifier);
6314 setOneSourcePositionNull(func_ref);
6315 ROSE_ASSERT(func_ref);
6316 return func_ref;
6317}
6318
6319// lookup member function symbol to create a reference to it
6321SageBuilder::buildMemberFunctionRefExp(SgMemberFunctionSymbol* sym, bool virtual_call, bool need_qualifier)
6322{
6323 SgMemberFunctionRefExp* func_ref = new SgMemberFunctionRefExp(sym, virtual_call, NULL, need_qualifier);
6325 ROSE_ASSERT(func_ref);
6326 return func_ref;
6327}
6328
6329// lookup class symbol to create a reference to it
6332{
6333 SgClassNameRefExp* class_ref = new SgClassNameRefExp(sym);
6334 setOneSourcePositionNull(class_ref);
6335 ROSE_ASSERT(class_ref);
6336 return class_ref;
6337}
6338
6341{
6342 SgClassNameRefExp* class_ref = new SgClassNameRefExp(sym);
6344 ROSE_ASSERT(class_ref);
6345 return class_ref;
6346}
6347
6351{
6352 if (scope == NULL)
6354 ROSE_ASSERT(scope != NULL);
6356
6357 if (symbol==NULL)
6358// in rare cases when function calls are inserted before any prototypes exist
6359 {
6360// assume int return type, and empty parameter list
6361
6362#if 1
6363// DQ (7/26/2012): I am at least temporarily removing this function from the API.
6364// Later if we need it, we can update it to reflect that passing of the new
6365// SgTemplateArgumentPtrList function parameter (part of the new API design).
6366
6367 SgFunctionDeclaration* funcDecl = NULL;
6368 printf ("Error: buildFunctionRefExp(): This function should not be used! \n");
6369 ROSE_ABORT();
6370#else
6371 SgType* return_type = buildIntType();
6373
6374 SgGlobal* globalscope = getGlobalScope(scope);
6375
6376 SgFunctionDeclaration * funcDecl = buildNondefiningFunctionDeclaration(name,return_type,parList,globalscope);
6377#endif
6378
6379 funcDecl->get_declarationModifier().get_storageModifier().setExtern();
6380
6381 symbol = lookupFunctionSymbolInParentScopes(name,scope);
6382 ROSE_ASSERT(symbol);
6383 }
6384
6385 SgFunctionRefExp* func_ref = buildFunctionRefExp(symbol);
6387
6388 ROSE_ASSERT(func_ref);
6389 return func_ref;
6390}
6391
6393SageBuilder::buildFunctionRefExp(const char* name, SgScopeStatement* scope /*=NULL*/)
6394{
6395 SgName name2(name);
6396 return buildFunctionRefExp(name2,scope);
6397}
6398
6399
6402{
6403 SgExprStatement* expStmt = new SgExprStatement(exp);
6404 ROSE_ASSERT(expStmt);
6405 if (exp) exp->set_parent(expStmt);
6407 return expStmt;
6408}
6409
6412{
6413 SgExprStatement* expStmt = new SgExprStatement(exp);
6414 ROSE_ASSERT(expStmt);
6415 if (exp) exp->set_parent(expStmt);
6416 setOneSourcePositionNull(expStmt);
6417 return expStmt;
6418}
6419
6420// DQ (3/27/2015): Added support for SgStatementExpression.
6423{
6424 SgStatementExpression* expStmt = new SgStatementExpression(exp);
6425 ROSE_ASSERT(expStmt);
6426 if (exp) exp->set_parent(expStmt);
6428
6429 return expStmt;
6430}
6431
6432// DQ (3/27/2015): Added support for SgStatementExpression.
6435{
6436 SgStatementExpression* expStmt = new SgStatementExpression(exp);
6437 ROSE_ASSERT(expStmt);
6438 if (exp) exp->set_parent(expStmt);
6439 setOneSourcePositionNull(expStmt);
6440
6441 return expStmt;
6442}
6443
6445SageBuilder::buildFunctionCallExp(const SgName& name, SgType* return_type, SgExprListExp* parameters/*=NULL*/, SgScopeStatement* scope/*=NULL*/)
6446 {
6447 if (scope == nullptr) {
6449 }
6450 ASSERT_not_null(scope);
6451
6452 if (parameters == nullptr) {
6453 parameters = buildExprListExp();
6454 }
6455
6457 SgFunctionType * func_type = buildFunctionType(return_type,typeList);
6458 SgFunctionRefExp* func_ref = buildFunctionRefExp(name,func_type,scope);
6459 SgFunctionCallExp * func_call_expr = new SgFunctionCallExp(func_ref,parameters,func_ref->get_type());
6460 parameters->set_parent(func_call_expr);
6461
6463 ASSERT_not_null(func_call_expr);
6464
6465 return func_call_expr;
6466 }
6467
6468
6471 SgExprListExp* parameters/*=NULL*/)
6472 {
6473 ROSE_ASSERT (sym != NULL);
6474 if (parameters == NULL)
6475 parameters = buildExprListExp();
6476 ROSE_ASSERT (parameters != NULL);
6477
6478 // DQ (8/21/2011): We want to preserve the support for member functions to be built as SgMemberFunctionRefExp.
6479 // This is important for the Java support and the C++ support else we will be lowering all mmember function calls
6480 // to function calls which will be a proble for eht analysis of object oriented languages.
6481 SgFunctionCallExp * func_call_expr = NULL;
6482 SgMemberFunctionSymbol* memberFunctionSymbol = isSgMemberFunctionSymbol(sym);
6483 if (memberFunctionSymbol != NULL)
6484 {
6485 // Note that we can't at this point be sure this is not a virtual function.
6486 bool virtual_call = false;
6487
6488 // Name qualificaiton is handled separately from the setting of this variable (old API).
6489 bool need_qualifier = false;
6490
6491 SgMemberFunctionRefExp* member_func_ref = buildMemberFunctionRefExp(memberFunctionSymbol,virtual_call,need_qualifier);
6492 func_call_expr = new SgFunctionCallExp(member_func_ref,parameters,member_func_ref->get_type());
6493 member_func_ref->set_parent(func_call_expr);
6494 }
6495 else
6496 {
6497 SgFunctionRefExp * func_ref = buildFunctionRefExp(sym);
6498 func_call_expr = new SgFunctionCallExp(func_ref,parameters,func_ref->get_type());
6499 func_ref->set_parent(func_call_expr);
6500 }
6501
6502
6503 parameters->set_parent(func_call_expr);
6504
6506
6507 ROSE_ASSERT(func_call_expr);
6508 return func_call_expr;
6509 }
6510
6513 {
6514 ROSE_ASSERT(f != NULL);
6515 SgFunctionCallExp* func_call_expr = new SgFunctionCallExp(f,parameters,f->get_type());
6516 ROSE_ASSERT(func_call_expr != NULL);
6517
6518 if (f != NULL) {
6519 f->set_parent(func_call_expr);
6520 }
6521 if (parameters != NULL) {
6522 parameters->set_parent(func_call_expr);
6523 }
6524 setOneSourcePositionNull(func_call_expr);
6525
6526 return func_call_expr;
6527 }
6528
6531 {
6532 ROSE_ASSERT(f != NULL);
6533 SgFunctionCallExp * func_call_expr = new SgFunctionCallExp(f,parameters,f->get_type());
6534 ROSE_ASSERT(func_call_expr != NULL);
6535
6536 if (f) f->set_parent(func_call_expr);
6537 if (parameters) parameters->set_parent(func_call_expr);
6539
6540 return func_call_expr;
6541 }
6542
6545 SgType* return_type,
6546 SgExprListExp* parameters /*= NULL*/,
6547 SgScopeStatement* scope /*=NULL*/)
6548{
6549 if (scope == NULL)
6551 ROSE_ASSERT(scope != NULL);
6552 SgFunctionCallExp* func_call_expr = buildFunctionCallExp(name,return_type,parameters,scope);
6553 SgExprStatement * expStmt = buildExprStatement(func_call_expr);
6554 return expStmt;
6555}
6556
6560{
6561 SgFunctionCallExp* func_call_expr = buildFunctionCallExp(function_exp, parameters);
6562 SgExprStatement * expStmt = buildExprStatement(func_call_expr);
6563 return expStmt;
6564}
6565
6566
6568
6576 SgExpression* objectExpression,
6577 std::string functionName,
6578 SgExprListExp* params,
6579 SgScopeStatement* scope
6580 )
6581{
6582 SgClassSymbol* classSymbol = SageInterface::lookupClassSymbolInParentScopes(className, scope);
6583 ROSE_ASSERT(classSymbol);
6584
6585 SgDeclarationStatement* classDecl = classSymbol->get_declaration()->get_definingDeclaration();
6586 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classDecl);
6587 ROSE_ASSERT(classDeclaration != NULL);
6588
6589 SgClassDefinition* classDefinition = classDeclaration->get_definition();
6590 ROSE_ASSERT(classDefinition);
6591
6592 SgSymbol* funsy = lookupFunctionSymbolInParentScopes(functionName, classDefinition);
6593 SgMemberFunctionSymbol* functionSymbol = isSgMemberFunctionSymbol(funsy);
6594 ROSE_ASSERT(functionSymbol);
6595
6596 SgMemberFunctionRefExp* memref = buildMemberFunctionRefExp(functionSymbol, false, false);
6597
6598 return buildFunctionCallExp(buildDotExp(objectExpression, memref), params);
6599}
6600
6601// with known varRef and mem function symbol : a.size()
6603 SgExprListExp* params)
6604{
6605 SgMemberFunctionRefExp* memref = SageBuilder::buildMemberFunctionRefExp(functionSymbol, false, false);
6606 return SageBuilder::buildFunctionCallExp(SageBuilder::buildDotExp(objectExpression, memref), params);
6607}
6608
6610SageBuilder::buildTypeTraitBuiltinOperator(SgName functionName, SgNodePtrList parameters)
6611 {
6612 // DQ (7/14/2013): This is supporting compiler extensions that are required to support type traits in C++.
6613 // These operators are used increasingly in newer versions of GNU and other compilers. They are builtin
6614 // compiler extensions that typically take types as arguments.
6615
6616 SgTypeTraitBuiltinOperator * builtin_func_call_expr = new SgTypeTraitBuiltinOperator(functionName);
6617 ROSE_ASSERT(builtin_func_call_expr != NULL);
6618
6619 SgNodePtrList & args = builtin_func_call_expr->get_args();
6620 for (SgNodePtrList::iterator it = parameters.begin(); it != parameters.end(); ++it) {
6621 args.push_back(*it);
6622 (*it)->set_parent(builtin_func_call_expr);
6623 }
6624
6625 return builtin_func_call_expr;
6626 }
6627
6628
6631 {
6632 ROSE_ASSERT(kernel);
6633 ROSE_ASSERT(parameters);
6634 ROSE_ASSERT(config);
6635
6636 // DQ (1/19/2016): Adding template function ref support.
6637 SgFunctionRefExp * func_ref_exp = isSgFunctionRefExp(kernel);
6638 SgTemplateFunctionRefExp * template_func_ref_exp = isSgTemplateFunctionRefExp(kernel);
6639 if (func_ref_exp == NULL && template_func_ref_exp == NULL)
6640 {
6641 std::cerr << "SgCudaKernelCallExp accept only direct reference to a function. Got, " << typeid(*kernel).name()
6642 << " with, " << kernel->unparseToString() << std::endl;
6643
6644 // PP (7/1/19): experimental support for RAJA/CUDA Lulesh codes (producing SgNonrealRefExp) **1
6645 // was: ROSE_ASSERT(false);
6646 }
6647 // DQ (1/19/2016): Adding template function ref support.
6648 else if ( (func_ref_exp != NULL && func_ref_exp->get_symbol_i()->get_declaration()->get_functionModifier().isCudaKernel() == false) &&
6649 (template_func_ref_exp != NULL && template_func_ref_exp->get_symbol_i()->get_declaration()->get_functionModifier().isCudaKernel() == false) )
6650 {
6651 std::cerr << "To build a SgCudaKernelCallExp the callee needs to be a kernel (having \"__global__\" attribute)." << std::endl;
6652 ROSE_ABORT();
6653 }
6654
6655 SgCudaKernelCallExp * kernel_call_expr = new SgCudaKernelCallExp(kernel, parameters, kernel->get_type(), config);
6656
6657 kernel->set_parent(kernel_call_expr);
6658 parameters->set_parent(kernel_call_expr);
6659 config->set_parent(kernel_call_expr);
6660
6661 setOneSourcePositionNull(kernel_call_expr);
6662
6663 ROSE_ASSERT(kernel_call_expr);
6664
6665 return kernel_call_expr;
6666 }
6667
6670 if (!grid || !blocks) {
6671 std::cerr << "SgCudaKernelExecConfig need fields 'grid' and 'blocks' to be set." << std::endl;
6672 ROSE_ABORT();
6673 }
6674
6675 // TODO-CUDA check types
6676
6677 SgCudaKernelExecConfig * config = new SgCudaKernelExecConfig (grid, blocks, shared, stream);
6678
6679 grid->set_parent(config);
6680 blocks->set_parent(config);
6681 if (shared)
6682 shared->set_parent(config);
6683 if (stream)
6684 stream->set_parent(config);
6685
6687
6688 ROSE_ASSERT(config);
6689
6690 return config;
6691}
6692
6695//SageBuilder::buildAssignStatement(SgExpression* lhs,SgExpression* rhs, SgScopeStatement* scope=NULL)
6696{
6697 ROSE_ASSERT(lhs != NULL);
6698 ROSE_ASSERT(rhs != NULL);
6699
6700 //SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,lhs->get_type());
6701// SgBinaryOp::get_type() assume p_expression_type is not set
6702 SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,NULL);
6703 ROSE_ASSERT(assignOp);
6705 lhs->set_parent(assignOp);
6706 rhs->set_parent(assignOp);
6707
6708 lhs->set_lvalue (true);
6709 SgExprStatement* exp = new SgExprStatement(assignOp);
6710 ROSE_ASSERT(exp);
6711 // some child nodes are transparently generated, using recursive setting is safer
6713 //setOneSourcePositionForTransformation(exp);
6714 assignOp->set_parent(exp);
6715 return exp;
6716}
6717
6718// DQ (8/16/2011): This is an AST translate specific version (see note below).
6719// We would like to phase out the version above if possible (but we want to
6720// test this later).
6723{
6724 ROSE_ASSERT(lhs != NULL);
6725 ROSE_ASSERT(rhs != NULL);
6726
6727 //SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,lhs->get_type());
6728// SgBinaryOp::get_type() assume p_expression_type is not set
6729 SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,NULL);
6730 ROSE_ASSERT(assignOp);
6732 lhs->set_parent(assignOp);
6733 rhs->set_parent(assignOp);
6734
6735 lhs->set_lvalue (true);
6736 SgExprStatement* exp = new SgExprStatement(assignOp);
6737 ROSE_ASSERT(exp);
6738
6739// DQ (8/16/2011): Modified to avoid recursive call to reset source position information
6740// (this version is required for the Java support where we have set source code position
6741// information on the lhs and rhs and we don't want it to be reset as a transformation.
6742// some child nodes are transparently generated, using recursive setting is safer
6744 assignOp->set_parent(exp);
6745 return exp;
6746}
6747
6748
6750{
6751 if (scope == NULL)
6753
6754 // should including current scope when searching for the function definition
6755 // since users can only pass FunctionDefinition when the function body is not yet attached
6756 SgLabelStatement * labelstmt = new SgLabelStatement(name,stmt);
6757 ROSE_ASSERT(labelstmt);
6759
6760 if(stmt!=NULL)
6761 stmt->set_parent(labelstmt);
6762
6763 // Liao 1/7/2010
6764 // SgLabelStatement is used for CONTINUE statement in Fortran
6765 // In this case , it has no inherent association with a Label symbol.
6766 // It is up to the SageInterface::setNumericalLabel(SgStatement*) to handle label symbol
6768 fixLabelStatement(labelstmt,scope);
6769 // we don't want to set parent here yet
6770 // delay it until append_statement() or alike
6771 return labelstmt;
6772}
6773
6775{
6776 SgLabelStatement* labelStmt = new SgLabelStatement(name,stmt);
6777 ASSERT_not_null(labelStmt);
6779
6780 if (stmt != nullptr) {
6781 stmt->set_parent(labelStmt);
6782 }
6783 if (scope) {
6784 fixLabelStatement(labelStmt,scope);
6785 }
6786
6787 // we don't want to set parent here yet
6788 // delay it until append_statement() or alike
6789 return labelStmt;
6790}
6791
6792SgIfStmt * SageBuilder::buildIfStmt(SgStatement* conditional, SgStatement * true_body, SgStatement * false_body)
6793{
6794 ROSE_ASSERT(conditional);
6795 ROSE_ASSERT(true_body);
6796 SgIfStmt *ifstmt = new SgIfStmt(conditional, true_body, false_body);
6797 ROSE_ASSERT(ifstmt);
6798
6799 // CR (3/22/2020): Fixed setting case insensitivity
6800 // if (symbol_table_case_insensitive_semantics == true)
6802 ifstmt->setCaseInsensitive(true);
6803
6805 conditional->set_parent(ifstmt);
6806 true_body->set_parent(ifstmt);
6807 if (false_body != NULL) false_body->set_parent(ifstmt);
6808
6810 {
6811 // Liao 1/20/2010
6812 // According to Fortran 77 standard Chapter 11.5 to 11.9,
6813 // this is a Fortran Block IF statement, if the true body is:
6814 // 1. A block of statement under SgBasicBlock
6815 // 2. DO, block if, or another logical if
6816 // Otherwise it is a logical if statement
6817 if (isSgBasicBlock(true_body)|| isSgFortranDo(true_body)|| isSgIfStmt(true_body))
6818 {
6819 ifstmt->set_use_then_keyword(true);
6820 ifstmt->set_has_end_statement(true);
6821 }
6822 }
6823
6824 return ifstmt;
6825}
6826
6828 {
6829 SgIfStmt *ifstmt = new SgIfStmt(conditional, true_body, false_body);
6830 ROSE_ASSERT(ifstmt);
6831 // DQ (2/13/2012): This allows us to separate the construction from the initialization (see note below).
6832 initializeIfStmt(ifstmt,conditional,true_body,false_body);
6833 return ifstmt;
6834 }
6835
6836// Rasmussen (9/3/2018): Added build function for a Fortran do construct
6838{
6839 if (initialization == nullptr) initialization = buildNullExpression();
6840 if (bound == nullptr) bound = buildNullExpression();
6841 if (increment == nullptr) increment = buildNullExpression();
6842 if (loopBody == nullptr) loopBody = buildBasicBlock();
6843
6844 SgFortranDo* result = new SgFortranDo(initialization, bound, increment, loopBody);
6845 ASSERT_not_null(result);
6846
6848 result->setCaseInsensitive(true);
6849 }
6850
6852
6853 initialization->set_parent(result);
6854 bound->set_parent(result);
6855 increment->set_parent(result);
6856 loopBody->set_parent(result);
6857
6858 return result;
6859}
6860
6862{
6863 if (initialization == nullptr) initialization = buildNullExpression_nfi();
6864 if (bound == nullptr) bound = buildNullExpression_nfi();
6865 if (increment == nullptr) increment = buildNullExpression_nfi();
6866 if (loopBody == nullptr) loopBody = buildBasicBlock_nfi();
6867
6868 SgFortranDo* result = new SgFortranDo(initialization, bound, increment, loopBody);
6869 ASSERT_not_null(result);
6870
6872 result->setCaseInsensitive(true);
6873 }
6874
6876
6877 initialization->set_parent(result);
6878 bound->set_parent(result);
6879 increment->set_parent(result);
6880 loopBody->set_parent(result);
6881
6882 return result;
6883}
6884
6885// charles4 10/14/2011: Vanilla allocation. Use prepend_init_stmt and append_init_stmt to populate afterward.
6887 {
6888 // return new SgForInitStatement();
6889 SgForInitStatement* result = new SgForInitStatement();
6890
6891 // DQ (11/3/2012): Added call to set file info to default settings.
6892 setSourcePosition(result);
6893
6894 return result;
6895 }
6896
6897// DQ (10/12/2012): Added specific API to handle simple (single) statement.
6900 {
6901 SgForInitStatement* forInit = new SgForInitStatement();
6902 ROSE_ASSERT(forInit != NULL);
6903
6904 ROSE_ASSERT(statement != NULL);
6905 forInit->append_init_stmt(statement);
6906
6907 // DQ (11/3/2012): Added call to set file info to default settings.
6908 setSourcePosition(forInit);
6909
6910 return forInit;
6911 }
6912
6913SgForInitStatement * SageBuilder::buildForInitStatement(const SgStatementPtrList & statements)
6914{
6915 SgForInitStatement * result = new SgForInitStatement();
6916 result->get_init_stmt() = statements;
6917
6918 for (SgStatementPtrList::iterator it = result->get_init_stmt().begin(); it != result->get_init_stmt().end(); it++)
6919 (*it)->set_parent(result);
6920
6922 return result;
6923}
6924
6926SageBuilder::buildForInitStatement_nfi(SgStatementPtrList & statements)
6927 {
6928 SgForInitStatement * result = new SgForInitStatement();
6929
6930 result->get_init_stmt() = statements;
6931
6932 for (SgStatementPtrList::iterator it = result->get_init_stmt().begin(); it != result->get_init_stmt().end(); it++)
6933 {
6934 (*it)->set_parent(result);
6935 }
6936
6937 // DQ (11/3/2012): Added call to set file info to default settings.
6938 setSourcePosition(result);
6939
6940 return result;
6941 }
6942
6944//Liao, 8/27/2008
6945SgForStatement * SageBuilder::buildForStatement(SgStatement* initialize_stmt, SgStatement * test, SgExpression * increment, SgStatement * loop_body, SgStatement * else_body)
6946{
6947 SgForStatement * result = new SgForStatement(test,increment, loop_body);
6948 ROSE_ASSERT(result);
6949
6951 result->setCaseInsensitive(true);
6952
6954 if (test)
6955 test->set_parent(result);
6956 if (loop_body)
6957 loop_body->set_parent(result);
6958 if (increment)
6959 increment->set_parent(result);
6960
6961 if (else_body)
6962 else_body->set_parent(result);
6963 result->set_else_body(else_body);
6964
6965 // CH (5/13/2010): If the initialize_stmt is an object of SgForInitStatement, we can directly put it
6966 // into for statement. Or else, there will be two semicolons after unparsing.
6967 if (SgForInitStatement* for_init_stmt = isSgForInitStatement(initialize_stmt))
6968 {
6969 // DQ (7/30/2011): We have to delete the the SgForInitStatement build within the SgForStatement::post_constructor_initialization()
6970 // to avoid causing errors in the AST consistancy checking later.
6971 if (result->get_for_init_stmt() != NULL)
6972 {
6973 delete result->get_for_init_stmt();
6974 result->set_for_init_stmt(NULL);
6975 }
6976
6977 result->set_for_init_stmt(for_init_stmt);
6978 for_init_stmt->set_parent(result);
6979 return result;
6980 }
6981
6982 SgForInitStatement* init_stmt = new SgForInitStatement();
6983 ROSE_ASSERT(init_stmt);
6985
6986 // DQ (7/30/2011): We have to delete the the SgForInitStatement build within the SgForStatement::post_constructor_initialization().
6987 // to avoid causeing errors in the AST consistancy checking later.
6988 if (result->get_for_init_stmt() != NULL)
6989 {
6990 delete result->get_for_init_stmt();
6991 result->set_for_init_stmt(NULL);
6992 }
6993
6994 result->set_for_init_stmt(init_stmt);
6995 init_stmt->set_parent(result);
6996
6997 if (initialize_stmt)
6998 {
6999 init_stmt->append_init_stmt(initialize_stmt);
7000 // Support for "for (int i=0; )", Liao, 3/11/2009
7001 // The symbols are inserted into the symbol table attached to SgForStatement
7002 if (isSgVariableDeclaration(initialize_stmt))
7003 {
7004 fixVariableDeclaration(isSgVariableDeclaration(initialize_stmt),result);
7005 // fix varRefExp to the index variable used in increment, conditional expressions
7006 fixVariableReferences(result);
7007 }
7008 }
7009
7010 return result;
7011 }
7012
7013
7015//Liao, 8/27/2008
7017SageBuilder::buildForStatement_nfi(SgStatement* initialize_stmt, SgStatement * test, SgExpression * increment, SgStatement * loop_body, SgStatement * else_body)
7018 {
7019 SgForStatement * result = new SgForStatement(test, increment, loop_body);
7020 ROSE_ASSERT(result);
7021
7022 // Rasmussen (3/22/2020): Fixed setting case insensitivity
7023 // if (symbol_table_case_insensitive_semantics == true)
7025 result->setCaseInsensitive(true);
7026
7028 if (test) test->set_parent(result);
7029 if (loop_body) loop_body->set_parent(result);
7030 if (increment) increment->set_parent(result);
7031 if (else_body) else_body->set_parent(result);
7032
7033 result->set_else_body(else_body);
7034
7035 if (initialize_stmt != NULL)
7036 {
7037 SgForInitStatement* init_stmt = result->get_for_init_stmt();
7038 ROSE_ASSERT(init_stmt);
7039 setOneSourcePositionNull(init_stmt);
7040 init_stmt->append_init_stmt(initialize_stmt);
7041 initialize_stmt->set_parent(init_stmt);
7042 }
7043
7044 return result;
7045 }
7046
7047
7050 {
7051 SgForStatement * result = new SgForStatement(init_stmt, test, increment, loop_body);
7052 ROSE_ASSERT(result != NULL);
7053
7054 // DQ (9/26/2012): Refactored this function to allow for where the SgForStatement had to be
7055 // constructed early to define the scope for types that can be defined in the SgForInitStatement.
7056 buildForStatement_nfi(result,init_stmt,test,increment,loop_body,else_body);
7057
7058 return result;
7059 }
7060
7061
7062void
7064 {
7065 // DQ (9/26/2012): Refactored this function to allow for where the SgForStatement had to be
7066 // constructed early to define the scope for types that can be defined in the SgForInitStatement.
7067
7068 ROSE_ASSERT(result != NULL);
7069
7070 // DQ (11/4/2012): I have added support for remove existing subtrees if they are different from what is provided as input.
7071 if (result->get_for_init_stmt() != NULL && init_stmt != result->get_for_init_stmt())
7072 {
7073 delete result->get_for_init_stmt();
7074 result->set_for_init_stmt(NULL);
7075 }
7076
7077 if (result->get_test() != NULL && test != result->get_test())
7078 {
7079 delete result->get_test();
7080 result->set_test(NULL);
7081 }
7082
7083 if (result->get_increment() != NULL && increment != result->get_increment())
7084 {
7085 delete result->get_increment();
7086 result->set_increment(NULL);
7087 }
7088
7089 if (result->get_loop_body() != NULL && loop_body != result->get_loop_body())
7090 {
7091 delete result->get_loop_body();
7092 result->set_loop_body(NULL);
7093 }
7094
7095 if (result->get_else_body() != NULL && else_body != result->get_else_body())
7096 {
7097 delete result->get_else_body();
7098 result->set_else_body(NULL);
7099 }
7100
7101 result->set_for_init_stmt(init_stmt);
7102 result->set_test(test);
7103 result->set_increment(increment);
7104 result->set_loop_body(loop_body);
7105
7107 result->setCaseInsensitive(true);
7108
7110 if (test) test->set_parent(result);
7111 if (loop_body) loop_body->set_parent(result);
7112 if (increment) increment->set_parent(result);
7113 if (init_stmt) init_stmt->set_parent(result);
7114 if (else_body) else_body->set_parent(result);
7115
7116 result->set_else_body(else_body);
7117
7118 ROSE_ASSERT(result->get_for_init_stmt() != NULL);
7119 ROSE_ASSERT(result->get_test() != NULL);
7120 ROSE_ASSERT(result->get_increment() != NULL);
7121 ROSE_ASSERT(result->get_loop_body() != NULL);
7122 }
7123
7124
7125// DQ (3/26/2018): Adding support for range based for statement.
7126// SgRangeBasedForStatement* SageBuilder::buildRangeBasedForStatement_nfi(SgVariableDeclaration* initializer, SgExpression* range, SgStatement* body)
7129 SgVariableDeclaration* initializer, SgVariableDeclaration* range,
7130 SgVariableDeclaration* begin_declaration, SgVariableDeclaration* end_declaration,
7131 SgExpression* not_equal_expression, SgExpression* increment_expression,
7132 SgStatement* body)
7133 {
7134 // DQ (6/26/2019): Commented these out so that we could build the SgRangeBasedForStatement before
7135 // building the children, since the scope of the chldren will be the SgRangeBasedForStatement and
7136 // it must exist before the children are constructed.
7137 // ROSE_ASSERT(initializer != NULL);
7138 // ROSE_ASSERT(range != NULL);
7139
7140 // DQ (6/26/2019): This was already commented out.
7141 // ROSE_ASSERT(body != NULL);
7142
7143 SgRangeBasedForStatement* result = new SgRangeBasedForStatement(initializer, range, begin_declaration, end_declaration, not_equal_expression, increment_expression, body);
7144 ROSE_ASSERT(result != NULL);
7145
7147
7148 if (initializer != NULL) initializer->set_parent(result);
7149 if (range != NULL) range->set_parent(result);
7150
7151 if (begin_declaration != NULL) begin_declaration->set_parent(result);
7152 if (end_declaration != NULL) end_declaration->set_parent(result);
7153
7154 if (not_equal_expression != NULL) not_equal_expression->set_parent(result);
7155 if (increment_expression != NULL) increment_expression->set_parent(result);
7156
7157 if (body != NULL) body->set_parent(result);
7158
7159 return result;
7160 }
7161
7162
7163void
7165 {
7166 // DQ (3/22/2014): This function has been built to support reusing an existing SgDoWhileStatement
7167 // that may have been built and pushed onto the stack as part of a top-down construction of the AST.
7168 // It is required in the EDG 4.8 useage because of a change from EDG 4.7 to 4.8 in how blocks are
7169 // handled (end-of-construct entries).
7170
7171 ASSERT_not_null(result);
7172 ASSERT_not_null(body);
7173 ASSERT_not_null(condition);
7174
7175 ASSERT_require(result->get_body() == nullptr);
7176 ASSERT_require(result->get_condition() == nullptr);
7177
7178 result->set_body(body);
7179 result->set_condition(condition);
7180
7181 body->set_parent(result);
7182 condition->set_parent(result);
7183
7185
7186 ASSERT_not_null(result->get_body());
7187 ASSERT_not_null(result->get_condition());
7188
7189 ASSERT_require(result->get_body()->get_parent() == result);
7190 ASSERT_require(result->get_condition()->get_parent() == result);
7191 }
7192
7193
7194
7196//Liao, 8/27/2008
7198{
7199 SgUpcForAllStatement * result = new SgUpcForAllStatement(test,increment, affinity, loop_body);
7200 ROSE_ASSERT(result);
7202 if (test) test->set_parent(result);
7203 if (loop_body) loop_body->set_parent(result);
7204 if (increment) increment->set_parent(result);
7205 if (affinity) affinity->set_parent(result);
7206
7207 if (initialize_stmt != NULL) {
7208 SgForInitStatement* init_stmt = result->get_for_init_stmt();
7209 ROSE_ASSERT(init_stmt);
7210 setOneSourcePositionNull(init_stmt);
7211 init_stmt->append_init_stmt(initialize_stmt);
7212 initialize_stmt->set_parent(init_stmt);
7213 }
7214
7215 return result;
7216}
7217
7218
7220{
7221 SgUpcForAllStatement * result = new SgUpcForAllStatement(init_stmt, test, increment, affinity, loop_body);
7222 ROSE_ASSERT(result);
7223
7224 // CR (3/22/2020): Fixed setting case insensitivity
7225 // if (symbol_table_case_insensitive_semantics == true)
7227 result->setCaseInsensitive(true);
7228
7230 if (test) test->set_parent(result);
7231 if (loop_body) loop_body->set_parent(result);
7232 if (increment) increment->set_parent(result);
7233 if (affinity) affinity->set_parent(result);
7234 if (init_stmt) init_stmt->set_parent(result);
7235
7236 return result;
7237}
7238
7239// DQ (3/3/2013): Added UPC specific build functions.
7242 {
7243 SgUpcNotifyStatement* result = new SgUpcNotifyStatement(exp);
7244
7246
7247 exp->set_parent(result);
7248
7249 ROSE_ASSERT(exp->get_parent() != NULL);
7250
7251 return result;
7252 }
7253
7256 {
7257 SgUpcWaitStatement* result = new SgUpcWaitStatement(exp);
7258
7260
7261 exp->set_parent(result);
7262
7263 ROSE_ASSERT(exp->get_parent() != NULL);
7264
7265 return result;
7266 }
7267
7270 {
7272
7274
7275 exp->set_parent(result);
7276
7277 ROSE_ASSERT(exp->get_parent() != NULL);
7278
7279 return result;
7280 }
7281
7284 {
7286
7288
7289 return result;
7290 }
7291
7292
7293
7294
7296{
7297 ROSE_ASSERT(condition);
7298 ROSE_ASSERT(body);
7299 SgWhileStmt * result = new SgWhileStmt(condition,body);
7300 ROSE_ASSERT(result);
7301
7302 // CR (3/22/2020): Fixed setting case insensitivity
7303 // if (symbol_table_case_insensitive_semantics == true)
7305 result->setCaseInsensitive(true);
7306
7308 condition->set_parent(result);
7309 body->set_parent(result);
7310
7311// DQ (8/10/2011): This is added by Michael to support a Python specific feature.
7312 if (else_body != NULL) {
7313 result->set_else_body(else_body);
7314 else_body->set_parent(result);
7315 }
7316
7317 return result;
7318}
7319
7320
7323 {
7324 SgWhileStmt * result = new SgWhileStmt(condition,body);
7325 ROSE_ASSERT(result);
7326
7327#if 0
7328 // DQ (11/28/2010): Added specification of case insensitivity for Fortran.
7330 result->setCaseInsensitive(true);
7331
7333 if (condition) condition->set_parent(result);
7334 if (body) body->set_parent(result);
7335
7336 // DQ (8/10/2011): This is added by Michael to support a Python specific feature.
7337 if (else_body != NULL)
7338 {
7339 result->set_else_body(else_body);
7340 else_body->set_parent(result);
7341 }
7342#else
7343 // DQ (2/15/2012): This function supports the case where in C++ the condition can include a variable declaration.
7344 initializeWhileStatement(result,condition,body,else_body);
7345#endif
7346
7347 return result;
7348 }
7349
7350
7352{
7353 ROSE_ASSERT(expr != NULL && body != NULL);
7354 SgWithStatement* result = new SgWithStatement(expr, body);
7355 expr->set_parent(result);
7356 body->set_parent(result);
7357
7359 return result;
7360}
7361
7363{
7364 ROSE_ASSERT(expr != NULL && body != NULL);
7365 SgWithStatement* result = new SgWithStatement(expr, body);
7366 expr->set_parent(result);
7367 body->set_parent(result);
7368
7370 return result;
7371}
7372
7374{
7375 ROSE_ASSERT(condition);
7376 ROSE_ASSERT(body);
7377 SgDoWhileStmt * result = new SgDoWhileStmt(body, condition);
7378 ROSE_ASSERT(result);
7380 condition->set_parent(result);
7381 body->set_parent(result);
7382 return result;
7383}
7384
7386{
7387 SgDoWhileStmt * result = new SgDoWhileStmt(body, condition);
7388 ROSE_ASSERT(result);
7390 if (condition) condition->set_parent(result);
7391 if (body) body->set_parent(result);
7392 return result;
7393}
7394
7396{
7397 SgMatlabForStatement* result = new SgMatlabForStatement(loop_index, loop_range, loop_body);
7399
7400 ROSE_ASSERT(result != NULL);
7401
7402 loop_index->set_parent(result);
7403 loop_range->set_parent(result);
7404 loop_body->set_parent(result);
7405 return result;
7406}
7407
7409{
7410 SgBreakStmt* result = new SgBreakStmt();
7411 ROSE_ASSERT(result);
7413 return result;
7414}
7415
7417{
7418 SgBreakStmt* result = new SgBreakStmt();
7419 ROSE_ASSERT(result);
7421 return result;
7422}
7423
7425{
7426 SgContinueStmt* result = new SgContinueStmt();
7427 ASSERT_not_null(result);
7429 return result;
7430}
7431
7433{
7434 SgContinueStmt* result = new SgContinueStmt();
7435 ASSERT_not_null(result);
7437 return result;
7438}
7439
7441{
7443 ASSERT_not_null(result);
7445 return result;
7446}
7447
7449{
7451 ASSERT_not_null(result);
7453 return result;
7454}
7455
7457{
7458 SgPassStatement* result = new SgPassStatement();
7459 ROSE_ASSERT(result);
7461 return result;
7462}
7463
7465{
7466 SgPassStatement* result = new SgPassStatement();
7467 ROSE_ASSERT(result);
7469 return result;
7470}
7471
7472SgDeleteExp* SageBuilder::buildDeleteExp(SgExpression *target, bool is_array, bool need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
7473{
7474 SgDeleteExp *result = new SgDeleteExp(target, is_array, need_global_specifier, deleteOperatorDeclaration);
7475 target->set_parent(result);
7477 return result;
7478}
7479
7480SgDeleteExp* SageBuilder::buildDeleteExp_nfi(SgExpression *target, bool is_array, bool need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
7481{
7482 SgDeleteExp *result = new SgDeleteExp(target, is_array, need_global_specifier, deleteOperatorDeclaration);
7483 target->set_parent(result);
7485 return result;
7486}
7487
7489{
7490 SgAssertStmt* result = new SgAssertStmt(test);
7491 ROSE_ASSERT(test != NULL);
7492 test->set_parent(result);
7494 return result;
7495}
7496
7497// DQ (7/18/2011): Added support for SgJavaInstanceOfOp
7500 {
7501 SgType* exp_type = SgTypeBool::createType();
7502
7503 SgJavaInstanceOfOp* result = new SgJavaInstanceOfOp(exp, type, exp_type);
7504 ROSE_ASSERT(result);
7505 if (exp != NULL)
7506 {
7507 exp->set_parent(result);
7508 markLhsValues(result);
7509 }
7510
7512 return result;
7513 }
7514
7516{
7517 SgAssertStmt* result = new SgAssertStmt(test);
7518 ROSE_ASSERT(test != NULL);
7519 test->set_parent(result);
7520 if (exceptionArgument != NULL) {
7521 result -> set_exception_argument(exceptionArgument);
7522 exceptionArgument->set_parent(result);
7523 }
7525 return result;
7526}
7527
7529{
7530 SgAssertStmt* result = new SgAssertStmt(test);
7531 ROSE_ASSERT(test != NULL);
7532 test->set_parent(result);
7534 return result;
7535}
7536
7538{
7539 ROSE_ASSERT(value != NULL);
7540 SgYieldExpression* result = new SgYieldExpression(value);
7541 value->set_parent(result);
7543 return result;
7544}
7545
7547{
7548 ROSE_ASSERT(value != NULL);
7549 SgYieldExpression* result = new SgYieldExpression(value);
7550 value->set_parent(result);
7552 return result;
7553}
7554
7556{
7557 ROSE_ASSERT(key != NULL && datum != NULL);
7558 SgKeyDatumPair *result = new SgKeyDatumPair(key, datum);
7559 key->set_parent(result);
7560 datum->set_parent(result);
7562 return result;
7563}
7564
7566{
7567 ROSE_ASSERT(key != NULL && datum != NULL);
7568 SgKeyDatumPair *result = new SgKeyDatumPair(key, datum);
7569 key->set_parent(result);
7570 datum->set_parent(result);
7572 return result;
7573}
7574
7575SgDictionaryExp* SageBuilder::buildDictionaryExp(std::vector<SgKeyDatumPair*> pairs)
7576{
7577 SgDictionaryExp *result = new SgDictionaryExp();
7578 ROSE_ASSERT(result);
7579 for (size_t i = 0; i < pairs.size(); ++i)
7580 result->append_pair(pairs[i]);
7582 return result;
7583}
7584
7585SgDictionaryExp* SageBuilder::buildDictionaryExp_nfi(std::vector<SgKeyDatumPair*> pairs)
7586{
7587 SgDictionaryExp *result = new SgDictionaryExp();
7588 ROSE_ASSERT(result);
7589 for (size_t i = 0; i < pairs.size(); ++i)
7590 result->append_pair(pairs[i]);
7592 return result;
7593}
7594
7597{
7598 ROSE_ASSERT(target != NULL);
7599 ROSE_ASSERT(iter != NULL);
7600 SgComprehension *result = new SgComprehension(target, iter, ifs);
7601 ROSE_ASSERT(result);
7602
7603 target->set_parent(result);
7604 iter->set_parent(result);
7605 if (ifs != NULL) ifs->set_parent(result);
7606
7608 return result;
7609}
7610
7613{
7614 ROSE_ASSERT(target != NULL);
7615 ROSE_ASSERT(iter != NULL);
7616 SgComprehension *result = new SgComprehension(target, iter, ifs);
7617 ROSE_ASSERT(result);
7618 target->set_parent(result);
7619 iter->set_parent(result);
7620 if (ifs != NULL) ifs->set_parent(result);
7622 return result;
7623}
7624
7627{
7628 ROSE_ASSERT(elt != NULL);
7629 ROSE_ASSERT(generators != NULL);
7630 SgListComprehension* result = new SgListComprehension(elt, generators);
7631 elt->set_parent(result);
7632 generators->set_parent(result);
7634 return result;
7635}
7636
7639{
7640 ROSE_ASSERT(elt != NULL);
7641 ROSE_ASSERT(generators != NULL);
7642 SgListComprehension* result = new SgListComprehension(elt, generators);
7643 elt->set_parent(result);
7644 generators->set_parent(result);
7646 return result;
7647}
7648
7651{
7652 ROSE_ASSERT(elt != NULL);
7653 ROSE_ASSERT(generators != NULL);
7654 SgSetComprehension* result = new SgSetComprehension(elt, generators);
7655 elt->set_parent(result);
7656 generators->set_parent(result);
7658 return result;
7659}
7660
7663{
7664 ROSE_ASSERT(elt != NULL);
7665 ROSE_ASSERT(generators != NULL);
7666 SgSetComprehension* result = new SgSetComprehension(elt, generators);
7667 elt->set_parent(result);
7668 generators->set_parent(result);
7670 return result;
7671}
7672
7675{
7676 ROSE_ASSERT(kd_pair != NULL);
7677 ROSE_ASSERT(generators != NULL);
7678 SgDictionaryComprehension* result = new SgDictionaryComprehension(kd_pair, generators);
7679 kd_pair->set_parent(result);
7680 generators->set_parent(result);
7682 return result;
7683}
7684
7687{
7688 ROSE_ASSERT(kd_pair != NULL);
7689 ROSE_ASSERT(generators != NULL);
7690 SgDictionaryComprehension* result = new SgDictionaryComprehension(kd_pair, generators);
7691 kd_pair->set_parent(result);
7692 generators->set_parent(result);
7694 return result;
7695}
7696
7699 ROSE_ASSERT(arg != NULL);
7700 SgActualArgumentExpression* result = new SgActualArgumentExpression(arg_name, arg);
7701 arg->set_parent(result);
7703 return result;
7704}
7705
7708 ROSE_ASSERT(arg != NULL);
7709 SgActualArgumentExpression* result = new SgActualArgumentExpression(arg_name, arg);
7710 arg->set_parent(result);
7712 return result;
7713}
7714
7717 {
7718 if (scope == NULL)
7720
7721 SgPragma* pragma = new SgPragma(name);
7722 ROSE_ASSERT(pragma);
7723
7725
7726 SgPragmaDeclaration* result = new SgPragmaDeclaration(pragma);
7727 ROSE_ASSERT(result);
7728
7730
7731 result->set_definingDeclaration (result);
7732 result->set_firstNondefiningDeclaration(result);
7733 pragma->set_parent(result);
7734
7735 // DQ (7/14/2012): Set the parent so that we can be consistent where possible (class declarations and
7736 // enum declaration can't have there parent set since they could be non-autonomous declarations).
7737 result->set_parent(scope);
7738
7739 if (scope || topScopeStack())
7740 ROSE_ASSERT(result->get_parent() != NULL);
7741
7742 return result;
7743 }
7744
7746SgPragma* SageBuilder::buildPragma(const std::string & name)
7747{
7748 SgPragma* result= new SgPragma(name);
7749 ROSE_ASSERT(result);
7751 return result;
7752}
7753
7754
7756 {
7757 // Build an empty declaration (useful for adding precission to comments and CPP handling under token-based unparsing).
7758 SgEmptyDeclaration* emptyDeclaration = new SgEmptyDeclaration();
7759 ROSE_ASSERT(emptyDeclaration != NULL);
7760
7761 setOneSourcePositionForTransformation(emptyDeclaration);
7762
7763 emptyDeclaration->set_definingDeclaration (emptyDeclaration);
7764 emptyDeclaration->set_firstNondefiningDeclaration(emptyDeclaration);
7765
7766 // DQ (7/14/2012): Set the parent so that we can be consistent where possible (class declarations and
7767 // enum declaration can't have there parent set since they could be non-autonomous declarations).
7768 emptyDeclaration->set_parent(topScopeStack());
7769
7770 if (topScopeStack() != NULL)
7771 {
7772 ROSE_ASSERT(emptyDeclaration->get_parent() != NULL);
7773 }
7774
7775 return emptyDeclaration;
7776 }
7777
7778
7780{
7781 SgBasicBlock* result = new SgBasicBlock();
7782 ROSE_ASSERT(result);
7783
7784 // CR (3/22/2020): Fixed setting case insensitivity
7785 // if (symbol_table_case_insensitive_semantics == true)
7787 result->setCaseInsensitive(true);
7788
7790 if (stmt1) SageInterface::appendStatement(stmt1, result);
7791 if (stmt2) SageInterface::appendStatement(stmt2, result);
7792 if (stmt3) SageInterface::appendStatement(stmt3, result);
7793 if (stmt4) SageInterface::appendStatement(stmt4, result);
7794 if (stmt5) SageInterface::appendStatement(stmt5, result);
7795 if (stmt6) SageInterface::appendStatement(stmt6, result);
7796 if (stmt7) SageInterface::appendStatement(stmt7, result);
7797 if (stmt8) SageInterface::appendStatement(stmt8, result);
7798 if (stmt9) SageInterface::appendStatement(stmt9, result);
7799 if (stmt10) SageInterface::appendStatement(stmt10, result);
7800
7801 return result;
7802}
7803
7805 {
7806 SgBasicBlock* result = new SgBasicBlock();
7807 ROSE_ASSERT(result);
7808
7809 // CR (3/22/2020): Fixed setting case insensitivity
7810 // if (symbol_table_case_insensitive_semantics == true)
7812 {
7813 result->setCaseInsensitive(true);
7814 }
7815
7817
7818#if 0
7819 printf ("In buildBasicBlock_nfi(): returning result = %p \n",result);
7820#endif
7821
7822 return result;
7823 }
7824
7825SgBasicBlock* SageBuilder::buildBasicBlock_nfi(const vector<SgStatement*>& stmts)
7826 {
7828 appendStatementList(stmts, result);
7829
7830#if 0
7831 printf ("In buildBasicBlock_nfi(const vector<SgStatement*>& stmts): returning result = %p \n",result);
7832#endif
7833
7834#if 0
7835 printf ("Exiting as a test! \n");
7836 ROSE_ABORT();
7837#endif
7838
7839 return result;
7840 }
7841
7842// CR (7/24/2020): Added additional functionality.
7843// Build a SgBasicBlock and set its parent. This function does NOT link the parent scope to the block.
7846{
7848 block->set_parent(parent);
7849
7850 return block;
7851}
7852
7853
7856{
7857 SgGotoStatement* result = new SgGotoStatement(label);
7858 ROSE_ASSERT(result);
7860 return result;
7861}
7862
7865{
7866 SgGotoStatement* result = NULL;
7867 ROSE_ASSERT (symbol != NULL);
7869 { // Fortran case
7870 result = buildGotoStatement((SgLabelStatement *)NULL);
7871 SgLabelRefExp* l_exp = buildLabelRefExp(symbol);
7872 l_exp->set_parent(result);
7873 result->set_label_expression(l_exp);
7874 }
7875 else // C/C++ case
7876 {
7877 SgLabelStatement* l_stmt = isSgLabelStatement(symbol->get_declaration());
7878 ROSE_ASSERT (l_stmt != NULL);
7879 result = buildGotoStatement(l_stmt);
7880 }
7881 ROSE_ASSERT(result);
7882 return result;
7883}
7884
7887{
7888 SgGotoStatement* result = new SgGotoStatement(label);
7889 ROSE_ASSERT(result);
7891 return result;
7892}
7893
7894// DQ (11/22/2017): Added support for computed code goto as defined by GNU C/C++ extension.
7897 {
7898 SgLabelStatement* label = NULL;
7899 SgGotoStatement* result = new SgGotoStatement(label);
7900 result->set_selector_expression(label_expression);
7901 ROSE_ASSERT(result);
7903 return result;
7904 }
7905
7908{
7909 // Liao 2/6/2013. We no longer allow NULL express pointer. Use SgNullExpression instead.
7910 // CR (4/27/18): The expression argument to the builder function is optional
7911 // (NULL is allowed). What is not allowed is constructing an SgReturnStmt with a NULL
7912 // expression argument.
7913 if (expression == NULL)
7914 {
7915 expression = buildNullExpression();
7916 }
7917 SgReturnStmt * result = new SgReturnStmt(expression);
7918 ROSE_ASSERT(result);
7919 if (expression != NULL) expression->set_parent(result);
7921 return result;
7922}
7923
7926{
7927 SgReturnStmt * result = new SgReturnStmt(expression);
7928 ROSE_ASSERT(result);
7929 if (expression != NULL) expression->set_parent(result);
7931 return result;
7932}
7933
7935{
7936 SgCaseOptionStmt* result = new SgCaseOptionStmt(key,body);
7937 ROSE_ASSERT(result);
7939 if (key) key->set_parent(result);
7940 if (body) body->set_parent(result);
7941 return result;
7942}
7943
7945{
7946 SgCaseOptionStmt* result = new SgCaseOptionStmt(key,body);
7947 ROSE_ASSERT(result);
7949 if (key) key->set_parent(result);
7950 if (body) body->set_parent(result);
7951 return result;
7952}
7953
7955{
7956 SgDefaultOptionStmt* result = new SgDefaultOptionStmt(body);
7957 ROSE_ASSERT(result);
7959 if (body) body->set_parent(result);
7960
7961#if 0
7962 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7963 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7964 printf ("SageBuilder::buildDefaultOptionStmt() body = %p \n",body);
7965 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7966 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7967#endif
7968
7969 return result;
7970}
7971
7973{
7974 SgDefaultOptionStmt* result = new SgDefaultOptionStmt(body);
7975 ROSE_ASSERT(result);
7977 if (body) body->set_parent(result);
7978
7979#if 0
7980 static int count = 0;
7981
7982 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7983 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7984 printf ("SageBuilder::buildDefaultOptionStmt_nfi() body = %p \n",body);
7985 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7986 printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
7987
7988 if (count >= 1)
7989 {
7990 printf ("Exiting as a test! \n");
7991 ROSE_ASSERT(false);
7992 }
7993 count++;
7994#endif
7995
7996 return result;
7997}
7998
8000{
8001 SgSwitchStatement* result = new SgSwitchStatement(item_selector,body);
8002 ROSE_ASSERT(result);
8003
8004 // CR (3/22/2020): Fixed setting case insensitivity
8005 // if (symbol_table_case_insensitive_semantics == true)
8007 result->setCaseInsensitive(true);
8008
8010 if (item_selector) item_selector->set_parent(result);
8011 if (body) body->set_parent(result);
8012 return result;
8013}
8014
8017 {
8018 SgSwitchStatement* result = new SgSwitchStatement(item_selector,body);
8019 ROSE_ASSERT(result);
8020
8021#if 0
8022 // DQ (11/28/2010): Added specification of case insensitivity for Fortran.
8024 result->setCaseInsensitive(true);
8025
8027 if (item_selector) item_selector->set_parent(result);
8028 if (body) body->set_parent(result);
8029#else
8030 // DQ (2/15/2012): Modified to handle C++ case where variable declarations are allowed in the condition.
8031 initializeSwitchStatement(result,item_selector,body);
8032#endif
8033
8034 return result;
8035 }
8036
8039{
8040 SgNullStatement* result = NULL;
8041 result = new SgNullStatement();
8042 ROSE_ASSERT(result);
8044 return result;
8045}
8046
8049{
8050 SgNullStatement* result = NULL;
8051 result = new SgNullStatement();
8052 ROSE_ASSERT(result);
8054 return result;
8055}
8056
8059 SgExpression* globals,
8060 SgExpression* locals) {
8061 if (locals != NULL && globals == NULL)
8062 ROSE_ASSERT(!"buildExecStatement with non-NULL locals requires non-NULL globals");
8063 ROSE_ASSERT(executable != NULL);
8064
8065 SgExecStatement* result = new SgExecStatement(executable, globals, locals);
8066 executable->set_parent(result);
8067 if (globals != NULL) globals->set_parent(result);
8068 if (locals != NULL) locals->set_parent(result);
8069
8071 return result;
8072}
8073
8076 SgExpression* globals,
8077 SgExpression* locals) {
8078 if (locals != NULL && globals == NULL)
8079 ROSE_ASSERT(!"buildExecStatement with non-NULL locals requires non-NULL globals");
8080 ROSE_ASSERT(executable != NULL);
8081
8082 SgExecStatement* result = new SgExecStatement(executable, globals, locals);
8083 executable->set_parent(result);
8084 if (globals != NULL) globals->set_parent(result);
8085 if (locals != NULL) locals->set_parent(result);
8086
8088 return result;
8089}
8090
8091// MH (6/10/2014): Added async support
8093{
8094 ROSE_ASSERT(body != NULL);
8095 SgAsyncStmt *async_stmt = new SgAsyncStmt(body);
8096 ROSE_ASSERT(async_stmt);
8097 body->set_parent(async_stmt);
8099
8100 return async_stmt;
8101}
8102
8103// MH (6/11/2014): Added finish support
8105{
8106 ROSE_ASSERT(body != NULL);
8107 SgFinishStmt *finish_stmt = new SgFinishStmt(body);
8108 ROSE_ASSERT(finish_stmt);
8109 body->set_parent(finish_stmt);
8111
8112 return finish_stmt;
8113}
8114
8115// MH (6/11/2014): Added at support
8117{
8118 ROSE_ASSERT(expression);
8119 ROSE_ASSERT(body);
8120 SgAtStmt *at_stmt = new SgAtStmt(expression, body);
8122 expression->set_parent(at_stmt);
8123 body->set_parent(at_stmt);
8124
8125 return at_stmt;
8126}
8127
8128// MH (11/12/2014): Added atomic support
8130{
8131 ROSE_ASSERT(body != NULL);
8132 SgAtomicStmt *atomic_stmt = new SgAtomicStmt(body);
8133 ROSE_ASSERT(atomic_stmt);
8134 body->set_parent(atomic_stmt);
8136
8137 return atomic_stmt;
8138}
8139
8140
8142{
8143 ROSE_ASSERT(expression);
8144 ROSE_ASSERT(body);
8145 SgWhenStmt *when_stmt = new SgWhenStmt(expression, body);
8147 expression->set_parent(when_stmt);
8148 body->set_parent(when_stmt);
8149
8150 return when_stmt;
8151}
8152
8153// MH (9/14/2014): Added atexpr support
8155{
8156 ROSE_ASSERT(expression);
8157 ROSE_ASSERT(body);
8158 SgAtExp *at_exp = new SgAtExp(expression, body);
8160 expression->set_parent(at_exp);
8161 body->set_parent(at_exp);
8162
8163 return at_exp;
8164}
8165
8166// MH (11/7/2014): Added finish expression support
8168{
8169 ROSE_ASSERT(expression);
8170 ROSE_ASSERT(body);
8171 SgFinishExp *finish_exp = new SgFinishExp(expression, body);
8173 expression->set_parent(finish_exp);
8174 body->set_parent(finish_exp);
8175
8176 return finish_exp;
8177}
8178
8180{
8181 SgHereExp *here = new SgHereExp(NULL);
8182 return here;
8183}
8184
8186{
8187 SgDotDotExp *dotdot = new SgDotDotExp(NULL);
8188 return dotdot;
8189}
8190
8191
8194 SgCatchOptionStmt* catch0,
8195 SgCatchOptionStmt* catch1,
8196 SgCatchOptionStmt* catch2,
8197 SgCatchOptionStmt* catch3,
8198 SgCatchOptionStmt* catch4
8199 )
8200 {
8201 ROSE_ASSERT(body != NULL);
8202 SgTryStmt* try_stmt = new SgTryStmt(body);
8203 body->set_parent(try_stmt);
8204
8205 // DQ (11/3/2012): Added setting default source position info.
8206 setSourcePosition(try_stmt);
8207
8208 if (try_stmt->get_catch_statement_seq_root() != NULL)
8209 {
8210 if (try_stmt->get_catch_statement_seq_root()->get_startOfConstruct() == NULL)
8211 {
8212 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_endOfConstruct() == NULL);
8214 }
8215
8216 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_startOfConstruct() != NULL);
8217 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_endOfConstruct() != NULL);
8218 }
8219
8220 if (catch0 != NULL) try_stmt->append_catch_statement(catch0);
8221 if (catch1 != NULL) try_stmt->append_catch_statement(catch1);
8222 if (catch2 != NULL) try_stmt->append_catch_statement(catch2);
8223 if (catch3 != NULL) try_stmt->append_catch_statement(catch3);
8224 if (catch4 != NULL) try_stmt->append_catch_statement(catch4);
8225
8226 return try_stmt;
8227 }
8228
8229
8230// charles4 09/16/2011
8233 {
8234 //
8235 // charles4 09/23/2011 - Note that when an SgTryStmt is allocated, its constructor
8236 // preallocates a SgCatchStementSeq for the field p_catch_statement_sequence_root.
8237 // So, although the method set_catch_statement_seq_root(catch_statement_sequence) is
8238 // available, it should not be used to set the catch_statement_sequence_root as that
8239 // would leave the one that was allocated by the constructor dangling!
8240 //
8241 ROSE_ASSERT(try_body != NULL);
8242 SgTryStmt* try_stmt = new SgTryStmt(try_body);
8243 try_body -> set_parent(try_stmt);
8244
8245 // DQ (11/3/2012): Added setting default source position info.
8246 setSourcePosition(try_stmt);
8247
8248 if (finally_body) {
8249 try_stmt -> set_finally_body(finally_body);
8250 finally_body -> set_parent(try_stmt);
8251 }
8252
8253 return try_stmt;
8254}
8255
8256// charles4 09/16/2011
8257// ! Build an initial sequence of Catch blocks containing 0 or 1 element.
8259 SgCatchStatementSeq *catch_statement_sequence = new SgCatchStatementSeq();
8260
8261 // DQ (11/3/2012): Added setting default source position info.
8262 setSourcePosition(catch_statement_sequence);
8263
8264 if (catch_option_stmt) {
8265 catch_statement_sequence -> append_catch_statement(catch_option_stmt);
8266 catch_option_stmt -> set_parent(catch_statement_sequence);
8267 }
8268
8269 return catch_statement_sequence;
8270}
8271
8272// charles4 09/21/2011 - Make condition and body arguments optional.
8275 SgCatchOptionStmt* result = new SgCatchOptionStmt(condition, body, /* SgTryStmt*= */ NULL);
8276 if (condition) condition->set_parent(result);
8277 if (body) body->set_parent(result);
8279 return result;
8280}
8281
8283{
8284 ROSE_ASSERT(expression);
8285 ROSE_ASSERT(body);
8286 SgJavaSynchronizedStatement *sync_stmt = new SgJavaSynchronizedStatement(expression, body);
8288
8289 expression->set_parent(sync_stmt);
8290 body->set_parent(sync_stmt);
8291
8292 return sync_stmt;
8293}
8294
8296{
8297 ROSE_ASSERT(op);
8298 SgJavaThrowStatement *throw_stmt = new SgJavaThrowStatement(op);
8299 ROSE_ASSERT(throw_stmt);
8300
8301 op->set_parent(throw_stmt);
8302
8303 return throw_stmt;
8304}
8305
8306// DQ (9/3/2011): Changed the API to conform to the Java grammar.
8307// SgJavaForEachStatement *SageBuilder::buildJavaForEachStatement(SgInitializedName *variable, SgExpression *collection, SgStatement *body)
8309{
8310 SgJavaForEachStatement *foreach_stmt = new SgJavaForEachStatement(variable, collection, body);
8311 ROSE_ASSERT(foreach_stmt);
8312 if (variable) variable -> set_parent(foreach_stmt);
8313 if (collection) collection -> set_parent(foreach_stmt);
8314 if (body) body -> set_parent(foreach_stmt);
8315
8316 return foreach_stmt;
8317}
8318
8320{
8321 SgJavaLabelStatement *label_stmt = new SgJavaLabelStatement(name, stmt);
8322 ROSE_ASSERT(label_stmt);
8324
8325 if (stmt != NULL)
8326 stmt -> set_parent(label_stmt);
8327
8328 SgJavaLabelSymbol *lsymbol = label_stmt -> lookup_java_label_symbol(name);
8329 if (! lsymbol) // Should be an Assertion - always true!
8330 {
8331 lsymbol= new SgJavaLabelSymbol(label_stmt);
8332 ROSE_ASSERT(lsymbol);
8333 label_stmt -> insert_symbol(lsymbol -> get_name(), lsymbol);
8334 }
8335
8336 return label_stmt;
8337}
8338
8341 SgPythonPrintStmt* result = new SgPythonPrintStmt(dest, values);
8342 if (dest) dest->set_parent(result);
8343 if (values) values->set_parent(result);
8345 return result;
8346}
8347
8350 SgPythonPrintStmt* result = new SgPythonPrintStmt(dest, values);
8351 if (dest) dest->set_parent(result);
8352 if (values) values->set_parent(result);
8354 return result;
8355}
8356
8358SageBuilder::buildPythonGlobalStmt(SgInitializedNamePtrList& names) {
8359 SgPythonGlobalStmt* result = new SgPythonGlobalStmt();
8360 for (SgInitializedName* name: names) {
8361 result->append_name(name);
8362 }
8364 return result;
8365}
8366
8368SageBuilder::buildPythonGlobalStmt_nfi(SgInitializedNamePtrList& names) {
8369 SgPythonGlobalStmt* result = new SgPythonGlobalStmt();
8370 for (SgInitializedName* name: names) {
8371 result->append_name(name);
8372 }
8374 return result;
8375}
8376
8377// DQ (4/30/2010): Added support for building asm statements.
8380{
8381 SgAsmStmt* result = NULL;
8382 result = new SgAsmStmt();
8383 ROSE_ASSERT(result);
8384 result->set_assemblyCode(s);
8386 return result;
8387}
8388
8389// DQ (4/30/2010): Added support for building asm statements.
8392{
8393 SgAsmStmt* result = NULL;
8394 result = new SgAsmStmt();
8395 ROSE_ASSERT(result);
8396 result->set_assemblyCode(s);
8398 return result;
8399}
8400
8401SgAsmStmt*
8403 {
8404// Multi-byte NOP instructions.
8405// Note: I can't seem to get the memonic versions to work properly
8406#define NOP_1_BYTE_STRING "nop"
8407#define NOP_2_BYTE_STRING ".byte 0x66,0x90"
8408#define NOP_3_BYTE_STRING "nopl (%eax)"
8409#define NOP_4_BYTE_STRING "nopl 0x01(%eax)"
8410#define NOP_5_BYTE_STRING ".byte 0x0f,0x1f,0x44,0x00,0x00"
8411#define NOP_6_BYTE_STRING ".byte 0x66,0x0f,0x1f,0x44,0x00,0x00"
8412#define NOP_7_BYTE_STRING ".byte 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00"
8413#define NOP_8_BYTE_STRING ".byte 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00"
8414#define NOP_9_BYTE_STRING ".byte 0x66,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00"
8415
8416 ROSE_ASSERT(n > 0);
8417
8418 SgAsmStmt* nopStatement = NULL;
8419
8420 switch (n)
8421 {
8422 case 1: nopStatement = buildAsmStatement(NOP_1_BYTE_STRING); break;
8423 case 2: nopStatement = buildAsmStatement(NOP_2_BYTE_STRING); break;
8424 case 3: nopStatement = buildAsmStatement(NOP_3_BYTE_STRING); break;
8425 case 4: nopStatement = buildAsmStatement(NOP_4_BYTE_STRING); break;
8426 case 5: nopStatement = buildAsmStatement(NOP_5_BYTE_STRING); break;
8427 case 6: nopStatement = buildAsmStatement(NOP_6_BYTE_STRING); break;
8428 case 7: nopStatement = buildAsmStatement(NOP_7_BYTE_STRING); break;
8429 case 8: nopStatement = buildAsmStatement(NOP_8_BYTE_STRING); break;
8430 case 9: nopStatement = buildAsmStatement(NOP_9_BYTE_STRING); break;
8431
8432 default:
8433 {
8434 printf ("Only supporting values of multi-byte nop's up to 9 bytes long. \n");
8435 ROSE_ABORT();
8436 }
8437 }
8438
8439 return nopStatement;
8440 }
8441
8443 {
8444 // DQ (7/25/2014): Adding support for C11 static assertions.
8445
8446 ROSE_ASSERT(condition != NULL);
8447
8448 SgStaticAssertionDeclaration* result = new SgStaticAssertionDeclaration(condition,string_literal);
8449 ROSE_ASSERT(result != NULL);
8450
8451 // DQ (7/25/2014): It is enforced that at least the firstNondefiningDeclaration be set.
8452 ROSE_ASSERT(result->get_firstNondefiningDeclaration() == NULL);
8453 result->set_firstNondefiningDeclaration(result);
8454 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
8455
8457
8458 return result;
8459 }
8460
8461
8462// DQ (8/17/2014): Adding support for Microsoft MSVC specific attributes.
8464 {
8466 ROSE_ASSERT(result != NULL);
8467
8468 // DQ (8/17/2014): It is enforced that at least the firstNondefiningDeclaration be set.
8469 ROSE_ASSERT(result->get_firstNondefiningDeclaration() == NULL);
8470 result->set_firstNondefiningDeclaration(result);
8471 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
8472
8474
8475 return result;
8476 }
8477
8479// This does not work properly since the global scope expects declaration statement, not just SgNullStatement
8480#if 0
8482{
8483 SgStatement* result = NULL;
8484
8485 return result;
8486
8487} //buildStatementFromString()
8488#endif
8489
8491 {
8492 // 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.
8493 // 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");
8494 // ROSE_ASSERT(false);
8495
8496 // DQ (7/29/2010): This function needs to call the SgPointerType::createType() function to support the new type table.
8497 // SgPointerType* result = new SgPointerType(base_type);
8498 if (isSgReferenceType (base_type))
8499 {
8500 cerr<<"Error in SageBuilder::buildPointerType(): trying to build a pointer to a reference type! This is not allowed in C++."<<endl;
8501 ROSE_ABORT ();
8502 }
8503
8504 SgPointerType* result = SgPointerType::createType(base_type);
8505 ROSE_ASSERT(result != NULL);
8506
8507 return result;
8508 }
8509
8511 {
8512 // 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.
8513 // 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");
8514 // ROSE_ASSERT(false);
8515
8516 // DQ (7/29/2010): This function needs to call the SgPointerType::createType() function to support the new type table.
8517 // SgReferenceType* result= new SgReferenceType(base_type);
8518 SgReferenceType* result = SgReferenceType::createType(base_type);
8519 ROSE_ASSERT(result != NULL);
8520
8521 return result;
8522 }
8523
8525 {
8526 ROSE_ASSERT(base_type != NULL);
8528 ROSE_ASSERT(result != NULL);
8529
8530 return result;
8531 }
8532
8534 {
8535 ROSE_ASSERT(base_expression != NULL);
8536
8537 // SgDeclType* result = SgDeclType::createType(base_expression);
8538 SgDeclType* result = NULL;
8539 if (isSgFunctionParameterRefExp(base_expression) != NULL)
8540 {
8541 result = new SgDeclType(base_expression);
8542 result->set_base_type(base_type);
8543 }
8544 else
8545 {
8546 result = SgDeclType::createType(base_expression);
8547 }
8548
8549 ROSE_ASSERT(result != NULL);
8550
8551 // DQ (8/12/2014): Set the parent in the expression.
8552 base_expression->set_parent(result);
8553
8554 return result;
8555 }
8556
8559 {
8560 // ROSE_ASSERT(base_expression != NULL);
8561
8562#define DEBUG_TYPEOF_TYPE 0
8563
8564#if DEBUG_TYPEOF_TYPE
8565 printf ("In SageBuilder::buildTypeOfType(): base_expression = %p = %s \n",base_expression,base_expression != NULL ? base_expression->class_name().c_str() : "NULL");
8566 printf (" ------------------------------- base_type = %p = %s \n",base_type,base_type != NULL ? base_type->class_name().c_str() : "NULL");
8567#endif
8568
8569 SgTypeOfType* result = NULL;
8570 if (isSgFunctionParameterRefExp(base_expression) != NULL)
8571 {
8572#if DEBUG_TYPEOF_TYPE
8573 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) != NULL: calling new SgTypeOfType(base_expression,NULL) \n");
8574#endif
8575 result = new SgTypeOfType(base_expression,NULL);
8576
8577 // DQ (3/28/2015): Testing for corruption in return value.
8578 ROSE_ASSERT(result != NULL);
8579#if DEBUG_TYPEOF_TYPE
8580 printf ("In buildTypeOfType(): test 1: result = %p = %s \n",result,result->class_name().c_str());
8581#endif
8582 result->set_base_type(base_type);
8583 }
8584 else
8585 {
8586 if (base_expression != NULL)
8587 {
8588#if DEBUG_TYPEOF_TYPE
8589 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) == NULL: base_expression != NULL: calling SgTypeOfType::createType(base_expression,NULL) \n");
8590#endif
8591 result = SgTypeOfType::createType(base_expression,NULL);
8592
8593 // DQ (3/28/2015): Testing for corruption in return value.
8594 ROSE_ASSERT(result != NULL);
8595#if DEBUG_TYPEOF_TYPE
8596 printf ("In buildTypeOfType(): test 2: result = %p = %s \n",result,result->class_name().c_str());
8597#endif
8598 }
8599 else
8600 {
8601 ROSE_ASSERT(base_type != NULL);
8602
8603#if DEBUG_TYPEOF_TYPE
8604 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) == NULL: base_expression == NULL: calling SgTypeOfType::createType(base_type,NULL) \n");
8605#endif
8606 result = SgTypeOfType::createType(base_type,NULL);
8607
8608 // DQ (3/28/2015): Testing for corruption in return value.
8609 ROSE_ASSERT(result != NULL);
8610
8611#if DEBUG_TYPEOF_TYPE
8612 printf ("In buildTypeOfType(): test 3: result = %p = %s \n",result,result->class_name().c_str());
8613#endif
8614 // result->set_base_type(base_type);
8615 if (result->get_base_type() != base_type)
8616 {
8617 ROSE_ASSERT(result->get_base_type() != NULL);
8618#if DEBUG_TYPEOF_TYPE
8619 printf ("result->get_base_type() = %p = %s \n",result->get_base_type(),result->get_base_type()->class_name().c_str());
8620#endif
8621 ROSE_ASSERT(base_type != NULL);
8622#if DEBUG_TYPEOF_TYPE
8623 printf ("base_type = %p = %s \n",base_type,base_type->class_name().c_str());
8624#endif
8625 }
8626 }
8627 }
8628
8629 ROSE_ASSERT(result != NULL);
8630
8631 if (base_expression != NULL)
8632 {
8633 base_expression->set_parent(result);
8634 }
8635
8636 // DQ (3/28/2015): Testing for corruption in return value.
8637 ROSE_ASSERT(result != NULL);
8638
8639#if DEBUG_TYPEOF_TYPE
8640 printf ("In buildTypeOfType(): test 4: result = %p = %s \n",result,result->class_name().c_str());
8641#endif
8642
8643 return result;
8644 }
8645
8646
8647
8648#if 0
8649// Liao, 8/16/2010, This function is being phased out. Please don't call this!!
8651 {
8652 // DQ (7/30/2010): Note that this is called by the outline test: tests/nonsmoke/functional/roseTests/astOutliningTests/moreTest3.cpp
8653 // DQ (7/28/2010): Now we want to make calling this function an error, the functions buildConst() will return SgModifierType objects instead.
8654 printf ("Error: this function SageBuilder::buildModifierType() should not be called! (call the buildConst() function (or whatever other function is required) directly \n");
8655 ROSE_ABORT();
8656 // Liao, 8/13/2010, This function is being phased out. Please don't call this!!
8657
8658 // 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.
8659 SgModifierType* result = new SgModifierType(base_type);
8660 // SgModifierType* result = SgModifierType::createType(base_type);
8661 ROSE_ASSERT(result != NULL);
8662
8663 // DQ (7/28/2010): Insert result type into type table and return it, or
8664 // replace the result type, if already available in the type table, with
8665 // the type from type table.
8666 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
8667
8668 return result;
8669 }
8670#endif
8671
8672// CR (2/20/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8674 SgTypeBool * result = SgTypeBool::createType(kind_expr);
8675 ROSE_ASSERT(result);
8676 if (kind_expr != NULL) kind_expr->set_parent(result);
8677 return result;
8678}
8682
8684 {
8686 ROSE_ASSERT(result);
8687 return result;
8688 }
8689
8691{
8693 ROSE_ASSERT(result);
8694 return result;
8695}
8696
8697#if 0 // did not work, build##itemType would be expanded correctly
8698#define BUILD_SGTYPE_DEF(item) \
8699 SgType##item * SageBuilder::build##itemType() { \
8700 SgType##item * result =SgType##item::createType(); \
8701 ROSE_ASSERT(result); \
8702 return result; \
8703 }
8704
8705 BUILD_SGTYPE_DEF(Bool)
8706 BUILD_SGTYPE_DEF(Char)
8707 BUILD_SGTYPE_DEF(Double)
8708 BUILD_SGTYPE_DEF(Float)
8709 BUILD_SGTYPE_DEF(Int)
8710 BUILD_SGTYPE_DEF(Long)
8711 BUILD_SGTYPE_DEF(LongDouble)
8712 BUILD_SGTYPE_DEF(LongLong)
8713 BUILD_SGTYPE_DEF(Short)
8714 BUILD_SGTYPE_DEF(Void)
8715
8716 BUILD_SGTYPE_DEF(Wchar)
8717
8718// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
8719 BUILD_SGTYPE_DEF(Char16)
8720 BUILD_SGTYPE_DEF(Char32)
8721
8722 BUILD_SGTYPE_DEF(SignedChar)
8723 BUILD_SGTYPE_DEF(SignedInt)
8724 BUILD_SGTYPE_DEF(SignedLong)
8725 BUILD_SGTYPE_DEF(SignedShort)
8726 BUILD_SGTYPE_DEF(UnsignedChar)
8727 BUILD_SGTYPE_DEF(UnsignedInt)
8728 BUILD_SGTYPE_DEF(UnsignedLong)
8729 BUILD_SGTYPE_DEF(UnsignedLongLong)
8730 BUILD_SGTYPE_DEF(UnsignedShort)
8731#undef BUILD_SGTYPE_DEF
8732#endif
8734{
8736 ROSE_ASSERT(result);
8737 return result;
8738}
8739
8741{
8743 ROSE_ASSERT(result);
8744 return result;
8745}
8746
8748{
8750 ROSE_ASSERT(result);
8751 return result;
8752}
8753
8755{
8757 ROSE_ASSERT(result);
8758 return result;
8759}
8760
8761// Rasmussen (2/20/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8763{
8765 ROSE_ASSERT(result);
8766 if (kind_expr != NULL) kind_expr->set_parent(result);
8767 return result;
8768}
8773
8775{
8777 ROSE_ASSERT(result);
8778 return result;
8779}
8780
8783 ROSE_ASSERT(result);
8784 return result;
8785}
8786
8789 ROSE_ASSERT(result);
8790 return result;
8791}
8792
8794{
8796 ROSE_ASSERT(result);
8797 return result;
8798}
8799
8801{
8803 ROSE_ASSERT(result);
8804 return result;
8805}
8806
8808{
8810 ROSE_ASSERT(result);
8811 return result;
8812}
8813
8815{
8817 ROSE_ASSERT(result);
8818 return result;
8819}
8820
8821#if 1
8828
8835#endif
8836
8837
8839{
8841 ROSE_ASSERT(result);
8842 return result;
8843}
8844
8845// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
8847{
8849 ROSE_ASSERT(result);
8850 return result;
8851}
8852
8853// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
8855{
8857 ROSE_ASSERT(result);
8858 return result;
8859}
8860
8861
8863{
8865 ROSE_ASSERT(result);
8866 return result;
8867}
8868
8870{
8872 ROSE_ASSERT(result);
8873 return result;
8874}
8875
8877{
8879 ROSE_ASSERT(result);
8880 return result;
8881}
8882
8884{
8885 SgAutoType * result =new SgAutoType();
8886 ROSE_ASSERT(result);
8887 return result;
8888}
8889
8891{
8893 ROSE_ASSERT(result);
8894 return result;
8895}
8896
8898{
8900 ROSE_ASSERT(result);
8901 return result;
8902}
8903
8905{
8907 ROSE_ASSERT(result);
8908 return result;
8909}
8910
8912 {
8913 // DQ (8/17/2010): This function needs to use a different API to handle a literal
8914 // value for the string size (typical) or an expression for the string size (rare).
8915 // For now we will make it an error to call this function.
8916
8917 // SgTypeString * result =SgTypeString::createType();
8918 SgTypeString * result = NULL;
8919 ROSE_ASSERT(result != NULL);
8920 return result;
8921 }
8922
8924 {
8925 // DQ (8/21/2010): This is a new API for this function. This type is specific to Fortran use,
8926 // in C/C++ a string is just an array of char. We could have a consistant handling between
8927 // C/C++ and Fortrna, but we have just corrected the implementation in Fortran to use this IR
8928 // node and we would have to add such support to C/C++. The current implementation reflects
8929 // the grammar of the two languages.
8930
8931 // This function needs to use a different API to handle a literal
8932 // value for the string size (typical) or an expression for the string size (rare).
8933
8934 SgTypeString* result = SgTypeString::createType(stringLengthExpression);
8935 ASSERT_not_null(result);
8936 return result;
8937 }
8938
8939// Rasmussen (2/20/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8941{
8942 SgTypeInt * result;
8943 if (kind_expr != NULL)
8944 {
8945 result = SgTypeInt::createType(0, kind_expr);
8946 kind_expr->set_parent(result);
8947 }
8948 else
8949 {
8950 result = SgTypeInt::createType();
8951 }
8952 ASSERT_not_null(result);
8953 return result;
8954}
8956{
8957 return buildIntType(NULL);
8958}
8959
8961{
8963 ROSE_ASSERT(result);
8964 return result;
8965}
8966
8967// Rasmussen (3/6/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8969{
8970 SgTypeFloat * result;
8971 if (kind_expr != NULL)
8972 {
8973 result = SgTypeFloat::createType(kind_expr);
8974 kind_expr->set_parent(result);
8975 }
8976 else
8977 {
8978 result = SgTypeFloat::createType();
8979 }
8980 ASSERT_not_null(result);
8981 return result;
8982}
8984{
8986 ASSERT_not_null(result);
8987 return result;
8988}
8989
8990// Rasmussen (2/20/2020): Added builder for Jovial fixed type
8992{
8993 SgTypeFixed * result = SgTypeFixed::createType(scale, fraction);
8994 ROSE_ASSERT(result);
8995
8996 if (scale) scale->set_parent(result);
8997 if (fraction) fraction->set_parent(result);
8998
8999 return result;
9000}
9001
9002// Rasmussen (5/5/2020): Added builder for Jovial bit type
9004{
9005 SgJovialBitType * result = SgJovialBitType::createType(size, NULL);
9006
9007 if (size) size->set_parent(result);
9008
9009 return result;
9010}
9011
9012// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9015 {
9016 // DQ (9/3/2012): Added assertion.
9017 ROSE_ASSERT(base_type != NULL);
9018
9019 // DQ (7/28/2010): New (similar) approach using type table support.
9020 SgModifierType* result = new SgModifierType(base_type);
9021 ROSE_ASSERT(result != NULL);
9022
9023 // DQ (3/10/2018): Adding assertion.
9024 ROSE_ASSERT(result != base_type);
9025
9026 // DQ (7/28/2010): Insert result type into type table and return it, or
9027 // replace the result type, if already available in the type table, with
9028 // the type from type table.
9029 SgModifierType* result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9030
9031 if (result != result2)
9032 {
9033 // DQ (10/27/2015): This is the cause of a bug in the test2015_97.C (boost template problem).
9034 printf ("WARNING: In SageBuilder::buildModifierType(): using previously build SgModifierType from global type table: result2 = %p = %s \n",result2,result2->class_name().c_str());
9035 delete result;
9036 }
9037
9038 // DQ (3/10/2018): Adding assertion.
9039 ROSE_ASSERT(result2 != base_type);
9040
9041 return result2;
9042 }
9043
9046 {
9047 // DQ (9/3/2012): Added assertion.
9048 ROSE_ASSERT(base_type != NULL);
9049
9050 // DQ (7/28/2010): New (similar) approach using type table support.
9051 SgModifierType *result = new SgModifierType(base_type);
9052 ROSE_ASSERT(result!=NULL);
9053 result->get_typeModifier().get_constVolatileModifier().setConst();
9054
9055 // DQ (7/28/2010): Insert result type into type table and return it, or
9056 // replace the result type, if already available in the type table, with
9057 // the type from type table.
9058 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9059
9060 if (result != result2)
9061 {
9062 delete result;
9063 }
9064
9065 // DQ (3/10/2018): Adding assertion.
9066 ROSE_ASSERT(result2 != base_type);
9067
9068 return result2;
9069 }
9070
9071// DQ (8/27/2010): Added Fortran specific support for types based on kind expressions.
9074 {
9075 // DQ (9/3/2012): Added assertion.
9076 ROSE_ASSERT(base_type != NULL);
9077
9078 SgModifierType *result = new SgModifierType(base_type);
9079 ROSE_ASSERT(result != NULL);
9080
9081 result->set_type_kind(kindExpression);
9082
9083#if 0
9084 printf ("In SageBuilder::buildFortranKindType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9085#endif
9086
9087 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9088
9089 if (result != result2)
9090 {
9091#if 0
9092 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9093 printf ("(debugging) In SageBuilder::buildFortranKindType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9094#else
9095 delete result;
9096#endif
9097 }
9098
9099 return result2;
9100 }
9101
9102// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9105 {
9106 // DQ (9/3/2012): Added assertion.
9107 ROSE_ASSERT(base_type != NULL);
9108
9109 SgModifierType *result = new SgModifierType(base_type);
9110 ROSE_ASSERT(result!=NULL);
9111
9112 result->get_typeModifier().get_constVolatileModifier().setVolatile();
9113
9114#if 0
9115 printf ("In SageBuilder::buildVolatileType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9116#endif
9117
9118 // DQ (7/29/2010): Insert result type into type table and return it, or
9119 // replace the result type, if already available in the type table, with
9120 // the type from type table.
9121 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9122 if (result != result2)
9123 {
9124#if 0
9125 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9126 printf ("(debugging) In SageBuilder::buildVolatileType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9127#else
9128 delete result;
9129#endif
9130 }
9131
9132 return result2;
9133 }
9134
9135// DQ (1/19/2019): Adding support for const volatile type (both together as another value).
9138 {
9139 // DQ (9/3/2012): Added assertion.
9140 ROSE_ASSERT(base_type != NULL);
9141
9142 SgModifierType *result = new SgModifierType(base_type);
9143 ROSE_ASSERT(result!=NULL);
9144
9145 result->get_typeModifier().get_constVolatileModifier().setConst();
9146 result->get_typeModifier().get_constVolatileModifier().setVolatile();
9147
9148#if 1
9149 printf ("In SageBuilder::buildConstVolatileType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9150#endif
9151
9152 // DQ (7/29/2010): Insert result type into type table and return it, or
9153 // replace the result type, if already available in the type table, with
9154 // the type from type table.
9155 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9156 if (result != result2)
9157 {
9158#if 0
9159 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9160 printf ("(debugging) In SageBuilder::buildConstVolatileType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9161#else
9162 delete result;
9163#endif
9164 }
9165
9166 return result2;
9167 }
9168
9169string
9170generate_type_list (SgType* type)
9171 {
9172 // This function generates a list of types for each level of the type structure.
9173 string returnString;
9174
9175 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);
9176
9177 SgType* currentType = type;
9178
9179 SgModifierType* modType = NULL;
9180 SgPointerType* pointType = NULL;
9181 SgReferenceType* refType = NULL;
9182 SgRvalueReferenceType* rRefType = NULL;
9183 SgArrayType* arrayType = NULL;
9184 SgTypedefType* typedefType = NULL;
9185
9186 while (currentType != NULL)
9187 {
9188 returnString += currentType->class_name();
9189#if 0
9190 printf ("In generate_type_list(): returnString = %s \n",returnString.c_str());
9191#endif
9192 if ( (bit_array & SgType::STRIP_MODIFIER_TYPE) && (modType = isSgModifierType(currentType)) )
9193 {
9194 currentType = modType->get_base_type();
9195 }
9196 else if ( (bit_array & SgType::STRIP_REFERENCE_TYPE) && (refType = isSgReferenceType(currentType)) )
9197 {
9198 currentType = refType->get_base_type();
9199 }
9200 else if ( (bit_array & SgType::STRIP_RVALUE_REFERENCE_TYPE) && (rRefType = isSgRvalueReferenceType(currentType)) )
9201 {
9202 currentType = rRefType->get_base_type();
9203 }
9204 else if ( (bit_array & SgType::STRIP_POINTER_TYPE) && (pointType = isSgPointerType(currentType)) )
9205 {
9206 currentType = pointType->get_base_type();
9207 }
9208 else if ( (bit_array & SgType::STRIP_ARRAY_TYPE) && (arrayType = isSgArrayType(currentType)) )
9209 {
9210 currentType = arrayType->get_base_type();
9211 }
9212 else if ( (bit_array & SgType::STRIP_TYPEDEF_TYPE) && (typedefType = isSgTypedefType(currentType)) )
9213 {
9214 currentType = typedefType->get_base_type();
9215 }
9216 else
9217 {
9218 break;
9219 }
9220
9221 if (type != NULL)
9222 returnString += " , ";
9223 }
9224
9225 return returnString;
9226 }
9227
9228// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9231 {
9232 ROSE_ASSERT(base_type != NULL);
9233
9234 // DQ (1/30/2014): We need to include typedefs here as well (see test2014_77.c).
9235 // DQ (9/28/2012): Added that the base type could be an array (see test2012_03.c (C test code)).
9236 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type))
9237 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type))
9238 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type) && !isSgTypedefType(base_type))
9239 if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type) && !isSgTypedefType(base_type) && !isSgModifierType(base_type))
9240 {
9241 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());
9242 printf (" --- generate_type_list() = %s \n",generate_type_list(base_type).c_str());
9243 ROSE_ABORT();
9244 }
9245
9246 SgModifierType *result = new SgModifierType(base_type);
9247 ROSE_ASSERT(result!=NULL);
9248
9249 result->get_typeModifier().setRestrict();
9250
9251#if 0
9252 printf ("In SageBuilder::buildRestrictType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9253#endif
9254
9255 // DQ (7/29/2010): Insert result type into type table and return it, or
9256 // replace the result type, if already available in the type table, with
9257 // the type from type table.
9258 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9259 if (result != result2)
9260 {
9261#if 0
9262 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9263 printf ("(debugging) In SageBuilder::buildRestrictType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9264#else
9265 delete result;
9266#endif
9267 }
9268
9269 return result2;
9270 }
9271
9272
9273namespace
9274{
9275 // PP (2/16/24): model builder function after buildRestrictType
9277 _buildModifierType(SgType* base_type, std::function<void(SgModifierType*)> setModifiers)
9278 {
9279 ASSERT_not_null(base_type);
9280
9281 SgModifierType* result = new SgModifierType(base_type);
9282
9283 setModifiers(result);
9284
9285 SgModifierType* result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9286 if (result != result2) delete result;
9287
9288 return result2;
9289 }
9290}
9291
9292
9294 {
9295 auto op = [](SgModifierType* ty) { ty->get_typeModifier().setAliased(); };
9296
9297 return _buildModifierType(base_type, op);
9298 }
9299
9301 {
9302 auto op = [](SgModifierType* ty) { ty->get_typeModifier().setNotNull(); };
9303
9304 return _buildModifierType(base_type, op);
9305 }
9306
9307
9308// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9311 {
9312 // DQ (9/3/2012): Added assertion.
9313 ROSE_ASSERT(base_type != NULL);
9314
9315 SgModifierType *result = new SgModifierType(base_type);
9316 ROSE_ASSERT(result!=NULL);
9317
9318 result->get_typeModifier().get_upcModifier().set_modifier(SgUPC_AccessModifier::e_upc_strict);
9319
9320#if 0
9321 printf ("In SageBuilder::buildUpcStrictType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9322#endif
9323
9324 // DQ (7/29/2010): Insert result type into type table and return it, or
9325 // replace the result type, if already available in the type table, with
9326 // the type from type table.
9327 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9328 if (result != result2)
9329 {
9330#if 0
9331 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9332 printf ("(debugging) In SageBuilder::buildUpcStrictType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9333#else
9334 delete result;
9335#endif
9336 }
9337
9338 return result2;
9339 }
9340
9341// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9344 {
9345 // DQ (9/3/2012): Added assertion.
9346 ROSE_ASSERT(base_type != NULL);
9347
9348 SgModifierType *result = new SgModifierType(base_type);
9349 ROSE_ASSERT(result!=NULL);
9350
9351 result->get_typeModifier().get_upcModifier().set_modifier(SgUPC_AccessModifier::e_upc_relaxed);
9352
9353#if 0
9354 printf ("In SageBuilder::buildUpcRelaxedType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9355#endif
9356
9357 // DQ (7/29/2010): Insert result type into type table and return it, or
9358 // replace the result type, if already available in the type table, with
9359 // the type from type table.
9360 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9361 if (result != result2)
9362 {
9363#if 0
9364 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9365 printf ("(debugging) In SageBuilder::buildUpcRelaxedType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9366#else
9367 delete result;
9368#endif
9369 }
9370
9371 return result2;
9372 }
9373
9374// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9376SgModifierType* SageBuilder::buildUpcSharedType(SgType* base_type /*=NULL*/, long layout /*= -1*/)
9377 {
9378 // DQ (9/3/2012): Added assertion.
9379 ROSE_ASSERT(base_type != NULL);
9380
9381 SgModifierType *result = new SgModifierType(base_type);
9382 ROSE_ASSERT(result!=NULL);
9383
9384 result->get_typeModifier().get_upcModifier().set_isShared(true);
9385
9386 // DQ (7/29/2010): Modified to use new input parameter.
9387 // result->get_typeModifier().get_upcModifier().set_layout(-1); // No layout ("shared" without a block size)
9388 result->get_typeModifier().get_upcModifier().set_layout(layout); // No layout ("shared" without a block size)
9389
9390#if 0
9391 printf ("In SageBuilder::buildUpcSharedType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9392#endif
9393
9394 // DQ (7/29/2010): Insert result type into type table and return it, or
9395 // replace the result type, if already available in the type table, with
9396 // the type from type table.
9397 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9398 if (result != result2)
9399 {
9400#if 0
9401 // DQ (9/3/2012): While debugging let's skip calling delete so that the slot in the memory pool will not be reused.
9402 printf ("(debugging) In SageBuilder::buildUpcSharedType(): Skipping delete of SgModifierType = %p = %s \n",result,result->class_name().c_str());
9403#else
9404 delete result;
9405#endif
9406 }
9407
9408 return result2;
9409 }
9410
9411// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9414 {
9415 // DQ (9/3/2012): Added assertion.
9416 ROSE_ASSERT(base_type != NULL);
9417
9418 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9419 ROSE_ASSERT(result!=NULL);
9420
9421 result->get_typeModifier().get_upcModifier().set_layout(0); // [] layout
9422
9423#if 0
9424 printf ("In SageBuilder::buildUpcBlockIndefiniteType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9425#endif
9426
9427 // DQ (7/29/2010): Insert result type into type table and return it, or
9428 // replace the result type, if already available in the type table, with
9429 // the type from type table.
9430 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9431
9432 return result;
9433 }
9434
9435// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9438 {
9439 // DQ (9/3/2012): Added assertion.
9440 ROSE_ASSERT(base_type != NULL);
9441
9442 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9443 ROSE_ASSERT(result!=NULL);
9444
9445 result->get_typeModifier().get_upcModifier().set_layout(-2); // [*] layout
9446
9447#if 0
9448 printf ("In SageBuilder::buildUpcBlockStarType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9449#endif
9450
9451 // DQ (7/29/2010): Insert result type into type table and return it, or
9452 // replace the result type, if already available in the type table, with
9453 // the type from type table.
9454 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9455
9456 return result;
9457 }
9458
9459// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9462 {
9463 // DQ (9/3/2012): Added assertion.
9464 ROSE_ASSERT(base_type != NULL);
9465
9466 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9467 ROSE_ASSERT(result!=NULL);
9468
9469 result->get_typeModifier().get_upcModifier().set_layout(block_factor); // [block_factor] layout
9470
9471#if 0
9472 printf ("In SageBuilder::buildUpcBlockNumberType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
9473#endif
9474
9475 // DQ (7/29/2010): Insert result type into type table and return it, or
9476 // replace the result type, if already available in the type table, with
9477 // the type from type table.
9478 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9479
9480 return result;
9481 }
9482
9483
9484
9487 {
9488 // DQ (9/3/2012): Added assertion.
9489 ROSE_ASSERT(base_type != NULL);
9490
9491 SgTypeComplex *result = new SgTypeComplex(base_type);
9492 ROSE_ASSERT(result!=NULL);
9493 return result;
9494 }
9495
9498 {
9499 // DQ (9/3/2012): Added assertion.
9500 ROSE_ASSERT(base_type != NULL);
9501
9502 SgTypeImaginary *result = new SgTypeImaginary(base_type);
9503 ROSE_ASSERT(result!=NULL);
9504 return result;
9505 }
9506
9509{
9510 SgTypeMatrix *result = new SgTypeMatrix();
9511 ROSE_ASSERT(result != NULL);
9512 return result;
9513}
9514
9517{
9518 SgTypeTuple *result = new SgTypeTuple();
9519 ROSE_ASSERT(result != NULL);
9520
9521 if(t1) result->append_type(t1);
9522 if(t2) result->append_type(t2);
9523 if(t3) result->append_type(t3);
9524 if(t4) result->append_type(t4);
9525 if(t5) result->append_type(t5);
9526 if(t6) result->append_type(t6);
9527 if(t7) result->append_type(t7);
9528 if(t8) result->append_type(t8);
9529 if(t9) result->append_type(t9);
9530 if(t10) result->append_type(t10);
9531
9533
9534 return result;
9535}
9536
9539 SgNonrealDecl * nrdecl = buildNonrealDecl(name, scope);
9540 nrdecl->set_parent(scope);
9541 nrdecl->set_is_template_param (true);
9542 return nrdecl->get_type();
9543}
9544
9546{
9547 SgRangeExp *result = new SgRangeExp();
9549 ROSE_ASSERT(result != NULL);
9550
9551 result->append(start);
9552 return result;
9553}
9554
9556{
9557 SgRangeExp *result = new SgRangeExp();
9559 ROSE_ASSERT(result != NULL);
9560
9561 result->set_start(start);
9562 start->set_parent(result);
9563
9564 result->set_end(end);
9565 end->set_parent(result);
9566
9567 result->set_stride(stride);
9568 stride->set_parent(result);
9569 return result;
9570}
9571
9572
9574{
9575 SgMatrixExp *result = new SgMatrixExp();
9577
9578 result->append_expression(firstRow);
9579 ROSE_ASSERT(result != NULL);
9580
9581 return result;
9582}
9583
9585{
9586 SgMagicColonExp *result = new SgMagicColonExp();
9588
9589 ROSE_ASSERT(result != NULL);
9590
9591 return result;
9592}
9593
9596{
9597 SgConstVolatileModifier * result = NULL;
9598 result = new SgConstVolatileModifier();
9599 ROSE_ASSERT (result != NULL);
9600 result->set_modifier (mtype);
9601
9602 return result;
9603}
9604
9608 {
9609 // SgFunctionDeclaration* func_decl = buildDefiningFunctionDeclaration("__rose__lambda__",return_type,params,scope,NULL,NULL);
9610 SgFunctionDeclaration* func_decl = buildDefiningFunctionDeclaration("__rose__lambda__",return_type,params,scope,NULL,false,NULL,NULL);
9611
9612 SgLambdaRefExp* result = new SgLambdaRefExp(func_decl);
9613 func_decl->set_parent(result);
9614
9616
9617 return result;
9618 }
9619
9622 {
9623 SgTypeExpression *expr = new SgTypeExpression(type);
9625 return expr;
9626 }
9627
9628// DQ (8/11/2014): Added support for C++11 decltype used in new function return syntax.
9630SageBuilder::buildFunctionParameterRefExp(int parameter_number, int parameter_level )
9631 {
9632 SgFunctionParameterRefExp *expr = new SgFunctionParameterRefExp(NULL,parameter_number,parameter_level);
9633 ROSE_ASSERT(expr != NULL);
9634
9635 setSourcePosition(expr);
9636 return expr;
9637 }
9638
9639
9640// DQ (8/11/2014): Added support for C++11 decltype used in new function return syntax.
9642SageBuilder::buildFunctionParameterRefExp_nfi(int parameter_number, int parameter_level )
9643 {
9644 SgFunctionParameterRefExp *expr = new SgFunctionParameterRefExp(NULL,parameter_number,parameter_level);
9645 ROSE_ASSERT(expr != NULL);
9646
9648 return expr;
9649 }
9650
9651// DQ (9/3/2014): Adding support for C++11 Lambda expressions
9653SageBuilder::buildLambdaExp(SgLambdaCaptureList* lambda_capture_list, SgClassDeclaration* lambda_closure_class, SgFunctionDeclaration* lambda_function)
9654 {
9655 SgLambdaExp *expr = new SgLambdaExp(lambda_capture_list,lambda_closure_class,lambda_function);
9656 ROSE_ASSERT(expr != NULL);
9657
9658 // Set the parents
9659 if (lambda_capture_list != NULL)
9660 {
9661 lambda_capture_list->set_parent(expr);
9662 }
9663
9664 if (lambda_closure_class != NULL)
9665 {
9666 lambda_closure_class->set_parent(expr);
9667 }
9668
9669 if (lambda_function != NULL)
9670 {
9671#if 1
9672 lambda_function->set_parent(expr);
9673#else
9674 if (lambda_closure_class != NULL)
9675 {
9676 lambda_function->set_parent(lambda_closure_class);
9677 }
9678 else
9679 {
9680 printf ("Warning: In SageBuilder::buildLambdaExp(): lambda_closure_class == NULL: lambda_function parent not set! \n");
9681 }
9682#endif
9683 }
9684
9685 setSourcePosition(expr);
9686 return expr;
9687 }
9688
9690SageBuilder::buildLambdaExp_nfi(SgLambdaCaptureList* lambda_capture_list, SgClassDeclaration* lambda_closure_class, SgFunctionDeclaration* lambda_function)
9691 {
9692 SgLambdaExp *expr = new SgLambdaExp(lambda_capture_list,lambda_closure_class,lambda_function);
9693 ROSE_ASSERT(expr != NULL);
9694
9695 // Set the parents
9696 if (lambda_capture_list != NULL)
9697 {
9698 lambda_capture_list->set_parent(expr);
9699 }
9700
9701 if (lambda_closure_class != NULL)
9702 {
9703 lambda_closure_class->set_parent(expr);
9704 }
9705
9706 if (lambda_function != NULL)
9707 {
9708#if 1
9709 lambda_function->set_parent(expr);
9710#else
9711 if (lambda_closure_class != NULL)
9712 {
9713 lambda_function->set_parent(lambda_closure_class);
9714 }
9715 else
9716 {
9717 printf ("Warning: In SageBuilder::buildLambdaExp(): lambda_closure_class == NULL: lambda_function parent not set! \n");
9718 }
9719#endif
9720 }
9721
9723 return expr;
9724 }
9725
9726#if 0
9728SageBuilder::buildLambdaCapture(SgInitializedName* capture_variable, SgInitializedName* source_closure_variable, SgInitializedName* closure_variable)
9729 {
9730 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9731 ROSE_ASSERT(lambdaCapture != NULL);
9732
9733 setSourcePosition(lambdaCapture);
9734 return lambdaCapture;
9735 }
9736
9738SageBuilder::buildLambdaCapture_nfi(SgInitializedName* capture_variable, SgInitializedName* source_closure_variable, SgInitializedName* closure_variable)
9739 {
9740 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9741 ROSE_ASSERT(lambdaCapture != NULL);
9742
9743 setOneSourcePositionNull(lambdaCapture);
9744 return lambdaCapture;
9745 }
9746#else
9748SageBuilder::buildLambdaCapture(SgExpression* capture_variable, SgExpression* source_closure_variable, SgExpression* closure_variable)
9749 {
9750 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9751 ROSE_ASSERT(lambdaCapture != NULL);
9752
9753 setSourcePosition(lambdaCapture);
9754 return lambdaCapture;
9755 }
9756
9758SageBuilder::buildLambdaCapture_nfi(SgExpression* capture_variable, SgExpression* source_closure_variable, SgExpression* closure_variable)
9759 {
9760 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9761 ROSE_ASSERT(lambdaCapture != NULL);
9762
9763 setOneSourcePositionNull(lambdaCapture);
9764 return lambdaCapture;
9765 }
9766#endif
9767
9770 {
9771 SgLambdaCaptureList *lambdaCaptureList = new SgLambdaCaptureList(NULL);
9772 ROSE_ASSERT(lambdaCaptureList != NULL);
9773
9774 setSourcePosition(lambdaCaptureList);
9775 return lambdaCaptureList;
9776 }
9777
9780 {
9781 SgLambdaCaptureList *lambdaCaptureList = new SgLambdaCaptureList(NULL);
9782 ROSE_ASSERT(lambdaCaptureList != NULL);
9783
9784 setOneSourcePositionNull(lambdaCaptureList);
9785 return lambdaCaptureList;
9786 }
9787
9788// DQ (7/25/2020): Adding C++17 support
9790SageBuilder::buildFoldExpression(SgExpression* operands, string operator_token_string, bool is_left_associative)
9791 {
9792 SgFoldExpression* result = new SgFoldExpression(NULL,operands,operator_token_string,is_left_associative);
9793 ROSE_ASSERT(result != NULL);
9794
9796 return result;
9797 }
9798
9800SageBuilder::buildFoldExpression_nfi(SgExpression* operands, string operator_token_string, bool is_left_associative)
9801 {
9802 SgFoldExpression* result = new SgFoldExpression(NULL,operands,operator_token_string,is_left_associative);
9803 ROSE_ASSERT(result != NULL);
9804
9806 return result;
9807 }
9808
9809// DQ (7/25/2020): Adding C++20 support
9812 {
9813 SgAwaitExpression* result = new SgAwaitExpression(NULL,NULL);
9814 ROSE_ASSERT(result != NULL);
9815
9817 return result;
9818 }
9821 {
9822 SgAwaitExpression* result = new SgAwaitExpression(NULL,NULL);
9823 ROSE_ASSERT(result != NULL);
9824
9826 return result;
9827 }
9828
9829// DQ (7/25/2020): Adding C++20 support
9832 {
9833 SgChooseExpression* result = new SgChooseExpression(NULL,NULL);
9834 ROSE_ASSERT(result != NULL);
9835
9837 return result;
9838 }
9839
9842 {
9843 SgChooseExpression* result = new SgChooseExpression(NULL,NULL);
9844 ROSE_ASSERT(result != NULL);
9845
9847 return result;
9848 }
9849
9850
9851
9854 {
9855 SgNamespaceDefinitionStatement* result = NULL;
9856 if (d!=NULL) // the constructor does not check for NULL d, causing segmentation fault
9857 {
9858 result = new SgNamespaceDefinitionStatement(d);
9859 result->set_parent(d); // set_declaration() == set_parent() in this case
9860 }
9861 else
9862 {
9863 result = new SgNamespaceDefinitionStatement(d);
9864 }
9865
9866 ROSE_ASSERT(result);
9867
9869 return result;
9870 }
9871
9874{
9875 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
9876 SageInterface::setSourcePosition(nonreal_decl_scope);
9877 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
9878 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
9879 return nonreal_decl_scope;
9880}
9881
9883SageBuilder::buildClassDefinition(SgClassDeclaration *d/*= NULL*/, bool buildTemplateInstantiation )
9884 {
9885 SgClassDefinition* result = NULL;
9886 if (d != NULL) // the constructor does not check for NULL d, causing segmentation fault
9887 {
9888 // result->set_parent(d); // set_declaration() == set_parent() in this case
9889 // result = new SgClassDefinition(d);
9890 ROSE_ASSERT(buildTemplateInstantiation == false || isSgTemplateInstantiationDecl(d) != NULL);
9891 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn(isSgTemplateInstantiationDecl(d)) : new SgClassDefinition(d);
9892 }
9893 else
9894 {
9895 // result = new SgClassDefinition();
9896 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn() : new SgClassDefinition();
9897 }
9898
9899 ROSE_ASSERT(result);
9900
9901 // CR (3/22/2020): Fixed setting case insensitivity
9902 // if (symbol_table_case_insensitive_semantics == true)
9904 {
9905 result->setCaseInsensitive(true);
9906 }
9907
9909
9910 return result;
9911 }
9912
9913
9914
9916SageBuilder::buildClassDefinition_nfi(SgClassDeclaration *d/*= NULL*/, bool buildTemplateInstantiation )
9917 {
9918 SgClassDefinition* result = NULL;
9919 if (d!=NULL) // the constructor does not check for NULL d, causing segmentation fault
9920 {
9921 // result->set_parent(d); // set_declaration() == set_parent() in this case
9922 // result = new SgClassDefinition(d);
9923 ROSE_ASSERT(buildTemplateInstantiation == false || isSgTemplateInstantiationDecl(d) != NULL);
9924 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn(isSgTemplateInstantiationDecl(d)) : new SgClassDefinition(d);
9925 }
9926 else
9927 {
9928 // result = new SgClassDefinition();
9929 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn() : new SgClassDefinition();
9930 }
9931
9932 ROSE_ASSERT(result);
9933
9934 // CR (3/22/2020): Fixed setting case insensitivity
9935 // if (symbol_table_case_insensitive_semantics == true)
9937 result->setCaseInsensitive(true);
9938
9940 return result;
9941 }
9942
9943
9945SageBuilder::buildNondefiningClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList)
9946 {
9947 SgName nameWithoutTemplateArguments = XXX_name;
9948
9949 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
9950
9951 // SgClassDeclaration* nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
9952 SgClassDeclaration* nondefdecl = NULL;
9953
9954#define DEBUG_NONDEFINING_CLASS_DECLARATION 0
9955
9956 // DQ (11/26/2011): Debugging EDG 3.3 use of templateArguments.
9957#if DEBUG_NONDEFINING_CLASS_DECLARATION
9958 printf ("Building a SgClassDeclaration: buildNondefiningClassDeclaration_nfi() nameWithoutTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithoutTemplateArguments.str(),buildTemplateInstantiation ? "true:" : "false");
9959 printf (" --- scope = %p = %s \n",scope,(scope != NULL) ? scope->class_name().c_str() : "null");
9960#endif
9961
9962 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
9963 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
9964 ROSE_ASSERT(SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == false);
9965
9966 if (buildTemplateInstantiation == true)
9967 {
9968 ROSE_ASSERT(templateArgumentsList != NULL);
9969 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
9970
9971#if DEBUG_NONDEFINING_CLASS_DECLARATION
9972 printf ("Building a SgClassDeclaration: buildNondefiningClassDeclaration_nfi() nameWithTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithTemplateArguments.str(),buildTemplateInstantiation ? "true:" : "false");
9973#endif
9974
9975 // SgTemplateInstantiationDecl (SgName name, SgClassDeclaration::class_types class_type, SgClassType *type, SgClassDefinition *definition, SgTemplateDeclaration *templateDeclaration, SgTemplateArgumentPtrList templateArguments)
9976 SgTemplateArgumentPtrList emptyList;
9977 // nondefdecl = new SgTemplateInstantiationDecl(name,kind,NULL,NULL,NULL,emptyList);
9978 nondefdecl = new SgTemplateInstantiationDecl(nameWithTemplateArguments,kind,NULL,NULL,NULL,emptyList);
9979#if DEBUG_NONDEFINING_CLASS_DECLARATION
9980 printf ("In buildNondefiningClassDeclaration_nfi(): built new SgTemplateInstantiationDecl: nondefdecl = %p \n",nondefdecl);
9981#endif
9982 ROSE_ASSERT(nondefdecl->get_type() == NULL);
9983 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl) != NULL);
9984#if DEBUG_NONDEFINING_CLASS_DECLARATION
9985 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_name() = %s nondefdecl->get_templateName() = %s \n",
9986 nondefdecl->get_name().str(),isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().str());
9987#endif
9988 // DQ (6/6/2012): Added support for template arguments so that they can be a part of any generated type.
9989 ROSE_ASSERT(templateArgumentsList != NULL);
9990
9991#if DEBUG_NONDEFINING_CLASS_DECLARATION
9992 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
9993 printf ("nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
9994 printf ("Output templateArgumentsList: \n");
9995 for (size_t i = 0; i < templateArgumentsList->size(); i++)
9996 {
9997 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
9998 printf (" --- --- name = %s \n",unparseTemplateArgumentToString(templateArgumentsList->operator[](i)).str());
9999 }
10000#endif
10001
10002 // DQ (3/9/2018): Added assertion.
10003 ROSE_ASSERT(nondefdecl->get_name() == nameWithTemplateArguments);
10004
10005 // DQ (5/8/2013): This fails for explicit template instantation examples (e.g. template <> class RepeatedPtrField<string>::TypeHandler {};, in test2013_159.C)
10006 // ROSE_ASSERT(templateArgumentsList->size() > 0);
10007#if 0
10008 // DQ (9/16/2012): Call the newly refactored function after the firstNondefiningDeclaration is set.
10009
10010 // Calling the assignment operator for the STL container class.
10011 isSgTemplateInstantiationDecl(nondefdecl)->get_templateArguments() = *templateArgumentsList;
10012
10013#error "DEAD CODE!"
10014
10015#if 1
10016 // DQ (9/13/2012): Refactored this code.
10017 setTemplateArgumentParents(nondefdecl);
10018#else
10019 // DQ (7/25/2012): Added this code here to reset the parents of the template arguments.
10020 for (size_t i = 0; i < templateArgumentsList->size(); i++)
10021 {
10022 // DQ (7/25/2012): This should be true because the template argument was set to the functions
10023 // scope so that the name with template arguments could be computed (with name qualification).
10024 ROSE_ASSERT((*templateArgumentsList)[i]->get_parent() != NULL);
10025
10026#error "DEAD CODE!"
10027
10028 // ROSE_ASSERT(isSgGlobal(templateArgumentsList[i]->get_parent()) == NULL);
10029 // ROSE_ASSERT(templateArgumentsList[i]->get_parent() == nondefining_templateInstantiation);
10030
10031 // Be we want to reset it to be the function (now that it is available, because this is more precise).
10032 // All qualified names should compute to the same qualified name (if not then it is a bug in the name
10033 // qualification mechanism).
10034 (*templateArgumentsList)[i]->set_parent(nondefdecl);
10035 }
10036#endif
10037#endif
10038 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == true);
10039 isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(nameWithoutTemplateArguments);
10040 }
10041 else
10042 {
10043 // nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
10044 nondefdecl = new SgClassDeclaration(nameWithoutTemplateArguments,kind,NULL,NULL);
10045#if DEBUG_NONDEFINING_CLASS_DECLARATION
10046 printf ("In buildNondefiningClassDeclaration_nfi(): built new SgClassDeclaration: nondefdecl = %p \n",nondefdecl);
10047#endif
10048 // The default name for nameWithTemplateArguments is nameWithoutTemplateArguments so that we can use
10049 // nameWithTemplateArguments uniformally as the name of the function and it will work from non-template
10050 // instantiations.
10051 ROSE_ASSERT(nameWithoutTemplateArguments == nameWithTemplateArguments);
10052 }
10053
10054 ROSE_ASSERT(nondefdecl != NULL);
10055
10056 // DQ (6/9/2013): Added assertion to debug test2013_198.C.
10057 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10058
10059 // DQ (3/22/2012): I think we can assert this! No, in fact we can assert that it is not built yet.
10060 // ROSE_ASSERT(nondefdecl->get_type() != NULL);
10061 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10062
10063#if 0
10064 // DQ (3/22/2012): I think this may be too early.
10065 // Liao, we ask for explicit creation of SgClassType to avoid duplicated type nodes
10066 if (nondefdecl->get_type() == NULL)
10067 {
10068 nondefdecl->set_type(SgClassType::createType(nondefdecl));
10069 }
10070#endif
10071
10072#if 0
10073 printf ("SageBuilder::buildNondefiningClassDeclaration_nfi(): (and setting source position) nondefdecl = %p \n",nondefdecl);
10074#endif
10075
10076 // The non-defining declaration asociated with a declaration does not have a
10077 // source position...unless it is the position of the defining declaration.
10078 // setOneSourcePositionNull(nondefdecl);
10079 setSourcePosition(nondefdecl);
10080
10081 // This is find for now, but a little later in this function (if we can find a symbol)
10082 // we want to find the first non-defining declaration (using the symbol table) and use
10083 // that as a paramter to "nondefdecl->set_firstNondefiningDeclaration()".
10084 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10085 nondefdecl->set_definingDeclaration(NULL);
10086 nondefdecl->setForward();
10087
10088 // This is the structural parent (the logical scope can be different than the parent).
10089 // TPS (09/18/2009) added a condition to be able to build this properly
10090 if (scope == NULL)
10091 nondefdecl->set_parent(topScopeStack());
10092 else
10093 nondefdecl->set_parent(scope);
10094
10095 // This is the logical scope...
10096 nondefdecl->set_scope(scope);
10097
10098 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10099
10100 SgClassDeclaration* firstNondefdecl = NULL;
10101 if (scope != NULL)
10102 {
10103#if 0
10104 SgClassSymbol* mysymbol = new SgClassSymbol(nondefdecl);
10105 ROSE_ASSERT(mysymbol != NULL);
10106
10107 // printf ("In SageBuilder::buildNondefiningClassDeclaration(): for nondefdecl = %p built SgClassSymbol = %p \n",nondefdecl,mysymbol);
10108
10109#error "DEAD CODE"
10110
10111 scope->insert_symbol(name, mysymbol);
10112#else
10113 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would
10114 // not include name qualification on template arguments.
10115 // Reuse any previously defined symbols (to avoid redundant symbols in the symbol table)
10116 // and find the firstNondefiningDeclaration.
10117 // SgClassSymbol* mysymbol = scope->lookup_class_symbol(name);
10118 // SgClassSymbol* mysymbol = scope->lookup_nontemplate_class_symbol(name);
10119 // SgClassSymbol* mysymbol = scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments);
10120 SgClassSymbol* mysymbol = scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
10121
10122#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10123 printf ("In SageBuilder::buildNondefiningClassDeclaration(): mysymbol = %p = %s \n",mysymbol,(mysymbol != NULL) ? mysymbol->class_name().c_str() : "null");
10124#endif
10125 if (mysymbol != NULL)
10126 {
10127 firstNondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
10128 ROSE_ASSERT(firstNondefdecl != NULL);
10129
10130 // DQ (9/4/2012): Added assertion.
10131 ROSE_ASSERT(firstNondefdecl->get_type() != NULL);
10132
10133 // 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).
10134 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10135
10136 if (nondefdecl->get_type() == NULL)
10137 {
10138#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10139 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);
10140#endif
10141 // Note: It would be better to just call: "nondefdecl->set_type(firstNondefdecl->get_type());"
10142#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10143 printf ("NOTE: Call nondefdecl->set_type(firstNondefdecl->get_type()); instead of nondefdecl->set_type(SgClassType::createType(firstNondefdecl)); \n");
10144#endif
10145 // DQ (3/22/2012): Be careful to use the same declaration as from the symbol.
10146 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
10147 nondefdecl->set_type(SgClassType::createType(firstNondefdecl));
10148 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10149#if 0
10150 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());
10151#endif
10152
10153#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10154 printf ("In SageBuilder::buildNondefiningClassDeclaration(): nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
10155#endif
10156 // DQ (9/4/2012): Added assertion.
10157 ROSE_ASSERT(nondefdecl->get_type() == firstNondefdecl->get_type());
10158 }
10159
10160#if (REUSE_CLASS_DECLARATION_FROM_SYMBOL == 0)
10161 ROSE_ASSERT(nondefdecl != NULL);
10162 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10163
10164 // DQ (5/18/2014): Added test to match that in set_firstNondefiningDeclaration().
10165 // This is a problem for the Boost code after the fix to detec templates vs. template instantiation declarations.
10166 if (nondefdecl->variantT() != firstNondefdecl->variantT())
10167 {
10168 printf ("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): nondefdecl = %p = %s IS NOT THE SAME AS firstNondefiningDeclaration = %p = %s \n",
10169 nondefdecl,nondefdecl->class_name().c_str(),firstNondefdecl,firstNondefdecl->class_name().c_str());
10170 ROSE_ASSERT(nondefdecl->get_file_info() != NULL);
10171 nondefdecl->get_file_info()->display("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): nondefdecl: debug");
10172 ROSE_ASSERT(firstNondefdecl->get_file_info() != NULL);
10173 firstNondefdecl->get_file_info()->display("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): firstNondefdecl: debug");
10174 }
10175
10176 // DQ (5/18/2014): Added test to match that in set_firstNondefiningDeclaration().
10177 ROSE_ASSERT(nondefdecl->variantT() == firstNondefdecl->variantT());
10178
10179 nondefdecl->set_firstNondefiningDeclaration(firstNondefdecl);
10180
10181 // This might be NULL if the defining declaration has not been seen yet!
10182 nondefdecl->set_definingDeclaration(firstNondefdecl->get_definingDeclaration());
10183
10184 // DQ (3/22/2012): New assertions.
10185 ROSE_ASSERT(firstNondefdecl != NULL);
10186 ROSE_ASSERT(firstNondefdecl->get_type() != NULL);
10187
10188 // DQ (9/16/2012): This is a newly refactored function (call this after we know the firstNondefiningDeclaration is set correctly).
10189 // This is called in the other branch (mysymbol == NULL), but there is must be called before the symbol table is appended with
10190 // 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
10191 // both branches or once after both branches.
10192 if (buildTemplateInstantiation == true)
10193 {
10194 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
10195 }
10196
10197 // DQ (9/4/2012): We can now assert this because of how the type is constructed above.
10198 ROSE_ASSERT (nondefdecl->get_type() == firstNondefdecl->get_type());
10199
10200 // Share the type!
10201 if (nondefdecl->get_type() != firstNondefdecl->get_type())
10202 {
10203 // Remove the type from the new SgClassDeclaration and set the reference to the type in the firstNondefiningDeclaration.
10204 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());
10205 printf ("Skipping delete of %p so we can maintain unique type pointers \n",nondefdecl->get_type());
10206 // delete nondefdecl->get_type();
10207 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());
10208 nondefdecl->set_type(firstNondefdecl->get_type());
10209#if 1
10210 // DQ (12/13/2011): Is this executed!
10211 printf ("Unclear if this code is executed \n");
10212 ROSE_ABORT();
10213#endif
10214 }
10215#else
10216#error "DEAD CODE"
10217
10218 ROSE_ASSERT(nondefdecl == NULL);
10219#endif
10220 // This function should return a new nondefining declaration each time (to support multile class prototypes!).
10221 // nondefdecl = firstNondefdecl;
10222 }
10223 else
10224 {
10225#if REUSE_CLASS_DECLARATION_FROM_SYMBOL
10226 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
10227
10228#error "DEAD CODE"
10229
10230 nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
10231
10232#error "DEAD CODE"
10233
10234 ROSE_ASSERT(nondefdecl != NULL);
10235 if (nondefdecl->get_type() == NULL)
10236 nondefdel->set_type(SgClassType::createType(nondefdecl));
10237
10238 printf ("SageBuilder::buildNondefiningClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
10239
10240 setOneSourcePositionNull(nondefdecl);
10241
10242#error "DEAD CODE"
10243
10244 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10245 nondefdecl->set_definingDeclaration(NULL);
10246 nondefdecl->setForward();
10247#endif
10248
10249 // DQ (6/9/2013): Added assertion to debug test2013_198.C.
10250 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10251
10252 mysymbol = new SgClassSymbol(nondefdecl);
10253 firstNondefdecl = nondefdecl;
10254
10255 // DQ (6/9/2013): Adding assertions to make sure that symbols only reference non-defining declarations.
10256 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10257 ROSE_ASSERT(mysymbol->get_declaration()->get_definition() == NULL);
10258
10259 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
10260 // Note that since the symbol tables use the template arguments associated with the declaration it is best to
10261 // fixup the template arguments before the symbol table is fixup to have a symbol for this declaration. So we
10262 // fixup the template arguments here (just after we know that the firstNondefiningDeclaration is set correctly
10263 // and just before the symbol is inserted into the symbol table.
10264 if (buildTemplateInstantiation == true)
10265 {
10266 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
10267 }
10268#if DEBUG_NONDEFINING_CLASS_DECLARATION
10269 printf ("BEFORE scope->insert_symbol(): scope = %p = %s nameWithTemplateArguments = %s mysymbol = %p = %s \n",
10270 scope,scope->class_name().c_str(),nameWithTemplateArguments.str(),mysymbol,mysymbol->class_name().c_str());
10271#endif
10272
10273 // scope->insert_symbol(name, mysymbol);
10274 scope->insert_symbol(nameWithTemplateArguments, mysymbol);
10275
10276 // 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).
10277 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10278 if (nondefdecl->get_type() == NULL)
10279 {
10280#if 0
10281 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
10282 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_firstNondefiningDeclaration() = %p \n",nondefdecl->get_firstNondefiningDeclaration());
10283#endif
10284 nondefdecl->set_type(SgClassType::createType(nondefdecl));
10285#if 0
10286 printf ("In SageBuilder::buildNondefiningClassDeclaration(): built class type: part 2: nondefdecl->get_type() = %p = %s = %s \n",
10287 nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str(),nondefdecl->get_type()->unparseToString().c_str());
10288#endif
10289 }
10290
10291#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10292 printf ("NOTE: In buildNondefiningClassDeclaration_nfi(): 2nd time this is a performance issue (maybe) to call the lookup_nontemplate_class_symbol() again \n");
10293#endif
10294 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would
10295 // not include name qualification on template arguments.
10296 // DQ (12/27/2011): Added new test.
10297 // ROSE_ASSERT(scope->lookup_nontemplate_class_symbol(name) != NULL);
10298 // TV (07/01/2013): this assertion fail when building basic class (buildTemplateInstantiation = false , templateArgumentsList = NULL)
10299 // ROSE_ASSERT(scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
10300
10301 // DQ (6/9/2013): Added test to make sure that symbols only reference non-defining declarations.
10302 SgClassSymbol* temp_classSymbol = nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
10303#if DEBUG_NONDEFINING_CLASS_DECLARATION
10304 // DQ (12/28/2018): When can this be NULL?
10305 printf ("In buildNondefiningClassDeclaration_nfi(): temp_classSymbol = %p \n",temp_classSymbol);
10306 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_scope() = %p = %s scope = %p \n",nondefdecl->get_scope(),nondefdecl->get_scope()->class_name().c_str(),scope);
10307
10308 printf ("In buildNondefiningClassDeclaration_nfi(): nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
10309 if (templateArgumentsList != NULL)
10310 {
10311 printf (" --- templateArgumentsList elements: \n");
10312 for (size_t i = 0; i < templateArgumentsList->size(); i++)
10313 {
10314 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
10315 printf (" --- --- templateArgumentsList->[%zu] = %s \n",i,templateArgumentsList->operator[](i)->class_name().c_str());
10316 templateArgumentsList->operator[](i)->display("In SageBuilder::buildNondefiningClassDeclaration_nfi()");
10317 }
10318 }
10319#endif
10320 // DQ (12/28/2018): When can this be NULL? When we call lookup_class_symbol() later it is NULL, so test it here.
10321 ROSE_ASSERT(nondefdecl->get_scope()->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
10322 ROSE_ASSERT(nondefdecl->get_scope() == scope);
10323
10324 // TV (07/01/2013): temp_classSymbol can be NULL, but lookup_class_symbol return a symbol
10325 // ROSE_ASSERT(temp_classSymbol->get_declaration()->get_definition() == NULL);
10326 ROSE_ASSERT(temp_classSymbol == NULL || temp_classSymbol->get_declaration()->get_definition() == NULL);
10327 }
10328
10329 ROSE_ASSERT(mysymbol != NULL);
10330 ROSE_ASSERT(firstNondefdecl != NULL);
10331#endif
10332 nondefdecl->set_scope(scope);
10333
10334 // 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).
10335 // TPS (09/18/2009) added a condition to be able to build this properly
10336 if (scope==NULL)
10337 nondefdecl->set_parent(topScopeStack());
10338 else
10339 nondefdecl->set_parent(scope);
10340 }
10341
10342 // The support for SgEnumDeclaration handles the type, but why not for SgClassDeclaration?
10343 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10344
10345 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10346
10347#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
10348 printf ("NOTE: In buildNondefiningClassDeclaration_nfi(): 3rd time this is a performance issue (maybe) to call the lookup_nontemplate_class_symbol() again \n");
10349#endif
10350
10351 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would not include name qualification on template arguments.
10352 // DQ (12/27/2011): Added new test.
10353 // ROSE_ASSERT(nondefdecl->get_scope()->lookup_nontemplate_class_symbol(name) != NULL);
10354 // TV (07/01/2013): this assertion fail when building basic class (buildTemplateInstantiation = false , templateArgumentsList = NULL)
10355 // ROSE_ASSERT(nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
10356
10357 // DQ (6/9/2013): Added test to make sure that symbols only reference non-defining declarations.
10358 SgClassSymbol* temp_classSymbol = nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
10359 // TV (07/01/2013): temp_classSymbol can be NULL, but lookup_class_symbol return a symbol
10360 ROSE_ASSERT(temp_classSymbol == NULL || temp_classSymbol->get_declaration()->get_definition() == NULL);
10361
10362 // DQ (3/9/2018): Added assertion.
10363 ROSE_ASSERT(nondefdecl != NULL);
10364 ROSE_ASSERT(nondefdecl->get_name() == nameWithTemplateArguments);
10365
10366 // DQ (3/9/2018): Test the consistancy of the template instantiation name.
10367 if (isSgTemplateInstantiationDecl(nondefdecl) != NULL)
10368 {
10369 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(nondefdecl);
10370 SgName finalName = appendTemplateArgumentsToName(templateInstantiationDecl->get_templateName(),templateInstantiationDecl->get_templateArguments());
10371 ROSE_ASSERT(finalName == nameWithTemplateArguments);
10372 ROSE_ASSERT(finalName == nondefdecl->get_name());
10373 }
10374
10375#if DEBUG_NONDEFINING_CLASS_DECLARATION
10376 printf ("Leaving buildNondefiningClassDeclaration_nfi(): nondefdecl = %p nondefdecl->unparseNameToString() = %s \n",nondefdecl,nondefdecl->unparseNameToString().c_str());
10377 printf (" --- nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
10378#endif
10379
10380#if DEBUG_NONDEFINING_CLASS_DECLARATION
10381 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
10382 printf ("Leaving buildNondefiningClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
10383 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
10384
10385 printf ("test_symbol = %p \n",test_symbol);
10386
10387 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
10388 printf ("Leaving buildNondefiningClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
10389 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
10390#endif
10391
10392 return nondefdecl;
10393 }
10394
10397 ROSE_ASSERT(stmt != NULL);
10398
10400 stmt->set_parent(result);
10401
10402 result->set_definingDeclaration(result);
10404 return result;
10405}
10406
10409 ROSE_ASSERT(stmt != NULL);
10410
10412 stmt->set_parent(result);
10413
10414 result->set_definingDeclaration(result);
10416 return result;
10417}
10418
10420SageBuilder::buildJovialDefineDeclaration_nfi(const SgName& name, const std::string& params,
10421 const std::string& def_string, SgScopeStatement* scope)
10422 {
10423 std::string directive_string(name);
10424
10425 if (scope == NULL)
10427 ROSE_ASSERT(scope);
10428
10429 if (params.length() > 0)
10430 directive_string += " " + params;
10431
10432 directive_string += " " + def_string;
10433
10434 SgJovialDefineDeclaration* define_decl = new SgJovialDefineDeclaration(directive_string);
10435 ROSE_ASSERT(define_decl);
10437
10438 // The first nondefining declaration must be set
10439 define_decl->set_firstNondefiningDeclaration(define_decl);
10440 define_decl->set_parent(scope);
10441
10442 return define_decl;
10443 }
10444
10445// Build a Jovial loop statement. Two variants are FOR and WHILE.
10446// A loop body will be created and its parent set to the loop statement.
10449{
10450 SgJovialForThenStatement* forStmt{nullptr};
10451
10453
10454 forStmt = new SgJovialForThenStatement(nullptr, nullptr, nullptr, body);
10455 ASSERT_not_null(forStmt);
10456 setOneSourcePositionNull(forStmt);
10457
10458 body->set_parent(forStmt);
10459
10461 forStmt->setCaseInsensitive(true);
10462 }
10463
10464 return forStmt;
10465}
10466
10467// This should take a SgClassDeclaration::class_types kind parameter!
10469 {
10470#if 0
10471
10472 if (scope == NULL)
10474
10475 // TODO How about class type??
10476 // build defining declaration
10478
10479 SgClassDeclaration* defdecl = new SgClassDeclaration (name,SgClassDeclaration::e_struct,NULL,classDef);
10480 ROSE_ASSERT(defdecl);
10482 // constructor is side-effect free
10483 classDef->set_declaration(defdecl);
10484 defdecl->set_definingDeclaration(defdecl);
10485
10486 // build the nondefining declaration
10487 SgClassDeclaration* nondefdecl = new SgClassDeclaration (name,SgClassDeclaration::e_struct,NULL,NULL);
10488 ROSE_ASSERT(nondefdecl);
10489
10491 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10492 nondefdecl->set_definingDeclaration(defdecl);
10493 defdecl->set_firstNondefiningDeclaration(nondefdecl);
10494 nondefdecl->setForward();
10495
10496 if (scope !=NULL ) // put into fixStructDeclaration() or alike later on
10497 {
10498 fixStructDeclaration(nondefdecl,scope);
10499 fixStructDeclaration(defdecl,scope);
10500 }
10501#else
10502 // DQ (1/24/2009): Refactored to use the buildStructDeclaration_nfi function.
10503 // (if this work it needs to be done uniformally for the other nfi functions)
10504 // Also, "_nfi" is not a great name.
10505 // SgClassDeclaration* defdecl = buildClassDeclaration_nfi(name,SgClassDeclaration::e_struct,scope,NULL);
10506 bool buildTemplateInstantiation = false;
10507 // SgClassDeclaration* defdecl = buildClassDeclaration_nfi(name,SgClassDeclaration::e_struct,scope,NULL,buildTemplateInstantiation);
10508 SgClassDeclaration* defdecl = buildClassDeclaration_nfi(name,SgClassDeclaration::e_struct,scope,NULL,buildTemplateInstantiation,NULL);
10509
10511 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
10513#endif
10514
10515 // DQ (1/26/2009): I think this should be an error, but that appears it would
10516 // break the existing interface. Need to discuss this with Liao.
10517 // ROSE_ASSERT(defdecl->get_parent() != NULL);
10518
10519 return defdecl;
10520 }
10521
10524 {
10526 SgDerivedTypeStatement* type_decl = buildClassDeclarationStatement_nfi <SgDerivedTypeStatement> (name, kind, scope);
10527
10529 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() != NULL);
10531
10532 return type_decl;
10533 }
10534
10537 {
10539 SgModuleStatement* module_stmt = buildClassDeclarationStatement_nfi <SgModuleStatement> (name, kind, scope);
10540
10542 ROSE_ASSERT(module_stmt->get_firstNondefiningDeclaration() != NULL);
10544
10545 return module_stmt;
10546 }
10547
10551 SgScopeStatement* scope /*=NULL*/)
10552 {
10553 SgJovialTableStatement* table_decl = buildClassDeclarationStatement_nfi <SgJovialTableStatement> (name, kind, scope);
10554
10556 ROSE_ASSERT(table_decl->get_firstNondefiningDeclaration() != NULL);
10558
10559 return table_decl;
10560 }
10561
10564 {
10565 std::string type_name(name);
10566 if (base_type) {
10567 // Mangle the name to make sure the table type and the base type don't have the same name
10568 type_name = "_table_of_" + type_name;
10569 // Add dim_info address if there are subscripts to ensure type is unique
10570 if (dim_info->get_expressions().size() > 0) {
10571 std::ostringstream address;
10572 address << (void const *)dim_info;
10573 type_name += "_" + address.str();
10574 }
10575 }
10576
10578 SgJovialTableStatement* table_decl = buildClassDeclarationStatement_nfi <SgJovialTableStatement> (type_name, kind, scope);
10579
10581 ROSE_ASSERT(table_decl->get_firstNondefiningDeclaration() != NULL);
10583
10584 // For a type declaration the parent of the nondefining declaration is the defining declaration
10585 SgClassDeclaration* nondef_decl = isSgClassDeclaration(table_decl->get_firstNondefiningDeclaration());
10586 ROSE_ASSERT(nondef_decl != NULL);
10587 nondef_decl->set_parent(table_decl);
10588
10589 SgJovialTableType* table_type = isSgJovialTableType(table_decl->get_type());
10590 ROSE_ASSERT(table_type != NULL);
10591
10592 table_type->set_base_type(base_type);
10593 table_type->set_dim_info(dim_info);
10594 table_type->set_rank(dim_info->get_expressions().size());
10595
10596 dim_info->set_parent(table_type);
10597 nondef_decl->set_type(table_type);
10598
10599 return table_type;
10600 }
10601
10603template <class DeclClass> DeclClass *
10605 SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl)
10606 {
10607 // DQ (3/15/2012): Added function to build C++ class (builds both the non-defining and defining declarations; in that order).
10608 // The implementation of this function could be simplified to directly call both:
10609 // SgClassDeclaration* buildNondefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10610 // and
10611 // SgClassDeclaration* buildDefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10612 // This might refactor the implementation nicely.
10613
10614 if (scope == NULL)
10615 {
10617 }
10618
10619 // Step 1. Build the nondefining declaration (but only if the input nonDefiningDecl pointer was NULL and it does not exist)
10620 // -----------------------------------------
10621 //
10622
10623 // Get the nondefining declaration from the symbol if it has been built (if this works,
10624 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
10625
10626 SgClassDeclaration* nondefdecl = NULL;
10627 SgClassSymbol* mysymbol = NULL;
10628
10629 if (scope != NULL)
10630 {
10631 // DQ (10/10/2015): look up the correct type of symbol.
10632 mysymbol = scope->lookup_class_symbol(name);
10633
10634 if (mysymbol == NULL)
10635 {
10636 // Note: this is an input parameter (could/should go away?) [CR]
10637 if (nonDefiningDecl != NULL)
10638 {
10639 // DQ (3/4/2018): I think this is the correct API to use (internal use only).
10640 SgSymbol* temp_mysymbol = nonDefiningDecl->get_symbol_from_symbol_table();
10641 ROSE_ASSERT(temp_mysymbol != NULL);
10642
10643 mysymbol = isSgClassSymbol(temp_mysymbol);
10644 ROSE_ASSERT(mysymbol != NULL);
10645
10646 // check that the scopes are the same.
10647 ROSE_ASSERT(scope == nonDefiningDecl->get_scope());
10648 }
10649 }
10650 }
10651
10652 if (mysymbol != NULL) // set links for existing nondefining declaration
10653 {
10654 nondefdecl = (mysymbol->get_declaration() == NULL)
10655 ? NULL : dynamic_cast<DeclClass*>(mysymbol->get_declaration());
10656 ROSE_ASSERT(nondefdecl != NULL);
10657
10658 // DQ (6/8/2013): This should not be true (see test2013_198.C).
10659 // Fundamentally the symbol should always only have a pointer to a non-defining
10660 // declaration, where by definition (get_definition() == NULL).
10661 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10662
10663 // DQ (9/16/2012): This should be true by definition (verify).
10664 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
10665
10666 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10667 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10668
10669 // DQ (9/7/2012): I think this might be the root of a problem in the haskell tests (ROSE compiling ROSE).
10670 if (nondefdecl->get_definingDeclaration() != NULL)
10671 {
10672 DeclClass* nondefining_classDeclaration = (nondefdecl == NULL) ? NULL : dynamic_cast<DeclClass*>(nondefdecl);
10673 ROSE_ASSERT(nondefining_classDeclaration != NULL);
10674 DeclClass* defining_classDeclaration = (nondefdecl->get_definingDeclaration() == NULL)
10675 ? NULL : dynamic_cast<DeclClass*>(nondefdecl->get_definingDeclaration());
10676 ROSE_ASSERT(defining_classDeclaration != NULL);
10677
10678 return defining_classDeclaration;
10679 }
10680 }
10681 else // build a nondefining declaration since it does not exist
10682 {
10683 ROSE_ASSERT(nondefdecl == NULL);
10684
10685 // DeclClass is the template type parameter
10686 nondefdecl = new DeclClass(name, kind, NULL, NULL);
10687 ROSE_ASSERT(nondefdecl != NULL);
10688
10689 // The first nondefining declaration has to be set before we generate the type.
10690 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10691
10692 // 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.
10693 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
10694
10695 // DQ (3/14/2012): For C++ we need the scope set so that types will have proper locations to resolve them
10696 // from being ambiguous or not properly defined. Basically, we need a handle from which to generate something
10697 // that amounts to a kind of name qualification internally (maybe even exactly name qualification, but I would
10698 // have to think about that a bit more).
10699 ROSE_ASSERT(scope != NULL);
10700
10701 // Set the parent before calling the SgClassType::createType() as the name mangling will require it.
10702 // This is true for Fortran SgDerivedTypeStatement at least.
10703 nondefdecl->set_parent(scope);
10704 nondefdecl->set_scope(scope);
10705
10706 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
10707 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10708
10709 if (nondefdecl->get_type() == NULL)
10710 {
10711 SgClassType* class_type = NULL;
10712 switch (kind)
10713 {
10715 class_type = SgJavaParameterType::createType(nondefdecl);
10716 break;
10719 class_type = SgJovialTableType::createType(nondefdecl);
10720 break;
10721 default:
10722 class_type = SgClassType::createType(nondefdecl);
10723 break;
10724 }
10725 ROSE_ASSERT(class_type != NULL);
10726
10727 nondefdecl->set_type(class_type);
10728
10729 SgClassDeclaration* tmp_classDeclarationFromType = isSgClassDeclaration(class_type->get_declaration());
10730 ROSE_ASSERT(tmp_classDeclarationFromType != NULL);
10731 }
10732
10733 // DQ (3/22/2012): Added assertions.
10734 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10735 if (nondefdecl->get_type()->get_declaration() != nondefdecl)
10736 {
10737 printf ("ERROR: nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
10738 printf ("ERROR: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
10739 printf ("ERROR: nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
10740
10741 SgClassDeclaration* classDeclarationFromType = isSgClassDeclaration(nondefdecl->get_type()->get_declaration());
10742 ROSE_ASSERT(classDeclarationFromType != NULL);
10743
10744 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
10745 printf ("nondefdecl->get_type()->get_name() = %s \n",nondefdecl->get_type()->get_name().str());
10746 printf ("nondefdecl->get_type()->get_declaration()->get_name() = %s \n",classDeclarationFromType->get_name().str());
10747
10748 printf ("nondefdecl->get_mangled_name() = %s \n",nondefdecl->get_mangled_name().getString().c_str());
10749 printf ("nondefdecl->get_type()->get_mangled() = %s \n",nondefdecl->get_type()->get_mangled().getString().c_str());
10750 printf ("nondefdecl->get_type()->get_declaration()->get_mangled_name() = %s \n",classDeclarationFromType->get_mangled_name().getString().c_str());
10751
10752 // DQ (12/27/2018): Added additional debugging support.
10753 printf ("nondefdecl->get_type()->get_declaration()->get_firstNondefiningDeclaration() = %s \n",classDeclarationFromType->get_firstNondefiningDeclaration() ? "true" : "false");
10754 printf ("nondefdecl->get_firstNondefiningDeclaration() = %s \n",nondefdecl->get_firstNondefiningDeclaration() ? "true" : "false");
10755
10756 // 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.
10757 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10758 if (nondefdecl->get_parent() != NULL)
10759 {
10760 printf ("nondefdecl->get_parent() = %p = %s \n",nondefdecl->get_parent(),nondefdecl->get_parent()->class_name().c_str());
10761 }
10762 }
10763 ROSE_ASSERT(nondefdecl->get_type()->get_declaration() == nondefdecl);
10764
10765 // The nondefining declaration will not appear in the source code, but is compiler
10766 // generated (so we have something about the class that we can reference; e.g in
10767 // types). At the moment we make it a transformation, there might be another kind
10768 // of source position that would be more precise. FIXME.
10769 // setOneSourcePositionNull(nondefdecl);
10771 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
10772
10773#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
10774 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
10775 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
10776 {
10777 detectTransformations(nondefdecl);
10778 }
10779#endif
10780
10781 nondefdecl->setForward();
10782
10783 if (scope != NULL)
10784 {
10785 mysymbol = new SgClassSymbol(nondefdecl);
10786 scope->insert_symbol(name, mysymbol);
10787
10788 ROSE_ASSERT(nondefdecl->get_scope() == scope);
10789 }
10790 }
10791
10792 // DQ (3/15/2012): I have moved construction of defining declaration to be AFTER the nondefining declaration!
10793 // This is a better organization ans also should make sure that the declaration in the SgClassType will
10794 // properly reference the firstNondefiningDeclaration (instead of the defining declaration).
10795
10796 // Step 2. Build the defining declaration
10797 // --------------------------------------
10798 //
10800
10801 DeclClass* defdecl = new DeclClass(name,kind,NULL,classDef);
10802 ROSE_ASSERT(defdecl != NULL);
10803 ROSE_ASSERT(defdecl->get_type() == NULL);
10804
10805 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
10806 ROSE_ASSERT(defdecl->get_definition() != NULL);
10807 ROSE_ASSERT(defdecl != NULL);
10808
10809 // DQ (3/15/2012): Moved from original location above...
10810 nondefdecl->set_definingDeclaration(defdecl);
10811
10812 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
10813 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
10814
10816 // constructor is side-effect free
10817 classDef->set_declaration(defdecl);
10818 defdecl->set_definingDeclaration(defdecl);
10819
10820 defdecl->set_firstNondefiningDeclaration(nondefdecl);
10821
10822 // DQ (3/22/2012): I think we can assert this.
10823 ROSE_ASSERT(defdecl->get_type() == NULL);
10824
10825 // Liao, 10/30/2009
10826 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
10827 // This is not desired when building a defining declaration and an inefficience in the constructor
10828 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
10829 // the defining class declaration (and other nondefining declaration) just share that SgClassType.
10830 if (defdecl->get_type() != NULL)
10831 {
10832 // Removed several lines of dead code because of the assertion just above
10833 }
10834 else
10835 {
10836 // DQ (3/15/2012): Make sure that both the defining and non-defining declarations use the same type.
10837 ROSE_ASSERT (nondefdecl->get_type() != NULL);
10838 defdecl->set_type(nondefdecl->get_type());
10839
10840 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
10841 }
10842
10843 // DQ (9/4/2012): Added assertion.
10844 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10845
10846 // patch up the SgClassType for the defining class declaration
10847 ROSE_ASSERT (nondefdecl->get_type() != NULL);
10848 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
10849 // ROSE_ASSERT (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl));
10850 ROSE_ASSERT (defdecl->get_type() != NULL);
10851 ROSE_ASSERT (defdecl->get_type()->get_declaration() != NULL);
10852 ROSE_ASSERT (defdecl->get_type()->get_declaration() != isSgDeclarationStatement(defdecl));
10853 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
10854 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
10855
10856 // DQ (9/4/2012): Added assertion.
10857 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10858
10859 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
10860 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
10861 // used in a defining declaration).
10862 nondefdecl->setForward();
10863
10864 if (scope != NULL) // put into fixStructDeclaration() or alike later on
10865 {
10866 // DQ (9/4/2012): Added assertion.
10867 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10868
10869 // Note, this function sets the parent to be the scope if it is not already set.
10870 fixStructDeclaration(defdecl,scope);
10871
10872 // DQ (9/4/2012): Added assertion.
10873 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10874
10875 fixStructDeclaration(nondefdecl,scope);
10876
10877 // DQ (9/4/2012): Added assertion.
10878 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10879 }
10880
10881 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
10882 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
10883 // ROSE_ASSERT(defdecl->get_parent() != NULL);
10884
10885 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
10886
10887 // DQ (2/27/2012): Tracking down where parents are not set correctly (class declaration in typedef is incorrectly set to SgGlobal).
10888 ROSE_ASSERT(defdecl->get_parent() == NULL);
10889
10890 // DQ (2/29/2012): We can't assert this (fails for test2012_09.C).
10891 // ROSE_ASSERT(nondefdecl->get_parent() == NULL);
10892
10893 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
10894 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
10895
10896 // DQ (3/8/2018): Added for debugging.
10897 SgClassDeclaration* temp_firstNondefiningDeclaration = isSgClassDeclaration(defdecl->get_firstNondefiningDeclaration());
10898 SgClassDeclaration* temp_definingDeclaration = isSgClassDeclaration(defdecl->get_definingDeclaration());
10899 ROSE_ASSERT(temp_firstNondefiningDeclaration != NULL);
10900 ROSE_ASSERT(temp_definingDeclaration != NULL);
10901
10902 // DQ (3/8/2018): Added assertion.
10903 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_name() == temp_definingDeclaration->get_name());
10904 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_type() == temp_definingDeclaration->get_type());
10905
10906#if 0
10907 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
10908 printf ("Leaving buildClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
10909 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
10910
10911 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
10912 printf ("Leaving buildClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
10913 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
10914#endif
10915
10916 return defdecl;
10917 }
10918
10921 {
10922 SgNamespaceAliasDeclarationStatement* aliasdecl = new SgNamespaceAliasDeclarationStatement(name,namespaceDeclaration);
10925 return aliasdecl;
10926 }
10927
10928
10931 {
10933
10935 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
10937
10938 return defdecl;
10939 }
10940
10942SageBuilder::buildNamespaceDeclaration_nfi(const SgName& name, bool unnamednamespace, SgScopeStatement* scope)
10943 {
10944 if (scope == NULL)
10946
10947 ROSE_ASSERT(scope != NULL);
10948
10949#if 0
10950 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): scope = %p = %s = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
10951#endif
10952
10953 // TODO How about class type??
10954 // build defining declaration
10956
10957 SgNamespaceDeclarationStatement* defdecl = new SgNamespaceDeclarationStatement(name,namespaceDef,unnamednamespace);
10958 ROSE_ASSERT(defdecl != NULL);
10959 namespaceDef->set_parent(defdecl);
10960
10961#if 0
10962 printf ("#################### SageBuilder::buildNamespaceDeclaration_nfi(): defdecl = %p = %s namespaceDef = %p \n",defdecl,defdecl->get_name().str(),namespaceDef);
10963#endif
10964
10965 // setOneSourcePositionForTransformation(defdecl);
10966 setOneSourcePositionNull(defdecl);
10967
10968 // constructor is side-effect free
10969 namespaceDef->set_namespaceDeclaration(defdecl);
10970
10971 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
10972 // defdecl->set_definingDeclaration(defdecl);
10973 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
10974
10975 // Get the nondefining declaration from the symbol if it has been built (if this works,
10976 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
10977 SgNamespaceDeclarationStatement* nondefdecl = NULL;
10978
10979 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
10980 // ROSE_ASSERT(scope != NULL);
10981 SgNamespaceSymbol* mysymbol = NULL;
10982 if (scope != NULL)
10983 {
10984 mysymbol = scope->lookup_namespace_symbol(name);
10985 }
10986 else
10987 {
10988 // DQ (1/26/2009): I think this should be an error, but that appears it would
10989 // break the existing interface. Need to discuss this with Liao.
10990 printf ("Warning: In SageBuilder::buildNamespaceDeclaration_nfi(): scope == NULL \n");
10991 }
10992
10993#if 0
10994 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): mysymbol = %p \n",mysymbol);
10995#endif
10996
10997 if (mysymbol != NULL)
10998 {
10999 // nondefdecl = isSgNamespaceDeclarationStatement(mysymbol->get_declaration());
11000 SgNamespaceDeclarationStatement* namespaceDeclaration = mysymbol->get_declaration();
11001 ROSE_ASSERT(namespaceDeclaration != NULL);
11002 nondefdecl = isSgNamespaceDeclarationStatement(namespaceDeclaration);
11003
11004 ROSE_ASSERT(nondefdecl != NULL);
11005 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11006
11007 // DQ (5/16/2013): These should be non-defining declarations for the case of a C++ namespace (all instances are a non-defining declaration).
11008 // nondefdecl->set_definingDeclaration(defdecl);
11009 // ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
11010 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == NULL);
11011 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
11012
11013 // DQ (5/16/2013): Set the global definition for the new namespace definition.
11014 ROSE_ASSERT(namespaceDeclaration->get_definition() != NULL);
11015 if (namespaceDeclaration->get_definition()->get_global_definition() == NULL)
11016 {
11017 printf ("ERROR: namespaceDeclaration->get_definition()->get_global_definition() == NULL: namespaceDeclaration = %p = %s namespaceDeclaration->get_definition() = %p \n",
11018 namespaceDeclaration,namespaceDeclaration->get_name().str(),namespaceDeclaration->get_definition());
11019 }
11020 ROSE_ASSERT(namespaceDeclaration->get_definition()->get_global_definition() != NULL);
11021 namespaceDef->set_global_definition(namespaceDeclaration->get_definition()->get_global_definition());
11022 ROSE_ASSERT(namespaceDef->get_global_definition() != NULL);
11023
11024 // DQ (5/19/2013): Make the global_definition point to itself.
11025 ROSE_ASSERT(namespaceDef->get_global_definition() == namespaceDef->get_global_definition()->get_global_definition());
11026
11027 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
11028
11029 ROSE_ASSERT(nondefdecl->get_definition()->get_previousNamespaceDefinition() == NULL);
11030 // ROSE_ASSERT(nondefdecl->get_definition()->get_nextNamespaceDefinition() == NULL);
11031
11032 SgNamespaceDefinitionStatement* i = namespaceDeclaration->get_definition();
11033 ROSE_ASSERT(i != NULL);
11034 while (i != NULL && i->get_nextNamespaceDefinition() != NULL)
11035 {
11036 i = i->get_nextNamespaceDefinition();
11037 ROSE_ASSERT(i->get_previousNamespaceDefinition() != NULL);
11038 }
11039
11040 ROSE_ASSERT(i != NULL);
11041 i->set_nextNamespaceDefinition(namespaceDef);
11042 namespaceDef->set_previousNamespaceDefinition(i);
11043 }
11044 else
11045 {
11046 // DQ (5/16/2013): Note that since we don't build a SgNamespaceDefinition for the declaration we can't
11047 // build the global_definition. This is a potential problem.
11048
11049#if 1
11050 nondefdecl = defdecl;
11051 ROSE_ASSERT(nondefdecl != NULL);
11052 namespaceDef = nondefdecl->get_definition();
11053 ROSE_ASSERT(namespaceDef->get_namespaceDeclaration() != NULL);
11054#else
11055 // DQ (5/16/2013): We want to build an associated SgNamespaceDefinitionStatement so that we can
11056 // support a reference to a SgNamespaceDefinitionStatement as a global definition.
11057 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
11058 // nondefdecl = new SgNamespaceDeclarationStatement(name,NULL, unnamednamespace);
11059
11060#error "DEAD CODE!"
11061
11063 nondefdecl = new SgNamespaceDeclarationStatement(name,namespaceDef,unnamednamespace);
11064 ROSE_ASSERT(nondefdecl != NULL);
11065#if 0
11066 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): Built namespace definition for nondefdecl = %p = %s definition = %p \n",nondefdecl,nondefdecl->get_name().str(),namespaceDef);
11067#endif
11068 // DQ (5/16/2013): Added tests and setting of the associated declaration.
11069 ROSE_ASSERT(namespaceDef->get_namespaceDeclaration() == NULL);
11070 namespaceDef->set_namespaceDeclaration(nondefdecl);
11071 ROSE_ASSERT(namespaceDef->get_namespaceDeclaration() != NULL);
11072#endif
11073
11074 // DQ (5/16/2013): Now add the global definition where we will accumulate all of the symbols for the logical namespace.
11075 SgNamespaceDefinitionStatement* global_definition_namespaceDef = buildNamespaceDefinition();
11076 namespaceDef->set_global_definition(global_definition_namespaceDef);
11077 ROSE_ASSERT(namespaceDef->get_global_definition() != NULL);
11078
11079 // DQ (5/19/2013): Make the global_definition point to itself.
11080 global_definition_namespaceDef->set_global_definition(global_definition_namespaceDef);
11081
11082 global_definition_namespaceDef->set_isUnionOfReentrantNamespaceDefinitions(true);
11083
11084 // DQ (8/23/2013): Set the parent of the global_definition_namespaceDef.
11085 ROSE_ASSERT(global_definition_namespaceDef->get_parent() == NULL);
11086 global_definition_namespaceDef->set_parent(defdecl);
11087 ROSE_ASSERT(global_definition_namespaceDef->get_parent() != NULL);
11088
11089 // DQ (5/16/2013): Added tests and setting of the associated declaration.
11090 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() == NULL);
11091 global_definition_namespaceDef->set_namespaceDeclaration(nondefdecl);
11092 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() != NULL);
11093
11094 // DQ (5/16/2013): Set the associated declaration to be the nondefdecl.
11095 global_definition_namespaceDef->set_namespaceDeclaration(nondefdecl);
11096 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() != NULL);
11097
11098#if 0
11099 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() == NULL);
11100 // defdecl->get_definition()->set_global_definition(namespaceDef->get_global_definition());
11101 defdecl->get_definition()->set_global_definition(global_definition_namespaceDef);
11102#else
11103#if 0
11104 printf ("In SageBuilder::buildNamespaceDeclaration_nfi(): defdecl->get_definition()->get_global_definition() = %p \n",defdecl->get_definition()->get_global_definition());
11105#endif
11106 if (defdecl->get_definition()->get_global_definition() == NULL)
11107 {
11108 defdecl->get_definition()->set_global_definition(global_definition_namespaceDef);
11109 }
11110
11111 // DQ (5/19/2013): Make the global_definition point to itself.
11112 ROSE_ASSERT(global_definition_namespaceDef == global_definition_namespaceDef->get_global_definition());
11113#endif
11114 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
11115 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() == namespaceDef->get_global_definition());
11116#if 0
11117 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());
11118#endif
11119 // printf ("SageBuilder::buildNamespaceDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11120
11121 // The nondefining declaration will not appear in the source code, but is compiler
11122 // generated (so we have something about the class that we can reference; e.g in
11123 // types). At the moment we make it a transformation, there might be another kind
11124 // of source position that would be more precise. FIXME.
11125 // setOneSourcePositionNull(nondefdecl);
11126 // setOneSourcePositionForTransformation(nondefdecl);
11127
11128 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11129
11130 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
11131 // nondefdecl->set_definingDeclaration(defdecl);
11132 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == NULL);
11133 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
11134
11135 nondefdecl->setForward();
11136
11137 // nondefdecl->set_parent(topScopeStack());
11138 nondefdecl->set_parent(scope);
11139 ROSE_ASSERT(nondefdecl->get_parent());
11140
11141 if (scope != NULL)
11142 {
11143 mysymbol = new SgNamespaceSymbol(name,nondefdecl); // tps: added name to constructor
11144 scope->insert_symbol(name, mysymbol);
11145 }
11146 else
11147 {
11148 // DQ (1/26/2009): I think this should be an error, but that appears it would
11149 // break the existing interface. Need to discuss this with Liao.
11150 printf ("Warning: no scope provided to support symbol table entry! \n");
11151 }
11152
11153 ROSE_ASSERT(defdecl->get_definition() != NULL);
11154 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
11155
11156 ROSE_ASSERT(nondefdecl->get_definition()->get_previousNamespaceDefinition() == NULL);
11157 ROSE_ASSERT(nondefdecl->get_definition()->get_nextNamespaceDefinition() == NULL);
11158 }
11159
11160 ROSE_ASSERT(nondefdecl != NULL);
11161
11162 // printf ("SageBuilder::buildNamespaceDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11163
11164 // setOneSourcePositionForTransformation(nondefdecl);
11165 // setOneSourcePositionNull(nondefdecl);
11166
11167 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11168 // nondefdecl->set_definingDeclaration(defdecl);
11169 defdecl->set_firstNondefiningDeclaration(nondefdecl);
11170
11171 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
11172 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
11173 // used in a defining declaration).
11174 nondefdecl->setForward();
11175
11176 if (scope != NULL) // put into fixStructDeclaration() or alike later on
11177 {
11178 fixNamespaceDeclaration(nondefdecl,scope);
11179 fixNamespaceDeclaration(defdecl,scope);
11180#if 0
11181 SgClassSymbol* mysymbol = new SgClassSymbol(nondefdecl);
11182 ROSE_ASSERT(mysymbol);
11183 scope->insert_symbol(name, mysymbol);
11184#endif
11185
11186 // tps namespace has no scope
11187 //defdecl->set_scope(scope);
11188 //nondefdecl->set_scope(scope);
11189
11190 // defdecl->set_parent(scope);
11191
11192 // 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).
11193 // nondefdecl->set_parent(scope);
11194 // nondefdecl->set_parent(topScopeStack());
11195 }
11196
11197 // defdecl->set_parent(topScopeStack());
11198
11199 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
11200 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
11201 // ROSE_ASSERT(defdecl->get_parent() != NULL);
11202
11203 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
11204
11205 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
11206 // ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
11207 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
11208
11209 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
11210 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
11211
11212 // DQ (5/16/2013): Added tests.
11213 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
11214 ROSE_ASSERT(defdecl->get_definition() != NULL);
11215 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
11216
11217#if 0
11218 // DQ (5/19/2013): There should always be proper source file position infomation so this should not be required.
11219 if (defdecl->get_file_info()->isOutputInCodeGeneration() == true)
11220 {
11221 defdecl->get_file_info()->display("In buildNamespaceDeclaration_nfi(): namespaceDeclaration: debug");
11222 }
11223 // ROSE_ASSERT(defdecl->get_file_info()->isOutputInCodeGeneration() == false);
11224#endif
11225
11226 return defdecl;
11227 }
11228
11229// driscoll6 (7/20/11) : Support n-ary operators for python
11232 SgNaryComparisonOp* result = new SgNaryComparisonOp();
11233
11234 result->get_operands().push_back(lhs);
11235 lhs->set_parent(result);
11236
11238 return result;
11239}
11240
11243 SgNaryComparisonOp* result = new SgNaryComparisonOp();
11244
11245 result->get_operands().push_back(lhs);
11246 lhs->set_parent(result);
11247
11249 return result;
11250}
11251
11254 SgNaryBooleanOp* result = new SgNaryBooleanOp();
11255
11256 result->get_operands().push_back(lhs);
11257 lhs->set_parent(result);
11258
11260 return result;
11261}
11262
11265 SgNaryBooleanOp* result = new SgNaryBooleanOp();
11266
11267 result->get_operands().push_back(lhs);
11268 lhs->set_parent(result);
11269
11271 return result;
11272}
11273
11276 ROSE_ASSERT(exp);
11277 SgStringConversion* result = new SgStringConversion(exp);
11278 exp->set_parent(result);
11279
11281 return result;
11282}
11283
11284
11287 ROSE_ASSERT(exp);
11288 SgStringConversion* result = new SgStringConversion(exp);
11289 exp->set_parent(result);
11290
11292 return result;
11293}
11294
11295// DQ (11/7/2009): Added more uniform support for building class declarations.
11298 {
11299 SgClassDeclaration* defdecl = NULL;
11300 SgClassDeclaration* nondefdecl = NULL;
11301
11302 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
11303 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
11304 ROSE_ASSERT(SageInterface::hasTemplateSyntax(name) == false);
11305
11306#if 1
11307 printf ("In buildNondefiningClassDeclaration(): name = %s scope = %p = %s \n",name.str(),scope,scope != NULL ? scope->class_name().c_str() : "NULL");
11308
11309 // DQ (8/12/2013): If this function were to be called then we would have to
11310 // support a template argument list for the call to lookup_class_symbol().
11311
11312 // DQ (6/9/2013): I want to know that I'm not debugging this function.
11313 ROSE_ABORT();
11314#endif
11315
11316 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
11317 // ROSE_ASSERT(scope != NULL);
11318 SgClassSymbol* mysymbol = NULL;
11319 if (scope != NULL)
11320 {
11321 // mysymbol = scope->lookup_class_symbol(name);
11322 mysymbol = scope->lookup_class_symbol(name,NULL);
11323 }
11324 else
11325 {
11326 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unkown.
11327 // DQ (1/26/2009): I think this should be an error, but that appears it would
11328 // break the existing interface. Need to discuss this with Liao.
11329 // printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): scope == NULL \n");
11330 }
11331
11332#if 0
11333 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
11334#endif
11335
11336 if (mysymbol != NULL) // set links if nondefining declaration already exists.
11337 {
11338 nondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
11339
11340 ROSE_ASSERT(nondefdecl != NULL);
11341 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11342
11343 nondefdecl->set_definingDeclaration(defdecl);
11344
11345 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
11346 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
11347
11348 // DQ (10/30/2010): There should be a properly defined type at this point!
11349 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11350
11351 // DQ (7/31/2019): Check that this is true.
11352 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11353 }
11354 else // build a nondefnining declaration if it does not exist
11355 {
11356 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
11357
11359 nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
11360 ROSE_ASSERT(nondefdecl != NULL);
11361 if (nondefdecl->get_type() == NULL)
11362 {
11363 nondefdecl->set_type(SgClassType::createType(nondefdecl));
11364#if 0
11365 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());
11366#endif
11367 }
11368
11369 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11370
11371 // The nondefining declaration will not appear in the source code, but is compiler
11372 // generated (so we have something about the class that we can reference; e.g in
11373 // types). At the moment we make it a transformation, there might be another kind
11374 // of source position that would be more precise. FIXME.
11375 // setOneSourcePositionNull(nondefdecl);
11377
11378 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11379 nondefdecl->set_definingDeclaration(defdecl);
11380 nondefdecl->setForward();
11381 // Liao, 9/2/2009. scope stack is optional, it can be empty
11382 // nondefdecl->set_parent(topScopeStack());
11383 // nondefdecl->set_parent(scope);
11384
11385 // DQ (7/31/2019): Check that this is true.
11386 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11387
11388 // DQ (3/24/2011): This should be NULL before we set it (if the scope is known).
11389 ROSE_ASSERT(nondefdecl->get_scope() == NULL);
11390 if (scope != NULL)
11391 {
11392 // 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.
11393 nondefdecl->set_scope(scope);
11394 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
11395
11396 mysymbol = new SgClassSymbol(nondefdecl);
11397#if 0
11398 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());
11399#endif
11400 scope->insert_symbol(name, mysymbol);
11401 }
11402 else
11403 {
11404 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknown.
11405 // DQ (1/26/2009): I think this should be an error, but that appears it would
11406 // break the existing interface. Need to discuss this with Liao.
11407 // printf ("Warning: no scope provided to support symbol table entry! \n");
11408 }
11409
11410 // DQ (10/30/2010): There should be a properly defined type at this point!
11411 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11412
11413 // DQ (3/24/2011): The scope should be set if the scope was available.
11414 ROSE_ASSERT(scope == NULL || (scope != NULL && nondefdecl->get_scope() != NULL));
11415 }
11416
11417 ROSE_ASSERT(nondefdecl != NULL);
11418
11419 return nondefdecl;
11420 }
11421
11422// DQ (11/7/2009): Added more uniform support for building class declarations.
11425 {
11426 // Note that the semantics of this function now differs from that of the buildDefiningFunctionDeclaration().
11427 // We want to have the non-defining declaration already exist before calling this function.
11428 // We could still build a higher level function that built both together. Or we could provide two versions
11429 // named differently (from this one) and deprecate this function...which I like much better.
11430 printf ("WARNING: This function for building defining class declarations has different semantics from that of the function to build defining function declarations. \n");
11431
11432#if 1
11433 printf ("In buildDefiningClassDeclaration(): name = %s scope = %p = %s \n",name.str(),scope,scope != NULL ? scope->class_name().c_str() : "NULL");
11434
11435 // DQ (6/9/2013): I want to know that I'm not debugging this function.
11436 ROSE_ABORT();
11437#endif
11438
11439 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
11440 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
11441 ROSE_ASSERT(SageInterface::hasTemplateSyntax(name) == false);
11442
11443 SgClassDeclaration* nondefiningClassDeclaration = buildNondefiningClassDeclaration(name,scope);
11444 ROSE_ASSERT(nondefiningClassDeclaration != NULL);
11445
11446 SgClassDefinition* definingClassDefinition = buildClassDefinition();
11447 ROSE_ASSERT(definingClassDefinition != NULL);
11448
11449 // DQ (10/30/2010): There should be a properly defined type at this point!
11450 SgClassType* classType = nondefiningClassDeclaration->get_type();
11451 ROSE_ASSERT(classType != NULL);
11452
11454
11455 // DQ (10/30/2010): We need to make sure that there is a type defined.
11456 // SgClassDeclaration* definingClassDeclaration = new SgClassDeclaration (name,kind,NULL,definingClassDefinition);
11457 SgClassDeclaration* definingClassDeclaration = new SgClassDeclaration (name,kind,classType,definingClassDefinition);
11458 ROSE_ASSERT(definingClassDeclaration != NULL);
11459
11460 // printf ("SageBuilder::buildDefiningClassDeclaration(): definingClassDeclaration = %p \n",definingClassDeclaration);
11461
11462 setOneSourcePositionForTransformation(definingClassDeclaration);
11463
11464 // constructor is side-effect free
11465 definingClassDefinition->set_declaration(definingClassDeclaration);
11466 definingClassDeclaration->set_definingDeclaration(definingClassDeclaration);
11467 definingClassDeclaration->set_firstNondefiningDeclaration(nondefiningClassDeclaration);
11468
11469 nondefiningClassDeclaration->set_definingDeclaration(definingClassDeclaration);
11470
11471 // some error checking
11472 ROSE_ASSERT(nondefiningClassDeclaration->get_definingDeclaration() != NULL);
11473 ROSE_ASSERT(nondefiningClassDeclaration->get_firstNondefiningDeclaration() != NULL);
11474 ROSE_ASSERT(definingClassDeclaration->get_firstNondefiningDeclaration() != NULL);
11475 ROSE_ASSERT(definingClassDeclaration->get_definition() != NULL);
11476
11477 ROSE_ASSERT(definingClassDeclaration->get_scope() == NULL);
11478 if (scope != NULL)
11479 {
11480 definingClassDeclaration->set_scope(scope);
11481 ROSE_ASSERT(definingClassDeclaration->get_scope() != NULL);
11482 ROSE_ASSERT(nondefiningClassDeclaration->get_scope() != NULL);
11483 }
11484
11485 ROSE_ASSERT(definingClassDeclaration->get_definition()->get_parent() != NULL);
11486
11487 // DQ (10/30/2010): There should be a properly defined type at this point!
11488 ROSE_ASSERT(definingClassDeclaration->get_type() != NULL);
11489
11490 return definingClassDeclaration;
11491 }
11492
11493// DQ (11/7/2009): Added more uniform support for building class declarations.
11496 {
11497 ROSE_ASSERT(scope != NULL);
11498 SgClassDeclaration* definingClassDeclaration = buildDefiningClassDeclaration(name,scope);
11499 ROSE_ASSERT(definingClassDeclaration != NULL);
11500
11501 return definingClassDeclaration;
11502 }
11503
11504
11505// 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).
11506// DQ (1/24/2009): Built this "nfi" version but factored the code.
11507// SgClassDeclaration* SageBuilder::buildClassDeclaration_nfi(const SgName& name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl , bool buildTemplateInstantiation )
11509SageBuilder::buildClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl , bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList )
11510 {
11511 // DQ (3/15/2012): Added function to build C++ class (builds both the non-defining and defining declarations; in that order).
11512 // The implementation of this function could be simplified to directly call both:
11513 // SgClassDeclaration* buildNondefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
11514 // and
11515 // SgClassDeclaration* buildDefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
11516 // This might refactor the implementation nicely.
11517
11518#define DEBUG_CLASS_DECLARATION 0
11519
11520 // Note that the nonDefiningDecl pointer does not appear to be used.
11521#if 0
11522 printf ("WARNING: In SageBuilder::buildClassDeclaration_nfi(): the nonDefiningDecl pointer = %p (input parameter) does not appear to be used. \n",nonDefiningDecl);
11523#endif
11524
11525#if 0
11526 // DQ (3/4/2018): Adding testing.
11527 // ROSE_ASSERT(nonDefiningDecl != NULL);
11528 if (nonDefiningDecl != NULL)
11529 {
11530 ROSE_ASSERT(nonDefiningDecl->get_type() != NULL);
11531 ROSE_ASSERT(nonDefiningDecl->get_type()->get_declaration() != NULL);
11532 printf ("nonDefiningDecl->get_type() = %p = %s \n",nonDefiningDecl->get_type(),nonDefiningDecl->get_type()->class_name().c_str());
11533 printf ("nonDefiningDecl->get_type()->get_declaration() = %p = %s \n",nonDefiningDecl->get_type()->get_declaration(),nonDefiningDecl->get_type()->get_declaration()->class_name().c_str());
11534#if 0
11535 printf ("In buildClassDeclaration_nfi(): nonDefiningDecl: unparseNameToString() = %s \n",nonDefiningDecl->unparseNameToString().c_str());
11536#endif
11537
11538 }
11539#endif
11540
11541
11542 // DQ (10/10/2015): I think we can assert this! NO we can't (see test2015_87.C).
11543 // ROSE_ASSERT(nonDefiningDecl != NULL);
11544
11545 // DQ (10/10/2015): OK, now we have a valid use on the input non-defining declaration.
11546 bool buildTemplateDeclaration = (isSgTemplateClassDeclaration(nonDefiningDecl) != NULL);
11547
11548 // DQ (10/10/2015): If this is true, then we should have called a different function to build the associated SgTemplateClassDeclaration.
11549 if (buildTemplateDeclaration == true)
11550 {
11551 // Error checking.
11552 printf ("ERROR: If buildTemplateDeclaration == true, then we should have called a different function to build the associated SgTemplateClassDeclaration \n");
11553 }
11554 ROSE_ASSERT(buildTemplateDeclaration == false);
11555
11556#if 0
11557 printf ("In SageBuilder::buildClassDeclaration_nfi(): XXX_name = %s \n",XXX_name.str());
11558 printf ("In SageBuilder::buildClassDeclaration_nfi(): the nonDefiningDecl pointer = %p = %s \n",nonDefiningDecl,nonDefiningDecl != NULL ? nonDefiningDecl->class_name().c_str() : "null");
11559 printf ("In SageBuilder::buildClassDeclaration_nfi(): buildTemplateDeclaration = %s \n",buildTemplateDeclaration ? "true" : "false");
11560 printf (" --- templateArgumentsList = %p \n",templateArgumentsList);
11561 if (templateArgumentsList != NULL)
11562 {
11563 printf (" --- templateArgumentsList.size() = %zu \n",templateArgumentsList->size());
11564 for (size_t i = 0; i < templateArgumentsList->size(); i++)
11565 {
11566 printf (" --- --- argument pointer: templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
11567 }
11568 }
11569#endif
11570
11571 if (scope == NULL)
11572 {
11574#if 0
11575 printf ("In SageBuilder::buildClassDeclaration_nfi(): no scope was provided so using the SageBuilder::topScopeStack() = %p = %s \n",scope,scope->class_name().c_str());
11576#endif
11577 }
11578 else
11579 {
11580#if 0
11581 printf ("In SageBuilder::buildClassDeclaration_nfi(): scope was provided scope = %p = %s \n",scope,scope->class_name().c_str());
11582#endif
11583 }
11584
11585#if 0
11586 printf ("Building a SgClassDeclaration: buildClassDeclaration_nfi() XXX_name = %s buildTemplateInstantiation = %s \n",XXX_name.str(),buildTemplateInstantiation ? "true" : "false");
11587#endif
11588
11589 // Step 2 (now step 1). build the nondefining declaration,
11590 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
11591
11592 // Get the nondefining declaration from the symbol if it has been built (if this works,
11593 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
11594 SgClassDeclaration* nondefdecl = NULL;
11595
11596 SgName nameWithoutTemplateArguments = XXX_name;
11597 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
11598 if (buildTemplateInstantiation == true)
11599 {
11600 ROSE_ASSERT(templateArgumentsList != NULL);
11601 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
11602 }
11603
11604#if DEBUG_CLASS_DECLARATION
11605 printf ("In SageBuilder::buildClassDeclaration_nfi():\n");
11606 printf (" -- nameWithoutTemplateArguments = %s\n", nameWithoutTemplateArguments.str());
11607 printf (" -- nameWithTemplateArguments = %s\n", nameWithTemplateArguments.str());
11608#endif
11609
11610 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
11611 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
11612 // This fails for test2005_35.C
11613 // ROSE_ASSERT(SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == false);
11614
11615 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
11616 // ROSE_ASSERT(scope != NULL);
11617 SgClassSymbol* mysymbol = NULL;
11618 if (scope != NULL)
11619 {
11620#if DEBUG_CLASS_DECLARATION
11621 printf ("Looking up the SgClassSymbol in scope = %p = %s nameWithTemplateArguments = %s \n",scope,scope->class_name().c_str(),nameWithTemplateArguments.str());
11622#endif
11623
11624 // DQ (8/22/2012): We need to provide more information ofr the symbol table lookup to correctly resolve
11625 // (and disambiguate template instantations where the name qualification of the template arguments would
11626 // be significant).
11627 // mysymbol = scope->lookup_class_symbol(name);
11628 // mysymbol = scope->lookup_class_symbol(name);
11629 // mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments);
11630#if 0
11631 // DQ (7/25/2017): Since this is overwritten below, for both branches, we don't need to call this here.
11632 printf ("This was a redundant call to lookup_class_symbol \n");
11633 // mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList);
11634#endif
11635
11636 // DQ (10/10/2015): look up the correct type of symbol.
11637 if (buildTemplateDeclaration == true)
11638 {
11639#if DEBUG_CLASS_DECLARATION
11640 printf ("Note: In SageBuilder::buildClassDeclaration_nfi(): Need to look up a template symbol \n");
11641#endif
11642 ROSE_ASSERT(nonDefiningDecl != NULL);
11643
11644 SgTemplateParameterPtrList templateParameterList;
11645 SgTemplateArgumentPtrList templateSpecializationArgumentList;
11646
11647 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateArguments,&templateParameterList,&templateSpecializationArgumentList) != NULL);
11648
11649 mysymbol = scope->lookup_template_class_symbol(nameWithTemplateArguments,&templateParameterList,&templateSpecializationArgumentList);
11650
11651 ROSE_ASSERT(mysymbol != NULL);
11652#if 0
11653 printf ("ERROR: Need to look up a template symbol \n");
11654 ROSE_ABORT();
11655#endif
11656 }
11657 else
11658 {
11659#if DEBUG_CLASS_DECLARATION
11660 printf ("In SageBuilder::buildClassDeclaration_nfi(): calling lookup_class_symbol(nameWithTemplateArguments = %s,templateArgumentsList->size() = %zu \n",
11661 nameWithTemplateArguments.str(),(templateArgumentsList != NULL) ? templateArgumentsList->size() : 999);
11662 if (templateArgumentsList != NULL)
11663 {
11664 printf (" --- templateArgumentsList elements: \n");
11665 for (size_t i = 0; i < templateArgumentsList->size(); i++)
11666 {
11667 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
11668 printf (" --- --- templateArgumentsList->[%zu] = %s \n",i,templateArgumentsList->operator[](i)->class_name().c_str());
11669 templateArgumentsList->operator[](i)->display("In SageBuilder::buildClassDeclaration_nfi()");
11670 }
11671 }
11672#endif
11673 mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList);
11674#if DEBUG_CLASS_DECLARATION
11675 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
11676#endif
11677 // 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).
11678 if (mysymbol == NULL)
11679 {
11680#if DEBUG_CLASS_DECLARATION
11681 printf ("WARNING: scope->lookup_class_symbol(nameWithTemplateArguments = %s,templateArgumentsList->size() = %zu) == NULL \n",nameWithTemplateArguments.str(),templateArgumentsList->size());
11682#endif
11683 // ROSE_ASSERT(nonDefiningDecl != NULL);
11684
11685 // DQ (12/28/2018): Could it be that we wanted to use the name without template arguments.
11686#if DEBUG_CLASS_DECLARATION
11687 printf ("Checking lookup_class_symbol() using nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11688#endif
11689 ROSE_ASSERT(scope->lookup_class_symbol(nameWithoutTemplateArguments,templateArgumentsList) == NULL);
11690
11691#if DEBUG_CLASS_DECLARATION
11692 printf ("nonDefiningDecl = %p \n",nonDefiningDecl);
11693#endif
11694 if (nonDefiningDecl != NULL)
11695 {
11696#if DEBUG_CLASS_DECLARATION
11697 printf ("nonDefiningDecl = %p = %s \n",nonDefiningDecl,nonDefiningDecl->class_name().c_str());
11698#endif
11699 // DQ (3/4/2018): I think this is the correct API to use (internal use only).
11700 SgSymbol* temp_mysymbol = nonDefiningDecl->get_symbol_from_symbol_table();
11701 ROSE_ASSERT(temp_mysymbol != NULL);
11702
11703 mysymbol = isSgClassSymbol(temp_mysymbol);
11704 ROSE_ASSERT(mysymbol != NULL);
11705
11706 // DQ (3/4/2018): check that the scopes are the same.
11707 ROSE_ASSERT(scope == nonDefiningDecl->get_scope());
11708 }
11709 }
11710 }
11711
11712#if 0
11713 // DQ (11/21/2013): Added test based on debugging session with Philippe.
11714 // This test is not a test for a bug, since we require that symbols in base classes be aliased in the derived classes.
11715 if (mysymbol != NULL)
11716 {
11717 SgClassDeclaration* symbol_declaration = isSgClassDeclaration(mysymbol->get_declaration());
11718 ROSE_ASSERT(symbol_declaration != NULL);
11719 ROSE_ASSERT(symbol_declaration->get_scope() == scope);
11720
11721 printf ("In SageBuilder::buildClassDeclaration_nfi(): Testing scope->get_symbol_table()->exists(mysymbol) == true (expensive) \n");
11722
11723 ROSE_ASSERT(scope->get_symbol_table()->exists(mysymbol) == true);
11724 }
11725#endif
11726 }
11727 else
11728 {
11729 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknow.
11730 // DQ (1/26/2009): I think this should be an error, but that appears it would
11731 // break the existing interface. Need to discuss this with Liao.
11732 // printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): scope == NULL \n");
11733 }
11734
11735#if DEBUG_CLASS_DECLARATION
11736 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
11737#endif
11738
11739 if (mysymbol != NULL) // set links if nondefining declaration already exists.
11740 {
11741 nondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
11742
11743 ROSE_ASSERT(nondefdecl != NULL);
11744
11745#if DEBUG_CLASS_DECLARATION
11746 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol->get_declaration(): nondefdecl = %p = %s nondefdecl->get_definition() = %p = %s \n",
11747 nondefdecl,nondefdecl->class_name().c_str(),nondefdecl->get_definition(),
11748 nondefdecl->get_definition() != NULL ? nondefdecl->get_definition()->class_name().c_str() : "NULL");
11749#endif
11750 // DQ (6/8/2013): This should not be true (see test2013_198.C).
11751 // Fundamentally the symbol should always only have a pointer to a non-defining
11752 // declaration, where by definition (get_definition() == NULL).
11753 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
11754
11755 // DQ (9/16/2012): This should be true by definition (verify).
11756 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
11757
11758 // DQ (9/16/2012): The declaration was build previously, but test it to make sure the template arguments were setup properly.
11759 testTemplateArgumentParents(nondefdecl);
11760
11761#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11762 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11763 detectTransformations(nondefdecl);
11764#endif
11765
11766 // DQ (3/22/2012): I think we can assert this.
11767 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11768
11769 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11770 if (nondefdecl->get_parent() == NULL)
11771 {
11772#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11773 printf ("In SageBuilder::buildClassDeclaration_nfi(): Note that nondefdecl->get_parent() == NULL, this might be OK. \n");
11774#endif
11775 }
11776
11777#if 0
11778 // DQ (12/22/2019): This is the code that causes the class declarations between defining
11779 // class declarations across multiple translation units to be shared.
11780
11781 // DQ (9/7/2012): I think this might be the root of a problem in the haskell tests (ROSE compiling ROSE).
11782 if (nondefdecl->get_definingDeclaration() != NULL)
11783 {
11784#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11785 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",
11786 nondefdecl,nondefdecl->class_name().c_str(),nondefdecl->get_definingDeclaration(),nondefdecl->get_definingDeclaration()->class_name().c_str());
11787#endif
11788 SgClassDeclaration* nondefining_classDeclaration = isSgClassDeclaration(nondefdecl);
11789 ROSE_ASSERT(nondefining_classDeclaration != NULL);
11790 SgClassDeclaration* defining_classDeclaration = isSgClassDeclaration(nondefdecl->get_definingDeclaration());
11791 ROSE_ASSERT(defining_classDeclaration != NULL);
11792
11793#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11794 printf ("In SageBuilder::buildClassDeclaration_nfi(): nondefining_classDeclaration: scope = %p = %s name = %s \n",
11795 nondefining_classDeclaration->get_scope(),nondefining_classDeclaration->get_scope()->class_name().c_str(),nondefining_classDeclaration->get_name().str());
11796 printf ("In SageBuilder::buildClassDeclaration_nfi(): defining_classDeclaration: scope = %p = %s name = %s \n",
11797 defining_classDeclaration->get_scope(),defining_classDeclaration->get_scope()->class_name().c_str(),defining_classDeclaration->get_name().str());
11798 defining_classDeclaration->get_file_info()->display("already has a defining declaration");
11799#endif
11800#if 0
11801 printf ("Error: In SageBuilder::buildClassDeclaration_nfi(): exiting as part of test \n");
11802 ROSE_ABORT();
11803#endif
11804 // 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.
11805#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11806 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);
11807#endif
11808
11809#if 0
11810 // DQ (2/26/2019): Debugging support for multiple files on the command line.
11811 printf ("Exiting as a test! \n");
11812 ROSE_ABORT();
11813#endif
11814 return defining_classDeclaration;
11815 }
11816#endif
11817
11818#if 0
11819 nondefdecl->set_definingDeclaration(defdecl);
11820
11821 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
11822 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
11823#endif
11824 }
11825 else // build a nondefnining declaration if it does not exist
11826 {
11827#if DEBUG_CLASS_DECLARATION
11828 printf ("In SageBuilder::buildClassDeclaration_nfi(): building a nondefining declaration since it does not exist \n");
11829#endif
11830 // DQ (10/10/2015): This should be true.
11831 ROSE_ASSERT(nondefdecl == NULL);
11832
11833 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
11834 // DQ (1/1/2012): Fixed to force matching types or IR nodes for defining and non-defining declarations.
11835 if (buildTemplateInstantiation == true)
11836 {
11837 // This adds: SgTemplateDeclaration *templateDeclaration and SgTemplateArgumentPtrList templateArguments
11838#if DEBUG_CLASS_DECLARATION
11839 printf ("************************************************************************* \n");
11840 printf ("Building SgTemplateInstantiationDecl with empty SgTemplateArgumentPtrList \n");
11841 printf (" --- using nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
11842 printf ("************************************************************************* \n");
11843#endif
11844 SgTemplateArgumentPtrList emptyList;
11845 // nondefdecl = new SgTemplateInstantiationDecl (name,kind,NULL,NULL,NULL,emptyList);
11846 nondefdecl = new SgTemplateInstantiationDecl (nameWithTemplateArguments,kind,NULL,NULL,NULL,emptyList);
11847 ROSE_ASSERT(nondefdecl != NULL);
11848#if DEBUG_CLASS_DECLARATION
11849 printf ("In SageBuilder::buildClassDeclaration_nfi(): Build SgTemplateInstantiationDecl: nondefdecl = %p \n",nondefdecl);
11850#endif
11851 // DQ (2/27/2018): Added assertion now that we have implemented more consistant semantics
11852 // for template instantiations (types are not generated in the constructor calls).
11853 ROSE_ASSERT(nondefdecl->get_type() == NULL);
11854 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl) != NULL);
11855#if 0
11856 printf ("In buildClassDeclaration_nfi(): nondefdecl->get_name() = %s nondefdecl->get_templateName() = %s \n",nondefdecl->get_name().str(),isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().str());
11857#endif
11858#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11859 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11860 // detectTransformations(nondefdecl);
11861#endif
11862 // DQ (6/6/2012): Set the first non-defining declaration to be itself.
11863 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11864
11865 // DQ (1/1/2012): Added support for setting the template name (I think this should be fixed in the constructor).
11866 // It can't be fixed in the constructor since it has to be set after construction (or passed in explicitly).
11867 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == true);
11868
11869 // DQ (6/6/2012): Added support for template arguments so that types would be computed with the template arguments.
11870 ROSE_ASSERT(templateArgumentsList != NULL);
11871
11872#if 0
11873 // DQ (5/30/2014): Removing output spew.
11874 // DQ (5/17/2014): This must be allowed for some template instantiations (see test2014_77.C).
11875 // This occurs now under some revised rules for when to interpret a class or struct as a template
11876 // declaration or template instantiation declaration. This revisions is required for test2014_56.C
11877 // but has had a small cascading effect on other parts of ROSE (all fixed on 5/17/2014, if I can
11878 // finish this work today).
11879 // ROSE_ASSERT(templateArgumentsList->size() > 0);
11880 if (templateArgumentsList->size() == 0)
11881 {
11882 printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): templateArgumentsList->size() == 0 \n");
11883 }
11884#endif
11885 // DQ (9/16/2012): Set the firstNondefiningDeclaration so that we can set the template parameters.
11886 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11887#if 1
11888 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
11889 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
11890#else
11891 isSgTemplateInstantiationDecl(nondefdecl)->get_templateArguments() = *templateArgumentsList;
11892
11893#error "DEAD CODE!"
11894
11895 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
11896 // printf ("Calling setTemplateArgumentParents(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11897 setTemplateArgumentParents(nondefdecl);
11898 // printf ("DONE: Calling setTemplateArgumentParents(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11899
11900 testTemplateArgumentParents(nondefdecl);
11901#endif
11902 // DQ (6/6/2012): Generate the name without the template arguments.
11903#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11904 printf ("Warning: In buildClassDeclaration_nfi(): calling set_templateName(nameWithTemplateArguments = %s) for nondefining declaration \n",nameWithTemplateArguments.str());
11905#endif
11906 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(name);
11907 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName("SETME_NONDEFINING_DECL<>");
11908 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(name);
11909 isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(nameWithoutTemplateArguments);
11910
11911 // DQ (6/6/2012): I don't think we want this test any more (should apply only to the result of get_templateName()).
11912 // DQ (5/31/2012): Find locations where this is set and include template syntax.
11913 // ROSE_ASSERT(name.getString().find('<') == string::npos);
11914 // printf ("Commented out test for: name.getString().find('<') == string::npos (should apply only to the result of get_templateName() \n");
11915
11916 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == false);
11917
11918 // DQ (3/25/2017): Fixed Clang warning: warning: if statement has empty body [-Wempty-body]
11919 // DQ (3/22/2012): Make sure there is template syntax present.
11920 // if (isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().getString().find('>') == string::npos)
11921 // if (hasTemplateSyntax(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName()) == false);
11922 if (hasTemplateSyntax(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName()) == false)
11923 {
11924#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11925 printf ("WARNING: No template syntax present in name of template class instantiation (nondefdecl) \n");
11926#endif
11927 }
11928 // ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().getString().find('>') != string::npos);
11929
11930#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11931 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11932 // detectTransformations(nondefdecl);
11933#endif
11934 // 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.
11935 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
11936 }
11937 else
11938 {
11939 // We know that the name without template arguments should be used here (but they are the same).
11940#if DEBUG_CLASS_DECLARATION
11941 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);
11942 printf (" --- nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11943#endif
11944 // nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
11945 nondefdecl = new SgClassDeclaration(nameWithoutTemplateArguments,kind,NULL,NULL);
11946
11947 ROSE_ASSERT(nondefdecl != NULL);
11948#if DEBUG_CLASS_DECLARATION
11949 printf ("In buildClassDeclaration_nfi(): (no file info set): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11950#endif
11951 // DQ (10/9/2015): Added assertion. We can't assert this yet (see test2015_87.C).
11952 // ROSE_ASSERT(nondefdecl->get_type() != NULL);
11953
11954 ROSE_ASSERT(nameWithoutTemplateArguments == nameWithTemplateArguments);
11955
11956#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11957 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11958 // detectTransformations(nondefdecl);
11959#endif
11960 // DQ (9/16/2012): Set the firstNondefiningDeclaration because this is the one branch left were it
11961 // was not set (required in the true branch so that we could set the template parameters).
11962 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11963
11964 testTemplateArgumentParents(nondefdecl);
11965
11966 // 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.
11967 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
11968 }
11969
11970 ROSE_ASSERT(nondefdecl != NULL);
11971
11972 // DQ (6/6/2012): This has to be set before we generate the type.
11973 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11974 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
11975
11976 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
11977 // setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
11978
11979 // DQ (3/14/2012): For C++ we need the scope set so that types will have proper locations to revolve them
11980 // from being ambiguous or not properly defined. Basically, we need a handle from which to generate something
11981 // that amounts to a kind of name qualification internally (maybe even exactly name qualification, but I would
11982 // have to think about that a bit more).
11983 ROSE_ASSERT(scope != NULL);
11984
11985#if DEBUG_CLASS_DECLARATION
11986 printf ("In SageBuilder::buildClassDeclaration_nfi(): Set the scope of the new non-defining declaration to %p = %s \n",scope,scope->class_name().c_str());
11987#endif
11988 nondefdecl->set_scope(scope);
11989 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
11990
11991 // DQ (8/2/2019): The was required becuase the parent pointers were not being set when reading a file from the SageBuilder::buildFil() API.
11992 // However the bug was that the astPostprocessing's call to resetParentPointersInMemoryPool() was not properly working to find the global
11993 // scope in anyother case but when it was called usign a SgProject node. This is not fixed to permit caloling using a SgSourceFile node
11994 // and it is now an error to call it using any other kind of IR node.
11995 // DQ (8/1/2019): Set the parent for the non defining declaration to be the same as the scope by default.
11996 // nondefdecl->set_parent(scope);
11997#if 0
11998 printf ("In buildClassDeclaration_nfi(): setting the parent of the non defining declaration to be the scope by default) \n");
11999#endif
12000 // DQ (7/31/2019): Check that the parent is set if this was used a the declaration referenced by a symbol.
12001 // ROSE_ASSERT (nondefdecl->get_parent() != NULL);
12002
12003 // DQ (3/22/2012): I think we can assert this.
12004 // ROSE_ASSERT(nondefdecl->get_type() != NULL);
12005 ROSE_ASSERT(nondefdecl->get_type() == NULL);
12006
12007 if (nondefdecl->get_type() == NULL)
12008 {
12009#if DEBUG_CLASS_DECLARATION
12010 // DQ (12/27/2018): If we have already built a type, then why did we need to build a nondefining declaration?
12011 printf ("Calling scope->get_type_table()->lookup_type(): nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
12012
12013 printf ("WE NEED THE MANGLED NAME FOR THIS TO BE RELEVANT! \n");
12014
12015 // SgType* existingType = scope->get_type_table()->lookup_type(nameWithTemplateArguments);
12016 // ROSE_ASSERT(existingType == NULL);
12017#endif
12018
12019#if DEBUG_CLASS_DECLARATION
12020 printf ("In SageBuilder::buildClassDeclaration_nfi(): kind == SgClassDeclaration::e_java_parameter = %s \n",(kind == SgClassDeclaration::e_java_parameter) ? "true" : "false");
12021#endif
12024 : (SgClassType *) SgClassType::createType(nondefdecl));
12025#if DEBUG_CLASS_DECLARATION
12026 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());
12027#endif
12028 nondefdecl->set_type(class_type);
12029#if DEBUG_CLASS_DECLARATION
12030 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());
12031#endif
12032 SgClassDeclaration* tmp_classDeclarationFromType = isSgClassDeclaration(class_type->get_declaration());
12033 ROSE_ASSERT(tmp_classDeclarationFromType != NULL);
12034#if DEBUG_CLASS_DECLARATION
12035 SgScopeStatement* scope = tmp_classDeclarationFromType->get_scope();
12036 printf ("tmp_classDeclarationFromType: scope = %p = %s \n",scope,scope->class_name().c_str());
12037 printf ("tmp_classDeclarationFromType = %p = %s \n",tmp_classDeclarationFromType,tmp_classDeclarationFromType->class_name().c_str());
12038 printf ("tmp_classDeclarationFromType name = %s \n",tmp_classDeclarationFromType->get_name().str());
12039 if (tmp_classDeclarationFromType->get_file_info() != NULL)
12040 {
12041 tmp_classDeclarationFromType->get_file_info()->display("tmp_classDeclarationFromType: debug");
12042 }
12043#endif
12044 }
12045
12046 // DQ (3/22/2012): Added assertions.
12047 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12048 if (nondefdecl->get_type()->get_declaration() != nondefdecl)
12049 {
12050 printf ("ERROR: nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
12051 printf ("ERROR: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12052 printf ("ERROR: nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
12053
12054 SgClassDeclaration* classDeclarationFromType = isSgClassDeclaration(nondefdecl->get_type()->get_declaration());
12055 ROSE_ASSERT(classDeclarationFromType != NULL);
12056
12057 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
12058 printf ("nondefdecl->get_type()->get_name() = %s \n",nondefdecl->get_type()->get_name().str());
12059 printf ("nondefdecl->get_type()->get_declaration()->get_name() = %s \n",classDeclarationFromType->get_name().str());
12060
12061 printf ("nondefdecl->get_mangled_name() = %s \n",nondefdecl->get_mangled_name().getString().c_str());
12062 printf ("nondefdecl->get_type()->get_mangled() = %s \n",nondefdecl->get_type()->get_mangled().getString().c_str());
12063 printf ("nondefdecl->get_type()->get_declaration()->get_mangled_name() = %s \n",classDeclarationFromType->get_mangled_name().getString().c_str());
12064
12065 // DQ (12/27/2018): Added additional debugging support.
12066 printf ("nondefdecl->get_type()->get_declaration()->get_firstNondefiningDeclaration() = %s \n",classDeclarationFromType->get_firstNondefiningDeclaration() ? "true" : "false");
12067 printf ("nondefdecl->get_firstNondefiningDeclaration() = %s \n",nondefdecl->get_firstNondefiningDeclaration() ? "true" : "false");
12068
12069 // 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.
12070 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
12071 {
12072 SgNode* parent = nondefdecl->get_parent();
12073 if (parent != NULL)
12074 {
12075 printf ("nondefdecl->get_parent() = %p = %s \n",parent,parent->class_name().c_str());
12076 }
12077 }
12078
12079 // DQ (12/27/2018): Activate this debugging support.
12080#if DEBUG_CLASS_DECLARATION
12081 nondefdecl->get_type()->get_declaration()->get_file_info()->display("nondefdecl->get_type()->get_declaration()");
12082
12083 // DQ (7/24/2017): Added more debug information to support debugging test2014_187.C.
12084 // Note that this can be caught as an error if the class declaration was built in the code above when
12085 // the symbol was not found. But if the nondefdecl->get_type()->get_declaration() == nondefdecl,
12086 // then this branch will not be taken (which is simply debugging information to assert that
12087 // nondefdecl->get_type()->get_declaration() == nondefdecl is true (below).
12088 if (nondefdecl->get_file_info() == NULL)
12089 {
12090 printf ("ERROR: In SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p = %s does not have its source position information setup \n",nondefdecl,nondefdecl->class_name().c_str());
12091 printf (" --- nondefdecl = %s \n",nondefdecl->get_name().str());
12092 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p \n",nondefdecl->get_firstNondefiningDeclaration());
12093 printf (" --- nondefdecl->get_definingDeclaration() = %p \n",nondefdecl->get_definingDeclaration());
12094 printf (" --- nondefdecl->get_type() = %p \n",nondefdecl->get_type());
12095 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
12096 printf ("The real error is: (nondefdecl->get_type()->get_declaration() != nondefdecl) \n");
12097 }
12098 else
12099 {
12100 ROSE_ASSERT(nondefdecl->get_file_info() != NULL);
12101 nondefdecl->get_file_info()->display("nondefdecl");
12102 }
12103#endif
12104 }
12105 ROSE_ASSERT(nondefdecl->get_type()->get_declaration() == nondefdecl);
12106
12107#if 0
12108 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());
12109#endif
12110
12111 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
12112
12113 // The nondefining declaration will not appear in the source code, but is compiler
12114 // generated (so we have something about the class that we can reference; e.g in
12115 // types). At the moment we make it a transformation, there might be another kind
12116 // of source position that would be more precise. FIXME.
12117 // setOneSourcePositionNull(nondefdecl);
12119 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
12120
12121#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
12122 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
12124 {
12125 detectTransformations(nondefdecl);
12126 }
12127#endif
12128 // DQ (6/6/2012): This has to be set before we generate the type.
12129 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12130
12131 // DQ (3/15/2012): This is now set below.
12132 // nondefdecl->set_definingDeclaration(defdecl);
12133 nondefdecl->setForward();
12134
12135 // 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).
12136 // Liao, 9/2/2009. scope stack is optional, it can be empty
12137 // nondefdecl->set_parent(topScopeStack());
12138#if 0
12139 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");
12140#endif
12141 // nondefdecl->set_parent(scope);
12142 // defdecl->set_parent(scope);
12143
12144 if (scope != NULL)
12145 {
12146 mysymbol = new SgClassSymbol(nondefdecl);
12147#if 0
12148 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());
12149#endif
12150 // scope->insert_symbol(name, mysymbol);
12151 scope->insert_symbol(nameWithTemplateArguments, mysymbol);
12152
12153 // DQ (11/21/2013): Added test based on debugging session with Philippe.
12154 ROSE_ASSERT(nondefdecl->get_scope() == scope);
12155 }
12156 else
12157 {
12158 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unkown.
12159 // DQ (1/26/2009): I think this should be an error, but that appears it would
12160 // break the existing interface. Need to discuss this with Liao.
12161 printf ("Warning: no scope provided to support symbol table entry! \n");
12162 }
12163
12164 // DQ (7/31/2019): Check that the parent is set if this was used a the declaration referenced by a symbol.
12165 // ROSE_ASSERT (nondefdecl->get_parent() != NULL);
12166 }
12167
12168 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
12169
12170#if 1
12171 // Refactored this code.
12172 testTemplateArgumentParents(nondefdecl);
12173#else
12174 if (buildTemplateInstantiation == true)
12175 {
12176 // DQ (7/25/2012): Added this code here to reset the parents of the template arguments.
12177 for (size_t i = 0; i < templateArgumentsList->size(); i++)
12178 {
12179 // DQ (7/25/2012): This should be true because the template argument was set to the functions
12180 // scope so that the name with template arguments could be computed (with name qualification).
12181 ROSE_ASSERT((*templateArgumentsList)[i]->get_parent() != NULL);
12182
12183#error "DEAD CODE!"
12184
12185 // ROSE_ASSERT(isSgGlobal(templateArgumentsList[i]->get_parent()) == NULL);
12186 // ROSE_ASSERT(templateArgumentsList[i]->get_parent() == nondefining_templateInstantiation);
12187
12188 // Be we want to reset it to be the function (now that it is available, because this is more precise).
12189 // All qualified names should compute to the same qualified name (if not then it is a bug in the name
12190 // qualification mechanism).
12191 (*templateArgumentsList)[i]->set_parent(nondefdecl);
12192 }
12193 }
12194#endif
12195
12196 // DQ (3/15/2012): I hhava moved construction of defining declaration to be AFTER the nondefining declaration!
12197 // This is a better organization ans also should make sure that the declaration in the SgClassType will
12198 // properly reference the firstNondefiningDeclaration (instead of the defining declaration).
12199
12200 // step 1 (now step 2). Build defining declaration
12201 // SgClassDefinition* classDef = buildClassDefinition();
12202 SgClassDefinition* classDef = buildClassDefinition(NULL,buildTemplateInstantiation);
12203
12204 // DQ (11/26/2011): Debugging EDG 3.3 use of templateArguments.
12205#if 0
12206 printf ("Building a SgClassDeclaration: buildClassDeclaration_nfi() buildTemplateInstantiation = %s \n",buildTemplateInstantiation ? "true:" : "false");
12207#endif
12208
12209 // SgClassDeclaration* defdecl = new SgClassDeclaration (name,kind,NULL,classDef);
12210 SgClassDeclaration* defdecl = NULL;
12211 if (buildTemplateInstantiation == true)
12212 {
12213 // This adds: SgTemplateDeclaration *templateDeclaration and SgTemplateArgumentPtrList templateArguments
12214 SgTemplateArgumentPtrList emptyList;
12215 // defdecl = new SgTemplateInstantiationDecl (name,kind,NULL,classDef,NULL,emptyList);
12216 defdecl = new SgTemplateInstantiationDecl (nameWithTemplateArguments,kind,NULL,classDef,NULL,emptyList);
12217
12218 // DQ (2/27/2018): Added assertion now that we have implemented more consistant semantics
12219 // for template instantiations (types are not generated in the constructor calls).
12220 ROSE_ASSERT(defdecl->get_type() == NULL);
12221 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl) != NULL);
12222#if 0
12223 printf ("In buildClassDeclaration_nfi(): defdecl->get_name() = %s defdecl->get_templateName() = %s \n",defdecl->get_name().str(),isSgTemplateInstantiationDecl(defdecl)->get_templateName().str());
12224#endif
12225 // DQ (1/1/2012): Added support for setting the template name (I think this should be fixed in the constructor).
12226 // It can't be fixed in the constructor since it has to be set after construction (or passed in explicitly).
12227 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().is_null() == true);
12228
12229#if 0
12230 printf ("Warning: In buildClassDeclaration_nfi(): calling set_templateName(name = %s) for defining declaration \n",name.str());
12231#if 0
12232 // isSgTemplateInstantiationDecl(defdecl)->set_templateName(name);
12233 // isSgTemplateInstantiationDecl(defdecl)->set_templateName("SETME_DEFINING_DECL<>");
12234 isSgTemplateInstantiationDecl(defdecl)->set_templateName(name);
12235
12236#error "DEAD CODE!"
12237
12238 // DQ (5/31/2012): Find locations where this is set and include template syntax.
12239 ROSE_ASSERT(name.getString().find('<') == string::npos);
12240#else
12241 // DQ (6/1/2012): Make sure that the templateName is set and they it does not include the template syntax.
12242 SgName templateName = generateTemplateNameFromTemplateNameWithTemplateArguments(name);
12243 printf ("In buildClassDeclaration_nfi(): templateName = %s \n",templateName.str());
12244 isSgTemplateInstantiationDecl(defdecl)->set_templateName(templateName);
12245
12246#error "DEAD CODE!"
12247
12248 // DQ (5/31/2012): Find locations where this is set and include template syntax.
12249 // ROSE_ASSERT(templateName.getString().find('<') == string::npos);
12250 ROSE_ASSERT(hasTemplateSyntax(templateName) == false);
12251
12252 // DQ (6/1/2012): Not clear if this is always true (for all template instantations).
12253 // ROSE_ASSERT(name.getString().find('<') != string::npos);
12254 ROSE_ASSERT(hasTemplateSyntax(name) == true);
12255#endif
12256#else
12257#if 0
12258 printf ("In buildClassDeclaration_nfi(): nameWithoutTemplateArguments = %s nameWithTemplateArguments = %s \n",nameWithoutTemplateArguments.str(),nameWithTemplateArguments.str());
12259#endif
12260 isSgTemplateInstantiationDecl(defdecl)->set_templateName(nameWithoutTemplateArguments);
12261
12262#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12263 // DQ (5/8/2013): This fails for test2013_159.C, and it appears that we have been overly restrictive here.
12264 if (hasTemplateSyntax(nameWithTemplateArguments) == false)
12265 {
12266 printf ("WARNING: In buildClassDeclaration_nfi(): nameWithTemplateArguments = %s is not using template syntax \n",nameWithTemplateArguments.str());
12267 }
12268#endif
12269 // ROSE_ASSERT(hasTemplateSyntax(nameWithTemplateArguments) == true);
12270
12271 // DQ (7/27/2012): This fails for test2005_35.C where conversion operators are seen.
12272 // ROSE_ASSERT(hasTemplateSyntax(nameWithoutTemplateArguments) == false);
12273#endif
12274
12275 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().is_null() == false);
12276
12277 // DQ (3/22/2012): Make sure there is template syntax present.
12278 if (isSgTemplateInstantiationDecl(defdecl)->get_templateName().getString().find('>') == string::npos)
12279 {
12280#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12281 printf ("WARNING: No template syntax present in name of template class instantiation (defdecl) \n");
12282#endif
12283 }
12284 // ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().getString().find('>') != string::npos);
12285#if 0
12286 printf ("Should we have set the template instantiation name at this point? \n");
12287 ROSE_ABORT();
12288#endif
12289 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
12290 ROSE_ASSERT(defdecl->get_definition() != NULL);
12291 ROSE_ASSERT(isSgTemplateInstantiationDefn(defdecl->get_definition()) != NULL);
12292 }
12293 else
12294 {
12295#if 0
12296 printf ("Building a SgClassDeclaration, but we might require a SgTemplateClassDeclaration \n");
12297#endif
12298 // defdecl = new SgClassDeclaration (name,kind,NULL,classDef);
12299 // defdecl = new SgClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
12300
12301 // DQ (10/11/2015): Try to build a matching SgTemplateClassDeclaration. The problem with this fix is that
12302 // I would prefer that the other function be called instead. We might still want to implementat that instead.
12303 if (buildTemplateDeclaration == true)
12304 {
12305 printf ("In buildClassDeclaration_nfi(): I think we also want template specialization arguments to be more general: using nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
12306
12307 // = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,classType,(SgClassDefinition*)NULL);
12308 defdecl = new SgTemplateClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
12309
12310 // DQ (2/27/2018): We should be able to enforce this, it should have always been true.
12311 ROSE_ASSERT(defdecl->get_type() == NULL);
12312#if 0
12313 printf ("Exiting afte test! \n");
12314 ROSE_ABORT();
12315#endif
12316 }
12317 else
12318 {
12319 defdecl = new SgClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
12320
12321#if 0
12322 // DQ (12/22/2019): Debugging the case of shared class declarations between multiple files referencing the same defining declaration.
12323 printf ("In SageBuilder::buildClassDeclaration_nfi(): build a SgClassDeclaration: defdecl = %p \n",defdecl);
12324#endif
12325
12326 // DQ (2/27/2018): We should be able to enforce this, it should have always been true.
12327 ROSE_ASSERT(defdecl->get_type() == NULL);
12328 }
12329
12330 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
12331 ROSE_ASSERT(defdecl->get_definition() != NULL);
12332 ROSE_ASSERT(isSgTemplateInstantiationDefn(defdecl->get_definition()) == NULL);
12333 }
12334 ROSE_ASSERT(defdecl != NULL);
12335
12336#if 0
12337 printf ("In buildClassDeclaration_nfi(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
12338#endif
12339
12340 // DQ (3/15/2012): Moved from original location above...
12341 nondefdecl->set_definingDeclaration(defdecl);
12342
12343 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
12344 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
12345
12346 // printf ("SageBuilder::buildClassDeclaration_nfi(): defdecl = %p \n",defdecl);
12347
12349 // constructor is side-effect free
12350 classDef->set_declaration(defdecl);
12351 defdecl->set_definingDeclaration(defdecl);
12352
12353 testTemplateArgumentParents(nondefdecl);
12355
12356 // setOneSourcePositionForTransformation(nondefdecl);
12357 //
12358 // Liao 1/18/2011, I changed the semantics of setOneSourcePositionNull to set file_info to null regardless the existence of
12359 // file_info of the input node.
12360 // We do want to keep the file_info of nodefdecl if it is set already as compiler generated.
12361 // setOneSourcePositionNull(nondefdecl);
12362
12363 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12364 // nondefdecl->set_definingDeclaration(defdecl);
12365 defdecl->set_firstNondefiningDeclaration(nondefdecl);
12366
12367 if (buildTemplateInstantiation == true)
12368 {
12369 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
12370 setTemplateArgumentsInDeclaration(defdecl,templateArgumentsList);
12371 }
12372
12373 // DQ (3/22/2012): I think we can assert this.
12374 ROSE_ASSERT(defdecl->get_type() == NULL);
12375
12376 // Liao, 10/30/2009
12377 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
12378 // This is not desired when building a defining declaration and an inefficience in the constructor
12379 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
12380 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
12381 if (defdecl->get_type() != NULL)
12382 {
12383 // if a defining class declaration's type is associated with a defining class.
12384 // This is a wrong SgClassType and has to be reset
12385 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl))
12386 {
12387 // DQ (3/21/2012): Added this test.
12388 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12389
12390 // DQ (3/15/2012): Make this conditional upon the types not already being equal.
12391 if (nondefdecl->get_type() != defdecl->get_type())
12392 {
12393#if 0
12394 printf ("Deleting defdecl->get_type() = %p = %s (using type from nondefdecl = %p) \n",defdecl->get_type(),defdecl->get_type()->class_name().c_str(),nondefdecl);
12395 printf ("Skipping delete of %p to maintain unique type pointers \n",defdecl->get_type());
12396#else
12397 delete defdecl->get_type();
12398#endif
12399 // DQ (3/15/2012): This will be reset below.
12400 defdecl->set_type(NULL);
12401#if 0
12402 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());
12403#endif
12404#if 0
12405 // DQ (12/13/2011): Is this executed...
12406 printf ("Is this executed! \n");
12407 ROSE_ABORT();
12408#endif
12409 // DQ (3/21/2012): set the types to be the same type.
12410 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12411 defdecl->set_type(nondefdecl->get_type());
12412#if 0
12413 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());
12414#endif
12415 // DQ (3/21/2012): Added these checks...
12416 SgClassType* classType = nondefdecl->get_type();
12417 ROSE_ASSERT(classType != NULL);
12418 SgClassDeclaration* local_classDeclaration = isSgClassDeclaration(classType->get_declaration());
12419 ROSE_ASSERT (local_classDeclaration != NULL);
12420 printf ("In buildClassDeclaration_nfi(): classType = %p local_classDeclaration = %p \n",classType,local_classDeclaration);
12421 ROSE_ASSERT (local_classDeclaration->get_firstNondefiningDeclaration() != NULL);
12422 ROSE_ASSERT (local_classDeclaration->get_firstNondefiningDeclaration() == local_classDeclaration);
12423 }
12424 }
12425 }
12426 else
12427 {
12428 // DQ (3/15/2012): Make sure that both the defining and non-defining declarations use the same type.
12429 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12430 defdecl->set_type(nondefdecl->get_type());
12431#if 0
12432 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());
12433#endif
12434
12435 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
12436#if 0
12437 // DQ (11/20/2017): Commented out output spew.
12438 // DQ (2/28/2015): This test is failing in the new application support for templates within the testRoseHeaders_01.C.
12439 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()))
12440 {
12441 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");
12442 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12443 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
12444 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
12445 }
12446 // DQ (7/22/2017): Uncomment this test to better understand why this is a new issue (after two years).
12447 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
12448#endif
12449#if 0
12450 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
12451#endif
12452 }
12453
12454 // DQ (9/4/2012): Added assertion.
12455 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12456
12457 // patch up the SgClassType for the defining class declaration
12458 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12459 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
12460#if 0
12461 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl))
12462 {
12463 printf ("nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
12464 printf ("nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12465 printf ("nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
12466 printf ("nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
12467 }
12468#endif
12469 // ROSE_ASSERT (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl));
12470 ROSE_ASSERT (defdecl->get_type() != NULL);
12471 ROSE_ASSERT (defdecl->get_type()->get_declaration() != NULL);
12472 ROSE_ASSERT (defdecl->get_type()->get_declaration() != isSgDeclarationStatement(defdecl));
12473 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
12474 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
12475#if 0
12476 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
12477#else
12478
12479#if 0
12480 // DQ (11/20/2017): Commented out output spew.
12481 // DQ (2/28/2015): This test is failing in the new application support for templates within the testRoseHeaders_01.C.
12482 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()))
12483 {
12484 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");
12485 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12486 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
12487 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
12488 }
12489 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
12490 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl))
12491 {
12492 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");
12493 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
12494 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
12495 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
12496 }
12497 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
12498#endif
12499
12500#endif
12501
12502 // DQ (9/4/2012): Added assertion.
12503 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12504
12505 // This appears to be redundant...is it?
12506 defdecl->set_type(nondefdecl->get_type());
12507
12508#if 0
12509 printf ("In buildClassDeclaration_nfi(): after calling set_type() again: defdecl = %p = %s defdecl->get_type() = %p = %s \n",
12510 defdecl,defdecl->class_name().c_str(),defdecl->get_type(),defdecl->get_type()->class_name().c_str());
12511#endif
12512
12513 // DQ (9/4/2012): Added assertion.
12514 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12515
12516 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
12517 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
12518 // used in a defining declaration).
12519 nondefdecl->setForward();
12520
12521 if (scope != NULL) // put into fixStructDeclaration() or alike later on
12522 {
12523 // DQ (9/4/2012): Added assertion.
12524 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12525
12526 // Note, this function sets the parent to be the scope if it is not already set.
12527 fixStructDeclaration(defdecl,scope);
12528
12529 // DQ (9/4/2012): Added assertion.
12530 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12531
12532 fixStructDeclaration(nondefdecl,scope);
12533
12534 // DQ (9/4/2012): Added assertion.
12535 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
12536
12537#if 0
12538 SgClassSymbol* mysymbol = new SgClassSymbol(nondefdecl);
12539 ROSE_ASSERT(mysymbol);
12540 scope->insert_symbol(name, mysymbol);
12541 printf ("@@@@@@@@@@@@@@ In buildClassDeclaration_nfi(): setting scope of defining and non-defining declaration to scope = %s \n",scope->class_name().c_str());
12542 defdecl->set_scope(scope);
12543 nondefdecl->set_scope(scope);
12544
12545 // defdecl->set_parent(scope);
12546
12547 // Liao, 9/2/2009. merged into fixStructDeclaration
12548 // 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).
12549 nondefdecl->set_parent(scope);
12550 // nondefdecl->set_parent(topScopeStack());
12551 // Liao, 9/2/2009. scope stack is optional, it can be empty
12552 defdecl->set_parent(scope);
12553 // defdecl->set_parent(topScopeStack());
12554#endif
12555 }
12556
12557 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
12558 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
12559 // ROSE_ASSERT(defdecl->get_parent() != NULL);
12560
12561 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
12562
12563 // DQ (2/27/2012): Tracking down where parents are not set correctly (class declaration in typedef is incorrectly set to SgGlobal).
12564 ROSE_ASSERT(defdecl->get_parent() == NULL);
12565
12566 // DQ (2/29/2012): We can't assert this (fails for test2012_09.C).
12567 // ROSE_ASSERT(nondefdecl->get_parent() == NULL);
12568
12569 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
12570 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
12571
12572 testTemplateArgumentParents(nondefdecl);
12574
12575 // DQ (3/8/2018): Added for debugging.
12576 SgClassDeclaration* temp_firstNondefiningDeclaration = isSgClassDeclaration(defdecl->get_firstNondefiningDeclaration());
12577 SgClassDeclaration* temp_definingDeclaration = isSgClassDeclaration(defdecl->get_definingDeclaration());
12578 ROSE_ASSERT(temp_firstNondefiningDeclaration != NULL);
12579 ROSE_ASSERT(temp_definingDeclaration != NULL);
12580
12581#if 0
12582 printf ("Leaving buildClassDeclaration_nfi(): defdecl = %p = %s = %s \n",defdecl,defdecl->class_name().c_str(),defdecl->get_name().str());
12583 printf (" --- defdecl->get_firstNondefiningDeclaration() = %p \n",defdecl->get_firstNondefiningDeclaration());
12584 printf (" --- defdecl->get_definingDeclaration() = %p \n",defdecl->get_definingDeclaration());
12585
12586 printf (" --- defdecl->get_firstNondefiningDeclaration()->get_name() = %s \n",temp_firstNondefiningDeclaration->get_name().str());
12587 printf (" --- defdecl->get_definingDeclaration()->get_name() = %s \n",temp_definingDeclaration->get_name().str());
12588
12589 printf (" --- defdecl->get_firstNondefiningDeclaration()->get_type() = %p = %s \n",
12590 temp_firstNondefiningDeclaration->get_type(),temp_firstNondefiningDeclaration->get_type()->unparseToString().c_str());
12591 printf (" --- defdecl->get_definingDeclaration()->get_type() = %p = %s \n",
12592 temp_definingDeclaration->get_type(),temp_definingDeclaration->get_type()->unparseToString().c_str());
12593
12594 printf (" --- nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
12595 printf (" --- nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
12596
12597#if 0
12598 printf ("Leaving buildClassDeclaration_nfi(): defdecl: unparseNameToString() = %s \n",defdecl->unparseNameToString().c_str());
12599#endif
12600#endif
12601
12602 // DQ (3/8/2018): Added assertion.
12603 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_name() == temp_definingDeclaration->get_name());
12604 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_type() == temp_definingDeclaration->get_type());
12605
12606 // DQ (3/7/2015): Only in EDG 4.7 does the defining declaration not have a valid templateDeclaration pointer (sometimes).
12607 SgTemplateInstantiationDecl* nondefiningDeclaration = isSgTemplateInstantiationDecl(defdecl->get_firstNondefiningDeclaration());
12608 SgTemplateInstantiationDecl* definingDeclaration = isSgTemplateInstantiationDecl(defdecl->get_definingDeclaration());
12609 if (definingDeclaration != NULL && nondefiningDeclaration != NULL)
12610 {
12611 SgTemplateClassDeclaration* templateDeclaration = nondefiningDeclaration->get_templateDeclaration();
12612 if (templateDeclaration != NULL && definingDeclaration->get_templateDeclaration() == NULL)
12613 {
12614#if 0
12615 printf ("NOTE: buildClassDeclaration_nfi(): Setting the templateDeclaration for the defining declaration = %p using the value = %p from the nondefiningDeclaration = %p \n",
12616 definingDeclaration,templateDeclaration,nondefiningDeclaration);
12617#endif
12618 definingDeclaration->set_templateDeclaration(templateDeclaration);
12619
12620 ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
12621 }
12622 // ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
12623 }
12624
12625 // DQ (3/7/2015): Only in EDG 4.7 does the defining declaration not have a valid templateDeclaration pointer (sometimes).
12626 if (definingDeclaration != NULL)
12627 {
12628 if (definingDeclaration->get_templateDeclaration() == NULL)
12629 {
12630#if 0
12631 printf ("NOTE: buildClassDeclaration_nfi(): definingDeclaration->get_templateDeclaration() == NULL \n");
12632#endif
12633 }
12634 // ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
12635 }
12636
12637#if 0
12638 printf ("Leaving buildClassDeclaration_nfi(): defdecl = %p defdecl->unparseNameToString() = %s \n",defdecl,defdecl->unparseNameToString().c_str());
12639#endif
12640
12641#if 0
12642 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12643 printf ("Leaving buildClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
12644 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
12645
12646 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12647 printf ("Leaving buildClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
12648 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
12649#endif
12650
12651 return defdecl;
12652 }
12653
12654
12656 {
12657 SgName myname(name);
12658 return buildStructDeclaration(myname, scope);
12659 }
12660
12662 {
12663 SgName myname(name);
12664 return buildStructDeclaration(myname, scope);
12665 }
12666
12667
12668#if 0
12669// DQ (11/19/2011): Added more uniform support for building class declarations.
12672 {
12673 ROSE_ASSERT(scope != NULL);
12674 SgTemplateClassDeclaration* definingClassDeclaration = buildDefiningTemplateClassDeclaration(name,scope);
12675 ROSE_ASSERT(definingClassDeclaration != NULL);
12676
12677 return definingClassDeclaration;
12678 }
12679#endif
12680
12681
12684 {
12685 SgTemplateClassDefinition* result = NULL;
12686 if (d != NULL) // the constructor does not check for NULL d, causing segmentation fault
12687 {
12688 result = new SgTemplateClassDefinition(d);
12689 // result->set_parent(d); // set_declaration() == set_parent() in this case
12690 }
12691 else
12692 {
12693 result = new SgTemplateClassDefinition();
12694 }
12695
12696 ROSE_ASSERT(result);
12697
12698 // CR (3/22/2020): Fixed setting case insensitivity
12699 // if (symbol_table_case_insensitive_semantics == true)
12701 result->setCaseInsensitive(true);
12702
12704 return result;
12705 }
12706
12708SageBuilder::buildNondefiningTemplateClassDeclaration(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12709{
12710 SgTemplateClassDeclaration* res = buildNondefiningTemplateClassDeclaration_nfi (XXX_name, kind, scope, templateParameterList, templateSpecializationArgumentList);
12712 return res;
12713}
12714
12715// SgTemplateClassDeclaration * SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(const SgName& name, SgClassDeclaration::class_types kind, SgScopeStatement* scope )
12717SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12718 {
12719#if 0
12720 printf("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(XXX_name = %p):\n", XXX_name.str());
12721#endif
12722
12723 if (scope == NULL)
12725
12726 // DQ (11/20/2011): This is for initial debugging only.
12727 ROSE_ASSERT(scope != NULL);
12728
12729#if 0
12730 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): XXX_name = %s scope = %p = %s \n",XXX_name.str(),scope,scope->class_name().c_str());
12731#endif
12732
12733 // 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.
12734 SgName nameWithoutTemplateArguments = XXX_name;
12735 SgName nameWithTemplateSpecializationArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateSpecializationArgumentList);
12736
12737#if 0
12738 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
12739#endif
12740
12741 // SgTemplateClassDeclaration::class_types template_class_kind = SgTemplateClassDeclaration::e_class;
12742
12743 // Step 2. build the nondefining declaration,
12744 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
12745
12746 // Get the nondefining declaration from the symbol if it has been built (if this works,
12747 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
12748 SgTemplateClassDeclaration* nondefdecl = NULL;
12749
12750 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
12751 // ROSE_ASSERT(scope != NULL);
12752
12753 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12754 // SgTemplateSymbol* mysymbol = NULL;
12755 SgClassSymbol* mysymbol = NULL;
12756
12757 if (scope != NULL)
12758 {
12759 // DQ (9/12/2012): We want to include the template specialization into the name where it is required (this handling
12760 // is similar to normal template arguments for non-template declaration, but different than template parameters).
12761 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12762 // mysymbol = scope->lookup_template_symbol(name);
12763 // mysymbol = scope->lookup_class_symbol(name);
12764 // mysymbol = scope->lookup_template_class_symbol(name);
12765 // mysymbol = scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList);
12766 mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
12767 }
12768 else
12769 {
12770 // Liao 9/2/2009: This is not an error. We support bottom-up AST construction and scope can be unknown.
12771 // DQ (1/26/2009): I think this should be an error, but that appears it would
12772 // break the existing interface. Need to discuss this with Liao.
12773 printf ("Warning: In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): scope == NULL \n");
12774 }
12775#if 0
12776 printf ("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
12777#endif
12778
12779 if (mysymbol != NULL) // set links if nondefining declaration already exists.
12780 {
12781 // DQ (3/7/2012): Build a seperate non-defining declaration (reusing the existing one will cause the test for unique statements to fail).
12782 // 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");
12783 // nondefdecl = isSgTemplateClassDeclaration(mysymbol->get_declaration());
12784 SgClassType* classType = isSgClassType(mysymbol->get_type());
12785 ROSE_ASSERT(classType != NULL);
12786
12787 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12788 // nondefdecl = new SgTemplateClassDeclaration(name,kind,classType,(SgClassDefinition*)NULL);
12789 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,classType,(SgClassDefinition*)NULL);
12790
12791#if 0
12792 // DQ (3/4/2018): relax this requirement for SgTemplateInstantiationClassDeclaration.
12793 // DQ (2/27/2018): Enforce that this is not already set (should be set after the constructor to
12794 // simplify how derived classes (e.g. SgTemplateInstantiationClassDeclaration statements) work.
12795 if (nondefdecl->get_type() != NULL)
12796 {
12797 printf ("Note: SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): nondefdecl->get_type() != NULL: name = %s \n",nondefdecl->get_name().str());
12798 }
12799 // ROSE_ASSERT(nondefdecl->get_type() == NULL);
12800#endif
12801
12802 ROSE_ASSERT(nondefdecl != NULL);
12803
12804 // DQ (9/10/2012): Initialize the template parameter list.
12805 ROSE_ASSERT(templateParameterList != NULL);
12806 nondefdecl->get_templateParameters() = *templateParameterList;
12807
12808 // DQ (9/16/2012): Moved this initialization of firstNondefiningDeclaration from farther down in this branch (and added assertion).
12809 nondefdecl->set_firstNondefiningDeclaration(mysymbol->get_declaration());
12810 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
12811
12812 // TV (04/12/2018): Add a scope for nonreal classes (and their member) on the first non-defining declaration of template classes
12813 if (nondefdecl == nondefdecl->get_firstNondefiningDeclaration()) {
12814 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
12815
12816 nonreal_decl_scope->set_parent(nondefdecl);
12817 nondefdecl->set_nonreal_decl_scope(nonreal_decl_scope);
12818
12819 SageInterface::setSourcePosition(nonreal_decl_scope);
12820 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
12821 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
12822#if 0
12823 printf("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(XXX_name = %p): nrscope = %p (new)\n", XXX_name.str(), nonreal_decl_scope);
12824#endif
12825 }
12826
12827#if 1
12828 // DQ (9/16/2012): This newly refactored function can only be called after firstNondefiningDeclaration is set.
12829 // This also sets the template argument parents to the firstNondefiningDeclaration.
12830 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
12831#else
12832 // DQ (9/12/2012): Adding support for template specialization.
12833 ROSE_ASSERT(templateSpecializationArgumentList != NULL);
12834 nondefdecl->get_templateSpecializationArguments() = *templateSpecializationArgumentList;
12835#endif
12836 // DQ (9/10/2012): Test the just built template with its template parameters.
12837 if (nondefdecl->get_templateParameters().size() == 0)
12838 {
12839#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12840 printf ("WARNING: In buildNondefiningTemplateClassDeclaration_nfi(): (part 1) nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
12841#endif
12842 }
12843 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12844
12845 // DQ (3/7/2012): We want this to be set later, so we can't test it here.
12846 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
12847#if 0
12848 nondefdecl->set_definingDeclaration(defdecl);
12849
12850 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
12851 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
12852#endif
12853 // DQ (3/7/2012): But always refer to the first non-defining declaration so it will be unique (and set the scope).
12854 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
12855 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != nondefdecl);
12856 nondefdecl->set_scope(scope);
12857 nondefdecl->setForward();
12858
12859 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12860 nondefdecl->set_templateName(nameWithoutTemplateArguments);
12861
12862 testTemplateArgumentParents(nondefdecl);
12863 }
12864 else // build a nondefnining declaration if it does not exist
12865 {
12866 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,(SgClassType*)NULL,(SgClassDefinition*)NULL);
12867 ROSE_ASSERT(nondefdecl != NULL);
12868
12869 // DQ (9/10/2012): Initialize the template parameter list.
12870 ROSE_ASSERT(templateParameterList != NULL);
12871 nondefdecl->get_templateParameters() = *templateParameterList;
12872
12873 // DQ (9/16/2012): Moved this initialization of firstNondefiningDeclaration from farther down in this branch.
12874 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12875
12876 // DQ (9/16/2012): This newly refactored function can only be called after firstNondefiningDeclaration is set.
12877 // This also sets the template argument parents to the firstNondefiningDeclaration.
12878 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
12879
12880 // DQ (9/10/2012): Test the just built template with its template parameters.
12881 if (nondefdecl->get_templateParameters().size() == 0)
12882 {
12883#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12884 printf ("WARNING: In buildNondefiningTemplateClassDeclaration_nfi(): (part 2) nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
12885#endif
12886 }
12887 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12888
12889 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12890 nondefdecl->set_templateName(nameWithoutTemplateArguments);
12891
12892#if 0
12893 // DQ (12/4/2011): Now we want to enable this so that the SgClassType will be available from a SgTemplateClassDeclaration.
12894 if (nondefdecl->get_type() == NULL)
12895 {
12896 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
12897 // nondefdecl->set_type(NULL);
12898 // nondefdecl->set_type(SgTemplateType::createType(nondefdecl));
12899 // nondefdecl->set_type(SgTemplateType::createType());
12900 nondefdecl->set_type(SgClassType::createType(nondefdecl));
12901 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12902 }
12903#endif
12904 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
12905
12906 // The nondefining declaration will not appear in the source code, but is compiler
12907 // generated (so we have something about the class that we can reference; e.g in
12908 // types). At the moment we make it a transformation, there might be another kind
12909 // of source position that would be more precise. FIXME.
12910 // setOneSourcePositionNull(nondefdecl);
12912 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
12913
12914 // nondefdecl->set_definingDeclaration(defdecl);
12915 nondefdecl->setForward();
12916
12917 // Liao, 9/2/2009. scope stack is optional, it can be empty
12918 // nondefdecl->set_parent(topScopeStack());
12919#if 0
12920 printf ("In buildNondefiningTemplateClassDeclaration_nfi(): Commented out setting the parent to the scope. \n");
12921#endif
12922 // printf ("Note that for C++, the parent may not be the same as the scope (dangerous code). \n");
12923 // nondefdecl->set_parent(scope);
12924
12925 nondefdecl->set_scope(scope);
12926
12927#if 1
12928 // DQ (12/4/2011): Set the scope first and then set the type (scope is required to compute the type (name mangling)).
12929 // DQ (12/4/2011): Now we want to enable this so that the SgClassType will be available from a SgTemplateClassDeclaration.
12930 if (nondefdecl->get_type() == NULL)
12931 {
12932 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
12933 // nondefdecl->set_type(NULL);
12934 // nondefdecl->set_type(SgTemplateType::createType(nondefdecl));
12935 // nondefdecl->set_type(SgTemplateType::createType());
12936 nondefdecl->set_type(SgClassType::createType(nondefdecl));
12937 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12938#if 0
12939 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());
12940#endif
12941 }
12942#endif
12943
12944 // Build a SgTemplateClassSymbol and put it into the specified scope.
12945 if (scope != NULL)
12946 {
12947#if 0
12948 printf ("Building a SgTemplateSymbol using nameWithTemplateSpecializationArguments = %s and nondefdecl = %p = %s \n",nameWithTemplateSpecializationArguments.str(),nondefdecl,nondefdecl->class_name().c_str());
12949#endif
12950 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12951 // mysymbol = new SgTemplateSymbol(nondefdecl);
12952 // mysymbol = new SgClassSymbol(nondefdecl);
12953 mysymbol = new SgTemplateClassSymbol(nondefdecl);
12954 ROSE_ASSERT(mysymbol != NULL);
12955
12956 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12957 // DQ (3/6/2012): Added test for existing symbol (see test2012_18.C).
12958 // ROSE_ASSERT(scope->lookup_template_class_symbol(name) == NULL);
12959 // ROSE_ASSERT(scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList) == NULL);
12960 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList) == NULL);
12961
12962 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12963 // scope->insert_symbol(name, mysymbol);
12964 scope->insert_symbol(nameWithTemplateSpecializationArguments, mysymbol);
12965#if 0
12966 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi() (after building symbol): scope = %p = %s \n",scope,scope->class_name().c_str());
12967#endif
12968 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
12969
12970 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
12971
12972 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12973 // ROSE_ASSERT(scope->lookup_template_class_symbol(name) != NULL);
12974 // ROSE_ASSERT(scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList) != NULL);
12975 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList) != NULL);
12976 }
12977 else
12978 {
12979 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknown.
12980 }
12981
12982 testTemplateArgumentParents(nondefdecl);
12983
12984#if 1
12985 // DQ (7/16/2017): Added code to set the template parameters in the just build declaration (if it is a template declaration).
12986 // We want to set the parents of the template paremters to the frst nondefining template class declaration, and we want to reset
12987 // the scope of the declarations associated with any previously marked SgClassType objects associated with any template parameters.
12988 // printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): Calling setTemplateParametersInDeclaration(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
12989
12990 setTemplateParametersInDeclaration(nondefdecl,templateParameterList);
12991
12992 // DQ (8/13/2013): Adding test of template parameter lists.
12993 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(nondefdecl);
12994 ROSE_ASSERT(templateClassDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateClassDeclaration->get_templateParameters().size()));
12995#endif
12996 }
12997
12998 // defdecl->set_firstNondefiningDeclaration(nondefdecl);
12999
13000 // DQ (11/3/2012): Setup the default source position information.
13001 setSourcePosition(nondefdecl);
13002
13003#if 0
13004 // 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).
13005
13006 // Liao, 10/30/2009
13007 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
13008 // This is not desired when building a defining declaration and an inefficience in the constructor
13009 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
13010 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
13011 if (defdecl->get_type() != NULL)
13012 {
13013 // if a defining class declaration's type is associated with a defining class.
13014 // This is a wrong SgClassType and has to be reset
13015 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
13016 {
13017 delete defdecl->get_type();
13018 }
13019 }
13020
13021 // patch up the SgClassType for the defining class declaration
13022 ROSE_ASSERT (nondefdecl->get_type() != NULL);
13023 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
13024 defdecl->set_type(nondefdecl->get_type());
13025#else
13026 // printf ("We might need to force the types used for defining and non-defining SgTemplateClassDeclaration to be the same! \n");
13027 ROSE_ASSERT(nondefdecl->get_type() != NULL);
13028#endif
13029
13030 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
13031 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
13032 // used in a defining declaration).
13033 nondefdecl->setForward();
13034
13035 if (scope != NULL) // put into fixStructDeclaration() or alike later on
13036 {
13037 // fixStructDeclaration(defdecl,scope);
13038 // fixStructDeclaration(nondefdecl,scope);
13039
13040 // printf ("***** WARNING *****: Commented out call to fixStructDeclaration() \n");
13041 // ROSE_ASSERT(false);
13042 }
13043
13044#if 0
13045 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
13046 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
13047
13048 ROSE_ASSERT(defdecl->get_scope() != NULL);
13049#endif
13050
13051 // 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).
13052 ROSE_ASSERT(nondefdecl->get_parent() == NULL);
13053
13054 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13055 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
13056
13057 testTemplateArgumentParents(nondefdecl);
13058
13059#if 0
13060 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
13061 printf ("Leaving buildNondefiningTemplateClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
13062 SgClassDeclaration* tmp_classDeclaration = nondefdecl;
13063 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(tmp_classDeclaration);
13064
13065 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
13066 printf ("Leaving buildNondefiningTemplateClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
13067 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
13068#endif
13069
13070 return nondefdecl;
13071 }
13072
13075 SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
13076{
13077 SgTemplateClassDeclaration * res = buildTemplateClassDeclaration_nfi (XXX_name, kind, scope, nonDefiningDecl, templateParameterList, templateSpecializationArgumentList);
13079 return res;
13080}
13081
13084 SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
13085 {
13086 // DQ (12/26/2011): Notes that the input nonDefiningDecl is not used...this is a confusing point.
13087 // The specification of the scope appears to be enough.
13088
13089 if (scope == NULL)
13091
13092#if 0
13093 printf ("In buildTemplateClassDeclaration_nfi(): nonDefiningDecl = %p \n",nonDefiningDecl);
13094 if (nonDefiningDecl != NULL)
13095 {
13096 printf ("--- nonDefiningDecl->get_firstNondefiningDeclaration() = %p \n",nonDefiningDecl->get_firstNondefiningDeclaration());
13097 printf ("--- nonDefiningDecl->get_definingDeclaration() = %p \n",nonDefiningDecl->get_definingDeclaration());
13098 }
13099#endif
13100
13101 // DQ (11/20/2011): This is for initial debugging only.
13102 ROSE_ASSERT(scope != NULL);
13103
13104 // 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.
13105 SgName nameWithoutTemplateArguments = XXX_name;
13106 SgName nameWithTemplateSpecializationArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateSpecializationArgumentList);
13107
13108 // step 1. Build defining declaration
13109 // Note that even the SgTemplateClassDeclaration uses a regular SgClassDefinition instead of the currently unused SgTemplateClassDefinition.
13110 // SgClassDefinition* classDef = buildClassDefinition();
13111 // SgTemplateClassDefinition* classDef = buildTemplateClassDefinition(name,);
13112
13113 // DQ (11/29/2011): Added checks...
13114 if (nonDefiningDecl != NULL)
13115 {
13116 ROSE_ASSERT(nonDefiningDecl->get_firstNondefiningDeclaration() == nonDefiningDecl);
13117 }
13118
13119 SgName templateString = "template string";
13120 // SgTemplateDeclaration::template_type_enum template_kind = SgTemplateDeclaration::e_template_class;
13121 SgTemplateParameterPtrList templateParameters;
13122
13123 // SgTemplateDeclaration (SgName name, SgName string, SgTemplateDeclaration::template_type_enum template_kind, SgTemplateParameterPtrList templateParameters)
13124 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,kind,NULL,classDef);
13125 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters);
13126
13127 // SgTemplateClassDeclaration::class_types template_class_kind = SgTemplateClassDeclaration::e_class;
13128 // SgTemplateType* classType = NULL;
13129 // SgTemplateClassDefinition* classDef = NULL;
13131
13132 // Constructure arguments: SgName, SgName, SgTemplateDeclaration::template_type_enum, SgTemplateParameterPtrList, SgTemplateClassDeclaration::class_types, SgClassType*, SgTemplateClassDefinition*
13133 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters);
13134 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,template_class_kind,classType,classDef);
13135 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,template_class_kind,classDef);
13136
13137#if 0
13138 printf ("In buildTemplateClassDeclaration_nfi(): calling new SgTemplateClassDeclaration() name = %s \n",nameWithTemplateSpecializationArguments.str());
13139#endif
13140
13141 // DQ (9/12/2012): We want to include the template specialization into the name where it is required (this handling
13142 // is similar to normal template arguments for non-template declaration, but different than template parameters).
13143 // This copy of SgName is required to support passing it to the SgTemplateClassDeclaration constructor.
13144 // SgName localName = name;
13145 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,template_class_kind,classDef);
13146 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,kind,NULL,classDef);
13147
13148 // DQ (1/13/2013): This is causing two defining declarations to be built for test2012_278.C (and the parent for the second defining
13149 // declaration is not being set, though the larger issue is that we have two defining declarations, however this might be acceptable
13150 // if this is a specialization).
13151 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (nameWithTemplateSpecializationArguments,kind,NULL,classDef);
13152 SgTemplateClassDeclaration* defdecl = NULL;
13153 if (nonDefiningDecl != NULL)
13154 {
13155 // If we have a non-defining declaration specified, try to use any existing defining declaration withouth building a 2nd one
13156 // (which would be an error, unless maybe if this is a specialization).
13157 if (nonDefiningDecl->get_definingDeclaration() != NULL)
13158 {
13159 // This must be a valid SgTemplateClassDefinition.
13160 defdecl = isSgTemplateClassDeclaration(nonDefiningDecl->get_definingDeclaration());
13161 ROSE_ASSERT(defdecl != NULL);
13162#if 0
13163 printf ("In buildTemplateClassDeclaration_nfi(): Reusing the defining declaration previously build: defdecl = %p = %s \n",defdecl,defdecl->get_name().str());
13164#endif
13165 }
13166 else
13167 {
13168#if 0
13169 printf ("In buildTemplateClassDeclaration_nfi(): No defining declaration found, so we have to build one. \n");
13170#endif
13171 }
13172 }
13173
13174 if (defdecl == NULL)
13175 {
13176#if 0
13177 printf ("Building a defining declaration \n");
13178#endif
13179 defdecl = new SgTemplateClassDeclaration (nameWithTemplateSpecializationArguments,kind,NULL,classDef);
13180 }
13181
13182 ROSE_ASSERT(defdecl != NULL);
13183
13184#if 0
13185 printf ("In buildTemplateClassDeclaration_nfi(): defdecl = %p = %s \n",defdecl,defdecl->class_name().c_str());
13186#endif
13187
13188 // DQ (9/10/2012): Initialize the template parameter list.
13189 ROSE_ASSERT(templateParameterList != NULL);
13190 defdecl->get_templateParameters() = *templateParameterList;
13191
13192 // DQ (9/12/2012): Adding support for template specialization.
13193 ROSE_ASSERT(templateSpecializationArgumentList != NULL);
13194 defdecl->get_templateSpecializationArguments() = *templateSpecializationArgumentList;
13195
13196 // DQ (9/16/2012): We can't test this yet, since the firstNondefiningDeclaration has not be set.
13197 // testTemplateArgumentParents(defdecl);
13198
13199 // DQ (9/10/2012): Test the just built template with its template parameters.
13200 if (defdecl->get_templateParameters().size() == 0)
13201 {
13202#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
13203 printf ("WARNING: In buildTemplateClassDeclaration_nfi(): defdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations defdecl = %p \n",defdecl);
13204#endif
13205 }
13206 // ROSE_ASSERT(defdecl->get_templateParameters().size() > 0);
13207
13208 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
13209 defdecl->set_templateName(nameWithoutTemplateArguments);
13210
13211#if 0
13212 printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): scope = %p = %s \n",scope,scope->class_name().c_str());
13213#endif
13214
13215 defdecl->set_scope(scope);
13216
13217 // 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.
13218 // DQ (11/20/2011): Can name qualification make this incorrect?
13219 // defdecl->set_parent(scope);
13220
13221 ROSE_ASSERT(classDef != NULL);
13222
13223 // printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): defdecl = %p \n",defdecl);
13224
13226
13227 // constructor is side-effect free
13228 classDef->set_declaration(defdecl);
13229 defdecl->set_definingDeclaration(defdecl);
13230
13231 // Step 2. build the nondefining declaration,
13232 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
13233
13234 // Get the nondefining declaration from the symbol if it has been built (if this works,
13235 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
13236 SgTemplateClassDeclaration* nondefdecl = nonDefiningDecl;
13237 if (nondefdecl == NULL) {
13238 ROSE_ASSERT(scope != NULL);
13239
13240 SgClassSymbol* mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
13241#if 0
13242 printf ("In buildTemplateClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
13243#endif
13244
13245 if (mysymbol != NULL) {
13246 nondefdecl = isSgTemplateClassDeclaration(mysymbol->get_declaration());
13247 ROSE_ASSERT(nondefdecl != NULL);
13248
13249 nondefdecl->set_definingDeclaration(defdecl);
13250 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
13251 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
13252
13253 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13254 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
13255
13256 // DQ (9/16/2012): Test this previously setup firstNondefiningDeclaration.
13257 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
13258 testTemplateArgumentParents(nondefdecl);
13259 } else {
13260#if 0
13261 printf(" start build non-defn decl for %p\n",defdecl);
13262#endif
13263 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
13264 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,NULL,NULL);
13265 ROSE_ASSERT(nondefdecl != NULL);
13266
13267 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
13268 nondefdecl->set_definingDeclaration(defdecl);
13269#if 0
13270 printf(" nondefdecl = %p\n",nondefdecl);
13271#endif
13272#if 0
13273 // TV (04/12/2018): Add a scope for nonreal classes (and their member) on the first non-defining declaration of template classes
13274 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
13275
13276 nonreal_decl_scope->set_parent(nondefdecl);
13277 nondefdecl->set_nonreal_decl_scope(nonreal_decl_scope);
13278
13279 SageInterface::setSourcePosition(nonreal_decl_scope);
13280 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
13281 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
13282#if 1
13283 printf("In buildTemplateClassDeclaration_nfi(): nrscope = %p\n", nonreal_decl_scope);
13284#endif
13285#endif
13286 // DQ (9/10/2012): Initialize the template parameter list.
13287 ROSE_ASSERT(templateParameterList != NULL);
13288 nondefdecl->get_templateParameters() = *templateParameterList;
13289
13290 // DQ (9/16/2012): Newly refactored code.
13291 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
13292 testTemplateArgumentParents(nondefdecl);
13293
13294 // DQ (9/10/2012): Test the just built template with its template parameters.
13295 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
13296 if (nondefdecl->get_templateParameters().size() == 0)
13297 {
13298#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
13299 printf ("WARNING: In buildTemplateClassDeclaration_nfi(): nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
13300#endif
13301 }
13302 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
13303#if 0
13304 printf(" next 1\n");
13305#endif
13306
13307 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
13308 nondefdecl->set_templateName(nameWithoutTemplateArguments);
13309
13310 // DQ (12/26/2011): The non defining declaration should not have a valid pointer to the class definition.
13311 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
13312
13313 // The nondefining declaration will not appear in the source code, but is compiler
13314 // generated (so we have something about the class that we can reference; e.g in
13315 // types). At the moment we make it a transformation, there might be another kind
13316 // of source position that would be more precise. FIXME.
13318 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
13319
13320 nondefdecl->setForward();
13321
13322 // Liao, 9/2/2009. scope stack is optional, it can be empty
13323 nondefdecl->set_parent(scope);
13324 nondefdecl->set_scope(scope);
13325#if 0
13326 printf(" next 2\n");
13327#endif
13328
13329 if (nondefdecl->get_type() == NULL)
13330 {
13331 nondefdecl->set_type(SgClassType::createType(nondefdecl));
13332#if 0
13333 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());
13334#endif
13335 }
13336#if 0
13337 printf(" next 3\n");
13338#endif
13339
13340 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13341 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
13342
13343 // DQ (7/16/2017): Added code to set the template parameters in the just build declaration (if it is a template declaration).
13344 // We want to set the parents of the template paremters to the frst nondefining template class declaration, and we want to reset
13345 // the scope of the declarations associated with any previously marked SgClassType objects associated with any template parameters.
13346 // printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): Calling setTemplateParametersInDeclaration(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
13347
13348 setTemplateParametersInDeclaration(nondefdecl,templateParameterList);
13349
13350 // DQ (8/13/2013): Adding test of template parameter lists.
13351 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(nondefdecl);
13352 ROSE_ASSERT(templateClassDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateClassDeclaration->get_templateParameters().size()));
13353
13354 mysymbol = new SgTemplateClassSymbol(nondefdecl);
13355 scope->insert_symbol(nameWithTemplateSpecializationArguments, mysymbol);
13356#if 0
13357 printf(" end build non-defn decl\n");
13358#endif
13359 }
13360 } else {
13361 SgClassSymbol* mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
13362 if (mysymbol == NULL) {
13363 printf("WARNING: In buildTemplateClassDeclaration_nfi(): non-defining declaration was provided but cannot be located in the associated scope.\n");
13364 }
13365 }
13366
13367#if 0
13368 printf ("In buildTemplateClassDeclaration_nfi(): Setting the firstNondefiningDeclaration to be nondefdecl = %p \n",nondefdecl);
13369#endif
13370
13371 defdecl->set_firstNondefiningDeclaration(nondefdecl);
13372
13373 // DQ (9/16/2012): Setup the template specialization arguments on the defining declaration (tested below at base of function).
13374 setTemplateSpecializationArgumentsInDeclaration(defdecl,templateSpecializationArgumentList);
13375
13376#if 1
13377 // 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).
13378
13379 // Liao, 10/30/2009
13380 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
13381 // This is not desired when building a defining declaration and an inefficience in the constructor
13382 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
13383 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
13384 if (defdecl->get_type() != NULL)
13385 {
13386 // if a defining class declaration's type is associated with a defining class.
13387 // This is a wrong SgClassType and has to be reset
13388#if 0
13389 // if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
13390 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
13391 {
13392 delete defdecl->get_type();
13393 }
13394#else
13395 // DQ (1/13/2013): I am not clear what this means... if (defdecl->get_type() != NULL) then it makes
13396 // no sense to assert that (defdecl->get_type() == NULL). This is related to the reuse of the defining
13397 // declaration when it is available (instead of building a new one, which still might be required for a
13398 // template specialization (or template partial specialization)).
13399 // ROSE_ASSERT(defdecl->get_type() == NULL);
13400#endif
13401 }
13402
13403 // patch up the SgClassType for the defining class declaration
13404 ROSE_ASSERT (nondefdecl->get_type() != NULL);
13405 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
13406
13407 // DQ (1/22/2013): This assertion is a problem for boost code represented by ROSE compiling ROSE (see testRoseHeaders_01.C)
13408 if (isSgClassType(nondefdecl->get_type())->get_declaration() != isSgDeclarationStatement(nondefdecl))
13409 {
13410#if 0
13411 printf ("In buildTemplateClassDeclaration_nfi(): detected isSgClassType(nondefdecl->get_type())->get_declaration() != isSgDeclarationStatement(nondefdecl) (problem with Boost code in ROSE compiling ROSE) \n");
13412#endif
13413 }
13414 // ROSE_ASSERT (isSgClassType(nondefdecl->get_type())->get_declaration() == isSgDeclarationStatement(nondefdecl));
13415
13416 defdecl->set_type(nondefdecl->get_type());
13417
13418#if 0
13419 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());
13420#endif
13421#endif
13422
13423 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
13424 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
13425 // used in a defining declaration).
13426 nondefdecl->setForward();
13427
13428#if 0
13429 if (scope != NULL) // put into fixStructDeclaration() or alike later on
13430 {
13431 // fixStructDeclaration(defdecl,scope);
13432 // fixStructDeclaration(nondefdecl,scope);
13433
13434 printf ("***** WARNING *****: Commented out call to fixStructDeclaration() \n");
13435 // ROSE_ASSERT(false);
13436 }
13437#endif
13438
13439 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
13440 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
13441
13442 ROSE_ASSERT(defdecl->get_scope() != NULL);
13443
13444 // DQ (12/4/2011): We need a concept for type for SgTemplateClassDeclaration so that we can construct SgMemberFunctionType nodes for template member functions.
13445 // We use a SgClassType which has been fixed to permit it to hold either a SgClassDeclaration or an SgTemplateClassDeclaration.
13446 ROSE_ASSERT(defdecl->get_type() != NULL);
13447
13448 // DQ (12/26/2011): The non defining declaration should not have a valid pointer to the class definition.
13449 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
13450
13451 // DQ (7/15/2012): We want to inforce this.
13452 // ROSE_ASSERT(defdecl->get_parent() == NULL);
13453 if (defdecl->get_parent() != NULL)
13454 {
13455#if PRINT_DEVELOPER_WARNINGS
13456 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());
13457#endif
13458 }
13459
13460 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13461 ROSE_ASSERT(defdecl->get_templateName().is_null() == false);
13462
13463 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
13464 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
13465
13467 testTemplateArgumentParents(nondefdecl);
13468
13469#if 0
13470 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
13471 printf ("Leaving buildTemplateClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
13472 SgClassDeclaration* tmp_classDeclaration = defdecl;
13473 SgSymbol* test_symbol = defdecl->get_scope()->find_symbol_from_declaration(tmp_classDeclaration);
13474
13475 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
13476 printf ("Leaving buildTemplateClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
13477 ROSE_ASSERT(defdecl->get_symbol_from_symbol_table() != NULL);
13478#endif
13479
13480 return defdecl;
13481 }
13482
13484 {
13485 // DQ (1/11/2009): This function has semantics very different from the buildEnumDeclaration_nfi() function!
13486
13487 if (scope == NULL)
13489
13490 SgEnumDeclaration* decl = buildEnumDeclaration_nfi(name, scope);
13494
13495 // DQ (7/15/2012): We want to inforce this.
13496 ROSE_ASSERT(decl->get_parent() == NULL);
13497
13498 return decl;
13499 } //buildEnumDeclaration()
13500
13501
13504 {
13505 // The support for SgEnumDeclaration is identical to that for SgClassDeclaration (except for the type handling, why is that?).
13506 ASSERT_not_null(scope);
13507
13508 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
13509 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
13510 ASSERT_require(SageInterface::hasTemplateSyntax(name) == false);
13511
13512 SgEnumType* enumType = nullptr;
13513 SgEnumDeclaration* first_nondefdecl = nullptr;
13514
13515 if (scope)
13516 {
13517 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
13518 if (existing_symbol != NULL)
13519 {
13520 enumType = isSgEnumType(existing_symbol->get_type());
13521 first_nondefdecl = existing_symbol->get_declaration();
13522 ROSE_ASSERT(first_nondefdecl != NULL);
13523 }
13524 }
13525
13526 // DQ (5/8/2013): We do want to build a new SgEnumDeclaration (to avoid sharing).
13527 // This forces each call to buildNondefiningEnumDeclaration_nfi() to build a unique declaration
13528 // required to avoid sharing declaration in examples such as test2007_29.C.
13529 SgEnumDeclaration* nondefdecl = new SgEnumDeclaration(name, enumType);
13530
13531 ROSE_ASSERT(nondefdecl);
13532 setOneSourcePositionNull(nondefdecl);
13533
13534 // Set the defining and first non-defining declarations.
13535 if (first_nondefdecl)
13536 {
13537 nondefdecl->set_firstNondefiningDeclaration(first_nondefdecl);
13538 nondefdecl->set_definingDeclaration(first_nondefdecl->get_definingDeclaration());
13539 }
13540 else
13541 {
13542 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
13543 nondefdecl->set_definingDeclaration(nullptr);
13544 }
13545
13546 // Any non-defining declaration is not always a forward declaration.
13547 nondefdecl->setForward();
13548
13549 SgType* type = nondefdecl->get_type();
13550 ASSERT_not_null(type);
13551
13552 if (scope)
13553 {
13554 // Check for an existing symbol (reuse it if it is found).
13555 SgEnumSymbol* mysymbol = nullptr;
13556 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
13557
13558 if (existing_symbol)
13559 {
13560 mysymbol = existing_symbol;
13561 first_nondefdecl = mysymbol->get_declaration();
13562 }
13563 else
13564 {
13565 first_nondefdecl = nondefdecl;
13566
13567 mysymbol = new SgEnumSymbol(nondefdecl);
13568 ASSERT_not_null(mysymbol);
13569 scope->insert_symbol(name, mysymbol);
13570 }
13571
13572 nondefdecl->set_scope(scope);
13573
13574 // Can this be defined in C++ so that it is in a logical scope different from its structural scope?
13575 nondefdecl->set_parent(scope);
13576 }
13577
13578 if (first_nondefdecl != nondefdecl)
13579 {
13580 nondefdecl->set_firstNondefiningDeclaration(first_nondefdecl);
13581
13582 if (first_nondefdecl->get_definingDeclaration() != NULL)
13583 {
13584 nondefdecl->set_definingDeclaration(first_nondefdecl->get_definingDeclaration());
13585 }
13586 }
13587
13588 ASSERT_not_null(nondefdecl->get_type());
13589 ASSERT_not_null(scope->lookup_enum_symbol(name));
13590
13591 return nondefdecl;
13592 }
13593
13594
13597 {
13598 ROSE_ASSERT(scope != NULL);
13599
13600#if 0
13601 printf ("In buildEnumDeclaration_nfi(): name = %s scope = %p = %s \n",name.str(),scope,scope->class_name().c_str());
13602#endif
13603
13604 // DQ (5/8/2013): I think if we searched for the type it might exist and this would allow the types to be shared.
13605 SgEnumType* enumType = NULL;
13606
13607 if (scope != NULL)
13608 {
13609 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
13610 if (existing_symbol != NULL)
13611 {
13612 enumType = isSgEnumType(existing_symbol->get_type());
13613 }
13614 }
13615
13616#if 0
13617 printf ("In buildEnumDeclaration_nfi(): name = %s building using enumType = %p \n",name.str(),enumType);
13618#endif
13619
13620 // SgEnumDeclaration* defdecl = new SgEnumDeclaration (name,NULL);
13621 SgEnumDeclaration* defdecl = new SgEnumDeclaration (name,enumType);
13622 ROSE_ASSERT(defdecl);
13623
13624#if 0
13625 printf ("In buildEnumDeclaration_nfi(): built defining declaration = %p name = %s scope = %p = %s \n",defdecl,name.str(),scope,scope->class_name().c_str());
13626#endif
13627
13628 // DQ (5/8/2013): Make sure that the enum type is available.
13629 SgType* type = defdecl->get_type();
13630 ROSE_ASSERT(type != NULL);
13631
13632 setOneSourcePositionNull(defdecl);
13633 // constructor is side-effect free
13634 defdecl->set_definingDeclaration(defdecl);
13635
13636#if 0
13637 printf ("In buildEnumDeclaration_nfi(): name = %s \n",name.str());
13638#endif
13639
13640#if 1
13641 // DQ (4/3/2017): Check for an existing non-defining declaration before building one (to avoid multiple versions). See test2017_13.C.
13642 ROSE_ASSERT(scope != NULL);
13643 SgEnumSymbol* enumSymbol = scope->lookup_enum_symbol(name);
13644 // ROSE_ASSERT(enumSymbol != NULL);
13645 SgEnumDeclaration* nondefdecl = NULL;
13646 if (enumSymbol != NULL)
13647 {
13648 ROSE_ASSERT(enumSymbol->get_declaration() != NULL);
13649 nondefdecl = enumSymbol->get_declaration();
13650 ROSE_ASSERT(nondefdecl != NULL);
13651 }
13652 else
13653 {
13654 // build the nondefining declaration
13655 nondefdecl = buildNondefiningEnumDeclaration_nfi(name, scope);
13656#if 0
13657 printf ("###### In buildEnumDeclaration_nfi(): built a non-defining declaration to support the symbol table: name = %s nondefdecl = %p \n",name.str(),nondefdecl);
13658#endif
13659 }
13660#else
13661 // build the nondefining declaration
13662 SgEnumDeclaration* nondefdecl = buildNondefiningEnumDeclaration_nfi(name, scope);
13663#endif
13664
13665 nondefdecl->set_definingDeclaration(defdecl);
13666 // defdecl->set_firstNondefiningDeclaration(nondefdecl);
13668
13669 // DQ (4/22/2013): We need to set the defining declaration on the first non-defining declaration.
13670 if (nondefdecl->get_firstNondefiningDeclaration() != NULL && nondefdecl->get_firstNondefiningDeclaration() != nondefdecl)
13671 {
13673 }
13674
13675 // DQ (4/22/2013): Thing that should be true at this point.
13676 ROSE_ASSERT(nondefdecl->get_definingDeclaration() != NULL);
13677 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
13678 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration()->get_definingDeclaration() != NULL);
13679 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration()->get_firstNondefiningDeclaration() != NULL);
13680 ROSE_ASSERT(defdecl->get_definingDeclaration() != NULL);
13681 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
13682
13683 // DQ (1/11/2009): The buildNondefiningEnumDeclaration function builds an entry in the symbol table, and so we don't want a second one!
13684#if 0
13685 SgEnumSymbol* mysymbol = new SgEnumSymbol(nondefdecl);
13686 ROSE_ASSERT(mysymbol);
13687 // scope->print_symboltable("buildEnumDeclaration_nfi(): before inserting new SgEnumSymbol");
13688 scope->insert_symbol(name, mysymbol);
13689#endif
13690
13691 defdecl->set_scope(scope);
13692 nondefdecl->set_scope(scope);
13693
13694#if 0
13695 // 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).
13696 defdecl->set_parent(scope);
13697 nondefdecl->set_parent(scope);
13698#endif
13699
13700 // DQ (7/12/2012): When this is an unnamed enum declaration, this it is NON-AUTONIMOUS
13701 // (and will have it's parent set in the associated variable or typedef declaration.
13702 // In the case of a class declaration this is always NULL (this should be similar).
13703 ROSE_ASSERT(defdecl->get_parent() == NULL);
13704
13705#if 0
13706 printf ("In buildEnumDeclaration_nfi(): name = %s defdecl = %p \n",name.str(),defdecl);
13707#endif
13708
13709 // DQ (5/8/2013): Check that the symbol is present.
13710 ROSE_ASSERT(scope->lookup_enum_symbol(name) != NULL);
13711
13712 return defdecl;
13713 } //buildEnumDeclaration_nfi()
13714
13715
13717SageBuilder::buildBaseClass ( SgClassDeclaration* classDeclaration, SgClassDefinition* classDefinition, bool isVirtual, bool isDirect )
13718 {
13719 // DQ (5/6/2013): Refactored the construction of the SgBaseClass support to the builder API.
13720
13721 // Note: classDeclaration should be the first non-defining class declaration, not required to be the the declaration associated with the SgClassDefinition.
13722 ROSE_ASSERT(classDeclaration != NULL);
13723 ROSE_ASSERT(classDefinition != NULL);
13724
13725 // DQ (5/6/2013): This is not always true (see test2013_63.C).
13726 // ROSE_ASSERT(classDeclaration == classDeclaration->get_firstNondefiningDeclaration());
13727
13728 ROSE_ASSERT(classDefinition->get_declaration() != NULL);
13729
13730 // DQ (5/6/2013): This is not always true (see test2004_30.C).
13731 // ROSE_ASSERT(classDefinition->get_declaration() == classDeclaration->get_firstNondefiningDeclaration());
13732
13733 SgBaseClass* baseclass = new SgBaseClass ( classDeclaration, isDirect );
13734 ROSE_ASSERT(baseclass != NULL);
13735
13736 if (isVirtual == true)
13737 {
13738 // DQ (1/21/2019): get_baseClassModifier() uses ROSETTA generated access functions which return a pointer.
13739 // baseclass->get_baseClassModifier().setVirtual();
13740 ROSE_ASSERT(baseclass->get_baseClassModifier() != NULL);
13741 baseclass->get_baseClassModifier()->setVirtual();
13742 }
13743
13744 // DQ (4/29/2004): add support to set access specifier
13745 // baseclass->get_baseClassModifier().get_accessModifier() = set_access_modifiers(bcdp->access);
13746 // baseclass->get_baseClassModifier().get_accessModifier() = buildAccessModifier(accessModifiers);
13747
13748 // DQ (6/21/2005): Set the parent of the base class to the class definition
13749 // (these are not traversed in ROSE currently, so their parents are not set).
13750 baseclass->set_parent(classDefinition);
13751
13752 // DQ (6/21/2005): Notice that this is copied by value (the base class list should be a list of pointers to SgBaseClass (later)
13753 classDefinition->append_inheritance(baseclass);
13754
13755 return baseclass;
13756 }
13757
13758
13760SageBuilder::buildNonrealBaseClass ( SgNonrealDecl* nrdecl, SgClassDefinition* classDefinition, bool isVirtual, bool isDirect )
13761 {
13762 ROSE_ASSERT(nrdecl != NULL);
13763 ROSE_ASSERT(classDefinition != NULL);
13764
13765 SgNonrealBaseClass * baseclass = new SgNonrealBaseClass ( NULL , isDirect , nrdecl );
13766 ROSE_ASSERT(baseclass != NULL);
13767
13768 if (isVirtual == true)
13769 {
13770 baseclass->get_baseClassModifier()->setVirtual();
13771 }
13772
13773 baseclass->set_parent(classDefinition);
13774
13775 classDefinition->append_inheritance(baseclass);
13776
13777 return baseclass;
13778 }
13779
13780
13781#if 0
13782// This function would be more complex that I want to support at present since the mapping of
13783// edg modifier values to ROSE modifier values is offset and backwards (reversed in numerical order).
13785SageBuilder::buildAccessModifier ( unsigned int access )
13786 {
13788
13789 switch (access)
13790 {
13791 case as_public:
13792#if 0
13793 printf ("In SageBuilder::set_access_modifiers(): Mark as public \n");
13794#endif
13795 a.setPublic();
13796 break;
13797
13798 case as_protected:
13799#if 0
13800 printf ("In SageBuilder::set_access_modifiers(): Mark as protected \n");
13801#endif
13802 a.setProtected();
13803 break;
13804
13805 case as_private:
13806#if 0
13807 printf ("In SageBuilder::set_access_modifiers(): Mark as private \n");
13808#endif
13809 a.setPrivate();
13810 break;
13811
13812 default:
13813 printf ("Error: default reached in SageBuilder::set_access_modifiers() \n");
13814 ROSE_ABORT ();
13815 }
13816
13817 return a;
13818 }
13819#endif
13820
13821
13822void
13823SageBuilder::fixupSourcePositionFileSpecification(SgNode* subtreeRoot, const std::string& newFileName)
13824 {
13825 // DQ (11/8/2019): This function changes the filename designation in all of the Sg_File_Info objects
13826 // associated with the designated AST subtree.
13827
13828 ROSE_ASSERT(subtreeRoot != NULL);
13829 ROSE_ASSERT(newFileName != "");
13830
13831#define DEBUG_FIXUP 0
13832
13833#if DEBUG_FIXUP
13834 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): newFileName = %s \n",newFileName.c_str());
13835 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13836#endif
13837
13838 class Traversal : public AstSimpleProcessing
13839 {
13840 public:
13841
13842 Traversal(const std::string& tmp_newFileName, int tmp_new_file_id, int tmp_originalFileId)
13843 {
13844 newFileName = tmp_newFileName;
13845 new_file_id = tmp_new_file_id;
13846 originalFileId = tmp_originalFileId;
13847#if DEBUG_FIXUP
13848 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): newFileName = %s new_file_id = %d originalFileId = %d \n",newFileName.c_str(),new_file_id,originalFileId);
13849#endif
13850 }
13851
13852 void visit (SgNode* node)
13853 {
13854#if DEBUG_FIXUP
13855 printf ("In fixupSourcePositionFileSpecification visit(): node = %p = %s \n",node,node->class_name().c_str());
13856#endif
13857
13858 SgLocatedNode* locatedNode = isSgLocatedNode(node);
13859 if (locatedNode != NULL)
13860 {
13861 // if (locatedNode->get_startOfConstruct()->get_file_id() == originalFileId)
13862 if (locatedNode->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13863 {
13864 ROSE_ASSERT(locatedNode->get_startOfConstruct() != NULL);
13865 ROSE_ASSERT(locatedNode->get_endOfConstruct() != NULL);
13866
13867 if (locatedNode->get_startOfConstruct()->isShared() == true)
13868 {
13869#if DEBUG_FIXUP
13870 printf ("Found SgLocatedNode marked as isShared() == true: locatedNode = %p = %s \n",locatedNode,locatedNode->class_name().c_str());
13871#endif
13872#if 0
13873 printf ("Exiting as a test! \n");
13874 ROSE_ABORT();
13875#endif
13876 }
13877 locatedNode->get_startOfConstruct()->set_file_id(new_file_id);
13878 locatedNode->get_endOfConstruct ()->set_file_id(new_file_id);
13879
13880 locatedNode->get_startOfConstruct()->set_physical_file_id(new_file_id);
13881 locatedNode->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13882
13883#if DEBUG_FIXUP
13884 printf ("locatedNode->get_startOfConstruct()->get_filename() = %s locatedNode->get_startOfConstruct()->get_physical_filename() = %s \n",
13885 locatedNode->get_startOfConstruct()->get_filenameString().c_str(),locatedNode->get_startOfConstruct()->get_physical_filename().c_str());
13886 printf ("locatedNode->get_startOfConstruct()->get_file_id() = %d locatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",
13887 locatedNode->get_startOfConstruct()->get_file_id(),locatedNode->get_startOfConstruct()->get_physical_file_id());
13888 printf ("locatedNode->get_startOfConstruct()->isShared() = %s \n",locatedNode->get_startOfConstruct()->isShared() ? "true" : "false");
13889#endif
13890 }
13891 else
13892 {
13893#if DEBUG_FIXUP
13894 printf ("NOT MATCHING: originalFileId = %d locatedNode->get_startOfConstruct()->get_file_id() = %d locatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",
13895 originalFileId,locatedNode->get_startOfConstruct()->get_file_id(),locatedNode->get_startOfConstruct()->get_physical_file_id());
13896 printf (" ------------ originalFileId = %d locatedNode->get_endOfConstruct()->get_file_id() = %d locatedNode->get_endOfConstruct()->get_physical_file_id() = %d \n",
13897 originalFileId,locatedNode->get_endOfConstruct()->get_file_id(),locatedNode->get_endOfConstruct()->get_physical_file_id());
13898#endif
13899 }
13900 }
13901 else
13902 {
13903 SgInitializedName* initializedName = isSgInitializedName(node);
13904 if (initializedName != NULL)
13905 {
13906 // if (initializedName->get_startOfConstruct()->get_file_id() == originalFileId)
13907 if (initializedName->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13908 {
13909 ROSE_ASSERT(initializedName->get_startOfConstruct() != NULL);
13910 ROSE_ASSERT(initializedName->get_endOfConstruct() != NULL);
13911
13912 initializedName->get_startOfConstruct()->set_file_id(new_file_id);
13913 initializedName->get_endOfConstruct ()->set_file_id(new_file_id);
13914
13915 initializedName->get_startOfConstruct()->set_physical_file_id(new_file_id);
13916 initializedName->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13917 }
13918 }
13919 else
13920 {
13921 SgSourceFile* sourceFile = isSgSourceFile(node);
13922 if (sourceFile != NULL)
13923 {
13924 ROSE_ASSERT(sourceFile->get_startOfConstruct() != NULL);
13925#if 0
13926 // A SgSourceFile has no endOfConstruct.
13927 if (sourceFile->get_endOfConstruct() == NULL)
13928 {
13929#if 0
13930 printf ("sourceFile->get_endOfConstruct() == NULL: fixup endOfConstruct \n");
13931#endif
13932 sourceFile->set_endOfConstruct(new Sg_File_Info());
13933 *(sourceFile->get_endOfConstruct()) = *(sourceFile->get_startOfConstruct());
13934 }
13935 ROSE_ASSERT(sourceFile->get_endOfConstruct() != NULL);
13936#endif
13937 // Need to test the physical_file_id because we already set the regular file_id (as part of seeding the process).
13938 // if (sourceFile->get_startOfConstruct()->get_file_id() == originalFileId)
13939 if (sourceFile->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13940 {
13941 sourceFile->get_startOfConstruct()->set_file_id(new_file_id);
13942 sourceFile->get_startOfConstruct()->set_physical_file_id(new_file_id);
13943#if DEBUG_FIXUP
13944 printf ("sourceFile->get_startOfConstruct()->get_file_id() = %d \n",sourceFile->get_startOfConstruct()->get_file_id());
13945 printf ("sourceFile->get_startOfConstruct()->get_physical_file_id() = %d \n",sourceFile->get_startOfConstruct()->get_physical_file_id());
13946#endif
13947 // sourceFile->get_endOfConstruct ()->set_file_id(new_file_id);
13948 // sourceFile->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13949 }
13950 }
13951 else
13952 {
13953#if DEBUG_FIXUP
13954 printf ("Unhandled: node = %p = %s \n",node,node->class_name().c_str());
13955#endif
13956 }
13957 }
13958 }
13959
13960 SgExpression* expression = isSgExpression(node);
13961 if (expression != NULL)
13962 {
13963 if (expression->get_operatorPosition()->get_physical_file_id() == originalFileId)
13964 {
13965 expression->get_operatorPosition()->set_file_id(new_file_id);
13966 expression->get_operatorPosition()->set_physical_file_id(new_file_id);
13967 }
13968 }
13969 }
13970
13971 // Data members.
13972 int new_file_id;
13973 int originalFileId;
13974 string newFileName;
13975 };
13976
13977
13978 SgFile* file = isSgFile(subtreeRoot);
13979 int new_file_id = -1;
13980 int originalFileId = -1;
13981
13982 if (file != NULL)
13983 {
13984 // We need to set the filename in at least one Sg_File_Info object so that we can have
13985 // the file_id be computed ans saved into the file_id to filename maps.
13986
13987 originalFileId = file->get_startOfConstruct()->get_file_id();
13988#if DEBUG_FIXUP
13989 printf ("originalFileId = %d \n",originalFileId);
13990#endif
13991 file->get_startOfConstruct()->set_filenameString(newFileName);
13992 new_file_id = Sg_File_Info::get_nametofileid_map()[newFileName];
13993
13994
13995#if 0
13996 file->get_endOfConstruct()->set_physical_file_id(new_file_id);
13997
13998 file->get_startOfConstruct()->set_physical_file_id(new_file_id);
13999 file->get_endOfConstruct()->set_physical_file_id(new_file_id);
14000
14001 // getFilenameFromID
14002 int new_file_id_2 = Sg_File_Info::getIDFromFilename(newFileName);
14003#if 0
14004 printf ("new_file_id = %d new_file_id_2 = %d \n",new_file_id,new_file_id_2);
14005#endif
14006 ROSE_ASSERT(new_file_id == new_file_id_2);
14007
14008 string new_filename_2 = Sg_File_Info::getFilenameFromID(new_file_id);
14009#if 0
14010 printf ("newFileName = %s new_filename_2 = %s \n",newFileName.c_str(),new_filename_2.c_str());
14011#endif
14012 ROSE_ASSERT(newFileName == new_filename_2);
14013#endif
14014
14015#if DEBUG_FIXUP
14016 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): file != NULL: newFileName = %s new_file_id = %d \n",newFileName.c_str(),new_file_id);
14017#endif
14018 }
14019 else
14020 {
14021 SgLocatedNode* subtreeLocatedNode = isSgLocatedNode(subtreeRoot);
14022 if (subtreeLocatedNode != NULL)
14023 {
14024#if DEBUG_FIXUP
14025 printf ("subtreeLocatedNode->get_startOfConstruct()->get_file_id() = %d \n",subtreeLocatedNode->get_startOfConstruct()->get_file_id());
14026 printf ("subtreeLocatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",subtreeLocatedNode->get_startOfConstruct()->get_physical_file_id());
14027#endif
14028 originalFileId = subtreeLocatedNode->get_startOfConstruct()->get_file_id();
14029 new_file_id = Sg_File_Info::getIDFromFilename(newFileName);
14030#if DEBUG_FIXUP
14031 printf ("originalFileId = %d \n",originalFileId);
14032 printf ("new_file_id = %d \n",new_file_id);
14033#endif
14034#if DEBUG_FIXUP
14035 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): subtreeLocatedNode = %s : originalFileId = %d newFileName = %s new_file_id = %d \n",
14036 subtreeLocatedNode->class_name().c_str(),originalFileId,newFileName.c_str(),new_file_id);
14037#endif
14038 }
14039 else
14040 {
14041 printf ("Error: In SageBuilder::fixupSourcePositionFileSpecification(): subtree should be a SgFile or SgLocatedNode: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
14042 ROSE_ABORT();
14043 }
14044
14045#if 0
14046 printf ("Error: In SageBuilder::fixupSourcePositionFileSpecification(): subtree should be a SgFile: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
14047 ROSE_ABORT();
14048#endif
14049 }
14050
14051 ROSE_ASSERT(new_file_id >= 0);
14052
14053 // Now build the traveral object and call the traversal (preorder) on the function definition.
14054 Traversal traversal (newFileName,new_file_id,originalFileId);
14055
14056 // traversal.traverse(subtreeRoot, preorder);
14057 // traversal.traverseInputFiles(subtreeRoot, preorder);
14058 // traversal.traverseWithinFile(subtreeRoot, preorder);
14059 traversal.traverse(subtreeRoot, preorder);
14060
14061#if 0
14062 printf ("Exiting as a test in SageBuilder::fixupSourcePositionFileSpecification() \n");
14063 ROSE_ABORT();
14064#endif
14065 }
14066
14067
14068
14069
14070
14071
14072
14073
14074void
14076 {
14077 // DQ (11/8/2019): This function changes the filename designation in all of the Sg_File_Info objects
14078 // associated with the designated AST subtree.
14079
14080 ROSE_ASSERT(subtreeRoot != NULL);
14081 ROSE_ASSERT(new_file_id >= 0);
14082
14083#if 0
14084 printf ("In SageBuilder::fixupSharingSourcePosition(): subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
14085 printf ("In SageBuilder::fixupSharingSourcePosition(): new_file_id = %d \n",new_file_id);
14086#endif
14087
14088 class Traversal : public AstSimpleProcessing
14089 {
14090 public:
14091
14092 Traversal(int tmp_new_file_id)
14093 {
14094 new_file_id = tmp_new_file_id;
14095#if 0
14096 printf ("In SageBuilder::fixupSharingSourcePosition(): new_file_id = %d \n",new_file_id);
14097#endif
14098 }
14099
14100 void visit (SgNode* node)
14101 {
14102#if 0
14103 printf ("In fixupSharingSourcePosition visit(): node = %p = %s new_file_id = %d \n",node,node->class_name().c_str(),new_file_id);
14104#endif
14105
14106 SgStatement* statement = isSgStatement(node);
14107 if (statement != NULL)
14108 {
14109 Sg_File_Info* startOfConstruct = statement->get_startOfConstruct();
14110 Sg_File_Info* endOfConstruct = statement->get_endOfConstruct();
14111#if 0
14112 printf ("new_file_id = %d startOfConstruct->get_physical_file_id() = %d \n",new_file_id,startOfConstruct->get_physical_file_id());
14113#endif
14114 // Only mark the files from the associated file (not statements in header files, for example).
14115 if (startOfConstruct->get_physical_file_id() == new_file_id)
14116 {
14117 // Mark this IR node as being shared
14118 startOfConstruct->setShared();
14119 endOfConstruct->setShared();
14120
14121 // Add this file_id to those file_id that will trigger this IR node to be unparsed.
14122#if 0
14123 printf (" --- adding entries for file_id and line number to support sharing: new_file_id = %d line = %d end line = %d \n",
14124 new_file_id,startOfConstruct->get_line(),endOfConstruct->get_line());
14125#endif
14126 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == startOfConstruct->get_fileLineNumbersToUnparse().size());
14127 ROSE_ASSERT(endOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
14128 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
14129
14130 // Add this existing_fi->get_file_id() to the list of file id's that will permit the assocated language construct to be unparsed.
14131 startOfConstruct->get_fileIDsToUnparse().push_back(new_file_id);
14132 startOfConstruct->get_fileLineNumbersToUnparse().push_back(startOfConstruct->get_line());
14133
14134 endOfConstruct->get_fileIDsToUnparse().push_back(new_file_id);
14135 endOfConstruct->get_fileLineNumbersToUnparse().push_back(endOfConstruct->get_line());
14136
14137 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == startOfConstruct->get_fileLineNumbersToUnparse().size());
14138 ROSE_ASSERT(endOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
14139 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
14140 }
14141 }
14142 else
14143 {
14144#if 0
14145 printf ("Unhandled: node = %p = %s \n",node,node->class_name().c_str());
14146#endif
14147 }
14148 }
14149
14150 // Data members.
14151 int new_file_id;
14152 };
14153
14154
14155 SgStatement* statement = isSgStatement(subtreeRoot);
14156 if (statement != NULL)
14157 {
14158#if 0
14159 printf ("statement->get_startOfConstruct()->get_file_id() = %d \n",statement->get_startOfConstruct()->get_file_id());
14160 printf ("statement->get_startOfConstruct()->get_physical_file_id() = %d \n",statement->get_startOfConstruct()->get_physical_file_id());
14161#endif
14162#if 0
14163 printf ("new_file_id = %d \n",new_file_id);
14164#endif
14165#if 0
14166 printf ("In SageBuilder::fixupSharingSourcePosition(): statement = %s : new_file_id = %d \n",statement->class_name().c_str(),new_file_id);
14167#endif
14168 }
14169 else
14170 {
14171 printf ("Error: In SageBuilder::fixupSharingSourcePosition(): subtree should be a SgFile or SgLocatedNode: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
14172 ROSE_ABORT();
14173 }
14174
14175 ROSE_ASSERT(new_file_id >= 0);
14176
14177 // Now buid the traveral object and call the traversal (preorder) on the function definition.
14178 Traversal traversal (new_file_id);
14179
14180 // traversal.traverse(subtreeRoot, preorder);
14181 // traversal.traverseInputFiles(subtreeRoot, preorder);
14182 // traversal.traverseWithinFile(subtreeRoot, preorder);
14183 traversal.traverse(subtreeRoot, preorder);
14184
14185#if 0
14186 printf ("Exiting as a test in SageBuilder::fixupSharingSourcePosition() \n");
14187 ROSE_ABORT();
14188#endif
14189 }
14190
14191
14192
14193
14194
14196SgFile*
14197SageBuilder::buildFile(const std::string& inputFileName, const std::string& outputFileName, SgProject* project/*=NULL*/, bool clear_globalScopeAcrossFiles /*=false*/)
14198 {
14199// Note that ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT defines a reduced set of ROSE to support front-end specific development.
14200// It is mostly used by quinlan to support laptop development where the smaller set of files permits one to do limited
14201// development work on a Mac (even with OSX's poor performance with large numbers of debug symbols). This is an
14202// infrequently used option.
14203#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
14204
14205#if 0
14206 printf ("In SageBuilder::buildFile(inputFileName = %s, outputFileName = %s, project = %p) \n",inputFileName.c_str(),outputFileName.c_str(),project);
14207 // printf (" --- fullname = %s \n",fullname.c_str());
14208#endif
14209
14210#if 0
14211 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14212 ROSE_ASSERT(project != NULL);
14213 std::set<SgLocatedNode*> tmp1_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14214
14215 if (tmp1_collectionOfModifiedLocatedNodes.size() > 0)
14216 {
14217 printf ("In Traversal::evaluateInheritedAttribute(): tmp1_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp1_collectionOfModifiedLocatedNodes.size());
14218#if 1
14219 printf ("Exiting as a test! \n");
14220 ROSE_ASSERT(false);
14221#endif
14222 }
14223#endif
14224
14225 ROSE_ASSERT(inputFileName.size() != 0); // empty file name is not allowed.
14226
14227 // DQ (9/18/2019): I am unclear what the use of fullname is below.
14228 // string sourceFilename = inputFileName, fullname;
14229 // string sourceFilename_fullname = inputFileName, fullname;
14230 string sourceFilename = inputFileName;
14231
14232#if 0
14233 // printf ("sourceFilename_fullname = %s \n",sourceFilename_fullname.c_str());
14234 printf ("sourceFilename = %s \n",sourceFilename.c_str());
14235#endif
14236
14237
14238 // DQ (11/5/2020): Experiment with clearing the global scope that is supporting multiple translation
14239 // units, since it is the cause of some problem when a tool is designed to read an input file twice.
14240 if (project != NULL)
14241 {
14242 SgGlobal* globalScopeAcrossFiles = project->get_globalScopeAcrossFiles();
14243 ROSE_ASSERT(globalScopeAcrossFiles != NULL);
14244
14245 ROSE_ASSERT(globalScopeAcrossFiles->get_symbol_table() != NULL);
14246 ROSE_ASSERT(globalScopeAcrossFiles->get_symbol_table()->get_table() != NULL);
14247
14248#if 0
14249 printf ("In SageBuilder::buildFile(): globalScopeAcrossFiles = %p \n",globalScopeAcrossFiles);
14250 printf (" --- globalScopeAcrossFiles->get_declarations().size() = %zu \n",globalScopeAcrossFiles->get_declarations().size());
14251 printf (" --- globalScopeAcrossFiles->get_symbol_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->size());
14252 printf (" --- globalScopeAcrossFiles->get_symbol_table()->get_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->get_table()->size());
14253#endif
14254#if 0
14255 printf ("Removing all elements from the globalScopeAcrossFiles->get_symbol_table() \n");
14256#endif
14257
14258 // DQ (11/5/2020): Clear the symbol table used to support multifile handling.
14259 // This breaks only one of the test codes in the codeSegregation tool, but it is a name
14260 // qualification that should likely be handled better so I think this is a good fix.
14261 if (clear_globalScopeAcrossFiles == true)
14262 {
14263 globalScopeAcrossFiles->get_symbol_table()->get_table()->delete_elements();
14264 }
14265
14266#if 0
14267 printf ("After removing all symbols (alias symbols): globalScopeAcrossFiles->get_symbol_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->size());
14268 printf ("After removing all symbols (alias symbols): globalScopeAcrossFiles->get_symbol_table()->get_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->get_table()->size());
14269#endif
14270 }
14271
14272 // DQ (9/18/2019): Test that the use of fullname has no effect.
14273 // ROSE_ASSERT(sourceFilename == sourceFilename_fullname);
14274
14275 Rose_STL_Container<std::string> arglist;
14276 int nextErrorCode = 0;
14277
14278#if 0
14279 bool set_header_file_unparsing_optimization = false;
14280#endif
14281
14282 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
14283 bool isCopyOfExistingFile_testForSharedNodes = false;
14284 SgFile* fileBeingCopied = NULL;
14285
14286 if (project == NULL)
14287 // SgProject is created on the fly
14288 // Make up an arglist in order to reuse the code inside SgFile::setupSourceFilename()
14289 {
14290#if 0
14291 printf ("In SageBuilder::buildFile(): build the SgProject \n");
14292#endif
14293 project = new SgProject();
14294 ROSE_ASSERT(project);
14295 project->get_fileList().clear();
14296
14297 arglist.push_back("cc");
14298 arglist.push_back("-c");
14299 project->set_originalCommandLineArgumentList (arglist);
14300 }
14301 else
14302 {
14303 // If project exists, then find the original source file if it exists and check the header file optimization setting for consistancy.
14304
14305 // DQ (9/18/2019): Adding debugging support to header file optimization support.
14306 SgFilePtrList & files = project->get_fileList();
14307 for (SgFilePtrList::iterator i = files.begin(); i != files.end(); i++)
14308 {
14309 SgFile* file = *i;
14310#if 0
14311 printf ("file = %p = %s name = %s \n",file,file->class_name().c_str(), file->getFileName().c_str());
14312
14313 printf ("file->get_header_file_unparsing_optimization() = %s \n",file->get_header_file_unparsing_optimization() ? "true" : "false");
14314 printf ("file->get_header_file_unparsing_optimization_source_file() = %s \n",file->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14315 printf ("file->get_header_file_unparsing_optimization_header_file() = %s \n",file->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14316#endif
14317 if (sourceFilename == file->getFileName())
14318 {
14319#if 0
14320 printf ("This is a copy of an existing file in the project: sourceFilename = %s \n",sourceFilename.c_str());
14321#endif
14322 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
14323 isCopyOfExistingFile_testForSharedNodes = true;
14324 fileBeingCopied = file;
14325
14326#if 0
14327 // DQ (4/24/2021): This data member header_file_unparsing_optimization is now static.
14328 // We are building a second copy of an originally specified file (so we need to set the optimization setting similarly).
14329 if (file->get_header_file_unparsing_optimization() == true)
14330 {
14331 set_header_file_unparsing_optimization = true;
14332 }
14333#endif
14334 }
14335 }
14336
14337#if 0
14338 printf ("Exiting as a test! \n");
14339 ROSE_ABORT();
14340#endif
14341 }
14342
14343 ifstream testfile(inputFileName.c_str());
14344 if (!testfile.is_open())
14345 {
14346 // create a temporary file if the file does not exist.
14347 // have to do this, otherwise StringUtility::getAbsolutePathFromRelativePath() complains
14348 // which is called by result->setupSourceFilename(arglist);
14349 testfile.close();
14350 ofstream outputfile(inputFileName.c_str(),ios::out);
14351 // DQ (2/6/2009): I think this comment is helpful to put into the file (helps explain why the file exists).
14352 outputfile<<"// Output file generated so that StringUtility::getAbsolutePathFromRelativePath() will see a vaild file ... unparsed file will have rose_ prefix "<<endl;
14353 outputfile.close();
14354 }
14355 else // file already exists , load and parse it
14356 {
14357 // should not reparse all files in case their ASTs have unsaved changes,
14358 // just parse the newly loaded file only.
14359 // use argv here, change non-existing input file later on
14360 // TODO add error code handling
14361
14362 // DQ (2/6/2009): Avoid closing this file twice (so put this here, instead of below).
14363 testfile.close();
14364 // should remove the old one here, Liao, 5/1/2009
14365 }
14366
14367 // DQ (2/6/2009): Avoid closing this file twice (moved to false branch above).
14368 // testfile.close();
14369
14370 // DQ (2/6/2009): Need to add the inputFileName to the source file list in the project,
14371 // because this list will be used to subtract off the source files as required to build
14372 // the commandline for the backend compiler.
14373 project->get_sourceFileNameList().push_back(inputFileName);
14374
14375 Rose_STL_Container<string> sourceFilenames = project->get_sourceFileNameList();
14376 // printf ("In SageBuilder::buildFile(): sourceFilenames.size() = %" PRIuPTR " sourceFilenames = %s \n",sourceFilenames.size(),StringUtility::listToString(sourceFilenames).c_str());
14377
14378 arglist = project->get_originalCommandLineArgumentList();
14379
14380 // DQ (2/6/2009): We will be compiling the source code generated in the
14381 // "rose_<inputFileName>" file, so we don't want this on the argument stack.
14382 // TV (09/19/2018): only add if not already present
14383 if (std::find(arglist.begin(), arglist.end(), sourceFilename) == arglist.end())
14384 {
14385 arglist.push_back(sourceFilename);
14386 }
14387
14388 // DQ (2/6/2009): Modified.
14389 // There is output file name specified for rose translators
14390 if (outputFileName.empty() == false)
14391 {
14392 arglist.push_back("-rose:o");
14393 // arglist.push_back("-o");
14394 arglist.push_back(outputFileName);
14395 }
14396
14397 // DQ (4/15/2010): Turn on verbose mode
14398 // arglist.push_back("-rose:verbose 2");
14399
14400 // This handles the case where the original command line may have referenced multiple files.
14401 Rose_STL_Container<string> fileList = CommandlineProcessing::generateSourceFilenames(arglist,/* binaryMode = */ false);
14402 CommandlineProcessing::removeAllFileNamesExcept(arglist,fileList,sourceFilename);
14403
14404 // DQ (9/3/2008): Added support for SgSourceFile IR node
14405 // SgFile* result = new SgFile (arglist, nextErrorCode, 0, project);
14406 // AS(10/04/08) Because of refactoring we require the determineFileType function to be called
14407 // to construct the node.
14408 // SgSourceFile* result = new SgSourceFile (arglist, nextErrorCode, 0, project);
14409 // SgSourceFile* result = isSgSourceFile(determineFileType(arglist, nextErrorCode, project));
14410 // TH (2009-07-15): changed to more generig isSgFile, this also supports SgBinaryComposite
14411 SgFile* result = determineFileType(arglist, nextErrorCode, project);
14412 ROSE_ASSERT(result != NULL);
14413
14414#if 0
14415 printf ("In SageBuilder::buildFile(): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",project,project->get_fileList_ptr()->get_listOfFiles().size());
14416#endif
14417
14418 SgSourceFile* sourceFile = isSgSourceFile(result);
14419 if (sourceFile != NULL)
14420 {
14421 SgGlobal* globalScope = sourceFile->get_globalScope();
14422 ROSE_ASSERT(globalScope != NULL);
14423
14424 // DQ (6/24/2021): We need to end this function with the isModified flag set to false. This is
14425 // important for the support of the token based unparsing when building a dynamic library.
14426 // This is important in permitting the simpleFrontierDetectionForTokenStreamMapping() function
14427 // to generate the correct settings for nodes in the second file constructed from the original file.
14428 if (globalScope->get_isModified() == true)
14429 {
14430#if 0
14431 printf ("In SageBuilder::buildFile(): globalScope->get_isModified() == true: reset to false \n");
14432#endif
14433 globalScope->set_isModified(false);
14434#if 0
14435 printf ("In SageBuilder::buildFile(): Verify false setting: globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
14436#endif
14437 }
14438 }
14439
14440#if 0
14441 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14442 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14443
14444 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14445 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14446#endif
14447
14448#if 0
14449 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14450 ROSE_ASSERT(project != NULL);
14451 std::set<SgLocatedNode*> tmp2_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14452
14453 if (tmp2_collectionOfModifiedLocatedNodes.size() > 0)
14454 {
14455 printf ("In Traversal::evaluateInheritedAttribute(): tmp2_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp2_collectionOfModifiedLocatedNodes.size());
14456#if 1
14457 printf ("Exiting as a test! \n");
14458 ROSE_ASSERT(false);
14459#endif
14460 }
14461#endif
14462
14463#if 0
14464 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14465 ROSE_ASSERT(project != NULL);
14466 std::set<SgLocatedNode*> tmp22_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(result);
14467
14468 if (tmp22_collectionOfModifiedLocatedNodes.size() > 0)
14469 {
14470 printf ("In Traversal::evaluateInheritedAttribute(): tmp22_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp22_collectionOfModifiedLocatedNodes.size());
14471#if 1
14472 printf ("Exiting as a test! \n");
14473 ROSE_ASSERT(false);
14474#endif
14475 }
14476#endif
14477
14478#if 0
14479 printf ("Calling outputFileIds() \n");
14480
14482
14483 printf ("DONE: Calling outputFileIds() \n");
14484#endif
14485
14486#if 0
14487 // DQ (9/18/2019): Adding debugging support.
14488 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization() = %s \n",
14489 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization() ? "true" : "false");
14490#endif
14491
14492#if 0
14493 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization_source_file() = %s \n",
14494 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14495 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization_header_file() = %s \n",
14496 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14497#endif
14498
14499 // DQ (9/18/2019): Adding debugging support.
14500 // ROSE_ASSERT(result->get_header_file_unparsing_optimization() == false);
14501 // ROSE_ASSERT(result->get_header_file_unparsing_optimization_source_file() == false);
14502 // ROSE_ASSERT(result->get_header_file_unparsing_optimization_header_file() == false);
14503
14504 // ROSE_ASSERT(result->get_header_file_unparsing_optimization() == true);
14505
14506#if 0
14507 // DQ (4/24/2021): This data member header_file_unparsing_optimization is now static (so we don't need this code).
14508 if (set_header_file_unparsing_optimization == true)
14509 {
14510 result->set_header_file_unparsing_optimization(true);
14511
14512 // DQ (9/18/2019): Also set the values for the source file and header files.
14513 // I think we only want to set the source file version to true and the header file version to false.
14514 // This is enforced in the attachPreprocessingInfo() function.
14515
14516 // DQ (4/24/2021): Debugging header file optimization.
14517 // result->set_header_file_unparsing_optimization_source_file(true);
14518
14519 // result->set_header_file_unparsing_optimization_header_file(true);
14520 result->set_header_file_unparsing_optimization_header_file(false);
14521
14522#if 0
14523 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization() = %s \n",
14524 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization() ? "true" : "false");
14525 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization_source_file() = %s \n",
14526 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14527 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization_header_file() = %s \n",
14528 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14529#endif
14530 }
14531#endif
14532
14533#if 0
14534 // 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.
14535 // 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
14536 // 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
14537 // cleaner semantics.
14538 // This just adds the new file to the list of files stored internally (note: this sets the parent of the newFile).
14539 // TOO1 (2/28/2014): This is definitely required for Java (ECJ frontend), though C passes without it (I think only
14540 // by luck :-).
14541 // The ECJ frontend uses the SgProject internally (via a global SgProject*). Therefore, the
14542 // SgProject must contain this newly created SgFile, otherwise ECJ won't be able to find it.
14543 // project->set_file ( *result );
14544 if (project->get_Java_only() == true)
14545 {
14546 // DQ (3/4/2014): For now we want to output a message and clean this up afterward (likely in the Java language support).
14547 printf ("WARNING: Java specific action to add new file to SgProject (using set_file()) (more uniform language handling symantics would avoid this problem) \n");
14548 project->set_file ( *result );
14549 }
14550#else
14551 // DQ (3/6/2014): The code below adresses the specific bug faced in the use of the outliner (so we use it directly).
14552 // This code was moved ahead of the call to "result->runFrontend(nextErrorCode);" because in the case of Java
14553 // the file must be set to be a part of the SgProject before calling the runFrontend() function.
14554 // project->set_file ( *result );
14555
14556 result->set_parent(project);
14557
14558#if 0
14559 printf ("In SageBuilder::buildFile(): Outliner::use_dlopen = %s \n",Outliner::use_dlopen ? "true" : "false");
14560#endif
14561
14562#if 0
14563 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14564 ROSE_ASSERT(project != NULL);
14565 std::set<SgLocatedNode*> tmp23_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(result);
14566
14567 if (tmp23_collectionOfModifiedLocatedNodes.size() > 0)
14568 {
14569 printf ("In Traversal::evaluateInheritedAttribute(): tmp23_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp23_collectionOfModifiedLocatedNodes.size());
14570#if 1
14571 printf ("Exiting as a test! \n");
14572 ROSE_ASSERT(false);
14573#endif
14574 }
14575#endif
14576
14577#if 0
14578 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14579 ROSE_ASSERT(project != NULL);
14580 std::set<SgLocatedNode*> tmp24_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14581
14582 if (tmp24_collectionOfModifiedLocatedNodes.size() > 0)
14583 {
14584 printf ("In Traversal::evaluateInheritedAttribute(): tmp24_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp24_collectionOfModifiedLocatedNodes.size());
14585#if 1
14586 printf ("Exiting as a test! \n");
14587 ROSE_ASSERT(false);
14588#endif
14589 }
14590#endif
14591
14592 // DQ (3/5/2014): I need to check with Liao to understand this part of the code better.
14593 // I think that the default value for Outliner::use_dlopen is false, so that when the
14594 // Java support is used the true branch is taken. However, if might be the we need
14595 // to support the outliner using the code below and so this would be a bug for the
14596 // outliner.
14597 if (!Outliner::use_dlopen)
14598 {
14599#if 0
14600 printf ("In SageBuilder::buildFile(): (after test for (!Outliner::use_dlopen) == true: project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14601 project,project->get_fileList_ptr()->get_listOfFiles().size());
14602#endif
14603 // DQ (3/5/2014): If we added the file above, then don't add it here since it is redundant.
14604 project->set_file(*result); // equal to push_back()
14605#if 0
14606 printf ("In SageBuilder::buildFile(): (after 2nd project->set_file()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14607 project,project->get_fileList_ptr()->get_listOfFiles().size());
14608#endif
14609 }
14610 else
14611 {
14612#if 0
14613 printf ("In SageBuilder::buildFile(): (after test for (!Outliner::use_dlopen) == false: project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14614 project,project->get_fileList_ptr()->get_listOfFiles().size());
14615#endif
14616
14617 // Liao, 5/1/2009,
14618 // if the original command line is: gcc -c -o my.o my.c and we want to
14619 // add a new file(mynew.c), the command line for the new file would become "gcc -c -o my.o mynew.c "
14620 // which overwrites the object file my.o from my.c and causes linking error.
14621 // To avoid this problem, I insert the file at the beginning and let the right object file to be the last generated one
14622 //
14623 // TODO This is not an elegant fix and it causes some strange assertion failure in addAssociatedNodes(): default case node
14624 // So we only turn this on if Outliner:: use_dlopen is used for now
14625 // The semantics of adding a new source file can cause changes to linking phase (new object files etc.)
14626 // But ROSE has a long-time bug in handling combined compiling and linking command like "translator -o a.out a.c b.c"
14627 // It will generated two command lines: "translator -o a.out a.c" and "translator -o a.out b.c", which are totally wrong.
14628 // This problem is very relevant to the bug.
14629 SgFilePtrList& flist = project->get_fileList();
14630 flist.insert(flist.begin(),result);
14631#if 0
14632 printf ("In SageBuilder::buildFile(): (after flist.insert(flist.begin(),result)): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14633 project,project->get_fileList_ptr()->get_listOfFiles().size());
14634#endif
14635 }
14636#endif
14637
14638#if 0
14639 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14640 ROSE_ASSERT(project != NULL);
14641 std::set<SgLocatedNode*> tmp25_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14642
14643 if (tmp25_collectionOfModifiedLocatedNodes.size() > 0)
14644 {
14645 printf ("In Traversal::evaluateInheritedAttribute(): tmp25_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp25_collectionOfModifiedLocatedNodes.size());
14646#if 1
14647 printf ("Exiting as a test! \n");
14648 ROSE_ASSERT(false);
14649#endif
14650 }
14651#endif
14652
14653 // DQ (6/3/2019): The case of outlining to a seperate file will have transformations
14654 // that this checking will fail on because it is for the typical case of checking the
14655 // AST for transformations after construction of the AST from an typical input file.
14656 EDG_ROSE_Translation::suppress_detection_of_transformations = true;
14657
14658#if 0
14659 printf ("In SageBuilder::buildFile(): EDG_ROSE_Translation::suppress_detection_of_transformations = %s \n",EDG_ROSE_Translation::suppress_detection_of_transformations ? "true" : "false");
14660#endif
14661
14662#if 0
14663 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());
14664#endif
14665
14666
14667 // 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.
14668 // 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
14669 // 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
14670 // 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
14671 // the traversal) and then afterward reset the set of isModified IR nodes to isModified. By isolating the fix in this function we can eliminate
14672 // the complexity of it being seen from the outside (outside of this abstraction). Note that the function:
14673 // SageInterface::collectModifiedLocatedNodes() has previously been implemented and used for debugging.
14674 std::set<SgLocatedNode*> modifiedNodeSet = collectModifiedLocatedNodes(project);
14675
14676#if 0
14677 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14678 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14679
14680 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14681 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14682#endif
14683
14684#if 0
14685 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14686 ROSE_ASSERT(project != NULL);
14687 std::set<SgLocatedNode*> tmp251_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14688
14689 if (tmp251_collectionOfModifiedLocatedNodes.size() > 0)
14690 {
14691 printf ("In Traversal::evaluateInheritedAttribute(): tmp251_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp251_collectionOfModifiedLocatedNodes.size());
14692#if 1
14693 printf ("Exiting as a test! \n");
14694 ROSE_ASSERT(false);
14695#endif
14696 }
14697#endif
14698
14699 // 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.
14700 // 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.
14701 // 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.
14702 result->runFrontend(nextErrorCode);
14703
14704#if 0
14705 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());
14706#endif
14707
14708#if 0
14709 printf ("After result->runFrontend(): calling outputFileIds() \n");
14710
14712
14713 printf ("DONE: After result->runFrontend(): calling outputFileIds() \n");
14714#endif
14715
14716#if 0
14717 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14718 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14719
14720 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14721 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14722#endif
14723
14724#if 0
14725 // DQ (6/24/2021): This can be expected to fail, because the new AST has been build and all of the
14726 // nodes are marked as isModified until rest in the AstPostProcessing() step (below).
14727 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14728 ROSE_ASSERT(project != NULL);
14729 std::set<SgLocatedNode*> tmp26_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14730
14731 if (tmp26_collectionOfModifiedLocatedNodes.size() > 0)
14732 {
14733 printf ("In Traversal::evaluateInheritedAttribute(): tmp26_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp26_collectionOfModifiedLocatedNodes.size());
14734#if 0
14735 printf ("Exiting as a test! \n");
14736 ROSE_ASSERT(false);
14737#endif
14738 }
14739#endif
14740
14741#if 0
14742 // Output an optional graph of the AST (just the tree, when active)
14743 printf ("Generating a dot file... (SgFile only) \n");
14744 generateDOT ( *project );
14745 // generateAstGraph(project, 2000);
14746#endif
14747
14748#if 0
14749 printf ("In SageBuilder::buildFile(): Generate the dot output for multiple files (ROSE AST) \n");
14750 // generateDOT ( *project );
14751 generateDOTforMultipleFile ( *project );
14752 printf ("DONE: Generate the dot output of the SAGE III AST \n");
14753#endif
14754
14755#if 0
14756 // DQ (7/18/2019): Output a graph of the AST for debugging.
14757 // Output an optional graph of the AST (the whole graph, of bounded complexity, when active)
14758 const int MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH = 8000;
14759 generateAstGraph(project,MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH);
14760#endif
14761
14762 // DQ (7/14/2019): I think we need to call the astPostProcessing at this point.
14763#if 0
14764 printf ("In SageBuilder::buildFile(): calling astPostProcessing() \n");
14765#endif
14766
14767 if (!project->get_skip_post_processing()) AstPostProcessing(result);
14768
14769#if 0
14770 printf ("In SageBuilder::buildFile(): DONE: calling astPostProcessing() \n");
14771#endif
14772
14773#if 0
14774 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14775 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14776
14777 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14778 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14779#endif
14780
14781#if 0
14782 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14783 ROSE_ASSERT(project != NULL);
14784 std::set<SgLocatedNode*> tmp265_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14785
14786 if (tmp265_collectionOfModifiedLocatedNodes.size() > 0)
14787 {
14788 printf ("In Traversal::evaluateInheritedAttribute(): tmp265_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp265_collectionOfModifiedLocatedNodes.size());
14789#if 1
14790 printf ("Exiting as a test! \n");
14791 ROSE_ASSERT(false);
14792#endif
14793 }
14794#endif
14795
14796#if 0
14797 result->display("SageBuilder::buildFile()");
14798#endif
14799
14800 ROSE_ASSERT(project != NULL);
14801 project->set_frontendErrorCode(max(project->get_frontendErrorCode(), nextErrorCode));
14802
14803 // Not sure why a warning shows up from astPostProcessing.C
14804 // SgNode::get_globalMangledNameMap().size() != 0 size = %" PRIuPTR " (clearing mangled name cache)
14805 if (result->get_globalMangledNameMap().size() != 0)
14806 {
14807 result->clearGlobalMangledNameMap();
14808 }
14809
14810 // DQ (6/5/2019): Use the previously constructed set (above) to reset the IR nodes to be marked as isModified.
14811 // std::set<SgLocatedNode*> modifiedNodeSet = collectModifiedLocatedNodes(project);
14812 // void resetModifiedLocatedNodes(const std::set<SgLocatedNode*> & modifiedNodeSet);
14813 resetModifiedLocatedNodes(modifiedNodeSet);
14814
14815#if 0
14816 printf ("Exiting as a test! \n");
14817 ROSE_ABORT();
14818#endif
14819
14820#if 0
14821 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14822 ROSE_ASSERT(project != NULL);
14823 std::set<SgLocatedNode*> tmp27_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14824
14825 if (tmp27_collectionOfModifiedLocatedNodes.size() > 0)
14826 {
14827 printf ("In Traversal::evaluateInheritedAttribute(): tmp27_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp27_collectionOfModifiedLocatedNodes.size());
14828#if 1
14829 printf ("Exiting as a test! \n");
14830 ROSE_ASSERT(false);
14831#endif
14832 }
14833#endif
14834
14835 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
14836 if (isCopyOfExistingFile_testForSharedNodes == true)
14837 {
14838 // Sharing of IR nodes happens in the AST when the same file is read twice.
14839 // Also in the case where two declarations in the global scope match in two different ASTs (typically in header files of different translation units).
14840
14841#if 0
14842 printf ("Found isCopyOfExistingFile_testForSharedNodes == true \n");
14843 printf ("fileBeingCopied = %p = %s \n",fileBeingCopied,fileBeingCopied->getFileName().c_str());
14844#endif
14845
14846 SgSourceFile* sourceFileBeingCopied = isSgSourceFile(fileBeingCopied);
14847 ROSE_ASSERT(sourceFileBeingCopied != NULL);
14848
14849 SgSourceFile* sourceResult = isSgSourceFile(result);
14850 ROSE_ASSERT(sourceResult != NULL);
14851
14852 SgGlobal* fileBeingCopied_globalScope = sourceFileBeingCopied->get_globalScope();
14853 SgGlobal* result_globalScope = sourceResult->get_globalScope();
14854#if 0
14855 printf ("fileBeingCopied_globalScope = %p \n",fileBeingCopied_globalScope);
14856 printf ("result_globalScope = %p \n",result_globalScope);
14857#endif
14858 ROSE_ASSERT(fileBeingCopied_globalScope != NULL);
14859 ROSE_ASSERT(result_globalScope != NULL);
14860
14861 SgDeclarationStatementPtrList fileBeingCopied_declarationList = fileBeingCopied_globalScope->get_declarations();
14862 SgDeclarationStatementPtrList result_declarationList = result_globalScope->get_declarations();
14863
14864#if 1
14865 // DQ (11/22/2019): Use set intersection to compute the list to make be shared (this is a better implementation).
14866 // This implementation is insensitive to transforamtions in the original AST for the file.
14867 vector<SgDeclarationStatement*>::iterator it;
14868 SgDeclarationStatementPtrList v(fileBeingCopied_declarationList.size());
14869
14870 // This is n log n in complexity, but likely OK.
14871 std::sort(fileBeingCopied_declarationList.begin(),fileBeingCopied_declarationList.end());
14872 std::sort(result_declarationList.begin(),result_declarationList.end());
14873
14874 // printf ("v.size() = %zu \n",v.size());
14875
14876 it = std::set_intersection(fileBeingCopied_declarationList.begin(),fileBeingCopied_declarationList.end(),result_declarationList.begin(),result_declarationList.end(),v.begin());
14877
14878 v.resize(it-v.begin());
14879
14880 int fileBeingCopied_file_id = fileBeingCopied->get_startOfConstruct()->get_physical_file_id();
14881
14882 // printf ("v.size() = %zu \n",v.size());
14883 for (size_t i = 0; i < v.size(); i++)
14884 {
14885 SgDeclarationStatement* intersection_element = v[i];
14886 // printf ("intersection_element = %p = %s \n",intersection_element,intersection_element->class_name().c_str());
14887#if 0
14888 printf (" --- SageBuilder::buildFile() is sharing this node: %p %s \n",intersection_element,intersection_element->class_name().c_str());
14889#endif
14890 // DQ (11/10/2019): Need to recursively mark this as shared so that the unparser will be able to test each line?
14891
14892 fixupSharingSourcePosition(intersection_element,fileBeingCopied_file_id);
14893#if 0
14894 printf ("Exiting as a test! \n");
14895 ROSE_ABORT();
14896#endif
14897 }
14898
14899#if 0
14900 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14901 ROSE_ASSERT(project != NULL);
14902 std::set<SgLocatedNode*> tmp28_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14903
14904 if (tmp28_collectionOfModifiedLocatedNodes.size() > 0)
14905 {
14906 printf ("In Traversal::evaluateInheritedAttribute(): tmp28_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp28_collectionOfModifiedLocatedNodes.size());
14907#if 1
14908 printf ("Exiting as a test! \n");
14909 ROSE_ASSERT(false);
14910#endif
14911 }
14912#endif
14913
14914#else
14915
14916#error "DEAD CODE!"
14917
14918 // This is the older implementation that is sensitive to transforamtions in the original AST from the file.
14919 // DQ (11/21/2019): Remove elements in the vector that are SgEmptyDeclarations which
14920 // are associated with some transformations (include header, for example).
14921 std::vector<SgDeclarationStatementPtrList::iterator> removeList;
14922 SgDeclarationStatementPtrList::iterator i = fileBeingCopied_declarationList.begin();
14923 while (i != fileBeingCopied_declarationList.end())
14924 {
14925 SgEmptyDeclaration* emptyDeclaration = isSgEmptyDeclaration(*i);
14926 if (emptyDeclaration != NULL)
14927 {
14928 removeList.push_back(i);
14929 }
14930
14931 i++;
14932 }
14933
14934#error "DEAD CODE!"
14935
14936 // Need seperate list to avoid iterator invalidation.
14937 // for (SgDeclarationStatementPtrList::iterator i = removeList.begin(); i != removeList.end(); i++)
14938 for (std::vector<SgDeclarationStatementPtrList::iterator>::iterator i = removeList.begin(); i != removeList.end(); i++)
14939 {
14940 fileBeingCopied_declarationList.erase(*i);
14941 }
14942
14943 // DQ (11/21/2019): These might be a different size if for example the file being
14944 // copied is being copied after some transformations to the AST from the original file.
14945 if (fileBeingCopied_declarationList.size() != result_declarationList.size())
14946 {
14947 printf ("fileBeingCopied_declarationList.size() = %zu \n",fileBeingCopied_declarationList.size());
14948 printf ("result_declarationList.size() = %zu \n",result_declarationList.size());
14949 }
14950 ROSE_ASSERT(fileBeingCopied_declarationList.size() == result_declarationList.size());
14951
14952#error "DEAD CODE!"
14953
14954#if 0
14955 printf ("Statements from global scope (size = %zu): \n",fileBeingCopied_declarationList.size());
14956#endif
14957 for (size_t i = 0; i < fileBeingCopied_declarationList.size(); i++)
14958 {
14959 SgDeclarationStatement* fileBeingCopied_decl = fileBeingCopied_declarationList[i];
14960 SgDeclarationStatement* result_decl = result_declarationList[i];
14961#if 0
14962 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());
14963#endif
14964 if (fileBeingCopied_decl == result_decl)
14965 {
14966#if 0
14967 printf (" --- SageBuilder::buildFile() is sharing this node: %p %s \n",fileBeingCopied_decl,fileBeingCopied_decl->class_name().c_str());
14968#endif
14969 // DQ (11/10/2019): Need to recursively mark this as shared so that the unparser will be able to test each line?
14970
14971#error "DEAD CODE!"
14972
14973 int fileBeingCopied_file_id = fileBeingCopied->get_startOfConstruct()->get_physical_file_id();
14974 fixupSharingSourcePosition(fileBeingCopied_decl,fileBeingCopied_file_id);
14975#if 0
14976 printf ("Exiting as a test! \n");
14977 ROSE_ABORT();
14978#endif
14979 }
14980 }
14981
14982#error "DEAD CODE!"
14983
14984#endif
14985
14986#if 0
14987 printf ("exiting as a test! \n");
14988 ROSE_ABORT();
14989#endif
14990 }
14991
14992#if 0
14993 reportModifiedStatements("Leaving SageBuilder::buildFile(): calling reportModifiedStatements()",project);
14994#endif
14995
14996#if 0
14997 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14998 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14999 printf ("Leaving SageBuilder::buildFile(): (after result->runFrontend()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
15000 project,project->get_fileList_ptr()->get_listOfFiles().size());
15001 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
15002 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
15003#endif
15004
15005#if 0
15006 // DQ (11/8/2019): This is not working and breaks the current work at present.
15007 // DQ (11/8/2019): Support function to change the name in each of the IR node's source position info objects.
15008 fixupSourcePositionFileSpecification(result,outputFileName);
15009#endif
15010
15011 // DQ (7/2/2020): Added assertion (fails for snippet tests).
15012 ROSE_ASSERT(result->get_preprocessorDirectivesAndCommentsList() != NULL);
15013
15014#if 0
15015 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
15016 ROSE_ASSERT(project != NULL);
15017 std::set<SgLocatedNode*> tmp3_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
15018
15019 if (tmp3_collectionOfModifiedLocatedNodes.size() > 0)
15020 {
15021 printf ("In Traversal::evaluateInheritedAttribute(): tmp3_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp3_collectionOfModifiedLocatedNodes.size());
15022#if 1
15023 printf ("Exiting as a test! \n");
15024 ROSE_ASSERT(false);
15025#endif
15026 }
15027#endif
15028
15029 return result;
15030#else
15031
15032 // false branch of #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT (at top of function.
15033
15034 return NULL;
15035#endif
15036 }
15037
15038
15041SageBuilder::buildSourceFile(const std::string& outputFileName, SgProject* project, bool clear_globalScopeAcrossFiles /*=false*/)
15042 {
15043 // DQ (2/9/2013): Adding support to build a SgSourceFile with an empty global scope.
15044 // This function calls the buildFile(string,string,SgProject*) function and provides
15045 // a simple API where one wants to create a new SgSourceFile that will then have
15046 // statements added to it and then unparsed.
15047
15048 // This function needs a way to specify the associated language for the generated file.
15049 // Currently this is taken from the input file (generated from a prefix on the output filename.
15050
15051#if 1
15052 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
15053 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
15054 printf ("In SageBuilder::buildSourceFile(outputFileName = %s, project = %p) \n",outputFileName.c_str(),project);
15055 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
15056 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
15057#endif
15058
15059 // Call the supporting function to build a file.
15060 string inputFilePrefix = "temp_dummy_file_";
15061
15062#if 0
15063 printf ("In SageBuilder::buildSourceFile(const std::string& outputFileName, SgProject* project): calling buildFile() \n");
15064#endif
15065
15066 SgFile* file = buildFile(inputFilePrefix+outputFileName,outputFileName,project,clear_globalScopeAcrossFiles);
15067 ROSE_ASSERT(file != NULL);
15068
15069#if 0
15070 printf ("DONE: In SageBuilder::buildSourceFile(): calling buildFile() \n");
15071#endif
15072
15073 SgSourceFile* sourceFile = isSgSourceFile(file);
15074 ROSE_ASSERT(sourceFile != NULL);
15075
15076 ROSE_ASSERT(sourceFile->get_globalScope() != NULL);
15077
15078#if 0
15079 printf ("call the unparser on the just built file \n");
15080#endif
15081
15082#if 0
15083 printf ("Exiting as a test! \n");
15084 ROSE_ABORT();
15085#endif
15086
15087 return sourceFile;
15088
15089 }
15090
15091SgSourceFile* SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project, bool clear_globalScopeAcrossFiles /*=false*/)
15092 {
15093#if 0
15094 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
15095 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
15096 printf ("In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling buildFile() \n");
15097 // printf (" --- inputFileName = %s outputFileName = %s \n",inputFileName.c_str(),outputFileName.c_str());
15098 printf (" --- inputFileName = %s \n",inputFileName.c_str());
15099 printf (" --- outputFileName = %s \n",outputFileName.c_str());
15100 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
15101 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
15102#endif
15103
15104#if 0
15105 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
15106 ROSE_ASSERT(project != NULL);
15107 std::set<SgLocatedNode*> tmp1_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
15108
15109 if (tmp1_collectionOfModifiedLocatedNodes.size() > 0)
15110 {
15111 printf ("In Traversal::evaluateInheritedAttribute(): tmp1_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp1_collectionOfModifiedLocatedNodes.size());
15112#if 1
15113 printf ("Exiting as a test! \n");
15114 ROSE_ASSERT(false);
15115#endif
15116 }
15117#endif
15118
15119 SgFile* file = buildFile(inputFileName, outputFileName,project,clear_globalScopeAcrossFiles);
15120 ROSE_ASSERT(file != NULL);
15121
15122#if 0
15123 printf ("DONE: In SageBuilder::buildSourceFile(): calling buildFile() \n");
15124#endif
15125
15126#if 0
15127 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
15128 ROSE_ASSERT(project != NULL);
15129 std::set<SgLocatedNode*> tmp2_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
15130
15131 if (tmp2_collectionOfModifiedLocatedNodes.size() > 0)
15132 {
15133 printf ("In Traversal::evaluateInheritedAttribute(): tmp2_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp2_collectionOfModifiedLocatedNodes.size());
15134#if 1
15135 printf ("Exiting as a test! \n");
15136 ROSE_ASSERT(false);
15137#endif
15138 }
15139#endif
15140
15141 SgSourceFile* sourceFile = isSgSourceFile(file);
15142 ROSE_ASSERT(sourceFile != NULL);
15143
15144 ROSE_ASSERT(sourceFile->get_globalScope() != NULL);
15145
15146#if 0
15147 // DQ (9/18/2019): Adding support for debugging the header file optimization.
15148 printf ("Debugging the unparsing header file optimization \n");
15149
15150 printf ("sourceFile->get_header_file_unparsing_optimization() = %s \n",sourceFile->get_header_file_unparsing_optimization() ? "true" : "false");
15151 printf ("sourceFile->get_header_file_unparsing_optimization_source_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
15152 printf ("sourceFile->get_header_file_unparsing_optimization_header_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
15153#endif
15154
15155#if 0
15156 // ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == false);
15157
15158 // 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.
15159 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization() == true);
15160 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_source_file() == true);
15161 // ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == true);
15162 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == false);
15163#endif
15164
15165 // DQ (9/18/2019): Adding support for the header file optimization.
15166 // Check is this file matches an existing file and if so avoid regathering the CPP directives and comments (if posible).
15167 // If the original file was specified as being optimized for unparsing header files, then make this one similarly.
15168 SgFilePtrList & fileList = project->get_fileList();
15169
15170#if 0
15171 printf ("Looking for file = %s \n",inputFileName.c_str());
15172#endif
15173
15174 for (SgFilePtrList::iterator i = fileList.begin(); i != fileList.end(); i++)
15175 {
15176 SgFile* temp_file = *i;
15177#if 0
15178 printf ("temp_file = %p = %s name = %s \n",temp_file,temp_file->class_name().c_str(),temp_file->getFileName().c_str());
15179#endif
15180 if (temp_file != file)
15181 {
15182 if (temp_file->getFileName() == file->getFileName())
15183 {
15184 // Then the temp_file is the original version of the file we are building for a second time
15185 // (usually as a part of the outlining to a seperate file). and we need to mark at least the
15186 // unparsing headr file optimizations to be the same across thje two file.
15187
15188 // DQ (6/12/2021): The header_file_unparsing_optimization is now a static data member and the
15189 // header_file_unparsing_optimization_source_file and header_file_unparsing_optimization_header_file
15190 // data members have been removed.
15191 // temp_file->set_header_file_unparsing_optimization(sourceFile->get_header_file_unparsing_optimization());
15192 // temp_file->set_header_file_unparsing_optimization_source_file(sourceFile->get_header_file_unparsing_optimization_source_file());
15193 // temp_file->set_header_file_unparsing_optimization_header_file(sourceFile->get_header_file_unparsing_optimization_header_file());
15194#if 0
15195 printf ("sourceFile = %p = %s \n",sourceFile,sourceFile->class_name().c_str());
15196 printf ("sourceFile->get_header_file_unparsing_optimization() = %s \n",sourceFile->get_header_file_unparsing_optimization() ? "true" : "false");
15197 printf ("sourceFile->get_header_file_unparsing_optimization_source_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
15198 printf ("sourceFile->get_header_file_unparsing_optimization_header_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
15199
15200 printf ("temp_file = %p = %s \n",temp_file,temp_file->class_name().c_str());
15201 printf ("temp_file->get_header_file_unparsing_optimization() = %s \n",temp_file->get_header_file_unparsing_optimization() ? "true" : "false");
15202 printf ("temp_file->get_header_file_unparsing_optimization_source_file() = %s \n",temp_file->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
15203 printf ("temp_file->get_header_file_unparsing_optimization_header_file() = %s \n",temp_file->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
15204#endif
15205 }
15206 else
15207 {
15208 // This is a different file.
15209 }
15210 }
15211 else
15212 {
15213 // This is the same file, already added to the SgProject file list (as it should be).
15214 }
15215 }
15216
15217
15218#if 0
15219 printf ("sourceFile->get_file_info()->get_filename() = %s \n",sourceFile->get_file_info()->get_filename());
15220 int filename_id = Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()];
15221 int filename_physical_id = Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()];
15222 printf ("Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()] = %d \n",filename_id);
15223 printf ("Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()] = %d \n",filename_physical_id);
15224 sourceFile->get_file_info()->set_physical_file_id(filename_physical_id);
15225
15226 printf ("sourceFile->get_file_info()->get_physical_filename() = %s \n",sourceFile->get_file_info()->get_physical_filename().c_str());
15227 printf ("sourceFile->get_file_info()->get_physical_file_id() = %d \n",sourceFile->get_file_info()->get_physical_file_id());
15228#endif
15229
15230#if 0
15231 printf ("Exiting as a test! \n");
15232 ROSE_ABORT();
15233#endif
15234
15235 // DQ (1/11/2021): I think we should be calling secondaryPassOverSourceFile() instead of attachPreprocessingInfo() because we need to support the token-based unparsing.
15236#if 0
15237
15238#error "DEAD CODE!"
15239
15240#if 1
15241 // DQ (11/4/2019): I need to add this when I went back to testing tool_G.
15242 // It is required in the functions to attach CPP directives and comments.
15243 if (sourceFile->get_preprocessorDirectivesAndCommentsList() == NULL)
15244 {
15245#if 1
15246 printf ("Initialize NULL p_preprocessorDirectivesAndCommentsList to empty ROSEAttributesListContainer \n");
15247#endif
15248 ROSEAttributesListContainer* tmp_preprocessorDirectivesAndCommentsList = new ROSEAttributesListContainer();
15249 sourceFile->set_preprocessorDirectivesAndCommentsList(tmp_preprocessorDirectivesAndCommentsList);
15250 }
15251 else
15252 {
15253#if 1
15254 printf ("NOTE: p_preprocessorDirectivesAndCommentsList is already defined! \n");
15255 printf (" --- inputFileName = %s \n",inputFileName.c_str());
15256 printf (" --- outputFileName = %s \n",outputFileName.c_str());
15257 printf (" --- sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size() = %zu \n",sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size());
15258#endif
15259 }
15260 ROSE_ASSERT (sourceFile->get_preprocessorDirectivesAndCommentsList() != NULL);
15261
15262#if 0
15263 // DQ (5/22/2020): If this is processing a previously processed file, then this
15264 // will cause comments and CPP directives to be collected twice. This happens
15265 // in the case where we build a copy of the source file to support construction
15266 // of a dynamic library.
15267 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");
15268#endif
15269
15270 // DQ (11/4/2019): This is a test that is use in attaching CPP directives and comments to the AST.
15271 ROSEAttributesListContainerPtr filePreprocInfo = sourceFile->get_preprocessorDirectivesAndCommentsList();
15272 ROSE_ASSERT(filePreprocInfo != NULL);
15273#endif
15274
15275#error "DEAD CODE!"
15276
15277#if 0
15278 printf ("In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling attachPreprocessingInfo() \n");
15279 printf (" --- sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size() = %zu \n",sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size());
15280#endif
15281
15282#if 0
15283 // 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.
15284 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");
15285 printf (" --- inputFileName = %s \n",inputFileName.c_str());
15286 printf (" --- outputFileName = %s \n",outputFileName.c_str());
15287 printf ("sourceFile = %p \n",sourceFile);
15288 printf ("sourceFile->get_token_list.size() = %zu \n",sourceFile->get_token_list().size());
15289 printf ("sourceFile->get_tokenSubsequenceMap().size() = %zu \n",sourceFile->get_tokenSubsequenceMap().size());
15290#endif
15291
15292#error "DEAD CODE!"
15293
15294 // DQ (1/4/2020): Adding support to permit comments and CPP directives and token stream to be defined using the outputFileName.
15295 // Liao, 2019, 1/31: We often need the preprocessing info. (e.g. #include ..) attached to make the new file compilable.
15296 // attachPreprocessingInfo (sourceFile);
15297 attachPreprocessingInfo (sourceFile,outputFileName);
15298#else
15299 // DQ (1/11/2021): Call the secondaryPassOverSourceFile() instead of attachPreprocessingInfo() because we need to support the token-based unparsing.
15301#endif
15302
15303#if 0
15304 printf ("Exiting after test! processed first phase of collecting comments and CPP directives for source file) \n");
15305 ROSE_ASSERT(false);
15306#endif
15307
15308#if 0
15309 printf ("DONE: In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling attachPreprocessingInfo() \n");
15310#endif
15311
15312#if 0
15313 printf ("call the unparser on the just built file \n");
15314#endif
15315
15316#if 0
15317 printf ("In buildSourceFile(): AS A TEST: calling unparseFile(): filename = %s \n",sourceFile->getFileName().c_str());
15318 backend(project);
15319#endif
15320
15321#if 1
15322 // DQ (11/8/2019): This is not working and breaks the current work at present.
15323 // DQ (11/8/2019): Support function to change the name in each of the IR node's source position info objects.
15324 fixupSourcePositionFileSpecification(sourceFile,outputFileName);
15325#endif
15326
15327 // DQ (1/8/2021): Set the filename used in the generated SgSourceFile to be the output file.
15328 // This appears to be important so that we can get either key correct for the comments and CPP
15329 // directives and or the comments and CPP directives to be consistant as well as the token stream,
15330 // I think this might be less about the comments and CPP directives than the key for the token stream.
15331 // Either that or I need to have an extra field for the SgSourceFile name when it is read from one
15332 // file, but trying to be another file.
15333 // sourceFile->setFileName(outputFileName);
15334
15335#if 0
15336 printf ("In SageBuilder::buildSourceFile(): changing the name of the file represented in sourceFile: \n");
15337 printf ("inputFileName = %s \n",inputFileName.c_str());
15338 printf ("outputFileName = %s \n",outputFileName.c_str());
15339 printf ("sourceFile->getFileName() = %s \n",sourceFile->getFileName().c_str());
15340#endif
15341
15342 SgGlobal* globalScope = sourceFile->get_globalScope();
15343
15344#if 0
15345 printf ("Leaving SageBuilder::buildSourceFile() sourceFile = %p globalScope = %p \n",sourceFile,sourceFile->get_globalScope());
15346 printf ("sourceFile->get_file_info()->get_file_id() = %d \n",sourceFile->get_file_info()->get_file_id());
15347 printf ("sourceFile->get_file_info()->get_physical_file_id() = %d \n",sourceFile->get_file_info()->get_physical_file_id());
15348 printf ("sourceFile->get_token_list.size() = %zu \n",sourceFile->get_token_list().size());
15349 printf ("sourceFile->get_tokenSubsequenceMap().size() = %zu \n",sourceFile->get_tokenSubsequenceMap().size());
15350 printf ("inputFileName = %s \n",inputFileName.c_str());
15351 printf ("outputFileName = %s \n",outputFileName.c_str());
15352 printf ("sourceFile->getFileName() = %s \n",sourceFile->getFileName().c_str());
15353
15354 printf ("sourceFile->get_globalScope() = %p \n",globalScope);
15355 printf ("globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
15356#endif
15357
15358 // DQ (6/1/2021): We need to end this function with the isModified flag set to false. This is
15359 // important for the support of the token based unparsing when building a dynamic library.
15360 // This is important in permitting the simpleFrontierDetectionForTokenStreamMapping() function
15361 // to generate the correct settings for nodes in the second file constructed from the original file.
15362 if (globalScope->get_isModified() == true)
15363 {
15364#if 0
15365 printf ("globalScope->get_isModified() == true: reset to false \n");
15366#endif
15367 globalScope->set_isModified(false);
15368#if 0
15369 printf ("Verify false setting: globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
15370#endif
15371 }
15372
15373#if 0
15374 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
15375 ROSE_ASSERT(project != NULL);
15376 std::set<SgLocatedNode*> tmp3_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
15377
15378 if (tmp3_collectionOfModifiedLocatedNodes.size() > 0)
15379 {
15380 printf ("In Traversal::evaluateInheritedAttribute(): tmp3_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp3_collectionOfModifiedLocatedNodes.size());
15381#if 1
15382 printf ("Exiting as a test! \n");
15383 ROSE_ASSERT(false);
15384#endif
15385 }
15386#endif
15387
15388#if 0
15389 printf ("Exiting as a test! \n");
15390 ROSE_ABORT();
15391#endif
15392
15393 return sourceFile;
15394 }
15395
15396
15397PreprocessingInfo* SageBuilder::buildComment(SgLocatedNode* target, const std::string & content,PreprocessingInfo::RelativePositionType position/*=PreprocessingInfo::before*/,PreprocessingInfo::DirectiveType dtype/* = PreprocessingInfo::CpreprocessorUnknownDeclaration*/)
15398 {
15399 return SageInterface::attachComment(target,content, position, dtype);
15400 }
15401
15403PreprocessingInfo* SageBuilder::buildHeader(const std::string& header_filename,
15404 PreprocessingInfo::RelativePositionType position/*=PreprocessingInfo::before*/,
15405 bool isSystemHeader/* =false*/)
15406{
15407 std::string content;
15408 if (isSystemHeader)
15409 content = "#include <" + header_filename + "> \n";
15410 else
15411 content = "#include \"" + header_filename + "\" \n";
15412 PreprocessingInfo* result = new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration,
15413 content, "Transformation generated",0, 0, 0, position);
15414 ROSE_ASSERT(result);
15415
15416 result->get_file_info()->setTransformation();
15417 return result;
15418}
15419
15421PreprocessingInfo* SageBuilder::buildCpreprocessorDefineDeclaration(SgLocatedNode* target,const std::string & content,PreprocessingInfo::RelativePositionType position /* =PreprocessingInfo::before*/)
15422 {
15423 ROSE_ASSERT(target != NULL); //dangling #define xxx is not allowed in the ROSE AST
15424 // simple input verification
15425 std::string content2 = content;
15426 boost::algorithm::trim(content2);
15427 string prefix = "#define";
15428 string::size_type pos = content2.find(prefix, 0);
15429 ROSE_ASSERT (pos == 0);
15430
15431 PreprocessingInfo* result = NULL;
15432
15433 PreprocessingInfo::DirectiveType mytype = PreprocessingInfo::CpreprocessorDefineDeclaration;
15434
15435 // DQ (7/19/2008): Modified interface to PreprocessingInfo
15436 // result = new PreprocessingInfo (mytype,content, "transformation-generated", 0, 0, 0, position, false, true);
15437 result = new PreprocessingInfo (mytype,content, "transformation-generated", 0, 0, 0, position);
15438 ROSE_ASSERT(result);
15439 target->addToAttachedPreprocessingInfo(result);
15440 return result;
15441
15442 }
15443
15444
15445#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
15448{
15449 // avoid duplicated creation
15450 static std::map<SgNode*, AbstractHandle::abstract_handle *> handleMap;
15451
15452 ROSE_ASSERT(n != NULL);
15453 AbstractHandle::abstract_handle * ahandle =handleMap[n];
15454 if (ahandle==NULL)
15455 {
15457 ROSE_ASSERT(anode !=NULL );
15458 ahandle = new AbstractHandle::abstract_handle(anode);
15459 //TODO do we allow NULL handle to be returned?
15460 ROSE_ASSERT(ahandle != NULL);
15461 }
15462 return ahandle;
15463}
15464#endif
15465
15468{
15469 ROSE_ASSERT(exp1 != NULL);
15470 ROSE_ASSERT(exp2 != NULL);
15471
15472 SgExprListExp* tuple = buildExprListExp(exp1,exp2);
15473 SgExprListExp* setList = buildExprListExp(tuple);
15474 SgEquivalenceStatement* equivalenceStatement = new SgEquivalenceStatement();
15475 ROSE_ASSERT(equivalenceStatement->get_equivalence_set_list() == NULL);
15476 equivalenceStatement->set_equivalence_set_list(setList);
15477 ROSE_ASSERT(equivalenceStatement->get_equivalence_set_list() != NULL);
15478 equivalenceStatement->set_firstNondefiningDeclaration(equivalenceStatement);
15479 setOneSourcePositionForTransformation(equivalenceStatement);
15480 return equivalenceStatement;
15481}
15482
15483SgSymbol*
15485 {
15486 // Starting at the snippet_declaration, record the associated scope list to the global scope.
15487 // The do a reverse traversal on the list starting with the global scope of the target AST.
15488 // Lookup each declaration as we proceed deeper into the target AST to find the associated
15489 // symbol in the target AST (associated with the input declaration from the snippet AST).
15490
15491 SgSymbol* returnSymbol = NULL;
15492
15493 typedef Rose_STL_Container<SgScopeStatement*> SgScopeStatementPtrList;
15494 SgScopeStatementPtrList snippet_scope_list;
15495
15496 // Starting at the snippet_declaration, record the associated scope list to the global scope.
15497 // SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15498 SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15499#if 1
15500 printf ("First scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15501 SgClassDefinition* temp_classDefinition = isSgClassDefinition(snippet_scope);
15502 if (temp_classDefinition != NULL)
15503 {
15504 SgClassDeclaration* temp_classDeclaration = temp_classDefinition->get_declaration();
15505 SgName className = temp_classDeclaration->get_name();
15506#if 1
15507 printf ("Input snippet declaration's class name = %s \n",className.str());
15508#endif
15509 }
15510 SgNamespaceDefinitionStatement* namespaceDefinitionStatement = isSgNamespaceDefinitionStatement(snippet_scope);
15511 if (namespaceDefinitionStatement != NULL)
15512 {
15513
15514 }
15515#endif
15516 snippet_scope_list.push_back(snippet_scope);
15517 while (snippet_scope != NULL && isSgGlobal(snippet_scope) == NULL)
15518 {
15519 // The scopes between the snippet declaration and the global scope should be named scopes,
15520 // else we will not be able to identify the associated scope in the target AST.
15521 ROSE_ASSERT(snippet_scope->isNamedScope() == true);
15522
15523 snippet_scope = snippet_scope->get_scope();
15524#if 1
15525 printf ("snippet_scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15526#endif
15527 snippet_scope_list.push_back(snippet_scope);
15528 }
15529
15530#if 1
15531 printf ("snippet_scope_list.size() = %" PRIuPTR " \n",snippet_scope_list.size());
15532#endif
15533
15534 SgGlobal* global_scope_in_target_ast = TransformationSupport::getGlobalScope(targetScope);
15535 SgScopeStatementPtrList::reverse_iterator i = snippet_scope_list.rbegin();
15536
15537 SgScopeStatement* target_AST_scope = global_scope_in_target_ast;
15538 SgScopeStatement* snippet_AST_scope = *i;
15539
15540 ROSE_ASSERT(isSgGlobal(snippet_AST_scope) != NULL);
15541 // Iterate past the global scope
15542 i++;
15543
15544 // Traverse the snippet scopes in the reverse order from global scope to the associated scope in the target AST.
15545 while (i != snippet_scope_list.rend())
15546 {
15547 // This loop has to handle different types of names scopes (for C this only means structs, I think).
15548#if 1
15549 printf ("snippet_AST_scope list *i = %p = %s \n",*i,(*i)->class_name().c_str());
15550#endif
15551 // printf ("target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope ->class_name().c_str());
15552 // printf ("snippet_AST_scope = %p = %s \n",snippet_AST_scope,snippet_AST_scope ->class_name().c_str());
15553
15554 // DQ (12/5/2020): I think this should be a switch statement.
15555 SgClassDefinition* classDefinition = isSgClassDefinition(*i);
15556 if (classDefinition != NULL)
15557 {
15558 SgClassDeclaration* classDeclaration = classDefinition->get_declaration();
15559 SgName className = classDeclaration->get_name();
15560#if 1
15561 printf ("Found snippet class name = %s \n",className.str());
15562#endif
15563 SgClassSymbol* classSymbol = target_AST_scope->lookup_class_symbol(className);
15564 ROSE_ASSERT(classSymbol != NULL);
15565 ROSE_ASSERT(classSymbol->get_declaration() != NULL);
15566#if 1
15567 printf ("Associated symbol in taget AST: declaration = %p name = %s \n",classSymbol->get_declaration(),classSymbol->get_declaration()->get_name().str());
15568#endif
15569 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15570 returnSymbol = classSymbol;
15571
15572 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15573 target_AST_scope = classDefinition;
15574 }
15575
15576 // Not clear if we can have this case for C or C++.
15577 SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(*i);
15578 if (functionDefinition != NULL)
15579 {
15580 printf ("ERROR: Found an unusual case of SgFunctionDefinition in list of scopes holding a declaration for a type \n");
15581 ROSE_ABORT();
15582 }
15583
15584 SgNamespaceDefinitionStatement* namespaceDefinition = isSgNamespaceDefinitionStatement(*i);
15585 if (namespaceDefinition != NULL)
15586 {
15587 SgNamespaceDeclarationStatement* namespaceDeclaration = namespaceDefinition->get_namespaceDeclaration();
15588 SgName namespaceName = namespaceDeclaration->get_name();
15589#if 1
15590 printf ("Found snippet namespace name = %s \n",namespaceName.str());
15591#endif
15592 SgNamespaceSymbol* namespaceSymbol = target_AST_scope->lookup_namespace_symbol(namespaceName);
15593 ROSE_ASSERT(namespaceSymbol != NULL);
15594 ROSE_ASSERT(namespaceSymbol->get_declaration() != NULL);
15595#if 1
15596 printf ("Associated symbol in taget AST: declaration = %p name = %s \n",namespaceSymbol->get_declaration(),namespaceSymbol->get_declaration()->get_name().str());
15597#endif
15598 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15599 returnSymbol = namespaceSymbol;
15600
15601 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15602 target_AST_scope = namespaceDefinition;
15603 }
15604
15605 // Increment the reverse iterator.
15606 i++;
15607 }
15608
15609 // Handle the different cases using a switch (there are only a few cases).
15610 switch (snippet_declaration->variantT())
15611 {
15612 case V_SgClassDeclaration:
15613 {
15614 SgClassDeclaration* snippet_classDeclaration = isSgClassDeclaration(snippet_declaration);
15615 ROSE_ASSERT(snippet_classDeclaration != NULL);
15616
15617 SgName snippet_className = snippet_classDeclaration->get_name();
15618#if 0
15619 printf ("snippet snippet declaration's class name = %s \n",snippet_className.str());
15620#endif
15621 SgClassSymbol* target_symbol = target_AST_scope->lookup_class_symbol(snippet_className);
15622 ROSE_ASSERT(target_symbol != NULL);
15623 returnSymbol = target_symbol;
15624
15625 SgClassSymbol* classSymbolInTargetAST = isSgClassSymbol(returnSymbol);
15626 ROSE_ASSERT(classSymbolInTargetAST != NULL);
15627 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
15628 ROSE_ASSERT(target_classDeclaration != NULL);
15629#if 0
15630 printf ("snippet: classDeclaration = %p = %s \n",snippet_classDeclaration,snippet_classDeclaration->get_name().str());
15631 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
15632#endif
15633 ROSE_ASSERT(snippet_classDeclaration->get_name() == target_classDeclaration->get_name());
15634 break;
15635 }
15636
15637 case V_SgTypedefDeclaration:
15638 {
15639 SgTypedefDeclaration* snippet_typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
15640 ROSE_ASSERT(snippet_typedefDeclaration != NULL);
15641
15642 SgName snippet_typedefName = snippet_typedefDeclaration->get_name();
15643#if 0
15644 printf ("snippet snippet declaration's typedef name = %s \n",snippet_typedefName.str());
15645#endif
15646 SgTypedefSymbol* target_symbol = target_AST_scope->lookup_typedef_symbol(snippet_typedefName);
15647 ROSE_ASSERT(target_symbol != NULL);
15648 returnSymbol = target_symbol;
15649
15650 SgTypedefSymbol* typedefSymbolInTargetAST = isSgTypedefSymbol(returnSymbol);
15651 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15652 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
15653 ROSE_ASSERT(target_typedefDeclaration != NULL);
15654#if 0
15655 printf ("snippet: typedefDeclaration = %p = %s \n",snippet_typedefDeclaration,snippet_typedefDeclaration->get_name().str());
15656 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
15657#endif
15658 ROSE_ASSERT(snippet_typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
15659 break;
15660 }
15661
15662 case V_SgEnumDeclaration:
15663 {
15664 SgEnumDeclaration* snippet_enumDeclaration = isSgEnumDeclaration(snippet_declaration);
15665 ROSE_ASSERT(snippet_enumDeclaration != NULL);
15666
15667 SgName snippet_enumName = snippet_enumDeclaration->get_name();
15668#if 0
15669 printf ("snippet snippet declaration's enum name = %s \n",snippet_enumName.str());
15670#endif
15671 // DQ (4/13/2014): check if this is an un-named enum beclaration.
15672 bool isUnNamed = snippet_enumDeclaration->get_isUnNamed();
15673 if (isUnNamed == false)
15674 {
15675 // SgEnumSymbol* target_symbol = target_AST_scope->lookup_enum_symbol(snippet_enumName);
15676 SgEnumSymbol* target_symbol = lookupEnumSymbolInParentScopes(snippet_enumName,target_AST_scope);
15677 if (target_symbol == NULL)
15678 {
15679 // Debug this case.
15680 SgScopeStatement* scope = snippet_enumDeclaration->get_scope();
15681 printf ("scope = %p = %s \n",scope,scope->class_name().c_str());
15682 scope->get_file_info()->display("case V_SgEnumDeclaration: target_symbol == NULL: scope: debug");
15683 }
15684 ROSE_ASSERT(target_symbol != NULL);
15685 returnSymbol = target_symbol;
15686
15687 SgEnumSymbol* enumSymbolInTargetAST = isSgEnumSymbol(returnSymbol);
15688 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
15689 SgEnumDeclaration* target_enumDeclaration = isSgEnumDeclaration(enumSymbolInTargetAST->get_declaration());
15690 ROSE_ASSERT(target_enumDeclaration != NULL);
15691#if 0
15692 printf ("snippet: enumDeclaration = %p = %s \n",snippet_enumDeclaration,snippet_enumDeclaration->get_name().str());
15693 printf ("target: enumDeclaration = %p = %s \n",target_enumDeclaration,target_enumDeclaration->get_name().str());
15694#endif
15695 ROSE_ASSERT(snippet_enumDeclaration->get_name() == target_enumDeclaration->get_name());
15696 }
15697 else
15698 {
15699 // DQ (4/13/2014): I think we all agreed these would not have to be handled.
15700 printf ("Warning: can't handle unnamed enum declarations \n");
15701 ROSE_ASSERT(returnSymbol == NULL);
15702 }
15703 break;
15704 }
15705
15706 // DQ (12/5/2020): Adding support for codeSegregation tool.
15707 case V_SgMemberFunctionDeclaration:
15708 case V_SgFunctionDeclaration:
15709 {
15710 SgFunctionDeclaration* snippet_functionDeclaration = isSgFunctionDeclaration(snippet_declaration);
15711 ROSE_ASSERT(snippet_functionDeclaration != NULL);
15712#if 1
15713 printf ("snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15714#endif
15715 SgName snippet_functionName = snippet_functionDeclaration->get_name();
15716#if 1
15717 printf ("snippet snippet declaration's function name = %s \n",snippet_functionName.str());
15718 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope->class_name().c_str());
15719#endif
15720 SgFunctionSymbol* target_symbol = target_AST_scope->lookup_function_symbol(snippet_functionName);
15721 ROSE_ASSERT(target_symbol != NULL);
15722 returnSymbol = target_symbol;
15723
15724 SgFunctionSymbol* functionSymbolInTargetAST = isSgFunctionSymbol(returnSymbol);
15725 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
15726 SgFunctionDeclaration* target_functionDeclaration = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
15727 ROSE_ASSERT(target_functionDeclaration != NULL);
15728#if 1
15729 printf ("snippet: functionDeclaration = %p = %s \n",snippet_functionDeclaration,snippet_functionDeclaration->get_name().str());
15730 printf ("target: functionDeclaration = %p = %s \n",target_functionDeclaration,target_functionDeclaration->get_name().str());
15731#endif
15732 ROSE_ASSERT(snippet_functionDeclaration->get_name() == target_functionDeclaration->get_name());
15733 break;
15734 }
15735
15736 default:
15737 {
15738 printf ("Error: default reached in switch: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15739 ROSE_ABORT();
15740 }
15741 }
15742
15743 // return the last found symbol.
15744 return returnSymbol;
15745 }
15746
15747
15750 {
15751 // DQ (12/6/2020): This is a similar function to findAssociatedSymbolInTargetAST() but since
15752 // I need to modify it to support the requirements of the codeSegregation, it was useful to not
15753 // modify the existing findAssociatedSymbolInTargetAST() function too much so as to avoid
15754 // compromizing the snippet transformation support.
15755
15756#define DEBUG_FIND_ASSOCIATED_DECLARATION 0
15757
15758 SgSymbol* returnSymbol = NULL;
15759 SgDeclarationStatement* returnDeclaration = NULL;
15760
15761 bool isDefiningDeclaration = (snippet_declaration == snippet_declaration->get_definingDeclaration());
15762
15763#if DEBUG_FIND_ASSOCIATED_DECLARATION
15764 printf ("isDefiningDeclaration = %s \n",isDefiningDeclaration ? "true" : "false");
15765#endif
15766
15767 // DQ (12/7/2020): This should be true.
15768 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,targetScope) == false);
15769
15770 typedef Rose_STL_Container<SgScopeStatement*> SgScopeStatementPtrList;
15771 SgScopeStatementPtrList snippet_scope_list;
15772
15773 // Starting at the snippet_declaration, record the associated scope list to the global scope.
15774 // SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15775 SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15776#if DEBUG_FIND_ASSOCIATED_DECLARATION
15777 printf ("First scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15778 SgClassDefinition* temp_classDefinition = isSgClassDefinition(snippet_scope);
15779 if (temp_classDefinition != NULL)
15780 {
15781 SgClassDeclaration* temp_classDeclaration = temp_classDefinition->get_declaration();
15782 SgName className = temp_classDeclaration->get_name();
15783 printf ("Input declaration's class name = %s \n",className.str());
15784 }
15785
15786 SgNamespaceDefinitionStatement* namespaceDefinitionStatement = isSgNamespaceDefinitionStatement(snippet_scope);
15787 if (namespaceDefinitionStatement != NULL)
15788 {
15789 SgNamespaceDeclarationStatement* temp_namespaceDeclaration = namespaceDefinitionStatement->get_namespaceDeclaration();
15790 SgName namespaceName = temp_namespaceDeclaration->get_name();
15791 printf ("Input declaration's namespace name = %s \n",namespaceName.str());
15792 }
15793#endif
15794
15795 snippet_scope_list.push_back(snippet_scope);
15796 while (snippet_scope != NULL && isSgGlobal(snippet_scope) == NULL)
15797 {
15798 // The scopes between the snippet declaration and the global scope should be named scopes,
15799 // else we will not be able to identify the associated scope in the target AST.
15800 ROSE_ASSERT(snippet_scope->isNamedScope() == true);
15801
15802 snippet_scope = snippet_scope->get_scope();
15803
15804#if DEBUG_FIND_ASSOCIATED_DECLARATION
15805 printf ("snippet_scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15806#endif
15807 snippet_scope_list.push_back(snippet_scope);
15808
15809 // DQ (12/7/2020): At this point the scopes that we are traversing to the global scope should
15810 // have the same global scope as the input declaration.
15811 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_scope) == true);
15812 }
15813
15814#if DEBUG_FIND_ASSOCIATED_DECLARATION
15815 printf ("snippet_scope_list.size() = %" PRIuPTR " \n",snippet_scope_list.size());
15816 for (SgScopeStatementPtrList::iterator i = snippet_scope_list.begin(); i != snippet_scope_list.end(); i++)
15817 {
15818 SgScopeStatement* scope = *i;
15819 printf (" --- *i = %p = %s name = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
15820 SgGlobal* global_scope_from_declarations_scope = TransformationSupport::getGlobalScope(scope);
15821 printf (" --- --- global_scope_from_declarations_scope = %p \n",global_scope_from_declarations_scope);
15822 }
15823#endif
15824
15825 // DQ (12/7/2020): At this point the scopes that we are traversing to the global scope should
15826 // have the same global scope as the input declaration.
15827 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_scope) == true);
15828
15829 SgGlobal* global_scope_in_target_ast = TransformationSupport::getGlobalScope(targetScope);
15830 SgScopeStatementPtrList::reverse_iterator i = snippet_scope_list.rbegin();
15831
15832#if DEBUG_FIND_ASSOCIATED_DECLARATION
15833 printf ("global_scope_in_target_ast = %p = %s \n",global_scope_in_target_ast,global_scope_in_target_ast->class_name().c_str());
15834#endif
15835
15836 SgScopeStatement* target_AST_scope = global_scope_in_target_ast;
15837 SgScopeStatement* snippet_AST_scope = *i;
15838
15839 // DQ (12/7/2020): This should be true.
15840 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_AST_scope) == true);
15841
15842 ROSE_ASSERT(isSgGlobal(snippet_AST_scope) != NULL);
15843 // Iterate past the global scope
15844 i++;
15845
15846#if DEBUG_FIND_ASSOCIATED_DECLARATION
15847 string otherASTnameFromGlobalScope = global_scope_in_target_ast->get_file_info()->get_filenameString();
15848 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(targetScope,true);
15849 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15850 printf ("Now traverse the list of scopes in reverse to find the declaration in the other AST: \n");
15851 printf ("otherASTnameFromGlobalScope = %s \n",otherASTnameFromGlobalScope.c_str());
15852 printf ("otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15853#endif
15854
15855 // DQ (12/7/2020): This should be true.
15856 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15857
15858 // Traverse the snippet scopes in the reverse order from global scope to the associated scope in the target AST.
15859 while (i != snippet_scope_list.rend())
15860 {
15861 // This loop has to handle different types of names scopes (for C this only means structs, I think).
15862
15863 SgScopeStatement* scope = *i;
15864
15865#if DEBUG_FIND_ASSOCIATED_DECLARATION
15866 printf ("snippet_AST_scope list *i = %p = %s \n",*i,(*i)->class_name().c_str());
15867 printf (" --- *i = %p = %s name = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
15868 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope ->class_name().c_str());
15869 // printf ("snippet_AST_scope = %p = %s \n",snippet_AST_scope,snippet_AST_scope ->class_name().c_str());
15870#endif
15871
15872 // DQ (12/7/2020): This should still be true.
15873 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,scope) == true);
15874
15875#if DEBUG_FIND_ASSOCIATED_DECLARATION
15876 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(targetScope,true);
15877 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15878 printf (" --- otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15879#endif
15880
15881 // DQ (12/5/2020): I think this should be a switch statement.
15882 SgClassDefinition* classDefinition = isSgClassDefinition(*i);
15883 if (classDefinition != NULL)
15884 {
15885 SgClassDeclaration* classDeclaration = classDefinition->get_declaration();
15886 SgName className = classDeclaration->get_name();
15887#if DEBUG_FIND_ASSOCIATED_DECLARATION
15888 printf (" --- Found snippet class name = %s \n",className.str());
15889#endif
15890 SgClassSymbol* classSymbol = target_AST_scope->lookup_class_symbol(className);
15891 ROSE_ASSERT(classSymbol != NULL);
15892 ROSE_ASSERT(classSymbol->get_declaration() != NULL);
15893#if DEBUG_FIND_ASSOCIATED_DECLARATION
15894 printf (" --- Associated symbol in taget AST: declaration = %p name = %s \n",classSymbol->get_declaration(),classSymbol->get_declaration()->get_name().str());
15895#endif
15896 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15897 returnSymbol = classSymbol;
15898
15899 // DQ (12/8/2020): Need to get the associated class definition from the symbol in the target scope.
15900 SgClassDeclaration* temp_classDeclaration_in_target_ast = classSymbol->get_declaration();
15901 ROSE_ASSERT(temp_classDeclaration_in_target_ast != NULL);
15902 SgClassDeclaration* classDeclaration_in_target_ast = isSgClassDeclaration(temp_classDeclaration_in_target_ast->get_definingDeclaration());
15903 ROSE_ASSERT(classDeclaration_in_target_ast != NULL);
15904 SgClassDefinition* classDefinition_in_target_ast = classDeclaration_in_target_ast->get_definition();
15905 ROSE_ASSERT(classDefinition_in_target_ast != NULL);
15906
15907 // DQ (12/7/2020): This should be true.
15908 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15909
15910 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15911 // target_AST_scope = classDefinition;
15912 target_AST_scope = classDefinition_in_target_ast;
15913
15914 // DQ (12/7/2020): This should be true.
15915 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15916 }
15917
15918 // Not clear if we can have this case for C or C++.
15919 SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(*i);
15920 if (functionDefinition != NULL)
15921 {
15922 printf ("ERROR: Found an unusual case of SgFunctionDefinition in list of scopes holding a declaration for a type \n");
15923 ROSE_ABORT();
15924 }
15925
15926 SgNamespaceDefinitionStatement* namespaceDefinition = isSgNamespaceDefinitionStatement(*i);
15927 if (namespaceDefinition != NULL)
15928 {
15929 SgNamespaceDeclarationStatement* namespaceDeclaration = namespaceDefinition->get_namespaceDeclaration();
15930 SgName namespaceName = namespaceDeclaration->get_name();
15931#if DEBUG_FIND_ASSOCIATED_DECLARATION
15932 printf (" --- Found snippet namespace name = %s \n",namespaceName.str());
15933#endif
15934 SgNamespaceSymbol* namespaceSymbol = target_AST_scope->lookup_namespace_symbol(namespaceName);
15935 ROSE_ASSERT(namespaceSymbol != NULL);
15936 ROSE_ASSERT(namespaceSymbol->get_declaration() != NULL);
15937 SgNamespaceDeclarationStatement* otherASTnamespaceDeclaration = namespaceSymbol->get_declaration();
15938#if DEBUG_FIND_ASSOCIATED_DECLARATION
15939 printf (" --- Associated symbol in taget AST: declaration = %p name = %s \n",namespaceSymbol->get_declaration(),namespaceSymbol->get_declaration()->get_name().str());
15940#endif
15941 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15942 returnSymbol = namespaceSymbol;
15943
15944 // DQ (12/7/2020): This should be true.
15945 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15946
15947 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15948 // target_AST_scope = namespaceDefinition;
15949 target_AST_scope = otherASTnamespaceDeclaration->get_definition();
15950
15951 // DQ (12/7/2020): This should be true.
15952 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15953 }
15954
15955 // DQ (12/7/2020): This should be true.
15956 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15957
15958#if DEBUG_FIND_ASSOCIATED_DECLARATION
15959 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());
15960
15961 {
15962 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(target_AST_scope,true);
15963 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15964 printf (" --- At base of loop: otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15965 }
15966#endif
15967 // Increment the reverse iterator.
15968 i++;
15969 }
15970
15971#if DEBUG_FIND_ASSOCIATED_DECLARATION
15972 printf ("##### Now based on the kind of declaration, search for that same named declaration in the target_AST_scope = %p = %s \n",
15973 target_AST_scope,target_AST_scope->class_name().c_str());
15974#endif
15975
15976 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15977
15978 // Handle the different cases using a switch (there are only a few cases).
15979 switch (snippet_declaration->variantT())
15980 {
15981 case V_SgClassDeclaration:
15982 {
15983 SgClassDeclaration* snippet_classDeclaration = isSgClassDeclaration(snippet_declaration);
15984 ROSE_ASSERT(snippet_classDeclaration != NULL);
15985
15986 SgName snippet_className = snippet_classDeclaration->get_name();
15987
15988#if DEBUG_FIND_ASSOCIATED_DECLARATION
15989 printf ("snippet snippet declaration's class name = %s \n",snippet_className.str());
15990#endif
15991 SgClassSymbol* target_symbol = target_AST_scope->lookup_class_symbol(snippet_className);
15992 ROSE_ASSERT(target_symbol != NULL);
15993 returnSymbol = target_symbol;
15994
15995 SgClassSymbol* classSymbolInTargetAST = isSgClassSymbol(returnSymbol);
15996 ROSE_ASSERT(classSymbolInTargetAST != NULL);
15997 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
15998 ROSE_ASSERT(target_classDeclaration != NULL);
15999
16000#if DEBUG_FIND_ASSOCIATED_DECLARATION
16001 printf ("snippet: classDeclaration = %p = %s \n",snippet_classDeclaration,snippet_classDeclaration->get_name().str());
16002 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
16003#endif
16004 ROSE_ASSERT(snippet_classDeclaration->get_name() == target_classDeclaration->get_name());
16005 break;
16006 }
16007
16008 case V_SgTypedefDeclaration:
16009 {
16010 SgTypedefDeclaration* snippet_typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
16011 ROSE_ASSERT(snippet_typedefDeclaration != NULL);
16012
16013 SgName snippet_typedefName = snippet_typedefDeclaration->get_name();
16014
16015#if DEBUG_FIND_ASSOCIATED_DECLARATION
16016 printf ("snippet snippet declaration's typedef name = %s \n",snippet_typedefName.str());
16017#endif
16018 SgTypedefSymbol* target_symbol = target_AST_scope->lookup_typedef_symbol(snippet_typedefName);
16019 ROSE_ASSERT(target_symbol != NULL);
16020 returnSymbol = target_symbol;
16021
16022 SgTypedefSymbol* typedefSymbolInTargetAST = isSgTypedefSymbol(returnSymbol);
16023 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16024 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
16025 ROSE_ASSERT(target_typedefDeclaration != NULL);
16026
16027#if DEBUG_FIND_ASSOCIATED_DECLARATION
16028 printf ("snippet: typedefDeclaration = %p = %s \n",snippet_typedefDeclaration,snippet_typedefDeclaration->get_name().str());
16029 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
16030#endif
16031 ROSE_ASSERT(snippet_typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
16032 break;
16033 }
16034
16035 case V_SgEnumDeclaration:
16036 {
16037 SgEnumDeclaration* snippet_enumDeclaration = isSgEnumDeclaration(snippet_declaration);
16038 ROSE_ASSERT(snippet_enumDeclaration != NULL);
16039
16040 SgName snippet_enumName = snippet_enumDeclaration->get_name();
16041
16042#if DEBUG_FIND_ASSOCIATED_DECLARATION
16043 printf ("snippet snippet declaration's enum name = %s \n",snippet_enumName.str());
16044#endif
16045 // DQ (4/13/2014): check if this is an un-named enum beclaration.
16046 bool isUnNamed = snippet_enumDeclaration->get_isUnNamed();
16047 if (isUnNamed == false)
16048 {
16049 // SgEnumSymbol* target_symbol = target_AST_scope->lookup_enum_symbol(snippet_enumName);
16050 SgEnumSymbol* target_symbol = lookupEnumSymbolInParentScopes(snippet_enumName,target_AST_scope);
16051 if (target_symbol == NULL)
16052 {
16053 // Debug this case.
16054 SgScopeStatement* scope = snippet_enumDeclaration->get_scope();
16055 printf ("scope = %p = %s \n",scope,scope->class_name().c_str());
16056 scope->get_file_info()->display("case V_SgEnumDeclaration: target_symbol == NULL: scope: debug");
16057 }
16058 ROSE_ASSERT(target_symbol != NULL);
16059 returnSymbol = target_symbol;
16060
16061 SgEnumSymbol* enumSymbolInTargetAST = isSgEnumSymbol(returnSymbol);
16062 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
16063 SgEnumDeclaration* target_enumDeclaration = isSgEnumDeclaration(enumSymbolInTargetAST->get_declaration());
16064 ROSE_ASSERT(target_enumDeclaration != NULL);
16065
16066#if DEBUG_FIND_ASSOCIATED_DECLARATION
16067 printf ("snippet: enumDeclaration = %p = %s \n",snippet_enumDeclaration,snippet_enumDeclaration->get_name().str());
16068 printf ("target: enumDeclaration = %p = %s \n",target_enumDeclaration,target_enumDeclaration->get_name().str());
16069#endif
16070 ROSE_ASSERT(snippet_enumDeclaration->get_name() == target_enumDeclaration->get_name());
16071 }
16072 else
16073 {
16074 // DQ (4/13/2014): I think we all agreed these would not have to be handled.
16075 printf ("Warning: can't handle unnamed enum declarations \n");
16076 ROSE_ASSERT(returnSymbol == NULL);
16077 }
16078 break;
16079 }
16080
16081 // DQ (12/11/2020): Adding support for codeSegregation tool.
16082 case V_SgTemplateMemberFunctionDeclaration:
16083 // DQ (12/8/2020): Adding support for codeSegregation tool.
16084 case V_SgTemplateFunctionDeclaration:
16085 // DQ (12/5/2020): Adding support for codeSegregation tool.
16086 case V_SgMemberFunctionDeclaration:
16087 case V_SgFunctionDeclaration:
16088 {
16089 SgFunctionDeclaration* snippet_functionDeclaration = isSgFunctionDeclaration(snippet_declaration);
16090 ROSE_ASSERT(snippet_functionDeclaration != NULL);
16091
16092#if DEBUG_FIND_ASSOCIATED_DECLARATION
16093 printf ("snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16094#endif
16095 SgName snippet_functionName = snippet_functionDeclaration->get_name();
16096
16097#if DEBUG_FIND_ASSOCIATED_DECLARATION
16098 printf ("snippet snippet declaration's function name = %s \n",snippet_functionName.str());
16099 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope->class_name().c_str());
16100#endif
16101 SgFunctionSymbol* target_symbol = target_AST_scope->lookup_function_symbol(snippet_functionName);
16102 ROSE_ASSERT(target_symbol != NULL);
16103 returnSymbol = target_symbol;
16104
16105 SgFunctionSymbol* functionSymbolInTargetAST = isSgFunctionSymbol(returnSymbol);
16106 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
16107 SgFunctionDeclaration* target_functionDeclaration = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
16108 ROSE_ASSERT(target_functionDeclaration != NULL);
16109
16110#if DEBUG_FIND_ASSOCIATED_DECLARATION
16111 printf ("snippet: functionDeclaration = %p = %s \n",snippet_functionDeclaration,snippet_functionDeclaration->get_name().str());
16112 printf ("target: functionDeclaration = %p = %s \n",target_functionDeclaration,target_functionDeclaration->get_name().str());
16113 printf ("isDefiningDeclaration = %s \n",isDefiningDeclaration ? "true" : "false");
16114#endif
16115 if (isDefiningDeclaration == true)
16116 {
16117#if DEBUG_FIND_ASSOCIATED_DECLARATION
16118 printf ("get the defining declaration instead of the firstNondefining declaration from the function symbol \n");
16119#endif
16120 returnDeclaration = target_functionDeclaration->get_definingDeclaration();
16121 }
16122
16123 ROSE_ASSERT(snippet_functionDeclaration->get_name() == target_functionDeclaration->get_name());
16124 break;
16125 }
16126
16127 default:
16128 {
16129 printf ("Error: default reached in switch: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16130 ROSE_ABORT();
16131 }
16132 }
16133
16134 ROSE_ASSERT(returnDeclaration != NULL);
16135
16136 // These should have different global scopes, because they are from different ASTs.
16137 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,returnDeclaration) == false);
16138
16139 // return the last found symbol.
16140 // return returnSymbol;
16141 return returnDeclaration;
16142 }
16143
16144
16145SgType*
16147 {
16148 // This is the inner function to getTargetFileType()
16149 SgType* returnType = NULL;
16150
16151 ROSE_ASSERT(snippet_type != NULL);
16152 ROSE_ASSERT(targetScope != NULL);
16153
16154 // DQ (3/17/2014): Refactored code.
16155 // See if the type might be asociated with the snippet file.
16156 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
16157 // SgType* type_copy = snippet_type;
16158
16159#if 0
16160 SgType* type_copy = snippet_type;
16161 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
16162#endif
16163
16164 SgNamedType* namedType = isSgNamedType(snippet_type);
16165 if (namedType != NULL)
16166 {
16167 // Find the associated declaration and it's corresponding declaration in the target AST.
16168 SgDeclarationStatement* snippet_declaration = namedType->get_declaration();
16169 ROSE_ASSERT(snippet_declaration != NULL);
16170#if 0
16171 printf ("Need to find the declaration in the target AST that is associated with the snippet_declaration in the snippet AST \n");
16172 printf (" --- snippet_declaration = %p = %s = %s \n",snippet_declaration,snippet_declaration->class_name().c_str(),SageInterface::get_name(snippet_declaration).c_str());
16173#endif
16174 // There are only a few cases here!
16175 switch (namedType->variantT())
16176 {
16177 case V_SgClassType:
16178 {
16179 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
16180 if (classDeclaration != NULL)
16181 {
16182 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
16183 if (classSymbolInTargetAST == NULL)
16184 {
16185 // For Java or C++ this could be a name qualified type and so we need a better mechanism
16186 // to identify it thorugh it's parent scopes. Build a list of parent scope back to the
16187 // global scope and then traverse the list backwards to identify each scope in the target
16188 // AST's global scope until we each the associated declaration in the target AST.
16189#if 0
16190 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");
16191 printf (" --- Looking for target AST match for class name = %s \n",classDeclaration->get_name().str());
16192#endif
16193 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
16194 ROSE_ASSERT(symbol != NULL);
16195
16196 classSymbolInTargetAST = isSgClassSymbol(symbol);
16197 }
16198
16199 ROSE_ASSERT(classSymbolInTargetAST != NULL);
16200 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
16201 ROSE_ASSERT(target_classDeclaration != NULL);
16202#if 0
16203 printf ("snippet: classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
16204 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
16205#endif
16206 ROSE_ASSERT(classDeclaration->get_name() == target_classDeclaration->get_name());
16207
16208 returnType = classSymbolInTargetAST->get_type();
16209 }
16210 break;
16211 }
16212
16213 case V_SgTypedefType:
16214 {
16215 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
16216 if (typedefDeclaration != NULL)
16217 {
16218 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(typedefDeclaration->get_name(),targetScope);
16219
16220 // Not clear if we have to handle a more general case here.
16221 // ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16222 // returnType = typedefSymbolInTargetAST->get_type();
16223 if (typedefSymbolInTargetAST == NULL)
16224 {
16225#if 0
16226 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");
16227 printf (" --- The target AST must have a valid typedef type (and associated declaration) to support resetting the SgTypedefType: %p \n",typedefDeclaration->get_type());
16228#endif
16229 // DQ (3/16/2014): Find the associated typedef declaration (from the target AST)
16230 // for the input type associated with its declaration in the snippet AST.
16231 SgSymbol* symbol = findAssociatedSymbolInTargetAST(typedefDeclaration,targetScope);
16232 ROSE_ASSERT(symbol != NULL);
16233
16234 typedefSymbolInTargetAST = isSgTypedefSymbol(symbol);
16235
16236 // Note that test5d demonstrates this problem.
16237 // ROSE_ASSERT(false);
16238 }
16239
16240 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16241 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
16242 ROSE_ASSERT(target_typedefDeclaration != NULL);
16243#if 0
16244 printf ("snippet: typedefDeclaration = %p = %s \n",typedefDeclaration,typedefDeclaration->get_name().str());
16245 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
16246#endif
16247 ROSE_ASSERT(typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
16248
16249 returnType = typedefSymbolInTargetAST->get_type();
16250 }
16251 break;
16252 }
16253
16254 case V_SgEnumType:
16255 {
16256 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(snippet_declaration);
16257 if (enumDeclaration != NULL)
16258 {
16259 ROSE_ASSERT(enumDeclaration->get_name().is_null() == false);
16260 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(enumDeclaration->get_name(),targetScope);
16261
16262 // Not clear if we have to handle a more general case here.
16263 // ROSE_ASSERT(enumSymbolInTargetAST != NULL);
16264 // returnType = enumSymbolInTargetAST->get_type();
16265 if (enumSymbolInTargetAST == NULL)
16266 {
16267 printf ("Error: It is an error to not have a enum type defined in the target AST! \n");
16268 printf (" --- The target AST must have a valid enum type (and associated declaration) to support resetting the SgEnumType: %p \n",enumDeclaration->get_type());
16269
16270 // We will allow this to pass for now, since it is a violation of the target AST, and not the snippet mechanism (I think).
16271 returnType = snippet_type;
16272
16273 // Note that test5d demonstrates this problem.
16274 // ROSE_ASSERT(false);
16275 }
16276 else
16277 {
16278 returnType = enumSymbolInTargetAST->get_type();
16279 }
16280 }
16281
16282 break;
16283 }
16284
16285 case V_SgJavaParameterizedType:
16286 {
16287 // DQ (3/10/2014): This type is a view of a generic class with dynamic type checking (e.g. T).
16288 // This acts more like a class with reference to the template instead of the template instantiation.
16289 // So reset the declaration.
16290#if 0
16291 printf ("In getTargetFileTypeSupport(): case V_SgJavaParameterizedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16292#endif
16293#if 1
16294 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
16295 if (classDeclaration != NULL)
16296 {
16297#if 0
16298 printf ("Looking for classDeclaration = %s \n",classDeclaration->get_name().str());
16299#endif
16300 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
16301 ROSE_ASSERT(javaParameterizedType != NULL);
16302#if 0
16303 // SgTemplateParameterPtrList* templateParameterList = javaParameterizedType->get_type_list();
16304 SgTemplateParameterList* templateParameterListNode = javaParameterizedType->get_type_list();
16305 ROSE_ASSERT(templateParameterListNode != NULL);
16306 SgTemplateParameterPtrList* templateParameterList = &templateParameterListNode->get_args();
16307#else
16308 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
16309 // SgTemplateParameterPtrList* templateParameterList = NULL;
16310#endif
16311 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
16312 // SgTemplateArgumentPtrList* templateSpecializationArgumentList = NULL;
16313#if 0
16314 printf ("Calling lookupTemplateClassSymbolInParentScopes() name = %s \n",classDeclaration->get_name().str());
16315#endif
16316 // SgTemplateClassSymbol* templateClassSymbolInTargetAST = lookupTemplateClassSymbolInParentScopes(classDeclaration->get_name(),templateParameterList,templateSpecializationArgumentList,targetScope);
16317 SgClassSymbol* templateClassSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
16318#if 0
16319 printf ("DONE: Calling lookupTemplateClassSymbolInParentScopes() \n");
16320#endif
16321#if 0
16322 printf ("targetScope->get_symbol_table()->size() = %d \n",targetScope->get_symbol_table()->size());
16323 if (templateClassSymbolInTargetAST == NULL)
16324 {
16325 targetScope->get_symbol_table()->print("ERROR: templateClassSymbolInTargetAST == NULL");
16326 }
16327#endif
16328 // DQ (3/30/2014): Add this approach.
16329 if (templateClassSymbolInTargetAST == NULL)
16330 {
16331#if 0
16332 printf ("Calling findAssociatedSymbolInTargetAST \n");
16333#endif
16334 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
16335 ROSE_ASSERT(symbol != NULL);
16336
16337 templateClassSymbolInTargetAST = isSgClassSymbol(symbol);
16338
16339 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
16340 }
16341
16342 // Not clear if we have to handle a more general case here.
16343 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
16344
16345 returnType = templateClassSymbolInTargetAST->get_type();
16346 }
16347#else
16348 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
16349 if (javaParameterizedType != NULL)
16350 {
16351#error "DEAD CODE!"
16352 // Not clear how to lookup this type in the target AST.
16353 returnType = javaParameterizedType;
16354
16355 SgType* internal_type = javaParameterizedType->get_raw_type();
16356 ROSE_ASSERT(internal_type != NULL);
16357 }
16358#endif
16359#if 0
16360 printf ("SgJavaParameterizedType not yet tested! \n");
16361 ROSE_ABORT();
16362#endif
16363 break;
16364 }
16365
16366 case V_SgJavaQualifiedType:
16367 {
16368 // DQ (3/10/2014): This type acts like a binary operator on types to define aggregate
16369 // types to represent what in C++ would be name qualification. I need only set the
16370 // declarations in each SgJavaQualifiedType to refer to a declaration in the target AST.
16371 // So reset the declaration.
16372
16373 // This case is demonstrated by test code:
16374 // SS_JAVA_CWES/src/Error_Handling/CWE_248/CWE_248_0.java,Error_Handling.CWE_248.CWE_248_0.cwe_248_0
16375 // printf ("***** SgJavaQualifiedType not yet tested! *** \n");
16376
16377 printf ("In getTargetFileTypeSupport(): case V_SgJavaQualifiedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16378
16379 SgJavaQualifiedType* javaQualifiedType = isSgJavaQualifiedType(namedType);
16380 if (javaQualifiedType != NULL)
16381 {
16382 // Not clear how to lookup this type in the target AST.
16383 returnType = javaQualifiedType;
16384
16385 SgType* internal_type_1 = javaQualifiedType->get_parent_type();
16386 ROSE_ASSERT(internal_type_1 != NULL);
16387 SgType* internal_type_2 = javaQualifiedType->get_type();
16388 ROSE_ASSERT(internal_type_2 != NULL);
16389 }
16390
16391 printf ("Case of SgJavaQualifiedType: not yet handled: commented out assertion! \n");
16392 // ROSE_ASSERT(false);
16393 break;
16394 }
16395
16396 case V_SgJavaWildcardType:
16397 {
16398 // DQ (3/10/2014): This type expressed constraints on an input type.
16399 // if (?) then it is associated with the Java object type.
16400 // It can be constraint with an upper bound or lower bound.
16401 // if (?extends List) would be an upper bound for List.
16402 // if (?super Integer) would be an lower bound for List.
16403 // So reset the declaration.
16404
16405 printf ("In getTargetFileTypeSupport(): case V_SgJavaWildcardType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16406
16407 SgJavaWildcardType* javaWildcardType = isSgJavaWildcardType(namedType);
16408 if (javaWildcardType != NULL)
16409 {
16410 // Not clear how to lookup this type in the target AST.
16411 returnType = javaWildcardType;
16412 }
16413
16414 printf ("SgJavaWildcardType not yet tested! \n");
16415 ROSE_ABORT();
16416 }
16417
16418 default:
16419 {
16420 printf ("Error: In getTargetFileTypeSupport(): default reached in switch: namedType = %p = %s \n",namedType,namedType->class_name().c_str());
16421 ROSE_ABORT();
16422 }
16423 }
16424
16425 ROSE_ASSERT(returnType != NULL);
16426#if 0
16427 printf ("Exiting as a test! \n");
16428 ROSE_ABORT();
16429#endif
16430 }
16431 else
16432 {
16433 // Non-named types are shared, so we need not reset them.
16434
16435 // If this was not a named type then return NULL (which is checked at the
16436 // calling point, so that the type will not be reset).
16437 }
16438
16439 return returnType;
16440 }
16441
16442
16443SgType*
16445 {
16446 SgType* returnType = NULL;
16447
16448 ROSE_ASSERT(snippet_type != NULL);
16449 ROSE_ASSERT(targetScope != NULL);
16450
16451 // DQ (3/17/2014): Refactored code.
16452 // See if the type might be asociated with the snippet file.
16453 SgType* type_copy = snippet_type;
16454
16455#if 0
16456 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
16457#endif
16458
16459 // We need to be able to reproduce the pointer types to class types, etc.
16460 Rose_STL_Container<SgType*> typeList = type_copy->getInternalTypes();
16461
16462#if 0
16463 for (size_t i = 0; i < typeList.size(); i++)
16464 {
16465 printf ("Input type: typeList[i=%" PRIuPTR "] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
16466 }
16467#endif
16468
16469#if 1
16470 // This is the unwrapped version of the getTargetFileType() function.
16471 returnType = getTargetFileTypeSupport(snippet_type,targetScope);
16472#else
16473 SgNamedType* namedType = isSgNamedType(snippet_type);
16474
16475#error "DEAD CODE!"
16476
16477 if (namedType != NULL)
16478 {
16479 // Find the associated declaration and it's corresponding declaration in the target AST.
16480 SgDeclarationStatement* snippet_declaration = namedType->get_declaration();
16481 ROSE_ASSERT(snippet_declaration != NULL);
16482#if 0
16483 printf ("Need to find the declaration in the target AST that is associated with the snippet_declaration in the snippet AST \n");
16484 printf (" --- snippet_declaration = %p = %s = %s \n",snippet_declaration,snippet_declaration->class_name().c_str(),SageInterface::get_name(snippet_declaration).c_str());
16485#endif
16486 // There are only a few cases here!
16487 switch (namedType->variantT())
16488 {
16489 case V_SgClassType:
16490 {
16491 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
16492 if (classDeclaration != NULL)
16493 {
16494 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
16495 if (classSymbolInTargetAST == NULL)
16496 {
16497 // For Java or C++ this could be a name qualified type and so we need a better mechanism
16498 // to identify it thorugh it's parent scopes. Build a list of parent scope back to the
16499 // global scope and then traverse the list backwards to identify each scope in the target
16500 // AST's global scope until we each the associated declaration in the target AST.
16501#if 0
16502 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");
16503 printf (" --- Looking for target AST match for class name = %s \n",classDeclaration->get_name().str());
16504#endif
16505 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
16506 ROSE_ASSERT(symbol != NULL);
16507
16508 classSymbolInTargetAST = isSgClassSymbol(symbol);
16509 }
16510
16511 ROSE_ASSERT(classSymbolInTargetAST != NULL);
16512 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
16513 ROSE_ASSERT(target_classDeclaration != NULL);
16514#if 0
16515 printf ("snippet: classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
16516 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
16517#endif
16518 ROSE_ASSERT(classDeclaration->get_name() == target_classDeclaration->get_name());
16519
16520 returnType = classSymbolInTargetAST->get_type();
16521 }
16522 break;
16523 }
16524
16525 case V_SgTypedefType:
16526 {
16527 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
16528 if (typedefDeclaration != NULL)
16529 {
16530 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(typedefDeclaration->get_name(),targetScope);
16531
16532 // Not clear if we have to handle a more general case here.
16533 // ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16534 // returnType = typedefSymbolInTargetAST->get_type();
16535 if (typedefSymbolInTargetAST == NULL)
16536 {
16537#if 0
16538 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");
16539 printf (" --- The target AST must have a valid typedef type (and associated declaration) to support resetting the SgTypedefType: %p \n",typedefDeclaration->get_type());
16540#endif
16541 // DQ (3/16/2014): Find the associated typedef declaration (from the target AST)
16542 // for the input type associated with its declaration in the snippet AST.
16543 SgSymbol* symbol = findAssociatedSymbolInTargetAST(typedefDeclaration,targetScope);
16544 ROSE_ASSERT(symbol != NULL);
16545
16546 typedefSymbolInTargetAST = isSgTypedefSymbol(symbol);
16547
16548 // Note that test5d demonstrates this problem.
16549 // ROSE_ASSERT(false);
16550 }
16551
16552 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
16553 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
16554 ROSE_ASSERT(target_typedefDeclaration != NULL);
16555#if 0
16556 printf ("snippet: typedefDeclaration = %p = %s \n",typedefDeclaration,typedefDeclaration->get_name().str());
16557 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
16558#endif
16559 ROSE_ASSERT(typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
16560
16561 returnType = typedefSymbolInTargetAST->get_type();
16562 }
16563 break;
16564 }
16565
16566 case V_SgEnumType:
16567 {
16568 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(snippet_declaration);
16569 if (enumDeclaration != NULL)
16570 {
16571 ROSE_ASSERT(enumDeclaration->get_name().is_null() == false);
16572 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(enumDeclaration->get_name(),targetScope);
16573
16574 // Not clear if we have to handle a more general case here.
16575 // ROSE_ASSERT(enumSymbolInTargetAST != NULL);
16576 // returnType = enumSymbolInTargetAST->get_type();
16577 if (enumSymbolInTargetAST == NULL)
16578 {
16579 printf ("Error: It is an error to not have a enum type defined in the target AST! \n");
16580 printf (" --- The target AST must have a valid enum type (and associated declaration) to support resetting the SgEnumType: %p \n",enumDeclaration->get_type());
16581
16582 // We will allow this to pass for now, since it is a violation of the target AST, and not the snippet mechanism (I think).
16583 returnType = snippet_type;
16584
16585 // Note that test5d demonstrates this problem.
16586 // ROSE_ASSERT(false);
16587 }
16588 else
16589 {
16590 returnType = enumSymbolInTargetAST->get_type();
16591 }
16592 }
16593
16594 break;
16595 }
16596
16597 case V_SgJavaParameterizedType:
16598 {
16599 // DQ (3/10/2014): This type is a view of a generic class with dynamic type checking (e.g. T).
16600 // This acts more like a class with reference to the template instead of the template instantiation.
16601 // So reset the declaration.
16602
16603 printf ("In getTargetFileType(): case V_SgJavaParameterizedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16604#if 1
16605 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
16606 if (classDeclaration != NULL)
16607 {
16608 SgTemplateParameterPtrList* templateParameterList = NULL;
16609 SgTemplateArgumentPtrList* templateSpecializationArgumentList = NULL;
16610 SgTemplateClassSymbol* templateClassSymbolInTargetAST = lookupTemplateClassSymbolInParentScopes(classDeclaration->get_name(),templateParameterList,templateSpecializationArgumentList,targetScope);
16611
16612 // Not clear if we have to handle a more general case here.
16613 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
16614
16615 returnType = templateClassSymbolInTargetAST->get_type();
16616 }
16617#else
16618 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
16619 if (javaParameterizedType != NULL)
16620 {
16621 // Not clear how to lookup this type in the target AST.
16622 returnType = javaParameterizedType;
16623
16624 SgType* internal_type = javaParameterizedType->get_raw_type();
16625 ROSE_ASSERT(internal_type != NULL);
16626 }
16627#endif
16628 printf ("SgJavaParameterizedType not yet tested! \n");
16629 ROSE_ABORT();
16630 }
16631
16632 case V_SgJavaQualifiedType:
16633 {
16634 // DQ (3/10/2014): This type acts like a binary operator on types to define aggregate
16635 // types to represent what in C++ would be name qualification. I need only set the
16636 // declarations in each SgJavaQualifiedType to refer to a declaration in the target AST.
16637 // So reset the declaration.
16638
16639 printf ("In getTargetFileType(): case V_SgJavaQualifiedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16640
16641 SgJavaQualifiedType* javaQualifiedType = isSgJavaQualifiedType(namedType);
16642 if (javaQualifiedType != NULL)
16643 {
16644 // Not clear how to lookup this type in the target AST.
16645 returnType = javaQualifiedType;
16646
16647 SgType* internal_type_1 = javaQualifiedType->get_parent_type();
16648 ROSE_ASSERT(internal_type_1 != NULL);
16649 SgType* internal_type_2 = javaQualifiedType->get_type();
16650 ROSE_ASSERT(internal_type_2 != NULL);
16651 }
16652
16653 printf ("SgJavaQualifiedType not yet tested! \n");
16654 ROSE_ABORT();
16655 }
16656
16657 case V_SgJavaWildcardType:
16658 {
16659 // DQ (3/10/2014): This type expressed constraints on an input type.
16660 // if (?) then it is associated with the Java object type.
16661 // It can be constraint with an upper bound or lower bound.
16662 // if (?extends List) would be an upper bound for List.
16663 // if (?super Integer) would be an lower bound for List.
16664 // So reset the declaration.
16665
16666 printf ("In getTargetFileType(): case V_SgJavaWildcardType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16667
16668 SgJavaWildcardType* javaWildcardType = isSgJavaWildcardType(namedType);
16669 if (javaWildcardType != NULL)
16670 {
16671 // Not clear how to lookup this type in the target AST.
16672 returnType = javaWildcardType;
16673
16674 SgType* internal_type_1 = javaWildcardType->get_bound_type();
16675 // ROSE_ASSERT(internal_type_1 != NULL); // PC: 03/15/2014 - Dan, this cannot be asserted as the bound_type CAN BE NULL.
16676 }
16677
16678 printf ("SgJavaWildcardType not yet tested! \n");
16679 ROSE_ABORT();
16680 }
16681
16682 default:
16683 {
16684 printf ("Error: In getTargetFileType(): default reached in switch: namedType = %p = %s \n",namedType,namedType->class_name().c_str());
16685 ROSE_ABORT();
16686 }
16687 }
16688
16689 ROSE_ASSERT(returnType != NULL);
16690#if 0
16691 printf ("Exiting as a test! \n");
16692 ROSE_ABORT();
16693#endif
16694 }
16695 else
16696 {
16697 // Non-named types are shared, so we need not reset them.
16698
16699 // If this was not a named type then return NULL (which is checked at the
16700 // calling point, so that the type will not be reset).
16701 }
16702#endif
16703
16704 SgType* new_type = returnType;
16705
16706 // DQ (3/17/2014): Refactored code.
16707 // Now rebuild the type_copy as required to represent associated modifiers, typedef wrappers, pointers and references.
16708 if (new_type != NULL && typeList.size() > 1)
16709 {
16710 int size = (int)typeList.size();
16711 for (int i = size - 2; i >= 0; i--)
16712 {
16713#if 0
16714 printf ("Rebuild type: typeList[i=%d] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
16715#endif
16716 // SgModifierType* SgModifierType::createType(SgType* base_type, unsigned int f, SgExpression* optional_fortran_type_kind )
16717 switch(typeList[i]->variantT())
16718 {
16719 case V_SgModifierType:
16720 {
16721 SgModifierType* modifierType = isSgModifierType(typeList[i]);
16722 ROSE_ASSERT(modifierType != NULL);
16723 if (modifierType->get_typeModifier().get_constVolatileModifier().isConst() == true)
16724 {
16725 ROSE_ASSERT(new_type != NULL);
16726#if 0
16727 printf ("Building a SgModifierType: calling buildConstType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16728#endif
16729 new_type = buildConstType(new_type);
16730 }
16731 else
16732 {
16733 // Flag any additional modifiers that we might require (make anything not supported an error).
16734 printf ("Modifier kind not handled (not implemented) check what sort of modifier this is: \n");
16735 modifierType->get_typeModifier().display("Modifier kind not handled");
16736 ROSE_ABORT();
16737 }
16738 break;
16739 }
16740
16741 case V_SgTypedefType:
16742 {
16743 SgTypedefType* typedefType = isSgTypedefType(typeList[i]);
16744 ROSE_ASSERT(typedefType != NULL);
16745
16746 // DQ (3/17/2014): Call the associated support function instead.
16747 // SgType* SageBuilder::getTargetFileType(SgType* snippet_type, SgScopeStatement* targetScope)
16748 // SgType* new_typedefType = getTargetFileType(typedefType,targetScope);
16749 SgType* new_typedefType = getTargetFileTypeSupport(typedefType,targetScope);
16750 ROSE_ASSERT(new_typedefType != NULL);
16751 ROSE_ASSERT(isSgTypedefType(new_typedefType) != NULL);
16752
16753 new_type = new_typedefType;
16754#if 0
16755 printf ("ERROSE: SgTypedefType kind not handled (not implemented) \n");
16756 ROSE_ABORT();
16757#endif
16758 break;
16759 }
16760
16761 case V_SgPointerType:
16762 {
16763 SgPointerType* pointerType = isSgPointerType(typeList[i]);
16764 ROSE_ASSERT(pointerType != NULL);
16765#if 0
16766 printf ("Building a SgPointerType: calling buildPointerType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16767#endif
16768 ROSE_ASSERT(new_type != NULL);
16769 new_type = buildPointerType(new_type);
16770#if 0
16771 printf ("ERROSE: SgPointerType kind not handled (not implemented) \n");
16772 ROSE_ABORT();
16773#endif
16774 break;
16775 }
16776
16777 default:
16778 {
16779 printf ("Error: default reached in evaluation of typelist: typeList[i] = %p = %s \n",typeList[i],typeList[i]->class_name().c_str());
16780 ROSE_ABORT();
16781 }
16782 }
16783 }
16784
16785 returnType = new_type;
16786 }
16787
16788#if 0
16789 if (typeList.size() > 1)
16790 {
16791 printf ("Exiting as a test! \n");
16792 ROSE_ABORT();
16793 }
16794#endif
16795
16796
16797 return returnType;
16798 }
16799
16800
16801
16802void
16803SageBuilder::errorCheckingTargetAST (SgNode* node_copy, SgNode* node_original, SgFile* targetFile, bool failOnWarning )
16804 {
16805#if 0
16806 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());
16807#endif
16808
16809 // Handle what is the same about all statements before getting to the switch.
16810 SgStatement* statement_copy = isSgStatement(node_copy);
16811 SgStatement* statement_original = isSgStatement(node_original);
16812 if (statement_copy != NULL)
16813 {
16814 // Check the scope if it is stored explicitly.
16815 if (statement_copy->hasExplicitScope() == true)
16816 {
16817 // Handle the scope for all statements.
16818 SgScopeStatement* scope_copy = statement_copy->get_scope();
16819 ROSE_ASSERT(statement_original != NULL);
16820 SgScopeStatement* scope_original = statement_original->get_scope();
16821 ROSE_ASSERT(scope_copy != NULL);
16822 ROSE_ASSERT(scope_original != NULL);
16823
16824 // if (TransformationSupport::getFile(scope_original) != targetFile)
16825 // if (getEnclosingFileNode(scope_original) != targetFile)
16826 if (getEnclosingFileNode(scope_copy) != targetFile)
16827 {
16828#if 0
16829 printf ("Warning: SgStatement: scope = %p = %s \n",scope_original,scope_original->class_name().c_str());
16830#endif
16831 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
16832 // SgFile* snippetFile = getEnclosingFileNode(scope_original);
16833 SgFile* snippetFile = getEnclosingFileNode(scope_copy);
16834 ROSE_ASSERT(snippetFile != NULL);
16835 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16836#if 1
16837 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16838 // ROSE_ASSERT(false);
16839#endif
16840 if (failOnWarning == true)
16841 {
16842 printf ("Exit on warning! \n");
16843 ROSE_ABORT();
16844 }
16845 }
16846#if 0
16847 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
16848 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
16849
16850 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
16851 // ROSE_ASSERT(targetScope != NULL);
16852
16853 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16854 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16855 // SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol->get_name(),targetScope);
16856 // ROSE_ASSERT(variableSymbolInTargetAST != NULL);
16857
16858 // Unless we know that this is a declaration we can't set the scope here using the information about this being a definng declaration.
16859 // If this is a defining declaration then we want to set it's scope to targetScope, else we want to lookup
16860 // the symbol through the parent scope and set the scope using the symbol's first non-defining declaration.
16861 // statement_copy->set_scope(targetScope);
16862
16863 // SgSymbol* symbol = statement_copy->search_for_symbol_from_symbol_table();
16864 // ROSE_ASSERT(symbol != NULL);
16865#endif
16866#if 0
16867 printf ("SgClassDeclaration: Exiting as a test! \n");
16868 ROSE_ABORT();
16869#endif
16870#if 0
16871 if (TransformationSupport::getFile(scope) != targetFile)
16872 {
16873 printf ("Warning: SgStatement: scope = %p = %s \n",scope,scope->class_name().c_str());
16874 SgFile* snippetFile = TransformationSupport::getFile(scope);
16875 ROSE_ASSERT(snippetFile != NULL);
16876 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16877
16878 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16879 // ROSE_ASSERT(false);
16880 }
16881#endif
16882 }
16883 }
16884
16885 // Handle what is the same about all declaration before getting to the switch.
16886 SgDeclarationStatement* declarationStatement_copy = isSgDeclarationStatement(node_copy);
16887 SgDeclarationStatement* declarationStatement_original = isSgDeclarationStatement(node_original);
16888 if (declarationStatement_copy != NULL)
16889 {
16890 // Check the firstnondefiningDeclaration and definingDeclaration
16891 SgDeclarationStatement* firstNondefiningDeclaration_copy = declarationStatement_copy->get_firstNondefiningDeclaration();
16892 SgDeclarationStatement* firstNondefiningDeclaration_original = declarationStatement_original->get_firstNondefiningDeclaration();
16893
16894 // DQ (3/17/2014): Bugfix, we want to use the firstNondefiningDeclaration_copy instead of firstNondefiningDeclaration_original.
16895 // DQ (3/10/2014): We want to allow for NULL return values from getEnclosingFileNode() for Java classes that are in java.lang (for example).
16896 // SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_original);
16897 SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_copy);
16898 if (snippetFile != NULL && snippetFile != targetFile)
16899 {
16900 // I think we want to allow this because it is a common occurence in any merged AST.
16901 // However, if might be worth fixing for other reasons. This needs to be discussed.
16902#if 0
16903 printf ("Note: SgDeclarationStatement: firstNondefiningDeclaration_original is not in target file (allowed for merged ASTs) \n");
16904#endif
16905 // ROSE_ASSERT(false);
16906 if (failOnWarning == true)
16907 {
16908 printf ("Exit on warning! \n");
16909 ROSE_ABORT();
16910 }
16911 }
16912 else
16913 {
16914 // Warn about this if snippetFile == NULL.
16915 if (snippetFile == NULL)
16916 {
16917 printf ("Note: firstNondefiningDeclaration_original = %p getEnclosingFileNode() returned NULL \n",firstNondefiningDeclaration_original);
16918
16919 if (failOnWarning == true)
16920 {
16921 printf ("Exit on warning! \n");
16922 ROSE_ABORT();
16923 }
16924 }
16925 }
16926
16927 SgDeclarationStatement* definingDeclaration_copy = declarationStatement_copy->get_definingDeclaration();
16928 SgDeclarationStatement* definingDeclaration_original = declarationStatement_original->get_definingDeclaration();
16929 if (definingDeclaration_original != NULL)
16930 {
16931 // DQ (3/17/2014): Bugfix, we want to use the definingDeclaration_copy instead of definingDeclaration_original.
16932 // if (TransformationSupport::getFile(definingDeclaration_original) != targetFile)
16933 // if (getEnclosingFileNode(definingDeclaration_original) != targetFile)
16934 // SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_original);
16935 SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_copy);
16936 if (snippetFile != NULL && snippetFile != targetFile)
16937 {
16938#if 1
16939 printf ("Warning: SgDeclarationStatement: definingDeclaration is not in target file \n");
16940 // ROSE_ASSERT(false);
16941#endif
16942 if (failOnWarning == true)
16943 {
16944 printf ("Exit on warning! \n");
16945 ROSE_ABORT();
16946 }
16947
16948 if (declarationStatement_original == definingDeclaration_original)
16949 {
16950 // This is a defining declaration, so we can set the scope (or can we?)
16951 // I guess we could if the translation map were complete, but it is not complete yet.
16952 }
16953 }
16954 else
16955 {
16956 // Warn about this if snippetFile == NULL.
16957 if (snippetFile == NULL)
16958 {
16959 printf ("Note: definingDeclaration_original = %p getEnclosingFileNode() returned NULL \n",definingDeclaration_original);
16960
16961 if (failOnWarning == true)
16962 {
16963 printf ("Exit on warning! \n");
16964 ROSE_ABORT();
16965 }
16966 }
16967 }
16968 }
16969 }
16970
16971 // Handle what is the same about all expressions before getting to the switch.
16972 SgExpression* expression = isSgExpression(node_copy);
16973 if (expression != NULL)
16974 {
16975 // Check the scope if it is stored explicitly.
16976
16977 // printf ("WARNING: Need to check if the type is explicitly stored in this expression! \n");
16978
16979 if (expression->hasExplicitType() == true)
16980 {
16981 // Handle the type for all expressions.
16982 SgType* type = expression->get_type();
16983 ROSE_ASSERT(type != NULL);
16984 }
16985 }
16986
16987#if 0
16988 printf ("Leaving errorCheckingTargetAST() \n");
16989#endif
16990 }
16991
16992
16993template <class T>
16994void
16995SageBuilder::resetDeclaration(T* classDeclaration_copy, T* classDeclaration_original, SgScopeStatement* targetScope)
16996 {
16997 // I'm not sure if this function is a good idea since we can't call set_scope() easily from any
16998 // SgDeclarationStatement and I don't want to make set_scope() a virtual function because it would
16999 // not make sense everywhere.
17000
17001 // DQ (3/17/2014): This code is similar to the case for SgEnumDeclaration (later we can refactor this if this works well).
17002 T* classDeclaration_copy_defining = dynamic_cast<T*>(classDeclaration_copy->get_definingDeclaration());
17003 T* classDeclaration_copy_nondefining = dynamic_cast<T*>(classDeclaration_copy->get_firstNondefiningDeclaration());
17004 T* classDeclaration_original_defining = dynamic_cast<T*>(classDeclaration_original->get_definingDeclaration());
17005 T* classDeclaration_original_nondefining = dynamic_cast<T*>(classDeclaration_original->get_firstNondefiningDeclaration());
17006
17007 // Set the scope if it is still set to the scope of the snippet AST.
17008 if (classDeclaration_copy_defining != NULL && classDeclaration_copy_defining->get_scope() == classDeclaration_original_defining->get_scope())
17009 {
17010#if 0
17011 printf ("reset the scope of classDeclaration_copy_defining \n");
17012#endif
17013 classDeclaration_copy_defining->set_scope(targetScope);
17014 }
17015
17016 // Set the scope if it is still set to the scope of the snippet AST.
17017 if (classDeclaration_copy_nondefining != NULL && classDeclaration_copy_nondefining->get_scope() == classDeclaration_original_nondefining->get_scope())
17018 {
17019#if 0
17020 printf ("reset the scope of classDeclaration_copy_nondefining \n");
17021#endif
17022 classDeclaration_copy_nondefining->set_scope(targetScope);
17023 }
17024
17025 // Set the parent if it is still set to a node of the snippet AST.
17026 if (classDeclaration_copy_nondefining != NULL && classDeclaration_copy_nondefining->get_parent() == classDeclaration_original_nondefining->get_parent())
17027 {
17028#if 0
17029 printf ("reset the parent of classDeclaration_copy_nondefining \n");
17030#endif
17031 classDeclaration_copy_nondefining->set_parent(classDeclaration_copy->get_parent());
17032 }
17033 }
17034
17035
17036void
17038 SgNode* node_copy, SgNode* node_original)
17039 {
17040 // This function fixes up invidual IR nodes to be consistant in the context of the target AST
17041 // where the node is inserted and at the point specified by insertionPoint. In this function,
17042 // node_copy is the copy that was made of node_original by the AST copy function. The node_original
17043 // is assumed to be the node that is in the AST snippet (it is still connected in the snippet's
17044 // AST (from compilation of the snippet file).
17045
17046 // This function hides the details of handling each different type of IR node.
17047 // It is assume that the node_copy is from an AST sub-tree generated by the AST copy mechanism,
17048 // and that the insertionPoint is a location in the target AST where the snippet AST has already
17049 // been inserted, this function makes each IR node internally consistant with the target AST.
17050
17051 // BTW, the translationMap should only be required to support references to things that are name
17052 // qualified (which are C++ specific). These are a performance option to simplify tacking back
17053 // through scopes with code similarly complex as to what is supported in the name qualification
17054 // support.
17055#if 0
17056 printf ("In fixupCopyOfNodeFromSeperateFileInNewTargetAst: node_copy = %p = %s \n",node_copy,node_copy->class_name().c_str());
17057#endif
17058
17059#if 0
17060 printf ("Disabled fixupCopyOfNodeFromSeperateFileInNewTargetAst() \n");
17061 return;
17062#endif
17063
17064 // SgFile* targetFile = TransformationSupport::getFile(insertionPoint);
17065 SgFile* targetFile = getEnclosingFileNode(insertionPoint);
17066
17067#if 0
17068 printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
17069 printf (" --- insertionPointIsScope = %s \n",insertionPointIsScope ? "true" : "false");
17070#endif
17071
17072 // DQ (3/4/2014): As I recall there is a reason why we can't setup the scope here.
17073
17074 // We also need to handle the symbol (move it from the body (SgBaicBlock) that was
17075 // a copy to the scope in the target AST where the SgInitializedName was inserted).
17076 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17077#if 0
17078 printf ("insertionPointScope = %p = %s \n",insertionPointScope,insertionPointScope->class_name().c_str());
17079#endif
17080 SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17081 ROSE_ASSERT(targetScope != NULL);
17082
17083#if 1
17084 // Refactored code (error checking done after AST fixup).
17085#if 0
17086 errorCheckingTargetAST(node_copy,node_original,targetFile, false);
17087#endif
17088#else
17089
17090#error "DEAD CODE!"
17091
17092 // Handle what is the same about all statements before getting to the switch.
17093 SgStatement* statement_copy = isSgStatement(node_copy);
17094 SgStatement* statement_original = isSgStatement(node_original);
17095 if (statement_copy != NULL)
17096 {
17097 // Check the scope if it is stored explicitly.
17098 if (statement_copy->hasExplicitScope() == true)
17099 {
17100 // Handle the scope for all statements.
17101 SgScopeStatement* scope_copy = statement_copy->get_scope();
17102 SgScopeStatement* scope_original = statement_original->get_scope();
17103 ROSE_ASSERT(scope_copy != NULL);
17104 ROSE_ASSERT(scope_original != NULL);
17105
17106 // if (TransformationSupport::getFile(scope_original) != targetFile)
17107 if (getEnclosingFileNode(scope_original) != targetFile)
17108 {
17109#if 0
17110 printf ("Warning: SgStatement: scope = %p = %s \n",scope_original,scope_original->class_name().c_str());
17111#endif
17112 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
17113 SgFile* snippetFile = getEnclosingFileNode(scope_original);
17114 ROSE_ASSERT(snippetFile != NULL);
17115 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
17116#if 0
17117 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
17118 // ROSE_ASSERT(false);
17119#endif
17120 }
17121#if 0
17122 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17123 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
17124
17125 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17126 // ROSE_ASSERT(targetScope != NULL);
17127
17128 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
17129 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
17130 // SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol->get_name(),targetScope);
17131 // ROSE_ASSERT(variableSymbolInTargetAST != NULL);
17132
17133 // Unless we know that this is a declaration we can't set the scope here using the information about this being a definng declaration.
17134 // If this is a defining declaration then we want to set it's scope to targetScope, else we want to lookup
17135 // the symbol through the parent scope and set the scope using the symbol's first non-defining declaration.
17136 // statement_copy->set_scope(targetScope);
17137
17138 // SgSymbol* symbol = statement_copy->search_for_symbol_from_symbol_table();
17139 // ROSE_ASSERT(symbol != NULL);
17140#endif
17141#if 0
17142 printf ("SgClassDeclaration: Exiting as a test! \n");
17143 ROSE_ABORT();
17144#endif
17145#if 0
17146 if (TransformationSupport::getFile(scope) != targetFile)
17147 {
17148 printf ("Warning: SgStatement: scope = %p = %s \n",scope,scope->class_name().c_str());
17149 SgFile* snippetFile = TransformationSupport::getFile(scope);
17150 ROSE_ASSERT(snippetFile != NULL);
17151 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
17152
17153 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
17154 // ROSE_ASSERT(false);
17155 }
17156#endif
17157 }
17158 }
17159
17160#error "DEAD CODE!"
17161
17162 // Handle what is the same about all declaration before getting to the switch.
17163 SgDeclarationStatement* declarationStatement_copy = isSgDeclarationStatement(node_copy);
17164 SgDeclarationStatement* declarationStatement_original = isSgDeclarationStatement(node_original);
17165 if (declarationStatement_copy != NULL)
17166 {
17167 // Check the firstnondefiningDeclaration and definingDeclaration
17168 SgDeclarationStatement* firstNondefiningDeclaration_original = declarationStatement_original->get_firstNondefiningDeclaration();
17169
17170 // DQ (3/10/2014): We want to allow for NULL return values from getEnclosingFileNode() for Java classes that are in java.lang (for example).
17171 SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_original);
17172 if (snippetFile != NULL && snippetFile != targetFile)
17173 {
17174 // I think we want to allow this because it is a common occurence in any merged AST.
17175 // However, if might be worth fixing for other reasons. This needs to be discussed.
17176#if 0
17177 printf ("Note: SgDeclarationStatement: firstNondefiningDeclaration_original is not in target file (allowed for merged ASTs) \n");
17178#endif
17179 // ROSE_ASSERT(false);
17180 }
17181 else
17182 {
17183 // Warn about this if snippetFile == NULL.
17184 if (snippetFile == NULL)
17185 {
17186 printf ("Note: firstNondefiningDeclaration_original = %p getEnclosingFileNode() returned NULL \n",firstNondefiningDeclaration_original);
17187 }
17188 }
17189
17190#error "DEAD CODE!"
17191
17192 SgDeclarationStatement* definingDeclaration_original = declarationStatement_original->get_definingDeclaration();
17193 if (definingDeclaration_original != NULL)
17194 {
17195 // if (TransformationSupport::getFile(definingDeclaration_original) != targetFile)
17196 // if (getEnclosingFileNode(definingDeclaration_original) != targetFile)
17197 SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_original);
17198 if (snippetFile != NULL && snippetFile != targetFile)
17199 {
17200#if 0
17201 printf ("Warning: SgDeclarationStatement: definingDeclaration is not in target file \n");
17202 // ROSE_ASSERT(false);
17203#endif
17204 if (declarationStatement_original == definingDeclaration_original)
17205 {
17206 // This is a defining declaration, so we can set the scope (or can we?)
17207 // I guess we could if the translation map were complete, but it is not complete yet.
17208 }
17209 }
17210 else
17211 {
17212 // Warn about this if snippetFile == NULL.
17213 if (snippetFile == NULL)
17214 {
17215 printf ("Note: definingDeclaration_original = %p getEnclosingFileNode() returned NULL \n",definingDeclaration_original);
17216 }
17217 }
17218 }
17219 }
17220
17221#error "DEAD CODE!"
17222
17223#endif
17224
17225 // Handle what is the same about all expressions before getting to the switch.
17226 SgExpression* expression = isSgExpression(node_copy);
17227 if (expression != NULL)
17228 {
17229 // Check the scope if it is stored explicitly.
17230
17231 // printf ("WARNING: Need to check if the type is explicitly stored in this expression! \n");
17232
17233 if (expression->hasExplicitType() == true)
17234 {
17235 // Handle the type for all expressions.
17236 SgType* type = expression->get_type();
17237 ROSE_ASSERT(type != NULL);
17238
17239 // DQ (3/17/2014): Avoid calling stripType with the newly refactored getTargetFileType() function.
17240 // SgType* new_type = getTargetFileType(type->stripType(),targetScope);
17241 SgType* new_type = getTargetFileType(type,targetScope);
17242 if (new_type != NULL)
17243 {
17244 // Reset the base type to be the one associated with the target file.
17245 expression->set_explicitly_stored_type(new_type);
17246 }
17247 }
17248 }
17249
17250 switch (node_copy->variantT())
17251 {
17252 case V_SgInitializedName:
17253 {
17254 SgInitializedName* initializedName_copy = isSgInitializedName(node_copy);
17255 SgInitializedName* initializedName_original = isSgInitializedName(node_original);
17256
17257 // See if the scope might be associated with the snippet file.
17258
17259 // Since we don't want the scope that is stored in the SgInitializedName we
17260 // have to get the associated statement and the scope of that statement.
17261 // SgScopeStatement* scope_copy = initializedName_copy->get_scope();
17262 SgStatement* enclosingStatement_copy = TransformationSupport::getStatement(initializedName_copy);
17263#if 0
17264 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
17265#endif
17266 SgScopeStatement* scope_copy = enclosingStatement_copy->get_scope();
17267
17268 SgScopeStatement* scope_original = initializedName_original->get_scope();
17269
17270 ROSE_ASSERT(scope_copy != NULL);
17271 ROSE_ASSERT(scope_original != NULL);
17272
17273 // if (TransformationSupport::getFile(scope_original) != targetFile)
17274 if (getEnclosingFileNode(scope_original) != targetFile)
17275 {
17276#if 0
17277 ROSE_ASSERT(initializedName_copy != NULL);
17278 printf ("initializedName_copy = %p = %s \n",initializedName_copy,initializedName_copy->get_name().str());
17279 ROSE_ASSERT(initializedName_original != NULL);
17280 printf ("initializedName_original = %p = %s \n",initializedName_original,initializedName_original->get_name().str());
17281 SgType* initializedName_original_type = initializedName_original->get_type();
17282 printf ("initializedName_original_type = %p = %s \n",initializedName_original_type,initializedName_original_type->class_name().c_str());
17283 SgClassType* classType = isSgClassType(initializedName_original_type);
17284 // ROSE_ASSERT(classType != NULL);
17285 if (classType != NULL)
17286 {
17287 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
17288 ROSE_ASSERT(classDeclaration != NULL);
17289 printf ("classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
17290 }
17291#endif
17292#if 0
17293 printf ("Warning: case V_SgInitializedName: scope_copy = %p = %s \n",scope_copy,scope_copy->class_name().c_str());
17294 printf ("Warning: case V_SgInitializedName: scope_original = %p = %s \n",scope_original,scope_original->class_name().c_str());
17295
17296 printf ("Warning: case V_SgInitializedName: initializedName_copy->get_parent() = %p \n",initializedName_copy->get_parent());
17297 printf ("Warning: case V_SgInitializedName: initializedName_original->get_parent() = %p \n",initializedName_original->get_parent());
17298#endif
17299 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
17300 SgFile* snippetFile = getEnclosingFileNode(scope_original);
17301
17302 ROSE_ASSERT(snippetFile != NULL);
17303 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
17304#if 0
17305 printf ("Warning: case V_SgInitializedName: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
17306 // ROSE_ASSERT(false);
17307#endif
17308 }
17309
17310 // See if the type might be asociated with the snippet file.
17311 SgType* type_copy = initializedName_copy->get_type();
17312#if 0
17313 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
17314#endif
17315
17316#if 0
17317
17318#error "DEAD CODE!"
17319
17320 // We need to be able to reproduce the pointer types to class types, etc.
17321 Rose_STL_Container<SgType*> typeList = type_copy->getInternalTypes();
17322#if 0
17323 for (size_t i = 0; i < typeList.size(); i++)
17324 {
17325 printf ("Input type: typeList[i=%" PRIuPTR "] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
17326 }
17327#endif
17328 // Note that the semantics of this function is that it can return a NULL pointer (e.g. for primative types).
17329 SgType* new_type = getTargetFileType(type_copy->stripType(),targetScope);
17330
17331#error "DEAD CODE!"
17332
17333 // Now rebuild the type_copy as required to represent associated modifiers, typedef wrappers, pointers and references.
17334 if (new_type != NULL && typeList.size() > 1)
17335 {
17336 int size = (int)typeList.size();
17337 for (int i = size - 2; i >= 0; i--)
17338 {
17339#if 0
17340 printf ("Rebuild type: typeList[i=%d] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
17341#endif
17342 // SgModifierType* SgModifierType::createType(SgType* base_type, unsigned int f, SgExpression* optional_fortran_type_kind )
17343 switch(typeList[i]->variantT())
17344 {
17345 case V_SgModifierType:
17346 {
17347 SgModifierType* modifierType = isSgModifierType(typeList[i]);
17348 ROSE_ASSERT(modifierType != NULL);
17349 if (modifierType->get_typeModifier().get_constVolatileModifier().isConst() == true)
17350 {
17351 ROSE_ASSERT(new_type != NULL);
17352#if 0
17353 printf ("Building a SgModifierType: calling buildConstType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
17354#endif
17355 new_type = buildConstType(new_type);
17356 }
17357 else
17358 {
17359 // Flag any additional modifiers that we might require (make anything not supported an error).
17360 printf ("Modifier kind not handled (not implemented) check what sort of modifier this is: \n");
17361 modifierType->get_typeModifier().display("Modifier kind not handled");
17362 ROSE_ABORT();
17363 }
17364 break;
17365 }
17366
17367#error "DEAD CODE!"
17368
17369 case V_SgTypedefType:
17370 {
17371 SgTypedefType* typedefType = isSgTypedefType(typeList[i]);
17372 ROSE_ASSERT(typedefType != NULL);
17373
17374 // SgType* SageBuilder::getTargetFileType(SgType* snippet_type, SgScopeStatement* targetScope)
17375 SgType* new_typedefType = getTargetFileType(typedefType,targetScope);
17376 ROSE_ASSERT(new_typedefType != NULL);
17377 ROSE_ASSERT(isSgTypedefType(new_typedefType) != NULL);
17378
17379 new_type = new_typedefType;
17380#if 0
17381 printf ("ERROSE: SgTypedefType kind not handled (not implemented) \n");
17382 ROSE_ABORT();
17383#endif
17384 break;
17385 }
17386
17387#error "DEAD CODE!"
17388
17389 case V_SgPointerType:
17390 {
17391 SgPointerType* pointerType = isSgPointerType(typeList[i]);
17392 ROSE_ASSERT(pointerType != NULL);
17393#if 0
17394 printf ("Building a SgPointerType: calling buildPointerType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
17395#endif
17396 ROSE_ASSERT(new_type != NULL);
17397 new_type = buildPointerType(new_type);
17398#if 0
17399 printf ("ERROSE: SgPointerType kind not handled (not implemented) \n");
17400 ROSE_ABORT();
17401#endif
17402 break;
17403 }
17404
17405#error "DEAD CODE!"
17406
17407 default:
17408 {
17409 printf ("Error: default reached in evaluation of typelist: typeList[i] = %p = %s \n",typeList[i],typeList[i]->class_name().c_str());
17410 ROSE_ABORT();
17411 }
17412 }
17413 }
17414 }
17415#if 0
17416 if (typeList.size() > 1)
17417 {
17418 printf ("Exiting as a test! \n");
17419 ROSE_ABORT();
17420 }
17421#endif
17422
17423#error "DEAD CODE!"
17424
17425#else
17426 // Refactored the above code to be a part of getTargetFileType() function.
17427 // Note that the semantics of this function is that it can return a NULL pointer (e.g. for primative types).
17428 // SgType* new_type = getTargetFileType(type_copy->stripType(),targetScope);
17429 SgType* new_type = getTargetFileType(type_copy,targetScope);
17430#endif
17431#if 0
17432 printf ("new_type = %p \n",new_type);
17433#endif
17434 if (new_type != NULL)
17435 {
17436 // Reset the base type to be the one associated with the target file.
17437#if 0
17438 printf ("Reset type for initializedName_copy = %p from type = %p to type = %p \n",initializedName_copy,initializedName_copy->get_type(),new_type);
17439#endif
17440 SgType* original_type = initializedName_copy->get_type();
17441 SgNamedType* original_named_type = isSgNamedType(original_type);
17442 SgNamedType* new_named_type = isSgNamedType(new_type);
17443 if (original_named_type != NULL)
17444 {
17445 ROSE_ASSERT(new_named_type != NULL);
17446 SgClassDeclaration* original_classDeclaration = isSgClassDeclaration(original_named_type->get_declaration());
17447 SgClassDeclaration* new_classDeclaration = isSgClassDeclaration(new_named_type->get_declaration());
17448 if (original_classDeclaration != NULL)
17449 {
17450 ROSE_ASSERT(new_classDeclaration != NULL);
17451#if 0
17452 printf ("original_classDeclaration = %p = %s \n",original_classDeclaration,original_classDeclaration->get_name().str());
17453 printf ("new_classDeclaration = %p = %s \n",new_classDeclaration,new_classDeclaration->get_name().str());
17454#endif
17455 // Make sure that the type names are the same.
17456 ROSE_ASSERT(new_classDeclaration->get_name() == original_classDeclaration->get_name());
17457 }
17458 }
17459#if 0
17460 SgType* old_type = initializedName_copy->get_type();
17461 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());
17462#endif
17463 initializedName_copy->set_type(new_type);
17464 }
17465#if 0
17466 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
17467#endif
17468 SgFunctionParameterList* functionParameterList = isSgFunctionParameterList(enclosingStatement_copy);
17469 if (functionParameterList != NULL)
17470 {
17471 // The use of SgInitializedName in function parametes is handled differently then in other
17472 // locations in the AST (e.g. how the scope is set).
17473 // This is a function parameter and the scope is set to the SgFunctionDefinition if
17474 // this is for a defining function and the SgGlobal if it is a function prototype.
17475 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(functionParameterList->get_parent());
17476 ROSE_ASSERT(functionDeclaration != NULL);
17477 SgFunctionDefinition* functionDefinition = functionDeclaration->get_definition();
17478 if (functionDefinition != NULL)
17479 {
17480 ROSE_ASSERT(initializedName_copy->get_scope() == functionDefinition);
17481 // initializedName_copy->set_scope(functionDefinition);
17482 }
17483 else
17484 {
17485 SgGlobal* globalScope = isSgGlobal(functionDeclaration->get_scope());
17486 ROSE_ASSERT(globalScope != NULL);
17487 if (initializedName_copy->get_scope() != globalScope)
17488 {
17489#if 0
17490 printf ("Reset scope for initializedName_copy = %p = %s \n",initializedName_copy,initializedName_copy->get_name().str());
17491#endif
17492 initializedName_copy->set_scope(globalScope);
17493 }
17494 ROSE_ASSERT(initializedName_copy->get_scope() == globalScope);
17495 }
17496 }
17497 else
17498 {
17499#if 0
17500 printf ("initializedName_copy->get_scope() = %p = %s \n",initializedName_copy->get_scope(),initializedName_copy->get_scope()->class_name().c_str());
17501#endif
17502 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(enclosingStatement_copy);
17503 if (enumDeclaration != NULL)
17504 {
17505 // The case of enum declarations is special because the associated SgInitializedName IR nodes has a scope
17506 // that is external to the SgEnumDeclaration (in the scope of the SgEnumDeclaration). The typical case in C
17507 // is that the enum declaration is in global scope and then the enum fields (represented by SgInitializedName
17508 // objects) are have their associated symbol in the global scope.
17509
17510 // We have to use the name to search for the symbol instead of the pointer value of the initializedName_copy
17511 // (since the original symbol was associated with initializedName_original).
17512 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
17513 SgName name = initializedName_copy->get_name();
17514 SgSymbol* symbol = initializedName_copy->get_scope()->lookup_enum_field_symbol(name);
17515 ROSE_ASSERT(symbol != NULL);
17516
17517 SgEnumFieldSymbol* enumFieldSymbol = isSgEnumFieldSymbol(symbol);
17518 ROSE_ASSERT(enumFieldSymbol != NULL);
17519
17520 // DQ (3/17/2014): Build a new sysmbol to for the initializedName_copy instead of reusing the existing symbol
17521 // from the snippet AST.
17522 SgEnumFieldSymbol* new_enumFieldSymbol = new SgEnumFieldSymbol(initializedName_copy);
17523 ROSE_ASSERT(new_enumFieldSymbol != NULL);
17524
17525 // targetScope->insert_symbol(name,enumFieldSymbol);
17526 targetScope->insert_symbol(name,new_enumFieldSymbol);
17527
17528 // DQ (3/6/2014): Set the scope of the SgInitializedName IR node.
17529 initializedName_copy->set_scope(targetScope);
17530#if 0
17531 printf ("Exiting as a test! \n");
17532 ROSE_ABORT();
17533#endif
17534 }
17535 else
17536 {
17537#if 0
17538 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
17539#endif
17540 SgCatchOptionStmt* catchOptionStatement = isSgCatchOptionStmt(enclosingStatement_copy->get_parent());
17541 if (catchOptionStatement != NULL)
17542 {
17543 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(enclosingStatement_copy);
17544 ROSE_ASSERT(variableDeclaration != NULL);
17545
17546 // SgSymbol* symbol = targetScope->lookup_variable_symbol(initializedName_copy->get_name());
17547 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(initializedName_original);
17548 ROSE_ASSERT(enclosingStatement_original != NULL);
17549 SgCatchOptionStmt* catchOptionStatement_original = isSgCatchOptionStmt(enclosingStatement_original->get_parent());
17550
17551 // SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),targetScope);
17552 SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),catchOptionStatement_original);
17553 if (symbol == NULL)
17554 {
17555 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
17556 // initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
17557 }
17558 ROSE_ASSERT(symbol != NULL);
17559
17560 initializedName_copy->set_scope(targetScope);
17561
17562 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
17563 ROSE_ASSERT(new_variableSymbol != NULL);
17564
17565 // DQ (3/19/2014): I am not certain this is the correct location to insert this symbol.
17566 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
17567 }
17568 else
17569 {
17570 // DQ (3/29/2014): Adding support for SgInitializedName IR nodes found in a SgJavaForEachStatement.
17571 SgJavaForEachStatement* javaForEachStatement = isSgJavaForEachStatement(enclosingStatement_copy->get_parent());
17572 if (javaForEachStatement != NULL)
17573 {
17574 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(enclosingStatement_copy);
17575 ROSE_ASSERT(variableDeclaration != NULL);
17576
17577 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(initializedName_original);
17578 ROSE_ASSERT(enclosingStatement_original != NULL);
17579 SgJavaForEachStatement* javaForEachStatement_original = isSgJavaForEachStatement(enclosingStatement_original->get_parent());
17580
17581 SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),javaForEachStatement_original);
17582 if (symbol == NULL)
17583 {
17584 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
17585 // initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
17586 }
17587 ROSE_ASSERT(symbol != NULL);
17588
17589 initializedName_copy->set_scope(targetScope);
17590
17591 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
17592 ROSE_ASSERT(new_variableSymbol != NULL);
17593
17594 // DQ (3/29/2014): I am not certain this is the correct location to insert this symbol.
17595 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
17596#if 0
17597 printf ("Need to handle case of SgJavaForEachStatement \n");
17598 ROSE_ABORT();
17599#endif
17600 }
17601 else
17602 {
17603 // Case of non-SgFunctionParameterList and non-SgEnumDeclaration use of SgInitializedName in AST.
17604 SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
17605 if (symbol == NULL)
17606 {
17607 printf ("ERROR: enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
17608 ROSE_ASSERT(enclosingStatement_copy->get_parent() != NULL);
17609 printf ("ERROR: enclosingStatement_copy->get_parent() = %p = %s \n",enclosingStatement_copy->get_parent(),enclosingStatement_copy->get_parent()->class_name().c_str());
17610 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
17611 initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
17612
17613 // DQ (3/30/2014): Add this appraoch to find the symbol.
17614 SgScopeStatement* initializedName_copy_scope = isSgScopeStatement(initializedName_copy->get_scope());
17615 ROSE_ASSERT(initializedName_copy_scope != NULL);
17616 SgVariableSymbol* variableSymbol = initializedName_copy_scope->lookup_variable_symbol(initializedName_copy->get_name());
17617 ROSE_ASSERT(variableSymbol != NULL);
17618
17619 symbol = variableSymbol;
17620 }
17621 ROSE_ASSERT(symbol != NULL);
17622
17623 SgVariableSymbol* variableSymbol = isSgVariableSymbol(symbol);
17624 ROSE_ASSERT(variableSymbol != NULL);
17625#if 0
17626 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());
17627#endif
17628 // DQ (3/17/2014): Build a new sysmbol to for the initializedName_copy instead of reusing the existing symbol
17629 // from the snippet AST.
17630 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
17631 ROSE_ASSERT(new_variableSymbol != NULL);
17632
17633 // targetScope->insert_symbol(initializedName_copy->get_name(),variableSymbol);
17634 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
17635
17636 // DQ (3/6/2014): Set the scope of the SgInitializedName IR node.
17637 initializedName_copy->set_scope(targetScope);
17638
17639 SgName mangledName = variableSymbol->get_mangled_name();
17640#if 0
17641 printf ("initializedName_copy: mangledName = %s \n",mangledName.str());
17642#endif
17643 // DQ (3/2/2014): Make sure this is true (I think it should be, but I don't see that it was explicitly set).
17644 // ROSE_ASSERT(initializedName_copy->get_scope() == targetScope);
17645 if (initializedName_copy->get_scope() != targetScope)
17646 {
17647 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());
17648
17649 printf ("I think this should be an error! \n");
17650 ROSE_ABORT();
17651 }
17652 }
17653 }
17654 }
17655 }
17656
17657 break;
17658 }
17659
17660 case V_SgVariableDeclaration:
17661 {
17662 // I think there is nothing to handle for this case (there is no type accessbile here
17663 // since they are in the SgInitializedName IR nodes).
17664 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(node_copy);
17665 ROSE_ASSERT(variableDeclaration != NULL);
17666
17667 break;
17668 }
17669
17670#define DEBUG_FUNCTION_DECLARATION 0
17671
17672 case V_SgFunctionDeclaration:
17673 {
17674 // SgFunctionDeclaration is handled directly in the snippet support (insertRelatedThingsForC() function).
17675
17676 // Note that function types are stored in global type tables so they need not be fixed up.
17677
17678 // DQ (3/13/2014): As of today, this assumption is no longer true, we need to be able to insert
17679 // any function declaration in insertRelatedThingsForC() and use this function to fixup the AST.
17680 // The target AST should have a prototype (non-defining declaration) of the function defined
17681 // so that all internal types of the SgFunctionType are defined in the target AST.
17682 SgFunctionDeclaration* functionDeclaration_copy = isSgFunctionDeclaration(node_copy);
17683 SgFunctionDeclaration* functionDeclaration_original = isSgFunctionDeclaration(node_original);
17684 SgFunctionType* functionType_copy = functionDeclaration_copy->get_type();
17685 SgFunctionType* functionType_original = functionDeclaration_original->get_type();
17686 ROSE_ASSERT(functionType_copy != NULL);
17687 ROSE_ASSERT(functionType_original != NULL);
17688 ROSE_ASSERT(functionType_copy == functionType_original);
17689#if DEBUG_FUNCTION_DECLARATION
17690 printf ("case SgFunctionDeclaration: part 1: Calling functionDeclaration_copy->search_for_symbol_from_symbol_table() \n");
17691#endif
17692 // SgSymbol* symbol_copy = functionDeclaration_copy->search_for_symbol_from_symbol_table();
17693 SgSymbol* symbol_original = functionDeclaration_original->search_for_symbol_from_symbol_table();
17694 ROSE_ASSERT(symbol_original != NULL);
17695 SgFunctionSymbol* functionSymbol_original = isSgFunctionSymbol(symbol_original);
17696 ROSE_ASSERT(functionSymbol_original != NULL);
17697
17698 SgFile* snippetFile = getEnclosingFileNode(functionSymbol_original);
17699 ROSE_ASSERT(snippetFile != NULL);
17700 if (snippetFile != targetFile)
17701 {
17702#if DEBUG_FUNCTION_DECLARATION
17703 printf ("Warning: case V_SgFunctionDeclaration: functionSymbol_original not in target file \n");
17704#endif
17705 // DQ (3/13/2014): Handle the case of a member function seperately (I think this can't appear in Java, only in C++).
17706 // ROSE_ASSERT(isSgMemberFunctionSymbol(symbol_copy) == NULL);
17707 ROSE_ASSERT(isSgMemberFunctionSymbol(symbol_original) == NULL);
17708
17709 // printf ("case SgFunctionDeclaration: part 2: Calling functionDeclaration_copy->search_for_symbol_from_symbol_table() \n");
17710 // SgFunctionSymbol* functionSymbol_copy = isSgFunctionSymbol(functionDeclaration_copy->search_for_symbol_from_symbol_table());
17711 // ROSE_ASSERT(functionSymbol_copy != NULL);
17712
17713 SgName name = functionDeclaration_copy->get_name();
17714 SgType* functionType = functionDeclaration_copy->get_type();
17715 ROSE_ASSERT(functionType != NULL);
17716#if DEBUG_FUNCTION_DECLARATION
17717 printf ("case V_SgFunctionDeclaration: name = %s \n",name.str());
17718 printf ("case V_SgFunctionDeclaration: functionType = %p \n",functionType);
17719 printf ("case V_SgFunctionDeclaration: functionType_original = %p \n",functionType_original);
17720 printf ("case V_SgFunctionDeclaration: functionType_copy = %p \n",functionType_copy);
17721#endif
17722 SgFunctionSymbol* functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,functionType,targetScope);
17723
17724 ROSE_ASSERT(targetScope != NULL);
17725 functionDeclaration_copy->set_scope(targetScope);
17726
17727 // Set the scope of the non-defining declaration.
17728 functionDeclaration_copy->get_firstNondefiningDeclaration()->set_scope(targetScope);
17729
17730 SgFunctionDeclaration* functionDeclaration_copy_firstNondefining = NULL;
17731
17732 if (functionSymbolInTargetAST == NULL)
17733 {
17734#if DEBUG_FUNCTION_DECLARATION
17735 printf ("functionSymbolInTargetAST not found in targetScope = %p = %s \n",targetScope,targetScope->class_name().c_str());
17736#endif
17737 // If could be that the symbol is in the local scope of the snippet AST.
17738 SgScopeStatement* otherPossibleScope = isSgScopeStatement(functionDeclaration_original->get_parent());
17739 ROSE_ASSERT(otherPossibleScope != NULL);
17740#if DEBUG_FUNCTION_DECLARATION
17741 printf ("case V_SgFunctionDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope,otherPossibleScope->class_name().c_str());
17742#endif
17743 // We want to out serch the additional other scope and not it's parent scope.
17744 // functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,functionType,otherPossibleScope);
17745 functionSymbolInTargetAST = otherPossibleScope->lookup_function_symbol(name,functionType);
17746
17747 if (functionSymbolInTargetAST == NULL)
17748 {
17749 printf ("function symbol not found in otherPossibleScope = %p = %s \n",otherPossibleScope,otherPossibleScope->class_name().c_str());
17750 }
17751
17752 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17753#if DEBUG_FUNCTION_DECLARATION
17754 printf ("(building a new SgFunctionSymbol): functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17755#endif
17756 // DQ (3/15/2014): We need to insert a new symbol into the targetScope instead of reusing
17757 // the existing symbol (because it points to the declaration in the snippet file).
17758 // Insert the symbol into the targetScope.
17759 // targetScope->insert_symbol(name,functionSymbolInTargetAST);
17760 functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionDeclaration_copy->get_firstNondefiningDeclaration());
17761 SgFunctionSymbol* new_symbol = new SgFunctionSymbol(functionDeclaration_copy_firstNondefining);
17762 ROSE_ASSERT(new_symbol != NULL);
17763
17764 targetScope->insert_symbol(name,new_symbol);
17765
17766 functionSymbolInTargetAST = new_symbol;
17767
17768 // DQ (3/26/2014): Added assertion.
17769 ROSE_ASSERT(lookupFunctionSymbolInParentScopes(name,functionType,targetScope) != NULL);
17770 }
17771 else
17772 {
17773 // If we happend to find an associated symbol in the target scope then we nave to use it and
17774 // set the first nondefining declaration pointer to the symbol's associate declaration.
17775 // This is the case of the test3a test code (because the snippet functions declaration is
17776 // in the target AST file (likely a mistake, but we should handle it properly).
17777#if DEBUG_FUNCTION_DECLARATION
17778 printf ("(using existing symbol found in target scope): functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17779#endif
17780 functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
17781 }
17782
17783 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17784
17785 ROSE_ASSERT(functionDeclaration_copy->get_firstNondefiningDeclaration() != NULL);
17786 ROSE_ASSERT(functionDeclaration_copy_firstNondefining != NULL);
17787
17788 // SgFunctionDeclaration* functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionDeclaration_copy->get_firstNondefiningDeclaration());
17789 SgFunctionDeclaration* functionDeclaration_original_firstNondefining = isSgFunctionDeclaration(functionDeclaration_original->get_firstNondefiningDeclaration());
17790 SgFunctionDeclaration* functionDeclaration_copy_defining = isSgFunctionDeclaration(functionDeclaration_copy->get_definingDeclaration());
17791 SgFunctionDeclaration* functionDeclaration_original_defining = isSgFunctionDeclaration(functionDeclaration_original->get_definingDeclaration());
17792 if (functionDeclaration_copy_firstNondefining->get_symbol_from_symbol_table() == NULL)
17793 {
17794 // Check what might be wrong here!
17795 ROSE_ASSERT(functionDeclaration_original_firstNondefining != NULL);
17796 printf ("functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17797
17798 printf ("functionDeclaration_original = %p = %s \n",functionDeclaration_original,functionDeclaration_original->class_name().c_str());
17799 printf ("functionDeclaration_copy = %p = %s \n",functionDeclaration_copy,functionDeclaration_copy->class_name().c_str());
17800 printf ("functionDeclaration_original_firstNondefining = %p \n",functionDeclaration_original_firstNondefining);
17801 printf ("functionDeclaration_copy_firstNondefining = %p \n",functionDeclaration_copy_firstNondefining);
17802 printf ("functionDeclaration_original_defining = %p \n",functionDeclaration_original_defining);
17803 printf ("functionDeclaration_copy_defining = %p \n",functionDeclaration_copy_defining);
17804
17805 printf ("functionDeclaration_original->get_scope() = %p = %s \n",functionDeclaration_original->get_scope(),functionDeclaration_original->get_scope()->class_name().c_str());
17806 printf ("functionDeclaration_copy->get_scope() = %p = %s \n",functionDeclaration_copy->get_scope(),functionDeclaration_copy->get_scope()->class_name().c_str());
17807 printf ("functionDeclaration_original_firstNondefining->get_scope() = %p = %s \n",functionDeclaration_original_firstNondefining->get_scope(),functionDeclaration_original_firstNondefining->get_scope()->class_name().c_str());
17808 printf ("functionDeclaration_copy_firstNondefining->get_scope() = %p = %s \n",functionDeclaration_copy_firstNondefining->get_scope(),functionDeclaration_copy_firstNondefining->get_scope()->class_name().c_str());
17809 printf ("functionDeclaration_original_defining->get_scope() = %p = %s \n",functionDeclaration_original_defining->get_scope(),functionDeclaration_original_defining->get_scope()->class_name().c_str());
17810 printf ("functionDeclaration_copy_defining->get_scope() = %p = %s \n",functionDeclaration_copy_defining->get_scope(),functionDeclaration_copy_defining->get_scope()->class_name().c_str());
17811 printf ("functionSymbolInTargetAST = %p = %s \n",functionSymbolInTargetAST,functionSymbolInTargetAST->class_name().c_str());
17812 }
17813
17814 ROSE_ASSERT(targetScope->lookup_function_symbol(name,functionType) != NULL);
17815
17816 // TV (10/22/2014): Might not be the case as we now have a project wide global scope
17817 // ROSE_ASSERT(functionDeclaration_copy_firstNondefining->get_scope() == targetScope);
17818
17819 ROSE_ASSERT(functionDeclaration_copy_firstNondefining == functionDeclaration_copy_firstNondefining->get_firstNondefiningDeclaration());
17820
17821 // This is what is called internal to the get_symbol_from_symbol_table() function below.
17822 // Use this function, SgFunctionDeclaration::get_symbol_from_symbol_table(), but not the template function: find_symbol_from_declaration().
17823 // ROSE_ASSERT(targetScope->find_symbol_from_declaration(functionDeclaration_copy_firstNondefining) != NULL);
17824
17825 ROSE_ASSERT(functionDeclaration_copy_firstNondefining->get_symbol_from_symbol_table() != NULL);
17826
17827#if 0
17828 bool isDefiningDeclaration (functionDeclaration_original->get_declaration() != NULL);
17829 if (isDefiningDeclaration == true)
17830 {
17831 // We may have to build a non-defining declaration.
17832 SgFunctionDeclaration* nondefiningFunctionDeclaration_original = functionDeclaration_original->get_firstNondefiningDeclaration();
17833 SgFile* nondefiningDeclarationFile = getEnclosingFileNode(functionSymbol_original);
17834 ROSE_ASSERT(nondefiningDeclarationFile != NULL);
17835 if (nondefiningDeclarationFile == targetFile)
17836 {
17837 // Use this nondefining declaration.
17838 }
17839 else
17840 {
17841 // Make a copy of the non-defining declaration for use in the symbol.
17842 }
17843
17844 }
17845 else
17846 {
17847 // Use this as non-defining declaration.
17848 }
17849
17850 SgFile* snippetFile = getEnclosingFileNode(functionSymbol_original);
17851 SgFunctionSymbol* new_function_symbol = new SgFunctionSymbol(isSgFunctionDeclaration(func));
17852 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
17853 targetScope->insert_symbol(name,symbol_original);
17854
17855 ROSE_ABORT();
17856#endif
17857 }
17858
17859 // DQ (3/17/2014): Refactored code to support resetting the scopes in the SgDeclarationStatement IR nodes.
17860 resetDeclaration(functionDeclaration_copy,functionDeclaration_original,targetScope);
17861#if 0
17862 printf ("SageBuilder::fixupCopyOfNodeFromSeperateFileInNewTargetAst(): Need to be able to fixup the SgFunctionDeclaration \n");
17863 ROSE_ABORT();
17864#endif
17865 break;
17866 }
17867
17868 case V_SgClassDeclaration:
17869 {
17870 // Need to handle the referenced types
17871 SgClassDeclaration* classDeclaration_copy = isSgClassDeclaration(node_copy);
17872 SgClassDeclaration* classDeclaration_original = isSgClassDeclaration(node_original);
17873 SgClassType* classType = classDeclaration_copy->get_type();
17874 ROSE_ASSERT(classType != NULL);
17875#if 0
17876 printf ("Need to handle named types from class declarations \n");
17877#endif
17878 // SgClassSymbol* classSymbol_copy = isSgClassSymbol(classDeclaration_copy->search_for_symbol_from_symbol_table());
17879 // ROSE_ASSERT(classSymbol_copy != NULL);
17880
17881 // if (TransformationSupport::getFile(classSymbol_copy) != targetFile)
17882 // if (getEnclosingFileNode(classSymbol_copy) != targetFile)
17883 // if (getEnclosingFileNode(classDeclaration_copy) != targetFile)
17884 {
17885 // printf ("Warning: case V_SgClassDeclaration: classSymbol_copy not in target file \n");
17886#if 0
17887 printf ("Warning: case V_SgClassDeclaration: assume getEnclosingFileNode(classDeclaration_copy) != targetFile \n");
17888#endif
17889 // Find the symbol in the target scope.
17890 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17891#if 0
17892 // printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
17893#endif
17894 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
17895
17896 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17897 // ROSE_ASSERT(targetScope != NULL);
17898
17899 SgName name = classDeclaration_copy->get_name();
17900#if 0
17901 // If we randomize the names then we need to handle this case...
17902 printf ("case V_SgClassDeclaration: targetScope = %p classSymbol_copy->get_name() = %s \n",targetScope,classSymbol_copy->get_name().str());
17903#endif
17904 // SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classSymbol_copy->get_name(),targetScope);
17905 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(name,targetScope);
17906
17907 if (classSymbolInTargetAST == NULL)
17908 {
17909 // If could be that the symbol is in the local scope of the snippet AST.
17910 SgScopeStatement* otherPossibleScope = isSgScopeStatement(classDeclaration_original->get_parent());
17911 ROSE_ASSERT(otherPossibleScope != NULL);
17912#if 0
17913 printf ("case V_SgClassDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
17914#endif
17915 // classSymbolInTargetAST = lookupClassSymbolInParentScopes(classSymbol_copy->get_name(),otherPossibleScope);
17916 classSymbolInTargetAST = lookupClassSymbolInParentScopes(name,otherPossibleScope);
17917 ROSE_ASSERT(classSymbolInTargetAST != NULL);
17918#if 0
17919 // I think this is the wrong code.
17920 SgClassDeclaration* classDeclaration = classSymbolInTargetAST->get_declaration();
17921 ROSE_ASSERT(classDeclaration != NULL);
17922 SgScopeStatement* scope = classDeclaration->get_scope();
17923 ROSE_ASSERT(scope != NULL);
17924 classDeclaration_copy->set_scope(scope);
17925#else
17926 // DQ (3/17/2014): The scope must be set to be the targetScope (at least for C, but maybe not C++).
17927 classDeclaration_copy->set_scope(targetScope);
17928#endif
17929 // DQ (3/17/2014): Build a new SgClassSymbol using the classDeclaration_copy.
17930 SgClassSymbol* classSymbol = new SgClassSymbol(classDeclaration_copy);
17931 ROSE_ASSERT(classSymbol != NULL);
17932 classSymbolInTargetAST = classSymbol;
17933
17934 // Insert the symbol into the targetScope.
17935 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
17936 targetScope->insert_symbol(name,classSymbolInTargetAST);
17937 }
17938 else
17939 {
17940 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
17941 SgClassDeclaration* classDeclaration = classSymbolInTargetAST->get_declaration();
17942 ROSE_ASSERT(classDeclaration != NULL);
17943 SgScopeStatement* scope = classDeclaration->get_scope();
17944 ROSE_ASSERT(scope != NULL);
17945 classDeclaration_copy->set_scope(scope);
17946 }
17947
17948 ROSE_ASSERT(classSymbolInTargetAST != NULL);
17949 }
17950
17951 // DQ (3/17/2014): Avoid calling strip type now that we have refactored the getTargetFileType() function.
17952 // DQ (3/10/2014): Added remaining type for this case.
17953 // SgType* new_type = getTargetFileType(classType->stripType(),targetScope);
17954 SgType* new_type = getTargetFileType(classType,targetScope);
17955 SgClassType* new_class_type = isSgClassType(new_type);
17956 if (new_class_type != NULL)
17957 {
17958 // Reset the base type to be the one associated with the target file.
17959 classDeclaration_copy->set_type(new_class_type);
17960#if 0
17961 printf ("case V_SgClassDeclaration: built class type: part 1: classDeclaration_copy->get_type() = %p = %s \n",
17962 classDeclaration_copy->get_type(),classDeclaration_copy->get_type()->class_name().c_str());
17963#endif
17964 }
17965
17966 resetDeclaration(classDeclaration_copy,classDeclaration_original,targetScope);
17967#if 0
17968 printf ("SgClassDeclaration: Exiting as a test! \n");
17969 ROSE_ABORT();
17970#endif
17971 break;
17972 }
17973
17974 case V_SgEnumDeclaration:
17975 {
17976 // Need to handle the referenced types
17977 SgEnumDeclaration* enumDeclaration_copy = isSgEnumDeclaration(node_copy);
17978 SgEnumDeclaration* enumDeclaration_original = isSgEnumDeclaration(node_original);
17979
17980 // SgEnumType* enumType = enumDeclaration_copy->get_type();
17981 // ROSE_ASSERT(enumType != NULL);
17982
17983 // I don't think we have to test for this being a part of the snippet file.
17984 {
17985 SgName name = enumDeclaration_copy->get_name();
17986#if 0
17987 // If we randomize the names then we need to handle this case...
17988 printf ("case V_SgEnumDeclaration: targetScope = %p enumSymbol_copy->get_name() = %s \n",targetScope,name.str());
17989#endif
17990 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(name,targetScope);
17991
17992 if (enumSymbolInTargetAST == NULL)
17993 {
17994 // If could be that the symbol is in the local scope of the snippet AST.
17995 SgScopeStatement* otherPossibleScope = isSgScopeStatement(enumDeclaration_original->get_parent());
17996 ROSE_ASSERT(otherPossibleScope != NULL);
17997#if 0
17998 printf ("case V_SgEnumDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
17999#endif
18000 // I think we are not looking in the correct scope! Or else we need to also look in the target global scope.
18001#if 0
18002 printf ("Since the symbol has not been inserted yet, what symbol are we looking for? \n");
18003#endif
18004 enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(name,otherPossibleScope);
18005
18006 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
18007 SgEnumDeclaration* enumDeclaration = enumSymbolInTargetAST->get_declaration();
18008 ROSE_ASSERT(enumDeclaration != NULL);
18009
18010 ROSE_ASSERT(enumDeclaration != enumDeclaration_original);
18011
18012 // This is true, so we need to build a new sysmbol.
18013 ROSE_ASSERT(enumSymbolInTargetAST->get_declaration() == enumDeclaration_original->get_firstNondefiningDeclaration());
18014
18015 // Build a new SgEnumSymbol using the enumDeclaration_copy.
18016 SgEnumSymbol* enumSymbol = new SgEnumSymbol(enumDeclaration_copy);
18017 ROSE_ASSERT(enumSymbol != NULL);
18018 enumSymbolInTargetAST = enumSymbol;
18019
18020 // If this is false then we need to build a new SgEnumSymbol rather than reusing the existing one.
18021 ROSE_ASSERT(enumSymbolInTargetAST->get_declaration() != enumDeclaration_original->get_firstNondefiningDeclaration());
18022
18023 // SgScopeStatement* scope = enumDeclaration->get_scope();
18024 SgScopeStatement* scope = targetScope;
18025 ROSE_ASSERT(scope != NULL);
18026 enumDeclaration_copy->set_scope(scope);
18027#if 0
18028 printf ("case V_SgEnumDeclaration: insert_symbol(): name = %s enumSymbolInTargetAST = %p \n",name.str(),enumSymbolInTargetAST);
18029#endif
18030 // Insert the symbol into the targetScope.
18031 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
18032 targetScope->insert_symbol(name,enumSymbolInTargetAST);
18033 }
18034 else
18035 {
18036#if 0
18037 printf ("Found an existing enum declaration: name = %s enumSymbolInTargetAST = %p \n",name.str(),enumSymbolInTargetAST);
18038#endif
18039 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
18040 SgEnumDeclaration* enumDeclaration = enumSymbolInTargetAST->get_declaration();
18041 ROSE_ASSERT(enumDeclaration != NULL);
18042#if 0
18043 SgScopeStatement* scope = enumDeclaration->get_scope();
18044 ROSE_ASSERT(scope != NULL);
18045 ROSE_ASSERT(scope == targetScope);
18046 // enumDeclaration_copy->set_scope(scope);
18047#else
18048 // TV (10/22/2014): Might not be the case as we now have a project wide global scope
18049 // ROSE_ASSERT(enumDeclaration->get_scope() == targetScope);
18050#endif
18051 }
18052
18053 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
18054 }
18055#if 0
18056 printf ("Exiting as a test 1! \n");
18057 ROSE_ABORT();
18058#endif
18059 SgEnumType* enumType = enumDeclaration_copy->get_type();
18060 ROSE_ASSERT(enumType != NULL);
18061 SgType* new_type = getTargetFileType(enumType,targetScope);
18062#if 0
18063 printf ("Return type from getTargetFileType(): original enumType = %p new_type = %p \n",enumType,new_type);
18064#endif
18065 SgEnumType* new_enum_type = isSgEnumType(new_type);
18066 if (new_enum_type != NULL)
18067 {
18068 // Reset the base type to be the one associated with the target file.
18069#if 0
18070 printf ("reset the type using the new enum type from the target AST \n");
18071#endif
18072 enumDeclaration_copy->set_type(new_enum_type);
18073 }
18074#if 0
18075 printf ("Exiting as a test 2! \n");
18076 ROSE_ABORT();
18077#endif
18078
18079 resetDeclaration(enumDeclaration_copy,enumDeclaration_original,targetScope);
18080 break;
18081 }
18082
18083 // This is not a required declaration of C.
18084 case V_SgTemplateClassDeclaration:
18085 {
18086 // Need to handle the referenced types
18087 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(node_copy);
18088 SgClassType* templateClassType = templateClassDeclaration->get_type();
18089 ROSE_ASSERT(templateClassType != NULL);
18090
18091 // DQ (3/10/2014): Added support for enum types.
18092 SgType* new_type = getTargetFileType(templateClassType,targetScope);
18093 SgClassType* new_templateClass_type = isSgClassType(new_type);
18094 if (new_templateClass_type != NULL)
18095 {
18096 // Reset the base type to be the one associated with the target file.
18097 templateClassDeclaration->set_type(new_templateClass_type);
18098#if 0
18099 printf ("case V_SgTemplateClassDeclaration: built class type: part 1: templateClassDeclaration->get_type() = %p = %s \n",
18100 templateClassDeclaration->get_type(),templateClassDeclaration->get_type()->class_name().c_str());
18101#endif
18102 }
18103
18104 break;
18105 }
18106
18107 case V_SgTypedefDeclaration:
18108 {
18109 // Need to handle the referenced types (there are two for the case of a SgTypedefDeclaration).
18110 SgTypedefDeclaration* typedefDeclaration_copy = isSgTypedefDeclaration(node_copy);
18111 SgTypedefDeclaration* typedefDeclaration_original = isSgTypedefDeclaration(node_original);
18112
18113 SgType* base_type = typedefDeclaration_copy->get_base_type();
18114 ROSE_ASSERT(base_type != NULL);
18115 SgType* new_base_type = getTargetFileType(base_type,targetScope);
18116 if (new_base_type != NULL)
18117 {
18118 // Reset the base type to be the one associated with the target file.
18119 typedefDeclaration_copy->set_base_type(new_base_type);
18120 }
18121
18122 // I don't think we have to test for this being a part of the snippet file.
18123 {
18124 SgName name = typedefDeclaration_copy->get_name();
18125#if 0
18126 // If we randomize the names then we need to handle this case...
18127 printf ("case V_SgTypedefDeclaration: targetScope = %p typedefSymbol_copy->get_name() = %s \n",targetScope,name.str());
18128#endif
18129 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(name,targetScope);
18130
18131 if (typedefSymbolInTargetAST == NULL)
18132 {
18133 // If could be that the symbol is in the local scope of the snippet AST.
18134 SgScopeStatement* otherPossibleScope = isSgScopeStatement(typedefDeclaration_original->get_parent());
18135 ROSE_ASSERT(otherPossibleScope != NULL);
18136#if 0
18137 printf ("case V_SgTypedefDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
18138#endif
18139 typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(name,otherPossibleScope);
18140
18141 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
18142 SgTypedefDeclaration* typedefDeclaration = typedefSymbolInTargetAST->get_declaration();
18143 ROSE_ASSERT(typedefDeclaration != NULL);
18144 // SgScopeStatement* scope = typedefDeclaration->get_scope();
18145 SgScopeStatement* scope = targetScope;
18146 ROSE_ASSERT(scope != NULL);
18147 typedefDeclaration_copy->set_scope(scope);
18148
18149 // DQ (3/17/2014): Build a new SgTypedefSymbol using the typedefDeclaration_copy.
18150 SgTypedefSymbol* typedefSymbol = new SgTypedefSymbol(typedefDeclaration_copy);
18151 ROSE_ASSERT(typedefSymbol != NULL);
18152 typedefSymbolInTargetAST = typedefSymbol;
18153#if 0
18154 printf ("case V_SgTypedefDeclaration: insert_symbol(): name = %s typedefSymbolInTargetAST = %p \n",name.str(),typedefSymbolInTargetAST);
18155#endif
18156 // Insert the symbol into the targetScope.
18157 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
18158 targetScope->insert_symbol(name,typedefSymbolInTargetAST);
18159 }
18160 else
18161 {
18162#if 0
18163 printf ("Found an existing typedef declaration: name = %s typedefSymbolInTargetAST = %p \n",name.str(),typedefSymbolInTargetAST);
18164#endif
18165 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
18166 SgTypedefDeclaration* typedefDeclaration = typedefSymbolInTargetAST->get_declaration();
18167 ROSE_ASSERT(typedefDeclaration != NULL);
18168 SgScopeStatement* scope = typedefDeclaration->get_scope();
18169 ROSE_ASSERT(scope != NULL);
18170 typedefDeclaration_copy->set_scope(scope);
18171 }
18172
18173 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
18174 }
18175#if 0
18176 printf ("Exiting as a test 1! \n");
18177 ROSE_ABORT();
18178#endif
18179 SgTypedefType* typedefType = typedefDeclaration_copy->get_type();
18180 ROSE_ASSERT(typedefType != NULL);
18181 SgType* new_type = getTargetFileType(typedefType,targetScope);
18182 SgTypedefType* new_typedef_type = isSgTypedefType(new_type);
18183 if (new_typedef_type != NULL)
18184 {
18185 // Reset the base type to be the one associated with the target file.
18186#if 0
18187 printf ("reset the type using the new typedef type from the target AST \n");
18188#endif
18189 typedefDeclaration_copy->set_type(new_typedef_type);
18190#if 0
18191 printf ("case V_SgTypedefDeclaration: built class type: part 1: typedefDeclaration_copy->get_type() = %p = %s \n",
18192 typedefDeclaration_copy->get_type(),typedefDeclaration_copy->get_type()->class_name().c_str());
18193#endif
18194 }
18195
18196 resetDeclaration(typedefDeclaration_copy,typedefDeclaration_original,targetScope);
18197#if 0
18198 printf ("Exiting as a test 2! \n");
18199 ROSE_ABORT();
18200#endif
18201 break;
18202 }
18203
18204 case V_SgVarRefExp:
18205 {
18206 // Need to handle the referenced symbol.
18207 // but if we have handle this in the declaration for the variable (case V_SgInitializedName)
18208 // then we don't have to do anything here. However, we have only handled this variable
18209 // declaration if the variable declaration was a part of the snippet. If the variable
18210 // declaration is not a part of the original snippet (the copy of the snippet's AST that
18211 // we are inserting (not the snippet program where it would have to be defined for the
18212 // snippet to compile) then we have to find the associated variable sysmbol in the target
18213 // AST and reset the SgVarRefExp to use that symbol.
18214
18215 SgVarRefExp* varRefExp_copy = isSgVarRefExp(node_copy);
18216 SgVarRefExp* varRefExp_original = isSgVarRefExp(node_original);
18217 SgVariableSymbol* variableSymbol_copy = isSgVariableSymbol(varRefExp_copy->get_symbol());
18218 ROSE_ASSERT(variableSymbol_copy != NULL);
18219 // if (TransformationSupport::getFile(variableSymbol_copy) != targetFile)
18220 if (getEnclosingFileNode(variableSymbol_copy) != targetFile)
18221 {
18222#if 0
18223 printf ("Warning: case V_SgVarRefExp: variableSymbol not in target file: name = %s \n",variableSymbol_copy->get_name().str());
18224#endif
18225#if 0
18226 printf ("insertionPoint = %p = %s \n",insertionPoint,insertionPoint->class_name().c_str());
18227#endif
18228 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
18229#if 0
18230 // printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
18231#endif
18232 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
18233
18234 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
18235 // ROSE_ASSERT(targetScope != NULL);
18236
18237 SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),targetScope);
18238
18239 if (variableSymbolInTargetAST == NULL)
18240 {
18241 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
18242 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
18243 // previously added snippet.
18244#if 0
18245 printf ("Error: The associated variable = %s should have been found in a parent scope of the target AST \n",variableSymbol_copy->get_name().str());
18246#endif
18247 // We need to look into the scope of the block used to define the statments as seperate snippets (same issue as for functions).
18248
18249 // If could be that the symbol is in the local scope of the snippet AST.
18250 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(varRefExp_original);
18251 ROSE_ASSERT(enclosingStatement_original != NULL);
18252#if 0
18253 printf ("case V_SgVarRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
18254#endif
18255 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
18256 ROSE_ASSERT(otherPossibleScope_original != NULL);
18257 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
18258 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
18259 ROSE_ASSERT(file != NULL);
18260#if 0
18261 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
18262 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18263
18264 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
18265 printf ("case V_SgClassDeclaration: variableSymbol_copy->get_name() = %s \n",variableSymbol_copy->get_name().str());
18266#endif
18267 variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),otherPossibleScope_original);
18268 if (variableSymbolInTargetAST == NULL)
18269 {
18270#if 0
18271 targetScope->get_symbol_table()->print("targetScope: symbol table");
18272 otherPossibleScope_original->get_symbol_table()->print("otherPossibleScope_original: symbol table");
18273#endif
18274
18275 // Check for the case of a record reference (member of data structure).
18276 SgExpression* parentExpression = isSgExpression(varRefExp_copy->get_parent());
18277 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
18278 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
18279 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
18280 if (parentDotExp != NULL || parentArrowExp != NULL)
18281 {
18282 // This is a data member reference, so it's scope is the associated data structure.
18283 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
18284 ROSE_ASSERT(lhs != NULL);
18285 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == varRefExp_copy);
18286
18287 SgType* type = lhs->get_type();
18288 ROSE_ASSERT(type != NULL);
18289#if 0
18290 printf ("type = %p = %s \n",type,type->class_name().c_str());
18291#endif
18292 SgNamedType* namedType = isSgNamedType(type);
18293 ROSE_ASSERT(namedType != NULL);
18294 SgDeclarationStatement* declaration = namedType->get_declaration();
18295 ROSE_ASSERT(declaration != NULL);
18296 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
18297 ROSE_ASSERT(classDeclaration != NULL);
18298 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
18299 ROSE_ASSERT(definingClassDeclaration != NULL);
18300 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18301 ROSE_ASSERT(classDefinition != NULL);
18302#if 0
18303 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
18304#endif
18305 // I think we want the copy.
18306 otherPossibleScope_original = classDefinition;
18307
18308 variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),otherPossibleScope_original);
18309 }
18310
18311 }
18312 ROSE_ASSERT(variableSymbolInTargetAST != NULL);
18313 SgInitializedName* initializedName = variableSymbolInTargetAST->get_declaration();
18314 ROSE_ASSERT(initializedName != NULL);
18315 SgScopeStatement* scope = initializedName->get_scope();
18316 ROSE_ASSERT(scope != NULL);
18317
18318 // Is this the correct scope?
18319 initializedName->set_scope(scope);
18320
18321 // Insert the symbol into the targetScope.
18322 targetScope->insert_symbol(variableSymbol_copy->get_name(),variableSymbolInTargetAST);
18323 }
18324 ROSE_ASSERT(variableSymbolInTargetAST != NULL);
18325
18326 // Reset the symbol associated with this variable reference.
18327 varRefExp_copy->set_symbol(variableSymbolInTargetAST);
18328
18329 // printf ("Exiting as a test! \n");
18330 // ROSE_ASSERT(false);
18331 }
18332
18333 break;
18334 }
18335
18336 case V_SgFunctionRefExp:
18337 {
18338 // Need to handle the referenced symbol
18339 SgFunctionRefExp* functionRefExp_copy = isSgFunctionRefExp(node_copy);
18340 // SgFunctionRefExp* functionRefExp_original = isSgFunctionRefExp(node_original);
18341 SgFunctionSymbol* functionSymbol_copy = isSgFunctionSymbol(functionRefExp_copy->get_symbol());
18342 ROSE_ASSERT(functionSymbol_copy != NULL);
18343 // if (TransformationSupport::getFile(functionSymbol) != targetFile)
18344 if (getEnclosingFileNode(functionSymbol_copy) != targetFile)
18345 {
18346#if 0
18347 printf ("Warning: case V_SgFunctionRefExp: functionSymbol_copy not in target file (find function = %s) \n",functionSymbol_copy->get_name().str());
18348#endif
18349 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
18350#if 0
18351 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
18352#endif
18353 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
18354
18355 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
18356 // ROSE_ASSERT(targetScope != NULL);
18357
18358 SgName name = functionSymbol_copy->get_name();
18359
18360 // I think we need the function's mangled name to support this lookup.
18361 SgFunctionSymbol* functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,targetScope);
18362
18363 if (functionSymbolInTargetAST == NULL)
18364 {
18365 // DQ (3/17/2014): Revised as of further discussion about how the snippet mechanism will copy required
18366 // declaration from the snippet file to the target AST.
18367 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
18368 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
18369 // previously added snippet.
18370 // DQ (3/17/2014): After some revision of the specification for the snippet injection, this is still
18371 // an error since this is the case where a declaration should have been visible from having already been
18372 // inserted into the target AST and this visible from this injection point in the target AST.
18373
18374 fprintf (stderr, "Error: The associated function = \"%s\" should have been found in a parent scope"
18375 " of the target AST\n", name.str());
18376
18377 fprintf (stderr, " targetScope = %p = %s \n",targetScope,targetScope->class_name().c_str());
18378 SgGlobal* globalScope = TransformationSupport::getGlobalScope(targetScope);
18379 ROSE_ASSERT(globalScope != NULL);
18380 fprintf (stderr, " globalScope = %p = %s \n",globalScope,globalScope->class_name().c_str());
18381#if 0
18382 targetScope->get_file_info()->display("case V_SgFunctionRefExp: targetScope: debug");
18383 node_original->get_file_info()->display("case V_SgFunctionRefExp: node_original: debug");
18384#endif
18385#if 0
18386 // DQ (3/10/2014): This might be important for friend functions in C++ (but we can ignore it for now).
18387#error "DEAD CODE!"
18388 // If could be that the symbol is in the local scope of the snippet AST.
18389 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(functionRefExp_original);
18390 ROSE_ASSERT(enclosingStatement_original != NULL);
18391#if 0
18392 printf ("case V_SgFunctionRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
18393#endif
18394 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
18395 ROSE_ASSERT(otherPossibleScope_original != NULL);
18396 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
18397 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
18398 ROSE_ASSERT(file != NULL);
18399#if 0
18400 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
18401 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18402
18403 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
18404 printf ("case V_SgClassDeclaration: functionSymbol_copy->get_name() = %s \n",functionSymbol_copy->get_name().str());
18405#endif
18406 functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(functionSymbol_copy->get_name(),otherPossibleScope_original);
18407#error "DEAD CODE!"
18408 if (functionSymbolInTargetAST == NULL)
18409 {
18410 // Check for the case of a record reference (member function of class declaration).
18411 SgExpression* parentExpression = isSgExpression(functionRefExp_copy->get_parent());
18412 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
18413 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
18414 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
18415 if (parentDotExp != NULL || parentArrowExp != NULL)
18416 {
18417 // This is a data member reference, so it's scope is the associated data structure.
18418 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
18419 ROSE_ASSERT(lhs != NULL);
18420 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == functionRefExp_copy);
18421#error "DEAD CODE!"
18422 SgType* type = lhs->get_type();
18423 ROSE_ASSERT(type != NULL);
18424#if 0
18425 printf ("type = %p = %s \n",type,type->class_name().c_str());
18426#endif
18427 SgNamedType* namedType = isSgNamedType(type);
18428 ROSE_ASSERT(namedType != NULL);
18429 SgDeclarationStatement* declaration = namedType->get_declaration();
18430 ROSE_ASSERT(declaration != NULL);
18431 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
18432 ROSE_ASSERT(classDeclaration != NULL);
18433 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
18434 ROSE_ASSERT(definingClassDeclaration != NULL);
18435 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18436 ROSE_ASSERT(classDefinition != NULL);
18437#if 0
18438 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
18439#endif
18440 // I think we want the copy.
18441 otherPossibleScope_original = classDefinition;
18442
18443 functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(functionSymbol_copy->get_name(),otherPossibleScope_original);
18444 }
18445 }
18446
18447#error "DEAD CODE!"
18448 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
18449 SgFunctionDeclaration* functionDeclaration = functionSymbolInTargetAST->get_declaration();
18450 ROSE_ASSERT(functionDeclaration != NULL);
18451 SgScopeStatement* scope = functionDeclaration->get_scope();
18452 ROSE_ASSERT(scope != NULL);
18453
18454 // Is this the correct scope?
18455 functionDeclaration->set_scope(scope);
18456#endif
18457 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
18458
18459 // Insert the symbol into the targetScope.
18460 targetScope->insert_symbol(functionSymbol_copy->get_name(),functionSymbolInTargetAST);
18461 }
18462 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
18463
18464 // Reset the symbol associated with this function reference.
18465 functionRefExp_copy->set_symbol(functionSymbolInTargetAST);
18466#if 0
18467 printf ("Exiting as a test! \n");
18468 ROSE_ABORT();
18469#endif
18470 }
18471
18472 break;
18473 }
18474
18475#define DEBUG_MEMBER_FUNCTION_REF_EXP 0
18476
18477 case V_SgMemberFunctionRefExp:
18478 {
18479 // Need to handle the referenced symbol
18480 SgMemberFunctionRefExp* memberFunctionRefExp_copy = isSgMemberFunctionRefExp(node_copy);
18481 SgMemberFunctionRefExp* memberFunctionRefExp_original = isSgMemberFunctionRefExp(node_original);
18482 SgMemberFunctionSymbol* memberFunctionSymbol_copy = isSgMemberFunctionSymbol(memberFunctionRefExp_copy->get_symbol());
18483 ROSE_ASSERT(memberFunctionSymbol_copy != NULL);
18484 // if (TransformationSupport::getFile(memberFunctionSymbol) != targetFile)
18485 if (getEnclosingFileNode(memberFunctionSymbol_copy) != targetFile)
18486 {
18487 // Not implemented (initial work is focused on C, then Java, then C++.
18488#if DEBUG_MEMBER_FUNCTION_REF_EXP
18489 printf ("Warning: case V_SgMemberFunctionRefExp: memberFunctionSymbol_copy not in target file (find member function = %s) \n",memberFunctionSymbol_copy->get_name().str());
18490#endif
18491 SgMemberFunctionSymbol* memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),targetScope));
18492
18493 if (memberFunctionSymbolInTargetAST == NULL)
18494 {
18495 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
18496 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
18497 // previously added snippet.
18498#if DEBUG_MEMBER_FUNCTION_REF_EXP
18499 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());
18500#endif
18501 // DQ (3/10/2014): This is important for member functions in Java and C++.
18502
18503 // If could be that the symbol is in the local scope of the snippet AST.
18504 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(memberFunctionRefExp_original);
18505 ROSE_ASSERT(enclosingStatement_original != NULL);
18506#if DEBUG_MEMBER_FUNCTION_REF_EXP
18507 printf ("case V_SgMemberFunctionRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
18508#endif
18509 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
18510 ROSE_ASSERT(otherPossibleScope_original != NULL);
18511 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
18512 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
18513 ROSE_ASSERT(file != NULL);
18514#if DEBUG_MEMBER_FUNCTION_REF_EXP
18515 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
18516 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18517
18518 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
18519 printf ("case V_SgClassDeclaration: memberFunctionSymbol_copy->get_name() = %s \n",memberFunctionSymbol_copy->get_name().str());
18520#endif
18521 memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original));
18522 if (memberFunctionSymbolInTargetAST == NULL)
18523 {
18524#if DEBUG_MEMBER_FUNCTION_REF_EXP
18525 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");
18526#endif
18527 // Check for the case of a record reference (member function of class declaration).
18528 SgExpression* parentExpression = isSgExpression(memberFunctionRefExp_copy->get_parent());
18529
18530 ROSE_ASSERT(parentExpression != NULL);
18531#if DEBUG_MEMBER_FUNCTION_REF_EXP
18532 printf ("parentExpression = %p = %s \n",parentExpression,parentExpression->class_name().c_str());
18533#endif
18534 bool handle_as_java = false;
18535 SgFunctionCallExp* functionCallExp = isSgFunctionCallExp(parentExpression);
18536 if (functionCallExp != NULL)
18537 {
18538 // Note that this is a Java specific organization of the SgMemberFunctionRefExp and the SgFunctionCallExp.
18539 // We might want to make this more uniform between C++ and Java later.
18540 handle_as_java = true;
18541
18542 SgExpression* parentOfFunctionCallExpression = isSgExpression(functionCallExp->get_parent());
18543
18544 ROSE_ASSERT(parentOfFunctionCallExpression != NULL);
18545#if DEBUG_MEMBER_FUNCTION_REF_EXP
18546 printf ("parentOfFunctionCallExpression = %p = %s \n",parentOfFunctionCallExpression,parentOfFunctionCallExpression->class_name().c_str());
18547#endif
18548 parentExpression = parentOfFunctionCallExpression;
18549 }
18550
18551 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
18552 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
18553 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
18554#if DEBUG_MEMBER_FUNCTION_REF_EXP
18555 printf ("parentBinaryOp = %p \n",parentBinaryOp);
18556 printf ("parentDotExp = %p \n",parentDotExp);
18557 printf ("parentArrowExp = %p \n",parentArrowExp);
18558#endif
18559 if (parentDotExp != NULL || parentArrowExp != NULL)
18560 {
18561 // This is a data member reference, so it's scope is the associated data structure.
18562 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
18563 ROSE_ASSERT(lhs != NULL);
18564
18565 // This will be true for C++, but not Java (a little odd).
18566 if (handle_as_java == true)
18567 {
18568 // The rhs is the SgFunctionCallExp for Java.
18569 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == functionCallExp);
18570 }
18571 else
18572 {
18573 // This is what we expect to be true for C++.
18574 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == memberFunctionRefExp_copy);
18575 }
18576#if DEBUG_MEMBER_FUNCTION_REF_EXP
18577 printf ("lhs = %p = %s \n",lhs,lhs->class_name().c_str());
18578#endif
18579 SgVarRefExp* varRefExp = isSgVarRefExp(lhs);
18580
18581 // DQ (3/15/2014): This can be a SgJavaTypeExpression (see testJava3a).
18582 // ROSE_ASSERT(varRefExp != NULL);
18583 if (varRefExp != NULL)
18584 {
18585 SgVariableSymbol* variableSymbol = isSgVariableSymbol(varRefExp->get_symbol());
18586 ROSE_ASSERT(variableSymbol != NULL);
18587 SgInitializedName* initializedName = variableSymbol->get_declaration();
18588 ROSE_ASSERT(initializedName != NULL);
18589
18590 SgType* initializedName_type = initializedName->get_type();
18591#if DEBUG_MEMBER_FUNCTION_REF_EXP
18592 printf ("initializedName = %p = %s \n",initializedName,initializedName->get_name().str());
18593 printf ("initializedName_type = %p \n",initializedName_type);
18594#endif
18595 SgClassType* classType = isSgClassType(initializedName_type);
18596 if (classType != NULL)
18597 {
18598 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
18599 ROSE_ASSERT(classDeclaration != NULL);
18600 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(classDeclaration->get_definingDeclaration());
18601 ROSE_ASSERT(definingClassDeclaration != NULL);
18602 printf ("definingClassDeclaration->get_name() = %s \n",definingClassDeclaration->get_name().str());
18603
18604 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18605 ROSE_ASSERT(classDefinition != NULL);
18606 SgType* memberFunctionType = memberFunctionSymbol_copy->get_type();
18607 SgName memberFunctionName = memberFunctionSymbol_copy->get_name();
18608 ROSE_ASSERT(memberFunctionType != NULL);
18609 SgFunctionSymbol *functionSymbol = classDefinition->lookup_function_symbol(memberFunctionName,memberFunctionType);
18610 if (functionSymbol == NULL)
18611 {
18612 printf ("Symbol not found: output symbol table (size = %d): \n",classDefinition->get_symbol_table()->size());
18613#if DEBUG_MEMBER_FUNCTION_REF_EXP
18614 classDefinition->get_symbol_table()->print("Symbol not found: output symbol table: SgClassDefinition");
18615#endif
18616 // DQ (3/30/2014): If functionSymbol is not found then I think it is because the class was not availalbe
18617 // in the target where the snippet is being copied. This is an error in the constrains for how the target
18618 // must be prepared for the snippet to be copied into it.
18619 printf ("\n*************************************************************** \n");
18620 printf ("ERROR: target has not be properly setup to receive the snippet. \n");
18621 printf ("*************************************************************** \n");
18622 }
18623 ROSE_ASSERT(functionSymbol != NULL);
18624 SgMemberFunctionSymbol *memberFunctionSymbol = isSgMemberFunctionSymbol(functionSymbol);
18625 ROSE_ASSERT(memberFunctionSymbol != NULL);
18626
18627 memberFunctionSymbolInTargetAST = memberFunctionSymbol;
18628#if 0
18629 printf ("Exiting as a test! \n");
18630 ROSE_ABORT();
18631#endif
18632 }
18633 }
18634
18635 // DQ (3/30/2014): If this is a value expression then calling the member function uses a shared
18636 // symbol from the global scope (or a type defined deep in the global scope, but common to the
18637 // snippet AST and the target AST).
18638 SgValueExp* valueExp = isSgValueExp(lhs);
18639 if (valueExp != NULL)
18640 {
18641 memberFunctionSymbolInTargetAST = memberFunctionSymbol_copy;
18642 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18643 }
18644
18645 if (memberFunctionSymbolInTargetAST == NULL)
18646 {
18647#if 1
18648 SgType* type = lhs->get_type();
18649 ROSE_ASSERT(type != NULL);
18650#if DEBUG_MEMBER_FUNCTION_REF_EXP
18651 printf ("type = %p = %s \n",type,type->class_name().c_str());
18652#endif
18653 SgNamedType* namedType = isSgNamedType(type);
18654 ROSE_ASSERT(namedType != NULL);
18655 SgDeclarationStatement* declaration = namedType->get_declaration();
18656 ROSE_ASSERT(declaration != NULL);
18657 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
18658 ROSE_ASSERT(classDeclaration != NULL);
18659 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
18660 ROSE_ASSERT(definingClassDeclaration != NULL);
18661 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18662 ROSE_ASSERT(classDefinition != NULL);
18663#if DEBUG_MEMBER_FUNCTION_REF_EXP
18664 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
18665#endif
18666 // I think we want the copy.
18667 otherPossibleScope_original = classDefinition;
18668#if DEBUG_MEMBER_FUNCTION_REF_EXP
18669 classDefinition->get_symbol_table()->print("Java classDefinition");
18670#endif
18671#if DEBUG_MEMBER_FUNCTION_REF_EXP
18672 SgClassDeclaration* associated_classDeclaration = classDefinition->get_declaration();
18673 SgFunctionSymbol* functionSymbol = lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original);
18674 printf ("associated_classDeclaration = %p name = %s \n",associated_classDeclaration,associated_classDeclaration->get_name().str());
18675 printf ("functionSymbol = %p \n",functionSymbol);
18676#endif
18677 memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original));
18678 if (memberFunctionSymbolInTargetAST == NULL)
18679 {
18680 // Output debugging info (16 of the CWE injection test codes fail here: see test_results.txt file for details).
18681 printf ("Error: (memberFunctionSymbolInTargetAST == NULL): memberFunctionSymbol_copy->get_name() = %s \n",memberFunctionSymbol_copy->get_name().str());
18682 }
18683#endif
18684 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18685 }
18686 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18687 }
18688 }
18689
18690 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18691 SgFunctionDeclaration* functionDeclaration = memberFunctionSymbolInTargetAST->get_declaration();
18692 ROSE_ASSERT(functionDeclaration != NULL);
18693 SgScopeStatement* scope = functionDeclaration->get_scope();
18694 ROSE_ASSERT(scope != NULL);
18695
18696 // Is this the correct scope?
18697 functionDeclaration->set_scope(scope);
18698 }
18699 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18700
18701 // Reset the symbol associated with this function reference.
18702 memberFunctionRefExp_copy->set_symbol(memberFunctionSymbolInTargetAST);
18703 }
18704
18705 break;
18706 }
18707
18708 // DQ (3/21/2014): I think we need this.
18709 case V_SgTryStmt:
18710 {
18711#if 0
18712 printf ("Exiting as a test! (SgTryStmt) \n");
18713 ROSE_ABORT();
18714#endif
18715 break;
18716 }
18717
18718 // DQ (3/19/2014): Just found this case in a few of the CWE Java snippet tests.
18719 case V_SgCatchStatementSeq:
18720 {
18721 // DQ (3/19/2014): Note sure that we need to handle this specific case.
18722
18723#if 0
18724 printf ("Exiting as a test! (SgCatchStatementSeq) \n");
18725 ROSE_ABORT();
18726#endif
18727 break;
18728 }
18729
18730 // DQ (3/19/2014): Just found this case in a few of the CWE Java snippet tests.
18731 case V_SgCatchOptionStmt:
18732 {
18733 // DQ (3/19/2014): Note sure that we need to handle this specific case.
18734 // Decide if we need to implement this newly identified case tomorrow (note that this is a SgScopeStatement).
18735 SgCatchOptionStmt* catchOptionStatement_copy = isSgCatchOptionStmt(node_copy);
18736 ROSE_ASSERT(catchOptionStatement_copy);
18737
18738 printf ("Need to check the symbol table of the SgCatchOptionStmt (which is a SgScopeStatement) \n");
18739
18740#if 0
18741 printf ("Exiting as a test! (SgCatchOptionStmt) \n");
18742 ROSE_ABORT();
18743#endif
18744 break;
18745 }
18746
18747 // DQ (3/21/2014): I think we need this.
18748 case V_SgJavaPackageStatement:
18749 {
18750#if 1
18751 printf ("Exiting as a test! (SgJavaPackageStatement) \n");
18752 ROSE_ABORT();
18753#endif
18754 break;
18755 }
18756
18757 case V_SgEnumVal:
18758 {
18759 // SgEnumVal expressions contain a reference to the associated SgEnumDeclaration, so this may have to be updated.
18760#if 0
18761 printf ("enum values contain a reference to the associated SgEnumDeclaration \n");
18762#endif
18763 SgEnumVal* enumVal_copy = isSgEnumVal(node_copy);
18764 SgEnumVal* enumVal_original = isSgEnumVal(node_original);
18765#if 0
18766 printf (" --- enumVal_original = %p = %d name = %s \n",enumVal_original,enumVal_original->get_value(),enumVal_original->get_name().str());
18767#endif
18768 SgEnumDeclaration* associatedEnumDeclaration_copy = isSgEnumDeclaration(enumVal_copy->get_declaration());
18769 SgEnumDeclaration* associatedEnumDeclaration_original = isSgEnumDeclaration(enumVal_original->get_declaration());
18770
18771 // DQ (4/13/2014): check if this is an un-named enum beclaration.
18772 bool isUnNamed = associatedEnumDeclaration_original->get_isUnNamed();
18773 if (isUnNamed == false)
18774 {
18775 if (associatedEnumDeclaration_copy == associatedEnumDeclaration_original)
18776 {
18777#if 0
18778 printf (" --- The stored reference to the enum declaration in the SgEnumVal must be reset \n");
18779#endif
18780 // SgSymbol* SageBuilder::findAssociatedSymbolInTargetAST(SgDeclarationStatement* snippet_declaration, SgScopeStatement* targetScope)
18781 SgSymbol* symbol = findAssociatedSymbolInTargetAST(associatedEnumDeclaration_original,targetScope);
18782 if (symbol == NULL)
18783 {
18784 // debug this case.
18785 enumVal_original->get_file_info()->display("case V_SgEnumVal: symbol == NULL: debug");
18786 }
18787 ROSE_ASSERT(symbol != NULL);
18788 SgEnumSymbol* enumSymbol = isSgEnumSymbol(symbol);
18789 ROSE_ASSERT(enumSymbol != NULL);
18790 SgEnumDeclaration* new_associatedEnumDeclaration_copy = enumSymbol->get_declaration();
18791 ROSE_ASSERT(new_associatedEnumDeclaration_copy != NULL);
18792
18793 // If this is false then in means that we should have built a new SgEnumSymbol instead of reusing the existing one from the snippet.
18794 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
18795 // ROSE_ASSERT(new_associatedEnumDeclaration_copy != associatedEnumDeclaration_original->get_firstNondefiningDeclaration());
18796 ROSE_ASSERT(new_associatedEnumDeclaration_copy != associatedEnumDeclaration_original->get_definingDeclaration());
18797
18798 enumVal_copy->set_declaration(new_associatedEnumDeclaration_copy);
18799#if 0
18800 printf ("Exiting as a test! \n");
18801 ROSE_ABORT();
18802#endif
18803 }
18804 }
18805 else
18806 {
18807 // DQ (4/13/2014): I think we all agreed these would not have to be handled, so issue a warning.
18808 // It still is likely that I can allow this, but permit this intermediate fix.
18809 printf ("Warning: can't handle enum values from unnamed enum declarations \n");
18810 printf (" --- enumVal_original = %p = %lld name = %s \n",enumVal_original,enumVal_original->get_value(),enumVal_original->get_name().str());
18811 }
18812
18813 break;
18814 }
18815
18816 default:
18817 {
18818 // Most IR nodes do not require specialized fixup (are not processed).
18819 }
18820 }
18821
18822#if 1
18823 // DQ (3/17/2014): Cause failure on warnings about any constructs referencing the snippet AST.
18824#if 0
18825 // Assert fail on warnings.
18826 errorCheckingTargetAST(node_copy,node_original,targetFile, true);
18827#else
18828 // Cause only warnings.
18829 errorCheckingTargetAST(node_copy,node_original,targetFile, false);
18830#endif
18831#endif
18832 }
18833
18834
18835void
18837 SgStatement *toInsert, SgStatement* original_before_copy)
18838 {
18839 // The semantics of the copy is that it will have been disconnected from the snippet AST in a few ways,
18840 // Namely the root of the copy of the snippet's AST will have been set with a NULL parent, and then
18841 // the parent would have been reset when the copy of the snippet was inserted into the target AST.
18842 // So a simple traversal of parents back to the SgFile will return the target AST's SgFile (confirmed below).
18843
18844 ROSE_ASSERT(insertionPoint != NULL);
18845 ROSE_ASSERT(toInsert != NULL);
18846 ROSE_ASSERT(original_before_copy != NULL);
18847
18848 // DQ (3/30/2014): Turn this on to support finding symbols in base classes (in Java).
18849 // Will be turned off at the base of this function (since we only only want to use it for the AST fixup, currently).
18850 SgSymbolTable::set_force_search_of_base_classes(true);
18851
18852 // DQ (3/4/2014): Switch to using the SageInterface function.
18853 // SgFile* targetFile = TransformationSupport::getFile(insertionPoint);
18854 SgFile* targetFile = getEnclosingFileNode(insertionPoint);
18855
18856 // For Java support this might be NULL, if the insertion point was in global scope.
18857 ROSE_ASSERT(targetFile != NULL);
18858
18859 // SgFile* snippetFile_of_copy = TransformationSupport::getFile(toInsert);
18860 SgFile* snippetFile_of_copy = getEnclosingFileNode(toInsert);
18861
18862 // At this point the parent pointers are set so that the same SgFile is found via a traversal back to the SgProject.
18863 // Confirm that the SgFile found by a traversal of parents in the copy of rthe snippet's AST will return that of the
18864 // SgFile for the target AST. This also confirms that the copy of the snippet has already been inserted into the
18865 // target AST.
18866 ROSE_ASSERT(snippetFile_of_copy == targetFile);
18867
18868 // SgFile* snippetFile_of_original = TransformationSupport::getFile(original_before_copy);
18869 SgFile* snippetFile_of_original = getEnclosingFileNode(original_before_copy);
18870
18871 ROSE_ASSERT(snippetFile_of_original != targetFile);
18872
18873#if 0
18874 printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18875 printf (" --- snippetFile_of_copy = %p = %s \n",snippetFile_of_copy,snippetFile_of_copy->get_sourceFileNameWithPath().c_str());
18876 printf (" --- snippetFile_of_original = %p = %s \n",snippetFile_of_original,snippetFile_of_original->get_sourceFileNameWithPath().c_str());
18877#endif
18878
18879 // Any node that has entries not referenced in the target file needs to be fixed up.
18880 // We can assume that any referenced variable or function that is referenced in the
18881 // snippet will exist in either the snippet or the target file.
18882
18883 // DQ (3/4/2014): This is a test of the structural equality of the original snippet and it's copy.
18884 // If they are different then we can't support fixing up the AST. Transformations on the snippet
18885 // should have been made after insertion into the AST. The complexity of this test is a traversal
18886 // of the copy of the snippet to be inserted (typically very small compared to the target application).
18887 bool isStructurallyEquivalent = isStructurallyEquivalentAST(toInsert,original_before_copy);
18888 if (isStructurallyEquivalent == false)
18889 {
18890 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");
18891 return;
18892 }
18893 ROSE_ASSERT(isStructurallyEquivalent == true);
18894
18895#ifndef USE_CMAKEx
18896 // DQ (3/8/2014): Make this conditionally compiled based on when CMake is not used because the libraries are not configured yet.
18897
18898 // This is AST container for the ROSE AST that will provide an iterator.
18899 // We want two iterators (one for the copy of the snippet and one for the
18900 // original snippet so that we can query the original snippet's AST
18901 // as we process each IR node of the AST for the copy of the snippet.
18902 // Only the copy of the snippet is inserted into the target AST.
18903 RoseAst ast_of_copy(toInsert);
18904 RoseAst ast_of_original(original_before_copy);
18905
18906 // printf ("ast_of_copy.size() = %" PRIuPTR " \n",ast_of_copy.size());
18907
18908 // Build the iterators so that we can increment thorugh both ASTs one IR node at a time.
18909 RoseAst::iterator i_copy = ast_of_copy.begin();
18910 RoseAst::iterator i_original = ast_of_original.begin();
18911
18912 // Iterate of the copy of the snippet's AST.
18913 while (i_copy != ast_of_copy.end())
18914 {
18915 // DQ (2/28/2014): This is a problem for some of the test codes (TEST store/load heap string [test7a] and [test7a])
18916 // ROSE_ASSERT((*i_copy)->variantT() == (*i_original)->variantT());
18917 if ((*i_copy)->variantT() != (*i_original)->variantT())
18918 {
18919 printf ("ERROR: return from fixupCopyOfAstFromSeparateFileInNewTargetAst(): "
18920 "(*i_copy)->variantT() != (*i_original)->variantT() \n");
18921#if 1
18922 printf ("Making this an error! \n");
18923 ROSE_ABORT();
18924#endif
18925 return;
18926 }
18927
18928 // Operate on individual IR nodes.
18929 fixupCopyOfNodeFromSeparateFileInNewTargetAst(insertionPoint, insertionPointIsScope, *i_copy, *i_original);
18930
18931 i_copy++;
18932
18933 // Verify that we have not reached the end of the ast for the original (both the
18934 // copy and the original are the same structurally, and thus the same size).
18935 ROSE_ASSERT(i_original != ast_of_original.end());
18936 i_original++;
18937 }
18938
18939 // We have reached the end of both ASTs.
18940 ROSE_ASSERT(i_copy == ast_of_copy.end() && i_original == ast_of_original.end());
18941
18942 // DQ (3/8/2014): ENDIF: Make this conditionally compiled based on when CMake is not used because the libraries are not configured yet.
18943#endif
18944
18945#if 0
18946 if (functionDeclaration != NULL)
18947 {
18948 printf ("functionDeclaration = %s \n",functionDeclaration->get_name().str());
18949#if 0
18950 printf ("Exiting as a test! \n");
18951 ROSE_ABORT();
18952#endif
18953 }
18954#endif
18955
18956 // DQ (3/30/2014): Turn this off (since we only only want to use it for the AST fixup, currently).
18957 SgSymbolTable::set_force_search_of_base_classes(false);
18958 }
18959
18960// Liao 9/18/2015
18961// The parser is implemented in
18962// src/frontend/SageIII/astFromString/AstFromString.h .C
18964{
18965
18966 SgStatement* result = NULL;
18967 ROSE_ASSERT (scope != NULL);
18968 // set input and context for the parser
18969 AstFromString::c_char = s.c_str();
18970 ROSE_ASSERT(AstFromString::c_char== s.c_str());
18973
18975 {
18976 result = isSgStatement(AstFromString::c_parsed_node); // grab the result
18977 ROSE_ASSERT(result != NULL);
18978 }
18979 else
18980 {
18981 cerr<<"Error. buildStatementFromString() cannot parse the input string:"<<s
18982 <<"\n\t within the given scope:"<<scope->class_name() <<endl;
18983 ROSE_ABORT();
18984 }
18985 return result;
18986}
18987
18997
18998//
18999// pp (07/16/16)
19000// initial support for creating template instantiations
19001// from template declarations
19002
19003namespace {
19004 // internal functions
19005
19006 template <class SgAstNode>
19007 SgTemplateArgument* createTemplateArg_(SgAstNode& n)
19008 {
19009 static const bool explicitlySpecified = true;
19010
19011 return new SgTemplateArgument(&n, explicitlySpecified);
19012 }
19013
19014 SgTemplateArgument* createTemplateArg_(SgExpression& n)
19015 {
19016 SgTemplateArgument* res = createTemplateArg_<SgExpression>(n);
19017
19018 n.set_parent(res);
19019 return res;
19020 }
19021
19022 SgTemplateArgument* createTemplateArg(SgNode& n)
19023 {
19024 SgTemplateArgument* res = NULL;
19025
19026 if (isSgType(&n))
19027 res = createTemplateArg_(*isSgType(&n));
19028 else if (isSgExpression(&n))
19029 res = createTemplateArg_(*isSgExpression(&n));
19030 else
19031 {
19032 ROSE_ASSERT(isSgTemplateDeclaration(&n));
19033 res = createTemplateArg_(*isSgTemplateDeclaration(&n));
19034 }
19035
19036 ROSE_ASSERT(res);
19037 return res;
19038 }
19039#if 0
19040 SgName genTemplateName(SgName base, Rose_STL_Container<SgNode*>& targs)
19041 {
19042 Rose_STL_Container<SgNode*>::iterator aa = targs.begin();
19043 Rose_STL_Container<SgNode*>::iterator zz = targs.begin();
19044 std::string name(base.getString());
19045
19046 name.append("<");
19047 for ( ; aa != zz; ++aa) name.append((*aa)->unparseToString());
19048 name.append(">");
19049
19050 return SgName(name);
19051 }
19052#endif
19053 SgTemplateArgumentPtrList genTemplateArgumentList(Rose_STL_Container<SgNode*>& targs)
19054 {
19055 Rose_STL_Container<SgNode*>::iterator aa = targs.begin();
19056 Rose_STL_Container<SgNode*>::iterator zz = targs.begin();
19057 SgTemplateArgumentPtrList lst;
19058
19059 for ( ; aa != zz; ++aa)
19060 {
19061 lst.push_back(createTemplateArg(**aa));
19062 }
19063
19064 return lst;
19065 }
19066
19067 SgTemplateClassDeclaration* getCanonicalTemplateDecl(SgTemplateClassDeclaration* main_decl)
19068 {
19069 ROSE_ASSERT(main_decl);
19070 SgClassType* ct = main_decl->get_type();
19071 ROSE_ASSERT(ct);
19072 SgDeclarationStatement* decl = ct->get_declaration();
19073 SgTemplateClassDeclaration* tdecl = isSgTemplateClassDeclaration(decl);
19074
19075 ROSE_ASSERT(tdecl);
19076 return tdecl;
19077 }
19078
19079 SgTemplateInstantiationDecl* genTemplateInstantiationDecl(SgName tname, SgTemplateClassDeclaration* tclassdecl, SgTemplateArgumentPtrList targs)
19080 {
19081 ROSE_ASSERT(tclassdecl);
19082
19083 SgTemplateInstantiationDecl* res = NULL;
19084
19085 res = new SgTemplateInstantiationDecl( tname,
19087 NULL /* SgClassType* type -- to be set later */,
19088 NULL /* SgClassDefinition* def -- to be set later */,
19089 tclassdecl,
19090 targs
19091 );
19092
19093 res->set_scope(tclassdecl->get_scope());
19094 res->set_templateName(tname); // \todo \pp create mangled name from tname
19096 res->setForward(); // \pp set forward, since this is not a proper declaration
19097 return res;
19098 }
19099
19100 SgClassType* genTemplateClass(SgTemplateInstantiationDecl* tdecl)
19101 {
19102 ROSE_ASSERT(tdecl);
19103
19104 return SgClassType::createType(tdecl);
19105 }
19106
19107 struct TemplateArgumentParentSetter
19108 {
19110
19111 TemplateArgumentParentSetter(SgTemplateInstantiationDecl* p)
19112 : parent(p)
19113 {}
19114
19115 void operator()(SgTemplateArgument* targ)
19116 {
19117 targ->set_parent(parent);
19118 }
19119 };
19120} /* anonymous namespace */
19121
19122
19125Rose_STL_Container<SgNode *>& template_args)
19126{
19127 return buildClassTemplateType (template_decl,template_args);
19128}
19129
19132Rose_STL_Container<SgNode *>& template_args)
19133{
19134 ROSE_ASSERT(template_decl);
19135
19136 // create a template instantiation decl
19137 SgName name = template_decl->get_name();
19138 // SgName tname = genTemplateName(, template_args);
19139 SgTemplateArgumentPtrList targs = genTemplateArgumentList(template_args);
19140 SgTemplateClassDeclaration* tdecl = getCanonicalTemplateDecl(template_decl);
19141 SgTemplateInstantiationDecl* tinst = genTemplateInstantiationDecl(name, tdecl, targs);
19142 ROSE_ASSERT(tinst);
19143
19144 // create class type
19145 SgClassType* tclass = genTemplateClass(tinst);
19146 ROSE_ASSERT(tclass);
19147
19148 // set remaining fields in the template instantiation decl
19149 tinst->set_type(tclass);
19150 tinst->set_definition(static_cast<SgTemplateInstantiationDefn*>(0)); /* \pp not sure what to set this to .. */
19151
19152 // set parent of template arguments
19153 std::for_each(targs.begin(), targs.end(), TemplateArgumentParentSetter(tinst)); //
19154
19155 return tclass;
19156}
19157
19158//-----------------------------------------------------------------------------
19159#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
19160//-----------------------------------------------------------------------------
19161
19166 ROSE_ASSERT(Rose::Frontend::Java::lengthSymbol);
19167 SgVarRefExp *var_ref = SageBuilder::buildVarRefExp(Rose::Frontend::Java::lengthSymbol);
19169 return var_ref;
19170}
19171
19176 SgScopeStatement *scope = new SgScopeStatement();
19178 if (parent_scope != NULL) {
19179 scope -> set_parent(parent_scope);
19180 }
19181 return scope;
19182}
19183
19190 return expr;
19191}
19192
19197 SgJavaMarkerAnnotation *annotation = new SgJavaMarkerAnnotation(type);
19199 return annotation;
19200}
19201
19208 pair -> set_name(name);
19209 pair -> set_value(value);
19210 value -> set_parent(pair);
19211 return pair;
19212}
19213
19218 SgJavaSingleMemberAnnotation *annotation = new SgJavaSingleMemberAnnotation(type, value);
19220 return annotation;
19221}
19222
19227 SgJavaNormalAnnotation *annotation = new SgJavaNormalAnnotation(type);
19229 return annotation;
19230}
19231
19235SgJavaNormalAnnotation *SageBuilder::buildJavaNormalAnnotation(SgType *type, list<SgJavaMemberValuePair *>& pair_list) {
19237 for (std::list<SgJavaMemberValuePair *>::iterator i = pair_list.begin(); i != pair_list.end(); i++) {
19238 SgJavaMemberValuePair *member_value_pair = *i;
19239 member_value_pair -> set_parent(annotation);
19240 annotation -> append_value_pair(member_value_pair);
19241 }
19242 return annotation;
19243}
19244
19245
19249SgInitializedName *SageBuilder::buildJavaFormalParameter(SgType *argument_type, const SgName &argument_name, bool is_var_args, bool is_final) {
19250 SgInitializedName *initialized_name = NULL;
19251 if (is_var_args) {
19252 initialized_name = SageBuilder::buildInitializedName(argument_name, SageBuilder::getUniqueJavaArrayType(argument_type, 1), NULL);
19253 initialized_name -> setAttribute("var_args", new AstRegExAttribute(""));
19254 }
19255 else {
19256 initialized_name = SageBuilder::buildInitializedName(argument_name, argument_type, NULL);
19257 }
19258 SageInterface::setSourcePosition(initialized_name);
19259 if (is_final) {
19260 initialized_name -> setAttribute("final", new AstRegExAttribute(""));
19261 }
19262
19263 return initialized_name;
19264}
19265
19270 SgJavaPackageStatement *package_statement = new SgJavaPackageStatement(package_name);
19271 SageInterface::setSourcePosition(package_statement);
19272 package_statement -> set_firstNondefiningDeclaration(package_statement);
19273 package_statement -> set_definingDeclaration(package_statement);
19274 return package_statement;
19275}
19276
19280SgJavaImportStatement *SageBuilder::buildJavaImportStatement(string import_info, bool contains_wildcard) {
19281 SgJavaImportStatement *import_statement = new SgJavaImportStatement(import_info, contains_wildcard);
19282 SageInterface::setSourcePosition(import_statement);
19283 import_statement -> set_firstNondefiningDeclaration(import_statement);
19284 import_statement -> set_definingDeclaration(import_statement);
19285 return import_statement;
19286}
19287
19292 ROSE_ASSERT(scope);
19293 SgName class_name = name;
19294 ROSE_ASSERT(scope -> lookup_class_symbol(class_name) == NULL);
19295
19296 SgClassDeclaration* nonDefiningDecl = NULL;
19297 bool buildTemplateInstantiation = false;
19298 SgTemplateArgumentPtrList* templateArgumentsList = NULL;
19299 SgClassDeclaration *class_declaration = SageBuilder::buildClassDeclaration_nfi(class_name, kind, scope, nonDefiningDecl, buildTemplateInstantiation, templateArgumentsList);
19300 ROSE_ASSERT(class_declaration);
19301 class_declaration -> set_parent(scope);
19302 class_declaration -> set_scope(scope);
19303 SageInterface::setSourcePosition(class_declaration);
19304 SgClassDefinition *class_definition = class_declaration -> get_definition();
19305 ROSE_ASSERT(class_definition);
19306 SageInterface::setSourcePosition(class_definition);
19307
19308 class_definition -> setAttribute("extensions", new AstSgNodeListAttribute());
19309 class_definition -> setAttribute("extension_type_names", new AstRegExAttribute());
19310
19311 SgScopeStatement *type_space = new SgScopeStatement();
19312 type_space -> set_parent(class_definition);
19314 class_declaration -> setAttribute("type_space", new AstSgNodeAttribute(type_space));
19315
19316 return class_declaration;
19317}
19318
19319
19324SgSourceFile *SageBuilder::buildJavaSourceFile(SgProject *project, string directory_name, SgClassDefinition *package_definition, string type_name) {
19325 string filename = directory_name + "/" + type_name + ".java";
19326 ROSE_ASSERT((*project)[filename] == NULL); // does not already exist!
19327
19328 string command = string("touch ") + filename; // create the file
19329 int status = system(command.c_str());
19330 ROSE_ASSERT(status == 0);
19331 project -> get_sourceFileNameList().push_back(filename);
19332 Rose_STL_Container<std::string> arg_list = project -> get_originalCommandLineArgumentList();
19333 arg_list.push_back(filename);
19334 Rose_STL_Container<string> fileList = CommandlineProcessing::generateSourceFilenames(arg_list, // binaryMode
19335 false);
19336 CommandlineProcessing::removeAllFileNamesExcept(arg_list, fileList, filename);
19337 int error_code = 0;
19338 SgFile *file = determineFileType(arg_list, error_code, project);
19339 SgSourceFile *sourcefile = isSgSourceFile(file);
19340 ROSE_ASSERT(sourcefile);
19341 sourcefile -> set_parent(project);
19342 project -> get_fileList_ptr() -> get_listOfFiles().push_back(sourcefile);
19343 ROSE_ASSERT(sourcefile == isSgSourceFile((*project)[filename]));
19344
19345 //
19346 // Create a package statement and add it to the source file
19347 //
19348 SgClassDeclaration* pkgDefDecl = package_definition->get_declaration();
19349 ROSE_ASSERT(pkgDefDecl != NULL);
19350 SgJavaPackageStatement *package_statement = SageBuilder::buildJavaPackageStatement(pkgDefDecl->get_qualified_name().getString());
19351 package_statement->set_parent(package_definition);
19352 sourcefile->set_package(package_statement);
19353
19354 //
19355 // Initialize an import-list for the sourcefile
19356 //
19357 SgJavaImportStatementList *import_statement_list = new SgJavaImportStatementList();
19358 import_statement_list -> set_parent(sourcefile);
19359 sourcefile -> set_import_list(import_statement_list);
19360
19361 //
19362 // Initialize a class-declaration-list for the sourcefile
19363 //
19364 SgJavaClassDeclarationList *class_declaration_list = new SgJavaClassDeclarationList();
19365 class_declaration_list -> set_parent(package_definition);
19366 sourcefile -> set_class_list(class_declaration_list);
19367
19368 return sourcefile;
19369}
19370
19371
19375SgArrayType *SageBuilder::getUniqueJavaArrayType(SgType *base_type, int num_dimensions) {
19376 ROSE_ASSERT(num_dimensions > 0);
19377 if (num_dimensions > 1) {
19378 base_type = getUniqueJavaArrayType(base_type, num_dimensions - 1);
19379 }
19380
19381 ROSE_ASSERT(base_type != NULL);
19382 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) base_type -> getAttribute("array");
19383 if (attribute == NULL) {
19384 SgArrayType *array_type = SageBuilder::buildArrayType(base_type);
19385 array_type -> set_rank(num_dimensions);
19386 attribute = new AstSgNodeAttribute(array_type);
19387 base_type -> setAttribute("array", attribute);
19388 }
19389
19390 return isSgArrayType(attribute -> getNode());
19391}
19392
19393
19397SgJavaParameterizedType *SageBuilder::getUniqueJavaParameterizedType(SgNamedType *generic_type, SgTemplateParameterPtrList *new_args) {
19398 AstParameterizedTypeAttribute *attribute = (AstParameterizedTypeAttribute *) generic_type -> getAttribute("parameterized types");
19399 if (! attribute) {
19400 attribute = new AstParameterizedTypeAttribute(generic_type);
19401 generic_type -> setAttribute("parameterized types", attribute);
19402 }
19403 ROSE_ASSERT(attribute);
19404
19405 return attribute -> findOrInsertParameterizedType(new_args);
19406}
19407
19408
19413 AstSgNodeListAttribute *attribute = (AstSgNodeListAttribute *) type -> getAttribute("qualified types");
19414 if (! attribute) {
19415 attribute = new AstSgNodeListAttribute();
19416 type -> setAttribute("qualified types", attribute);
19417 }
19418 ROSE_ASSERT(attribute);
19419
19420 for (int i = 0; i < attribute -> size(); i++) {
19421 SgJavaQualifiedType *qualified_type = isSgJavaQualifiedType(attribute -> getNode(i));
19422 ROSE_ASSERT(qualified_type);
19423 if (qualified_type -> get_parent_type() == parent_type && qualified_type -> get_type() == type) {
19424 return qualified_type;
19425 }
19426 }
19427
19428 SgJavaQualifiedType *qualified_type = new SgJavaQualifiedType(class_declaration);
19429 qualified_type -> set_parent_type(parent_type);
19430 qualified_type -> set_type(type);
19431
19432 attribute -> addNode(qualified_type);
19433
19434 return qualified_type;
19435}
19436
19437
19443 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) Rose::Frontend::Java::ObjectClassType -> getAttribute("unbound");
19444 if (! attribute) {
19445 SgClassDeclaration *class_declaration = isSgClassDeclaration(Rose::Frontend::Java::ObjectClassType -> get_declaration());
19446 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration());
19447 attribute = new AstSgNodeAttribute(wildcard);
19448 Rose::Frontend::Java::ObjectClassType -> setAttribute("unbound", attribute);
19449 }
19450
19451 return isSgJavaWildcardType(attribute -> getNode());
19452}
19453
19454
19459 ROSE_ASSERT(type);
19460 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) type -> getAttribute("extends");
19461 if (! attribute) {
19462 SgArrayType *array_type = isSgArrayType(type);
19463 SgNamedType *named_type = isSgNamedType(type);
19464 ROSE_ASSERT(array_type || named_type);
19465 SgClassDeclaration *class_declaration = isSgClassDeclaration((array_type ? (SgNamedType *) Rose::Frontend::Java::ObjectClassType : named_type) -> get_declaration());
19466 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration(), type);
19467
19468 wildcard -> set_has_extends(true);
19469
19470 attribute = new AstSgNodeAttribute(wildcard);
19471 type -> setAttribute("extends", attribute);
19472 }
19473
19474 return isSgJavaWildcardType(attribute -> getNode());
19475}
19476
19477
19482 ROSE_ASSERT(type);
19483 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) type -> getAttribute("super");
19484 if (! attribute) {
19485 SgArrayType *array_type = isSgArrayType(type);
19486 SgNamedType *named_type = isSgNamedType(type);
19487 ROSE_ASSERT(array_type || named_type);
19488 SgClassDeclaration *class_declaration = isSgClassDeclaration((array_type ? (SgNamedType *) Rose::Frontend::Java::ObjectClassType : named_type) -> get_declaration());
19489 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration(), type);
19490
19491 wildcard -> set_has_super(true);
19492
19493 attribute = new AstSgNodeAttribute(wildcard);
19494 type -> setAttribute("super", attribute);
19495 }
19496
19497 return isSgJavaWildcardType(attribute -> getNode());
19498}
19499
19500
19501//-----------------------------------------------------------------------------
19502#endif // ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
19503//-----------------------------------------------------------------------------
19504
19505
19506namespace Rose {
19507 namespace Builder {
19508 namespace Templates {
19509
19510SgTemplateArgument * buildTemplateArgument(SgType * t) {
19511 if (t == nullptr) return nullptr;
19512 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::type_argument, false, t, nullptr, nullptr);
19513 return r;
19514}
19515
19516SgTemplateArgument * buildTemplateArgument(SgExpression * e) {
19517 if (e == nullptr) return nullptr;
19518 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
19519 e->set_parent(r);
19520 return r;
19521}
19522
19523SgTemplateArgument * buildTemplateArgument(int v) {
19525 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
19526 e->set_parent(r);
19527 return r;
19528}
19529
19530SgTemplateArgument * buildTemplateArgument(bool v) {
19532 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
19533 e->set_parent(r);
19534 return r;
19535}
19536
19537std::string strTemplateArgument(int v) {
19538 std::ostringstream oss;
19539 oss << v;
19540 return oss.str();
19541}
19542
19543std::string strTemplateArgument(bool v) {
19544 std::ostringstream oss;
19545 if (v) oss << "true";
19546 else oss << "false";
19547 return oss.str();
19548}
19549
19550std::string strTemplateArgument(SgNamedType * nt) {
19551 std::ostringstream oss;
19552 oss << nt->get_qualified_name().getString();
19553 return oss.str();
19554}
19555
19556std::string strTemplateArgument(SgType * t) {
19557 std::ostringstream oss;
19558 oss << t->unparseToString();
19559 return oss.str();
19560}
19561
19562std::string strTemplateArgument(SgExpression * e) {
19563 std::ostringstream oss;
19564 oss << e->unparseToString();
19565 return oss.str();
19566}
19567
19568#define DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps 0
19569
19570SgExpression * instantiateNonrealRefExps(
19571 SgExpression * expr,
19572 std::vector<std::vector<SgTemplateParameter *>> & tpl_params,
19573 std::vector<std::vector<SgTemplateArgument *>> & tpl_args
19574) {
19575#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19576 std::cout << "Rose::Builder::Templates::instantiateNonrealRefExps" << std::endl;
19577 std::cout << " expr = " << std::hex << expr << " : " << ( expr ? expr->class_name() : "" ) << std::endl;
19578 std::cout << " = " << ( expr ? expr->unparseToString() : "" ) << std::endl;
19579#endif
19580 if (!expr) {
19581 return nullptr;
19582 } else if (isSgNonrealRefExp(expr)) {
19583#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19584 std::cerr << "Error: In instantiateNonrealRefExps: case of a SgNonrealRefExp!!!" << std::endl;
19585#endif
19586 return nullptr;
19587 } else if (isSgVarRefExp(expr)) {
19588 SgVarRefExp * vref = (SgVarRefExp*)expr;
19589 SgInitializedName * iname = vref->get_symbol()->get_declaration();
19590 ROSE_ASSERT(iname);
19591#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19592 std::cout << " iname = " << std::hex << iname << " : " << ( iname ? iname->class_name() : "" ) << std::endl;
19593 std::cout << " iname->get_name() = " << iname->get_name() << std::endl;
19594 std::cout << " iname->get_initializer() = " << std::hex << iname->get_initializer() << " : " << ( iname->get_initializer() ? iname->get_initializer()->class_name() : "" ) << std::endl;
19595 std::cout << " iname->get_parent() = " << std::hex << iname->get_parent() << " : " << ( iname->get_parent() ? iname->get_parent()->class_name() : "" ) << std::endl;
19596#endif
19597
19598 unsigned depth = 0;
19599 unsigned pos = 0;
19600 for (auto tpl_params_: tpl_params) {
19601 pos = 0;
19602 for (auto tpl_param: tpl_params_) {
19603 if (tpl_param->get_initializedName()) {
19604#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19605 std::cout << " tpl_param->get_initializedName() = " << std::hex << tpl_param->get_initializedName() << std::endl;
19606 std::cout << " tpl_param->get_initializedName()->get_name() = " << tpl_param->get_initializedName()->get_name() << std::endl;
19607#endif
19608 if (tpl_param->get_initializedName()->get_name() == iname->get_name()) {
19609 iname = tpl_param->get_initializedName();
19610 break;
19611 }
19612 }
19613 pos++;
19614 }
19615 depth++;
19616 }
19617
19618 if (depth < tpl_args.size() && pos < tpl_args[depth].size()) {
19619 SgExpression * res = tpl_args[depth][pos]->get_expression();
19620 ROSE_ASSERT(res);
19621 return res;
19622 } else if (depth < tpl_params.size() && pos < tpl_params[depth].size()) {
19623 SgExpression * dft = tpl_params[depth][pos]->get_defaultExpressionParameter();
19624 ROSE_ASSERT(dft);
19625 dft = instantiateNonrealRefExps(dft, tpl_params, tpl_args);
19626 ROSE_ASSERT(dft);
19627 return dft;
19628 }
19629#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19630 std::cerr << "Error: In instantiateNonrealRefExps: this should not be reached!!!" << std::endl;
19631#endif
19632 return vref;
19633 } else if (isSgValueExp(expr)) {
19634 return expr;
19635 } else if (isSgConditionalExp(expr)) {
19636 SgConditionalExp * cond = (SgConditionalExp*)expr;
19637 cond->set_conditional_exp(instantiateNonrealRefExps(cond->get_conditional_exp(), tpl_params, tpl_args));
19638 cond->set_true_exp(instantiateNonrealRefExps(cond->get_true_exp(), tpl_params, tpl_args));
19639 cond->set_false_exp(instantiateNonrealRefExps(cond->get_false_exp(), tpl_params, tpl_args));
19640 return cond;
19641 } else if (isSgSizeOfOp(expr)) {
19642 SgSizeOfOp * szo = (SgSizeOfOp*)expr;
19643#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19644 std::cout << " szo->get_operand_expr() = " << std::hex << szo->get_operand_expr() << " : " << ( szo->get_operand_expr() ? szo->get_operand_expr()->class_name() : "" ) << std::endl;
19645 std::cout << " szo->get_operand_type() = " << std::hex << szo->get_operand_type() << " : " << ( szo->get_operand_type() ? szo->get_operand_type()->class_name() : "" ) << std::endl;
19646#endif
19647 SgExpression * eres = instantiateNonrealRefExps(szo->get_operand_expr(), tpl_params, tpl_args);
19648 ROSE_ASSERT(szo->get_operand_expr() == nullptr || eres != nullptr);
19649 szo->set_operand_expr(eres);
19650
19651 SgType * tres = instantiateNonrealTypes(szo->get_operand_type(), tpl_params, tpl_args);
19652 ROSE_ASSERT(szo->get_operand_type() == nullptr || tres != nullptr);
19653 szo->set_operand_type(tres);
19654
19655#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
19656 std::cout << " szo->get_operand_expr() = " << std::hex << szo->get_operand_expr() << " : " << ( szo->get_operand_expr() ? szo->get_operand_expr()->class_name() : "" ) << std::endl;
19657 std::cout << " szo->get_operand_type() = " << std::hex << szo->get_operand_type() << " : " << ( szo->get_operand_type() ? szo->get_operand_type()->class_name() : "" ) << std::endl;
19658#endif
19659 return szo;
19660 } else if (isSgCastExp(expr)) {
19661 SgCastExp * cast = (SgCastExp*)expr;
19662 auto operand = instantiateNonrealRefExps(cast->get_operand_i(), tpl_params, tpl_args);
19663 if (operand == nullptr) return nullptr;
19664 auto type = instantiateNonrealTypes(cast->get_type(), tpl_params, tpl_args);
19665 if (type == nullptr) return operand;
19666 cast->set_operand_i(operand);
19667 cast->set_type(type);
19668 return cast;
19669 } else if (isSgUnaryOp(expr)) {
19670 SgUnaryOp * uop = (SgUnaryOp*)expr;
19671 uop->set_operand_i(instantiateNonrealRefExps(uop->get_operand_i(), tpl_params, tpl_args));
19672 return uop;
19673 } else if (isSgBinaryOp(expr)) {
19674 SgBinaryOp * bop = (SgBinaryOp*)expr;
19675 bop->set_lhs_operand_i(instantiateNonrealRefExps(bop->get_lhs_operand_i(), tpl_params, tpl_args));
19676 bop->set_rhs_operand_i(instantiateNonrealRefExps(bop->get_rhs_operand_i(), tpl_params, tpl_args));
19677 return bop;
19678 } else {
19679 std::cerr << "!!! expr = " << std::hex << expr << " : " << ( expr ? expr->class_name() : "" ) << std::endl;
19680 ROSE_ABORT();
19681 }
19682}
19683
19684SgExpression * instantiateNonrealRefExps(
19685 SgExpression * expr,
19686 std::vector<SgTemplateParameter *> & tpl_params,
19687 std::vector<SgTemplateArgument *> & tpl_args
19688) {
19689 std::vector<std::vector<SgTemplateParameter *>> tpl_params_{tpl_params};
19690 std::vector<std::vector<SgTemplateArgument *>> tpl_args_{tpl_args};
19691 return instantiateNonrealRefExps(expr, tpl_params_, tpl_args_);
19692}
19693
19694#define DEBUG_Rose_Builder_Templates_instantiateNonrealTypes 0
19695
19696SgType * instantiateNonrealTypes(
19697 SgType * type,
19698 std::vector<std::vector<SgTemplateParameter *>> & tpl_params,
19699 std::vector<std::vector<SgTemplateArgument *>> & tpl_args
19700) {
19701#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19702 std::cout << "Rose::Builder::Templates::instantiateNonrealTypes" << std::endl;
19703 std::cout << " type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
19704 std::cout << " = " << ( type ? type->unparseToString() : "" ) << std::endl;
19705#endif
19706 if (!type) {
19707 return nullptr;
19708 } else if (isSgNonrealType(type)) {
19709 SgNonrealType * nrtype = (SgNonrealType*)type;
19710 SgNonrealDecl * nrdecl = isSgNonrealDecl(nrtype->get_declaration());
19711 ROSE_ASSERT(nrdecl != nullptr);
19712#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19713 std::cout << " nrdecl = " << std::hex << nrdecl << " : " << nrdecl->class_name() << std::endl;
19714 std::cout << " ->get_qualified_name() = " << nrdecl->get_qualified_name().getString() << std::endl;
19715// std::cout << " ->unparseToString() = " << nrdecl->unparseToString() << std::endl;
19716 std::cout << " ->get_tpl_args() = " << std::dec << nrdecl->get_tpl_args().size() << std::endl;
19717 std::cout << " ->get_tpl_params() = " << std::dec << nrdecl->get_tpl_params().size() << std::endl;
19718 std::cout << " ->get_is_class_member() = " << ( nrdecl->get_is_class_member() ? "true" : "false" ) << std::endl;
19719 std::cout << " ->get_is_template_param() = " << ( nrdecl->get_is_template_param() ? "true" : "false" ) << std::endl;
19720 std::cout << " ->get_is_template_template_param() = " << ( nrdecl->get_is_template_template_param() ? "true" : "false" ) << std::endl;
19721 std::cout << " ->get_is_nonreal_template() = " << ( nrdecl->get_is_nonreal_template() ? "true" : "false" ) << std::endl;
19722 std::cout << " ->get_is_nonreal_function() = " << ( nrdecl->get_is_nonreal_function() ? "true" : "false" ) << std::endl;
19723#endif
19724 SgDeclarationStatement * tpldecl = nrdecl->get_templateDeclaration();
19725 if (tpldecl != nullptr) {
19726#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19727 std::cout << " tpldecl = " << std::hex << tpldecl << " : " << tpldecl->class_name() << std::endl;
19728#endif
19729
19730 SgTemplateClassDeclaration * xtpldecl = isSgTemplateClassDeclaration(tpldecl);
19731 if (xtpldecl != nullptr) {
19732#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19733 std::cout << " xtpldecl->get_name() = " << xtpldecl->get_name() << std::endl;
19734#endif
19735 std::vector<SgTemplateArgument *> inst_tpl_args;
19736 for (SgTemplateArgument * tplarg: nrdecl->get_tpl_args()) {
19737#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19738 std::cout << " tplarg = " << std::hex << tplarg << " : " << ( tplarg ? tplarg->class_name() : "" ) << std::endl;
19739 std::cout << " ->get_argumentType() = " << tplarg->get_argumentType() << std::endl;
19740#endif
19741 switch (tplarg->get_argumentType()) {
19743#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19744 std::cout << " tplarg->get_type() = " << std::hex << tplarg->get_type() << " : " << ( tplarg->get_type() ? tplarg->get_type()->class_name() : "" ) << std::endl;
19745#endif
19746 auto inst_tplarg = instantiateNonrealTypes(tplarg->get_type(), tpl_params, tpl_args);
19747 if (inst_tplarg)
19748 inst_tpl_args.push_back(buildTemplateArgument(inst_tplarg));
19749 break;
19750 }
19752#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19753 std::cout << " tplarg->get_expression() = " << std::hex << tplarg->get_expression() << " : " << ( tplarg->get_expression() ? tplarg->get_expression()->class_name() : "" ) << std::endl;
19754 std::cout << " ->unparseToString() = " << tplarg->get_expression()->unparseToString() << std::endl;
19755#endif
19756 auto inst_tplarg = instantiateNonrealRefExps(SageInterface::copyExpression(tplarg->get_expression()), tpl_params, tpl_args);
19757#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19758 std::cout << " inst_tplarg = " << std::hex << inst_tplarg << " : " << ( inst_tplarg ? inst_tplarg->class_name() : "" ) << std::endl;
19759 std::cout << " inst_tplarg->unparseToString() = " << ( inst_tplarg ? inst_tplarg->unparseToString() : "" ) << std::endl;
19760#endif
19761 if (inst_tplarg)
19762 inst_tpl_args.push_back(buildTemplateArgument(inst_tplarg));
19763 break;
19764 }
19766#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19767 std::cout << " tplarg->get_templateDeclaration() = " << std::hex << tplarg->get_templateDeclaration() << " : " << ( tplarg->get_templateDeclaration() ? tplarg->get_templateDeclaration()->class_name() : "" ) << std::endl;
19768#endif
19769 ROSE_ABORT(); // TODO
19770 }
19772#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19773 std::cout << " start_of_pack_expansion_argument" << std::endl;
19774#endif
19775 break; // NOP
19776 }
19777 default: ROSE_ABORT();
19778 }
19779 }
19780 SgTemplateInstantiationDecl * inst_decl = isSgTemplateInstantiationDecl(SageBuilder::buildClassDeclaration_nfi(
19781 xtpldecl->get_name(), SgClassDeclaration::e_struct, xtpldecl->get_scope(), nullptr, true, &inst_tpl_args
19782 ));
19783 ROSE_ASSERT(inst_decl);
19784#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19785 std::cout << " inst_decl = " << std::hex << inst_decl << " : " << inst_decl->class_name() << std::endl;
19786 std::cout << " inst_decl->get_firstNondefiningDeclaration() = " << std::hex << inst_decl->get_firstNondefiningDeclaration() << std::endl;
19787 std::cout << " inst_decl->get_definingDeclaration() = " << std::hex << inst_decl->get_definingDeclaration() << std::endl;
19788#endif
19789 ROSE_ASSERT(inst_decl->get_definingDeclaration());
19790 ROSE_ASSERT(inst_decl->get_definingDeclaration() == inst_decl);
19791 inst_decl->set_templateDeclaration(xtpldecl);
19792 ((SgTemplateInstantiationDecl *)(inst_decl->get_firstNondefiningDeclaration()))->set_templateDeclaration(xtpldecl);
19793
19794 for (auto inst_tpl_arg: inst_tpl_args) {
19795 inst_tpl_arg->set_parent(inst_decl);
19796 }
19797
19798 xtpldecl->get_scope()->append_statement(inst_decl);
19799 return inst_decl->get_type();
19800 } else {
19801 ROSE_ABORT(); // TODO probably typedef
19802 }
19803 } else if (nrdecl->get_is_template_param()) {
19804 auto depth = nrdecl->get_template_parameter_depth();
19805 auto position = nrdecl->get_template_parameter_position();
19806#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19807 std::cout << " ->get_template_parameter_position() = " << std::dec << position << std::endl;
19808 std::cout << " ->get_template_parameter_depth() = " << std::dec << depth << std::endl;
19809#endif
19810 ROSE_ASSERT(depth > 0);
19811 ROSE_ASSERT(position > 0);
19812 if (depth <= tpl_args.size() && position <= tpl_args[depth-1].size()) {
19813 SgType * res = tpl_args[depth-1][position-1]->get_type();
19814#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19815 std::cout << " tpl_args[" << std::dec << depth-1 << "][" << std::dec << position-1 << "]->get_type() = " << std::dec << res << std::endl;
19816#endif
19817 return res;
19818 } else if (depth <= tpl_params.size() && position <= tpl_params[depth-1].size()) {
19819 SgType * dft_tpl_arg = tpl_params[depth-1][position-1]->get_defaultTypeParameter();
19820#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19821 std::cout << " tpl_params[" << std::dec << depth-1 << "][" << std::dec << position-1 << "]->get_type() = " << std::dec << dft_tpl_arg << std::endl;
19822#endif
19823 dft_tpl_arg = instantiateNonrealTypes(dft_tpl_arg, tpl_params, tpl_args);
19824#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19825 std::cout << " dft_tpl_arg = " << std::dec << dft_tpl_arg << std::endl;
19826#endif
19827 return dft_tpl_arg;
19828 } else {
19829 return nullptr;
19830 }
19831 } else if (nrdecl->get_is_class_member()) {
19832#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19833 std::cout << " Case of a non-real class member will return INT." << std::endl;
19834#endif
19835 // TODO case such as "template <unsigned depth=0> static constexpr typename range_at_depth_t<depth>::Base ub;"
19836 // -> retrieve parent type
19837 // -> instantiate parent type
19838 // -> lookup member(s) in original parent type
19839 // -> instantiate (matching) member inside instantiated parent type
19840
19842 } else {
19843 ROSE_ABORT();
19844 }
19845 } else if (isSgTypeVoid(type) || isSgTypeUnsignedLong(type) || isSgTypeInt(type) || isSgTypeLong(type) || isSgTypeUnsignedInt(type) || isSgTypedefType(type) || isSgClassType(type)) {
19846 return type;
19847 } else if (isSgModifierType(type)) {
19848 SgModifierType * mtype = (SgModifierType *)type;
19849 SgType * btype = mtype->get_base_type();
19850 ROSE_ASSERT(btype != nullptr);
19852 ROSE_ASSERT(rtype != nullptr);
19853 rtype->get_typeModifier() = mtype->get_typeModifier();
19854 return rtype;
19855 } else {
19856 std::cerr << "!!! type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
19857 ROSE_ABORT(); // TODO maybe pointer/reference
19858 }
19859 return nullptr;
19860}
19861
19862SgType * instantiateNonrealTypes(
19863 SgType * type,
19864 std::vector<SgTemplateParameter *> & tpl_params,
19865 std::vector<SgTemplateArgument *> & tpl_args
19866) {
19867 std::vector<std::vector<SgTemplateParameter *>> tpl_params_{tpl_params};
19868 std::vector<std::vector<SgTemplateArgument *>> tpl_args_{tpl_args};
19869 return instantiateNonrealTypes(type, tpl_params_, tpl_args_);
19870}
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.