ROSE 0.11.145.354
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 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(classDeclaration->get_definingDeclaration());
121 ASSERT_not_null(definingClassDeclaration);
122 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
123 ASSERT_not_null(classDefinition);
124
126 ASSERT_not_null(functionParameterList);
127
128 // Constructors are specified with type void internally, though the type name is not output.
129 SgType* return_type = SageBuilder::buildVoidType();
130 ASSERT_not_null(return_type);
131
132 SgExprListExp* decoratorList = nullptr;
133 bool buildTemplateInstantiation = false;
134
135 // These are zero for a constructor.
136 unsigned int functionConstVolatileFlags = 0;
137
138 SgTemplateArgumentPtrList templateArgumentsList;
139
140 SgMemberFunctionDeclaration* first_nondefining_declaration = buildNondefiningMemberFunctionDeclaration (className, return_type, functionParameterList,
141 classDefinition, decoratorList, functionConstVolatileFlags, buildTemplateInstantiation, &templateArgumentsList);
142 ASSERT_not_null(first_nondefining_declaration);
143
144 first_nondefining_declaration->get_specialFunctionModifier().setConstructor();
145 ROSE_ASSERT(first_nondefining_declaration->get_specialFunctionModifier().isConstructor() == true);
146
147 // DQ (11/10/2020): Need to make sure that the firstNondefiningDeclaration is being used (reset is needed).
148 if (first_nondefining_declaration->get_firstNondefiningDeclaration() != first_nondefining_declaration)
149 {
150 first_nondefining_declaration = isSgMemberFunctionDeclaration(first_nondefining_declaration->get_firstNondefiningDeclaration());
151 }
152 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
153
154 SgMemberFunctionDeclaration* memberFunctionDeclaration = SageBuilder::buildDefiningMemberFunctionDeclaration (className, return_type, functionParameterList,
155 classDefinition, decoratorList, buildTemplateInstantiation, functionConstVolatileFlags, first_nondefining_declaration, &templateArgumentsList);
156 ASSERT_not_null(memberFunctionDeclaration);
157
158 memberFunctionDeclaration->get_specialFunctionModifier().setConstructor();
159 ROSE_ASSERT(memberFunctionDeclaration->get_specialFunctionModifier().isConstructor() == true);
160
161 // We return the default constructor and the use should insert it, I think.
162 // classDefinition->prepend_statement(memberFunctionDeclaration);
163
164 // Mark the constructor as public.
165 memberFunctionDeclaration->get_declarationModifier().get_accessModifier().setPublic();
166
167 ROSE_ASSERT (memberFunctionDeclaration->get_declarationModifier().get_accessModifier().isPublic() == true);
168
169 return memberFunctionDeclaration;
170 }
171
178
180void
185
186string
188 {
189 // DQ (11/19/2012): This function is build to support debugging the value of the statically defined mode.
190
191 string s;
192 switch(scp)
193 {
194 case e_sourcePositionError: s = "e_sourcePositionError"; break;
195 case e_sourcePositionDefault: s = "e_sourcePositionDefault"; break;
196 case e_sourcePositionTransformation: s = "e_sourcePositionTransformation"; break;
197 case e_sourcePositionCompilerGenerated: s = "e_sourcePositionCompilerGenerated"; break;
198 case e_sourcePositionNullPointers: s = "e_sourcePositionNullPointers"; break;
199 case e_sourcePositionFrontendConstruction: s = "e_sourcePositionFrontendConstruction"; break;
200 case e_sourcePosition_last: s = "e_sourcePosition_last"; break;
201
202 default:
203 {
204 printf ("Error: default reached in SageBuilder::display(SourcePositionClassification & scp): scp = %d \n",scp);
205 ROSE_ABORT();
206 }
207
208 }
209
210 return s;
211 }
212
213
214// DQ (5/21/2013): Added function to support hidding the implementation in the SgScopeStatement API.
215// template <class T> SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function (const SgName & name, const SgType* func_type)
216template <class T>
218SgScopeStatement::find_symbol_by_type_of_function (const SgName & name, const SgType* func_type, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateArgumentsList)
219 {
220 // DQ (3/13/2012): This is to address the fact that there are 6 different types of functions in ROSE:
221 // 1) SgFunctionDeclaration
222 // 2) SgMemberFunctionDeclaration
223 // 3) SgTemplateFunctionDeclaration
224 // 4) SgTemplateMemberFunctionDeclaration
225 // 5) SgTemplateFunctionInstntiationDeclaration
226 // 6) SgTemplateMemberFunctionInstntiationDeclaration
227 // And 4 different types of function symbols:
228 // 1) SgFunctionSymbol
229 // 2) SgMemberFunctionSymbol
230 // 3) SgTemplateFunctionSymbol
231 // 4) SgTemplateMemberFunctionSymbol
232 // Note that both:
233 // SgTemplateFunctionInstntiationDeclaration
234 // SgTemplateMemberFunctionInstntiationDeclaration
235 // map to
236 // SgFunctionSymbol
237 // SgMemberFunctionSymbol
238 // respectively.
239
240 // Check if there is a function symbol of any kind, then narrow the selection.
241 SgFunctionSymbol* func_symbol = nullptr;
242
243 {
244 // Use the static variant as a selector.
245 switch((VariantT)T::static_variant)
246 {
247 case V_SgFunctionDeclaration:
248 case V_SgProcedureHeaderStatement:
249 case V_SgTemplateInstantiationFunctionDecl:
250 {
251 // DQ (8/11/2013): Verify that the template arguments are provided for the correct cases and not for the incorrect cases.
252 if ((VariantT)T::static_variant == V_SgTemplateInstantiationFunctionDecl)
253 {
254 ROSE_ASSERT(templateArgumentsList != NULL);
255 }
256 else
257 {
258 ROSE_ASSERT(templateArgumentsList == NULL);
259 }
260
261 // DQ (5/21/2013): Calling the SgScopeStatement API.
262 func_symbol = lookup_nontemplate_function_symbol(name,func_type,templateArgumentsList);
263 // DQ (5/22/2013): This function symbol should not be a SgTemplateFunctionSymbol (associated with a template function. It should be an instantiated template.
264 ROSE_ASSERT(isSgTemplateFunctionSymbol(func_symbol) == NULL);
265 break;
266 }
267
268 case V_SgMemberFunctionDeclaration:
269 case V_SgTemplateInstantiationMemberFunctionDecl:
270 {
271 // DQ (5/21/2013): there is no SgScopeStatement API that calls this function.
272 // DQ (8/11/2013): Verify that the template arguments are provided for the correct cases and not for the incorrect cases.
273 if ((VariantT)T::static_variant == V_SgTemplateInstantiationMemberFunctionDecl)
274 {
275 ROSE_ASSERT(templateArgumentsList != NULL);
276 }
277 else
278 {
279 ROSE_ASSERT(templateArgumentsList == NULL);
280 }
281 func_symbol = lookup_nontemplate_member_function_symbol(name,func_type,templateArgumentsList);
282 break;
283 }
284
285 case V_SgTemplateFunctionDeclaration:
286 {
287 // DQ (8/11/2013): I think this should fail in cases were we should be handing the templateArgumentsList
288 // to the lookup_template_function_symbol() function.
289 ROSE_ASSERT(templateArgumentsList == NULL);
290
291 // DQ (8/11/2013): I think this should always be non-null.
292 ROSE_ASSERT(templateParameterList != NULL);
293
294 // DQ (8/7/2013): Adding support to permit template function overloading on template parameters.
295 // Note that the template arguments are being handed in as templateSpecializationArgumentList since this is the matching list.
296 // However, we might expect template parameter.
297
298 // DQ (8/7/2013): Adding support for template function overloading using template parameters (info passed as template arguments for specialization).
299 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
300 // In this case these are unavailable from this point.
301 // DQ (5/21/2013): Calling the SgScopeStatement API.
302 func_symbol = lookup_template_function_symbol(name,func_type,templateParameterList);
303
304 break;
305 }
306
307 case V_SgTemplateMemberFunctionDeclaration:
308 {
309 // DQ (8/11/2013): I think this should fail in cases were we should be handing the templateArgumentsList
310 // to the lookup_template_member_function_symbol() function.
311 ROSE_ASSERT(templateArgumentsList == NULL);
312
313 // DQ (8/11/2013): I think this sould always be non-null.
314 ROSE_ASSERT(templateParameterList != NULL);
315
316 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
317 // In this case these are unavailable from this point.
318 // DQ (5/21/2013): Calling the SgScopeStatement API.
319 func_symbol = lookup_template_member_function_symbol(name,func_type,templateParameterList);
320 break;
321 }
322
323 default:
324 {
325 printf ("In SgScopeStatement::find_symbol_by_type_of_function(): default reached --- variantT(T::static_variant) = %d \n",T::static_variant);
326 ROSE_ABORT();
327 }
328 }
329 }
330 return func_symbol;
331 }
332
333
334// explicit instantiation of find_symbol_by_type_of_function
335template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgTemplateFunctionDeclaration>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
336template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgTemplateInstantiationMemberFunctionDecl>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
337template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgTemplateInstantiationFunctionDecl>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
338template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgMemberFunctionDeclaration>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
339template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgTemplateMemberFunctionDeclaration>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
340template SgFunctionSymbol* SgScopeStatement::find_symbol_by_type_of_function<SgFunctionDeclaration>(SgName const&, SgType const*, SgTemplateParameterPtrList*, SgTemplateArgumentPtrList*);
341
342void
344 {
345 ASSERT_not_null(stmt);
346 ScopeStack.push_back(stmt);
347 }
348
350 {
351 ASSERT_require(ScopeStack.empty() == false);
352 ScopeStack.pop_back();
353 }
354
356 {
357 // If this is an empty stack, return nullptr (ScopeStack.back() should be undefined for this case).
358 if (ScopeStack.empty()) {
359 return nullptr;
360 }
361
362 // DQ (9/28/2009): This is part of testing for GNU 4.0.x (other versions of g++ work fine).
363 SgScopeStatement* tempScope = ScopeStack.back();
364 if (tempScope) {
365 tempScope->class_name();
366 }
367
368 return tempScope;
369 }
370
371
374 {
375 // This function adds new support within the internal scope stack mechanism.
376
377 // DQ (3/20/2017): This branch is never taken and can be reported as an error (this improves code coverage).
378 // DQ (3/11/2012): Test if this is an empty stack, and if so return NULL (ScopeStack.back() should be undefined for this case).
379 ROSE_ASSERT(ScopeStack.empty() == false);
380
381 // The SgGlobal scope should be the first (front) element in the list (the current scope at the end (back) of the list).
382 SgScopeStatement* tempScope = ScopeStack.front();
383 ASSERT_not_null(isSgGlobal(tempScope));
384
385 return tempScope;
386 }
387
389 {
390 return ScopeStack.empty();
391 }
392
394 {
395 ScopeStack.clear();
396 }
397
399 {
400 // DQ (11/26/2012): This is used to turn off some pragma processing which is a problem in switch statements.
401 bool returnVar = false;
402 std::list<SgScopeStatement*>::iterator i;
403 for (i = ScopeStack.begin(); i != ScopeStack.end(); i++)
404 {
405 if (isSgSwitchStatement(*i) != nullptr)
406 returnVar = true;
407 }
408
409 return returnVar;
410 }
411
412// *******************************************************************************
413// ******************************* Build Functions *****************************
414// *******************************************************************************
415SgName
416SageBuilder::appendTemplateArgumentsToName( const SgName & name, const SgTemplateArgumentPtrList & templateArgumentsList)
417 {
418 // DQ (7/23/2012): This function is somewhat redundant with the SgDeclarationStatement::resetTemplateNameSupport() in that
419 // they both have to generate identical names. this was a problem and thus this code is seneitive to " ," instead of ","
420 // below.
421
422 // DQ (7/23/2012): This is one of three locations where the template arguments are assembled and where
423 // the name generated identically (in each case) is critical. Not clear how to best refactor this code.
424 // The other two are:
425 // Unparse_ExprStmt::unparseTemplateArgumentList()
426 // and in:
427 // void SgDeclarationStatement::resetTemplateNameSupport ( bool & nameResetFromMangledForm, SgName & name )
428 // It is less clear how to refactor this code.
429
430#define DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST 0
431
432#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST
433 printf ("In SageBuilder::appendTemplateArgumentsToName(): CRITICAL FUNCTION TO BE REFACTORED (name = %s) \n",name.str());
434#endif
435
436 // DQ (3/10/2018): This is now partially redundant with SgTemplateArgumentList::unparseToStringSupport().
437 SgUnparse_Info *info = new SgUnparse_Info();
438 ASSERT_not_null(info);
439
440 info->set_language(SgFile::e_Cxx_language);
441 info->set_requiresGlobalNameQualification();
442
443 // DQ (4/28/2017): For template arguments we never want to output the definitions of classes, and enums.
444 info->set_SkipClassDefinition();
445 info->set_SkipEnumDefinition();
446 info->set_use_generated_name_for_template_arguments(true);
447
448 bool emptyArgumentList = templateArgumentsList.empty();
449
450 // DQ (9/24/2012): Don't add "< >" if there are no template arguments (see test2012_221.C).
451 // SgName returnName = name + " < ";
452 SgName returnName = name;
453 if (emptyArgumentList == false)
454 returnName += " < ";
455
456 SgTemplateArgumentPtrList::const_iterator i = templateArgumentsList.begin();
457 bool need_separator = false;
458
459 bool exit_after_name_is_generated = false;
460
461 while (i != templateArgumentsList.end())
462 {
463 if ((*i)->get_argumentType() == SgTemplateArgument::start_of_pack_expansion_argument)
464 {
465 i++;
466 continue;
467 }
468
469 if (need_separator)
470 {
471 returnName += " , ";
472 }
473
474#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST
475 printf ("In SageBuilder::appendTemplateArgumentsToName(): (top of loop) templateArgumentsList element *i = %p = %s returnName = %s \n",*i,(*i)->class_name().c_str(),returnName.str());
476#endif
477
478 // DQ (2/5/2022): We need to use a fully qualified name as demonstrated by test2022_05.C.
479 // Where there are two different template arguments with the same name (e.g. in different
480 // namespaces) the generated names will be the same and the symbols will collide in the
481 // symbol table for the scope where they are both constructed.
482 // So a fix is to add the fully qualified name of the scope of the expression used as a template argument.
483
484 // DQ (2/6/2022): Newer version of code (still refactoring this section).
485 bool used_fully_qualified_name = false;
486
487#define DEBUG_TEMPLATE_ARGUMENT_NAMES 0
488
489 // DQ (2/6/2022): This is the newly refactored implementation to add name qualification to
490 // the template arguments in the used in symbol tables key for template instantiations.
491 SgTemplateArgument* templateArgument = *i;
492 ASSERT_not_null(templateArgument);
493
494 switch (templateArgument->get_argumentType())
495 {
497 {
498 SgType* type = templateArgument->get_type();
499 ASSERT_not_null(type);
500
501#if DEBUG_TEMPLATE_ARGUMENT_NAMES
502 printf ("In SageBuilder::appendTemplateArgumentsToName(): case SgTemplateArgument::type_argument: BEFORE stripType: type = %p = %s \n",type,type->class_name().c_str());
503#endif
504
505#if DEBUG_TEMPLATE_ARGUMENT_NAMES
506 printf ("In SageBuilder::appendTemplateArgumentsToName(): case SgTemplateArgument::type_argument: AFTER stripType: type = %p = %s \n",type,type->class_name().c_str());
507#endif
508 // DQ (2/6/2022): We need to find an example of the case where the template argument is a pointer type.
509 if (isSgPointerType(templateArgument->get_type()) != nullptr)
510 {
511
512#if DEBUG_TEMPLATE_ARGUMENT_NAMES
513 printf ("Found a templateArgument->get_type() that is SgPointerType: name = %s \n",name.str());
514#endif
515 }
516
517 SgNamedType* namedType = isSgNamedType(type);
518 if (namedType != nullptr)
519 {
520 // DQ (2/5/2022): Since SgNonrealType is a SgNamedType, is this sufficiant to handle those cases?
521 SgDeclarationStatement* declaration = namedType->get_declaration();
522 ASSERT_not_null(declaration);
523
524 switch (declaration->variantT())
525 {
526 case V_SgTemplateInstantiationDecl:
527 case V_SgTemplateClassDeclaration:
528 case V_SgClassDeclaration:
529 {
530 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
531 string fully_qualified_name = classDeclaration->get_qualified_name();
532#if DEBUG_TEMPLATE_ARGUMENT_NAMES
533 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
534#endif
535 returnName += fully_qualified_name;
536 used_fully_qualified_name = true;
537 break;
538 }
539
540 case V_SgTemplateInstantiationTypedefDeclaration:
541 case V_SgTemplateTypedefDeclaration:
542 case V_SgTypedefDeclaration:
543 {
544 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(declaration);
545 string fully_qualified_name = typedefDeclaration->get_qualified_name();
546#if DEBUG_TEMPLATE_ARGUMENT_NAMES
547 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
548#endif
549 returnName += fully_qualified_name;
550 used_fully_qualified_name = true;
551 break;
552 }
553
554 case V_SgEnumDeclaration:
555 {
556 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(declaration);
557 string fully_qualified_name = enumDeclaration->get_qualified_name();
558#if DEBUG_TEMPLATE_ARGUMENT_NAMES
559 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
560#endif
561 returnName += fully_qualified_name;
562 used_fully_qualified_name = true;
563 break;
564 }
565
566 // DQ (2/5/2022): Is this implementation correct for SgNonrealDecl?
567 case V_SgNonrealDecl:
568 {
569 SgNonrealDecl* nonrealDeclaration = isSgNonrealDecl(declaration);
570 string fully_qualified_name = nonrealDeclaration->get_qualified_name();
571#if DEBUG_TEMPLATE_ARGUMENT_NAMES
572 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
573#endif
574 returnName += fully_qualified_name;
575 used_fully_qualified_name = true;
576 break;
577 }
578
579 default:
580 {
581 // I'm not clear if we need to support any other cases, so this default case is an error.
582 printf ("In SageBuilder::appendTemplateArgumentsToName(): default reached: get_type() != NULL: declaration = %s \n",declaration->class_name().c_str());
583 ROSE_ASSERT(false);
584 }
585 }
586 }
587 else
588 {
589#if DEBUG_TEMPLATE_ARGUMENT_NAMES
590 printf ("In SageBuilder::appendTemplateArgumentsToName(): not a SgNamedType: get_type() != NULL: type = %s \n",type->class_name().c_str());
591#endif
592 }
593
594 break;
595 }
596
598 {
599 // DQ (8/12/2013): This can be either an SgExpression or SgInitializedName.
600 ROSE_ASSERT (templateArgument->get_expression() != NULL || templateArgument->get_initializedName() != NULL);
601 ROSE_ASSERT (templateArgument->get_expression() == NULL || templateArgument->get_initializedName() == NULL);
602 if (templateArgument->get_expression() != NULL)
603 {
604 SgExpression* expression = templateArgument->get_expression();
605 ASSERT_not_null(expression);
606
607 // Now we care about types of expression that could require name qualification.
608 // Is there anything more than SgVarRefExp that we need to worry about?
609 SgVarRefExp* varRefExp = isSgVarRefExp(expression);
610 if (varRefExp != NULL)
611 {
612 // SgVariableSymbol* variableSymbol = isSgVariableSymbol(varRefExp->get_symbol());
613 SgVariableSymbol* variableSymbol = varRefExp->get_symbol();
614 ROSE_ASSERT(variableSymbol != NULL);
615 SgInitializedName* initializedName = variableSymbol->get_declaration();
616 ROSE_ASSERT(initializedName != NULL);
617 string fully_qualified_name = initializedName->get_qualified_name();
618#if DEBUG_TEMPLATE_ARGUMENT_NAMES
619 printf ("fully_qualified_name = %s \n",fully_qualified_name.c_str());
620#endif
621 returnName += fully_qualified_name;
622 used_fully_qualified_name = true;
623 }
624 else
625 {
626 // Unclear if we have cases here to support (need more examples of different types of template arguments in use).
627#if DEBUG_TEMPLATE_ARGUMENT_NAMES
628 printf ("In SageBuilder::appendTemplateArgumentsToName(): Case of template argument varRefExp == NULL: expression = %p = %s \n",
629 expression,expression->class_name().c_str());
630#endif
631 }
632 }
633 else
634 {
635 SgInitializedName* initializedName = templateArgument->get_initializedName();
636 ROSE_ASSERT(initializedName != NULL);
637 printf ("initializedName = %p = %s \n",initializedName,initializedName->get_name().str());
638
639 printf ("In SageBuilder::appendTemplateArgumentsToName(): Case of template argument initializedName != NULL: Unclear what do do in this case \n");
640 ROSE_ASSERT(false);
641 }
642
643 break;
644 }
645
647 {
648 SgDeclarationStatement* decl = templateArgument->get_templateDeclaration();
649 ASSERT_not_null(decl);
650#if DEBUG_TEMPLATE_ARGUMENT_NAMES
651 printf ("In SageBuilder::appendTemplateArgumentsToName(): case SgTemplateArgument::template_template_argument: decl = %p = %s \n",decl,decl->class_name().c_str());
652#endif
653 exit_after_name_is_generated = true;
654 SgTemplateDeclaration* tpl_decl = isSgTemplateDeclaration(decl);
655 ROSE_ASSERT(tpl_decl == NULL);
656
657 break;
658 }
659
661 {
662#if DEBUG_TEMPLATE_ARGUMENT_NAMES
663 printf("WARNING: start_of_pack_expansion_argument in evaluateNameQualificationForTemplateArgumentList (can happen from some debug output)\n");
664#endif
665 break;
666 }
667
669 {
670 // mfprintf(mlog [ WARN ] ) ("Error argument_undefined in evaluateNameQualificationForTemplateArgumentList \n");
671 printf("Error argument_undefined in evaluateNameQualificationForTemplateArgumentList \n");
672 ROSE_ABORT();
673 break;
674 }
675
676 default:
677 {
678 // mfprintf(mlog [ WARN ] ) ("Error default reached in evaluateNameQualificationForTemplateArgumentList \n");
679 printf("Error default reached in evaluateNameQualificationForTemplateArgumentList \n");
680 ROSE_ABORT();
681 }
682 }
683
684 // DQ (2/5/2022): if it is not set above then use the old way without name qualification (debugging test2022_05.C).
685 // 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).
686 // Calling the unparseToString (SgUnparse_Info *info) function instead of the version not taking an argument.
687 // returnName += (*i)->unparseToString(info);
688 if (used_fully_qualified_name == false)
689 {
690 returnName += (*i)->unparseToString(info);
691 }
692
693#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST
694 printf ("In SageBuilder::appendTemplateArgumentsToName(): (after appending template name) *i = %p returnName = %s \n",*i,returnName.str());
695#endif
696 need_separator = true;
697 i++;
698
699#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST
700 printf ("In SageBuilder::appendTemplateArgumentsToName(): (bottom of loop) returnName = %s \n",returnName.str());
701#endif
702 }
703
704 if (emptyArgumentList == false)
705 returnName += " > ";
706
707#if DEBUG_APPEND_TEMPLATE_ARGUMENT_LIST || DEBUG_TEMPLATE_ARGUMENT_NAMES
708 printf ("Leaving SageBuilder::appendTemplateArgumentsToName(): returnName = %s \n",returnName.str());
709#endif
710
711 if (false)
712 {
713 // This allows me to test a large number of input codes and identify ones that are using specific features (e.g. template template parameters).
714 if (exit_after_name_is_generated == true)
715 {
716 printf ("Exiting as a test! \n");
717 ROSE_ASSERT(false);
718 }
719 }
720
721 delete info;
722 info = NULL;
723
724 return returnName;
725 }
726
727
728SgName
730 {
731 ROSE_ASSERT(templateArgument != NULL);
732
733 SgUnparse_Info *info = new SgUnparse_Info();
734 ROSE_ASSERT(info != NULL);
735
736 info->set_language(SgFile::e_Cxx_language);
737
738 // DQ (4/28/2017): For template arguments we never want to output the definitions of classes, and enums.
739 info->set_SkipClassDefinition();
740 info->set_SkipEnumDefinition();
741 info->set_use_generated_name_for_template_arguments(true);
742
743 SgName returnName = templateArgument->unparseToString(info);
744
745 delete info;
746 info = NULL;
747
748 return returnName;
749 }
750
751
752SgTemplateArgumentPtrList*
754 {
755 // DQ (9/13/2012): This function returns the SgTemplateArgumentPtrList. Both template declarations and template instanatiations have them.
756 // In a template instantiation it is the templateArguments field and from template declarations it is the templateSpecializationArguments field.
757
758 ROSE_ASSERT(decl != NULL);
759
760 SgTemplateArgumentPtrList* templateArgumentsList = NULL;
761
762 switch(decl->variantT())
763 {
764 case V_SgNamespaceAliasDeclarationStatement:
765 case V_SgNamespaceDeclarationStatement:
766 case V_SgEnumDeclaration:
767 case V_SgVariableDeclaration:
768 case V_SgTypedefDeclaration:
769 case V_SgProcedureHeaderStatement:
770 case V_SgJovialTableStatement:
771 case V_SgJavaPackageDeclaration:
772 case V_SgFunctionDeclaration:
773 case V_SgMemberFunctionDeclaration:
774 case V_SgClassDeclaration:
775 {
776 templateArgumentsList = NULL;
777 break;
778 }
779
780 case V_SgTemplateInstantiationDecl:
781 {
782 templateArgumentsList = &(isSgTemplateInstantiationDecl(decl)->get_templateArguments());
783 break;
784 }
785
786 case V_SgTemplateClassDeclaration:
787 {
788 templateArgumentsList = &(isSgTemplateClassDeclaration(decl)->get_templateSpecializationArguments());
789 break;
790 }
791
792 case V_SgTemplateInstantiationFunctionDecl:
793 {
794 templateArgumentsList = &(isSgTemplateInstantiationFunctionDecl(decl)->get_templateArguments());
795 break;
796 }
797
798 case V_SgTemplateFunctionDeclaration:
799 {
800 templateArgumentsList = &(isSgTemplateFunctionDeclaration(decl)->get_templateSpecializationArguments());
801 break;
802 }
803
804 case V_SgTemplateInstantiationMemberFunctionDecl:
805 {
806 templateArgumentsList = &(isSgTemplateInstantiationMemberFunctionDecl(decl)->get_templateArguments());
807 break;
808 }
809
810 case V_SgTemplateMemberFunctionDeclaration:
811 {
812 templateArgumentsList = &(isSgTemplateMemberFunctionDeclaration(decl)->get_templateSpecializationArguments());
813 break;
814 }
815
816 case V_SgTemplateVariableDeclaration:
817 {
818 templateArgumentsList = &(isSgTemplateVariableDeclaration(decl)->get_templateSpecializationArguments());
819 break;
820 }
821
822 case V_SgTemplateVariableInstantiation:
823 {
824 templateArgumentsList = &(isSgTemplateVariableInstantiation(decl)->get_templateArguments());
825 break;
826 }
827
828 case V_SgTemplateTypedefDeclaration:
829 {
830 templateArgumentsList = &(isSgTemplateTypedefDeclaration(decl)->get_templateSpecializationArguments());
831 break;
832 }
833
834 case V_SgTemplateInstantiationTypedefDeclaration:
835 {
836 templateArgumentsList = &(isSgTemplateInstantiationTypedefDeclaration(decl)->get_templateArguments());
837 break;
838 }
839
840 case V_SgTemplateDeclaration:
841 {
842 templateArgumentsList = NULL;
843 break;
844 }
845
846 case V_SgNonrealDecl:
847 {
848 templateArgumentsList = &(isSgNonrealDecl(decl)->get_tpl_args());
849 break;
850 }
851
852 default:
853 {
854 printf ("getTemplateArgumentList(): Default reached in switch: decl = %p = %s \n",decl,decl->class_name().c_str());
855 ROSE_ABORT();
856 }
857 }
858
859 return templateArgumentsList;
860 }
861
862
863
864SgTemplateParameterPtrList*
866 {
867 // DQ (9/16/2012): This function returns the SgTemplateParameterPtrList that is associated with template declarations.
868 // For all other cases it returns NULL (or is an error).
869
870 ROSE_ASSERT(decl != NULL);
871
872 SgTemplateParameterPtrList* templateParameterList = NULL;
873
874 switch(decl->variantT())
875 {
876 case V_SgNamespaceAliasDeclarationStatement:
877 case V_SgNamespaceDeclarationStatement:
878 case V_SgEnumDeclaration:
879 case V_SgVariableDeclaration:
880 case V_SgTypedefDeclaration:
881 case V_SgProcedureHeaderStatement:
882 case V_SgJovialTableStatement:
883 case V_SgJavaPackageDeclaration:
884 case V_SgFunctionDeclaration:
885 case V_SgMemberFunctionDeclaration:
886 case V_SgClassDeclaration:
887 case V_SgTemplateInstantiationTypedefDeclaration:
888 case V_SgTemplateInstantiationFunctionDecl:
889 case V_SgTemplateInstantiationMemberFunctionDecl:
890 case V_SgTemplateVariableInstantiation:
891 case V_SgTemplateInstantiationDecl:
892 {
893 templateParameterList = NULL;
894 break;
895 }
896
897 case V_SgTemplateClassDeclaration:
898 {
899 templateParameterList = &(isSgTemplateClassDeclaration(decl)->get_templateParameters());
900 break;
901 }
902
903 case V_SgTemplateFunctionDeclaration:
904 {
905 templateParameterList = &(isSgTemplateFunctionDeclaration(decl)->get_templateParameters());
906 break;
907 }
908
909 case V_SgTemplateMemberFunctionDeclaration:
910 {
911 templateParameterList = &(isSgTemplateMemberFunctionDeclaration(decl)->get_templateParameters());
912 break;
913 }
914
915 case V_SgTemplateVariableDeclaration:
916 {
917 templateParameterList = &(isSgTemplateVariableDeclaration(decl)->get_templateParameters());
918 break;
919 }
920
921 case V_SgTemplateTypedefDeclaration:
922 {
923 templateParameterList = &(isSgTemplateTypedefDeclaration(decl)->get_templateParameters());
924 break;
925 }
926
927 case V_SgNonrealDecl:
928 {
929 templateParameterList = &(isSgNonrealDecl(decl)->get_tpl_params());
930 break;
931 }
932
933 case V_SgTemplateDeclaration:
934 {
935 templateParameterList = &(isSgTemplateDeclaration(decl)->get_templateParameters());
936 break;
937 }
938
939 default:
940 {
941 printf ("getTemplateParameterList(): Default reached in switch: decl = %p = %s \n",decl,decl->class_name().c_str());
942 ROSE_ABORT();
943 }
944 }
945
946 return templateParameterList;
947 }
948
949
950
951void
953 {
954 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
955
956 ROSE_ASSERT(decl != NULL);
957
958 SgTemplateArgumentPtrList* templateArgumentsList = getTemplateArgumentList(decl);
959
960 if (templateArgumentsList != NULL)
961 {
963 ROSE_ASSERT(first_decl != NULL);
964
965 SgTemplateArgumentPtrList::iterator i = templateArgumentsList->begin();
966 while (i != templateArgumentsList->end())
967 {
968 SgNode* parent = (*i)->get_parent();
969 if (parent== NULL)
970 {
971 // (*i)->set_parent(decl);
972 (*i)->set_parent(first_decl);
973 }
974 else
975 {
976 SgScopeStatement* scope = isSgScopeStatement(parent);
977 if (scope != NULL)
978 {
979 // Template Arguments should have had there parents set to a scope when they were build, we want
980 // to refine that now that the declaration which we want them to be specified in has been build.
981 (*i)->set_parent(first_decl);
982 }
983 else
984 {
985 SgDeclarationStatement* declaration = isSgDeclarationStatement(parent);
986 if (declaration != NULL)
987 {
988#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
989 printf ("In setTemplateArgumentParents(): Template argument already set to declaration = %p = %s \n",declaration,declaration->class_name().c_str());
990#endif
991 }
992 else
993 {
994#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
995 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());
996#endif
997 }
998 }
999 }
1000
1001 i++;
1002 }
1003 }
1004
1006 }
1007
1008
1009void
1011 {
1012 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1013 ROSE_ASSERT(decl != NULL);
1014
1015 SgTemplateParameterPtrList* templateParameterList = getTemplateParameterList(decl);
1016
1017 if (templateParameterList != NULL)
1018 {
1020 ROSE_ASSERT(first_decl != NULL);
1021
1022 SgTemplateParameterPtrList::iterator i = templateParameterList->begin();
1023 while (i != templateParameterList->end())
1024 {
1025 SgNode* parent = (*i)->get_parent();
1026 if (parent == NULL)
1027 {
1028 (*i)->set_parent(first_decl);
1029 }
1030 else
1031 {
1032 SgScopeStatement* scope = isSgScopeStatement(parent);
1033 if (scope != NULL)
1034 {
1035 // Template Arguments should have had their parents set to a scope when they were build, we want
1036 // to refine that now that the declaration which we want them to be specified in has been build.
1037 (*i)->set_parent(first_decl);
1038 }
1039 }
1040
1041 i++;
1042 }
1043 }
1044
1046 }
1047
1048
1049void
1051 {
1052 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1053
1054 ROSE_ASSERT(decl != NULL);
1055
1056 SgTemplateArgumentPtrList* templateArgumentsList = getTemplateArgumentList(decl);
1057
1058 if (templateArgumentsList != NULL)
1059 {
1060 SgTemplateArgumentPtrList::iterator i = templateArgumentsList->begin();
1061 while (i != templateArgumentsList->end())
1062 {
1063 SgNode* parent = (*i)->get_parent();
1064 if (parent == NULL)
1065 {
1066 printf ("Error: In testTemplateArgumentParents(): decl = %p = %s has template argument = %p with null parent \n",decl,decl->class_name().c_str(),*i);
1067 }
1068 ROSE_ASSERT(parent != NULL);
1069
1070 // DQ (9/16/2012): Adding new test.
1071 ROSE_ASSERT(decl->get_firstNondefiningDeclaration() != NULL);
1072 // DQ (1/30/2013): Commented this test out so that we could reuse SgTemplateArguments and
1073 // assure that the mapping from EDG a_template_arg_ptr's to SgTemplateArgument's was 1-to-1.
1074 // It is not clear if we can relax this constraint in the future.
1075
1076 i++;
1077 }
1078 }
1079 }
1080
1081
1082void
1084 {
1085 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
1086
1087 ROSE_ASSERT(decl != NULL);
1088
1089 SgTemplateParameterPtrList* templateParameterList = getTemplateParameterList(decl);
1090
1091 if (templateParameterList != NULL)
1092 {
1093 SgTemplateParameterPtrList::iterator i = templateParameterList->begin();
1094 while (i != templateParameterList->end())
1095 {
1096 SgNode* parent = (*i)->get_parent();
1097 if (parent == NULL)
1098 {
1099 printf ("Error: In testTemplateParameterParents(): decl = %p = %s has template argument = %p with null parent \n",decl,decl->class_name().c_str(),*i);
1100 }
1101 ROSE_ASSERT(parent != NULL);
1102 ROSE_ASSERT(decl->get_firstNondefiningDeclaration() != NULL);
1103
1104 // DQ (8/22/2013): Since these are now shared, it makes less sense to expect these to have such simple parent relationships.
1105 // This commit of work on ROSE added caching to template parameters so that we could support pointer equality for tests
1106 // of template parameter equality in the symbol table handling (this was a technique previously used for template arguments).
1107 // 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).
1108
1109 i++;
1110 }
1111 }
1112 }
1113
1114
1115void
1116SageBuilder::setTemplateArgumentsInDeclaration( SgDeclarationStatement* decl, SgTemplateArgumentPtrList* templateArgumentsList_input )
1117 {
1118 // DQ (9/16/2012): Setup the template arguments for any type of template instantiation.
1119
1120 ROSE_ASSERT(templateArgumentsList_input != NULL);
1121
1122 ROSE_ASSERT(decl->variantT() == V_SgTemplateInstantiationDecl ||
1123 decl->variantT() == V_SgTemplateInstantiationFunctionDecl ||
1124 decl->variantT() == V_SgTemplateInstantiationMemberFunctionDecl ||
1125 decl->variantT() == V_SgTemplateInstantiationTypedefDeclaration);
1126
1127 SgTemplateArgumentPtrList* templateArgumentsList_from_declaration = getTemplateArgumentList(decl);
1128
1129 if (templateArgumentsList_from_declaration != NULL)
1130 {
1131 *templateArgumentsList_from_declaration = *templateArgumentsList_input;
1132
1133 // Set the parents.
1135 }
1136
1138 }
1139
1140
1141void
1142SageBuilder::setTemplateSpecializationArgumentsInDeclaration( SgDeclarationStatement* decl, SgTemplateArgumentPtrList* templateSpecializationArgumentsList_input )
1143 {
1144 // DQ (9/16/2012): Setup the template arguments for any type of template declaration
1145
1146 ROSE_ASSERT(templateSpecializationArgumentsList_input != NULL);
1147
1148 ROSE_ASSERT(decl->variantT() == V_SgTemplateClassDeclaration || decl->variantT() == V_SgTemplateFunctionDeclaration ||
1149 decl->variantT() == V_SgTemplateMemberFunctionDeclaration || decl->variantT() == V_SgTemplateVariableDeclaration );
1150
1151 SgTemplateArgumentPtrList* templateSpecializationArgumentsList_from_declaration = getTemplateArgumentList(decl);
1152
1153 if (templateSpecializationArgumentsList_from_declaration != NULL)
1154 {
1155 *templateSpecializationArgumentsList_from_declaration = *templateSpecializationArgumentsList_input;
1156
1157 // Set the parents.
1159 }
1160
1162 }
1163
1164void
1165SageBuilder::setTemplateParametersInDeclaration( SgDeclarationStatement* decl, SgTemplateParameterPtrList* templateParameterList_input )
1166 {
1167 // DQ (9/16/2012): Setup the template parameters for any type of template declaration.
1168
1169 ROSE_ASSERT(templateParameterList_input != NULL);
1170
1171 ROSE_ASSERT(decl->variantT() == V_SgTemplateClassDeclaration || decl->variantT() == V_SgTemplateFunctionDeclaration ||
1172 decl->variantT() == V_SgTemplateMemberFunctionDeclaration || decl->variantT() == V_SgTemplateVariableDeclaration );
1173
1174 SgTemplateParameterPtrList* templateParameterList_from_declaration = getTemplateParameterList(decl);
1175
1176 if (templateParameterList_from_declaration != NULL)
1177 {
1178 *templateParameterList_from_declaration = *templateParameterList_input;
1179
1180 // Set the parents.
1182 }
1183
1185 }
1186
1187#define DEBUG__buildInitializedName 0
1188// Only used to build parameter arguments for function ??
1189// should be transparently generated for most variable declaration builder
1190// deferred symbol insertion, scope setting , etc
1191// do them when it is actually used with the parameterList!!
1193#if DEBUG__buildInitializedName
1194 std::cout << "SageBuilder::buildInitializedName" << std::endl;
1195 std::cout << " name = " << name << std::endl;
1196#endif
1197 ASSERT_not_null(type);
1198
1199 SgInitializedName* initializedName = new SgInitializedName(name,type,init);
1200 ROSE_ASSERT(initializedName);
1201
1203 return initializedName;
1204}
1205
1206SgInitializedName * SageBuilder::buildInitializedName ( const std::string & name, SgType* type) {
1207 SgName var_name(name);
1208 return buildInitializedName(var_name,type);
1209}
1210
1212 string var_name(name);
1213 return buildInitializedName(var_name,type);
1214}
1215
1217#if DEBUG__buildInitializedName
1218 std::cout << "SageBuilder::buildInitializedName_nfi" << std::endl;
1219 std::cout << " name = " << name << std::endl;
1220#endif
1221 ROSE_ASSERT(type != NULL);
1222
1223 SgInitializedName* initializedName = new SgInitializedName(name,type,init);
1224 ROSE_ASSERT(initializedName != NULL);
1225
1226 if (declptr)
1227 {
1228 initializedName->set_parent(declptr);
1229 initializedName->set_declptr(declptr);
1230 }
1231
1232 setOneSourcePositionNull(initializedName);
1233
1234 return initializedName;
1235}
1236
1237//-----------------------------------------------
1238// could have two declarations for a same variable
1239// extern int i;
1240// int i;
1243 //(const SgName & name, SgType* type, SgInitializer * varInit= NULL, SgScopeStatement* scope = NULL)
1244{
1245 if (scope == NULL)
1247 ROSE_ASSERT(name.is_null() == false);
1248 ROSE_ASSERT(type != NULL);
1249
1250 SgVariableDeclaration * varDecl = new SgVariableDeclaration(name, type, varInit);
1251 ROSE_ASSERT(varDecl);
1252
1253// DQ (8/21/2011): Note that the default is to set the declaration modifier's access modifier to be
1254// default (which is the same as public). So the effect it to set it to be public. This is ignored
1255// by the unparser for most languguages in ROSE.
1256 varDecl->set_firstNondefiningDeclaration(varDecl);
1257
1258 if (scope!=NULL)
1259 {
1260 // Liao 12/13/2010
1261 // Fortran subroutine/function parameters have corresponding variable declarations in the body
1262 // For this declaration, it should use the initialized names of the parameters instead of creating new ones
1263 // The symbol of the init name should be under SgFunctionDefinition, instead of the function body block
1264 bool isFortranParameter = false;
1266 {
1268 if (f_def != NULL)
1269 {
1270 // DQ (5/21/2013): Removed direct reference to symbol table (namespace handling is only supported at the SgScopeStatement level).
1271 SgVariableSymbol * v_symbol = f_def->lookup_variable_symbol(name);
1272 if (v_symbol != NULL) // find a function parameter with the same name
1273 {
1274 // replace the default one with the one from parameter
1275 SgInitializedName *default_initName = varDecl->get_decl_item (name);
1276 ROSE_ASSERT (default_initName != NULL);
1277 SgInitializedName * new_initName = v_symbol->get_declaration();
1278 ROSE_ASSERT (new_initName != NULL);
1279 ROSE_ASSERT (default_initName != new_initName);
1280
1281 SgInitializedNamePtrList& n_list= varDecl->get_variables();
1282 std::replace (n_list.begin(), n_list.end(),default_initName, new_initName );
1283 ROSE_ASSERT (varDecl->get_decl_item (name)==new_initName); //ensure the new one can be found
1284
1285 // change the function argument's old parent to the variable declaration
1286 SgNode * old_parent = new_initName->get_parent();
1287 ROSE_ASSERT (old_parent != NULL);
1288 ROSE_ASSERT (isSgFunctionParameterList(old_parent) != NULL);
1289 new_initName->set_parent(varDecl); // adjust parent from SgFunctionParameterList to SgVariableDeclaration
1290
1291 // DQ (1/25/2011): Deleting these causes problems if I use this function in the Fortran support...
1292 // delete (default_initName->get_declptr()); // delete the var definition
1293 // delete (default_initName->get_declptr()); // relink the var definition
1294
1295 SgVariableDefinition * var_def = isSgVariableDefinition(default_initName->get_declptr()) ;
1296 ROSE_ASSERT (var_def != NULL);
1297 var_def->set_parent(new_initName);
1298 var_def->set_vardefn(new_initName);
1299 new_initName->set_declptr(var_def); // it was set to SgProcedureHeaderStatement as a function argument
1300
1301 delete (default_initName); // must delete the old one to pass AST consistency test
1302
1303 // DQ (12/13/2011): Is this executed...
1304 //printf ("Is this executed \n");
1305 //ROSE_ASSERT(false);
1306
1307 isFortranParameter = true;
1308 }
1309 }
1310 }
1311 if (! isFortranParameter) // No need to add symbol to the function body if it is a Fortran parameter
1312 // The symbol should already exist under function definition for the parameter
1313 fixVariableDeclaration(varDecl,scope);
1314 }
1315
1316 SgInitializedName *initName = varDecl->get_decl_item (name);
1317 ROSE_ASSERT(initName != NULL);
1318 ROSE_ASSERT((initName->get_declptr())!=NULL);
1319
1320 //bug 119, SgVariableDefintion's File_info is needed for deep copy to work
1321 // AstQuery based setSourcePositionForTransformation() cannot access all child nodes
1322 // have to set SgVariableDefintion explicitly
1323 SgDeclarationStatement* variableDefinition_original = initName->get_declptr();
1324 setOneSourcePositionForTransformation(variableDefinition_original);
1325 ROSE_ASSERT((variableDefinition_original->get_startOfConstruct()) !=NULL);
1326 ROSE_ASSERT((variableDefinition_original->get_endOfConstruct())!=NULL);
1327
1329 //ROSE_ASSERT (isSgVariableDefinition(initName->get_declptr())->get_startOfConstruct()!=NULL);
1330
1331
1332 // DQ (4/16/2015): This is replaced with a better implementation.
1333 // DQ (4/15/2015): We should reset the isModified flags as part of the transforamtion
1334 // because we have added statements explicitly marked as transformations.
1335 // checkIsModifiedFlag(varDecl);
1336 unsetNodesMarkedAsModified(varDecl);
1337
1338// ROSE_ASSERT(findFirstSgCastExpMarkedAsTransformation(varDecl,"testing buildVariableDeclaration(): 9") == false);
1339// ROSE_ASSERT(findFirstSgCastExpMarkedAsTransformation(scope,"testing buildVariableDeclaration(): 9-scope") == false);
1340
1341 return varDecl;
1342}
1343
1344//-----------------------------------------------
1345// could have two declarations for a same variable
1346// extern int i;
1347// int i;
1350 {
1351
1352#define DEBUG_BUILD_VARIABLE_DECLARATION 0
1353
1354#if DEBUG_BUILD_VARIABLE_DECLARATION
1355 printf ("In SageBuilder::buildVariableDeclaration_nfi(): name = %s scope = %p varInit = %p \n",name.str(),scope,varInit);
1356 if (scope != NULL)
1357 {
1358 printf (" --- scope = %p = %s \n",scope,scope->class_name().c_str());
1359 }
1360#endif
1361
1362 if (scope == NULL)
1363 {
1364#if DEBUG_BUILD_VARIABLE_DECLARATION
1365 printf ("Scope determined from the SageBuilder::topScopeStack() \n");
1366#endif
1368 }
1369
1370 ROSE_ASSERT (scope != NULL);
1371 ROSE_ASSERT(type != NULL);
1372
1373 // DQ (7/18/2012): Added debugging code (should fail for test2011_75.C).
1374 SgVariableSymbol* variableSymbol = scope->lookup_variable_symbol(name);
1375
1376#if DEBUG_BUILD_VARIABLE_DECLARATION
1377 printf ("In SageBuilder::buildVariableDeclaration_nfi(): variableSymbol = %p \n",variableSymbol);
1378#endif
1379
1380 // 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.
1381 SgVariableDeclaration * varDecl = NULL;
1382 if (variableSymbol == NULL)
1383 {
1384 varDecl = new SgVariableDeclaration(name, type, varInit);
1385#if DEBUG_BUILD_VARIABLE_DECLARATION
1386 SgInitializedName* tmp_initializedName = getFirstInitializedName(varDecl);
1387 ROSE_ASSERT(tmp_initializedName != NULL);
1388 printf ("In SageBuilder::buildVariableDeclaration_nfi(): variableSymbol == NULL: varDecl = %p: initializedName = %p = %s \n",varDecl,tmp_initializedName,tmp_initializedName->get_name().str());
1389 printf (" --- tmp_initializedName->get_initptr() = %p \n",tmp_initializedName->get_initptr());
1390#endif
1391 // DQ (6/25/2019): This is a new feature to input the builtFromUseOnly function optional parameter.
1392 if (builtFromUseOnly == true)
1393 {
1394#if DEBUG_BUILD_VARIABLE_DECLARATION
1395 printf ("In buildVariableDeclaration_nfi(): this is the first reference to this variable: building a new SgVariableDeclaration: varDecl = %p name = %s \n",varDecl,name.str());
1396#endif
1397 varDecl->set_builtFromUseOnly(true);
1398 }
1399 }
1400 else
1401 {
1402 SgInitializedName* initializedName = variableSymbol->get_declaration();
1403 ROSE_ASSERT(initializedName != NULL);
1404
1405 SgVariableDeclaration* associatedVariableDeclaration = isSgVariableDeclaration(initializedName->get_parent());
1406
1407#if DEBUG_BUILD_VARIABLE_DECLARATION
1408 printf ("In SageBuilder::buildVariableDeclaration_nfi(): initializedName->get_parent() = %p \n",initializedName->get_parent());
1409 if (initializedName->get_parent() != NULL)
1410 {
1411 printf ("In SageBuilder::buildVariableDeclaration_nfi(): initializedName->get_parent() = %p = %s \n",initializedName->get_parent(),initializedName->get_parent()->class_name().c_str());
1412 }
1413 printf ("In SageBuilder::buildVariableDeclaration_nfi(): associatedVariableDeclaration = %p \n",associatedVariableDeclaration);
1414#endif
1415#if DEBUG_BUILD_VARIABLE_DECLARATION
1416 // DQ (6/24/2019): If this has been previously built as part of a variable use (in a class declaration),
1417 // then it should not be attached to the class definition as a variable declaration yet, and we should reuse it.
1418 if (associatedVariableDeclaration != NULL && associatedVariableDeclaration->get_parent() != NULL)
1419 {
1420 printf ("In SageBuilder::buildVariableDeclaration_nfi(): associatedVariableDeclaration->get_parent() = %p = %s \n",
1421 associatedVariableDeclaration->get_parent(),associatedVariableDeclaration->get_parent()->class_name().c_str());
1422 }
1423#endif
1424
1425#if DEBUG_BUILD_VARIABLE_DECLARATION
1426 printf ("associatedVariableDeclaration = %p \n",associatedVariableDeclaration);
1427 if (associatedVariableDeclaration != NULL)
1428 {
1429 printf ("associatedVariableDeclaration->get_builtFromUseOnly() = %s \n",associatedVariableDeclaration->get_builtFromUseOnly() ? "true" : "false");
1430 }
1431#endif
1432
1433 // DQ (6/25/2019): Trigger the reuse of the available variable declaration.
1434 bool reuseTheAssociatedVariableDeclaration = ((associatedVariableDeclaration != NULL) && (associatedVariableDeclaration->get_builtFromUseOnly() == true));
1435 if (reuseTheAssociatedVariableDeclaration == true)
1436 {
1437 // Build a seperate SgVariableDeclaration so that we can avoid sharing the SgInitializedName
1438 // (and it's possible initializer which would be an error for the secondary declaration
1439 // (the declaration in the class for the case of a static declaration))
1440
1441 ROSE_ASSERT(associatedVariableDeclaration != NULL);
1442
1443 // DQ (6/24/2019): Fix this to use the associatedVariableDeclaration.
1444 varDecl = associatedVariableDeclaration;
1445
1446 // DQ (6/25/2019): Mark this variable declaration so that it will not be reused again.
1447 varDecl->set_builtFromUseOnly(false);
1448
1449 // 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.
1450 varDecl->set_parent(NULL);
1451
1452 // DQ (6/24/2019): this veriable declaration that is being reused, should not have had an initializer (check this).
1454 ROSE_ASSERT(variable != NULL);
1455
1456 // DQ (6/25/2019): See Cxx11_tests/test2019_121.C and Cxx11_tests/test2019_482.C.
1457 // ROSE_ASSERT(variable->get_initptr() == NULL);
1458#if DEBUG_BUILD_VARIABLE_DECLARATION
1459 if (variable->get_initptr() != NULL)
1460 {
1461 printf ("Found initializer associated with variable declaration being reused: variable = %p name = %s \n",variable,variable->get_name().str());
1462 }
1463#endif
1464 // DQ (7/3/2019): Reuse in a conditional will have a valid initializer.
1465 }
1466 else
1467 {
1468 // DQ (6/25/2019): We can't reuse the existing SgInitializedName, because it could have been initialized in the other SgVariableDeclaration.
1469 ROSE_ASSERT(reuseTheAssociatedVariableDeclaration == false);
1470
1471 // DQ (6/27/2019): If the SgInitializedName was generated from the convert_variable_use() function in the
1472 // EDG/ROSE translation, then where was not associated SgVariableDeclaration built (an inconsistancy).
1473 // So we want to check for the parent being a scope statement (e.g. SgIfStmt or other statement that can
1474 // accept a conditional expression where in C++ it can alternatively declare a variable.
1475 if (associatedVariableDeclaration == NULL)
1476 {
1477 ROSE_ASSERT(initializedName->get_parent() != NULL);
1478 SgScopeStatement* scopeStatement = isSgScopeStatement(initializedName->get_parent());
1479 if (scopeStatement != NULL)
1480 {
1481#if DEBUG_BUILD_VARIABLE_DECLARATION
1482 printf ("scopeStatement = %p = %s \n",scopeStatement,scopeStatement->class_name().c_str());
1483#endif
1484 }
1485 else
1486 {
1487#if DEBUG_BUILD_VARIABLE_DECLARATION
1488 printf ("initializedName->get_parent() = %p = %s \n",initializedName->get_parent(),initializedName->get_parent()->class_name().c_str());
1489#endif
1490 }
1491 }
1492
1493 // DQ (6/27/2019): In some case we want to reuse the associated SgInitializedName node.
1494 // For example: variable declarations in conditionals (e.g. SgIfStmt, and other scope statements).
1495 // DQ (6/26/2019): Build an additional variable to support another reference to the original variable.
1496 // Note: we need another one because either one can have an initializer that cannot be shared in the AST.
1497 SgInitializedName* additional_variable = NULL;
1498
1499#if DEBUG_BUILD_VARIABLE_DECLARATION
1500 printf ("In SageBuilder::buildVariableDeclaration_nfi(): initializedName->get_scope() = %p = %s \n",initializedName->get_scope(),initializedName->get_scope()->class_name().c_str());
1501#endif
1502 SgScopeStatement* scopeStatement = isSgScopeStatement(initializedName->get_parent());
1503 if (scopeStatement != NULL)
1504 {
1505 additional_variable = initializedName;
1506
1507 // DQ (6/28/2019): Support case when the borrowed SgInitializedName has a valid initializer.
1508 // DQ (6/26/2019): Adding the initializer.
1509 if (additional_variable->get_initptr() != NULL)
1510 {
1511#if DEBUG_BUILD_VARIABLE_DECLARATION
1512 printf ("In SageBuilder::buildVariableDeclaration_nfi(): borrowed SgInitializedName is alread initialized \n");
1513 printf (" --- additional_variable->get_initptr() = %p \n",additional_variable->get_initptr());
1514 printf (" --- varInit = %p \n",varInit);
1515#endif
1516 // DQ (6/28/2019): when this is assertion is false, we have constructed a redundant initializer (debugging this).
1517 // PP (7/22/2019) faults in CUDA code
1518 }
1519 else
1520 {
1521 additional_variable->set_initptr(varInit);
1522 }
1523
1524#if DEBUG_BUILD_VARIABLE_DECLARATION || 0
1525 printf (" --- additional_variable->get_scope() = %p = %s \n",additional_variable->get_scope(),additional_variable->get_scope()->class_name().c_str());
1526 printf (" --- Reusing the SgInitializedName (not associated with a previous SgVariableDeclaration where the parent is a SgScopeStatement) \n");
1527#endif
1528 }
1529 else
1530 {
1531#if DEBUG_BUILD_VARIABLE_DECLARATION
1532 printf (" --- Building a new SgInitializedName \n");
1533#endif
1534 additional_variable = buildInitializedName_nfi(name,type,varInit);
1535 }
1536
1537#if DEBUG_BUILD_VARIABLE_DECLARATION
1538 ROSE_ASSERT(initializedName->get_scope() != NULL);
1539#endif
1540 // DQ (6/26/2019): Set the scopes to be the same (a symbol already exists at this point).
1541 // DQ (6/26/2019): Set the pointer to the original version of this variable (unless we reused the SgInitializedName above).
1542 if (additional_variable != initializedName)
1543 {
1544 additional_variable->set_prev_decl_item(initializedName);
1545 }
1546
1547 // If there is not an associated SgVariableDeclaration then reuse the existing SgInitializedName.
1548 varDecl = new SgVariableDeclaration(additional_variable);
1549#if DEBUG_BUILD_VARIABLE_DECLARATION
1550 ROSE_ASSERT(initializedName->get_parent() != NULL);
1551 printf ("initializedName->get_parent() = %p = %s \n",initializedName->get_parent(),initializedName->get_parent()->class_name().c_str());
1552 ROSE_ASSERT(additional_variable->get_parent() != NULL);
1553 printf ("additional_variable->get_parent() = %p = %s \n",additional_variable->get_parent(),additional_variable->get_parent()->class_name().c_str());
1554#endif
1555 // DQ (6/26/2019): Set the parent of the first SgInitializedName to that of the second SgInitializedName.
1556 // This is an issue for the range for initialization: see test2019_483.C.
1557
1558 ASSERT_not_null(initializedName->get_scope());
1559
1560 // DQ (6/26/2019): Set the pointer to the original version of this variable (unless we reused the SgInitializedName above).
1561 if (additional_variable != initializedName)
1562 {
1563 additional_variable->set_scope(initializedName->get_scope());
1564 }
1565 // DQ (7/14/2014): Set the variable initialized (see test2014_107.C, also required for boost for_each support)).
1566 // initializedName->set_initptr(varInit);
1567#if DEBUG_BUILD_VARIABLE_DECLARATION
1568 printf ("In SageBuilder::buildVariableDeclaration_nfi(): After sharing the exisitng SgInitializedName: initializedName = %p = %s \n",initializedName,initializedName->get_name().str());
1569 printf (" --- initializedName->get_initptr() = %p \n",initializedName->get_initptr());
1570 printf (" --- additional_variable->get_initptr() = %p \n",additional_variable->get_initptr());
1571#endif
1572 }
1573 }
1574
1575 // DQ (11/3/2012): The SgInitializedName inside the SgVariableDeclaration must have valid source position object (even if default initialized).
1577 ASSERT_not_null(variable);
1579
1580 ASSERT_not_null(varDecl);
1581 varDecl->set_firstNondefiningDeclaration(varDecl);
1582 varDecl->get_declarationModifier().get_storageModifier().set_modifier(sm);
1583
1584 // DQ (7/9/2012): Added test (parent should not be set yet; set in parse_statement).
1585 ROSE_ASSERT(varDecl->get_parent() == NULL);
1586
1587 if (name != "")
1588 {
1589 // Anonymous bit fields should not have symbols
1590 fixVariableDeclaration(varDecl,scope);
1591
1592 // DQ (7/9/2012): Added test (parent should not be set yet; set in parse_statement).
1593 }
1594 else
1595 {
1596 // 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).
1597 // 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...
1598 varDecl->set_parent(topScopeStack());
1599 ASSERT_not_null(varDecl->get_parent());
1600 }
1601
1602 SgInitializedName *initName = varDecl->get_decl_item (name);
1603 ASSERT_not_null(initName);
1604 ASSERT_not_null(initName->get_declptr());
1605
1606 if (initName->get_scope())
1607 {
1608 // Make this a warning for the few places where this fails.
1609#if DEBUG_BUILD_VARIABLE_DECLARATION
1610 printf ("WARNING: Note in buildVariableDeclaration_nfi(): initName->get_scope() == NULL \n");
1611#endif
1612 }
1613
1614 // DQ (7/9/2012): Added test (parent should not be set yet; set in parse_statement).
1615 // bug 119, SgVariableDefintion's File_info is needed for deep copy to work
1616 // AstQuery based setSourcePositionForTransformation() cannot access all child nodes
1617 // have to set SgVariableDefintion explicitly
1618 SgVariableDefinition* variableDefinition_original = isSgVariableDefinition(initName->get_declptr());
1619 ASSERT_not_null(variableDefinition_original);
1620 setOneSourcePositionNull(variableDefinition_original);
1621 setOneSourcePositionNull(varDecl);
1622
1623 // DQ (7/12/2012): The parent should be set to the current scope (not the same as that specified
1624 // in the scope (since that applies to the variable (SgInitializedName) not the SgVariableDeclaration).
1625 // Liao, 1/23/2013, quick fix for now, this condition is a mirror to the code setting parent in SageInterface::fixVariableDeclaration()
1626 if (topScopeStack())
1627 {
1628 ASSERT_not_null(varDecl->get_parent());
1629 }
1630
1631 // DQ (4/16/2015): This is replaced with a better implementation.
1632 // DQ (4/15/2015): We should reset the isModified flags as part of the transforamtion
1633 // because we have added statements explicitly marked as transformations.
1634 unsetNodesMarkedAsModified(varDecl);
1635
1636 ASSERT_not_null(varDecl);
1637
1638#if DEBUG_BUILD_VARIABLE_DECLARATION
1639 printf ("Leaving buildVariableDeclaration_nfi(): varDecl = %p varDecl->get_parent() = %p \n",varDecl,varDecl->get_parent());
1640#endif
1641
1642 return varDecl;
1643 }
1644
1645
1648{
1649// refactored from ROSETTA/Grammar/Statement.code SgVariableDeclaration::append_variable ()
1650
1651 ROSE_ASSERT (decl!=NULL);
1652 ROSE_ASSERT (init_name !=NULL);
1653 // init can be NULL
1654
1655 SgVariableDefinition *defn_stmt = NULL;
1656 if (!isSgFunctionType(init_name->get_type()))
1657 {
1658 Sg_File_Info* copyOfFileInfo = NULL;
1659 if (decl->get_file_info() != NULL)
1660 {
1661 copyOfFileInfo = new Sg_File_Info(*(decl->get_file_info()));
1662 ROSE_ASSERT (copyOfFileInfo != NULL);
1663
1664 // Note that the SgVariableDefinition will connect the new IR node into the AST.
1665 defn_stmt = new SgVariableDefinition(copyOfFileInfo, init_name, init);
1666 ROSE_ASSERT (defn_stmt != NULL);
1667
1668 copyOfFileInfo->set_parent(defn_stmt);
1669
1670 // DQ (3/13/2007): We can't enforce that the endOfConstruct is set (if the interface using the startOfConstruct is used.
1671 // DQ (2/3/2007): Need to build the endOfConstruct position as well.
1672 if (decl->get_endOfConstruct() != NULL)
1673 {
1674 Sg_File_Info* copyOfEndOfConstruct = new Sg_File_Info(*(decl->get_endOfConstruct()));
1675 defn_stmt->set_endOfConstruct(copyOfEndOfConstruct);
1676 copyOfEndOfConstruct->set_parent(defn_stmt);
1677 }
1678 }
1679 else
1680 {
1681 // Note that the SgVariableDefinition will connect the new IR node into the AST.
1682 defn_stmt = new SgVariableDefinition(init_name, init);
1683 }
1684 ROSE_ASSERT(defn_stmt != NULL);
1685 }
1686 else
1687 defn_stmt = NULL;
1688 return defn_stmt ;
1689}
1690
1691
1694{
1697 return res;
1698}
1699
1702 {
1703 ROSE_ASSERT (scope != NULL);
1704 ROSE_ASSERT(type != NULL);
1705
1706 SgTemplateVariableDeclaration * varDecl = new SgTemplateVariableDeclaration(name, type, varInit);
1707 ROSE_ASSERT(varDecl);
1708
1709 varDecl->set_firstNondefiningDeclaration(varDecl);
1710
1711 // DQ (11/3/2012): The SgInitializedName inside the SgVariableDeclaration must have valid source position object (even if default initialized).
1713 ROSE_ASSERT(variable != NULL);
1715
1716 if (name != "")
1717 {
1718 // Anonymous bit fields should not have symbols
1719 fixVariableDeclaration(varDecl,scope);
1720 }
1721
1722 SgInitializedName *initName = varDecl->get_decl_item (name);
1723 ROSE_ASSERT(initName);
1724 ROSE_ASSERT((initName->get_declptr())!=NULL);
1725
1726 // bug 119, SgVariableDefintion's File_info is needed for deep copy to work
1727 // AstQuery based setSourcePositionForTransformation() cannot access all child nodes
1728 // have to set SgVariableDefintion explicitly
1729 SgVariableDefinition* variableDefinition_original = isSgVariableDefinition(initName->get_declptr());
1730 ROSE_ASSERT(variableDefinition_original != NULL);
1731 setOneSourcePositionNull(variableDefinition_original);
1732
1733 setOneSourcePositionNull(varDecl);
1734
1735 return varDecl;
1736 }
1737
1740 const SgName & name, SgType *type, SgInitializer *varInit, SgScopeStatement* scope,
1742 SgTemplateArgumentPtrList & tpl_args
1743) {
1744 SgTemplateVariableInstantiation* res = buildTemplateVariableInstantiation_nfi(name, type, varInit, scope, tpl_decl, tpl_args);
1746 return res;
1747}
1748
1749#define DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi 0
1750
1753 const SgName & name, SgType *type, SgInitializer *varInit, SgScopeStatement* scope,
1755 SgTemplateArgumentPtrList & tpl_args
1756) {
1757#if DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi
1758 std::cout << "SageBuilder::buildTemplateVariableInstantiation_nfi" << std::endl;
1759 std::cout << " name = " << name.getString() << std::endl;
1760 std::cout << " type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
1761 std::cout << " scope = " << std::hex << scope << " : " << ( scope ? scope->class_name() : "" ) << std::endl;
1762#endif
1763 ROSE_ASSERT (type != NULL);
1764
1765 SgName nameWithoutTemplateArguments = name;
1766 SgName nameWithTemplateArguments = appendTemplateArgumentsToName(name,tpl_args);
1767#if DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi
1768 std::cout << " nameWithoutTemplateArguments = " << nameWithoutTemplateArguments.getString() << std::endl;
1769 std::cout << " nameWithTemplateArguments = " << nameWithTemplateArguments.getString() << std::endl;
1770#endif
1771
1772 ROSE_ASSERT (scope != NULL);
1773 ROSE_ASSERT(type != NULL);
1774
1775 SgTemplateVariableInstantiation * varDecl = new SgTemplateVariableInstantiation(name, type, varInit);
1776 ROSE_ASSERT(varDecl);
1777#if DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi
1778 std::cout << " varDecl = " << std::hex << varDecl << " : " << ( varDecl ? varDecl->class_name() : "" ) << std::endl;
1779#endif
1780
1781 varDecl->set_firstNondefiningDeclaration(varDecl);
1782 varDecl->get_templateArguments() = tpl_args;
1783
1785 ROSE_ASSERT(variable != NULL);
1787
1788 if (name != "") {
1789 fixVariableDeclaration(varDecl, scope);
1790 }
1791
1792 SgInitializedName *initName = varDecl->get_decl_item (name);
1793 ROSE_ASSERT(initName);
1794 ROSE_ASSERT((initName->get_declptr()) != nullptr);
1795#if DEBUG__SageBuilder__buildTemplateVariableInstantiation_nfi
1796 std::cout << " initName = " << std::hex << initName << " : " << ( initName ? initName->class_name() : "" ) << std::endl;
1797#endif
1798
1799 SgVariableDefinition* variableDefinition_original = isSgVariableDefinition(initName->get_declptr());
1800 ROSE_ASSERT(variableDefinition_original != NULL);
1801 setOneSourcePositionNull(variableDefinition_original);
1802
1803 setOneSourcePositionNull(varDecl);
1804
1805 return varDecl;
1806 }
1807
1809SageBuilder::buildVariableDeclaration(const std::string & name, SgType* type, SgInitializer * varInit, SgScopeStatement* scope)
1810{
1811 SgName name2(name);
1812 return buildVariableDeclaration(name2,type, varInit,scope);
1813}
1814
1817{
1818 SgName name2(name);
1819 return buildVariableDeclaration(name2,type, varInit,scope);
1820}
1821
1824SageBuilder::buildTypedefDeclaration(const std::string& name, SgType* base_type, SgScopeStatement* scope /*= NULL*/, bool has_defining_base/*= false*/)
1825{
1826 SgTypedefDeclaration* type_decl = buildTypedefDeclaration_nfi(name, base_type, scope, has_defining_base);
1828
1829 return type_decl;
1830}
1831
1833// The side effects include: creating SgTypedefType, SgTypedefSymbol, and add SgTypedefType to the base type
1835SageBuilder::buildTypedefDeclaration_nfi(const std::string& name, SgType* base_type, SgScopeStatement* scope /*= NULL*/, bool has_defining_base/*=false*/)
1836 {
1837 ROSE_ASSERT (base_type != NULL);
1838
1839 if (scope == NULL )
1840 {
1842 }
1843
1844 // We don't yet support bottom up construction for this node yet
1845 ASSERT_not_null(scope);
1846
1847 SgDeclarationStatement* base_decl = nullptr;
1848
1849 // Handle the case where this is a pointer, reference, or typedef to another type.
1850 SgType* stripedBaseType = base_type->stripType();
1851 ASSERT_not_null(stripedBaseType);
1852
1853 SgNamedType* namedType = isSgNamedType(stripedBaseType);
1854 if (namedType)
1855 {
1856 // DQ (12/28/2019): the problem with getting the base declaration from the type is that it forces sharing
1857 // of the base declaration when the typedef has a defining declaration for a base type in multiple files.
1858
1859 // DQ (3/20/2012): Use this to set the value of base_decl (which was previously unset).
1860 // isSgNamedType(base_type)->get_declaration();
1861 // base_decl = isSgNamedType(base_type)->get_declaration();
1862 base_decl = namedType->get_declaration();
1863
1864 // DQ (3/20/2012): All named types should have a valid declaration!
1865 ROSE_ASSERT(base_decl != NULL);
1866 }
1867
1868 // DQ (3/20/2012): I don't remember why we need to provide the symbol for the scope of the
1869 // parent rather then the scope. But as I recall there was a special corner of C++ that
1870 // required this sort of support.
1871 SgSymbol* parent_scope = NULL;
1872#ifndef ROSE_USE_CLANG_FRONTEND
1873 if (scope != NULL)
1874 {
1875 ROSE_ASSERT(scope->get_parent() != NULL);
1876 SgDeclarationStatement* declaration = isSgDeclarationStatement(scope->get_parent());
1877
1878 // PP (3/9/22)
1879 // In Ada, discriminated type may not have been fully built yet.
1880 // this is because a the discriminated type obtains the name of the underlying
1881 // declaration.
1882 // PP (5/9/22)
1883 // Unsure if declaration link should be set at all for Ada.
1884 // The AstConsistencyTest flags typedefdecls with declaration link set...
1885 if (declaration && !isSgAdaDiscriminatedTypeDecl(declaration))
1886 {
1887 mprintf ("Found a valid declaration = %p = %s \n",declaration,declaration->class_name().c_str());
1888
1889 ROSE_ASSERT(SageInterface::is_Ada_language() || declaration->get_firstNondefiningDeclaration() != NULL);
1890
1891 parent_scope = declaration->search_for_symbol_from_symbol_table();
1892
1893 ROSE_ASSERT(parent_scope != NULL);
1894 }
1895 }
1896#endif
1897
1898 // Create the first nondefining declaration (note that the typedef type is always a NULL input value).
1899 SgTypedefDeclaration* type_decl = new SgTypedefDeclaration(SgName(name), base_type, NULL, base_decl, parent_scope);
1900 ROSE_ASSERT(type_decl != NULL);
1901
1902 // 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)
1903 type_decl->set_scope(scope);
1904 type_decl->set_parent(scope);
1905
1906 // DQ (2/27/2018): Add this call here to reflect change to the constructor semantics.
1907 type_decl->set_type(SgTypedefType::createType(type_decl));
1908
1909 // 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)).
1910 type_decl->set_firstNondefiningDeclaration (type_decl);
1911 type_decl->set_definingDeclaration(NULL);
1912
1913 // Set the source code position information.
1914 setOneSourcePositionNull(type_decl);
1915
1916 // Liao 11/29/2012, for typedef struct Frame {int x;} st_frame; We have to set parent for the struct.
1917 // AstPostProcessing() has resetParentPointers(). But it is kind of too late.
1918 if (SgClassDeclaration* base_class = isSgClassDeclaration(base_decl))
1919 {
1920 SgClassDeclaration* def_class = isSgClassDeclaration(base_class->get_definingDeclaration());
1921 SgClassDeclaration* nondef_class = isSgClassDeclaration(base_class->get_firstNondefiningDeclaration());
1922 // Dan and Liao, 12/3/2012, handle test2003_08.C nested typedef
1923 if (has_defining_base)
1924 {
1925 if (def_class != NULL)
1926 if (def_class->get_parent() == NULL)
1927 def_class->set_parent(type_decl);
1928 }
1929 else
1930 {
1931 if (nondef_class != NULL)
1932 if (nondef_class->get_parent() == NULL)
1933 {
1934 nondef_class->set_parent(type_decl);
1935 }
1936 }
1937 }
1938
1939 SgTypedefSymbol* typedef_symbol = new SgTypedefSymbol(type_decl);
1940 ROSE_ASSERT(typedef_symbol);
1941
1942 scope->insert_symbol(SgName(name),typedef_symbol);
1943
1944 return type_decl;
1945 }
1946
1947
1949SageBuilder::buildTemplateTypedefDeclaration_nfi(const SgName & name, SgType* base_type, SgScopeStatement* scope, bool has_defining_base )
1950 {
1951 // DQ (11/2/2014): Adding support for templated typedef.
1952
1953 ROSE_ASSERT (base_type != NULL);
1954
1955 if (scope == NULL )
1956 {
1958 }
1959
1960 // We don't yet support bottom up construction for this node yet
1961 ROSE_ASSERT(scope != NULL);
1962
1963 SgDeclarationStatement* base_decl = NULL;
1964
1965 // DQ (3/20/2012): I don't remember why we need to provide the symbol for the scope of the
1966 // parent rather then the scope. But as I recall there was a special corner of C++ that
1967 // required this sort of support.
1968 SgSymbol* parent_scope = NULL;
1969 if (scope != NULL)
1970 {
1971 ROSE_ASSERT(scope->get_parent() != NULL);
1972 SgDeclarationStatement* declaration = isSgDeclarationStatement(scope->get_parent());
1973
1974 if (declaration != NULL)
1975 {
1976 ROSE_ASSERT(declaration->get_firstNondefiningDeclaration() != NULL);
1977 parent_scope = declaration->search_for_symbol_from_symbol_table();
1978
1979 ROSE_ASSERT(parent_scope != NULL);
1980 }
1981 // 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.
1982 SgNamedType* namedType = isSgNamedType(base_type);
1983
1984 // DQ (3/4/2018): This might not always be true (sure enough it fails for Cxx11_tests/test2014_58.C).
1985
1986 if (namedType != NULL)
1987 {
1988 SgDeclarationStatement* declarationStatement = namedType->get_declaration();
1989
1990 // This might not always be true.
1991 ROSE_ASSERT(declarationStatement != NULL);
1992 if (declarationStatement != NULL)
1993 {
1994 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(declarationStatement);
1995 if (templateInstantiationDecl != NULL)
1996 {
1997 SgName name = templateInstantiationDecl->get_name();
1998 // DQ (2/28/2018): Added debugging to track down redundnat symbol.
1999 if (scope->lookup_template_typedef_symbol(name) != NULL)
2000 {
2001 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());
2002 }
2003 ROSE_ASSERT(scope->lookup_template_typedef_symbol(name) == NULL);
2004 }
2005 }
2006 }
2007 }
2008
2009 // We need to add the template parameter and partial specialization support to the SgTemplateTypedefDeclaration IR node.
2010 SgTemplateTypedefDeclaration* type_decl = new SgTemplateTypedefDeclaration(name, base_type, NULL, base_decl, parent_scope);
2011 ROSE_ASSERT(type_decl != NULL);
2012
2013 // 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)
2014 type_decl->set_scope(scope);
2015 type_decl->set_parent(scope);
2016
2017 // DQ (2/27/2018): We now have to set the type explicitly.
2018 ROSE_ASSERT(type_decl->get_type() == NULL);
2019
2020 SgTypedefType* typedefType = SgTypedefType::createType(type_decl);
2021 ROSE_ASSERT(typedefType != NULL);
2022
2023 // DQ (2/27/2018): It is an inconsistancy for the type to be set here.
2024 type_decl->set_type(typedefType);
2025
2026 // DQ (2/27/2018): This should be non-null, since we just built the new type.
2027 ROSE_ASSERT(type_decl->get_type() != NULL);
2028
2029 // 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)).
2030 type_decl->set_firstNondefiningDeclaration (type_decl);
2031 type_decl->set_definingDeclaration(NULL);
2032
2033 // Set the source code position information.
2034 setOneSourcePositionNull(type_decl);
2035
2036 // 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.
2037 SgNamedType* namedType = isSgNamedType(base_type);
2038
2039 // DQ (3/4/2018): This might not always be true (sure enough it fails for Cxx11_tests/test2014_58.C).
2040
2041 if (namedType != NULL)
2042 {
2043 SgDeclarationStatement* declarationStatement = namedType->get_declaration();
2044
2045 // This might not always be true.
2046 ROSE_ASSERT(declarationStatement != NULL);
2047 if (declarationStatement != NULL)
2048 {
2049 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(declarationStatement);
2050 if (templateInstantiationDecl != NULL)
2051 {
2052 SgName name = templateInstantiationDecl->get_name();
2053 // DQ (2/28/2018): Added debugging to track down redundnat symbol.
2054 if (scope->lookup_template_typedef_symbol(name) != NULL)
2055 {
2056 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());
2057 }
2058 ROSE_ASSERT(scope->lookup_template_typedef_symbol(name) == NULL);
2059 }
2060 }
2061 }
2062
2063 SgTemplateTypedefSymbol* typedef_symbol = new SgTemplateTypedefSymbol(type_decl);
2064 ROSE_ASSERT(typedef_symbol);
2065
2066 // DQ (5/16/2013): This is the code we want now that we have implemented the namespace support behind the scope symbol bable interface.
2067 scope->insert_symbol(name, typedef_symbol);
2068
2069 ROSE_ASSERT(scope->lookup_template_typedef_symbol(name) != NULL);
2070
2071 return type_decl;
2072 }
2073
2074#define DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi 0
2075
2078 SgName & name, SgType* base_type, SgScopeStatement* scope, bool has_defining_base,
2079 SgTemplateTypedefDeclaration* templateTypedefDeclaration,
2080 SgTemplateArgumentPtrList & templateArgumentsList
2081) {
2082#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2083 std::cout << "SageBuilder::buildTemplateInstantiationTypedefDeclaration_nfi" << std::endl;
2084 std::cout << " name = " << name.getString() << std::endl;
2085 std::cout << " base_type = " << std::hex << base_type << " : " << ( base_type ? base_type->class_name() : "" ) << std::endl;
2086#endif
2087 ROSE_ASSERT (base_type != NULL);
2088
2089 SgName nameWithoutTemplateArguments = name;
2090 SgName nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,templateArgumentsList);
2091#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2092 std::cout << " nameWithoutTemplateArguments = " << nameWithoutTemplateArguments.getString() << std::endl;
2093 std::cout << " nameWithTemplateArguments = " << nameWithTemplateArguments.getString() << std::endl;
2094#endif
2095
2096 // We don't yet support bottom up construction for this node yet
2097 ROSE_ASSERT(scope != NULL);
2098
2099 SgDeclarationStatement* base_decl = NULL;
2100
2101 // DQ (3/20/2012): I don't remember why we need to provide the symbol for the scope of the
2102 // parent rather then the scope. But as I recall there was a special corner of C++ that
2103 // required this sort of support.
2104 SgSymbol* parent_scope = NULL;
2105 if (scope != NULL)
2106 {
2107 ROSE_ASSERT(scope->get_parent() != NULL);
2108 SgDeclarationStatement* declaration = isSgDeclarationStatement(scope->get_parent());
2109 if (declaration != NULL)
2110 {
2111 ROSE_ASSERT(declaration->get_firstNondefiningDeclaration() != NULL);
2112 parent_scope = declaration->search_for_symbol_from_symbol_table();
2113
2114 ROSE_ASSERT(parent_scope != NULL);
2115 }
2116 }
2117
2118 // DQ (11/5/2014): I think this might be set afterward.
2119 ROSE_ASSERT(templateTypedefDeclaration != NULL);
2120
2121 SgTemplateTypedefSymbol* prexisting_template_typedef_symbol = scope->lookup_template_typedef_symbol(nameWithTemplateArguments);
2122 if (prexisting_template_typedef_symbol != NULL)
2123 {
2124 SgDeclarationStatement* declarationStatement = prexisting_template_typedef_symbol->get_declaration();
2125 ROSE_ASSERT(declarationStatement != NULL);
2126#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2127 std::cout << " declarationStatement = " << declarationStatement << " : " << declarationStatement->class_name() << std::endl;
2128#endif
2129 SgTemplateInstantiationTypedefDeclaration* return_declaration = isSgTemplateInstantiationTypedefDeclaration(declarationStatement);
2130 ROSE_ASSERT(return_declaration != NULL);
2131 return return_declaration;
2132 }
2133 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == NULL);
2134
2135 // DQ (2/25/2018): Not clear if we want to use the template name with arguments.
2136 // Calling: SgTemplateInstantiationTypedefDeclaration(SgName, SgType*, SgTypedefType*, SgDeclarationStatement*, SgSymbol*, SgTemplateTypedefDeclaration*, SgTemplateArgumentPtrList)
2137 SgTypedefType* typedefType = NULL;
2139 new SgTemplateInstantiationTypedefDeclaration(nameWithTemplateArguments, base_type, typedefType, base_decl, parent_scope, templateTypedefDeclaration, templateArgumentsList);
2140 ROSE_ASSERT(type_decl != NULL);
2141 ROSE_ASSERT(type_decl->get_base_type() == base_type);
2142
2143#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2144 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2145 std::cout << " ->get_base_type() = " << std::hex << type_decl->get_base_type() << " : " << ( type_decl->get_base_type() ? type_decl->get_base_type()->class_name() : "" ) << std::endl;
2146#endif
2147
2148 // DQ (2/27/2018): This is a change in the constructor semantics, we now have to build the type explicitly.
2149 // printf ("We now have to build the type explicitly \n");
2150 ROSE_ASSERT(type_decl->get_type() == NULL);
2151
2152
2153 // DQ (2/27/2018): Set the template name that this instantiation is using.
2154 type_decl->set_templateName(nameWithoutTemplateArguments);
2155
2156 ROSE_ASSERT(scope != NULL);
2157 type_decl->set_scope(scope);
2158
2159 // DQ (3/1/2018): A bug in the name of the template with arguments has been detected (extra spaces in
2160 // the name generated by type_decl->resetTemplateName()), make sure that we have a consistant naming.
2161 ROSE_ASSERT(type_decl->get_name() == nameWithTemplateArguments);
2162
2163 // DQ (2/28/2018): Added debugging to track down redundnat symbol.
2164 if (scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != NULL)
2165 {
2166 printf ("Error: it appears that there is already a symbol in scope = %p = %s for name = %s \n",scope,scope->class_name().c_str(),name.str());
2167 }
2168 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == NULL);
2169
2170
2171 // DQ (2/26/2018): Can we assert this?
2172 ROSE_ASSERT(type_decl->get_type() == NULL);
2173
2174 SgTypedefType* new_typedefType = SgTypedefType::createType(type_decl);
2175 ROSE_ASSERT(new_typedefType != NULL);
2176
2177 type_decl->set_type(new_typedefType);
2178 ROSE_ASSERT(type_decl->get_type() != NULL);
2179 ROSE_ASSERT(type_decl->get_scope() != NULL);
2180
2181 type_decl->set_firstNondefiningDeclaration (type_decl);
2182 type_decl->set_definingDeclaration(NULL);
2183
2184 setOneSourcePositionNull(type_decl);
2185
2186 setTemplateArgumentsInDeclaration(type_decl,&templateArgumentsList);
2187
2188 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() != NULL);
2189 ROSE_ASSERT(type_decl->get_definingDeclaration() == NULL);
2190 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() == type_decl);
2191
2192 ROSE_ASSERT(type_decl->get_type() != NULL);
2193 ROSE_ASSERT(scope != NULL);
2194
2195#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2196 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2197 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;
2198#endif
2199
2200 if (scope != NULL)
2201 {
2202 if (scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != NULL)
2203 {
2204 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());
2205 }
2206 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) == NULL);
2207
2208 SgTemplateTypedefSymbol* typedef_symbol = new SgTemplateTypedefSymbol(type_decl);
2209 ROSE_ASSERT(typedef_symbol);
2210
2211 scope->insert_symbol(nameWithTemplateArguments,typedef_symbol);
2212 type_decl->set_scope(scope);
2213 type_decl->set_parent(scope);
2214 ROSE_ASSERT(scope->lookup_template_typedef_symbol(nameWithTemplateArguments) != NULL);
2215 }
2216
2217#if DEBUG__SageBuilder__buildTemplateInstantiationTypedefDeclaration_nfi
2218 std::cout << " type_decl = " << std::hex << type_decl << " : " << ( type_decl ? type_decl->class_name() : "" ) << std::endl;
2219 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;
2220#endif
2221
2222 return type_decl;
2223 }
2224
2225
2226
2227
2228
2229//-----------------------------------------------
2230// Assertion `definingDeclaration != NULL || firstNondefiningDeclaration != NULL'
2233{
2234 SgFunctionParameterList *parameterList = new SgFunctionParameterList();
2235 ROSE_ASSERT (parameterList);
2236
2237 parameterList->set_definingDeclaration (NULL);
2238 parameterList->set_firstNondefiningDeclaration (parameterList);
2239
2241
2242 if (in1) appendArg(parameterList, in1);
2243 if (in2) appendArg(parameterList, in2);
2244 if (in3) appendArg(parameterList, in3);
2245 if (in4) appendArg(parameterList, in4);
2246 if (in5) appendArg(parameterList, in5);
2247 if (in6) appendArg(parameterList, in6);
2248 if (in7) appendArg(parameterList, in7);
2249 if (in8) appendArg(parameterList, in8);
2250 if (in9) appendArg(parameterList, in9);
2251 if (in10) appendArg(parameterList, in10);
2252
2253 return parameterList;
2254}
2255
2258 SgFunctionParameterList *parameterList = new SgFunctionParameterList();
2259 ROSE_ASSERT (parameterList);
2260 parameterList->set_definingDeclaration (NULL);
2261 parameterList->set_firstNondefiningDeclaration (parameterList);
2262
2263 setOneSourcePositionNull(parameterList);
2264
2265 return parameterList;
2266}
2267
2268//-----------------------------------------------
2271 SgCtorInitializerList *ctorInitList = new SgCtorInitializerList();
2272 ROSE_ASSERT (ctorInitList);
2273 ctorInitList->set_definingDeclaration (NULL);
2274 ctorInitList->set_firstNondefiningDeclaration (ctorInitList);
2275
2276 setOneSourcePositionNull(ctorInitList);
2277
2278 return ctorInitList;
2279}
2280
2281//-----------------------------------------------
2282// no type vs. void type ?
2285 {
2286 // DQ (8/19/2012): I am not a fan of this sort of codeing style either (NULL pointers as inputs should be an error).
2287 if (paralist == NULL)
2288 {
2289 printf ("WARNING: In buildFunctionParameterTypeList(): Accepting NULL input and returning NULL pointer. \n");
2290
2291 return NULL;
2292 }
2293
2294 // 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).
2295 // if (paralist->get_args().size()==0)
2296 // return NULL;
2297
2299 ROSE_ASSERT(typePtrList != NULL);
2300
2301 SgInitializedNamePtrList args = paralist->get_args();
2302 SgInitializedNamePtrList::const_iterator i;
2303 for(i = args.begin(); i != args.end(); i++)
2304 (typePtrList->get_arguments()).push_back( (*i)->get_type() );
2305
2307
2308 return typePtrList;
2309 }
2310
2311
2314 {
2315 if (expList ==NULL) return NULL;
2316 SgExpressionPtrList expPtrList = expList->get_expressions();
2317
2319 ROSE_ASSERT(typePtrList);
2320
2321 SgExpressionPtrList::const_iterator i;
2322 for (i=expPtrList.begin();i!=expPtrList.end();i++)
2323 {
2324 typePtrList->get_arguments().push_back( (*i)->get_type() );
2325 }
2326
2328
2329 return typePtrList;
2330 }
2331
2334 SgType* type4, SgType* type5, SgType* type6, SgType* type7)
2335 {
2337 ROSE_ASSERT(typePtrList);
2338
2339 SgTypePtrList & types = typePtrList->get_arguments();
2340
2341 if (type0 != NULL) types.push_back(type0);
2342 if (type1 != NULL) types.push_back(type1);
2343 if (type2 != NULL) types.push_back(type2);
2344 if (type3 != NULL) types.push_back(type3);
2345 if (type4 != NULL) types.push_back(type4);
2346 if (type5 != NULL) types.push_back(type5);
2347 if (type6 != NULL) types.push_back(type6);
2348 if (type7 != NULL) types.push_back(type7);
2349
2350 return typePtrList;
2351 }
2352
2353//-----------------------------------------------
2354// build function type,
2355//
2356// insert into symbol table when not duplicated
2359 {
2360 ROSE_ASSERT(return_type != NULL);
2361
2362 // DQ (8/19/2012): Can we enforce this?
2363 ROSE_ASSERT(typeList != NULL);
2364
2366 ROSE_ASSERT(fTable);
2367
2368 // This function make clever use of a static member function which can't be built
2369 // for the case of a SgMemberFunctionType (or at least not without more work).
2370 SgName typeName = SgFunctionType::get_mangled(return_type, typeList);
2371
2372 SgFunctionType* funcType = isSgFunctionType(fTable->lookup_function_type(typeName));
2373
2374 if (funcType == NULL)
2375 {
2376 // Only build the new type if it can't be found in the global type table.
2377 funcType = new SgFunctionType(return_type, false);
2378 ROSE_ASSERT(funcType);
2379
2380 if (typeList != NULL)
2381 {
2382 // DQ (12/5/2012): We want to avoid overwriting an existing SgFunctionParameterTypeList. Could be related to failing tests for AST File I/O.
2383 if (funcType->get_argument_list() != NULL)
2384 {
2385 delete funcType->get_argument_list();
2386 funcType->set_argument_list(NULL);
2387 }
2388 ROSE_ASSERT(funcType->get_argument_list() == NULL);
2389
2390 funcType->set_argument_list(typeList);
2391 typeList->set_parent(funcType);
2392 }
2393
2394 fTable->insert_function_type(typeName,funcType);
2395 }
2396 else
2397 {
2398 // DQ (12/6/2012): Tracking down orphaned SgFunctionParameterTypeList objects.
2399 }
2400
2401 return funcType;
2402 }
2403
2405SageBuilder::buildMemberFunctionType(SgType* return_type, SgFunctionParameterTypeList* typeList, SgType *classType, unsigned int mfunc_specifier)
2406 {
2407 // DQ (8/19/2012): This is a refactored version of the buildMemberFunctionType() below so that we can
2408 // isolate out the part that uses a SgClassType from the version that uses the SgClassDefinition.
2409
2410 // Maintain the global type table
2412 ROSE_ASSERT(fTable != NULL);
2413 ROSE_ASSERT(typeList != NULL);
2414
2415 SgName typeName = SgMemberFunctionType::get_mangled(return_type,typeList,classType,mfunc_specifier);
2416 SgType* typeInTable = fTable->lookup_function_type(typeName);
2417
2418 SgMemberFunctionType* funcType = NULL;
2419 if (typeInTable == NULL)
2420 {
2421 bool has_ellipses = false;
2422 // PP (10/4/22): removing ref_qualifiers
2423 SgPartialFunctionType* partialFunctionType = new SgPartialFunctionType(return_type, has_ellipses, classType, mfunc_specifier);
2424 ROSE_ASSERT(partialFunctionType != NULL);
2425
2426 // DQ (12/5/2012): We want to avoid overwriting an existing SgFunctionParameterTypeList. Could be related to failing tests for AST File I/O.
2427 if (partialFunctionType->get_argument_list() != NULL)
2428 {
2429 delete partialFunctionType->get_argument_list();
2430 partialFunctionType->set_argument_list(NULL);
2431 }
2432 ROSE_ASSERT(partialFunctionType->get_argument_list() == NULL);
2433
2434 typeList->set_parent(partialFunctionType);
2435
2436 // DQ (12/6/2012): Set the SgFunctionParameterTypeList in the SgPartialFunctionType before trying
2437 // to build a SgMemberFunctionType (not critical that it be set before, but might be in the future,
2438 // but it is important that it be set).
2439 partialFunctionType->set_argument_list(typeList);
2440
2441 ROSE_ASSERT(partialFunctionType->get_argument_list() != NULL);
2442
2443 // The optional_fortran_type_kind is only required for Fortran support.
2444 SgExpression* optional_fortran_type_kind = NULL;
2445 funcType = SgMemberFunctionType::createType(partialFunctionType, optional_fortran_type_kind);
2446
2447 // DQ (12/13/2012): Remove the SgPartialFunctionType after it has been used to build the SgMemberFunctionType.
2448 // I would rather modify the SgMemberFunctionType::createType() API so that we didn't use the SgPartialFunctionType IR nodes.
2449 // First we have to reset the pointer to the type argument list to NULL since it is shared with the SgMemberFunctionType.
2450 partialFunctionType->set_argument_list(NULL);
2451
2452 // Then we can delete the SgPartialFunctionType.
2453 delete partialFunctionType;
2454 partialFunctionType = NULL;
2455
2456 // This is perhaps redundant since it was set to a derived class (but might be an important distiction).
2457 typeList->set_parent(funcType);
2458
2459 ROSE_ASSERT(funcType->get_argument_list() != NULL);
2460 }
2461
2462 if (typeInTable == nullptr)
2463 {
2464 ASSERT_not_null(funcType);
2465 fTable->insert_function_type(typeName,funcType);
2466 }
2467 else
2468 {
2469 // DQ (12/3/2011): Added this case to support reuse of function types (not handled by the createType functions).
2470 // Delete the one generated so that we could form the mangled name.
2471 ASSERT_require(typeInTable != funcType);
2472 delete funcType;
2473
2474 // Return the one from the global type table.
2475 funcType = isSgMemberFunctionType(typeInTable);
2476 ASSERT_not_null(funcType);
2477 }
2478
2479 return funcType;
2480 }
2481
2482
2483// DQ (1/4/2009): Need to finish this!!!
2484//-----------------------------------------------
2485// build member function type,
2486//
2487// insert into symbol table when not duplicated
2489SageBuilder::buildMemberFunctionType(SgType* return_type, SgFunctionParameterTypeList* typeList, SgScopeStatement * struct_name, unsigned int mfunc_specifier)
2490 {
2491 // This function has to first build a version of the SgMemberFunctionType so that it can generate a mangled name.
2492 // If the mangled name can be use to lookup a SgMemberFunctionType then the "just built" SgMemberFunctionType
2493 // is deleted and the one from the global function type table is returned. This fixes a lot of subtle C++
2494 // specific issues with the build interface and it's use with the newer EDG 4.3 connection to ROSE.
2495
2496 ROSE_ASSERT(return_type != NULL);
2497 ROSE_ASSERT(struct_name != NULL);
2498 ROSE_ASSERT(struct_name->get_parent() != NULL);
2499
2500 SgClassDefinition* classDefinition = isSgClassDefinition(struct_name);
2501 SgDeclarationScope* decl_scope = isSgDeclarationScope(struct_name);
2502
2503 if (classDefinition == NULL && decl_scope == NULL)
2504 {
2505 printf ("Error: (classDefinition == NULL && decl_scope == NULL): struct_name = %p = %s name = %s \n",
2506 struct_name,struct_name->class_name().c_str(),SageInterface::get_name(struct_name).c_str());
2507 }
2508 ROSE_ASSERT(classDefinition != NULL || decl_scope != NULL);
2509
2510 SgDeclarationStatement* declaration = NULL;
2511 if (classDefinition != NULL)
2512 {
2513 declaration = classDefinition->get_declaration();
2514 }
2515 else if (decl_scope != NULL)
2516 {
2517 declaration = isSgDeclarationStatement(decl_scope->get_parent());
2518 }
2519 else
2520 {
2521 ROSE_ABORT();
2522 }
2523
2524 ROSE_ASSERT(declaration != NULL);
2525
2526 if (typeList == nullptr) {
2527 printf ("WARNING: typeList == NULL \n");
2528 }
2529
2530 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
2531 SgNonrealDecl * nrdecl = isSgNonrealDecl(declaration);
2532
2533 ROSE_ASSERT(classDeclaration != NULL || nrdecl != NULL);
2534
2535 SgType* classType = NULL;
2536 if (classDeclaration != NULL)
2537 {
2538 classType = classDeclaration->get_type();
2539 }
2540 else if (decl_scope != NULL)
2541 {
2542 classType = nrdecl->get_type();
2543 }
2544 else
2545 {
2546 ROSE_ABORT();
2547 }
2548 ROSE_ASSERT(classType != NULL);
2549
2550 return buildMemberFunctionType(return_type,typeList,classType,mfunc_specifier);
2551 }
2552
2555 {
2556 ROSE_ASSERT(base_type != NULL);
2557
2558 ROSE_ASSERT(classType != NULL);
2559 SgPointerMemberType* pointerToMemberType = new SgPointerMemberType(base_type,classType);
2560 return pointerToMemberType;
2561 }
2562
2563//----------------------------------------------------
2565SgType * SageBuilder::buildOpaqueType(std::string const name, SgScopeStatement * scope)
2566{
2567 // we require users to specify a target scope
2568 ASSERT_not_null(scope);
2569 SgTypedefDeclaration* type_decl = NULL;
2570 SgTypedefType* result = NULL;
2571
2572 // Liao and Greg Bronevetsky , 8/27/2009
2573 // patch up the symbol
2574 // and avoid duplicated creation
2575 // TODO a function like fixTypeDeclaration() (similar to SageInterface::fixVariableDeclaration()) for this
2576 SgTypedefSymbol* type_symbol = scope->lookup_typedef_symbol(name);
2577 if (type_symbol == NULL)
2578 {
2579 type_decl = new SgTypedefDeclaration(name,buildIntType(),NULL, NULL, NULL);
2580 ASSERT_not_null(type_decl);
2581
2582 type_decl->set_scope(scope); // PP (05/29/25): set the scope of the decl
2583
2584 // DQ (2/27/2018): Add this call here to reflect change to the constructor semantics.
2585 type_decl->set_type(SgTypedefType::createType(type_decl));
2586
2587 type_symbol = new SgTypedefSymbol(type_decl);
2588 ROSE_ASSERT(type_symbol);
2589 SgName n = name;
2590
2591 // DQ (5/21/2013): The symbol table should only be accessed through the SgScopeStatement interface.
2592 scope->insert_symbol(n,type_symbol);
2593
2594 type_decl->set_firstNondefiningDeclaration (type_decl);
2596 prependStatement(type_decl,scope);
2597 // Hide it from unparser
2598 Sg_File_Info* file_info = type_decl->get_file_info();
2599 file_info->unsetOutputInCodeGeneration ();
2600 result = new SgTypedefType(type_decl); // QUESTION: PP: why do not we return type_decl->get_type()?
2601 }
2602 else
2603 {
2604 type_decl = type_symbol->get_declaration();
2605 result = type_decl->get_type();
2606 }
2607 ASSERT_not_null(result);
2608 return result;
2609}
2610
2611
2612//----------------- function type------------
2613// same function declarations (defining or nondefining) should share the same function type!
2616 {
2617 ASSERT_not_null(argList);
2618
2620 SgFunctionType* func_type = buildFunctionType(return_type, typeList);
2621
2622 if (func_type->get_argument_list() != typeList)
2623 {
2624 delete typeList;
2625 typeList = NULL;
2626 }
2627
2628 return func_type;
2629 }
2630
2631void
2632checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope ( SgDeclarationStatement* func, SgScopeStatement* scope )
2633 {
2634 // DQ (12/14/2011): We need the parent to be set so that we can call some of the test functions
2635 // (e.g assert that get_class_scope() for member functions). So we set the parent to the scope
2636 // by default and see if this will work, else we could disable to assertion that the parent is
2637 // non-null in the get_class_scope() member function.
2638
2639 if (isSgMemberFunctionDeclaration(func) != NULL)
2640 {
2641#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
2642 printf ("WARNING: setting parent of function to match scope by default \n");
2643#endif
2644 func->set_parent(scope);
2645
2646 ROSE_ASSERT(scope != NULL);
2647
2648 if (isSgTemplateInstantiationMemberFunctionDecl(func) != NULL)
2649 {
2650 // DQ (12/14/2011): We should not have a member function template instantiation in a template class definition.
2651
2652 // DQ (8/25/2014): Un-Commented out to revert to previous working state.
2653 // DQ (8/25/2014): Commented out to test new logic at base of isTemplateDeclaration(a_routine_ptr).
2654 // DQ (8/25/2014): Un-Commented out to revert to previous working state.
2655 // DQ (8/25/2014): Allow non-template functions in a template class declaration (see test2014_161.C).
2656#if !ENFORCE_NO_FUNCTION_TEMPLATE_DECLARATIONS_IN_TEMPLATE_CLASS_INSTANTIATIONS
2657 // 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");
2658#endif
2659 }
2660 }
2661 else
2662 {
2663 if (isSgTemplateFunctionDeclaration(func) != NULL)
2664 {
2665 if (isSgTemplateInstantiationMemberFunctionDecl(func) != NULL)
2666 {
2667 ROSE_ASSERT(isSgTemplateClassDefinition(scope) != NULL);
2668 }
2669 }
2670 }
2671 }
2672
2673//----------------- function declaration------------
2674// considering
2675// 1. fresh building
2676// 2. secondary building after another nondefining functiondeclaration
2677// 3. secondary building after another defining function declaration
2678// 4. fortran ?
2679template <class actualFunction>
2680actualFunction*
2681SageBuilder::buildNondefiningFunctionDeclaration_T (
2682 const SgName & XXX_name, SgType* return_type, SgFunctionParameterList * paralist, bool isMemberFunction,
2683 SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags,
2684 SgTemplateArgumentPtrList* templateArgumentsList, SgTemplateParameterPtrList* templateParameterList,
2686) {
2687 // DQ (11/25/2011): This function has been modified to work when used with a SgTemplateFunctionDeclaration as a template argument.
2688 // It was originally designed to work with only SgFunctionDeclaration and SgMemberFunctionDeclaration, it now works with these
2689 // plus SgTemplateFunctionDeclaration and SgTemplateMemberonDeclaration IR nodes. This is part of providing new support for template
2690 // declarations in the AST and a general update of this function to support this expanded use.
2691
2692 // 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.
2693
2694 // argument verification
2695 if (scope == nullptr)
2696 {
2698 }
2699 ASSERT_not_null(scope);
2700
2701 if (XXX_name.is_null() == true)
2702 {
2703 // DQ (4/2/2013): This case is generated for test2013_86.C.
2704 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");
2705 }
2706
2707 SgName nameWithoutTemplateArguments = XXX_name;
2708 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
2709
2710 bool buildTemplateInstantiation = ((VariantT)actualFunction::static_variant == V_SgTemplateInstantiationFunctionDecl || (VariantT)actualFunction::static_variant == V_SgTemplateInstantiationMemberFunctionDecl);
2711
2712 // DQ (8/7/2013): Added support for template declarations.
2713 bool buildTemplateDeclaration = ((VariantT)actualFunction::static_variant == V_SgTemplateFunctionDeclaration || (VariantT)actualFunction::static_variant == V_SgTemplateMemberFunctionDeclaration);
2714
2715 // DQ (8/7/2013): Added support for template declarations (need to handle template names overloaded on template parameters).
2716 // We want to use the template arguments in the symbol table lookup, but not in the name generation.
2717 if (buildTemplateInstantiation == true)
2718 {
2719 ASSERT_not_null(templateArgumentsList);
2720 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
2721 }
2722
2723 // this function is also called when building a function reference before the function declaration exists. So, skip the check
2724 if (nameWithTemplateArguments.is_null() == true)
2725 {
2726 // DQ (3/25/2017): Modified to use message logging.
2727 // DQ (4/2/2013): This case is generated for test2013_86.C.
2728 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");
2729 }
2730
2731 if (nameWithoutTemplateArguments.is_null() == true)
2732 {
2733 // DQ (3/25/2017): Modified to use message logging.
2734 // DQ (4/2/2013): This case is generated for test2013_86.C.
2735 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");
2736 }
2737
2738 ASSERT_not_null(return_type);
2739 ASSERT_not_null(paralist);
2740
2741 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
2742 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
2743 if (SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == true)
2744 {
2745#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
2746 printf ("Warning: In buildNondefiningFunctionDeclaration_T(): nameWithoutTemplateArguments = %s nameWithTemplateArguments = %s \n",nameWithoutTemplateArguments.str(),nameWithTemplateArguments.str());
2747#endif
2748 }
2749 // DQ (7/27/2012): There are reasons why this can fail: e.g. for functions with names such as:
2750 // "operator std::auto_ptr_ref<_Tp1>" which is a user defined conversion operator to one class from another.
2751
2752 // tentatively build a function type, since it is shared
2753 // by all prototypes and defining declarations of a same function!
2754
2755 SgFunctionType* func_type = nullptr;
2756 if (isMemberFunction == true)
2757 {
2759 func_type = buildMemberFunctionType(return_type,typeList,scope, functionConstVolatileFlags);
2760 }
2761 else
2762 {
2763 func_type = buildFunctionType(return_type,paralist);
2764 }
2765
2766 ASSERT_not_null(func_type);
2767
2768 // function declaration
2769 actualFunction* func = nullptr;
2770
2771 // search before using the function type to create the function declaration
2772 // TODO only search current scope or all ancestor scope?? (DQ: Only current scope!)
2773 // We don't have lookup_member_function_symbol yet
2774
2775 // DQ (12/27/2011): Under the new design we can make the symbol type SgFunctionSymbol instead of the less specific SgSymbol.
2776 // DQ (11/25/2011): We want to add the support for template function declarations,
2777 // so this should be a SgSymbol so that we can have it be either a SgFunctionSymbol
2778 // or a SgTemplateSymbol.
2779 SgFunctionSymbol* func_symbol = NULL;
2780
2781 if (scope != NULL)
2782 {
2783 // DQ (3/13/2012): Experiment with new function to support only associating the right type of symbol with the
2784 // function being built. I don't think I like the design of this interface, but we might change that later.
2785
2786 // 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.
2787 func_symbol = scope->find_symbol_by_type_of_function<actualFunction>(nameWithTemplateArguments,func_type,templateParameterList,templateArgumentsList);
2788
2789 // If not a proper function (or instantiated template function), then check for a template function declaration.
2790 if (func_symbol == NULL)
2791 {
2792 // Note that a template function does not have a function type (just a name).
2793 ROSE_ASSERT(func_type != NULL);
2794 }
2795 }
2796
2797 if (func_symbol != NULL)
2798 {
2799 switch((VariantT)actualFunction::static_variant)
2800 {
2801 case V_SgFunctionDeclaration:
2802 case V_SgProcedureHeaderStatement:
2803 case V_SgTemplateInstantiationFunctionDecl:
2804 {
2805 ROSE_ASSERT(isSgFunctionSymbol(func_symbol) != NULL);
2806 break;
2807 }
2808 case V_SgMemberFunctionDeclaration:
2809 case V_SgTemplateInstantiationMemberFunctionDecl:
2810 {
2811 ROSE_ASSERT(isSgMemberFunctionSymbol(func_symbol) != NULL);
2812 break;
2813 }
2814 case V_SgTemplateFunctionDeclaration:
2815 {
2816 ROSE_ASSERT(isSgTemplateFunctionSymbol(func_symbol) != NULL);
2817 break;
2818 }
2819 case V_SgTemplateMemberFunctionDeclaration:
2820 {
2821 ROSE_ASSERT(isSgTemplateMemberFunctionSymbol(func_symbol) != NULL);
2822 break;
2823 }
2824
2825 default:
2826 {
2827 printf ("default reach in buildNondefiningFunctionDeclaration_T(): variantT(actualFunction::static_variant) = %d \n",actualFunction::static_variant);
2828 ROSE_ABORT();
2829 }
2830 }
2831
2832 // TV (2/5/14): Found symbol might come from another file, in this case we need to insert it in the current scope.
2833 // Can only happen when scope is a global scope
2834 ROSE_ASSERT(scope != NULL);
2835 if ( isSgGlobal(scope) != NULL
2836 && scope != func_symbol->get_scope()
2837 && !SageInterface::isAncestor(scope, func_symbol->get_scope())
2838 && !scope->symbol_exists(nameWithTemplateArguments, func_symbol) )
2839 {
2840 scope->insert_symbol(nameWithTemplateArguments, func_symbol);
2841 }
2842 }
2843
2844 if (func_symbol == NULL)
2845 {
2846 func = new actualFunction (nameWithTemplateArguments,func_type,NULL);
2847 ROSE_ASSERT(func != NULL);
2848
2849 // Storage modifier (esp. static) must be set before inserting symbol
2850 func->get_declarationModifier().get_storageModifier().set_modifier(sm);
2851
2852 // DQ (5/1/2012): This should always be true.
2853 ROSE_ASSERT(func->get_file_info() == NULL);
2854
2855 // DQ (12/14/2011): Moved this from lower in this function.
2856 func->set_scope(scope);
2857
2858 // DQ (12/15/2011): Added test.
2859 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(func,scope);
2860
2861 // This fails below for a SgTemplateFunctionDeclaration, so test it here.
2862 ROSE_ASSERT(func->get_parameterList() != NULL);
2863
2864 // NOTE: we want to allow the input scope to be NULL (and even the SageBuilder::topScopeStack() == NULL)
2865 // so that function can be built bottom up style. However this means that the symbol tables in the
2866 // scope of the returned function declaration will have to be setup separately.
2867 if (scope != NULL)
2868 {
2869 // function symbol table
2870 if (isSgMemberFunctionDeclaration(func))
2871 {
2872 // DQ (11/23/2011): This change allows this to compile for where SgTemplateFunctionDeclarations are used. I have
2873 // not decided if template declarations should cause symbols to be generated for functions and member functions.
2874 // func_symbol = new SgMemberFunctionSymbol(func);
2875 if (isSgTemplateMemberFunctionDeclaration(func) != NULL)
2876 func_symbol = new SgTemplateMemberFunctionSymbol(isSgTemplateMemberFunctionDeclaration(func));
2877 else
2878 {
2879 SgMemberFunctionDeclaration* memberFunctionDeclaration = isSgMemberFunctionDeclaration(func);
2880 ROSE_ASSERT(memberFunctionDeclaration != NULL);
2881 func_symbol = new SgMemberFunctionSymbol(memberFunctionDeclaration);
2882 }
2883
2884 ROSE_ASSERT(func_symbol != NULL);
2885 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
2886 }
2887 else
2888 {
2889 // if (isSgFunctionDeclaration(func))
2890 if (isSgTemplateFunctionDeclaration(func))
2891 {
2892 // How should we handled template functions in the symbol table???
2893 // DQ (11/24/2011): After some thought, I think that template declarations for function are more template declarations
2894 // than functions. So all template function declarations will be handled as SgTemplateSymbols and not SgFunctionSymbols.mplate function declarations.
2895 SgTemplateFunctionDeclaration* templatedeclaration = isSgTemplateFunctionDeclaration(func);
2896 ROSE_ASSERT(templatedeclaration != NULL);
2897 SgTemplateFunctionSymbol* template_symbol = new SgTemplateFunctionSymbol(templatedeclaration);
2898 ROSE_ASSERT(template_symbol != NULL);
2899 ROSE_ASSERT(template_symbol->get_symbol_basis() != NULL);
2900 func_symbol = template_symbol;
2901 }
2902 else
2903 {
2904 func_symbol = new SgFunctionSymbol(isSgFunctionDeclaration(func));
2905 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
2906 }
2907 }
2908
2909 ROSE_ASSERT(func_symbol != NULL);
2910 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
2911 scope->insert_symbol(nameWithTemplateArguments, func_symbol);
2912
2913 ROSE_ASSERT(func->get_symbol_from_symbol_table() != NULL);
2914
2915 if (isSgFunctionDeclaration(func) == NULL)
2916 {
2917 // DQ (12/18/2011): If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
2918 // DQ (8/12/2013): Added template parameter list.
2919 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
2920 // In this case these are unavailable from this point.
2921 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
2922 }
2923
2924 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
2925 // In this case these are unavailable from this point.
2926 // DQ (11/25/2011): Added support for template functions.
2927 // DQ (2/26/2009): uncommented assertion.
2928 // Did not pass for member function? Should we have used the mangled name?
2929 ROSE_ASSERT(buildTemplateDeclaration == false || templateParameterList != NULL);
2930
2931 // DQ (8/13/2013): We need to test for function symbols (which will include member function symbols),
2932 // template functions and template member functions. Each must be tested for seperately because template
2933 // functions and template member functions are not connected to derivation which non-template functions
2934 // and non-template member functions are connected through derivation.
2935 ROSE_ASSERT(scope->lookup_function_symbol(nameWithTemplateArguments) != NULL ||
2936 scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL ||
2937 scope->lookup_template_member_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
2938
2939#if BUILDER_MAKE_REDUNDANT_CALLS_TO_SYMBOL_TABLE_LOOKUP
2940 // if (scope->lookup_function_symbol(name) == NULL || scope->lookup_template_symbol(name) != NULL)
2941 // if (scope->lookup_function_symbol(nameWithTemplateArguments) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments) != NULL)
2942 // if (scope->lookup_function_symbol(nameWithTemplateArguments) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments,NULL,NULL) != NULL)
2943 if (scope->lookup_function_symbol(nameWithTemplateArguments,templateArgumentList) == NULL || scope->lookup_template_symbol(nameWithTemplateArguments,templateParameterList,NULL) != NULL)
2944 {
2945 // Make sure this is a template function declaration...
2946 printf ("Need to make sure this is a template function declaration... \n");
2947 }
2948#endif
2949 }
2950
2951 // DQ (12/14/2011): Added test.
2952 ROSE_ASSERT(func->get_scope() != NULL);
2953
2954 if (isSgFunctionDeclaration(func) == NULL)
2955 {
2956 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
2957
2958 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
2959 // In this case these are unavailable from this point.
2960 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
2961 }
2962 func->set_firstNondefiningDeclaration(func);
2963 func->set_definingDeclaration(NULL);
2964
2965 // DQ (5/8/2016): We need to test the first defining declaration that we used.
2966 ROSE_ASSERT(func->get_firstNondefiningDeclaration() == func);
2967
2968 ROSE_ASSERT(func->get_definingDeclaration() == NULL);
2969
2970 // DQ (12/14/2011): Error checking
2971 SgTemplateInstantiationMemberFunctionDecl* testMemberDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
2972 if (testMemberDecl != NULL)
2973 {
2974 ROSE_ASSERT(testMemberDecl->get_scope() != NULL);
2975 ROSE_ASSERT(testMemberDecl->get_class_scope() != NULL);
2976 ROSE_ASSERT(testMemberDecl->get_associatedClassDeclaration() != NULL);
2977 }
2978 }
2979 else
2980 {
2981 ROSE_ASSERT(func_symbol != NULL);
2982
2983 ROSE_ASSERT(scope != NULL);
2984
2985 // 2nd, or 3rd... prototype declaration
2986 // reuse function type, function symbol of previous declaration
2987
2988 // std::cout<<"debug:SageBuilder.C: 267: "<<"found func_symbol!"<<std::endl;
2989 // delete (func_type-> get_argument_list ());
2990 // delete func_type; // bug 189
2991 SgNode* associatedSymbolBasis = func_symbol->get_symbol_basis();
2992 ROSE_ASSERT(associatedSymbolBasis != NULL);
2993
2994 SgDeclarationStatement* associatedDeclaration = isSgDeclarationStatement(associatedSymbolBasis);
2995 ROSE_ASSERT(associatedDeclaration != NULL);
2996 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(associatedDeclaration);
2997 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(associatedDeclaration);
2998
2999 if (functionDeclaration != NULL)
3000 {
3001 func_type = functionDeclaration->get_type();
3002 }
3003 else
3004 {
3005 if (templateFunctionDeclaration != NULL)
3006 {
3007 // DQ (5/8/2016): I think this code is never executed (because a templateFunctionDeclaration
3008 // is derived from a SgFunctionDeclaration, in the newer design (a few years ago)).
3009
3010 printf ("This code should not be reachable! \n");
3011 ROSE_ABORT();
3012
3013 func_type = templateFunctionDeclaration->get_type();
3014 }
3015 else
3016 {
3017 printf ("Error: associatedDeclaration = %p = %s \n",associatedDeclaration,associatedDeclaration->class_name().c_str());
3018 ROSE_ABORT();
3019 }
3020 }
3021 ROSE_ASSERT(func_type != NULL);
3022
3023 func = new actualFunction(nameWithTemplateArguments,func_type,NULL);
3024 ROSE_ASSERT(func != NULL);
3025
3026#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3027 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as translformations.
3028 // This is too early a point to test since the source position has not been set for func yet.
3029 // detectTransformations_local(func);
3030#endif
3031
3032 // DQ (12/14/2011): Moved this up from below.
3033 func->set_scope(scope);
3034
3035 ROSE_ASSERT(func->get_symbol_from_symbol_table() == NULL);
3036
3037 // DQ (12/15/2011): Added test.
3038 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(func,scope);
3039
3040 // we don't care if it is member function or function here for a pointer
3041 SgDeclarationStatement* prevDecl = NULL;
3042
3043 // This does not handle the case of a template function declaration.
3044 if (functionDeclaration != NULL)
3045 {
3046 prevDecl = functionDeclaration;
3047 }
3048 else
3049 {
3050 ROSE_ASSERT(templateFunctionDeclaration != NULL);
3051 prevDecl = templateFunctionDeclaration;
3052 }
3053
3054 ROSE_ASSERT(prevDecl != NULL);
3055
3056 SgFunctionSymbol *function_symbol = isSgFunctionSymbol(func_symbol);
3057 if (prevDecl == prevDecl->get_definingDeclaration())
3058 {
3059 // The symbol points to a defining declaration and now that we have added a non-defining
3060 // declaration we should have the symbol point to the new non-defining declaration.
3061 printf ("WARNING: Switching declaration in functionSymbol to point to the non-defining declaration \n");
3062 function_symbol->set_declaration(isSgFunctionDeclaration(func));
3063 ROSE_ASSERT(function_symbol->get_declaration() != NULL);
3064 }
3065
3066 // If this is the first non-defining declaration then set the associated data member.
3067 SgDeclarationStatement* nondefiningDeclaration = prevDecl->get_firstNondefiningDeclaration();
3068 if (nondefiningDeclaration == NULL)
3069 {
3070 nondefiningDeclaration = func;
3071 }
3072
3073 ROSE_ASSERT(nondefiningDeclaration != NULL);
3074 ROSE_ASSERT(func != NULL);
3075 ROSE_ASSERT(prevDecl != NULL);
3076
3077 func->set_firstNondefiningDeclaration(nondefiningDeclaration);
3078 func->set_definingDeclaration(prevDecl->get_definingDeclaration());
3079
3080 ROSE_ASSERT(nondefiningDeclaration->get_symbol_from_symbol_table() != NULL);
3081 ROSE_ASSERT(func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3082
3083 // DQ (3/8/2012): If this is the redundant function prototype then we have to look
3084 // at the first defining declaration since only it will have an associated symbol.
3085 if (func->get_symbol_from_symbol_table() == NULL)
3086 {
3087 ROSE_ASSERT(nondefiningDeclaration != NULL);
3088 ROSE_ASSERT(func->get_firstNondefiningDeclaration() == nondefiningDeclaration);
3089 }
3090
3091 // DQ (12/14/2011): Added test.
3092 ROSE_ASSERT(scope != NULL);
3093 ROSE_ASSERT(func->get_scope() != NULL);
3094 ROSE_ASSERT(func->get_scope() == scope);
3095
3096 // DQ (12/14/2011): Error checking
3097 SgTemplateInstantiationMemberFunctionDecl* testMemberDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
3098 if (testMemberDecl != NULL)
3099 {
3100 ROSE_ASSERT(testMemberDecl->get_scope() != NULL);
3101 ROSE_ASSERT(testMemberDecl->get_associatedClassDeclaration() != NULL);
3102 }
3103
3104 // DQ (12/18/2011): Testing to debug generation of wrong kind of declaration (symbol not found in correct scope or ...).
3105 if (isSgFunctionDeclaration(func) == NULL)
3106 {
3107 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3108 // DQ (8/12/2013): Added template parameter list.
3109 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3110 // In this case these are unavailable from this point.
3111 // DQ (12/18/2011): This fails because the first use of the function causes a non-defining function declaration
3112 // to be built and it is built as a template instantiation instead of a template declaration. So the symbol for
3113 // the non-defining declaration is put into the correct scope, but as a SgMemberFunctionSymbol instead of as a
3114 // SgTemplateSymbol (if it were built as a SgTemplateMemberFunctionDeclaration). So of course we can't find it
3115 // using lookup_template_symbol().
3116 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3117 }
3118 }
3119
3120 ROSE_ASSERT(func != NULL);
3121
3122 ROSE_ASSERT(func->get_file_info() == NULL);
3123
3124 ROSE_ASSERT(func->get_firstNondefiningDeclaration() != NULL);
3125 ROSE_ASSERT(func_symbol != NULL);
3126 ROSE_ASSERT(func_symbol->get_symbol_basis() == func->get_firstNondefiningDeclaration());
3127 ROSE_ASSERT(func->get_symbol_from_symbol_table() != NULL || func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3128
3129 // DQ (2/24/2009): Delete the old parameter list build by the actualFunction (template argument) constructor.
3130 ROSE_ASSERT(func->get_parameterList() != NULL);
3131 delete func->get_parameterList();
3132 func->set_parameterList(NULL);
3133
3134 // DQ (9/16/2012): Setup up the template arguments and the parents of the template arguments.
3135 if (buildTemplateInstantiation == true)
3136 {
3137 setTemplateArgumentsInDeclaration(func,templateArgumentsList);
3138 }
3139
3140 // DQ (8/10/2013): Setup the template parameters if this is a template declaration.
3141 if (buildTemplateDeclaration == true)
3142 {
3143 setTemplateParametersInDeclaration(func,templateParameterList);
3144
3145 // DQ (8/13/2013): Adding test of template parameter lists.
3146 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(func);
3147 ROSE_ASSERT(templateFunctionDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateFunctionDeclaration->get_templateParameters().size()));
3148
3149 SgTemplateMemberFunctionDeclaration* templateMemberFunctionDeclaration = isSgTemplateMemberFunctionDeclaration(func);
3150 ROSE_ASSERT(templateMemberFunctionDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateMemberFunctionDeclaration->get_templateParameters().size()));
3151 }
3152
3153 // parameter list
3154 // DQ (11/23/2011): This change allows this to compile for where SgTemplateFunctionDeclarations are used.
3155 setParameterList(func, paralist);
3156
3157 for (SgInitializedName* i_name : paralist->get_args())
3158 {
3159 i_name->set_scope(scope);
3160 }
3161
3162 // DQ (5/2/2012): Test this to make sure we have SgInitializedNames set properly.
3164
3165#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3166 // Liao 11/21/2012: we should assert no transformation only when the current model is NOT transformation
3167 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
3168 {
3169 detectTransformations_local(paralist);
3170 }
3171#endif
3172
3173 ASSERT_not_null(scope);
3174 ASSERT_not_null(func->get_scope());
3175 ASSERT_require(func->get_scope() == scope);
3176
3177 if (SageBuilder::topScopeStack() != nullptr) // This comparison only makes sense when topScopeStack() returns non-NULL value
3178 {
3179 // since stack scope is totally optional in SageBuilder.
3180 if (scope != SageBuilder::topScopeStack())
3181 {
3182#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
3183 printf ("Warning: SageBuilder::buildNondefiningFunctionDeclaration_T(): scope parameter may not be the same as the topScopeStack() (e.g. for member functions) \n");
3184#endif
3185 }
3186 }
3187
3188 func->set_parent(scope);
3189 ASSERT_not_null(func->get_firstNondefiningDeclaration());
3190
3191 // mark as a forward declartion
3192 func->setForward();
3193
3194 ROSE_ASSERT(func->get_file_info() == NULL);
3195
3196 // set File_Info as transformation generated or front end generated
3198
3199 ROSE_ASSERT(func->get_file_info() != NULL);
3200
3201#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3202 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3203 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
3204 {
3205 detectTransformations_local(func);
3206 }
3207#endif
3208
3209 // printf ("In SageBuilder::buildNondefiningFunctionDeclaration_T(): generated function func = %p \n",func);
3210
3211 // Liao 12/2/2010, special handling for Fortran functions and subroutines
3212 if ((SageInterface::is_Fortran_language() == true) && (getEnclosingFileNode(scope)->get_outputLanguage() == SgFile::e_Fortran_language))
3213 {
3214 SgProcedureHeaderStatement * f_func = isSgProcedureHeaderStatement(func);
3215 ROSE_ASSERT (f_func != NULL);
3216 if (return_type == buildVoidType())
3218 else
3219 f_func->set_subprogram_kind(SgProcedureHeaderStatement::e_function_subprogram_kind);
3220
3221 // hide it from the unparser since fortran prototype func declaration is internally used by ROSE AST
3224 ROSE_ASSERT(f_func->get_startOfConstruct()->isOutputInCodeGeneration() == false);
3225 ROSE_ASSERT(f_func->get_endOfConstruct()->isOutputInCodeGeneration() == false);
3226 }
3227
3228 // DQ (12/11/2011): Added new test.
3229 ROSE_ASSERT(func->get_firstNondefiningDeclaration() != NULL);
3230 SgSymbol* symbol_from_first_nondefining_function = func->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table();
3231 ROSE_ASSERT(symbol_from_first_nondefining_function != NULL);
3232
3233 // DQ (12/11/2011): Note that this may be false when func is not the first nondefining declaration.
3234 if (func != func->get_firstNondefiningDeclaration())
3235 {
3236 SgSymbol* symbol_from_nondefining_function = func->get_symbol_from_symbol_table();
3237 ROSE_ASSERT(symbol_from_nondefining_function == NULL);
3238 }
3239
3240 // DQ (12/18/2011): Testing to debug generation of wrong kind of declaration (symbol not found in correct scope or ...).
3241 if (isSgFunctionDeclaration(func) == NULL)
3242 {
3243 // If this is a SgTemplateDeclaration, then we shuld be able to find the name in the associated scope.
3244 // DQ (8/12/2013): Make sure we use the template parameters and the template arguments that are available.
3245 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3246 // In this case these are unavailable from this point.
3247 ROSE_ASSERT(scope->lookup_template_function_symbol(nameWithTemplateArguments,func_type,templateParameterList) != NULL);
3248 }
3249
3250 // 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)).
3251 setTemplateNameInTemplateInstantiations(func,nameWithoutTemplateArguments);
3252
3253#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3254 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3255 if (SourcePositionClassificationMode !=e_sourcePositionTransformation)
3256 {
3257 detectTransformations_local(func);
3258 }
3259#endif
3260
3261 // DQ (12/11/2012): Force the two different ways that this can be set to match (we want consistancy).
3262 if (functionConstVolatileFlags & SgMemberFunctionType::e_restrict)
3263 {
3264 func->get_declarationModifier().get_typeModifier().setRestrict();
3265 }
3266
3267 unsetNodesMarkedAsModified(func);
3268
3269 ROSE_ASSERT(paralist->get_parent() != NULL);
3270 return func;
3271 }
3272
3273
3277{
3278 ROSE_ASSERT(funcdecl!=NULL);
3279 SgName name=funcdecl->get_name();
3280 SgFunctionType * funcType = funcdecl->get_type();
3281 SgType* return_type = funcType->get_return_type();
3282 SgFunctionParameterList* paralist = deepCopy<SgFunctionParameterList>(funcdecl->get_parameterList());
3283
3284 // make sure the function has consistent function type based on its return type and parameter list
3285 SgFunctionType * ref_funcType= findFunctionType (return_type, funcType->get_argument_list());
3286 ROSE_ASSERT(funcType== ref_funcType);
3287
3288 // buildNondefiningFunctionDeclaration() will check if a same function is created before by looking up function symbols.
3289 SgFunctionDeclaration* returnFunction = buildNondefiningFunctionDeclaration (name, return_type, paralist, scope, decoratorList, false, NULL);
3290
3291 returnFunction->set_linkage(funcdecl->get_linkage());
3292 if (funcdecl->get_declarationModifier().get_storageModifier().isExtern() == true)
3293 {
3294 returnFunction->get_declarationModifier().get_storageModifier().setExtern();
3295 }
3296
3297 ROSE_ASSERT (returnFunction->get_linkage() == funcdecl->get_linkage());
3298 ROSE_ASSERT (returnFunction->get_declarationModifier().get_storageModifier().isExtern() ==
3299 funcdecl->get_declarationModifier().get_storageModifier().isExtern());
3300
3301 ROSE_ASSERT(returnFunction->get_firstNondefiningDeclaration() != NULL);
3302 // Make sure that internal references are to the same file (else the symbol table information will not be consistent).
3303 if (scope != NULL)
3304 {
3305 ROSE_ASSERT(returnFunction->get_firstNondefiningDeclaration() != NULL);
3306 }
3307
3308 return returnFunction;
3309}
3310
3312SageBuilder::buildNondefiningFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList, SgStorageModifier::storage_modifier_enum sm)
3313 {
3314 SgFunctionDeclaration * result = NULL;
3315 if ((SageInterface::is_Fortran_language() == true) && (getEnclosingFileNode(scope)->get_outputLanguage() == SgFile::e_Fortran_language))
3316 {
3317 result = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, NULL, sm);
3318 }
3319 else
3320 {
3321 // 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).
3322 if (buildTemplateInstantiation == true)
3323 {
3324 result = buildNondefiningFunctionDeclaration_T <SgTemplateInstantiationFunctionDecl> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, templateArgumentsList, NULL, sm);
3325 }
3326 else
3327 {
3328 result = buildNondefiningFunctionDeclaration_T <SgFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, NULL, sm);
3329 }
3330 }
3331
3332 return result;
3333 }
3334
3335
3336// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficent).
3337// We need to decide if the SageBuilder API should include these sorts of functions.
3340 {
3341 unsigned int memberFunctionModifiers = 0;
3342 return buildNondefiningMemberFunctionDeclaration (name,return_type,paralist,scope,NULL,memberFunctionModifiers,false,NULL);
3343 }
3344
3345// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficient).
3346// We need to decide if the SageBuilder API should include these sorts of functions.
3349 {
3350 if (scope == NULL)
3351 {
3353 }
3354
3355 unsigned int memberFunctionModifiers = 0;
3357 SgMemberFunctionDeclaration* nondefining_decl = NULL;
3358 SgMemberFunctionType* member_func_type = buildMemberFunctionType(return_type,param_type_list, scope, memberFunctionModifiers);
3359 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgMemberFunctionDeclaration>(name,member_func_type,NULL,NULL);
3360 SgMemberFunctionSymbol* member_func_symbol = isSgMemberFunctionSymbol(func_symbol);
3361
3362 if (member_func_symbol != NULL)
3363 {
3364 nondefining_decl = member_func_symbol->get_declaration();
3365 }
3366 else
3367 {
3368 // each defining member function decl must have a non-defining counter part now. 11/27/2012, Liao
3369 nondefining_decl = buildNondefiningMemberFunctionDeclaration (name, return_type, paralist, scope,NULL, memberFunctionModifiers, false, NULL);
3370 }
3371 return buildDefiningMemberFunctionDeclaration (name,return_type,paralist,scope,NULL,false,memberFunctionModifiers,nondefining_decl,NULL);
3372 }
3373
3374
3375// SgTemplateFunctionDeclaration* SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList)
3376// SgTemplateFunctionDeclaration* SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateArgumentPtrList* templateArgumentsList)
3378SageBuilder::buildNondefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateParameterPtrList* templateParameterList)
3379 {
3380 // DQ (8/15/2013): Note that we don't need template arguments because teplate functions can't support partial specialization.
3381
3382 // DQ (11/25/2011): Adding support for template declarations in the AST.
3383
3384 // DQ (8/7/2013): Added support for template function overloading using template parameters.
3385 SgTemplateFunctionDeclaration* result = buildNondefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ false, scope, decoratorList, false, NULL, templateParameterList, SgStorageModifier::e_default);
3386
3387 // DQ (12/12/2011): Added test.
3388 ROSE_ASSERT(result != NULL);
3389 if (result->get_symbol_from_symbol_table() == NULL)
3390 {
3391 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3392 ROSE_ASSERT(result != result->get_firstNondefiningDeclaration());
3393 ROSE_ASSERT(result->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table() != NULL);
3394 }
3395 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3396
3397 return result;
3398 }
3399
3401SageBuilder::buildDefiningTemplateFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, SgTemplateFunctionDeclaration* first_nondefining_declaration)
3402 {
3403 // DQ (12/1/2011): Adding support for template declarations in the AST.
3404 ROSE_ASSERT(first_nondefining_declaration != NULL);
3405 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() != NULL);
3406 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3407
3408 SgTemplateFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ false, scope, decoratorList, 0, first_nondefining_declaration, NULL);
3409
3410 return result;
3411 }
3412
3414SageBuilder::buildDefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList *paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, SgTemplateMemberFunctionDeclaration* first_nondefining_declaration)
3415 {
3416 // DQ (12/1/2011): Adding support for template declarations in the AST.
3417
3418 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3419
3420 SgTemplateMemberFunctionDeclaration* result = buildDefiningFunctionDeclaration_T <SgTemplateMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true, scope, decoratorList, functionConstVolatileFlags, first_nondefining_declaration, NULL);
3421 ROSE_ASSERT(result != NULL);
3422
3423 ROSE_ASSERT(result->get_definition() != NULL);
3424
3425 return result;
3426 }
3427
3430 SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList)
3431 {
3432 // This function builds either a SgMemberFunctionDeclaration (non-template; normal member function) or a SgTemplateInstantiationMemberFunctionDecl (template instantiation).
3433
3434 // DQ (11/27/2011): Added support for instations of template member functions.
3435 SgMemberFunctionDeclaration * result = NULL;
3436
3437 if (buildTemplateInstantiation == true)
3438 {
3439 // This is how we build an instantiation of a template (SgTemplateInstantiationMemberFunctionDecl).
3440 result = buildNondefiningFunctionDeclaration_T <SgTemplateInstantiationMemberFunctionDecl> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,templateArgumentsList,NULL, SgStorageModifier::e_default);
3441 }
3442 else
3443 {
3444 // This is a non-template instatiation (normal member function).
3445 result = buildNondefiningFunctionDeclaration_T <SgMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,NULL,NULL, SgStorageModifier::e_default);
3446 }
3447 ROSE_ASSERT(result != NULL);
3448
3449 // set definingdecl for SgCtorInitializerList
3451 ROSE_ASSERT(ctor != NULL);
3452
3453 // required in AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3454 ctor->set_definingDeclaration(ctor);
3456
3457 // DQ (1/4/2009): Error checking
3458 ROSE_ASSERT(result->get_associatedClassDeclaration() != NULL);
3459
3460 if (result->get_associatedClassDeclaration() == NULL)
3461 {
3462 printf ("Warning, must set the SgMemberFunctionDeclaration::associatedClassDeclaration \n");
3463
3464 ROSE_ASSERT(scope != NULL);
3465 SgClassDefinition* classDefinition = isSgClassDefinition(scope);
3466 ROSE_ASSERT(classDefinition != NULL);
3467 SgDeclarationStatement* associatedDeclaration = classDefinition->get_declaration();
3468 ROSE_ASSERT(associatedDeclaration != NULL);
3469 SgClassDeclaration* associatedClassDeclaration = isSgClassDeclaration(associatedDeclaration);
3470
3471 // DQ (1/4/2009): This needs to be set, checked in AstConsistencyTests.C!
3472 result->set_associatedClassDeclaration(associatedClassDeclaration);
3473 }
3474
3475 return result;
3476 }
3477
3478
3479// DQ (8/12/2013): This function needs to handle the SgTemplateParameterPtrList (since it is generating a template).
3480// It need not take a SgTemplateArgumentPtrList because template functions (including template member functions) can not support partial specialization.
3481// SgTemplateMemberFunctionDeclaration* SageBuilder::buildNondefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags)
3483SageBuilder::buildNondefiningTemplateMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, unsigned int functionConstVolatileFlags, SgTemplateParameterPtrList* templateParameterList)
3484 {
3485 // This function only builds template member function declarations.
3486
3487 SgTemplateMemberFunctionDeclaration * result = buildNondefiningFunctionDeclaration_T <SgTemplateMemberFunctionDeclaration> (name,return_type,paralist, /* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,NULL,templateParameterList, SgStorageModifier::e_default);
3488
3489 // set definingdecl for SgCtorInitializerList
3490 ROSE_ASSERT(result != NULL);
3491
3492#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3493 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as translformations.
3495 {
3496 detectTransformations_local(result);
3497 }
3498#endif
3499
3500 // DQ (8/12/2013): Added template paremter list to call to get the function template symbol.
3501 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3502 // In this case these are unavailable from this point.
3503 SgSymbol* associatedSymbol = scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList);
3504 if (associatedSymbol == NULL)
3505 {
3506 printf ("ERROR: associatedSymbol == NULL \n");
3507 printf (" --- result = %p = %s \n",result,result->class_name().c_str());
3508 printf (" --- scope = %p = %s \n",scope,scope->class_name().c_str());
3509 printf (" --- name = %s \n",name.str());
3510 printf (" --- result->get_type() = %p = %s \n",result->get_type(),result->get_type()->class_name().c_str());
3511 printf (" --- result->get_type()->get_mangled() = %s \n",result->get_type()->get_mangled().str());
3512 }
3513 ROSE_ASSERT(associatedSymbol != NULL);
3514
3516 ROSE_ASSERT(ctor != NULL);
3517 // required ty AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3518 ctor->set_definingDeclaration(ctor);
3520
3521 // DQ (12/11/2011): Added new test (also at the base of buildNondefiningFunctionDeclaration_T<>() function).
3522 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
3523 SgSymbol* symbol_from_first_nondefining_function = result->get_firstNondefiningDeclaration()->get_symbol_from_symbol_table();
3524 ROSE_ASSERT(symbol_from_first_nondefining_function != NULL);
3525
3526 // DQ (12/11/2011): Note that this may be false when func is not the first nondefining declaration.
3527 if (result != result->get_firstNondefiningDeclaration())
3528 {
3529 SgSymbol* symbol_from_nondefining_function = result->get_symbol_from_symbol_table();
3530 ROSE_ASSERT(symbol_from_nondefining_function == NULL);
3531 }
3532
3533#if BUILDER_MAKE_REDUNDANT_CALLS_TO_SYMBOL_TABLE_LOOKUP
3534 // DQ (7/31/2013): Fixing API to use functions that now require template parameters and template specialization arguments.
3535 // In this case these are unavailable from this point.
3536 if (scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList) == NULL)
3537 {
3538 printf ("Error: scope->lookup_template_member_function_symbol(name,result->get_type()) == NULL (investigate this) \n");
3539 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());
3540 scope->get_symbol_table()->print("Error: scope->lookup_template_member_function_symbol(name,result->get_type()) == NULL (investigate this)");
3541 }
3542#endif
3543 ROSE_ASSERT(scope->lookup_template_member_function_symbol(name,result->get_type(),templateParameterList) != NULL);
3544
3545#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
3546 // DQ (5/1/2012): Make sure that we don't have IR nodes marked as transformations.
3548 {
3549 detectTransformations_local(result);
3550 }
3551#endif
3552
3553 return result;
3554 }
3555
3557SageBuilder::buildDefiningMemberFunctionDeclaration (const SgName & name, SgType* return_type, SgFunctionParameterList * paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, unsigned int functionConstVolatileFlags, SgMemberFunctionDeclaration* first_nondefining_declaration, SgTemplateArgumentPtrList* templateArgumentsList)
3558 {
3559 // DQ (12/18/2011): Need to build a SgTemplateInstantiationMemberFunctionDecl when buildTemplateInstantiation == true
3560 SgMemberFunctionDeclaration * result = NULL;
3561 if (buildTemplateInstantiation == true)
3562 {
3563 SgTemplateInstantiationMemberFunctionDecl* templateInstantiationMemberFunctionDecl = isSgTemplateInstantiationMemberFunctionDecl(first_nondefining_declaration);
3564 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
3565
3566 // DQ (1/26/2013): Added test failing in buildDefiningFunctionDeclaration_T().
3567 {
3568 ROSE_ASSERT(templateArgumentsList != NULL);
3569 string nameWithoutTemplateArguments = name;
3570 string nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
3571 SgMemberFunctionType* func_type = isSgMemberFunctionType(first_nondefining_declaration->get_type());
3572 ROSE_ASSERT(func_type != NULL);
3573
3574 // DQ (8/7/2013): API change due to added support for template function overloading using template parameters.
3575 SgSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgTemplateInstantiationMemberFunctionDecl>(nameWithTemplateArguments,func_type,NULL,templateArgumentsList);
3576 if (func_symbol == NULL)
3577 {
3578 printf ("ERROR caught in SageBuilder::buildDefiningMemberFunctionDeclaration(): nameWithTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithTemplateArguments.c_str(),buildTemplateInstantiation ? "true:" : "false");
3579 printf ("ERROR caught in SageBuilder::buildDefiningMemberFunctionDeclaration(): func_symbol == NULL for first_nondefining_declaration = %p = %s and func_type = %p = %s \n",
3580 templateInstantiationMemberFunctionDecl,templateInstantiationMemberFunctionDecl->class_name().c_str(),func_type,func_type->class_name().c_str());
3581 }
3582 }
3583
3584 result = buildDefiningFunctionDeclaration_T <SgTemplateInstantiationMemberFunctionDecl> (name, return_type, paralist, /* isMemberFunction = */ true, scope, decoratorList, functionConstVolatileFlags, templateInstantiationMemberFunctionDecl, templateArgumentsList);
3585 ROSE_ASSERT(isSgTemplateInstantiationMemberFunctionDecl(result) != NULL);
3586 ROSE_ASSERT(isSgTemplateInstantiationMemberFunctionDecl(result)->get_templateName().is_null() == false);
3587 }
3588 else
3589 {
3590 ROSE_ASSERT(first_nondefining_declaration != NULL);
3591
3592 // DQ (12/27/20134): Added these to permit testing earlier than in the buildDefiningFunctionDeclaration_T() function.
3593 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() != NULL);
3594 ROSE_ASSERT(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3595
3596 result = buildDefiningFunctionDeclaration_T <SgMemberFunctionDeclaration> (name,return_type,paralist,/* isMemberFunction = */ true,scope,decoratorList,functionConstVolatileFlags,first_nondefining_declaration, NULL);
3597 }
3598
3599 ROSE_ASSERT(result != NULL);
3600
3601 // set definingdecl for SgCtorInitializerList
3603 ROSE_ASSERT(ctor != NULL);
3604
3605 // required ty AstConsistencyTests.C:TestAstForProperlySetDefiningAndNondefiningDeclarations()
3606 ctor->set_definingDeclaration(ctor);
3608
3609 // DQ (1/4/2009): Error checking
3610 ROSE_ASSERT(result->get_associatedClassDeclaration() != NULL);
3611
3612 return result;
3613 }
3614
3615
3616//----------------- defining function declaration------------
3617// a template builder for all kinds of defining SgFunctionDeclaration
3618// handle common chores for function type, symbol, paramter etc.
3619
3620template <class actualFunction>
3621actualFunction*
3622SageBuilder::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)
3623 {
3624 // Note that the semantics of this function now differs from that of the buildDefiningClassDeclaration().
3625 // We want to have the non-defining declaration already exist before calling this function.
3626 // We could still build a higher level function that built both together. Or we could provide two versions
3627 // named differently (from this one) and depricate this function...which I like much better.
3628
3629#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
3630 printf ("WARNING: This function for building defining function declarations has different semantics from that of the function to build defining class declarations. \n");
3631#endif
3632
3633 ASSERT_not_null(first_nondefining_declaration);
3634 ASSERT_require(first_nondefining_declaration->get_firstNondefiningDeclaration() == first_nondefining_declaration);
3635
3636 if (scope == nullptr)
3637 {
3639 }
3640
3641 ASSERT_require(XXX_name.is_null() == false);
3642 ASSERT_not_null(scope);
3643 ASSERT_not_null(return_type);
3644
3645 SgName nameWithoutTemplateArguments = XXX_name;
3646 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
3647
3648 bool buildTemplateInstantiation = ((VariantT)actualFunction::static_variant == V_SgTemplateInstantiationFunctionDecl || (VariantT)actualFunction::static_variant == V_SgTemplateInstantiationMemberFunctionDecl);
3649
3650 // DQ (8/7/2013): Added support for template declarations.
3651 bool buildTemplateDeclaration = ((VariantT)actualFunction::static_variant == V_SgTemplateFunctionDeclaration || (VariantT)actualFunction::static_variant == V_SgTemplateMemberFunctionDeclaration);
3652
3653 // DQ (8/11/2013): Check that the template argument lists are consistant. The templateArgumentsList can then be considered redundant if this works.
3654 if (buildTemplateInstantiation == true)
3655 {
3656 ASSERT_not_null(templateArgumentsList);
3657
3658 SgTemplateArgumentPtrList & templateArgumentsList_from_first_nondefining_declaration = (isMemberFunction == false) ?
3659 isSgTemplateInstantiationFunctionDecl(first_nondefining_declaration)->get_templateArguments() :
3660 isSgTemplateInstantiationMemberFunctionDecl(first_nondefining_declaration)->get_templateArguments();
3661
3662 ASSERT_not_null(templateArgumentsList);
3663 bool templateArgumentListsAreEquivalent = SageInterface::templateArgumentListEquivalence(*templateArgumentsList, templateArgumentsList_from_first_nondefining_declaration);
3664 ASSERT_require(templateArgumentListsAreEquivalent == true);
3665 }
3666
3667 SgTemplateParameterPtrList* templateParameterList = nullptr;
3668 if (buildTemplateDeclaration == true)
3669 {
3670 // 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.
3671 templateParameterList = (isMemberFunction == false) ?
3672 &(isSgTemplateFunctionDeclaration(first_nondefining_declaration)->get_templateParameters()) :
3673 &(isSgTemplateMemberFunctionDeclaration(first_nondefining_declaration)->get_templateParameters());
3674
3675 ASSERT_require(templateArgumentsList == nullptr);
3676 ASSERT_not_null(templateParameterList);
3677 }
3678
3679 if (buildTemplateInstantiation == true)
3680 {
3681 ASSERT_not_null(templateArgumentsList);
3682 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
3683
3684 if (nameWithTemplateArguments == "insert < __normal_iterator< SgInitializedName ** , __type > > ")
3685 {
3686 printf ("In buildDefiningFunctionDeclaration_T(): Found function nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
3687 }
3688 }
3689
3690 ASSERT_require(nameWithoutTemplateArguments.is_null() == false);
3691 ASSERT_require(nameWithTemplateArguments.is_null() == false);
3692 ASSERT_not_null(paralist);
3693
3695 {
3696 ASSERT_require(scope->containsOnlyDeclarations());
3697 }
3698
3699 // build function type, manage function type symbol internally
3700 actualFunction* defining_func = nullptr;
3701 SgFunctionType* func_type = nullptr;
3702
3703 // 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).
3704 // This is a special problem for templates because the function parameters will evaluate different for different builds of the same template.
3705 // This is a problem for test2012_74.C (and a dozen other test codes that make use of STL).
3706 ASSERT_not_null(first_nondefining_declaration);
3707
3708 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
3709 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
3710 // DQ (7/27/2012): There are reasons why this can fail: e.g. for functions with names such as:
3711 // "operator std::auto_ptr_ref<_Tp1>" which is a user defined conversion operator to one class from another.
3712
3713 // DQ (5/12/2012): Use the newly added parameter to get the exact SgFunctionType used to build the symbol.
3714 // This should make the template handling more robust since we were sometimes using types that had different
3715 // levels of template instantiation between the non-definng and defining function declarations and this
3716 // caused symbols build to support the non-defining declaration to not be found when we searched for them
3717 // using the function type built for the defining declaration. We want the function types for all defining
3718 // and non-defining declarations to be identical. This define also means that we don't have to build a
3719 // SgFunctionType just to look up a symbol in the symbol table (which was always silly). However, only
3720 // the defining function declaration can use the existing function type because it is required that a
3721 // non-defining declaration exist prior to the construction of the defining declaration (built by this
3722 // function).
3723 func_type = first_nondefining_declaration->get_type();
3724 ASSERT_not_null(func_type);
3725
3726 // Make sure these are the same (this will fail until we generate the func_type directly from first_nondefining_declaration).
3727 ASSERT_require(func_type == first_nondefining_declaration->get_type());
3728
3729 SgDeclarationStatement* firstNondefiningFunctionDeclaration = nullptr;
3730
3731 // symbol table and non-defining
3732 SgSymbol* func_symbol = scope->find_symbol_by_type_of_function<actualFunction>(nameWithTemplateArguments,func_type,templateParameterList,templateArgumentsList);
3733
3734 // DQ (1/26/2013): This fails for ROSE compiling ROSE.
3735 ASSERT_not_null(func_symbol);
3736
3737 if (func_symbol == nullptr)
3738 {
3739 // DQ (12/2/2011): After discussion with Liao, we think this should be an error.
3740 // The defining declaration requires that the associated non-defining declaration should already exist.
3741 // If required, a higher level build function could build both of these and connect them as required.
3742 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");
3743 ROSE_ABORT();
3744 }
3745 else
3746 {
3747 // We will now build a reference to the non-defining declaration found in the symbol.
3748
3749 // defining declaration after nondefining declaration
3750 // reuse function type, function symbol
3751
3752 // Cong (10/25/2010): Make sure in this situation there is no defining declaration for this symbol.
3753
3754 SgFunctionSymbol* temp_function_sym = isSgFunctionSymbol(func_symbol);
3755 SgTemplateSymbol* temp_template_sym = isSgTemplateSymbol(func_symbol);
3756 if (temp_function_sym != nullptr)
3757 {
3758 func_type = temp_function_sym->get_declaration()->get_type();
3759 firstNondefiningFunctionDeclaration = temp_function_sym->get_declaration()->get_firstNondefiningDeclaration();
3760 }
3761 else
3762 {
3763 // There is no type for a template function declaration.
3764 ASSERT_not_null(temp_template_sym);
3765 firstNondefiningFunctionDeclaration = temp_template_sym->get_declaration()->get_firstNondefiningDeclaration();
3766 }
3767 ASSERT_not_null(firstNondefiningFunctionDeclaration);
3768 }
3769
3770 defining_func = new actualFunction(nameWithTemplateArguments,func_type,nullptr);
3771 ASSERT_not_null(defining_func);
3772
3773 ASSERT_not_null(firstNondefiningFunctionDeclaration);
3774 defining_func->set_firstNondefiningDeclaration(firstNondefiningFunctionDeclaration);
3775
3776 // fix up defining declarations before current statement
3777 firstNondefiningFunctionDeclaration->set_definingDeclaration(defining_func);
3778
3779 // Handle decorators (Python specific)
3780 if (decoratorList != nullptr)
3781 {
3782 defining_func->set_decoratorList(decoratorList);
3783 decoratorList->set_parent(defining_func);
3784 }
3785
3786 // definingDeclaration
3787 defining_func->set_definingDeclaration(defining_func);
3788
3789 // function body and definition are created before setting argument list
3790 SgBasicBlock * func_body = new SgBasicBlock();
3791 ASSERT_not_null(func_body);
3792
3793 SgFunctionDefinition* func_def = nullptr;
3794 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(defining_func);
3795
3796 // Build either a definition for a template or non-template function definition.
3797 if (templateFunctionDeclaration == nullptr)
3798 {
3799 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(defining_func);
3800 ASSERT_not_null(functionDeclaration);
3801 func_def = new SgFunctionDefinition(functionDeclaration,func_body);
3802 }
3803 else
3804 {
3805 ASSERT_not_null(templateFunctionDeclaration);
3806 func_def = new SgTemplateFunctionDefinition(templateFunctionDeclaration,func_body);
3807 }
3808 ASSERT_not_null(func_def);
3809
3811 {
3812 func_def->setCaseInsensitive(true);
3813 func_body->setCaseInsensitive(true);
3814 }
3815
3816 func_def->set_parent(defining_func);
3817 func_def->set_body(func_body);
3818 func_body->set_parent(func_def);
3819
3820 // parameter list,
3821 // TODO consider the difference between C++ and Fortran
3822 setParameterList(defining_func,paralist);
3823 // fixup the scope and symbol of arguments,
3824 for (SgInitializedName* i_name : paralist->get_args())
3825 {
3826 i_name->set_scope(func_def);
3827
3828 SgVariableSymbol* variableSymbol = new SgVariableSymbol(i_name);
3829 ASSERT_not_null(variableSymbol);
3830 func_def->insert_symbol(i_name->get_name(), variableSymbol);
3831
3832 // For variable length array types in the function parameter list
3833 SgArrayType* arrayType = isSgArrayType(i_name->get_type());
3834 if (arrayType != nullptr)
3835 {
3836 // Check if this is a VLA array type, if so look for the index expressions and check
3837 // if we need to add asociated symbols to the current function definition scope.
3838 SgExpression* indexExpression = arrayType->get_index();
3839
3840 if (indexExpression != nullptr)
3841 {
3842 // DQ (2/14/2016): Handle the case of an expression tree with any number of variable references.
3843 // Get the list of SgVarRef IR nodes and process each one as above.
3844 vector<SgVarRefExp* > varRefList;
3845 collectVarRefs(indexExpression,varRefList);
3846
3847 for (size_t i = 0; i < varRefList.size(); i++)
3848 {
3849 // Process each index subtree's SgVarRefExp.
3850 SgVariableSymbol* dimension_variableSymbol = varRefList[i]->get_symbol();
3851 ASSERT_not_null(dimension_variableSymbol);
3852 ASSERT_require(dimension_variableSymbol != variableSymbol);
3853
3854 // The symbol from the referenced variable for the array dimension expression shuld already by in the function definition's symbol table.
3855 SgSymbol* symbolFromLookup = func_def->lookup_symbol(dimension_variableSymbol->get_name());
3856 if (symbolFromLookup != nullptr)
3857 {
3858 SgVariableSymbol* variableSymbolFromLookup = isSgVariableSymbol(symbolFromLookup);
3859 ASSERT_not_null(variableSymbolFromLookup);
3860
3861 varRefList[i]->set_symbol(variableSymbolFromLookup);
3862 ASSERT_require(dimension_variableSymbol != variableSymbol);
3863 }
3864 else
3865 {
3866 // 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.
3867 }
3868 }
3869 }
3870 }
3871 }
3872
3873 defining_func->set_parent(scope);
3874 defining_func->set_scope(scope);
3875
3876 ASSERT_not_null(defining_func->get_scope());
3877
3878 checkThatNoTemplateInstantiationIsDeclaredInTemplateDefinitionScope(defining_func,scope);
3879
3880 // set File_Info as transformation generated
3882
3883 // Enforce that the return type matches the specification to build a member function.
3884 if (isMemberFunction == true)
3885 {
3886 ASSERT_not_null(isSgMemberFunctionDeclaration(defining_func));
3887 }
3888
3889 // 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)).
3890 setTemplateNameInTemplateInstantiations(defining_func,nameWithoutTemplateArguments);
3891
3892 // DQ (9/16/2012): Setup up the template arguments and the parents of the template arguments.
3893 if (buildTemplateInstantiation == true)
3894 {
3895 setTemplateArgumentsInDeclaration(defining_func,templateArgumentsList);
3896 }
3897
3898 // DQ (8/13/2013): Added code to set the template parameters in the defining declaration (if it is a template declaration).
3899 if (buildTemplateDeclaration == true)
3900 {
3901 setTemplateParametersInDeclaration(defining_func,templateParameterList);
3902
3903 // DQ (8/13/2013): Adding test of template parameter lists.
3904 SgTemplateFunctionDeclaration* templateFunctionDeclaration = isSgTemplateFunctionDeclaration(defining_func);
3905 ROSE_ASSERT(templateFunctionDeclaration == nullptr || (templateParameterList != nullptr && templateParameterList->size() == templateFunctionDeclaration->get_templateParameters().size()));
3906 SgTemplateMemberFunctionDeclaration* templateMemberFunctionDeclaration = isSgTemplateMemberFunctionDeclaration(defining_func);
3907 ROSE_ASSERT(templateMemberFunctionDeclaration == nullptr || (templateParameterList != nullptr && templateParameterList->size() == templateMemberFunctionDeclaration->get_templateParameters().size()));
3908 }
3909
3910 // DQ (12/12/2012): Force the two different ways that this can be set to match (we want consistancy).
3911 if (functionConstVolatileFlags & SgMemberFunctionType::e_restrict)
3912 {
3913 defining_func->get_declarationModifier().get_typeModifier().setRestrict();
3914 }
3915
3916 // DQ (4/16/2015): This is replaced with a better implementation.
3917 // DQ (4/15/2015): We should reset the isModified flags as part of the transforamtion
3918 // because we have added statements explicitly marked as transformations.
3919 // checkIsModifiedFlag(defining_func);
3920 unsetNodesMarkedAsModified(defining_func);
3921
3922 return defining_func;
3923 }
3924
3925void
3927 {
3928 // 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)).
3929
3930 SgTemplateInstantiationFunctionDecl* templateInstantiationFunctionDecl = isSgTemplateInstantiationFunctionDecl(func);
3931 SgTemplateInstantiationMemberFunctionDecl* templateInstantiationMemberFunctionDecl = isSgTemplateInstantiationMemberFunctionDecl(func);
3932 bool isTemplateInstantition = (templateInstantiationFunctionDecl != NULL) || (templateInstantiationMemberFunctionDecl != NULL);
3933 if (isTemplateInstantition == true)
3934 {
3935 // If this is a template instantiation then we need to take care of a few more issues.
3936
3937 SgName templateNameWithoutArguments = name;
3938
3939 // DQ (7/27/2012): New semantics is that we want to have the input name be without template arguments and
3940 // we will add the template arguments instead of trying to remove then (which was problematic for examples
3941 // such as "X<Y<Z>> operator X&()" and "X<Y<Z>> operator>()".
3942
3943 bool isMemberFunction = (templateInstantiationMemberFunctionDecl != NULL);
3944 if (isMemberFunction == true)
3945 {
3946 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
3947 ROSE_ASSERT(templateInstantiationFunctionDecl == NULL);
3948
3949 if (templateInstantiationMemberFunctionDecl->get_templateName().is_null() == true)
3950 {
3951 // Set the template name for the member function template instantiation.
3952 // templateInstantiationMemberFunctionDecl->set_templateName(name);
3953 templateInstantiationMemberFunctionDecl->set_templateName(templateNameWithoutArguments);
3954
3955 // DQ (5/31/2012): Find locations where this is set and include template syntax.
3956 }
3957 ROSE_ASSERT(templateInstantiationMemberFunctionDecl->get_templateName().is_null() == false);
3958 }
3959 else
3960 {
3961 ROSE_ASSERT(templateInstantiationFunctionDecl != NULL);
3962 ROSE_ASSERT(templateInstantiationMemberFunctionDecl == NULL);
3963
3964 if (templateInstantiationFunctionDecl->get_templateName().is_null() == true)
3965 {
3966 // Set the template name for the function template instantiation.
3967 // templateInstantiationFunctionDecl->set_templateName(name);
3968 templateInstantiationFunctionDecl->set_templateName(templateNameWithoutArguments);
3969
3970 // DQ (5/31/2012): Find locations where this is set and include template syntax.
3971 ROSE_ASSERT(hasTemplateSyntax(templateNameWithoutArguments) == false);
3972 }
3973 ROSE_ASSERT(templateInstantiationFunctionDecl->get_templateName().is_null() == false);
3974 }
3975 }
3976 }
3977
3979SageBuilder::buildDefiningFunctionDeclaration(const SgName& name, SgType* return_type, SgFunctionParameterList* paralist, SgScopeStatement* scope, SgExprListExp* decoratorList, bool buildTemplateInstantiation, SgFunctionDeclaration* first_nondefining_declaration, SgTemplateArgumentPtrList* templateArgumentsList)
3980 {
3981 // DQ (2/10/2012): Fixed to build either SgTemplateInstantiationFunctionDecl or SgFunctionDeclaration.
3982 SgFunctionDeclaration* func = NULL;
3983 if (buildTemplateInstantiation == true)
3984 {
3985 SgTemplateInstantiationFunctionDecl* templateInstantiationFunctionDecl = isSgTemplateInstantiationFunctionDecl(first_nondefining_declaration);
3986
3987 ROSE_ASSERT(first_nondefining_declaration != NULL);
3988
3989 func = buildDefiningFunctionDeclaration_T<SgTemplateInstantiationFunctionDecl>(name,return_type,paralist,/* isMemberFunction = */ false,scope,decoratorList,0,templateInstantiationFunctionDecl, templateArgumentsList);
3990
3991 ROSE_ASSERT(isSgTemplateInstantiationFunctionDecl(func) != NULL);
3992 ROSE_ASSERT(isSgTemplateInstantiationFunctionDecl(func)->get_templateName().is_null() == false);
3993 }
3994 else
3995 {
3996 ROSE_ASSERT(first_nondefining_declaration != NULL);
3997
3998 func = buildDefiningFunctionDeclaration_T<SgFunctionDeclaration>(name,return_type,paralist,/* isMemberFunction = */ false,scope,decoratorList,0,first_nondefining_declaration, NULL);
3999
4000 ROSE_ASSERT(isSgFunctionDeclaration(func) != NULL);
4001 }
4002
4003 return func;
4004 }
4005
4006
4007// DQ (8/28/2012): This preserves the original API with a simpler function (however for C++ at least, it is frequently not sufficent).
4008// We need to decide if the SageBuilder API should include these sorts of functions.
4011 {
4012 // DQ (11/12/2012): Note that this function is not used in the AST construction in the EDG/ROSE interface.
4013 ROSE_ASSERT(return_type != NULL);
4014 ROSE_ASSERT(parameter_list != NULL);
4015
4016 if (scope == NULL)
4017 {
4019 }
4020
4021 SgFunctionDeclaration* nondefiningDeclaration = NULL;
4022
4023 SgFunctionType* func_type = buildFunctionType(return_type,parameter_list);
4024 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgFunctionDeclaration>(name,func_type,NULL,NULL);
4025 if (func_symbol != NULL)
4026 {
4027 nondefiningDeclaration = func_symbol->get_declaration();
4028 }
4029 else
4030 {
4031 nondefiningDeclaration = buildNondefiningFunctionDeclaration(name,return_type,parameter_list,scope,NULL);
4032 }
4033
4034 ROSE_ASSERT(nondefiningDeclaration != NULL);
4035 ROSE_ASSERT(nondefiningDeclaration->get_firstNondefiningDeclaration() != NULL);
4036 ROSE_ASSERT(nondefiningDeclaration->get_firstNondefiningDeclaration() == nondefiningDeclaration);
4037
4038 return buildDefiningFunctionDeclaration (name,return_type,parameter_list,scope,NULL,false,nondefiningDeclaration,NULL);
4039 }
4040
4041// Build a nondefining SgProcedureHeaderStatement, handle function type, symbol etc transparently [Rasmussen 9/24/2020]
4045 {
4046 ASSERT_not_null(return_type);
4047 ASSERT_not_null(param_list);
4048
4049 SgProcedureHeaderStatement* nondef_decl = nullptr;
4050
4051 if (scope == nullptr) {
4053 }
4054
4055 // A new nondefing declaration is needed even if the function symbol already exists. The function symbol
4056 // should always contain the _first_ nondefining declaration (even though this may not be the first one).
4057 nondef_decl = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement>
4058 ( name, return_type, param_list, /*isMemberFunction*/false, scope, /*decoratorList*/nullptr,
4059 /*functionConstVolatileFlags*/0, nullptr, nullptr, SgStorageModifier::e_default );
4060
4061 ASSERT_not_null(isSgProcedureHeaderStatement(nondef_decl));
4062 ASSERT_not_null(nondef_decl->get_firstNondefiningDeclaration());
4063
4064 nondef_decl->set_subprogram_kind(kind);
4065
4066 return nondef_decl;
4067 }
4068
4070buildProcedureHeaderStatement(const SgName& name, SgType* return_type, SgFunctionParameterList* parameter_list,
4072 {
4073 ASSERT_not_null(return_type);
4074 ASSERT_not_null(parameter_list);
4075
4076 SgFunctionDeclaration* nondef_decl = nullptr;
4077
4078 if (scope == nullptr) {
4080 }
4081
4082 SgFunctionType* func_type = buildFunctionType(return_type,parameter_list);
4083 SgFunctionSymbol* func_symbol = scope->find_symbol_by_type_of_function<SgProcedureHeaderStatement>(name,func_type,nullptr,nullptr);
4084 if (func_symbol == nullptr)
4085 {
4086 nondef_decl = buildNondefiningFunctionDeclaration_T <SgProcedureHeaderStatement>
4087 ( name, return_type, parameter_list, /*isMemberFunction*/false, scope,
4088 /*decoratorList*/nullptr, /*functionConstVolatileFlags*/0, nullptr, nullptr, SgStorageModifier::e_default);
4089 }
4090 else
4091 {
4092 nondef_decl = func_symbol->get_declaration();
4093 }
4094
4095 SgProcedureHeaderStatement* proc_header_stmt = isSgProcedureHeaderStatement(nondef_decl);
4096 ASSERT_not_null(proc_header_stmt);
4097 ASSERT_require(nondef_decl->get_firstNondefiningDeclaration() == nondef_decl);
4098
4099 return buildProcedureHeaderStatement(name.str(), return_type, parameter_list, kind, scope, proc_header_stmt);
4100 }
4101
4102
4107 SgProcedureHeaderStatement* firstNondefDecl)
4108{
4109 ASSERT_not_null(firstNondefDecl);
4110 SgProcedureHeaderStatement* func{nullptr};
4111
4114 ASSERT_require(returnType == buildVoidType());
4115 }
4117 mlog[ERROR] << "unhandled subprogram kind for Fortran (or Jovial) function declaration:"
4118 << kind << endl;
4119 ROSE_ABORT();
4120 }
4121
4122 func = buildDefiningFunctionDeclaration_T<SgProcedureHeaderStatement>(SgName(name), returnType, params, /*isMemberFunction =*/false,
4123 scope, nullptr, 0U, firstNondefDecl, nullptr);
4124 ASSERT_not_null(func);
4125 func->set_subprogram_kind(kind);
4126
4127 return func;
4128}
4129
4130//------------------build value expressions -------------------
4131//-------------------------------------------------------------
4133{
4134 //TODO does valueString matter here?
4135 SgBoolValExp* boolValue= new SgBoolValExp(value);
4136 ROSE_ASSERT(boolValue);
4138 return boolValue;
4139}
4141{
4142 return buildBoolValExp(int(value));
4143}
4145{
4146 SgBoolValExp* boolValue= new SgBoolValExp(value);
4147 ROSE_ASSERT(boolValue);
4148 setOneSourcePositionNull(boolValue);
4149 return boolValue;
4150}
4151
4153 {
4154 SgNullptrValExp* nullptrValue = new SgNullptrValExp();
4155 ROSE_ASSERT(nullptrValue);
4157 return nullptrValue;
4158 }
4159
4161 {
4162 SgNullptrValExp* nullptrValue = new SgNullptrValExp();
4163 ROSE_ASSERT(nullptrValue);
4164 setOneSourcePositionNull(nullptrValue);
4165 return nullptrValue;
4166 }
4167
4169 {
4170 SgVoidVal* voidValue = new SgVoidVal();
4171 ROSE_ASSERT(voidValue);
4173 return voidValue;
4174 }
4175
4177 {
4178 SgVoidVal* voidValue = new SgVoidVal();
4179 ROSE_ASSERT(voidValue);
4180 setOneSourcePositionNull(voidValue);
4181 return voidValue;
4182 }
4183
4185{
4186 SgCharVal* result = new SgCharVal(value, "");
4187 ROSE_ASSERT(result);
4189 return result;
4190}
4191
4192SgCharVal* SageBuilder::buildCharVal_nfi(char value, const string& str)
4193{
4194 SgCharVal* result = new SgCharVal(value, str);
4195 ROSE_ASSERT(result);
4197 return result;
4198}
4199
4201{
4202 SgWcharVal* result = new SgWcharVal(value, "");
4203 ROSE_ASSERT(result);
4205 return result;
4206}
4207
4208SgWcharVal* SageBuilder::buildWcharVal_nfi(wchar_t value, const string& str)
4209{
4210 SgWcharVal* result = new SgWcharVal(value, str);
4211 ROSE_ASSERT(result);
4213 return result;
4214}
4215
4216// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
4217SgChar16Val* SageBuilder::buildChar16Val(unsigned short value /*= 0*/)
4218{
4219 SgChar16Val* result = new SgChar16Val(value, "");
4220 ROSE_ASSERT(result);
4222 return result;
4223}
4224
4225SgChar16Val* SageBuilder::buildChar16Val_nfi(unsigned short value, const string& str)
4226{
4227 SgChar16Val* result = new SgChar16Val(value, str);
4228 ROSE_ASSERT(result);
4230 return result;
4231}
4232
4233// DQ (2/16/2018): Adding support for char16_t and char32_t (C99 and C++11 specific types).
4234SgChar32Val* SageBuilder::buildChar32Val(unsigned int value /*= 0*/)
4235{
4236 SgChar32Val* result = new SgChar32Val(value, "");
4237 ROSE_ASSERT(result);
4239 return result;
4240}
4241
4242SgChar32Val* SageBuilder::buildChar32Val_nfi(unsigned int value, const string& str)
4243{
4244 SgChar32Val* result = new SgChar32Val(value, str);
4245 ROSE_ASSERT(result);
4247 return result;
4248}
4249
4250
4252{
4253 SgComplexVal* result = new SgComplexVal(real_value,imaginary_value,imaginary_value->get_type(),"");
4254 ROSE_ASSERT(result);
4255
4256// DQ (12/31/2008): set and test the parents
4257 if (real_value != NULL)
4258 real_value->set_parent(result);
4259
4260 if (imaginary_value != NULL)
4261 imaginary_value->set_parent(result);
4262
4263 ROSE_ASSERT(real_value == NULL || real_value->get_parent() != NULL);
4264 ROSE_ASSERT(imaginary_value == NULL || imaginary_value->get_parent() != NULL);
4265
4267 return result;
4268}
4269
4270SgComplexVal* SageBuilder::buildComplexVal_nfi(SgValueExp* real_value, SgValueExp* imaginary_value, const std::string& str)
4271{
4272 ROSE_ASSERT(imaginary_value != NULL);
4273 SgComplexVal* result = new SgComplexVal(real_value,imaginary_value,imaginary_value->get_type(),str);
4274 ROSE_ASSERT(result != NULL);
4275
4276// DQ (12/31/2008): set and test the parents
4277 if (real_value != NULL)
4278 real_value->set_parent(result);
4279
4280 if (imaginary_value != NULL)
4281 imaginary_value->set_parent(result);
4282
4283 ROSE_ASSERT(real_value == NULL || real_value->get_parent() != NULL);
4284 ROSE_ASSERT(imaginary_value == NULL || imaginary_value->get_parent() != NULL);
4285
4287 return result;
4288}
4289
4290SgComplexVal* SageBuilder::buildImaginaryVal(long double imaginary_value /*= 0.0*/ )
4291{
4292 SgComplexVal* result = new SgComplexVal(NULL,buildLongDoubleVal(imaginary_value),SgTypeLongDouble::createType(),"");
4293 ROSE_ASSERT(result);
4294
4295// DQ (12/31/2008): set and test the parents
4296 result->get_imaginary_value()->set_parent(result);
4297 ROSE_ASSERT(result->get_imaginary_value()->get_parent() != NULL);
4298
4300 return result;
4301}
4302
4304{
4305 ROSE_ASSERT(imaginary_value != NULL);
4306
4307 SgComplexVal* result = new SgComplexVal(NULL,imaginary_value,imaginary_value->get_type(),"");
4308 ROSE_ASSERT(result);
4309
4310// DQ (12/31/2008): set and test the parents
4311 imaginary_value->set_parent(result);
4312 ROSE_ASSERT(imaginary_value->get_parent() != NULL);
4313
4315 return result;
4316}
4317
4318SgComplexVal* SageBuilder::buildImaginaryVal_nfi(SgValueExp* imaginary_value, const std::string& str)
4319{
4320 ROSE_ASSERT(imaginary_value != NULL);
4321
4322 SgComplexVal* result = new SgComplexVal(NULL,imaginary_value,imaginary_value->get_type(),str);
4323 imaginary_value->set_parent(result);
4324 ROSE_ASSERT(result);
4325
4326// DQ (12/31/2008): set and test the parents
4327 ROSE_ASSERT(imaginary_value->get_parent() != NULL);
4328
4330 return result;
4331}
4332
4334{
4335 SgDoubleVal* value = new SgDoubleVal(t,"");
4336 ROSE_ASSERT(value);
4338 return value;
4339}
4340
4342{
4343 SgDoubleVal* value = new SgDoubleVal(t,str);
4344 ROSE_ASSERT(value);
4346 return value;
4347}
4348
4350{
4351 SgFloatVal* result = new SgFloatVal(value,"");
4352 ROSE_ASSERT(result);
4354 return result;
4355}
4356
4358{
4359 SgFloatVal* result = new SgFloatVal(value,"");
4360 ROSE_ASSERT(result);
4362 return result;
4363}
4364
4365SgFloatVal* SageBuilder::buildFloatVal_nfi(float value, const string& str)
4366{
4367 SgFloatVal* result = new SgFloatVal(value,str);
4368 ROSE_ASSERT(result);
4370 return result;
4371}
4372
4374{
4375 // C++11 please [CR 2020.02.25]
4376 // return buildFloatVal_nfi(std::stof(str), str);
4377 return buildFloatVal_nfi(atof(str.c_str()), str);
4378}
4379
4381 {
4382 SgIntVal* intValue= new SgIntVal(value,"");
4383 ASSERT_not_null(intValue);
4385 return intValue;
4386 }
4387
4389 {
4390 SgIntVal* intValue= new SgIntVal(value, (value >= 0 ? StringUtility::intToHex((unsigned int)value) : "-" + StringUtility::intToHex((unsigned int)(-value))));
4391 ASSERT_not_null(intValue);
4393 return intValue;
4394 }
4395
4397 {
4398 SgIntVal* intValue = new SgIntVal(value,"");
4399 ASSERT_not_null(intValue);
4400 setOneSourcePositionNull(intValue);
4401 return intValue;
4402 }
4403
4404SgIntVal* SageBuilder::buildIntVal_nfi(int value, const string& str)
4405 {
4406 SgIntVal* intValue = new SgIntVal(value,str);
4407 ASSERT_not_null(intValue);
4408 setOneSourcePositionNull(intValue);
4409 return intValue;
4410 }
4411
4413 {
4414 return buildIntVal_nfi(std::stoi(str), str);
4415 }
4416
4418{
4419 SgLongIntVal* intValue= new SgLongIntVal(value,"");
4420 ASSERT_not_null(intValue);
4422 return intValue;
4423}
4424
4425SgLongIntVal* SageBuilder::buildLongIntVal_nfi(long value, const string& str)
4426{
4427 SgLongIntVal* intValue= new SgLongIntVal(value,str);
4428 ASSERT_not_null(intValue);
4429 setOneSourcePositionNull(intValue);
4430 return intValue;
4431}
4432
4434{
4435 SgLongLongIntVal* intValue= new SgLongLongIntVal(value,"");
4436 ASSERT_not_null(intValue);
4438 return intValue;
4439}
4440
4441SgLongLongIntVal* SageBuilder::buildLongLongIntVal_nfi(long long value, const string& str)
4442{
4443 SgLongLongIntVal* intValue= new SgLongLongIntVal(value,str);
4444 ASSERT_not_null(intValue);
4445 setOneSourcePositionNull(intValue);
4446 return intValue;
4447}
4448
4450 {
4451 SgEnumVal* enumVal= new SgEnumVal(value,decl,name);
4452 ASSERT_not_null(enumVal);
4454 return enumVal;
4455 }
4456
4457
4459 {
4460 SgEnumVal* enumVal= new SgEnumVal(value,decl,name);
4461 ASSERT_not_null(enumVal);
4462 setOneSourcePositionNull(enumVal);
4463 return enumVal;
4464 }
4465
4467 SgInitializedName * init_name = sym->get_declaration();
4468 ROSE_ASSERT(init_name != NULL);
4469 SgAssignInitializer * assign_init = isSgAssignInitializer(init_name->get_initptr());
4470 ROSE_ASSERT(assign_init != NULL);
4471 SgEnumVal * enum_val = isSgEnumVal(assign_init->get_operand_i());
4472 ROSE_ASSERT(enum_val != NULL);
4473 enum_val = isSgEnumVal(SageInterface::copyExpression(enum_val));
4474 return enum_val;
4475}
4476
4478{
4479 SgLongDoubleVal* result = new SgLongDoubleVal(value,"");
4480 ASSERT_not_null(result);
4482 return result;
4483}
4484
4485SgLongDoubleVal* SageBuilder::buildLongDoubleVal_nfi(long double value, const string& str)
4486{
4487 SgLongDoubleVal* result = new SgLongDoubleVal(value,str);
4488 ASSERT_not_null(result);
4490 return result;
4491}
4492
4493SgFloat80Val* SageBuilder::buildFloat80Val(long double value /*= 0.0*/)
4494{
4495 SgFloat80Val* result = new SgFloat80Val(value,"");
4496 ASSERT_not_null(result);
4498 return result;
4499}
4500
4501SgFloat80Val* SageBuilder::buildFloat80Val_nfi(long double value, const string& str)
4502{
4503 SgFloat80Val* result = new SgFloat80Val(value,str);
4504 ASSERT_not_null(result);
4506 return result;
4507}
4508
4510{
4511 SgBFloat16Val* result = new SgBFloat16Val(value,"");
4512 ASSERT_not_null(result);
4514 return result;
4515}
4516
4517SgBFloat16Val* SageBuilder::buildBFloat16Val_nfi(float value, const string& str)
4518{
4519 SgBFloat16Val* result = new SgBFloat16Val(value,str);
4520 ASSERT_not_null(result);
4522 return result;
4523}
4524
4526{
4527 SgFloat16Val* result = new SgFloat16Val(value,"");
4528 ASSERT_not_null(result);
4530 return result;
4531}
4532
4533SgFloat16Val* SageBuilder::buildFloat16Val_nfi(float value, const string& str)
4534{
4535 SgFloat16Val* result = new SgFloat16Val(value,str);
4536 ASSERT_not_null(result);
4538 return result;
4539}
4540
4542{
4543 SgFloat32Val* result = new SgFloat32Val(value,"");
4544 ASSERT_not_null(result);
4546 return result;
4547}
4548
4549SgFloat32Val* SageBuilder::buildFloat32Val_nfi(float value, const string& str)
4550{
4551 SgFloat32Val* result = new SgFloat32Val(value,str);
4552 ASSERT_not_null(result);
4554 return result;
4555}
4556
4558{
4559 SgFloat64Val* result = new SgFloat64Val(value,"");
4560 ASSERT_not_null(result);
4562 return result;
4563}
4564
4565SgFloat64Val* SageBuilder::buildFloat64Val_nfi(double value, const string& str)
4566{
4567 SgFloat64Val* result = new SgFloat64Val(value,str);
4568 ASSERT_not_null(result);
4570 return result;
4571}
4572
4574{
4575 SgFloat128Val* result = new SgFloat128Val(value,"");
4576 ASSERT_not_null(result);
4578 return result;
4579}
4580
4581SgFloat128Val* SageBuilder::buildFloat128Val_nfi(long double value, const string& str)
4582{
4583 SgFloat128Val* result = new SgFloat128Val(value,str);
4584 ASSERT_not_null(result);
4586 return result;
4587}
4588
4589SgStringVal* SageBuilder::buildStringVal(std::string value /*=""*/)
4590{
4591 SgStringVal* result = new SgStringVal(value);
4592 ASSERT_not_null(result);
4594 return result;
4595}
4596
4598{
4599 SgStringVal* result = new SgStringVal(value);
4600 ASSERT_not_null(result);
4602 return result;
4603}
4604
4606{
4607 SgUnsignedCharVal* result = new SgUnsignedCharVal(v,"");
4608 ASSERT_not_null(result);
4610 return result;
4611}
4612
4614{
4616 ASSERT_not_null(result);
4618 return result;
4619}
4620
4622{
4623 SgUnsignedCharVal* result = new SgUnsignedCharVal(v,str);
4624 ASSERT_not_null(result);
4626 return result;
4627}
4628
4630{
4631 SgSignedCharVal* result = new SgSignedCharVal(v,"");
4632 ASSERT_not_null(result);
4634 return result;
4635}
4636
4638{
4640 ASSERT_not_null(result);
4642 return result;
4643}
4644
4646{
4647 SgSignedCharVal* result = new SgSignedCharVal(v,str);
4648 ASSERT_not_null(result);
4650 return result;
4651}
4652
4654{
4655 SgShortVal* result = new SgShortVal(v,"");
4656 ASSERT_not_null(result);
4658 return result;
4659}
4660
4662{
4663 SgShortVal* result = new SgShortVal(v, (v >= 0 ? StringUtility::intToHex((unsigned int)v) : "-" + StringUtility::intToHex((unsigned int)(-v))));
4664 ASSERT_not_null(result);
4666 return result;
4667}
4668
4669SgShortVal* SageBuilder::buildShortVal_nfi(short v, const string& str)
4670{
4671 SgShortVal* result = new SgShortVal(v,str);
4672 ASSERT_not_null(result);
4674 return result;
4675}
4676
4678{
4679 SgUnsignedShortVal* result = new SgUnsignedShortVal(v,"");
4680 ASSERT_not_null(result);
4682 return result;
4683}
4684
4686{
4688 ASSERT_not_null(result);
4690 return result;
4691}
4692
4694{
4695 SgUnsignedShortVal* result = new SgUnsignedShortVal(v,str);
4696 ASSERT_not_null(result);
4698 return result;
4699}
4700
4702{
4703 SgUnsignedIntVal* result = new SgUnsignedIntVal(v,"");
4704 ASSERT_not_null(result);
4706 return result;
4707}
4708
4710{
4712 ASSERT_not_null(result);
4714 return result;
4715}
4716
4718{
4719 SgUnsignedIntVal* result = new SgUnsignedIntVal(v,str);
4720 ASSERT_not_null(result);
4722 return result;
4723}
4724
4726{
4727 SgUnsignedLongVal* result = new SgUnsignedLongVal(v,"");
4728 ASSERT_not_null(result);
4730 return result;
4731}
4732
4734{
4736 ASSERT_not_null(result);
4738 return result;
4739}
4740
4742{
4743 SgUnsignedLongVal* result = new SgUnsignedLongVal(v,str);
4744 ASSERT_not_null(result);
4746 return result;
4747}
4748
4750{
4752 ASSERT_not_null(result);
4754 return result;
4755}
4756
4758{
4760 ASSERT_not_null(result);
4762 return result;
4763}
4764
4766{
4768 ASSERT_not_null(result);
4770 return result;
4771}
4772
4773SgJovialBitVal* SageBuilder::buildJovialBitVal_nfi(const string& str)
4774{
4775 SgJovialBitVal* result = new SgJovialBitVal(str);
4776 ASSERT_not_null(result);
4778 return result;
4779}
4780
4782{
4783 SgTemplateType* result = new SgTemplateType (name);
4784 ASSERT_not_null (result);
4786 return result;
4787}
4788
4790{
4791 ROSE_ASSERT (t);
4792 SgTemplateParameter* result = new SgTemplateParameter(parameterType, t);
4793 ROSE_ASSERT (result);
4795 return result;
4796}
4797
4799{
4800 SgTemplateParameterVal* templateParameterValue = new SgTemplateParameterVal(template_parameter_position,"");
4801 ROSE_ASSERT(templateParameterValue);
4802 setOneSourcePositionForTransformation(templateParameterValue);
4803
4804// DQ (7/25/2012): Assert this (it will be set later).
4805 ROSE_ASSERT(templateParameterValue->get_parent() == NULL);
4806
4807 return templateParameterValue;
4808}
4809
4810SgTemplateParameterVal* SageBuilder::buildTemplateParameterVal_nfi(int template_parameter_position, const string& str)
4811{
4812 SgTemplateParameterVal* templateParameterValue= new SgTemplateParameterVal(template_parameter_position,str);
4813 ROSE_ASSERT(templateParameterValue);
4814 setOneSourcePositionNull(templateParameterValue);
4815
4816// DQ (7/25/2012): Assert this (it will be set later).
4817 ROSE_ASSERT(templateParameterValue->get_parent() == NULL);
4818
4819 return templateParameterValue;
4820}
4821
4822#define DEBUG_BUILD_NONREAL_DECL 0
4823
4825 ROSE_ASSERT(scope != NULL);
4826#if DEBUG_BUILD_NONREAL_DECL
4827 printf("ENTER SageBuilder::buildNonrealDecl\n");
4828 printf(" --- name = %s\n", name.str());
4829 printf(" --- scope = %p (%s)\n", scope, scope->class_name().c_str());
4830#endif
4831
4832 SgNonrealDecl * nrdecl = NULL;
4833
4834 nrdecl = new SgNonrealDecl(name);
4836 nrdecl->set_firstNondefiningDeclaration(nrdecl);
4837#if DEBUG_BUILD_NONREAL_DECL
4838 printf(" --- nrdecl = %p (%s)\n", nrdecl, nrdecl->class_name().c_str());
4839#endif
4840
4841 SgNonrealSymbol * symbol = new SgNonrealSymbol(nrdecl);
4842 scope->insert_symbol(name, symbol);
4843#if DEBUG_BUILD_NONREAL_DECL
4844 printf(" --- symbol = %p (%s)\n", symbol, symbol->class_name().c_str());
4845#endif
4846
4847 SgNonrealType * type = new SgNonrealType();
4848 type->set_declaration(nrdecl);
4849 type->set_parent(scope);
4850 nrdecl->set_type(type);
4851 // FIXME (???) insert `type` in `scope`
4852#if DEBUG_BUILD_NONREAL_DECL
4853 printf(" --- type = %p (%s)\n", type, type->class_name().c_str());
4854#endif
4855
4856 if (child_scope == NULL) {
4857 child_scope = new SgDeclarationScope();
4858#if DEBUG_BUILD_NONREAL_DECL
4859 printf(" --- child_scope = %p (new)\n", name.str(), child_scope);
4860#endif
4863 child_scope->get_endOfConstruct()->setCompilerGenerated();
4864 } else {
4865#if DEBUG_BUILD_NONREAL_DECL
4866 printf(" --- child_scope = %p (provided)\n", name.str(), child_scope);
4867#endif
4868
4869 }
4870 child_scope->set_parent(nrdecl);
4871 nrdecl->set_nonreal_decl_scope(child_scope);
4872
4873#if DEBUG_BUILD_NONREAL_DECL
4874 printf("LEAVE SageBuilder::buildNonrealDecl\n");
4875#endif
4876
4877 return nrdecl;
4878}
4879
4882{
4883 SgUpcThreads* result = new SgUpcThreads(0,"");
4884 ROSE_ASSERT(result);
4886 return result;
4887}
4888
4891{
4892 SgUpcThreads* result = new SgUpcThreads(0,"");
4893 ROSE_ASSERT(result);
4895 return result;
4896}
4897
4900{
4901 SgUpcMythread* result = new SgUpcMythread(0,"");
4902 ROSE_ASSERT(result);
4904 return result;
4905}
4906
4909{
4910 SgUpcMythread* result = new SgUpcMythread(0,"");
4911 ROSE_ASSERT(result);
4913 return result;
4914}
4915
4917{
4918 SgThisExp* result = new SgThisExp(isSgClassSymbol(sym), isSgNonrealSymbol(sym), 0);
4919 ROSE_ASSERT(result);
4921 return result;
4922}
4923
4925{
4926 SgThisExp* result = new SgThisExp(isSgClassSymbol(sym), isSgNonrealSymbol(sym), 0);
4927 ROSE_ASSERT(result);
4929 return result;
4930}
4931
4933{
4934 SgSuperExp* result = new SgSuperExp(sym, 0);
4935 ROSE_ASSERT(result);
4937 return result;
4938}
4939
4941{
4942 SgSuperExp* result = new SgSuperExp(sym, 0);
4943 ROSE_ASSERT(result);
4945 return result;
4946}
4947
4949{
4950 SgClassExp* result = new SgClassExp(sym, 0);
4951 ROSE_ASSERT(result);
4953 return result;
4954}
4955
4957{
4958 SgClassExp* result = new SgClassExp(sym, 0);
4959 ROSE_ASSERT(result);
4961 return result;
4962}
4963
4966{
4967 SgTupleExp* tuple = new SgTupleExp();
4968 ROSE_ASSERT(tuple);
4969 if (elt1) appendExpression(tuple, elt1);
4970 if (elt2) appendExpression(tuple, elt2);
4971 if (elt3) appendExpression(tuple, elt3);
4972 if (elt4) appendExpression(tuple, elt4);
4973 if (elt5) appendExpression(tuple, elt5);
4974 if (elt6) appendExpression(tuple, elt6);
4975 if (elt7) appendExpression(tuple, elt7);
4976 if (elt8) appendExpression(tuple, elt8);
4977 if (elt9) appendExpression(tuple, elt9);
4978 if (elt10) appendExpression(tuple, elt10);
4979
4981 return tuple;
4982}
4983
4985SageBuilder::buildTupleExp(const std::vector<SgExpression*>& elts)
4986{
4988 appendExpressionList(expList, elts);
4989 return expList;
4990}
4991
4994{
4995 SgTupleExp* tuple = new SgTupleExp();
4996 ROSE_ASSERT(tuple);
4998 return tuple;
4999}
5000
5002SageBuilder::buildTupleExp_nfi(const std::vector<SgExpression*>& elts)
5003{
5005 appendExpressionList(tuple, elts);
5006 return tuple;
5007}
5008
5009SgListExp*
5011{
5012 SgListExp* tuple = new SgListExp();
5013 ROSE_ASSERT(tuple);
5014 if (elt1) appendExpression(tuple, elt1);
5015 if (elt2) appendExpression(tuple, elt2);
5016 if (elt3) appendExpression(tuple, elt3);
5017 if (elt4) appendExpression(tuple, elt4);
5018 if (elt5) appendExpression(tuple, elt5);
5019 if (elt6) appendExpression(tuple, elt6);
5020 if (elt7) appendExpression(tuple, elt7);
5021 if (elt8) appendExpression(tuple, elt8);
5022 if (elt9) appendExpression(tuple, elt9);
5023 if (elt10) appendExpression(tuple, elt10);
5024
5026 return tuple;
5027}
5028
5029SgListExp*
5030SageBuilder::buildListExp(const std::vector<SgExpression*>& elts)
5031{
5033 appendExpressionList(expList, elts);
5034 return expList;
5035}
5036
5037SgListExp*
5039{
5040 SgListExp* tuple = new SgListExp();
5041 ROSE_ASSERT(tuple);
5043 return tuple;
5044}
5045
5046SgListExp*
5047SageBuilder::buildListExp_nfi(const std::vector<SgExpression*>& elts)
5048{
5050 appendExpressionList(tuple, elts);
5051 return tuple;
5052}
5053
5054
5055#define BUILD_UNARY_DEF(suffix) \
5056 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix##_nfi(SgExpression* op) \
5057 { \
5058 return SageBuilder::buildUnaryExpression_nfi<Sg##suffix>(op); \
5059 } \
5060 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix(SgExpression* op) \
5061 { \
5062 return SageBuilder::buildUnaryExpression<Sg##suffix>(op); \
5063 }
5064
5065BUILD_UNARY_DEF(AddressOfOp)
5066BUILD_UNARY_DEF(BitComplementOp)
5067BUILD_UNARY_DEF(MinusOp)
5068BUILD_UNARY_DEF(NotOp)
5069BUILD_UNARY_DEF(PointerDerefExp)
5070BUILD_UNARY_DEF(UnaryAddOp)
5071BUILD_UNARY_DEF(AbsOp)
5072BUILD_UNARY_DEF(MinusMinusOp)
5073BUILD_UNARY_DEF(PlusPlusOp)
5074BUILD_UNARY_DEF(RealPartOp)
5075BUILD_UNARY_DEF(ImagPartOp)
5076BUILD_UNARY_DEF(ConjugateOp)
5077BUILD_UNARY_DEF(VarArgStartOneOperandOp)
5078BUILD_UNARY_DEF(VarArgEndOp)
5079
5080BUILD_UNARY_DEF(MatrixTransposeOp) //SK(08/20/2015): Matlab matrix transpose operators
5081
5082#undef BUILD_UNARY_DEF
5083
5085 SgType * expression_type,
5086 SgCastExp::cast_type_enum cast_type)
5087{
5088 SgCastExp* result = new SgCastExp(operand_i, expression_type, cast_type);
5089 ROSE_ASSERT(result);
5090 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5092 return result;
5093}
5094
5095SgNewExp*
5097 SgExprListExp* placement_args,
5098 SgConstructorInitializer* constructor_args,
5099 SgExpression* builtin_args,
5100 // FIXME: Change this from "short int" to "bool".
5101 short int need_global_specifier,
5102 SgFunctionDeclaration* newOperatorDeclaration)
5103 {
5104 // DQ (11/18/2012): Modified parameter names to make this function more clear.
5105 SgNewExp* result = new SgNewExp(specified_type, placement_args, constructor_args, builtin_args, need_global_specifier, newOperatorDeclaration);
5106 ROSE_ASSERT(result);
5107
5109 return result;
5110 }
5111
5113 short is_array,
5114 short need_global_specifier,
5115 SgFunctionDeclaration* deleteOperatorDeclaration)
5116{
5117 SgDeleteExp* result = new SgDeleteExp(variable, is_array,
5118 need_global_specifier, deleteOperatorDeclaration);
5119 ROSE_ASSERT(result);
5121 return result;
5122}
5123
5126 {
5127 // DQ (1/25/2013): Added support for typeId operators.
5128 SgTypeIdOp* result = new SgTypeIdOp(operand_expr,operand_type);
5129 ROSE_ASSERT(result != NULL);
5131 return result;
5132 }
5133
5135{
5136 SgCastExp* result = new SgCastExp(operand_i, expression_type, cast_type);
5137 ROSE_ASSERT(result);
5138 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5140 return result;
5141}
5142
5144 SgVarArgOp* result = new SgVarArgOp(operand_i, expression_type);
5145 ROSE_ASSERT(result);
5146 if (operand_i) {operand_i->set_parent(result); markLhsValues(result);}
5148 return result;
5149}
5150
5152{
5153 SgMinusMinusOp* result = buildUnaryExpression<SgMinusMinusOp>(operand_i);
5154 ROSE_ASSERT(result);
5155 result->set_mode(a_mode);
5156 return result;
5157}
5158
5160{
5161 SgMinusMinusOp* result = buildUnaryExpression_nfi<SgMinusMinusOp>(operand_i);
5162 ROSE_ASSERT(result);
5163 result->set_mode(a_mode);
5164 return result;
5165}
5166
5168{
5169 SgMinusOp* result = buildUnaryExpression<SgMinusOp>(operand_i);
5170 ROSE_ASSERT(result);
5171 result->set_mode(a_mode);
5172 return result;
5173}
5174
5176{
5177 SgMinusOp* result = buildUnaryExpression_nfi<SgMinusOp>(operand_i);
5178 ROSE_ASSERT(result);
5179 result->set_mode(a_mode);
5180 return result;
5181}
5182
5184{
5185 SgPlusPlusOp* result = buildUnaryExpression<SgPlusPlusOp>(operand_i);
5186 ROSE_ASSERT(result);
5187 result->set_mode(a_mode);
5188 return result;
5189}
5190
5191
5193{
5194 SgPlusPlusOp* result = buildUnaryExpression_nfi<SgPlusPlusOp>(operand_i);
5195 ROSE_ASSERT(result);
5196 result->set_mode(a_mode);
5197 return result;
5198}
5199
5201 {
5202 // DQ (11/8/2011): operand_i is allowed to be NULL.
5203
5204 // SgThrowOp* result = new SgThrowOp(operand_i, operand_i -> get_type(), throwKind);
5205 SgThrowOp* result = new SgThrowOp(operand_i, (operand_i != NULL) ? operand_i->get_type() : NULL, throwKind);
5206
5207 if (operand_i)
5208 {
5209 markLhsValues(result);
5210 }
5211
5213
5214 if (operand_i)
5215 operand_i -> set_parent(result);
5216
5217 ROSE_ASSERT(result);
5218
5219 return result;
5220 }
5221
5222
5223
5224#define BUILD_BINARY_DEF(suffix) \
5225 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix##_nfi(SgExpression* lhs, SgExpression* rhs) \
5226 { \
5227 return buildBinaryExpression_nfi<Sg##suffix>(lhs, rhs); \
5228 } \
5229 ROSE_DLL_API Sg##suffix* SageBuilder::build##suffix(SgExpression* lhs, SgExpression* rhs) \
5230 { \
5231 return buildBinaryExpression<Sg##suffix>(lhs, rhs); \
5232 }
5233
5234BUILD_BINARY_DEF(AddOp)
5235BUILD_BINARY_DEF(AndAssignOp)
5236BUILD_BINARY_DEF(AndOp)
5237BUILD_BINARY_DEF(ArrowExp)
5238BUILD_BINARY_DEF(ArrowStarOp)
5239BUILD_BINARY_DEF(AssignOp)
5240BUILD_BINARY_DEF(AtOp)
5241BUILD_BINARY_DEF(BitAndOp)
5242BUILD_BINARY_DEF(BitOrOp)
5243BUILD_BINARY_DEF(BitXorOp)
5244
5245BUILD_BINARY_DEF(CommaOpExp)
5246BUILD_BINARY_DEF(ConcatenationOp)
5247BUILD_BINARY_DEF(DivAssignOp)
5248BUILD_BINARY_DEF(DivideOp)
5249BUILD_BINARY_DEF(DotExp)
5250BUILD_BINARY_DEF(DotStarOp)
5251BUILD_BINARY_DEF(EqualityOp)
5252
5253BUILD_BINARY_DEF(ExponentiationOp)
5254BUILD_BINARY_DEF(ExponentiationAssignOp)
5255BUILD_BINARY_DEF(GreaterOrEqualOp)
5256BUILD_BINARY_DEF(GreaterThanOp)
5257BUILD_BINARY_DEF(IntegerDivideOp)
5258BUILD_BINARY_DEF(IntegerDivideAssignOp)
5259BUILD_BINARY_DEF(IorAssignOp)
5260BUILD_BINARY_DEF(IsOp)
5261BUILD_BINARY_DEF(IsNotOp)
5262
5263BUILD_BINARY_DEF(LessOrEqualOp)
5264BUILD_BINARY_DEF(LessThanOp)
5265BUILD_BINARY_DEF(LshiftAssignOp)
5266BUILD_BINARY_DEF(LshiftOp)
5267
5268BUILD_BINARY_DEF(MembershipOp)
5269BUILD_BINARY_DEF(MinusAssignOp)
5270BUILD_BINARY_DEF(ModAssignOp)
5271BUILD_BINARY_DEF(ModOp)
5272BUILD_BINARY_DEF(MultAssignOp)
5273BUILD_BINARY_DEF(MultiplyOp)
5274
5275BUILD_BINARY_DEF(NotEqualOp)
5276BUILD_BINARY_DEF(NonMembershipOp)
5277BUILD_BINARY_DEF(OrOp)
5278BUILD_BINARY_DEF(PlusAssignOp)
5279BUILD_BINARY_DEF(PntrArrRefExp)
5280BUILD_BINARY_DEF(RemOp)
5281BUILD_BINARY_DEF(RshiftAssignOp)
5282BUILD_BINARY_DEF(JavaUnsignedRshiftAssignOp)
5283
5284BUILD_BINARY_DEF(RshiftOp)
5285BUILD_BINARY_DEF(JavaUnsignedRshiftOp)
5286BUILD_BINARY_DEF(ScopeOp)
5287BUILD_BINARY_DEF(SubtractOp)
5288BUILD_BINARY_DEF(XorAssignOp)
5289
5290BUILD_BINARY_DEF(VarArgCopyOp)
5291BUILD_BINARY_DEF(VarArgStartOp)
5292
5293// CR(07/26/2018): Jovial operators
5294BUILD_BINARY_DEF(ReplicationOp);
5295
5296//SK(08/20/2015): Matlab operators
5297BUILD_BINARY_DEF(PowerOp);
5298BUILD_BINARY_DEF(ElementwisePowerOp);
5299BUILD_BINARY_DEF(ElementwiseMultiplyOp);
5300BUILD_BINARY_DEF(ElementwiseDivideOp);
5301BUILD_BINARY_DEF(LeftDivideOp);
5302BUILD_BINARY_DEF(ElementwiseLeftDivideOp);
5303BUILD_BINARY_DEF(ElementwiseAddOp);
5304BUILD_BINARY_DEF(ElementwiseSubtractOp);
5305
5306// DQ (7/25/2020): Adding C++20 support
5307BUILD_BINARY_DEF(SpaceshipOp)
5308
5309#undef BUILD_BINARY_DEF
5310
5311
5312
5313// CR ( 1/25/2018):
5314// (10/30/2018): Fixed case when this function is called with NULL dim_info object.
5316 {
5317 ROSE_ASSERT(base_type != NULL);
5318
5319 // There must always be a dim_info object for this function. If not, the
5320 // overloaded function must be used to handle it.
5321 if (dim_info == NULL)
5322 {
5323 SgExpression* index = NULL;
5324 return buildArrayType(base_type, index);
5325 }
5326
5327 SgExpression* index = new SgNullExpression();
5328 ROSE_ASSERT(index);
5329 setSourcePosition(index);
5330
5331 SgArrayType* array_type = new SgArrayType(base_type, index);
5332 ROSE_ASSERT(array_type);
5333 ROSE_ASSERT(array_type->get_dim_info() == NULL);
5334
5335 index ->set_parent(array_type);
5336 dim_info->set_parent(array_type);
5337
5338 array_type->set_dim_info(dim_info);
5339 array_type->set_rank(dim_info->get_expressions().size());
5340
5341 return array_type;
5342 }
5343
5344SgArrayType* SageBuilder::buildArrayType(SgType* base_type/*=NULL*/, SgExpression* index/*=NULL*/)
5345{
5346 SgArrayType* result = new SgArrayType(base_type,index);
5347 ASSERT_not_null(result);
5348
5349 if (index != nullptr) {
5350 index->set_parent(result); // important!
5351 }
5352
5353 return result;
5354}
5355
5357{
5358 SgConditionalExp* result = new SgConditionalExp(test, a, b, NULL);
5359 if (test) test->set_parent(result);
5360 if (a) a->set_parent(result);
5361 if (b) b->set_parent(result);
5363 return result;
5364}
5365
5367{
5368 SgConditionalExp* result = new SgConditionalExp(test, a, b, t);
5369 if (test) test->set_parent(result);
5370 if (a) {a->set_parent(result); markLhsValues(a);}
5371 if (b) {b->set_parent(result); markLhsValues(b);}
5373 return result;
5374}
5375
5377{
5379 ROSE_ASSERT(result);
5381 return result;
5382}
5383
5386 ROSE_ASSERT(ne);
5388 return ne;
5389}
5390
5396
5398 SgColonShapeExp* expr = new SgColonShapeExp();
5399 ASSERT_not_null(expr);
5401 return expr;
5402}
5403
5409
5410SgAssignInitializer * SageBuilder::buildAssignInitializer(SgExpression * operand_i /*= NULL*/, SgType * expression_type /* = NULL */)
5411 {
5412 SgAssignInitializer* result = new SgAssignInitializer(operand_i, expression_type);
5413 ROSE_ASSERT(result);
5414 if (operand_i!=NULL)
5415 {
5416 operand_i->set_parent(result);
5417 // set lvalue, it asserts operand!=NULL
5418 markLhsValues(result);
5419 }
5421 return result;
5422 }
5423
5424SgAssignInitializer * SageBuilder::buildAssignInitializer_nfi(SgExpression * operand_i /*= nullptr*/, SgType * expression_type /*=nullptr*/)
5425 {
5426 SgAssignInitializer* result = new SgAssignInitializer(operand_i, expression_type);
5427 ASSERT_not_null(result);
5428 if (operand_i)
5429 {
5430 operand_i->set_parent(result);
5431 // set lvalue, it asserts operand!=NULL
5432 markLhsValues(result);
5433 }
5434
5435 setSourcePosition(result);
5436 result->set_need_paren(false);
5437
5438 return result;
5439 }
5440
5443{
5444 SgAggregateInitializer* result = new SgAggregateInitializer(initializers, type);
5445 ROSE_ASSERT(result);
5446 if (initializers!=NULL)
5447 {
5448 initializers->set_parent(result);
5449 }
5450 result->set_need_explicit_braces(true);
5452 return result;
5453}
5454
5457{
5458 SgAggregateInitializer* result = new SgAggregateInitializer(initializers, type);
5459 ROSE_ASSERT(result);
5460 if (initializers!=NULL)
5461 {
5462 initializers->set_parent(result);
5463 }
5464 result->set_need_explicit_braces(true);
5466 return result;
5467}
5468
5471{
5472 SgCompoundInitializer* result = new SgCompoundInitializer(initializers, type);
5473 ROSE_ASSERT(result);
5474 if (initializers!=NULL)
5475 {
5476 initializers->set_parent(result);
5477 }
5479 return result;
5480}
5481
5484{
5485 SgCompoundInitializer* result = new SgCompoundInitializer(initializers, type);
5486 ROSE_ASSERT(result);
5487 if (initializers!=NULL)
5488 {
5489 initializers->set_parent(result);
5490 }
5492 return result;
5493}
5494
5495// DQ (1/4/2009): Added support for SgConstructorInitializer
5498 SgMemberFunctionDeclaration *declaration/* = NULL*/,
5499 SgExprListExp *args/* = NULL*/,
5500 SgType *expression_type/* = NULL*/,
5501 bool need_name /*= false*/,
5502 bool need_qualifier /*= false*/,
5503 bool need_parenthesis_after_name /*= false*/,
5504 bool associated_class_unknown /*= false*/)
5505 {
5506 // Prototype:
5507 // SgConstructorInitializer (SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type,
5508 // bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown);
5509
5510 //George Vulov (05/24/2011) Modified this assertion to allow for a NULL declaration (in case of implicit constructors)
5511 ROSE_ASSERT(declaration == NULL || declaration->get_associatedClassDeclaration() != NULL);
5512
5513 SgConstructorInitializer* result = new SgConstructorInitializer( declaration, args, expression_type, need_name,
5514 need_qualifier, need_parenthesis_after_name, associated_class_unknown );
5515 ROSE_ASSERT(result != NULL);
5516 if (args != NULL)
5517 {
5518 args->set_parent(result);
5520 }
5521
5523
5524 return result;
5525 }
5526
5527// DQ (1/4/2009): Added support for SgConstructorInitializer
5530 SgMemberFunctionDeclaration *declaration/* = NULL*/,
5531 SgExprListExp *args/* = NULL*/,
5532 SgType *expression_type/* = NULL*/,
5533 bool need_name /*= false*/,
5534 bool need_qualifier /*= false*/,
5535 bool need_parenthesis_after_name /*= false*/,
5536 bool associated_class_unknown /*= false*/)
5537 {
5538 // Prototype:
5539 // SgConstructorInitializer (SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type, bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown);
5540
5541 // DQ (11/7/2011): Fix symetric to the way George did it above.
5542 ROSE_ASSERT(declaration == NULL || declaration->get_associatedClassDeclaration() != NULL);
5543
5544 SgConstructorInitializer* result = new SgConstructorInitializer( declaration, args, expression_type, need_name, need_qualifier, need_parenthesis_after_name, associated_class_unknown );
5545 ROSE_ASSERT(result != NULL);
5546
5548
5549 if (args != NULL)
5550 {
5551 args->set_parent(result);
5552 }
5553
5554 // DQ (11/4/2012): This is required and appears to work fine now.
5555 // DQ (11/23/2011): Fixup the expression list (but this does not appear to work...)
5556 if (result->get_args()->get_startOfConstruct() == NULL)
5557 {
5558 setOneSourcePositionNull(result->get_args());
5559 }
5560
5561 return result;
5562 }
5563
5564// DQ (11/15/2016):Adding support for braced initializer (required for template support).
5568 {
5569 SgBracedInitializer* result = new SgBracedInitializer(initializers, expression_type);
5570 ROSE_ASSERT(result);
5571 if (initializers!=NULL)
5572 {
5573 initializers->set_parent(result);
5574 }
5576 return result;
5577 }
5578
5580 {
5581 SgBracedInitializer* result = new SgBracedInitializer(initializers, expression_type);
5582 ROSE_ASSERT(result);
5583 if (initializers!=NULL)
5584 {
5585 initializers->set_parent(result);
5586 }
5588 return result;
5589 }
5590
5591
5594 {
5595 // SgType* exp_type = NULL;
5596 // if (exp) exp_type = exp->get_type();
5597
5598 SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, NULL);
5599 // SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, exp_type);
5600 ROSE_ASSERT(result);
5601 if (exp)
5602 {
5603 exp->set_parent(result);
5604 markLhsValues(result);
5605 }
5607 return result;
5608 }
5609
5612 {
5613 // SgType* exp_type =NULL;
5614 // if (exp) exp_type = exp->get_type();
5615
5616 SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, NULL);
5617 // SgSizeOfOp* result = new SgSizeOfOp(exp,NULL, exp_type);
5618 ROSE_ASSERT(result);
5619 if (exp)
5620 {
5621 exp->set_parent(result);
5622 markLhsValues(result);
5623 }
5625 return result;
5626 }
5627
5630 {
5631 SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,NULL);
5632 // SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,type);
5633 ROSE_ASSERT(result);
5635 return result;
5636 }
5637
5640 {
5641 SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,NULL);
5642 // SgSizeOfOp* result = new SgSizeOfOp((SgExpression*)NULL,type,type);
5643 ROSE_ASSERT(result);
5645 return result;
5646 }
5647
5650 {
5651 // SgType* exp_type =NULL;
5652 // if (exp) exp_type = exp->get_type();
5653
5654 SgAlignOfOp* result = new SgAlignOfOp(exp,NULL, NULL);
5655 ROSE_ASSERT(result);
5656 if (exp)
5657 {
5658 exp->set_parent(result);
5659 markLhsValues(result);
5660 }
5662 return result;
5663 }
5664
5667 {
5668 // SgType* exp_type =NULL;
5669 // if (exp) exp_type = exp->get_type();
5670
5671 SgAlignOfOp* result = new SgAlignOfOp(exp,NULL, NULL);
5672 ROSE_ASSERT(result);
5673 if (exp)
5674 {
5675 exp->set_parent(result);
5676 markLhsValues(result);
5677 }
5679 return result;
5680 }
5681
5684 {
5685 // SgType* exp_type =NULL;
5686 // if (exp) exp_type = exp->get_type();
5687
5688 SgNoexceptOp* result = new SgNoexceptOp(exp);
5689 ROSE_ASSERT(result);
5690 if (exp)
5691 {
5692 exp->set_parent(result);
5693 markLhsValues(result);
5694 }
5695
5697 return result;
5698 }
5699
5702 {
5703 // SgType* exp_type =NULL;
5704 // if (exp) exp_type = exp->get_type();
5705
5706 SgNoexceptOp* result = new SgNoexceptOp(exp);
5707 ROSE_ASSERT(result);
5708 if (exp)
5709 {
5710 exp->set_parent(result);
5711 markLhsValues(result);
5712 }
5713
5715 return result;
5716 }
5717
5720 {
5721 SgAlignOfOp* result = new SgAlignOfOp((SgExpression*)NULL,type,NULL);
5722 ROSE_ASSERT(result);
5724 return result;
5725 }
5726
5729 {
5730 SgAlignOfOp* result = new SgAlignOfOp((SgExpression*)NULL,type,NULL);
5731 ROSE_ASSERT(result);
5733 return result;
5734 }
5735
5736
5738{
5739 SgExprListExp* expList = new SgExprListExp();
5740 ROSE_ASSERT(expList);
5741
5742// printf ("In SageBuilder::buildExprListExp(SgExpression * expr1, SgExpression* expr2, ...): SgExprListExp* expList = %p \n",expList);
5743
5745 if (expr1) appendExpression(expList, expr1);
5746 if (expr2) appendExpression(expList, expr2);
5747 if (expr3) appendExpression(expList, expr3);
5748 if (expr4) appendExpression(expList, expr4);
5749 if (expr5) appendExpression(expList, expr5);
5750 if (expr6) appendExpression(expList, expr6);
5751 if (expr7) appendExpression(expList, expr7);
5752 if (expr8) appendExpression(expList, expr8);
5753 if (expr9) appendExpression(expList, expr9);
5754 if (expr10) appendExpression(expList, expr10);
5755 return expList;
5756}
5757
5758// CH (5/11/2010): Seems that this function is useful.
5759SgExprListExp * SageBuilder::buildExprListExp(const std::vector<SgExpression*>& exprs)
5760{
5761 SgExprListExp* expList = new SgExprListExp();
5762 ROSE_ASSERT(expList);
5763
5765 for (size_t i = 0; i < exprs.size(); ++i) {
5766 appendExpression(expList, exprs[i]);
5767 }
5768 return expList;
5769}
5770
5772 {
5773 SgExprListExp* expList = new SgExprListExp();
5774 ROSE_ASSERT(expList);
5775
5776 setOneSourcePositionNull(expList);
5777 return expList;
5778 }
5779
5780SgExprListExp * SageBuilder::buildExprListExp_nfi(const std::vector<SgExpression*>& exprs)
5781 {
5782 SgExprListExp* expList = new SgExprListExp();
5783 ROSE_ASSERT(expList != NULL);
5784
5785 setOneSourcePositionNull(expList);
5786 for (size_t i = 0; i < exprs.size(); ++i)
5787 {
5788 appendExpression(expList, exprs[i]);
5789 }
5790
5791 // DQ (4/3/2012): Added test to make sure that the pointers are unique.
5792 testAstForUniqueNodes(expList);
5793
5794 return expList;
5795 }
5796
5799 {
5800 if (lower_bound == NULL)
5801 {
5803 }
5804 if (stride == NULL)
5805 {
5807 }
5808
5809 ROSE_ASSERT(lower_bound);
5810 ROSE_ASSERT(upper_bound);
5811 ROSE_ASSERT(stride);
5812
5813 SgSubscriptExpression* subscript = new SgSubscriptExpression(lower_bound, upper_bound, stride);
5814 ROSE_ASSERT(subscript);
5816
5817 // Set the parents of all the parts of the SgSubscriptExpression
5818 lower_bound->set_parent(subscript);
5819 upper_bound->set_parent(subscript);
5820 stride ->set_parent(subscript);
5821
5822 return subscript;
5823 }
5824
5827 {
5828 ROSE_ASSERT(initname);
5829 if (scope == NULL)
5831
5832 SgVarRefExp *varRef = NULL;
5833 // there is assertion for get_scope() != NULL in get_symbol_from_symbol_table()
5834 SgSymbol* symbol = NULL;
5835 if (initname->get_scope()!=NULL)
5836 symbol = initname->get_symbol_from_symbol_table ();
5837
5838 if (symbol != NULL)
5839 {
5840 varRef = new SgVarRefExp(isSgVariableSymbol(symbol));
5842 ROSE_ASSERT(varRef);
5843 }
5844 else
5845 {
5846 varRef = buildVarRefExp(initname->get_name(), scope);
5847 }
5848
5849 return varRef;
5850 }
5851
5854{
5855 SgName name(varName);
5856 return buildVarRefExp(name,scope);
5857}
5858
5860SageBuilder::buildVarRefExp(const std::string& varName, SgScopeStatement* scope)
5861{
5862 SgName name(varName);
5863 return buildVarRefExp(name,scope);
5864}
5865
5868 {
5869 if (scope == NULL)
5871
5872 SgSymbol* symbol = NULL;
5873 SgVariableSymbol* varSymbol = NULL;
5874
5875 if (scope != NULL)
5876 {
5877 // DQ (12/30/2011): This is a bad idea for C++ since qualified names might indicate different scopes.
5878 // If the scope has been provided then is should be the correct scope.
5879
5880 // DQ (8/16/2013): Modified to use the new API supporting template parameters and template arguments, however
5881 // this should more likely be using lookupVariableSymbolInParentScopes() instead of lookupSymbolInParentScopes().
5882 symbol = lookupVariableSymbolInParentScopes(name,scope);
5883 }
5884
5885 if (symbol != NULL)
5886 {
5887 varSymbol = isSgVariableSymbol(symbol);
5888 }
5889 else
5890 {
5891 // if not found: put fake init name and symbol here and
5892 // waiting for a postProcessing phase to clean it up
5893 // two features: no scope and unknown type for initializedName
5895 name1->set_scope(scope); // buildInitializedName() does not set scope for various reasons
5896 name1->set_parent(scope);
5897 varSymbol = new SgVariableSymbol(name1);
5898 varSymbol->set_parent(scope);
5899 }
5900
5901 if (varSymbol == NULL)
5902 {
5903 printf ("Error: varSymbol == NULL for name = %s \n",name.str());
5904 }
5905 ROSE_ASSERT(varSymbol != NULL);
5906
5907 SgVarRefExp *varRef = new SgVarRefExp(varSymbol);
5909 ROSE_ASSERT(varRef != NULL);
5910
5911 ROSE_ASSERT (isSgVariableSymbol(varRef->get_symbol())->get_declaration()!=NULL);
5912
5913 return varRef;
5914 }
5915
5919 {
5920 SgVariableSymbol* symbol = getFirstVarSym(vardecl);
5921 ROSE_ASSERT(symbol);
5922
5923 return buildVarRefExp(symbol);
5924 }
5925
5926
5929 {
5930 SgVarRefExp *varRef = new SgVarRefExp(sym);
5931 ROSE_ASSERT(varRef);
5932
5934
5935 return varRef;
5936 }
5937
5940 {
5941 SgVarRefExp *varRef = new SgVarRefExp(sym);
5942 ROSE_ASSERT(varRef);
5943
5945
5946 return varRef;
5947 }
5948
5951 {
5952 SgNonrealRefExp * refexp = new SgNonrealRefExp(sym);
5953 ROSE_ASSERT(refexp != NULL);
5955 return refexp;
5956 }
5957
5959
5962SageBuilder::buildOpaqueVarRefExp(const std::string& name,SgScopeStatement* scope/* =NULL */)
5963 {
5964 SgVarRefExp *result = NULL;
5965
5966 if (scope == NULL)
5968 ROSE_ASSERT(scope != NULL);
5969
5970 // DQ (8/16/2013): Modified to use the new API supporting template parameters and template arguments, however
5971 // this should more likely be using lookupVariableSymbolInParentScopes() instead of lookupSymbolInParentScopes().
5972 // SgSymbol * symbol = lookupSymbolInParentScopes(name,scope);
5973 SgSymbol * symbol = lookupVariableSymbolInParentScopes(name,scope);
5974
5975 if (symbol)
5976 {
5977 // Can be the same opaque var ref built before
5978 // cerr<<"Error: trying to build an opaque var ref when the variable is actual explicit!"<<endl;
5979 ROSE_ASSERT(isSgVariableSymbol(symbol));
5980 result = buildVarRefExp(isSgVariableSymbol(symbol));
5981 }
5982 else
5983 {
5984 SgVariableDeclaration* fakeVar = buildVariableDeclaration(name, buildIntType(),NULL, scope);
5985 Sg_File_Info* file_info = fakeVar->get_file_info();
5986
5987 // TGWE (7/16/2014): on the advice of DQ who doesn't like the function at all
5988 fakeVar->set_parent(scope);
5989
5990 file_info->unsetOutputInCodeGeneration ();
5991 SgVariableSymbol* fakeSymbol = getFirstVarSym (fakeVar);
5992 result = buildVarRefExp(fakeSymbol);
5993 }
5994
5995 return result;
5996 } // buildOpaqueVarRefExp()
5997
5998
5999// DQ (9/4/2013): Added support for building compound literals (similar to a SgVarRefExp).
6003 {
6004 SgCompoundLiteralExp *compoundLiteral = new SgCompoundLiteralExp(varSymbol);
6005 ROSE_ASSERT(compoundLiteral != NULL);
6006
6007 setOneSourcePositionNull(compoundLiteral);
6008
6009 return compoundLiteral;
6010 }
6011
6012// DQ (9/4/2013): Added support for building compound literals (similar to a SgVarRefExp).
6016 {
6017 SgCompoundLiteralExp *compoundLiteral = new SgCompoundLiteralExp(varSymbol);
6018 ROSE_ASSERT(compoundLiteral != NULL);
6019
6021
6022 return compoundLiteral;
6023 }
6024
6025
6028{
6029 SgLabelRefExp * result= NULL;
6030 ROSE_ASSERT (s!= NULL);
6031 result = new SgLabelRefExp(s);
6032 ROSE_ASSERT (result != NULL);
6034 return result;
6035}
6036
6039{
6041 if (paraTypeList==NULL) return paraList;
6042
6043 SgTypePtrList typeList = paraTypeList->get_arguments();
6044 SgTypePtrList::iterator i;
6045 for (i=typeList.begin();i!=typeList.end();i++)
6046 {
6048 appendArg(paraList,arg);
6049 }
6050
6051 return paraList;
6052}
6053
6056{
6058 ROSE_ASSERT (paraList);
6059 SgTypePtrList typeList = paraTypeList->get_arguments();
6060 SgTypePtrList::iterator i;
6061 for (i=typeList.begin();i!=typeList.end();i++)
6062 {
6064 appendArg(paraList,arg);
6065 }
6066 return paraList;
6067}
6068
6069// lookup function symbol to create a reference to it
6071SageBuilder::buildFunctionRefExp(const SgName& name,const SgType* funcType, SgScopeStatement* scope /*=NULL*/)
6072{
6073 ASSERT_not_null(funcType); // function type cannot be NULL
6074 SgFunctionType* func_type = isSgFunctionType(const_cast<SgType*>(funcType));
6075 ASSERT_not_null(func_type);
6076
6077 bool isMemberFunc = isSgMemberFunctionType(func_type);
6078
6079 if (scope == nullptr) {
6081 }
6082 ASSERT_not_null(scope);
6083 SgFunctionSymbol* symbol = lookupFunctionSymbolInParentScopes(name,func_type,scope);
6084 if (symbol == nullptr)
6085 // in rare cases when function calls are inserted before any prototypes exist
6086 {
6087 SgType* return_type = func_type->get_return_type();
6088 SgFunctionParameterTypeList * paraTypeList = func_type->get_argument_list();
6089 SgFunctionParameterList *parList = buildFunctionParameterList(paraTypeList);
6090
6091 SgGlobal* globalscope = getGlobalScope(scope);
6092
6093 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
6094
6095 // TODO: consider C++ template functions
6096 SgFunctionDeclaration * funcDecl = nullptr;
6098 {
6099 funcDecl = buildNondefiningFunctionDeclaration_T
6100 <SgProcedureHeaderStatement>(name,return_type,parList,false,globalscope,nullptr,false,nullptr,nullptr,SgStorageModifier::e_default);
6101 }
6102 else
6103 {
6104 funcDecl = buildNondefiningFunctionDeclaration_T
6105 <SgFunctionDeclaration>(name,return_type,parList,false,globalscope,nullptr,false,nullptr,nullptr,SgStorageModifier::e_default);
6106 }
6107
6108 funcDecl->get_declarationModifier().get_storageModifier().setExtern();
6109
6110 symbol = lookupFunctionSymbolInParentScopes(name,func_type,scope);
6111 ASSERT_not_null(symbol);
6112 }
6113 SgFunctionRefExp* func_ref = new SgFunctionRefExp(symbol,func_type);
6115
6116 ASSERT_not_null(func_ref);
6117 return func_ref;
6118}
6119
6121SageBuilder::buildFunctionRefExp(const char* name,const SgType* funcType, SgScopeStatement* scope /*=NULL*/)
6122{
6123 SgName name2(name);
6124 return buildFunctionRefExp(name2,funcType,scope);
6125}
6126
6127// lookup function symbol to create a reference to it
6130{
6131 ROSE_ASSERT(func_decl != NULL);
6132 SgDeclarationStatement* nondef_func = func_decl->get_firstNondefiningDeclaration ();
6133 SgDeclarationStatement* def_func = func_decl->get_definingDeclaration ();
6134 SgSymbol* symbol = NULL;
6135 if (nondef_func != NULL)
6136 {
6137 ROSE_ASSERT(nondef_func!= NULL);
6138 symbol = nondef_func->get_symbol_from_symbol_table();
6139 ROSE_ASSERT( symbol != NULL);
6140 }
6141 // Liao 12/1/2010. It is possible that there is no prototype declarations at all
6142 else if (def_func != NULL)
6143 {
6144 symbol = def_func->get_symbol_from_symbol_table();
6145 }
6146 else
6147 {
6148 std::cerr<<"Fatal error: SageBuilder::buildFunctionRefExp():defining and nondefining declarations for a function cannot be both NULL"<<std::endl;
6149 ROSE_ABORT ();
6150 }
6151 ROSE_ASSERT( symbol != NULL);
6152 return buildFunctionRefExp( isSgFunctionSymbol (symbol));
6153}
6154
6155
6156// lookup function symbol to create a reference to it
6159{
6160 SgFunctionRefExp* func_ref = new SgFunctionRefExp(sym, NULL);
6162 ROSE_ASSERT(func_ref);
6163 return func_ref;
6164}
6165
6166// lookup function symbol to create a reference to it
6169{
6170 SgFunctionRefExp* func_ref = new SgFunctionRefExp(sym, NULL);
6171 setOneSourcePositionNull(func_ref);
6172 ROSE_ASSERT(func_ref);
6173 return func_ref;
6174}
6175
6176// DQ (12/15/2011): Adding template declaration support to the AST.
6179 {
6180 ROSE_ASSERT(sym != NULL);
6181
6183 ROSE_ASSERT(func_ref != NULL);
6184
6185 setOneSourcePositionNull(func_ref);
6186 ROSE_ASSERT(func_ref->get_symbol() != NULL);
6187
6188 return func_ref;
6189 }
6190
6191// DQ (12/29/2011): Adding template declaration support to the AST.
6194 {
6195 SgTemplateMemberFunctionRefExp* func_ref = new SgTemplateMemberFunctionRefExp(sym, virtual_call, need_qualifier);
6196 setOneSourcePositionNull(func_ref);
6197 ROSE_ASSERT(func_ref);
6198 return func_ref;
6199 }
6200
6201// lookup member function symbol to create a reference to it
6203SageBuilder::buildMemberFunctionRefExp_nfi(SgMemberFunctionSymbol* sym, bool virtual_call, bool need_qualifier)
6204{
6205 SgMemberFunctionRefExp* func_ref = new SgMemberFunctionRefExp(sym, virtual_call, NULL, need_qualifier);
6206 setOneSourcePositionNull(func_ref);
6207 ROSE_ASSERT(func_ref);
6208 return func_ref;
6209}
6210
6211// lookup member function symbol to create a reference to it
6213SageBuilder::buildMemberFunctionRefExp(SgMemberFunctionSymbol* sym, bool virtual_call, bool need_qualifier)
6214{
6215 SgMemberFunctionRefExp* func_ref = new SgMemberFunctionRefExp(sym, virtual_call, NULL, need_qualifier);
6217 ROSE_ASSERT(func_ref);
6218 return func_ref;
6219}
6220
6221// lookup class symbol to create a reference to it
6224{
6225 SgClassNameRefExp* class_ref = new SgClassNameRefExp(sym);
6226 setOneSourcePositionNull(class_ref);
6227 ROSE_ASSERT(class_ref);
6228 return class_ref;
6229}
6230
6233{
6234 SgClassNameRefExp* class_ref = new SgClassNameRefExp(sym);
6236 ROSE_ASSERT(class_ref);
6237 return class_ref;
6238}
6239
6243{
6244 if (scope == NULL)
6246 ROSE_ASSERT(scope != NULL);
6248
6249 if (symbol==NULL)
6250// in rare cases when function calls are inserted before any prototypes exist
6251 {
6252// assume int return type, and empty parameter list
6253
6254#if 1
6255// DQ (7/26/2012): I am at least temporarily removing this function from the API.
6256// Later if we need it, we can update it to reflect that passing of the new
6257// SgTemplateArgumentPtrList function parameter (part of the new API design).
6258
6259 SgFunctionDeclaration* funcDecl = NULL;
6260 printf ("Error: buildFunctionRefExp(): This function should not be used! \n");
6261 ROSE_ABORT();
6262#else
6263 SgType* return_type = buildIntType();
6265
6266 SgGlobal* globalscope = getGlobalScope(scope);
6267
6268 SgFunctionDeclaration * funcDecl = buildNondefiningFunctionDeclaration(name,return_type,parList,globalscope);
6269#endif
6270
6271 funcDecl->get_declarationModifier().get_storageModifier().setExtern();
6272
6273 symbol = lookupFunctionSymbolInParentScopes(name,scope);
6274 ROSE_ASSERT(symbol);
6275 }
6276
6277 SgFunctionRefExp* func_ref = buildFunctionRefExp(symbol);
6279
6280 ROSE_ASSERT(func_ref);
6281 return func_ref;
6282}
6283
6285SageBuilder::buildFunctionRefExp(const char* name, SgScopeStatement* scope /*=NULL*/)
6286{
6287 SgName name2(name);
6288 return buildFunctionRefExp(name2,scope);
6289}
6290
6291
6294{
6295 SgExprStatement* expStmt = new SgExprStatement(exp);
6296 ROSE_ASSERT(expStmt);
6297 if (exp) exp->set_parent(expStmt);
6299 return expStmt;
6300}
6301
6304{
6305 SgExprStatement* expStmt = new SgExprStatement(exp);
6306 ROSE_ASSERT(expStmt);
6307 if (exp) exp->set_parent(expStmt);
6308 setOneSourcePositionNull(expStmt);
6309 return expStmt;
6310}
6311
6312// DQ (3/27/2015): Added support for SgStatementExpression.
6315{
6316 SgStatementExpression* expStmt = new SgStatementExpression(exp);
6317 ROSE_ASSERT(expStmt);
6318 if (exp) exp->set_parent(expStmt);
6320
6321 return expStmt;
6322}
6323
6324// DQ (3/27/2015): Added support for SgStatementExpression.
6327{
6328 SgStatementExpression* expStmt = new SgStatementExpression(exp);
6329 ROSE_ASSERT(expStmt);
6330 if (exp) exp->set_parent(expStmt);
6331 setOneSourcePositionNull(expStmt);
6332
6333 return expStmt;
6334}
6335
6337SageBuilder::buildFunctionCallExp(const SgName& name, SgType* return_type, SgExprListExp* parameters/*=NULL*/, SgScopeStatement* scope/*=NULL*/)
6338 {
6339 if (scope == nullptr) {
6341 }
6342 ASSERT_not_null(scope);
6343
6344 if (parameters == nullptr) {
6345 parameters = buildExprListExp();
6346 }
6347
6349 SgFunctionType * func_type = buildFunctionType(return_type,typeList);
6350 SgFunctionRefExp* func_ref = buildFunctionRefExp(name,func_type,scope);
6351 SgFunctionCallExp * func_call_expr = new SgFunctionCallExp(func_ref,parameters,func_ref->get_type());
6352 parameters->set_parent(func_call_expr);
6353
6355 ASSERT_not_null(func_call_expr);
6356
6357 return func_call_expr;
6358 }
6359
6360
6363 SgExprListExp* parameters/*=NULL*/)
6364 {
6365 ROSE_ASSERT (sym != NULL);
6366 if (parameters == NULL)
6367 parameters = buildExprListExp();
6368 ROSE_ASSERT (parameters != NULL);
6369
6370 // DQ (8/21/2011): We want to preserve the support for member functions to be built as SgMemberFunctionRefExp.
6371 // This is important for the Java support and the C++ support else we will be lowering all mmember function calls
6372 // to function calls which will be a proble for eht analysis of object oriented languages.
6373 SgFunctionCallExp * func_call_expr = NULL;
6374 SgMemberFunctionSymbol* memberFunctionSymbol = isSgMemberFunctionSymbol(sym);
6375 if (memberFunctionSymbol != NULL)
6376 {
6377 // Note that we can't at this point be sure this is not a virtual function.
6378 bool virtual_call = false;
6379
6380 // Name qualificaiton is handled separately from the setting of this variable (old API).
6381 bool need_qualifier = false;
6382
6383 SgMemberFunctionRefExp* member_func_ref = buildMemberFunctionRefExp(memberFunctionSymbol,virtual_call,need_qualifier);
6384 func_call_expr = new SgFunctionCallExp(member_func_ref,parameters,member_func_ref->get_type());
6385 member_func_ref->set_parent(func_call_expr);
6386 }
6387 else
6388 {
6389 SgFunctionRefExp * func_ref = buildFunctionRefExp(sym);
6390 func_call_expr = new SgFunctionCallExp(func_ref,parameters,func_ref->get_type());
6391 func_ref->set_parent(func_call_expr);
6392 }
6393
6394
6395 parameters->set_parent(func_call_expr);
6396
6398
6399 ROSE_ASSERT(func_call_expr);
6400 return func_call_expr;
6401 }
6402
6405 {
6406 ROSE_ASSERT(f != NULL);
6407 SgFunctionCallExp* func_call_expr = new SgFunctionCallExp(f,parameters,f->get_type());
6408 ROSE_ASSERT(func_call_expr != NULL);
6409
6410 if (f != NULL) {
6411 f->set_parent(func_call_expr);
6412 }
6413 if (parameters != NULL) {
6414 parameters->set_parent(func_call_expr);
6415 }
6416 setOneSourcePositionNull(func_call_expr);
6417
6418 return func_call_expr;
6419 }
6420
6423 {
6424 ROSE_ASSERT(f != NULL);
6425 SgFunctionCallExp * func_call_expr = new SgFunctionCallExp(f,parameters,f->get_type());
6426 ROSE_ASSERT(func_call_expr != NULL);
6427
6428 if (f) f->set_parent(func_call_expr);
6429 if (parameters) parameters->set_parent(func_call_expr);
6431
6432 return func_call_expr;
6433 }
6434
6437 SgType* return_type,
6438 SgExprListExp* parameters /*= NULL*/,
6439 SgScopeStatement* scope /*=NULL*/)
6440{
6441 if (scope == NULL)
6443 ROSE_ASSERT(scope != NULL);
6444 SgFunctionCallExp* func_call_expr = buildFunctionCallExp(name,return_type,parameters,scope);
6445 SgExprStatement * expStmt = buildExprStatement(func_call_expr);
6446 return expStmt;
6447}
6448
6452{
6453 SgFunctionCallExp* func_call_expr = buildFunctionCallExp(function_exp, parameters);
6454 SgExprStatement * expStmt = buildExprStatement(func_call_expr);
6455 return expStmt;
6456}
6457
6458
6460
6468 SgExpression* objectExpression,
6469 std::string functionName,
6470 SgExprListExp* params,
6471 SgScopeStatement* scope
6472 )
6473{
6474 SgClassSymbol* classSymbol = SageInterface::lookupClassSymbolInParentScopes(className, scope);
6475 ROSE_ASSERT(classSymbol);
6476
6477 SgDeclarationStatement* classDecl = classSymbol->get_declaration()->get_definingDeclaration();
6478 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classDecl);
6479 ROSE_ASSERT(classDeclaration != NULL);
6480
6481 SgClassDefinition* classDefinition = classDeclaration->get_definition();
6482 ROSE_ASSERT(classDefinition);
6483
6484 SgSymbol* funsy = lookupFunctionSymbolInParentScopes(functionName, classDefinition);
6485 SgMemberFunctionSymbol* functionSymbol = isSgMemberFunctionSymbol(funsy);
6486 ROSE_ASSERT(functionSymbol);
6487
6488 SgMemberFunctionRefExp* memref = buildMemberFunctionRefExp(functionSymbol, false, false);
6489
6490 return buildFunctionCallExp(buildDotExp(objectExpression, memref), params);
6491}
6492
6493// with known varRef and mem function symbol : a.size()
6495 SgExprListExp* params)
6496{
6497 SgMemberFunctionRefExp* memref = SageBuilder::buildMemberFunctionRefExp(functionSymbol, false, false);
6498 return SageBuilder::buildFunctionCallExp(SageBuilder::buildDotExp(objectExpression, memref), params);
6499}
6500
6502SageBuilder::buildTypeTraitBuiltinOperator(SgName functionName, SgNodePtrList parameters)
6503 {
6504 // DQ (7/14/2013): This is supporting compiler extensions that are required to support type traits in C++.
6505 // These operators are used increasingly in newer versions of GNU and other compilers. They are builtin
6506 // compiler extensions that typically take types as arguments.
6507
6508 SgTypeTraitBuiltinOperator * builtin_func_call_expr = new SgTypeTraitBuiltinOperator(functionName);
6509 ROSE_ASSERT(builtin_func_call_expr != NULL);
6510
6511 SgNodePtrList & args = builtin_func_call_expr->get_args();
6512 for (SgNodePtrList::iterator it = parameters.begin(); it != parameters.end(); ++it) {
6513 args.push_back(*it);
6514 (*it)->set_parent(builtin_func_call_expr);
6515 }
6516
6517 return builtin_func_call_expr;
6518 }
6519
6520
6523 {
6524 ROSE_ASSERT(kernel);
6525 ROSE_ASSERT(parameters);
6526 ROSE_ASSERT(config);
6527
6528 // DQ (1/19/2016): Adding template function ref support.
6529 SgFunctionRefExp * func_ref_exp = isSgFunctionRefExp(kernel);
6530 SgTemplateFunctionRefExp * template_func_ref_exp = isSgTemplateFunctionRefExp(kernel);
6531 if (func_ref_exp == NULL && template_func_ref_exp == NULL)
6532 {
6533 std::cerr << "SgCudaKernelCallExp accept only direct reference to a function. Got, " << typeid(*kernel).name()
6534 << " with, " << kernel->unparseToString() << std::endl;
6535
6536 // PP (7/1/19): experimental support for RAJA/CUDA Lulesh codes (producing SgNonrealRefExp) **1
6537 // was: ROSE_ASSERT(false);
6538 }
6539 // DQ (1/19/2016): Adding template function ref support.
6540 else if ( (func_ref_exp != NULL && func_ref_exp->get_symbol_i()->get_declaration()->get_functionModifier().isCudaKernel() == false) &&
6541 (template_func_ref_exp != NULL && template_func_ref_exp->get_symbol_i()->get_declaration()->get_functionModifier().isCudaKernel() == false) )
6542 {
6543 std::cerr << "To build a SgCudaKernelCallExp the callee needs to be a kernel (having \"__global__\" attribute)." << std::endl;
6544 ROSE_ABORT();
6545 }
6546
6547 SgCudaKernelCallExp * kernel_call_expr = new SgCudaKernelCallExp(kernel, parameters, kernel->get_type(), config);
6548
6549 kernel->set_parent(kernel_call_expr);
6550 parameters->set_parent(kernel_call_expr);
6551 config->set_parent(kernel_call_expr);
6552
6553 setOneSourcePositionNull(kernel_call_expr);
6554
6555 ROSE_ASSERT(kernel_call_expr);
6556
6557 return kernel_call_expr;
6558 }
6559
6562 if (!grid || !blocks) {
6563 std::cerr << "SgCudaKernelExecConfig need fields 'grid' and 'blocks' to be set." << std::endl;
6564 ROSE_ABORT();
6565 }
6566
6567 // TODO-CUDA check types
6568
6569 SgCudaKernelExecConfig * config = new SgCudaKernelExecConfig (grid, blocks, shared, stream);
6570
6571 grid->set_parent(config);
6572 blocks->set_parent(config);
6573 if (shared)
6574 shared->set_parent(config);
6575 if (stream)
6576 stream->set_parent(config);
6577
6579
6580 ROSE_ASSERT(config);
6581
6582 return config;
6583}
6584
6587//SageBuilder::buildAssignStatement(SgExpression* lhs,SgExpression* rhs, SgScopeStatement* scope=NULL)
6588{
6589 ROSE_ASSERT(lhs != NULL);
6590 ROSE_ASSERT(rhs != NULL);
6591
6592 //SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,lhs->get_type());
6593// SgBinaryOp::get_type() assume p_expression_type is not set
6594 SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,NULL);
6595 ROSE_ASSERT(assignOp);
6597 lhs->set_parent(assignOp);
6598 rhs->set_parent(assignOp);
6599
6600 lhs->set_lvalue (true);
6601 SgExprStatement* exp = new SgExprStatement(assignOp);
6602 ROSE_ASSERT(exp);
6603 // some child nodes are transparently generated, using recursive setting is safer
6605 //setOneSourcePositionForTransformation(exp);
6606 assignOp->set_parent(exp);
6607 return exp;
6608}
6609
6610// DQ (8/16/2011): This is an AST translate specific version (see note below).
6611// We would like to phase out the version above if possible (but we want to
6612// test this later).
6615{
6616 ROSE_ASSERT(lhs != NULL);
6617 ROSE_ASSERT(rhs != NULL);
6618
6619 //SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,lhs->get_type());
6620// SgBinaryOp::get_type() assume p_expression_type is not set
6621 SgAssignOp* assignOp = new SgAssignOp(lhs,rhs,NULL);
6622 ROSE_ASSERT(assignOp);
6624 lhs->set_parent(assignOp);
6625 rhs->set_parent(assignOp);
6626
6627 lhs->set_lvalue (true);
6628 SgExprStatement* exp = new SgExprStatement(assignOp);
6629 ROSE_ASSERT(exp);
6630
6631// DQ (8/16/2011): Modified to avoid recursive call to reset source position information
6632// (this version is required for the Java support where we have set source code position
6633// information on the lhs and rhs and we don't want it to be reset as a transformation.
6634// some child nodes are transparently generated, using recursive setting is safer
6636 assignOp->set_parent(exp);
6637 return exp;
6638}
6639
6640
6642{
6643 if (scope == NULL)
6645
6646 // should including current scope when searching for the function definition
6647 // since users can only pass FunctionDefinition when the function body is not yet attached
6648 SgLabelStatement * labelstmt = new SgLabelStatement(name,stmt);
6649 ROSE_ASSERT(labelstmt);
6651
6652 if(stmt!=NULL)
6653 stmt->set_parent(labelstmt);
6654
6655 // Liao 1/7/2010
6656 // SgLabelStatement is used for CONTINUE statement in Fortran
6657 // In this case , it has no inherent association with a Label symbol.
6658 // It is up to the SageInterface::setNumericalLabel(SgStatement*) to handle label symbol
6660 fixLabelStatement(labelstmt,scope);
6661 // we don't want to set parent here yet
6662 // delay it until append_statement() or alike
6663 return labelstmt;
6664}
6665
6667{
6668 SgLabelStatement* labelStmt = new SgLabelStatement(name,stmt);
6669 ASSERT_not_null(labelStmt);
6671
6672 if (stmt != nullptr) {
6673 stmt->set_parent(labelStmt);
6674 }
6675 if (scope) {
6676 fixLabelStatement(labelStmt,scope);
6677 }
6678
6679 // we don't want to set parent here yet
6680 // delay it until append_statement() or alike
6681 return labelStmt;
6682}
6683
6684SgIfStmt * SageBuilder::buildIfStmt(SgStatement* conditional, SgStatement * true_body, SgStatement * false_body)
6685{
6686 ROSE_ASSERT(conditional);
6687 ROSE_ASSERT(true_body);
6688 SgIfStmt *ifstmt = new SgIfStmt(conditional, true_body, false_body);
6689 ROSE_ASSERT(ifstmt);
6690
6691 // CR (3/22/2020): Fixed setting case insensitivity
6692 // if (symbol_table_case_insensitive_semantics == true)
6694 ifstmt->setCaseInsensitive(true);
6695
6697 conditional->set_parent(ifstmt);
6698 true_body->set_parent(ifstmt);
6699 if (false_body != NULL) false_body->set_parent(ifstmt);
6700
6702 {
6703 // Liao 1/20/2010
6704 // According to Fortran 77 standard Chapter 11.5 to 11.9,
6705 // this is a Fortran Block IF statement, if the true body is:
6706 // 1. A block of statement under SgBasicBlock
6707 // 2. DO, block if, or another logical if
6708 // Otherwise it is a logical if statement
6709 if (isSgBasicBlock(true_body)|| isSgFortranDo(true_body)|| isSgIfStmt(true_body))
6710 {
6711 ifstmt->set_use_then_keyword(true);
6712 ifstmt->set_has_end_statement(true);
6713 }
6714 }
6715
6716 return ifstmt;
6717}
6718
6720 {
6721 SgIfStmt *ifstmt = new SgIfStmt(conditional, true_body, false_body);
6722 ROSE_ASSERT(ifstmt);
6723 // DQ (2/13/2012): This allows us to separate the construction from the initialization (see note below).
6724 initializeIfStmt(ifstmt,conditional,true_body,false_body);
6725 return ifstmt;
6726 }
6727
6728// Rasmussen (9/3/2018): Added build function for a Fortran do construct
6730{
6731 if (initialization == nullptr) initialization = buildNullExpression();
6732 if (bound == nullptr) bound = buildNullExpression();
6733 if (increment == nullptr) increment = buildNullExpression();
6734 if (loopBody == nullptr) loopBody = buildBasicBlock();
6735
6736 SgFortranDo* result = new SgFortranDo(initialization, bound, increment, loopBody);
6737 ASSERT_not_null(result);
6738
6740 result->setCaseInsensitive(true);
6741 }
6742
6744
6745 initialization->set_parent(result);
6746 bound->set_parent(result);
6747 increment->set_parent(result);
6748 loopBody->set_parent(result);
6749
6750 return result;
6751}
6752
6754{
6755 if (initialization == nullptr) initialization = buildNullExpression_nfi();
6756 if (bound == nullptr) bound = buildNullExpression_nfi();
6757 if (increment == nullptr) increment = buildNullExpression_nfi();
6758 if (loopBody == nullptr) loopBody = buildBasicBlock_nfi();
6759
6760 SgFortranDo* result = new SgFortranDo(initialization, bound, increment, loopBody);
6761 ASSERT_not_null(result);
6762
6764 result->setCaseInsensitive(true);
6765 }
6766
6768
6769 initialization->set_parent(result);
6770 bound->set_parent(result);
6771 increment->set_parent(result);
6772 loopBody->set_parent(result);
6773
6774 return result;
6775}
6776
6777// charles4 10/14/2011: Vanilla allocation. Use prepend_init_stmt and append_init_stmt to populate afterward.
6779 {
6780 // return new SgForInitStatement();
6781 SgForInitStatement* result = new SgForInitStatement();
6782
6783 // DQ (11/3/2012): Added call to set file info to default settings.
6784 setSourcePosition(result);
6785
6786 return result;
6787 }
6788
6789// DQ (10/12/2012): Added specific API to handle simple (single) statement.
6792 {
6793 SgForInitStatement* forInit = new SgForInitStatement();
6794 ROSE_ASSERT(forInit != NULL);
6795
6796 ROSE_ASSERT(statement != NULL);
6797 forInit->append_init_stmt(statement);
6798
6799 // DQ (11/3/2012): Added call to set file info to default settings.
6800 setSourcePosition(forInit);
6801
6802 return forInit;
6803 }
6804
6805SgForInitStatement * SageBuilder::buildForInitStatement(const SgStatementPtrList & statements)
6806{
6807 SgForInitStatement * result = new SgForInitStatement();
6808 result->get_init_stmt() = statements;
6809
6810 for (SgStatementPtrList::iterator it = result->get_init_stmt().begin(); it != result->get_init_stmt().end(); it++)
6811 (*it)->set_parent(result);
6812
6814 return result;
6815}
6816
6818SageBuilder::buildForInitStatement_nfi(SgStatementPtrList & statements)
6819 {
6820 SgForInitStatement * result = new SgForInitStatement();
6821
6822 result->get_init_stmt() = statements;
6823
6824 for (SgStatementPtrList::iterator it = result->get_init_stmt().begin(); it != result->get_init_stmt().end(); it++)
6825 {
6826 (*it)->set_parent(result);
6827 }
6828
6829 // DQ (11/3/2012): Added call to set file info to default settings.
6830 setSourcePosition(result);
6831
6832 return result;
6833 }
6834
6836//Liao, 8/27/2008
6837SgForStatement * SageBuilder::buildForStatement(SgStatement* initialize_stmt, SgStatement * test, SgExpression * increment, SgStatement * loop_body, SgStatement * else_body)
6838{
6839 SgForStatement * result = new SgForStatement(test,increment, loop_body);
6840 ROSE_ASSERT(result);
6841
6843 result->setCaseInsensitive(true);
6844
6846 if (test)
6847 test->set_parent(result);
6848 if (loop_body)
6849 loop_body->set_parent(result);
6850 if (increment)
6851 increment->set_parent(result);
6852
6853 if (else_body)
6854 else_body->set_parent(result);
6855 result->set_else_body(else_body);
6856
6857 // CH (5/13/2010): If the initialize_stmt is an object of SgForInitStatement, we can directly put it
6858 // into for statement. Or else, there will be two semicolons after unparsing.
6859 if (SgForInitStatement* for_init_stmt = isSgForInitStatement(initialize_stmt))
6860 {
6861 // DQ (7/30/2011): We have to delete the the SgForInitStatement build within the SgForStatement::post_constructor_initialization()
6862 // to avoid causing errors in the AST consistancy checking later.
6863 if (result->get_for_init_stmt() != NULL)
6864 {
6865 delete result->get_for_init_stmt();
6866 result->set_for_init_stmt(NULL);
6867 }
6868
6869 result->set_for_init_stmt(for_init_stmt);
6870 for_init_stmt->set_parent(result);
6871 return result;
6872 }
6873
6874 SgForInitStatement* init_stmt = new SgForInitStatement();
6875 ROSE_ASSERT(init_stmt);
6877
6878 // DQ (7/30/2011): We have to delete the the SgForInitStatement build within the SgForStatement::post_constructor_initialization().
6879 // to avoid causeing errors in the AST consistancy checking later.
6880 if (result->get_for_init_stmt() != NULL)
6881 {
6882 delete result->get_for_init_stmt();
6883 result->set_for_init_stmt(NULL);
6884 }
6885
6886 result->set_for_init_stmt(init_stmt);
6887 init_stmt->set_parent(result);
6888
6889 if (initialize_stmt)
6890 {
6891 init_stmt->append_init_stmt(initialize_stmt);
6892 // Support for "for (int i=0; )", Liao, 3/11/2009
6893 // The symbols are inserted into the symbol table attached to SgForStatement
6894 if (isSgVariableDeclaration(initialize_stmt))
6895 {
6896 fixVariableDeclaration(isSgVariableDeclaration(initialize_stmt),result);
6897 // fix varRefExp to the index variable used in increment, conditional expressions
6898 fixVariableReferences(result);
6899 }
6900 }
6901
6902 return result;
6903 }
6904
6905
6907//Liao, 8/27/2008
6909SageBuilder::buildForStatement_nfi(SgStatement* initialize_stmt, SgStatement * test, SgExpression * increment, SgStatement * loop_body, SgStatement * else_body)
6910 {
6911 SgForStatement * result = new SgForStatement(test, increment, loop_body);
6912 ROSE_ASSERT(result);
6913
6914 // Rasmussen (3/22/2020): Fixed setting case insensitivity
6915 // if (symbol_table_case_insensitive_semantics == true)
6917 result->setCaseInsensitive(true);
6918
6920 if (test) test->set_parent(result);
6921 if (loop_body) loop_body->set_parent(result);
6922 if (increment) increment->set_parent(result);
6923 if (else_body) else_body->set_parent(result);
6924
6925 result->set_else_body(else_body);
6926
6927 if (initialize_stmt != NULL)
6928 {
6929 SgForInitStatement* init_stmt = result->get_for_init_stmt();
6930 ROSE_ASSERT(init_stmt);
6931 setOneSourcePositionNull(init_stmt);
6932 init_stmt->append_init_stmt(initialize_stmt);
6933 initialize_stmt->set_parent(init_stmt);
6934 }
6935
6936 return result;
6937 }
6938
6939
6942 {
6943 SgForStatement * result = new SgForStatement(init_stmt, test, increment, loop_body);
6944 ROSE_ASSERT(result != NULL);
6945
6946 // DQ (9/26/2012): Refactored this function to allow for where the SgForStatement had to be
6947 // constructed early to define the scope for types that can be defined in the SgForInitStatement.
6948 buildForStatement_nfi(result,init_stmt,test,increment,loop_body,else_body);
6949
6950 return result;
6951 }
6952
6953
6954void
6956 {
6957 // DQ (9/26/2012): Refactored this function to allow for where the SgForStatement had to be
6958 // constructed early to define the scope for types that can be defined in the SgForInitStatement.
6959
6960 ROSE_ASSERT(result != NULL);
6961
6962 // DQ (11/4/2012): I have added support for remove existing subtrees if they are different from what is provided as input.
6963 if (result->get_for_init_stmt() != NULL && init_stmt != result->get_for_init_stmt())
6964 {
6965 delete result->get_for_init_stmt();
6966 result->set_for_init_stmt(NULL);
6967 }
6968
6969 if (result->get_test() != NULL && test != result->get_test())
6970 {
6971 delete result->get_test();
6972 result->set_test(NULL);
6973 }
6974
6975 if (result->get_increment() != NULL && increment != result->get_increment())
6976 {
6977 delete result->get_increment();
6978 result->set_increment(NULL);
6979 }
6980
6981 if (result->get_loop_body() != NULL && loop_body != result->get_loop_body())
6982 {
6983 delete result->get_loop_body();
6984 result->set_loop_body(NULL);
6985 }
6986
6987 if (result->get_else_body() != NULL && else_body != result->get_else_body())
6988 {
6989 delete result->get_else_body();
6990 result->set_else_body(NULL);
6991 }
6992
6993 result->set_for_init_stmt(init_stmt);
6994 result->set_test(test);
6995 result->set_increment(increment);
6996 result->set_loop_body(loop_body);
6997
6999 result->setCaseInsensitive(true);
7000
7002 if (test) test->set_parent(result);
7003 if (loop_body) loop_body->set_parent(result);
7004 if (increment) increment->set_parent(result);
7005 if (init_stmt) init_stmt->set_parent(result);
7006 if (else_body) else_body->set_parent(result);
7007
7008 result->set_else_body(else_body);
7009
7010 ROSE_ASSERT(result->get_for_init_stmt() != NULL);
7011 ROSE_ASSERT(result->get_test() != NULL);
7012 ROSE_ASSERT(result->get_increment() != NULL);
7013 ROSE_ASSERT(result->get_loop_body() != NULL);
7014 }
7015
7016
7017// DQ (3/26/2018): Adding support for range based for statement.
7018// SgRangeBasedForStatement* SageBuilder::buildRangeBasedForStatement_nfi(SgVariableDeclaration* initializer, SgExpression* range, SgStatement* body)
7021 SgVariableDeclaration* initializer, SgVariableDeclaration* range,
7022 SgVariableDeclaration* begin_declaration, SgVariableDeclaration* end_declaration,
7023 SgExpression* not_equal_expression, SgExpression* increment_expression,
7024 SgStatement* body)
7025 {
7026 // DQ (6/26/2019): Commented these out so that we could build the SgRangeBasedForStatement before
7027 // building the children, since the scope of the chldren will be the SgRangeBasedForStatement and
7028 // it must exist before the children are constructed.
7029 // ROSE_ASSERT(initializer != NULL);
7030 // ROSE_ASSERT(range != NULL);
7031
7032 // DQ (6/26/2019): This was already commented out.
7033 // ROSE_ASSERT(body != NULL);
7034
7035 SgRangeBasedForStatement* result = new SgRangeBasedForStatement(initializer, range, begin_declaration, end_declaration, not_equal_expression, increment_expression, body);
7036 ROSE_ASSERT(result != NULL);
7037
7039
7040 if (initializer != NULL) initializer->set_parent(result);
7041 if (range != NULL) range->set_parent(result);
7042
7043 if (begin_declaration != NULL) begin_declaration->set_parent(result);
7044 if (end_declaration != NULL) end_declaration->set_parent(result);
7045
7046 if (not_equal_expression != NULL) not_equal_expression->set_parent(result);
7047 if (increment_expression != NULL) increment_expression->set_parent(result);
7048
7049 if (body != NULL) body->set_parent(result);
7050
7051 return result;
7052 }
7053
7054
7055void
7057 {
7058 // DQ (3/22/2014): This function has been built to support reusing an existing SgDoWhileStatement
7059 // that may have been built and pushed onto the stack as part of a top-down construction of the AST.
7060 // It is required in the EDG 4.8 useage because of a change from EDG 4.7 to 4.8 in how blocks are
7061 // handled (end-of-construct entries).
7062
7063 ASSERT_not_null(result);
7064 ASSERT_not_null(body);
7065 ASSERT_not_null(condition);
7066
7067 ASSERT_require(result->get_body() == nullptr);
7068 ASSERT_require(result->get_condition() == nullptr);
7069
7070 result->set_body(body);
7071 result->set_condition(condition);
7072
7073 body->set_parent(result);
7074 condition->set_parent(result);
7075
7077
7078 ASSERT_not_null(result->get_body());
7079 ASSERT_not_null(result->get_condition());
7080
7081 ASSERT_require(result->get_body()->get_parent() == result);
7082 ASSERT_require(result->get_condition()->get_parent() == result);
7083 }
7084
7085
7086
7088//Liao, 8/27/2008
7090{
7091 SgUpcForAllStatement * result = new SgUpcForAllStatement(test,increment, affinity, loop_body);
7092 ROSE_ASSERT(result);
7094 if (test) test->set_parent(result);
7095 if (loop_body) loop_body->set_parent(result);
7096 if (increment) increment->set_parent(result);
7097 if (affinity) affinity->set_parent(result);
7098
7099 if (initialize_stmt != NULL) {
7100 SgForInitStatement* init_stmt = result->get_for_init_stmt();
7101 ROSE_ASSERT(init_stmt);
7102 setOneSourcePositionNull(init_stmt);
7103 init_stmt->append_init_stmt(initialize_stmt);
7104 initialize_stmt->set_parent(init_stmt);
7105 }
7106
7107 return result;
7108}
7109
7110
7112{
7113 SgUpcForAllStatement * result = new SgUpcForAllStatement(init_stmt, test, increment, affinity, loop_body);
7114 ROSE_ASSERT(result);
7115
7116 // CR (3/22/2020): Fixed setting case insensitivity
7117 // if (symbol_table_case_insensitive_semantics == true)
7119 result->setCaseInsensitive(true);
7120
7122 if (test) test->set_parent(result);
7123 if (loop_body) loop_body->set_parent(result);
7124 if (increment) increment->set_parent(result);
7125 if (affinity) affinity->set_parent(result);
7126 if (init_stmt) init_stmt->set_parent(result);
7127
7128 return result;
7129}
7130
7131// DQ (3/3/2013): Added UPC specific build functions.
7134 {
7135 SgUpcNotifyStatement* result = new SgUpcNotifyStatement(exp);
7136
7138
7139 exp->set_parent(result);
7140
7141 ROSE_ASSERT(exp->get_parent() != NULL);
7142
7143 return result;
7144 }
7145
7148 {
7149 SgUpcWaitStatement* result = new SgUpcWaitStatement(exp);
7150
7152
7153 exp->set_parent(result);
7154
7155 ROSE_ASSERT(exp->get_parent() != NULL);
7156
7157 return result;
7158 }
7159
7162 {
7164
7166
7167 exp->set_parent(result);
7168
7169 ROSE_ASSERT(exp->get_parent() != NULL);
7170
7171 return result;
7172 }
7173
7176 {
7178
7180
7181 return result;
7182 }
7183
7184
7185
7186
7188{
7189 ROSE_ASSERT(condition);
7190 ROSE_ASSERT(body);
7191 SgWhileStmt * result = new SgWhileStmt(condition,body);
7192 ROSE_ASSERT(result);
7193
7194 // CR (3/22/2020): Fixed setting case insensitivity
7195 // if (symbol_table_case_insensitive_semantics == true)
7197 result->setCaseInsensitive(true);
7198
7200 condition->set_parent(result);
7201 body->set_parent(result);
7202
7203// DQ (8/10/2011): This is added by Michael to support a Python specific feature.
7204 if (else_body != NULL) {
7205 result->set_else_body(else_body);
7206 else_body->set_parent(result);
7207 }
7208
7209 return result;
7210}
7211
7214{
7215 SgWhileStmt* result = new SgWhileStmt(condition,body);
7216 ROSE_ASSERT(result);
7217
7218 // DQ (2/15/2012): This function supports the case where in C++ the condition can include a variable declaration.
7219 initializeWhileStatement(result,condition,body,else_body);
7220 return result;
7221}
7222
7224{
7225 ROSE_ASSERT(expr != NULL && body != NULL);
7226 SgWithStatement* result = new SgWithStatement(expr, body);
7227 expr->set_parent(result);
7228 body->set_parent(result);
7229
7231 return result;
7232}
7233
7235{
7236 ROSE_ASSERT(expr != NULL && body != NULL);
7237 SgWithStatement* result = new SgWithStatement(expr, body);
7238 expr->set_parent(result);
7239 body->set_parent(result);
7240
7242 return result;
7243}
7244
7246{
7247 ROSE_ASSERT(condition);
7248 ROSE_ASSERT(body);
7249 SgDoWhileStmt* result = new SgDoWhileStmt(body, condition);
7250 ROSE_ASSERT(result);
7252 condition->set_parent(result);
7253 body->set_parent(result);
7254 return result;
7255}
7256
7258{
7259 SgDoWhileStmt* result = new SgDoWhileStmt(body, condition);
7260 ROSE_ASSERT(result);
7262 if (condition) condition->set_parent(result);
7263 if (body) body->set_parent(result);
7264 return result;
7265}
7266
7268{
7269 SgMatlabForStatement* result = new SgMatlabForStatement(loop_index, loop_range, loop_body);
7271
7272 ROSE_ASSERT(result != NULL);
7273
7274 loop_index->set_parent(result);
7275 loop_range->set_parent(result);
7276 loop_body->set_parent(result);
7277 return result;
7278}
7279
7281{
7282 SgBreakStmt* result = new SgBreakStmt();
7283 ROSE_ASSERT(result);
7285 return result;
7286}
7287
7289{
7290 SgBreakStmt* result = new SgBreakStmt();
7291 ROSE_ASSERT(result);
7293 return result;
7294}
7295
7297{
7298 SgContinueStmt* result = new SgContinueStmt();
7299 ASSERT_not_null(result);
7301 return result;
7302}
7303
7305{
7306 SgContinueStmt* result = new SgContinueStmt();
7307 ASSERT_not_null(result);
7309 return result;
7310}
7311
7313{
7315 ASSERT_not_null(result);
7317 return result;
7318}
7319
7321{
7323 ASSERT_not_null(result);
7325 return result;
7326}
7327
7329{
7330 SgPassStatement* result = new SgPassStatement();
7331 ROSE_ASSERT(result);
7333 return result;
7334}
7335
7337{
7338 SgPassStatement* result = new SgPassStatement();
7339 ROSE_ASSERT(result);
7341 return result;
7342}
7343
7344SgDeleteExp* SageBuilder::buildDeleteExp(SgExpression *target, bool is_array, bool need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
7345{
7346 SgDeleteExp *result = new SgDeleteExp(target, is_array, need_global_specifier, deleteOperatorDeclaration);
7347 target->set_parent(result);
7349 return result;
7350}
7351
7352SgDeleteExp* SageBuilder::buildDeleteExp_nfi(SgExpression *target, bool is_array, bool need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
7353{
7354 SgDeleteExp *result = new SgDeleteExp(target, is_array, need_global_specifier, deleteOperatorDeclaration);
7355 target->set_parent(result);
7357 return result;
7358}
7359
7361{
7362 SgAssertStmt* result = new SgAssertStmt(test);
7363 ROSE_ASSERT(test != NULL);
7364 test->set_parent(result);
7366 return result;
7367}
7368
7369// DQ (7/18/2011): Added support for SgJavaInstanceOfOp
7372 {
7373 SgType* exp_type = SgTypeBool::createType();
7374
7375 SgJavaInstanceOfOp* result = new SgJavaInstanceOfOp(exp, type, exp_type);
7376 ROSE_ASSERT(result);
7377 if (exp != NULL)
7378 {
7379 exp->set_parent(result);
7380 markLhsValues(result);
7381 }
7382
7384 return result;
7385 }
7386
7388{
7389 SgAssertStmt* result = new SgAssertStmt(test);
7390 ROSE_ASSERT(test != NULL);
7391 test->set_parent(result);
7392 if (exceptionArgument != NULL) {
7393 result -> set_exception_argument(exceptionArgument);
7394 exceptionArgument->set_parent(result);
7395 }
7397 return result;
7398}
7399
7401{
7402 SgAssertStmt* result = new SgAssertStmt(test);
7403 ROSE_ASSERT(test != NULL);
7404 test->set_parent(result);
7406 return result;
7407}
7408
7410{
7411 ROSE_ASSERT(value != NULL);
7412 SgYieldExpression* result = new SgYieldExpression(value);
7413 value->set_parent(result);
7415 return result;
7416}
7417
7419{
7420 ROSE_ASSERT(value != NULL);
7421 SgYieldExpression* result = new SgYieldExpression(value);
7422 value->set_parent(result);
7424 return result;
7425}
7426
7428{
7429 ROSE_ASSERT(key != NULL && datum != NULL);
7430 SgKeyDatumPair *result = new SgKeyDatumPair(key, datum);
7431 key->set_parent(result);
7432 datum->set_parent(result);
7434 return result;
7435}
7436
7438{
7439 ROSE_ASSERT(key != NULL && datum != NULL);
7440 SgKeyDatumPair *result = new SgKeyDatumPair(key, datum);
7441 key->set_parent(result);
7442 datum->set_parent(result);
7444 return result;
7445}
7446
7447SgDictionaryExp* SageBuilder::buildDictionaryExp(std::vector<SgKeyDatumPair*> pairs)
7448{
7449 SgDictionaryExp *result = new SgDictionaryExp();
7450 ROSE_ASSERT(result);
7451 for (size_t i = 0; i < pairs.size(); ++i)
7452 result->append_pair(pairs[i]);
7454 return result;
7455}
7456
7457SgDictionaryExp* SageBuilder::buildDictionaryExp_nfi(std::vector<SgKeyDatumPair*> pairs)
7458{
7459 SgDictionaryExp *result = new SgDictionaryExp();
7460 ROSE_ASSERT(result);
7461 for (size_t i = 0; i < pairs.size(); ++i)
7462 result->append_pair(pairs[i]);
7464 return result;
7465}
7466
7469{
7470 ROSE_ASSERT(target != NULL);
7471 ROSE_ASSERT(iter != NULL);
7472 SgComprehension *result = new SgComprehension(target, iter, ifs);
7473 ROSE_ASSERT(result);
7474
7475 target->set_parent(result);
7476 iter->set_parent(result);
7477 if (ifs != NULL) ifs->set_parent(result);
7478
7480 return result;
7481}
7482
7485{
7486 ROSE_ASSERT(target != NULL);
7487 ROSE_ASSERT(iter != NULL);
7488 SgComprehension *result = new SgComprehension(target, iter, ifs);
7489 ROSE_ASSERT(result);
7490 target->set_parent(result);
7491 iter->set_parent(result);
7492 if (ifs != NULL) ifs->set_parent(result);
7494 return result;
7495}
7496
7499{
7500 ROSE_ASSERT(elt != NULL);
7501 ROSE_ASSERT(generators != NULL);
7502 SgListComprehension* result = new SgListComprehension(elt, generators);
7503 elt->set_parent(result);
7504 generators->set_parent(result);
7506 return result;
7507}
7508
7511{
7512 ROSE_ASSERT(elt != NULL);
7513 ROSE_ASSERT(generators != NULL);
7514 SgListComprehension* result = new SgListComprehension(elt, generators);
7515 elt->set_parent(result);
7516 generators->set_parent(result);
7518 return result;
7519}
7520
7523{
7524 ROSE_ASSERT(elt != NULL);
7525 ROSE_ASSERT(generators != NULL);
7526 SgSetComprehension* result = new SgSetComprehension(elt, generators);
7527 elt->set_parent(result);
7528 generators->set_parent(result);
7530 return result;
7531}
7532
7535{
7536 ROSE_ASSERT(elt != NULL);
7537 ROSE_ASSERT(generators != NULL);
7538 SgSetComprehension* result = new SgSetComprehension(elt, generators);
7539 elt->set_parent(result);
7540 generators->set_parent(result);
7542 return result;
7543}
7544
7547{
7548 ROSE_ASSERT(kd_pair != NULL);
7549 ROSE_ASSERT(generators != NULL);
7550 SgDictionaryComprehension* result = new SgDictionaryComprehension(kd_pair, generators);
7551 kd_pair->set_parent(result);
7552 generators->set_parent(result);
7554 return result;
7555}
7556
7559{
7560 ROSE_ASSERT(kd_pair != NULL);
7561 ROSE_ASSERT(generators != NULL);
7562 SgDictionaryComprehension* result = new SgDictionaryComprehension(kd_pair, generators);
7563 kd_pair->set_parent(result);
7564 generators->set_parent(result);
7566 return result;
7567}
7568
7571 ROSE_ASSERT(arg != NULL);
7572 SgActualArgumentExpression* result = new SgActualArgumentExpression(arg_name, arg);
7573 arg->set_parent(result);
7575 return result;
7576}
7577
7580 ROSE_ASSERT(arg != NULL);
7581 SgActualArgumentExpression* result = new SgActualArgumentExpression(arg_name, arg);
7582 arg->set_parent(result);
7584 return result;
7585}
7586
7589 {
7590 if (scope == NULL)
7592
7593 SgPragma* pragma = new SgPragma(name);
7594 ROSE_ASSERT(pragma);
7595
7597
7598 SgPragmaDeclaration* result = new SgPragmaDeclaration(pragma);
7599 ROSE_ASSERT(result);
7600
7602
7603 result->set_definingDeclaration (result);
7604 result->set_firstNondefiningDeclaration(result);
7605 pragma->set_parent(result);
7606
7607 // DQ (7/14/2012): Set the parent so that we can be consistent where possible (class declarations and
7608 // enum declaration can't have there parent set since they could be non-autonomous declarations).
7609 result->set_parent(scope);
7610
7611 if (scope || topScopeStack())
7612 ROSE_ASSERT(result->get_parent() != NULL);
7613
7614 return result;
7615 }
7616
7618SgPragma* SageBuilder::buildPragma(const std::string & name)
7619{
7620 SgPragma* result= new SgPragma(name);
7621 ROSE_ASSERT(result);
7623 return result;
7624}
7625
7626
7628 {
7629 // Build an empty declaration (useful for adding precission to comments and CPP handling under token-based unparsing).
7630 SgEmptyDeclaration* emptyDeclaration = new SgEmptyDeclaration();
7631 ROSE_ASSERT(emptyDeclaration != NULL);
7632
7633 setOneSourcePositionForTransformation(emptyDeclaration);
7634
7635 emptyDeclaration->set_definingDeclaration (emptyDeclaration);
7636 emptyDeclaration->set_firstNondefiningDeclaration(emptyDeclaration);
7637
7638 // DQ (7/14/2012): Set the parent so that we can be consistent where possible (class declarations and
7639 // enum declaration can't have there parent set since they could be non-autonomous declarations).
7640 emptyDeclaration->set_parent(topScopeStack());
7641
7642 if (topScopeStack() != NULL)
7643 {
7644 ROSE_ASSERT(emptyDeclaration->get_parent() != NULL);
7645 }
7646
7647 return emptyDeclaration;
7648 }
7649
7650
7652{
7653 SgBasicBlock* result = new SgBasicBlock();
7654 ROSE_ASSERT(result);
7655
7656 // CR (3/22/2020): Fixed setting case insensitivity
7657 // if (symbol_table_case_insensitive_semantics == true)
7659 result->setCaseInsensitive(true);
7660
7662 if (stmt1) SageInterface::appendStatement(stmt1, result);
7663 if (stmt2) SageInterface::appendStatement(stmt2, result);
7664 if (stmt3) SageInterface::appendStatement(stmt3, result);
7665 if (stmt4) SageInterface::appendStatement(stmt4, result);
7666 if (stmt5) SageInterface::appendStatement(stmt5, result);
7667 if (stmt6) SageInterface::appendStatement(stmt6, result);
7668 if (stmt7) SageInterface::appendStatement(stmt7, result);
7669 if (stmt8) SageInterface::appendStatement(stmt8, result);
7670 if (stmt9) SageInterface::appendStatement(stmt9, result);
7671 if (stmt10) SageInterface::appendStatement(stmt10, result);
7672
7673 return result;
7674}
7675
7677 {
7678 SgBasicBlock* result = new SgBasicBlock();
7679 ROSE_ASSERT(result);
7680
7682 {
7683 result->setCaseInsensitive(true);
7684 }
7685
7687 return result;
7688 }
7689
7690SgBasicBlock* SageBuilder::buildBasicBlock_nfi(const vector<SgStatement*>& stmts)
7691 {
7693 appendStatementList(stmts, result);
7694 return result;
7695 }
7696
7697// Build a SgBasicBlock and set its parent. This function does NOT link the parent scope to the block.
7700{
7702 block->set_parent(parent);
7703
7704 return block;
7705}
7706
7709{
7710 SgGotoStatement* result = new SgGotoStatement(label);
7711 ROSE_ASSERT(result);
7713 return result;
7714}
7715
7718{
7719 SgGotoStatement* result = NULL;
7720 ROSE_ASSERT (symbol != NULL);
7722 { // Fortran case
7723 result = buildGotoStatement((SgLabelStatement *)NULL);
7724 SgLabelRefExp* l_exp = buildLabelRefExp(symbol);
7725 l_exp->set_parent(result);
7726 result->set_label_expression(l_exp);
7727 }
7728 else // C/C++ case
7729 {
7730 SgLabelStatement* l_stmt = isSgLabelStatement(symbol->get_declaration());
7731 ROSE_ASSERT (l_stmt != NULL);
7732 result = buildGotoStatement(l_stmt);
7733 }
7734 ROSE_ASSERT(result);
7735 return result;
7736}
7737
7740{
7741 SgGotoStatement* result = new SgGotoStatement(label);
7742 ROSE_ASSERT(result);
7744 return result;
7745}
7746
7747// DQ (11/22/2017): Added support for computed code goto as defined by GNU C/C++ extension.
7750 {
7751 SgLabelStatement* label = NULL;
7752 SgGotoStatement* result = new SgGotoStatement(label);
7753 result->set_selector_expression(label_expression);
7754 ROSE_ASSERT(result);
7756 return result;
7757 }
7758
7761{
7762 // Liao 2/6/2013. We no longer allow NULL express pointer. Use SgNullExpression instead.
7763 // CR (4/27/18): The expression argument to the builder function is optional
7764 // (NULL is allowed). What is not allowed is constructing an SgReturnStmt with a NULL
7765 // expression argument.
7766 if (expression == NULL)
7767 {
7768 expression = buildNullExpression();
7769 }
7770 SgReturnStmt* result = new SgReturnStmt(expression);
7771 ROSE_ASSERT(result);
7772 if (expression != NULL) expression->set_parent(result);
7774 return result;
7775}
7776
7779{
7780 SgReturnStmt* result = new SgReturnStmt(expression);
7781 ROSE_ASSERT(result);
7782 if (expression != NULL) expression->set_parent(result);
7784 return result;
7785}
7786
7788{
7789 SgCaseOptionStmt* result = new SgCaseOptionStmt(key,body);
7790 ROSE_ASSERT(result);
7792 if (key) key->set_parent(result);
7793 if (body) body->set_parent(result);
7794 return result;
7795}
7796
7798{
7799 SgCaseOptionStmt* result = new SgCaseOptionStmt(key,body);
7800 ROSE_ASSERT(result);
7802 if (key) key->set_parent(result);
7803 if (body) body->set_parent(result);
7804 return result;
7805}
7806
7808{
7809 SgDefaultOptionStmt* result = new SgDefaultOptionStmt(body);
7810 ROSE_ASSERT(result);
7812 if (body) body->set_parent(result);
7813 return result;
7814}
7815
7817{
7818 SgDefaultOptionStmt* result = new SgDefaultOptionStmt(body);
7819 ROSE_ASSERT(result);
7821 if (body) body->set_parent(result);
7822 return result;
7823}
7824
7826{
7827 SgSwitchStatement* result = new SgSwitchStatement(item_selector,body);
7828 ROSE_ASSERT(result);
7829
7831 result->setCaseInsensitive(true);
7832
7834 if (item_selector) item_selector->set_parent(result);
7835 if (body) body->set_parent(result);
7836 return result;
7837}
7838
7841{
7842 SgSwitchStatement* result = new SgSwitchStatement(item_selector,body);
7843 ROSE_ASSERT(result);
7844
7845 // DQ (2/15/2012): Modified to handle C++ case where variable declarations are allowed in the condition.
7846 initializeSwitchStatement(result,item_selector,body);
7847 return result;
7848}
7849
7852{
7853 SgNullStatement* result = NULL;
7854 result = new SgNullStatement();
7855 ROSE_ASSERT(result);
7857 return result;
7858}
7859
7862{
7863 SgNullStatement* result = NULL;
7864 result = new SgNullStatement();
7865 ROSE_ASSERT(result);
7867 return result;
7868}
7869
7872 SgExpression* globals,
7873 SgExpression* locals) {
7874 if (locals != NULL && globals == NULL)
7875 ROSE_ASSERT(!"buildExecStatement with non-NULL locals requires non-NULL globals");
7876 ROSE_ASSERT(executable != NULL);
7877
7878 SgExecStatement* result = new SgExecStatement(executable, globals, locals);
7879 executable->set_parent(result);
7880 if (globals != NULL) globals->set_parent(result);
7881 if (locals != NULL) locals->set_parent(result);
7882
7884 return result;
7885}
7886
7889 SgExpression* globals,
7890 SgExpression* locals) {
7891 if (locals != NULL && globals == NULL)
7892 ROSE_ASSERT(!"buildExecStatement with non-NULL locals requires non-NULL globals");
7893 ROSE_ASSERT(executable != NULL);
7894
7895 SgExecStatement* result = new SgExecStatement(executable, globals, locals);
7896 executable->set_parent(result);
7897 if (globals != NULL) globals->set_parent(result);
7898 if (locals != NULL) locals->set_parent(result);
7899
7901 return result;
7902}
7903
7904// MH (6/10/2014): Added async support
7906{
7907 ROSE_ASSERT(body != NULL);
7908 SgAsyncStmt *async_stmt = new SgAsyncStmt(body);
7909 ROSE_ASSERT(async_stmt);
7910 body->set_parent(async_stmt);
7912
7913 return async_stmt;
7914}
7915
7916// MH (6/11/2014): Added finish support
7918{
7919 ROSE_ASSERT(body != NULL);
7920 SgFinishStmt *finish_stmt = new SgFinishStmt(body);
7921 ROSE_ASSERT(finish_stmt);
7922 body->set_parent(finish_stmt);
7924
7925 return finish_stmt;
7926}
7927
7928// MH (6/11/2014): Added at support
7930{
7931 ROSE_ASSERT(expression);
7932 ROSE_ASSERT(body);
7933 SgAtStmt *at_stmt = new SgAtStmt(expression, body);
7935 expression->set_parent(at_stmt);
7936 body->set_parent(at_stmt);
7937
7938 return at_stmt;
7939}
7940
7941// MH (11/12/2014): Added atomic support
7943{
7944 ROSE_ASSERT(body != NULL);
7945 SgAtomicStmt *atomic_stmt = new SgAtomicStmt(body);
7946 ROSE_ASSERT(atomic_stmt);
7947 body->set_parent(atomic_stmt);
7949
7950 return atomic_stmt;
7951}
7952
7953
7955{
7956 ROSE_ASSERT(expression);
7957 ROSE_ASSERT(body);
7958 SgWhenStmt *when_stmt = new SgWhenStmt(expression, body);
7960 expression->set_parent(when_stmt);
7961 body->set_parent(when_stmt);
7962
7963 return when_stmt;
7964}
7965
7966// MH (9/14/2014): Added atexpr support
7968{
7969 ROSE_ASSERT(expression);
7970 ROSE_ASSERT(body);
7971 SgAtExp *at_exp = new SgAtExp(expression, body);
7973 expression->set_parent(at_exp);
7974 body->set_parent(at_exp);
7975
7976 return at_exp;
7977}
7978
7979// MH (11/7/2014): Added finish expression support
7981{
7982 ROSE_ASSERT(expression);
7983 ROSE_ASSERT(body);
7984 SgFinishExp *finish_exp = new SgFinishExp(expression, body);
7986 expression->set_parent(finish_exp);
7987 body->set_parent(finish_exp);
7988
7989 return finish_exp;
7990}
7991
7993{
7994 SgHereExp *here = new SgHereExp(NULL);
7995 return here;
7996}
7997
7999{
8000 SgDotDotExp *dotdot = new SgDotDotExp(NULL);
8001 return dotdot;
8002}
8003
8004
8007 SgCatchOptionStmt* catch0,
8008 SgCatchOptionStmt* catch1,
8009 SgCatchOptionStmt* catch2,
8010 SgCatchOptionStmt* catch3,
8011 SgCatchOptionStmt* catch4
8012 )
8013 {
8014 ROSE_ASSERT(body != NULL);
8015 SgTryStmt* try_stmt = new SgTryStmt(body);
8016 body->set_parent(try_stmt);
8017
8018 // DQ (11/3/2012): Added setting default source position info.
8019 setSourcePosition(try_stmt);
8020
8021 if (try_stmt->get_catch_statement_seq_root() != NULL)
8022 {
8023 if (try_stmt->get_catch_statement_seq_root()->get_startOfConstruct() == NULL)
8024 {
8025 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_endOfConstruct() == NULL);
8027 }
8028
8029 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_startOfConstruct() != NULL);
8030 ROSE_ASSERT(try_stmt->get_catch_statement_seq_root()->get_endOfConstruct() != NULL);
8031 }
8032
8033 if (catch0 != NULL) try_stmt->append_catch_statement(catch0);
8034 if (catch1 != NULL) try_stmt->append_catch_statement(catch1);
8035 if (catch2 != NULL) try_stmt->append_catch_statement(catch2);
8036 if (catch3 != NULL) try_stmt->append_catch_statement(catch3);
8037 if (catch4 != NULL) try_stmt->append_catch_statement(catch4);
8038
8039 return try_stmt;
8040 }
8041
8042
8043// charles4 09/16/2011
8046 {
8047 //
8048 // charles4 09/23/2011 - Note that when an SgTryStmt is allocated, its constructor
8049 // preallocates a SgCatchStementSeq for the field p_catch_statement_sequence_root.
8050 // So, although the method set_catch_statement_seq_root(catch_statement_sequence) is
8051 // available, it should not be used to set the catch_statement_sequence_root as that
8052 // would leave the one that was allocated by the constructor dangling!
8053 //
8054 ROSE_ASSERT(try_body != NULL);
8055 SgTryStmt* try_stmt = new SgTryStmt(try_body);
8056 try_body -> set_parent(try_stmt);
8057
8058 // DQ (11/3/2012): Added setting default source position info.
8059 setSourcePosition(try_stmt);
8060
8061 if (finally_body) {
8062 try_stmt -> set_finally_body(finally_body);
8063 finally_body -> set_parent(try_stmt);
8064 }
8065
8066 return try_stmt;
8067}
8068
8069// charles4 09/16/2011
8070// ! Build an initial sequence of Catch blocks containing 0 or 1 element.
8072 SgCatchStatementSeq *catch_statement_sequence = new SgCatchStatementSeq();
8073
8074 // DQ (11/3/2012): Added setting default source position info.
8075 setSourcePosition(catch_statement_sequence);
8076
8077 if (catch_option_stmt) {
8078 catch_statement_sequence -> append_catch_statement(catch_option_stmt);
8079 catch_option_stmt -> set_parent(catch_statement_sequence);
8080 }
8081
8082 return catch_statement_sequence;
8083}
8084
8085// charles4 09/21/2011 - Make condition and body arguments optional.
8088 SgCatchOptionStmt* result = new SgCatchOptionStmt(condition, body, /* SgTryStmt*= */ NULL);
8089 if (condition) condition->set_parent(result);
8090 if (body) body->set_parent(result);
8092 return result;
8093}
8094
8096{
8097 ROSE_ASSERT(expression);
8098 ROSE_ASSERT(body);
8099 SgJavaSynchronizedStatement *sync_stmt = new SgJavaSynchronizedStatement(expression, body);
8101
8102 expression->set_parent(sync_stmt);
8103 body->set_parent(sync_stmt);
8104
8105 return sync_stmt;
8106}
8107
8109{
8110 ROSE_ASSERT(op);
8111 SgJavaThrowStatement *throw_stmt = new SgJavaThrowStatement(op);
8112 ROSE_ASSERT(throw_stmt);
8113
8114 op->set_parent(throw_stmt);
8115
8116 return throw_stmt;
8117}
8118
8119// DQ (9/3/2011): Changed the API to conform to the Java grammar.
8120// SgJavaForEachStatement *SageBuilder::buildJavaForEachStatement(SgInitializedName *variable, SgExpression *collection, SgStatement *body)
8122{
8123 SgJavaForEachStatement *foreach_stmt = new SgJavaForEachStatement(variable, collection, body);
8124 ROSE_ASSERT(foreach_stmt);
8125 if (variable) variable -> set_parent(foreach_stmt);
8126 if (collection) collection -> set_parent(foreach_stmt);
8127 if (body) body -> set_parent(foreach_stmt);
8128
8129 return foreach_stmt;
8130}
8131
8133{
8134 SgJavaLabelStatement *label_stmt = new SgJavaLabelStatement(name, stmt);
8135 ROSE_ASSERT(label_stmt);
8137
8138 if (stmt != NULL)
8139 stmt -> set_parent(label_stmt);
8140
8141 SgJavaLabelSymbol *lsymbol = label_stmt -> lookup_java_label_symbol(name);
8142 if (! lsymbol) // Should be an Assertion - always true!
8143 {
8144 lsymbol= new SgJavaLabelSymbol(label_stmt);
8145 ROSE_ASSERT(lsymbol);
8146 label_stmt -> insert_symbol(lsymbol -> get_name(), lsymbol);
8147 }
8148
8149 return label_stmt;
8150}
8151
8154 SgPythonPrintStmt* result = new SgPythonPrintStmt(dest, values);
8155 if (dest) dest->set_parent(result);
8156 if (values) values->set_parent(result);
8158 return result;
8159}
8160
8163 SgPythonPrintStmt* result = new SgPythonPrintStmt(dest, values);
8164 if (dest) dest->set_parent(result);
8165 if (values) values->set_parent(result);
8167 return result;
8168}
8169
8171SageBuilder::buildPythonGlobalStmt(SgInitializedNamePtrList& names) {
8172 SgPythonGlobalStmt* result = new SgPythonGlobalStmt();
8173 for (SgInitializedName* name: names) {
8174 result->append_name(name);
8175 }
8177 return result;
8178}
8179
8181SageBuilder::buildPythonGlobalStmt_nfi(SgInitializedNamePtrList& names) {
8182 SgPythonGlobalStmt* result = new SgPythonGlobalStmt();
8183 for (SgInitializedName* name: names) {
8184 result->append_name(name);
8185 }
8187 return result;
8188}
8189
8190// DQ (4/30/2010): Added support for building asm statements.
8193{
8194 SgAsmStmt* result = NULL;
8195 result = new SgAsmStmt();
8196 ROSE_ASSERT(result);
8197 result->set_assemblyCode(s);
8199 return result;
8200}
8201
8202// DQ (4/30/2010): Added support for building asm statements.
8205{
8206 SgAsmStmt* result = NULL;
8207 result = new SgAsmStmt();
8208 ROSE_ASSERT(result);
8209 result->set_assemblyCode(s);
8211 return result;
8212}
8213
8214SgAsmStmt*
8216 {
8217// Multi-byte NOP instructions.
8218// Note: I can't seem to get the memonic versions to work properly
8219#define NOP_1_BYTE_STRING "nop"
8220#define NOP_2_BYTE_STRING ".byte 0x66,0x90"
8221#define NOP_3_BYTE_STRING "nopl (%eax)"
8222#define NOP_4_BYTE_STRING "nopl 0x01(%eax)"
8223#define NOP_5_BYTE_STRING ".byte 0x0f,0x1f,0x44,0x00,0x00"
8224#define NOP_6_BYTE_STRING ".byte 0x66,0x0f,0x1f,0x44,0x00,0x00"
8225#define NOP_7_BYTE_STRING ".byte 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00"
8226#define NOP_8_BYTE_STRING ".byte 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00"
8227#define NOP_9_BYTE_STRING ".byte 0x66,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00"
8228
8229 ROSE_ASSERT(n > 0);
8230
8231 SgAsmStmt* nopStatement = NULL;
8232
8233 switch (n)
8234 {
8235 case 1: nopStatement = buildAsmStatement(NOP_1_BYTE_STRING); break;
8236 case 2: nopStatement = buildAsmStatement(NOP_2_BYTE_STRING); break;
8237 case 3: nopStatement = buildAsmStatement(NOP_3_BYTE_STRING); break;
8238 case 4: nopStatement = buildAsmStatement(NOP_4_BYTE_STRING); break;
8239 case 5: nopStatement = buildAsmStatement(NOP_5_BYTE_STRING); break;
8240 case 6: nopStatement = buildAsmStatement(NOP_6_BYTE_STRING); break;
8241 case 7: nopStatement = buildAsmStatement(NOP_7_BYTE_STRING); break;
8242 case 8: nopStatement = buildAsmStatement(NOP_8_BYTE_STRING); break;
8243 case 9: nopStatement = buildAsmStatement(NOP_9_BYTE_STRING); break;
8244
8245 default:
8246 {
8247 printf ("Only supporting values of multi-byte nop's up to 9 bytes long. \n");
8248 ROSE_ABORT();
8249 }
8250 }
8251
8252 return nopStatement;
8253 }
8254
8256 {
8257 // DQ (7/25/2014): Adding support for C11 static assertions.
8258
8259 ROSE_ASSERT(condition != NULL);
8260
8261 SgStaticAssertionDeclaration* result = new SgStaticAssertionDeclaration(condition,string_literal);
8262 ROSE_ASSERT(result != NULL);
8263
8264 // DQ (7/25/2014): It is enforced that at least the firstNondefiningDeclaration be set.
8265 ROSE_ASSERT(result->get_firstNondefiningDeclaration() == NULL);
8266 result->set_firstNondefiningDeclaration(result);
8267 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
8268
8270
8271 return result;
8272 }
8273
8274
8275// DQ (8/17/2014): Adding support for Microsoft MSVC specific attributes.
8277 {
8279 ROSE_ASSERT(result != NULL);
8280
8281 // DQ (8/17/2014): It is enforced that at least the firstNondefiningDeclaration be set.
8282 ROSE_ASSERT(result->get_firstNondefiningDeclaration() == NULL);
8283 result->set_firstNondefiningDeclaration(result);
8284 ROSE_ASSERT(result->get_firstNondefiningDeclaration() != NULL);
8285
8287
8288 return result;
8289 }
8290
8292 {
8293 if (isSgReferenceType (base_type))
8294 {
8295 cerr<<"Error in SageBuilder::buildPointerType(): trying to build a pointer to a reference type! This is not allowed in C++."<<endl;
8296 ROSE_ABORT ();
8297 }
8298
8299 SgPointerType* result = SgPointerType::createType(base_type);
8300 ROSE_ASSERT(result != NULL);
8301
8302 return result;
8303 }
8304
8306 {
8307 SgReferenceType* result = SgReferenceType::createType(base_type);
8308 ROSE_ASSERT(result != NULL);
8309 return result;
8310 }
8311
8313 {
8314 ROSE_ASSERT(base_type != NULL);
8316 ROSE_ASSERT(result != NULL);
8317
8318 return result;
8319 }
8320
8322 {
8323 ROSE_ASSERT(base_expression != NULL);
8324
8325 // SgDeclType* result = SgDeclType::createType(base_expression);
8326 SgDeclType* result = NULL;
8327 if (isSgFunctionParameterRefExp(base_expression) != NULL)
8328 {
8329 result = new SgDeclType(base_expression);
8330 result->set_base_type(base_type);
8331 }
8332 else
8333 {
8334 result = SgDeclType::createType(base_expression);
8335 }
8336
8337 ROSE_ASSERT(result != NULL);
8338
8339 // DQ (8/12/2014): Set the parent in the expression.
8340 base_expression->set_parent(result);
8341
8342 return result;
8343 }
8344
8347 {
8348 // ROSE_ASSERT(base_expression != NULL);
8349
8350#define DEBUG_TYPEOF_TYPE 0
8351
8352#if DEBUG_TYPEOF_TYPE
8353 printf ("In SageBuilder::buildTypeOfType(): base_expression = %p = %s \n",base_expression,base_expression != NULL ? base_expression->class_name().c_str() : "NULL");
8354 printf (" ------------------------------- base_type = %p = %s \n",base_type,base_type != NULL ? base_type->class_name().c_str() : "NULL");
8355#endif
8356
8357 SgTypeOfType* result = NULL;
8358 if (isSgFunctionParameterRefExp(base_expression) != NULL)
8359 {
8360#if DEBUG_TYPEOF_TYPE
8361 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) != NULL: calling new SgTypeOfType(base_expression,NULL) \n");
8362#endif
8363 result = new SgTypeOfType(base_expression,NULL);
8364
8365 // DQ (3/28/2015): Testing for corruption in return value.
8366 ROSE_ASSERT(result != NULL);
8367#if DEBUG_TYPEOF_TYPE
8368 printf ("In buildTypeOfType(): test 1: result = %p = %s \n",result,result->class_name().c_str());
8369#endif
8370 result->set_base_type(base_type);
8371 }
8372 else
8373 {
8374 if (base_expression != NULL)
8375 {
8376#if DEBUG_TYPEOF_TYPE
8377 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) == NULL: base_expression != NULL: calling SgTypeOfType::createType(base_expression,NULL) \n");
8378#endif
8379 result = SgTypeOfType::createType(base_expression,NULL);
8380
8381 // DQ (3/28/2015): Testing for corruption in return value.
8382 ROSE_ASSERT(result != NULL);
8383#if DEBUG_TYPEOF_TYPE
8384 printf ("In buildTypeOfType(): test 2: result = %p = %s \n",result,result->class_name().c_str());
8385#endif
8386 }
8387 else
8388 {
8389 ROSE_ASSERT(base_type != NULL);
8390
8391#if DEBUG_TYPEOF_TYPE
8392 printf ("In SageBuilder::buildTypeOfType(): isSgFunctionParameterRefExp(base_expression) == NULL: base_expression == NULL: calling SgTypeOfType::createType(base_type,NULL) \n");
8393#endif
8394 result = SgTypeOfType::createType(base_type,NULL);
8395
8396 // DQ (3/28/2015): Testing for corruption in return value.
8397 ROSE_ASSERT(result != NULL);
8398
8399#if DEBUG_TYPEOF_TYPE
8400 printf ("In buildTypeOfType(): test 3: result = %p = %s \n",result,result->class_name().c_str());
8401#endif
8402 // result->set_base_type(base_type);
8403 if (result->get_base_type() != base_type)
8404 {
8405 ROSE_ASSERT(result->get_base_type() != NULL);
8406#if DEBUG_TYPEOF_TYPE
8407 printf ("result->get_base_type() = %p = %s \n",result->get_base_type(),result->get_base_type()->class_name().c_str());
8408#endif
8409 ROSE_ASSERT(base_type != NULL);
8410#if DEBUG_TYPEOF_TYPE
8411 printf ("base_type = %p = %s \n",base_type,base_type->class_name().c_str());
8412#endif
8413 }
8414 }
8415 }
8416
8417 ROSE_ASSERT(result != NULL);
8418
8419 if (base_expression != NULL)
8420 {
8421 base_expression->set_parent(result);
8422 }
8423
8424 // DQ (3/28/2015): Testing for corruption in return value.
8425 ROSE_ASSERT(result != NULL);
8426
8427#if DEBUG_TYPEOF_TYPE
8428 printf ("In buildTypeOfType(): test 4: result = %p = %s \n",result,result->class_name().c_str());
8429#endif
8430
8431 return result;
8432 }
8433
8434// Builder functions for type size (kind) expressions for Fortran and Jovial
8436 SgTypeBool* result = SgTypeBool::createType(kind_expr);
8437 ROSE_ASSERT(result);
8438 if (kind_expr != NULL) kind_expr->set_parent(result);
8439 return result;
8440}
8444
8446{
8448 ROSE_ASSERT(result);
8449 return result;
8450}
8451
8453{
8455 ROSE_ASSERT(result);
8456 return result;
8457}
8458
8460{
8462 ROSE_ASSERT(result);
8463 return result;
8464}
8465
8467{
8469 ROSE_ASSERT(result);
8470 return result;
8471}
8472
8474{
8476 ROSE_ASSERT(result);
8477 return result;
8478}
8479
8481{
8483 ROSE_ASSERT(result);
8484 return result;
8485}
8486
8487// Builder functions for type size (kind) expressions for Fortran and Jovial
8489{
8491 ROSE_ASSERT(result);
8492 if (kind_expr != NULL) kind_expr->set_parent(result);
8493 return result;
8494}
8499
8501{
8503 ROSE_ASSERT(result);
8504 return result;
8505}
8506
8509 ROSE_ASSERT(result);
8510 return result;
8511}
8512
8515 ROSE_ASSERT(result);
8516 return result;
8517}
8518
8521 ROSE_ASSERT(result);
8522 return result;
8523}
8524
8527 ROSE_ASSERT(result);
8528 return result;
8529}
8530
8533 ROSE_ASSERT(result);
8534 return result;
8535}
8536
8539 ROSE_ASSERT(result);
8540 return result;
8541}
8542
8545 ROSE_ASSERT(result);
8546 return result;
8547}
8548
8551 ROSE_ASSERT(result);
8552 return result;
8553}
8554
8557 ROSE_ASSERT(result);
8558 return result;
8559}
8560
8562{
8564 ROSE_ASSERT(result);
8565 return result;
8566}
8567
8569{
8571 ROSE_ASSERT(result);
8572 return result;
8573}
8574
8576{
8578 ROSE_ASSERT(result);
8579 return result;
8580}
8581
8583{
8585 ROSE_ASSERT(result);
8586 return result;
8587}
8588
8595
8602
8604{
8606 ROSE_ASSERT(result);
8607 return result;
8608}
8609
8611{
8613 ROSE_ASSERT(result);
8614 return result;
8615}
8616
8618{
8620 ROSE_ASSERT(result);
8621 return result;
8622}
8623
8625{
8627 ROSE_ASSERT(result);
8628 return result;
8629}
8630
8632{
8634 ROSE_ASSERT(result);
8635 return result;
8636}
8637
8639{
8641 ROSE_ASSERT(result);
8642 return result;
8643}
8644
8646{
8647 SgAutoType * result =new SgAutoType();
8648 ROSE_ASSERT(result);
8649 return result;
8650}
8651
8653{
8655 ROSE_ASSERT(result);
8656 return result;
8657}
8658
8660{
8662 ROSE_ASSERT(result);
8663 return result;
8664}
8665
8667{
8669 ROSE_ASSERT(result);
8670 return result;
8671}
8672
8674 {
8675 // DQ (8/17/2010): This function needs to use a different API to handle a literal
8676 // value for the string size (typical) or an expression for the string size (rare).
8677 // For now we will make it an error to call this function.
8678
8679 // SgTypeString * result =SgTypeString::createType();
8680 SgTypeString * result = NULL;
8681 ROSE_ASSERT(result != NULL);
8682 return result;
8683 }
8684
8686 {
8687 // DQ (8/21/2010): This is a new API for this function. This type is specific to Fortran use,
8688 // in C/C++ a string is just an array of char. We could have a consistant handling between
8689 // C/C++ and Fortrna, but we have just corrected the implementation in Fortran to use this IR
8690 // node and we would have to add such support to C/C++. The current implementation reflects
8691 // the grammar of the two languages.
8692
8693 // This function needs to use a different API to handle a literal
8694 // value for the string size (typical) or an expression for the string size (rare).
8695
8696 SgTypeString* result = SgTypeString::createType(stringLengthExpression);
8697 ASSERT_not_null(result);
8698 return result;
8699 }
8700
8701// Rasmussen (2/20/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8703{
8704 SgTypeInt * result;
8705 if (kind_expr != NULL)
8706 {
8707 result = SgTypeInt::createType(0, kind_expr);
8708 kind_expr->set_parent(result);
8709 }
8710 else
8711 {
8712 result = SgTypeInt::createType();
8713 }
8714 ASSERT_not_null(result);
8715 return result;
8716}
8718{
8719 return buildIntType(NULL);
8720}
8721
8723{
8725 ROSE_ASSERT(result);
8726 return result;
8727}
8728
8729// Rasmussen (3/6/2020): Added builder functions for type size (kind) expressions for Fortran and Jovial
8731{
8732 SgTypeFloat * result;
8733 if (kind_expr != NULL)
8734 {
8735 result = SgTypeFloat::createType(kind_expr);
8736 kind_expr->set_parent(result);
8737 }
8738 else
8739 {
8740 result = SgTypeFloat::createType();
8741 }
8742 ASSERT_not_null(result);
8743 return result;
8744}
8746{
8748 ASSERT_not_null(result);
8749 return result;
8750}
8751
8752// Rasmussen (2/20/2020): Added builder for Jovial fixed type
8754{
8755 SgTypeFixed * result = SgTypeFixed::createType(scale, fraction);
8756 ROSE_ASSERT(result);
8757
8758 if (scale) scale->set_parent(result);
8759 if (fraction) fraction->set_parent(result);
8760
8761 return result;
8762}
8763
8764// Rasmussen (5/5/2020): Added builder for Jovial bit type
8766{
8767 SgJovialBitType * result = SgJovialBitType::createType(size, NULL);
8768
8769 if (size) size->set_parent(result);
8770
8771 return result;
8772}
8773
8774// DQ (7/29/2010): Changed return type from SgType to SgModifierType
8777 {
8778 ROSE_ASSERT(base_type != NULL);
8779
8780 // DQ (7/28/2010): New (similar) approach using type table support.
8781 SgModifierType* result = new SgModifierType(base_type);
8782 ROSE_ASSERT(result != NULL);
8783
8784 // DQ (3/10/2018): Adding assertion.
8785 ROSE_ASSERT(result != base_type);
8786
8787 // DQ (7/28/2010): Insert result type into type table and return it, or
8788 // replace the result type, if already available in the type table, with
8789 // the type from type table.
8790 SgModifierType* result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8791
8792 if (result != result2)
8793 {
8794 // DQ (10/27/2015): This is the cause of a bug in the test2015_97.C (boost template problem).
8795 printf ("WARNING: In SageBuilder::buildModifierType(): using previously build SgModifierType from global type table: result2 = %p = %s \n",result2,result2->class_name().c_str());
8796 delete result;
8797 }
8798
8799 // DQ (3/10/2018): Adding assertion.
8800 ROSE_ASSERT(result2 != base_type);
8801
8802 return result2;
8803 }
8804
8807 {
8808 ROSE_ASSERT(base_type != NULL);
8809
8810 // DQ (7/28/2010): New (similar) approach using type table support.
8811 SgModifierType *result = new SgModifierType(base_type);
8812 ROSE_ASSERT(result!=NULL);
8813 result->get_typeModifier().get_constVolatileModifier().setConst();
8814
8815 // DQ (7/28/2010): Insert result type into type table and return it, or
8816 // replace the result type, if already available in the type table, with
8817 // the type from type table.
8818 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8819
8820 if (result != result2)
8821 {
8822 delete result;
8823 }
8824
8825 // DQ (3/10/2018): Adding assertion.
8826 ROSE_ASSERT(result2 != base_type);
8827
8828 return result2;
8829 }
8830
8831// DQ (8/27/2010): Added Fortran specific support for types based on kind expressions.
8834 {
8835 ROSE_ASSERT(base_type != NULL);
8836
8837 SgModifierType *result = new SgModifierType(base_type);
8838 ROSE_ASSERT(result != NULL);
8839
8840 result->set_type_kind(kindExpression);
8841
8842 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8843 if (result != result2)
8844 {
8845 delete result;
8846 }
8847
8848 return result2;
8849 }
8850
8851// DQ (7/29/2010): Changed return type from SgType to SgModifierType
8854 {
8855 ROSE_ASSERT(base_type != NULL);
8856 SgModifierType *result = new SgModifierType(base_type);
8857 ROSE_ASSERT(result!=NULL);
8858
8859 result->get_typeModifier().get_constVolatileModifier().setVolatile();
8860
8861 // DQ (7/29/2010): Insert result type into type table and return it, or
8862 // replace the result type, if already available in the type table, with
8863 // the type from type table.
8864 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8865 if (result != result2)
8866 {
8867 delete result;
8868 }
8869
8870 return result2;
8871 }
8872
8873// DQ (1/19/2019): Adding support for const volatile type (both together as another value).
8876 {
8877 ROSE_ASSERT(base_type != NULL);
8878
8879 SgModifierType *result = new SgModifierType(base_type);
8880 ROSE_ASSERT(result!=NULL);
8881
8882 result->get_typeModifier().get_constVolatileModifier().setConst();
8883 result->get_typeModifier().get_constVolatileModifier().setVolatile();
8884
8885 printf ("In SageBuilder::buildConstVolatileType(): Building a SgModifierType: result = %p base_type = %p = %s \n",result,base_type,base_type->class_name().c_str());
8886
8887 // DQ (7/29/2010): Insert result type into type table and return it, or
8888 // replace the result type, if already available in the type table, with
8889 // the type from type table.
8890 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8891 if (result != result2) {
8892 delete result;
8893 }
8894
8895 return result2;
8896 }
8897
8898string
8899generate_type_list (SgType* type)
8900 {
8901 // This function generates a list of types for each level of the type structure.
8902 string returnString;
8903
8904 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);
8905
8906 SgType* currentType = type;
8907
8908 SgModifierType* modType = NULL;
8909 SgPointerType* pointType = NULL;
8910 SgReferenceType* refType = NULL;
8911 SgRvalueReferenceType* rRefType = NULL;
8912 SgArrayType* arrayType = NULL;
8913 SgTypedefType* typedefType = NULL;
8914
8915 while (currentType != NULL)
8916 {
8917 returnString += currentType->class_name();
8918 if ( (bit_array & SgType::STRIP_MODIFIER_TYPE) && (modType = isSgModifierType(currentType)) )
8919 {
8920 currentType = modType->get_base_type();
8921 }
8922 else if ( (bit_array & SgType::STRIP_REFERENCE_TYPE) && (refType = isSgReferenceType(currentType)) )
8923 {
8924 currentType = refType->get_base_type();
8925 }
8926 else if ( (bit_array & SgType::STRIP_RVALUE_REFERENCE_TYPE) && (rRefType = isSgRvalueReferenceType(currentType)) )
8927 {
8928 currentType = rRefType->get_base_type();
8929 }
8930 else if ( (bit_array & SgType::STRIP_POINTER_TYPE) && (pointType = isSgPointerType(currentType)) )
8931 {
8932 currentType = pointType->get_base_type();
8933 }
8934 else if ( (bit_array & SgType::STRIP_ARRAY_TYPE) && (arrayType = isSgArrayType(currentType)) )
8935 {
8936 currentType = arrayType->get_base_type();
8937 }
8938 else if ( (bit_array & SgType::STRIP_TYPEDEF_TYPE) && (typedefType = isSgTypedefType(currentType)) )
8939 {
8940 currentType = typedefType->get_base_type();
8941 }
8942 else
8943 {
8944 break;
8945 }
8946
8947 if (type != NULL)
8948 returnString += " , ";
8949 }
8950
8951 return returnString;
8952 }
8953
8954// DQ (7/29/2010): Changed return type from SgType to SgModifierType
8957 {
8958 ROSE_ASSERT(base_type != NULL);
8959
8960 // DQ (1/30/2014): We need to include typedefs here as well (see test2014_77.c).
8961 // DQ (9/28/2012): Added that the base type could be an array (see test2012_03.c (C test code)).
8962 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type))
8963 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type))
8964 // if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type) && !isSgTypedefType(base_type))
8965 if (!isSgPointerType(base_type) && !isSgReferenceType(base_type) && !isSgArrayType(base_type) && !isSgTypedefType(base_type) && !isSgModifierType(base_type))
8966 {
8967 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());
8968 printf (" --- generate_type_list() = %s \n",generate_type_list(base_type).c_str());
8969 ROSE_ABORT();
8970 }
8971
8972 SgModifierType* result = new SgModifierType(base_type);
8973 ASSERT_not_null(result);
8974 result->get_typeModifier().setRestrict();
8975
8976 // DQ (7/29/2010): Insert result type into type table and return it, or
8977 // replace the result type, if already available in the type table, with
8978 // the type from type table.
8979 SgModifierType* result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8980 if (result != result2) {
8981 delete result;
8982 }
8983 return result2;
8984 }
8985
8986namespace
8987{
8988 // PP (2/16/24): model builder function after buildRestrictType
8990 _buildModifierType(SgType* base_type, std::function<void(SgModifierType*)> setModifiers)
8991 {
8992 ASSERT_not_null(base_type);
8993
8994 SgModifierType* result = new SgModifierType(base_type);
8995 setModifiers(result);
8996
8997 SgModifierType* result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
8998 if (result != result2) delete result;
8999
9000 return result2;
9001 }
9002}
9003
9005 {
9006 auto op = [](SgModifierType* ty) { ty->get_typeModifier().setAliased(); };
9007
9008 return _buildModifierType(base_type, op);
9009 }
9010
9012 {
9013 auto op = [](SgModifierType* ty) { ty->get_typeModifier().setNotNull(); };
9014
9015 return _buildModifierType(base_type, op);
9016 }
9017
9018
9019// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9022 {
9023 ROSE_ASSERT(base_type != NULL);
9024
9025 SgModifierType *result = new SgModifierType(base_type);
9026 ROSE_ASSERT(result!=NULL);
9027 result->get_typeModifier().get_upcModifier().set_modifier(SgUPC_AccessModifier::e_upc_strict);
9028
9029 // DQ (7/29/2010): Insert result type into type table and return it, or
9030 // replace the result type, if already available in the type table, with
9031 // the type from type table.
9032 SgModifierType *result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9033 if (result != result2) {
9034 delete result;
9035 }
9036 return result2;
9037 }
9038
9039// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9042 {
9043 ROSE_ASSERT(base_type != NULL);
9044
9045 SgModifierType *result = new SgModifierType(base_type);
9046 ROSE_ASSERT(result!=NULL);
9047 result->get_typeModifier().get_upcModifier().set_modifier(SgUPC_AccessModifier::e_upc_relaxed);
9048
9049 // DQ (7/29/2010): Insert result type into type table and return it, or
9050 // replace the result type, if already available in the type table, with
9051 // the type from type table.
9052 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9053 if (result != result2) {
9054 delete result;
9055 }
9056 return result2;
9057 }
9058
9059// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9061SgModifierType* SageBuilder::buildUpcSharedType(SgType* base_type /*=NULL*/, long layout /*= -1*/)
9062 {
9063 ROSE_ASSERT(base_type != NULL);
9064
9065 SgModifierType *result = new SgModifierType(base_type);
9066 ROSE_ASSERT(result!=NULL);
9067
9068 result->get_typeModifier().get_upcModifier().set_isShared(true);
9069 result->get_typeModifier().get_upcModifier().set_layout(layout); // No layout ("shared" without a block size)
9070
9071 // DQ (7/29/2010): Insert result type into type table and return it, or
9072 // replace the result type, if already available in the type table, with
9073 // the type from type table.
9074 SgModifierType * result2 = SgModifierType::insertModifierTypeIntoTypeTable(result);
9075 if (result != result2) {
9076 delete result;
9077 }
9078 return result2;
9079 }
9080
9081// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9084 {
9085 ROSE_ASSERT(base_type != NULL);
9086
9087 SgModifierType* result = isSgModifierType(buildUpcSharedType(base_type));
9088 ROSE_ASSERT(result != NULL);
9089 result->get_typeModifier().get_upcModifier().set_layout(0); // [] layout
9090
9091 // DQ (7/29/2010): Insert result type into type table and return it, or
9092 // replace the result type, if already available in the type table, with
9093 // the type from type table.
9094 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9095 return result;
9096 }
9097
9098// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9101 {
9102 ROSE_ASSERT(base_type != NULL);
9103
9104 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9105 ROSE_ASSERT(result!=NULL);
9106 result->get_typeModifier().get_upcModifier().set_layout(-2); // [*] layout
9107
9108 // DQ (7/29/2010): Insert result type into type table and return it, or
9109 // replace the result type, if already available in the type table, with
9110 // the type from type table.
9111 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9112 return result;
9113 }
9114
9115// DQ (7/29/2010): Changed return type from SgType to SgModifierType
9118 {
9119 ROSE_ASSERT(base_type != NULL);
9120
9121 SgModifierType *result = isSgModifierType(buildUpcSharedType(base_type));
9122 ROSE_ASSERT(result!=NULL);
9123 result->get_typeModifier().get_upcModifier().set_layout(block_factor); // [block_factor] layout
9124
9125 // DQ (7/29/2010): Insert result type into type table and return it, or
9126 // replace the result type, if already available in the type table, with
9127 // the type from type table.
9128 result = SgModifierType::insertModifierTypeIntoTypeTable(result);
9129 return result;
9130 }
9131
9134{
9135 ROSE_ASSERT(base_type != NULL);
9136 SgTypeComplex *result = new SgTypeComplex(base_type);
9137 ROSE_ASSERT(result!=NULL);
9138 return result;
9139}
9140
9143{
9144 ROSE_ASSERT(base_type != NULL);
9145 SgTypeImaginary *result = new SgTypeImaginary(base_type);
9146 ROSE_ASSERT(result!=NULL);
9147 return result;
9148}
9149
9152{
9153 SgTypeMatrix *result = new SgTypeMatrix();
9154 ROSE_ASSERT(result != NULL);
9155 return result;
9156}
9157
9160{
9161 SgTypeTuple *result = new SgTypeTuple();
9162 ROSE_ASSERT(result != NULL);
9163
9164 if(t1) result->append_type(t1);
9165 if(t2) result->append_type(t2);
9166 if(t3) result->append_type(t3);
9167 if(t4) result->append_type(t4);
9168 if(t5) result->append_type(t5);
9169 if(t6) result->append_type(t6);
9170 if(t7) result->append_type(t7);
9171 if(t8) result->append_type(t8);
9172 if(t9) result->append_type(t9);
9173 if(t10) result->append_type(t10);
9174
9176
9177 return result;
9178}
9179
9182 SgNonrealDecl * nrdecl = buildNonrealDecl(name, scope);
9183 nrdecl->set_parent(scope);
9184 nrdecl->set_is_template_param (true);
9185 return nrdecl->get_type();
9186}
9187
9189{
9190 SgRangeExp *result = new SgRangeExp();
9192 ROSE_ASSERT(result != NULL);
9193
9194 result->append(start);
9195 return result;
9196}
9197
9199{
9200 SgRangeExp *result = new SgRangeExp();
9202 ROSE_ASSERT(result != NULL);
9203
9204 result->set_start(start);
9205 start->set_parent(result);
9206
9207 result->set_end(end);
9208 end->set_parent(result);
9209
9210 result->set_stride(stride);
9211 stride->set_parent(result);
9212 return result;
9213}
9214
9215
9217{
9218 SgMatrixExp *result = new SgMatrixExp();
9220
9221 result->append_expression(firstRow);
9222 ROSE_ASSERT(result != NULL);
9223
9224 return result;
9225}
9226
9228{
9229 SgMagicColonExp *result = new SgMagicColonExp();
9231
9232 ROSE_ASSERT(result != NULL);
9233
9234 return result;
9235}
9236
9239{
9240 SgConstVolatileModifier * result = NULL;
9241 result = new SgConstVolatileModifier();
9242 ROSE_ASSERT (result != NULL);
9243 result->set_modifier (mtype);
9244
9245 return result;
9246}
9247
9251 {
9252 // SgFunctionDeclaration* func_decl = buildDefiningFunctionDeclaration("__rose__lambda__",return_type,params,scope,NULL,NULL);
9253 SgFunctionDeclaration* func_decl = buildDefiningFunctionDeclaration("__rose__lambda__",return_type,params,scope,NULL,false,NULL,NULL);
9254
9255 SgLambdaRefExp* result = new SgLambdaRefExp(func_decl);
9256 func_decl->set_parent(result);
9257
9259
9260 return result;
9261 }
9262
9265 {
9266 SgTypeExpression *expr = new SgTypeExpression(type);
9268 return expr;
9269 }
9270
9271// DQ (8/11/2014): Added support for C++11 decltype used in new function return syntax.
9273SageBuilder::buildFunctionParameterRefExp(int parameter_number, int parameter_level )
9274 {
9275 SgFunctionParameterRefExp *expr = new SgFunctionParameterRefExp(NULL,parameter_number,parameter_level);
9276 ROSE_ASSERT(expr != NULL);
9277
9278 setSourcePosition(expr);
9279 return expr;
9280 }
9281
9282
9283// DQ (8/11/2014): Added support for C++11 decltype used in new function return syntax.
9285SageBuilder::buildFunctionParameterRefExp_nfi(int parameter_number, int parameter_level )
9286 {
9287 SgFunctionParameterRefExp *expr = new SgFunctionParameterRefExp(NULL,parameter_number,parameter_level);
9288 ROSE_ASSERT(expr != NULL);
9289
9291 return expr;
9292 }
9293
9294// DQ (9/3/2014): Adding support for C++11 Lambda expressions
9296SageBuilder::buildLambdaExp(SgLambdaCaptureList* lambda_capture_list, SgClassDeclaration* lambda_closure_class, SgFunctionDeclaration* lambda_function)
9297 {
9298 SgLambdaExp *expr = new SgLambdaExp(lambda_capture_list,lambda_closure_class,lambda_function);
9299 ROSE_ASSERT(expr != NULL);
9300
9301 // Set the parents
9302 if (lambda_capture_list != NULL)
9303 {
9304 lambda_capture_list->set_parent(expr);
9305 }
9306
9307 if (lambda_closure_class != NULL)
9308 {
9309 lambda_closure_class->set_parent(expr);
9310 }
9311
9312 if (lambda_function != NULL)
9313 {
9314#if 1
9315 lambda_function->set_parent(expr);
9316#else
9317 if (lambda_closure_class != NULL)
9318 {
9319 lambda_function->set_parent(lambda_closure_class);
9320 }
9321 else
9322 {
9323 printf ("Warning: In SageBuilder::buildLambdaExp(): lambda_closure_class == NULL: lambda_function parent not set! \n");
9324 }
9325#endif
9326 }
9327
9328 setSourcePosition(expr);
9329 return expr;
9330 }
9331
9333SageBuilder::buildLambdaExp_nfi(SgLambdaCaptureList* lambda_capture_list, SgClassDeclaration* lambda_closure_class, SgFunctionDeclaration* lambda_function)
9334 {
9335 SgLambdaExp *expr = new SgLambdaExp(lambda_capture_list,lambda_closure_class,lambda_function);
9336 ROSE_ASSERT(expr != NULL);
9337
9338 // Set the parents
9339 if (lambda_capture_list != NULL)
9340 {
9341 lambda_capture_list->set_parent(expr);
9342 }
9343
9344 if (lambda_closure_class != NULL)
9345 {
9346 lambda_closure_class->set_parent(expr);
9347 }
9348
9349 if (lambda_function != NULL)
9350 {
9351#if 1
9352 lambda_function->set_parent(expr);
9353#else
9354#endif
9355 }
9356
9358 return expr;
9359 }
9360
9362SageBuilder::buildLambdaCapture(SgExpression* capture_variable, SgExpression* source_closure_variable, SgExpression* closure_variable)
9363 {
9364 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9365 ROSE_ASSERT(lambdaCapture != NULL);
9366
9367 setSourcePosition(lambdaCapture);
9368 return lambdaCapture;
9369 }
9370
9372SageBuilder::buildLambdaCapture_nfi(SgExpression* capture_variable, SgExpression* source_closure_variable, SgExpression* closure_variable)
9373 {
9374 SgLambdaCapture *lambdaCapture = new SgLambdaCapture(NULL,capture_variable,source_closure_variable,closure_variable);
9375 ROSE_ASSERT(lambdaCapture != NULL);
9376
9377 setOneSourcePositionNull(lambdaCapture);
9378 return lambdaCapture;
9379 }
9380
9383 {
9384 SgLambdaCaptureList *lambdaCaptureList = new SgLambdaCaptureList(NULL);
9385 ROSE_ASSERT(lambdaCaptureList != NULL);
9386
9387 setSourcePosition(lambdaCaptureList);
9388 return lambdaCaptureList;
9389 }
9390
9393 {
9394 SgLambdaCaptureList *lambdaCaptureList = new SgLambdaCaptureList(NULL);
9395 ROSE_ASSERT(lambdaCaptureList != NULL);
9396
9397 setOneSourcePositionNull(lambdaCaptureList);
9398 return lambdaCaptureList;
9399 }
9400
9401// DQ (7/25/2020): Adding C++17 support
9403SageBuilder::buildFoldExpression(SgExpression* operands, string operator_token_string, bool is_left_associative)
9404 {
9405 SgFoldExpression* result = new SgFoldExpression(NULL,operands,operator_token_string,is_left_associative);
9406 ROSE_ASSERT(result != NULL);
9407
9409 return result;
9410 }
9411
9413SageBuilder::buildFoldExpression_nfi(SgExpression* operands, string operator_token_string, bool is_left_associative)
9414 {
9415 SgFoldExpression* result = new SgFoldExpression(NULL,operands,operator_token_string,is_left_associative);
9416 ROSE_ASSERT(result != NULL);
9417
9419 return result;
9420 }
9421
9422// DQ (7/25/2020): Adding C++20 support
9425 {
9426 SgAwaitExpression* result = new SgAwaitExpression(NULL,NULL);
9427 ROSE_ASSERT(result != NULL);
9428
9430 return result;
9431 }
9434 {
9435 SgAwaitExpression* result = new SgAwaitExpression(NULL,NULL);
9436 ROSE_ASSERT(result != NULL);
9437
9439 return result;
9440 }
9441
9442// DQ (7/25/2020): Adding C++20 support
9445 {
9446 SgChooseExpression* result = new SgChooseExpression(NULL,NULL);
9447 ROSE_ASSERT(result != NULL);
9448
9450 return result;
9451 }
9452
9455 {
9456 SgChooseExpression* result = new SgChooseExpression(NULL,NULL);
9457 ROSE_ASSERT(result != NULL);
9458
9460 return result;
9461 }
9462
9463
9464
9467 {
9468 SgNamespaceDefinitionStatement* result = NULL;
9469 if (d!=NULL) // the constructor does not check for NULL d, causing segmentation fault
9470 {
9471 result = new SgNamespaceDefinitionStatement(d);
9472 result->set_parent(d); // set_declaration() == set_parent() in this case
9473 }
9474 else
9475 {
9476 result = new SgNamespaceDefinitionStatement(d);
9477 }
9478
9479 ROSE_ASSERT(result);
9480
9482 return result;
9483 }
9484
9487{
9488 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
9489 SageInterface::setSourcePosition(nonreal_decl_scope);
9490 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
9491 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
9492 return nonreal_decl_scope;
9493}
9494
9496SageBuilder::buildClassDefinition(SgClassDeclaration *d/*= NULL*/, bool buildTemplateInstantiation )
9497 {
9498 SgClassDefinition* result = NULL;
9499 if (d != NULL) // the constructor does not check for NULL d, causing segmentation fault
9500 {
9501 // result->set_parent(d); // set_declaration() == set_parent() in this case
9502 // result = new SgClassDefinition(d);
9503 ROSE_ASSERT(buildTemplateInstantiation == false || isSgTemplateInstantiationDecl(d) != NULL);
9504 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn(isSgTemplateInstantiationDecl(d)) : new SgClassDefinition(d);
9505 }
9506 else
9507 {
9508 // result = new SgClassDefinition();
9509 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn() : new SgClassDefinition();
9510 }
9511
9512 ROSE_ASSERT(result);
9513
9514 // CR (3/22/2020): Fixed setting case insensitivity
9515 // if (symbol_table_case_insensitive_semantics == true)
9517 {
9518 result->setCaseInsensitive(true);
9519 }
9520
9522
9523 return result;
9524 }
9525
9526
9527
9529SageBuilder::buildClassDefinition_nfi(SgClassDeclaration *d/*= NULL*/, bool buildTemplateInstantiation )
9530 {
9531 SgClassDefinition* result = NULL;
9532 if (d!=NULL) // the constructor does not check for NULL d, causing segmentation fault
9533 {
9534 // result->set_parent(d); // set_declaration() == set_parent() in this case
9535 // result = new SgClassDefinition(d);
9536 ROSE_ASSERT(buildTemplateInstantiation == false || isSgTemplateInstantiationDecl(d) != NULL);
9537 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn(isSgTemplateInstantiationDecl(d)) : new SgClassDefinition(d);
9538 }
9539 else
9540 {
9541 // result = new SgClassDefinition();
9542 result = (buildTemplateInstantiation == true) ? new SgTemplateInstantiationDefn() : new SgClassDefinition();
9543 }
9544
9545 ROSE_ASSERT(result);
9546
9547 // CR (3/22/2020): Fixed setting case insensitivity
9548 // if (symbol_table_case_insensitive_semantics == true)
9550 result->setCaseInsensitive(true);
9551
9553 return result;
9554 }
9555
9556
9558SageBuilder::buildNondefiningClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList)
9559 {
9560 SgName nameWithoutTemplateArguments = XXX_name;
9561
9562 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
9563
9564 // SgClassDeclaration* nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
9565 SgClassDeclaration* nondefdecl = NULL;
9566
9567#define DEBUG_NONDEFINING_CLASS_DECLARATION 0
9568
9569 // DQ (11/26/2011): Debugging EDG 3.3 use of templateArguments.
9570#if DEBUG_NONDEFINING_CLASS_DECLARATION
9571 printf ("Building a SgClassDeclaration: buildNondefiningClassDeclaration_nfi() nameWithoutTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithoutTemplateArguments.str(),buildTemplateInstantiation ? "true:" : "false");
9572 printf (" --- scope = %p = %s \n",scope,(scope != NULL) ? scope->class_name().c_str() : "null");
9573#endif
9574
9575 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
9576 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
9577 ROSE_ASSERT(SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == false);
9578
9579 if (buildTemplateInstantiation == true)
9580 {
9581 ROSE_ASSERT(templateArgumentsList != NULL);
9582 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
9583
9584#if DEBUG_NONDEFINING_CLASS_DECLARATION
9585 printf ("Building a SgClassDeclaration: buildNondefiningClassDeclaration_nfi() nameWithTemplateArguments = %s buildTemplateInstantiation = %s \n",nameWithTemplateArguments.str(),buildTemplateInstantiation ? "true:" : "false");
9586#endif
9587
9588 // SgTemplateInstantiationDecl (SgName name, SgClassDeclaration::class_types class_type, SgClassType *type, SgClassDefinition *definition, SgTemplateDeclaration *templateDeclaration, SgTemplateArgumentPtrList templateArguments)
9589 SgTemplateArgumentPtrList emptyList;
9590 // nondefdecl = new SgTemplateInstantiationDecl(name,kind,NULL,NULL,NULL,emptyList);
9591 nondefdecl = new SgTemplateInstantiationDecl(nameWithTemplateArguments,kind,NULL,NULL,NULL,emptyList);
9592#if DEBUG_NONDEFINING_CLASS_DECLARATION
9593 printf ("In buildNondefiningClassDeclaration_nfi(): built new SgTemplateInstantiationDecl: nondefdecl = %p \n",nondefdecl);
9594#endif
9595 ROSE_ASSERT(nondefdecl->get_type() == NULL);
9596 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl) != NULL);
9597#if DEBUG_NONDEFINING_CLASS_DECLARATION
9598 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_name() = %s nondefdecl->get_templateName() = %s \n",
9599 nondefdecl->get_name().str(),isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().str());
9600#endif
9601 // DQ (6/6/2012): Added support for template arguments so that they can be a part of any generated type.
9602 ROSE_ASSERT(templateArgumentsList != NULL);
9603
9604#if DEBUG_NONDEFINING_CLASS_DECLARATION
9605 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
9606 printf ("nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
9607 printf ("Output templateArgumentsList: \n");
9608 for (size_t i = 0; i < templateArgumentsList->size(); i++)
9609 {
9610 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
9611 printf (" --- --- name = %s \n",unparseTemplateArgumentToString(templateArgumentsList->operator[](i)).str());
9612 }
9613#endif
9614
9615 ROSE_ASSERT(nondefdecl->get_name() == nameWithTemplateArguments);
9616 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == true);
9617 isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(nameWithoutTemplateArguments);
9618 }
9619 else
9620 {
9621 nondefdecl = new SgClassDeclaration(nameWithoutTemplateArguments,kind,NULL,NULL);
9622#if DEBUG_NONDEFINING_CLASS_DECLARATION
9623 printf ("In buildNondefiningClassDeclaration_nfi(): built new SgClassDeclaration: nondefdecl = %p \n",nondefdecl);
9624#endif
9625 // The default name for nameWithTemplateArguments is nameWithoutTemplateArguments so that we can use
9626 // nameWithTemplateArguments uniformally as the name of the function and it will work from non-template
9627 // instantiations.
9628 ROSE_ASSERT(nameWithoutTemplateArguments == nameWithTemplateArguments);
9629 }
9630
9631 ROSE_ASSERT(nondefdecl != NULL);
9632 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
9633 ROSE_ASSERT(nondefdecl->get_type() == NULL);
9634
9635 // The non-defining declaration asociated with a declaration does not have a
9636 // source position...unless it is the position of the defining declaration.
9637 // setOneSourcePositionNull(nondefdecl);
9638 setSourcePosition(nondefdecl);
9639
9640 // This is find for now, but a little later in this function (if we can find a symbol)
9641 // we want to find the first non-defining declaration (using the symbol table) and use
9642 // that as a paramter to "nondefdecl->set_firstNondefiningDeclaration()".
9643 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
9644 nondefdecl->set_definingDeclaration(NULL);
9645 nondefdecl->setForward();
9646
9647 // This is the structural parent (the logical scope can be different than the parent).
9648 // TPS (09/18/2009) added a condition to be able to build this properly
9649 if (scope == NULL)
9650 nondefdecl->set_parent(topScopeStack());
9651 else
9652 nondefdecl->set_parent(scope);
9653
9654 // This is the logical scope...
9655 nondefdecl->set_scope(scope);
9656
9657 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
9658
9659 SgClassDeclaration* firstNondefdecl = NULL;
9660 if (scope != NULL)
9661 {
9662#if 0
9663#error "DEAD CODE"
9664#else
9665 SgClassSymbol* mysymbol = scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
9666
9667#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
9668 printf ("In SageBuilder::buildNondefiningClassDeclaration(): mysymbol = %p = %s \n",mysymbol,(mysymbol != NULL) ? mysymbol->class_name().c_str() : "null");
9669#endif
9670 if (mysymbol != NULL)
9671 {
9672 firstNondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
9673 ROSE_ASSERT(firstNondefdecl != NULL);
9674
9675 ROSE_ASSERT(firstNondefdecl->get_type() != NULL);
9676
9677 // 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).
9678 ROSE_ASSERT(nondefdecl->get_type() == NULL);
9679
9680 if (nondefdecl->get_type() == NULL)
9681 {
9682#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
9683 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);
9684#endif
9685 // Note: It would be better to just call: "nondefdecl->set_type(firstNondefdecl->get_type());"
9686#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
9687 printf ("NOTE: Call nondefdecl->set_type(firstNondefdecl->get_type()); instead of nondefdecl->set_type(SgClassType::createType(firstNondefdecl)); \n");
9688#endif
9689 nondefdecl->set_type(SgClassType::createType(firstNondefdecl));
9690 ROSE_ASSERT(nondefdecl->get_type() != NULL);
9691
9692#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
9693 printf ("In SageBuilder::buildNondefiningClassDeclaration(): nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
9694#endif
9695 ROSE_ASSERT(nondefdecl->get_type() == firstNondefdecl->get_type());
9696 }
9697
9698#if (REUSE_CLASS_DECLARATION_FROM_SYMBOL == 0)
9699 ROSE_ASSERT(nondefdecl != NULL);
9700 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
9701
9702 // DQ (5/18/2014): Added test to match that in set_firstNondefiningDeclaration().
9703 // This is a problem for the Boost code after the fix to detec templates vs. template instantiation declarations.
9704 if (nondefdecl->variantT() != firstNondefdecl->variantT())
9705 {
9706 printf ("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): nondefdecl = %p = %s IS NOT THE SAME AS firstNondefiningDeclaration = %p = %s \n",
9707 nondefdecl,nondefdecl->class_name().c_str(),firstNondefdecl,firstNondefdecl->class_name().c_str());
9708 ROSE_ASSERT(nondefdecl->get_file_info() != NULL);
9709 nondefdecl->get_file_info()->display("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): nondefdecl: debug");
9710 ROSE_ASSERT(firstNondefdecl->get_file_info() != NULL);
9711 firstNondefdecl->get_file_info()->display("ERROR: In SgDeclarationStatement::set_firstNondefiningDeclaration(): firstNondefdecl: debug");
9712 }
9713
9714 // DQ (5/18/2014): Added test to match that in set_firstNondefiningDeclaration().
9715 ROSE_ASSERT(nondefdecl->variantT() == firstNondefdecl->variantT());
9716
9717 nondefdecl->set_firstNondefiningDeclaration(firstNondefdecl);
9718
9719 // This might be NULL if the defining declaration has not been seen yet!
9720 nondefdecl->set_definingDeclaration(firstNondefdecl->get_definingDeclaration());
9721
9722 // DQ (3/22/2012): New assertions.
9723 ROSE_ASSERT(firstNondefdecl != NULL);
9724 ROSE_ASSERT(firstNondefdecl->get_type() != NULL);
9725
9726 // DQ (9/16/2012): This is a newly refactored function (call this after we know the firstNondefiningDeclaration is set correctly).
9727 // This is called in the other branch (mysymbol == NULL), but there is must be called before the symbol table is appended with
9728 // 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
9729 // both branches or once after both branches.
9730 if (buildTemplateInstantiation == true)
9731 {
9732 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
9733 }
9734
9735 // DQ (9/4/2012): We can now assert this because of how the type is constructed above.
9736 ROSE_ASSERT (nondefdecl->get_type() == firstNondefdecl->get_type());
9737
9738 // Share the type!
9739 if (nondefdecl->get_type() != firstNondefdecl->get_type())
9740 {
9741 // Remove the type from the new SgClassDeclaration and set the reference to the type in the firstNondefiningDeclaration.
9742 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());
9743 printf ("Skipping delete of %p so we can maintain unique type pointers \n",nondefdecl->get_type());
9744 // delete nondefdecl->get_type();
9745 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());
9746 nondefdecl->set_type(firstNondefdecl->get_type());
9747#if 1
9748 // DQ (12/13/2011): Is this executed!
9749 printf ("Unclear if this code is executed \n");
9750 ROSE_ABORT();
9751#endif
9752 }
9753#else
9754#error "DEAD CODE"
9755
9756 ROSE_ASSERT(nondefdecl == NULL);
9757#endif
9758 // This function should return a new nondefining declaration each time (to support multile class prototypes!).
9759 // nondefdecl = firstNondefdecl;
9760 }
9761 else
9762 {
9763#if REUSE_CLASS_DECLARATION_FROM_SYMBOL
9764 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
9765
9766#error "DEAD CODE"
9767
9768 nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
9769
9770#error "DEAD CODE"
9771
9772 ROSE_ASSERT(nondefdecl != NULL);
9773 if (nondefdecl->get_type() == NULL)
9774 nondefdel->set_type(SgClassType::createType(nondefdecl));
9775
9776 printf ("SageBuilder::buildNondefiningClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
9777
9778 setOneSourcePositionNull(nondefdecl);
9779
9780#error "DEAD CODE"
9781
9782 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
9783 nondefdecl->set_definingDeclaration(NULL);
9784 nondefdecl->setForward();
9785#endif
9786
9787 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
9788
9789 mysymbol = new SgClassSymbol(nondefdecl);
9790 firstNondefdecl = nondefdecl;
9791
9792 // DQ (6/9/2013): Adding assertions to make sure that symbols only reference non-defining declarations.
9793 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
9794 ROSE_ASSERT(mysymbol->get_declaration()->get_definition() == NULL);
9795
9796 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
9797 // Note that since the symbol tables use the template arguments associated with the declaration it is best to
9798 // fixup the template arguments before the symbol table is fixup to have a symbol for this declaration. So we
9799 // fixup the template arguments here (just after we know that the firstNondefiningDeclaration is set correctly
9800 // and just before the symbol is inserted into the symbol table.
9801 if (buildTemplateInstantiation == true)
9802 {
9803 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
9804 }
9805#if DEBUG_NONDEFINING_CLASS_DECLARATION
9806 printf ("BEFORE scope->insert_symbol(): scope = %p = %s nameWithTemplateArguments = %s mysymbol = %p = %s \n",
9807 scope,scope->class_name().c_str(),nameWithTemplateArguments.str(),mysymbol,mysymbol->class_name().c_str());
9808#endif
9809
9810 // scope->insert_symbol(name, mysymbol);
9811 scope->insert_symbol(nameWithTemplateArguments, mysymbol);
9812
9813 // 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).
9814 ROSE_ASSERT(nondefdecl->get_type() == NULL);
9815 if (nondefdecl->get_type() == NULL)
9816 {
9817 nondefdecl->set_type(SgClassType::createType(nondefdecl));
9818 }
9819
9820#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
9821 printf ("NOTE: In buildNondefiningClassDeclaration_nfi(): 2nd time this is a performance issue (maybe) to call the lookup_nontemplate_class_symbol() again \n");
9822#endif
9823 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would
9824 // not include name qualification on template arguments.
9825 // DQ (12/27/2011): Added new test.
9826 // ROSE_ASSERT(scope->lookup_nontemplate_class_symbol(name) != NULL);
9827 // TV (07/01/2013): this assertion fail when building basic class (buildTemplateInstantiation = false , templateArgumentsList = NULL)
9828 // ROSE_ASSERT(scope->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
9829
9830 // DQ (6/9/2013): Added test to make sure that symbols only reference non-defining declarations.
9831 SgClassSymbol* temp_classSymbol = nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
9832#if DEBUG_NONDEFINING_CLASS_DECLARATION
9833 // DQ (12/28/2018): When can this be NULL?
9834 printf ("In buildNondefiningClassDeclaration_nfi(): temp_classSymbol = %p \n",temp_classSymbol);
9835 printf ("In buildNondefiningClassDeclaration_nfi(): nondefdecl->get_scope() = %p = %s scope = %p \n",nondefdecl->get_scope(),nondefdecl->get_scope()->class_name().c_str(),scope);
9836
9837 printf ("In buildNondefiningClassDeclaration_nfi(): nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
9838 if (templateArgumentsList != NULL)
9839 {
9840 printf (" --- templateArgumentsList elements: \n");
9841 for (size_t i = 0; i < templateArgumentsList->size(); i++)
9842 {
9843 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
9844 printf (" --- --- templateArgumentsList->[%zu] = %s \n",i,templateArgumentsList->operator[](i)->class_name().c_str());
9845 templateArgumentsList->operator[](i)->display("In SageBuilder::buildNondefiningClassDeclaration_nfi()");
9846 }
9847 }
9848#endif
9849 // DQ (12/28/2018): When can this be NULL? When we call lookup_class_symbol() later it is NULL, so test it here.
9850 ROSE_ASSERT(nondefdecl->get_scope()->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
9851 ROSE_ASSERT(nondefdecl->get_scope() == scope);
9852
9853 // TV (07/01/2013): temp_classSymbol can be NULL, but lookup_class_symbol return a symbol
9854 // ROSE_ASSERT(temp_classSymbol->get_declaration()->get_definition() == NULL);
9855 ROSE_ASSERT(temp_classSymbol == NULL || temp_classSymbol->get_declaration()->get_definition() == NULL);
9856 }
9857
9858 ROSE_ASSERT(mysymbol != NULL);
9859 ROSE_ASSERT(firstNondefdecl != NULL);
9860#endif
9861 nondefdecl->set_scope(scope);
9862
9863 // 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).
9864 // TPS (09/18/2009) added a condition to be able to build this properly
9865 if (scope==NULL)
9866 nondefdecl->set_parent(topScopeStack());
9867 else
9868 nondefdecl->set_parent(scope);
9869 }
9870
9871 // The support for SgEnumDeclaration handles the type, but why not for SgClassDeclaration?
9872 ROSE_ASSERT(nondefdecl->get_type() != NULL);
9873
9874 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
9875
9876#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
9877 printf ("NOTE: In buildNondefiningClassDeclaration_nfi(): 3rd time this is a performance issue (maybe) to call the lookup_nontemplate_class_symbol() again \n");
9878#endif
9879
9880 // DQ (8/22/2012): Use the template arguments to further disambiguate names that would not include name qualification on template arguments.
9881 // DQ (12/27/2011): Added new test.
9882 // ROSE_ASSERT(nondefdecl->get_scope()->lookup_nontemplate_class_symbol(name) != NULL);
9883 // TV (07/01/2013): this assertion fail when building basic class (buildTemplateInstantiation = false , templateArgumentsList = NULL)
9884 // ROSE_ASSERT(nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList) != NULL);
9885
9886 // DQ (6/9/2013): Added test to make sure that symbols only reference non-defining declarations.
9887 SgClassSymbol* temp_classSymbol = nondefdecl->get_scope()->lookup_nontemplate_class_symbol(nameWithTemplateArguments,templateArgumentsList);
9888 // TV (07/01/2013): temp_classSymbol can be NULL, but lookup_class_symbol return a symbol
9889 ROSE_ASSERT(temp_classSymbol == NULL || temp_classSymbol->get_declaration()->get_definition() == NULL);
9890
9891 ROSE_ASSERT(nondefdecl != NULL);
9892 ROSE_ASSERT(nondefdecl->get_name() == nameWithTemplateArguments);
9893
9894 // DQ (3/9/2018): Test the consistancy of the template instantiation name.
9895 if (isSgTemplateInstantiationDecl(nondefdecl) != NULL)
9896 {
9897 SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(nondefdecl);
9898 SgName finalName = appendTemplateArgumentsToName(templateInstantiationDecl->get_templateName(),templateInstantiationDecl->get_templateArguments());
9899 ROSE_ASSERT(finalName == nameWithTemplateArguments);
9900 ROSE_ASSERT(finalName == nondefdecl->get_name());
9901 }
9902
9903#if DEBUG_NONDEFINING_CLASS_DECLARATION
9904 printf ("Leaving buildNondefiningClassDeclaration_nfi(): nondefdecl = %p nondefdecl->unparseNameToString() = %s \n",nondefdecl,nondefdecl->unparseNameToString().c_str());
9905 printf (" --- nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
9906#endif
9907
9908#if DEBUG_NONDEFINING_CLASS_DECLARATION
9909 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
9910 printf ("Leaving buildNondefiningClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
9911 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
9912
9913 printf ("test_symbol = %p \n",test_symbol);
9914
9915 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
9916 printf ("Leaving buildNondefiningClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
9917 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
9918#endif
9919
9920 return nondefdecl;
9921 }
9922
9925 ROSE_ASSERT(stmt != NULL);
9926
9928 stmt->set_parent(result);
9929
9930 result->set_definingDeclaration(result);
9932 return result;
9933}
9934
9937 ROSE_ASSERT(stmt != NULL);
9938
9940 stmt->set_parent(result);
9941
9942 result->set_definingDeclaration(result);
9944 return result;
9945}
9946
9948SageBuilder::buildJovialDefineDeclaration_nfi(const SgName& name, const std::string& params,
9949 const std::string& def_string, SgScopeStatement* scope)
9950 {
9951 std::string directive_string(name);
9952
9953 if (scope == NULL)
9955 ROSE_ASSERT(scope);
9956
9957 if (params.length() > 0)
9958 directive_string += " " + params;
9959
9960 directive_string += " " + def_string;
9961
9962 SgJovialDefineDeclaration* define_decl = new SgJovialDefineDeclaration(directive_string);
9963 ROSE_ASSERT(define_decl);
9965
9966 // The first nondefining declaration must be set
9967 define_decl->set_firstNondefiningDeclaration(define_decl);
9968 define_decl->set_parent(scope);
9969
9970 return define_decl;
9971 }
9972
9973// Build a Jovial loop statement. Two variants are FOR and WHILE.
9974// A loop body will be created and its parent set to the loop statement.
9977{
9978 SgJovialForThenStatement* forStmt{nullptr};
9979
9981
9982 forStmt = new SgJovialForThenStatement(nullptr, nullptr, nullptr, body);
9983 ASSERT_not_null(forStmt);
9984 setOneSourcePositionNull(forStmt);
9985
9986 body->set_parent(forStmt);
9987
9989 forStmt->setCaseInsensitive(true);
9990 }
9991
9992 return forStmt;
9993}
9994
9995// This should take a SgClassDeclaration::class_types kind parameter!
9997 {
9998 bool buildTemplateInstantiation = false;
9999 SgClassDeclaration* defdecl = buildClassDeclaration_nfi(name,SgClassDeclaration::e_struct,scope,NULL,buildTemplateInstantiation,NULL);
10000
10002 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
10004
10005 return defdecl;
10006 }
10007
10010 {
10012 SgDerivedTypeStatement* type_decl = buildClassDeclarationStatement_nfi <SgDerivedTypeStatement> (name, kind, scope);
10013
10015 ROSE_ASSERT(type_decl->get_firstNondefiningDeclaration() != NULL);
10017
10018 return type_decl;
10019 }
10020
10023 {
10025 SgModuleStatement* module_stmt = buildClassDeclarationStatement_nfi <SgModuleStatement> (name, kind, scope);
10026
10028 ROSE_ASSERT(module_stmt->get_firstNondefiningDeclaration() != NULL);
10030
10031 return module_stmt;
10032 }
10033
10037 SgScopeStatement* scope /*=NULL*/)
10038 {
10039 SgJovialTableStatement* table_decl = buildClassDeclarationStatement_nfi <SgJovialTableStatement> (name, kind, scope);
10040
10042 ROSE_ASSERT(table_decl->get_firstNondefiningDeclaration() != NULL);
10044
10045 return table_decl;
10046 }
10047
10050 {
10051 std::string type_name(name);
10052 if (base_type) {
10053 // Mangle the name to make sure the table type and the base type don't have the same name
10054 type_name = "_table_of_" + type_name;
10055 // Add dim_info address if there are subscripts to ensure type is unique
10056 if (dim_info->get_expressions().size() > 0) {
10057 std::ostringstream address;
10058 address << (void const *)dim_info;
10059 type_name += "_" + address.str();
10060 }
10061 }
10062
10064 SgJovialTableStatement* table_decl = buildClassDeclarationStatement_nfi <SgJovialTableStatement> (type_name, kind, scope);
10065
10067 ROSE_ASSERT(table_decl->get_firstNondefiningDeclaration() != NULL);
10069
10070 // For a type declaration the parent of the nondefining declaration is the defining declaration
10071 SgClassDeclaration* nondef_decl = isSgClassDeclaration(table_decl->get_firstNondefiningDeclaration());
10072 ROSE_ASSERT(nondef_decl != NULL);
10073 nondef_decl->set_parent(table_decl);
10074
10075 SgJovialTableType* table_type = isSgJovialTableType(table_decl->get_type());
10076 ROSE_ASSERT(table_type != NULL);
10077
10078 table_type->set_base_type(base_type);
10079 table_type->set_dim_info(dim_info);
10080 table_type->set_rank(dim_info->get_expressions().size());
10081
10082 dim_info->set_parent(table_type);
10083 nondef_decl->set_type(table_type);
10084
10085 return table_type;
10086 }
10087
10089template <class DeclClass> DeclClass *
10091 SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl)
10092 {
10093 // DQ (3/15/2012): Added function to build C++ class (builds both the non-defining and defining declarations; in that order).
10094 // The implementation of this function could be simplified to directly call both:
10095 // SgClassDeclaration* buildNondefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10096 // and
10097 // SgClassDeclaration* buildDefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10098 // This might refactor the implementation nicely.
10099
10100 if (scope == NULL)
10101 {
10103 }
10104
10105 // Step 1. Build the nondefining declaration (but only if the input nonDefiningDecl pointer was NULL and it does not exist)
10106 // -----------------------------------------
10107 //
10108
10109 // Get the nondefining declaration from the symbol if it has been built (if this works,
10110 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
10111
10112 SgClassDeclaration* nondefdecl = NULL;
10113 SgClassSymbol* mysymbol = NULL;
10114
10115 if (scope != NULL)
10116 {
10117 // DQ (10/10/2015): look up the correct type of symbol.
10118 mysymbol = scope->lookup_class_symbol(name);
10119
10120 if (mysymbol == NULL)
10121 {
10122 // Note: this is an input parameter (could/should go away?) [CR]
10123 if (nonDefiningDecl != NULL)
10124 {
10125 // DQ (3/4/2018): I think this is the correct API to use (internal use only).
10126 SgSymbol* temp_mysymbol = nonDefiningDecl->get_symbol_from_symbol_table();
10127 ROSE_ASSERT(temp_mysymbol != NULL);
10128
10129 mysymbol = isSgClassSymbol(temp_mysymbol);
10130 ROSE_ASSERT(mysymbol != NULL);
10131
10132 // check that the scopes are the same.
10133 ROSE_ASSERT(scope == nonDefiningDecl->get_scope());
10134 }
10135 }
10136 }
10137
10138 if (mysymbol != NULL) // set links for existing nondefining declaration
10139 {
10140 nondefdecl = (mysymbol->get_declaration() == NULL)
10141 ? NULL : dynamic_cast<DeclClass*>(mysymbol->get_declaration());
10142 ROSE_ASSERT(nondefdecl != NULL);
10143
10144 // DQ (6/8/2013): This should not be true (see test2013_198.C).
10145 // Fundamentally the symbol should always only have a pointer to a non-defining
10146 // declaration, where by definition (get_definition() == NULL).
10147 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
10148
10149 // DQ (9/16/2012): This should be true by definition (verify).
10150 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
10151
10152 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10153 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10154
10155 // DQ (9/7/2012): I think this might be the root of a problem in the haskell tests (ROSE compiling ROSE).
10156 if (nondefdecl->get_definingDeclaration() != NULL)
10157 {
10158 DeclClass* nondefining_classDeclaration = (nondefdecl == NULL) ? NULL : dynamic_cast<DeclClass*>(nondefdecl);
10159 ROSE_ASSERT(nondefining_classDeclaration != NULL);
10160 DeclClass* defining_classDeclaration = (nondefdecl->get_definingDeclaration() == NULL)
10161 ? NULL : dynamic_cast<DeclClass*>(nondefdecl->get_definingDeclaration());
10162 ROSE_ASSERT(defining_classDeclaration != NULL);
10163
10164 return defining_classDeclaration;
10165 }
10166 }
10167 else // build a nondefining declaration since it does not exist
10168 {
10169 ROSE_ASSERT(nondefdecl == NULL);
10170
10171 // DeclClass is the template type parameter
10172 nondefdecl = new DeclClass(name, kind, NULL, NULL);
10173 ROSE_ASSERT(nondefdecl != NULL);
10174
10175 // The first nondefining declaration has to be set before we generate the type.
10176 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10177
10178 // 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.
10179 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
10180
10181 // DQ (3/14/2012): For C++ we need the scope set so that types will have proper locations to resolve them
10182 // from being ambiguous or not properly defined. Basically, we need a handle from which to generate something
10183 // that amounts to a kind of name qualification internally (maybe even exactly name qualification, but I would
10184 // have to think about that a bit more).
10185 ROSE_ASSERT(scope != NULL);
10186
10187 // Set the parent before calling the SgClassType::createType() as the name mangling will require it.
10188 // This is true for Fortran SgDerivedTypeStatement at least.
10189 nondefdecl->set_parent(scope);
10190 nondefdecl->set_scope(scope);
10191
10192 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
10193 ROSE_ASSERT(nondefdecl->get_type() == NULL);
10194
10195 if (nondefdecl->get_type() == NULL)
10196 {
10197 SgClassType* class_type = NULL;
10198 switch (kind)
10199 {
10201 class_type = SgJavaParameterType::createType(nondefdecl);
10202 break;
10205 class_type = SgJovialTableType::createType(nondefdecl);
10206 break;
10207 default:
10208 class_type = SgClassType::createType(nondefdecl);
10209 break;
10210 }
10211 ROSE_ASSERT(class_type != NULL);
10212
10213 nondefdecl->set_type(class_type);
10214
10215 SgClassDeclaration* tmp_classDeclarationFromType = isSgClassDeclaration(class_type->get_declaration());
10216 ROSE_ASSERT(tmp_classDeclarationFromType != NULL);
10217 }
10218
10219 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10220 if (nondefdecl->get_type()->get_declaration() != nondefdecl)
10221 {
10222 printf ("ERROR: nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
10223 printf ("ERROR: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
10224 printf ("ERROR: nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
10225
10226 SgClassDeclaration* classDeclarationFromType = isSgClassDeclaration(nondefdecl->get_type()->get_declaration());
10227 ROSE_ASSERT(classDeclarationFromType != NULL);
10228
10229 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
10230 printf ("nondefdecl->get_type()->get_name() = %s \n",nondefdecl->get_type()->get_name().str());
10231 printf ("nondefdecl->get_type()->get_declaration()->get_name() = %s \n",classDeclarationFromType->get_name().str());
10232
10233 printf ("nondefdecl->get_mangled_name() = %s \n",nondefdecl->get_mangled_name().getString().c_str());
10234 printf ("nondefdecl->get_type()->get_mangled() = %s \n",nondefdecl->get_type()->get_mangled().getString().c_str());
10235 printf ("nondefdecl->get_type()->get_declaration()->get_mangled_name() = %s \n",classDeclarationFromType->get_mangled_name().getString().c_str());
10236
10237 // DQ (12/27/2018): Added additional debugging support.
10238 printf ("nondefdecl->get_type()->get_declaration()->get_firstNondefiningDeclaration() = %s \n",classDeclarationFromType->get_firstNondefiningDeclaration() ? "true" : "false");
10239 printf ("nondefdecl->get_firstNondefiningDeclaration() = %s \n",nondefdecl->get_firstNondefiningDeclaration() ? "true" : "false");
10240
10241 // 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.
10242 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10243 if (nondefdecl->get_parent() != NULL)
10244 {
10245 printf ("nondefdecl->get_parent() = %p = %s \n",nondefdecl->get_parent(),nondefdecl->get_parent()->class_name().c_str());
10246 }
10247 }
10248 ROSE_ASSERT(nondefdecl->get_type()->get_declaration() == nondefdecl);
10249
10250 // The nondefining declaration will not appear in the source code, but is compiler
10251 // generated (so we have something about the class that we can reference; e.g in
10252 // types). At the moment we make it a transformation, there might be another kind
10253 // of source position that would be more precise. FIXME.
10254 // setOneSourcePositionNull(nondefdecl);
10256 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
10257
10258#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
10259 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
10260 if (SourcePositionClassificationMode != e_sourcePositionTransformation)
10261 {
10262 detectTransformations(nondefdecl);
10263 }
10264#endif
10265
10266 nondefdecl->setForward();
10267
10268 if (scope != NULL)
10269 {
10270 mysymbol = new SgClassSymbol(nondefdecl);
10271 scope->insert_symbol(name, mysymbol);
10272
10273 ROSE_ASSERT(nondefdecl->get_scope() == scope);
10274 }
10275 }
10276
10277 // DQ (3/15/2012): I have moved construction of defining declaration to be AFTER the nondefining declaration!
10278 // This is a better organization ans also should make sure that the declaration in the SgClassType will
10279 // properly reference the firstNondefiningDeclaration (instead of the defining declaration).
10280
10281 // Step 2. Build the defining declaration
10282 // --------------------------------------
10283 //
10285
10286 DeclClass* defdecl = new DeclClass(name,kind,NULL,classDef);
10287 ROSE_ASSERT(defdecl != NULL);
10288 ROSE_ASSERT(defdecl->get_type() == NULL);
10289
10290 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
10291 ROSE_ASSERT(defdecl->get_definition() != NULL);
10292 ROSE_ASSERT(defdecl != NULL);
10293
10294 // DQ (3/15/2012): Moved from original location above...
10295 nondefdecl->set_definingDeclaration(defdecl);
10296
10297 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
10298 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
10299
10301 // constructor is side-effect free
10302 classDef->set_declaration(defdecl);
10303 defdecl->set_definingDeclaration(defdecl);
10304
10305 defdecl->set_firstNondefiningDeclaration(nondefdecl);
10306
10307 // DQ (3/22/2012): I think we can assert this.
10308 ROSE_ASSERT(defdecl->get_type() == NULL);
10309
10310 // Liao, 10/30/2009
10311 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
10312 // This is not desired when building a defining declaration and an inefficience in the constructor
10313 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
10314 // the defining class declaration (and other nondefining declaration) just share that SgClassType.
10315 if (defdecl->get_type() != NULL)
10316 {
10317 // Removed several lines of dead code because of the assertion just above
10318 }
10319 else
10320 {
10321 // DQ (3/15/2012): Make sure that both the defining and non-defining declarations use the same type.
10322 ROSE_ASSERT (nondefdecl->get_type() != NULL);
10323 defdecl->set_type(nondefdecl->get_type());
10324
10325 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
10326 }
10327
10328 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10329
10330 // patch up the SgClassType for the defining class declaration
10331 ROSE_ASSERT (nondefdecl->get_type() != NULL);
10332 ROSE_ASSERT (defdecl->get_type() != NULL);
10333 ROSE_ASSERT (defdecl->get_type()->get_declaration() != NULL);
10334 ROSE_ASSERT (defdecl->get_type()->get_declaration() != isSgDeclarationStatement(defdecl));
10335 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
10336 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
10337
10338 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10339
10340 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
10341 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
10342 // used in a defining declaration).
10343 nondefdecl->setForward();
10344
10345 if (scope != NULL) // put into fixStructDeclaration() or alike later on
10346 {
10347 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10348
10349 // Note, this function sets the parent to be the scope if it is not already set.
10350 fixStructDeclaration(defdecl,scope);
10351
10352 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10353
10354 fixStructDeclaration(nondefdecl,scope);
10355
10356 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
10357 }
10358
10359 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
10360 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
10361 // ROSE_ASSERT(defdecl->get_parent() != NULL);
10362
10363 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
10364
10365 // DQ (2/27/2012): Tracking down where parents are not set correctly (class declaration in typedef is incorrectly set to SgGlobal).
10366 ROSE_ASSERT(defdecl->get_parent() == NULL);
10367
10368 // DQ (2/29/2012): We can't assert this (fails for test2012_09.C).
10369 // ROSE_ASSERT(nondefdecl->get_parent() == NULL);
10370
10371 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
10372 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
10373
10374 // DQ (3/8/2018): Added for debugging.
10375 SgClassDeclaration* temp_firstNondefiningDeclaration = isSgClassDeclaration(defdecl->get_firstNondefiningDeclaration());
10376 SgClassDeclaration* temp_definingDeclaration = isSgClassDeclaration(defdecl->get_definingDeclaration());
10377 ROSE_ASSERT(temp_firstNondefiningDeclaration != NULL);
10378 ROSE_ASSERT(temp_definingDeclaration != NULL);
10379 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_name() == temp_definingDeclaration->get_name());
10380 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_type() == temp_definingDeclaration->get_type());
10381
10382 return defdecl;
10383 }
10384
10387 {
10388 SgNamespaceAliasDeclarationStatement* aliasdecl = new SgNamespaceAliasDeclarationStatement(name,namespaceDeclaration);
10391 return aliasdecl;
10392 }
10393
10396 {
10398
10400 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
10402
10403 return defdecl;
10404 }
10405
10407SageBuilder::buildNamespaceDeclaration_nfi(const SgName& name, bool unnamednamespace, SgScopeStatement* scope)
10408 {
10409 if (scope == NULL)
10411
10412 ROSE_ASSERT(scope != NULL);
10413
10414 // TODO How about class type??
10415 // build defining declaration
10417
10418 SgNamespaceDeclarationStatement* defdecl = new SgNamespaceDeclarationStatement(name,namespaceDef,unnamednamespace);
10419 ROSE_ASSERT(defdecl != NULL);
10420 namespaceDef->set_parent(defdecl);
10421 setOneSourcePositionNull(defdecl);
10422
10423 // constructor is side-effect free
10424 namespaceDef->set_namespaceDeclaration(defdecl);
10425 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
10426
10427 // Get the nondefining declaration from the symbol if it has been built (if this works,
10428 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
10429 SgNamespaceDeclarationStatement* nondefdecl = NULL;
10430 SgNamespaceSymbol* mysymbol = NULL;
10431 if (scope != NULL)
10432 {
10433 mysymbol = scope->lookup_namespace_symbol(name);
10434 }
10435 else
10436 {
10437 // DQ (1/26/2009): I think this should be an error, but that appears it would
10438 // break the existing interface. Need to discuss this with Liao.
10439 printf ("Warning: In SageBuilder::buildNamespaceDeclaration_nfi(): scope == NULL \n");
10440 }
10441
10442 if (mysymbol != NULL)
10443 {
10444 SgNamespaceDeclarationStatement* namespaceDeclaration = mysymbol->get_declaration();
10445 ROSE_ASSERT(namespaceDeclaration != NULL);
10446 nondefdecl = isSgNamespaceDeclarationStatement(namespaceDeclaration);
10447
10448 ROSE_ASSERT(nondefdecl != NULL);
10449 ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10450 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == NULL);
10451 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
10452
10453 // DQ (5/16/2013): Set the global definition for the new namespace definition.
10454 ROSE_ASSERT(namespaceDeclaration->get_definition() != NULL);
10455 if (namespaceDeclaration->get_definition()->get_global_definition() == NULL)
10456 {
10457 printf ("ERROR: namespaceDeclaration->get_definition()->get_global_definition() == NULL: namespaceDeclaration = %p = %s namespaceDeclaration->get_definition() = %p \n",
10458 namespaceDeclaration,namespaceDeclaration->get_name().str(),namespaceDeclaration->get_definition());
10459 }
10460 ROSE_ASSERT(namespaceDeclaration->get_definition()->get_global_definition() != NULL);
10461 namespaceDef->set_global_definition(namespaceDeclaration->get_definition()->get_global_definition());
10462 ROSE_ASSERT(namespaceDef->get_global_definition() != NULL);
10463
10464 // DQ (5/19/2013): Make the global_definition point to itself.
10465 ROSE_ASSERT(namespaceDef->get_global_definition() == namespaceDef->get_global_definition()->get_global_definition());
10466
10467 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
10468
10469 ROSE_ASSERT(nondefdecl->get_definition()->get_previousNamespaceDefinition() == NULL);
10470 // ROSE_ASSERT(nondefdecl->get_definition()->get_nextNamespaceDefinition() == NULL);
10471
10472 SgNamespaceDefinitionStatement* i = namespaceDeclaration->get_definition();
10473 ROSE_ASSERT(i != NULL);
10474 while (i != NULL && i->get_nextNamespaceDefinition() != NULL)
10475 {
10476 i = i->get_nextNamespaceDefinition();
10477 ROSE_ASSERT(i->get_previousNamespaceDefinition() != NULL);
10478 }
10479
10480 ROSE_ASSERT(i != NULL);
10481 i->set_nextNamespaceDefinition(namespaceDef);
10482 namespaceDef->set_previousNamespaceDefinition(i);
10483 }
10484 else
10485 {
10486 // DQ (5/16/2013): Note that since we don't build a SgNamespaceDefinition for the declaration we can't
10487 // build the global_definition. This is a potential problem.
10488
10489 nondefdecl = defdecl;
10490 ROSE_ASSERT(nondefdecl != NULL);
10491 namespaceDef = nondefdecl->get_definition();
10492 ROSE_ASSERT(namespaceDef->get_namespaceDeclaration() != NULL);
10493
10494 // DQ (5/16/2013): Now add the global definition where we will accumulate all of the symbols for the logical namespace.
10495 SgNamespaceDefinitionStatement* global_definition_namespaceDef = buildNamespaceDefinition();
10496 namespaceDef->set_global_definition(global_definition_namespaceDef);
10497 ROSE_ASSERT(namespaceDef->get_global_definition() != NULL);
10498
10499 // DQ (5/19/2013): Make the global_definition point to itself.
10500 global_definition_namespaceDef->set_global_definition(global_definition_namespaceDef);
10501
10502 global_definition_namespaceDef->set_isUnionOfReentrantNamespaceDefinitions(true);
10503
10504 // DQ (8/23/2013): Set the parent of the global_definition_namespaceDef.
10505 ROSE_ASSERT(global_definition_namespaceDef->get_parent() == NULL);
10506 global_definition_namespaceDef->set_parent(defdecl);
10507 ROSE_ASSERT(global_definition_namespaceDef->get_parent() != NULL);
10508
10509 // DQ (5/16/2013): Added tests and setting of the associated declaration.
10510 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() == NULL);
10511 global_definition_namespaceDef->set_namespaceDeclaration(nondefdecl);
10512 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() != NULL);
10513
10514 // DQ (5/16/2013): Set the associated declaration to be the nondefdecl.
10515 global_definition_namespaceDef->set_namespaceDeclaration(nondefdecl);
10516 ROSE_ASSERT(global_definition_namespaceDef->get_namespaceDeclaration() != NULL);
10517
10518 if (defdecl->get_definition()->get_global_definition() == NULL)
10519 {
10520 defdecl->get_definition()->set_global_definition(global_definition_namespaceDef);
10521 }
10522
10523 // DQ (5/19/2013): Make the global_definition point to itself.
10524 ROSE_ASSERT(global_definition_namespaceDef == global_definition_namespaceDef->get_global_definition());
10525 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
10526 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() == namespaceDef->get_global_definition());
10527 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10528
10529 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == NULL);
10530 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
10531
10532 nondefdecl->setForward();
10533 nondefdecl->set_parent(scope);
10534 ROSE_ASSERT(nondefdecl->get_parent());
10535
10536 if (scope != NULL)
10537 {
10538 mysymbol = new SgNamespaceSymbol(name,nondefdecl); // tps: added name to constructor
10539 scope->insert_symbol(name, mysymbol);
10540 }
10541 else
10542 {
10543 // DQ (1/26/2009): I think this should be an error, but that appears it would
10544 // break the existing interface. Need to discuss this with Liao.
10545 printf ("Warning: no scope provided to support symbol table entry! \n");
10546 }
10547
10548 ROSE_ASSERT(defdecl->get_definition() != NULL);
10549 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
10550
10551 ROSE_ASSERT(nondefdecl->get_definition()->get_previousNamespaceDefinition() == NULL);
10552 ROSE_ASSERT(nondefdecl->get_definition()->get_nextNamespaceDefinition() == NULL);
10553 }
10554
10555 ROSE_ASSERT(nondefdecl != NULL);
10556 defdecl->set_firstNondefiningDeclaration(nondefdecl);
10557
10558 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
10559 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
10560 // used in a defining declaration).
10561 nondefdecl->setForward();
10562
10563 if (scope != NULL) // put into fixStructDeclaration() or alike later on
10564 {
10565 fixNamespaceDeclaration(nondefdecl,scope);
10566 fixNamespaceDeclaration(defdecl,scope);
10567 }
10568
10569 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
10570
10571 // DQ (3/6/2012): For namespaces the definingDeclaration should be NULL.
10572 ROSE_ASSERT(defdecl->get_definingDeclaration() == NULL);
10573 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
10574 ROSE_ASSERT(defdecl->get_definition() != NULL);
10575 ROSE_ASSERT(defdecl->get_definition()->get_global_definition() != NULL);
10576
10577 return defdecl;
10578 }
10579
10580// driscoll6 (7/20/11) : Support n-ary operators for python
10583 SgNaryComparisonOp* result = new SgNaryComparisonOp();
10584
10585 result->get_operands().push_back(lhs);
10586 lhs->set_parent(result);
10587
10589 return result;
10590}
10591
10594 SgNaryComparisonOp* result = new SgNaryComparisonOp();
10595
10596 result->get_operands().push_back(lhs);
10597 lhs->set_parent(result);
10598
10600 return result;
10601}
10602
10605 SgNaryBooleanOp* result = new SgNaryBooleanOp();
10606
10607 result->get_operands().push_back(lhs);
10608 lhs->set_parent(result);
10609
10611 return result;
10612}
10613
10616 SgNaryBooleanOp* result = new SgNaryBooleanOp();
10617
10618 result->get_operands().push_back(lhs);
10619 lhs->set_parent(result);
10620
10622 return result;
10623}
10624
10627 ROSE_ASSERT(exp);
10628 SgStringConversion* result = new SgStringConversion(exp);
10629 exp->set_parent(result);
10630
10632 return result;
10633}
10634
10635
10638 ROSE_ASSERT(exp);
10639 SgStringConversion* result = new SgStringConversion(exp);
10640 exp->set_parent(result);
10641
10643 return result;
10644}
10645
10646// DQ (11/7/2009): Added more uniform support for building class declarations.
10649 {
10650 SgClassDeclaration* defdecl = NULL;
10651 SgClassDeclaration* nondefdecl = NULL;
10652
10653 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
10654 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
10655 ROSE_ASSERT(SageInterface::hasTemplateSyntax(name) == false);
10656
10657#if 1
10658 printf ("In buildNondefiningClassDeclaration(): name = %s scope = %p = %s \n",name.str(),scope,scope != NULL ? scope->class_name().c_str() : "NULL");
10659
10660 // DQ (8/12/2013): If this function were to be called then we would have to
10661 // support a template argument list for the call to lookup_class_symbol().
10662
10663 // DQ (6/9/2013): I want to know that I'm not debugging this function.
10664 ROSE_ABORT();
10665#endif
10666
10667 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
10668 // ROSE_ASSERT(scope != NULL);
10669 SgClassSymbol* mysymbol = NULL;
10670 if (scope != NULL)
10671 {
10672 // mysymbol = scope->lookup_class_symbol(name);
10673 mysymbol = scope->lookup_class_symbol(name,NULL);
10674 }
10675 else
10676 {
10677 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unkown.
10678 // DQ (1/26/2009): I think this should be an error, but that appears it would
10679 // break the existing interface. Need to discuss this with Liao.
10680 // printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): scope == NULL \n");
10681 }
10682
10683#if 0
10684 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
10685#endif
10686
10687 if (mysymbol != NULL) // set links if nondefining declaration already exists.
10688 {
10689 nondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
10690
10691 ROSE_ASSERT(nondefdecl != NULL);
10692 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10693
10694 nondefdecl->set_definingDeclaration(defdecl);
10695
10696 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
10697 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
10698
10699 // DQ (10/30/2010): There should be a properly defined type at this point!
10700 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10701
10702 // DQ (7/31/2019): Check that this is true.
10703 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10704 }
10705 else // build a nondefnining declaration if it does not exist
10706 {
10707 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
10708
10710 nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
10711 ROSE_ASSERT(nondefdecl != NULL);
10712 if (nondefdecl->get_type() == NULL)
10713 {
10714 nondefdecl->set_type(SgClassType::createType(nondefdecl));
10715#if 0
10716 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());
10717#endif
10718 }
10719
10720 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
10721
10722 // The nondefining declaration will not appear in the source code, but is compiler
10723 // generated (so we have something about the class that we can reference; e.g in
10724 // types). At the moment we make it a transformation, there might be another kind
10725 // of source position that would be more precise. FIXME.
10726 // setOneSourcePositionNull(nondefdecl);
10728
10729 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
10730 nondefdecl->set_definingDeclaration(defdecl);
10731 nondefdecl->setForward();
10732 // Liao, 9/2/2009. scope stack is optional, it can be empty
10733 // nondefdecl->set_parent(topScopeStack());
10734 // nondefdecl->set_parent(scope);
10735
10736 // DQ (7/31/2019): Check that this is true.
10737 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
10738
10739 // DQ (3/24/2011): This should be NULL before we set it (if the scope is known).
10740 ROSE_ASSERT(nondefdecl->get_scope() == NULL);
10741 if (scope != NULL)
10742 {
10743 // 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.
10744 nondefdecl->set_scope(scope);
10745 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
10746
10747 mysymbol = new SgClassSymbol(nondefdecl);
10748#if 0
10749 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());
10750#endif
10751 scope->insert_symbol(name, mysymbol);
10752 }
10753 else
10754 {
10755 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknown.
10756 // DQ (1/26/2009): I think this should be an error, but that appears it would
10757 // break the existing interface. Need to discuss this with Liao.
10758 // printf ("Warning: no scope provided to support symbol table entry! \n");
10759 }
10760
10761 // DQ (10/30/2010): There should be a properly defined type at this point!
10762 ROSE_ASSERT(nondefdecl->get_type() != NULL);
10763
10764 // DQ (3/24/2011): The scope should be set if the scope was available.
10765 ROSE_ASSERT(scope == NULL || (scope != NULL && nondefdecl->get_scope() != NULL));
10766 }
10767
10768 ROSE_ASSERT(nondefdecl != NULL);
10769
10770 return nondefdecl;
10771 }
10772
10773// DQ (11/7/2009): Added more uniform support for building class declarations.
10776 {
10777 // Note that the semantics of this function now differs from that of the buildDefiningFunctionDeclaration().
10778 // We want to have the non-defining declaration already exist before calling this function.
10779 // We could still build a higher level function that built both together. Or we could provide two versions
10780 // named differently (from this one) and deprecate this function...which I like much better.
10781 printf ("WARNING: This function for building defining class declarations has different semantics from that of the function to build defining function declarations. \n");
10782
10783#if 1
10784 printf ("In buildDefiningClassDeclaration(): name = %s scope = %p = %s \n",name.str(),scope,scope != NULL ? scope->class_name().c_str() : "NULL");
10785
10786 // DQ (6/9/2013): I want to know that I'm not debugging this function.
10787 ROSE_ABORT();
10788#endif
10789
10790 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
10791 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
10792 ROSE_ASSERT(SageInterface::hasTemplateSyntax(name) == false);
10793
10794 SgClassDeclaration* nondefiningClassDeclaration = buildNondefiningClassDeclaration(name,scope);
10795 ROSE_ASSERT(nondefiningClassDeclaration != NULL);
10796
10797 SgClassDefinition* definingClassDefinition = buildClassDefinition();
10798 ROSE_ASSERT(definingClassDefinition != NULL);
10799
10800 // DQ (10/30/2010): There should be a properly defined type at this point!
10801 SgClassType* classType = nondefiningClassDeclaration->get_type();
10802 ROSE_ASSERT(classType != NULL);
10803
10805
10806 // DQ (10/30/2010): We need to make sure that there is a type defined.
10807 // SgClassDeclaration* definingClassDeclaration = new SgClassDeclaration (name,kind,NULL,definingClassDefinition);
10808 SgClassDeclaration* definingClassDeclaration = new SgClassDeclaration (name,kind,classType,definingClassDefinition);
10809 ROSE_ASSERT(definingClassDeclaration != NULL);
10810
10811 // printf ("SageBuilder::buildDefiningClassDeclaration(): definingClassDeclaration = %p \n",definingClassDeclaration);
10812
10813 setOneSourcePositionForTransformation(definingClassDeclaration);
10814
10815 // constructor is side-effect free
10816 definingClassDefinition->set_declaration(definingClassDeclaration);
10817 definingClassDeclaration->set_definingDeclaration(definingClassDeclaration);
10818 definingClassDeclaration->set_firstNondefiningDeclaration(nondefiningClassDeclaration);
10819
10820 nondefiningClassDeclaration->set_definingDeclaration(definingClassDeclaration);
10821
10822 // some error checking
10823 ROSE_ASSERT(nondefiningClassDeclaration->get_definingDeclaration() != NULL);
10824 ROSE_ASSERT(nondefiningClassDeclaration->get_firstNondefiningDeclaration() != NULL);
10825 ROSE_ASSERT(definingClassDeclaration->get_firstNondefiningDeclaration() != NULL);
10826 ROSE_ASSERT(definingClassDeclaration->get_definition() != NULL);
10827
10828 ROSE_ASSERT(definingClassDeclaration->get_scope() == NULL);
10829 if (scope != NULL)
10830 {
10831 definingClassDeclaration->set_scope(scope);
10832 ROSE_ASSERT(definingClassDeclaration->get_scope() != NULL);
10833 ROSE_ASSERT(nondefiningClassDeclaration->get_scope() != NULL);
10834 }
10835
10836 ROSE_ASSERT(definingClassDeclaration->get_definition()->get_parent() != NULL);
10837
10838 // DQ (10/30/2010): There should be a properly defined type at this point!
10839 ROSE_ASSERT(definingClassDeclaration->get_type() != NULL);
10840
10841 return definingClassDeclaration;
10842 }
10843
10844// DQ (11/7/2009): Added more uniform support for building class declarations.
10847 {
10848 ROSE_ASSERT(scope != NULL);
10849 SgClassDeclaration* definingClassDeclaration = buildDefiningClassDeclaration(name,scope);
10850 ROSE_ASSERT(definingClassDeclaration != NULL);
10851
10852 return definingClassDeclaration;
10853 }
10854
10855
10856// 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).
10857// DQ (1/24/2009): Built this "nfi" version but factored the code.
10858// SgClassDeclaration* SageBuilder::buildClassDeclaration_nfi(const SgName& name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl , bool buildTemplateInstantiation )
10860SageBuilder::buildClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgClassDeclaration* nonDefiningDecl , bool buildTemplateInstantiation, SgTemplateArgumentPtrList* templateArgumentsList )
10861 {
10862 // DQ (3/15/2012): Added function to build C++ class (builds both the non-defining and defining declarations; in that order).
10863 // The implementation of this function could be simplified to directly call both:
10864 // SgClassDeclaration* buildNondefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10865 // and
10866 // SgClassDeclaration* buildDefiningClassDeclaration ( SgName name, SgScopeStatement* scope );
10867 // This might refactor the implementation nicely.
10868
10869#define DEBUG_CLASS_DECLARATION 0
10870
10871 // Note that the nonDefiningDecl pointer does not appear to be used.
10872#if 0
10873 printf ("WARNING: In SageBuilder::buildClassDeclaration_nfi(): the nonDefiningDecl pointer = %p (input parameter) does not appear to be used. \n",nonDefiningDecl);
10874#endif
10875
10876#if 0
10877 // DQ (3/4/2018): Adding testing.
10878 // ROSE_ASSERT(nonDefiningDecl != NULL);
10879 if (nonDefiningDecl != NULL)
10880 {
10881 ROSE_ASSERT(nonDefiningDecl->get_type() != NULL);
10882 ROSE_ASSERT(nonDefiningDecl->get_type()->get_declaration() != NULL);
10883 printf ("nonDefiningDecl->get_type() = %p = %s \n",nonDefiningDecl->get_type(),nonDefiningDecl->get_type()->class_name().c_str());
10884 printf ("nonDefiningDecl->get_type()->get_declaration() = %p = %s \n",nonDefiningDecl->get_type()->get_declaration(),nonDefiningDecl->get_type()->get_declaration()->class_name().c_str());
10885#if 0
10886 printf ("In buildClassDeclaration_nfi(): nonDefiningDecl: unparseNameToString() = %s \n",nonDefiningDecl->unparseNameToString().c_str());
10887#endif
10888
10889 }
10890#endif
10891
10892
10893 // DQ (10/10/2015): I think we can assert this! NO we can't (see test2015_87.C).
10894 // ROSE_ASSERT(nonDefiningDecl != NULL);
10895
10896 // DQ (10/10/2015): OK, now we have a valid use on the input non-defining declaration.
10897 bool buildTemplateDeclaration = (isSgTemplateClassDeclaration(nonDefiningDecl) != NULL);
10898
10899 // DQ (10/10/2015): If this is true, then we should have called a different function to build the associated SgTemplateClassDeclaration.
10900 if (buildTemplateDeclaration == true)
10901 {
10902 // Error checking.
10903 printf ("ERROR: If buildTemplateDeclaration == true, then we should have called a different function to build the associated SgTemplateClassDeclaration \n");
10904 }
10905 ROSE_ASSERT(buildTemplateDeclaration == false);
10906
10907#if 0
10908 printf ("In SageBuilder::buildClassDeclaration_nfi(): XXX_name = %s \n",XXX_name.str());
10909 printf ("In SageBuilder::buildClassDeclaration_nfi(): the nonDefiningDecl pointer = %p = %s \n",nonDefiningDecl,nonDefiningDecl != NULL ? nonDefiningDecl->class_name().c_str() : "null");
10910 printf ("In SageBuilder::buildClassDeclaration_nfi(): buildTemplateDeclaration = %s \n",buildTemplateDeclaration ? "true" : "false");
10911 printf (" --- templateArgumentsList = %p \n",templateArgumentsList);
10912 if (templateArgumentsList != NULL)
10913 {
10914 printf (" --- templateArgumentsList.size() = %zu \n",templateArgumentsList->size());
10915 for (size_t i = 0; i < templateArgumentsList->size(); i++)
10916 {
10917 printf (" --- --- argument pointer: templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
10918 }
10919 }
10920#endif
10921
10922 if (scope == NULL)
10923 {
10925#if 0
10926 printf ("In SageBuilder::buildClassDeclaration_nfi(): no scope was provided so using the SageBuilder::topScopeStack() = %p = %s \n",scope,scope->class_name().c_str());
10927#endif
10928 }
10929 else
10930 {
10931#if 0
10932 printf ("In SageBuilder::buildClassDeclaration_nfi(): scope was provided scope = %p = %s \n",scope,scope->class_name().c_str());
10933#endif
10934 }
10935
10936#if 0
10937 printf ("Building a SgClassDeclaration: buildClassDeclaration_nfi() XXX_name = %s buildTemplateInstantiation = %s \n",XXX_name.str(),buildTemplateInstantiation ? "true" : "false");
10938#endif
10939
10940 // Step 2 (now step 1). build the nondefining declaration,
10941 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
10942
10943 // Get the nondefining declaration from the symbol if it has been built (if this works,
10944 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
10945 SgClassDeclaration* nondefdecl = NULL;
10946
10947 SgName nameWithoutTemplateArguments = XXX_name;
10948 SgName nameWithTemplateArguments = nameWithoutTemplateArguments;
10949 if (buildTemplateInstantiation == true)
10950 {
10951 ROSE_ASSERT(templateArgumentsList != NULL);
10952 nameWithTemplateArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateArgumentsList);
10953 }
10954
10955#if DEBUG_CLASS_DECLARATION
10956 printf ("In SageBuilder::buildClassDeclaration_nfi():\n");
10957 printf (" -- nameWithoutTemplateArguments = %s\n", nameWithoutTemplateArguments.str());
10958 printf (" -- nameWithTemplateArguments = %s\n", nameWithTemplateArguments.str());
10959#endif
10960
10961 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
10962 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
10963 // This fails for test2005_35.C
10964 // ROSE_ASSERT(SageInterface::hasTemplateSyntax(nameWithoutTemplateArguments) == false);
10965
10966 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
10967 // ROSE_ASSERT(scope != NULL);
10968 SgClassSymbol* mysymbol = NULL;
10969 if (scope != NULL)
10970 {
10971#if DEBUG_CLASS_DECLARATION
10972 printf ("Looking up the SgClassSymbol in scope = %p = %s nameWithTemplateArguments = %s \n",scope,scope->class_name().c_str(),nameWithTemplateArguments.str());
10973#endif
10974
10975 // DQ (8/22/2012): We need to provide more information ofr the symbol table lookup to correctly resolve
10976 // (and disambiguate template instantations where the name qualification of the template arguments would
10977 // be significant).
10978 // mysymbol = scope->lookup_class_symbol(name);
10979 // mysymbol = scope->lookup_class_symbol(name);
10980 // mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments);
10981#if 0
10982 // DQ (7/25/2017): Since this is overwritten below, for both branches, we don't need to call this here.
10983 printf ("This was a redundant call to lookup_class_symbol \n");
10984 // mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList);
10985#endif
10986
10987 // DQ (10/10/2015): look up the correct type of symbol.
10988 if (buildTemplateDeclaration == true)
10989 {
10990#if DEBUG_CLASS_DECLARATION
10991 printf ("Note: In SageBuilder::buildClassDeclaration_nfi(): Need to look up a template symbol \n");
10992#endif
10993 ROSE_ASSERT(nonDefiningDecl != NULL);
10994
10995 SgTemplateParameterPtrList templateParameterList;
10996 SgTemplateArgumentPtrList templateSpecializationArgumentList;
10997
10998 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateArguments,&templateParameterList,&templateSpecializationArgumentList) != NULL);
10999
11000 mysymbol = scope->lookup_template_class_symbol(nameWithTemplateArguments,&templateParameterList,&templateSpecializationArgumentList);
11001
11002 ROSE_ASSERT(mysymbol != NULL);
11003#if 0
11004 printf ("ERROR: Need to look up a template symbol \n");
11005 ROSE_ABORT();
11006#endif
11007 }
11008 else
11009 {
11010#if DEBUG_CLASS_DECLARATION
11011 printf ("In SageBuilder::buildClassDeclaration_nfi(): calling lookup_class_symbol(nameWithTemplateArguments = %s,templateArgumentsList->size() = %zu \n",
11012 nameWithTemplateArguments.str(),(templateArgumentsList != NULL) ? templateArgumentsList->size() : 999);
11013 if (templateArgumentsList != NULL)
11014 {
11015 printf (" --- templateArgumentsList elements: \n");
11016 for (size_t i = 0; i < templateArgumentsList->size(); i++)
11017 {
11018 printf (" --- --- templateArgumentsList->[%zu] = %p \n",i,templateArgumentsList->operator[](i));
11019 printf (" --- --- templateArgumentsList->[%zu] = %s \n",i,templateArgumentsList->operator[](i)->class_name().c_str());
11020 templateArgumentsList->operator[](i)->display("In SageBuilder::buildClassDeclaration_nfi()");
11021 }
11022 }
11023#endif
11024 mysymbol = scope->lookup_class_symbol(nameWithTemplateArguments,templateArgumentsList);
11025#if DEBUG_CLASS_DECLARATION
11026 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
11027#endif
11028 // 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).
11029 if (mysymbol == NULL)
11030 {
11031#if DEBUG_CLASS_DECLARATION
11032 printf ("WARNING: scope->lookup_class_symbol(nameWithTemplateArguments = %s,templateArgumentsList->size() = %zu) == NULL \n",nameWithTemplateArguments.str(),templateArgumentsList->size());
11033#endif
11034 // ROSE_ASSERT(nonDefiningDecl != NULL);
11035
11036 // DQ (12/28/2018): Could it be that we wanted to use the name without template arguments.
11037#if DEBUG_CLASS_DECLARATION
11038 printf ("Checking lookup_class_symbol() using nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11039#endif
11040 ROSE_ASSERT(scope->lookup_class_symbol(nameWithoutTemplateArguments,templateArgumentsList) == NULL);
11041
11042#if DEBUG_CLASS_DECLARATION
11043 printf ("nonDefiningDecl = %p \n",nonDefiningDecl);
11044#endif
11045 if (nonDefiningDecl != NULL)
11046 {
11047#if DEBUG_CLASS_DECLARATION
11048 printf ("nonDefiningDecl = %p = %s \n",nonDefiningDecl,nonDefiningDecl->class_name().c_str());
11049#endif
11050 // DQ (3/4/2018): I think this is the correct API to use (internal use only).
11051 SgSymbol* temp_mysymbol = nonDefiningDecl->get_symbol_from_symbol_table();
11052 ROSE_ASSERT(temp_mysymbol != NULL);
11053
11054 mysymbol = isSgClassSymbol(temp_mysymbol);
11055 ROSE_ASSERT(mysymbol != NULL);
11056
11057 // DQ (3/4/2018): check that the scopes are the same.
11058 ROSE_ASSERT(scope == nonDefiningDecl->get_scope());
11059 }
11060 }
11061 }
11062
11063#if 0
11064 // DQ (11/21/2013): Added test based on debugging session with Philippe.
11065 // This test is not a test for a bug, since we require that symbols in base classes be aliased in the derived classes.
11066 if (mysymbol != NULL)
11067 {
11068 SgClassDeclaration* symbol_declaration = isSgClassDeclaration(mysymbol->get_declaration());
11069 ROSE_ASSERT(symbol_declaration != NULL);
11070 ROSE_ASSERT(symbol_declaration->get_scope() == scope);
11071
11072 printf ("In SageBuilder::buildClassDeclaration_nfi(): Testing scope->get_symbol_table()->exists(mysymbol) == true (expensive) \n");
11073
11074 ROSE_ASSERT(scope->get_symbol_table()->exists(mysymbol) == true);
11075 }
11076#endif
11077 }
11078 else
11079 {
11080 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknow.
11081 // DQ (1/26/2009): I think this should be an error, but that appears it would
11082 // break the existing interface. Need to discuss this with Liao.
11083 // printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): scope == NULL \n");
11084 }
11085
11086#if DEBUG_CLASS_DECLARATION
11087 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
11088#endif
11089
11090 if (mysymbol != NULL) // set links if nondefining declaration already exists.
11091 {
11092 nondefdecl = isSgClassDeclaration(mysymbol->get_declaration());
11093
11094 ROSE_ASSERT(nondefdecl != NULL);
11095
11096#if DEBUG_CLASS_DECLARATION
11097 printf ("In SageBuilder::buildClassDeclaration_nfi(): mysymbol->get_declaration(): nondefdecl = %p = %s nondefdecl->get_definition() = %p = %s \n",
11098 nondefdecl,nondefdecl->class_name().c_str(),nondefdecl->get_definition(),
11099 nondefdecl->get_definition() != NULL ? nondefdecl->get_definition()->class_name().c_str() : "NULL");
11100#endif
11101 // DQ (6/8/2013): This should not be true (see test2013_198.C).
11102 // Fundamentally the symbol should always only have a pointer to a non-defining
11103 // declaration, where by definition (get_definition() == NULL).
11104 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
11105
11106 // DQ (9/16/2012): This should be true by definition (verify).
11107 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
11108
11109 // DQ (9/16/2012): The declaration was build previously, but test it to make sure the template arguments were setup properly.
11110 testTemplateArgumentParents(nondefdecl);
11111
11112#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11113 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11114 detectTransformations(nondefdecl);
11115#endif
11116
11117 // DQ (3/22/2012): I think we can assert this.
11118 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11119
11120 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11121 if (nondefdecl->get_parent() == NULL)
11122 {
11123#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11124 printf ("In SageBuilder::buildClassDeclaration_nfi(): Note that nondefdecl->get_parent() == NULL, this might be OK. \n");
11125#endif
11126 }
11127
11128#if 0
11129 // DQ (12/22/2019): This is the code that causes the class declarations between defining
11130 // class declarations across multiple translation units to be shared.
11131
11132 // DQ (9/7/2012): I think this might be the root of a problem in the haskell tests (ROSE compiling ROSE).
11133 if (nondefdecl->get_definingDeclaration() != NULL)
11134 {
11135#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11136 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",
11137 nondefdecl,nondefdecl->class_name().c_str(),nondefdecl->get_definingDeclaration(),nondefdecl->get_definingDeclaration()->class_name().c_str());
11138#endif
11139 SgClassDeclaration* nondefining_classDeclaration = isSgClassDeclaration(nondefdecl);
11140 ROSE_ASSERT(nondefining_classDeclaration != NULL);
11141 SgClassDeclaration* defining_classDeclaration = isSgClassDeclaration(nondefdecl->get_definingDeclaration());
11142 ROSE_ASSERT(defining_classDeclaration != NULL);
11143
11144#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11145 printf ("In SageBuilder::buildClassDeclaration_nfi(): nondefining_classDeclaration: scope = %p = %s name = %s \n",
11146 nondefining_classDeclaration->get_scope(),nondefining_classDeclaration->get_scope()->class_name().c_str(),nondefining_classDeclaration->get_name().str());
11147 printf ("In SageBuilder::buildClassDeclaration_nfi(): defining_classDeclaration: scope = %p = %s name = %s \n",
11148 defining_classDeclaration->get_scope(),defining_classDeclaration->get_scope()->class_name().c_str(),defining_classDeclaration->get_name().str());
11149 defining_classDeclaration->get_file_info()->display("already has a defining declaration");
11150#endif
11151#if 0
11152 printf ("Error: In SageBuilder::buildClassDeclaration_nfi(): exiting as part of test \n");
11153 ROSE_ABORT();
11154#endif
11155 // 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.
11156#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11157 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);
11158#endif
11159
11160#if 0
11161 // DQ (2/26/2019): Debugging support for multiple files on the command line.
11162 printf ("Exiting as a test! \n");
11163 ROSE_ABORT();
11164#endif
11165 return defining_classDeclaration;
11166 }
11167#endif
11168
11169#if 0
11170 nondefdecl->set_definingDeclaration(defdecl);
11171
11172 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
11173 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
11174#endif
11175 }
11176 else // build a nondefnining declaration if it does not exist
11177 {
11178#if DEBUG_CLASS_DECLARATION
11179 printf ("In SageBuilder::buildClassDeclaration_nfi(): building a nondefining declaration since it does not exist \n");
11180#endif
11181 // DQ (10/10/2015): This should be true.
11182 ROSE_ASSERT(nondefdecl == NULL);
11183
11184 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
11185 // DQ (1/1/2012): Fixed to force matching types or IR nodes for defining and non-defining declarations.
11186 if (buildTemplateInstantiation == true)
11187 {
11188 // This adds: SgTemplateDeclaration *templateDeclaration and SgTemplateArgumentPtrList templateArguments
11189#if DEBUG_CLASS_DECLARATION
11190 printf ("************************************************************************* \n");
11191 printf ("Building SgTemplateInstantiationDecl with empty SgTemplateArgumentPtrList \n");
11192 printf (" --- using nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
11193 printf ("************************************************************************* \n");
11194#endif
11195 SgTemplateArgumentPtrList emptyList;
11196 // nondefdecl = new SgTemplateInstantiationDecl (name,kind,NULL,NULL,NULL,emptyList);
11197 nondefdecl = new SgTemplateInstantiationDecl (nameWithTemplateArguments,kind,NULL,NULL,NULL,emptyList);
11198 ROSE_ASSERT(nondefdecl != NULL);
11199#if DEBUG_CLASS_DECLARATION
11200 printf ("In SageBuilder::buildClassDeclaration_nfi(): Build SgTemplateInstantiationDecl: nondefdecl = %p \n",nondefdecl);
11201#endif
11202 // DQ (2/27/2018): Added assertion now that we have implemented more consistant semantics
11203 // for template instantiations (types are not generated in the constructor calls).
11204 ROSE_ASSERT(nondefdecl->get_type() == NULL);
11205 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl) != NULL);
11206#if 0
11207 printf ("In buildClassDeclaration_nfi(): nondefdecl->get_name() = %s nondefdecl->get_templateName() = %s \n",nondefdecl->get_name().str(),isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().str());
11208#endif
11209#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11210 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11211 // detectTransformations(nondefdecl);
11212#endif
11213 // DQ (6/6/2012): Set the first non-defining declaration to be itself.
11214 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11215
11216 // DQ (1/1/2012): Added support for setting the template name (I think this should be fixed in the constructor).
11217 // It can't be fixed in the constructor since it has to be set after construction (or passed in explicitly).
11218 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == true);
11219
11220 // DQ (6/6/2012): Added support for template arguments so that types would be computed with the template arguments.
11221 ROSE_ASSERT(templateArgumentsList != NULL);
11222
11223#if 0
11224 // DQ (5/30/2014): Removing output spew.
11225 // DQ (5/17/2014): This must be allowed for some template instantiations (see test2014_77.C).
11226 // This occurs now under some revised rules for when to interpret a class or struct as a template
11227 // declaration or template instantiation declaration. This revisions is required for test2014_56.C
11228 // but has had a small cascading effect on other parts of ROSE (all fixed on 5/17/2014, if I can
11229 // finish this work today).
11230 // ROSE_ASSERT(templateArgumentsList->size() > 0);
11231 if (templateArgumentsList->size() == 0)
11232 {
11233 printf ("Warning: In SageBuilder::buildClassDeclaration_nfi(): templateArgumentsList->size() == 0 \n");
11234 }
11235#endif
11236 // DQ (9/16/2012): Set the firstNondefiningDeclaration so that we can set the template parameters.
11237 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11238#if 1
11239 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
11240 setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
11241#else
11242 isSgTemplateInstantiationDecl(nondefdecl)->get_templateArguments() = *templateArgumentsList;
11243
11244#error "DEAD CODE!"
11245
11246 // DQ (9/13/2012): Set the parents of the template arguments (if not already set, to the first non-defining declaration).
11247 // printf ("Calling setTemplateArgumentParents(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11248 setTemplateArgumentParents(nondefdecl);
11249 // printf ("DONE: Calling setTemplateArgumentParents(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11250
11251 testTemplateArgumentParents(nondefdecl);
11252#endif
11253 // DQ (6/6/2012): Generate the name without the template arguments.
11254#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11255 printf ("Warning: In buildClassDeclaration_nfi(): calling set_templateName(nameWithTemplateArguments = %s) for nondefining declaration \n",nameWithTemplateArguments.str());
11256#endif
11257 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(name);
11258 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName("SETME_NONDEFINING_DECL<>");
11259 // isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(name);
11260 isSgTemplateInstantiationDecl(nondefdecl)->set_templateName(nameWithoutTemplateArguments);
11261
11262 // DQ (6/6/2012): I don't think we want this test any more (should apply only to the result of get_templateName()).
11263 // DQ (5/31/2012): Find locations where this is set and include template syntax.
11264 // ROSE_ASSERT(name.getString().find('<') == string::npos);
11265 // printf ("Commented out test for: name.getString().find('<') == string::npos (should apply only to the result of get_templateName() \n");
11266
11267 ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().is_null() == false);
11268
11269 // DQ (3/25/2017): Fixed Clang warning: warning: if statement has empty body [-Wempty-body]
11270 // DQ (3/22/2012): Make sure there is template syntax present.
11271 // if (isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().getString().find('>') == string::npos)
11272 // if (hasTemplateSyntax(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName()) == false);
11273 if (hasTemplateSyntax(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName()) == false)
11274 {
11275#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11276 printf ("WARNING: No template syntax present in name of template class instantiation (nondefdecl) \n");
11277#endif
11278 }
11279 // ROSE_ASSERT(isSgTemplateInstantiationDecl(nondefdecl)->get_templateName().getString().find('>') != string::npos);
11280
11281#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11282 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11283 // detectTransformations(nondefdecl);
11284#endif
11285 // 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.
11286 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
11287 }
11288 else
11289 {
11290 // We know that the name without template arguments should be used here (but they are the same).
11291#if DEBUG_CLASS_DECLARATION
11292 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);
11293 printf (" --- nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11294#endif
11295 // nondefdecl = new SgClassDeclaration(name,kind,NULL,NULL);
11296 nondefdecl = new SgClassDeclaration(nameWithoutTemplateArguments,kind,NULL,NULL);
11297
11298 ROSE_ASSERT(nondefdecl != NULL);
11299#if DEBUG_CLASS_DECLARATION
11300 printf ("In buildClassDeclaration_nfi(): (no file info set): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11301#endif
11302 ROSE_ASSERT(nameWithoutTemplateArguments == nameWithTemplateArguments);
11303
11304#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11305 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11306 // detectTransformations(nondefdecl);
11307#endif
11308 // DQ (9/16/2012): Set the firstNondefiningDeclaration because this is the one branch left were it
11309 // was not set (required in the true branch so that we could set the template parameters).
11310 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11311
11312 testTemplateArgumentParents(nondefdecl);
11313
11314 // 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.
11315 ROSE_ASSERT(nondefdecl->get_file_info() == NULL);
11316 }
11317
11318 ROSE_ASSERT(nondefdecl != NULL);
11319
11320 // DQ (6/6/2012): This has to be set before we generate the type.
11321 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11322 ROSE_ASSERT(nondefdecl == nondefdecl->get_firstNondefiningDeclaration());
11323
11324 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
11325 // setTemplateArgumentsInDeclaration(nondefdecl,templateArgumentsList);
11326
11327 // DQ (3/14/2012): For C++ we need the scope set so that types will have proper locations to revolve them
11328 // from being ambiguous or not properly defined. Basically, we need a handle from which to generate something
11329 // that amounts to a kind of name qualification internally (maybe even exactly name qualification, but I would
11330 // have to think about that a bit more).
11331 ROSE_ASSERT(scope != NULL);
11332
11333#if DEBUG_CLASS_DECLARATION
11334 printf ("In SageBuilder::buildClassDeclaration_nfi(): Set the scope of the new non-defining declaration to %p = %s \n",scope,scope->class_name().c_str());
11335#endif
11336 nondefdecl->set_scope(scope);
11337 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
11338
11339 // DQ (8/2/2019): The was required becuase the parent pointers were not being set when reading a file from the SageBuilder::buildFil() API.
11340 // However the bug was that the astPostprocessing's call to resetParentPointersInMemoryPool() was not properly working to find the global
11341 // scope in anyother case but when it was called usign a SgProject node. This is not fixed to permit caloling using a SgSourceFile node
11342 // and it is now an error to call it using any other kind of IR node.
11343 // DQ (8/1/2019): Set the parent for the non defining declaration to be the same as the scope by default.
11344 // nondefdecl->set_parent(scope);
11345#if 0
11346 printf ("In buildClassDeclaration_nfi(): setting the parent of the non defining declaration to be the scope by default) \n");
11347#endif
11348 // DQ (7/31/2019): Check that the parent is set if this was used a the declaration referenced by a symbol.
11349 // ROSE_ASSERT (nondefdecl->get_parent() != NULL);
11350
11351 // DQ (3/22/2012): I think we can assert this.
11352 // ROSE_ASSERT(nondefdecl->get_type() != NULL);
11353 ROSE_ASSERT(nondefdecl->get_type() == NULL);
11354
11355 if (nondefdecl->get_type() == NULL)
11356 {
11357#if DEBUG_CLASS_DECLARATION
11358 // DQ (12/27/2018): If we have already built a type, then why did we need to build a nondefining declaration?
11359 printf ("Calling scope->get_type_table()->lookup_type(): nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
11360
11361 printf ("WE NEED THE MANGLED NAME FOR THIS TO BE RELEVANT! \n");
11362
11363 // SgType* existingType = scope->get_type_table()->lookup_type(nameWithTemplateArguments);
11364 // ROSE_ASSERT(existingType == NULL);
11365#endif
11366
11367#if DEBUG_CLASS_DECLARATION
11368 printf ("In SageBuilder::buildClassDeclaration_nfi(): kind == SgClassDeclaration::e_java_parameter = %s \n",(kind == SgClassDeclaration::e_java_parameter) ? "true" : "false");
11369#endif
11372 : (SgClassType *) SgClassType::createType(nondefdecl));
11373#if DEBUG_CLASS_DECLARATION
11374 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());
11375#endif
11376 nondefdecl->set_type(class_type);
11377#if DEBUG_CLASS_DECLARATION
11378 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());
11379#endif
11380 SgClassDeclaration* tmp_classDeclarationFromType = isSgClassDeclaration(class_type->get_declaration());
11381 ROSE_ASSERT(tmp_classDeclarationFromType != NULL);
11382#if DEBUG_CLASS_DECLARATION
11383 SgScopeStatement* scope = tmp_classDeclarationFromType->get_scope();
11384 printf ("tmp_classDeclarationFromType: scope = %p = %s \n",scope,scope->class_name().c_str());
11385 printf ("tmp_classDeclarationFromType = %p = %s \n",tmp_classDeclarationFromType,tmp_classDeclarationFromType->class_name().c_str());
11386 printf ("tmp_classDeclarationFromType name = %s \n",tmp_classDeclarationFromType->get_name().str());
11387 if (tmp_classDeclarationFromType->get_file_info() != NULL)
11388 {
11389 tmp_classDeclarationFromType->get_file_info()->display("tmp_classDeclarationFromType: debug");
11390 }
11391#endif
11392 }
11393
11394 ROSE_ASSERT(nondefdecl->get_type() != NULL);
11395 if (nondefdecl->get_type()->get_declaration() != nondefdecl)
11396 {
11397 printf ("ERROR: nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11398 printf ("ERROR: nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11399 printf ("ERROR: nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
11400
11401 SgClassDeclaration* classDeclarationFromType = isSgClassDeclaration(nondefdecl->get_type()->get_declaration());
11402 ROSE_ASSERT(classDeclarationFromType != NULL);
11403
11404 printf ("nondefdecl->get_name() = %s \n",nondefdecl->get_name().str());
11405 printf ("nondefdecl->get_type()->get_name() = %s \n",nondefdecl->get_type()->get_name().str());
11406 printf ("nondefdecl->get_type()->get_declaration()->get_name() = %s \n",classDeclarationFromType->get_name().str());
11407
11408 printf ("nondefdecl->get_mangled_name() = %s \n",nondefdecl->get_mangled_name().getString().c_str());
11409 printf ("nondefdecl->get_type()->get_mangled() = %s \n",nondefdecl->get_type()->get_mangled().getString().c_str());
11410 printf ("nondefdecl->get_type()->get_declaration()->get_mangled_name() = %s \n",classDeclarationFromType->get_mangled_name().getString().c_str());
11411
11412 // DQ (12/27/2018): Added additional debugging support.
11413 printf ("nondefdecl->get_type()->get_declaration()->get_firstNondefiningDeclaration() = %s \n",classDeclarationFromType->get_firstNondefiningDeclaration() ? "true" : "false");
11414 printf ("nondefdecl->get_firstNondefiningDeclaration() = %s \n",nondefdecl->get_firstNondefiningDeclaration() ? "true" : "false");
11415
11416 // 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.
11417 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
11418 {
11419 SgNode* parent = nondefdecl->get_parent();
11420 if (parent != NULL)
11421 {
11422 printf ("nondefdecl->get_parent() = %p = %s \n",parent,parent->class_name().c_str());
11423 }
11424 }
11425
11426 // DQ (12/27/2018): Activate this debugging support.
11427#if DEBUG_CLASS_DECLARATION
11428 nondefdecl->get_type()->get_declaration()->get_file_info()->display("nondefdecl->get_type()->get_declaration()");
11429
11430 // DQ (7/24/2017): Added more debug information to support debugging test2014_187.C.
11431 // Note that this can be caught as an error if the class declaration was built in the code above when
11432 // the symbol was not found. But if the nondefdecl->get_type()->get_declaration() == nondefdecl,
11433 // then this branch will not be taken (which is simply debugging information to assert that
11434 // nondefdecl->get_type()->get_declaration() == nondefdecl is true (below).
11435 if (nondefdecl->get_file_info() == NULL)
11436 {
11437 printf ("ERROR: In SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p = %s does not have its source position information setup \n",nondefdecl,nondefdecl->class_name().c_str());
11438 printf (" --- nondefdecl = %s \n",nondefdecl->get_name().str());
11439 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p \n",nondefdecl->get_firstNondefiningDeclaration());
11440 printf (" --- nondefdecl->get_definingDeclaration() = %p \n",nondefdecl->get_definingDeclaration());
11441 printf (" --- nondefdecl->get_type() = %p \n",nondefdecl->get_type());
11442 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
11443 printf ("The real error is: (nondefdecl->get_type()->get_declaration() != nondefdecl) \n");
11444 }
11445 else
11446 {
11447 ROSE_ASSERT(nondefdecl->get_file_info() != NULL);
11448 nondefdecl->get_file_info()->display("nondefdecl");
11449 }
11450#endif
11451 }
11452 ROSE_ASSERT(nondefdecl->get_type()->get_declaration() == nondefdecl);
11453
11454#if 0
11455 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());
11456#endif
11457
11458 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11459
11460 // The nondefining declaration will not appear in the source code, but is compiler
11461 // generated (so we have something about the class that we can reference; e.g in
11462 // types). At the moment we make it a transformation, there might be another kind
11463 // of source position that would be more precise. FIXME.
11464 // setOneSourcePositionNull(nondefdecl);
11466 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
11467
11468#if BUILDER_MAKE_REDUNDANT_CALLS_TO_DETECT_TRANSFORAMTIONS
11469 // DQ (5/2/2012): After EDG/ROSE translation, there should be no IR nodes marked as transformations.
11471 {
11472 detectTransformations(nondefdecl);
11473 }
11474#endif
11475 // DQ (6/6/2012): This has to be set before we generate the type.
11476 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11477
11478 // DQ (3/15/2012): This is now set below.
11479 // nondefdecl->set_definingDeclaration(defdecl);
11480 nondefdecl->setForward();
11481
11482 // 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).
11483 // Liao, 9/2/2009. scope stack is optional, it can be empty
11484 // nondefdecl->set_parent(topScopeStack());
11485#if 0
11486 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");
11487#endif
11488 // nondefdecl->set_parent(scope);
11489 // defdecl->set_parent(scope);
11490
11491 if (scope != NULL)
11492 {
11493 mysymbol = new SgClassSymbol(nondefdecl);
11494#if 0
11495 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());
11496#endif
11497 // scope->insert_symbol(name, mysymbol);
11498 scope->insert_symbol(nameWithTemplateArguments, mysymbol);
11499
11500 // DQ (11/21/2013): Added test based on debugging session with Philippe.
11501 ROSE_ASSERT(nondefdecl->get_scope() == scope);
11502 }
11503 else
11504 {
11505 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unkown.
11506 // DQ (1/26/2009): I think this should be an error, but that appears it would
11507 // break the existing interface. Need to discuss this with Liao.
11508 printf ("Warning: no scope provided to support symbol table entry! \n");
11509 }
11510
11511 // DQ (7/31/2019): Check that the parent is set if this was used a the declaration referenced by a symbol.
11512 // ROSE_ASSERT (nondefdecl->get_parent() != NULL);
11513 }
11514
11515 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
11516
11517#if 1
11518 // Refactored this code.
11519 testTemplateArgumentParents(nondefdecl);
11520#else
11521 if (buildTemplateInstantiation == true)
11522 {
11523 // DQ (7/25/2012): Added this code here to reset the parents of the template arguments.
11524 for (size_t i = 0; i < templateArgumentsList->size(); i++)
11525 {
11526 // DQ (7/25/2012): This should be true because the template argument was set to the functions
11527 // scope so that the name with template arguments could be computed (with name qualification).
11528 ROSE_ASSERT((*templateArgumentsList)[i]->get_parent() != NULL);
11529
11530#error "DEAD CODE!"
11531
11532 // ROSE_ASSERT(isSgGlobal(templateArgumentsList[i]->get_parent()) == NULL);
11533 // ROSE_ASSERT(templateArgumentsList[i]->get_parent() == nondefining_templateInstantiation);
11534
11535 // Be we want to reset it to be the function (now that it is available, because this is more precise).
11536 // All qualified names should compute to the same qualified name (if not then it is a bug in the name
11537 // qualification mechanism).
11538 (*templateArgumentsList)[i]->set_parent(nondefdecl);
11539 }
11540 }
11541#endif
11542
11543 // DQ (3/15/2012): I hhava moved construction of defining declaration to be AFTER the nondefining declaration!
11544 // This is a better organization ans also should make sure that the declaration in the SgClassType will
11545 // properly reference the firstNondefiningDeclaration (instead of the defining declaration).
11546
11547 // step 1 (now step 2). Build defining declaration
11548 // SgClassDefinition* classDef = buildClassDefinition();
11549 SgClassDefinition* classDef = buildClassDefinition(NULL,buildTemplateInstantiation);
11550
11551 // DQ (11/26/2011): Debugging EDG 3.3 use of templateArguments.
11552#if 0
11553 printf ("Building a SgClassDeclaration: buildClassDeclaration_nfi() buildTemplateInstantiation = %s \n",buildTemplateInstantiation ? "true:" : "false");
11554#endif
11555
11556 // SgClassDeclaration* defdecl = new SgClassDeclaration (name,kind,NULL,classDef);
11557 SgClassDeclaration* defdecl = NULL;
11558 if (buildTemplateInstantiation == true)
11559 {
11560 // This adds: SgTemplateDeclaration *templateDeclaration and SgTemplateArgumentPtrList templateArguments
11561 SgTemplateArgumentPtrList emptyList;
11562 // defdecl = new SgTemplateInstantiationDecl (name,kind,NULL,classDef,NULL,emptyList);
11563 defdecl = new SgTemplateInstantiationDecl (nameWithTemplateArguments,kind,NULL,classDef,NULL,emptyList);
11564
11565 // DQ (2/27/2018): Added assertion now that we have implemented more consistant semantics
11566 // for template instantiations (types are not generated in the constructor calls).
11567 ROSE_ASSERT(defdecl->get_type() == NULL);
11568 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl) != NULL);
11569#if 0
11570 printf ("In buildClassDeclaration_nfi(): defdecl->get_name() = %s defdecl->get_templateName() = %s \n",defdecl->get_name().str(),isSgTemplateInstantiationDecl(defdecl)->get_templateName().str());
11571#endif
11572 // DQ (1/1/2012): Added support for setting the template name (I think this should be fixed in the constructor).
11573 // It can't be fixed in the constructor since it has to be set after construction (or passed in explicitly).
11574 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().is_null() == true);
11575
11576#if 0
11577 printf ("Warning: In buildClassDeclaration_nfi(): calling set_templateName(name = %s) for defining declaration \n",name.str());
11578#if 0
11579 // isSgTemplateInstantiationDecl(defdecl)->set_templateName(name);
11580 // isSgTemplateInstantiationDecl(defdecl)->set_templateName("SETME_DEFINING_DECL<>");
11581 isSgTemplateInstantiationDecl(defdecl)->set_templateName(name);
11582
11583#error "DEAD CODE!"
11584
11585 // DQ (5/31/2012): Find locations where this is set and include template syntax.
11586 ROSE_ASSERT(name.getString().find('<') == string::npos);
11587#else
11588 // DQ (6/1/2012): Make sure that the templateName is set and they it does not include the template syntax.
11589 SgName templateName = generateTemplateNameFromTemplateNameWithTemplateArguments(name);
11590 printf ("In buildClassDeclaration_nfi(): templateName = %s \n",templateName.str());
11591 isSgTemplateInstantiationDecl(defdecl)->set_templateName(templateName);
11592
11593#error "DEAD CODE!"
11594
11595 // DQ (5/31/2012): Find locations where this is set and include template syntax.
11596 // ROSE_ASSERT(templateName.getString().find('<') == string::npos);
11597 ROSE_ASSERT(hasTemplateSyntax(templateName) == false);
11598
11599 // DQ (6/1/2012): Not clear if this is always true (for all template instantations).
11600 // ROSE_ASSERT(name.getString().find('<') != string::npos);
11601 ROSE_ASSERT(hasTemplateSyntax(name) == true);
11602#endif
11603#else
11604#if 0
11605 printf ("In buildClassDeclaration_nfi(): nameWithoutTemplateArguments = %s nameWithTemplateArguments = %s \n",nameWithoutTemplateArguments.str(),nameWithTemplateArguments.str());
11606#endif
11607 isSgTemplateInstantiationDecl(defdecl)->set_templateName(nameWithoutTemplateArguments);
11608
11609#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11610 // DQ (5/8/2013): This fails for test2013_159.C, and it appears that we have been overly restrictive here.
11611 if (hasTemplateSyntax(nameWithTemplateArguments) == false)
11612 {
11613 printf ("WARNING: In buildClassDeclaration_nfi(): nameWithTemplateArguments = %s is not using template syntax \n",nameWithTemplateArguments.str());
11614 }
11615#endif
11616 // ROSE_ASSERT(hasTemplateSyntax(nameWithTemplateArguments) == true);
11617
11618 // DQ (7/27/2012): This fails for test2005_35.C where conversion operators are seen.
11619 // ROSE_ASSERT(hasTemplateSyntax(nameWithoutTemplateArguments) == false);
11620#endif
11621
11622 ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().is_null() == false);
11623
11624 // DQ (3/22/2012): Make sure there is template syntax present.
11625 if (isSgTemplateInstantiationDecl(defdecl)->get_templateName().getString().find('>') == string::npos)
11626 {
11627#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
11628 printf ("WARNING: No template syntax present in name of template class instantiation (defdecl) \n");
11629#endif
11630 }
11631 // ROSE_ASSERT(isSgTemplateInstantiationDecl(defdecl)->get_templateName().getString().find('>') != string::npos);
11632#if 0
11633 printf ("Should we have set the template instantiation name at this point? \n");
11634 ROSE_ABORT();
11635#endif
11636 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
11637 ROSE_ASSERT(defdecl->get_definition() != NULL);
11638 ROSE_ASSERT(isSgTemplateInstantiationDefn(defdecl->get_definition()) != NULL);
11639 }
11640 else
11641 {
11642#if 0
11643 printf ("Building a SgClassDeclaration, but we might require a SgTemplateClassDeclaration \n");
11644#endif
11645 // defdecl = new SgClassDeclaration (name,kind,NULL,classDef);
11646 // defdecl = new SgClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
11647
11648 // DQ (10/11/2015): Try to build a matching SgTemplateClassDeclaration. The problem with this fix is that
11649 // I would prefer that the other function be called instead. We might still want to implementat that instead.
11650 if (buildTemplateDeclaration == true)
11651 {
11652 printf ("In buildClassDeclaration_nfi(): I think we also want template specialization arguments to be more general: using nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11653
11654 // = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,classType,(SgClassDefinition*)NULL);
11655 defdecl = new SgTemplateClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
11656
11657 // DQ (2/27/2018): We should be able to enforce this, it should have always been true.
11658 ROSE_ASSERT(defdecl->get_type() == NULL);
11659#if 0
11660 printf ("Exiting afte test! \n");
11661 ROSE_ABORT();
11662#endif
11663 }
11664 else
11665 {
11666 defdecl = new SgClassDeclaration (nameWithoutTemplateArguments,kind,NULL,classDef);
11667
11668#if 0
11669 // DQ (12/22/2019): Debugging the case of shared class declarations between multiple files referencing the same defining declaration.
11670 printf ("In SageBuilder::buildClassDeclaration_nfi(): build a SgClassDeclaration: defdecl = %p \n",defdecl);
11671#endif
11672
11673 // DQ (2/27/2018): We should be able to enforce this, it should have always been true.
11674 ROSE_ASSERT(defdecl->get_type() == NULL);
11675 }
11676
11677 // DQ (3/5/2012): Check that the SgClassDefinition is properly matching.
11678 ROSE_ASSERT(defdecl->get_definition() != NULL);
11679 ROSE_ASSERT(isSgTemplateInstantiationDefn(defdecl->get_definition()) == NULL);
11680 }
11681 ROSE_ASSERT(defdecl != NULL);
11682
11683#if 0
11684 printf ("In buildClassDeclaration_nfi(): nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11685#endif
11686
11687 // DQ (3/15/2012): Moved from original location above...
11688 nondefdecl->set_definingDeclaration(defdecl);
11689
11690 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
11691 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
11692
11693 // printf ("SageBuilder::buildClassDeclaration_nfi(): defdecl = %p \n",defdecl);
11694
11696 // constructor is side-effect free
11697 classDef->set_declaration(defdecl);
11698 defdecl->set_definingDeclaration(defdecl);
11699
11700 testTemplateArgumentParents(nondefdecl);
11702
11703 // setOneSourcePositionForTransformation(nondefdecl);
11704 //
11705 // Liao 1/18/2011, I changed the semantics of setOneSourcePositionNull to set file_info to null regardless the existence of
11706 // file_info of the input node.
11707 // We do want to keep the file_info of nodefdecl if it is set already as compiler generated.
11708 // setOneSourcePositionNull(nondefdecl);
11709
11710 // nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
11711 // nondefdecl->set_definingDeclaration(defdecl);
11712 defdecl->set_firstNondefiningDeclaration(nondefdecl);
11713
11714 if (buildTemplateInstantiation == true)
11715 {
11716 // DQ (9/16/2012): This is a newly refactored function (call this after the firstNondefiningDeclaration is set).
11717 setTemplateArgumentsInDeclaration(defdecl,templateArgumentsList);
11718 }
11719
11720 // DQ (3/22/2012): I think we can assert this.
11721 ROSE_ASSERT(defdecl->get_type() == NULL);
11722
11723 // Liao, 10/30/2009
11724 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
11725 // This is not desired when building a defining declaration and an inefficience in the constructor
11726 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
11727 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
11728 if (defdecl->get_type() != NULL)
11729 {
11730 // if a defining class declaration's type is associated with a defining class.
11731 // This is a wrong SgClassType and has to be reset
11732 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl))
11733 {
11734 // DQ (3/21/2012): Added this test.
11735 ROSE_ASSERT (nondefdecl->get_type() != NULL);
11736
11737 // DQ (3/15/2012): Make this conditional upon the types not already being equal.
11738 if (nondefdecl->get_type() != defdecl->get_type())
11739 {
11740#if 0
11741 printf ("Deleting defdecl->get_type() = %p = %s (using type from nondefdecl = %p) \n",defdecl->get_type(),defdecl->get_type()->class_name().c_str(),nondefdecl);
11742 printf ("Skipping delete of %p to maintain unique type pointers \n",defdecl->get_type());
11743#else
11744 delete defdecl->get_type();
11745#endif
11746 // DQ (3/15/2012): This will be reset below.
11747 defdecl->set_type(NULL);
11748#if 0
11749 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());
11750#endif
11751#if 0
11752 // DQ (12/13/2011): Is this executed...
11753 printf ("Is this executed! \n");
11754 ROSE_ABORT();
11755#endif
11756 // DQ (3/21/2012): set the types to be the same type.
11757 ROSE_ASSERT (nondefdecl->get_type() != NULL);
11758 defdecl->set_type(nondefdecl->get_type());
11759#if 0
11760 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());
11761#endif
11762 // DQ (3/21/2012): Added these checks...
11763 SgClassType* classType = nondefdecl->get_type();
11764 ROSE_ASSERT(classType != NULL);
11765 SgClassDeclaration* local_classDeclaration = isSgClassDeclaration(classType->get_declaration());
11766 ROSE_ASSERT (local_classDeclaration != NULL);
11767 printf ("In buildClassDeclaration_nfi(): classType = %p local_classDeclaration = %p \n",classType,local_classDeclaration);
11768 ROSE_ASSERT (local_classDeclaration->get_firstNondefiningDeclaration() != NULL);
11769 ROSE_ASSERT (local_classDeclaration->get_firstNondefiningDeclaration() == local_classDeclaration);
11770 }
11771 }
11772 }
11773 else
11774 {
11775 // DQ (3/15/2012): Make sure that both the defining and non-defining declarations use the same type.
11776 ROSE_ASSERT (nondefdecl->get_type() != NULL);
11777 defdecl->set_type(nondefdecl->get_type());
11778#if 0
11779 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());
11780#endif
11781
11782 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
11783#if 0
11784 // DQ (11/20/2017): Commented out output spew.
11785 // DQ (2/28/2015): This test is failing in the new application support for templates within the testRoseHeaders_01.C.
11786 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()))
11787 {
11788 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");
11789 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11790 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
11791 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
11792 }
11793 // DQ (7/22/2017): Uncomment this test to better understand why this is a new issue (after two years).
11794 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
11795#endif
11796#if 0
11797 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
11798#endif
11799 }
11800
11801 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
11802
11803 // patch up the SgClassType for the defining class declaration
11804 ROSE_ASSERT (nondefdecl->get_type() != NULL);
11805 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
11806#if 0
11807 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl))
11808 {
11809 printf ("nondefdecl = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11810 printf ("nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11811 printf ("nondefdecl->get_type()->get_declaration() = %p = %s \n",nondefdecl->get_type()->get_declaration(),nondefdecl->get_type()->get_declaration()->class_name().c_str());
11812 printf ("nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
11813 }
11814#endif
11815 // ROSE_ASSERT (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl));
11816 ROSE_ASSERT (defdecl->get_type() != NULL);
11817 ROSE_ASSERT (defdecl->get_type()->get_declaration() != NULL);
11818 ROSE_ASSERT (defdecl->get_type()->get_declaration() != isSgDeclarationStatement(defdecl));
11819 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() != NULL);
11820 ROSE_ASSERT (nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
11821#if 0
11822 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
11823#else
11824
11825#if 0
11826 // DQ (11/20/2017): Commented out output spew.
11827 // DQ (2/28/2015): This test is failing in the new application support for templates within the testRoseHeaders_01.C.
11828 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()))
11829 {
11830 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");
11831 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11832 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
11833 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl->get_firstNondefiningDeclaration(),nondefdecl->get_firstNondefiningDeclaration()->class_name().c_str());
11834 }
11835 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl->get_firstNondefiningDeclaration()));
11836 if (nondefdecl->get_type()->get_declaration() != isSgDeclarationStatement(nondefdecl))
11837 {
11838 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");
11839 printf (" --- nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->class_name().c_str());
11840 printf (" --- nondefdecl->get_type()->get_declaration() = %p \n",nondefdecl->get_type()->get_declaration());
11841 printf (" --- nondefdecl->get_firstNondefiningDeclaration() = %p = %s \n",nondefdecl,nondefdecl->class_name().c_str());
11842 }
11843 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
11844#endif
11845
11846#endif
11847
11848 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
11849
11850 // This appears to be redundant...is it?
11851 defdecl->set_type(nondefdecl->get_type());
11852
11853#if 0
11854 printf ("In buildClassDeclaration_nfi(): after calling set_type() again: defdecl = %p = %s defdecl->get_type() = %p = %s \n",
11855 defdecl,defdecl->class_name().c_str(),defdecl->get_type(),defdecl->get_type()->class_name().c_str());
11856#endif
11857
11858 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
11859
11860 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
11861 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
11862 // used in a defining declaration).
11863 nondefdecl->setForward();
11864
11865 if (scope != NULL) // put into fixStructDeclaration() or alike later on
11866 {
11867 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
11868
11869 // Note, this function sets the parent to be the scope if it is not already set.
11870 fixStructDeclaration(defdecl,scope);
11871
11872 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
11873
11874 fixStructDeclaration(nondefdecl,scope);
11875
11876 ROSE_ASSERT (defdecl->get_type() == nondefdecl->get_type());
11877
11878#if 0
11879 SgClassSymbol* mysymbol = new SgClassSymbol(nondefdecl);
11880 ROSE_ASSERT(mysymbol);
11881 scope->insert_symbol(name, mysymbol);
11882 printf ("@@@@@@@@@@@@@@ In buildClassDeclaration_nfi(): setting scope of defining and non-defining declaration to scope = %s \n",scope->class_name().c_str());
11883 defdecl->set_scope(scope);
11884 nondefdecl->set_scope(scope);
11885
11886 // defdecl->set_parent(scope);
11887
11888 // Liao, 9/2/2009. merged into fixStructDeclaration
11889 // 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).
11890 nondefdecl->set_parent(scope);
11891 // nondefdecl->set_parent(topScopeStack());
11892 // Liao, 9/2/2009. scope stack is optional, it can be empty
11893 defdecl->set_parent(scope);
11894 // defdecl->set_parent(topScopeStack());
11895#endif
11896 }
11897
11898 // DQ (1/26/2009): I think we should assert this, but it breaks the interface as defined
11899 // by the test code in tests/nonsmoke/functional/roseTests/astInterfaceTests.
11900 // ROSE_ASSERT(defdecl->get_parent() != NULL);
11901
11902 // ROSE_ASSERT(nonDefiningDecl->get_parent() != NULL);
11903
11904 // DQ (2/27/2012): Tracking down where parents are not set correctly (class declaration in typedef is incorrectly set to SgGlobal).
11905 ROSE_ASSERT(defdecl->get_parent() == NULL);
11906
11907 // DQ (2/29/2012): We can't assert this (fails for test2012_09.C).
11908 // ROSE_ASSERT(nondefdecl->get_parent() == NULL);
11909
11910 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
11911 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
11912
11913 testTemplateArgumentParents(nondefdecl);
11915
11916 // DQ (3/8/2018): Added for debugging.
11917 SgClassDeclaration* temp_firstNondefiningDeclaration = isSgClassDeclaration(defdecl->get_firstNondefiningDeclaration());
11918 SgClassDeclaration* temp_definingDeclaration = isSgClassDeclaration(defdecl->get_definingDeclaration());
11919 ROSE_ASSERT(temp_firstNondefiningDeclaration != NULL);
11920 ROSE_ASSERT(temp_definingDeclaration != NULL);
11921
11922#if 0
11923 printf ("Leaving buildClassDeclaration_nfi(): defdecl = %p = %s = %s \n",defdecl,defdecl->class_name().c_str(),defdecl->get_name().str());
11924 printf (" --- defdecl->get_firstNondefiningDeclaration() = %p \n",defdecl->get_firstNondefiningDeclaration());
11925 printf (" --- defdecl->get_definingDeclaration() = %p \n",defdecl->get_definingDeclaration());
11926
11927 printf (" --- defdecl->get_firstNondefiningDeclaration()->get_name() = %s \n",temp_firstNondefiningDeclaration->get_name().str());
11928 printf (" --- defdecl->get_definingDeclaration()->get_name() = %s \n",temp_definingDeclaration->get_name().str());
11929
11930 printf (" --- defdecl->get_firstNondefiningDeclaration()->get_type() = %p = %s \n",
11931 temp_firstNondefiningDeclaration->get_type(),temp_firstNondefiningDeclaration->get_type()->unparseToString().c_str());
11932 printf (" --- defdecl->get_definingDeclaration()->get_type() = %p = %s \n",
11933 temp_definingDeclaration->get_type(),temp_definingDeclaration->get_type()->unparseToString().c_str());
11934
11935 printf (" --- nameWithoutTemplateArguments = %s \n",nameWithoutTemplateArguments.str());
11936 printf (" --- nameWithTemplateArguments = %s \n",nameWithTemplateArguments.str());
11937
11938#if 0
11939 printf ("Leaving buildClassDeclaration_nfi(): defdecl: unparseNameToString() = %s \n",defdecl->unparseNameToString().c_str());
11940#endif
11941#endif
11942
11943 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_name() == temp_definingDeclaration->get_name());
11944 ROSE_ASSERT(temp_firstNondefiningDeclaration->get_type() == temp_definingDeclaration->get_type());
11945
11946 // DQ (3/7/2015): Only in EDG 4.7 does the defining declaration not have a valid templateDeclaration pointer (sometimes).
11947 SgTemplateInstantiationDecl* nondefiningDeclaration = isSgTemplateInstantiationDecl(defdecl->get_firstNondefiningDeclaration());
11948 SgTemplateInstantiationDecl* definingDeclaration = isSgTemplateInstantiationDecl(defdecl->get_definingDeclaration());
11949 if (definingDeclaration != NULL && nondefiningDeclaration != NULL)
11950 {
11951 SgTemplateClassDeclaration* templateDeclaration = nondefiningDeclaration->get_templateDeclaration();
11952 if (templateDeclaration != NULL && definingDeclaration->get_templateDeclaration() == NULL)
11953 {
11954#if 0
11955 printf ("NOTE: buildClassDeclaration_nfi(): Setting the templateDeclaration for the defining declaration = %p using the value = %p from the nondefiningDeclaration = %p \n",
11956 definingDeclaration,templateDeclaration,nondefiningDeclaration);
11957#endif
11958 definingDeclaration->set_templateDeclaration(templateDeclaration);
11959
11960 ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
11961 }
11962 // ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
11963 }
11964
11965 // DQ (3/7/2015): Only in EDG 4.7 does the defining declaration not have a valid templateDeclaration pointer (sometimes).
11966 if (definingDeclaration != NULL)
11967 {
11968 if (definingDeclaration->get_templateDeclaration() == NULL)
11969 {
11970#if 0
11971 printf ("NOTE: buildClassDeclaration_nfi(): definingDeclaration->get_templateDeclaration() == NULL \n");
11972#endif
11973 }
11974 // ROSE_ASSERT(definingDeclaration->get_templateDeclaration() != NULL);
11975 }
11976
11977#if 0
11978 printf ("Leaving buildClassDeclaration_nfi(): defdecl = %p defdecl->unparseNameToString() = %s \n",defdecl,defdecl->unparseNameToString().c_str());
11979#endif
11980
11981#if 0
11982 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
11983 printf ("Leaving buildClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
11984 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(nondefdecl);
11985
11986 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
11987 printf ("Leaving buildClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
11988 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
11989#endif
11990
11991 return defdecl;
11992 }
11993
11994
11996 {
11997 SgName myname(name);
11998 return buildStructDeclaration(myname, scope);
11999 }
12000
12002 {
12003 SgName myname(name);
12004 return buildStructDeclaration(myname, scope);
12005 }
12006
12007
12008#if 0
12009// DQ (11/19/2011): Added more uniform support for building class declarations.
12012 {
12013 ROSE_ASSERT(scope != NULL);
12014 SgTemplateClassDeclaration* definingClassDeclaration = buildDefiningTemplateClassDeclaration(name,scope);
12015 ROSE_ASSERT(definingClassDeclaration != NULL);
12016
12017 return definingClassDeclaration;
12018 }
12019#endif
12020
12021
12024 {
12025 SgTemplateClassDefinition* result = NULL;
12026 if (d != NULL) // the constructor does not check for NULL d, causing segmentation fault
12027 {
12028 result = new SgTemplateClassDefinition(d);
12029 // result->set_parent(d); // set_declaration() == set_parent() in this case
12030 }
12031 else
12032 {
12033 result = new SgTemplateClassDefinition();
12034 }
12035
12036 ROSE_ASSERT(result);
12037
12038 // CR (3/22/2020): Fixed setting case insensitivity
12039 // if (symbol_table_case_insensitive_semantics == true)
12041 result->setCaseInsensitive(true);
12042
12044 return result;
12045 }
12046
12048SageBuilder::buildNondefiningTemplateClassDeclaration(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12049{
12050 SgTemplateClassDeclaration* res = buildNondefiningTemplateClassDeclaration_nfi (XXX_name, kind, scope, templateParameterList, templateSpecializationArgumentList);
12052 return res;
12053}
12054
12055// SgTemplateClassDeclaration * SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(const SgName& name, SgClassDeclaration::class_types kind, SgScopeStatement* scope )
12057SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(const SgName& XXX_name, SgClassDeclaration::class_types kind, SgScopeStatement* scope, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12058 {
12059#if 0
12060 printf("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(XXX_name = %p):\n", XXX_name.str());
12061#endif
12062
12063 if (scope == NULL)
12065
12066 // DQ (11/20/2011): This is for initial debugging only.
12067 ROSE_ASSERT(scope != NULL);
12068
12069#if 0
12070 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): XXX_name = %s scope = %p = %s \n",XXX_name.str(),scope,scope->class_name().c_str());
12071#endif
12072
12073 // 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.
12074 SgName nameWithoutTemplateArguments = XXX_name;
12075 SgName nameWithTemplateSpecializationArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateSpecializationArgumentList);
12076
12077#if 0
12078 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
12079#endif
12080
12081 // SgTemplateClassDeclaration::class_types template_class_kind = SgTemplateClassDeclaration::e_class;
12082
12083 // Step 2. build the nondefining declaration,
12084 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
12085
12086 // Get the nondefining declaration from the symbol if it has been built (if this works,
12087 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
12088 SgTemplateClassDeclaration* nondefdecl = NULL;
12089
12090 // DQ (1/26/2009): It seems that (scope == NULL) can happen in the tests/nonsmoke/functional/roseTests/astInterfaceTests test codes.
12091 // ROSE_ASSERT(scope != NULL);
12092
12093 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12094 // SgTemplateSymbol* mysymbol = NULL;
12095 SgClassSymbol* mysymbol = NULL;
12096
12097 if (scope != NULL)
12098 {
12099 // DQ (9/12/2012): We want to include the template specialization into the name where it is required (this handling
12100 // is similar to normal template arguments for non-template declaration, but different than template parameters).
12101 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12102 // mysymbol = scope->lookup_template_symbol(name);
12103 // mysymbol = scope->lookup_class_symbol(name);
12104 // mysymbol = scope->lookup_template_class_symbol(name);
12105 // mysymbol = scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList);
12106 mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
12107 }
12108 else
12109 {
12110 // Liao 9/2/2009: This is not an error. We support bottom-up AST construction and scope can be unknown.
12111 // DQ (1/26/2009): I think this should be an error, but that appears it would
12112 // break the existing interface. Need to discuss this with Liao.
12113 printf ("Warning: In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): scope == NULL \n");
12114 }
12115#if 0
12116 printf ("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
12117#endif
12118
12119 if (mysymbol != NULL) // set links if nondefining declaration already exists.
12120 {
12121 // DQ (3/7/2012): Build a seperate non-defining declaration (reusing the existing one will cause the test for unique statements to fail).
12122 // 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");
12123 // nondefdecl = isSgTemplateClassDeclaration(mysymbol->get_declaration());
12124 SgClassType* classType = isSgClassType(mysymbol->get_type());
12125 ROSE_ASSERT(classType != NULL);
12126
12127 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12128 // nondefdecl = new SgTemplateClassDeclaration(name,kind,classType,(SgClassDefinition*)NULL);
12129 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,classType,(SgClassDefinition*)NULL);
12130
12131#if 0
12132 // DQ (3/4/2018): relax this requirement for SgTemplateInstantiationClassDeclaration.
12133 // DQ (2/27/2018): Enforce that this is not already set (should be set after the constructor to
12134 // simplify how derived classes (e.g. SgTemplateInstantiationClassDeclaration statements) work.
12135 if (nondefdecl->get_type() != NULL)
12136 {
12137 printf ("Note: SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): nondefdecl->get_type() != NULL: name = %s \n",nondefdecl->get_name().str());
12138 }
12139 // ROSE_ASSERT(nondefdecl->get_type() == NULL);
12140#endif
12141
12142 ROSE_ASSERT(nondefdecl != NULL);
12143
12144 // DQ (9/10/2012): Initialize the template parameter list.
12145 ROSE_ASSERT(templateParameterList != NULL);
12146 nondefdecl->get_templateParameters() = *templateParameterList;
12147
12148 // DQ (9/16/2012): Moved this initialization of firstNondefiningDeclaration from farther down in this branch (and added assertion).
12149 nondefdecl->set_firstNondefiningDeclaration(mysymbol->get_declaration());
12150 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
12151
12152 // TV (04/12/2018): Add a scope for nonreal classes (and their member) on the first non-defining declaration of template classes
12153 if (nondefdecl == nondefdecl->get_firstNondefiningDeclaration()) {
12154 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
12155
12156 nonreal_decl_scope->set_parent(nondefdecl);
12157 nondefdecl->set_nonreal_decl_scope(nonreal_decl_scope);
12158
12159 SageInterface::setSourcePosition(nonreal_decl_scope);
12160 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
12161 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
12162#if 0
12163 printf("In SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(XXX_name = %p): nrscope = %p (new)\n", XXX_name.str(), nonreal_decl_scope);
12164#endif
12165 }
12166
12167#if 1
12168 // DQ (9/16/2012): This newly refactored function can only be called after firstNondefiningDeclaration is set.
12169 // This also sets the template argument parents to the firstNondefiningDeclaration.
12170 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
12171#else
12172 // DQ (9/12/2012): Adding support for template specialization.
12173 ROSE_ASSERT(templateSpecializationArgumentList != NULL);
12174 nondefdecl->get_templateSpecializationArguments() = *templateSpecializationArgumentList;
12175#endif
12176 // DQ (9/10/2012): Test the just built template with its template parameters.
12177 if (nondefdecl->get_templateParameters().size() == 0)
12178 {
12179#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12180 printf ("WARNING: In buildNondefiningTemplateClassDeclaration_nfi(): (part 1) nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
12181#endif
12182 }
12183 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12184
12185 // DQ (3/7/2012): We want this to be set later, so we can't test it here.
12186 // ROSE_ASSERT(nondefdecl->get_parent() != NULL);
12187#if 0
12188 nondefdecl->set_definingDeclaration(defdecl);
12189
12190 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
12191 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
12192#endif
12193 // DQ (3/7/2012): But always refer to the first non-defining declaration so it will be unique (and set the scope).
12194 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
12195 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != nondefdecl);
12196 nondefdecl->set_scope(scope);
12197 nondefdecl->setForward();
12198
12199 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12200 nondefdecl->set_templateName(nameWithoutTemplateArguments);
12201
12202 testTemplateArgumentParents(nondefdecl);
12203 }
12204 else // build a nondefnining declaration if it does not exist
12205 {
12206 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,(SgClassType*)NULL,(SgClassDefinition*)NULL);
12207 ROSE_ASSERT(nondefdecl != NULL);
12208
12209 // DQ (9/10/2012): Initialize the template parameter list.
12210 ROSE_ASSERT(templateParameterList != NULL);
12211 nondefdecl->get_templateParameters() = *templateParameterList;
12212
12213 // DQ (9/16/2012): Moved this initialization of firstNondefiningDeclaration from farther down in this branch.
12214 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12215
12216 // DQ (9/16/2012): This newly refactored function can only be called after firstNondefiningDeclaration is set.
12217 // This also sets the template argument parents to the firstNondefiningDeclaration.
12218 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
12219
12220 // DQ (9/10/2012): Test the just built template with its template parameters.
12221 if (nondefdecl->get_templateParameters().size() == 0)
12222 {
12223#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12224 printf ("WARNING: In buildNondefiningTemplateClassDeclaration_nfi(): (part 2) nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
12225#endif
12226 }
12227 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12228
12229 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12230 nondefdecl->set_templateName(nameWithoutTemplateArguments);
12231
12232#if 0
12233 // DQ (12/4/2011): Now we want to enable this so that the SgClassType will be available from a SgTemplateClassDeclaration.
12234 if (nondefdecl->get_type() == NULL)
12235 {
12236 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
12237 // nondefdecl->set_type(NULL);
12238 // nondefdecl->set_type(SgTemplateType::createType(nondefdecl));
12239 // nondefdecl->set_type(SgTemplateType::createType());
12240 nondefdecl->set_type(SgClassType::createType(nondefdecl));
12241 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12242 }
12243#endif
12244 // printf ("SageBuilder::buildClassDeclaration_nfi(): nondefdecl = %p \n",nondefdecl);
12245
12246 // The nondefining declaration will not appear in the source code, but is compiler
12247 // generated (so we have something about the class that we can reference; e.g in
12248 // types). At the moment we make it a transformation, there might be another kind
12249 // of source position that would be more precise. FIXME.
12250 // setOneSourcePositionNull(nondefdecl);
12252 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
12253
12254 // nondefdecl->set_definingDeclaration(defdecl);
12255 nondefdecl->setForward();
12256
12257 // Liao, 9/2/2009. scope stack is optional, it can be empty
12258 // nondefdecl->set_parent(topScopeStack());
12259#if 0
12260 printf ("In buildNondefiningTemplateClassDeclaration_nfi(): Commented out setting the parent to the scope. \n");
12261#endif
12262 // printf ("Note that for C++, the parent may not be the same as the scope (dangerous code). \n");
12263 // nondefdecl->set_parent(scope);
12264
12265 nondefdecl->set_scope(scope);
12266
12267#if 1
12268 // DQ (12/4/2011): Set the scope first and then set the type (scope is required to compute the type (name mangling)).
12269 // DQ (12/4/2011): Now we want to enable this so that the SgClassType will be available from a SgTemplateClassDeclaration.
12270 if (nondefdecl->get_type() == NULL)
12271 {
12272 // nondefdecl->set_type(SgClassType::createType(nondefdecl));
12273 // nondefdecl->set_type(NULL);
12274 // nondefdecl->set_type(SgTemplateType::createType(nondefdecl));
12275 // nondefdecl->set_type(SgTemplateType::createType());
12276 nondefdecl->set_type(SgClassType::createType(nondefdecl));
12277 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12278#if 0
12279 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());
12280#endif
12281 }
12282#endif
12283
12284 // Build a SgTemplateClassSymbol and put it into the specified scope.
12285 if (scope != NULL)
12286 {
12287#if 0
12288 printf ("Building a SgTemplateSymbol using nameWithTemplateSpecializationArguments = %s and nondefdecl = %p = %s \n",nameWithTemplateSpecializationArguments.str(),nondefdecl,nondefdecl->class_name().c_str());
12289#endif
12290 // DQ (12/21/2011): We want to use a newer design that derives the SgTemplateClassDeclaration from the SgClassDeclaration.
12291 // mysymbol = new SgTemplateSymbol(nondefdecl);
12292 // mysymbol = new SgClassSymbol(nondefdecl);
12293 mysymbol = new SgTemplateClassSymbol(nondefdecl);
12294 ROSE_ASSERT(mysymbol != NULL);
12295
12296 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12297 // DQ (3/6/2012): Added test for existing symbol (see test2012_18.C).
12298 // ROSE_ASSERT(scope->lookup_template_class_symbol(name) == NULL);
12299 // ROSE_ASSERT(scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList) == NULL);
12300 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList) == NULL);
12301
12302 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12303 // scope->insert_symbol(name, mysymbol);
12304 scope->insert_symbol(nameWithTemplateSpecializationArguments, mysymbol);
12305#if 0
12306 printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi() (after building symbol): scope = %p = %s \n",scope,scope->class_name().c_str());
12307#endif
12308 ROSE_ASSERT(nondefdecl->get_scope() != NULL);
12309
12310 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
12311
12312 // DQ (9/12/2012): We want to include the template specialization into the name where it is required.
12313 // ROSE_ASSERT(scope->lookup_template_class_symbol(name) != NULL);
12314 // ROSE_ASSERT(scope->lookup_template_class_symbol(name,templateParameterList,templateSpecializationArgumentList) != NULL);
12315 ROSE_ASSERT(scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList) != NULL);
12316 }
12317 else
12318 {
12319 // Liao 9/2/2009: This is not an error. We support bottomup AST construction and scope can be unknown.
12320 }
12321
12322 testTemplateArgumentParents(nondefdecl);
12323
12324#if 1
12325 // DQ (7/16/2017): Added code to set the template parameters in the just build declaration (if it is a template declaration).
12326 // We want to set the parents of the template paremters to the frst nondefining template class declaration, and we want to reset
12327 // the scope of the declarations associated with any previously marked SgClassType objects associated with any template parameters.
12328 // printf ("SageBuilder::buildNondefiningTemplateClassDeclaration_nfi(): Calling setTemplateParametersInDeclaration(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
12329
12330 setTemplateParametersInDeclaration(nondefdecl,templateParameterList);
12331
12332 // DQ (8/13/2013): Adding test of template parameter lists.
12333 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(nondefdecl);
12334 ROSE_ASSERT(templateClassDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateClassDeclaration->get_templateParameters().size()));
12335#endif
12336 }
12337
12338 // defdecl->set_firstNondefiningDeclaration(nondefdecl);
12339
12340 // DQ (11/3/2012): Setup the default source position information.
12341 setSourcePosition(nondefdecl);
12342
12343#if 0
12344 // 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).
12345
12346 // Liao, 10/30/2009
12347 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
12348 // This is not desired when building a defining declaration and an inefficience in the constructor
12349 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
12350 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
12351 if (defdecl->get_type() != NULL)
12352 {
12353 // if a defining class declaration's type is associated with a defining class.
12354 // This is a wrong SgClassType and has to be reset
12355 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
12356 {
12357 delete defdecl->get_type();
12358 }
12359 }
12360
12361 // patch up the SgClassType for the defining class declaration
12362 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12363 ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
12364 defdecl->set_type(nondefdecl->get_type());
12365#else
12366 // printf ("We might need to force the types used for defining and non-defining SgTemplateClassDeclaration to be the same! \n");
12367 ROSE_ASSERT(nondefdecl->get_type() != NULL);
12368#endif
12369
12370 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
12371 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
12372 // used in a defining declaration).
12373 nondefdecl->setForward();
12374
12375 if (scope != NULL) // put into fixStructDeclaration() or alike later on
12376 {
12377 // fixStructDeclaration(defdecl,scope);
12378 // fixStructDeclaration(nondefdecl,scope);
12379
12380 // printf ("***** WARNING *****: Commented out call to fixStructDeclaration() \n");
12381 // ROSE_ASSERT(false);
12382 }
12383
12384#if 0
12385 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
12386 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
12387
12388 ROSE_ASSERT(defdecl->get_scope() != NULL);
12389#endif
12390
12391 // 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).
12392 ROSE_ASSERT(nondefdecl->get_parent() == NULL);
12393
12394 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
12395 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
12396
12397 testTemplateArgumentParents(nondefdecl);
12398
12399#if 0
12400 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12401 printf ("Leaving buildNondefiningTemplateClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
12402 SgClassDeclaration* tmp_classDeclaration = nondefdecl;
12403 SgSymbol* test_symbol = nondefdecl->get_scope()->find_symbol_from_declaration(tmp_classDeclaration);
12404
12405 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12406 printf ("Leaving buildNondefiningTemplateClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
12407 ROSE_ASSERT(nondefdecl->get_symbol_from_symbol_table() != NULL);
12408#endif
12409
12410 return nondefdecl;
12411 }
12412
12415 SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12416{
12417 SgTemplateClassDeclaration * res = buildTemplateClassDeclaration_nfi (XXX_name, kind, scope, nonDefiningDecl, templateParameterList, templateSpecializationArgumentList);
12419 return res;
12420}
12421
12424 SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateSpecializationArgumentList )
12425 {
12426 // DQ (12/26/2011): Notes that the input nonDefiningDecl is not used...this is a confusing point.
12427 // The specification of the scope appears to be enough.
12428
12429 if (scope == NULL)
12431
12432#if 0
12433 printf ("In buildTemplateClassDeclaration_nfi(): nonDefiningDecl = %p \n",nonDefiningDecl);
12434 if (nonDefiningDecl != NULL)
12435 {
12436 printf ("--- nonDefiningDecl->get_firstNondefiningDeclaration() = %p \n",nonDefiningDecl->get_firstNondefiningDeclaration());
12437 printf ("--- nonDefiningDecl->get_definingDeclaration() = %p \n",nonDefiningDecl->get_definingDeclaration());
12438 }
12439#endif
12440
12441 // DQ (11/20/2011): This is for initial debugging only.
12442 ROSE_ASSERT(scope != NULL);
12443
12444 // 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.
12445 SgName nameWithoutTemplateArguments = XXX_name;
12446 SgName nameWithTemplateSpecializationArguments = appendTemplateArgumentsToName(nameWithoutTemplateArguments,*templateSpecializationArgumentList);
12447
12448 // step 1. Build defining declaration
12449 // Note that even the SgTemplateClassDeclaration uses a regular SgClassDefinition instead of the currently unused SgTemplateClassDefinition.
12450 // SgClassDefinition* classDef = buildClassDefinition();
12451 // SgTemplateClassDefinition* classDef = buildTemplateClassDefinition(name,);
12452
12453 // DQ (11/29/2011): Added checks...
12454 if (nonDefiningDecl != NULL)
12455 {
12456 ROSE_ASSERT(nonDefiningDecl->get_firstNondefiningDeclaration() == nonDefiningDecl);
12457 }
12458
12459 SgName templateString = "template string";
12460 // SgTemplateDeclaration::template_type_enum template_kind = SgTemplateDeclaration::e_template_class;
12461 SgTemplateParameterPtrList templateParameters;
12462
12463 // SgTemplateDeclaration (SgName name, SgName string, SgTemplateDeclaration::template_type_enum template_kind, SgTemplateParameterPtrList templateParameters)
12464 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,kind,NULL,classDef);
12465 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters);
12466
12467 // SgTemplateClassDeclaration::class_types template_class_kind = SgTemplateClassDeclaration::e_class;
12468 // SgTemplateType* classType = NULL;
12469 // SgTemplateClassDefinition* classDef = NULL;
12471
12472 // Constructure arguments: SgName, SgName, SgTemplateDeclaration::template_type_enum, SgTemplateParameterPtrList, SgTemplateClassDeclaration::class_types, SgClassType*, SgTemplateClassDefinition*
12473 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters);
12474 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,template_class_kind,classType,classDef);
12475 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,templateString,template_kind,templateParameters,template_class_kind,classDef);
12476
12477#if 0
12478 printf ("In buildTemplateClassDeclaration_nfi(): calling new SgTemplateClassDeclaration() name = %s \n",nameWithTemplateSpecializationArguments.str());
12479#endif
12480
12481 // DQ (9/12/2012): We want to include the template specialization into the name where it is required (this handling
12482 // is similar to normal template arguments for non-template declaration, but different than template parameters).
12483 // This copy of SgName is required to support passing it to the SgTemplateClassDeclaration constructor.
12484 // SgName localName = name;
12485 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,template_class_kind,classDef);
12486 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (name,kind,NULL,classDef);
12487
12488 // DQ (1/13/2013): This is causing two defining declarations to be built for test2012_278.C (and the parent for the second defining
12489 // declaration is not being set, though the larger issue is that we have two defining declarations, however this might be acceptable
12490 // if this is a specialization).
12491 // SgTemplateClassDeclaration* defdecl = new SgTemplateClassDeclaration (nameWithTemplateSpecializationArguments,kind,NULL,classDef);
12492 SgTemplateClassDeclaration* defdecl = NULL;
12493 if (nonDefiningDecl != NULL)
12494 {
12495 // If we have a non-defining declaration specified, try to use any existing defining declaration withouth building a 2nd one
12496 // (which would be an error, unless maybe if this is a specialization).
12497 if (nonDefiningDecl->get_definingDeclaration() != NULL)
12498 {
12499 // This must be a valid SgTemplateClassDefinition.
12500 defdecl = isSgTemplateClassDeclaration(nonDefiningDecl->get_definingDeclaration());
12501 ROSE_ASSERT(defdecl != NULL);
12502#if 0
12503 printf ("In buildTemplateClassDeclaration_nfi(): Reusing the defining declaration previously build: defdecl = %p = %s \n",defdecl,defdecl->get_name().str());
12504#endif
12505 }
12506 else
12507 {
12508#if 0
12509 printf ("In buildTemplateClassDeclaration_nfi(): No defining declaration found, so we have to build one. \n");
12510#endif
12511 }
12512 }
12513
12514 if (defdecl == NULL)
12515 {
12516#if 0
12517 printf ("Building a defining declaration \n");
12518#endif
12519 defdecl = new SgTemplateClassDeclaration (nameWithTemplateSpecializationArguments,kind,NULL,classDef);
12520 }
12521
12522 ROSE_ASSERT(defdecl != NULL);
12523
12524#if 0
12525 printf ("In buildTemplateClassDeclaration_nfi(): defdecl = %p = %s \n",defdecl,defdecl->class_name().c_str());
12526#endif
12527
12528 // DQ (9/10/2012): Initialize the template parameter list.
12529 ROSE_ASSERT(templateParameterList != NULL);
12530 defdecl->get_templateParameters() = *templateParameterList;
12531
12532 // DQ (9/12/2012): Adding support for template specialization.
12533 ROSE_ASSERT(templateSpecializationArgumentList != NULL);
12534 defdecl->get_templateSpecializationArguments() = *templateSpecializationArgumentList;
12535
12536 // DQ (9/16/2012): We can't test this yet, since the firstNondefiningDeclaration has not be set.
12537 // testTemplateArgumentParents(defdecl);
12538
12539 // DQ (9/10/2012): Test the just built template with its template parameters.
12540 if (defdecl->get_templateParameters().size() == 0)
12541 {
12542#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12543 printf ("WARNING: In buildTemplateClassDeclaration_nfi(): defdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations defdecl = %p \n",defdecl);
12544#endif
12545 }
12546 // ROSE_ASSERT(defdecl->get_templateParameters().size() > 0);
12547
12548 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12549 defdecl->set_templateName(nameWithoutTemplateArguments);
12550
12551#if 0
12552 printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): scope = %p = %s \n",scope,scope->class_name().c_str());
12553#endif
12554
12555 defdecl->set_scope(scope);
12556
12557 // 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.
12558 // DQ (11/20/2011): Can name qualification make this incorrect?
12559 // defdecl->set_parent(scope);
12560
12561 ROSE_ASSERT(classDef != NULL);
12562
12563 // printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): defdecl = %p \n",defdecl);
12564
12566
12567 // constructor is side-effect free
12568 classDef->set_declaration(defdecl);
12569 defdecl->set_definingDeclaration(defdecl);
12570
12571 // Step 2. build the nondefining declaration,
12572 // but only if the input nonDefiningDecl pointer was NULL and it does not exist
12573
12574 // Get the nondefining declaration from the symbol if it has been built (if this works,
12575 // then we likely don't need the "SgClassDeclaration* nonDefiningDecl" parameter).
12576 SgTemplateClassDeclaration* nondefdecl = nonDefiningDecl;
12577 if (nondefdecl == NULL) {
12578 ROSE_ASSERT(scope != NULL);
12579
12580 SgClassSymbol* mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
12581#if 0
12582 printf ("In buildTemplateClassDeclaration_nfi(): mysymbol = %p \n",mysymbol);
12583#endif
12584
12585 if (mysymbol != NULL) {
12586 nondefdecl = isSgTemplateClassDeclaration(mysymbol->get_declaration());
12587 ROSE_ASSERT(nondefdecl != NULL);
12588
12589 nondefdecl->set_definingDeclaration(defdecl);
12590 ROSE_ASSERT(nondefdecl->get_definingDeclaration() == defdecl);
12591 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != defdecl);
12592
12593 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
12594 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
12595
12596 // DQ (9/16/2012): Test this previously setup firstNondefiningDeclaration.
12597 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() == nondefdecl);
12598 testTemplateArgumentParents(nondefdecl);
12599 } else {
12600#if 0
12601 printf(" start build non-defn decl for %p\n",defdecl);
12602#endif
12603 // DQ (1/25/2009): We only want to build a new declaration if we can't reuse the existing declaration.
12604 nondefdecl = new SgTemplateClassDeclaration(nameWithTemplateSpecializationArguments,kind,NULL,NULL);
12605 ROSE_ASSERT(nondefdecl != NULL);
12606
12607 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12608 nondefdecl->set_definingDeclaration(defdecl);
12609#if 0
12610 printf(" nondefdecl = %p\n",nondefdecl);
12611#endif
12612#if 0
12613 // TV (04/12/2018): Add a scope for nonreal classes (and their member) on the first non-defining declaration of template classes
12614 SgDeclarationScope * nonreal_decl_scope = new SgDeclarationScope();
12615
12616 nonreal_decl_scope->set_parent(nondefdecl);
12617 nondefdecl->set_nonreal_decl_scope(nonreal_decl_scope);
12618
12619 SageInterface::setSourcePosition(nonreal_decl_scope);
12620 nonreal_decl_scope->get_startOfConstruct()->setCompilerGenerated();
12621 nonreal_decl_scope->get_endOfConstruct()->setCompilerGenerated();
12622#if 1
12623 printf("In buildTemplateClassDeclaration_nfi(): nrscope = %p\n", nonreal_decl_scope);
12624#endif
12625#endif
12626 // DQ (9/10/2012): Initialize the template parameter list.
12627 ROSE_ASSERT(templateParameterList != NULL);
12628 nondefdecl->get_templateParameters() = *templateParameterList;
12629
12630 // DQ (9/16/2012): Newly refactored code.
12631 setTemplateSpecializationArgumentsInDeclaration(nondefdecl,templateSpecializationArgumentList);
12632 testTemplateArgumentParents(nondefdecl);
12633
12634 // DQ (9/10/2012): Test the just built template with its template parameters.
12635 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12636 if (nondefdecl->get_templateParameters().size() == 0)
12637 {
12638#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
12639 printf ("WARNING: In buildTemplateClassDeclaration_nfi(): nondefdecl->get_templateParameters().size() == 0: OK for nested classes/structs in template declarations nondefdecl = %p \n",nondefdecl);
12640#endif
12641 }
12642 // ROSE_ASSERT(nondefdecl->get_templateParameters().size() > 0);
12643#if 0
12644 printf(" next 1\n");
12645#endif
12646
12647 // DQ (9/12/2012): Set the template name to be the name without template specialization arguments.
12648 nondefdecl->set_templateName(nameWithoutTemplateArguments);
12649
12650 // DQ (12/26/2011): The non defining declaration should not have a valid pointer to the class definition.
12651 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
12652
12653 // The nondefining declaration will not appear in the source code, but is compiler
12654 // generated (so we have something about the class that we can reference; e.g in
12655 // types). At the moment we make it a transformation, there might be another kind
12656 // of source position that would be more precise. FIXME.
12658 ROSE_ASSERT (nondefdecl->get_startOfConstruct() != NULL);
12659
12660 nondefdecl->setForward();
12661
12662 // Liao, 9/2/2009. scope stack is optional, it can be empty
12663 nondefdecl->set_parent(scope);
12664 nondefdecl->set_scope(scope);
12665#if 0
12666 printf(" next 2\n");
12667#endif
12668
12669 if (nondefdecl->get_type() == NULL)
12670 {
12671 nondefdecl->set_type(SgClassType::createType(nondefdecl));
12672#if 0
12673 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());
12674#endif
12675 }
12676#if 0
12677 printf(" next 3\n");
12678#endif
12679
12680 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
12681 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
12682
12683 // DQ (7/16/2017): Added code to set the template parameters in the just build declaration (if it is a template declaration).
12684 // We want to set the parents of the template paremters to the frst nondefining template class declaration, and we want to reset
12685 // the scope of the declarations associated with any previously marked SgClassType objects associated with any template parameters.
12686 // printf ("SageBuilder::buildTemplateClassDeclaration_nfi(): Calling setTemplateParametersInDeclaration(): nameWithTemplateSpecializationArguments = %s \n",nameWithTemplateSpecializationArguments.str());
12687
12688 setTemplateParametersInDeclaration(nondefdecl,templateParameterList);
12689
12690 // DQ (8/13/2013): Adding test of template parameter lists.
12691 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(nondefdecl);
12692 ROSE_ASSERT(templateClassDeclaration == NULL || (templateParameterList != NULL && templateParameterList->size() == templateClassDeclaration->get_templateParameters().size()));
12693
12694 mysymbol = new SgTemplateClassSymbol(nondefdecl);
12695 scope->insert_symbol(nameWithTemplateSpecializationArguments, mysymbol);
12696#if 0
12697 printf(" end build non-defn decl\n");
12698#endif
12699 }
12700 } else {
12701 SgClassSymbol* mysymbol = scope->lookup_template_class_symbol(nameWithTemplateSpecializationArguments,templateParameterList,templateSpecializationArgumentList);
12702 if (mysymbol == NULL) {
12703 printf("WARNING: In buildTemplateClassDeclaration_nfi(): non-defining declaration was provided but cannot be located in the associated scope.\n");
12704 }
12705 }
12706
12707#if 0
12708 printf ("In buildTemplateClassDeclaration_nfi(): Setting the firstNondefiningDeclaration to be nondefdecl = %p \n",nondefdecl);
12709#endif
12710
12711 defdecl->set_firstNondefiningDeclaration(nondefdecl);
12712
12713 // DQ (9/16/2012): Setup the template specialization arguments on the defining declaration (tested below at base of function).
12714 setTemplateSpecializationArgumentsInDeclaration(defdecl,templateSpecializationArgumentList);
12715
12716#if 1
12717 // 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).
12718
12719 // Liao, 10/30/2009
12720 // The SgClassDeclaration constructor will automatically generate a SgClassType internally if NULL is passed for SgClassType
12721 // This is not desired when building a defining declaration and an inefficience in the constructor
12722 // Ideally, only the first nondefining class declaration should have a dedicated SgClassType and
12723 // the defining class declaration (and other nondefining declaration) just shared that SgClassType.
12724 if (defdecl->get_type() != NULL)
12725 {
12726 // if a defining class declaration's type is associated with a defining class.
12727 // This is a wrong SgClassType and has to be reset
12728#if 0
12729 // if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
12730 if (defdecl->get_type()->get_declaration() == isSgDeclarationStatement(defdecl) )
12731 {
12732 delete defdecl->get_type();
12733 }
12734#else
12735 // DQ (1/13/2013): I am not clear what this means... if (defdecl->get_type() != NULL) then it makes
12736 // no sense to assert that (defdecl->get_type() == NULL). This is related to the reuse of the defining
12737 // declaration when it is available (instead of building a new one, which still might be required for a
12738 // template specialization (or template partial specialization)).
12739 // ROSE_ASSERT(defdecl->get_type() == NULL);
12740#endif
12741 }
12742
12743 // patch up the SgClassType for the defining class declaration
12744 ROSE_ASSERT (nondefdecl->get_type() != NULL);
12745 // ROSE_ASSERT (nondefdecl->get_type()->get_declaration() == isSgDeclarationStatement(nondefdecl));
12746
12747 // DQ (1/22/2013): This assertion is a problem for boost code represented by ROSE compiling ROSE (see testRoseHeaders_01.C)
12748 if (isSgClassType(nondefdecl->get_type())->get_declaration() != isSgDeclarationStatement(nondefdecl))
12749 {
12750#if 0
12751 printf ("In buildTemplateClassDeclaration_nfi(): detected isSgClassType(nondefdecl->get_type())->get_declaration() != isSgDeclarationStatement(nondefdecl) (problem with Boost code in ROSE compiling ROSE) \n");
12752#endif
12753 }
12754 // ROSE_ASSERT (isSgClassType(nondefdecl->get_type())->get_declaration() == isSgDeclarationStatement(nondefdecl));
12755
12756 defdecl->set_type(nondefdecl->get_type());
12757
12758#if 0
12759 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());
12760#endif
12761#endif
12762
12763 // I don't think this is always a forward declaration (e.g. if it is not used in a prototype).
12764 // Checking the olded EDG/ROSE interface it appears that it is always marked forward (unless
12765 // used in a defining declaration).
12766 nondefdecl->setForward();
12767
12768#if 0
12769 if (scope != NULL) // put into fixStructDeclaration() or alike later on
12770 {
12771 // fixStructDeclaration(defdecl,scope);
12772 // fixStructDeclaration(nondefdecl,scope);
12773
12774 printf ("***** WARNING *****: Commented out call to fixStructDeclaration() \n");
12775 // ROSE_ASSERT(false);
12776 }
12777#endif
12778
12779 ROSE_ASSERT(defdecl->get_definingDeclaration() == defdecl);
12780 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != defdecl->get_definingDeclaration());
12781
12782 ROSE_ASSERT(defdecl->get_scope() != NULL);
12783
12784 // DQ (12/4/2011): We need a concept for type for SgTemplateClassDeclaration so that we can construct SgMemberFunctionType nodes for template member functions.
12785 // We use a SgClassType which has been fixed to permit it to hold either a SgClassDeclaration or an SgTemplateClassDeclaration.
12786 ROSE_ASSERT(defdecl->get_type() != NULL);
12787
12788 // DQ (12/26/2011): The non defining declaration should not have a valid pointer to the class definition.
12789 ROSE_ASSERT(nondefdecl->get_definition() == NULL);
12790
12791 // DQ (7/15/2012): We want to inforce this.
12792 // ROSE_ASSERT(defdecl->get_parent() == NULL);
12793 if (defdecl->get_parent() != NULL)
12794 {
12795#if PRINT_DEVELOPER_WARNINGS
12796 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());
12797#endif
12798 }
12799
12800 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
12801 ROSE_ASSERT(defdecl->get_templateName().is_null() == false);
12802
12803 // DQ (9/12/2012): Test that the templateName is set (name without template specialization parameters).
12804 ROSE_ASSERT(nondefdecl->get_templateName().is_null() == false);
12805
12807 testTemplateArgumentParents(nondefdecl);
12808
12809#if 0
12810 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12811 printf ("Leaving buildTemplateClassDeclaration_nfi(): Calling find_symbol_from_declaration() \n");
12812 SgClassDeclaration* tmp_classDeclaration = defdecl;
12813 SgSymbol* test_symbol = defdecl->get_scope()->find_symbol_from_declaration(tmp_classDeclaration);
12814
12815 // DQ (1/27/2019): Test that symbol table to debug Cxx11_tests/test2019)33.C.
12816 printf ("Leaving buildTemplateClassDeclaration_nfi(): Calling get_symbol_from_symbol_table() \n");
12817 ROSE_ASSERT(defdecl->get_symbol_from_symbol_table() != NULL);
12818#endif
12819
12820 return defdecl;
12821 }
12822
12824 {
12825 // DQ (1/11/2009): This function has semantics very different from the buildEnumDeclaration_nfi() function!
12826
12827 if (scope == NULL)
12829
12830 SgEnumDeclaration* decl = buildEnumDeclaration_nfi(name, scope);
12834
12835 // DQ (7/15/2012): We want to inforce this.
12836 ROSE_ASSERT(decl->get_parent() == NULL);
12837
12838 return decl;
12839 } //buildEnumDeclaration()
12840
12841
12844 {
12845 // The support for SgEnumDeclaration is identical to that for SgClassDeclaration (except for the type handling, why is that?).
12846 ASSERT_not_null(scope);
12847
12848 // DQ (7/27/2012): Note that the input name should not have template argument syntax.
12849 // I think this could still fail for a function with a name such as "X<Y>" strange converstion operators.
12850 ASSERT_require(SageInterface::hasTemplateSyntax(name) == false);
12851
12852 SgEnumType* enumType = nullptr;
12853 SgEnumDeclaration* first_nondefdecl = nullptr;
12854
12855 if (scope)
12856 {
12857 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
12858 if (existing_symbol != NULL)
12859 {
12860 enumType = isSgEnumType(existing_symbol->get_type());
12861 first_nondefdecl = existing_symbol->get_declaration();
12862 ROSE_ASSERT(first_nondefdecl != NULL);
12863 }
12864 }
12865
12866 // DQ (5/8/2013): We do want to build a new SgEnumDeclaration (to avoid sharing).
12867 // This forces each call to buildNondefiningEnumDeclaration_nfi() to build a unique declaration
12868 // required to avoid sharing declaration in examples such as test2007_29.C.
12869 SgEnumDeclaration* nondefdecl = new SgEnumDeclaration(name, enumType);
12870
12871 ROSE_ASSERT(nondefdecl);
12872 setOneSourcePositionNull(nondefdecl);
12873
12874 // Set the defining and first non-defining declarations.
12875 if (first_nondefdecl)
12876 {
12877 nondefdecl->set_firstNondefiningDeclaration(first_nondefdecl);
12878 nondefdecl->set_definingDeclaration(first_nondefdecl->get_definingDeclaration());
12879 }
12880 else
12881 {
12882 nondefdecl->set_firstNondefiningDeclaration(nondefdecl);
12883 nondefdecl->set_definingDeclaration(nullptr);
12884 }
12885
12886 // Any non-defining declaration is not always a forward declaration.
12887 nondefdecl->setForward();
12888
12889 SgType* type = nondefdecl->get_type();
12890 ASSERT_not_null(type);
12891
12892 if (scope)
12893 {
12894 // Check for an existing symbol (reuse it if it is found).
12895 SgEnumSymbol* mysymbol = nullptr;
12896 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
12897
12898 if (existing_symbol)
12899 {
12900 mysymbol = existing_symbol;
12901 first_nondefdecl = mysymbol->get_declaration();
12902 }
12903 else
12904 {
12905 first_nondefdecl = nondefdecl;
12906
12907 mysymbol = new SgEnumSymbol(nondefdecl);
12908 ASSERT_not_null(mysymbol);
12909 scope->insert_symbol(name, mysymbol);
12910 }
12911
12912 nondefdecl->set_scope(scope);
12913
12914 // Can this be defined in C++ so that it is in a logical scope different from its structural scope?
12915 nondefdecl->set_parent(scope);
12916 }
12917
12918 if (first_nondefdecl != nondefdecl)
12919 {
12920 nondefdecl->set_firstNondefiningDeclaration(first_nondefdecl);
12921
12922 if (first_nondefdecl->get_definingDeclaration() != NULL)
12923 {
12924 nondefdecl->set_definingDeclaration(first_nondefdecl->get_definingDeclaration());
12925 }
12926 }
12927
12928 ASSERT_not_null(nondefdecl->get_type());
12929 ASSERT_not_null(scope->lookup_enum_symbol(name));
12930
12931 return nondefdecl;
12932 }
12933
12934
12937 {
12938 ROSE_ASSERT(scope != NULL);
12939
12940#if 0
12941 printf ("In buildEnumDeclaration_nfi(): name = %s scope = %p = %s \n",name.str(),scope,scope->class_name().c_str());
12942#endif
12943
12944 // DQ (5/8/2013): I think if we searched for the type it might exist and this would allow the types to be shared.
12945 SgEnumType* enumType = NULL;
12946
12947 if (scope != NULL)
12948 {
12949 SgEnumSymbol* existing_symbol = scope->lookup_enum_symbol(name);
12950 if (existing_symbol != NULL)
12951 {
12952 enumType = isSgEnumType(existing_symbol->get_type());
12953 }
12954 }
12955
12956#if 0
12957 printf ("In buildEnumDeclaration_nfi(): name = %s building using enumType = %p \n",name.str(),enumType);
12958#endif
12959
12960 // SgEnumDeclaration* defdecl = new SgEnumDeclaration (name,NULL);
12961 SgEnumDeclaration* defdecl = new SgEnumDeclaration (name,enumType);
12962 ROSE_ASSERT(defdecl);
12963
12964#if 0
12965 printf ("In buildEnumDeclaration_nfi(): built defining declaration = %p name = %s scope = %p = %s \n",defdecl,name.str(),scope,scope->class_name().c_str());
12966#endif
12967
12968 // DQ (5/8/2013): Make sure that the enum type is available.
12969 SgType* type = defdecl->get_type();
12970 ROSE_ASSERT(type != NULL);
12971
12972 setOneSourcePositionNull(defdecl);
12973 // constructor is side-effect free
12974 defdecl->set_definingDeclaration(defdecl);
12975
12976#if 0
12977 printf ("In buildEnumDeclaration_nfi(): name = %s \n",name.str());
12978#endif
12979
12980#if 1
12981 // DQ (4/3/2017): Check for an existing non-defining declaration before building one (to avoid multiple versions). See test2017_13.C.
12982 ROSE_ASSERT(scope != NULL);
12983 SgEnumSymbol* enumSymbol = scope->lookup_enum_symbol(name);
12984 // ROSE_ASSERT(enumSymbol != NULL);
12985 SgEnumDeclaration* nondefdecl = NULL;
12986 if (enumSymbol != NULL)
12987 {
12988 ROSE_ASSERT(enumSymbol->get_declaration() != NULL);
12989 nondefdecl = enumSymbol->get_declaration();
12990 ROSE_ASSERT(nondefdecl != NULL);
12991 }
12992 else
12993 {
12994 // build the nondefining declaration
12995 nondefdecl = buildNondefiningEnumDeclaration_nfi(name, scope);
12996#if 0
12997 printf ("###### In buildEnumDeclaration_nfi(): built a non-defining declaration to support the symbol table: name = %s nondefdecl = %p \n",name.str(),nondefdecl);
12998#endif
12999 }
13000#else
13001 // build the nondefining declaration
13002 SgEnumDeclaration* nondefdecl = buildNondefiningEnumDeclaration_nfi(name, scope);
13003#endif
13004
13005 nondefdecl->set_definingDeclaration(defdecl);
13006 // defdecl->set_firstNondefiningDeclaration(nondefdecl);
13008
13009 // DQ (4/22/2013): We need to set the defining declaration on the first non-defining declaration.
13010 if (nondefdecl->get_firstNondefiningDeclaration() != NULL && nondefdecl->get_firstNondefiningDeclaration() != nondefdecl)
13011 {
13013 }
13014
13015 // DQ (4/22/2013): Thing that should be true at this point.
13016 ROSE_ASSERT(nondefdecl->get_definingDeclaration() != NULL);
13017 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration() != NULL);
13018 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration()->get_definingDeclaration() != NULL);
13019 ROSE_ASSERT(nondefdecl->get_firstNondefiningDeclaration()->get_firstNondefiningDeclaration() != NULL);
13020 ROSE_ASSERT(defdecl->get_definingDeclaration() != NULL);
13021 ROSE_ASSERT(defdecl->get_firstNondefiningDeclaration() != NULL);
13022
13023 // DQ (1/11/2009): The buildNondefiningEnumDeclaration function builds an entry in the symbol table, and so we don't want a second one!
13024#if 0
13025 SgEnumSymbol* mysymbol = new SgEnumSymbol(nondefdecl);
13026 ROSE_ASSERT(mysymbol);
13027 // scope->print_symboltable("buildEnumDeclaration_nfi(): before inserting new SgEnumSymbol");
13028 scope->insert_symbol(name, mysymbol);
13029#endif
13030
13031 defdecl->set_scope(scope);
13032 nondefdecl->set_scope(scope);
13033
13034#if 0
13035 // 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).
13036 defdecl->set_parent(scope);
13037 nondefdecl->set_parent(scope);
13038#endif
13039
13040 // DQ (7/12/2012): When this is an unnamed enum declaration, this it is NON-AUTONIMOUS
13041 // (and will have it's parent set in the associated variable or typedef declaration.
13042 // In the case of a class declaration this is always NULL (this should be similar).
13043 ROSE_ASSERT(defdecl->get_parent() == NULL);
13044
13045#if 0
13046 printf ("In buildEnumDeclaration_nfi(): name = %s defdecl = %p \n",name.str(),defdecl);
13047#endif
13048
13049 // DQ (5/8/2013): Check that the symbol is present.
13050 ROSE_ASSERT(scope->lookup_enum_symbol(name) != NULL);
13051
13052 return defdecl;
13053 } //buildEnumDeclaration_nfi()
13054
13055
13057SageBuilder::buildBaseClass ( SgClassDeclaration* classDeclaration, SgClassDefinition* classDefinition, bool isVirtual, bool isDirect )
13058 {
13059 // DQ (5/6/2013): Refactored the construction of the SgBaseClass support to the builder API.
13060
13061 // Note: classDeclaration should be the first non-defining class declaration, not required to be the the declaration associated with the SgClassDefinition.
13062 ROSE_ASSERT(classDeclaration != NULL);
13063 ROSE_ASSERT(classDefinition != NULL);
13064
13065 // DQ (5/6/2013): This is not always true (see test2013_63.C).
13066 // ROSE_ASSERT(classDeclaration == classDeclaration->get_firstNondefiningDeclaration());
13067
13068 ROSE_ASSERT(classDefinition->get_declaration() != NULL);
13069
13070 // DQ (5/6/2013): This is not always true (see test2004_30.C).
13071 // ROSE_ASSERT(classDefinition->get_declaration() == classDeclaration->get_firstNondefiningDeclaration());
13072
13073 SgBaseClass* baseclass = new SgBaseClass ( classDeclaration, isDirect );
13074 ROSE_ASSERT(baseclass != NULL);
13075
13076 if (isVirtual == true)
13077 {
13078 // DQ (1/21/2019): get_baseClassModifier() uses ROSETTA generated access functions which return a pointer.
13079 // baseclass->get_baseClassModifier().setVirtual();
13080 ROSE_ASSERT(baseclass->get_baseClassModifier() != NULL);
13081 baseclass->get_baseClassModifier()->setVirtual();
13082 }
13083
13084 // DQ (4/29/2004): add support to set access specifier
13085 // baseclass->get_baseClassModifier().get_accessModifier() = set_access_modifiers(bcdp->access);
13086 // baseclass->get_baseClassModifier().get_accessModifier() = buildAccessModifier(accessModifiers);
13087
13088 // DQ (6/21/2005): Set the parent of the base class to the class definition
13089 // (these are not traversed in ROSE currently, so their parents are not set).
13090 baseclass->set_parent(classDefinition);
13091
13092 // DQ (6/21/2005): Notice that this is copied by value (the base class list should be a list of pointers to SgBaseClass (later)
13093 classDefinition->append_inheritance(baseclass);
13094
13095 return baseclass;
13096 }
13097
13098
13100SageBuilder::buildNonrealBaseClass ( SgNonrealDecl* nrdecl, SgClassDefinition* classDefinition, bool isVirtual, bool isDirect )
13101 {
13102 ROSE_ASSERT(nrdecl != NULL);
13103 ROSE_ASSERT(classDefinition != NULL);
13104
13105 SgNonrealBaseClass * baseclass = new SgNonrealBaseClass ( NULL , isDirect , nrdecl );
13106 ROSE_ASSERT(baseclass != NULL);
13107
13108 if (isVirtual == true)
13109 {
13110 baseclass->get_baseClassModifier()->setVirtual();
13111 }
13112
13113 baseclass->set_parent(classDefinition);
13114
13115 classDefinition->append_inheritance(baseclass);
13116
13117 return baseclass;
13118 }
13119
13120
13121#if 0
13122// This function would be more complex that I want to support at present since the mapping of
13123// edg modifier values to ROSE modifier values is offset and backwards (reversed in numerical order).
13125SageBuilder::buildAccessModifier ( unsigned int access )
13126 {
13128
13129 switch (access)
13130 {
13131 case as_public:
13132#if 0
13133 printf ("In SageBuilder::set_access_modifiers(): Mark as public \n");
13134#endif
13135 a.setPublic();
13136 break;
13137
13138 case as_protected:
13139#if 0
13140 printf ("In SageBuilder::set_access_modifiers(): Mark as protected \n");
13141#endif
13142 a.setProtected();
13143 break;
13144
13145 case as_private:
13146#if 0
13147 printf ("In SageBuilder::set_access_modifiers(): Mark as private \n");
13148#endif
13149 a.setPrivate();
13150 break;
13151
13152 default:
13153 printf ("Error: default reached in SageBuilder::set_access_modifiers() \n");
13154 ROSE_ABORT ();
13155 }
13156
13157 return a;
13158 }
13159#endif
13160
13161
13162void
13163SageBuilder::fixupSourcePositionFileSpecification(SgNode* subtreeRoot, const std::string& newFileName)
13164 {
13165 // DQ (11/8/2019): This function changes the filename designation in all of the Sg_File_Info objects
13166 // associated with the designated AST subtree.
13167
13168 ROSE_ASSERT(subtreeRoot != NULL);
13169 ROSE_ASSERT(newFileName != "");
13170
13171#define DEBUG_FIXUP 0
13172
13173#if DEBUG_FIXUP
13174 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): newFileName = %s \n",newFileName.c_str());
13175 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13176#endif
13177
13178 class Traversal : public AstSimpleProcessing
13179 {
13180 public:
13181
13182 Traversal(const std::string& tmp_newFileName, int tmp_new_file_id, int tmp_originalFileId)
13183 {
13184 newFileName = tmp_newFileName;
13185 new_file_id = tmp_new_file_id;
13186 originalFileId = tmp_originalFileId;
13187#if DEBUG_FIXUP
13188 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): newFileName = %s new_file_id = %d originalFileId = %d \n",newFileName.c_str(),new_file_id,originalFileId);
13189#endif
13190 }
13191
13192 void visit (SgNode* node)
13193 {
13194#if DEBUG_FIXUP
13195 printf ("In fixupSourcePositionFileSpecification visit(): node = %p = %s \n",node,node->class_name().c_str());
13196#endif
13197
13198 SgLocatedNode* locatedNode = isSgLocatedNode(node);
13199 if (locatedNode != NULL)
13200 {
13201 // if (locatedNode->get_startOfConstruct()->get_file_id() == originalFileId)
13202 if (locatedNode->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13203 {
13204 ROSE_ASSERT(locatedNode->get_startOfConstruct() != NULL);
13205 ROSE_ASSERT(locatedNode->get_endOfConstruct() != NULL);
13206
13207 if (locatedNode->get_startOfConstruct()->isShared() == true)
13208 {
13209#if DEBUG_FIXUP
13210 printf ("Found SgLocatedNode marked as isShared() == true: locatedNode = %p = %s \n",locatedNode,locatedNode->class_name().c_str());
13211#endif
13212#if 0
13213 printf ("Exiting as a test! \n");
13214 ROSE_ABORT();
13215#endif
13216 }
13217 locatedNode->get_startOfConstruct()->set_file_id(new_file_id);
13218 locatedNode->get_endOfConstruct ()->set_file_id(new_file_id);
13219
13220 locatedNode->get_startOfConstruct()->set_physical_file_id(new_file_id);
13221 locatedNode->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13222
13223#if DEBUG_FIXUP
13224 printf ("locatedNode->get_startOfConstruct()->get_filename() = %s locatedNode->get_startOfConstruct()->get_physical_filename() = %s \n",
13225 locatedNode->get_startOfConstruct()->get_filenameString().c_str(),locatedNode->get_startOfConstruct()->get_physical_filename().c_str());
13226 printf ("locatedNode->get_startOfConstruct()->get_file_id() = %d locatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",
13227 locatedNode->get_startOfConstruct()->get_file_id(),locatedNode->get_startOfConstruct()->get_physical_file_id());
13228 printf ("locatedNode->get_startOfConstruct()->isShared() = %s \n",locatedNode->get_startOfConstruct()->isShared() ? "true" : "false");
13229#endif
13230 }
13231 else
13232 {
13233#if DEBUG_FIXUP
13234 printf ("NOT MATCHING: originalFileId = %d locatedNode->get_startOfConstruct()->get_file_id() = %d locatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",
13235 originalFileId,locatedNode->get_startOfConstruct()->get_file_id(),locatedNode->get_startOfConstruct()->get_physical_file_id());
13236 printf (" ------------ originalFileId = %d locatedNode->get_endOfConstruct()->get_file_id() = %d locatedNode->get_endOfConstruct()->get_physical_file_id() = %d \n",
13237 originalFileId,locatedNode->get_endOfConstruct()->get_file_id(),locatedNode->get_endOfConstruct()->get_physical_file_id());
13238#endif
13239 }
13240 }
13241 else
13242 {
13243 SgInitializedName* initializedName = isSgInitializedName(node);
13244 if (initializedName != NULL)
13245 {
13246 // if (initializedName->get_startOfConstruct()->get_file_id() == originalFileId)
13247 if (initializedName->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13248 {
13249 ROSE_ASSERT(initializedName->get_startOfConstruct() != NULL);
13250 ROSE_ASSERT(initializedName->get_endOfConstruct() != NULL);
13251
13252 initializedName->get_startOfConstruct()->set_file_id(new_file_id);
13253 initializedName->get_endOfConstruct ()->set_file_id(new_file_id);
13254
13255 initializedName->get_startOfConstruct()->set_physical_file_id(new_file_id);
13256 initializedName->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13257 }
13258 }
13259 else
13260 {
13261 SgSourceFile* sourceFile = isSgSourceFile(node);
13262 if (sourceFile != NULL)
13263 {
13264 ROSE_ASSERT(sourceFile->get_startOfConstruct() != NULL);
13265#if 0
13266 // A SgSourceFile has no endOfConstruct.
13267 if (sourceFile->get_endOfConstruct() == NULL)
13268 {
13269#if 0
13270 printf ("sourceFile->get_endOfConstruct() == NULL: fixup endOfConstruct \n");
13271#endif
13272 sourceFile->set_endOfConstruct(new Sg_File_Info());
13273 *(sourceFile->get_endOfConstruct()) = *(sourceFile->get_startOfConstruct());
13274 }
13275 ROSE_ASSERT(sourceFile->get_endOfConstruct() != NULL);
13276#endif
13277 // Need to test the physical_file_id because we already set the regular file_id (as part of seeding the process).
13278 // if (sourceFile->get_startOfConstruct()->get_file_id() == originalFileId)
13279 if (sourceFile->get_startOfConstruct()->get_physical_file_id() == originalFileId)
13280 {
13281 sourceFile->get_startOfConstruct()->set_file_id(new_file_id);
13282 sourceFile->get_startOfConstruct()->set_physical_file_id(new_file_id);
13283#if DEBUG_FIXUP
13284 printf ("sourceFile->get_startOfConstruct()->get_file_id() = %d \n",sourceFile->get_startOfConstruct()->get_file_id());
13285 printf ("sourceFile->get_startOfConstruct()->get_physical_file_id() = %d \n",sourceFile->get_startOfConstruct()->get_physical_file_id());
13286#endif
13287 // sourceFile->get_endOfConstruct ()->set_file_id(new_file_id);
13288 // sourceFile->get_endOfConstruct ()->set_physical_file_id(new_file_id);
13289 }
13290 }
13291 else
13292 {
13293#if DEBUG_FIXUP
13294 printf ("Unhandled: node = %p = %s \n",node,node->class_name().c_str());
13295#endif
13296 }
13297 }
13298 }
13299
13300 SgExpression* expression = isSgExpression(node);
13301 if (expression != NULL)
13302 {
13303 if (expression->get_operatorPosition()->get_physical_file_id() == originalFileId)
13304 {
13305 expression->get_operatorPosition()->set_file_id(new_file_id);
13306 expression->get_operatorPosition()->set_physical_file_id(new_file_id);
13307 }
13308 }
13309 }
13310
13311 // Data members.
13312 int new_file_id;
13313 int originalFileId;
13314 string newFileName;
13315 };
13316
13317
13318 SgFile* file = isSgFile(subtreeRoot);
13319 int new_file_id = -1;
13320 int originalFileId = -1;
13321
13322 if (file != NULL)
13323 {
13324 // We need to set the filename in at least one Sg_File_Info object so that we can have
13325 // the file_id be computed ans saved into the file_id to filename maps.
13326
13327 originalFileId = file->get_startOfConstruct()->get_file_id();
13328#if DEBUG_FIXUP
13329 printf ("originalFileId = %d \n",originalFileId);
13330#endif
13331 file->get_startOfConstruct()->set_filenameString(newFileName);
13332 new_file_id = Sg_File_Info::get_nametofileid_map()[newFileName];
13333
13334
13335#if 0
13336 file->get_endOfConstruct()->set_physical_file_id(new_file_id);
13337
13338 file->get_startOfConstruct()->set_physical_file_id(new_file_id);
13339 file->get_endOfConstruct()->set_physical_file_id(new_file_id);
13340
13341 // getFilenameFromID
13342 int new_file_id_2 = Sg_File_Info::getIDFromFilename(newFileName);
13343#if 0
13344 printf ("new_file_id = %d new_file_id_2 = %d \n",new_file_id,new_file_id_2);
13345#endif
13346 ROSE_ASSERT(new_file_id == new_file_id_2);
13347
13348 string new_filename_2 = Sg_File_Info::getFilenameFromID(new_file_id);
13349#if 0
13350 printf ("newFileName = %s new_filename_2 = %s \n",newFileName.c_str(),new_filename_2.c_str());
13351#endif
13352 ROSE_ASSERT(newFileName == new_filename_2);
13353#endif
13354
13355#if DEBUG_FIXUP
13356 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): file != NULL: newFileName = %s new_file_id = %d \n",newFileName.c_str(),new_file_id);
13357#endif
13358 }
13359 else
13360 {
13361 SgLocatedNode* subtreeLocatedNode = isSgLocatedNode(subtreeRoot);
13362 if (subtreeLocatedNode != NULL)
13363 {
13364#if DEBUG_FIXUP
13365 printf ("subtreeLocatedNode->get_startOfConstruct()->get_file_id() = %d \n",subtreeLocatedNode->get_startOfConstruct()->get_file_id());
13366 printf ("subtreeLocatedNode->get_startOfConstruct()->get_physical_file_id() = %d \n",subtreeLocatedNode->get_startOfConstruct()->get_physical_file_id());
13367#endif
13368 originalFileId = subtreeLocatedNode->get_startOfConstruct()->get_file_id();
13369 new_file_id = Sg_File_Info::getIDFromFilename(newFileName);
13370#if DEBUG_FIXUP
13371 printf ("originalFileId = %d \n",originalFileId);
13372 printf ("new_file_id = %d \n",new_file_id);
13373#endif
13374#if DEBUG_FIXUP
13375 printf ("In SageBuilder::fixupSourcePositionFileSpecification(): subtreeLocatedNode = %s : originalFileId = %d newFileName = %s new_file_id = %d \n",
13376 subtreeLocatedNode->class_name().c_str(),originalFileId,newFileName.c_str(),new_file_id);
13377#endif
13378 }
13379 else
13380 {
13381 printf ("Error: In SageBuilder::fixupSourcePositionFileSpecification(): subtree should be a SgFile or SgLocatedNode: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13382 ROSE_ABORT();
13383 }
13384
13385#if 0
13386 printf ("Error: In SageBuilder::fixupSourcePositionFileSpecification(): subtree should be a SgFile: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13387 ROSE_ABORT();
13388#endif
13389 }
13390
13391 ROSE_ASSERT(new_file_id >= 0);
13392
13393 // Now build the traveral object and call the traversal (preorder) on the function definition.
13394 Traversal traversal (newFileName,new_file_id,originalFileId);
13395
13396 // traversal.traverse(subtreeRoot, preorder);
13397 // traversal.traverseInputFiles(subtreeRoot, preorder);
13398 // traversal.traverseWithinFile(subtreeRoot, preorder);
13399 traversal.traverse(subtreeRoot, preorder);
13400
13401#if 0
13402 printf ("Exiting as a test in SageBuilder::fixupSourcePositionFileSpecification() \n");
13403 ROSE_ABORT();
13404#endif
13405 }
13406
13407
13408
13409
13410
13411
13412
13413
13414void
13416 {
13417 // DQ (11/8/2019): This function changes the filename designation in all of the Sg_File_Info objects
13418 // associated with the designated AST subtree.
13419
13420 ROSE_ASSERT(subtreeRoot != NULL);
13421 ROSE_ASSERT(new_file_id >= 0);
13422
13423#if 0
13424 printf ("In SageBuilder::fixupSharingSourcePosition(): subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13425 printf ("In SageBuilder::fixupSharingSourcePosition(): new_file_id = %d \n",new_file_id);
13426#endif
13427
13428 class Traversal : public AstSimpleProcessing
13429 {
13430 public:
13431
13432 Traversal(int tmp_new_file_id)
13433 {
13434 new_file_id = tmp_new_file_id;
13435#if 0
13436 printf ("In SageBuilder::fixupSharingSourcePosition(): new_file_id = %d \n",new_file_id);
13437#endif
13438 }
13439
13440 void visit (SgNode* node)
13441 {
13442#if 0
13443 printf ("In fixupSharingSourcePosition visit(): node = %p = %s new_file_id = %d \n",node,node->class_name().c_str(),new_file_id);
13444#endif
13445
13446 SgStatement* statement = isSgStatement(node);
13447 if (statement != NULL)
13448 {
13449 Sg_File_Info* startOfConstruct = statement->get_startOfConstruct();
13450 Sg_File_Info* endOfConstruct = statement->get_endOfConstruct();
13451#if 0
13452 printf ("new_file_id = %d startOfConstruct->get_physical_file_id() = %d \n",new_file_id,startOfConstruct->get_physical_file_id());
13453#endif
13454 // Only mark the files from the associated file (not statements in header files, for example).
13455 if (startOfConstruct->get_physical_file_id() == new_file_id)
13456 {
13457 // Mark this IR node as being shared
13458 startOfConstruct->setShared();
13459 endOfConstruct->setShared();
13460
13461 // Add this file_id to those file_id that will trigger this IR node to be unparsed.
13462#if 0
13463 printf (" --- adding entries for file_id and line number to support sharing: new_file_id = %d line = %d end line = %d \n",
13464 new_file_id,startOfConstruct->get_line(),endOfConstruct->get_line());
13465#endif
13466 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == startOfConstruct->get_fileLineNumbersToUnparse().size());
13467 ROSE_ASSERT(endOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
13468 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
13469
13470 // Add this existing_fi->get_file_id() to the list of file id's that will permit the assocated language construct to be unparsed.
13471 startOfConstruct->get_fileIDsToUnparse().push_back(new_file_id);
13472 startOfConstruct->get_fileLineNumbersToUnparse().push_back(startOfConstruct->get_line());
13473
13474 endOfConstruct->get_fileIDsToUnparse().push_back(new_file_id);
13475 endOfConstruct->get_fileLineNumbersToUnparse().push_back(endOfConstruct->get_line());
13476
13477 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == startOfConstruct->get_fileLineNumbersToUnparse().size());
13478 ROSE_ASSERT(endOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
13479 ROSE_ASSERT(startOfConstruct->get_fileIDsToUnparse().size() == endOfConstruct->get_fileLineNumbersToUnparse().size());
13480 }
13481 }
13482 else
13483 {
13484#if 0
13485 printf ("Unhandled: node = %p = %s \n",node,node->class_name().c_str());
13486#endif
13487 }
13488 }
13489
13490 // Data members.
13491 int new_file_id;
13492 };
13493
13494
13495 SgStatement* statement = isSgStatement(subtreeRoot);
13496 if (statement != NULL)
13497 {
13498#if 0
13499 printf ("statement->get_startOfConstruct()->get_file_id() = %d \n",statement->get_startOfConstruct()->get_file_id());
13500 printf ("statement->get_startOfConstruct()->get_physical_file_id() = %d \n",statement->get_startOfConstruct()->get_physical_file_id());
13501#endif
13502#if 0
13503 printf ("new_file_id = %d \n",new_file_id);
13504#endif
13505#if 0
13506 printf ("In SageBuilder::fixupSharingSourcePosition(): statement = %s : new_file_id = %d \n",statement->class_name().c_str(),new_file_id);
13507#endif
13508 }
13509 else
13510 {
13511 printf ("Error: In SageBuilder::fixupSharingSourcePosition(): subtree should be a SgFile or SgLocatedNode: subtreeRoot = %p = %s \n",subtreeRoot,subtreeRoot->class_name().c_str());
13512 ROSE_ABORT();
13513 }
13514
13515 ROSE_ASSERT(new_file_id >= 0);
13516
13517 // Now buid the traveral object and call the traversal (preorder) on the function definition.
13518 Traversal traversal (new_file_id);
13519
13520 // traversal.traverse(subtreeRoot, preorder);
13521 // traversal.traverseInputFiles(subtreeRoot, preorder);
13522 // traversal.traverseWithinFile(subtreeRoot, preorder);
13523 traversal.traverse(subtreeRoot, preorder);
13524
13525#if 0
13526 printf ("Exiting as a test in SageBuilder::fixupSharingSourcePosition() \n");
13527 ROSE_ABORT();
13528#endif
13529 }
13530
13531
13532
13533
13534
13536SgFile*
13537SageBuilder::buildFile(const std::string& inputFileName, const std::string& outputFileName, SgProject* project/*=NULL*/, bool clear_globalScopeAcrossFiles /*=false*/)
13538 {
13539// Note that ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT defines a reduced set of ROSE to support front-end specific development.
13540// It is mostly used by quinlan to support laptop development where the smaller set of files permits one to do limited
13541// development work on a Mac (even with OSX's poor performance with large numbers of debug symbols). This is an
13542// infrequently used option.
13543#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
13544
13545#if 0
13546 printf ("In SageBuilder::buildFile(inputFileName = %s, outputFileName = %s, project = %p) \n",inputFileName.c_str(),outputFileName.c_str(),project);
13547 // printf (" --- fullname = %s \n",fullname.c_str());
13548#endif
13549
13550#if 0
13551 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13552 ROSE_ASSERT(project != NULL);
13553 std::set<SgLocatedNode*> tmp1_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
13554
13555 if (tmp1_collectionOfModifiedLocatedNodes.size() > 0)
13556 {
13557 printf ("In Traversal::evaluateInheritedAttribute(): tmp1_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp1_collectionOfModifiedLocatedNodes.size());
13558#if 1
13559 printf ("Exiting as a test! \n");
13560 ROSE_ASSERT(false);
13561#endif
13562 }
13563#endif
13564
13565 ROSE_ASSERT(inputFileName.size() != 0); // empty file name is not allowed.
13566
13567 // DQ (9/18/2019): I am unclear what the use of fullname is below.
13568 // string sourceFilename = inputFileName, fullname;
13569 // string sourceFilename_fullname = inputFileName, fullname;
13570 string sourceFilename = inputFileName;
13571
13572#if 0
13573 // printf ("sourceFilename_fullname = %s \n",sourceFilename_fullname.c_str());
13574 printf ("sourceFilename = %s \n",sourceFilename.c_str());
13575#endif
13576
13577
13578 // DQ (11/5/2020): Experiment with clearing the global scope that is supporting multiple translation
13579 // units, since it is the cause of some problem when a tool is designed to read an input file twice.
13580 if (project != NULL)
13581 {
13582 SgGlobal* globalScopeAcrossFiles = project->get_globalScopeAcrossFiles();
13583 ROSE_ASSERT(globalScopeAcrossFiles != NULL);
13584
13585 ROSE_ASSERT(globalScopeAcrossFiles->get_symbol_table() != NULL);
13586 ROSE_ASSERT(globalScopeAcrossFiles->get_symbol_table()->get_table() != NULL);
13587
13588#if 0
13589 printf ("In SageBuilder::buildFile(): globalScopeAcrossFiles = %p \n",globalScopeAcrossFiles);
13590 printf (" --- globalScopeAcrossFiles->get_declarations().size() = %zu \n",globalScopeAcrossFiles->get_declarations().size());
13591 printf (" --- globalScopeAcrossFiles->get_symbol_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->size());
13592 printf (" --- globalScopeAcrossFiles->get_symbol_table()->get_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->get_table()->size());
13593#endif
13594#if 0
13595 printf ("Removing all elements from the globalScopeAcrossFiles->get_symbol_table() \n");
13596#endif
13597
13598 // DQ (11/5/2020): Clear the symbol table used to support multifile handling.
13599 // This breaks only one of the test codes in the codeSegregation tool, but it is a name
13600 // qualification that should likely be handled better so I think this is a good fix.
13601 if (clear_globalScopeAcrossFiles == true)
13602 {
13603 globalScopeAcrossFiles->get_symbol_table()->get_table()->delete_elements();
13604 }
13605
13606#if 0
13607 printf ("After removing all symbols (alias symbols): globalScopeAcrossFiles->get_symbol_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->size());
13608 printf ("After removing all symbols (alias symbols): globalScopeAcrossFiles->get_symbol_table()->get_table()->size() = %d \n",globalScopeAcrossFiles->get_symbol_table()->get_table()->size());
13609#endif
13610 }
13611
13612 // DQ (9/18/2019): Test that the use of fullname has no effect.
13613 // ROSE_ASSERT(sourceFilename == sourceFilename_fullname);
13614
13615 Rose_STL_Container<std::string> arglist;
13616 int nextErrorCode = 0;
13617
13618#if 0
13619 bool set_header_file_unparsing_optimization = false;
13620#endif
13621
13622 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
13623 bool isCopyOfExistingFile_testForSharedNodes = false;
13624 SgFile* fileBeingCopied = NULL;
13625
13626 if (project == NULL)
13627 // SgProject is created on the fly
13628 // Make up an arglist in order to reuse the code inside SgFile::setupSourceFilename()
13629 {
13630#if 0
13631 printf ("In SageBuilder::buildFile(): build the SgProject \n");
13632#endif
13633 project = new SgProject();
13634 ROSE_ASSERT(project);
13635 project->get_fileList().clear();
13636
13637 arglist.push_back("cc");
13638 arglist.push_back("-c");
13639 project->set_originalCommandLineArgumentList (arglist);
13640 }
13641 else
13642 {
13643 // If project exists, then find the original source file if it exists and check the header file optimization setting for consistancy.
13644
13645 // DQ (9/18/2019): Adding debugging support to header file optimization support.
13646 SgFilePtrList & files = project->get_fileList();
13647 for (SgFilePtrList::iterator i = files.begin(); i != files.end(); i++)
13648 {
13649 SgFile* file = *i;
13650#if 0
13651 printf ("file = %p = %s name = %s \n",file,file->class_name().c_str(), file->getFileName().c_str());
13652
13653 printf ("file->get_header_file_unparsing_optimization() = %s \n",file->get_header_file_unparsing_optimization() ? "true" : "false");
13654 printf ("file->get_header_file_unparsing_optimization_source_file() = %s \n",file->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
13655 printf ("file->get_header_file_unparsing_optimization_header_file() = %s \n",file->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
13656#endif
13657 if (sourceFilename == file->getFileName())
13658 {
13659#if 0
13660 printf ("This is a copy of an existing file in the project: sourceFilename = %s \n",sourceFilename.c_str());
13661#endif
13662 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
13663 isCopyOfExistingFile_testForSharedNodes = true;
13664 fileBeingCopied = file;
13665
13666#if 0
13667 // DQ (4/24/2021): This data member header_file_unparsing_optimization is now static.
13668 // We are building a second copy of an originally specified file (so we need to set the optimization setting similarly).
13669 if (file->get_header_file_unparsing_optimization() == true)
13670 {
13671 set_header_file_unparsing_optimization = true;
13672 }
13673#endif
13674 }
13675 }
13676
13677#if 0
13678 printf ("Exiting as a test! \n");
13679 ROSE_ABORT();
13680#endif
13681 }
13682
13683 ifstream testfile(inputFileName.c_str());
13684 if (!testfile.is_open())
13685 {
13686 // create a temporary file if the file does not exist.
13687 // have to do this, otherwise StringUtility::getAbsolutePathFromRelativePath() complains
13688 // which is called by result->setupSourceFilename(arglist);
13689 testfile.close();
13690 ofstream outputfile(inputFileName.c_str(),ios::out);
13691 // DQ (2/6/2009): I think this comment is helpful to put into the file (helps explain why the file exists).
13692 outputfile<<"// Output file generated so that StringUtility::getAbsolutePathFromRelativePath() will see a vaild file ... unparsed file will have rose_ prefix "<<endl;
13693 outputfile.close();
13694 }
13695 else // file already exists , load and parse it
13696 {
13697 // should not reparse all files in case their ASTs have unsaved changes,
13698 // just parse the newly loaded file only.
13699 // use argv here, change non-existing input file later on
13700 // TODO add error code handling
13701
13702 // DQ (2/6/2009): Avoid closing this file twice (so put this here, instead of below).
13703 testfile.close();
13704 // should remove the old one here, Liao, 5/1/2009
13705 }
13706
13707 // DQ (2/6/2009): Avoid closing this file twice (moved to false branch above).
13708 // testfile.close();
13709
13710 // DQ (2/6/2009): Need to add the inputFileName to the source file list in the project,
13711 // because this list will be used to subtract off the source files as required to build
13712 // the commandline for the backend compiler.
13713 project->get_sourceFileNameList().push_back(inputFileName);
13714
13715 Rose_STL_Container<string> sourceFilenames = project->get_sourceFileNameList();
13716 // printf ("In SageBuilder::buildFile(): sourceFilenames.size() = %" PRIuPTR " sourceFilenames = %s \n",sourceFilenames.size(),StringUtility::listToString(sourceFilenames).c_str());
13717
13718 arglist = project->get_originalCommandLineArgumentList();
13719
13720 // DQ (2/6/2009): We will be compiling the source code generated in the
13721 // "rose_<inputFileName>" file, so we don't want this on the argument stack.
13722 // TV (09/19/2018): only add if not already present
13723 if (std::find(arglist.begin(), arglist.end(), sourceFilename) == arglist.end())
13724 {
13725 arglist.push_back(sourceFilename);
13726 }
13727
13728 // DQ (2/6/2009): Modified.
13729 // There is output file name specified for rose translators
13730 if (outputFileName.empty() == false)
13731 {
13732 arglist.push_back("-rose:o");
13733 // arglist.push_back("-o");
13734 arglist.push_back(outputFileName);
13735 }
13736
13737 // DQ (4/15/2010): Turn on verbose mode
13738 // arglist.push_back("-rose:verbose 2");
13739
13740 // This handles the case where the original command line may have referenced multiple files.
13741 Rose_STL_Container<string> fileList = CommandlineProcessing::generateSourceFilenames(arglist,/* binaryMode = */ false);
13742 CommandlineProcessing::removeAllFileNamesExcept(arglist,fileList,sourceFilename);
13743
13744 // DQ (9/3/2008): Added support for SgSourceFile IR node
13745 // SgFile* result = new SgFile (arglist, nextErrorCode, 0, project);
13746 // AS(10/04/08) Because of refactoring we require the determineFileType function to be called
13747 // to construct the node.
13748 // SgSourceFile* result = new SgSourceFile (arglist, nextErrorCode, 0, project);
13749 // SgSourceFile* result = isSgSourceFile(determineFileType(arglist, nextErrorCode, project));
13750 // TH (2009-07-15): changed to more generig isSgFile, this also supports SgBinaryComposite
13751 SgFile* result = determineFileType(arglist, nextErrorCode, project);
13752 ROSE_ASSERT(result != NULL);
13753
13754#if 0
13755 printf ("In SageBuilder::buildFile(): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",project,project->get_fileList_ptr()->get_listOfFiles().size());
13756#endif
13757
13758 SgSourceFile* sourceFile = isSgSourceFile(result);
13759 if (sourceFile != NULL)
13760 {
13761 SgGlobal* globalScope = sourceFile->get_globalScope();
13762 ROSE_ASSERT(globalScope != NULL);
13763
13764 // DQ (6/24/2021): We need to end this function with the isModified flag set to false. This is
13765 // important for the support of the token based unparsing when building a dynamic library.
13766 // This is important in permitting the simpleFrontierDetectionForTokenStreamMapping() function
13767 // to generate the correct settings for nodes in the second file constructed from the original file.
13768 if (globalScope->get_isModified() == true)
13769 {
13770#if 0
13771 printf ("In SageBuilder::buildFile(): globalScope->get_isModified() == true: reset to false \n");
13772#endif
13773 globalScope->set_isModified(false);
13774#if 0
13775 printf ("In SageBuilder::buildFile(): Verify false setting: globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
13776#endif
13777 }
13778 }
13779
13780#if 0
13781 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
13782 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
13783
13784 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
13785 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
13786#endif
13787
13788#if 0
13789 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13790 ROSE_ASSERT(project != NULL);
13791 std::set<SgLocatedNode*> tmp2_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
13792
13793 if (tmp2_collectionOfModifiedLocatedNodes.size() > 0)
13794 {
13795 printf ("In Traversal::evaluateInheritedAttribute(): tmp2_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp2_collectionOfModifiedLocatedNodes.size());
13796#if 1
13797 printf ("Exiting as a test! \n");
13798 ROSE_ASSERT(false);
13799#endif
13800 }
13801#endif
13802
13803#if 0
13804 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13805 ROSE_ASSERT(project != NULL);
13806 std::set<SgLocatedNode*> tmp22_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(result);
13807
13808 if (tmp22_collectionOfModifiedLocatedNodes.size() > 0)
13809 {
13810 printf ("In Traversal::evaluateInheritedAttribute(): tmp22_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp22_collectionOfModifiedLocatedNodes.size());
13811#if 1
13812 printf ("Exiting as a test! \n");
13813 ROSE_ASSERT(false);
13814#endif
13815 }
13816#endif
13817
13818#if 0
13819 printf ("Calling outputFileIds() \n");
13820
13822
13823 printf ("DONE: Calling outputFileIds() \n");
13824#endif
13825
13826#if 0
13827 // DQ (9/18/2019): Adding debugging support.
13828 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization() = %s \n",
13829 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization() ? "true" : "false");
13830#endif
13831
13832#if 0
13833 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization_source_file() = %s \n",
13834 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
13835 printf ("In SageBuilder::buildFile(): file = %p = %s result->get_header_file_unparsing_optimization_header_file() = %s \n",
13836 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
13837#endif
13838
13839 // DQ (9/18/2019): Adding debugging support.
13840 // ROSE_ASSERT(result->get_header_file_unparsing_optimization() == false);
13841 // ROSE_ASSERT(result->get_header_file_unparsing_optimization_source_file() == false);
13842 // ROSE_ASSERT(result->get_header_file_unparsing_optimization_header_file() == false);
13843
13844 // ROSE_ASSERT(result->get_header_file_unparsing_optimization() == true);
13845
13846#if 0
13847 // DQ (4/24/2021): This data member header_file_unparsing_optimization is now static (so we don't need this code).
13848 if (set_header_file_unparsing_optimization == true)
13849 {
13850 result->set_header_file_unparsing_optimization(true);
13851
13852 // DQ (9/18/2019): Also set the values for the source file and header files.
13853 // I think we only want to set the source file version to true and the header file version to false.
13854 // This is enforced in the attachPreprocessingInfo() function.
13855
13856 // DQ (4/24/2021): Debugging header file optimization.
13857 // result->set_header_file_unparsing_optimization_source_file(true);
13858
13859 // result->set_header_file_unparsing_optimization_header_file(true);
13860 result->set_header_file_unparsing_optimization_header_file(false);
13861
13862#if 0
13863 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization() = %s \n",
13864 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization() ? "true" : "false");
13865 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization_source_file() = %s \n",
13866 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
13867 printf ("In SageBuilder::buildFile(): set_header_file_unparsing_optimization == true: file = %p = %s result->get_header_file_unparsing_optimization_header_file() = %s \n",
13868 result,result->class_name().c_str(),result->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
13869#endif
13870 }
13871#endif
13872
13873#if 0
13874 // 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.
13875 // 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
13876 // 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
13877 // cleaner semantics.
13878 // This just adds the new file to the list of files stored internally (note: this sets the parent of the newFile).
13879 // TOO1 (2/28/2014): This is definitely required for Java (ECJ frontend), though C passes without it (I think only
13880 // by luck :-).
13881 // The ECJ frontend uses the SgProject internally (via a global SgProject*). Therefore, the
13882 // SgProject must contain this newly created SgFile, otherwise ECJ won't be able to find it.
13883 // project->set_file ( *result );
13884 if (project->get_Java_only() == true)
13885 {
13886 // DQ (3/4/2014): For now we want to output a message and clean this up afterward (likely in the Java language support).
13887 printf ("WARNING: Java specific action to add new file to SgProject (using set_file()) (more uniform language handling symantics would avoid this problem) \n");
13888 project->set_file ( *result );
13889 }
13890#else
13891 // DQ (3/6/2014): The code below adresses the specific bug faced in the use of the outliner (so we use it directly).
13892 // This code was moved ahead of the call to "result->runFrontend(nextErrorCode);" because in the case of Java
13893 // the file must be set to be a part of the SgProject before calling the runFrontend() function.
13894 // project->set_file ( *result );
13895
13896 result->set_parent(project);
13897
13898#if 0
13899 printf ("In SageBuilder::buildFile(): Outliner::use_dlopen = %s \n",Outliner::use_dlopen ? "true" : "false");
13900#endif
13901
13902#if 0
13903 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13904 ROSE_ASSERT(project != NULL);
13905 std::set<SgLocatedNode*> tmp23_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(result);
13906
13907 if (tmp23_collectionOfModifiedLocatedNodes.size() > 0)
13908 {
13909 printf ("In Traversal::evaluateInheritedAttribute(): tmp23_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp23_collectionOfModifiedLocatedNodes.size());
13910#if 1
13911 printf ("Exiting as a test! \n");
13912 ROSE_ASSERT(false);
13913#endif
13914 }
13915#endif
13916
13917#if 0
13918 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13919 ROSE_ASSERT(project != NULL);
13920 std::set<SgLocatedNode*> tmp24_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
13921
13922 if (tmp24_collectionOfModifiedLocatedNodes.size() > 0)
13923 {
13924 printf ("In Traversal::evaluateInheritedAttribute(): tmp24_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp24_collectionOfModifiedLocatedNodes.size());
13925#if 1
13926 printf ("Exiting as a test! \n");
13927 ROSE_ASSERT(false);
13928#endif
13929 }
13930#endif
13931
13932 // DQ (3/5/2014): I need to check with Liao to understand this part of the code better.
13933 // I think that the default value for Outliner::use_dlopen is false, so that when the
13934 // Java support is used the true branch is taken. However, if might be the we need
13935 // to support the outliner using the code below and so this would be a bug for the
13936 // outliner.
13937 if (!Outliner::use_dlopen)
13938 {
13939#if 0
13940 printf ("In SageBuilder::buildFile(): (after test for (!Outliner::use_dlopen) == true: project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
13941 project,project->get_fileList_ptr()->get_listOfFiles().size());
13942#endif
13943 // DQ (3/5/2014): If we added the file above, then don't add it here since it is redundant.
13944 project->set_file(*result); // equal to push_back()
13945#if 0
13946 printf ("In SageBuilder::buildFile(): (after 2nd project->set_file()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
13947 project,project->get_fileList_ptr()->get_listOfFiles().size());
13948#endif
13949 }
13950 else
13951 {
13952#if 0
13953 printf ("In SageBuilder::buildFile(): (after test for (!Outliner::use_dlopen) == false: project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
13954 project,project->get_fileList_ptr()->get_listOfFiles().size());
13955#endif
13956
13957 // Liao, 5/1/2009,
13958 // if the original command line is: gcc -c -o my.o my.c and we want to
13959 // add a new file(mynew.c), the command line for the new file would become "gcc -c -o my.o mynew.c "
13960 // which overwrites the object file my.o from my.c and causes linking error.
13961 // To avoid this problem, I insert the file at the beginning and let the right object file to be the last generated one
13962 //
13963 // TODO This is not an elegant fix and it causes some strange assertion failure in addAssociatedNodes(): default case node
13964 // So we only turn this on if Outliner:: use_dlopen is used for now
13965 // The semantics of adding a new source file can cause changes to linking phase (new object files etc.)
13966 // But ROSE has a long-time bug in handling combined compiling and linking command like "translator -o a.out a.c b.c"
13967 // It will generated two command lines: "translator -o a.out a.c" and "translator -o a.out b.c", which are totally wrong.
13968 // This problem is very relevant to the bug.
13969 SgFilePtrList& flist = project->get_fileList();
13970 flist.insert(flist.begin(),result);
13971#if 0
13972 printf ("In SageBuilder::buildFile(): (after flist.insert(flist.begin(),result)): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
13973 project,project->get_fileList_ptr()->get_listOfFiles().size());
13974#endif
13975 }
13976#endif
13977
13978#if 0
13979 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
13980 ROSE_ASSERT(project != NULL);
13981 std::set<SgLocatedNode*> tmp25_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
13982
13983 if (tmp25_collectionOfModifiedLocatedNodes.size() > 0)
13984 {
13985 printf ("In Traversal::evaluateInheritedAttribute(): tmp25_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp25_collectionOfModifiedLocatedNodes.size());
13986#if 1
13987 printf ("Exiting as a test! \n");
13988 ROSE_ASSERT(false);
13989#endif
13990 }
13991#endif
13992
13993 // DQ (6/3/2019): The case of outlining to a seperate file will have transformations
13994 // that this checking will fail on because it is for the typical case of checking the
13995 // AST for transformations after construction of the AST from an typical input file.
13996 EDG_ROSE_Translation::suppress_detection_of_transformations = true;
13997
13998#if 0
13999 printf ("In SageBuilder::buildFile(): EDG_ROSE_Translation::suppress_detection_of_transformations = %s \n",EDG_ROSE_Translation::suppress_detection_of_transformations ? "true" : "false");
14000#endif
14001
14002#if 0
14003 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());
14004#endif
14005
14006
14007 // 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.
14008 // 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
14009 // 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
14010 // 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
14011 // the traversal) and then afterward reset the set of isModified IR nodes to isModified. By isolating the fix in this function we can eliminate
14012 // the complexity of it being seen from the outside (outside of this abstraction). Note that the function:
14013 // SageInterface::collectModifiedLocatedNodes() has previously been implemented and used for debugging.
14014 std::set<SgLocatedNode*> modifiedNodeSet = collectModifiedLocatedNodes(project);
14015
14016#if 0
14017 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14018 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14019
14020 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14021 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14022#endif
14023
14024#if 0
14025 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14026 ROSE_ASSERT(project != NULL);
14027 std::set<SgLocatedNode*> tmp251_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14028
14029 if (tmp251_collectionOfModifiedLocatedNodes.size() > 0)
14030 {
14031 printf ("In Traversal::evaluateInheritedAttribute(): tmp251_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp251_collectionOfModifiedLocatedNodes.size());
14032#if 1
14033 printf ("Exiting as a test! \n");
14034 ROSE_ASSERT(false);
14035#endif
14036 }
14037#endif
14038
14039 // 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.
14040 // 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.
14041 // 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.
14042 result->runFrontend(nextErrorCode);
14043
14044#if 0
14045 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());
14046#endif
14047
14048#if 0
14049 printf ("After result->runFrontend(): calling outputFileIds() \n");
14050
14052
14053 printf ("DONE: After result->runFrontend(): calling outputFileIds() \n");
14054#endif
14055
14056#if 0
14057 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14058 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14059
14060 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14061 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14062#endif
14063
14064#if 0
14065 // DQ (6/24/2021): This can be expected to fail, because the new AST has been build and all of the
14066 // nodes are marked as isModified until rest in the AstPostProcessing() step (below).
14067 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14068 ROSE_ASSERT(project != NULL);
14069 std::set<SgLocatedNode*> tmp26_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14070
14071 if (tmp26_collectionOfModifiedLocatedNodes.size() > 0)
14072 {
14073 printf ("In Traversal::evaluateInheritedAttribute(): tmp26_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp26_collectionOfModifiedLocatedNodes.size());
14074#if 0
14075 printf ("Exiting as a test! \n");
14076 ROSE_ASSERT(false);
14077#endif
14078 }
14079#endif
14080
14081#if 0
14082 // Output an optional graph of the AST (just the tree, when active)
14083 printf ("Generating a dot file... (SgFile only) \n");
14084 generateDOT ( *project );
14085 // generateAstGraph(project, 2000);
14086#endif
14087
14088#if 0
14089 printf ("In SageBuilder::buildFile(): Generate the dot output for multiple files (ROSE AST) \n");
14090 // generateDOT ( *project );
14091 generateDOTforMultipleFile ( *project );
14092 printf ("DONE: Generate the dot output of the SAGE III AST \n");
14093#endif
14094
14095#if 0
14096 // DQ (7/18/2019): Output a graph of the AST for debugging.
14097 // Output an optional graph of the AST (the whole graph, of bounded complexity, when active)
14098 const int MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH = 8000;
14099 generateAstGraph(project,MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH);
14100#endif
14101
14102 // DQ (7/14/2019): I think we need to call the astPostProcessing at this point.
14103#if 0
14104 printf ("In SageBuilder::buildFile(): calling astPostProcessing() \n");
14105#endif
14106
14107 if (!project->get_skip_post_processing()) AstPostProcessing(result);
14108
14109#if 0
14110 printf ("In SageBuilder::buildFile(): DONE: calling astPostProcessing() \n");
14111#endif
14112
14113#if 0
14114 reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): project",project);
14115 // reportModifiedStatements("In SageBuilder::buildFile(): calling reportModifiedStatements(): result",result);
14116
14117 reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): project",project);
14118 // reportModifiedLocatedNodes("In SageBuilder::buildFile(): calling reportModifiedLocatedNodes(): result",result);
14119#endif
14120
14121#if 0
14122 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14123 ROSE_ASSERT(project != NULL);
14124 std::set<SgLocatedNode*> tmp265_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14125
14126 if (tmp265_collectionOfModifiedLocatedNodes.size() > 0)
14127 {
14128 printf ("In Traversal::evaluateInheritedAttribute(): tmp265_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp265_collectionOfModifiedLocatedNodes.size());
14129#if 1
14130 printf ("Exiting as a test! \n");
14131 ROSE_ASSERT(false);
14132#endif
14133 }
14134#endif
14135
14136#if 0
14137 result->display("SageBuilder::buildFile()");
14138#endif
14139
14140 ROSE_ASSERT(project != NULL);
14141 project->set_frontendErrorCode(max(project->get_frontendErrorCode(), nextErrorCode));
14142
14143 // Not sure why a warning shows up from astPostProcessing.C
14144 // SgNode::get_globalMangledNameMap().size() != 0 size = %" PRIuPTR " (clearing mangled name cache)
14145 if (result->get_globalMangledNameMap().size() != 0)
14146 {
14147 result->clearGlobalMangledNameMap();
14148 }
14149
14150 // DQ (6/5/2019): Use the previously constructed set (above) to reset the IR nodes to be marked as isModified.
14151 // std::set<SgLocatedNode*> modifiedNodeSet = collectModifiedLocatedNodes(project);
14152 // void resetModifiedLocatedNodes(const std::set<SgLocatedNode*> & modifiedNodeSet);
14153 resetModifiedLocatedNodes(modifiedNodeSet);
14154
14155#if 0
14156 printf ("Exiting as a test! \n");
14157 ROSE_ABORT();
14158#endif
14159
14160#if 0
14161 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14162 ROSE_ASSERT(project != NULL);
14163 std::set<SgLocatedNode*> tmp27_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14164
14165 if (tmp27_collectionOfModifiedLocatedNodes.size() > 0)
14166 {
14167 printf ("In Traversal::evaluateInheritedAttribute(): tmp27_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp27_collectionOfModifiedLocatedNodes.size());
14168#if 1
14169 printf ("Exiting as a test! \n");
14170 ROSE_ASSERT(false);
14171#endif
14172 }
14173#endif
14174
14175 // DQ (11/10/2019): Shared nodes between existing files that are copied need to be marked as shared.
14176 if (isCopyOfExistingFile_testForSharedNodes == true)
14177 {
14178 // Sharing of IR nodes happens in the AST when the same file is read twice.
14179 // Also in the case where two declarations in the global scope match in two different ASTs (typically in header files of different translation units).
14180
14181#if 0
14182 printf ("Found isCopyOfExistingFile_testForSharedNodes == true \n");
14183 printf ("fileBeingCopied = %p = %s \n",fileBeingCopied,fileBeingCopied->getFileName().c_str());
14184#endif
14185
14186 SgSourceFile* sourceFileBeingCopied = isSgSourceFile(fileBeingCopied);
14187 ROSE_ASSERT(sourceFileBeingCopied != NULL);
14188
14189 SgSourceFile* sourceResult = isSgSourceFile(result);
14190 ROSE_ASSERT(sourceResult != NULL);
14191
14192 SgGlobal* fileBeingCopied_globalScope = sourceFileBeingCopied->get_globalScope();
14193 SgGlobal* result_globalScope = sourceResult->get_globalScope();
14194#if 0
14195 printf ("fileBeingCopied_globalScope = %p \n",fileBeingCopied_globalScope);
14196 printf ("result_globalScope = %p \n",result_globalScope);
14197#endif
14198 ROSE_ASSERT(fileBeingCopied_globalScope != NULL);
14199 ROSE_ASSERT(result_globalScope != NULL);
14200
14201 SgDeclarationStatementPtrList fileBeingCopied_declarationList = fileBeingCopied_globalScope->get_declarations();
14202 SgDeclarationStatementPtrList result_declarationList = result_globalScope->get_declarations();
14203
14204#if 1
14205 // DQ (11/22/2019): Use set intersection to compute the list to make be shared (this is a better implementation).
14206 // This implementation is insensitive to transforamtions in the original AST for the file.
14207 vector<SgDeclarationStatement*>::iterator it;
14208 SgDeclarationStatementPtrList v(fileBeingCopied_declarationList.size());
14209
14210 // This is n log n in complexity, but likely OK.
14211 std::sort(fileBeingCopied_declarationList.begin(),fileBeingCopied_declarationList.end());
14212 std::sort(result_declarationList.begin(),result_declarationList.end());
14213
14214 // printf ("v.size() = %zu \n",v.size());
14215
14216 it = std::set_intersection(fileBeingCopied_declarationList.begin(),fileBeingCopied_declarationList.end(),result_declarationList.begin(),result_declarationList.end(),v.begin());
14217
14218 v.resize(it-v.begin());
14219
14220 int fileBeingCopied_file_id = fileBeingCopied->get_startOfConstruct()->get_physical_file_id();
14221
14222 // printf ("v.size() = %zu \n",v.size());
14223 for (size_t i = 0; i < v.size(); i++)
14224 {
14225 SgDeclarationStatement* intersection_element = v[i];
14226 // printf ("intersection_element = %p = %s \n",intersection_element,intersection_element->class_name().c_str());
14227#if 0
14228 printf (" --- SageBuilder::buildFile() is sharing this node: %p %s \n",intersection_element,intersection_element->class_name().c_str());
14229#endif
14230 // DQ (11/10/2019): Need to recursively mark this as shared so that the unparser will be able to test each line?
14231
14232 fixupSharingSourcePosition(intersection_element,fileBeingCopied_file_id);
14233#if 0
14234 printf ("Exiting as a test! \n");
14235 ROSE_ABORT();
14236#endif
14237 }
14238
14239#if 0
14240 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14241 ROSE_ASSERT(project != NULL);
14242 std::set<SgLocatedNode*> tmp28_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14243
14244 if (tmp28_collectionOfModifiedLocatedNodes.size() > 0)
14245 {
14246 printf ("In Traversal::evaluateInheritedAttribute(): tmp28_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp28_collectionOfModifiedLocatedNodes.size());
14247#if 1
14248 printf ("Exiting as a test! \n");
14249 ROSE_ASSERT(false);
14250#endif
14251 }
14252#endif
14253
14254#else
14255
14256#error "DEAD CODE!"
14257
14258 // This is the older implementation that is sensitive to transforamtions in the original AST from the file.
14259 // DQ (11/21/2019): Remove elements in the vector that are SgEmptyDeclarations which
14260 // are associated with some transformations (include header, for example).
14261 std::vector<SgDeclarationStatementPtrList::iterator> removeList;
14262 SgDeclarationStatementPtrList::iterator i = fileBeingCopied_declarationList.begin();
14263 while (i != fileBeingCopied_declarationList.end())
14264 {
14265 SgEmptyDeclaration* emptyDeclaration = isSgEmptyDeclaration(*i);
14266 if (emptyDeclaration != NULL)
14267 {
14268 removeList.push_back(i);
14269 }
14270
14271 i++;
14272 }
14273
14274#error "DEAD CODE!"
14275
14276 // Need seperate list to avoid iterator invalidation.
14277 // for (SgDeclarationStatementPtrList::iterator i = removeList.begin(); i != removeList.end(); i++)
14278 for (std::vector<SgDeclarationStatementPtrList::iterator>::iterator i = removeList.begin(); i != removeList.end(); i++)
14279 {
14280 fileBeingCopied_declarationList.erase(*i);
14281 }
14282
14283 // DQ (11/21/2019): These might be a different size if for example the file being
14284 // copied is being copied after some transformations to the AST from the original file.
14285 if (fileBeingCopied_declarationList.size() != result_declarationList.size())
14286 {
14287 printf ("fileBeingCopied_declarationList.size() = %zu \n",fileBeingCopied_declarationList.size());
14288 printf ("result_declarationList.size() = %zu \n",result_declarationList.size());
14289 }
14290 ROSE_ASSERT(fileBeingCopied_declarationList.size() == result_declarationList.size());
14291
14292#error "DEAD CODE!"
14293
14294#if 0
14295 printf ("Statements from global scope (size = %zu): \n",fileBeingCopied_declarationList.size());
14296#endif
14297 for (size_t i = 0; i < fileBeingCopied_declarationList.size(); i++)
14298 {
14299 SgDeclarationStatement* fileBeingCopied_decl = fileBeingCopied_declarationList[i];
14300 SgDeclarationStatement* result_decl = result_declarationList[i];
14301#if 0
14302 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());
14303#endif
14304 if (fileBeingCopied_decl == result_decl)
14305 {
14306#if 0
14307 printf (" --- SageBuilder::buildFile() is sharing this node: %p %s \n",fileBeingCopied_decl,fileBeingCopied_decl->class_name().c_str());
14308#endif
14309 // DQ (11/10/2019): Need to recursively mark this as shared so that the unparser will be able to test each line?
14310
14311#error "DEAD CODE!"
14312
14313 int fileBeingCopied_file_id = fileBeingCopied->get_startOfConstruct()->get_physical_file_id();
14314 fixupSharingSourcePosition(fileBeingCopied_decl,fileBeingCopied_file_id);
14315#if 0
14316 printf ("Exiting as a test! \n");
14317 ROSE_ABORT();
14318#endif
14319 }
14320 }
14321
14322#error "DEAD CODE!"
14323
14324#endif
14325
14326#if 0
14327 printf ("exiting as a test! \n");
14328 ROSE_ABORT();
14329#endif
14330 }
14331
14332#if 0
14333 reportModifiedStatements("Leaving SageBuilder::buildFile(): calling reportModifiedStatements()",project);
14334#endif
14335
14336#if 0
14337 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14338 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14339 printf ("Leaving SageBuilder::buildFile(): (after result->runFrontend()): project = %p project->get_fileList_ptr()->get_listOfFiles().size() = %" PRIuPTR " \n",
14340 project,project->get_fileList_ptr()->get_listOfFiles().size());
14341 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14342 printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n");
14343#endif
14344
14345#if 0
14346 // DQ (11/8/2019): This is not working and breaks the current work at present.
14347 // DQ (11/8/2019): Support function to change the name in each of the IR node's source position info objects.
14348 fixupSourcePositionFileSpecification(result,outputFileName);
14349#endif
14350
14351 ROSE_ASSERT(result->get_preprocessorDirectivesAndCommentsList() != NULL);
14352
14353#if 0
14354 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14355 ROSE_ASSERT(project != NULL);
14356 std::set<SgLocatedNode*> tmp3_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14357
14358 if (tmp3_collectionOfModifiedLocatedNodes.size() > 0)
14359 {
14360 printf ("In Traversal::evaluateInheritedAttribute(): tmp3_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp3_collectionOfModifiedLocatedNodes.size());
14361#if 1
14362 printf ("Exiting as a test! \n");
14363 ROSE_ASSERT(false);
14364#endif
14365 }
14366#endif
14367
14368 return result;
14369#else
14370
14371 // false branch of #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT (at top of function.
14372
14373 return NULL;
14374#endif
14375 }
14376
14377
14380SageBuilder::buildSourceFile(const std::string& outputFileName, SgProject* project, bool clear_globalScopeAcrossFiles /*=false*/)
14381 {
14382 // DQ (2/9/2013): Adding support to build a SgSourceFile with an empty global scope.
14383 // This function calls the buildFile(string,string,SgProject*) function and provides
14384 // a simple API where one wants to create a new SgSourceFile that will then have
14385 // statements added to it and then unparsed.
14386
14387 // This function needs a way to specify the associated language for the generated file.
14388 // Currently this is taken from the input file (generated from a prefix on the output filename.
14389
14390#if 1
14391 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
14392 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
14393 printf ("In SageBuilder::buildSourceFile(outputFileName = %s, project = %p) \n",outputFileName.c_str(),project);
14394 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
14395 printf ("B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1 \n");
14396#endif
14397
14398 // Call the supporting function to build a file.
14399 string inputFilePrefix = "temp_dummy_file_";
14400
14401#if 0
14402 printf ("In SageBuilder::buildSourceFile(const std::string& outputFileName, SgProject* project): calling buildFile() \n");
14403#endif
14404
14405 SgFile* file = buildFile(inputFilePrefix+outputFileName,outputFileName,project,clear_globalScopeAcrossFiles);
14406 ROSE_ASSERT(file != NULL);
14407
14408#if 0
14409 printf ("DONE: In SageBuilder::buildSourceFile(): calling buildFile() \n");
14410#endif
14411
14412 SgSourceFile* sourceFile = isSgSourceFile(file);
14413 ROSE_ASSERT(sourceFile != NULL);
14414
14415 ROSE_ASSERT(sourceFile->get_globalScope() != NULL);
14416
14417#if 0
14418 printf ("call the unparser on the just built file \n");
14419#endif
14420
14421#if 0
14422 printf ("Exiting as a test! \n");
14423 ROSE_ABORT();
14424#endif
14425
14426 return sourceFile;
14427
14428 }
14429
14430SgSourceFile* SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project, bool clear_globalScopeAcrossFiles /*=false*/)
14431 {
14432#if 0
14433 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
14434 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
14435 printf ("In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling buildFile() \n");
14436 // printf (" --- inputFileName = %s outputFileName = %s \n",inputFileName.c_str(),outputFileName.c_str());
14437 printf (" --- inputFileName = %s \n",inputFileName.c_str());
14438 printf (" --- outputFileName = %s \n",outputFileName.c_str());
14439 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
14440 printf ("B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2 \n");
14441#endif
14442
14443#if 0
14444 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14445 ROSE_ASSERT(project != NULL);
14446 std::set<SgLocatedNode*> tmp1_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14447
14448 if (tmp1_collectionOfModifiedLocatedNodes.size() > 0)
14449 {
14450 printf ("In Traversal::evaluateInheritedAttribute(): tmp1_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp1_collectionOfModifiedLocatedNodes.size());
14451#if 1
14452 printf ("Exiting as a test! \n");
14453 ROSE_ASSERT(false);
14454#endif
14455 }
14456#endif
14457
14458 SgFile* file = buildFile(inputFileName, outputFileName,project,clear_globalScopeAcrossFiles);
14459 ROSE_ASSERT(file != NULL);
14460
14461#if 0
14462 printf ("DONE: In SageBuilder::buildSourceFile(): calling buildFile() \n");
14463#endif
14464
14465#if 0
14466 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14467 ROSE_ASSERT(project != NULL);
14468 std::set<SgLocatedNode*> tmp2_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14469
14470 if (tmp2_collectionOfModifiedLocatedNodes.size() > 0)
14471 {
14472 printf ("In Traversal::evaluateInheritedAttribute(): tmp2_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp2_collectionOfModifiedLocatedNodes.size());
14473#if 1
14474 printf ("Exiting as a test! \n");
14475 ROSE_ASSERT(false);
14476#endif
14477 }
14478#endif
14479
14480 SgSourceFile* sourceFile = isSgSourceFile(file);
14481 ROSE_ASSERT(sourceFile != NULL);
14482
14483 ROSE_ASSERT(sourceFile->get_globalScope() != NULL);
14484
14485#if 0
14486 // DQ (9/18/2019): Adding support for debugging the header file optimization.
14487 printf ("Debugging the unparsing header file optimization \n");
14488
14489 printf ("sourceFile->get_header_file_unparsing_optimization() = %s \n",sourceFile->get_header_file_unparsing_optimization() ? "true" : "false");
14490 printf ("sourceFile->get_header_file_unparsing_optimization_source_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14491 printf ("sourceFile->get_header_file_unparsing_optimization_header_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14492#endif
14493
14494#if 0
14495 // ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == false);
14496
14497 // 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.
14498 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization() == true);
14499 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_source_file() == true);
14500 // ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == true);
14501 ROSE_ASSERT(sourceFile->get_header_file_unparsing_optimization_header_file() == false);
14502#endif
14503
14504 // DQ (9/18/2019): Adding support for the header file optimization.
14505 // Check is this file matches an existing file and if so avoid regathering the CPP directives and comments (if posible).
14506 // If the original file was specified as being optimized for unparsing header files, then make this one similarly.
14507 SgFilePtrList & fileList = project->get_fileList();
14508
14509#if 0
14510 printf ("Looking for file = %s \n",inputFileName.c_str());
14511#endif
14512
14513 for (SgFilePtrList::iterator i = fileList.begin(); i != fileList.end(); i++)
14514 {
14515 SgFile* temp_file = *i;
14516#if 0
14517 printf ("temp_file = %p = %s name = %s \n",temp_file,temp_file->class_name().c_str(),temp_file->getFileName().c_str());
14518#endif
14519 if (temp_file != file)
14520 {
14521 if (temp_file->getFileName() == file->getFileName())
14522 {
14523 // Then the temp_file is the original version of the file we are building for a second time
14524 // (usually as a part of the outlining to a seperate file). and we need to mark at least the
14525 // unparsing headr file optimizations to be the same across thje two file.
14526
14527 // DQ (6/12/2021): The header_file_unparsing_optimization is now a static data member and the
14528 // header_file_unparsing_optimization_source_file and header_file_unparsing_optimization_header_file
14529 // data members have been removed.
14530 // temp_file->set_header_file_unparsing_optimization(sourceFile->get_header_file_unparsing_optimization());
14531 // temp_file->set_header_file_unparsing_optimization_source_file(sourceFile->get_header_file_unparsing_optimization_source_file());
14532 // temp_file->set_header_file_unparsing_optimization_header_file(sourceFile->get_header_file_unparsing_optimization_header_file());
14533#if 0
14534 printf ("sourceFile = %p = %s \n",sourceFile,sourceFile->class_name().c_str());
14535 printf ("sourceFile->get_header_file_unparsing_optimization() = %s \n",sourceFile->get_header_file_unparsing_optimization() ? "true" : "false");
14536 printf ("sourceFile->get_header_file_unparsing_optimization_source_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14537 printf ("sourceFile->get_header_file_unparsing_optimization_header_file() = %s \n",sourceFile->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14538
14539 printf ("temp_file = %p = %s \n",temp_file,temp_file->class_name().c_str());
14540 printf ("temp_file->get_header_file_unparsing_optimization() = %s \n",temp_file->get_header_file_unparsing_optimization() ? "true" : "false");
14541 printf ("temp_file->get_header_file_unparsing_optimization_source_file() = %s \n",temp_file->get_header_file_unparsing_optimization_source_file() ? "true" : "false");
14542 printf ("temp_file->get_header_file_unparsing_optimization_header_file() = %s \n",temp_file->get_header_file_unparsing_optimization_header_file() ? "true" : "false");
14543#endif
14544 }
14545 else
14546 {
14547 // This is a different file.
14548 }
14549 }
14550 else
14551 {
14552 // This is the same file, already added to the SgProject file list (as it should be).
14553 }
14554 }
14555
14556
14557#if 0
14558 printf ("sourceFile->get_file_info()->get_filename() = %s \n",sourceFile->get_file_info()->get_filename());
14559 int filename_id = Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()];
14560 int filename_physical_id = Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()];
14561 printf ("Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()] = %d \n",filename_id);
14562 printf ("Sg_File_Info::get_nametofileid_map()[sourceFile->get_file_info()->get_filename()] = %d \n",filename_physical_id);
14563 sourceFile->get_file_info()->set_physical_file_id(filename_physical_id);
14564
14565 printf ("sourceFile->get_file_info()->get_physical_filename() = %s \n",sourceFile->get_file_info()->get_physical_filename().c_str());
14566 printf ("sourceFile->get_file_info()->get_physical_file_id() = %d \n",sourceFile->get_file_info()->get_physical_file_id());
14567#endif
14568
14569#if 0
14570 printf ("Exiting as a test! \n");
14571 ROSE_ABORT();
14572#endif
14573
14574 // DQ (1/11/2021): I think we should be calling secondaryPassOverSourceFile() instead of attachPreprocessingInfo() because we need to support the token-based unparsing.
14575#if 0
14576
14577#error "DEAD CODE!"
14578
14579#if 1
14580 // DQ (11/4/2019): I need to add this when I went back to testing tool_G.
14581 // It is required in the functions to attach CPP directives and comments.
14582 if (sourceFile->get_preprocessorDirectivesAndCommentsList() == NULL)
14583 {
14584#if 1
14585 printf ("Initialize NULL p_preprocessorDirectivesAndCommentsList to empty ROSEAttributesListContainer \n");
14586#endif
14587 ROSEAttributesListContainer* tmp_preprocessorDirectivesAndCommentsList = new ROSEAttributesListContainer();
14588 sourceFile->set_preprocessorDirectivesAndCommentsList(tmp_preprocessorDirectivesAndCommentsList);
14589 }
14590 else
14591 {
14592#if 1
14593 printf ("NOTE: p_preprocessorDirectivesAndCommentsList is already defined! \n");
14594 printf (" --- inputFileName = %s \n",inputFileName.c_str());
14595 printf (" --- outputFileName = %s \n",outputFileName.c_str());
14596 printf (" --- sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size() = %zu \n",sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size());
14597#endif
14598 }
14599 ROSE_ASSERT (sourceFile->get_preprocessorDirectivesAndCommentsList() != NULL);
14600
14601#if 0
14602 // DQ (5/22/2020): If this is processing a previously processed file, then this
14603 // will cause comments and CPP directives to be collected twice. This happens
14604 // in the case where we build a copy of the source file to support construction
14605 // of a dynamic library.
14606 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");
14607#endif
14608
14609 // DQ (11/4/2019): This is a test that is use in attaching CPP directives and comments to the AST.
14610 ROSEAttributesListContainerPtr filePreprocInfo = sourceFile->get_preprocessorDirectivesAndCommentsList();
14611 ROSE_ASSERT(filePreprocInfo != NULL);
14612#endif
14613
14614#error "DEAD CODE!"
14615
14616#if 0
14617 printf ("In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling attachPreprocessingInfo() \n");
14618 printf (" --- sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size() = %zu \n",sourceFile->get_preprocessorDirectivesAndCommentsList()->getList().size());
14619#endif
14620
14621#if 0
14622 // 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.
14623 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");
14624 printf (" --- inputFileName = %s \n",inputFileName.c_str());
14625 printf (" --- outputFileName = %s \n",outputFileName.c_str());
14626 printf ("sourceFile = %p \n",sourceFile);
14627 printf ("sourceFile->get_token_list.size() = %zu \n",sourceFile->get_token_list().size());
14628 printf ("sourceFile->get_tokenSubsequenceMap().size() = %zu \n",sourceFile->get_tokenSubsequenceMap().size());
14629#endif
14630
14631#error "DEAD CODE!"
14632
14633 // DQ (1/4/2020): Adding support to permit comments and CPP directives and token stream to be defined using the outputFileName.
14634 // Liao, 2019, 1/31: We often need the preprocessing info. (e.g. #include ..) attached to make the new file compilable.
14635 // attachPreprocessingInfo (sourceFile);
14636 attachPreprocessingInfo (sourceFile,outputFileName);
14637#else
14638 // DQ (1/11/2021): Call the secondaryPassOverSourceFile() instead of attachPreprocessingInfo() because we need to support the token-based unparsing.
14640#endif
14641
14642#if 0
14643 printf ("Exiting after test! processed first phase of collecting comments and CPP directives for source file) \n");
14644 ROSE_ASSERT(false);
14645#endif
14646
14647#if 0
14648 printf ("DONE: In SageBuilder::buildSourceFile(const std::string& inputFileName,const std::string& outputFileName, SgProject* project): calling attachPreprocessingInfo() \n");
14649#endif
14650
14651#if 0
14652 printf ("call the unparser on the just built file \n");
14653#endif
14654
14655#if 0
14656 printf ("In buildSourceFile(): AS A TEST: calling unparseFile(): filename = %s \n",sourceFile->getFileName().c_str());
14657 backend(project);
14658#endif
14659
14660#if 1
14661 // DQ (11/8/2019): This is not working and breaks the current work at present.
14662 // DQ (11/8/2019): Support function to change the name in each of the IR node's source position info objects.
14663 fixupSourcePositionFileSpecification(sourceFile,outputFileName);
14664#endif
14665
14666 // DQ (1/8/2021): Set the filename used in the generated SgSourceFile to be the output file.
14667 // This appears to be important so that we can get either key correct for the comments and CPP
14668 // directives and or the comments and CPP directives to be consistant as well as the token stream,
14669 // I think this might be less about the comments and CPP directives than the key for the token stream.
14670 // Either that or I need to have an extra field for the SgSourceFile name when it is read from one
14671 // file, but trying to be another file.
14672 // sourceFile->setFileName(outputFileName);
14673
14674#if 0
14675 printf ("In SageBuilder::buildSourceFile(): changing the name of the file represented in sourceFile: \n");
14676 printf ("inputFileName = %s \n",inputFileName.c_str());
14677 printf ("outputFileName = %s \n",outputFileName.c_str());
14678 printf ("sourceFile->getFileName() = %s \n",sourceFile->getFileName().c_str());
14679#endif
14680
14681 SgGlobal* globalScope = sourceFile->get_globalScope();
14682
14683#if 0
14684 printf ("Leaving SageBuilder::buildSourceFile() sourceFile = %p globalScope = %p \n",sourceFile,sourceFile->get_globalScope());
14685 printf ("sourceFile->get_file_info()->get_file_id() = %d \n",sourceFile->get_file_info()->get_file_id());
14686 printf ("sourceFile->get_file_info()->get_physical_file_id() = %d \n",sourceFile->get_file_info()->get_physical_file_id());
14687 printf ("sourceFile->get_token_list.size() = %zu \n",sourceFile->get_token_list().size());
14688 printf ("sourceFile->get_tokenSubsequenceMap().size() = %zu \n",sourceFile->get_tokenSubsequenceMap().size());
14689 printf ("inputFileName = %s \n",inputFileName.c_str());
14690 printf ("outputFileName = %s \n",outputFileName.c_str());
14691 printf ("sourceFile->getFileName() = %s \n",sourceFile->getFileName().c_str());
14692
14693 printf ("sourceFile->get_globalScope() = %p \n",globalScope);
14694 printf ("globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
14695#endif
14696
14697 // DQ (6/1/2021): We need to end this function with the isModified flag set to false. This is
14698 // important for the support of the token based unparsing when building a dynamic library.
14699 // This is important in permitting the simpleFrontierDetectionForTokenStreamMapping() function
14700 // to generate the correct settings for nodes in the second file constructed from the original file.
14701 if (globalScope->get_isModified() == true)
14702 {
14703#if 0
14704 printf ("globalScope->get_isModified() == true: reset to false \n");
14705#endif
14706 globalScope->set_isModified(false);
14707#if 0
14708 printf ("Verify false setting: globalScope->get_isModified() = %s \n",globalScope->get_isModified() ? "true" : "false");
14709#endif
14710 }
14711
14712#if 0
14713 // DQ (6/21/2021): Checking for any modifications to located nodes (an issue when we are detecting which header files to unparse).
14714 ROSE_ASSERT(project != NULL);
14715 std::set<SgLocatedNode*> tmp3_collectionOfModifiedLocatedNodes = collectModifiedLocatedNodes(project);
14716
14717 if (tmp3_collectionOfModifiedLocatedNodes.size() > 0)
14718 {
14719 printf ("In Traversal::evaluateInheritedAttribute(): tmp3_collectionOfModifiedLocatedNodes.size() = %zu \n",tmp3_collectionOfModifiedLocatedNodes.size());
14720#if 1
14721 printf ("Exiting as a test! \n");
14722 ROSE_ASSERT(false);
14723#endif
14724 }
14725#endif
14726
14727#if 0
14728 printf ("Exiting as a test! \n");
14729 ROSE_ABORT();
14730#endif
14731
14732 return sourceFile;
14733 }
14734
14735
14736PreprocessingInfo* SageBuilder::buildComment(SgLocatedNode* target, const std::string & content,PreprocessingInfo::RelativePositionType position/*=PreprocessingInfo::before*/,PreprocessingInfo::DirectiveType dtype/* = PreprocessingInfo::CpreprocessorUnknownDeclaration*/)
14737 {
14738 return SageInterface::attachComment(target,content, position, dtype);
14739 }
14740
14742PreprocessingInfo* SageBuilder::buildHeader(const std::string& header_filename,
14743 PreprocessingInfo::RelativePositionType position/*=PreprocessingInfo::before*/,
14744 bool isSystemHeader/* =false*/)
14745{
14746 std::string content;
14747 if (isSystemHeader)
14748 content = "#include <" + header_filename + "> \n";
14749 else
14750 content = "#include \"" + header_filename + "\" \n";
14751 PreprocessingInfo* result = new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration,
14752 content, "Transformation generated",0, 0, 0, position);
14753 ROSE_ASSERT(result);
14754
14755 result->get_file_info()->setTransformation();
14756 return result;
14757}
14758
14760PreprocessingInfo* SageBuilder::buildCpreprocessorDefineDeclaration(SgLocatedNode* target,const std::string & content,PreprocessingInfo::RelativePositionType position /* =PreprocessingInfo::before*/)
14761 {
14762 ROSE_ASSERT(target != NULL); //dangling #define xxx is not allowed in the ROSE AST
14763 // simple input verification
14764 std::string content2 = content;
14765 boost::algorithm::trim(content2);
14766 string prefix = "#define";
14767 string::size_type pos = content2.find(prefix, 0);
14768 ROSE_ASSERT (pos == 0);
14769
14770 PreprocessingInfo* result = NULL;
14771
14772 PreprocessingInfo::DirectiveType mytype = PreprocessingInfo::CpreprocessorDefineDeclaration;
14773
14774 // DQ (7/19/2008): Modified interface to PreprocessingInfo
14775 // result = new PreprocessingInfo (mytype,content, "transformation-generated", 0, 0, 0, position, false, true);
14776 result = new PreprocessingInfo (mytype,content, "transformation-generated", 0, 0, 0, position);
14777 ROSE_ASSERT(result);
14778 target->addToAttachedPreprocessingInfo(result);
14779 return result;
14780
14781 }
14782
14783
14784#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
14787{
14788 // avoid duplicated creation
14789 static std::map<SgNode*, AbstractHandle::abstract_handle *> handleMap;
14790
14791 ROSE_ASSERT(n != NULL);
14792 AbstractHandle::abstract_handle * ahandle =handleMap[n];
14793 if (ahandle==NULL)
14794 {
14796 ROSE_ASSERT(anode !=NULL );
14797 ahandle = new AbstractHandle::abstract_handle(anode);
14798 //TODO do we allow NULL handle to be returned?
14799 ROSE_ASSERT(ahandle != NULL);
14800 }
14801 return ahandle;
14802}
14803#endif
14804
14807{
14808 ROSE_ASSERT(exp1 != NULL);
14809 ROSE_ASSERT(exp2 != NULL);
14810
14811 SgExprListExp* tuple = buildExprListExp(exp1,exp2);
14812 SgExprListExp* setList = buildExprListExp(tuple);
14813 SgEquivalenceStatement* equivalenceStatement = new SgEquivalenceStatement();
14814 ROSE_ASSERT(equivalenceStatement->get_equivalence_set_list() == NULL);
14815 equivalenceStatement->set_equivalence_set_list(setList);
14816 ROSE_ASSERT(equivalenceStatement->get_equivalence_set_list() != NULL);
14817 equivalenceStatement->set_firstNondefiningDeclaration(equivalenceStatement);
14818 setOneSourcePositionForTransformation(equivalenceStatement);
14819 return equivalenceStatement;
14820}
14821
14822SgSymbol*
14824 {
14825 // Starting at the snippet_declaration, record the associated scope list to the global scope.
14826 // The do a reverse traversal on the list starting with the global scope of the target AST.
14827 // Lookup each declaration as we proceed deeper into the target AST to find the associated
14828 // symbol in the target AST (associated with the input declaration from the snippet AST).
14829
14830 SgSymbol* returnSymbol = NULL;
14831
14832 typedef Rose_STL_Container<SgScopeStatement*> SgScopeStatementPtrList;
14833 SgScopeStatementPtrList snippet_scope_list;
14834
14835 // Starting at the snippet_declaration, record the associated scope list to the global scope.
14836 // SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
14837 SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
14838#if 1
14839 printf ("First scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
14840 SgClassDefinition* temp_classDefinition = isSgClassDefinition(snippet_scope);
14841 if (temp_classDefinition != NULL)
14842 {
14843 SgClassDeclaration* temp_classDeclaration = temp_classDefinition->get_declaration();
14844 SgName className = temp_classDeclaration->get_name();
14845#if 1
14846 printf ("Input snippet declaration's class name = %s \n",className.str());
14847#endif
14848 }
14849 SgNamespaceDefinitionStatement* namespaceDefinitionStatement = isSgNamespaceDefinitionStatement(snippet_scope);
14850 if (namespaceDefinitionStatement != NULL)
14851 {
14852
14853 }
14854#endif
14855 snippet_scope_list.push_back(snippet_scope);
14856 while (snippet_scope != NULL && isSgGlobal(snippet_scope) == NULL)
14857 {
14858 // The scopes between the snippet declaration and the global scope should be named scopes,
14859 // else we will not be able to identify the associated scope in the target AST.
14860 ROSE_ASSERT(snippet_scope->isNamedScope() == true);
14861
14862 snippet_scope = snippet_scope->get_scope();
14863#if 1
14864 printf ("snippet_scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
14865#endif
14866 snippet_scope_list.push_back(snippet_scope);
14867 }
14868
14869#if 1
14870 printf ("snippet_scope_list.size() = %" PRIuPTR " \n",snippet_scope_list.size());
14871#endif
14872
14873 SgGlobal* global_scope_in_target_ast = TransformationSupport::getGlobalScope(targetScope);
14874 SgScopeStatementPtrList::reverse_iterator i = snippet_scope_list.rbegin();
14875
14876 SgScopeStatement* target_AST_scope = global_scope_in_target_ast;
14877 SgScopeStatement* snippet_AST_scope = *i;
14878
14879 ROSE_ASSERT(isSgGlobal(snippet_AST_scope) != NULL);
14880 // Iterate past the global scope
14881 i++;
14882
14883 // Traverse the snippet scopes in the reverse order from global scope to the associated scope in the target AST.
14884 while (i != snippet_scope_list.rend())
14885 {
14886 // This loop has to handle different types of names scopes (for C this only means structs, I think).
14887#if 1
14888 printf ("snippet_AST_scope list *i = %p = %s \n",*i,(*i)->class_name().c_str());
14889#endif
14890 // printf ("target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope ->class_name().c_str());
14891 // printf ("snippet_AST_scope = %p = %s \n",snippet_AST_scope,snippet_AST_scope ->class_name().c_str());
14892
14893 // DQ (12/5/2020): I think this should be a switch statement.
14894 SgClassDefinition* classDefinition = isSgClassDefinition(*i);
14895 if (classDefinition != NULL)
14896 {
14897 SgClassDeclaration* classDeclaration = classDefinition->get_declaration();
14898 SgName className = classDeclaration->get_name();
14899#if 1
14900 printf ("Found snippet class name = %s \n",className.str());
14901#endif
14902 SgClassSymbol* classSymbol = target_AST_scope->lookup_class_symbol(className);
14903 ROSE_ASSERT(classSymbol != NULL);
14904 ROSE_ASSERT(classSymbol->get_declaration() != NULL);
14905#if 1
14906 printf ("Associated symbol in taget AST: declaration = %p name = %s \n",classSymbol->get_declaration(),classSymbol->get_declaration()->get_name().str());
14907#endif
14908 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
14909 returnSymbol = classSymbol;
14910
14911 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
14912 target_AST_scope = classDefinition;
14913 }
14914
14915 // Not clear if we can have this case for C or C++.
14916 SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(*i);
14917 if (functionDefinition != NULL)
14918 {
14919 printf ("ERROR: Found an unusual case of SgFunctionDefinition in list of scopes holding a declaration for a type \n");
14920 ROSE_ABORT();
14921 }
14922
14923 SgNamespaceDefinitionStatement* namespaceDefinition = isSgNamespaceDefinitionStatement(*i);
14924 if (namespaceDefinition != NULL)
14925 {
14926 SgNamespaceDeclarationStatement* namespaceDeclaration = namespaceDefinition->get_namespaceDeclaration();
14927 SgName namespaceName = namespaceDeclaration->get_name();
14928#if 1
14929 printf ("Found snippet namespace name = %s \n",namespaceName.str());
14930#endif
14931 SgNamespaceSymbol* namespaceSymbol = target_AST_scope->lookup_namespace_symbol(namespaceName);
14932 ROSE_ASSERT(namespaceSymbol != NULL);
14933 ROSE_ASSERT(namespaceSymbol->get_declaration() != NULL);
14934#if 1
14935 printf ("Associated symbol in taget AST: declaration = %p name = %s \n",namespaceSymbol->get_declaration(),namespaceSymbol->get_declaration()->get_name().str());
14936#endif
14937 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
14938 returnSymbol = namespaceSymbol;
14939
14940 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
14941 target_AST_scope = namespaceDefinition;
14942 }
14943
14944 // Increment the reverse iterator.
14945 i++;
14946 }
14947
14948 // Handle the different cases using a switch (there are only a few cases).
14949 switch (snippet_declaration->variantT())
14950 {
14951 case V_SgClassDeclaration:
14952 {
14953 SgClassDeclaration* snippet_classDeclaration = isSgClassDeclaration(snippet_declaration);
14954 ROSE_ASSERT(snippet_classDeclaration != NULL);
14955
14956 SgName snippet_className = snippet_classDeclaration->get_name();
14957#if 0
14958 printf ("snippet snippet declaration's class name = %s \n",snippet_className.str());
14959#endif
14960 SgClassSymbol* target_symbol = target_AST_scope->lookup_class_symbol(snippet_className);
14961 ROSE_ASSERT(target_symbol != NULL);
14962 returnSymbol = target_symbol;
14963
14964 SgClassSymbol* classSymbolInTargetAST = isSgClassSymbol(returnSymbol);
14965 ROSE_ASSERT(classSymbolInTargetAST != NULL);
14966 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
14967 ROSE_ASSERT(target_classDeclaration != NULL);
14968#if 0
14969 printf ("snippet: classDeclaration = %p = %s \n",snippet_classDeclaration,snippet_classDeclaration->get_name().str());
14970 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
14971#endif
14972 ROSE_ASSERT(snippet_classDeclaration->get_name() == target_classDeclaration->get_name());
14973 break;
14974 }
14975
14976 case V_SgTypedefDeclaration:
14977 {
14978 SgTypedefDeclaration* snippet_typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
14979 ROSE_ASSERT(snippet_typedefDeclaration != NULL);
14980
14981 SgName snippet_typedefName = snippet_typedefDeclaration->get_name();
14982#if 0
14983 printf ("snippet snippet declaration's typedef name = %s \n",snippet_typedefName.str());
14984#endif
14985 SgTypedefSymbol* target_symbol = target_AST_scope->lookup_typedef_symbol(snippet_typedefName);
14986 ROSE_ASSERT(target_symbol != NULL);
14987 returnSymbol = target_symbol;
14988
14989 SgTypedefSymbol* typedefSymbolInTargetAST = isSgTypedefSymbol(returnSymbol);
14990 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
14991 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
14992 ROSE_ASSERT(target_typedefDeclaration != NULL);
14993#if 0
14994 printf ("snippet: typedefDeclaration = %p = %s \n",snippet_typedefDeclaration,snippet_typedefDeclaration->get_name().str());
14995 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
14996#endif
14997 ROSE_ASSERT(snippet_typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
14998 break;
14999 }
15000
15001 case V_SgEnumDeclaration:
15002 {
15003 SgEnumDeclaration* snippet_enumDeclaration = isSgEnumDeclaration(snippet_declaration);
15004 ROSE_ASSERT(snippet_enumDeclaration != NULL);
15005
15006 SgName snippet_enumName = snippet_enumDeclaration->get_name();
15007#if 0
15008 printf ("snippet snippet declaration's enum name = %s \n",snippet_enumName.str());
15009#endif
15010 // DQ (4/13/2014): check if this is an un-named enum beclaration.
15011 bool isUnNamed = snippet_enumDeclaration->get_isUnNamed();
15012 if (isUnNamed == false)
15013 {
15014 // SgEnumSymbol* target_symbol = target_AST_scope->lookup_enum_symbol(snippet_enumName);
15015 SgEnumSymbol* target_symbol = lookupEnumSymbolInParentScopes(snippet_enumName,target_AST_scope);
15016 if (target_symbol == NULL)
15017 {
15018 // Debug this case.
15019 SgScopeStatement* scope = snippet_enumDeclaration->get_scope();
15020 printf ("scope = %p = %s \n",scope,scope->class_name().c_str());
15021 scope->get_file_info()->display("case V_SgEnumDeclaration: target_symbol == NULL: scope: debug");
15022 }
15023 ROSE_ASSERT(target_symbol != NULL);
15024 returnSymbol = target_symbol;
15025
15026 SgEnumSymbol* enumSymbolInTargetAST = isSgEnumSymbol(returnSymbol);
15027 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
15028 SgEnumDeclaration* target_enumDeclaration = isSgEnumDeclaration(enumSymbolInTargetAST->get_declaration());
15029 ROSE_ASSERT(target_enumDeclaration != NULL);
15030#if 0
15031 printf ("snippet: enumDeclaration = %p = %s \n",snippet_enumDeclaration,snippet_enumDeclaration->get_name().str());
15032 printf ("target: enumDeclaration = %p = %s \n",target_enumDeclaration,target_enumDeclaration->get_name().str());
15033#endif
15034 ROSE_ASSERT(snippet_enumDeclaration->get_name() == target_enumDeclaration->get_name());
15035 }
15036 else
15037 {
15038 // DQ (4/13/2014): I think we all agreed these would not have to be handled.
15039 printf ("Warning: can't handle unnamed enum declarations \n");
15040 ROSE_ASSERT(returnSymbol == NULL);
15041 }
15042 break;
15043 }
15044
15045 // DQ (12/5/2020): Adding support for codeSegregation tool.
15046 case V_SgMemberFunctionDeclaration:
15047 case V_SgFunctionDeclaration:
15048 {
15049 SgFunctionDeclaration* snippet_functionDeclaration = isSgFunctionDeclaration(snippet_declaration);
15050 ROSE_ASSERT(snippet_functionDeclaration != NULL);
15051#if 1
15052 printf ("snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15053#endif
15054 SgName snippet_functionName = snippet_functionDeclaration->get_name();
15055#if 1
15056 printf ("snippet snippet declaration's function name = %s \n",snippet_functionName.str());
15057 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope->class_name().c_str());
15058#endif
15059 SgFunctionSymbol* target_symbol = target_AST_scope->lookup_function_symbol(snippet_functionName);
15060 ROSE_ASSERT(target_symbol != NULL);
15061 returnSymbol = target_symbol;
15062
15063 SgFunctionSymbol* functionSymbolInTargetAST = isSgFunctionSymbol(returnSymbol);
15064 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
15065 SgFunctionDeclaration* target_functionDeclaration = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
15066 ROSE_ASSERT(target_functionDeclaration != NULL);
15067#if 1
15068 printf ("snippet: functionDeclaration = %p = %s \n",snippet_functionDeclaration,snippet_functionDeclaration->get_name().str());
15069 printf ("target: functionDeclaration = %p = %s \n",target_functionDeclaration,target_functionDeclaration->get_name().str());
15070#endif
15071 ROSE_ASSERT(snippet_functionDeclaration->get_name() == target_functionDeclaration->get_name());
15072 break;
15073 }
15074
15075 default:
15076 {
15077 printf ("Error: default reached in switch: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15078 ROSE_ABORT();
15079 }
15080 }
15081
15082 // return the last found symbol.
15083 return returnSymbol;
15084 }
15085
15086
15089 {
15090 // DQ (12/6/2020): This is a similar function to findAssociatedSymbolInTargetAST() but since
15091 // I need to modify it to support the requirements of the codeSegregation, it was useful to not
15092 // modify the existing findAssociatedSymbolInTargetAST() function too much so as to avoid
15093 // compromizing the snippet transformation support.
15094
15095#define DEBUG_FIND_ASSOCIATED_DECLARATION 0
15096
15097 SgSymbol* returnSymbol = NULL;
15098 SgDeclarationStatement* returnDeclaration = NULL;
15099
15100 bool isDefiningDeclaration = (snippet_declaration == snippet_declaration->get_definingDeclaration());
15101
15102#if DEBUG_FIND_ASSOCIATED_DECLARATION
15103 printf ("isDefiningDeclaration = %s \n",isDefiningDeclaration ? "true" : "false");
15104#endif
15105
15106 // DQ (12/7/2020): This should be true.
15107 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,targetScope) == false);
15108
15109 typedef Rose_STL_Container<SgScopeStatement*> SgScopeStatementPtrList;
15110 SgScopeStatementPtrList snippet_scope_list;
15111
15112 // Starting at the snippet_declaration, record the associated scope list to the global scope.
15113 // SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15114 SgScopeStatement* snippet_scope = snippet_declaration->get_scope();
15115#if DEBUG_FIND_ASSOCIATED_DECLARATION
15116 printf ("First scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15117 SgClassDefinition* temp_classDefinition = isSgClassDefinition(snippet_scope);
15118 if (temp_classDefinition != NULL)
15119 {
15120 SgClassDeclaration* temp_classDeclaration = temp_classDefinition->get_declaration();
15121 SgName className = temp_classDeclaration->get_name();
15122 printf ("Input declaration's class name = %s \n",className.str());
15123 }
15124
15125 SgNamespaceDefinitionStatement* namespaceDefinitionStatement = isSgNamespaceDefinitionStatement(snippet_scope);
15126 if (namespaceDefinitionStatement != NULL)
15127 {
15128 SgNamespaceDeclarationStatement* temp_namespaceDeclaration = namespaceDefinitionStatement->get_namespaceDeclaration();
15129 SgName namespaceName = temp_namespaceDeclaration->get_name();
15130 printf ("Input declaration's namespace name = %s \n",namespaceName.str());
15131 }
15132#endif
15133
15134 snippet_scope_list.push_back(snippet_scope);
15135 while (snippet_scope != NULL && isSgGlobal(snippet_scope) == NULL)
15136 {
15137 // The scopes between the snippet declaration and the global scope should be named scopes,
15138 // else we will not be able to identify the associated scope in the target AST.
15139 ROSE_ASSERT(snippet_scope->isNamedScope() == true);
15140
15141 snippet_scope = snippet_scope->get_scope();
15142
15143#if DEBUG_FIND_ASSOCIATED_DECLARATION
15144 printf ("snippet_scope = %p = %s \n",snippet_scope,snippet_scope->class_name().c_str());
15145#endif
15146 snippet_scope_list.push_back(snippet_scope);
15147
15148 // DQ (12/7/2020): At this point the scopes that we are traversing to the global scope should
15149 // have the same global scope as the input declaration.
15150 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_scope) == true);
15151 }
15152
15153#if DEBUG_FIND_ASSOCIATED_DECLARATION
15154 printf ("snippet_scope_list.size() = %" PRIuPTR " \n",snippet_scope_list.size());
15155 for (SgScopeStatementPtrList::iterator i = snippet_scope_list.begin(); i != snippet_scope_list.end(); i++)
15156 {
15157 SgScopeStatement* scope = *i;
15158 printf (" --- *i = %p = %s name = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
15159 SgGlobal* global_scope_from_declarations_scope = TransformationSupport::getGlobalScope(scope);
15160 printf (" --- --- global_scope_from_declarations_scope = %p \n",global_scope_from_declarations_scope);
15161 }
15162#endif
15163
15164 // DQ (12/7/2020): At this point the scopes that we are traversing to the global scope should
15165 // have the same global scope as the input declaration.
15166 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_scope) == true);
15167
15168 SgGlobal* global_scope_in_target_ast = TransformationSupport::getGlobalScope(targetScope);
15169 SgScopeStatementPtrList::reverse_iterator i = snippet_scope_list.rbegin();
15170
15171#if DEBUG_FIND_ASSOCIATED_DECLARATION
15172 printf ("global_scope_in_target_ast = %p = %s \n",global_scope_in_target_ast,global_scope_in_target_ast->class_name().c_str());
15173#endif
15174
15175 SgScopeStatement* target_AST_scope = global_scope_in_target_ast;
15176 SgScopeStatement* snippet_AST_scope = *i;
15177
15178 // DQ (12/7/2020): This should be true.
15179 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,snippet_AST_scope) == true);
15180
15181 ROSE_ASSERT(isSgGlobal(snippet_AST_scope) != NULL);
15182 // Iterate past the global scope
15183 i++;
15184
15185#if DEBUG_FIND_ASSOCIATED_DECLARATION
15186 string otherASTnameFromGlobalScope = global_scope_in_target_ast->get_file_info()->get_filenameString();
15187 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(targetScope,true);
15188 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15189 printf ("Now traverse the list of scopes in reverse to find the declaration in the other AST: \n");
15190 printf ("otherASTnameFromGlobalScope = %s \n",otherASTnameFromGlobalScope.c_str());
15191 printf ("otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15192#endif
15193
15194 // DQ (12/7/2020): This should be true.
15195 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15196
15197 // Traverse the snippet scopes in the reverse order from global scope to the associated scope in the target AST.
15198 while (i != snippet_scope_list.rend())
15199 {
15200 // This loop has to handle different types of names scopes (for C this only means structs, I think).
15201
15202 SgScopeStatement* scope = *i;
15203
15204#if DEBUG_FIND_ASSOCIATED_DECLARATION
15205 printf ("snippet_AST_scope list *i = %p = %s \n",*i,(*i)->class_name().c_str());
15206 printf (" --- *i = %p = %s name = %s \n",scope,scope->class_name().c_str(),SageInterface::get_name(scope).c_str());
15207 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope ->class_name().c_str());
15208 // printf ("snippet_AST_scope = %p = %s \n",snippet_AST_scope,snippet_AST_scope ->class_name().c_str());
15209#endif
15210
15211 // DQ (12/7/2020): This should still be true.
15212 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,scope) == true);
15213
15214#if DEBUG_FIND_ASSOCIATED_DECLARATION
15215 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(targetScope,true);
15216 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15217 printf (" --- otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15218#endif
15219
15220 // DQ (12/5/2020): I think this should be a switch statement.
15221 SgClassDefinition* classDefinition = isSgClassDefinition(*i);
15222 if (classDefinition != NULL)
15223 {
15224 SgClassDeclaration* classDeclaration = classDefinition->get_declaration();
15225 SgName className = classDeclaration->get_name();
15226#if DEBUG_FIND_ASSOCIATED_DECLARATION
15227 printf (" --- Found snippet class name = %s \n",className.str());
15228#endif
15229 SgClassSymbol* classSymbol = target_AST_scope->lookup_class_symbol(className);
15230 ROSE_ASSERT(classSymbol != NULL);
15231 ROSE_ASSERT(classSymbol->get_declaration() != NULL);
15232#if DEBUG_FIND_ASSOCIATED_DECLARATION
15233 printf (" --- Associated symbol in taget AST: declaration = %p name = %s \n",classSymbol->get_declaration(),classSymbol->get_declaration()->get_name().str());
15234#endif
15235 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15236 returnSymbol = classSymbol;
15237
15238 // DQ (12/8/2020): Need to get the associated class definition from the symbol in the target scope.
15239 SgClassDeclaration* temp_classDeclaration_in_target_ast = classSymbol->get_declaration();
15240 ROSE_ASSERT(temp_classDeclaration_in_target_ast != NULL);
15241 SgClassDeclaration* classDeclaration_in_target_ast = isSgClassDeclaration(temp_classDeclaration_in_target_ast->get_definingDeclaration());
15242 ROSE_ASSERT(classDeclaration_in_target_ast != NULL);
15243 SgClassDefinition* classDefinition_in_target_ast = classDeclaration_in_target_ast->get_definition();
15244 ROSE_ASSERT(classDefinition_in_target_ast != NULL);
15245
15246 // DQ (12/7/2020): This should be true.
15247 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15248
15249 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15250 // target_AST_scope = classDefinition;
15251 target_AST_scope = classDefinition_in_target_ast;
15252
15253 // DQ (12/7/2020): This should be true.
15254 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15255 }
15256
15257 // Not clear if we can have this case for C or C++.
15258 SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(*i);
15259 if (functionDefinition != NULL)
15260 {
15261 printf ("ERROR: Found an unusual case of SgFunctionDefinition in list of scopes holding a declaration for a type \n");
15262 ROSE_ABORT();
15263 }
15264
15265 SgNamespaceDefinitionStatement* namespaceDefinition = isSgNamespaceDefinitionStatement(*i);
15266 if (namespaceDefinition != NULL)
15267 {
15268 SgNamespaceDeclarationStatement* namespaceDeclaration = namespaceDefinition->get_namespaceDeclaration();
15269 SgName namespaceName = namespaceDeclaration->get_name();
15270#if DEBUG_FIND_ASSOCIATED_DECLARATION
15271 printf (" --- Found snippet namespace name = %s \n",namespaceName.str());
15272#endif
15273 SgNamespaceSymbol* namespaceSymbol = target_AST_scope->lookup_namespace_symbol(namespaceName);
15274 ROSE_ASSERT(namespaceSymbol != NULL);
15275 ROSE_ASSERT(namespaceSymbol->get_declaration() != NULL);
15276 SgNamespaceDeclarationStatement* otherASTnamespaceDeclaration = namespaceSymbol->get_declaration();
15277#if DEBUG_FIND_ASSOCIATED_DECLARATION
15278 printf (" --- Associated symbol in taget AST: declaration = %p name = %s \n",namespaceSymbol->get_declaration(),namespaceSymbol->get_declaration()->get_name().str());
15279#endif
15280 // Set the return value as we go so that it will be properly set at the end of the reverse iteration over the scopes.
15281 returnSymbol = namespaceSymbol;
15282
15283 // DQ (12/7/2020): This should be true.
15284 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15285
15286 // Reset the target AST scope (as we traverse down the AST to the associated declaration in the target AST).
15287 // target_AST_scope = namespaceDefinition;
15288 target_AST_scope = otherASTnamespaceDeclaration->get_definition();
15289
15290 // DQ (12/7/2020): This should be true.
15291 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15292 }
15293
15294 // DQ (12/7/2020): This should be true.
15295 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15296
15297#if DEBUG_FIND_ASSOCIATED_DECLARATION
15298 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());
15299
15300 {
15301 SgSourceFile* otherSourceFile = SageInterface::getEnclosingNode<SgSourceFile>(target_AST_scope,true);
15302 string otherASTnameFromSourceFile = otherSourceFile->getFileName();
15303 printf (" --- At base of loop: otherASTnameFromSourceFile = %s \n",otherASTnameFromSourceFile.c_str());
15304 }
15305#endif
15306 // Increment the reverse iterator.
15307 i++;
15308 }
15309
15310#if DEBUG_FIND_ASSOCIATED_DECLARATION
15311 printf ("##### Now based on the kind of declaration, search for that same named declaration in the target_AST_scope = %p = %s \n",
15312 target_AST_scope,target_AST_scope->class_name().c_str());
15313#endif
15314
15315 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,target_AST_scope) == false);
15316
15317 // Handle the different cases using a switch (there are only a few cases).
15318 switch (snippet_declaration->variantT())
15319 {
15320 case V_SgClassDeclaration:
15321 {
15322 SgClassDeclaration* snippet_classDeclaration = isSgClassDeclaration(snippet_declaration);
15323 ROSE_ASSERT(snippet_classDeclaration != NULL);
15324
15325 SgName snippet_className = snippet_classDeclaration->get_name();
15326
15327#if DEBUG_FIND_ASSOCIATED_DECLARATION
15328 printf ("snippet snippet declaration's class name = %s \n",snippet_className.str());
15329#endif
15330 SgClassSymbol* target_symbol = target_AST_scope->lookup_class_symbol(snippet_className);
15331 ROSE_ASSERT(target_symbol != NULL);
15332 returnSymbol = target_symbol;
15333
15334 SgClassSymbol* classSymbolInTargetAST = isSgClassSymbol(returnSymbol);
15335 ROSE_ASSERT(classSymbolInTargetAST != NULL);
15336 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
15337 ROSE_ASSERT(target_classDeclaration != NULL);
15338
15339#if DEBUG_FIND_ASSOCIATED_DECLARATION
15340 printf ("snippet: classDeclaration = %p = %s \n",snippet_classDeclaration,snippet_classDeclaration->get_name().str());
15341 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
15342#endif
15343 ROSE_ASSERT(snippet_classDeclaration->get_name() == target_classDeclaration->get_name());
15344 break;
15345 }
15346
15347 case V_SgTypedefDeclaration:
15348 {
15349 SgTypedefDeclaration* snippet_typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
15350 ROSE_ASSERT(snippet_typedefDeclaration != NULL);
15351
15352 SgName snippet_typedefName = snippet_typedefDeclaration->get_name();
15353
15354#if DEBUG_FIND_ASSOCIATED_DECLARATION
15355 printf ("snippet snippet declaration's typedef name = %s \n",snippet_typedefName.str());
15356#endif
15357 SgTypedefSymbol* target_symbol = target_AST_scope->lookup_typedef_symbol(snippet_typedefName);
15358 ROSE_ASSERT(target_symbol != NULL);
15359 returnSymbol = target_symbol;
15360
15361 SgTypedefSymbol* typedefSymbolInTargetAST = isSgTypedefSymbol(returnSymbol);
15362 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15363 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
15364 ROSE_ASSERT(target_typedefDeclaration != NULL);
15365
15366#if DEBUG_FIND_ASSOCIATED_DECLARATION
15367 printf ("snippet: typedefDeclaration = %p = %s \n",snippet_typedefDeclaration,snippet_typedefDeclaration->get_name().str());
15368 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
15369#endif
15370 ROSE_ASSERT(snippet_typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
15371 break;
15372 }
15373
15374 case V_SgEnumDeclaration:
15375 {
15376 SgEnumDeclaration* snippet_enumDeclaration = isSgEnumDeclaration(snippet_declaration);
15377 ROSE_ASSERT(snippet_enumDeclaration != NULL);
15378
15379 SgName snippet_enumName = snippet_enumDeclaration->get_name();
15380
15381#if DEBUG_FIND_ASSOCIATED_DECLARATION
15382 printf ("snippet snippet declaration's enum name = %s \n",snippet_enumName.str());
15383#endif
15384 // DQ (4/13/2014): check if this is an un-named enum beclaration.
15385 bool isUnNamed = snippet_enumDeclaration->get_isUnNamed();
15386 if (isUnNamed == false)
15387 {
15388 // SgEnumSymbol* target_symbol = target_AST_scope->lookup_enum_symbol(snippet_enumName);
15389 SgEnumSymbol* target_symbol = lookupEnumSymbolInParentScopes(snippet_enumName,target_AST_scope);
15390 if (target_symbol == NULL)
15391 {
15392 // Debug this case.
15393 SgScopeStatement* scope = snippet_enumDeclaration->get_scope();
15394 printf ("scope = %p = %s \n",scope,scope->class_name().c_str());
15395 scope->get_file_info()->display("case V_SgEnumDeclaration: target_symbol == NULL: scope: debug");
15396 }
15397 ROSE_ASSERT(target_symbol != NULL);
15398 returnSymbol = target_symbol;
15399
15400 SgEnumSymbol* enumSymbolInTargetAST = isSgEnumSymbol(returnSymbol);
15401 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
15402 SgEnumDeclaration* target_enumDeclaration = isSgEnumDeclaration(enumSymbolInTargetAST->get_declaration());
15403 ROSE_ASSERT(target_enumDeclaration != NULL);
15404
15405#if DEBUG_FIND_ASSOCIATED_DECLARATION
15406 printf ("snippet: enumDeclaration = %p = %s \n",snippet_enumDeclaration,snippet_enumDeclaration->get_name().str());
15407 printf ("target: enumDeclaration = %p = %s \n",target_enumDeclaration,target_enumDeclaration->get_name().str());
15408#endif
15409 ROSE_ASSERT(snippet_enumDeclaration->get_name() == target_enumDeclaration->get_name());
15410 }
15411 else
15412 {
15413 // DQ (4/13/2014): I think we all agreed these would not have to be handled.
15414 printf ("Warning: can't handle unnamed enum declarations \n");
15415 ROSE_ASSERT(returnSymbol == NULL);
15416 }
15417 break;
15418 }
15419
15420 // DQ (12/11/2020): Adding support for codeSegregation tool.
15421 case V_SgTemplateMemberFunctionDeclaration:
15422 // DQ (12/8/2020): Adding support for codeSegregation tool.
15423 case V_SgTemplateFunctionDeclaration:
15424 // DQ (12/5/2020): Adding support for codeSegregation tool.
15425 case V_SgMemberFunctionDeclaration:
15426 case V_SgFunctionDeclaration:
15427 {
15428 SgFunctionDeclaration* snippet_functionDeclaration = isSgFunctionDeclaration(snippet_declaration);
15429 ROSE_ASSERT(snippet_functionDeclaration != NULL);
15430
15431#if DEBUG_FIND_ASSOCIATED_DECLARATION
15432 printf ("snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15433#endif
15434 SgName snippet_functionName = snippet_functionDeclaration->get_name();
15435
15436#if DEBUG_FIND_ASSOCIATED_DECLARATION
15437 printf ("snippet snippet declaration's function name = %s \n",snippet_functionName.str());
15438 printf (" --- target_AST_scope = %p = %s \n",target_AST_scope,target_AST_scope->class_name().c_str());
15439#endif
15440 SgFunctionSymbol* target_symbol = target_AST_scope->lookup_function_symbol(snippet_functionName);
15441 ROSE_ASSERT(target_symbol != NULL);
15442 returnSymbol = target_symbol;
15443
15444 SgFunctionSymbol* functionSymbolInTargetAST = isSgFunctionSymbol(returnSymbol);
15445 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
15446 SgFunctionDeclaration* target_functionDeclaration = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
15447 ROSE_ASSERT(target_functionDeclaration != NULL);
15448
15449#if DEBUG_FIND_ASSOCIATED_DECLARATION
15450 printf ("snippet: functionDeclaration = %p = %s \n",snippet_functionDeclaration,snippet_functionDeclaration->get_name().str());
15451 printf ("target: functionDeclaration = %p = %s \n",target_functionDeclaration,target_functionDeclaration->get_name().str());
15452 printf ("isDefiningDeclaration = %s \n",isDefiningDeclaration ? "true" : "false");
15453#endif
15454 if (isDefiningDeclaration == true)
15455 {
15456#if DEBUG_FIND_ASSOCIATED_DECLARATION
15457 printf ("get the defining declaration instead of the firstNondefining declaration from the function symbol \n");
15458#endif
15459 returnDeclaration = target_functionDeclaration->get_definingDeclaration();
15460 }
15461
15462 ROSE_ASSERT(snippet_functionDeclaration->get_name() == target_functionDeclaration->get_name());
15463 break;
15464 }
15465
15466 default:
15467 {
15468 printf ("Error: default reached in switch: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15469 ROSE_ABORT();
15470 }
15471 }
15472
15473 ROSE_ASSERT(returnDeclaration != NULL);
15474
15475 // These should have different global scopes, because they are from different ASTs.
15476 ROSE_ASSERT(SageInterface::hasSameGlobalScope(snippet_declaration,returnDeclaration) == false);
15477
15478 // return the last found symbol.
15479 // return returnSymbol;
15480 return returnDeclaration;
15481 }
15482
15483
15484SgType*
15486 {
15487 // This is the inner function to getTargetFileType()
15488 SgType* returnType = NULL;
15489
15490 ROSE_ASSERT(snippet_type != NULL);
15491 ROSE_ASSERT(targetScope != NULL);
15492
15493 // DQ (3/17/2014): Refactored code.
15494 // See if the type might be asociated with the snippet file.
15495 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
15496 // SgType* type_copy = snippet_type;
15497
15498#if 0
15499 SgType* type_copy = snippet_type;
15500 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
15501#endif
15502
15503 SgNamedType* namedType = isSgNamedType(snippet_type);
15504 if (namedType != NULL)
15505 {
15506 // Find the associated declaration and it's corresponding declaration in the target AST.
15507 SgDeclarationStatement* snippet_declaration = namedType->get_declaration();
15508 ROSE_ASSERT(snippet_declaration != NULL);
15509#if 0
15510 printf ("Need to find the declaration in the target AST that is associated with the snippet_declaration in the snippet AST \n");
15511 printf (" --- snippet_declaration = %p = %s = %s \n",snippet_declaration,snippet_declaration->class_name().c_str(),SageInterface::get_name(snippet_declaration).c_str());
15512#endif
15513 // There are only a few cases here!
15514 switch (namedType->variantT())
15515 {
15516 case V_SgClassType:
15517 {
15518 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
15519 if (classDeclaration != NULL)
15520 {
15521 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
15522 if (classSymbolInTargetAST == NULL)
15523 {
15524 // For Java or C++ this could be a name qualified type and so we need a better mechanism
15525 // to identify it thorugh it's parent scopes. Build a list of parent scope back to the
15526 // global scope and then traverse the list backwards to identify each scope in the target
15527 // AST's global scope until we each the associated declaration in the target AST.
15528#if 0
15529 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");
15530 printf (" --- Looking for target AST match for class name = %s \n",classDeclaration->get_name().str());
15531#endif
15532 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
15533 ROSE_ASSERT(symbol != NULL);
15534
15535 classSymbolInTargetAST = isSgClassSymbol(symbol);
15536 }
15537
15538 ROSE_ASSERT(classSymbolInTargetAST != NULL);
15539 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
15540 ROSE_ASSERT(target_classDeclaration != NULL);
15541#if 0
15542 printf ("snippet: classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
15543 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
15544#endif
15545 ROSE_ASSERT(classDeclaration->get_name() == target_classDeclaration->get_name());
15546
15547 returnType = classSymbolInTargetAST->get_type();
15548 }
15549 break;
15550 }
15551
15552 case V_SgTypedefType:
15553 {
15554 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
15555 if (typedefDeclaration != NULL)
15556 {
15557 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(typedefDeclaration->get_name(),targetScope);
15558
15559 // Not clear if we have to handle a more general case here.
15560 // ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15561 // returnType = typedefSymbolInTargetAST->get_type();
15562 if (typedefSymbolInTargetAST == NULL)
15563 {
15564#if 0
15565 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");
15566 printf (" --- The target AST must have a valid typedef type (and associated declaration) to support resetting the SgTypedefType: %p \n",typedefDeclaration->get_type());
15567#endif
15568 // DQ (3/16/2014): Find the associated typedef declaration (from the target AST)
15569 // for the input type associated with its declaration in the snippet AST.
15570 SgSymbol* symbol = findAssociatedSymbolInTargetAST(typedefDeclaration,targetScope);
15571 ROSE_ASSERT(symbol != NULL);
15572
15573 typedefSymbolInTargetAST = isSgTypedefSymbol(symbol);
15574
15575 // Note that test5d demonstrates this problem.
15576 // ROSE_ASSERT(false);
15577 }
15578
15579 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15580 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
15581 ROSE_ASSERT(target_typedefDeclaration != NULL);
15582#if 0
15583 printf ("snippet: typedefDeclaration = %p = %s \n",typedefDeclaration,typedefDeclaration->get_name().str());
15584 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
15585#endif
15586 ROSE_ASSERT(typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
15587
15588 returnType = typedefSymbolInTargetAST->get_type();
15589 }
15590 break;
15591 }
15592
15593 case V_SgEnumType:
15594 {
15595 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(snippet_declaration);
15596 if (enumDeclaration != NULL)
15597 {
15598 ROSE_ASSERT(enumDeclaration->get_name().is_null() == false);
15599 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(enumDeclaration->get_name(),targetScope);
15600
15601 // Not clear if we have to handle a more general case here.
15602 // ROSE_ASSERT(enumSymbolInTargetAST != NULL);
15603 // returnType = enumSymbolInTargetAST->get_type();
15604 if (enumSymbolInTargetAST == NULL)
15605 {
15606 printf ("Error: It is an error to not have a enum type defined in the target AST! \n");
15607 printf (" --- The target AST must have a valid enum type (and associated declaration) to support resetting the SgEnumType: %p \n",enumDeclaration->get_type());
15608
15609 // We will allow this to pass for now, since it is a violation of the target AST, and not the snippet mechanism (I think).
15610 returnType = snippet_type;
15611
15612 // Note that test5d demonstrates this problem.
15613 // ROSE_ASSERT(false);
15614 }
15615 else
15616 {
15617 returnType = enumSymbolInTargetAST->get_type();
15618 }
15619 }
15620
15621 break;
15622 }
15623
15624 case V_SgJavaParameterizedType:
15625 {
15626 // DQ (3/10/2014): This type is a view of a generic class with dynamic type checking (e.g. T).
15627 // This acts more like a class with reference to the template instead of the template instantiation.
15628 // So reset the declaration.
15629#if 0
15630 printf ("In getTargetFileTypeSupport(): case V_SgJavaParameterizedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15631#endif
15632#if 1
15633 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
15634 if (classDeclaration != NULL)
15635 {
15636#if 0
15637 printf ("Looking for classDeclaration = %s \n",classDeclaration->get_name().str());
15638#endif
15639 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
15640 ROSE_ASSERT(javaParameterizedType != NULL);
15641#if 0
15642 // SgTemplateParameterPtrList* templateParameterList = javaParameterizedType->get_type_list();
15643 SgTemplateParameterList* templateParameterListNode = javaParameterizedType->get_type_list();
15644 ROSE_ASSERT(templateParameterListNode != NULL);
15645 SgTemplateParameterPtrList* templateParameterList = &templateParameterListNode->get_args();
15646#else
15647 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
15648 // SgTemplateParameterPtrList* templateParameterList = NULL;
15649#endif
15650 // DQ (7/25/2014): Remove warning from GNU 4.8 compiler.
15651 // SgTemplateArgumentPtrList* templateSpecializationArgumentList = NULL;
15652#if 0
15653 printf ("Calling lookupTemplateClassSymbolInParentScopes() name = %s \n",classDeclaration->get_name().str());
15654#endif
15655 // SgTemplateClassSymbol* templateClassSymbolInTargetAST = lookupTemplateClassSymbolInParentScopes(classDeclaration->get_name(),templateParameterList,templateSpecializationArgumentList,targetScope);
15656 SgClassSymbol* templateClassSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
15657#if 0
15658 printf ("DONE: Calling lookupTemplateClassSymbolInParentScopes() \n");
15659#endif
15660#if 0
15661 printf ("targetScope->get_symbol_table()->size() = %d \n",targetScope->get_symbol_table()->size());
15662 if (templateClassSymbolInTargetAST == NULL)
15663 {
15664 targetScope->get_symbol_table()->print("ERROR: templateClassSymbolInTargetAST == NULL");
15665 }
15666#endif
15667 // DQ (3/30/2014): Add this approach.
15668 if (templateClassSymbolInTargetAST == NULL)
15669 {
15670#if 0
15671 printf ("Calling findAssociatedSymbolInTargetAST \n");
15672#endif
15673 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
15674 ROSE_ASSERT(symbol != NULL);
15675
15676 templateClassSymbolInTargetAST = isSgClassSymbol(symbol);
15677
15678 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
15679 }
15680
15681 // Not clear if we have to handle a more general case here.
15682 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
15683
15684 returnType = templateClassSymbolInTargetAST->get_type();
15685 }
15686#else
15687 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
15688 if (javaParameterizedType != NULL)
15689 {
15690#error "DEAD CODE!"
15691 // Not clear how to lookup this type in the target AST.
15692 returnType = javaParameterizedType;
15693
15694 SgType* internal_type = javaParameterizedType->get_raw_type();
15695 ROSE_ASSERT(internal_type != NULL);
15696 }
15697#endif
15698#if 0
15699 printf ("SgJavaParameterizedType not yet tested! \n");
15700 ROSE_ABORT();
15701#endif
15702 break;
15703 }
15704
15705 case V_SgJavaQualifiedType:
15706 {
15707 // DQ (3/10/2014): This type acts like a binary operator on types to define aggregate
15708 // types to represent what in C++ would be name qualification. I need only set the
15709 // declarations in each SgJavaQualifiedType to refer to a declaration in the target AST.
15710 // So reset the declaration.
15711
15712 // This case is demonstrated by test code:
15713 // SS_JAVA_CWES/src/Error_Handling/CWE_248/CWE_248_0.java,Error_Handling.CWE_248.CWE_248_0.cwe_248_0
15714 // printf ("***** SgJavaQualifiedType not yet tested! *** \n");
15715
15716 printf ("In getTargetFileTypeSupport(): case V_SgJavaQualifiedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15717
15718 SgJavaQualifiedType* javaQualifiedType = isSgJavaQualifiedType(namedType);
15719 if (javaQualifiedType != NULL)
15720 {
15721 // Not clear how to lookup this type in the target AST.
15722 returnType = javaQualifiedType;
15723
15724 SgType* internal_type_1 = javaQualifiedType->get_parent_type();
15725 ROSE_ASSERT(internal_type_1 != NULL);
15726 SgType* internal_type_2 = javaQualifiedType->get_type();
15727 ROSE_ASSERT(internal_type_2 != NULL);
15728 }
15729
15730 printf ("Case of SgJavaQualifiedType: not yet handled: commented out assertion! \n");
15731 // ROSE_ASSERT(false);
15732 break;
15733 }
15734
15735 case V_SgJavaWildcardType:
15736 {
15737 // DQ (3/10/2014): This type expressed constraints on an input type.
15738 // if (?) then it is associated with the Java object type.
15739 // It can be constraint with an upper bound or lower bound.
15740 // if (?extends List) would be an upper bound for List.
15741 // if (?super Integer) would be an lower bound for List.
15742 // So reset the declaration.
15743
15744 printf ("In getTargetFileTypeSupport(): case V_SgJavaWildcardType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15745
15746 SgJavaWildcardType* javaWildcardType = isSgJavaWildcardType(namedType);
15747 if (javaWildcardType != NULL)
15748 {
15749 // Not clear how to lookup this type in the target AST.
15750 returnType = javaWildcardType;
15751 }
15752
15753 printf ("SgJavaWildcardType not yet tested! \n");
15754 ROSE_ABORT();
15755 }
15756
15757 default:
15758 {
15759 printf ("Error: In getTargetFileTypeSupport(): default reached in switch: namedType = %p = %s \n",namedType,namedType->class_name().c_str());
15760 ROSE_ABORT();
15761 }
15762 }
15763
15764 ROSE_ASSERT(returnType != NULL);
15765#if 0
15766 printf ("Exiting as a test! \n");
15767 ROSE_ABORT();
15768#endif
15769 }
15770 else
15771 {
15772 // Non-named types are shared, so we need not reset them.
15773
15774 // If this was not a named type then return NULL (which is checked at the
15775 // calling point, so that the type will not be reset).
15776 }
15777
15778 return returnType;
15779 }
15780
15781
15782SgType*
15784 {
15785 SgType* returnType = NULL;
15786
15787 ROSE_ASSERT(snippet_type != NULL);
15788 ROSE_ASSERT(targetScope != NULL);
15789
15790 // DQ (3/17/2014): Refactored code.
15791 // See if the type might be asociated with the snippet file.
15792 SgType* type_copy = snippet_type;
15793
15794#if 0
15795 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
15796#endif
15797
15798 // We need to be able to reproduce the pointer types to class types, etc.
15799 Rose_STL_Container<SgType*> typeList = type_copy->getInternalTypes();
15800
15801#if 0
15802 for (size_t i = 0; i < typeList.size(); i++)
15803 {
15804 printf ("Input type: typeList[i=%" PRIuPTR "] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
15805 }
15806#endif
15807
15808#if 1
15809 // This is the unwrapped version of the getTargetFileType() function.
15810 returnType = getTargetFileTypeSupport(snippet_type,targetScope);
15811#else
15812 SgNamedType* namedType = isSgNamedType(snippet_type);
15813
15814#error "DEAD CODE!"
15815
15816 if (namedType != NULL)
15817 {
15818 // Find the associated declaration and it's corresponding declaration in the target AST.
15819 SgDeclarationStatement* snippet_declaration = namedType->get_declaration();
15820 ROSE_ASSERT(snippet_declaration != NULL);
15821#if 0
15822 printf ("Need to find the declaration in the target AST that is associated with the snippet_declaration in the snippet AST \n");
15823 printf (" --- snippet_declaration = %p = %s = %s \n",snippet_declaration,snippet_declaration->class_name().c_str(),SageInterface::get_name(snippet_declaration).c_str());
15824#endif
15825 // There are only a few cases here!
15826 switch (namedType->variantT())
15827 {
15828 case V_SgClassType:
15829 {
15830 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
15831 if (classDeclaration != NULL)
15832 {
15833 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classDeclaration->get_name(),targetScope);
15834 if (classSymbolInTargetAST == NULL)
15835 {
15836 // For Java or C++ this could be a name qualified type and so we need a better mechanism
15837 // to identify it thorugh it's parent scopes. Build a list of parent scope back to the
15838 // global scope and then traverse the list backwards to identify each scope in the target
15839 // AST's global scope until we each the associated declaration in the target AST.
15840#if 0
15841 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");
15842 printf (" --- Looking for target AST match for class name = %s \n",classDeclaration->get_name().str());
15843#endif
15844 SgSymbol* symbol = findAssociatedSymbolInTargetAST(classDeclaration,targetScope);
15845 ROSE_ASSERT(symbol != NULL);
15846
15847 classSymbolInTargetAST = isSgClassSymbol(symbol);
15848 }
15849
15850 ROSE_ASSERT(classSymbolInTargetAST != NULL);
15851 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(classSymbolInTargetAST->get_declaration());
15852 ROSE_ASSERT(target_classDeclaration != NULL);
15853#if 0
15854 printf ("snippet: classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
15855 printf ("target: classDeclaration = %p = %s \n",target_classDeclaration,target_classDeclaration->get_name().str());
15856#endif
15857 ROSE_ASSERT(classDeclaration->get_name() == target_classDeclaration->get_name());
15858
15859 returnType = classSymbolInTargetAST->get_type();
15860 }
15861 break;
15862 }
15863
15864 case V_SgTypedefType:
15865 {
15866 SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(snippet_declaration);
15867 if (typedefDeclaration != NULL)
15868 {
15869 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(typedefDeclaration->get_name(),targetScope);
15870
15871 // Not clear if we have to handle a more general case here.
15872 // ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15873 // returnType = typedefSymbolInTargetAST->get_type();
15874 if (typedefSymbolInTargetAST == NULL)
15875 {
15876#if 0
15877 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");
15878 printf (" --- The target AST must have a valid typedef type (and associated declaration) to support resetting the SgTypedefType: %p \n",typedefDeclaration->get_type());
15879#endif
15880 // DQ (3/16/2014): Find the associated typedef declaration (from the target AST)
15881 // for the input type associated with its declaration in the snippet AST.
15882 SgSymbol* symbol = findAssociatedSymbolInTargetAST(typedefDeclaration,targetScope);
15883 ROSE_ASSERT(symbol != NULL);
15884
15885 typedefSymbolInTargetAST = isSgTypedefSymbol(symbol);
15886
15887 // Note that test5d demonstrates this problem.
15888 // ROSE_ASSERT(false);
15889 }
15890
15891 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
15892 SgTypedefDeclaration* target_typedefDeclaration = isSgTypedefDeclaration(typedefSymbolInTargetAST->get_declaration());
15893 ROSE_ASSERT(target_typedefDeclaration != NULL);
15894#if 0
15895 printf ("snippet: typedefDeclaration = %p = %s \n",typedefDeclaration,typedefDeclaration->get_name().str());
15896 printf ("target: typedefDeclaration = %p = %s \n",target_typedefDeclaration,target_typedefDeclaration->get_name().str());
15897#endif
15898 ROSE_ASSERT(typedefDeclaration->get_name() == target_typedefDeclaration->get_name());
15899
15900 returnType = typedefSymbolInTargetAST->get_type();
15901 }
15902 break;
15903 }
15904
15905 case V_SgEnumType:
15906 {
15907 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(snippet_declaration);
15908 if (enumDeclaration != NULL)
15909 {
15910 ROSE_ASSERT(enumDeclaration->get_name().is_null() == false);
15911 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(enumDeclaration->get_name(),targetScope);
15912
15913 // Not clear if we have to handle a more general case here.
15914 // ROSE_ASSERT(enumSymbolInTargetAST != NULL);
15915 // returnType = enumSymbolInTargetAST->get_type();
15916 if (enumSymbolInTargetAST == NULL)
15917 {
15918 printf ("Error: It is an error to not have a enum type defined in the target AST! \n");
15919 printf (" --- The target AST must have a valid enum type (and associated declaration) to support resetting the SgEnumType: %p \n",enumDeclaration->get_type());
15920
15921 // We will allow this to pass for now, since it is a violation of the target AST, and not the snippet mechanism (I think).
15922 returnType = snippet_type;
15923
15924 // Note that test5d demonstrates this problem.
15925 // ROSE_ASSERT(false);
15926 }
15927 else
15928 {
15929 returnType = enumSymbolInTargetAST->get_type();
15930 }
15931 }
15932
15933 break;
15934 }
15935
15936 case V_SgJavaParameterizedType:
15937 {
15938 // DQ (3/10/2014): This type is a view of a generic class with dynamic type checking (e.g. T).
15939 // This acts more like a class with reference to the template instead of the template instantiation.
15940 // So reset the declaration.
15941
15942 printf ("In getTargetFileType(): case V_SgJavaParameterizedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15943#if 1
15944 SgClassDeclaration* classDeclaration = isSgClassDeclaration(snippet_declaration);
15945 if (classDeclaration != NULL)
15946 {
15947 SgTemplateParameterPtrList* templateParameterList = NULL;
15948 SgTemplateArgumentPtrList* templateSpecializationArgumentList = NULL;
15949 SgTemplateClassSymbol* templateClassSymbolInTargetAST = lookupTemplateClassSymbolInParentScopes(classDeclaration->get_name(),templateParameterList,templateSpecializationArgumentList,targetScope);
15950
15951 // Not clear if we have to handle a more general case here.
15952 ROSE_ASSERT(templateClassSymbolInTargetAST != NULL);
15953
15954 returnType = templateClassSymbolInTargetAST->get_type();
15955 }
15956#else
15957 SgJavaParameterizedType* javaParameterizedType = isSgJavaParameterizedType(namedType);
15958 if (javaParameterizedType != NULL)
15959 {
15960 // Not clear how to lookup this type in the target AST.
15961 returnType = javaParameterizedType;
15962
15963 SgType* internal_type = javaParameterizedType->get_raw_type();
15964 ROSE_ASSERT(internal_type != NULL);
15965 }
15966#endif
15967 printf ("SgJavaParameterizedType not yet tested! \n");
15968 ROSE_ABORT();
15969 }
15970
15971 case V_SgJavaQualifiedType:
15972 {
15973 // DQ (3/10/2014): This type acts like a binary operator on types to define aggregate
15974 // types to represent what in C++ would be name qualification. I need only set the
15975 // declarations in each SgJavaQualifiedType to refer to a declaration in the target AST.
15976 // So reset the declaration.
15977
15978 printf ("In getTargetFileType(): case V_SgJavaQualifiedType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
15979
15980 SgJavaQualifiedType* javaQualifiedType = isSgJavaQualifiedType(namedType);
15981 if (javaQualifiedType != NULL)
15982 {
15983 // Not clear how to lookup this type in the target AST.
15984 returnType = javaQualifiedType;
15985
15986 SgType* internal_type_1 = javaQualifiedType->get_parent_type();
15987 ROSE_ASSERT(internal_type_1 != NULL);
15988 SgType* internal_type_2 = javaQualifiedType->get_type();
15989 ROSE_ASSERT(internal_type_2 != NULL);
15990 }
15991
15992 printf ("SgJavaQualifiedType not yet tested! \n");
15993 ROSE_ABORT();
15994 }
15995
15996 case V_SgJavaWildcardType:
15997 {
15998 // DQ (3/10/2014): This type expressed constraints on an input type.
15999 // if (?) then it is associated with the Java object type.
16000 // It can be constraint with an upper bound or lower bound.
16001 // if (?extends List) would be an upper bound for List.
16002 // if (?super Integer) would be an lower bound for List.
16003 // So reset the declaration.
16004
16005 printf ("In getTargetFileType(): case V_SgJavaWildcardType: snippet_declaration = %p = %s \n",snippet_declaration,snippet_declaration->class_name().c_str());
16006
16007 SgJavaWildcardType* javaWildcardType = isSgJavaWildcardType(namedType);
16008 if (javaWildcardType != NULL)
16009 {
16010 // Not clear how to lookup this type in the target AST.
16011 returnType = javaWildcardType;
16012
16013 SgType* internal_type_1 = javaWildcardType->get_bound_type();
16014 // ROSE_ASSERT(internal_type_1 != NULL); // PC: 03/15/2014 - Dan, this cannot be asserted as the bound_type CAN BE NULL.
16015 }
16016
16017 printf ("SgJavaWildcardType not yet tested! \n");
16018 ROSE_ABORT();
16019 }
16020
16021 default:
16022 {
16023 printf ("Error: In getTargetFileType(): default reached in switch: namedType = %p = %s \n",namedType,namedType->class_name().c_str());
16024 ROSE_ABORT();
16025 }
16026 }
16027
16028 ROSE_ASSERT(returnType != NULL);
16029#if 0
16030 printf ("Exiting as a test! \n");
16031 ROSE_ABORT();
16032#endif
16033 }
16034 else
16035 {
16036 // Non-named types are shared, so we need not reset them.
16037
16038 // If this was not a named type then return NULL (which is checked at the
16039 // calling point, so that the type will not be reset).
16040 }
16041#endif
16042
16043 SgType* new_type = returnType;
16044
16045 // DQ (3/17/2014): Refactored code.
16046 // Now rebuild the type_copy as required to represent associated modifiers, typedef wrappers, pointers and references.
16047 if (new_type != NULL && typeList.size() > 1)
16048 {
16049 int size = (int)typeList.size();
16050 for (int i = size - 2; i >= 0; i--)
16051 {
16052#if 0
16053 printf ("Rebuild type: typeList[i=%d] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
16054#endif
16055 // SgModifierType* SgModifierType::createType(SgType* base_type, unsigned int f, SgExpression* optional_fortran_type_kind )
16056 switch(typeList[i]->variantT())
16057 {
16058 case V_SgModifierType:
16059 {
16060 SgModifierType* modifierType = isSgModifierType(typeList[i]);
16061 ROSE_ASSERT(modifierType != NULL);
16062 if (modifierType->get_typeModifier().get_constVolatileModifier().isConst() == true)
16063 {
16064 ROSE_ASSERT(new_type != NULL);
16065#if 0
16066 printf ("Building a SgModifierType: calling buildConstType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16067#endif
16068 new_type = buildConstType(new_type);
16069 }
16070 else
16071 {
16072 // Flag any additional modifiers that we might require (make anything not supported an error).
16073 printf ("Modifier kind not handled (not implemented) check what sort of modifier this is: \n");
16074 modifierType->get_typeModifier().display("Modifier kind not handled");
16075 ROSE_ABORT();
16076 }
16077 break;
16078 }
16079
16080 case V_SgTypedefType:
16081 {
16082 SgTypedefType* typedefType = isSgTypedefType(typeList[i]);
16083 ROSE_ASSERT(typedefType != NULL);
16084
16085 // DQ (3/17/2014): Call the associated support function instead.
16086 // SgType* SageBuilder::getTargetFileType(SgType* snippet_type, SgScopeStatement* targetScope)
16087 // SgType* new_typedefType = getTargetFileType(typedefType,targetScope);
16088 SgType* new_typedefType = getTargetFileTypeSupport(typedefType,targetScope);
16089 ROSE_ASSERT(new_typedefType != NULL);
16090 ROSE_ASSERT(isSgTypedefType(new_typedefType) != NULL);
16091
16092 new_type = new_typedefType;
16093#if 0
16094 printf ("ERROSE: SgTypedefType kind not handled (not implemented) \n");
16095 ROSE_ABORT();
16096#endif
16097 break;
16098 }
16099
16100 case V_SgPointerType:
16101 {
16102 SgPointerType* pointerType = isSgPointerType(typeList[i]);
16103 ROSE_ASSERT(pointerType != NULL);
16104#if 0
16105 printf ("Building a SgPointerType: calling buildPointerType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16106#endif
16107 ROSE_ASSERT(new_type != NULL);
16108 new_type = buildPointerType(new_type);
16109#if 0
16110 printf ("ERROSE: SgPointerType kind not handled (not implemented) \n");
16111 ROSE_ABORT();
16112#endif
16113 break;
16114 }
16115
16116 default:
16117 {
16118 printf ("Error: default reached in evaluation of typelist: typeList[i] = %p = %s \n",typeList[i],typeList[i]->class_name().c_str());
16119 ROSE_ABORT();
16120 }
16121 }
16122 }
16123
16124 returnType = new_type;
16125 }
16126
16127#if 0
16128 if (typeList.size() > 1)
16129 {
16130 printf ("Exiting as a test! \n");
16131 ROSE_ABORT();
16132 }
16133#endif
16134
16135
16136 return returnType;
16137 }
16138
16139
16140
16141void
16142SageBuilder::errorCheckingTargetAST (SgNode* node_copy, SgNode* node_original, SgFile* targetFile, bool failOnWarning )
16143 {
16144#if 0
16145 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());
16146#endif
16147
16148 // Handle what is the same about all statements before getting to the switch.
16149 SgStatement* statement_copy = isSgStatement(node_copy);
16150 SgStatement* statement_original = isSgStatement(node_original);
16151 if (statement_copy != NULL)
16152 {
16153 // Check the scope if it is stored explicitly.
16154 if (statement_copy->hasExplicitScope() == true)
16155 {
16156 // Handle the scope for all statements.
16157 SgScopeStatement* scope_copy = statement_copy->get_scope();
16158 ROSE_ASSERT(statement_original != NULL);
16159 SgScopeStatement* scope_original = statement_original->get_scope();
16160 ROSE_ASSERT(scope_copy != NULL);
16161 ROSE_ASSERT(scope_original != NULL);
16162
16163 // if (TransformationSupport::getFile(scope_original) != targetFile)
16164 // if (getEnclosingFileNode(scope_original) != targetFile)
16165 if (getEnclosingFileNode(scope_copy) != targetFile)
16166 {
16167#if 0
16168 printf ("Warning: SgStatement: scope = %p = %s \n",scope_original,scope_original->class_name().c_str());
16169#endif
16170 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
16171 // SgFile* snippetFile = getEnclosingFileNode(scope_original);
16172 SgFile* snippetFile = getEnclosingFileNode(scope_copy);
16173 ROSE_ASSERT(snippetFile != NULL);
16174 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16175#if 1
16176 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16177 // ROSE_ASSERT(false);
16178#endif
16179 if (failOnWarning == true)
16180 {
16181 printf ("Exit on warning! \n");
16182 ROSE_ABORT();
16183 }
16184 }
16185#if 0
16186 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
16187 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
16188
16189 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
16190 // ROSE_ASSERT(targetScope != NULL);
16191
16192 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16193 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16194 // SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol->get_name(),targetScope);
16195 // ROSE_ASSERT(variableSymbolInTargetAST != NULL);
16196
16197 // Unless we know that this is a declaration we can't set the scope here using the information about this being a definng declaration.
16198 // If this is a defining declaration then we want to set it's scope to targetScope, else we want to lookup
16199 // the symbol through the parent scope and set the scope using the symbol's first non-defining declaration.
16200 // statement_copy->set_scope(targetScope);
16201
16202 // SgSymbol* symbol = statement_copy->search_for_symbol_from_symbol_table();
16203 // ROSE_ASSERT(symbol != NULL);
16204#endif
16205#if 0
16206 printf ("SgClassDeclaration: Exiting as a test! \n");
16207 ROSE_ABORT();
16208#endif
16209#if 0
16210 if (TransformationSupport::getFile(scope) != targetFile)
16211 {
16212 printf ("Warning: SgStatement: scope = %p = %s \n",scope,scope->class_name().c_str());
16213 SgFile* snippetFile = TransformationSupport::getFile(scope);
16214 ROSE_ASSERT(snippetFile != NULL);
16215 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16216
16217 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16218 // ROSE_ASSERT(false);
16219 }
16220#endif
16221 }
16222 }
16223
16224 // Handle what is the same about all declaration before getting to the switch.
16225 SgDeclarationStatement* declarationStatement_copy = isSgDeclarationStatement(node_copy);
16226 SgDeclarationStatement* declarationStatement_original = isSgDeclarationStatement(node_original);
16227 if (declarationStatement_copy != NULL)
16228 {
16229 // Check the firstnondefiningDeclaration and definingDeclaration
16230 SgDeclarationStatement* firstNondefiningDeclaration_copy = declarationStatement_copy->get_firstNondefiningDeclaration();
16231 SgDeclarationStatement* firstNondefiningDeclaration_original = declarationStatement_original->get_firstNondefiningDeclaration();
16232
16233 // DQ (3/17/2014): Bugfix, we want to use the firstNondefiningDeclaration_copy instead of firstNondefiningDeclaration_original.
16234 // DQ (3/10/2014): We want to allow for NULL return values from getEnclosingFileNode() for Java classes that are in java.lang (for example).
16235 // SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_original);
16236 SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_copy);
16237 if (snippetFile != NULL && snippetFile != targetFile)
16238 {
16239 // I think we want to allow this because it is a common occurence in any merged AST.
16240 // However, if might be worth fixing for other reasons. This needs to be discussed.
16241#if 0
16242 printf ("Note: SgDeclarationStatement: firstNondefiningDeclaration_original is not in target file (allowed for merged ASTs) \n");
16243#endif
16244 // ROSE_ASSERT(false);
16245 if (failOnWarning == true)
16246 {
16247 printf ("Exit on warning! \n");
16248 ROSE_ABORT();
16249 }
16250 }
16251 else
16252 {
16253 // Warn about this if snippetFile == NULL.
16254 if (snippetFile == NULL)
16255 {
16256 printf ("Note: firstNondefiningDeclaration_original = %p getEnclosingFileNode() returned NULL \n",firstNondefiningDeclaration_original);
16257
16258 if (failOnWarning == true)
16259 {
16260 printf ("Exit on warning! \n");
16261 ROSE_ABORT();
16262 }
16263 }
16264 }
16265
16266 SgDeclarationStatement* definingDeclaration_copy = declarationStatement_copy->get_definingDeclaration();
16267 SgDeclarationStatement* definingDeclaration_original = declarationStatement_original->get_definingDeclaration();
16268 if (definingDeclaration_original != NULL)
16269 {
16270 // DQ (3/17/2014): Bugfix, we want to use the definingDeclaration_copy instead of definingDeclaration_original.
16271 // if (TransformationSupport::getFile(definingDeclaration_original) != targetFile)
16272 // if (getEnclosingFileNode(definingDeclaration_original) != targetFile)
16273 // SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_original);
16274 SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_copy);
16275 if (snippetFile != NULL && snippetFile != targetFile)
16276 {
16277#if 1
16278 printf ("Warning: SgDeclarationStatement: definingDeclaration is not in target file \n");
16279 // ROSE_ASSERT(false);
16280#endif
16281 if (failOnWarning == true)
16282 {
16283 printf ("Exit on warning! \n");
16284 ROSE_ABORT();
16285 }
16286
16287 if (declarationStatement_original == definingDeclaration_original)
16288 {
16289 // This is a defining declaration, so we can set the scope (or can we?)
16290 // I guess we could if the translation map were complete, but it is not complete yet.
16291 }
16292 }
16293 else
16294 {
16295 // Warn about this if snippetFile == NULL.
16296 if (snippetFile == NULL)
16297 {
16298 printf ("Note: definingDeclaration_original = %p getEnclosingFileNode() returned NULL \n",definingDeclaration_original);
16299
16300 if (failOnWarning == true)
16301 {
16302 printf ("Exit on warning! \n");
16303 ROSE_ABORT();
16304 }
16305 }
16306 }
16307 }
16308 }
16309
16310 // Handle what is the same about all expressions before getting to the switch.
16311 SgExpression* expression = isSgExpression(node_copy);
16312 if (expression != NULL)
16313 {
16314 // Check the scope if it is stored explicitly.
16315
16316 // printf ("WARNING: Need to check if the type is explicitly stored in this expression! \n");
16317
16318 if (expression->hasExplicitType() == true)
16319 {
16320 // Handle the type for all expressions.
16321 SgType* type = expression->get_type();
16322 ROSE_ASSERT(type != NULL);
16323 }
16324 }
16325
16326#if 0
16327 printf ("Leaving errorCheckingTargetAST() \n");
16328#endif
16329 }
16330
16331
16332template <class T>
16333void
16334SageBuilder::resetDeclaration(T* classDeclaration_copy, T* classDeclaration_original, SgScopeStatement* targetScope)
16335 {
16336 // I'm not sure if this function is a good idea since we can't call set_scope() easily from any
16337 // SgDeclarationStatement and I don't want to make set_scope() a virtual function because it would
16338 // not make sense everywhere.
16339
16340 // DQ (3/17/2014): This code is similar to the case for SgEnumDeclaration (later we can refactor this if this works well).
16341 T* classDeclaration_copy_defining = dynamic_cast<T*>(classDeclaration_copy->get_definingDeclaration());
16342 T* classDeclaration_copy_nondefining = dynamic_cast<T*>(classDeclaration_copy->get_firstNondefiningDeclaration());
16343 T* classDeclaration_original_defining = dynamic_cast<T*>(classDeclaration_original->get_definingDeclaration());
16344 T* classDeclaration_original_nondefining = dynamic_cast<T*>(classDeclaration_original->get_firstNondefiningDeclaration());
16345
16346 // Set the scope if it is still set to the scope of the snippet AST.
16347 if (classDeclaration_copy_defining != NULL && classDeclaration_copy_defining->get_scope() == classDeclaration_original_defining->get_scope())
16348 {
16349#if 0
16350 printf ("reset the scope of classDeclaration_copy_defining \n");
16351#endif
16352 classDeclaration_copy_defining->set_scope(targetScope);
16353 }
16354
16355 // Set the scope if it is still set to the scope of the snippet AST.
16356 if (classDeclaration_copy_nondefining != NULL && classDeclaration_copy_nondefining->get_scope() == classDeclaration_original_nondefining->get_scope())
16357 {
16358#if 0
16359 printf ("reset the scope of classDeclaration_copy_nondefining \n");
16360#endif
16361 classDeclaration_copy_nondefining->set_scope(targetScope);
16362 }
16363
16364 // Set the parent if it is still set to a node of the snippet AST.
16365 if (classDeclaration_copy_nondefining != NULL && classDeclaration_copy_nondefining->get_parent() == classDeclaration_original_nondefining->get_parent())
16366 {
16367#if 0
16368 printf ("reset the parent of classDeclaration_copy_nondefining \n");
16369#endif
16370 classDeclaration_copy_nondefining->set_parent(classDeclaration_copy->get_parent());
16371 }
16372 }
16373
16374
16375void
16377 SgNode* node_copy, SgNode* node_original)
16378 {
16379 // This function fixes up invidual IR nodes to be consistant in the context of the target AST
16380 // where the node is inserted and at the point specified by insertionPoint. In this function,
16381 // node_copy is the copy that was made of node_original by the AST copy function. The node_original
16382 // is assumed to be the node that is in the AST snippet (it is still connected in the snippet's
16383 // AST (from compilation of the snippet file).
16384
16385 // This function hides the details of handling each different type of IR node.
16386 // It is assume that the node_copy is from an AST sub-tree generated by the AST copy mechanism,
16387 // and that the insertionPoint is a location in the target AST where the snippet AST has already
16388 // been inserted, this function makes each IR node internally consistant with the target AST.
16389
16390 // BTW, the translationMap should only be required to support references to things that are name
16391 // qualified (which are C++ specific). These are a performance option to simplify tacking back
16392 // through scopes with code similarly complex as to what is supported in the name qualification
16393 // support.
16394#if 0
16395 printf ("In fixupCopyOfNodeFromSeperateFileInNewTargetAst: node_copy = %p = %s \n",node_copy,node_copy->class_name().c_str());
16396#endif
16397
16398#if 0
16399 printf ("Disabled fixupCopyOfNodeFromSeperateFileInNewTargetAst() \n");
16400 return;
16401#endif
16402
16403 // SgFile* targetFile = TransformationSupport::getFile(insertionPoint);
16404 SgFile* targetFile = getEnclosingFileNode(insertionPoint);
16405
16406#if 0
16407 printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
16408 printf (" --- insertionPointIsScope = %s \n",insertionPointIsScope ? "true" : "false");
16409#endif
16410
16411 // DQ (3/4/2014): As I recall there is a reason why we can't setup the scope here.
16412
16413 // We also need to handle the symbol (move it from the body (SgBaicBlock) that was
16414 // a copy to the scope in the target AST where the SgInitializedName was inserted).
16415 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
16416#if 0
16417 printf ("insertionPointScope = %p = %s \n",insertionPointScope,insertionPointScope->class_name().c_str());
16418#endif
16419 SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
16420 ROSE_ASSERT(targetScope != NULL);
16421
16422#if 1
16423 // Refactored code (error checking done after AST fixup).
16424#if 0
16425 errorCheckingTargetAST(node_copy,node_original,targetFile, false);
16426#endif
16427#else
16428
16429#error "DEAD CODE!"
16430
16431 // Handle what is the same about all statements before getting to the switch.
16432 SgStatement* statement_copy = isSgStatement(node_copy);
16433 SgStatement* statement_original = isSgStatement(node_original);
16434 if (statement_copy != NULL)
16435 {
16436 // Check the scope if it is stored explicitly.
16437 if (statement_copy->hasExplicitScope() == true)
16438 {
16439 // Handle the scope for all statements.
16440 SgScopeStatement* scope_copy = statement_copy->get_scope();
16441 SgScopeStatement* scope_original = statement_original->get_scope();
16442 ROSE_ASSERT(scope_copy != NULL);
16443 ROSE_ASSERT(scope_original != NULL);
16444
16445 // if (TransformationSupport::getFile(scope_original) != targetFile)
16446 if (getEnclosingFileNode(scope_original) != targetFile)
16447 {
16448#if 0
16449 printf ("Warning: SgStatement: scope = %p = %s \n",scope_original,scope_original->class_name().c_str());
16450#endif
16451 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
16452 SgFile* snippetFile = getEnclosingFileNode(scope_original);
16453 ROSE_ASSERT(snippetFile != NULL);
16454 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16455#if 0
16456 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16457 // ROSE_ASSERT(false);
16458#endif
16459 }
16460#if 0
16461 SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
16462 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
16463
16464 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
16465 // ROSE_ASSERT(targetScope != NULL);
16466
16467 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16468 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16469 // SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol->get_name(),targetScope);
16470 // ROSE_ASSERT(variableSymbolInTargetAST != NULL);
16471
16472 // Unless we know that this is a declaration we can't set the scope here using the information about this being a definng declaration.
16473 // If this is a defining declaration then we want to set it's scope to targetScope, else we want to lookup
16474 // the symbol through the parent scope and set the scope using the symbol's first non-defining declaration.
16475 // statement_copy->set_scope(targetScope);
16476
16477 // SgSymbol* symbol = statement_copy->search_for_symbol_from_symbol_table();
16478 // ROSE_ASSERT(symbol != NULL);
16479#endif
16480#if 0
16481 printf ("SgClassDeclaration: Exiting as a test! \n");
16482 ROSE_ABORT();
16483#endif
16484#if 0
16485 if (TransformationSupport::getFile(scope) != targetFile)
16486 {
16487 printf ("Warning: SgStatement: scope = %p = %s \n",scope,scope->class_name().c_str());
16488 SgFile* snippetFile = TransformationSupport::getFile(scope);
16489 ROSE_ASSERT(snippetFile != NULL);
16490 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16491
16492 printf ("Warning: SgStatement: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16493 // ROSE_ASSERT(false);
16494 }
16495#endif
16496 }
16497 }
16498
16499#error "DEAD CODE!"
16500
16501 // Handle what is the same about all declaration before getting to the switch.
16502 SgDeclarationStatement* declarationStatement_copy = isSgDeclarationStatement(node_copy);
16503 SgDeclarationStatement* declarationStatement_original = isSgDeclarationStatement(node_original);
16504 if (declarationStatement_copy != NULL)
16505 {
16506 // Check the firstnondefiningDeclaration and definingDeclaration
16507 SgDeclarationStatement* firstNondefiningDeclaration_original = declarationStatement_original->get_firstNondefiningDeclaration();
16508
16509 // DQ (3/10/2014): We want to allow for NULL return values from getEnclosingFileNode() for Java classes that are in java.lang (for example).
16510 SgFile* snippetFile = getEnclosingFileNode(firstNondefiningDeclaration_original);
16511 if (snippetFile != NULL && snippetFile != targetFile)
16512 {
16513 // I think we want to allow this because it is a common occurence in any merged AST.
16514 // However, if might be worth fixing for other reasons. This needs to be discussed.
16515#if 0
16516 printf ("Note: SgDeclarationStatement: firstNondefiningDeclaration_original is not in target file (allowed for merged ASTs) \n");
16517#endif
16518 // ROSE_ASSERT(false);
16519 }
16520 else
16521 {
16522 // Warn about this if snippetFile == NULL.
16523 if (snippetFile == NULL)
16524 {
16525 printf ("Note: firstNondefiningDeclaration_original = %p getEnclosingFileNode() returned NULL \n",firstNondefiningDeclaration_original);
16526 }
16527 }
16528
16529#error "DEAD CODE!"
16530
16531 SgDeclarationStatement* definingDeclaration_original = declarationStatement_original->get_definingDeclaration();
16532 if (definingDeclaration_original != NULL)
16533 {
16534 // if (TransformationSupport::getFile(definingDeclaration_original) != targetFile)
16535 // if (getEnclosingFileNode(definingDeclaration_original) != targetFile)
16536 SgFile* snippetFile = getEnclosingFileNode(definingDeclaration_original);
16537 if (snippetFile != NULL && snippetFile != targetFile)
16538 {
16539#if 0
16540 printf ("Warning: SgDeclarationStatement: definingDeclaration is not in target file \n");
16541 // ROSE_ASSERT(false);
16542#endif
16543 if (declarationStatement_original == definingDeclaration_original)
16544 {
16545 // This is a defining declaration, so we can set the scope (or can we?)
16546 // I guess we could if the translation map were complete, but it is not complete yet.
16547 }
16548 }
16549 else
16550 {
16551 // Warn about this if snippetFile == NULL.
16552 if (snippetFile == NULL)
16553 {
16554 printf ("Note: definingDeclaration_original = %p getEnclosingFileNode() returned NULL \n",definingDeclaration_original);
16555 }
16556 }
16557 }
16558 }
16559
16560#error "DEAD CODE!"
16561
16562#endif
16563
16564 // Handle what is the same about all expressions before getting to the switch.
16565 SgExpression* expression = isSgExpression(node_copy);
16566 if (expression != NULL)
16567 {
16568 // Check the scope if it is stored explicitly.
16569
16570 // printf ("WARNING: Need to check if the type is explicitly stored in this expression! \n");
16571
16572 if (expression->hasExplicitType() == true)
16573 {
16574 // Handle the type for all expressions.
16575 SgType* type = expression->get_type();
16576 ROSE_ASSERT(type != NULL);
16577
16578 // DQ (3/17/2014): Avoid calling stripType with the newly refactored getTargetFileType() function.
16579 // SgType* new_type = getTargetFileType(type->stripType(),targetScope);
16580 SgType* new_type = getTargetFileType(type,targetScope);
16581 if (new_type != NULL)
16582 {
16583 // Reset the base type to be the one associated with the target file.
16584 expression->set_explicitly_stored_type(new_type);
16585 }
16586 }
16587 }
16588
16589 switch (node_copy->variantT())
16590 {
16591 case V_SgInitializedName:
16592 {
16593 SgInitializedName* initializedName_copy = isSgInitializedName(node_copy);
16594 SgInitializedName* initializedName_original = isSgInitializedName(node_original);
16595
16596 // See if the scope might be associated with the snippet file.
16597
16598 // Since we don't want the scope that is stored in the SgInitializedName we
16599 // have to get the associated statement and the scope of that statement.
16600 // SgScopeStatement* scope_copy = initializedName_copy->get_scope();
16601 SgStatement* enclosingStatement_copy = TransformationSupport::getStatement(initializedName_copy);
16602#if 0
16603 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
16604#endif
16605 SgScopeStatement* scope_copy = enclosingStatement_copy->get_scope();
16606
16607 SgScopeStatement* scope_original = initializedName_original->get_scope();
16608
16609 ROSE_ASSERT(scope_copy != NULL);
16610 ROSE_ASSERT(scope_original != NULL);
16611
16612 // if (TransformationSupport::getFile(scope_original) != targetFile)
16613 if (getEnclosingFileNode(scope_original) != targetFile)
16614 {
16615#if 0
16616 ROSE_ASSERT(initializedName_copy != NULL);
16617 printf ("initializedName_copy = %p = %s \n",initializedName_copy,initializedName_copy->get_name().str());
16618 ROSE_ASSERT(initializedName_original != NULL);
16619 printf ("initializedName_original = %p = %s \n",initializedName_original,initializedName_original->get_name().str());
16620 SgType* initializedName_original_type = initializedName_original->get_type();
16621 printf ("initializedName_original_type = %p = %s \n",initializedName_original_type,initializedName_original_type->class_name().c_str());
16622 SgClassType* classType = isSgClassType(initializedName_original_type);
16623 // ROSE_ASSERT(classType != NULL);
16624 if (classType != NULL)
16625 {
16626 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
16627 ROSE_ASSERT(classDeclaration != NULL);
16628 printf ("classDeclaration = %p = %s \n",classDeclaration,classDeclaration->get_name().str());
16629 }
16630#endif
16631#if 0
16632 printf ("Warning: case V_SgInitializedName: scope_copy = %p = %s \n",scope_copy,scope_copy->class_name().c_str());
16633 printf ("Warning: case V_SgInitializedName: scope_original = %p = %s \n",scope_original,scope_original->class_name().c_str());
16634
16635 printf ("Warning: case V_SgInitializedName: initializedName_copy->get_parent() = %p \n",initializedName_copy->get_parent());
16636 printf ("Warning: case V_SgInitializedName: initializedName_original->get_parent() = %p \n",initializedName_original->get_parent());
16637#endif
16638 // SgFile* snippetFile = TransformationSupport::getFile(scope_original);
16639 SgFile* snippetFile = getEnclosingFileNode(scope_original);
16640
16641 ROSE_ASSERT(snippetFile != NULL);
16642 ROSE_ASSERT(snippetFile->get_sourceFileNameWithPath().empty() == false);
16643#if 0
16644 printf ("Warning: case V_SgInitializedName: scope not in target file (snippetFile = %p = %s) \n",snippetFile,snippetFile->get_sourceFileNameWithPath().c_str());
16645 // ROSE_ASSERT(false);
16646#endif
16647 }
16648
16649 // See if the type might be asociated with the snippet file.
16650 SgType* type_copy = initializedName_copy->get_type();
16651#if 0
16652 printf ("(before type_copy->getInternalTypes()): type_copy = %p = %s \n",type_copy,type_copy->class_name().c_str());
16653#endif
16654
16655#if 0
16656
16657#error "DEAD CODE!"
16658
16659 // We need to be able to reproduce the pointer types to class types, etc.
16660 Rose_STL_Container<SgType*> typeList = type_copy->getInternalTypes();
16661#if 0
16662 for (size_t i = 0; i < typeList.size(); i++)
16663 {
16664 printf ("Input type: typeList[i=%" PRIuPTR "] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
16665 }
16666#endif
16667 // Note that the semantics of this function is that it can return a NULL pointer (e.g. for primative types).
16668 SgType* new_type = getTargetFileType(type_copy->stripType(),targetScope);
16669
16670#error "DEAD CODE!"
16671
16672 // Now rebuild the type_copy as required to represent associated modifiers, typedef wrappers, pointers and references.
16673 if (new_type != NULL && typeList.size() > 1)
16674 {
16675 int size = (int)typeList.size();
16676 for (int i = size - 2; i >= 0; i--)
16677 {
16678#if 0
16679 printf ("Rebuild type: typeList[i=%d] = %p = %s \n",i,typeList[i],typeList[i]->class_name().c_str());
16680#endif
16681 // SgModifierType* SgModifierType::createType(SgType* base_type, unsigned int f, SgExpression* optional_fortran_type_kind )
16682 switch(typeList[i]->variantT())
16683 {
16684 case V_SgModifierType:
16685 {
16686 SgModifierType* modifierType = isSgModifierType(typeList[i]);
16687 ROSE_ASSERT(modifierType != NULL);
16688 if (modifierType->get_typeModifier().get_constVolatileModifier().isConst() == true)
16689 {
16690 ROSE_ASSERT(new_type != NULL);
16691#if 0
16692 printf ("Building a SgModifierType: calling buildConstType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16693#endif
16694 new_type = buildConstType(new_type);
16695 }
16696 else
16697 {
16698 // Flag any additional modifiers that we might require (make anything not supported an error).
16699 printf ("Modifier kind not handled (not implemented) check what sort of modifier this is: \n");
16700 modifierType->get_typeModifier().display("Modifier kind not handled");
16701 ROSE_ABORT();
16702 }
16703 break;
16704 }
16705
16706#error "DEAD CODE!"
16707
16708 case V_SgTypedefType:
16709 {
16710 SgTypedefType* typedefType = isSgTypedefType(typeList[i]);
16711 ROSE_ASSERT(typedefType != NULL);
16712
16713 // SgType* SageBuilder::getTargetFileType(SgType* snippet_type, SgScopeStatement* targetScope)
16714 SgType* new_typedefType = getTargetFileType(typedefType,targetScope);
16715 ROSE_ASSERT(new_typedefType != NULL);
16716 ROSE_ASSERT(isSgTypedefType(new_typedefType) != NULL);
16717
16718 new_type = new_typedefType;
16719#if 0
16720 printf ("ERROSE: SgTypedefType kind not handled (not implemented) \n");
16721 ROSE_ABORT();
16722#endif
16723 break;
16724 }
16725
16726#error "DEAD CODE!"
16727
16728 case V_SgPointerType:
16729 {
16730 SgPointerType* pointerType = isSgPointerType(typeList[i]);
16731 ROSE_ASSERT(pointerType != NULL);
16732#if 0
16733 printf ("Building a SgPointerType: calling buildPointerType(): new_type = %p = %s \n",new_type,new_type->class_name().c_str());
16734#endif
16735 ROSE_ASSERT(new_type != NULL);
16736 new_type = buildPointerType(new_type);
16737#if 0
16738 printf ("ERROSE: SgPointerType kind not handled (not implemented) \n");
16739 ROSE_ABORT();
16740#endif
16741 break;
16742 }
16743
16744#error "DEAD CODE!"
16745
16746 default:
16747 {
16748 printf ("Error: default reached in evaluation of typelist: typeList[i] = %p = %s \n",typeList[i],typeList[i]->class_name().c_str());
16749 ROSE_ABORT();
16750 }
16751 }
16752 }
16753 }
16754#if 0
16755 if (typeList.size() > 1)
16756 {
16757 printf ("Exiting as a test! \n");
16758 ROSE_ABORT();
16759 }
16760#endif
16761
16762#error "DEAD CODE!"
16763
16764#else
16765 // Refactored the above code to be a part of getTargetFileType() function.
16766 // Note that the semantics of this function is that it can return a NULL pointer (e.g. for primative types).
16767 // SgType* new_type = getTargetFileType(type_copy->stripType(),targetScope);
16768 SgType* new_type = getTargetFileType(type_copy,targetScope);
16769#endif
16770#if 0
16771 printf ("new_type = %p \n",new_type);
16772#endif
16773 if (new_type != NULL)
16774 {
16775 // Reset the base type to be the one associated with the target file.
16776#if 0
16777 printf ("Reset type for initializedName_copy = %p from type = %p to type = %p \n",initializedName_copy,initializedName_copy->get_type(),new_type);
16778#endif
16779 SgType* original_type = initializedName_copy->get_type();
16780 SgNamedType* original_named_type = isSgNamedType(original_type);
16781 SgNamedType* new_named_type = isSgNamedType(new_type);
16782 if (original_named_type != NULL)
16783 {
16784 ROSE_ASSERT(new_named_type != NULL);
16785 SgClassDeclaration* original_classDeclaration = isSgClassDeclaration(original_named_type->get_declaration());
16786 SgClassDeclaration* new_classDeclaration = isSgClassDeclaration(new_named_type->get_declaration());
16787 if (original_classDeclaration != NULL)
16788 {
16789 ROSE_ASSERT(new_classDeclaration != NULL);
16790#if 0
16791 printf ("original_classDeclaration = %p = %s \n",original_classDeclaration,original_classDeclaration->get_name().str());
16792 printf ("new_classDeclaration = %p = %s \n",new_classDeclaration,new_classDeclaration->get_name().str());
16793#endif
16794 // Make sure that the type names are the same.
16795 ROSE_ASSERT(new_classDeclaration->get_name() == original_classDeclaration->get_name());
16796 }
16797 }
16798#if 0
16799 SgType* old_type = initializedName_copy->get_type();
16800 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());
16801#endif
16802 initializedName_copy->set_type(new_type);
16803 }
16804#if 0
16805 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
16806#endif
16807 SgFunctionParameterList* functionParameterList = isSgFunctionParameterList(enclosingStatement_copy);
16808 if (functionParameterList != NULL)
16809 {
16810 // The use of SgInitializedName in function parametes is handled differently then in other
16811 // locations in the AST (e.g. how the scope is set).
16812 // This is a function parameter and the scope is set to the SgFunctionDefinition if
16813 // this is for a defining function and the SgGlobal if it is a function prototype.
16814 SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(functionParameterList->get_parent());
16815 ROSE_ASSERT(functionDeclaration != NULL);
16816 SgFunctionDefinition* functionDefinition = functionDeclaration->get_definition();
16817 if (functionDefinition != NULL)
16818 {
16819 ROSE_ASSERT(initializedName_copy->get_scope() == functionDefinition);
16820 // initializedName_copy->set_scope(functionDefinition);
16821 }
16822 else
16823 {
16824 SgGlobal* globalScope = isSgGlobal(functionDeclaration->get_scope());
16825 ROSE_ASSERT(globalScope != NULL);
16826 if (initializedName_copy->get_scope() != globalScope)
16827 {
16828#if 0
16829 printf ("Reset scope for initializedName_copy = %p = %s \n",initializedName_copy,initializedName_copy->get_name().str());
16830#endif
16831 initializedName_copy->set_scope(globalScope);
16832 }
16833 ROSE_ASSERT(initializedName_copy->get_scope() == globalScope);
16834 }
16835 }
16836 else
16837 {
16838#if 0
16839 printf ("initializedName_copy->get_scope() = %p = %s \n",initializedName_copy->get_scope(),initializedName_copy->get_scope()->class_name().c_str());
16840#endif
16841 SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(enclosingStatement_copy);
16842 if (enumDeclaration != NULL)
16843 {
16844 // The case of enum declarations is special because the associated SgInitializedName IR nodes has a scope
16845 // that is external to the SgEnumDeclaration (in the scope of the SgEnumDeclaration). The typical case in C
16846 // is that the enum declaration is in global scope and then the enum fields (represented by SgInitializedName
16847 // objects) are have their associated symbol in the global scope.
16848
16849 // We have to use the name to search for the symbol instead of the pointer value of the initializedName_copy
16850 // (since the original symbol was associated with initializedName_original).
16851 // SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16852 SgName name = initializedName_copy->get_name();
16853 SgSymbol* symbol = initializedName_copy->get_scope()->lookup_enum_field_symbol(name);
16854 ROSE_ASSERT(symbol != NULL);
16855
16856 SgEnumFieldSymbol* enumFieldSymbol = isSgEnumFieldSymbol(symbol);
16857 ROSE_ASSERT(enumFieldSymbol != NULL);
16858
16859 // DQ (3/17/2014): Build a new sysmbol to for the initializedName_copy instead of reusing the existing symbol
16860 // from the snippet AST.
16861 SgEnumFieldSymbol* new_enumFieldSymbol = new SgEnumFieldSymbol(initializedName_copy);
16862 ROSE_ASSERT(new_enumFieldSymbol != NULL);
16863
16864 // targetScope->insert_symbol(name,enumFieldSymbol);
16865 targetScope->insert_symbol(name,new_enumFieldSymbol);
16866
16867 // DQ (3/6/2014): Set the scope of the SgInitializedName IR node.
16868 initializedName_copy->set_scope(targetScope);
16869#if 0
16870 printf ("Exiting as a test! \n");
16871 ROSE_ABORT();
16872#endif
16873 }
16874 else
16875 {
16876#if 0
16877 printf ("enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
16878#endif
16879 SgCatchOptionStmt* catchOptionStatement = isSgCatchOptionStmt(enclosingStatement_copy->get_parent());
16880 if (catchOptionStatement != NULL)
16881 {
16882 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(enclosingStatement_copy);
16883 ROSE_ASSERT(variableDeclaration != NULL);
16884
16885 // SgSymbol* symbol = targetScope->lookup_variable_symbol(initializedName_copy->get_name());
16886 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(initializedName_original);
16887 ROSE_ASSERT(enclosingStatement_original != NULL);
16888 SgCatchOptionStmt* catchOptionStatement_original = isSgCatchOptionStmt(enclosingStatement_original->get_parent());
16889
16890 // SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),targetScope);
16891 SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),catchOptionStatement_original);
16892 if (symbol == NULL)
16893 {
16894 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
16895 // initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
16896 }
16897 ROSE_ASSERT(symbol != NULL);
16898
16899 initializedName_copy->set_scope(targetScope);
16900
16901 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
16902 ROSE_ASSERT(new_variableSymbol != NULL);
16903
16904 // DQ (3/19/2014): I am not certain this is the correct location to insert this symbol.
16905 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
16906 }
16907 else
16908 {
16909 // DQ (3/29/2014): Adding support for SgInitializedName IR nodes found in a SgJavaForEachStatement.
16910 SgJavaForEachStatement* javaForEachStatement = isSgJavaForEachStatement(enclosingStatement_copy->get_parent());
16911 if (javaForEachStatement != NULL)
16912 {
16913 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(enclosingStatement_copy);
16914 ROSE_ASSERT(variableDeclaration != NULL);
16915
16916 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(initializedName_original);
16917 ROSE_ASSERT(enclosingStatement_original != NULL);
16918 SgJavaForEachStatement* javaForEachStatement_original = isSgJavaForEachStatement(enclosingStatement_original->get_parent());
16919
16920 SgSymbol* symbol = lookupVariableSymbolInParentScopes(initializedName_copy->get_name(),javaForEachStatement_original);
16921 if (symbol == NULL)
16922 {
16923 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
16924 // initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
16925 }
16926 ROSE_ASSERT(symbol != NULL);
16927
16928 initializedName_copy->set_scope(targetScope);
16929
16930 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
16931 ROSE_ASSERT(new_variableSymbol != NULL);
16932
16933 // DQ (3/29/2014): I am not certain this is the correct location to insert this symbol.
16934 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
16935#if 0
16936 printf ("Need to handle case of SgJavaForEachStatement \n");
16937 ROSE_ABORT();
16938#endif
16939 }
16940 else
16941 {
16942 // Case of non-SgFunctionParameterList and non-SgEnumDeclaration use of SgInitializedName in AST.
16943 SgSymbol* symbol = initializedName_copy->search_for_symbol_from_symbol_table();
16944 if (symbol == NULL)
16945 {
16946 printf ("ERROR: enclosingStatement_copy = %p = %s \n",enclosingStatement_copy,enclosingStatement_copy->class_name().c_str());
16947 ROSE_ASSERT(enclosingStatement_copy->get_parent() != NULL);
16948 printf ("ERROR: enclosingStatement_copy->get_parent() = %p = %s \n",enclosingStatement_copy->get_parent(),enclosingStatement_copy->get_parent()->class_name().c_str());
16949 printf ("ERROR: (symbol == NULL): initializedName_copy->get_name() = %s \n",initializedName_copy->get_name().str());
16950 initializedName_original->get_file_info()->display("ERROR: (symbol == NULL): debug");
16951
16952 // DQ (3/30/2014): Add this appraoch to find the symbol.
16953 SgScopeStatement* initializedName_copy_scope = isSgScopeStatement(initializedName_copy->get_scope());
16954 ROSE_ASSERT(initializedName_copy_scope != NULL);
16955 SgVariableSymbol* variableSymbol = initializedName_copy_scope->lookup_variable_symbol(initializedName_copy->get_name());
16956 ROSE_ASSERT(variableSymbol != NULL);
16957
16958 symbol = variableSymbol;
16959 }
16960 ROSE_ASSERT(symbol != NULL);
16961
16962 SgVariableSymbol* variableSymbol = isSgVariableSymbol(symbol);
16963 ROSE_ASSERT(variableSymbol != NULL);
16964#if 0
16965 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());
16966#endif
16967 // DQ (3/17/2014): Build a new sysmbol to for the initializedName_copy instead of reusing the existing symbol
16968 // from the snippet AST.
16969 SgVariableSymbol* new_variableSymbol = new SgVariableSymbol(initializedName_copy);
16970 ROSE_ASSERT(new_variableSymbol != NULL);
16971
16972 // targetScope->insert_symbol(initializedName_copy->get_name(),variableSymbol);
16973 targetScope->insert_symbol(initializedName_copy->get_name(),new_variableSymbol);
16974
16975 // DQ (3/6/2014): Set the scope of the SgInitializedName IR node.
16976 initializedName_copy->set_scope(targetScope);
16977
16978#if 0
16979 SgName mangledName = variableSymbol->get_mangled_name();
16980 printf ("initializedName_copy: mangledName = %s \n",mangledName.str());
16981#endif
16982 // DQ (3/2/2014): Make sure this is true (I think it should be, but I don't see that it was explicitly set).
16983 // ROSE_ASSERT(initializedName_copy->get_scope() == targetScope);
16984 if (initializedName_copy->get_scope() != targetScope)
16985 {
16986 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());
16987
16988 printf ("I think this should be an error! \n");
16989 ROSE_ABORT();
16990 }
16991 }
16992 }
16993 }
16994 }
16995
16996 break;
16997 }
16998
16999 case V_SgVariableDeclaration:
17000 {
17001 // I think there is nothing to handle for this case (there is no type accessbile here
17002 // since they are in the SgInitializedName IR nodes).
17003 SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(node_copy);
17004 ROSE_ASSERT(variableDeclaration != NULL);
17005
17006 break;
17007 }
17008
17009#define DEBUG_FUNCTION_DECLARATION 0
17010
17011 case V_SgFunctionDeclaration:
17012 {
17013 // SgFunctionDeclaration is handled directly in the snippet support (insertRelatedThingsForC() function).
17014
17015 // Note that function types are stored in global type tables so they need not be fixed up.
17016
17017 // DQ (3/13/2014): As of today, this assumption is no longer true, we need to be able to insert
17018 // any function declaration in insertRelatedThingsForC() and use this function to fixup the AST.
17019 // The target AST should have a prototype (non-defining declaration) of the function defined
17020 // so that all internal types of the SgFunctionType are defined in the target AST.
17021 SgFunctionDeclaration* functionDeclaration_copy = isSgFunctionDeclaration(node_copy);
17022 SgFunctionDeclaration* functionDeclaration_original = isSgFunctionDeclaration(node_original);
17023 SgFunctionType* functionType_copy = functionDeclaration_copy->get_type();
17024 SgFunctionType* functionType_original = functionDeclaration_original->get_type();
17025 ROSE_ASSERT(functionType_copy != NULL);
17026 ROSE_ASSERT(functionType_original != NULL);
17027 ROSE_ASSERT(functionType_copy == functionType_original);
17028#if DEBUG_FUNCTION_DECLARATION
17029 printf ("case SgFunctionDeclaration: part 1: Calling functionDeclaration_copy->search_for_symbol_from_symbol_table() \n");
17030#endif
17031 // SgSymbol* symbol_copy = functionDeclaration_copy->search_for_symbol_from_symbol_table();
17032 SgSymbol* symbol_original = functionDeclaration_original->search_for_symbol_from_symbol_table();
17033 ROSE_ASSERT(symbol_original != NULL);
17034 SgFunctionSymbol* functionSymbol_original = isSgFunctionSymbol(symbol_original);
17035 ROSE_ASSERT(functionSymbol_original != NULL);
17036
17037 SgFile* snippetFile = getEnclosingFileNode(functionSymbol_original);
17038 ROSE_ASSERT(snippetFile != NULL);
17039 if (snippetFile != targetFile)
17040 {
17041#if DEBUG_FUNCTION_DECLARATION
17042 printf ("Warning: case V_SgFunctionDeclaration: functionSymbol_original not in target file \n");
17043#endif
17044 // DQ (3/13/2014): Handle the case of a member function seperately (I think this can't appear in Java, only in C++).
17045 // ROSE_ASSERT(isSgMemberFunctionSymbol(symbol_copy) == NULL);
17046 ROSE_ASSERT(isSgMemberFunctionSymbol(symbol_original) == NULL);
17047
17048 // printf ("case SgFunctionDeclaration: part 2: Calling functionDeclaration_copy->search_for_symbol_from_symbol_table() \n");
17049 // SgFunctionSymbol* functionSymbol_copy = isSgFunctionSymbol(functionDeclaration_copy->search_for_symbol_from_symbol_table());
17050 // ROSE_ASSERT(functionSymbol_copy != NULL);
17051
17052 SgName name = functionDeclaration_copy->get_name();
17053 SgType* functionType = functionDeclaration_copy->get_type();
17054 ROSE_ASSERT(functionType != NULL);
17055#if DEBUG_FUNCTION_DECLARATION
17056 printf ("case V_SgFunctionDeclaration: name = %s \n",name.str());
17057 printf ("case V_SgFunctionDeclaration: functionType = %p \n",functionType);
17058 printf ("case V_SgFunctionDeclaration: functionType_original = %p \n",functionType_original);
17059 printf ("case V_SgFunctionDeclaration: functionType_copy = %p \n",functionType_copy);
17060#endif
17061 SgFunctionSymbol* functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,functionType,targetScope);
17062
17063 ROSE_ASSERT(targetScope != NULL);
17064 functionDeclaration_copy->set_scope(targetScope);
17065
17066 // Set the scope of the non-defining declaration.
17067 functionDeclaration_copy->get_firstNondefiningDeclaration()->set_scope(targetScope);
17068
17069 SgFunctionDeclaration* functionDeclaration_copy_firstNondefining = NULL;
17070
17071 if (functionSymbolInTargetAST == NULL)
17072 {
17073#if DEBUG_FUNCTION_DECLARATION
17074 printf ("functionSymbolInTargetAST not found in targetScope = %p = %s \n",targetScope,targetScope->class_name().c_str());
17075#endif
17076 // If could be that the symbol is in the local scope of the snippet AST.
17077 SgScopeStatement* otherPossibleScope = isSgScopeStatement(functionDeclaration_original->get_parent());
17078 ROSE_ASSERT(otherPossibleScope != NULL);
17079#if DEBUG_FUNCTION_DECLARATION
17080 printf ("case V_SgFunctionDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope,otherPossibleScope->class_name().c_str());
17081#endif
17082 // We want to out serch the additional other scope and not it's parent scope.
17083 // functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,functionType,otherPossibleScope);
17084 functionSymbolInTargetAST = otherPossibleScope->lookup_function_symbol(name,functionType);
17085
17086 if (functionSymbolInTargetAST == NULL)
17087 {
17088 printf ("function symbol not found in otherPossibleScope = %p = %s \n",otherPossibleScope,otherPossibleScope->class_name().c_str());
17089 }
17090
17091 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17092#if DEBUG_FUNCTION_DECLARATION
17093 printf ("(building a new SgFunctionSymbol): functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17094#endif
17095 // DQ (3/15/2014): We need to insert a new symbol into the targetScope instead of reusing
17096 // the existing symbol (because it points to the declaration in the snippet file).
17097 // Insert the symbol into the targetScope.
17098 // targetScope->insert_symbol(name,functionSymbolInTargetAST);
17099 functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionDeclaration_copy->get_firstNondefiningDeclaration());
17100 SgFunctionSymbol* new_symbol = new SgFunctionSymbol(functionDeclaration_copy_firstNondefining);
17101 ROSE_ASSERT(new_symbol != NULL);
17102
17103 targetScope->insert_symbol(name,new_symbol);
17104
17105 functionSymbolInTargetAST = new_symbol;
17106
17107 ROSE_ASSERT(lookupFunctionSymbolInParentScopes(name,functionType,targetScope) != NULL);
17108 }
17109 else
17110 {
17111 // If we happend to find an associated symbol in the target scope then we nave to use it and
17112 // set the first nondefining declaration pointer to the symbol's associate declaration.
17113 // This is the case of the test3a test code (because the snippet functions declaration is
17114 // in the target AST file (likely a mistake, but we should handle it properly).
17115#if DEBUG_FUNCTION_DECLARATION
17116 printf ("(using existing symbol found in target scope): functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17117#endif
17118 functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionSymbolInTargetAST->get_declaration());
17119 }
17120
17121 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17122
17123 ROSE_ASSERT(functionDeclaration_copy->get_firstNondefiningDeclaration() != NULL);
17124 ROSE_ASSERT(functionDeclaration_copy_firstNondefining != NULL);
17125
17126 // SgFunctionDeclaration* functionDeclaration_copy_firstNondefining = isSgFunctionDeclaration(functionDeclaration_copy->get_firstNondefiningDeclaration());
17127 SgFunctionDeclaration* functionDeclaration_original_firstNondefining = isSgFunctionDeclaration(functionDeclaration_original->get_firstNondefiningDeclaration());
17128 SgFunctionDeclaration* functionDeclaration_copy_defining = isSgFunctionDeclaration(functionDeclaration_copy->get_definingDeclaration());
17129 SgFunctionDeclaration* functionDeclaration_original_defining = isSgFunctionDeclaration(functionDeclaration_original->get_definingDeclaration());
17130 if (functionDeclaration_copy_firstNondefining->get_symbol_from_symbol_table() == NULL)
17131 {
17132 // Check what might be wrong here!
17133 ROSE_ASSERT(functionDeclaration_original_firstNondefining != NULL);
17134 printf ("functionSymbolInTargetAST->get_declaration() = %p \n",functionSymbolInTargetAST->get_declaration());
17135
17136 printf ("functionDeclaration_original = %p = %s \n",functionDeclaration_original,functionDeclaration_original->class_name().c_str());
17137 printf ("functionDeclaration_copy = %p = %s \n",functionDeclaration_copy,functionDeclaration_copy->class_name().c_str());
17138 printf ("functionDeclaration_original_firstNondefining = %p \n",functionDeclaration_original_firstNondefining);
17139 printf ("functionDeclaration_copy_firstNondefining = %p \n",functionDeclaration_copy_firstNondefining);
17140 printf ("functionDeclaration_original_defining = %p \n",functionDeclaration_original_defining);
17141 printf ("functionDeclaration_copy_defining = %p \n",functionDeclaration_copy_defining);
17142
17143 printf ("functionDeclaration_original->get_scope() = %p = %s \n",functionDeclaration_original->get_scope(),functionDeclaration_original->get_scope()->class_name().c_str());
17144 printf ("functionDeclaration_copy->get_scope() = %p = %s \n",functionDeclaration_copy->get_scope(),functionDeclaration_copy->get_scope()->class_name().c_str());
17145 printf ("functionDeclaration_original_firstNondefining->get_scope() = %p = %s \n",functionDeclaration_original_firstNondefining->get_scope(),functionDeclaration_original_firstNondefining->get_scope()->class_name().c_str());
17146 printf ("functionDeclaration_copy_firstNondefining->get_scope() = %p = %s \n",functionDeclaration_copy_firstNondefining->get_scope(),functionDeclaration_copy_firstNondefining->get_scope()->class_name().c_str());
17147 printf ("functionDeclaration_original_defining->get_scope() = %p = %s \n",functionDeclaration_original_defining->get_scope(),functionDeclaration_original_defining->get_scope()->class_name().c_str());
17148 printf ("functionDeclaration_copy_defining->get_scope() = %p = %s \n",functionDeclaration_copy_defining->get_scope(),functionDeclaration_copy_defining->get_scope()->class_name().c_str());
17149 printf ("functionSymbolInTargetAST = %p = %s \n",functionSymbolInTargetAST,functionSymbolInTargetAST->class_name().c_str());
17150 }
17151
17152 ROSE_ASSERT(targetScope->lookup_function_symbol(name,functionType) != NULL);
17153
17154 // TV (10/22/2014): Might not be the case as we now have a project wide global scope
17155 // ROSE_ASSERT(functionDeclaration_copy_firstNondefining->get_scope() == targetScope);
17156
17157 ROSE_ASSERT(functionDeclaration_copy_firstNondefining == functionDeclaration_copy_firstNondefining->get_firstNondefiningDeclaration());
17158
17159 // This is what is called internal to the get_symbol_from_symbol_table() function below.
17160 // Use this function, SgFunctionDeclaration::get_symbol_from_symbol_table(), but not the template function: find_symbol_from_declaration().
17161 // ROSE_ASSERT(targetScope->find_symbol_from_declaration(functionDeclaration_copy_firstNondefining) != NULL);
17162
17163 ROSE_ASSERT(functionDeclaration_copy_firstNondefining->get_symbol_from_symbol_table() != NULL);
17164
17165#if 0
17166 bool isDefiningDeclaration (functionDeclaration_original->get_declaration() != NULL);
17167 if (isDefiningDeclaration == true)
17168 {
17169 // We may have to build a non-defining declaration.
17170 SgFunctionDeclaration* nondefiningFunctionDeclaration_original = functionDeclaration_original->get_firstNondefiningDeclaration();
17171 SgFile* nondefiningDeclarationFile = getEnclosingFileNode(functionSymbol_original);
17172 ROSE_ASSERT(nondefiningDeclarationFile != NULL);
17173 if (nondefiningDeclarationFile == targetFile)
17174 {
17175 // Use this nondefining declaration.
17176 }
17177 else
17178 {
17179 // Make a copy of the non-defining declaration for use in the symbol.
17180 }
17181
17182 }
17183 else
17184 {
17185 // Use this as non-defining declaration.
17186 }
17187
17188 SgFile* snippetFile = getEnclosingFileNode(functionSymbol_original);
17189 SgFunctionSymbol* new_function_symbol = new SgFunctionSymbol(isSgFunctionDeclaration(func));
17190 ROSE_ASSERT(func_symbol->get_symbol_basis() != NULL);
17191 targetScope->insert_symbol(name,symbol_original);
17192
17193 ROSE_ABORT();
17194#endif
17195 }
17196
17197 // DQ (3/17/2014): Refactored code to support resetting the scopes in the SgDeclarationStatement IR nodes.
17198 resetDeclaration(functionDeclaration_copy,functionDeclaration_original,targetScope);
17199#if 0
17200 printf ("SageBuilder::fixupCopyOfNodeFromSeperateFileInNewTargetAst(): Need to be able to fixup the SgFunctionDeclaration \n");
17201 ROSE_ABORT();
17202#endif
17203 break;
17204 }
17205
17206 case V_SgClassDeclaration:
17207 {
17208 // Need to handle the referenced types
17209 SgClassDeclaration* classDeclaration_copy = isSgClassDeclaration(node_copy);
17210 SgClassDeclaration* classDeclaration_original = isSgClassDeclaration(node_original);
17211 SgClassType* classType = classDeclaration_copy->get_type();
17212 ROSE_ASSERT(classType != NULL);
17213#if 0
17214 printf ("Need to handle named types from class declarations \n");
17215#endif
17216 // SgClassSymbol* classSymbol_copy = isSgClassSymbol(classDeclaration_copy->search_for_symbol_from_symbol_table());
17217 // ROSE_ASSERT(classSymbol_copy != NULL);
17218
17219 // if (TransformationSupport::getFile(classSymbol_copy) != targetFile)
17220 // if (getEnclosingFileNode(classSymbol_copy) != targetFile)
17221 // if (getEnclosingFileNode(classDeclaration_copy) != targetFile)
17222 {
17223 // printf ("Warning: case V_SgClassDeclaration: classSymbol_copy not in target file \n");
17224#if 0
17225 printf ("Warning: case V_SgClassDeclaration: assume getEnclosingFileNode(classDeclaration_copy) != targetFile \n");
17226#endif
17227 // Find the symbol in the target scope.
17228 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17229#if 0
17230 // printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
17231#endif
17232 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
17233
17234 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17235 // ROSE_ASSERT(targetScope != NULL);
17236
17237 SgName name = classDeclaration_copy->get_name();
17238#if 0
17239 // If we randomize the names then we need to handle this case...
17240 printf ("case V_SgClassDeclaration: targetScope = %p classSymbol_copy->get_name() = %s \n",targetScope,classSymbol_copy->get_name().str());
17241#endif
17242 // SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(classSymbol_copy->get_name(),targetScope);
17243 SgClassSymbol* classSymbolInTargetAST = lookupClassSymbolInParentScopes(name,targetScope);
17244
17245 if (classSymbolInTargetAST == NULL)
17246 {
17247 // If could be that the symbol is in the local scope of the snippet AST.
17248 SgScopeStatement* otherPossibleScope = isSgScopeStatement(classDeclaration_original->get_parent());
17249 ROSE_ASSERT(otherPossibleScope != NULL);
17250#if 0
17251 printf ("case V_SgClassDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
17252#endif
17253 // classSymbolInTargetAST = lookupClassSymbolInParentScopes(classSymbol_copy->get_name(),otherPossibleScope);
17254 classSymbolInTargetAST = lookupClassSymbolInParentScopes(name,otherPossibleScope);
17255 ROSE_ASSERT(classSymbolInTargetAST != NULL);
17256#if 0
17257 // I think this is the wrong code.
17258 SgClassDeclaration* classDeclaration = classSymbolInTargetAST->get_declaration();
17259 ROSE_ASSERT(classDeclaration != NULL);
17260 SgScopeStatement* scope = classDeclaration->get_scope();
17261 ROSE_ASSERT(scope != NULL);
17262 classDeclaration_copy->set_scope(scope);
17263#else
17264 // DQ (3/17/2014): The scope must be set to be the targetScope (at least for C, but maybe not C++).
17265 classDeclaration_copy->set_scope(targetScope);
17266#endif
17267 // DQ (3/17/2014): Build a new SgClassSymbol using the classDeclaration_copy.
17268 SgClassSymbol* classSymbol = new SgClassSymbol(classDeclaration_copy);
17269 ROSE_ASSERT(classSymbol != NULL);
17270 classSymbolInTargetAST = classSymbol;
17271
17272 // Insert the symbol into the targetScope.
17273 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
17274 targetScope->insert_symbol(name,classSymbolInTargetAST);
17275 }
17276 else
17277 {
17278 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
17279 SgClassDeclaration* classDeclaration = classSymbolInTargetAST->get_declaration();
17280 ROSE_ASSERT(classDeclaration != NULL);
17281 SgScopeStatement* scope = classDeclaration->get_scope();
17282 ROSE_ASSERT(scope != NULL);
17283 classDeclaration_copy->set_scope(scope);
17284 }
17285
17286 ROSE_ASSERT(classSymbolInTargetAST != NULL);
17287 }
17288
17289 // DQ (3/17/2014): Avoid calling strip type now that we have refactored the getTargetFileType() function.
17290 // DQ (3/10/2014): Added remaining type for this case.
17291 // SgType* new_type = getTargetFileType(classType->stripType(),targetScope);
17292 SgType* new_type = getTargetFileType(classType,targetScope);
17293 SgClassType* new_class_type = isSgClassType(new_type);
17294 if (new_class_type != NULL)
17295 {
17296 // Reset the base type to be the one associated with the target file.
17297 classDeclaration_copy->set_type(new_class_type);
17298#if 0
17299 printf ("case V_SgClassDeclaration: built class type: part 1: classDeclaration_copy->get_type() = %p = %s \n",
17300 classDeclaration_copy->get_type(),classDeclaration_copy->get_type()->class_name().c_str());
17301#endif
17302 }
17303
17304 resetDeclaration(classDeclaration_copy,classDeclaration_original,targetScope);
17305#if 0
17306 printf ("SgClassDeclaration: Exiting as a test! \n");
17307 ROSE_ABORT();
17308#endif
17309 break;
17310 }
17311
17312 case V_SgEnumDeclaration:
17313 {
17314 // Need to handle the referenced types
17315 SgEnumDeclaration* enumDeclaration_copy = isSgEnumDeclaration(node_copy);
17316 SgEnumDeclaration* enumDeclaration_original = isSgEnumDeclaration(node_original);
17317
17318 // SgEnumType* enumType = enumDeclaration_copy->get_type();
17319 // ROSE_ASSERT(enumType != NULL);
17320
17321 // I don't think we have to test for this being a part of the snippet file.
17322 {
17323 SgName name = enumDeclaration_copy->get_name();
17324#if 0
17325 // If we randomize the names then we need to handle this case...
17326 printf ("case V_SgEnumDeclaration: targetScope = %p enumSymbol_copy->get_name() = %s \n",targetScope,name.str());
17327#endif
17328 SgEnumSymbol* enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(name,targetScope);
17329
17330 if (enumSymbolInTargetAST == NULL)
17331 {
17332 // If could be that the symbol is in the local scope of the snippet AST.
17333 SgScopeStatement* otherPossibleScope = isSgScopeStatement(enumDeclaration_original->get_parent());
17334 ROSE_ASSERT(otherPossibleScope != NULL);
17335#if 0
17336 printf ("case V_SgEnumDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
17337#endif
17338 // I think we are not looking in the correct scope! Or else we need to also look in the target global scope.
17339#if 0
17340 printf ("Since the symbol has not been inserted yet, what symbol are we looking for? \n");
17341#endif
17342 enumSymbolInTargetAST = lookupEnumSymbolInParentScopes(name,otherPossibleScope);
17343
17344 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
17345 SgEnumDeclaration* enumDeclaration = enumSymbolInTargetAST->get_declaration();
17346 ROSE_ASSERT(enumDeclaration != NULL);
17347
17348 ROSE_ASSERT(enumDeclaration != enumDeclaration_original);
17349
17350 // This is true, so we need to build a new sysmbol.
17351 ROSE_ASSERT(enumSymbolInTargetAST->get_declaration() == enumDeclaration_original->get_firstNondefiningDeclaration());
17352
17353 // Build a new SgEnumSymbol using the enumDeclaration_copy.
17354 SgEnumSymbol* enumSymbol = new SgEnumSymbol(enumDeclaration_copy);
17355 ROSE_ASSERT(enumSymbol != NULL);
17356 enumSymbolInTargetAST = enumSymbol;
17357
17358 // If this is false then we need to build a new SgEnumSymbol rather than reusing the existing one.
17359 ROSE_ASSERT(enumSymbolInTargetAST->get_declaration() != enumDeclaration_original->get_firstNondefiningDeclaration());
17360
17361 // SgScopeStatement* scope = enumDeclaration->get_scope();
17362 SgScopeStatement* scope = targetScope;
17363 ROSE_ASSERT(scope != NULL);
17364 enumDeclaration_copy->set_scope(scope);
17365#if 0
17366 printf ("case V_SgEnumDeclaration: insert_symbol(): name = %s enumSymbolInTargetAST = %p \n",name.str(),enumSymbolInTargetAST);
17367#endif
17368 // Insert the symbol into the targetScope.
17369 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
17370 targetScope->insert_symbol(name,enumSymbolInTargetAST);
17371 }
17372 else
17373 {
17374#if 0
17375 printf ("Found an existing enum declaration: name = %s enumSymbolInTargetAST = %p \n",name.str(),enumSymbolInTargetAST);
17376#endif
17377 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
17378 SgEnumDeclaration* enumDeclaration = enumSymbolInTargetAST->get_declaration();
17379 ROSE_ASSERT(enumDeclaration != NULL);
17380#if 0
17381 SgScopeStatement* scope = enumDeclaration->get_scope();
17382 ROSE_ASSERT(scope != NULL);
17383 ROSE_ASSERT(scope == targetScope);
17384 // enumDeclaration_copy->set_scope(scope);
17385#else
17386 // TV (10/22/2014): Might not be the case as we now have a project wide global scope
17387 // ROSE_ASSERT(enumDeclaration->get_scope() == targetScope);
17388#endif
17389 }
17390
17391 ROSE_ASSERT(enumSymbolInTargetAST != NULL);
17392 }
17393#if 0
17394 printf ("Exiting as a test 1! \n");
17395 ROSE_ABORT();
17396#endif
17397 SgEnumType* enumType = enumDeclaration_copy->get_type();
17398 ROSE_ASSERT(enumType != NULL);
17399 SgType* new_type = getTargetFileType(enumType,targetScope);
17400#if 0
17401 printf ("Return type from getTargetFileType(): original enumType = %p new_type = %p \n",enumType,new_type);
17402#endif
17403 SgEnumType* new_enum_type = isSgEnumType(new_type);
17404 if (new_enum_type != NULL)
17405 {
17406 // Reset the base type to be the one associated with the target file.
17407#if 0
17408 printf ("reset the type using the new enum type from the target AST \n");
17409#endif
17410 enumDeclaration_copy->set_type(new_enum_type);
17411 }
17412#if 0
17413 printf ("Exiting as a test 2! \n");
17414 ROSE_ABORT();
17415#endif
17416
17417 resetDeclaration(enumDeclaration_copy,enumDeclaration_original,targetScope);
17418 break;
17419 }
17420
17421 // This is not a required declaration of C.
17422 case V_SgTemplateClassDeclaration:
17423 {
17424 // Need to handle the referenced types
17425 SgTemplateClassDeclaration* templateClassDeclaration = isSgTemplateClassDeclaration(node_copy);
17426 SgClassType* templateClassType = templateClassDeclaration->get_type();
17427 ROSE_ASSERT(templateClassType != NULL);
17428
17429 // DQ (3/10/2014): Added support for enum types.
17430 SgType* new_type = getTargetFileType(templateClassType,targetScope);
17431 SgClassType* new_templateClass_type = isSgClassType(new_type);
17432 if (new_templateClass_type != NULL)
17433 {
17434 // Reset the base type to be the one associated with the target file.
17435 templateClassDeclaration->set_type(new_templateClass_type);
17436#if 0
17437 printf ("case V_SgTemplateClassDeclaration: built class type: part 1: templateClassDeclaration->get_type() = %p = %s \n",
17438 templateClassDeclaration->get_type(),templateClassDeclaration->get_type()->class_name().c_str());
17439#endif
17440 }
17441
17442 break;
17443 }
17444
17445 case V_SgTypedefDeclaration:
17446 {
17447 // Need to handle the referenced types (there are two for the case of a SgTypedefDeclaration).
17448 SgTypedefDeclaration* typedefDeclaration_copy = isSgTypedefDeclaration(node_copy);
17449 SgTypedefDeclaration* typedefDeclaration_original = isSgTypedefDeclaration(node_original);
17450
17451 SgType* base_type = typedefDeclaration_copy->get_base_type();
17452 ROSE_ASSERT(base_type != NULL);
17453 SgType* new_base_type = getTargetFileType(base_type,targetScope);
17454 if (new_base_type != NULL)
17455 {
17456 // Reset the base type to be the one associated with the target file.
17457 typedefDeclaration_copy->set_base_type(new_base_type);
17458 }
17459
17460 // I don't think we have to test for this being a part of the snippet file.
17461 {
17462 SgName name = typedefDeclaration_copy->get_name();
17463#if 0
17464 // If we randomize the names then we need to handle this case...
17465 printf ("case V_SgTypedefDeclaration: targetScope = %p typedefSymbol_copy->get_name() = %s \n",targetScope,name.str());
17466#endif
17467 SgTypedefSymbol* typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(name,targetScope);
17468
17469 if (typedefSymbolInTargetAST == NULL)
17470 {
17471 // If could be that the symbol is in the local scope of the snippet AST.
17472 SgScopeStatement* otherPossibleScope = isSgScopeStatement(typedefDeclaration_original->get_parent());
17473 ROSE_ASSERT(otherPossibleScope != NULL);
17474#if 0
17475 printf ("case V_SgTypedefDeclaration: otherPossibleScope = %p \n",otherPossibleScope);
17476#endif
17477 typedefSymbolInTargetAST = lookupTypedefSymbolInParentScopes(name,otherPossibleScope);
17478
17479 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
17480 SgTypedefDeclaration* typedefDeclaration = typedefSymbolInTargetAST->get_declaration();
17481 ROSE_ASSERT(typedefDeclaration != NULL);
17482 // SgScopeStatement* scope = typedefDeclaration->get_scope();
17483 SgScopeStatement* scope = targetScope;
17484 ROSE_ASSERT(scope != NULL);
17485 typedefDeclaration_copy->set_scope(scope);
17486
17487 // DQ (3/17/2014): Build a new SgTypedefSymbol using the typedefDeclaration_copy.
17488 SgTypedefSymbol* typedefSymbol = new SgTypedefSymbol(typedefDeclaration_copy);
17489 ROSE_ASSERT(typedefSymbol != NULL);
17490 typedefSymbolInTargetAST = typedefSymbol;
17491#if 0
17492 printf ("case V_SgTypedefDeclaration: insert_symbol(): name = %s typedefSymbolInTargetAST = %p \n",name.str(),typedefSymbolInTargetAST);
17493#endif
17494 // Insert the symbol into the targetScope.
17495 // targetScope->insert_symbol(classSymbol_copy->get_name(),classSymbolInTargetAST);
17496 targetScope->insert_symbol(name,typedefSymbolInTargetAST);
17497 }
17498 else
17499 {
17500#if 0
17501 printf ("Found an existing typedef declaration: name = %s typedefSymbolInTargetAST = %p \n",name.str(),typedefSymbolInTargetAST);
17502#endif
17503 // In this case the symbol is in a parent scope already (find the scope and set the scope of the classDeclaration_copy.
17504 SgTypedefDeclaration* typedefDeclaration = typedefSymbolInTargetAST->get_declaration();
17505 ROSE_ASSERT(typedefDeclaration != NULL);
17506 SgScopeStatement* scope = typedefDeclaration->get_scope();
17507 ROSE_ASSERT(scope != NULL);
17508 typedefDeclaration_copy->set_scope(scope);
17509 }
17510
17511 ROSE_ASSERT(typedefSymbolInTargetAST != NULL);
17512 }
17513#if 0
17514 printf ("Exiting as a test 1! \n");
17515 ROSE_ABORT();
17516#endif
17517 SgTypedefType* typedefType = typedefDeclaration_copy->get_type();
17518 ROSE_ASSERT(typedefType != NULL);
17519 SgType* new_type = getTargetFileType(typedefType,targetScope);
17520 SgTypedefType* new_typedef_type = isSgTypedefType(new_type);
17521 if (new_typedef_type != NULL)
17522 {
17523 // Reset the base type to be the one associated with the target file.
17524#if 0
17525 printf ("reset the type using the new typedef type from the target AST \n");
17526#endif
17527 typedefDeclaration_copy->set_type(new_typedef_type);
17528#if 0
17529 printf ("case V_SgTypedefDeclaration: built class type: part 1: typedefDeclaration_copy->get_type() = %p = %s \n",
17530 typedefDeclaration_copy->get_type(),typedefDeclaration_copy->get_type()->class_name().c_str());
17531#endif
17532 }
17533
17534 resetDeclaration(typedefDeclaration_copy,typedefDeclaration_original,targetScope);
17535#if 0
17536 printf ("Exiting as a test 2! \n");
17537 ROSE_ABORT();
17538#endif
17539 break;
17540 }
17541
17542 case V_SgVarRefExp:
17543 {
17544 // Need to handle the referenced symbol.
17545 // but if we have handle this in the declaration for the variable (case V_SgInitializedName)
17546 // then we don't have to do anything here. However, we have only handled this variable
17547 // declaration if the variable declaration was a part of the snippet. If the variable
17548 // declaration is not a part of the original snippet (the copy of the snippet's AST that
17549 // we are inserting (not the snippet program where it would have to be defined for the
17550 // snippet to compile) then we have to find the associated variable sysmbol in the target
17551 // AST and reset the SgVarRefExp to use that symbol.
17552
17553 SgVarRefExp* varRefExp_copy = isSgVarRefExp(node_copy);
17554 SgVarRefExp* varRefExp_original = isSgVarRefExp(node_original);
17555 SgVariableSymbol* variableSymbol_copy = isSgVariableSymbol(varRefExp_copy->get_symbol());
17556 ROSE_ASSERT(variableSymbol_copy != NULL);
17557 // if (TransformationSupport::getFile(variableSymbol_copy) != targetFile)
17558 if (getEnclosingFileNode(variableSymbol_copy) != targetFile)
17559 {
17560#if 0
17561 printf ("Warning: case V_SgVarRefExp: variableSymbol not in target file: name = %s \n",variableSymbol_copy->get_name().str());
17562#endif
17563#if 0
17564 printf ("insertionPoint = %p = %s \n",insertionPoint,insertionPoint->class_name().c_str());
17565#endif
17566 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17567#if 0
17568 // printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
17569#endif
17570 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
17571
17572 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17573 // ROSE_ASSERT(targetScope != NULL);
17574
17575 SgVariableSymbol* variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),targetScope);
17576
17577 if (variableSymbolInTargetAST == NULL)
17578 {
17579 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
17580 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
17581 // previously added snippet.
17582#if 0
17583 printf ("Error: The associated variable = %s should have been found in a parent scope of the target AST \n",variableSymbol_copy->get_name().str());
17584#endif
17585 // We need to look into the scope of the block used to define the statments as seperate snippets (same issue as for functions).
17586
17587 // If could be that the symbol is in the local scope of the snippet AST.
17588 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(varRefExp_original);
17589 ROSE_ASSERT(enclosingStatement_original != NULL);
17590#if 0
17591 printf ("case V_SgVarRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
17592#endif
17593 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
17594 ROSE_ASSERT(otherPossibleScope_original != NULL);
17595 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
17596 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
17597 ROSE_ASSERT(file != NULL);
17598#if 0
17599 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
17600 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
17601
17602 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
17603 printf ("case V_SgClassDeclaration: variableSymbol_copy->get_name() = %s \n",variableSymbol_copy->get_name().str());
17604#endif
17605 variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),otherPossibleScope_original);
17606 if (variableSymbolInTargetAST == NULL)
17607 {
17608#if 0
17609 targetScope->get_symbol_table()->print("targetScope: symbol table");
17610 otherPossibleScope_original->get_symbol_table()->print("otherPossibleScope_original: symbol table");
17611#endif
17612
17613 // Check for the case of a record reference (member of data structure).
17614 SgExpression* parentExpression = isSgExpression(varRefExp_copy->get_parent());
17615 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
17616 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
17617 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
17618 if (parentDotExp != NULL || parentArrowExp != NULL)
17619 {
17620 // This is a data member reference, so it's scope is the associated data structure.
17621 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
17622 ROSE_ASSERT(lhs != NULL);
17623 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == varRefExp_copy);
17624
17625 SgType* type = lhs->get_type();
17626 ROSE_ASSERT(type != NULL);
17627#if 0
17628 printf ("type = %p = %s \n",type,type->class_name().c_str());
17629#endif
17630 SgNamedType* namedType = isSgNamedType(type);
17631 ROSE_ASSERT(namedType != NULL);
17632 SgDeclarationStatement* declaration = namedType->get_declaration();
17633 ROSE_ASSERT(declaration != NULL);
17634 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
17635 ROSE_ASSERT(classDeclaration != NULL);
17636 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
17637 ROSE_ASSERT(definingClassDeclaration != NULL);
17638 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
17639 ROSE_ASSERT(classDefinition != NULL);
17640#if 0
17641 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
17642#endif
17643 // I think we want the copy.
17644 otherPossibleScope_original = classDefinition;
17645
17646 variableSymbolInTargetAST = lookupVariableSymbolInParentScopes(variableSymbol_copy->get_name(),otherPossibleScope_original);
17647 }
17648
17649 }
17650 ROSE_ASSERT(variableSymbolInTargetAST != NULL);
17651 SgInitializedName* initializedName = variableSymbolInTargetAST->get_declaration();
17652 ROSE_ASSERT(initializedName != NULL);
17653 SgScopeStatement* scope = initializedName->get_scope();
17654 ROSE_ASSERT(scope != NULL);
17655
17656 // Is this the correct scope?
17657 initializedName->set_scope(scope);
17658
17659 // Insert the symbol into the targetScope.
17660 targetScope->insert_symbol(variableSymbol_copy->get_name(),variableSymbolInTargetAST);
17661 }
17662 ROSE_ASSERT(variableSymbolInTargetAST != NULL);
17663
17664 // Reset the symbol associated with this variable reference.
17665 varRefExp_copy->set_symbol(variableSymbolInTargetAST);
17666
17667 // printf ("Exiting as a test! \n");
17668 // ROSE_ASSERT(false);
17669 }
17670
17671 break;
17672 }
17673
17674 case V_SgFunctionRefExp:
17675 {
17676 // Need to handle the referenced symbol
17677 SgFunctionRefExp* functionRefExp_copy = isSgFunctionRefExp(node_copy);
17678 // SgFunctionRefExp* functionRefExp_original = isSgFunctionRefExp(node_original);
17679 SgFunctionSymbol* functionSymbol_copy = isSgFunctionSymbol(functionRefExp_copy->get_symbol());
17680 ROSE_ASSERT(functionSymbol_copy != NULL);
17681 // if (TransformationSupport::getFile(functionSymbol) != targetFile)
17682 if (getEnclosingFileNode(functionSymbol_copy) != targetFile)
17683 {
17684#if 0
17685 printf ("Warning: case V_SgFunctionRefExp: functionSymbol_copy not in target file (find function = %s) \n",functionSymbol_copy->get_name().str());
17686#endif
17687 // SgNode* insertionPointScope = (insertionPointIsScope == true) ? insertionPoint : insertionPoint->get_parent();
17688#if 0
17689 printf ("insertionPointIsScope = %s insertionPointScope = %p = %s \n",insertionPointIsScope ? "true" : "false",insertionPointScope,insertionPointScope->class_name().c_str());
17690#endif
17691 // Find the nearest variable with the same name in an outer scope (starting at insertionPointScope).
17692
17693 // SgScopeStatement* targetScope = isSgScopeStatement(insertionPointScope);
17694 // ROSE_ASSERT(targetScope != NULL);
17695
17696 SgName name = functionSymbol_copy->get_name();
17697
17698 // I think we need the function's mangled name to support this lookup.
17699 SgFunctionSymbol* functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(name,targetScope);
17700
17701 if (functionSymbolInTargetAST == NULL)
17702 {
17703 // DQ (3/17/2014): Revised as of further discussion about how the snippet mechanism will copy required
17704 // declaration from the snippet file to the target AST.
17705 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
17706 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
17707 // previously added snippet.
17708 // DQ (3/17/2014): After some revision of the specification for the snippet injection, this is still
17709 // an error since this is the case where a declaration should have been visible from having already been
17710 // inserted into the target AST and this visible from this injection point in the target AST.
17711
17712 fprintf (stderr, "Error: The associated function = \"%s\" should have been found in a parent scope"
17713 " of the target AST\n", name.str());
17714
17715 fprintf (stderr, " targetScope = %p = %s \n",targetScope,targetScope->class_name().c_str());
17716 SgGlobal* globalScope = TransformationSupport::getGlobalScope(targetScope);
17717 ROSE_ASSERT(globalScope != NULL);
17718 fprintf (stderr, " globalScope = %p = %s \n",globalScope,globalScope->class_name().c_str());
17719#if 0
17720 targetScope->get_file_info()->display("case V_SgFunctionRefExp: targetScope: debug");
17721 node_original->get_file_info()->display("case V_SgFunctionRefExp: node_original: debug");
17722#endif
17723#if 0
17724 // DQ (3/10/2014): This might be important for friend functions in C++ (but we can ignore it for now).
17725#error "DEAD CODE!"
17726 // If could be that the symbol is in the local scope of the snippet AST.
17727 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(functionRefExp_original);
17728 ROSE_ASSERT(enclosingStatement_original != NULL);
17729#if 0
17730 printf ("case V_SgFunctionRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
17731#endif
17732 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
17733 ROSE_ASSERT(otherPossibleScope_original != NULL);
17734 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
17735 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
17736 ROSE_ASSERT(file != NULL);
17737#if 0
17738 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
17739 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
17740
17741 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
17742 printf ("case V_SgClassDeclaration: functionSymbol_copy->get_name() = %s \n",functionSymbol_copy->get_name().str());
17743#endif
17744 functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(functionSymbol_copy->get_name(),otherPossibleScope_original);
17745#error "DEAD CODE!"
17746 if (functionSymbolInTargetAST == NULL)
17747 {
17748 // Check for the case of a record reference (member function of class declaration).
17749 SgExpression* parentExpression = isSgExpression(functionRefExp_copy->get_parent());
17750 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
17751 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
17752 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
17753 if (parentDotExp != NULL || parentArrowExp != NULL)
17754 {
17755 // This is a data member reference, so it's scope is the associated data structure.
17756 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
17757 ROSE_ASSERT(lhs != NULL);
17758 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == functionRefExp_copy);
17759#error "DEAD CODE!"
17760 SgType* type = lhs->get_type();
17761 ROSE_ASSERT(type != NULL);
17762#if 0
17763 printf ("type = %p = %s \n",type,type->class_name().c_str());
17764#endif
17765 SgNamedType* namedType = isSgNamedType(type);
17766 ROSE_ASSERT(namedType != NULL);
17767 SgDeclarationStatement* declaration = namedType->get_declaration();
17768 ROSE_ASSERT(declaration != NULL);
17769 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
17770 ROSE_ASSERT(classDeclaration != NULL);
17771 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
17772 ROSE_ASSERT(definingClassDeclaration != NULL);
17773 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
17774 ROSE_ASSERT(classDefinition != NULL);
17775#if 0
17776 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
17777#endif
17778 // I think we want the copy.
17779 otherPossibleScope_original = classDefinition;
17780
17781 functionSymbolInTargetAST = lookupFunctionSymbolInParentScopes(functionSymbol_copy->get_name(),otherPossibleScope_original);
17782 }
17783 }
17784
17785#error "DEAD CODE!"
17786 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17787 SgFunctionDeclaration* functionDeclaration = functionSymbolInTargetAST->get_declaration();
17788 ROSE_ASSERT(functionDeclaration != NULL);
17789 SgScopeStatement* scope = functionDeclaration->get_scope();
17790 ROSE_ASSERT(scope != NULL);
17791
17792 // Is this the correct scope?
17793 functionDeclaration->set_scope(scope);
17794#endif
17795 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17796
17797 // Insert the symbol into the targetScope.
17798 targetScope->insert_symbol(functionSymbol_copy->get_name(),functionSymbolInTargetAST);
17799 }
17800 ROSE_ASSERT(functionSymbolInTargetAST != NULL);
17801
17802 // Reset the symbol associated with this function reference.
17803 functionRefExp_copy->set_symbol(functionSymbolInTargetAST);
17804#if 0
17805 printf ("Exiting as a test! \n");
17806 ROSE_ABORT();
17807#endif
17808 }
17809
17810 break;
17811 }
17812
17813#define DEBUG_MEMBER_FUNCTION_REF_EXP 0
17814
17815 case V_SgMemberFunctionRefExp:
17816 {
17817 // Need to handle the referenced symbol
17818 SgMemberFunctionRefExp* memberFunctionRefExp_copy = isSgMemberFunctionRefExp(node_copy);
17819 SgMemberFunctionRefExp* memberFunctionRefExp_original = isSgMemberFunctionRefExp(node_original);
17820 SgMemberFunctionSymbol* memberFunctionSymbol_copy = isSgMemberFunctionSymbol(memberFunctionRefExp_copy->get_symbol());
17821 ROSE_ASSERT(memberFunctionSymbol_copy != NULL);
17822 // if (TransformationSupport::getFile(memberFunctionSymbol) != targetFile)
17823 if (getEnclosingFileNode(memberFunctionSymbol_copy) != targetFile)
17824 {
17825 // Not implemented (initial work is focused on C, then Java, then C++.
17826#if DEBUG_MEMBER_FUNCTION_REF_EXP
17827 printf ("Warning: case V_SgMemberFunctionRefExp: memberFunctionSymbol_copy not in target file (find member function = %s) \n",memberFunctionSymbol_copy->get_name().str());
17828#endif
17829 SgMemberFunctionSymbol* memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),targetScope));
17830
17831 if (memberFunctionSymbolInTargetAST == NULL)
17832 {
17833 // This is a violation of the policy that the a variable with the same name will be found in the target AST.
17834 // Note that if the variable could not be found then it should have been added as part of the snippet, or a
17835 // previously added snippet.
17836#if DEBUG_MEMBER_FUNCTION_REF_EXP
17837 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());
17838#endif
17839 // DQ (3/10/2014): This is important for member functions in Java and C++.
17840
17841 // If could be that the symbol is in the local scope of the snippet AST.
17842 SgStatement* enclosingStatement_original = TransformationSupport::getStatement(memberFunctionRefExp_original);
17843 ROSE_ASSERT(enclosingStatement_original != NULL);
17844#if DEBUG_MEMBER_FUNCTION_REF_EXP
17845 printf ("case V_SgMemberFunctionRefExp: enclosingStatement_original = %p = %s \n",enclosingStatement_original,enclosingStatement_original->class_name().c_str());
17846#endif
17847 SgScopeStatement* otherPossibleScope_original = isSgScopeStatement(enclosingStatement_original->get_parent());
17848 ROSE_ASSERT(otherPossibleScope_original != NULL);
17849 // SgFile* file = TransformationSupport::getFile(enclosingStatement_original);
17850 SgFile* file = getEnclosingFileNode(enclosingStatement_original);
17851 ROSE_ASSERT(file != NULL);
17852#if DEBUG_MEMBER_FUNCTION_REF_EXP
17853 printf ("enclosingStatement_original: associated file name = %s \n",file->get_sourceFileNameWithPath().c_str());
17854 // printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
17855
17856 printf ("case V_SgClassDeclaration: otherPossibleScope = %p = %s \n",otherPossibleScope_original,otherPossibleScope_original->class_name().c_str());
17857 printf ("case V_SgClassDeclaration: memberFunctionSymbol_copy->get_name() = %s \n",memberFunctionSymbol_copy->get_name().str());
17858#endif
17859 memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original));
17860 if (memberFunctionSymbolInTargetAST == NULL)
17861 {
17862#if DEBUG_MEMBER_FUNCTION_REF_EXP
17863 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");
17864#endif
17865 // Check for the case of a record reference (member function of class declaration).
17866 SgExpression* parentExpression = isSgExpression(memberFunctionRefExp_copy->get_parent());
17867
17868 ROSE_ASSERT(parentExpression != NULL);
17869#if DEBUG_MEMBER_FUNCTION_REF_EXP
17870 printf ("parentExpression = %p = %s \n",parentExpression,parentExpression->class_name().c_str());
17871#endif
17872 bool handle_as_java = false;
17873 SgFunctionCallExp* functionCallExp = isSgFunctionCallExp(parentExpression);
17874 if (functionCallExp != NULL)
17875 {
17876 // Note that this is a Java specific organization of the SgMemberFunctionRefExp and the SgFunctionCallExp.
17877 // We might want to make this more uniform between C++ and Java later.
17878 handle_as_java = true;
17879
17880 SgExpression* parentOfFunctionCallExpression = isSgExpression(functionCallExp->get_parent());
17881
17882 ROSE_ASSERT(parentOfFunctionCallExpression != NULL);
17883#if DEBUG_MEMBER_FUNCTION_REF_EXP
17884 printf ("parentOfFunctionCallExpression = %p = %s \n",parentOfFunctionCallExpression,parentOfFunctionCallExpression->class_name().c_str());
17885#endif
17886 parentExpression = parentOfFunctionCallExpression;
17887 }
17888
17889 SgBinaryOp* parentBinaryOp = isSgBinaryOp(parentExpression);
17890 SgDotExp* parentDotExp = isSgDotExp(parentExpression);
17891 SgArrowExp* parentArrowExp = isSgArrowExp(parentExpression);
17892#if DEBUG_MEMBER_FUNCTION_REF_EXP
17893 printf ("parentBinaryOp = %p \n",parentBinaryOp);
17894 printf ("parentDotExp = %p \n",parentDotExp);
17895 printf ("parentArrowExp = %p \n",parentArrowExp);
17896#endif
17897 if (parentDotExp != NULL || parentArrowExp != NULL)
17898 {
17899 // This is a data member reference, so it's scope is the associated data structure.
17900 SgExpression* lhs = parentBinaryOp->get_lhs_operand();
17901 ROSE_ASSERT(lhs != NULL);
17902
17903 // This will be true for C++, but not Java (a little odd).
17904 if (handle_as_java == true)
17905 {
17906 // The rhs is the SgFunctionCallExp for Java.
17907 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == functionCallExp);
17908 }
17909 else
17910 {
17911 // This is what we expect to be true for C++.
17912 ROSE_ASSERT(parentBinaryOp->get_rhs_operand() == memberFunctionRefExp_copy);
17913 }
17914#if DEBUG_MEMBER_FUNCTION_REF_EXP
17915 printf ("lhs = %p = %s \n",lhs,lhs->class_name().c_str());
17916#endif
17917 SgVarRefExp* varRefExp = isSgVarRefExp(lhs);
17918
17919 // DQ (3/15/2014): This can be a SgJavaTypeExpression (see testJava3a).
17920 // ROSE_ASSERT(varRefExp != NULL);
17921 if (varRefExp != NULL)
17922 {
17923 SgVariableSymbol* variableSymbol = isSgVariableSymbol(varRefExp->get_symbol());
17924 ROSE_ASSERT(variableSymbol != NULL);
17925 SgInitializedName* initializedName = variableSymbol->get_declaration();
17926 ROSE_ASSERT(initializedName != NULL);
17927
17928 SgType* initializedName_type = initializedName->get_type();
17929#if DEBUG_MEMBER_FUNCTION_REF_EXP
17930 printf ("initializedName = %p = %s \n",initializedName,initializedName->get_name().str());
17931 printf ("initializedName_type = %p \n",initializedName_type);
17932#endif
17933 SgClassType* classType = isSgClassType(initializedName_type);
17934 if (classType != NULL)
17935 {
17936 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
17937 ROSE_ASSERT(classDeclaration != NULL);
17938 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(classDeclaration->get_definingDeclaration());
17939 ROSE_ASSERT(definingClassDeclaration != NULL);
17940 printf ("definingClassDeclaration->get_name() = %s \n",definingClassDeclaration->get_name().str());
17941
17942 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
17943 ROSE_ASSERT(classDefinition != NULL);
17944 SgType* memberFunctionType = memberFunctionSymbol_copy->get_type();
17945 SgName memberFunctionName = memberFunctionSymbol_copy->get_name();
17946 ROSE_ASSERT(memberFunctionType != NULL);
17947 SgFunctionSymbol *functionSymbol = classDefinition->lookup_function_symbol(memberFunctionName,memberFunctionType);
17948 if (functionSymbol == NULL)
17949 {
17950 printf ("Symbol not found: output symbol table (size = %d): \n",classDefinition->get_symbol_table()->size());
17951#if DEBUG_MEMBER_FUNCTION_REF_EXP
17952 classDefinition->get_symbol_table()->print("Symbol not found: output symbol table: SgClassDefinition");
17953#endif
17954 // DQ (3/30/2014): If functionSymbol is not found then I think it is because the class was not availalbe
17955 // in the target where the snippet is being copied. This is an error in the constrains for how the target
17956 // must be prepared for the snippet to be copied into it.
17957 printf ("\n*************************************************************** \n");
17958 printf ("ERROR: target has not be properly setup to receive the snippet. \n");
17959 printf ("*************************************************************** \n");
17960 }
17961 ROSE_ASSERT(functionSymbol != NULL);
17962 SgMemberFunctionSymbol *memberFunctionSymbol = isSgMemberFunctionSymbol(functionSymbol);
17963 ROSE_ASSERT(memberFunctionSymbol != NULL);
17964
17965 memberFunctionSymbolInTargetAST = memberFunctionSymbol;
17966#if 0
17967 printf ("Exiting as a test! \n");
17968 ROSE_ABORT();
17969#endif
17970 }
17971 }
17972
17973 // DQ (3/30/2014): If this is a value expression then calling the member function uses a shared
17974 // symbol from the global scope (or a type defined deep in the global scope, but common to the
17975 // snippet AST and the target AST).
17976 SgValueExp* valueExp = isSgValueExp(lhs);
17977 if (valueExp != NULL)
17978 {
17979 memberFunctionSymbolInTargetAST = memberFunctionSymbol_copy;
17980 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
17981 }
17982
17983 if (memberFunctionSymbolInTargetAST == NULL)
17984 {
17985#if 1
17986 SgType* type = lhs->get_type();
17987 ROSE_ASSERT(type != NULL);
17988#if DEBUG_MEMBER_FUNCTION_REF_EXP
17989 printf ("type = %p = %s \n",type,type->class_name().c_str());
17990#endif
17991 SgNamedType* namedType = isSgNamedType(type);
17992 ROSE_ASSERT(namedType != NULL);
17993 SgDeclarationStatement* declaration = namedType->get_declaration();
17994 ROSE_ASSERT(declaration != NULL);
17995 SgClassDeclaration* classDeclaration = isSgClassDeclaration(declaration);
17996 ROSE_ASSERT(classDeclaration != NULL);
17997 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(declaration->get_definingDeclaration());
17998 ROSE_ASSERT(definingClassDeclaration != NULL);
17999 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
18000 ROSE_ASSERT(classDefinition != NULL);
18001#if DEBUG_MEMBER_FUNCTION_REF_EXP
18002 printf ("case V_SgClassDeclaration: classDefinition = %p = %s \n",classDefinition,classDefinition->class_name().c_str());
18003#endif
18004 // I think we want the copy.
18005 otherPossibleScope_original = classDefinition;
18006#if DEBUG_MEMBER_FUNCTION_REF_EXP
18007 classDefinition->get_symbol_table()->print("Java classDefinition");
18008#endif
18009#if DEBUG_MEMBER_FUNCTION_REF_EXP
18010 SgClassDeclaration* associated_classDeclaration = classDefinition->get_declaration();
18011 SgFunctionSymbol* functionSymbol = lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original);
18012 printf ("associated_classDeclaration = %p name = %s \n",associated_classDeclaration,associated_classDeclaration->get_name().str());
18013 printf ("functionSymbol = %p \n",functionSymbol);
18014#endif
18015 memberFunctionSymbolInTargetAST = isSgMemberFunctionSymbol(lookupFunctionSymbolInParentScopes(memberFunctionSymbol_copy->get_name(),otherPossibleScope_original));
18016 if (memberFunctionSymbolInTargetAST == NULL)
18017 {
18018 // Output debugging info (16 of the CWE injection test codes fail here: see test_results.txt file for details).
18019 printf ("Error: (memberFunctionSymbolInTargetAST == NULL): memberFunctionSymbol_copy->get_name() = %s \n",memberFunctionSymbol_copy->get_name().str());
18020 }
18021#endif
18022 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18023 }
18024 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18025 }
18026 }
18027
18028 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18029 SgFunctionDeclaration* functionDeclaration = memberFunctionSymbolInTargetAST->get_declaration();
18030 ROSE_ASSERT(functionDeclaration != NULL);
18031 SgScopeStatement* scope = functionDeclaration->get_scope();
18032 ROSE_ASSERT(scope != NULL);
18033
18034 // Is this the correct scope?
18035 functionDeclaration->set_scope(scope);
18036 }
18037 ROSE_ASSERT(memberFunctionSymbolInTargetAST != NULL);
18038
18039 // Reset the symbol associated with this function reference.
18040 memberFunctionRefExp_copy->set_symbol(memberFunctionSymbolInTargetAST);
18041 }
18042
18043 break;
18044 }
18045
18046 // DQ (3/21/2014): I think we need this.
18047 case V_SgTryStmt:
18048 {
18049#if 0
18050 printf ("Exiting as a test! (SgTryStmt) \n");
18051 ROSE_ABORT();
18052#endif
18053 break;
18054 }
18055
18056 // DQ (3/19/2014): Just found this case in a few of the CWE Java snippet tests.
18057 case V_SgCatchStatementSeq:
18058 {
18059 // DQ (3/19/2014): Note sure that we need to handle this specific case.
18060
18061#if 0
18062 printf ("Exiting as a test! (SgCatchStatementSeq) \n");
18063 ROSE_ABORT();
18064#endif
18065 break;
18066 }
18067
18068 // DQ (3/19/2014): Just found this case in a few of the CWE Java snippet tests.
18069 case V_SgCatchOptionStmt:
18070 {
18071 // DQ (3/19/2014): Note sure that we need to handle this specific case.
18072 // Decide if we need to implement this newly identified case tomorrow (note that this is a SgScopeStatement).
18073 SgCatchOptionStmt* catchOptionStatement_copy = isSgCatchOptionStmt(node_copy);
18074 ROSE_ASSERT(catchOptionStatement_copy);
18075
18076 printf ("Need to check the symbol table of the SgCatchOptionStmt (which is a SgScopeStatement) \n");
18077
18078#if 0
18079 printf ("Exiting as a test! (SgCatchOptionStmt) \n");
18080 ROSE_ABORT();
18081#endif
18082 break;
18083 }
18084
18085 // DQ (3/21/2014): I think we need this.
18086 case V_SgJavaPackageStatement:
18087 {
18088#if 1
18089 printf ("Exiting as a test! (SgJavaPackageStatement) \n");
18090 ROSE_ABORT();
18091#endif
18092 break;
18093 }
18094
18095 case V_SgEnumVal:
18096 {
18097 // SgEnumVal expressions contain a reference to the associated SgEnumDeclaration, so this may have to be updated.
18098#if 0
18099 printf ("enum values contain a reference to the associated SgEnumDeclaration \n");
18100#endif
18101 SgEnumVal* enumVal_copy = isSgEnumVal(node_copy);
18102 SgEnumVal* enumVal_original = isSgEnumVal(node_original);
18103#if 0
18104 printf (" --- enumVal_original = %p = %d name = %s \n",enumVal_original,enumVal_original->get_value(),enumVal_original->get_name().str());
18105#endif
18106 SgEnumDeclaration* associatedEnumDeclaration_copy = isSgEnumDeclaration(enumVal_copy->get_declaration());
18107 SgEnumDeclaration* associatedEnumDeclaration_original = isSgEnumDeclaration(enumVal_original->get_declaration());
18108
18109 // DQ (4/13/2014): check if this is an un-named enum beclaration.
18110 bool isUnNamed = associatedEnumDeclaration_original->get_isUnNamed();
18111 if (isUnNamed == false)
18112 {
18113 if (associatedEnumDeclaration_copy == associatedEnumDeclaration_original)
18114 {
18115#if 0
18116 printf (" --- The stored reference to the enum declaration in the SgEnumVal must be reset \n");
18117#endif
18118 // SgSymbol* SageBuilder::findAssociatedSymbolInTargetAST(SgDeclarationStatement* snippet_declaration, SgScopeStatement* targetScope)
18119 SgSymbol* symbol = findAssociatedSymbolInTargetAST(associatedEnumDeclaration_original,targetScope);
18120 if (symbol == NULL)
18121 {
18122 // debug this case.
18123 enumVal_original->get_file_info()->display("case V_SgEnumVal: symbol == NULL: debug");
18124 }
18125 ROSE_ASSERT(symbol != NULL);
18126 SgEnumSymbol* enumSymbol = isSgEnumSymbol(symbol);
18127 ROSE_ASSERT(enumSymbol != NULL);
18128 SgEnumDeclaration* new_associatedEnumDeclaration_copy = enumSymbol->get_declaration();
18129 ROSE_ASSERT(new_associatedEnumDeclaration_copy != NULL);
18130
18131 // If this is false then in means that we should have built a new SgEnumSymbol instead of reusing the existing one from the snippet.
18132 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
18133 // ROSE_ASSERT(new_associatedEnumDeclaration_copy != associatedEnumDeclaration_original->get_firstNondefiningDeclaration());
18134 ROSE_ASSERT(new_associatedEnumDeclaration_copy != associatedEnumDeclaration_original->get_definingDeclaration());
18135
18136 enumVal_copy->set_declaration(new_associatedEnumDeclaration_copy);
18137#if 0
18138 printf ("Exiting as a test! \n");
18139 ROSE_ABORT();
18140#endif
18141 }
18142 }
18143 else
18144 {
18145 // DQ (4/13/2014): I think we all agreed these would not have to be handled, so issue a warning.
18146 // It still is likely that I can allow this, but permit this intermediate fix.
18147 printf ("Warning: can't handle enum values from unnamed enum declarations \n");
18148 printf (" --- enumVal_original = %p = %lld name = %s \n",enumVal_original,enumVal_original->get_value(),enumVal_original->get_name().str());
18149 }
18150
18151 break;
18152 }
18153
18154 default:
18155 {
18156 // Most IR nodes do not require specialized fixup (are not processed).
18157 }
18158 }
18159
18160#if 1
18161 // DQ (3/17/2014): Cause failure on warnings about any constructs referencing the snippet AST.
18162#if 0
18163 // Assert fail on warnings.
18164 errorCheckingTargetAST(node_copy,node_original,targetFile, true);
18165#else
18166 // Cause only warnings.
18167 errorCheckingTargetAST(node_copy,node_original,targetFile, false);
18168#endif
18169#endif
18170 }
18171
18172
18173void
18175 SgStatement *toInsert, SgStatement* original_before_copy)
18176 {
18177 // The semantics of the copy is that it will have been disconnected from the snippet AST in a few ways,
18178 // Namely the root of the copy of the snippet's AST will have been set with a NULL parent, and then
18179 // the parent would have been reset when the copy of the snippet was inserted into the target AST.
18180 // So a simple traversal of parents back to the SgFile will return the target AST's SgFile (confirmed below).
18181
18182 ROSE_ASSERT(insertionPoint != NULL);
18183 ROSE_ASSERT(toInsert != NULL);
18184 ROSE_ASSERT(original_before_copy != NULL);
18185
18186 // DQ (3/30/2014): Turn this on to support finding symbols in base classes (in Java).
18187 // Will be turned off at the base of this function (since we only only want to use it for the AST fixup, currently).
18188 SgSymbolTable::set_force_search_of_base_classes(true);
18189
18190 // DQ (3/4/2014): Switch to using the SageInterface function.
18191 // SgFile* targetFile = TransformationSupport::getFile(insertionPoint);
18192 SgFile* targetFile = getEnclosingFileNode(insertionPoint);
18193
18194 // For Java support this might be NULL, if the insertion point was in global scope.
18195 ROSE_ASSERT(targetFile != NULL);
18196
18197 // SgFile* snippetFile_of_copy = TransformationSupport::getFile(toInsert);
18198 SgFile* snippetFile_of_copy = getEnclosingFileNode(toInsert);
18199
18200 // At this point the parent pointers are set so that the same SgFile is found via a traversal back to the SgProject.
18201 // Confirm that the SgFile found by a traversal of parents in the copy of rthe snippet's AST will return that of the
18202 // SgFile for the target AST. This also confirms that the copy of the snippet has already been inserted into the
18203 // target AST.
18204 ROSE_ASSERT(snippetFile_of_copy == targetFile);
18205
18206 // SgFile* snippetFile_of_original = TransformationSupport::getFile(original_before_copy);
18207 SgFile* snippetFile_of_original = getEnclosingFileNode(original_before_copy);
18208
18209 ROSE_ASSERT(snippetFile_of_original != targetFile);
18210
18211#if 0
18212 printf (" --- targetFile = %p = %s \n",targetFile,targetFile->get_sourceFileNameWithPath().c_str());
18213 printf (" --- snippetFile_of_copy = %p = %s \n",snippetFile_of_copy,snippetFile_of_copy->get_sourceFileNameWithPath().c_str());
18214 printf (" --- snippetFile_of_original = %p = %s \n",snippetFile_of_original,snippetFile_of_original->get_sourceFileNameWithPath().c_str());
18215#endif
18216
18217 // Any node that has entries not referenced in the target file needs to be fixed up.
18218 // We can assume that any referenced variable or function that is referenced in the
18219 // snippet will exist in either the snippet or the target file.
18220
18221 // DQ (3/4/2014): This is a test of the structural equality of the original snippet and it's copy.
18222 // If they are different then we can't support fixing up the AST. Transformations on the snippet
18223 // should have been made after insertion into the AST. The complexity of this test is a traversal
18224 // of the copy of the snippet to be inserted (typically very small compared to the target application).
18225 bool isStructurallyEquivalent = isStructurallyEquivalentAST(toInsert,original_before_copy);
18226 if (isStructurallyEquivalent == false)
18227 {
18228 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");
18229 return;
18230 }
18231 ROSE_ASSERT(isStructurallyEquivalent == true);
18232
18233#ifndef USE_CMAKEx
18234 // DQ (3/8/2014): Make this conditionally compiled based on when CMake is not used because the libraries are not configured yet.
18235
18236 // This is AST container for the ROSE AST that will provide an iterator.
18237 // We want two iterators (one for the copy of the snippet and one for the
18238 // original snippet so that we can query the original snippet's AST
18239 // as we process each IR node of the AST for the copy of the snippet.
18240 // Only the copy of the snippet is inserted into the target AST.
18241 RoseAst ast_of_copy(toInsert);
18242 RoseAst ast_of_original(original_before_copy);
18243
18244 // printf ("ast_of_copy.size() = %" PRIuPTR " \n",ast_of_copy.size());
18245
18246 // Build the iterators so that we can increment thorugh both ASTs one IR node at a time.
18247 RoseAst::iterator i_copy = ast_of_copy.begin();
18248 RoseAst::iterator i_original = ast_of_original.begin();
18249
18250 // Iterate of the copy of the snippet's AST.
18251 while (i_copy != ast_of_copy.end())
18252 {
18253 // DQ (2/28/2014): This is a problem for some of the test codes (TEST store/load heap string [test7a] and [test7a])
18254 // ROSE_ASSERT((*i_copy)->variantT() == (*i_original)->variantT());
18255 if ((*i_copy)->variantT() != (*i_original)->variantT())
18256 {
18257 printf ("ERROR: return from fixupCopyOfAstFromSeparateFileInNewTargetAst(): "
18258 "(*i_copy)->variantT() != (*i_original)->variantT() \n");
18259#if 1
18260 printf ("Making this an error! \n");
18261 ROSE_ABORT();
18262#endif
18263 return;
18264 }
18265
18266 // Operate on individual IR nodes.
18267 fixupCopyOfNodeFromSeparateFileInNewTargetAst(insertionPoint, insertionPointIsScope, *i_copy, *i_original);
18268
18269 i_copy++;
18270
18271 // Verify that we have not reached the end of the ast for the original (both the
18272 // copy and the original are the same structurally, and thus the same size).
18273 ROSE_ASSERT(i_original != ast_of_original.end());
18274 i_original++;
18275 }
18276
18277 // We have reached the end of both ASTs.
18278 ROSE_ASSERT(i_copy == ast_of_copy.end() && i_original == ast_of_original.end());
18279
18280 // DQ (3/8/2014): ENDIF: Make this conditionally compiled based on when CMake is not used because the libraries are not configured yet.
18281#endif
18282
18283#if 0
18284 if (functionDeclaration != NULL)
18285 {
18286 printf ("functionDeclaration = %s \n",functionDeclaration->get_name().str());
18287#if 0
18288 printf ("Exiting as a test! \n");
18289 ROSE_ABORT();
18290#endif
18291 }
18292#endif
18293
18294 // DQ (3/30/2014): Turn this off (since we only only want to use it for the AST fixup, currently).
18295 SgSymbolTable::set_force_search_of_base_classes(false);
18296 }
18297
18298// Liao 9/18/2015
18299// The parser is implemented in
18300// src/frontend/SageIII/astFromString/AstFromString.h .C
18302{
18303
18304 SgStatement* result = NULL;
18305 ROSE_ASSERT (scope != NULL);
18306 // set input and context for the parser
18307 AstFromString::c_char = s.c_str();
18308 ROSE_ASSERT(AstFromString::c_char== s.c_str());
18311
18313 {
18314 result = isSgStatement(AstFromString::c_parsed_node); // grab the result
18315 ROSE_ASSERT(result != NULL);
18316 }
18317 else
18318 {
18319 cerr<<"Error. buildStatementFromString() cannot parse the input string:"<<s
18320 <<"\n\t within the given scope:"<<scope->class_name() <<endl;
18321 ROSE_ABORT();
18322 }
18323 return result;
18324}
18325
18335
18336//
18337// pp (07/16/16)
18338// initial support for creating template instantiations
18339// from template declarations
18340
18341namespace {
18342 // internal functions
18343
18344 template <class SgAstNode>
18345 SgTemplateArgument* createTemplateArg_(SgAstNode& n)
18346 {
18347 static const bool explicitlySpecified = true;
18348
18349 return new SgTemplateArgument(&n, explicitlySpecified);
18350 }
18351
18352 SgTemplateArgument* createTemplateArg_(SgExpression& n)
18353 {
18354 SgTemplateArgument* res = createTemplateArg_<SgExpression>(n);
18355
18356 n.set_parent(res);
18357 return res;
18358 }
18359
18360 SgTemplateArgument* createTemplateArg(SgNode& n)
18361 {
18362 SgTemplateArgument* res = NULL;
18363
18364 if (isSgType(&n))
18365 res = createTemplateArg_(*isSgType(&n));
18366 else if (isSgExpression(&n))
18367 res = createTemplateArg_(*isSgExpression(&n));
18368 else
18369 {
18370 ROSE_ASSERT(isSgTemplateDeclaration(&n));
18371 res = createTemplateArg_(*isSgTemplateDeclaration(&n));
18372 }
18373
18374 ROSE_ASSERT(res);
18375 return res;
18376 }
18377#if 0
18378 SgName genTemplateName(SgName base, Rose_STL_Container<SgNode*>& targs)
18379 {
18380 Rose_STL_Container<SgNode*>::iterator aa = targs.begin();
18381 Rose_STL_Container<SgNode*>::iterator zz = targs.begin();
18382 std::string name(base.getString());
18383
18384 name.append("<");
18385 for ( ; aa != zz; ++aa) name.append((*aa)->unparseToString());
18386 name.append(">");
18387
18388 return SgName(name);
18389 }
18390#endif
18391 SgTemplateArgumentPtrList genTemplateArgumentList(Rose_STL_Container<SgNode*>& targs)
18392 {
18393 Rose_STL_Container<SgNode*>::iterator aa = targs.begin();
18394 Rose_STL_Container<SgNode*>::iterator zz = targs.begin();
18395 SgTemplateArgumentPtrList lst;
18396
18397 for ( ; aa != zz; ++aa)
18398 {
18399 lst.push_back(createTemplateArg(**aa));
18400 }
18401
18402 return lst;
18403 }
18404
18405 SgTemplateClassDeclaration* getCanonicalTemplateDecl(SgTemplateClassDeclaration* main_decl)
18406 {
18407 ROSE_ASSERT(main_decl);
18408 SgClassType* ct = main_decl->get_type();
18409 ROSE_ASSERT(ct);
18410 SgDeclarationStatement* decl = ct->get_declaration();
18411 SgTemplateClassDeclaration* tdecl = isSgTemplateClassDeclaration(decl);
18412
18413 ROSE_ASSERT(tdecl);
18414 return tdecl;
18415 }
18416
18417 SgTemplateInstantiationDecl* genTemplateInstantiationDecl(SgName tname, SgTemplateClassDeclaration* tclassdecl, SgTemplateArgumentPtrList targs)
18418 {
18419 ROSE_ASSERT(tclassdecl);
18420
18421 SgTemplateInstantiationDecl* res = NULL;
18422
18423 res = new SgTemplateInstantiationDecl( tname,
18425 NULL /* SgClassType* type -- to be set later */,
18426 NULL /* SgClassDefinition* def -- to be set later */,
18427 tclassdecl,
18428 targs
18429 );
18430
18431 res->set_scope(tclassdecl->get_scope());
18432 res->set_templateName(tname); // \todo \pp create mangled name from tname
18434 res->setForward(); // \pp set forward, since this is not a proper declaration
18435 return res;
18436 }
18437
18438 SgClassType* genTemplateClass(SgTemplateInstantiationDecl* tdecl)
18439 {
18440 ROSE_ASSERT(tdecl);
18441
18442 return SgClassType::createType(tdecl);
18443 }
18444
18445 struct TemplateArgumentParentSetter
18446 {
18448
18449 TemplateArgumentParentSetter(SgTemplateInstantiationDecl* p)
18450 : parent(p)
18451 {}
18452
18453 void operator()(SgTemplateArgument* targ)
18454 {
18455 targ->set_parent(parent);
18456 }
18457 };
18458} /* anonymous namespace */
18459
18460
18463Rose_STL_Container<SgNode *>& template_args)
18464{
18465 return buildClassTemplateType (template_decl,template_args);
18466}
18467
18470Rose_STL_Container<SgNode *>& template_args)
18471{
18472 ROSE_ASSERT(template_decl);
18473
18474 // create a template instantiation decl
18475 SgName name = template_decl->get_name();
18476 // SgName tname = genTemplateName(, template_args);
18477 SgTemplateArgumentPtrList targs = genTemplateArgumentList(template_args);
18478 SgTemplateClassDeclaration* tdecl = getCanonicalTemplateDecl(template_decl);
18479 SgTemplateInstantiationDecl* tinst = genTemplateInstantiationDecl(name, tdecl, targs);
18480 ROSE_ASSERT(tinst);
18481
18482 // create class type
18483 SgClassType* tclass = genTemplateClass(tinst);
18484 ROSE_ASSERT(tclass);
18485
18486 // set remaining fields in the template instantiation decl
18487 tinst->set_type(tclass);
18488 tinst->set_definition(static_cast<SgTemplateInstantiationDefn*>(0)); /* \pp not sure what to set this to .. */
18489
18490 // set parent of template arguments
18491 std::for_each(targs.begin(), targs.end(), TemplateArgumentParentSetter(tinst)); //
18492
18493 return tclass;
18494}
18495
18496//-----------------------------------------------------------------------------
18497#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
18498//-----------------------------------------------------------------------------
18499
18504 ROSE_ASSERT(Rose::Frontend::Java::lengthSymbol);
18505 SgVarRefExp *var_ref = SageBuilder::buildVarRefExp(Rose::Frontend::Java::lengthSymbol);
18507 return var_ref;
18508}
18509
18514 SgScopeStatement *scope = new SgScopeStatement();
18516 if (parent_scope != NULL) {
18517 scope -> set_parent(parent_scope);
18518 }
18519 return scope;
18520}
18521
18528 return expr;
18529}
18530
18535 SgJavaMarkerAnnotation *annotation = new SgJavaMarkerAnnotation(type);
18537 return annotation;
18538}
18539
18546 pair -> set_name(name);
18547 pair -> set_value(value);
18548 value -> set_parent(pair);
18549 return pair;
18550}
18551
18556 SgJavaSingleMemberAnnotation *annotation = new SgJavaSingleMemberAnnotation(type, value);
18558 return annotation;
18559}
18560
18565 SgJavaNormalAnnotation *annotation = new SgJavaNormalAnnotation(type);
18567 return annotation;
18568}
18569
18573SgJavaNormalAnnotation *SageBuilder::buildJavaNormalAnnotation(SgType *type, list<SgJavaMemberValuePair *>& pair_list) {
18575 for (std::list<SgJavaMemberValuePair *>::iterator i = pair_list.begin(); i != pair_list.end(); i++) {
18576 SgJavaMemberValuePair *member_value_pair = *i;
18577 member_value_pair -> set_parent(annotation);
18578 annotation -> append_value_pair(member_value_pair);
18579 }
18580 return annotation;
18581}
18582
18583
18587SgInitializedName *SageBuilder::buildJavaFormalParameter(SgType *argument_type, const SgName &argument_name, bool is_var_args, bool is_final) {
18588 SgInitializedName *initialized_name = NULL;
18589 if (is_var_args) {
18590 initialized_name = SageBuilder::buildInitializedName(argument_name, SageBuilder::getUniqueJavaArrayType(argument_type, 1), NULL);
18591 initialized_name -> setAttribute("var_args", new AstRegExAttribute(""));
18592 }
18593 else {
18594 initialized_name = SageBuilder::buildInitializedName(argument_name, argument_type, NULL);
18595 }
18596 SageInterface::setSourcePosition(initialized_name);
18597 if (is_final) {
18598 initialized_name -> setAttribute("final", new AstRegExAttribute(""));
18599 }
18600
18601 return initialized_name;
18602}
18603
18608 SgJavaPackageStatement *package_statement = new SgJavaPackageStatement(package_name);
18609 SageInterface::setSourcePosition(package_statement);
18610 package_statement -> set_firstNondefiningDeclaration(package_statement);
18611 package_statement -> set_definingDeclaration(package_statement);
18612 return package_statement;
18613}
18614
18618SgJavaImportStatement *SageBuilder::buildJavaImportStatement(string import_info, bool contains_wildcard) {
18619 SgJavaImportStatement *import_statement = new SgJavaImportStatement(import_info, contains_wildcard);
18620 SageInterface::setSourcePosition(import_statement);
18621 import_statement -> set_firstNondefiningDeclaration(import_statement);
18622 import_statement -> set_definingDeclaration(import_statement);
18623 return import_statement;
18624}
18625
18630 ROSE_ASSERT(scope);
18631 SgName class_name = name;
18632 ROSE_ASSERT(scope -> lookup_class_symbol(class_name) == NULL);
18633
18634 SgClassDeclaration* nonDefiningDecl = NULL;
18635 bool buildTemplateInstantiation = false;
18636 SgTemplateArgumentPtrList* templateArgumentsList = NULL;
18637 SgClassDeclaration *class_declaration = SageBuilder::buildClassDeclaration_nfi(class_name, kind, scope, nonDefiningDecl, buildTemplateInstantiation, templateArgumentsList);
18638 ROSE_ASSERT(class_declaration);
18639 class_declaration -> set_parent(scope);
18640 class_declaration -> set_scope(scope);
18641 SageInterface::setSourcePosition(class_declaration);
18642 SgClassDefinition *class_definition = class_declaration -> get_definition();
18643 ROSE_ASSERT(class_definition);
18644 SageInterface::setSourcePosition(class_definition);
18645
18646 class_definition -> setAttribute("extensions", new AstSgNodeListAttribute());
18647 class_definition -> setAttribute("extension_type_names", new AstRegExAttribute());
18648
18649 SgScopeStatement *type_space = new SgScopeStatement();
18650 type_space -> set_parent(class_definition);
18652 class_declaration -> setAttribute("type_space", new AstSgNodeAttribute(type_space));
18653
18654 return class_declaration;
18655}
18656
18657
18662SgSourceFile *SageBuilder::buildJavaSourceFile(SgProject *project, string directory_name, SgClassDefinition *package_definition, string type_name) {
18663 string filename = directory_name + "/" + type_name + ".java";
18664 ROSE_ASSERT((*project)[filename] == NULL); // does not already exist!
18665
18666 string command = string("touch ") + filename; // create the file
18667 int status = system(command.c_str());
18668 ROSE_ASSERT(status == 0);
18669 project -> get_sourceFileNameList().push_back(filename);
18670 Rose_STL_Container<std::string> arg_list = project -> get_originalCommandLineArgumentList();
18671 arg_list.push_back(filename);
18672 Rose_STL_Container<string> fileList = CommandlineProcessing::generateSourceFilenames(arg_list, // binaryMode
18673 false);
18674 CommandlineProcessing::removeAllFileNamesExcept(arg_list, fileList, filename);
18675 int error_code = 0;
18676 SgFile *file = determineFileType(arg_list, error_code, project);
18677 SgSourceFile *sourcefile = isSgSourceFile(file);
18678 ROSE_ASSERT(sourcefile);
18679 sourcefile -> set_parent(project);
18680 project -> get_fileList_ptr() -> get_listOfFiles().push_back(sourcefile);
18681 ROSE_ASSERT(sourcefile == isSgSourceFile((*project)[filename]));
18682
18683 //
18684 // Create a package statement and add it to the source file
18685 //
18686 SgClassDeclaration* pkgDefDecl = package_definition->get_declaration();
18687 ROSE_ASSERT(pkgDefDecl != NULL);
18688 SgJavaPackageStatement *package_statement = SageBuilder::buildJavaPackageStatement(pkgDefDecl->get_qualified_name().getString());
18689 package_statement->set_parent(package_definition);
18690 sourcefile->set_package(package_statement);
18691
18692 //
18693 // Initialize an import-list for the sourcefile
18694 //
18695 SgJavaImportStatementList *import_statement_list = new SgJavaImportStatementList();
18696 import_statement_list -> set_parent(sourcefile);
18697 sourcefile -> set_import_list(import_statement_list);
18698
18699 //
18700 // Initialize a class-declaration-list for the sourcefile
18701 //
18702 SgJavaClassDeclarationList *class_declaration_list = new SgJavaClassDeclarationList();
18703 class_declaration_list -> set_parent(package_definition);
18704 sourcefile -> set_class_list(class_declaration_list);
18705
18706 return sourcefile;
18707}
18708
18709
18713SgArrayType *SageBuilder::getUniqueJavaArrayType(SgType *base_type, int num_dimensions) {
18714 ROSE_ASSERT(num_dimensions > 0);
18715 if (num_dimensions > 1) {
18716 base_type = getUniqueJavaArrayType(base_type, num_dimensions - 1);
18717 }
18718
18719 ROSE_ASSERT(base_type != NULL);
18720 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) base_type -> getAttribute("array");
18721 if (attribute == NULL) {
18722 SgArrayType *array_type = SageBuilder::buildArrayType(base_type);
18723 array_type -> set_rank(num_dimensions);
18724 attribute = new AstSgNodeAttribute(array_type);
18725 base_type -> setAttribute("array", attribute);
18726 }
18727
18728 return isSgArrayType(attribute -> getNode());
18729}
18730
18731
18735SgJavaParameterizedType *SageBuilder::getUniqueJavaParameterizedType(SgNamedType *generic_type, SgTemplateParameterPtrList *new_args) {
18736 AstParameterizedTypeAttribute *attribute = (AstParameterizedTypeAttribute *) generic_type -> getAttribute("parameterized types");
18737 if (! attribute) {
18738 attribute = new AstParameterizedTypeAttribute(generic_type);
18739 generic_type -> setAttribute("parameterized types", attribute);
18740 }
18741 ROSE_ASSERT(attribute);
18742
18743 return attribute -> findOrInsertParameterizedType(new_args);
18744}
18745
18746
18751 AstSgNodeListAttribute *attribute = (AstSgNodeListAttribute *) type -> getAttribute("qualified types");
18752 if (! attribute) {
18753 attribute = new AstSgNodeListAttribute();
18754 type -> setAttribute("qualified types", attribute);
18755 }
18756 ROSE_ASSERT(attribute);
18757
18758 for (int i = 0; i < attribute -> size(); i++) {
18759 SgJavaQualifiedType *qualified_type = isSgJavaQualifiedType(attribute -> getNode(i));
18760 ROSE_ASSERT(qualified_type);
18761 if (qualified_type -> get_parent_type() == parent_type && qualified_type -> get_type() == type) {
18762 return qualified_type;
18763 }
18764 }
18765
18766 SgJavaQualifiedType *qualified_type = new SgJavaQualifiedType(class_declaration);
18767 qualified_type -> set_parent_type(parent_type);
18768 qualified_type -> set_type(type);
18769
18770 attribute -> addNode(qualified_type);
18771
18772 return qualified_type;
18773}
18774
18775
18781 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) Rose::Frontend::Java::ObjectClassType -> getAttribute("unbound");
18782 if (! attribute) {
18783 SgClassDeclaration *class_declaration = isSgClassDeclaration(Rose::Frontend::Java::ObjectClassType -> get_declaration());
18784 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration());
18785 attribute = new AstSgNodeAttribute(wildcard);
18786 Rose::Frontend::Java::ObjectClassType -> setAttribute("unbound", attribute);
18787 }
18788
18789 return isSgJavaWildcardType(attribute -> getNode());
18790}
18791
18792
18797 ROSE_ASSERT(type);
18798 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) type -> getAttribute("extends");
18799 if (! attribute) {
18800 SgArrayType *array_type = isSgArrayType(type);
18801 SgNamedType *named_type = isSgNamedType(type);
18802 ROSE_ASSERT(array_type || named_type);
18803 SgClassDeclaration *class_declaration = isSgClassDeclaration((array_type ? (SgNamedType *) Rose::Frontend::Java::ObjectClassType : named_type) -> get_declaration());
18804 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration(), type);
18805
18806 wildcard -> set_has_extends(true);
18807
18808 attribute = new AstSgNodeAttribute(wildcard);
18809 type -> setAttribute("extends", attribute);
18810 }
18811
18812 return isSgJavaWildcardType(attribute -> getNode());
18813}
18814
18815
18820 ROSE_ASSERT(type);
18821 AstSgNodeAttribute *attribute = (AstSgNodeAttribute *) type -> getAttribute("super");
18822 if (! attribute) {
18823 SgArrayType *array_type = isSgArrayType(type);
18824 SgNamedType *named_type = isSgNamedType(type);
18825 ROSE_ASSERT(array_type || named_type);
18826 SgClassDeclaration *class_declaration = isSgClassDeclaration((array_type ? (SgNamedType *) Rose::Frontend::Java::ObjectClassType : named_type) -> get_declaration());
18827 SgJavaWildcardType *wildcard = new SgJavaWildcardType(class_declaration -> get_definingDeclaration(), type);
18828
18829 wildcard -> set_has_super(true);
18830
18831 attribute = new AstSgNodeAttribute(wildcard);
18832 type -> setAttribute("super", attribute);
18833 }
18834
18835 return isSgJavaWildcardType(attribute -> getNode());
18836}
18837
18838
18839//-----------------------------------------------------------------------------
18840#endif // ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
18841//-----------------------------------------------------------------------------
18842
18843
18844namespace Rose {
18845 namespace Builder {
18846 namespace Templates {
18847
18848SgTemplateArgument * buildTemplateArgument(SgType * t) {
18849 if (t == nullptr) return nullptr;
18850 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::type_argument, false, t, nullptr, nullptr);
18851 return r;
18852}
18853
18854SgTemplateArgument * buildTemplateArgument(SgExpression * e) {
18855 if (e == nullptr) return nullptr;
18856 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
18857 e->set_parent(r);
18858 return r;
18859}
18860
18861SgTemplateArgument * buildTemplateArgument(int v) {
18863 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
18864 e->set_parent(r);
18865 return r;
18866}
18867
18868SgTemplateArgument * buildTemplateArgument(bool v) {
18870 SgTemplateArgument * r = new SgTemplateArgument(SgTemplateArgument::nontype_argument, false, nullptr, e, nullptr);
18871 e->set_parent(r);
18872 return r;
18873}
18874
18875std::string strTemplateArgument(int v) {
18876 std::ostringstream oss;
18877 oss << v;
18878 return oss.str();
18879}
18880
18881std::string strTemplateArgument(bool v) {
18882 std::ostringstream oss;
18883 if (v) oss << "true";
18884 else oss << "false";
18885 return oss.str();
18886}
18887
18888std::string strTemplateArgument(SgNamedType * nt) {
18889 std::ostringstream oss;
18890 oss << nt->get_qualified_name().getString();
18891 return oss.str();
18892}
18893
18894std::string strTemplateArgument(SgType * t) {
18895 std::ostringstream oss;
18896 oss << t->unparseToString();
18897 return oss.str();
18898}
18899
18900std::string strTemplateArgument(SgExpression * e) {
18901 std::ostringstream oss;
18902 oss << e->unparseToString();
18903 return oss.str();
18904}
18905
18906#define DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps 0
18907
18908SgExpression * instantiateNonrealRefExps(
18909 SgExpression * expr,
18910 std::vector<std::vector<SgTemplateParameter *>> & tpl_params,
18911 std::vector<std::vector<SgTemplateArgument *>> & tpl_args
18912) {
18913#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18914 std::cout << "Rose::Builder::Templates::instantiateNonrealRefExps" << std::endl;
18915 std::cout << " expr = " << std::hex << expr << " : " << ( expr ? expr->class_name() : "" ) << std::endl;
18916 std::cout << " = " << ( expr ? expr->unparseToString() : "" ) << std::endl;
18917#endif
18918 if (!expr) {
18919 return nullptr;
18920 } else if (isSgNonrealRefExp(expr)) {
18921#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18922 std::cerr << "Error: In instantiateNonrealRefExps: case of a SgNonrealRefExp!!!" << std::endl;
18923#endif
18924 return nullptr;
18925 } else if (isSgVarRefExp(expr)) {
18926 SgVarRefExp * vref = (SgVarRefExp*)expr;
18927 SgInitializedName * iname = vref->get_symbol()->get_declaration();
18928 ROSE_ASSERT(iname);
18929#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18930 std::cout << " iname = " << std::hex << iname << " : " << ( iname ? iname->class_name() : "" ) << std::endl;
18931 std::cout << " iname->get_name() = " << iname->get_name() << std::endl;
18932 std::cout << " iname->get_initializer() = " << std::hex << iname->get_initializer() << " : " << ( iname->get_initializer() ? iname->get_initializer()->class_name() : "" ) << std::endl;
18933 std::cout << " iname->get_parent() = " << std::hex << iname->get_parent() << " : " << ( iname->get_parent() ? iname->get_parent()->class_name() : "" ) << std::endl;
18934#endif
18935
18936 unsigned depth = 0;
18937 unsigned pos = 0;
18938 for (auto tpl_params_: tpl_params) {
18939 pos = 0;
18940 for (auto tpl_param: tpl_params_) {
18941 if (tpl_param->get_initializedName()) {
18942#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18943 std::cout << " tpl_param->get_initializedName() = " << std::hex << tpl_param->get_initializedName() << std::endl;
18944 std::cout << " tpl_param->get_initializedName()->get_name() = " << tpl_param->get_initializedName()->get_name() << std::endl;
18945#endif
18946 if (tpl_param->get_initializedName()->get_name() == iname->get_name()) {
18947 iname = tpl_param->get_initializedName();
18948 break;
18949 }
18950 }
18951 pos++;
18952 }
18953 depth++;
18954 }
18955
18956 if (depth < tpl_args.size() && pos < tpl_args[depth].size()) {
18957 SgExpression * res = tpl_args[depth][pos]->get_expression();
18958 ROSE_ASSERT(res);
18959 return res;
18960 } else if (depth < tpl_params.size() && pos < tpl_params[depth].size()) {
18961 SgExpression * dft = tpl_params[depth][pos]->get_defaultExpressionParameter();
18962 ROSE_ASSERT(dft);
18963 dft = instantiateNonrealRefExps(dft, tpl_params, tpl_args);
18964 ROSE_ASSERT(dft);
18965 return dft;
18966 }
18967#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18968 std::cerr << "Error: In instantiateNonrealRefExps: this should not be reached!!!" << std::endl;
18969#endif
18970 return vref;
18971 } else if (isSgValueExp(expr)) {
18972 return expr;
18973 } else if (isSgConditionalExp(expr)) {
18974 SgConditionalExp * cond = (SgConditionalExp*)expr;
18975 cond->set_conditional_exp(instantiateNonrealRefExps(cond->get_conditional_exp(), tpl_params, tpl_args));
18976 cond->set_true_exp(instantiateNonrealRefExps(cond->get_true_exp(), tpl_params, tpl_args));
18977 cond->set_false_exp(instantiateNonrealRefExps(cond->get_false_exp(), tpl_params, tpl_args));
18978 return cond;
18979 } else if (isSgSizeOfOp(expr)) {
18980 SgSizeOfOp * szo = (SgSizeOfOp*)expr;
18981#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18982 std::cout << " szo->get_operand_expr() = " << std::hex << szo->get_operand_expr() << " : " << ( szo->get_operand_expr() ? szo->get_operand_expr()->class_name() : "" ) << std::endl;
18983 std::cout << " szo->get_operand_type() = " << std::hex << szo->get_operand_type() << " : " << ( szo->get_operand_type() ? szo->get_operand_type()->class_name() : "" ) << std::endl;
18984#endif
18985 SgExpression * eres = instantiateNonrealRefExps(szo->get_operand_expr(), tpl_params, tpl_args);
18986 ROSE_ASSERT(szo->get_operand_expr() == nullptr || eres != nullptr);
18987 szo->set_operand_expr(eres);
18988
18989 SgType * tres = instantiateNonrealTypes(szo->get_operand_type(), tpl_params, tpl_args);
18990 ROSE_ASSERT(szo->get_operand_type() == nullptr || tres != nullptr);
18991 szo->set_operand_type(tres);
18992
18993#if DEBUG_Rose_Builder_Templates_instantiateNonrealRefExps
18994 std::cout << " szo->get_operand_expr() = " << std::hex << szo->get_operand_expr() << " : " << ( szo->get_operand_expr() ? szo->get_operand_expr()->class_name() : "" ) << std::endl;
18995 std::cout << " szo->get_operand_type() = " << std::hex << szo->get_operand_type() << " : " << ( szo->get_operand_type() ? szo->get_operand_type()->class_name() : "" ) << std::endl;
18996#endif
18997 return szo;
18998 } else if (isSgCastExp(expr)) {
18999 SgCastExp * cast = (SgCastExp*)expr;
19000 auto operand = instantiateNonrealRefExps(cast->get_operand_i(), tpl_params, tpl_args);
19001 if (operand == nullptr) return nullptr;
19002 auto type = instantiateNonrealTypes(cast->get_type(), tpl_params, tpl_args);
19003 if (type == nullptr) return operand;
19004 cast->set_operand_i(operand);
19005 cast->set_type(type);
19006 return cast;
19007 } else if (isSgUnaryOp(expr)) {
19008 SgUnaryOp * uop = (SgUnaryOp*)expr;
19009 uop->set_operand_i(instantiateNonrealRefExps(uop->get_operand_i(), tpl_params, tpl_args));
19010 return uop;
19011 } else if (isSgBinaryOp(expr)) {
19012 SgBinaryOp * bop = (SgBinaryOp*)expr;
19013 bop->set_lhs_operand_i(instantiateNonrealRefExps(bop->get_lhs_operand_i(), tpl_params, tpl_args));
19014 bop->set_rhs_operand_i(instantiateNonrealRefExps(bop->get_rhs_operand_i(), tpl_params, tpl_args));
19015 return bop;
19016 } else {
19017 std::cerr << "!!! expr = " << std::hex << expr << " : " << ( expr ? expr->class_name() : "" ) << std::endl;
19018 ROSE_ABORT();
19019 }
19020}
19021
19022SgExpression * instantiateNonrealRefExps(
19023 SgExpression * expr,
19024 std::vector<SgTemplateParameter *> & tpl_params,
19025 std::vector<SgTemplateArgument *> & tpl_args
19026) {
19027 std::vector<std::vector<SgTemplateParameter *>> tpl_params_{tpl_params};
19028 std::vector<std::vector<SgTemplateArgument *>> tpl_args_{tpl_args};
19029 return instantiateNonrealRefExps(expr, tpl_params_, tpl_args_);
19030}
19031
19032#define DEBUG_Rose_Builder_Templates_instantiateNonrealTypes 0
19033
19034SgType * instantiateNonrealTypes(
19035 SgType * type,
19036 std::vector<std::vector<SgTemplateParameter *>> & tpl_params,
19037 std::vector<std::vector<SgTemplateArgument *>> & tpl_args
19038) {
19039#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19040 std::cout << "Rose::Builder::Templates::instantiateNonrealTypes" << std::endl;
19041 std::cout << " type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
19042 std::cout << " = " << ( type ? type->unparseToString() : "" ) << std::endl;
19043#endif
19044 if (!type) {
19045 return nullptr;
19046 } else if (isSgNonrealType(type)) {
19047 SgNonrealType * nrtype = (SgNonrealType*)type;
19048 SgNonrealDecl * nrdecl = isSgNonrealDecl(nrtype->get_declaration());
19049 ROSE_ASSERT(nrdecl != nullptr);
19050#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19051 std::cout << " nrdecl = " << std::hex << nrdecl << " : " << nrdecl->class_name() << std::endl;
19052 std::cout << " ->get_qualified_name() = " << nrdecl->get_qualified_name().getString() << std::endl;
19053// std::cout << " ->unparseToString() = " << nrdecl->unparseToString() << std::endl;
19054 std::cout << " ->get_tpl_args() = " << std::dec << nrdecl->get_tpl_args().size() << std::endl;
19055 std::cout << " ->get_tpl_params() = " << std::dec << nrdecl->get_tpl_params().size() << std::endl;
19056 std::cout << " ->get_is_class_member() = " << ( nrdecl->get_is_class_member() ? "true" : "false" ) << std::endl;
19057 std::cout << " ->get_is_template_param() = " << ( nrdecl->get_is_template_param() ? "true" : "false" ) << std::endl;
19058 std::cout << " ->get_is_template_template_param() = " << ( nrdecl->get_is_template_template_param() ? "true" : "false" ) << std::endl;
19059 std::cout << " ->get_is_nonreal_template() = " << ( nrdecl->get_is_nonreal_template() ? "true" : "false" ) << std::endl;
19060 std::cout << " ->get_is_nonreal_function() = " << ( nrdecl->get_is_nonreal_function() ? "true" : "false" ) << std::endl;
19061#endif
19062 SgDeclarationStatement * tpldecl = nrdecl->get_templateDeclaration();
19063 if (tpldecl != nullptr) {
19064#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19065 std::cout << " tpldecl = " << std::hex << tpldecl << " : " << tpldecl->class_name() << std::endl;
19066#endif
19067
19068 SgTemplateClassDeclaration * xtpldecl = isSgTemplateClassDeclaration(tpldecl);
19069 if (xtpldecl != nullptr) {
19070#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19071 std::cout << " xtpldecl->get_name() = " << xtpldecl->get_name() << std::endl;
19072#endif
19073 std::vector<SgTemplateArgument *> inst_tpl_args;
19074 for (SgTemplateArgument * tplarg: nrdecl->get_tpl_args()) {
19075#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19076 std::cout << " tplarg = " << std::hex << tplarg << " : " << ( tplarg ? tplarg->class_name() : "" ) << std::endl;
19077 std::cout << " ->get_argumentType() = " << tplarg->get_argumentType() << std::endl;
19078#endif
19079 switch (tplarg->get_argumentType()) {
19081#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19082 std::cout << " tplarg->get_type() = " << std::hex << tplarg->get_type() << " : " << ( tplarg->get_type() ? tplarg->get_type()->class_name() : "" ) << std::endl;
19083#endif
19084 auto inst_tplarg = instantiateNonrealTypes(tplarg->get_type(), tpl_params, tpl_args);
19085 if (inst_tplarg)
19086 inst_tpl_args.push_back(buildTemplateArgument(inst_tplarg));
19087 break;
19088 }
19090#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19091 std::cout << " tplarg->get_expression() = " << std::hex << tplarg->get_expression() << " : " << ( tplarg->get_expression() ? tplarg->get_expression()->class_name() : "" ) << std::endl;
19092 std::cout << " ->unparseToString() = " << tplarg->get_expression()->unparseToString() << std::endl;
19093#endif
19094 auto inst_tplarg = instantiateNonrealRefExps(SageInterface::copyExpression(tplarg->get_expression()), tpl_params, tpl_args);
19095#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19096 std::cout << " inst_tplarg = " << std::hex << inst_tplarg << " : " << ( inst_tplarg ? inst_tplarg->class_name() : "" ) << std::endl;
19097 std::cout << " inst_tplarg->unparseToString() = " << ( inst_tplarg ? inst_tplarg->unparseToString() : "" ) << std::endl;
19098#endif
19099 if (inst_tplarg)
19100 inst_tpl_args.push_back(buildTemplateArgument(inst_tplarg));
19101 break;
19102 }
19104#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19105 std::cout << " tplarg->get_templateDeclaration() = " << std::hex << tplarg->get_templateDeclaration() << " : " << ( tplarg->get_templateDeclaration() ? tplarg->get_templateDeclaration()->class_name() : "" ) << std::endl;
19106#endif
19107 ROSE_ABORT(); // TODO
19108 }
19110#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19111 std::cout << " start_of_pack_expansion_argument" << std::endl;
19112#endif
19113 break; // NOP
19114 }
19115 default: ROSE_ABORT();
19116 }
19117 }
19118 SgTemplateInstantiationDecl * inst_decl = isSgTemplateInstantiationDecl(SageBuilder::buildClassDeclaration_nfi(
19119 xtpldecl->get_name(), SgClassDeclaration::e_struct, xtpldecl->get_scope(), nullptr, true, &inst_tpl_args
19120 ));
19121 ROSE_ASSERT(inst_decl);
19122#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19123 std::cout << " inst_decl = " << std::hex << inst_decl << " : " << inst_decl->class_name() << std::endl;
19124 std::cout << " inst_decl->get_firstNondefiningDeclaration() = " << std::hex << inst_decl->get_firstNondefiningDeclaration() << std::endl;
19125 std::cout << " inst_decl->get_definingDeclaration() = " << std::hex << inst_decl->get_definingDeclaration() << std::endl;
19126#endif
19127 ROSE_ASSERT(inst_decl->get_definingDeclaration());
19128 ROSE_ASSERT(inst_decl->get_definingDeclaration() == inst_decl);
19129 inst_decl->set_templateDeclaration(xtpldecl);
19130 ((SgTemplateInstantiationDecl *)(inst_decl->get_firstNondefiningDeclaration()))->set_templateDeclaration(xtpldecl);
19131
19132 for (auto inst_tpl_arg: inst_tpl_args) {
19133 inst_tpl_arg->set_parent(inst_decl);
19134 }
19135
19136 xtpldecl->get_scope()->append_statement(inst_decl);
19137 return inst_decl->get_type();
19138 } else {
19139 ROSE_ABORT(); // TODO probably typedef
19140 }
19141 } else if (nrdecl->get_is_template_param()) {
19142 auto depth = nrdecl->get_template_parameter_depth();
19143 auto position = nrdecl->get_template_parameter_position();
19144#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19145 std::cout << " ->get_template_parameter_position() = " << std::dec << position << std::endl;
19146 std::cout << " ->get_template_parameter_depth() = " << std::dec << depth << std::endl;
19147#endif
19148 ROSE_ASSERT(depth > 0);
19149 ROSE_ASSERT(position > 0);
19150 if (std::size_t(depth) <= tpl_args.size() && std::size_t(position) <= tpl_args[depth-1].size()) {
19151 SgType * res = tpl_args[depth-1][position-1]->get_type();
19152#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19153 std::cout << " tpl_args[" << std::dec << depth-1 << "][" << std::dec << position-1 << "]->get_type() = " << std::dec << res << std::endl;
19154#endif
19155 return res;
19156 } else if (std::size_t(depth) <= tpl_params.size() && std::size_t(position) <= tpl_params[depth-1].size()) {
19157 SgType * dft_tpl_arg = tpl_params[depth-1][position-1]->get_defaultTypeParameter();
19158#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19159 std::cout << " tpl_params[" << std::dec << depth-1 << "][" << std::dec << position-1 << "]->get_type() = " << std::dec << dft_tpl_arg << std::endl;
19160#endif
19161 dft_tpl_arg = instantiateNonrealTypes(dft_tpl_arg, tpl_params, tpl_args);
19162#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19163 std::cout << " dft_tpl_arg = " << std::dec << dft_tpl_arg << std::endl;
19164#endif
19165 return dft_tpl_arg;
19166 } else {
19167 return nullptr;
19168 }
19169 } else if (nrdecl->get_is_class_member()) {
19170#if DEBUG_Rose_Builder_Templates_instantiateNonrealTypes
19171 std::cout << " Case of a non-real class member will return INT." << std::endl;
19172#endif
19173 // TODO case such as "template <unsigned depth=0> static constexpr typename range_at_depth_t<depth>::Base ub;"
19174 // -> retrieve parent type
19175 // -> instantiate parent type
19176 // -> lookup member(s) in original parent type
19177 // -> instantiate (matching) member inside instantiated parent type
19178
19180 } else {
19181 ROSE_ABORT();
19182 }
19183 } else if (isSgTypeVoid(type) || isSgTypeUnsignedLong(type) || isSgTypeInt(type) || isSgTypeLong(type) || isSgTypeUnsignedInt(type) || isSgTypedefType(type) || isSgClassType(type)) {
19184 return type;
19185 } else if (isSgModifierType(type)) {
19186 SgModifierType * mtype = (SgModifierType *)type;
19187 SgType * btype = mtype->get_base_type();
19188 ROSE_ASSERT(btype != nullptr);
19190 ROSE_ASSERT(rtype != nullptr);
19191 rtype->get_typeModifier() = mtype->get_typeModifier();
19192 return rtype;
19193 } else {
19194 std::cerr << "!!! type = " << std::hex << type << " : " << ( type ? type->class_name() : "" ) << std::endl;
19195 ROSE_ABORT(); // TODO maybe pointer/reference
19196 }
19197 return nullptr;
19198}
19199
19200SgType * instantiateNonrealTypes(
19201 SgType * type,
19202 std::vector<SgTemplateParameter *> & tpl_params,
19203 std::vector<SgTemplateArgument *> & tpl_args
19204) {
19205 std::vector<std::vector<SgTemplateParameter *>> tpl_params_{tpl_params};
19206 std::vector<std::vector<SgTemplateArgument *>> tpl_args_{tpl_args};
19207 return instantiateNonrealTypes(type, tpl_params_, tpl_args_);
19208}
19209
19210} } }
to specify a construct using a specifier Can be used alone or with parent handles when relative speci...
Users should provide a concrete node implementation especially a constructor/builder to avoid duplica...
Attribute containing a regex expression as a string.
Attribute storing an SgNode.
Class for traversing the AST.
virtual void visit(SgNode *astNode)=0
this method is called at every traversed node.
For preprocessing information including source comments, include , if, define, etc.
RelativePositionType
MK: Enum type to store if the directive goes before or after the corresponding line of source code.
AST iterator.
Definition RoseAst.h:54
Interface for iterating over an AST.
Definition RoseAst.h:26
iterator begin()
Iterator positioned at root of subtree.
iterator end()
Iterator positioned at the end of the traversal.
Collection of streams.
Definition Message.h:1606
std::string comment() const
Property: Comment associated with facility.
This class represents the concept of a C Assembler statement.
This class represents the rhs of a variable declaration which includes an optional assignment (e....
This class represents the concept of a block (not a basic block from control flow analysis).
This class represents the notion of a binary operator. It is derived from a SgExpression because oper...
void set_rhs_operand_i(SgExpression *rhs_operand_i)
This function allows the p_rhs_operand_i pointer to be set (used internally).
SgExpression * get_lhs_operand() const
returns SgExpression pointer to the lhs operand associated with this binary operator.
SgExpression * get_rhs_operand_i() const
returns SgExpression pointer to the operand associated with this binary operator.
SgExpression * get_lhs_operand_i() const
returns SgExpression pointer to the operand associated with this binary operator.
void set_lhs_operand_i(SgExpression *lhs_operand_i)
This function allows the p_lhs_operand_i pointer to be set (used internally).
SgExpression * get_rhs_operand() const
returns SgExpression pointer to the rhs operand associated with this binary operator.
This class represents a boolean value (expression value).
This class represents the notion of a break statement (typically used in a switch statment).
This class represents the concept of a C and C++ case option (used within a switch statement).
This class represents a cast of one type to another.
cast_type_enum
Classification of Casts.
SgType * get_type() const override
unparsing support for pragmas
This class represents the concept of a catch within a try-catch construct used in C++ exception handl...
This class represents the concept of a C++ sequence of catch statements.
This class represents the concept of a class declaration statement. It includes the concept of an ins...
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
virtual std::string class_name() const override
returns a string representing the class name
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
SgScopeStatement * get_scope() const override
Returns scope of current statement.
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the concept of a class definition in C++.
SgClassDeclaration * get_declaration() const
returns the class declaration associated with this class decinition.
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a C++ expression built from a class name.
This class represents the concept of a class name within the compiler.
virtual std::string class_name() const override
returns a string representing the class name
SgType * get_type() const override
This function returns the type associated with the named entity.
virtual std::string class_name() const override
returns a string representing the class name
virtual SgName get_mangled(void) const override
Mangled name support for unparser support.
SgName get_name() const override
Support for some classes which have pure virtual function in base classes.
static SgClassType * createType(SgDeclarationStatement *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgClassType (types whose constructors take par...
This class represents the concept of a C trinary conditional expression (e.g. "test ?...
SgExpression * get_true_exp() const
Access function for p_true_exp.
void set_false_exp(SgExpression *false_exp)
Access function for p_false_exp.
SgExpression * get_conditional_exp() const
Access function for p_conditional_exp.
SgExpression * get_false_exp() const
Access function for p_false_exp.
void set_true_exp(SgExpression *true_exp)
Access function for p_true_exp.
void set_conditional_exp(SgExpression *conditional_exp)
Access function for p_conditional_exp.
cv_modifier_enum
Const Volatile Modifier.
This class represents the call of a class constructor to initialize a variable. For example "Foo foo;...
This class represents the concept of a C or C++ continue statement.
This class represents the concept of a contructor initializer list (used in constructor (member funct...
static SgDeclType * createType(SgExpression *expr=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgDeclType (types whose constructors take para...
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a declaration statement.
SgSymbol * search_for_symbol_from_symbol_table() const
User interface for retrieving the associated symbol from the declaration.
void set_definingDeclaration(SgDeclarationStatement *definingDeclaration)
This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see tha...
void set_firstNondefiningDeclaration(SgDeclarationStatement *firstNondefiningDeclaration)
This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member ...
SgDeclarationStatement * get_definingDeclaration() const
This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see tha...
virtual VariantT variantT() const override
returns new style SageIII enum values
virtual std::string class_name() const override
returns a string representing the class name
SgDeclarationStatement * get_firstNondefiningDeclaration() const
This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member ...
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
void setForward()
Marks a declaration as a forward declaration.
This class represents the concept of a C or C++ default case within a switch statement.
This class represents the concept of a C++ call to the delete operator.
This class represents the concept of a do-while statement.
SgStatement * get_condition() const
Access function for p_condition.
SgStatement * get_body() const
Access function for p_body.
void set_condition(SgStatement *condition)
Access function for p_condition.
void set_body(SgStatement *body)
Access function for p_body.
This class represents the notion of an value (expression value).
This class represents the concept of an enum declaration.
void set_type(SgEnumType *type)
Access function for p_type.
SgScopeStatement * get_scope() const override
Access function for p_scope.
SgName get_name() const
Access function for p_name.
void set_scope(SgScopeStatement *scope) override
Access function for p_scope.
SgEnumType * get_type() const
Access function for p_type.
SgType * get_type() const override
This function returns the type associated with the named entity.
This class represents the concept of the dynamic execution of a string, file, or code object....
This class represents the concept of a C and C++ expression list.
This class represents the concept of a C or C++ statement which contains a expression.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes,...
virtual std::string class_name() const override
returns a string representing the class name
void set_need_paren(bool need_paren)
This function allows the p_need_paren flag to be set (used internally).
virtual SgType * get_type() const
unparsing support for pragmas
bool hasExplicitType()
Some expressions store internal SgType pointers explicitly while others compute them from other expre...
virtual Sg_File_Info * get_file_info(void) const override
Interface function to implement original SAGE interface to SgFile_Info objects.
void set_lvalue(bool lvalue)
This function allows the p_lvalue flag to be set (used internally).
void set_explicitly_stored_type(SgType *type)
Some expressions store internal SgType pointers explicitly, this allows these IR nodes to be reset wi...
This class represents a source file for a project (which may contian many source files and or directo...
Sg_File_Info * get_startOfConstruct() const override
New function interface for Sg_File_Info data stores starting location of contruct (typically the open...
void secondaryPassOverSourceFile()
Fixups to be run when the whole project has been created (this attaches preprocessing information).
@ e_Fortran_language
std::string getFileName() const
associated filename
virtual std::string class_name() const override
returns a string representing the class name
Sg_File_Info * get_file_info() const override
Access function calling get_startOfConstruct(), provided to support older interface.
This class represents the notion of an value (expression value).
This class represents the variable declaration or variable initialization withn a for loop.
const SgStatementPtrList & get_init_stmt() const
Returns const reference to a SgStatementPtrList (typedef to a STL list).
This class represents the concept of a for loop.
SgForInitStatement * get_for_init_stmt() const
Access function for p_for_init_stmt.
void set_loop_body(SgStatement *loop_body)
Access function for p_loop_body.
SgStatement * get_loop_body() const
Access function for p_loop_body.
void set_for_init_stmt(SgForInitStatement *for_init_stmt)
Access function for p_for_init_stmt.
This class represents the concept of a C++ function call (which is an expression).
This class represents the concept of a function declaration statement.
SgScopeStatement * get_scope() const override
Returns scope of current statement.
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
void set_body(SgBasicBlock *body)
Access function for p_body.
This class represents the concept of a declaration list.
const SgInitializedNamePtrList & get_args() const
Access function for p_args.
const SgTypePtrList & get_arguments() const
Get a const list of input types (types of the parameters list) to this function type (from a cost fun...
This class represents the function being called and must be assembled in the SgFunctionCall with the ...
SgType * get_type() const override
Get the type associated with this expression.
virtual std::string class_name() const override
returns a string representing the class name
SgName get_name() const override
Access function for getting name from declarations or types internally.
This class represents the function type table (stores all function types so that they can be shared i...
This class represents a type for all functions.
virtual std::string class_name() const override
returns a string representing the class name
virtual SgName get_mangled(void) const override
Mangled name support for unparser support.
This class represents the concept of a namespace definition.
virtual std::string class_name() const override
returns a string representing the class name
const SgDeclarationStatementPtrList & get_declarations() const
Returns a const list to the global scope declarations.
This class represents the concept of a C or C++ goto statement.
This class represents the concept of an "if" construct.
void set_use_then_keyword(bool use_then_keyword)
Fortran specific function to indicate if the Fortran "if" statement uses the "then" construct (C/C++ ...
void set_has_end_statement(bool has_end_statement)
Fortran specific function to indicate if the Fortran "if" statement has an "end" construct (C/C++ use...
This class represents the notion of a declared variable.
SgName get_qualified_name() const
Returns the name with appropriate qualified names representing nested scopes.
SgSymbol * get_symbol_from_symbol_table() const
Get the associated SgSymbol from the symbol table located in the scope, without considering possible ...
virtual std::string class_name() const override
returns a string representing the class name
SgSymbol * search_for_symbol_from_symbol_table() const
User interface for retrieving the associated symbol. It searches through the possible chain of prev_d...
This class represents the notion of an initializer for a variable declaration or expression in a func...
virtual std::string class_name() const override
returns a string representing the class name
static SgJavaParameterType * createType(SgClassDeclaration *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgJavaParameterType (types whose constructors ...
static SgJovialBitType * createType(SgExpression *size=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgJovialBitType (types whose constructors take...
static SgJovialTableType * createType(SgClassDeclaration *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgJovialTableType (types whose constructors ta...
This class represents the concept of a C or C++ label statement.
This class represents a lambda expression.
This class represents a list display.
This class represents the notion of an expression or statement which has a position within the source...
virtual std::string class_name() const override
returns a string representing the class name
Sg_File_Info * get_endOfConstruct() const override
New function interface for Sg_File_Info data stores ending location of contruct (typically the closin...
void set_endOfConstruct(Sg_File_Info *endOfConstruct)
This function sets the current source location position of the end of the current construct.
Sg_File_Info * get_startOfConstruct() const override
New function interface for Sg_File_Info data stores starting location of contruct (typically the open...
virtual Sg_File_Info * get_file_info() const override
Interface function to implement original SAGE interface to SgFile_Info objects.
This class represents the notion of an value (expression value).
This class represents the concept of a member function declaration statement.
SgCtorInitializerList * get_CtorInitializerList() const
Access function for p_CtorInitializerList.
void set_associatedClassDeclaration(SgDeclarationStatement *associatedClassDeclaration)
This is an access function for the p_associatedClassDeclaration data member.
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
This class represents the member function being called and must be assembled in the SgFunctionCall wi...
SgType * get_type() const override
Get the type associated with this expression.
SgName get_name() const override
Access function for getting name from declarations or types internally.
SgType * get_type() const override
This function returns the type associated with the named entity.
virtual std::string class_name() const override
returns a string representing the class name
virtual SgName get_mangled(void) const override
Mangled name support for unparser support.
static SgMemberFunctionType * createType(SgPartialFunctionType *type=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgMemberFunctionType (types whose constructors...
This class represents the numeric negation of a value. Not to be confused with SgSubtractOp.
SgTypeModifier & get_typeModifier()
Access function for modifier.
virtual std::string class_name() const override
returns a string representing the class name
This class represents strings within the IR nodes.
virtual std::string class_name() const override
returns a string representing the class name
SgName get_qualified_name() const
Used for the SgNamedType object (base class for the SgClassType, SgTypedefType and the SgEnumType obj...
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the concept of a C++ namespace alias declaration statement.
This class represents the concept of a C++ namespace declaration.
SgName get_name() const
Access function for p_name.
SgNamespaceDefinitionStatement * get_definition() const
Returns pointer to SgNamespaceDefinitionStatement.
This class represents the concept of a namespace definition.
This class represents the concept of a namespace name within the compiler.
SgNamespaceDeclarationStatement * get_declaration() const
Access function for getting the declaration of the original namespace.
This class represents the notion of an n-ary boolean operation. This node is intended for use with Py...
This class represents the notion of an n-ary comparison operation. This node is intended for use with...
This class represents the concept of a C++ call to the new operator.
This class represents the base class for all IR nodes within Sage III.
static void clearGlobalMangledNameMap()
Support to clear the performance optimizing global mangled name map.
virtual Sg_File_Info * get_endOfConstruct(void) const
New function interface for Sg_File_Info data stores ending location of contruct (typically the closin...
SgNode * get_parent() const
Access function for parent node.
void set_isModified(bool isModified)
All nodes in the AST contain a isModified flag used to track changes to the AST.
virtual VariantT variantT() const
returns new style SageIII enum values
void set_parent(SgNode *parent)
All nodes in the AST contain a reference to a parent node.
virtual std::string unparseToString(SgUnparse_Info *info) const
This function unparses the AST node (excluding comments and unnecessary white space)
virtual std::string class_name() const
returns a string representing the class name
static std::map< SgNode *, std::string > & get_globalMangledNameMap()
Access function for performance optimizing global mangled name map.
static SgFunctionTypeTable * get_globalFunctionTypeTable()
Access function for symbol table specific to function types.
virtual Sg_File_Info * get_file_info(void) const
File information containing filename, line number, column number, and if the SgNode is a part of a ne...
bool get_isModified() const
Acess function for isModified flag.
virtual std::string class_name() const override
returns a string representing the class name
virtual std::string class_name() const override
returns a string representing the class name
virtual std::string class_name() const override
returns a string representing the class name
static SgPointerType * createType(SgType *type=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgPointerType (types whose constructors take p...
This class represents the concept of a C Assembler statement (untested).
subprogram_kind_enum
Classification for different types of Fortran subprograms.
This class represents a source project, with a list of SgFile objects and global information about th...
void set_originalCommandLineArgumentList(SgStringList originalCommandLineArgumentList)
Sets the list of strings representing the original command-line.
SgStringList get_originalCommandLineArgumentList() const
Returns a list of strings representing the original command-line.
void set_file(SgFile &)
Access function for putting a new SgFile object into the list stored internally This function is depr...
This class represents the concept of a 'global' stmt in Python.
virtual void append_name(SgInitializedName *element)
Append a name to the list of identifiers imported into the inner scope.
static SgReferenceType * createType(SgType *type=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgReferenceType (types whose constructors take...
This class represents the concept of a C Assembler statement (untested).
static SgRvalueReferenceType * createType(SgType *type=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgRvalueReferenceType (types whose constructor...
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
bool isNamedScope()
Some scopes have associated names for purposed of name qualification. This returns true if the scope ...
SgSymbolTable * get_symbol_table() const
Returns a pointer to the locally strored SgSymbolTable.
void append_statement(SgStatement *stmt)
Higher level function to handle statements and declarations is scopes.
virtual std::string class_name() const override
returns a string representing the class name
bool containsOnlyDeclarations() const
This function is used to indicate if either the getDeclarationList() or getStatementList() can be cal...
void insert_symbol(const SgName &n, SgSymbol *s)
Puts a SgSymbol object into the local symbol table.
This class represents the "sizeof()" operator (applied to any type).
virtual std::string class_name() const override
returns a string representing the class name
This class represents the GNU extension "statement expression" (thus is non-standard C and C++).
This class represents the notion of a statement.
virtual std::string class_name() const override
returns a string representing the class name
virtual void set_scope(SgScopeStatement *newScope)
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
virtual bool hasExplicitScope() const
Support for where the scope is explicitly required.
virtual SgScopeStatement * get_scope(void) const
Returns scope of current statement.
This class is intended to be a wrapper around SgStatements, allowing them to exist in scopes that onl...
void setExtern()
Set storage.
bool isExtern() const
Storage modifier is extern (not the same as extern "C").
storage_modifier_enum
Storage Modifiers (only one value can be specified)
This class represents the conversion of an arbitrary expression to a string. This node is intended fo...
This class represents the concept of a switch.
void print(std::string label, VariantT nodeType=V_SgSymbol)
Outputs symbol table information (useful for debugging)
int size() const
Computes the number of symbols in the symbol table (forced to count them, I think,...
This class represents the concept of a name within the compiler.
This class represents template argument within the use of a template to build an instantiation.
SgExpression * get_expression() const
This function returns argumentExpression.
SgType * get_type() const
This function returns argumentType.
SgTemplateArgument::template_argument_enum get_argumentType() const
This function returns argumentType.
virtual std::string class_name() const override
returns a string representing the class name
SgType * get_type() const override
This function returns the type associated with the named entity.
This class represents the concept of a template declaration.
This class represents the concept of an instantiated class template.
virtual std::string class_name() const override
returns a string representing the class name
void set_templateDeclaration(SgTemplateClassDeclaration *templateDeclaration)
Access function for p_templateDeclaration.
SgName get_templateName() const
Returns name of class template, the name excludes template arguments.
void set_templateName(SgName templateName)
sets name of instantiated class template, name excludes template arguments.
const SgTemplateArgumentPtrList & get_templateArguments() const
Returns pointer to STL list of pointers to SgTemplateArgument objects.
SgTemplateClassDeclaration * get_templateDeclaration() const
Returns pointer to SgTemplateDeclaration from which instantiation is generated.
This class represents the concept of a class definition in C++.
This class represents the concept of an instantiation of function template.
const SgTemplateArgumentPtrList & get_templateArguments() const
Returns pointer to STL list of pointers to SgTemplateArgument objects.
SgName get_templateName() const
Returns name of instantiated function template, name includes template arguments.
void set_templateName(SgName templateName)
sets name of instantiated function template, name includes template arguments.
This class represents the concept of an instantiation of member function template or a member functio...
void set_templateName(SgName templateName)
sets name of instantiated function template, name includes template arguments.
virtual std::string class_name() const override
returns a string representing the class name
const SgTemplateArgumentPtrList & get_templateArguments() const
Returns pointer to STL list of pointers to SgTemplateArgument objects.
SgName get_templateName() const
Returns name of instantiated function template, name includes template arguments.
virtual std::string class_name() const override
returns a string representing the class name
virtual std::string class_name() const override
returns a string representing the class name
virtual std::string class_name() const override
returns a string representing the class name
This class represents the "this" operator (can be applied to any member data).
This class represents the C++ throw expression (handled as a unary operator).
e_throw_kind
Throw IR node can be used in three different ways.
This class represents the concept of try statement within the try-catch support for exception handlin...
SgCatchStatementSeq * get_catch_statement_seq_root() const
Returns pointer to SgCatchStatementSeq.
This class represents a tuple display.
static SgTypeBFloat16 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeBool * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeChar16 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeChar32 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeChar * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents a C99 complex type.
static SgTypeDouble * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFixed * createType(SgExpression *scale=NULL, SgExpression *fraction=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypeFixed (types whose constructors take par...
static SgTypeFloat128 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat16 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat32 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat32x * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat64 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat64x * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat80 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFloat * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeFp16 * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents a C99 complex type.
static SgTypeInt * createType(int sz=0, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypeInt (types whose constructors take param...
static SgTypeLongDouble * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeLongLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeNullptr * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeOfType * createType(SgExpression *expr=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypeOfType (types whose constructors take pa...
static SgTypeShort * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSigned128bitInteger * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedChar * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedInt * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedLongLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeSignedShort * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents a string type used for SgStringVal IR node.
static SgTypeUnknown * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsigned128bitInteger * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedChar * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedInt * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedLongLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedLong * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeUnsignedShort * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeVoid * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeWchar * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents the base class for all types.
std::vector< SgType * > getInternalTypes() const
Generate a container of types hidden in the input type.
SgType * stripType(unsigned char bit_array=STRIP_MODIFIER_TYPE|STRIP_REFERENCE_TYPE|STRIP_RVALUE_REFERENCE_TYPE|STRIP_POINTER_TYPE|STRIP_ARRAY_TYPE|STRIP_TYPEDEF_TYPE|STRIP_POINTER_MEMBER_TYPE) const
Returns hidden type beneath layers of typedefs, pointers, references, modifiers, array representation...
virtual std::string class_name() const override
returns a string representing the class name
This class represents the notion of a typedef declaration.
SgScopeStatement * get_scope() const override
Returns scope of current statement.
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
SgType * get_type() const override
This function returns the type associated with the named entity.
virtual std::string class_name() const override
returns a string representing the class name
SgType * get_base_type() const
This is used in the SgTypedefType object (is not associated with a base_type data field)
static SgTypedefType * createType(SgTypedefDeclaration *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypedefType (types whose constructors take p...
This class represents the notion of a unary operator. It is derived from a SgExpression because opera...
void set_mode(SgUnaryOp::Sgop_mode mode)
Set the mode (prefix/postfix) associated with this operator.
SgExpression * get_operand_i() const
returns SgExpression pointer to the operand associated with this unary operator.
Sgop_mode
Enum value defines operators as prefix or postfix, as appropriate, e.g. operator++().
void set_operand_i(SgExpression *operand_i)
This function allows the p_operand_i pointer to be set (used internally).
This class represents the concept of a C++ using directive.
This class represents the notion of an value (expression value).
This class represents the variable refernece in expressions.
This class represents the concept of a C or C++ variable declaration.
const SgInitializedNamePtrList & get_variables() const
Access function for p_variables.
This class represents the definition (initialization) of a variable.
void set_vardefn(SgInitializedName *vardefn)
Access function for SgInitializedName in p_vardefn.
This class represents the concept of a variable name within the compiler (a shared container for the ...
SgName get_name() const override
Access function for getting name from declarations or types internally.
This class represents the concept of a do-while statement.
This class represents the location of the code associated with the IR node in the original source cod...
static std::map< std::string, int > & get_nametofileid_map()
Access function for static datamember nametofileid_map.
void setTransformation()
Marks an IR node to be a transformation if it is not one already.
const char * get_filename() const
Returns filename of source code associated with IR node.
bool isOutputInCodeGeneration() const
Returns true only if required to be unparsed in generated code.
void unsetOutputInCodeGeneration()
Mark as to be output by the unparser (code generator)
int get_line() const
Returns the line number of the associated code for this IR node.
void setShared()
Marks IR node as shared.
void setCompilerGenerated()
Marks IR node as compiler generated.
bool isShared() const
Returns true only if shared internally (either by the front-end or by ROSE).
ROSE_DLL_API roseNode * buildroseNode(SgNode *snode)
A builder function to avoid duplicated building.
ROSE_DLL_API const char * c_char
A namespace scope char* to avoid passing and returning a target c string for every and each function ...
ROSE_DLL_API SgNode * c_sgnode
current anchor SgNode associated with parsing. It will serve as a start point to find enclosing scope...
ROSE_DLL_API SgNode * c_parsed_node
Store the AST substree (expression, statement) generated from a helper function.
ROSE_DLL_API bool afs_match_statement()
match any statement, not complete yet. Don't use it yet . : labeled_statement | compound_statement | ...
ROSE_DLL_API std::vector< std::string > generateSourceFilenames(std::vector< std::string > argList, bool binaryMode)
Build the list of isolated file names from the command line.
ROSE_UTIL_API void removeAllFileNamesExcept(std::vector< std::string > &argv, std::vector< std::string > filenameList, std::string exceptFilename)
Remove file names specified in filenameList from argv, except for 'exceptFilename'.
Unsigned position(size_t i)
Generate a single-bit mask.
Definition BitOps.h:159
Controls diagnostic messages from ROSE.
ROSE_DLL_API void initAndRegister(Facility *mlog, const std::string &name)
Initialize and register a logging facility.
ROSE_DLL_API Sawyer::Message::Facility mlog
Diagnostic facility for the ROSE library as a whole.
Definition sageBuilder.C: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 SgTypeFloat16 * buildFloat16Type()
Built in simple types.
ROSE_DLL_API SgTemplateInstantiationTypedefDeclaration * buildTemplateInstantiationTypedefDeclaration_nfi(SgName &name, SgType *base_type, SgScopeStatement *scope, bool has_defining_base, SgTemplateTypedefDeclaration *templateTypedefDeclaration, SgTemplateArgumentPtrList &templateArgumentsList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgJavaMemberValuePair * buildJavaMemberValuePair(const SgName &, SgExpression *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgCastExp * buildCastExp_nfi(SgExpression *operand_i, SgType *expression_type, SgCastExp::cast_type_enum cast_type)
ROSE_DLL_API SgUpcBarrierStatement * buildUpcBarrierStatement_nfi(SgExpression *exp)
Build a UPC barrier statement.
ROSE_DLL_API SgAtomicStmt * buildAtomicStmt(SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAtStmt * buildAtStmt(SgExpression *expression, SgBasicBlock *body)
MH (6/11/2014): Added at support.
ROSE_DLL_API SgJovialBitType * buildJovialBitType(SgExpression *size)
Build a Jovial bit type of a given size.
ROSE_DLL_API SgColonShapeExp * buildColonShapeExp()
Build a Fortran colon-shape expression, set file info as the default one.
ROSE_DLL_API SgJovialTableType * buildJovialTableType(const SgName &name, SgType *base_type, SgExprListExp *dim_info, SgScopeStatement *scope=NULL)
Build a Jovial table type with required class definition and defining and nondefining declarations.
ROSE_DLL_API SgFunctionDeclaration * buildNondefiningFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope=NULL, SgExprListExp *decoratorList=NULL, bool buildTemplateInstantiation=false, SgTemplateArgumentPtrList *templateArgumentsList=NULL, SgStorageModifier::storage_modifier_enum sm=SgStorageModifier::e_default)
Build a prototype for a function, handle function type, symbol etc transparently.
ROSE_DLL_API SgFloat32Val * buildFloat32Val(float v=0)
Build a float32.
ROSE_DLL_API SgTemplateArgumentPtrList * getTemplateArgumentList(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgSwitchStatement * buildSwitchStatement_nfi(SgStatement *item_selector, SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgBaseClass * buildBaseClass(SgClassDeclaration *classDeclaration, SgClassDefinition *classDefinition, bool isVirtual, bool isDirect)
DQ (5/6/2013): Added build functions to support SgBaseClass construction.
SourcePositionClassification
intended to be a private member, don't access it directly. could be changed any time
@ e_sourcePosition_last
Specify as source position to be filled in as part of AST construction in the front-end.
@ e_sourcePositionNullPointers
Classify as compiler generated code (e.g. template instantiation).
@ e_sourcePositionCompilerGenerated
Classify as a transformation.
@ e_sourcePositionFrontendConstruction
Set pointers to Sg_File_Info objects to NULL.
@ e_sourcePositionDefault
Error value for enum.
@ e_sourcePositionTransformation
Default source position.
ROSE_DLL_API SgFunctionParameterRefExp * buildFunctionParameterRefExp_nfi(int parameter_number, int parameter_level)
ROSE_DLL_API SgThrowOp * buildThrowOp(SgExpression *, SgThrowOp::e_throw_kind)
Build a ThrowOp expression.
ROSE_DLL_API SgPointerMemberType * buildPointerMemberType(SgType *base_type, SgType *classType)
Pei-Hung (06/30/2023): support for SgPointerMemberType.
ROSE_DLL_API SgPragma * buildPragma(const std::string &name)
Build SgPragma.
ROSE_DLL_API void testTemplateParameterParents(SgDeclarationStatement *decl)
DQ (9/16/2012): Added function to support setting the template parameters and setting their parents (...
ROSE_DLL_API SgStringConversion * buildStringConversion(SgExpression *exp)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgChooseExpression * buildChooseExpression_nfi()
ROSE_DLL_API SgJavaWildcardType * getUniqueJavaWildcardExtends(SgType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgUpcForAllStatement * buildUpcForAllStatement_nfi(SgStatement *initialize_stmt, SgStatement *test, SgExpression *increment, SgExpression *affinity, SgStatement *loop_body)
Build a UPC forall statement.
ROSE_DLL_API SgBFloat16Val * buildBFloat16Val_nfi(float v, const std::string &str)
ROSE_DLL_API SgUnsignedLongVal * buildUnsignedLongValHex(unsigned long v=0)
ROSE_DLL_API SgClassType * buildClassTemplateType(SgTemplateClassDeclaration *template_decl, std::vector< SgNode * > &template_args)
Some support for building class template instantiation declarations.
ROSE_DLL_API SgNullptrValExp * buildNullptrValExp_nfi()
ROSE_DLL_API SgDerivedTypeStatement * buildDerivedTypeStatement(const SgName &name, SgScopeStatement *scope=NULL)
Build an SgDerivedTypeStatement Fortran derived type declaration with a class declaration and definit...
ROSE_DLL_API SgExprStatement * buildFunctionCallStmt(const SgName &name, SgType *return_type, SgExprListExp *parameters=NULL, SgScopeStatement *scope=NULL)
Build a regular function call statement.
ROSE_DLL_API SgExecStatement * buildExecStatement(SgExpression *executable, SgExpression *globals=NULL, SgExpression *locals=NULL)
Build an exec statement.
ROSE_DLL_API SgShortVal * buildShortValHex(short value=0)
ROSE_DLL_API SgClassDeclaration * buildClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgClassDeclaration *nonDefiningDecl, bool buildTemplateInstantiation, SgTemplateArgumentPtrList *templateArgumentsList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeSignedLongLong * buildSignedLongLongType()
Built in simple types.
ROSE_DLL_API SgNewExp * buildNewExp(SgType *type, SgExprListExp *exprListExp, SgConstructorInitializer *constInit, SgExpression *expr, short int val, SgFunctionDeclaration *funcDecl)
SgPythonGlobalStmt * buildPythonGlobalStmt_nfi(SgInitializedNamePtrList &names)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SourcePositionClassification getSourcePositionClassificationMode()
Get the current source position classification (defines how IR nodes built by the SageBuilder interfa...
SgNullStatement * buildNullStatement_nfi()
Build a NULL statement.
ROSE_DLL_API SgForStatement * buildForStatement_nfi(SgStatement *initialize_stmt, SgStatement *test, SgExpression *increment, SgStatement *loop_body, SgStatement *else_body=NULL)
Based on the contribution from Pradeep Srinivasa@ LANL.
ROSE_DLL_API SgTypeUnsignedLongLong * buildUnsignedLongLongType()
Built in simple types.
ROSE_DLL_API SgCompoundInitializer * buildCompoundInitializer(SgExprListExp *initializers=NULL, SgType *type=NULL)
Build a compound initializer, for vector type initialization.
ROSE_DLL_API SgTypeString * buildStringType()
DQ (8/21/2010): We want to move to the new buildStringType( SgExpression*,size_t) function over the o...
ROSE_DLL_API SgUpcThreads * buildUpcThreads_nfi()
Build UPC THREADS (integer expression)
ROSE_DLL_API SgModifierType * buildModifierType(SgType *base_type=nullptr)
Build a modifier type.
ROSE_DLL_API SgCaseOptionStmt * buildCaseOptionStmt(SgExpression *key=NULL, SgStatement *body=NULL)
Build a case option statement.
ROSE_DLL_API SgTemplateFunctionDeclaration * buildDefiningTemplateFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, SgTemplateFunctionDeclaration *first_nondefining_declaration)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgCatchOptionStmt * buildCatchOptionStmt(SgVariableDeclaration *condition=NULL, SgStatement *body=NULL)
Build a catch statement.
ROSE_DLL_API SgLongLongIntVal * buildLongLongIntVal_nfi(long long value, const std::string &str)
ROSE_DLL_API SgClassType * buildTemplateClassType(SgTemplateClassDeclaration *template_decl, std::vector< SgNode * > &template_args)
Same as buildClassTemplateType(), just better name.
SgFortranContinueStmt * buildFortranContinueStmt_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTemplateMemberFunctionDeclaration * buildNondefiningTemplateMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, SgTemplateParameterPtrList *templateParameterList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgLabelStatement * buildLabelStatement(const SgName &name, SgStatement *stmt=NULL, SgScopeStatement *scope=NULL)
Build a label statement, name is the label's name. Handling label symbol and scope internally.
ROSE_DLL_API SgFortranDo * buildFortranDo_nfi(SgExpression *initialization, SgExpression *bound, SgExpression *increment, SgBasicBlock *)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUpcThreads * buildUpcThreads()
Build UPC THREADS (integer expression)
ROSE_DLL_API SgModifierType * buildRestrictType(SgType *base_type)
Build a restrict type.
ROSE_DLL_API SgIntVal * buildIntVal_nfi(int value=0)
ROSE_DLL_API SgLongDoubleVal * buildLongDoubleVal(long double value=0.0)
SgFunctionParameterList * buildFunctionParameterList_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API AbstractHandle::abstract_handle * buildAbstractHandle(SgNode *n)
Build an abstract handle from a SgNode.
ROSE_DLL_API SgClassDeclaration * buildClassDeclaration(SgName name, SgScopeStatement *scope)
Build C++ class (builds both the non-defining and defining declarations; in that order).
ROSE_DLL_API SgMinusOp * buildMinusOp_nfi(SgExpression *op)
ROSE_DLL_API SgTemplateFunctionDeclaration * buildNondefiningTemplateFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope=NULL, SgExprListExp *decoratorList=NULL, SgTemplateParameterPtrList *templateParameterList=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAsmStmt * buildMultibyteNopStatement(int n)
DQ (4/30/2010): Added support for building nop statement using asm statement Building nop statement u...
ROSE_DLL_API SgKeyDatumPair * buildKeyDatumPair(SgExpression *key, SgExpression *datum)
Build a key-datum pair.
ROSE_DLL_API SgComprehension * buildComprehension(SgExpression *target, SgExpression *iter, SgExprListExp *ifs)
ROSE_DLL_API SgJavaParameterizedType * getUniqueJavaParameterizedType(SgNamedType *, SgTemplateParameterPtrList *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgComplexVal * buildImaginaryVal_nfi(SgValueExp *imaginary_value, const std::string &str)
ROSE_DLL_API SgFunctionCallExp * buildFunctionCallExp(SgFunctionSymbol *sym, SgExprListExp *parameters=NULL)
Build a function call expression.
ROSE_DLL_API SgType * getTargetFileType(SgType *snippet_type, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgTemplateParameter * buildTemplateParameter(SgTemplateParameter::template_parameter_enum parameterType, SgType *)
Build a template parameter, passing enum kind and SgTemplateType template_parameter_enum { parameter_...
ROSE_DLL_API SgNoexceptOp * buildNoexceptOp(SgExpression *exp=NULL)
Build noexcept operator expression with an expression parameter.
ROSE_DLL_API SgSignedCharVal * buildSignedCharVal_nfi(signed char v, const std::string &str)
ROSE_DLL_API SgClassDeclaration * buildNondefiningClassDeclaration(SgName name, SgScopeStatement *scope)
DQ (11/7/2009): Added functions to build C++ class.
SgMemberFunctionRefExp * buildMemberFunctionRefExp_nfi(SgMemberFunctionSymbol *sym, bool virtual_call, bool need_qualifier)
ROSE_DLL_API SgFunctionDeclaration * buildDefiningFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, bool buildTemplateInstantiation=false, SgFunctionDeclaration *first_nondefinng_declaration=NULL, SgTemplateArgumentPtrList *templateArgumentsList=NULL)
Build a function declaration with a function body.
ROSE_DLL_API SgModifierType * buildUpcSharedType(SgType *base_type=nullptr, long layout=-1)
Build a UPC shared type.
ROSE_DLL_API SgGotoStatement * buildGotoStatement(SgLabelStatement *label=NULL)
Build a goto statement.
ROSE_DLL_API std::string display(SourcePositionClassification &scp)
display function for debugging
ROSE_DLL_API SgUnsignedLongVal * buildUnsignedLongVal_nfi(unsigned long v, const std::string &str)
ROSE_DLL_API SgLabelRefExp * buildLabelRefExp(SgLabelSymbol *s)
Build a Fortran numeric label ref exp.
ROSE_DLL_API SgCompoundInitializer * buildCompoundInitializer_nfi(SgExprListExp *initializers, SgType *type=NULL)
Build a compound initializer, for vector type initialization.
ROSE_DLL_API SgSourceFile * buildJavaSourceFile(SgProject *, std::string, SgClassDefinition *, std::string)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgCatchStatementSeq * buildCatchStatementSeq(SgCatchOptionStmt *=NULL)
Build an initial sequence of Catch blocks containing 0 or 1 element.
ROSE_DLL_API SgInitializedName * buildInitializedName(const SgName &name, SgType *type, SgInitializer *init=NULL)
Initialized names are tricky, their scope vary depending on context, so scope and symbol information ...
ROSE_DLL_API SgTryStmt * buildTryStmt(SgStatement *body, SgCatchOptionStmt *catch0=NULL, SgCatchOptionStmt *catch1=NULL, SgCatchOptionStmt *catch2=NULL, SgCatchOptionStmt *catch3=NULL, SgCatchOptionStmt *catch4=NULL)
Build a try statement.
ROSE_DLL_API SgJavaImportStatement * buildJavaImportStatement(std::string, bool)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgThisExp * buildThisExp_nfi(SgSymbol *sym)
ROSE_DLL_API SgEnumDeclaration * buildEnumDeclaration_nfi(const SgName &name, SgScopeStatement *scope=NULL)
Build an enum, It is also a declaration statement in SAGE III.
ROSE_DLL_API SgNonrealDecl * buildNonrealDecl(const SgName &name, SgDeclarationScope *scope, SgDeclarationScope *child_scope=NULL)
Build a declaration of a non-real class or class-member representing template parameters and their me...
SgAssertStmt * buildAssertStmt_nfi(SgExpression *test)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgThisExp * buildThisExp(SgSymbol *sym)
Build this pointer.
ROSE_DLL_API SgSymbol * findAssociatedSymbolInTargetAST(SgDeclarationStatement *snippet_declaration, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgListComprehension * buildListComprehension(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgMinusMinusOp * buildMinusMinusOp_nfi(SgExpression *op)
ROSE_DLL_API SgModifierType * buildUpcBlockStarType(SgType *base_type=nullptr)
Build a UPC shared[*] type.
ROSE_DLL_API SgStringConversion * buildStringConversion_nfi(SgExpression *exp)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgFloat16Val * buildFloat16Val_nfi(float v, const std::string &str)
SgTupleExp * buildTupleExp_nfi()
ROSE_DLL_API SgIntVal * buildIntValHex(int value=0)
ROSE_DLL_API SgTemplateClassDeclaration * buildNondefiningTemplateClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateSpecializationArgumentList)
DQ (11/29/2011): Adding template declaration support to the AST.
ROSE_DLL_API void setTemplateParametersInDeclaration(SgDeclarationStatement *decl, SgTemplateParameterPtrList *templateParametersList_input)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDeclType * buildDeclType(SgExpression *base_expression, SgType *base_type)
Build a decltype reference type.
ROSE_DLL_API SgUnsignedShortVal * buildUnsignedShortVal_nfi(unsigned short v, const std::string &str)
ROSE_DLL_API SgJavaWildcardType * getUniqueJavaWildcardUnbound()
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgIfStmt * buildIfStmt_nfi(SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDictionaryComprehension * buildDictionaryComprehension(SgKeyDatumPair *kd_pair, SgExprListExp *generators)
ROSE_DLL_API SgShortVal * buildShortVal_nfi(short value, const std::string &str)
ROSE_DLL_API void clearScopeStack()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgLongIntVal * buildLongIntVal(long value=0)
Build a long integer value expression.
ROSE_DLL_API SgJavaTypeExpression * buildJavaTypeExpression(SgType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgChar16Val * buildChar16Val(unsigned short value=0)
ROSE_DLL_API SgAwaitExpression * buildAwaitExpression()
SgDeleteExp * buildDeleteExp_nfi(SgExpression *target, bool is_array=false, bool need_global_specifier=false, SgFunctionDeclaration *deleteOperatorDeclaration=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgFoldExpression * buildFoldExpression_nfi(SgExpression *operands, std::string operator_token_string, bool is_left_associative)
ROSE_DLL_API SgBracedInitializer * buildBracedInitializer_nfi(SgExprListExp *initializers=NULL, SgType *expression_type=NULL)
ROSE_DLL_API SgMemberFunctionType * buildMemberFunctionType(SgType *return_type, SgFunctionParameterTypeList *typeList, SgScopeStatement *struct_name, unsigned int mfunc_specifier)
Built in simple types.
ROSE_DLL_API SgVariableDefinition * buildVariableDefinition_nfi(SgVariableDeclaration *decl, SgInitializedName *init_name, SgInitializer *init)
Build variable definition.
ROSE_DLL_API SgBasicBlock * buildBasicBlock_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUpcMythread * buildUpcMythread_nfi()
Build UPC MYTHREAD (integer expression)
ROSE_DLL_API SgWhileStmt * buildWhileStmt(SgStatement *condition, SgStatement *body, SgStatement *else_body=NULL)
Build while statement.
ROSE_DLL_API SgTypeFloat32 * buildFloat32Type()
Built in simple types.
ROSE_DLL_API SgTemplateClassDeclaration * buildNondefiningTemplateClassDeclaration(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateSpecializationArgumentList)
buildNondefiningTemplateClassDeclaration()
ROSE_DLL_API void setSourcePositionClassificationMode(SourcePositionClassification X)
Set the current source position classification (defines how IR nodes built by the SageBuilder interfa...
ROSE_DLL_API SgClassDeclaration * buildStructDeclaration(const SgName &name, SgScopeStatement *scope=NULL)
Build a structure, It is also a declaration statement in SAGE III.
SgCtorInitializerList * buildCtorInitializerList_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgNamespaceAliasDeclarationStatement * buildNamespaceAliasDeclarationStatement(const SgName &name, SgNamespaceDeclarationStatement *namespaceDeclaration)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgClassDefinition * buildClassDefinition(SgClassDeclaration *d=NULL, bool buildTemplateInstantiation=false)
Build a class definition scope statement.
ROSE_DLL_API SgJovialBitVal * buildJovialBitVal_nfi(const std::string &str)
Build a Jovial bit value expression.
ROSE_DLL_API SgCharVal * buildCharVal_nfi(char value, const std::string &str)
ROSE_DLL_API SgJavaThrowStatement * buildJavaThrowStatement(SgThrowOp *)
Build a Java Throw statement.
ROSE_DLL_API SgJavaSynchronizedStatement * buildJavaSynchronizedStatement(SgExpression *, SgBasicBlock *)
Build a Java Synchronized statement.
ROSE_DLL_API PreprocessingInfo * buildComment(SgLocatedNode *target, const std::string &content, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before, PreprocessingInfo::DirectiveType dtype=PreprocessingInfo::CpreprocessorUnknownDeclaration)
Build and attach a comment, comment style is inferred from the language type of the target node if no...
SgConditionalExp * buildConditionalExp_nfi(SgExpression *test, SgExpression *a, SgExpression *b, SgType *t)
ROSE_DLL_API SgNamespaceDefinitionStatement * buildNamespaceDefinition(SgNamespaceDeclarationStatement *d=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDefaultOptionStmt * buildDefaultOptionStmt(SgStatement *body=NULL)
Build a default option statement.
SgCudaKernelExecConfig * buildCudaKernelExecConfig_nfi(SgExpression *grid=NULL, SgExpression *blocks=NULL, SgExpression *shared=NULL, SgExpression *stream=NULL)
Build a CUDA kernel execution configuration (<<<grid, blocks, shared, stream>>>)
ROSE_DLL_API SgJavaSingleMemberAnnotation * buildJavaSingleMemberAnnotation(SgType *, SgExpression *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgForStatement * buildForStatement(SgStatement *initialize_stmt, SgStatement *test, SgExpression *increment, SgStatement *loop_body, SgStatement *else_body=NULL)
Build a for statement, assume none of the arguments is NULL.
ROSE_DLL_API SgTypeMatrix * buildMatrixType()
Build a Matlab Matrix Type.
ROSE_DLL_API SgModuleStatement * buildModuleStatement(const SgName &name, SgScopeStatement *scope)
Build a Fortran module declaration.
ROSE_DLL_API SgContinueStmt * buildContinueStmt()
Build a continue statement.
ROSE_DLL_API SgEmptyDeclaration * buildEmptyDeclaration()
Build an empty declaration (useful for adding precission to comments and CPP handling under token-bas...
ROSE_DLL_API SgUnsignedIntVal * buildUnsignedIntValHex(unsigned int v=0)
ROSE_DLL_API SgTemplateType * buildTemplateType(SgName name="")
Build a template type, used for template parameter and later argument.
ROSE_DLL_API SgLambdaRefExp * buildLambdaRefExp(SgType *return_type, SgFunctionParameterList *params, SgScopeStatement *scope)
Build lambda expression.
ROSE_DLL_API SgFloatVal * buildFloatVal_nfi(float value=0.0)
ROSE_DLL_API SgConditionalExp * buildConditionalExp(SgExpression *test=NULL, SgExpression *a=NULL, SgExpression *b=NULL)
Build a conditional expression ?:
ROSE_DLL_API SgUnsignedLongVal * buildUnsignedLongVal(unsigned long v=0)
Build a unsigned long integer.
ROSE_DLL_API SgTypeInt * buildIntType()
Built in simple types.
SgDictionaryComprehension * buildDictionaryComprehension_nfi(SgKeyDatumPair *kd_pair, SgExprListExp *generators)
ROSE_DLL_API SgTemplateClassDeclaration * buildTemplateClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgTemplateClassDeclaration *nonDefiningDecl, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateSpecializationArgumentList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeUnsignedInt * buildUnsignedIntType()
Built in simple types.
ROSE_DLL_API SgFloat80Val * buildFloat80Val(long double value=0.0)
SgSubscriptExpression * buildSubscriptExpression_nfi(SgExpression *lower_bound, SgExpression *upper_bound, SgExpression *stride)
Build a SgSubscriptExpression, used for array shape expressions. The lower bound and stride may be nu...
ROSE_DLL_API SgDotDotExp * buildDotDotExp()
Build a variable declaration, handle symbol table transparently.
SourcePositionClassification SourcePositionClassificationMode
C++ SageBuilder namespace specific state for storage of the source code position state (used to contr...
ROSE_DLL_API SgTypeBFloat16 * buildBFloat16Type()
Built in simple types.
ROSE_DLL_API SgMinusOp * buildMinusOp(SgExpression *op=NULL)
std::list< SgScopeStatement * > ScopeStack
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgModifierType * buildUpcBlockIndefiniteType(SgType *base_type=nullptr)
Build a UPC shared[] type.
SgSetComprehension * buildSetComprehension_nfi(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgTypeFp16 * buildFp16Type()
Built in simple types.
SgName unparseTemplateArgumentToString(SgTemplateArgument *templateArgument)
DQ (3/9/2018): Added to support debugging.
ROSE_DLL_API SgSuperExp * buildSuperExp(SgClassSymbol *sym)
Build super pointer.
ROSE_DLL_API SgExprListExp * buildExprListExp(SgExpression *expr1=NULL, SgExpression *expr2=NULL, SgExpression *expr3=NULL, SgExpression *expr4=NULL, SgExpression *expr5=NULL, SgExpression *expr6=NULL, SgExpression *expr7=NULL, SgExpression *expr8=NULL, SgExpression *expr9=NULL, SgExpression *expr10=NULL)
Build a SgExprListExp, used for function call parameter list etc.
ROSE_DLL_API void resetDeclaration(T *classDeclaration_copy, T *classDeclaration_original, SgScopeStatement *targetScope)
Function to reset scopes in SgDeclarationStatement IR nodes.
ROSE_DLL_API SgRangeBasedForStatement * buildRangeBasedForStatement_nfi(SgVariableDeclaration *initializer, SgVariableDeclaration *range, SgVariableDeclaration *begin_declaration, SgVariableDeclaration *end_declaration, SgExpression *not_equal_expression, SgExpression *increment_expression, SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgJavaPackageStatement * buildJavaPackageStatement(std::string)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgJavaLabelStatement * buildJavaLabelStatement(const SgName &, SgStatement *=NULL)
Build a Java Label statement.
ROSE_DLL_API SgEquivalenceStatement * buildEquivalenceStatement(SgExpression *lhs, SgExpression *rhs)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgListExp * buildListExp(SgExpression *expr1=NULL, SgExpression *expr2=NULL, SgExpression *expr3=NULL, SgExpression *expr4=NULL, SgExpression *expr5=NULL, SgExpression *expr6=NULL, SgExpression *expr7=NULL, SgExpression *expr8=NULL, SgExpression *expr9=NULL, SgExpression *expr10=NULL)
Build a SgListExp.
ROSE_DLL_API SgUnsignedCharVal * buildUnsignedCharValHex(unsigned char v=0)
ROSE_DLL_API SgModifierType * buildNotNullType(SgType *base_type)
Build a not null type for Ada.
ROSE_DLL_API SgLambdaExp * buildLambdaExp_nfi(SgLambdaCaptureList *lambda_capture_list, SgClassDeclaration *lambda_closure_class, SgFunctionDeclaration *lambda_function)
ROSE_DLL_API SgTemplateClassDeclaration * buildTemplateClassDeclaration(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, SgTemplateClassDeclaration *nonDefiningDecl, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateSpecializationArgumentList)
Build tempplate class declaration.
ROSE_DLL_API SgSourceFile * buildSourceFile(const std::string &outputFileName, SgProject *project=NULL, bool clear_globalScopeAcrossFiles=false)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API void setTemplateSpecializationArgumentsInDeclaration(SgDeclarationStatement *decl, SgTemplateArgumentPtrList *templateSpecializationArgumentsList_input)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgArrayType * buildArrayType(SgType *base_type=nullptr, SgExpression *index=nullptr)
Build ArrayType.
ROSE_DLL_API SgTypeFloat32x * buildFloat32xType()
Built in simple types.
ROSE_DLL_API SgEnumDeclaration * buildNondefiningEnumDeclaration_nfi(const SgName &name, SgScopeStatement *scope)
Build an enum first nondefining declaration, without file info.
ROSE_DLL_API SgComplexVal * buildImaginaryVal(long double imaginary_value)
ROSE_DLL_API SgLambdaCapture * buildLambdaCapture_nfi(SgExpression *capture_variable, SgExpression *source_closure_variable, SgExpression *closure_variable)
ROSE_DLL_API SgNullptrValExp * buildNullptrValExp()
DQ (7/31/2014): Adding support for C++11 nullptr const value expressions.
ROSE_DLL_API void fixupCopyOfAstFromSeparateFileInNewTargetAst(SgStatement *insertionPoint, bool insertionPointIsScope, SgStatement *toInsert, SgStatement *original_before_copy)
Fixup any AST moved from one file two another (references to symbols, types, etc.).
SgExprStatement * buildExprStatement_nfi(SgExpression *exp)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeExpression * buildTypeExpression(SgType *type)
DQ (7/24/2014): Adding support for c11 generic operands.
ROSE_DLL_API SgTypeFixed * buildFixedType(SgExpression *fraction, SgExpression *scale)
Build a Jovial fixed type with a fraction specifier and a scale specifier.
SgPythonPrintStmt * buildPythonPrintStmt_nfi(SgExpression *dest=NULL, SgExprListExp *values=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTemplateVariableDeclaration * buildTemplateVariableDeclaration_nfi(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgNaryComparisonOp * buildNaryComparisonOp_nfi(SgExpression *lhs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgReturnStmt * buildReturnStmt(SgExpression *expression=NULL)
Build a return statement.
SgCaseOptionStmt * buildCaseOptionStmt_nfi(SgExpression *key, SgStatement *body)
Build a variable declaration, handle symbol table transparently.
SgWithStatement * buildWithStatement_nfi(SgExpression *expr, SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUpcFenceStatement * buildUpcFenceStatement_nfi()
Build a UPC fence statement.
ROSE_DLL_API SgComplexVal * buildComplexVal_nfi(SgValueExp *real_value, SgValueExp *imaginary_value, const std::string &str)
SgCudaKernelCallExp * buildCudaKernelCallExp_nfi(SgExpression *kernel, SgExprListExp *parameters=NULL, SgCudaKernelExecConfig *config=NULL)
Build a CUDA kernel call expression (kernel<<<config>>>(parameters))
ROSE_DLL_API SgTypeFloat64x * buildFloat64xType()
Built in simple types.
SgCompoundLiteralExp * buildCompoundLiteralExp_nfi(SgVariableSymbol *varSymbol)
Build function for compound literals (uses a SgVariableSymbol and is similar to buildVarRefExp_nfi())...
actualFunction * buildDefiningFunctionDeclaration_T(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, bool isMemberFunction, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, actualFunction *first_nondefinng_declaration, SgTemplateArgumentPtrList *templateArgumentsList)
A template function for function declaration builders.
ROSE_DLL_API SgChar16Val * buildChar16Val_nfi(unsigned short value, const std::string &str)
ROSE_DLL_API SgTypeLongLong * buildLongLongType()
Built in simple types.
ROSE_DLL_API SgTypeFloat128 * buildFloat128Type()
Built in simple types.
ROSE_DLL_API SgProcedureHeaderStatement * buildNondefiningProcedureHeaderStatement(const SgName &name, SgType *return_type, SgFunctionParameterList *param_list, SgProcedureHeaderStatement::subprogram_kind_enum, SgScopeStatement *scope=NULL)
Build a nondefining SgProcedureHeaderStatement, handle function type, symbol etc transparently.
ROSE_DLL_API SgFloat32Val * buildFloat32Val_nfi(float v, const std::string &str)
ROSE_DLL_API SgVarRefExp * buildVarRefExp(const SgName &name, SgScopeStatement *scope=NULL)
Build SgVarRefExp based on a variable's Sage name. It will lookup the name in the symbol table intern...
SgComprehension * buildComprehension_nfi(SgExpression *target, SgExpression *iter, SgExprListExp *ifs)
ROSE_DLL_API SgJovialTableStatement * buildJovialTableStatement(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope=NULL)
Build a Jovial table declaration statement.
ROSE_DLL_API SgLongLongIntVal * buildLongLongIntVal(long long value=0)
Build a long long integer value expression.
ROSE_DLL_API SgUnsignedLongLongIntVal * buildUnsignedLongLongIntVal(unsigned long long v=0)
Build an unsigned long long integer.
ROSE_DLL_API SgVarRefExp * buildJavaArrayLengthVarRefExp()
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgSuperExp * buildSuperExp_nfi(SgClassSymbol *sym)
SgKeyDatumPair * buildKeyDatumPair_nfi(SgExpression *key, SgExpression *datum)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgNamespaceDeclarationStatement * buildNamespaceDeclaration(const SgName &name, SgScopeStatement *scope=NULL)
tps (09/02/2009) : Added support for building namespaces
ROSE_DLL_API SgAggregateInitializer * buildAggregateInitializer_nfi(SgExprListExp *initializers, SgType *type=NULL)
Build an aggregate initializer.
ROSE_DLL_API SgTypeUnsignedShort * buildUnsignedShortType()
Built in simple types.
ROSE_DLL_API SgTypedefDeclaration * buildTypedefDeclaration_nfi(const std::string &name, SgType *base_type, SgScopeStatement *scope=NULL, bool has_defining_base=false)
Build a typedef declaration, such as: typedef int myint;.
ROSE_DLL_API SgTemplateVariableDeclaration * buildTemplateVariableDeclaration(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope)
Build template variable declarations.
ROSE_DLL_API SgMinusMinusOp * buildMinusMinusOp(SgExpression *op=NULL)
ROSE_DLL_API void buildDoWhileStatement_nfi(SgDoWhileStmt *result, SgStatement *body, SgStatement *condition)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeSigned128bitInteger * buildSigned128bitIntegerType()
Built in simple types.
ROSE_DLL_API SgUnsignedCharVal * buildUnsignedCharVal_nfi(unsigned char v, const std::string &str)
bool symbol_table_case_insensitive_semantics
Support for construction of case sensitive/insensitive symbol table handling in scopes.
SgListExp * buildListExp_nfi()
ROSE_DLL_API SgPythonPrintStmt * buildPythonPrintStmt(SgExpression *dest=NULL, SgExprListExp *values=NULL)
Build a python print statement.
ROSE_DLL_API SgConstructorInitializer * buildConstructorInitializer(SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type, bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown)
ROSE_DLL_API SgDoWhileStmt * buildDoWhileStmt(SgStatement *body, SgStatement *condition)
Build do-while statement.
ROSE_DLL_API void errorCheckingTargetAST(SgNode *node_copy, SgNode *node_original, SgFile *targetFile, bool failOnWarning)
Error checking the inserted snippet AST.
ROSE_DLL_API SgDotExp * buildDotExp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgFortranDo * buildFortranDo(SgExpression *initialization, SgExpression *bound, SgExpression *increment, SgBasicBlock *)
Build a Fortran do construct.
ROSE_DLL_API SgPythonGlobalStmt * buildPythonGlobalStmt(SgInitializedNamePtrList &names)
Build a python global statement.
ROSE_DLL_API SgUnsignedLongLongIntVal * buildUnsignedLongLongIntValHex(unsigned long long v=0)
ROSE_DLL_API SgBoolValExp * buildBoolValExp_nfi(int value)
ROSE_DLL_API SgReturnStmt * buildReturnStmt_nfi(SgExpression *expression)
Build a return statement.
ROSE_DLL_API SgClassExp * buildClassExp(SgClassSymbol *sym)
Build class pointer.
ROSE_DLL_API SgTypeChar16 * buildChar16Type()
Built in simple types.
ROSE_DLL_API SgLambdaExp * buildLambdaExp(SgLambdaCaptureList *lambda_capture_list, SgClassDeclaration *lambda_closure_class, SgFunctionDeclaration *lambda_function)
DQ (9/3/2014): Adding support for C++11 Lambda expressions.
ROSE_DLL_API SgWhenStmt * buildWhenStmt(SgExpression *expression, SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
SgAsmStmt * buildAsmStatement_nfi(std::string s)
Build an asm statement.
SgListComprehension * buildListComprehension_nfi(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgClassDeclaration * buildJavaDefiningClassDeclaration(SgScopeStatement *, std::string, SgClassDeclaration::class_types kind=SgClassDeclaration::e_class)
Build a SgFile node and attach it to SgProject.
SgContinueStmt * buildContinueStmt_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAssignInitializer * buildAssignInitializer(SgExpression *operand_i=NULL, SgType *expression_type=NULL)
Build the rhs of a variable declaration which includes an assignment.
ROSE_DLL_API SgArrayType * getUniqueJavaArrayType(SgType *, int)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgLambdaCapture * buildLambdaCapture(SgExpression *capture_variable, SgExpression *source_closure_variable, SgExpression *closure_variable)
ROSE_DLL_API SgRangeExp * buildRangeExp(SgExpression *start)
Build a Matlab range expression like start:end or start:stride:end.
ROSE_DLL_API SgEnumDeclaration * buildEnumDeclaration(const SgName &name, SgScopeStatement *scope=NULL)
Build an enum, It is also a declaration statement in SAGE III.
ROSE_DLL_API SgModifierType * buildConstVolatileType(SgType *base_type=nullptr)
Build a const volatile type.
ROSE_DLL_API SgEnumVal * buildEnumVal(long long int value, SgEnumDeclaration *decl, SgName name)
ROSE_DLL_API SgEnumVal * buildEnumVal_nfi(long long int value, SgEnumDeclaration *decl, SgName name)
ROSE_DLL_API void setTemplateNameInTemplateInstantiations(SgFunctionDeclaration *func, const SgName &name)
DQ (2/11/2012): Added support to set the template name in function template instantiations (member an...
ROSE_DLL_API SgVariableDeclaration * buildVariableDeclaration(const SgName &name, SgType *type, SgInitializer *varInit=NULL, SgScopeStatement *scope=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgFloat128Val * buildFloat128Val(long double value=0.0)
ROSE_DLL_API SgJovialDefineDeclaration * buildJovialDefineDeclaration_nfi(const SgName &name, const std::string &params, const std::string &def_string, SgScopeStatement *scope=NULL)
Build a Jovial define directive declaration statement.
ROSE_DLL_API SgTypeFloat80 * buildFloat80Type()
Built in simple types.
SgBreakStmt * buildBreakStmt_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgWcharVal * buildWcharVal_nfi(wchar_t value, const std::string &str)
ROSE_DLL_API SgFloatVal * buildFloatVal(float value=0.0)
ROSE_DLL_API SgFinishStmt * buildFinishStmt(SgBasicBlock *body)
MH (6/11/2014): Added finish support.
ROSE_DLL_API SgScopeStatement * topScopeStack()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgModifierType * buildUpcRelaxedType(SgType *base_type=nullptr)
Build a UPC relaxed type.
SgScopeStatement * getGlobalScopeFromScopeStack()
Support to retrive the SgGlobal from the internal scope stack (error if not present in a non-empty li...
ROSE_DLL_API SgChooseExpression * buildChooseExpression()
SgClassDefinition * buildClassDefinition_nfi(SgClassDeclaration *d=NULL, bool buildTemplateInstantiation=false)
Build a class definition scope statement.
ROSE_DLL_API SgClassNameRefExp * buildClassNameRefExp(SgClassSymbol *sym)
ROSE_DLL_API SgWithStatement * buildWithStatement(SgExpression *expr, SgStatement *body)
Build a with statement.
SgTemplateClassDefinition * buildTemplateClassDefinition(SgTemplateClassDeclaration *d=NULL)
Build a template class definition statement.
ROSE_DLL_API SgNullExpression * buildNullExpression()
Build a null expression, set file info as the default one.
ROSE_DLL_API SgNaryBooleanOp * buildNaryBooleanOp_nfi(SgExpression *lhs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgModifierType * buildAliasedType(SgType *base_type)
Build an aliased type for Ada.
ROSE_DLL_API SgTupleExp * buildTupleExp(SgExpression *expr1=NULL, SgExpression *expr2=NULL, SgExpression *expr3=NULL, SgExpression *expr4=NULL, SgExpression *expr5=NULL, SgExpression *expr6=NULL, SgExpression *expr7=NULL, SgExpression *expr8=NULL, SgExpression *expr9=NULL, SgExpression *expr10=NULL)
Build a SgTupleExp.
ROSE_DLL_API SgTypeImaginary * buildImaginaryType(SgType *base_type=nullptr)
Build an imaginary type.
ROSE_DLL_API SgStringVal * buildStringVal_nfi(std::string value)
ROSE_DLL_API SgStatementExpression * buildStatementExpression_nfi(SgStatement *exp)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void setTemplateArgumentParents(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgStmtDeclarationStatement * buildStmtDeclarationStatement(SgStatement *stmt)
Build a StmtDeclarationStmt.
ROSE_DLL_API SgAwaitExpression * buildAwaitExpression_nfi()
ROSE_DLL_API SgTemplateParameterVal * buildTemplateParameterVal_nfi(int template_parameter_position, const std::string &str)
ROSE_DLL_API SgJavaQualifiedType * getUniqueJavaQualifiedType(SgClassDeclaration *, SgNamedType *, SgNamedType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgFinishExp * buildFinishExp(SgExpression *expression, SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgYieldExpression * buildYieldExpression(SgExpression *value)
Build a yield statement.
ROSE_DLL_API SgJavaInstanceOfOp * buildJavaInstanceOfOp(SgExpression *exp=NULL, SgType *type=NULL)
This is part of Java specific operator support.
ROSE_DLL_API SgLambdaCaptureList * buildLambdaCaptureList_nfi()
ROSE_DLL_API SgShortVal * buildShortVal(short value=0)
ROSE_DLL_API SgAsmStmt * buildAsmStatement(std::string s)
Build a NULL statement.
ROSE_DLL_API SgModifierType * buildConstType(SgType *base_type=nullptr)
Build a const type.
ROSE_DLL_API void setTemplateArgumentsInDeclaration(SgDeclarationStatement *decl, SgTemplateArgumentPtrList *templateArgumentsList_input)
DQ (9/16/2012): Added function to support setting the template arguments and setting their parents (a...
ROSE_DLL_API SgJavaNormalAnnotation * buildJavaNormalAnnotation(SgType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgDoubleVal * buildDoubleVal_nfi(double value, const std::string &str)
ROSE_DLL_API SgUnsignedShortVal * buildUnsignedShortVal(unsigned short v=0)
Build an unsigned short integer.
ROSE_DLL_API SgInitializedName * buildInitializedName_nfi(const SgName &name, SgType *type, SgInitializer *init, SgVariableDeclaration *declptr=NULL)
Initialized names are tricky, their scope vary depending on context, so scope and symbol information ...
ROSE_DLL_API PreprocessingInfo * buildCpreprocessorDefineDeclaration(SgLocatedNode *target, const std::string &content, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before)
Build and attach #define XX directives, pass "#define xxx xxx" as content.
ROSE_DLL_API SgTypeDouble * buildDoubleType()
Built in simple types.
ROSE_DLL_API SgReferenceType * buildReferenceType(SgType *base_type=nullptr)
Build a reference type.
SgExecStatement * buildExecStatement_nfi(SgExpression *executable, SgExpression *globals=NULL, SgExpression *locals=NULL)
Build an exec stmt.
ROSE_DLL_API SgTypeLongDouble * buildLongDoubleType()
Built in simple types.
ROSE_DLL_API SgTypeLong * buildLongType()
Built in simple types.
ROSE_DLL_API SgExprStatement * buildExprStatement(SgExpression *exp=NULL)
Build a SgExprStatement, set File_Info automatically.
ROSE_DLL_API SgLongIntVal * buildLongIntVal_nfi(long value, const std::string &str)
ROSE_DLL_API SgFunctionParameterRefExp * buildFunctionParameterRefExp(int parameter_number, int parameter_level)
ROSE_DLL_API SgTemplateTypedefDeclaration * buildTemplateTypedefDeclaration_nfi(const SgName &name, SgType *base_type, SgScopeStatement *scope=NULL, bool has_defining_base=false)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void fixupSourcePositionFileSpecification(SgNode *subtreeRoot, const std::string &newFileName)
Change the source file associated with the source position information in the AST.
ROSE_DLL_API SgAssertStmt * buildAssertStmt(SgExpression *test)
Build a Assert statement.
ROSE_DLL_API SgAtExp * buildAtExp(SgExpression *expression, SgBasicBlock *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgChar32Val * buildChar32Val(unsigned int value=0)
ROSE_DLL_API SgSizeOfOp * buildSizeOfOp_nfi(SgExpression *exp)
Build sizeof() expression with an expression parameter.
ROSE_DLL_API SgIfStmt * buildIfStmt(SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Build if statement.
ROSE_DLL_API SgAsyncStmt * buildAsyncStmt(SgBasicBlock *body)
MH (6/10/2014): Added async support.
ROSE_DLL_API SgFunctionParameterList * buildFunctionParameterList(SgInitializedName *in1=NULL, SgInitializedName *in2=NULL, SgInitializedName *in3=NULL, SgInitializedName *in4=NULL, SgInitializedName *in5=NULL, SgInitializedName *in6=NULL, SgInitializedName *in7=NULL, SgInitializedName *in8=NULL, SgInitializedName *in9=NULL, SgInitializedName *in10=NULL)
Build an empty SgFunctionParameterList, possibly with some initialized names filled in.
ROSE_DLL_API SgModifierType * buildFortranKindType(SgType *base_type, SgExpression *kindExpression)
Build a type based on the Fortran kind mechanism.
ROSE_DLL_API SgPragmaDeclaration * buildPragmaDeclaration(const std::string &name, SgScopeStatement *scope=NULL)
Build pragma declaration, handle SgPragma and defining/nondefining pointers internally.
ROSE_DLL_API SgUnsignedCharVal * buildUnsignedCharVal(unsigned char v=0)
Build an unsigned char.
SgLabelStatement * buildLabelStatement_nfi(const SgName &name, SgStatement *stmt, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgAlignOfOp * buildAlignOfOp(SgExpression *exp=NULL)
Build alignof() expression with an expression parameter.
ROSE_DLL_API SgMatlabForStatement * buildMatlabForStatement(SgExpression *loop_index, SgExpression *loop_range, SgBasicBlock *loop_body)
Build a For-loop statement for matlab.
bool inSwitchScope()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgFloat64Val * buildFloat64Val_nfi(double v, const std::string &str)
ROSE_DLL_API SgUpcMythread * buildUpcMythread()
Build UPC MYTHREAD (integer expression)
ROSE_DLL_API SgTypeUnsignedLong * buildUnsignedLongType()
Built in simple types.
ROSE_DLL_API SgPlusPlusOp * buildPlusPlusOp_nfi(SgExpression *op)
ROSE_DLL_API SgSignedCharVal * buildSignedCharValHex(signed char v=0)
ROSE_DLL_API SgTypeShort * buildShortType()
Built in simple types.
ROSE_DLL_API SgNonrealRefExp * buildNonrealRefExp_nfi(SgNonrealSymbol *sym)
Build a reference to the non-real declaration of a member of a non-real class.
SgFunctionCallExp * buildFunctionCallExp_nfi(SgExpression *f, SgExprListExp *parameters=NULL)
ROSE_DLL_API SgTypeVoid * buildVoidType()
Built in simple types.
ROSE_DLL_API void fixupSharingSourcePosition(SgNode *subtreeRoot, int new_file_id)
Sharing IR nodes requires that the file id be added to the fileIDsToUnparse held in the Sg_File_Info ...
ROSE_DLL_API SgAssignInitializer * buildAssignInitializer_nfi(SgExpression *operand_i=NULL, SgType *expression_type=NULL)
ROSE_DLL_API SgTypeBool * buildBoolType()
Built in simple types.
ROSE_DLL_API SgMicrosoftAttributeDeclaration * buildMicrosoftAttributeDeclaration(const SgName &name)
DQ (8/17/2014): Adding support for Microsoft MSVC specific attributes.
ROSE_DLL_API SgStatement * buildStatementFromString(const std::string &stmt_str, SgScopeStatement *scope)
Liao (9/18/2015): experimental support of building a statement from a string.
ROSE_DLL_API SgFile * buildFile(const std::string &inputFileName, const std::string &outputFileName, SgProject *project=NULL, bool clear_globalScopeAcrossFiles=false)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgMemberFunctionDeclaration * buildDefiningMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, bool buildTemplateInstantiation, unsigned int functionConstVolatileFlags, SgMemberFunctionDeclaration *first_nondefinng_declaration, SgTemplateArgumentPtrList *templateArgumentsList)
Build a defining ( non-prototype) member function declaration.
ROSE_DLL_API SgVarRefExp * buildVarRefExp_nfi(SgVariableSymbol *varSymbol)
ROSE_DLL_API SgPointerType * buildPointerType(SgType *base_type=nullptr)
Build a pointer type.
ROSE_DLL_API SgLongDoubleVal * buildLongDoubleVal_nfi(long double value, const std::string &str)
ROSE_DLL_API SgMagicColonExp * buildMagicColonExp()
Build a Matlab colon expression :
ROSE_DLL_API SgTypedefDeclaration * buildTypedefDeclaration(const std::string &name, SgType *base_type, SgScopeStatement *scope=NULL, bool has_defining_base=false)
Build a typedef declaration, such as: typedef int myint; typedef struct A {..} s_A;.
ROSE_DLL_API SgTemplateParameterVal * buildTemplateParameterVal(int template_parameter_position=-1)
Build an template parameter value expression.
ROSE_DLL_API SgFortranContinueStmt * buildFortranContinueStmt()
Build a Fortran continue statement.
ROSE_DLL_API SgFloat128Val * buildFloat128Val_nfi(long double value, const std::string &str)
ROSE_DLL_API SgBoolValExp * buildBoolValExp(int value=0)
Build a bool value expression, the name convention of SgBoolValExp is little different from others fo...
ROSE_DLL_API SgSwitchStatement * buildSwitchStatement(SgStatement *item_selector=NULL, SgStatement *body=NULL)
Build a switch statement.
ROSE_DLL_API SgType * buildOpaqueType(std::string const type_name, SgScopeStatement *scope)
Build an opaque type with a name, useful when a type's details are unknown during transformation,...
ROSE_DLL_API SgTypeChar32 * buildChar32Type()
Built in simple types.
ROSE_DLL_API SgConstructorInitializer * buildConstructorInitializer_nfi(SgMemberFunctionDeclaration *declaration, SgExprListExp *args, SgType *expression_type, bool need_name, bool need_qualifier, bool need_parenthesis_after_name, bool associated_class_unknown)
ROSE_DLL_API SgMatrixExp * buildMatrixExp(SgExprListExp *firstRow)
Build a Matlab Matrix.
ROSE_DLL_API SgPassStatement * buildPassStatement()
Build a pass statement.
ROSE_DLL_API SgTypeComplex * buildComplexType(SgType *base_type=nullptr)
Build a complex type.
ROSE_DLL_API SgProcedureHeaderStatement * buildProcedureHeaderStatement(const SgName &name, SgType *return_type, SgFunctionParameterList *parameter_list, SgProcedureHeaderStatement::subprogram_kind_enum, SgScopeStatement *scope=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgDeclarationStatement * findAssociatedDeclarationInTargetAST(SgDeclarationStatement *snippet_declaration, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgTypeTuple * buildTupleType(SgType *t1=NULL, SgType *t2=NULL, SgType *t3=NULL, SgType *t4=NULL, SgType *t5=NULL, SgType *t6=NULL, SgType *t7=NULL, SgType *t8=NULL, SgType *t9=NULL, SgType *t10=NULL)
Build a tuple of types. Useful for a function returning multiple variables of different types.
ROSE_DLL_API SgNaryComparisonOp * buildNaryComparisonOp(SgExpression *lhs)
driscoll6 (7/20/11) : Support n-ary operators for python
ROSE_DLL_API SgNonrealType * buildNonrealType(const SgName &name, SgDeclarationScope *scope)
Build a non real type used for template parameter. Internally a SgNorealDecl is also built.
ROSE_DLL_API SgDeclarationScope * buildDeclarationScope()
Build a scope statement. Used to build SgNonrealDecl and SgNonrealType.
ROSE_DLL_API SgName appendTemplateArgumentsToName(const SgName &name, const SgTemplateArgumentPtrList &templateArgumentsList)
DQ (7/27/2012): changed semantics from removing the template arguments in names to adding the templat...
ROSE_DLL_API SgStaticAssertionDeclaration * buildStaticAssertionDeclaration(SgExpression *condition, const SgName &string_literal)
DQ (7/25/2014): Adding support for C11 static assertions.
ROSE_DLL_API SgNullExpression * buildNullExpression_nfi()
No file info version of buildNullExpression(). File info is to be set later on.
ROSE_DLL_API SgFunctionParameterTypeList * buildFunctionParameterTypeList(SgFunctionParameterList *paralist)
Build SgFunctionParameterTypeList from SgFunctionParameterList.
ROSE_DLL_API SgFunctionCallExp * buildMemberFunctionCall(std::string className, SgExpression *objectExpression, std::string functionName, SgExprListExp *params, SgScopeStatement *scope)
Build member function calls.
SgDefaultOptionStmt * buildDefaultOptionStmt_nfi(SgStatement *body)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgFloat64Val * buildFloat64Val(double v=0)
Build a float64.
ROSE_DLL_API SgActualArgumentExpression * buildActualArgumentExpression(SgName arg_name, SgExpression *arg)
Build an Actual Argument Expression.
ROSE_DLL_API PreprocessingInfo * buildHeader(const std::string &header_filename, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before, bool isSystemHeader=false)
Build a dangling #include "x.h" header, insertHeader() is needed to actually insert it.
SgPassStatement * buildPassStatement_nfi()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgStringVal * buildStringVal(std::string value="")
ROSE_DLL_API SgTypeSignedLong * buildSignedLongType()
Built in simple types.
ROSE_DLL_API SgClassDeclaration * buildDefiningClassDeclaration(SgName name, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
SgGotoStatement * buildGotoStatement_nfi(SgLabelStatement *label)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeChar * buildCharType()
Built in simple types.
ROSE_DLL_API SgTemplateParameterPtrList * getTemplateParameterList(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgClassExp * buildClassExp_nfi(SgClassSymbol *sym)
ROSE_DLL_API SgBreakStmt * buildBreakStmt()
Build a break statement.
ROSE_DLL_API SgForInitStatement * buildForInitStatement_nfi(SgStatementPtrList &statements)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void setTemplateParameterParents(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void pushScopeStack(SgScopeStatement *stmt)
Public interfaces of the scope stack, should be stable.
ROSE_DLL_API SgTypeSignedShort * buildSignedShortType()
Built in simple types.
ROSE_DLL_API SgUsingDirectiveStatement * buildUsingDirectiveStatement(SgNamespaceDeclarationStatement *ns_decl)
Build a using directive statement.
SgDictionaryExp * buildDictionaryExp_nfi(std::vector< SgKeyDatumPair * > pairs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgCastExp * buildCastExp(SgExpression *operand_i=NULL, SgType *expression_type=NULL, SgCastExp::cast_type_enum cast_type=SgCastExp::e_C_style_cast)
Build a type casting expression.
SgTemplateMemberFunctionRefExp * buildTemplateMemberFunctionRefExp_nfi(SgTemplateMemberFunctionSymbol *sym, bool virtual_call, bool need_qualifier)
DQ (12/29/2011): Adding template declaration support to the AST.
ROSE_DLL_API SgRvalueReferenceType * buildRvalueReferenceType(SgType *base_type)
Build a rvalue reference type.
ROSE_DLL_API SgClassDeclaration * buildNondefiningClassDeclaration_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope, bool buildTemplateInstantiation, SgTemplateArgumentPtrList *templateArgumentsList)
Build a structure first nondefining declaration, without file info.
ROSE_DLL_API SgStmtDeclarationStatement * buildStmtDeclarationStatement_nfi(SgStatement *stmt)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgForInitStatement * buildForInitStatement()
Build a for init statement.
SgDoWhileStmt * buildDoWhileStmt_nfi(SgStatement *body, SgStatement *condition)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API void popScopeStack()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgSignedCharVal * buildSignedCharVal(signed char v=0)
Build a signed char.
ROSE_DLL_API SgAlignOfOp * buildAlignOfOp_nfi(SgExpression *exp)
Build alignof() expression with an expression parameter.
ROSE_DLL_API SgVarArgOp * buildVarArgOp_nfi(SgExpression *operand_i, SgType *expression_type)
Build vararg op expression.
ROSE_DLL_API void testTemplateArgumentParents(SgDeclarationStatement *decl)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeNullptr * buildNullptrType()
Built in simple types.
ROSE_DLL_API SgModifierType * buildUpcStrictType(SgType *base_type=nullptr)
Build a UPC strict type.
ROSE_DLL_API SgExprStatement * buildAssignStatement_ast_translate(SgExpression *lhs, SgExpression *rhs)
This version does not recursively reset the file info as a transformation.
ROSE_DLL_API SgTypeFloat * buildFloatType()
Built in simple types.
ROSE_DLL_API SgDeleteExp * buildDeleteExp(SgExpression *variable, short is_array, short need_global_specifier, SgFunctionDeclaration *deleteOperatorDeclaration)
ROSE_DLL_API SgTypeOfType * buildTypeOfType(SgExpression *base_expression, SgType *base_type)
Build a GNU typeof operator.
ROSE_DLL_API SgVoidVal * buildVoidVal()
DQ (2/14/2019): Adding support for C++14 void value expressions.
SgWhileStmt * buildWhileStmt_nfi(SgStatement *condition, SgStatement *body, SgStatement *else_body=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API bool emptyScopeStack()
intended to be a private member, don't access it directly. could be changed any time
SgClassNameRefExp * buildClassNameRefExp_nfi(SgClassSymbol *sym)
ROSE_DLL_API SgFloat80Val * buildFloat80Val_nfi(long double value, const std::string &str)
ROSE_DLL_API SgSetComprehension * buildSetComprehension(SgExpression *elt, SgExprListExp *generators)
ROSE_DLL_API SgTypeFloat64 * buildFloat64Type()
Built in simple types.
ROSE_DLL_API SgColonShapeExp * buildColonShapeExp_nfi()
No file info version of buildColonShapeExp(). File info is to be set later on.
ROSE_DLL_API SgVoidVal * buildVoidVal_nfi()
ROSE_DLL_API SgModifierType * buildVolatileType(SgType *base_type=nullptr)
Build a volatile type.
ROSE_DLL_API SgFunctionRefExp * buildFunctionRefExp(const SgName &name, const SgType *func_type, SgScopeStatement *scope=NULL)
Build SgFunctionRefExp based on a C++ function's name and function type. It will lookup symbol table ...
ROSE_DLL_API SgTemplateVariableInstantiation * buildTemplateVariableInstantiation(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope, SgTemplateVariableDeclaration *tpl_decl, SgTemplateArgumentPtrList &tpl_args)
Build template variable declarations.
ROSE_DLL_API SgTypeWchar * buildWcharType()
Built in simple types.
ROSE_DLL_API SgBasicBlock * buildBasicBlock(SgStatement *stmt1=NULL, SgStatement *stmt2=NULL, SgStatement *stmt3=NULL, SgStatement *stmt4=NULL, SgStatement *stmt5=NULL, SgStatement *stmt6=NULL, SgStatement *stmt7=NULL, SgStatement *stmt8=NULL, SgStatement *stmt9=NULL, SgStatement *stmt10=NULL)
Build a SgBasicBlock, setting file info internally.
ROSE_DLL_API SgAggregateInitializer * buildAggregateInitializer(SgExprListExp *initializers=NULL, SgType *type=NULL)
Build an aggregate initializer.
ROSE_DLL_API SgNoexceptOp * buildNoexceptOp_nfi(SgExpression *exp)
Build noexcept operator expression with an expression parameter.
ROSE_DLL_API SgTypeUnknown * buildUnknownType()
Built in simple types.
ROSE_DLL_API SgFoldExpression * buildFoldExpression(SgExpression *operands, std::string operator_token_string, bool is_left_associative)
ROSE_DLL_API SgVariableDeclaration * buildVariableDeclaration_nfi(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope, bool builtFromUseOnly=false, SgStorageModifier::storage_modifier_enum sm=SgStorageModifier::e_default)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeIdOp * buildTypeIdOp(SgExpression *operand_expr, SgType *operand_type)
DQ (1/25/2013): Added support for typeId operators.
ROSE_DLL_API SgExprStatement * buildAssignStatement(SgExpression *lhs, SgExpression *rhs)
Build an assignment statement from lefthand operand and right hand operand.
ROSE_DLL_API SgTypeUnsigned128bitInteger * buildUnsigned128bitIntegerType()
Built in simple types.
ROSE_DLL_API SgUnsignedIntVal * buildUnsignedIntVal(unsigned int v=0)
Build an unsigned integer.
SgFunctionRefExp * buildFunctionRefExp_nfi(SgFunctionSymbol *sym)
ROSE_DLL_API SgCharVal * buildCharVal(char value=0)
SgActualArgumentExpression * buildActualArgumentExpression_nfi(SgName arg_name, SgExpression *arg)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgSizeOfOp * buildSizeOfOp(SgExpression *exp=NULL)
Build sizeof() expression with an expression parameter.
ROSE_DLL_API SgMemberFunctionDeclaration * buildNondefiningMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, bool buildTemplateInstantiation, SgTemplateArgumentPtrList *templateArgumentsList)
Build a prototype member function declaration.
ROSE_DLL_API SgJavaWildcardType * getUniqueJavaWildcardSuper(SgType *)
Build a SgFile node and attach it to SgProject.
SgTypeTraitBuiltinOperator * buildTypeTraitBuiltinOperator(SgName functionName, SgNodePtrList parameters)
SgCompoundLiteralExp * buildCompoundLiteralExp(SgVariableSymbol *varSymbol)
Build function for compound literals (uses a SgVariableSymbol and is similar to buildVarRefExp()).
ROSE_DLL_API SgTemplateVariableInstantiation * buildTemplateVariableInstantiation_nfi(const SgName &name, SgType *type, SgInitializer *varInit, SgScopeStatement *scope, SgTemplateVariableDeclaration *tpl_decl, SgTemplateArgumentPtrList &tpl_args)
Build a variable declaration, handle symbol table transparently.
SgExprListExp * buildExprListExp_nfi()
ROSE_DLL_API SgType * getTargetFileTypeSupport(SgType *snippet_type, SgScopeStatement *targetScope)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgVariantExpression * buildVariantExpression()
ROSE_DLL_API SgNonrealBaseClass * buildNonrealBaseClass(SgNonrealDecl *classDeclaration, SgClassDefinition *classDefinition, bool isVirtual, bool isDirect)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgTypeSignedInt * buildSignedIntType()
Built in simple types.
ROSE_DLL_API SgBFloat16Val * buildBFloat16Val(float v=0)
Build a bfloat16.
ROSE_DLL_API void fixupCopyOfNodeFromSeparateFileInNewTargetAst(SgStatement *insertionPoint, bool insertionPointIsScope, SgNode *node_copy, SgNode *node_original)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgWcharVal * buildWcharVal(wchar_t value=0)
ROSE_DLL_API SgUnsignedShortVal * buildUnsignedShortValHex(unsigned short v=0)
ROSE_DLL_API SgTemplateMemberFunctionDeclaration * buildDefiningTemplateMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, SgTemplateMemberFunctionDeclaration *first_nondefing_declaration)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgVarRefExp * buildOpaqueVarRefExp(const std::string &varName, SgScopeStatement *scope=NULL)
Build a variable reference expression at scope to an opaque variable which has unknown information ex...
ROSE_DLL_API SgTypeUnsignedChar * buildUnsignedCharType()
Built in simple types.
ROSE_DLL_API SgJavaMarkerAnnotation * buildJavaMarkerAnnotation(SgType *)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgUnsignedIntVal * buildUnsignedIntVal_nfi(unsigned int v, const std::string &str)
ROSE_DLL_API SgNaryBooleanOp * buildNaryBooleanOp(SgExpression *lhs)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgModifierType * buildUpcBlockNumberType(SgType *base_type, long block_factor)
Build a UPC shared[n] type.
ROSE_DLL_API SgStatementExpression * buildStatementExpression(SgStatement *exp)
Build a GNU statement expression.
ROSE_DLL_API SgTypeSignedChar * buildSignedCharType()
Built in simple types.
ROSE_DLL_API SgUpcWaitStatement * buildUpcWaitStatement_nfi(SgExpression *exp)
Build a UPC wait statement.
ROSE_DLL_API SgDoubleVal * buildDoubleVal(double value=0.0)
Build a double value expression.
ROSE_DLL_API SgMemberFunctionDeclaration * buildDefaultConstructor(SgClassType *classType)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgUnsignedLongLongIntVal * buildUnsignedLongLongIntVal_nfi(unsigned long long v, const std::string &str)
ROSE_DLL_API SgAutoType * buildAutoType()
Built in simple types.
ROSE_DLL_API SgMemberFunctionRefExp * buildMemberFunctionRefExp(SgMemberFunctionSymbol *sym, bool virtual_call, bool need_qualifier)
ROSE_DLL_API SgFloat16Val * buildFloat16Val(float v=0)
Build a float16.
ROSE_DLL_API SgHereExp * buildHereExpression()
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgPlusPlusOp * buildPlusPlusOp(SgExpression *op=NULL)
ROSE_DLL_API SgComplexVal * buildComplexVal(SgValueExp *real_value, SgValueExp *imaginary_value)
ROSE_DLL_API SgNamespaceDeclarationStatement * buildNamespaceDeclaration_nfi(const SgName &name, bool unnamednamespace, SgScopeStatement *scope)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgIntVal * buildIntVal(int value=0)
Build an integer value expression.
SgYieldExpression * buildYieldExpression_nfi(SgExpression *value)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgChar32Val * buildChar32Val_nfi(unsigned int value, const std::string &str)
ROSE_DLL_API DeclClass * buildClassDeclarationStatement_nfi(const SgName &name, SgClassDeclaration::class_types kind, SgScopeStatement *scope=NULL, SgClassDeclaration *nonDefiningDecl=NULL)
Build a generic class declaration statement (SgClassDeclaration or subclass) with a class declaration...
SgTemplateFunctionRefExp * buildTemplateFunctionRefExp_nfi(SgTemplateFunctionSymbol *sym)
DQ (12/15/2011): Adding template declaration support to the AST.
ROSE_DLL_API SgNullStatement * buildNullStatement()
Build a NULL statement.
ROSE_DLL_API SgUpcNotifyStatement * buildUpcNotifyStatement_nfi(SgExpression *exp)
Build a UPC notify statement.
ROSE_DLL_API SgConstVolatileModifier * buildConstVolatileModifier(SgConstVolatileModifier::cv_modifier_enum mtype=SgConstVolatileModifier::e_unknown)
Build a const/volatile type qualifier.
ROSE_DLL_API SgJavaForEachStatement * buildJavaForEachStatement(SgVariableDeclaration *=NULL, SgExpression *=NULL, SgStatement *=NULL)
Build a Java Foreach statement.
ROSE_DLL_API SgBracedInitializer * buildBracedInitializer(SgExprListExp *initializers=NULL, SgType *expression_type=NULL)
Build an braced initializer.
ROSE_DLL_API SgFunctionType * buildFunctionType(SgType *return_type, SgFunctionParameterTypeList *typeList=nullptr)
Build function type from return type and parameter type list.
ROSE_DLL_API SgScopeStatement * buildScopeStatement(SgClassDefinition *=NULL)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgDictionaryExp * buildDictionaryExp(std::vector< SgKeyDatumPair * > pairs)
Build a list of key-datum pairs.
ROSE_DLL_API SgLambdaCaptureList * buildLambdaCaptureList()
ROSE_DLL_API SgJovialForThenStatement * buildJovialForThenStatement_nfi()
Build a Jovial loop statement.
ROSE_DLL_API SgInitializedName * buildJavaFormalParameter(SgType *, const SgName &, bool is_var_args=false, bool is_final=false)
Build a SgFile node and attach it to SgProject.
SgDeclarationStatement * associatedDeclaration(const SgSymbol &n)
returns the associated declaration for symbol n or nullptr if there is none.
Functions that are useful when operating on the AST.
Definition sageBuilder.h:25
void initializeIfStmt(SgIfStmt *ifstmt, SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void fixNamespaceDeclaration(SgNamespaceDeclarationStatement *structDecl, SgScopeStatement *scope)
Fix symbols, parent and scope pointers. Used internally within appendStatment(), insertStatement() et...
ROSE_DLL_API bool is_Jovial_language()
ROSE_DLL_API bool hasSameGlobalScope(SgStatement *statement_1, SgStatement *statement_2)
This is supporting the recognition of functions in header files from two different ASTs.
ROSE_DLL_API bool language_may_contain_nondeclarations_in_scope()
ROSE_DLL_API void fixStructDeclaration(SgClassDeclaration *structDecl, SgScopeStatement *scope)
Fix symbols, parent and scope pointers. Used internally within appendStatment(), insertStatement() et...
ROSE_DLL_API void appendExpressionList(SgExprListExp *, const std::vector< SgExpression * > &)
Append an expression list to a SgExprListExp, set the parent pointers also.
ROSE_DLL_API int set_name(SgInitializedName *initializedNameNode, SgName new_name)
set_name of symbol in symbol table.
ROSE_DLL_API SgVariableSymbol * getFirstVarSym(SgVariableDeclaration *decl)
Get the variable symbol for the first initialized name of a declaration stmt.
void initializeSwitchStatement(SgSwitchStatement *switchStatement, SgStatement *item_selector, SgStatement *body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void setOneSourcePositionForTransformation(SgNode *root)
Set current node's source position as transformation generated.
PreprocessingInfo * attachComment(SgSourceFile *source_file, const std::string &content, PreprocessingInfo::DirectiveType directive_type=PreprocessingInfo::C_StyleComment, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before)
Build and attach comment onto the global scope of a source file.
ROSE_DLL_API SgInitializedName * getFirstInitializedName(SgVariableDeclaration *decl)
Get the first initialized name of a declaration statement.
ROSE_DLL_API void reportModifiedStatements(const std::string &label, SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API void setSourcePositionForTransformation(SgNode *root)
Recursively set source position info(Sg_File_Info) as transformation generated.
ROSE_DLL_API SgGlobal * getGlobalScope(const SgNode *astNode)
Traverse back through a node's parents to find the enclosing global scope.
ROSE_DLL_API bool templateArgumentListEquivalence(const SgTemplateArgumentPtrList &list1, const SgTemplateArgumentPtrList &list2)
Verify that 2 SgTemplateArgumentPtrList are equivalent.
ROSE_DLL_API void reportModifiedLocatedNodes(const std::string &label, SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
void initializeWhileStatement(SgWhileStmt *whileStatement, SgStatement *condition, SgStatement *body, SgStatement *else_body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void setSourcePosition(SgNode *node)
Set the source code positon for the current (input) node.
bool isStructurallyEquivalentAST(SgNode *tree1, SgNode *tree2)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API bool is_language_case_insensitive()
ROSE_DLL_API SgFunctionSymbol * lookupFunctionSymbolInParentScopes(const SgName &functionName, SgScopeStatement *currentScope=NULL)
look up the first matched function symbol in parent scopes given only a function name,...
ROSE_DLL_API SgFile * getEnclosingFileNode(SgNode *astNode)
get the SgFile node from current node
bool ROSE_DLL_API isAncestor(SgNode *node1, SgNode *node2)
check if node1 is a strict ancestor of node 2. (a node is not considered its own ancestor)
ROSE_DLL_API void resetModifiedLocatedNodes(const std::set< SgLocatedNode * > &modifiedNodeSet)
Use the set of IR nodes and set the isModified flag in each IR node to true.
ROSE_DLL_API SgEnumSymbol * lookupEnumSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API SgTypedefSymbol * lookupTypedefSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API bool is_Fortran_language()
ROSE_DLL_API SgVariableSymbol * lookupVariableSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API void outputFileIds(SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API SgTemplateClassSymbol * lookupTemplateClassSymbolInParentScopes(const SgName &name, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateArgumentList, SgScopeStatement *cscope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
void collectVarRefs(SgLocatedNode *root, std::vector< SgVarRefExp * > &result)
Collect all variable references in a subtree.
ROSE_DLL_API SgVariableSymbol * appendArg(SgFunctionParameterList *, SgInitializedName *)
Append an argument to SgFunctionParameterList, transparently set parent,scope, and symbols for argume...
ROSE_DLL_API int fixVariableReferences(SgNode *root, bool cleanUnusedSymbol=true)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API void appendStatement(SgStatement *stmt, SgScopeStatement *scope=NULL)
Append a statement to the end of the current scope, handle side effect of appending statements,...
ROSE_DLL_API void setOneSourcePositionNull(SgNode *node)
Set current node's source position as NULL.
ROSE_DLL_API void fixVariableDeclaration(SgVariableDeclaration *varDecl, SgScopeStatement *scope)
Patch up symbol, scope, and parent information when a SgVariableDeclaration's scope is known.
ROSE_DLL_API SgFunctionDefinition * getEnclosingProcedure(SgNode *n, const bool includingSelf=false)
Find the function definition.
std::string get_name(const SgNode *node)
Generate a useful name to describe the SgNode.
ROSE_DLL_API bool is_Ada_language()
ROSE_DLL_API std::set< SgLocatedNode * > collectModifiedLocatedNodes(SgNode *node)
This collects the SgLocatedNodes that are marked as modified (a flag automatically set by all set_* g...
ROSE_DLL_API void fixLabelStatement(SgLabelStatement *label_stmt, SgScopeStatement *scope)
Fix symbol table for SgLabelStatement. Used Internally when the label is built without knowing its ta...
ROSE_DLL_API void appendStatementList(const std::vector< SgStatement * > &stmt, SgScopeStatement *scope=NULL)
Append a list of statements to the end of the current scope, handle side effect of appending statemen...
bool hasTemplateSyntax(const SgName &name)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API SgClassSymbol * lookupClassSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL, SgTemplateArgumentPtrList *templateArgumentList=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API void appendExpression(SgExprListExp *, SgExpression *)
Append an expression to a SgExprListExp, set the parent pointer also.
ROSE_DLL_API void prependStatement(SgStatement *stmt, SgScopeStatement *scope=NULL)
Prepend a statement to the beginning of the current scope, handling side effects as appropriate.
ROSE_DLL_API void setSourcePositionAtRootAndAllChildren(SgNode *root)
Set the source code positon for the subtree (including the root).
ROSE_DLL_API SgExpression * copyExpression(SgExpression *e)
Deep copy an expression.
void setParameterList(actualFunction *func, SgFunctionParameterList *paralist)
Set parameter list for a function declaration, considering existing parameter list etc.
ROSE_DLL_API SgFunctionType * findFunctionType(SgType *return_type, SgFunctionParameterTypeList *typeList)
Find the function type matching a function signature plus a given return type.